pax_global_header00006660000000000000000000000064146561421640014523gustar00rootroot0000000000000052 comment=0cf10190773843e1544d6467d7429165e866b087 objfw-1.1.6/000077500000000000000000000000001465614216400126375ustar00rootroot00000000000000objfw-1.1.6/COPYING000066400000000000000000001045151465614216400137000ustar00rootroot00000000000000 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 . objfw-1.1.6/COPYING.LESSER000066400000000000000000000167441465614216400147020ustar00rootroot00000000000000 GNU LESSER 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. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. objfw-1.1.6/ChangeLog000066400000000000000000000605731465614216400144240ustar00rootroot00000000000000Legend: * Changes of existing features or bugfixes + New features This file only contains the most significant changes. ObjFW 1.1.5 -> ObjFW 1.1.6, 2024-08-11 * Fixes ObjC++ with GCC. * Adds handling of EINTR in OFKernelEventObserver. * Fixes overriding / reusing stack arguments in super calls on x86. * Makes headers compatible with -Wunused-parameter. ObjFW 1.1.4 -> ObjFW 1.1.5, 2024-07-06 * Fixes MIPS32. * Properly hides private symbols in the runtime so they can't be used accidentally anymore. ObjFW 1.1.3 -> ObjFW 1.1.4, 2024-05-22 * Fixes ofarc failing to extract from stdin on macOS. * Fixes the workaround for missing blx on ARM. * Avoids Clang's integrated assembler on MIPS64 for .S files (as it cannot calcualte the offset between two labels). * Fixes X32 being mistaken for AMD64. ObjFW 1.1.2 -> ObjFW 1.1.3, 2024-05-12 * Fixes +[OFSystemInfo networkInterfaces] on NetBSD. * Properly hides private symbols so they can't be used accidentally anymore. * Adds missing documentation for various functions and macros. * Uses RtlGenRandom to get proper randomness on Windows now. * No longer uses _wutime64, which is buggy in some MinGW distributions. * Only uses blx on ARM if it is available now. * Adds a workaround for OFSubprocess tests on Windows 9x. * Skips symlink tests if symlinks are unavailable. ObjFW 1.1.1 -> ObjFW 1.1.2, 2024-04-20 * Fixes configure script on systems using BusyBox for tr. * Fixes compiling for Haiku. * Fixes -[contentsOfDirectoryAtIRI:] corrupting the stack on Solaris. * Fixes compiling for Wii with newer SDK. * Fixes missing endbr / bti. * Minor optimizations to ARM64 assembly. ObjFW 1.1 -> ObjFW 1.1.1, 2024-04-14 * Fixes missing ${DESTDIR} in some Makefiles. ObjFW 1.0.12 -> ObjFW 1.1, 2024-04-14 * ObjFW is now licensed under LGPLv3.0-only. + Adds a new framework for writing tests called ObjFWTest. * All tests were migrated to ObjFWTest. + The runtime now supports associated objects. + OFDNSResolver now caches responses. + OFDNSResolver now supports URI and LOC DNS resource records. + Adds methods to handle path extension to OFIRI. + Adds support for Mbed TLS. + Adds more methods to OFSystemInfo to check for CPU features. * OFSystemInfo now only indicates CPU features as supported if the OS also supports them. + OFLHAArchive now supports extracting and creating files > 4 GB. + OFLHAArchive now supports header level 3. + OFLHAArchive now supports extracting -lhx-, -lz4- and -pm0- files. * OFLHAArchive no longer defaults to ISO 8859-1. + New class OFZooArchive for extracting and creating Zoo files. * The schemes for archive IRI handlers have been renamed. * The schemes for archive IRI handlers now look for the rightmost `!`, which allows for chaining with less quoting. * Fixes -[OFMutableArray replaceObjectIdenticalTo:withObject:] being inconsistent with -[OFMutableArray replaceObject:withObject:]. * Fixes getting non-existent xattrs in OFFileManager. * Objects on Windows, MS-DOS and 32 bit Solaris now get properly aligned so that SIMD can be used on ivars. * Fixes parsing of signed numbers in MessagePack. * Fixes a memory leak in OFTarArchive. + Adds support for typed extended file attributes (only on Haiku). + Adds support for extended file attributes on Haiku, NetBSD and FreeBSD. + OFStdIOStream now supports cursor movement and colors on MS-DOS. * All headers are now compatible with -masm=intel. + OFMatrix4x4 can now transform multiple vectors at once. + OFMatrix4x4 has a 3DNow! implementation for multiplication and vector transformations now. + OFMatrix4x4 has an SSE implementation for vector transformations now. * Updates Unicode support to 15.1. * Fixes compatibility with LibreSSL. * Fixes two linker warnings on macOS. * Fixes compiling on QNX. * OFLocale now supports automatic initialization. + ofarc now supports extracting and creating Zoo archives. + ofarc now has an --iri option to directly work on local and remote IRIs. + ofarc now prints the archive comment with -lv. + ofarc can now add an archive comment with --archive-comment=. + ofarc now propagates the quarantine xattr on macOS when extracting an archive. ObjFW 1.0.11 -> ObjFW 1.0.12, 2024-03-11 * Fixes a regression in OFZIPArchive that was introduced in 1.0.11 that resulted in failing to extract archives and creating broken archives. * Fixes a rare condition where OFInflateStream could end up in an endless loop. * Fixes OFTarArchiveEntry not having a default date, which could result in messaging nil on a FP return, which yielded invalid results on 32-bit x86 with GCC. ObjFW 1.0.10 -> ObjFW 1.0.11, 2024-03-09 * Fixes -[OFHTTPClientResponse isAtEndOfStream] and -[OFGZIPStream isAtEndOfStream]. * Fixes how OFZIPArchive handles disk 0 vs. disk 1. * OFLHAArchive and OFZIPArchive create more compatible archives now. * OFLHAArchive ignores padding in level 2 headers now. * ofarc correctly sets modification dates of directories now by delaying setting those until after all files have been extracted. * Fixes a linker warning on macOS/iOS. * Several minor documentation fixes. * OFFileIRIHandler correctly transforms exceptions now so that they use an IRI and not a path. ObjFW 1.0.9 -> ObjFW 1.0.10, 2024-02-24 * Fixes objc_getClassList() not releasing the global runtime mutex. * Improves OFLHAArchive's compatibility with non-standard archives. + Adds endbr32 / endbr64 / bti instructions for compatibility with Control Flow Integrity. ObjFW 1.0.8 -> ObjFW 1.0.9, 2024-02-18 * Fixes OFGZIPStream reading the size and CRC32 incorrectly when either spans multiple reads. * Fixes a type mismatch in OFMapTable that could cause problems on big endian systems when uint32_t and unsigned long have a different size. * Fixes the default implementation of -[initWithKeys:arguments:] for custom dictionaries. * Improves detection of mutation during enumeration in -[enumerateKeysAndObjectsUsingBlock:]. * Minor documentation fixes. ObjFW 1.0.7 -> ObjFW 1.0.8, 2024-01-21 * Fixes compilation on NetBSD, OpenBSD, OpenIndiana etc. which was broken by 1.0.7. ObjFW 1.0.6 -> ObjFW 1.0.7, 2024-01-21 * Fixes inheriting the environment in OFSubprocess. * Fixes dealloc in OFSubprocess when -[closeForWriting] was called. + Adds tests for OFSubprocess. * Changes the key for +[OFSystemInfo networkInterfaces] to the adapter name on Windows XP and newer to avoid a possible collission on the adapter index. * Fixes compilation with old MinGW versions. * Fixes the documentation for OFSRVDNSResourceRecord. ObjFW 1.0.5 -> ObjFW 1.0.6, 2024-01-15 * Fixes compatibility with autoconf 2.72. * Fixes OFDNSResolver's handling of types, classes and lengths > 255. ObjFW 1.0.4 -> ObjFW 1.0.5, 2023-11-05 * Fixes the calculation of the extra alignment in OFAllocObject() * Fixes +[OFSystemInfo networkInterfaces] on OpenBSD and Windows 98 * Fixes OFSocketAddressString() for AppleTalk addresses * Uses GetModuleHandle() instead of LoadLibrary() where possible on Windows * Disables tests for global blocks on Win64 due to broken compilers * Adds PGP keys to verify tarballs and commits in the code repository ObjFW 1.0.3 -> ObjFW 1.0.4, 2023-10-08 * Fixes OFFile closing fd 0 when initialization fails * Fixes -[stringByAppendingPathComponent:] on empty strings * Fixes +[OFSystemInfo operatingSystemName] and +[OFSystemInfo operatingSystemVersion] returning nil on some systems * Adds a license for localizations ObjFW 1.0.2 -> ObjFW 1.0.3, 2023-09-14 * Fixes -[OFConcreteData initWithItemSize:] not setting freeWhenDone to true, which resulted in a memory leak * Fixes -[OFData initWithContentsOfIRI:] freeing the buffer in @catch instead of @finally, which resulted in a memory leak ObjFW 1.0.1 -> ObjFW 1.0.2, 2023-09-11 * The build system has been updated to fix building .frameworks and to build them differently for macOS and iOS ObjFW 1.0 -> ObjFW 1.0.1, 2023-09-10 * Hanging connections with OFTLSStream have been fixed when using OpenSSL * The same fix as for OpenSSL has been applied to GnuTLS and SecureTransport out of caution, even though there have been no hangs in practice * The build system has been updated to fix building .frameworks among other minor changes * Some headers have been changed to fix compatibility with ObjC++ * Warnings about empty .o files on x86_64 Darwin have been fixed * The OFDate documentation has been improved to list supported formats ObjFW 0.90.2 -> ObjFW 1.0, 2023-08-29 + First stable release with stable API and ABI * Too many changes to list, as it has been almost 6 years since the last release. See commits in the repository for details. ObjFW 0.90.1 -> ObjFW 0.90.2, 2017-10-23 * Fix shadowed variables which caused many bugs (e.g. using the wrong object) * Many, many nullability fixes * OFTCPSocket: Fix exception not being retained for async connect * OFThread: Fix setting the name on the wrong thread * OFMutableSet: Fix missing override for -[copy] * configure: Fix posix_spawnp check * Xcode project: Set the correct version for the bridge * Better check for iOS * tests: Fix testing the wrong OFKernelEventObserver ObjFW 0.90 -> ObjFW 0.90.1, 2017-08-20 * OFData: Fix -[description] * OFFileManager: Set errno to 0 before readdir() * OFDate: Add -[localMinute] * OFTarArchiveEntry: Fix prefix handling for ustar * OFZIPArchive: Fix uncompressed + data descriptor * OFArray: Fix MessagePack encoding * of_asprintf: Don't require set up OFLocalization * OFGZIPStream: Add missing documentation * Fix a linker warning on OpenBSD/SPARC64 * Remove the OFFile b modes from MorphOS (they were already removed for all other OSes) ObjFW 0.8.1 -> ObjFW 0.90, 2017-08-01 + New classes: OFFileManager, OFGZIPStream, OFTarArchive, OFTarArchiveEntry OFHMAC, OFSandbox, OFHTTPCookie, OFHTTPCookieManager, OFLocalization + New platforms: Nintendo 3DS, MorphOS + New lookup assembly for platforms: SPARC64/ELF, ARM64/ELF + New forwarding for: ARM64/ELF + New tools: objfw-new (to create boilerplate code) + New options: --disable-unicode-tables * Required GCC version increased to 4.6 * OFDataArray was split into OFData and OFMutableData * OFURL was split into OFURL and OFMutableURL * Most properties are now nonatomic (this changes from returned retained + autoreleased to +0 retained) * Correct handling of encoding on Win32 console (stream is read and written in UTF-8 and translated to UTF-16 on the fly) * Runtime is now built as a separate library + More encodings for strings * Reworked OFOptionsParser API * Refactored OFKernelEventObserver * Better randomization of HTTP header order * Allow overriding all HTTP headers * Definition of thread priorities changed + Key Value Coding + Exceptions in ObjC++ * OFHash was renamed to OFCryptoHash + PBKDF2 + scrypt + Xcode project to build for iOS + String decomposition to NFD * OFFile modes simplified ('b' removed) ObjFW 0.8 -> ObjFW 0.8.1, 2015-10-04 * Adjust to __nullable / __nonnull being changed to _Nullable / _Nonnull in Clang 3.7 (this fixes compilation with Clang 3.7) * Blocks: Proper handling when called from a byref handler * Fix compilation on Solaris * Fix compilation for Wii, PSP and Nintendo DS * OFProcess: Send SIGTERM on close instead of SIGKILL * OFZIPArchive: Throw invalid format exception on failed seeks * Make sure of_hash_seed is never initialized to 0 * Special cases for the Wii's weird network stack (fixes the tests) * Better length checks for write / send calls * Don't use -pedantic on platforms where it's broken by the system headers * Documentation fixes ObjFW 0.7.1 -> ObjFW 0.8, 2015-08-14 + An insanely huge amount of new APIs + New classes: OFHTTPServer, OFINICategory, OFINIFile, OFInflate64Stream, OFInflateStream, OFMapTable, OFRIPEMD160Hash, OFSHA224Hash, OFSHA256Hash, OFSHA384Hash, OFSHA512Hash, OFSettings, OFStdIOStream, OFSystemInfo, OFUDPSocket, OFZIPArchive, OFZIPArchiveEntry + New utils: ofzip, ofhash, ofhttp + Support for -[forwardingTargetForSelector:] on a lot of platforms (see PLATFORMS.md) * OFHTTPRequest: Split into OFHTTPRequest and OFHTTPClient * Rename OFHTTPRequestReply to OFHTTPResponse * OFDictionary now uses OFMapTable internally + Highly randomized, DoS-resistant hashtables (different seed per hashtable, additionally rotated by a random number of bits) * Reworked exceptions API that explicitly passes errno around + OFHTTPClient: Keep-alive and Basic Authorization support + Support for (and use of) ObjC generics, nullability and kindof + Fast path for resolving classes when using GCC (Clang doesn't need the fast path, as it directly references classes) * OFStreamObserver: Refactored and renamed to OFKernelEventObserver (as it is no longer limited to streams) + Support for SjLj and SEH exceptions + Support for DOS/DJGPP, Nintendo Wii, Nintendo DS and PlayStation Portable + Support for bare metal (in other words: running without any OS; tested on ARM) + Full support for ARM64 on iOS + Full MessagePack implementation (the new MessagePack version that supports strings) + Backtraces for uncaught exceptions + Bridge to Cocoa now part of ObjFW * Default depth limit for XML and JSON parser + Optional support for outputting JSON5 (default is JSON) * 16 bit selector UIDs are now the default * BOOL replaced with bool everywhere (except where required by the ABI) * Fix for a nasty bug in -[replaceCharactersInRange:withString:] * Fix for a nasty bug in atomic ops * OFTLSKey replaced with +[OFThread threadDictionary] * Documentation improvements (for example, imports should now be shown correctly everywhere and many APIs have been documented in more detail) + Property introspection * OFProcess: Use posix_spawnp if available * OFProcess improvements for Win32 + epoll support for OFKernelEventObserver * Rewritten OFMD5Hash and OFSHA1Hash * Reworked OFTLSSocket API (easier verification) * Unicode support updated to Unicode 8.0 * OFURL: Proper escaping and unescaping ObjFW 0.7 -> ObjFW 0.7.1, 2012-11-12 + Support for Haiku * Autorelease pools now work properly without __thread * Incorrect framework version in Xcode project fixed * Documentation fixes and improvements * Blocks now only use 16 bits for the reference count in order to avoid problems with newer Clang versions * More use of OF_SENTINEL ObjFW 0.6 -> ObjFW 0.7, 2012-10-27 Again, the differences are more than in any release before, thus listing them all would be too much. The major differences are: + ObjFW now comes with its own runtime, which greatly increases performance compared to the GNU runtime and is even faster than the Apple runtime (using Clang >= 3.2 is recommended, but not necessary) * Support for the GNU runtime has been dropped + New, much faster autorelease pool implementation (now inside the runtime) + Support for Automatic Reference Counting (requires Clang >= 3.2) + Forwarding has been implemented + Asynchronous stream handling + New classes: OFThreadPool, OFRecursiveMutex, OFSortedList, OFTimer, OFRunLoop + New protocols: OFLocking, OFTLSSocket * Lots of API changes to make APIs more future-proof + Support for the new Objective-C literals * OFHTTPRequest now implements HTTP/1.1 * OFObject's memory handling has been improved, leading to better performance * Strings are allocated faster now + Support for JSON5 * All private methods use the prefix OF_ now instead of _, making it possible to use the _ prefix in applications * Most ObjC compiler feature checks are not part of configure anymore, making it possible to use the same installation with different compilers ObjFW 0.5.4 -> ObjFW 0.6, 2012-02-27 The differences between 0.5.4 and 0.6 are too big to list them all. However, the major new features are: * OFString, OFArray, OFDictionary, OFSet and OFCountedSet are now class clusters + Serialization and deserialization of objects into/from XML and JSON + New class OFIntrospection for introspecting classes + New class OFProcess for working with and controlling child processes * Lots of OFXMLParser and OFXMLElement improvements + OFHTTPRequests can have a delegate now for status updates and processing data as soon as it arrives + There are several backends for OFStreamObserver now, including kqueue, poll and select + SOCKS5 support for OFTCPSockets (client only) * Several API changes ObjFW 0.5.3 -> ObjFW 0.5.4, 2011-08-30 * The blocks runtime is now working correctly * Documentation fixes * -framework works with objfw-compile now + Support for QNX * Various small fixes ObjFW 0.5.2 -> ObjFW 0.5.3, 2011-07-01 * Lots of bugfixes, see Git log for details ObjFW 0.5.1 -> ObjFW 0.5.2, 2011-04-25 * Fix double-retain in OFList * Don't ignore the timeout in OFStreamObserver when using select() * Do -[OFURL copy] in a try block to prevent a leak when an exception occurs * Fix too big buffer in -[OFMutableString _applyTable:withSize:] * Call madvise() on the correct length variable so it covers the whole string * Fix a warning when sizeof(size_t) < sizeof(long long) * Skip possible BOMs when appending strings ObjFW 0.5 -> ObjFW 0.5.1, 2011-04-21 * Work around a wrong warning produced by Apple GCC 4.0.1 which would cause the build to fail due to -Werror * Call objc_thread_{add,remove} when using the GNU runtime to make sure the runtime knows about our thread * Detach a thread before restarting if it was never joined * Release the old return value when restarting a thread ObjFW 0.4-alpha1 -> 0.5, 2011-04-09 + %@ is now allowed in format strings + Added of_log for easy logging * Exceptions have one header per exception now * Lots of exception improvements * Huge improvements in XML handling * Improvements in socket handling, including improved API * OFStreamObserver is now thread-safe and stops the current observe call when the set of streams to observe is modified + New class OFURL + New class OFHTTPRequest + New class OFCondition * Improvements in objfw-compile + Blocks can be used together with Cocoa now + When linking ObjFW and Cocoa, OFAutoreleasePools are used by both now + Support for Base64 + Use a real Xcode project instead of just calling make + Add Haiku to the list of supported platforms * Lots of small bugfixes and countless small changes. Read the commits! ObjFW 0.3.1 -> 0.4-alpha1, 2011-01-03 * ObjFW is now available under the terms of the QPL, GPLv2 and GPLv3 + Support for blocks was added, including a blocks runtime + Added support for the new GNU runtime, introduced in GCC 4.6 * Objects returned from collections are no longer retained and autoreleased + Added new classes OFXMLParser, OFXMLElement, OFXMLAttribute and OFXMLElementBuilder + Added new class OFStreamObserver to observe streams + Added new class OFDate for storing dates + Many new methods in almost all classes * OFAutoreleasePool was optimized * Handling of ASCII strings was optimized * OFSocket was renamed to OFStreamSocket * OFConstString was renamed to OFConstantString * objfw-compile now has a new syntax + objfw-compile can now compile libraries and plugins * Many small changes and new features that would be too much to list here The diff between 0.3.1 and 0.4-alpha1 has almost 24000 lines! ObjFW 0.3 -> 0.3.1, 2010-06-19 * Fix a typo in OFMutableDictionary that prevented termination in case the last bucket is already used when the dictionary is resized * The mutations pointer is now correctly initialized in enumerators for immutable collections * The objc_sync test was still using the old threads API and was updated to use the new one now * PLATFORMS has been updated to be more specific ObjFW 0.2.1 -> 0.3, 2010-05-09 + Many new methods were added to different classes + A huge amount of methods was added to OFStream, allowing easy binary stream handling and even mixing string-based and binary operations + An optional write buffer was added to OFStream + OFSeekableStream was added for streams that allow seeking, for example OFFiles * OFNumber was completely reworked and got many new features now * Large parts of OFDictionary were rewritten for better readability, better memory usage and to fix a bug with removing objects * OFThread has been greatly improved * Many small optimizations * Many documentation improvements * Method replacing was reworked and the methods renamed + Tests for OFStream were added * A bug with building ObjFW as a Universal Binary Framework was fixed + Support for ObjFW-RT, the ObjFW Objective C runtime, was added * Sockets are now properly closed before an exception is thrown * Error handling with sockets was improved * OFFile now uses open(), read() and write(), thus allowing -[readLine] to be used on of_stdin and fixing many other annoyances * A few misc methods were renamed + OFApplication was added * All tests and the table generator are now using OFApplication + It is now possible to get the remote address of an OFTCPSocket + OFString can now build paths in the OS-native format + It is now possible to create a string with the contents of a file + Many new file operations were added to OFFile * The existing file operations in OFFile were improved * Almost all functions that returned self before now return void + OFHash was added as a superclass for OFMD5Hash and OFSHA1Hash and OFHashes renamed to OFHash + objfw-compile was added for easy compilation of ObjFW projects, which includes dependency checking for headers etc. * The instance variable naming convention was changed so that properties work + Properties were added to the interfaces and are used if they are supported by the compiler + The library version is now included in the resulting dylib and libobjc is reexported now. Additionally, objfw-config offers --reexport now to produce libraries that link against ObjFW and reexport it ObjFW 0.2 -> 0.2.1, 2010-03-14 * Fix for OFNumbers not doing calculations * Improved -[hash] for OFNumbers with floats and doubles + Tests for OFNumber * Small optimization for OFArray's -[componentsJoinedByString:] * Documentation improvements * Updated copyright ObjFW 0.1.2 -> 0.2, 2010-02-01 + Support for ObjC 2 Fast Enumerations on every platform which has compiler support for fast enumerations + Support for ObjC 2 properties on every platform with compiler support + Fast Enumeration through arrays and dictionaries * OFIterator has been removed + OFEnumerator was added to replace OFIterator, which is more general and works with arrays and dictionaries + Portable implementation for atomic operations + Portable implementation for spinlocks. They use atomic operations if available, if not they fall back to pthread spinlocks. If both are unavailable, mutexes are used as a last fallback * -[retain] and -[release] are now atomic. If no atomic operations are available, spinlocks are used (which can fall back to mutexes, see above) * -[readLine] now handles \r\n without having the \r included in the returned line + OFThread now has -[tryLock] * Mutation methods have been removed from immutable interfaces, thus already giving an error at compilation instead of at runtime * Dependencies between headers have been reduced, leading to faster compile times * The interfaces of OFSocket and OFStream were cleaned up and some methods were moved to OFTCPSocket, as they make sense only there * File methods unavailable on Windows don't throw an exception at runtime anymore, but instead are not even in the interface on Windows. This way, it is a compile time error instead of a runtime error ObjFW 0.1.1 -> 0.1.2, 2010-01-15 * Fix a bug in OFMutableArray's -[removeObject:] and -[removeObjectIdenticalTo:] that could lead to not removing all occurrences of the object from the array and to out of bounds reads * Change the URL in the framework plist to the homepage ObjFW 0.1 -> 0.1.1, 2010-01-04 * Fix a missing out of range check for -[removeNItems:atIndex:] that allowed the programmer to specify too big ranges so it would crash instead of throwing an exception * Fix missing calls to -[retain] and -[autorelease] when getting objects from an OFArray or OFDictionary * Safer and more fault-tolerant way to remove objects from an OFMutableArray * Calling +[dealloc] throws an exception now. If someone really calls [SomeClass dealloc], this should be punished and not ignored, as this is a serious programmer error * -[readLineWithEncoding:] is more fault-tolerant now and does not lose data when it stumbles upon invalid encoding. Instead, it allows recalling with the correct encoding now ObjFW 0.1, 2009-12-24 + Initial release objfw-1.1.6/Doxyfile000066400000000000000000000030121465614216400143410ustar00rootroot00000000000000PROJECT_NAME = "ObjFW" OUTPUT_DIRECTORY = docs/ INPUT = src src/exceptions src/runtime src/test FILE_PATTERNS = *.h *.m HTML_OUTPUT = . HAVE_DOT = NO GENERATE_LATEX = NO HIDE_UNDOC_CLASSES = YES HIDE_UNDOC_MEMBERS = YES TYPEDEF_HIDES_STRUCT = YES PREDEFINED = _Nonnull= \ _Nullable= \ DOXYGEN \ OF_BOXABLE= \ OF_CONSUMED= \ OF_DESIGNATED_INITIALIZER= \ OF_DEPRECATED(...)= \ OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES \ OF_FILE_MANAGER_SUPPORTS_LINKS \ OF_FILE_MANAGER_SUPPORTS_OWNER \ OF_FILE_MANAGER_SUPPORTS_PERMISSIONS \ OF_FILE_MANAGER_SUPPORTS_SYMLINKS \ OF_GENERIC(...)= \ OF_HAVE_APPLETALK \ OF_HAVE_BLOCKS \ OF_HAVE_FILES \ OF_HAVE_IPV6 \ OF_HAVE_IPX \ OF_HAVE_PLUGINS \ OF_HAVE_SANDBOX \ OF_HAVE_SOCKETS \ OF_HAVE_THREADS \ OF_HAVE_UNICODE_TABLES \ OF_KINDOF(...)= \ OF_NO_RETURN= \ OF_NO_RETURN_FUNC= \ OF_NULLABLE_PROPERTY(...)= \ OF_NULL_RESETTABLE_PROPERTY(...)= \ OF_REQUIRES_SUPER= \ OF_RETURNS_INNER_POINTER= \ OF_RETURNS_NOT_RETAINED= \ OF_RETURNS_RETAINED= \ OF_ROOT_CLASS= \ OF_SENTINEL= \ OF_WARN_UNUSED_RESULT= \ OF_WEAK_UNAVAILABLE= \ SIGHUP \ SIGUSR1 \ SIGUSR2 MACRO_EXPANSION = YES EXPAND_ONLY_PREDEF = YES IGNORE_PREFIX = OF OF_ OT OT_ EXTRACT_STATIC = yes objfw-1.1.6/Makefile000066400000000000000000000025371465614216400143060ustar00rootroot00000000000000include extra.mk SUBDIRS = src utils tests DISTCLEAN = Info.plist \ aclocal.m4 \ autom4te.cache \ buildsys.mk \ config.h \ config.log \ config.status \ extra.mk include buildsys.mk .PHONY: check docs release utils tests: src check: tests ${MAKE} -C tests -s run docs: rm -fr docs doxygen >/dev/null release: docs echo "Generating tarball for version ${PACKAGE_VERSION}..." rm -fr objfw-${PACKAGE_VERSION} objfw-${PACKAGE_VERSION}.tar \ objfw-${PACKAGE_VERSION}.tar.gz fossil tarball --name objfw-${PACKAGE_VERSION} current - \ --exclude '.fossil*,.git*' | ofarc -ttgz -xq - cp configure config.h.in objfw-${PACKAGE_VERSION}/ ofarc -cq objfw-${PACKAGE_VERSION}.tar objfw-${PACKAGE_VERSION} rm -fr objfw-${PACKAGE_VERSION} gzip -9 objfw-${PACKAGE_VERSION}.tar rm -f objfw-${PACKAGE_VERSION}.tar gpg -b objfw-${PACKAGE_VERSION}.tar.gz || true rm -fr objfw-docs-${PACKAGE_VERSION} objfw-docs-${PACKAGE_VERSION}.tar \ objfw-docs-${PACKAGE_VERSION}.tar.gz mv docs objfw-docs-${PACKAGE_VERSION} echo "Generating docs tarball for version ${PACKAGE_VERSION}..." ofarc -cq objfw-docs-${PACKAGE_VERSION}.tar \ objfw-docs-${PACKAGE_VERSION} rm -fr objfw-docs-${PACKAGE_VERSION} gzip -9 objfw-docs-${PACKAGE_VERSION}.tar rm -f objfw-docs-${PACKAGE_VERSION}.tar gpg -b objfw-docs-${PACKAGE_VERSION}.tar.gz || true objfw-1.1.6/PLATFORMS.md000066400000000000000000000135401465614216400145330ustar00rootroot00000000000000Platforms ========= ObjFW is known to work on the following platforms, but should run on many others as well. AmigaOS ------- * OS Versions: 3.1, 4.1 Final Edition Update 1 * Architectures: m68k, PowerPC * Compilers: GCC 6.4.1b (amiga-gcc), GCC 8.3.0 (adtools) * Runtimes: ObjFW Android ------- * OS Versions: 4.0.4, 4.1.2, 6.0.1 * Architectures: ARMv6, ARMv7, ARM64 * Compilers: Clang 3.3, Clang 3.8.0 * Runtimes: ObjFW Bare metal ARM Cortex-M4 ------------------------ * Architectures: ARMv7E-M * Compilers: Clang 3.5 * Runtimes: ObjFW * Notes: Bootloader, libc (newlib) and possibly external RAM required DOS --- * OS Versions: Windows XP DOS Emulation, DOSBox, MS-DOS 6.0, FreeDOS 1.2 * Architectures: x86 * Compilers: DJGPP GCC 4.7.3 (djdev204) * Runtimes: ObjFW DragonFlyBSD ------------ * OS Versions: 3.0, 3.3-DEVELOPMENT * Architectures: AMD64, x86 * Compilers: GCC 4.4.7 * Runtimes: ObjFW FreeBSD ------- * OS Versions: 9.1-rc3, 10.0 * Architectures: AMD64 * Compilers: Clang 3.1, Clang 3.3 * Runtimes: ObjFW GNU/Hurd -------- * OS Versions: 0.9 * Architectures: i686 * Compilers: Clang 14.0.6 * Runtimes: ObjFW Haiku ----- * OS version: r1-alpha4 * Architectures: x86 * Compilers: Clang 3.2, GCC 4.6.3 * Runtimes: ObjFW HP-UX ----- * OS versions: 11i v1, 11i v3 * Architectures: Itanium, PA-RISC 2.0 * Compilers: GCC 4.7.2, GCC 7.5.0 * Runtimes: ObjFW * Notes: Exception handling on Itanium in 32 bit mode is broken, you need to use 64 bit mode by passing `OBJC="gcc -mlp64"` to `configure`. iOS --- * Architectures: ARMv7, ARM64 * Compilers: Clang * Runtimes: Apple Linux ----- * Architectures: Alpha, AMD64, ARMv5, ARMv6, ARMv7, ARM64, Itanium, LoongArch 64, m68k, MIPS (O32), MIPS64 (N64), RISC-V 64, PA-RISC, PowerPC, PowerPC 64, S390x, SuperH-4, x86 * Compilers: Clang 3.0-18.1.1, GCC 4.6-14.1.1 * C libraries: glibc, musl * Runtimes: ObjFW macOS ----- * OS Versions: 10.5, 10.7-10.15, Darling * Architectures: AMD64, PowerPC, PowerPC64, x86 * Compilers: Clang 3.1-10.0, Apple GCC 4.0.1 & 4.2.1 * Runtimes: Apple, ObjFW MiNT ---- * OS Versions: FreeMiNT 1.19 * Architectures: m68k * Runtimes: ObjFW * Compilers: GCC 4.6.4 (MiNT 20130415) * Limitations: No shared libraries, no threads MorphOS ------- * OS Versions: 3.14 * Architectures: PowerPC * Compilers: GCC 9.3.0 * Runtimes: ObjFW NetBSD ------ * OS Versions: 5.1-9.0 * Architectures: AMD64, ARM, ARM (big endian, BE8 mode), MIPS (O32), PowerPC, SPARC, SPARC64, x86 * Compilers: Clang 3.0-3.2, GCC 4.1.3 & 4.5.3 & 7.4.0 * Runtimes: ObjFW Nintendo 3DS ------------ * OS Versions: 9.2.0-20E, 10.5.0-30E / Homebrew Channel 1.1.0 * Architectures: ARM (EABI) * Compilers: GCC 5.3.0 (devkitARM release 45) * Runtimes: ObjFW * Limitations: No threads Nintendo DS ----------- * Architectures: ARM (EABI) * Compilers: GCC 4.8.2 (devkitARM release 42) * Runtimes: ObjFW * Limitations: No threads, no sockets * Notes: File support requires an argv-compatible launcher (such as HBMenu) Nintendo Switch --------------- * OS Versions: yuzu 1093 * Architectures: AArch64 * Compilers: GCC 12.1.0 (devkitA64 release 19) * Runtimes: ObjFW * Limitations: No sockets, no shared libraries, not tested on real hardware OpenBSD ------- * OS Versions: 5.2-6.7 * Architectures: AMD64, MIPS64, PA-RISC, PowerPC, SPARC64 * Compilers: GCC 6.3.0, Clang 4.0 * Runtimes: ObjFW PlayStation Portable -------------------- * OS Versions: 5.00 M33-4 * Architectures: MIPS (EABI) * Compiler: GCC 4.6.2 (devkitPSP release 16) * Runtimes: ObjFW * Limitations: No threads, no sockets QNX --- * OS Versions: 6.5.0 * Architectures: x86 * Compilers: GCC 4.6.1 * Runtimes: ObjFW Solaris ------- * OS Versions: OpenIndiana 2015.03, OpenIndiana 2023.04, Oracle Solaris 11.4 * Architectures: AMD64, x86 * Compilers: Clang 3.4.2, Clang 11.0.0, Clang 13.0.1, GCC 4.8.3, GCC 10.4.0 * Runtimes: ObjFW Wii --- * OS Versions: 4.3E / Homebrew Channel 1.1.0 * Architectures: PowerPC * Compilers: GCC 4.6.3 (devkitPPC release 26) * Runtimes: ObjFW * Limitations: No threads Wii U ----- * OS Versions: Cemu 12.26.2f * Architectures: PowerPC * Compilers: gcc version 12.1.0 (devkitPPC release 41) * Runtimes: ObjFW * Limitations: No files, no threads, no sockets, no shared libraries, not tested on real hardware Windows ------- * OS Versions: 98 SE, NT 4.0, XP, 7, 8, 8.1, 10, 11, Wine * Architectures: AArch64, AMD64, x86 * Compilers: GCC 5.3.0 & 6.2.0 from msys2 (AMD64 & x86), Clang 3.9.0 from msys2 (x86), Clang 10.0 from msys2 (AMD64 & x86), Clang 14.0.4 from msys2 (AArch64) * Runtimes: ObjFW Others ------ Basically, it should run on any POSIX system to which GCC >= 4.6 or a recent Clang version has been ported. If not, please send an e-mail with a bug report. If you successfully ran ObjFW on a platform not listed here, please send an e-mail to js@nil.im so it can be added here! If you have a platform on which ObjFW does not work, please contact me as well! Forwarding ========== As forwarding needs hand-written assembly for each combination of CPU architecture, executable format and calling convention, it is only available for the following platforms (except resolveClassMethod: and resolveInstanceMethod:, which are always available): * AMD64 (SysV/ELF, Apple/Mach-O, Mach-O, Win64/PE) * ARM (EABI/ELF, Apple/Mach-O) * ARM64 (ARM64/ELF, Apple/Mach-O) * MIPS (O32/ELF, EABI/ELF) * PowerPC (SysV/ELF, EABI/ELF, Apple/Mach-O) * SPARC (SysV/ELF) * SPARC64 (SysV/ELF) * x86 (SysV/ELF, Apple/Mach-O, Win32/PE) Apple/Mach-O means both, the Apple ABI and runtime, while Mach-O means the ObjFW runtime on Mach-O. objfw-1.1.6/README.md000066400000000000000000000374321465614216400141270ustar00rootroot00000000000000There are three ways you are probably reading this right now: * On [ObjFW](https://objfw.nil.im/)'s homepage, via Fossil's web interface * On [GitHub](https://github.com/ObjFW/ObjFW) * Via an editor or pager, by opening `README.md` from a clone or tarball ObjFW is developed using Fossil, so if you are reading this on GitHub or any other place, you are most likely using a mirror.

Table of Contents

* [What is ObjFW?](#what) * [Installation](#installation) * [License](#license) * [Releases](#releases) * [Cloning the repository](#cloning) * [Building from source](#building-from-source) * [macOS and iOS](#macos-and-ios) * [Building as a framework](#building-framework) * [Using the macOS or iOS framework in Xcode](#framework-in-xcode) * [Broken Xcode versions](#broken-xcode-versions) * [Windows](#windows) * [Getting MSYS2](#getting-msys2) * [Setting up MSYS2](#setting-up-msys2) * [Getting, building and installing ObjFW](#steps-windows) * [Nintendo DS, Nintendo 3DS and Wii](#nintendo) * [Nintendo DS](#nintendo-ds) * [Nintendo 3DS](#nintendo-3ds) * [Wii](#wii) * [Amiga](#amiga) * [Writing your first application with ObjFW](#first-app) * [Documentation](#documentation) * [Bugs and feature requests](#bugs) * [Support and community](#support) * [Donating](#donating) * [Thanks](#thanks) * [Commercial use](#commercial-use)

What is ObjFW?

ObjFW is a portable, lightweight framework for the Objective-C language. It enables you to write an application in Objective-C that will run on any [platform](PLATFORMS.md) supported by ObjFW without having to worry about differences between operating systems or various frameworks you would otherwise need if you want to be portable. It supports all modern Objective-C features when using Clang, but is also compatible with GCC ≥ 4.6 to allow maximum portability. ObjFW is intentionally incompatible with Foundation. This has two reasons: * GNUstep already provides a reimplementation of Foundation, which is only compatible to a certain degree. This means that a developer still needs to care about differences between frameworks if they want to be portable. The idea behind ObjFW is that a developer does not need to concern themselves with portability and making sure their code works with multiple frameworks: Instead, if it works it ObjFW on one platform, they can reasonably expect it to also work with ObjFW on another platform. ObjFW behaving differently on different operating systems (unless inevitable because it is a platform-specific part, like the Windows Registry) is considered a bug and will be fixed. * Foundation predates a lot of modern Objective-C concepts. The most prominent one is exceptions, which are only used in Foundation as a replacement for `abort()`. This results in cumbersome error handling, especially in initializers, which in Foundation only return `nil` on error with no indication of what went wrong. It also means that the return of every `init` call needs to be checked against `nil`. But in the wild, nobody actually checks *each and every* return from `init` against `nil`, leading to bugs. ObjFW fixes this by making exceptions a first class citizen. ObjFW also comes with its own lightweight and extremely fast Objective-C runtime, which in real world use cases was found to be significantly faster than both GNU's and Apple's runtime.

Installation

ObjFW packages are available for various operating systems and can be installed as following: Operating System | Command ---------------------------|--------------------------------------------- Alpine Linux | `doas apk add objfw` CRUX | `sudo prt-get depinst objfw` Debian | `sudo apt install objfw` Fedora | `sudo dnf install objfw` FreeBSD | `sudo pkg install objfw` Haiku | `pkgman install objfw` Haiku (gcc2h) | `pkgman install objfw_x86` macOS (Homebrew) | `brew install objfw` macOS (pkgsrc) | `cd $PKGSRCDIR/devel/objfw && make install` NetBSD | `cd /usr/pkgsrc/devel/objfw && make install` OpenBSD | `doas pkg_add objfw` OpenIndiana | `sudo pkg install developer/objfw` Ubuntu | `sudo apt install objfw` Windows (MSYS2/CLANG64) | `pacman -S mingw-w64-clang-x86_64-objfw` Windows (MSYS2/CLANGARM64) | `pacman -S mingw-w64-clang-aarch64-objfw` Windows (MSYS2/UCRT64) | `pacman -S mingw-w64-ucrt-x86_64-objfw` Windows (MSYS2/MINGW32) | `pacman -S mingw-w64-i686-objfw` If your operating system is not listed, you can build ObjFW from source.

License

ObjFW is released under the GNU Lesser General Public License version 3.0. If this license does not work for you, contact me and we can find a solution.

Releases

Releases of ObjFW, as well as change logs and the accompanying documentation, can be found [here](https://objfw.nil.im/wiki?name=Releases).

Cloning the repository

ObjFW is developed in a [Fossil](https://fossil-scm.org) repository, with automatic incremental exports to Git. This means you can either clone the Fossil repository or the Git repository - it does not make a huge difference. The main advantage of cloning the Fossil repository over cloning the Git repository is that you also get all the tickets, wiki pages, etc.

Fossil

Clone the Fossil repository like this: fossil clone https://objfw.nil.im You can then use Fossil's web interface to browse the timeline, tickets, wiki pages, etc.: cd objfw fossil ui In order to verify the signature of the currently checked out checkin, you can use: fossil artifact current | gpg --verify Please note that not all checkins are signed, as the signing key only resides on trusted systems. This means that checkins I perform on e.g. Windows are unsigned. However, usually it should not take long until there is another signed checkin. Alternatively, you can go back until the last signed checkin and review changes from there on.

Git

To clone the Git repository, use the following: git clone https://github.com/ObjFW/ObjFW Git commits are not signed, so if you want to check the signature of an individual commit, branch head or tag, please use Fossil.

Building from source

To build ObjFW from source and install it, just run the following commands: ./configure make make check sudo make install In case you checked out ObjFW from the Fossil or Git repository, you need to run the following command first: ./autogen.sh

macOS and iOS

Building as a framework

When building for macOS or iOS, everything is built as a `.framework` by default if `--disable-shared` has not been specified to `./configure`. The frameworks will end up in `$PREFIX/Library/Frameworks`. To build for macOS, just follow the regular instructions above. To build for iOS, follow the regular instructions, but instead of `./configure` do something like this: clang="xcrun --sdk iphoneos clang" export OBJC="$clang -arch arm64e -arch arm64" export OBJCPP="$clang -arch arm64e -E" export IPHONEOS_DEPLOYMENT_TARGET="10.0" ./configure --prefix=/usr/local/ios --host=arm64-apple-darwin To build for the iOS simulator, follow the regular instructions, but instead of `./configure` use something like this: clang="xcrun --sdk iphonesimulator clang" export OBJC="$clang -arch $(uname -m)" export IPHONEOS_DEPLOYMENT_TARGET="10.0" ./configure --prefix=/usr/local/iossim --host=$(uname -m)-apple-darwin

Using the macOS or iOS framework in Xcode

To use the macOS framework in Xcode, you need to add the `.framework`s to your project and add the following flags to `Other C Flags`: -fconstant-string-class=OFConstantString -fno-constant-cfstrings

Broken Xcode versions

Some versions of Xcode shipped with a version of Clang that ignores `-fconstant-string-class=OFConstantString`. This will manifest in an error like this: OFAllocFailedException.m:94:10: error: cannot find interface declaration for 'NSConstantString' return @"Allocating an object failed!"; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. Unfortunately, there is no workaround for this other than to upgrade/downgrade Xcode or to build upstream Clang yourself. In particular, Xcode 11 Beta 1 to Beta 3 are known to be affected. While Xcode 11 Beta 4 to Xcode 11.3 work, the bug was unfortunately reintroduced in Xcode 11.4.1 and was only fixed in Xcode 12 Beta 1. You can get older versions of Xcode [here](https://developer.apple.com/download) by clicking on "More" in the top-right corner.

Windows

Windows is only officially supported when following these instructions, as there are many MinGW versions that behave slightly differently and often cause problems.

Getting MSYS2

The first thing to install is [MSYS2](https://www.msys2.org) to provide a basic UNIX-like environment for Windows. Unfortunately, the binaries are not signed, so make sure you download it via HTTPS. However, packages you download and install via MSYS2 are cryptographically signed.

Setting up MSYS2

MSYS2 currently supports 7 different [environments](https://www.msys2.org/docs/environments/). All of them except for the one called just "MSYS" are supported, but which packages you need to install depends on the environment(s) you want to use. If you only want to target Windows 10 and newer, the CLANG64 and CLANG32 environments are the recommended ones. For CLANG64, use: pacman -Syu mingw-w64-clang-x86_64-clang \ mingw-w64-clang-x86_64-fossil \ mingw-w64-clang-x86_64-openssl For CLANG32, use: pacman -Syu mingw-w64-clang-i686-clang \ mingw-w64-clang-i686-fossil \ mingw-w64-clang-i686-openssl For CLANGARM64, use (you need to use Fossil via another environment): pacman -Syu mingw-w64-clang-aarch64-clang mingw-w64-clang-aarch64-openssl For MINGW64, use: pacman -Syu mingw-w64-x86_64-clang \ mingw-w64-x86_64-fossil \ mingw-w64-x86_64-openssl For MINGW32, use: pacman -Syu mingw-w64-i686-clang \ mingw-w64-i686-fossil \ mingw-w64-i686-openssl For UCRT64, use: pacman -Syu mingw-w64-ucrt-x86_64-clang \ mingw-w64-ucrt-x86_64-fossil \ mingw-w64-ucrt-x86_64-openssl When using `pacman` to install the packages, `pacman` might tell you to close the window. If it does so, close the window, restart MSYS2 and execute the `pacman` command again. There is nothing wrong with installing multiple environments, as MSYS2 has created shortcuts for each of them in your start menu. Just make sure to use the correct shortcut for the environment you want to use. Finally, install a few more things that are common between all environments: pacman -S autoconf automake make

Getting, building and installing ObjFW

Start the MSYS2 using the shortcut for the environment you want to use and check out ObjFW: fossil clone https://objfw.nil.im You can also download a release tarball if you want. Now `cd` to the newly checked out repository and build and install it: ./autogen.sh && ./configure && make -j16 install If everything was successful, you can now build projects using ObjFW for Windows using the normal `objfw-compile` and friends.

Nintendo DS, Nintendo 3DS and Wii

Download and install [devkitPro](https://devkitpro.org/wiki/Getting_Started).

Nintendo DS

Follow the normal process, but instead of `./configure` run: ./configure --host=arm-none-eabi --with-nds

Nintendo 3DS

Follow the normal process, but instead of `./configure` run: ./configure --host=arm-none-eabi --with-3ds

Wii

Follow the normal process, but instead of `./configure` run: ./configure --host=powerpc-eabi --with-wii

Amiga

Install [amiga-gcc](https://github.com/bebbo/amiga-gcc). Then follow the normal process, but instead of `./configure` run: ./configure --host=m68k-amigaos

Writing your first application with ObjFW

To create your first, empty application, you can use `objfw-new`: objfw-new --app MyFirstApp This creates a file `MyFirstApp.m`. The `-[applicationDidFinishLaunching:]` method is called as soon as ObjFW finished all initialization. Use this as the entry point to your own code. For example, you could add the following line there to create a "Hello World": [OFStdOut writeLine: @"Hello World!"]; You can compile your new app using `objfw-compile`: objfw-compile -o MyFirstApp MyFirstApp.m `objfw-compile` is a tool that allows building applications and libraries using ObjFW without needing a full-blown build system. If you want to use your own build system, you can get the necessary flags from `objfw-config`.

Documentation

You can find the documentation for released versions of ObjFW [here](https://objfw.nil.im/docs/). In order to build the documentation yourself (necessary to have documentation for trunk / master), you need to have [Doxygen](https://www.doxygen.nl) installed. Once installed, you can build the documentation from the root directory of the repository: make docs

Bugs and feature requests

If you find any bugs or have feature requests, please [file a new bug](https://objfw.nil.im/tktnew) in the [bug tracker](https://objfw.nil.im/reportlist). Alternatively, feel free to send a mail to js@nil.im!

Support and community

If you have any questions about ObjFW or would like to talk to other ObjFW users, the following venues are available: * The [forum](https://objfw.nil.im/forum) * A [Matrix room](https://matrix.to/#/%23objfw:nil.im) * A [Discord room](https://objfw.nil.im/discord), bridged to the Matrix room above * A [Telegram room](https://t.me/objfw), bridged to the Matrix room above * A [Slack room](https://objfw.nil.im/slack), bridged to the Matrix room above * An IRC channel named `#objfw` on `irc.oftc.net` ([Web chat](https://webchat.oftc.net/?channels=%23objfw)), bridged to the Matrix room above Please don't hesitate to join any or all of those!

Donating

If you want to donate to ObjFW, you can read about possible ways to do so [here](https://objfw.nil.im/wiki?name=Donating).

Thanks

* Thank you to [Jonathan Neuschäfer](https://github.com/neuschaefer) for reviewing the *entirety* (all 84k LoC at the time) of ObjFW's codebase in 2017! * Thank you to [Hill Ma](https://github.com/mahiuchun) for donating an M1 Mac Mini to the project in 2022!

Commercial use

If for whatever reason the terms of GNU Lesser General Public License version 3.0 don't work for you, a proprietary license for ObjFW including support is available upon request. Just write a mail to js@nil.im and we can find a reasonable solution for both parties. objfw-1.1.6/autogen.sh000077500000000000000000000003541465614216400146420ustar00rootroot00000000000000#!/bin/sh set -e # Set a version for OpenBSD if test x"$(uname -s)" = x"OpenBSD"; then : ${AUTOCONF_VERSION:=2.71} : ${AUTOMAKE_VERSION:=1.16} export AUTOCONF_VERSION AUTOMAKE_VERSION fi aclocal -I build-aux/m4 autoconf autoheader objfw-1.1.6/build-aux/000077500000000000000000000000001465614216400145315ustar00rootroot00000000000000objfw-1.1.6/build-aux/config.guess000066400000000000000000001426761465614216400170660ustar00rootroot00000000000000#! /bin/sh # Attempt to guess a canonical system name. # Copyright 1992-2023 Free Software Foundation, Inc. # shellcheck disable=SC2006,SC2268 # see below for rationale timestamp='2023-08-22' # This file 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 . # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that # program. This Exception is an additional permission under section 7 # of the GNU General Public License, version 3 ("GPLv3"). # # Originally written by Per Bothner; maintained since 2000 by Ben Elliston. # # You can get the latest version of this script from: # https://git.savannah.gnu.org/cgit/config.git/plain/config.guess # # Please send patches to . # The "shellcheck disable" line above the timestamp inhibits complaints # about features and limitations of the classic Bourne shell that were # superseded or lifted in POSIX. However, this script identifies a wide # variety of pre-POSIX systems that do not have POSIX shells at all, and # even some reasonably current systems (Solaris 10 as case-in-point) still # have a pre-POSIX /bin/sh. me=`echo "$0" | sed -e 's,.*/,,'` usage="\ Usage: $0 [OPTION] Output the configuration name of the system '$me' is run on. Options: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit Report bugs and patches to ." version="\ GNU config.guess ($timestamp) Originally written by Per Bothner. Copyright 1992-2023 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." help=" Try '$me --help' for more information." # Parse command line while test $# -gt 0 ; do case $1 in --time-stamp | --time* | -t ) echo "$timestamp" ; exit ;; --version | -v ) echo "$version" ; exit ;; --help | --h* | -h ) echo "$usage"; exit ;; -- ) # Stop option processing shift; break ;; - ) # Use stdin as input. break ;; -* ) echo "$me: invalid option $1$help" >&2 exit 1 ;; * ) break ;; esac done if test $# != 0; then echo "$me: too many arguments$help" >&2 exit 1 fi # Just in case it came from the environment. GUESS= # CC_FOR_BUILD -- compiler used by this script. Note that the use of a # compiler to aid in system detection is discouraged as it requires # temporary files to be created and, as you can see below, it is a # headache to deal with in a portable fashion. # Historically, 'CC_FOR_BUILD' used to be named 'HOST_CC'. We still # use 'HOST_CC' if defined, but it is deprecated. # Portable tmp directory creation inspired by the Autoconf team. tmp= # shellcheck disable=SC2172 trap 'test -z "$tmp" || rm -fr "$tmp"' 0 1 2 13 15 set_cc_for_build() { # prevent multiple calls if $tmp is already set test "$tmp" && return 0 : "${TMPDIR=/tmp}" # shellcheck disable=SC2039,SC3028 { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir "$tmp" 2>/dev/null) ; } || { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir "$tmp" 2>/dev/null) && echo "Warning: creating insecure temp directory" >&2 ; } || { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } dummy=$tmp/dummy case ${CC_FOR_BUILD-},${HOST_CC-},${CC-} in ,,) echo "int x;" > "$dummy.c" for driver in cc gcc c89 c99 ; do if ($driver -c -o "$dummy.o" "$dummy.c") >/dev/null 2>&1 ; then CC_FOR_BUILD=$driver break fi done if test x"$CC_FOR_BUILD" = x ; then CC_FOR_BUILD=no_compiler_found fi ;; ,,*) CC_FOR_BUILD=$CC ;; ,*,*) CC_FOR_BUILD=$HOST_CC ;; esac } # This is needed to find uname on a Pyramid OSx when run in the BSD universe. # (ghazi@noc.rutgers.edu 1994-08-24) if test -f /.attbin/uname ; then PATH=$PATH:/.attbin ; export PATH fi UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown case $UNAME_SYSTEM in Linux|GNU|GNU/*) LIBC=unknown set_cc_for_build cat <<-EOF > "$dummy.c" #if defined(__ANDROID__) LIBC=android #else #include #if defined(__UCLIBC__) LIBC=uclibc #elif defined(__dietlibc__) LIBC=dietlibc #elif defined(__GLIBC__) LIBC=gnu #else #include /* First heuristic to detect musl libc. */ #ifdef __DEFINED_va_list LIBC=musl #endif #endif #endif EOF cc_set_libc=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g'` eval "$cc_set_libc" # Second heuristic to detect musl libc. if [ "$LIBC" = unknown ] && command -v ldd >/dev/null && ldd --version 2>&1 | grep -q ^musl; then LIBC=musl fi # If the system lacks a compiler, then just pick glibc. # We could probably try harder. if [ "$LIBC" = unknown ]; then LIBC=gnu fi ;; esac # Note: order is significant - the case branches are not exclusive. case $UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION in *:NetBSD:*:*) # NetBSD (nbsd) targets should (where applicable) match one or # more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*, # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently # switched to ELF, *-*-netbsd* would select the old # object file format. This provides both forward # compatibility and a consistent mechanism for selecting the # object file format. # # Note: NetBSD doesn't particularly care about the vendor # portion of the name. We always set it to "unknown". UNAME_MACHINE_ARCH=`(uname -p 2>/dev/null || \ /sbin/sysctl -n hw.machine_arch 2>/dev/null || \ /usr/sbin/sysctl -n hw.machine_arch 2>/dev/null || \ echo unknown)` case $UNAME_MACHINE_ARCH in aarch64eb) machine=aarch64_be-unknown ;; armeb) machine=armeb-unknown ;; arm*) machine=arm-unknown ;; sh3el) machine=shl-unknown ;; sh3eb) machine=sh-unknown ;; sh5el) machine=sh5le-unknown ;; earmv*) arch=`echo "$UNAME_MACHINE_ARCH" | sed -e 's,^e\(armv[0-9]\).*$,\1,'` endian=`echo "$UNAME_MACHINE_ARCH" | sed -ne 's,^.*\(eb\)$,\1,p'` machine=${arch}${endian}-unknown ;; *) machine=$UNAME_MACHINE_ARCH-unknown ;; esac # The Operating System including object format, if it has switched # to ELF recently (or will in the future) and ABI. case $UNAME_MACHINE_ARCH in earm*) os=netbsdelf ;; arm*|i386|m68k|ns32k|sh3*|sparc|vax) set_cc_for_build if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ELF__ then # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). # Return netbsd for either. FIX? os=netbsd else os=netbsdelf fi ;; *) os=netbsd ;; esac # Determine ABI tags. case $UNAME_MACHINE_ARCH in earm*) expr='s/^earmv[0-9]/-eabi/;s/eb$//' abi=`echo "$UNAME_MACHINE_ARCH" | sed -e "$expr"` ;; esac # The OS release # Debian GNU/NetBSD machines have a different userland, and # thus, need a distinct triplet. However, they do not need # kernel version information, so it can be replaced with a # suitable tag, in the style of linux-gnu. case $UNAME_VERSION in Debian*) release='-gnu' ;; *) release=`echo "$UNAME_RELEASE" | sed -e 's/[-_].*//' | cut -d. -f1,2` ;; esac # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: # contains redundant information, the shorter form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. GUESS=$machine-${os}${release}${abi-} ;; *:Bitrig:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'` GUESS=$UNAME_MACHINE_ARCH-unknown-bitrig$UNAME_RELEASE ;; *:OpenBSD:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` GUESS=$UNAME_MACHINE_ARCH-unknown-openbsd$UNAME_RELEASE ;; *:SecBSD:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/SecBSD.//'` GUESS=$UNAME_MACHINE_ARCH-unknown-secbsd$UNAME_RELEASE ;; *:LibertyBSD:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/^.*BSD\.//'` GUESS=$UNAME_MACHINE_ARCH-unknown-libertybsd$UNAME_RELEASE ;; *:MidnightBSD:*:*) GUESS=$UNAME_MACHINE-unknown-midnightbsd$UNAME_RELEASE ;; *:ekkoBSD:*:*) GUESS=$UNAME_MACHINE-unknown-ekkobsd$UNAME_RELEASE ;; *:SolidBSD:*:*) GUESS=$UNAME_MACHINE-unknown-solidbsd$UNAME_RELEASE ;; *:OS108:*:*) GUESS=$UNAME_MACHINE-unknown-os108_$UNAME_RELEASE ;; macppc:MirBSD:*:*) GUESS=powerpc-unknown-mirbsd$UNAME_RELEASE ;; *:MirBSD:*:*) GUESS=$UNAME_MACHINE-unknown-mirbsd$UNAME_RELEASE ;; *:Sortix:*:*) GUESS=$UNAME_MACHINE-unknown-sortix ;; *:Twizzler:*:*) GUESS=$UNAME_MACHINE-unknown-twizzler ;; *:Redox:*:*) GUESS=$UNAME_MACHINE-unknown-redox ;; mips:OSF1:*.*) GUESS=mips-dec-osf1 ;; alpha:OSF1:*:*) # Reset EXIT trap before exiting to avoid spurious non-zero exit code. trap '' 0 case $UNAME_RELEASE in *4.0) UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` ;; *5.*) UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` ;; esac # According to Compaq, /usr/sbin/psrinfo has been available on # OSF/1 and Tru64 systems produced since 1995. I hope that # covers most systems running today. This code pipes the CPU # types through head -n 1, so we only detect the type of CPU 0. ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` case $ALPHA_CPU_TYPE in "EV4 (21064)") UNAME_MACHINE=alpha ;; "EV4.5 (21064)") UNAME_MACHINE=alpha ;; "LCA4 (21066/21068)") UNAME_MACHINE=alpha ;; "EV5 (21164)") UNAME_MACHINE=alphaev5 ;; "EV5.6 (21164A)") UNAME_MACHINE=alphaev56 ;; "EV5.6 (21164PC)") UNAME_MACHINE=alphapca56 ;; "EV5.7 (21164PC)") UNAME_MACHINE=alphapca57 ;; "EV6 (21264)") UNAME_MACHINE=alphaev6 ;; "EV6.7 (21264A)") UNAME_MACHINE=alphaev67 ;; "EV6.8CB (21264C)") UNAME_MACHINE=alphaev68 ;; "EV6.8AL (21264B)") UNAME_MACHINE=alphaev68 ;; "EV6.8CX (21264D)") UNAME_MACHINE=alphaev68 ;; "EV6.9A (21264/EV69A)") UNAME_MACHINE=alphaev69 ;; "EV7 (21364)") UNAME_MACHINE=alphaev7 ;; "EV7.9 (21364A)") UNAME_MACHINE=alphaev79 ;; esac # A Pn.n version is a patched version. # A Vn.n version is a released version. # A Tn.n version is a released field test version. # A Xn.n version is an unreleased experimental baselevel. # 1.2 uses "1.2" for uname -r. OSF_REL=`echo "$UNAME_RELEASE" | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` GUESS=$UNAME_MACHINE-dec-osf$OSF_REL ;; Amiga*:UNIX_System_V:4.0:*) GUESS=m68k-unknown-sysv4 ;; *:[Aa]miga[Oo][Ss]:*:*) GUESS=$UNAME_MACHINE-unknown-amigaos ;; *:[Mm]orph[Oo][Ss]:*:*) GUESS=$UNAME_MACHINE-unknown-morphos ;; *:OS/390:*:*) GUESS=i370-ibm-openedition ;; *:z/VM:*:*) GUESS=s390-ibm-zvmoe ;; *:OS400:*:*) GUESS=powerpc-ibm-os400 ;; arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) GUESS=arm-acorn-riscix$UNAME_RELEASE ;; arm*:riscos:*:*|arm*:RISCOS:*:*) GUESS=arm-unknown-riscos ;; SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) GUESS=hppa1.1-hitachi-hiuxmpp ;; Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. case `(/bin/universe) 2>/dev/null` in att) GUESS=pyramid-pyramid-sysv3 ;; *) GUESS=pyramid-pyramid-bsd ;; esac ;; NILE*:*:*:dcosx) GUESS=pyramid-pyramid-svr4 ;; DRS?6000:unix:4.0:6*) GUESS=sparc-icl-nx6 ;; DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) case `/usr/bin/uname -p` in sparc) GUESS=sparc-icl-nx7 ;; esac ;; s390x:SunOS:*:*) SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` GUESS=$UNAME_MACHINE-ibm-solaris2$SUN_REL ;; sun4H:SunOS:5.*:*) SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` GUESS=sparc-hal-solaris2$SUN_REL ;; sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` GUESS=sparc-sun-solaris2$SUN_REL ;; i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*) GUESS=i386-pc-auroraux$UNAME_RELEASE ;; i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) set_cc_for_build SUN_ARCH=i386 # If there is a compiler, see if it is configured for 64-bit objects. # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. # This test works for both compilers. if test "$CC_FOR_BUILD" != no_compiler_found; then if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \ (CCOPTS="" $CC_FOR_BUILD -m64 -E - 2>/dev/null) | \ grep IS_64BIT_ARCH >/dev/null then SUN_ARCH=x86_64 fi fi SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` GUESS=$SUN_ARCH-pc-solaris2$SUN_REL ;; sun4*:SunOS:6*:*) # According to config.sub, this is the proper way to canonicalize # SunOS6. Hard to guess exactly what SunOS6 will be like, but # it's likely to be more like Solaris than SunOS4. SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` GUESS=sparc-sun-solaris3$SUN_REL ;; sun4*:SunOS:*:*) case `/usr/bin/arch -k` in Series*|S4*) UNAME_RELEASE=`uname -v` ;; esac # Japanese Language versions have a version number like '4.1.3-JL'. SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/-/_/'` GUESS=sparc-sun-sunos$SUN_REL ;; sun3*:SunOS:*:*) GUESS=m68k-sun-sunos$UNAME_RELEASE ;; sun*:*:4.2BSD:*) UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` test "x$UNAME_RELEASE" = x && UNAME_RELEASE=3 case `/bin/arch` in sun3) GUESS=m68k-sun-sunos$UNAME_RELEASE ;; sun4) GUESS=sparc-sun-sunos$UNAME_RELEASE ;; esac ;; aushp:SunOS:*:*) GUESS=sparc-auspex-sunos$UNAME_RELEASE ;; # The situation for MiNT is a little confusing. The machine name # can be virtually everything (everything which is not # "atarist" or "atariste" at least should have a processor # > m68000). The system name ranges from "MiNT" over "FreeMiNT" # to the lowercase version "mint" (or "freemint"). Finally # the system name "TOS" denotes a system which is actually not # MiNT. But MiNT is downward compatible to TOS, so this should # be no problem. atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) GUESS=m68k-atari-mint$UNAME_RELEASE ;; atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) GUESS=m68k-atari-mint$UNAME_RELEASE ;; *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) GUESS=m68k-atari-mint$UNAME_RELEASE ;; milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) GUESS=m68k-milan-mint$UNAME_RELEASE ;; hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) GUESS=m68k-hades-mint$UNAME_RELEASE ;; *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) GUESS=m68k-unknown-mint$UNAME_RELEASE ;; m68k:machten:*:*) GUESS=m68k-apple-machten$UNAME_RELEASE ;; powerpc:machten:*:*) GUESS=powerpc-apple-machten$UNAME_RELEASE ;; RISC*:Mach:*:*) GUESS=mips-dec-mach_bsd4.3 ;; RISC*:ULTRIX:*:*) GUESS=mips-dec-ultrix$UNAME_RELEASE ;; VAX*:ULTRIX*:*:*) GUESS=vax-dec-ultrix$UNAME_RELEASE ;; 2020:CLIX:*:* | 2430:CLIX:*:*) GUESS=clipper-intergraph-clix$UNAME_RELEASE ;; mips:*:*:UMIPS | mips:*:*:RISCos) set_cc_for_build sed 's/^ //' << EOF > "$dummy.c" #ifdef __cplusplus #include /* for printf() prototype */ int main (int argc, char *argv[]) { #else int main (argc, argv) int argc; char *argv[]; { #endif #if defined (host_mips) && defined (MIPSEB) #if defined (SYSTYPE_SYSV) printf ("mips-mips-riscos%ssysv\\n", argv[1]); exit (0); #endif #if defined (SYSTYPE_SVR4) printf ("mips-mips-riscos%ssvr4\\n", argv[1]); exit (0); #endif #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) printf ("mips-mips-riscos%sbsd\\n", argv[1]); exit (0); #endif #endif exit (-1); } EOF $CC_FOR_BUILD -o "$dummy" "$dummy.c" && dummyarg=`echo "$UNAME_RELEASE" | sed -n 's/\([0-9]*\).*/\1/p'` && SYSTEM_NAME=`"$dummy" "$dummyarg"` && { echo "$SYSTEM_NAME"; exit; } GUESS=mips-mips-riscos$UNAME_RELEASE ;; Motorola:PowerMAX_OS:*:*) GUESS=powerpc-motorola-powermax ;; Motorola:*:4.3:PL8-*) GUESS=powerpc-harris-powermax ;; Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) GUESS=powerpc-harris-powermax ;; Night_Hawk:Power_UNIX:*:*) GUESS=powerpc-harris-powerunix ;; m88k:CX/UX:7*:*) GUESS=m88k-harris-cxux7 ;; m88k:*:4*:R4*) GUESS=m88k-motorola-sysv4 ;; m88k:*:3*:R3*) GUESS=m88k-motorola-sysv3 ;; AViiON:dgux:*:*) # DG/UX returns AViiON for all architectures UNAME_PROCESSOR=`/usr/bin/uname -p` if test "$UNAME_PROCESSOR" = mc88100 || test "$UNAME_PROCESSOR" = mc88110 then if test "$TARGET_BINARY_INTERFACE"x = m88kdguxelfx || \ test "$TARGET_BINARY_INTERFACE"x = x then GUESS=m88k-dg-dgux$UNAME_RELEASE else GUESS=m88k-dg-dguxbcs$UNAME_RELEASE fi else GUESS=i586-dg-dgux$UNAME_RELEASE fi ;; M88*:DolphinOS:*:*) # DolphinOS (SVR3) GUESS=m88k-dolphin-sysv3 ;; M88*:*:R3*:*) # Delta 88k system running SVR3 GUESS=m88k-motorola-sysv3 ;; XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) GUESS=m88k-tektronix-sysv3 ;; Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) GUESS=m68k-tektronix-bsd ;; *:IRIX*:*:*) IRIX_REL=`echo "$UNAME_RELEASE" | sed -e 's/-/_/g'` GUESS=mips-sgi-irix$IRIX_REL ;; ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. GUESS=romp-ibm-aix # uname -m gives an 8 hex-code CPU id ;; # Note that: echo "'`uname -s`'" gives 'AIX ' i*86:AIX:*:*) GUESS=i386-ibm-aix ;; ia64:AIX:*:*) if test -x /usr/bin/oslevel ; then IBM_REV=`/usr/bin/oslevel` else IBM_REV=$UNAME_VERSION.$UNAME_RELEASE fi GUESS=$UNAME_MACHINE-ibm-aix$IBM_REV ;; *:AIX:2:3) if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then set_cc_for_build sed 's/^ //' << EOF > "$dummy.c" #include main() { if (!__power_pc()) exit(1); puts("powerpc-ibm-aix3.2.5"); exit(0); } EOF if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` then GUESS=$SYSTEM_NAME else GUESS=rs6000-ibm-aix3.2.5 fi elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then GUESS=rs6000-ibm-aix3.2.4 else GUESS=rs6000-ibm-aix3.2 fi ;; *:AIX:*:[4567]) IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` if /usr/sbin/lsattr -El "$IBM_CPU_ID" | grep ' POWER' >/dev/null 2>&1; then IBM_ARCH=rs6000 else IBM_ARCH=powerpc fi if test -x /usr/bin/lslpp ; then IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc | \ awk -F: '{ print $3 }' | sed s/[0-9]*$/0/` else IBM_REV=$UNAME_VERSION.$UNAME_RELEASE fi GUESS=$IBM_ARCH-ibm-aix$IBM_REV ;; *:AIX:*:*) GUESS=rs6000-ibm-aix ;; ibmrt:4.4BSD:*|romp-ibm:4.4BSD:*) GUESS=romp-ibm-bsd4.4 ;; ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and GUESS=romp-ibm-bsd$UNAME_RELEASE # 4.3 with uname added to ;; # report: romp-ibm BSD 4.3 *:BOSX:*:*) GUESS=rs6000-bull-bosx ;; DPX/2?00:B.O.S.:*:*) GUESS=m68k-bull-sysv3 ;; 9000/[34]??:4.3bsd:1.*:*) GUESS=m68k-hp-bsd ;; hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) GUESS=m68k-hp-bsd4.4 ;; 9000/[34678]??:HP-UX:*:*) HPUX_REV=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*.[0B]*//'` case $UNAME_MACHINE in 9000/31?) HP_ARCH=m68000 ;; 9000/[34]??) HP_ARCH=m68k ;; 9000/[678][0-9][0-9]) if test -x /usr/bin/getconf; then sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` case $sc_cpu_version in 523) HP_ARCH=hppa1.0 ;; # CPU_PA_RISC1_0 528) HP_ARCH=hppa1.1 ;; # CPU_PA_RISC1_1 532) # CPU_PA_RISC2_0 case $sc_kernel_bits in 32) HP_ARCH=hppa2.0n ;; 64) HP_ARCH=hppa2.0w ;; '') HP_ARCH=hppa2.0 ;; # HP-UX 10.20 esac ;; esac fi if test "$HP_ARCH" = ""; then set_cc_for_build sed 's/^ //' << EOF > "$dummy.c" #define _HPUX_SOURCE #include #include int main () { #if defined(_SC_KERNEL_BITS) long bits = sysconf(_SC_KERNEL_BITS); #endif long cpu = sysconf (_SC_CPU_VERSION); switch (cpu) { case CPU_PA_RISC1_0: puts ("hppa1.0"); break; case CPU_PA_RISC1_1: puts ("hppa1.1"); break; case CPU_PA_RISC2_0: #if defined(_SC_KERNEL_BITS) switch (bits) { case 64: puts ("hppa2.0w"); break; case 32: puts ("hppa2.0n"); break; default: puts ("hppa2.0"); break; } break; #else /* !defined(_SC_KERNEL_BITS) */ puts ("hppa2.0"); break; #endif default: puts ("hppa1.0"); break; } exit (0); } EOF (CCOPTS="" $CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null) && HP_ARCH=`"$dummy"` test -z "$HP_ARCH" && HP_ARCH=hppa fi ;; esac if test "$HP_ARCH" = hppa2.0w then set_cc_for_build # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler # generating 64-bit code. GNU and HP use different nomenclature: # # $ CC_FOR_BUILD=cc ./config.guess # => hppa2.0w-hp-hpux11.23 # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess # => hppa64-hp-hpux11.23 if echo __LP64__ | (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | grep -q __LP64__ then HP_ARCH=hppa2.0w else HP_ARCH=hppa64 fi fi GUESS=$HP_ARCH-hp-hpux$HPUX_REV ;; ia64:HP-UX:*:*) HPUX_REV=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*.[0B]*//'` GUESS=ia64-hp-hpux$HPUX_REV ;; 3050*:HI-UX:*:*) set_cc_for_build sed 's/^ //' << EOF > "$dummy.c" #include int main () { long cpu = sysconf (_SC_CPU_VERSION); /* The order matters, because CPU_IS_HP_MC68K erroneously returns true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct results, however. */ if (CPU_IS_PA_RISC (cpu)) { switch (cpu) { case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; default: puts ("hppa-hitachi-hiuxwe2"); break; } } else if (CPU_IS_HP_MC68K (cpu)) puts ("m68k-hitachi-hiuxwe2"); else puts ("unknown-hitachi-hiuxwe2"); exit (0); } EOF $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` && { echo "$SYSTEM_NAME"; exit; } GUESS=unknown-hitachi-hiuxwe2 ;; 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:*) GUESS=hppa1.1-hp-bsd ;; 9000/8??:4.3bsd:*:*) GUESS=hppa1.0-hp-bsd ;; *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) GUESS=hppa1.0-hp-mpeix ;; hp7??:OSF1:*:* | hp8?[79]:OSF1:*:*) GUESS=hppa1.1-hp-osf ;; hp8??:OSF1:*:*) GUESS=hppa1.0-hp-osf ;; i*86:OSF1:*:*) if test -x /usr/sbin/sysversion ; then GUESS=$UNAME_MACHINE-unknown-osf1mk else GUESS=$UNAME_MACHINE-unknown-osf1 fi ;; parisc*:Lites*:*:*) GUESS=hppa1.1-hp-lites ;; C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) GUESS=c1-convex-bsd ;; C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) if getsysinfo -f scalar_acc then echo c32-convex-bsd else echo c2-convex-bsd fi exit ;; C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) GUESS=c34-convex-bsd ;; C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) GUESS=c38-convex-bsd ;; C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) GUESS=c4-convex-bsd ;; CRAY*Y-MP:*:*:*) CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` GUESS=ymp-cray-unicos$CRAY_REL ;; CRAY*[A-Z]90:*:*:*) echo "$UNAME_MACHINE"-cray-unicos"$UNAME_RELEASE" \ | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ -e 's/\.[^.]*$/.X/' exit ;; CRAY*TS:*:*:*) CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` GUESS=t90-cray-unicos$CRAY_REL ;; CRAY*T3E:*:*:*) CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` GUESS=alphaev5-cray-unicosmk$CRAY_REL ;; CRAY*SV1:*:*:*) CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` GUESS=sv1-cray-unicos$CRAY_REL ;; *:UNICOS/mp:*:*) CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` GUESS=craynv-cray-unicosmp$CRAY_REL ;; F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) FUJITSU_PROC=`uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` FUJITSU_REL=`echo "$UNAME_RELEASE" | sed -e 's/ /_/'` GUESS=${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL} ;; 5000:UNIX_System_V:4.*:*) FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` FUJITSU_REL=`echo "$UNAME_RELEASE" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/'` GUESS=sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL} ;; i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) GUESS=$UNAME_MACHINE-pc-bsdi$UNAME_RELEASE ;; sparc*:BSD/OS:*:*) GUESS=sparc-unknown-bsdi$UNAME_RELEASE ;; *:BSD/OS:*:*) GUESS=$UNAME_MACHINE-unknown-bsdi$UNAME_RELEASE ;; arm:FreeBSD:*:*) UNAME_PROCESSOR=`uname -p` set_cc_for_build if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_PCS_VFP then FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL-gnueabi else FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL-gnueabihf fi ;; *:FreeBSD:*:*) UNAME_PROCESSOR=`uname -p` case $UNAME_PROCESSOR in amd64) UNAME_PROCESSOR=x86_64 ;; i386) UNAME_PROCESSOR=i586 ;; esac FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL ;; i*:CYGWIN*:*) GUESS=$UNAME_MACHINE-pc-cygwin ;; *:MINGW64*:*) GUESS=$UNAME_MACHINE-pc-mingw64 ;; *:MINGW*:*) GUESS=$UNAME_MACHINE-pc-mingw32 ;; *:MSYS*:*) GUESS=$UNAME_MACHINE-pc-msys ;; i*:PW*:*) GUESS=$UNAME_MACHINE-pc-pw32 ;; *:SerenityOS:*:*) GUESS=$UNAME_MACHINE-pc-serenity ;; *:Interix*:*) case $UNAME_MACHINE in x86) GUESS=i586-pc-interix$UNAME_RELEASE ;; authenticamd | genuineintel | EM64T) GUESS=x86_64-unknown-interix$UNAME_RELEASE ;; IA64) GUESS=ia64-unknown-interix$UNAME_RELEASE ;; esac ;; i*:UWIN*:*) GUESS=$UNAME_MACHINE-pc-uwin ;; amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) GUESS=x86_64-pc-cygwin ;; prep*:SunOS:5.*:*) SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` GUESS=powerpcle-unknown-solaris2$SUN_REL ;; *:GNU:*:*) # the GNU system GNU_ARCH=`echo "$UNAME_MACHINE" | sed -e 's,[-/].*$,,'` GNU_REL=`echo "$UNAME_RELEASE" | sed -e 's,/.*$,,'` GUESS=$GNU_ARCH-unknown-$LIBC$GNU_REL ;; *:GNU/*:*:*) # other systems with GNU libc and userland GNU_SYS=`echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"` GNU_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` GUESS=$UNAME_MACHINE-unknown-$GNU_SYS$GNU_REL-$LIBC ;; x86_64:[Mm]anagarm:*:*|i?86:[Mm]anagarm:*:*) GUESS="$UNAME_MACHINE-pc-managarm-mlibc" ;; *:[Mm]anagarm:*:*) GUESS="$UNAME_MACHINE-unknown-managarm-mlibc" ;; *:Minix:*:*) GUESS=$UNAME_MACHINE-unknown-minix ;; aarch64:Linux:*:*) set_cc_for_build CPU=$UNAME_MACHINE LIBCABI=$LIBC if test "$CC_FOR_BUILD" != no_compiler_found; then ABI=64 sed 's/^ //' << EOF > "$dummy.c" #ifdef __ARM_EABI__ #ifdef __ARM_PCS_VFP ABI=eabihf #else ABI=eabi #endif #endif EOF cc_set_abi=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^ABI' | sed 's, ,,g'` eval "$cc_set_abi" case $ABI in eabi | eabihf) CPU=armv8l; LIBCABI=$LIBC$ABI ;; esac fi GUESS=$CPU-unknown-linux-$LIBCABI ;; aarch64_be:Linux:*:*) UNAME_MACHINE=aarch64_be GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; alpha:Linux:*:*) case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' /proc/cpuinfo 2>/dev/null` in EV5) UNAME_MACHINE=alphaev5 ;; EV56) UNAME_MACHINE=alphaev56 ;; PCA56) UNAME_MACHINE=alphapca56 ;; PCA57) UNAME_MACHINE=alphapca56 ;; EV6) UNAME_MACHINE=alphaev6 ;; EV67) UNAME_MACHINE=alphaev67 ;; EV68*) UNAME_MACHINE=alphaev68 ;; esac objdump --private-headers /bin/sh | grep -q ld.so.1 if test "$?" = 0 ; then LIBC=gnulibc1 ; fi GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; arc:Linux:*:* | arceb:Linux:*:* | arc32:Linux:*:* | arc64:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; arm*:Linux:*:*) set_cc_for_build if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_EABI__ then GUESS=$UNAME_MACHINE-unknown-linux-$LIBC else if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_PCS_VFP then GUESS=$UNAME_MACHINE-unknown-linux-${LIBC}eabi else GUESS=$UNAME_MACHINE-unknown-linux-${LIBC}eabihf fi fi ;; avr32*:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; cris:Linux:*:*) GUESS=$UNAME_MACHINE-axis-linux-$LIBC ;; crisv32:Linux:*:*) GUESS=$UNAME_MACHINE-axis-linux-$LIBC ;; e2k:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; frv:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; hexagon:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; i*86:Linux:*:*) GUESS=$UNAME_MACHINE-pc-linux-$LIBC ;; ia64:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; k1om:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; kvx:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; kvx:cos:*:*) GUESS=$UNAME_MACHINE-unknown-cos ;; kvx:mbr:*:*) GUESS=$UNAME_MACHINE-unknown-mbr ;; loongarch32:Linux:*:* | loongarch64:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; m32r*:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; m68*:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; mips:Linux:*:* | mips64:Linux:*:*) set_cc_for_build IS_GLIBC=0 test x"${LIBC}" = xgnu && IS_GLIBC=1 sed 's/^ //' << EOF > "$dummy.c" #undef CPU #undef mips #undef mipsel #undef mips64 #undef mips64el #if ${IS_GLIBC} && defined(_ABI64) LIBCABI=gnuabi64 #else #if ${IS_GLIBC} && defined(_ABIN32) LIBCABI=gnuabin32 #else LIBCABI=${LIBC} #endif #endif #if ${IS_GLIBC} && defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 CPU=mipsisa64r6 #else #if ${IS_GLIBC} && !defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 CPU=mipsisa32r6 #else #if defined(__mips64) CPU=mips64 #else CPU=mips #endif #endif #endif #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) MIPS_ENDIAN=el #else #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) MIPS_ENDIAN= #else MIPS_ENDIAN= #endif #endif EOF cc_set_vars=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU\|^MIPS_ENDIAN\|^LIBCABI'` eval "$cc_set_vars" test "x$CPU" != x && { echo "$CPU${MIPS_ENDIAN}-unknown-linux-$LIBCABI"; exit; } ;; mips64el:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; openrisc*:Linux:*:*) GUESS=or1k-unknown-linux-$LIBC ;; or32:Linux:*:* | or1k*:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; padre:Linux:*:*) GUESS=sparc-unknown-linux-$LIBC ;; parisc64:Linux:*:* | hppa64:Linux:*:*) GUESS=hppa64-unknown-linux-$LIBC ;; parisc:Linux:*:* | hppa:Linux:*:*) # Look for CPU level case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in PA7*) GUESS=hppa1.1-unknown-linux-$LIBC ;; PA8*) GUESS=hppa2.0-unknown-linux-$LIBC ;; *) GUESS=hppa-unknown-linux-$LIBC ;; esac ;; ppc64:Linux:*:*) GUESS=powerpc64-unknown-linux-$LIBC ;; ppc:Linux:*:*) GUESS=powerpc-unknown-linux-$LIBC ;; ppc64le:Linux:*:*) GUESS=powerpc64le-unknown-linux-$LIBC ;; ppcle:Linux:*:*) GUESS=powerpcle-unknown-linux-$LIBC ;; riscv32:Linux:*:* | riscv32be:Linux:*:* | riscv64:Linux:*:* | riscv64be:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; s390:Linux:*:* | s390x:Linux:*:*) GUESS=$UNAME_MACHINE-ibm-linux-$LIBC ;; sh64*:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; sh*:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; sparc:Linux:*:* | sparc64:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; tile*:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; vax:Linux:*:*) GUESS=$UNAME_MACHINE-dec-linux-$LIBC ;; x86_64:Linux:*:*) set_cc_for_build CPU=$UNAME_MACHINE LIBCABI=$LIBC if test "$CC_FOR_BUILD" != no_compiler_found; then ABI=64 sed 's/^ //' << EOF > "$dummy.c" #ifdef __i386__ ABI=x86 #else #ifdef __ILP32__ ABI=x32 #endif #endif EOF cc_set_abi=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^ABI' | sed 's, ,,g'` eval "$cc_set_abi" case $ABI in x86) CPU=i686 ;; x32) LIBCABI=${LIBC}x32 ;; esac fi GUESS=$CPU-pc-linux-$LIBCABI ;; xtensa*:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; i*86:DYNIX/ptx:4*:*) # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. # earlier versions are messed up and put the nodename in both # sysname and nodename. GUESS=i386-sequent-sysv4 ;; i*86:UNIX_SV:4.2MP:2.*) # Unixware is an offshoot of SVR4, but it has its own version # number series starting with 2... # I am not positive that other SVR4 systems won't match this, # I just have to hope. -- rms. # Use sysv4.2uw... so that sysv4* matches it. GUESS=$UNAME_MACHINE-pc-sysv4.2uw$UNAME_VERSION ;; i*86:OS/2:*:*) # If we were able to find 'uname', then EMX Unix compatibility # is probably installed. GUESS=$UNAME_MACHINE-pc-os2-emx ;; i*86:XTS-300:*:STOP) GUESS=$UNAME_MACHINE-unknown-stop ;; i*86:atheos:*:*) GUESS=$UNAME_MACHINE-unknown-atheos ;; i*86:syllable:*:*) GUESS=$UNAME_MACHINE-pc-syllable ;; i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*) GUESS=i386-unknown-lynxos$UNAME_RELEASE ;; i*86:*DOS:*:*) GUESS=$UNAME_MACHINE-pc-msdosdjgpp ;; i*86:*:4.*:*) UNAME_REL=`echo "$UNAME_RELEASE" | sed 's/\/MP$//'` if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then GUESS=$UNAME_MACHINE-univel-sysv$UNAME_REL else GUESS=$UNAME_MACHINE-pc-sysv$UNAME_REL fi ;; i*86:*:5:[678]*) # UnixWare 7.x, OpenUNIX and OpenServer 6. case `/bin/uname -X | grep "^Machine"` in *486*) UNAME_MACHINE=i486 ;; *Pentium) UNAME_MACHINE=i586 ;; *Pent*|*Celeron) UNAME_MACHINE=i686 ;; esac GUESS=$UNAME_MACHINE-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} ;; i*86:*:3.2:*) if test -f /usr/options/cb.name; then UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ && UNAME_MACHINE=i586 (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ && UNAME_MACHINE=i686 (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ && UNAME_MACHINE=i686 GUESS=$UNAME_MACHINE-pc-sco$UNAME_REL else GUESS=$UNAME_MACHINE-pc-sysv32 fi ;; pc:*:*:*) # Left here for compatibility: # uname -m prints for DJGPP always 'pc', but it prints nothing about # the processor, so we play safe by assuming i586. # Note: whatever this is, it MUST be the same as what config.sub # prints for the "djgpp" host, or else GDB configure will decide that # this is a cross-build. GUESS=i586-pc-msdosdjgpp ;; Intel:Mach:3*:*) GUESS=i386-pc-mach3 ;; paragon:*:*:*) GUESS=i860-intel-osf1 ;; i860:*:4.*:*) # i860-SVR4 if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then GUESS=i860-stardent-sysv$UNAME_RELEASE # Stardent Vistra i860-SVR4 else # Add other i860-SVR4 vendors below as they are discovered. GUESS=i860-unknown-sysv$UNAME_RELEASE # Unknown i860-SVR4 fi ;; mini*:CTIX:SYS*5:*) # "miniframe" GUESS=m68010-convergent-sysv ;; mc68k:UNIX:SYSTEM5:3.51m) GUESS=m68k-convergent-sysv ;; M680?0:D-NIX:5.3:*) GUESS=m68k-diab-dnix ;; M68*:*:R3V[5678]*:*) test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) OS_REL='' test -r /etc/.relid \ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4.3"$OS_REL"; exit; } /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;; 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4; exit; } ;; NCR*:*:4.2:* | MPRAS*:*:4.2:*) OS_REL='.3' test -r /etc/.relid \ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4.3"$OS_REL"; exit; } /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \ && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;; m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) GUESS=m68k-unknown-lynxos$UNAME_RELEASE ;; mc68030:UNIX_System_V:4.*:*) GUESS=m68k-atari-sysv4 ;; TSUNAMI:LynxOS:2.*:*) GUESS=sparc-unknown-lynxos$UNAME_RELEASE ;; rs6000:LynxOS:2.*:*) GUESS=rs6000-unknown-lynxos$UNAME_RELEASE ;; PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*) GUESS=powerpc-unknown-lynxos$UNAME_RELEASE ;; SM[BE]S:UNIX_SV:*:*) GUESS=mips-dde-sysv$UNAME_RELEASE ;; RM*:ReliantUNIX-*:*:*) GUESS=mips-sni-sysv4 ;; RM*:SINIX-*:*:*) GUESS=mips-sni-sysv4 ;; *:SINIX-*:*:*) if uname -p 2>/dev/null >/dev/null ; then UNAME_MACHINE=`(uname -p) 2>/dev/null` GUESS=$UNAME_MACHINE-sni-sysv4 else GUESS=ns32k-sni-sysv fi ;; PENTIUM:*:4.0*:*) # Unisys 'ClearPath HMP IX 4000' SVR4/MP effort # says GUESS=i586-unisys-sysv4 ;; *:UNIX_System_V:4*:FTX*) # From Gerald Hewes . # How about differentiating between stratus architectures? -djm GUESS=hppa1.1-stratus-sysv4 ;; *:*:*:FTX*) # From seanf@swdc.stratus.com. GUESS=i860-stratus-sysv4 ;; i*86:VOS:*:*) # From Paul.Green@stratus.com. GUESS=$UNAME_MACHINE-stratus-vos ;; *:VOS:*:*) # From Paul.Green@stratus.com. GUESS=hppa1.1-stratus-vos ;; mc68*:A/UX:*:*) GUESS=m68k-apple-aux$UNAME_RELEASE ;; news*:NEWS-OS:6*:*) GUESS=mips-sony-newsos6 ;; R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) if test -d /usr/nec; then GUESS=mips-nec-sysv$UNAME_RELEASE else GUESS=mips-unknown-sysv$UNAME_RELEASE fi ;; BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. GUESS=powerpc-be-beos ;; BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. GUESS=powerpc-apple-beos ;; BePC:BeOS:*:*) # BeOS running on Intel PC compatible. GUESS=i586-pc-beos ;; BePC:Haiku:*:*) # Haiku running on Intel PC compatible. GUESS=i586-pc-haiku ;; ppc:Haiku:*:*) # Haiku running on Apple PowerPC GUESS=powerpc-apple-haiku ;; *:Haiku:*:*) # Haiku modern gcc (not bound by BeOS compat) GUESS=$UNAME_MACHINE-unknown-haiku ;; SX-4:SUPER-UX:*:*) GUESS=sx4-nec-superux$UNAME_RELEASE ;; SX-5:SUPER-UX:*:*) GUESS=sx5-nec-superux$UNAME_RELEASE ;; SX-6:SUPER-UX:*:*) GUESS=sx6-nec-superux$UNAME_RELEASE ;; SX-7:SUPER-UX:*:*) GUESS=sx7-nec-superux$UNAME_RELEASE ;; SX-8:SUPER-UX:*:*) GUESS=sx8-nec-superux$UNAME_RELEASE ;; SX-8R:SUPER-UX:*:*) GUESS=sx8r-nec-superux$UNAME_RELEASE ;; SX-ACE:SUPER-UX:*:*) GUESS=sxace-nec-superux$UNAME_RELEASE ;; Power*:Rhapsody:*:*) GUESS=powerpc-apple-rhapsody$UNAME_RELEASE ;; *:Rhapsody:*:*) GUESS=$UNAME_MACHINE-apple-rhapsody$UNAME_RELEASE ;; arm64:Darwin:*:*) GUESS=aarch64-apple-darwin$UNAME_RELEASE ;; *:Darwin:*:*) UNAME_PROCESSOR=`uname -p` case $UNAME_PROCESSOR in unknown) UNAME_PROCESSOR=powerpc ;; esac if command -v xcode-select > /dev/null 2> /dev/null && \ ! xcode-select --print-path > /dev/null 2> /dev/null ; then # Avoid executing cc if there is no toolchain installed as # cc will be a stub that puts up a graphical alert # prompting the user to install developer tools. CC_FOR_BUILD=no_compiler_found else set_cc_for_build fi if test "$CC_FOR_BUILD" != no_compiler_found; then if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ grep IS_64BIT_ARCH >/dev/null then case $UNAME_PROCESSOR in i386) UNAME_PROCESSOR=x86_64 ;; powerpc) UNAME_PROCESSOR=powerpc64 ;; esac fi # On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \ (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ grep IS_PPC >/dev/null then UNAME_PROCESSOR=powerpc fi elif test "$UNAME_PROCESSOR" = i386 ; then # uname -m returns i386 or x86_64 UNAME_PROCESSOR=$UNAME_MACHINE fi GUESS=$UNAME_PROCESSOR-apple-darwin$UNAME_RELEASE ;; *:procnto*:*:* | *:QNX:[0123456789]*:*) UNAME_PROCESSOR=`uname -p` if test "$UNAME_PROCESSOR" = x86; then UNAME_PROCESSOR=i386 UNAME_MACHINE=pc fi GUESS=$UNAME_PROCESSOR-$UNAME_MACHINE-nto-qnx$UNAME_RELEASE ;; *:QNX:*:4*) GUESS=i386-pc-qnx ;; NEO-*:NONSTOP_KERNEL:*:*) GUESS=neo-tandem-nsk$UNAME_RELEASE ;; NSE-*:NONSTOP_KERNEL:*:*) GUESS=nse-tandem-nsk$UNAME_RELEASE ;; NSR-*:NONSTOP_KERNEL:*:*) GUESS=nsr-tandem-nsk$UNAME_RELEASE ;; NSV-*:NONSTOP_KERNEL:*:*) GUESS=nsv-tandem-nsk$UNAME_RELEASE ;; NSX-*:NONSTOP_KERNEL:*:*) GUESS=nsx-tandem-nsk$UNAME_RELEASE ;; *:NonStop-UX:*:*) GUESS=mips-compaq-nonstopux ;; BS2000:POSIX*:*:*) GUESS=bs2000-siemens-sysv ;; DS/*:UNIX_System_V:*:*) GUESS=$UNAME_MACHINE-$UNAME_SYSTEM-$UNAME_RELEASE ;; *:Plan9:*:*) # "uname -m" is not consistent, so use $cputype instead. 386 # is converted to i386 for consistency with other x86 # operating systems. if test "${cputype-}" = 386; then UNAME_MACHINE=i386 elif test "x${cputype-}" != x; then UNAME_MACHINE=$cputype fi GUESS=$UNAME_MACHINE-unknown-plan9 ;; *:TOPS-10:*:*) GUESS=pdp10-unknown-tops10 ;; *:TENEX:*:*) GUESS=pdp10-unknown-tenex ;; KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) GUESS=pdp10-dec-tops20 ;; XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) GUESS=pdp10-xkl-tops20 ;; *:TOPS-20:*:*) GUESS=pdp10-unknown-tops20 ;; *:ITS:*:*) GUESS=pdp10-unknown-its ;; SEI:*:*:SEIUX) GUESS=mips-sei-seiux$UNAME_RELEASE ;; *:DragonFly:*:*) DRAGONFLY_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` GUESS=$UNAME_MACHINE-unknown-dragonfly$DRAGONFLY_REL ;; *:*VMS:*:*) UNAME_MACHINE=`(uname -p) 2>/dev/null` case $UNAME_MACHINE in A*) GUESS=alpha-dec-vms ;; I*) GUESS=ia64-dec-vms ;; V*) GUESS=vax-dec-vms ;; esac ;; *:XENIX:*:SysV) GUESS=i386-pc-xenix ;; i*86:skyos:*:*) SKYOS_REL=`echo "$UNAME_RELEASE" | sed -e 's/ .*$//'` GUESS=$UNAME_MACHINE-pc-skyos$SKYOS_REL ;; i*86:rdos:*:*) GUESS=$UNAME_MACHINE-pc-rdos ;; i*86:Fiwix:*:*) GUESS=$UNAME_MACHINE-pc-fiwix ;; *:AROS:*:*) GUESS=$UNAME_MACHINE-unknown-aros ;; x86_64:VMkernel:*:*) GUESS=$UNAME_MACHINE-unknown-esx ;; amd64:Isilon\ OneFS:*:*) GUESS=x86_64-unknown-onefs ;; *:Unleashed:*:*) GUESS=$UNAME_MACHINE-unknown-unleashed$UNAME_RELEASE ;; esac # Do we have a guess based on uname results? if test "x$GUESS" != x; then echo "$GUESS" exit fi # No uname command or uname output not recognized. set_cc_for_build cat > "$dummy.c" < #include #endif #if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) #if defined (vax) || defined (__vax) || defined (__vax__) || defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) #include #if defined(_SIZE_T_) || defined(SIGLOST) #include #endif #endif #endif main () { #if defined (sony) #if defined (MIPSEB) /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, I don't know.... */ printf ("mips-sony-bsd\n"); exit (0); #else #include printf ("m68k-sony-newsos%s\n", #ifdef NEWSOS4 "4" #else "" #endif ); exit (0); #endif #endif #if defined (NeXT) #if !defined (__ARCHITECTURE__) #define __ARCHITECTURE__ "m68k" #endif int version; version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; if (version < 4) printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); else printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); exit (0); #endif #if defined (MULTIMAX) || defined (n16) #if defined (UMAXV) printf ("ns32k-encore-sysv\n"); exit (0); #else #if defined (CMU) printf ("ns32k-encore-mach\n"); exit (0); #else printf ("ns32k-encore-bsd\n"); exit (0); #endif #endif #endif #if defined (__386BSD__) printf ("i386-pc-bsd\n"); exit (0); #endif #if defined (sequent) #if defined (i386) printf ("i386-sequent-dynix\n"); exit (0); #endif #if defined (ns32000) printf ("ns32k-sequent-dynix\n"); exit (0); #endif #endif #if defined (_SEQUENT_) struct utsname un; uname(&un); if (strncmp(un.version, "V2", 2) == 0) { printf ("i386-sequent-ptx2\n"); exit (0); } if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ printf ("i386-sequent-ptx1\n"); exit (0); } printf ("i386-sequent-ptx\n"); exit (0); #endif #if defined (vax) #if !defined (ultrix) #include #if defined (BSD) #if BSD == 43 printf ("vax-dec-bsd4.3\n"); exit (0); #else #if BSD == 199006 printf ("vax-dec-bsd4.3reno\n"); exit (0); #else printf ("vax-dec-bsd\n"); exit (0); #endif #endif #else printf ("vax-dec-bsd\n"); exit (0); #endif #else #if defined(_SIZE_T_) || defined(SIGLOST) struct utsname un; uname (&un); printf ("vax-dec-ultrix%s\n", un.release); exit (0); #else printf ("vax-dec-ultrix\n"); exit (0); #endif #endif #endif #if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) #if defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) #if defined(_SIZE_T_) || defined(SIGLOST) struct utsname *un; uname (&un); printf ("mips-dec-ultrix%s\n", un.release); exit (0); #else printf ("mips-dec-ultrix\n"); exit (0); #endif #endif #endif #if defined (alliant) && defined (i860) printf ("i860-alliant-bsd\n"); exit (0); #endif exit (1); } EOF $CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null && SYSTEM_NAME=`"$dummy"` && { echo "$SYSTEM_NAME"; exit; } # Apollos put the system type in the environment. test -d /usr/apollo && { echo "$ISP-apollo-$SYSTYPE"; exit; } echo "$0: unable to guess system type" >&2 case $UNAME_MACHINE:$UNAME_SYSTEM in mips:Linux | mips64:Linux) # If we got here on MIPS GNU/Linux, output extra information. cat >&2 <&2 <&2 </dev/null || echo unknown` uname -r = `(uname -r) 2>/dev/null || echo unknown` uname -s = `(uname -s) 2>/dev/null || echo unknown` uname -v = `(uname -v) 2>/dev/null || echo unknown` /usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` /bin/uname -X = `(/bin/uname -X) 2>/dev/null` hostinfo = `(hostinfo) 2>/dev/null` /bin/universe = `(/bin/universe) 2>/dev/null` /usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` /bin/arch = `(/bin/arch) 2>/dev/null` /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` UNAME_MACHINE = "$UNAME_MACHINE" UNAME_RELEASE = "$UNAME_RELEASE" UNAME_SYSTEM = "$UNAME_SYSTEM" UNAME_VERSION = "$UNAME_VERSION" EOF fi exit 1 # Local variables: # eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" # End: objfw-1.1.6/build-aux/config.sub000066400000000000000000001072021465614216400165130ustar00rootroot00000000000000#! /bin/sh # Configuration validation subroutine script. # Copyright 1992-2023 Free Software Foundation, Inc. # shellcheck disable=SC2006,SC2268 # see below for rationale timestamp='2023-09-19' # This file 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 . # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that # program. This Exception is an additional permission under section 7 # of the GNU General Public License, version 3 ("GPLv3"). # Please send patches to . # # Configuration subroutine to validate and canonicalize a configuration type. # Supply the specified configuration type as an argument. # If it is invalid, we print an error message on stderr and exit with code 1. # Otherwise, we print the canonical config type on stdout and succeed. # You can get the latest version of this script from: # https://git.savannah.gnu.org/cgit/config.git/plain/config.sub # This file is supposed to be the same for all GNU packages # and recognize all the CPU types, system types and aliases # that are meaningful with *any* GNU software. # Each package is responsible for reporting which valid configurations # it does not support. The user should be able to distinguish # a failure to support a valid configuration from a meaningless # configuration. # The goal of this file is to map all the various variations of a given # machine specification into a single specification in the form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM # or in some cases, the newer four-part form: # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM # It is wrong to echo any other type of specification. # The "shellcheck disable" line above the timestamp inhibits complaints # about features and limitations of the classic Bourne shell that were # superseded or lifted in POSIX. However, this script identifies a wide # variety of pre-POSIX systems that do not have POSIX shells at all, and # even some reasonably current systems (Solaris 10 as case-in-point) still # have a pre-POSIX /bin/sh. me=`echo "$0" | sed -e 's,.*/,,'` usage="\ Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS Canonicalize a configuration name. Options: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit Report bugs and patches to ." version="\ GNU config.sub ($timestamp) Copyright 1992-2023 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." help=" Try '$me --help' for more information." # Parse command line while test $# -gt 0 ; do case $1 in --time-stamp | --time* | -t ) echo "$timestamp" ; exit ;; --version | -v ) echo "$version" ; exit ;; --help | --h* | -h ) echo "$usage"; exit ;; -- ) # Stop option processing shift; break ;; - ) # Use stdin as input. break ;; -* ) echo "$me: invalid option $1$help" >&2 exit 1 ;; *local*) # First pass through any local machine types. echo "$1" exit ;; * ) break ;; esac done case $# in 0) echo "$me: missing argument$help" >&2 exit 1;; 1) ;; *) echo "$me: too many arguments$help" >&2 exit 1;; esac # Split fields of configuration type # shellcheck disable=SC2162 saved_IFS=$IFS IFS="-" read field1 field2 field3 field4 <&2 exit 1 ;; *-*-*-*) basic_machine=$field1-$field2 basic_os=$field3-$field4 ;; *-*-*) # Ambiguous whether COMPANY is present, or skipped and KERNEL-OS is two # parts maybe_os=$field2-$field3 case $maybe_os in nto-qnx* | linux-* | uclinux-uclibc* \ | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* \ | netbsd*-eabi* | kopensolaris*-gnu* | cloudabi*-eabi* \ | storm-chaos* | os2-emx* | rtmk-nova* | managarm-* \ | windows-* ) basic_machine=$field1 basic_os=$maybe_os ;; android-linux) basic_machine=$field1-unknown basic_os=linux-android ;; *) basic_machine=$field1-$field2 basic_os=$field3 ;; esac ;; *-*) # A lone config we happen to match not fitting any pattern case $field1-$field2 in decstation-3100) basic_machine=mips-dec basic_os= ;; *-*) # Second component is usually, but not always the OS case $field2 in # Prevent following clause from handling this valid os sun*os*) basic_machine=$field1 basic_os=$field2 ;; zephyr*) basic_machine=$field1-unknown basic_os=$field2 ;; # Manufacturers dec* | mips* | sequent* | encore* | pc533* | sgi* | sony* \ | att* | 7300* | 3300* | delta* | motorola* | sun[234]* \ | unicom* | ibm* | next | hp | isi* | apollo | altos* \ | convergent* | ncr* | news | 32* | 3600* | 3100* \ | hitachi* | c[123]* | convex* | sun | crds | omron* | dg \ | ultra | tti* | harris | dolphin | highlevel | gould \ | cbm | ns | masscomp | apple | axis | knuth | cray \ | microblaze* | sim | cisco \ | oki | wec | wrs | winbond) basic_machine=$field1-$field2 basic_os= ;; *) basic_machine=$field1 basic_os=$field2 ;; esac ;; esac ;; *) # Convert single-component short-hands not valid as part of # multi-component configurations. case $field1 in 386bsd) basic_machine=i386-pc basic_os=bsd ;; a29khif) basic_machine=a29k-amd basic_os=udi ;; adobe68k) basic_machine=m68010-adobe basic_os=scout ;; alliant) basic_machine=fx80-alliant basic_os= ;; altos | altos3068) basic_machine=m68k-altos basic_os= ;; am29k) basic_machine=a29k-none basic_os=bsd ;; amdahl) basic_machine=580-amdahl basic_os=sysv ;; amiga) basic_machine=m68k-unknown basic_os= ;; amigaos | amigados) basic_machine=m68k-unknown basic_os=amigaos ;; amigaunix | amix) basic_machine=m68k-unknown basic_os=sysv4 ;; apollo68) basic_machine=m68k-apollo basic_os=sysv ;; apollo68bsd) basic_machine=m68k-apollo basic_os=bsd ;; aros) basic_machine=i386-pc basic_os=aros ;; aux) basic_machine=m68k-apple basic_os=aux ;; balance) basic_machine=ns32k-sequent basic_os=dynix ;; blackfin) basic_machine=bfin-unknown basic_os=linux ;; cegcc) basic_machine=arm-unknown basic_os=cegcc ;; convex-c1) basic_machine=c1-convex basic_os=bsd ;; convex-c2) basic_machine=c2-convex basic_os=bsd ;; convex-c32) basic_machine=c32-convex basic_os=bsd ;; convex-c34) basic_machine=c34-convex basic_os=bsd ;; convex-c38) basic_machine=c38-convex basic_os=bsd ;; cray) basic_machine=j90-cray basic_os=unicos ;; crds | unos) basic_machine=m68k-crds basic_os= ;; da30) basic_machine=m68k-da30 basic_os= ;; decstation | pmax | pmin | dec3100 | decstatn) basic_machine=mips-dec basic_os= ;; delta88) basic_machine=m88k-motorola basic_os=sysv3 ;; dicos) basic_machine=i686-pc basic_os=dicos ;; djgpp) basic_machine=i586-pc basic_os=msdosdjgpp ;; ebmon29k) basic_machine=a29k-amd basic_os=ebmon ;; es1800 | OSE68k | ose68k | ose | OSE) basic_machine=m68k-ericsson basic_os=ose ;; gmicro) basic_machine=tron-gmicro basic_os=sysv ;; go32) basic_machine=i386-pc basic_os=go32 ;; h8300hms) basic_machine=h8300-hitachi basic_os=hms ;; h8300xray) basic_machine=h8300-hitachi basic_os=xray ;; h8500hms) basic_machine=h8500-hitachi basic_os=hms ;; harris) basic_machine=m88k-harris basic_os=sysv3 ;; hp300 | hp300hpux) basic_machine=m68k-hp basic_os=hpux ;; hp300bsd) basic_machine=m68k-hp basic_os=bsd ;; hppaosf) basic_machine=hppa1.1-hp basic_os=osf ;; hppro) basic_machine=hppa1.1-hp basic_os=proelf ;; i386mach) basic_machine=i386-mach basic_os=mach ;; isi68 | isi) basic_machine=m68k-isi basic_os=sysv ;; m68knommu) basic_machine=m68k-unknown basic_os=linux ;; magnum | m3230) basic_machine=mips-mips basic_os=sysv ;; merlin) basic_machine=ns32k-utek basic_os=sysv ;; mingw64) basic_machine=x86_64-pc basic_os=mingw64 ;; mingw32) basic_machine=i686-pc basic_os=mingw32 ;; mingw32ce) basic_machine=arm-unknown basic_os=mingw32ce ;; monitor) basic_machine=m68k-rom68k basic_os=coff ;; morphos) basic_machine=powerpc-unknown basic_os=morphos ;; moxiebox) basic_machine=moxie-unknown basic_os=moxiebox ;; msdos) basic_machine=i386-pc basic_os=msdos ;; msys) basic_machine=i686-pc basic_os=msys ;; mvs) basic_machine=i370-ibm basic_os=mvs ;; nacl) basic_machine=le32-unknown basic_os=nacl ;; ncr3000) basic_machine=i486-ncr basic_os=sysv4 ;; netbsd386) basic_machine=i386-pc basic_os=netbsd ;; netwinder) basic_machine=armv4l-rebel basic_os=linux ;; news | news700 | news800 | news900) basic_machine=m68k-sony basic_os=newsos ;; news1000) basic_machine=m68030-sony basic_os=newsos ;; necv70) basic_machine=v70-nec basic_os=sysv ;; nh3000) basic_machine=m68k-harris basic_os=cxux ;; nh[45]000) basic_machine=m88k-harris basic_os=cxux ;; nindy960) basic_machine=i960-intel basic_os=nindy ;; mon960) basic_machine=i960-intel basic_os=mon960 ;; nonstopux) basic_machine=mips-compaq basic_os=nonstopux ;; os400) basic_machine=powerpc-ibm basic_os=os400 ;; OSE68000 | ose68000) basic_machine=m68000-ericsson basic_os=ose ;; os68k) basic_machine=m68k-none basic_os=os68k ;; paragon) basic_machine=i860-intel basic_os=osf ;; parisc) basic_machine=hppa-unknown basic_os=linux ;; psp) basic_machine=mipsallegrexel-sony basic_os=psp ;; pw32) basic_machine=i586-unknown basic_os=pw32 ;; rdos | rdos64) basic_machine=x86_64-pc basic_os=rdos ;; rdos32) basic_machine=i386-pc basic_os=rdos ;; rom68k) basic_machine=m68k-rom68k basic_os=coff ;; sa29200) basic_machine=a29k-amd basic_os=udi ;; sei) basic_machine=mips-sei basic_os=seiux ;; sequent) basic_machine=i386-sequent basic_os= ;; sps7) basic_machine=m68k-bull basic_os=sysv2 ;; st2000) basic_machine=m68k-tandem basic_os= ;; stratus) basic_machine=i860-stratus basic_os=sysv4 ;; sun2) basic_machine=m68000-sun basic_os= ;; sun2os3) basic_machine=m68000-sun basic_os=sunos3 ;; sun2os4) basic_machine=m68000-sun basic_os=sunos4 ;; sun3) basic_machine=m68k-sun basic_os= ;; sun3os3) basic_machine=m68k-sun basic_os=sunos3 ;; sun3os4) basic_machine=m68k-sun basic_os=sunos4 ;; sun4) basic_machine=sparc-sun basic_os= ;; sun4os3) basic_machine=sparc-sun basic_os=sunos3 ;; sun4os4) basic_machine=sparc-sun basic_os=sunos4 ;; sun4sol2) basic_machine=sparc-sun basic_os=solaris2 ;; sun386 | sun386i | roadrunner) basic_machine=i386-sun basic_os= ;; sv1) basic_machine=sv1-cray basic_os=unicos ;; symmetry) basic_machine=i386-sequent basic_os=dynix ;; t3e) basic_machine=alphaev5-cray basic_os=unicos ;; t90) basic_machine=t90-cray basic_os=unicos ;; toad1) basic_machine=pdp10-xkl basic_os=tops20 ;; tpf) basic_machine=s390x-ibm basic_os=tpf ;; udi29k) basic_machine=a29k-amd basic_os=udi ;; ultra3) basic_machine=a29k-nyu basic_os=sym1 ;; v810 | necv810) basic_machine=v810-nec basic_os=none ;; vaxv) basic_machine=vax-dec basic_os=sysv ;; vms) basic_machine=vax-dec basic_os=vms ;; vsta) basic_machine=i386-pc basic_os=vsta ;; vxworks960) basic_machine=i960-wrs basic_os=vxworks ;; vxworks68) basic_machine=m68k-wrs basic_os=vxworks ;; vxworks29k) basic_machine=a29k-wrs basic_os=vxworks ;; xbox) basic_machine=i686-pc basic_os=mingw32 ;; ymp) basic_machine=ymp-cray basic_os=unicos ;; *) basic_machine=$1 basic_os= ;; esac ;; esac # Decode 1-component or ad-hoc basic machines case $basic_machine in # Here we handle the default manufacturer of certain CPU types. It is in # some cases the only manufacturer, in others, it is the most popular. w89k) cpu=hppa1.1 vendor=winbond ;; op50n) cpu=hppa1.1 vendor=oki ;; op60c) cpu=hppa1.1 vendor=oki ;; ibm*) cpu=i370 vendor=ibm ;; orion105) cpu=clipper vendor=highlevel ;; mac | mpw | mac-mpw) cpu=m68k vendor=apple ;; pmac | pmac-mpw) cpu=powerpc vendor=apple ;; # Recognize the various machine names and aliases which stand # for a CPU type and a company and sometimes even an OS. 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) cpu=m68000 vendor=att ;; 3b*) cpu=we32k vendor=att ;; bluegene*) cpu=powerpc vendor=ibm basic_os=cnk ;; decsystem10* | dec10*) cpu=pdp10 vendor=dec basic_os=tops10 ;; decsystem20* | dec20*) cpu=pdp10 vendor=dec basic_os=tops20 ;; delta | 3300 | motorola-3300 | motorola-delta \ | 3300-motorola | delta-motorola) cpu=m68k vendor=motorola ;; dpx2*) cpu=m68k vendor=bull basic_os=sysv3 ;; encore | umax | mmax) cpu=ns32k vendor=encore ;; elxsi) cpu=elxsi vendor=elxsi basic_os=${basic_os:-bsd} ;; fx2800) cpu=i860 vendor=alliant ;; genix) cpu=ns32k vendor=ns ;; h3050r* | hiux*) cpu=hppa1.1 vendor=hitachi basic_os=hiuxwe2 ;; hp3k9[0-9][0-9] | hp9[0-9][0-9]) cpu=hppa1.0 vendor=hp ;; hp9k2[0-9][0-9] | hp9k31[0-9]) cpu=m68000 vendor=hp ;; hp9k3[2-9][0-9]) cpu=m68k vendor=hp ;; hp9k6[0-9][0-9] | hp6[0-9][0-9]) cpu=hppa1.0 vendor=hp ;; hp9k7[0-79][0-9] | hp7[0-79][0-9]) cpu=hppa1.1 vendor=hp ;; hp9k78[0-9] | hp78[0-9]) # FIXME: really hppa2.0-hp cpu=hppa1.1 vendor=hp ;; hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) # FIXME: really hppa2.0-hp cpu=hppa1.1 vendor=hp ;; hp9k8[0-9][13679] | hp8[0-9][13679]) cpu=hppa1.1 vendor=hp ;; hp9k8[0-9][0-9] | hp8[0-9][0-9]) cpu=hppa1.0 vendor=hp ;; i*86v32) cpu=`echo "$1" | sed -e 's/86.*/86/'` vendor=pc basic_os=sysv32 ;; i*86v4*) cpu=`echo "$1" | sed -e 's/86.*/86/'` vendor=pc basic_os=sysv4 ;; i*86v) cpu=`echo "$1" | sed -e 's/86.*/86/'` vendor=pc basic_os=sysv ;; i*86sol2) cpu=`echo "$1" | sed -e 's/86.*/86/'` vendor=pc basic_os=solaris2 ;; j90 | j90-cray) cpu=j90 vendor=cray basic_os=${basic_os:-unicos} ;; iris | iris4d) cpu=mips vendor=sgi case $basic_os in irix*) ;; *) basic_os=irix4 ;; esac ;; miniframe) cpu=m68000 vendor=convergent ;; *mint | mint[0-9]* | *MiNT | *MiNT[0-9]*) cpu=m68k vendor=atari basic_os=mint ;; news-3600 | risc-news) cpu=mips vendor=sony basic_os=newsos ;; next | m*-next) cpu=m68k vendor=next case $basic_os in openstep*) ;; nextstep*) ;; ns2*) basic_os=nextstep2 ;; *) basic_os=nextstep3 ;; esac ;; np1) cpu=np1 vendor=gould ;; op50n-* | op60c-*) cpu=hppa1.1 vendor=oki basic_os=proelf ;; pa-hitachi) cpu=hppa1.1 vendor=hitachi basic_os=hiuxwe2 ;; pbd) cpu=sparc vendor=tti ;; pbb) cpu=m68k vendor=tti ;; pc532) cpu=ns32k vendor=pc532 ;; pn) cpu=pn vendor=gould ;; power) cpu=power vendor=ibm ;; ps2) cpu=i386 vendor=ibm ;; rm[46]00) cpu=mips vendor=siemens ;; rtpc | rtpc-*) cpu=romp vendor=ibm ;; sde) cpu=mipsisa32 vendor=sde basic_os=${basic_os:-elf} ;; simso-wrs) cpu=sparclite vendor=wrs basic_os=vxworks ;; tower | tower-32) cpu=m68k vendor=ncr ;; vpp*|vx|vx-*) cpu=f301 vendor=fujitsu ;; w65) cpu=w65 vendor=wdc ;; w89k-*) cpu=hppa1.1 vendor=winbond basic_os=proelf ;; none) cpu=none vendor=none ;; leon|leon[3-9]) cpu=sparc vendor=$basic_machine ;; leon-*|leon[3-9]-*) cpu=sparc vendor=`echo "$basic_machine" | sed 's/-.*//'` ;; *-*) # shellcheck disable=SC2162 saved_IFS=$IFS IFS="-" read cpu vendor <&2 exit 1 ;; esac ;; esac # Here we canonicalize certain aliases for manufacturers. case $vendor in digital*) vendor=dec ;; commodore*) vendor=cbm ;; *) ;; esac # Decode manufacturer-specific aliases for certain operating systems. if test x"$basic_os" != x then # First recognize some ad-hoc cases, or perhaps split kernel-os, or else just # set os. obj= case $basic_os in gnu/linux*) kernel=linux os=`echo "$basic_os" | sed -e 's|gnu/linux|gnu|'` ;; os2-emx) kernel=os2 os=`echo "$basic_os" | sed -e 's|os2-emx|emx|'` ;; nto-qnx*) kernel=nto os=`echo "$basic_os" | sed -e 's|nto-qnx|qnx|'` ;; *-*) # shellcheck disable=SC2162 saved_IFS=$IFS IFS="-" read kernel os <&2 fi ;; *) echo "Invalid configuration '$1': OS '$os' not recognized" 1>&2 exit 1 ;; esac case $obj in aout* | coff* | elf* | pe*) ;; '') # empty is fine ;; *) echo "Invalid configuration '$1': Machine code format '$obj' not recognized" 1>&2 exit 1 ;; esac # Here we handle the constraint that a (synthetic) cpu and os are # valid only in combination with each other and nowhere else. case $cpu-$os in # The "javascript-unknown-ghcjs" triple is used by GHC; we # accept it here in order to tolerate that, but reject any # variations. javascript-ghcjs) ;; javascript-* | *-ghcjs) echo "Invalid configuration '$1': cpu '$cpu' is not valid with os '$os$obj'" 1>&2 exit 1 ;; esac # As a final step for OS-related things, validate the OS-kernel combination # (given a valid OS), if there is a kernel. case $kernel-$os-$obj in linux-gnu*- | linux-dietlibc*- | linux-android*- | linux-newlib*- \ | linux-musl*- | linux-relibc*- | linux-uclibc*- | linux-mlibc*- ) ;; uclinux-uclibc*- ) ;; managarm-mlibc*- | managarm-kernel*- ) ;; windows*-msvc*-) ;; -dietlibc*- | -newlib*- | -musl*- | -relibc*- | -uclibc*- | -mlibc*- ) # These are just libc implementations, not actual OSes, and thus # require a kernel. echo "Invalid configuration '$1': libc '$os' needs explicit kernel." 1>&2 exit 1 ;; -kernel*- ) echo "Invalid configuration '$1': '$os' needs explicit kernel." 1>&2 exit 1 ;; *-kernel*- ) echo "Invalid configuration '$1': '$kernel' does not support '$os'." 1>&2 exit 1 ;; *-msvc*- ) echo "Invalid configuration '$1': '$os' needs 'windows'." 1>&2 exit 1 ;; kfreebsd*-gnu*- | kopensolaris*-gnu*-) ;; vxworks-simlinux- | vxworks-simwindows- | vxworks-spe-) ;; nto-qnx*-) ;; os2-emx-) ;; *-eabi*- | *-gnueabi*-) ;; none--*) # None (no kernel, i.e. freestanding / bare metal), # can be paired with an machine code file format ;; -*-) # Blank kernel with real OS is always fine. ;; --*) # Blank kernel and OS with real machine code file format is always fine. ;; *-*-*) echo "Invalid configuration '$1': Kernel '$kernel' not known to work with OS '$os'." 1>&2 exit 1 ;; esac # Here we handle the case where we know the os, and the CPU type, but not the # manufacturer. We pick the logical manufacturer. case $vendor in unknown) case $cpu-$os in *-riscix*) vendor=acorn ;; *-sunos*) vendor=sun ;; *-cnk* | *-aix*) vendor=ibm ;; *-beos*) vendor=be ;; *-hpux*) vendor=hp ;; *-mpeix*) vendor=hp ;; *-hiux*) vendor=hitachi ;; *-unos*) vendor=crds ;; *-dgux*) vendor=dg ;; *-luna*) vendor=omron ;; *-genix*) vendor=ns ;; *-clix*) vendor=intergraph ;; *-mvs* | *-opened*) vendor=ibm ;; *-os400*) vendor=ibm ;; s390-* | s390x-*) vendor=ibm ;; *-ptx*) vendor=sequent ;; *-tpf*) vendor=ibm ;; *-vxsim* | *-vxworks* | *-windiss*) vendor=wrs ;; *-aux*) vendor=apple ;; *-hms*) vendor=hitachi ;; *-mpw* | *-macos*) vendor=apple ;; *-*mint | *-mint[0-9]* | *-*MiNT | *-MiNT[0-9]*) vendor=atari ;; *-vos*) vendor=stratus ;; esac ;; esac echo "$cpu-$vendor${kernel:+-$kernel}${os:+-$os}${obj:+-$obj}" exit # Local variables: # eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" # End: objfw-1.1.6/build-aux/install-sh000077500000000000000000000361011465614216400165360ustar00rootroot00000000000000#!/bin/sh # install - install a program, script, or datafile scriptversion=2023-11-23.18; # UTC # This originates from X11R5 (mit/util/scripts/install.sh), which was # later released in X11R6 (xc/config/util/install.sh) with the # following copyright and license. # # Copyright (C) 1994 X Consortium # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to # deal in the Software without restriction, including without limitation the # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or # sell copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # # Except as contained in this notice, the name of the X Consortium shall not # be used in advertising or otherwise to promote the sale, use or other deal- # ings in this Software without prior written authorization from the X Consor- # tium. # # # FSF changes to this file are in the public domain. # # Calling this script install-sh is preferred over install.sh, to prevent # 'make' implicit rules from creating a file called install from it # when there is no Makefile. # # This script is compatible with the BSD install script, but was written # from scratch. tab=' ' nl=' ' IFS=" $tab$nl" # Set DOITPROG to "echo" to test this script. doit=${DOITPROG-} doit_exec=${doit:-exec} # Put in absolute file names if you don't have them in your path; # or use environment vars. chgrpprog=${CHGRPPROG-chgrp} chmodprog=${CHMODPROG-chmod} chownprog=${CHOWNPROG-chown} cmpprog=${CMPPROG-cmp} cpprog=${CPPROG-cp} mkdirprog=${MKDIRPROG-mkdir} mvprog=${MVPROG-mv} rmprog=${RMPROG-rm} stripprog=${STRIPPROG-strip} posix_mkdir= # Desired mode of installed file. mode=0755 # Create dirs (including intermediate dirs) using mode 755. # This is like GNU 'install' as of coreutils 8.32 (2020). mkdir_umask=22 backupsuffix= chgrpcmd= chmodcmd=$chmodprog chowncmd= mvcmd=$mvprog rmcmd="$rmprog -f" stripcmd= src= dst= dir_arg= dst_arg= copy_on_change=false is_target_a_directory=possibly usage="\ Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE or: $0 [OPTION]... SRCFILES... DIRECTORY or: $0 [OPTION]... -t DIRECTORY SRCFILES... or: $0 [OPTION]... -d DIRECTORIES... In the 1st form, copy SRCFILE to DSTFILE. In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. In the 4th, create DIRECTORIES. Options: --help display this help and exit. --version display version info and exit. -c (ignored) -C install only if different (preserve data modification time) -d create directories instead of installing files. -g GROUP $chgrpprog installed files to GROUP. -m MODE $chmodprog installed files to MODE. -o USER $chownprog installed files to USER. -p pass -p to $cpprog. -s $stripprog installed files. -S SUFFIX attempt to back up existing files, with suffix SUFFIX. -t DIRECTORY install into DIRECTORY. -T report an error if DSTFILE is a directory. Environment variables override the default commands: CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG By default, rm is invoked with -f; when overridden with RMPROG, it's up to you to specify -f if you want it. If -S is not specified, no backups are attempted. Report bugs to . GNU Automake home page: . General help using GNU software: ." while test $# -ne 0; do case $1 in -c) ;; -C) copy_on_change=true;; -d) dir_arg=true;; -g) chgrpcmd="$chgrpprog $2" shift;; --help) echo "$usage"; exit $?;; -m) mode=$2 case $mode in *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) echo "$0: invalid mode: $mode" >&2 exit 1;; esac shift;; -o) chowncmd="$chownprog $2" shift;; -p) cpprog="$cpprog -p";; -s) stripcmd=$stripprog;; -S) backupsuffix="$2" shift;; -t) is_target_a_directory=always dst_arg=$2 # Protect names problematic for 'test' and other utilities. case $dst_arg in -* | [=\(\)!]) dst_arg=./$dst_arg;; esac shift;; -T) is_target_a_directory=never;; --version) echo "$0 $scriptversion"; exit $?;; --) shift break;; -*) echo "$0: invalid option: $1" >&2 exit 1;; *) break;; esac shift done # We allow the use of options -d and -T together, by making -d # take the precedence; this is for compatibility with GNU install. if test -n "$dir_arg"; then if test -n "$dst_arg"; then echo "$0: target directory not allowed when installing a directory." >&2 exit 1 fi fi if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then # When -d is used, all remaining arguments are directories to create. # When -t is used, the destination is already specified. # Otherwise, the last argument is the destination. Remove it from $@. for arg do if test -n "$dst_arg"; then # $@ is not empty: it contains at least $arg. set fnord "$@" "$dst_arg" shift # fnord fi shift # arg dst_arg=$arg # Protect names problematic for 'test' and other utilities. case $dst_arg in -* | [=\(\)!]) dst_arg=./$dst_arg;; esac done fi if test $# -eq 0; then if test -z "$dir_arg"; then echo "$0: no input file specified." >&2 exit 1 fi # It's OK to call 'install-sh -d' without argument. # This can happen when creating conditional directories. exit 0 fi if test -z "$dir_arg"; then if test $# -gt 1 || test "$is_target_a_directory" = always; then if test ! -d "$dst_arg"; then echo "$0: $dst_arg: Is not a directory." >&2 exit 1 fi fi fi if test -z "$dir_arg"; then do_exit='(exit $ret); exit $ret' trap "ret=129; $do_exit" 1 trap "ret=130; $do_exit" 2 trap "ret=141; $do_exit" 13 trap "ret=143; $do_exit" 15 # Set umask so as not to create temps with too-generous modes. # However, 'strip' requires both read and write access to temps. case $mode in # Optimize common cases. *644) cp_umask=133;; *755) cp_umask=22;; *[0-7]) if test -z "$stripcmd"; then u_plus_rw= else u_plus_rw='% 200' fi cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; *) if test -z "$stripcmd"; then u_plus_rw= else u_plus_rw=,u+rw fi cp_umask=$mode$u_plus_rw;; esac fi for src do # Protect names problematic for 'test' and other utilities. case $src in -* | [=\(\)!]) src=./$src;; esac if test -n "$dir_arg"; then dst=$src dstdir=$dst test -d "$dstdir" dstdir_status=$? # Don't chown directories that already exist. if test $dstdir_status = 0; then chowncmd="" fi else # Waiting for this to be detected by the "$cpprog $src $dsttmp" command # might cause directories to be created, which would be especially bad # if $src (and thus $dsttmp) contains '*'. if test ! -f "$src" && test ! -d "$src"; then echo "$0: $src does not exist." >&2 exit 1 fi if test -z "$dst_arg"; then echo "$0: no destination specified." >&2 exit 1 fi dst=$dst_arg # If destination is a directory, append the input filename. if test -d "$dst"; then if test "$is_target_a_directory" = never; then echo "$0: $dst_arg: Is a directory" >&2 exit 1 fi dstdir=$dst dstbase=`basename "$src"` case $dst in */) dst=$dst$dstbase;; *) dst=$dst/$dstbase;; esac dstdir_status=0 else dstdir=`dirname "$dst"` test -d "$dstdir" dstdir_status=$? fi fi case $dstdir in */) dstdirslash=$dstdir;; *) dstdirslash=$dstdir/;; esac obsolete_mkdir_used=false if test $dstdir_status != 0; then case $posix_mkdir in '') # With -d, create the new directory with the user-specified mode. # Otherwise, rely on $mkdir_umask. if test -n "$dir_arg"; then mkdir_mode=-m$mode else mkdir_mode= fi posix_mkdir=false # The $RANDOM variable is not portable (e.g., dash). Use it # here however when possible just to lower collision chance. tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ trap ' ret=$? rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null exit $ret ' 0 # Because "mkdir -p" follows existing symlinks and we likely work # directly in world-writeable /tmp, make sure that the '$tmpdir' # directory is successfully created first before we actually test # 'mkdir -p'. if (umask $mkdir_umask && $mkdirprog $mkdir_mode "$tmpdir" && exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1 then if test -z "$dir_arg" || { # Check for POSIX incompatibilities with -m. # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or # other-writable bit of parent directory when it shouldn't. # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. test_tmpdir="$tmpdir/a" ls_ld_tmpdir=`ls -ld "$test_tmpdir"` case $ls_ld_tmpdir in d????-?r-*) different_mode=700;; d????-?--*) different_mode=755;; *) false;; esac && $mkdirprog -m$different_mode -p -- "$test_tmpdir" && { ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" } } then posix_mkdir=: fi rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" else # Remove any dirs left behind by ancient mkdir implementations. rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null fi trap '' 0;; esac if $posix_mkdir && ( umask $mkdir_umask && $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" ) then : else # mkdir does not conform to POSIX, # or it failed possibly due to a race condition. Create the # directory the slow way, step by step, checking for races as we go. case $dstdir in /*) prefix='/';; [-=\(\)!]*) prefix='./';; *) prefix='';; esac oIFS=$IFS IFS=/ set -f set fnord $dstdir shift set +f IFS=$oIFS prefixes= for d do test X"$d" = X && continue prefix=$prefix$d if test -d "$prefix"; then prefixes= else if $posix_mkdir; then (umask $mkdir_umask && $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break # Don't fail if two instances are running concurrently. test -d "$prefix" || exit 1 else case $prefix in *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; *) qprefix=$prefix;; esac prefixes="$prefixes '$qprefix'" fi fi prefix=$prefix/ done if test -n "$prefixes"; then # Don't fail if two instances are running concurrently. (umask $mkdir_umask && eval "\$doit_exec \$mkdirprog $prefixes") || test -d "$dstdir" || exit 1 obsolete_mkdir_used=true fi fi fi if test -n "$dir_arg"; then { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 else # Make a couple of temp file names in the proper directory. dsttmp=${dstdirslash}_inst.$$_ rmtmp=${dstdirslash}_rm.$$_ # Trap to clean up those temp files at exit. trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 # Copy the file name to the temp name. (umask $cp_umask && { test -z "$stripcmd" || { # Create $dsttmp read-write so that cp doesn't create it read-only, # which would cause strip to fail. if test -z "$doit"; then : >"$dsttmp" # No need to fork-exec 'touch'. else $doit touch "$dsttmp" fi } } && $doit_exec $cpprog "$src" "$dsttmp") && # and set any options; do chmod last to preserve setuid bits. # # If any of these fail, we abort the whole thing. If we want to # ignore errors from any of these, just make sure not to ignore # errors from the above "$doit $cpprog $src $dsttmp" command. # { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && # If -C, don't bother to copy if it wouldn't change the file. if $copy_on_change && old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && set -f && set X $old && old=:$2:$4:$5:$6 && set X $new && new=:$2:$4:$5:$6 && set +f && test "$old" = "$new" && $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 then rm -f "$dsttmp" else # If $backupsuffix is set, and the file being installed # already exists, attempt a backup. Don't worry if it fails, # e.g., if mv doesn't support -f. if test -n "$backupsuffix" && test -f "$dst"; then $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null fi # Rename the file to the real destination. $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || # The rename failed, perhaps because mv can't rename something else # to itself, or perhaps because mv is so ancient that it does not # support -f. { # Now remove or move aside any old file at destination location. # We try this two ways since rm can't unlink itself on some # systems and the destination file might be busy for other # reasons. In this case, the final cleanup might fail but the new # file should still install successfully. { test ! -f "$dst" || $doit $rmcmd "$dst" 2>/dev/null || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && { $doit $rmcmd "$rmtmp" 2>/dev/null; :; } } || { echo "$0: cannot unlink or rename $dst" >&2 (exit 1); exit 1 } } && # Now rename the file to the real destination. $doit $mvcmd "$dsttmp" "$dst" } fi || exit 1 trap '' 0 fi done # Local variables: # eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC0" # time-stamp-end: "; # UTC" # End: objfw-1.1.6/build-aux/m4/000077500000000000000000000000001465614216400150515ustar00rootroot00000000000000objfw-1.1.6/build-aux/m4/ax_check_compiler_flags.m4000066400000000000000000000063611465614216400221340ustar00rootroot00000000000000# =========================================================================== # http://autoconf-archive.cryp.to/ax_check_compiler_flags.html # =========================================================================== # # SYNOPSIS # # AX_CHECK_COMPILER_FLAGS(FLAGS, [ACTION-SUCCESS], [ACTION-FAILURE]) # # DESCRIPTION # # Check whether the given compiler FLAGS work with the current language's # compiler, or whether they give an error. (Warnings, however, are # ignored.) # # ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on # success/failure. # # LAST MODIFICATION # # 2008-04-12 # # COPYLEFT # # Copyright (c) 2008 Steven G. Johnson # Copyright (c) 2008 Matteo Frigo # # 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 . # # As a special exception, the respective Autoconf Macro's copyright owner # gives unlimited permission to copy, distribute and modify the configure # scripts that are the output of Autoconf when processing the Macro. You # need not follow the terms of the GNU General Public License when using # or distributing such scripts, even though portions of the text of the # Macro appear in them. The GNU General Public License (GPL) does govern # all other use of the material that constitutes the Autoconf Macro. # # This special exception to the GPL applies to versions of the Autoconf # Macro released by the Autoconf Macro Archive. When you make and # distribute a modified version of the Autoconf Macro, you may extend this # special exception to the GPL to apply to your modified version as well. AC_DEFUN([AX_CHECK_COMPILER_FLAGS], [AC_PREREQ(2.59) dnl for _AC_LANG_PREFIX AC_MSG_CHECKING([whether _AC_LANG compiler accepts $1]) dnl Some hackery here since AC_CACHE_VAL can't handle a non-literal varname: AS_LITERAL_IF([$1], [AC_CACHE_VAL(AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_$1), [ ax_save_FLAGS=$[]_AC_LANG_PREFIX[]FLAGS _AC_LANG_PREFIX[]FLAGS="$1" AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_$1)=yes, AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_$1)=no) _AC_LANG_PREFIX[]FLAGS=$ax_save_FLAGS])], [ax_save_FLAGS=$[]_AC_LANG_PREFIX[]FLAGS _AC_LANG_PREFIX[]FLAGS="$1" AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], eval AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_$1)=yes, eval AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_$1)=no) _AC_LANG_PREFIX[]FLAGS=$ax_save_FLAGS]) eval ax_check_compiler_flags=$AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_$1) AC_MSG_RESULT($ax_check_compiler_flags) if test "x$ax_check_compiler_flags" = xyes; then m4_default([$2], :) else m4_default([$3], :) fi ])dnl AX_CHECK_COMPILER_FLAGS objfw-1.1.6/build-aux/m4/buildsys.m4000066400000000000000000000326051465614216400171570ustar00rootroot00000000000000dnl dnl Copyright (c) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016, 2017, dnl 2018, 2020, 2021, 2022, 2023 dnl Jonathan Schleifer dnl dnl https://fossil.nil.im/buildsys dnl dnl Permission to use, copy, modify, and/or distribute this software for any dnl purpose with or without fee is hereby granted, provided that the above dnl copyright notice and this permission notice is present in all copies. dnl dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" dnl AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE dnl IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE dnl ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE dnl LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR dnl CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF dnl SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS dnl INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN dnl CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) dnl ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE dnl POSSIBILITY OF SUCH DAMAGE. dnl AC_DEFUN([BUILDSYS_INIT], [ AC_REQUIRE([AC_CANONICAL_BUILD]) AC_REQUIRE([AC_CANONICAL_HOST]) AC_ARG_ENABLE(rpath, AS_HELP_STRING([--disable-rpath], [do not use rpath])) AC_ARG_ENABLE(silent-rules, AS_HELP_STRING([--disable-silent-rules], [print executed commands during build])) case "$build_os" in darwin*) case "$host_os" in darwin*) AC_SUBST(BUILD_AND_HOST_ARE_DARWIN, yes) ;; esac ;; esac AC_PROG_INSTALL case "$INSTALL" in ./build-aux/install-sh*) INSTALL="$PWD/$INSTALL" ;; esac AC_CONFIG_COMMANDS_PRE([ AS_IF([test x"$GCC" = x"yes"], [AC_SUBST(DEP_CFLAGS, '-MD -MF $${out%.o}.dep')]) AS_IF([test x"$GXX" = x"yes"], [AC_SUBST(DEP_CXXFLAGS, '-MD -MF $${out%.o}.dep')]) AS_IF([test x"$GOBJC" = x"yes"], [AC_SUBST(DEP_OBJCFLAGS, '-MD -MF $${out%.o}.dep')]) AS_IF([test x"$GOBJCXX" = x"yes"], [AC_SUBST(DEP_OBJCXXFLAGS, '-MD -MF $${out%.o}.dep')]) AC_SUBST(AMIGA_LIB_CFLAGS) AC_SUBST(AMIGA_LIB_LDFLAGS) case "$build_os" in morphos*) dnl Don't use tput on MorphOS: The colored output is dnl quite unreadable and in some MorphOS versions the dnl output from tput is not 8-bit safe, with awk (for dnl AC_SUBST) failing as a result. ;; *) AC_PATH_PROG(TPUT, tput) ;; esac AS_IF([test x"$TPUT" != x""], [ if x=$($TPUT el 2>/dev/null); then AC_SUBST(TERM_EL, "$x") else AC_SUBST(TERM_EL, "$($TPUT ce 2>/dev/null)") fi if x=$($TPUT sgr0 2>/dev/null); then AC_SUBST(TERM_SGR0, "$x") else AC_SUBST(TERM_SGR0, "$($TPUT me 2>/dev/null)") fi if x=$($TPUT bold 2>/dev/null); then AC_SUBST(TERM_BOLD, "$x") else AC_SUBST(TERM_BOLD, "$($TPUT md 2>/dev/null)") fi if x=$($TPUT setaf 1 2>/dev/null); then AC_SUBST(TERM_SETAF1, "$x") AC_SUBST(TERM_SETAF2, "$($TPUT setaf 2 2>/dev/null)") AC_SUBST(TERM_SETAF3, "$($TPUT setaf 3 2>/dev/null)") AC_SUBST(TERM_SETAF4, "$($TPUT setaf 4 2>/dev/null)") AC_SUBST(TERM_SETAF6, "$($TPUT setaf 6 2>/dev/null)") dnl OpenBSD seems to want 3 parameters for terminals dnl ending in -256color, but the additional two dnl parameters don't seem to do anything, so we set dnl them to 0. elif x=$($TPUT setaf 1 0 0 2>/dev/null); then AC_SUBST(TERM_SETAF1, "$x") AC_SUBST(TERM_SETAF2, "$($TPUT setaf 2 0 0 2>/dev/null)") AC_SUBST(TERM_SETAF3, "$($TPUT setaf 3 0 0 2>/dev/null)") AC_SUBST(TERM_SETAF4, "$($TPUT setaf 4 0 0 2>/dev/null)") AC_SUBST(TERM_SETAF6, "$($TPUT setaf 6 0 0 2>/dev/null)") else AC_SUBST(TERM_SETAF1, "$($TPUT AF 1 2>/dev/null)") AC_SUBST(TERM_SETAF2, "$($TPUT AF 2 2>/dev/null)") AC_SUBST(TERM_SETAF3, "$($TPUT AF 3 2>/dev/null)") AC_SUBST(TERM_SETAF4, "$($TPUT AF 4 2>/dev/null)") AC_SUBST(TERM_SETAF6, "$($TPUT AF 6 2>/dev/null)") fi ]) AS_IF([test x"$enable_silent_rules" != x"no"], [ AC_SUBST(SILENT, '.SILENT:') AC_SUBST(MAKEFLAGS_SILENT, '-s') ]) ]) ]) AC_DEFUN([BUILDSYS_CHECK_IOS], [ case "$host_os" in darwin*) AC_MSG_CHECKING(whether host is iOS) AC_EGREP_CPP(yes, [ #include #if (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) || \ (defined(TARGET_OS_SIMULATOR) && \ TARGET_OS_SIMULATOR) yes #endif ], [ host_is_ios="yes" AC_SUBST(HOST_IS_IOS, yes) ], [ host_is_ios="no" ]) AC_MSG_RESULT($host_is_ios) AC_CHECK_TOOL(CODESIGN, codesign) ;; esac ]) AC_DEFUN([BUILDSYS_PROG_IMPLIB], [ AC_REQUIRE([AC_CANONICAL_HOST]) AC_MSG_CHECKING(whether we need an implib) case "$host_os" in cygwin* | mingw*) AC_MSG_RESULT(yes) PROG_IMPLIB_NEEDED='yes' PROG_IMPLIB_LDFLAGS='-Wl,--export-all-symbols,--out-implib,lib${PROG}.a' ;; *) AC_MSG_RESULT(no) PROG_IMPLIB_NEEDED='no' PROG_IMPLIB_LDFLAGS='' ;; esac AC_SUBST(PROG_IMPLIB_NEEDED) AC_SUBST(PROG_IMPLIB_LDFLAGS) ]) AC_DEFUN([BUILDSYS_SHARED_LIB], [ AC_REQUIRE([AC_CANONICAL_HOST]) AC_REQUIRE([BUILDSYS_CHECK_IOS]) AC_MSG_CHECKING(for shared library type) case "$host" in *-*-darwin*) AC_MSG_RESULT(Darwin) LIB_CFLAGS='-fPIC -DPIC' LIB_LDFLAGS='-dynamiclib -current_version ${LIB_MAJOR}.${LIB_MINOR} -compatibility_version ${LIB_MAJOR}' LIB_LDFLAGS_INSTALL_NAME='-Wl,-install_name,${libdir}/$${out%.dylib}.${LIB_MAJOR}.dylib' LIB_PREFIX='lib' LIB_SUFFIX='.dylib' AS_IF([test x"$enable_rpath" != x"no"], [ LDFLAGS_RPATH='-Wl,-rpath,${libdir}' ]) INSTALL_LIB='&& ${INSTALL} -m 755 $$i ${DESTDIR}${libdir}/$${i%.dylib}.${LIB_MAJOR}.${LIB_MINOR}.dylib && ${LN_S} -f $${i%.dylib}.${LIB_MAJOR}.${LIB_MINOR}.dylib ${DESTDIR}${libdir}/$${i%.dylib}.${LIB_MAJOR}.dylib && ${LN_S} -f $${i%.dylib}.${LIB_MAJOR}.${LIB_MINOR}.dylib ${DESTDIR}${libdir}/$$i' UNINSTALL_LIB='&& rm -f ${DESTDIR}${libdir}/$$i ${DESTDIR}${libdir}/$${i%.dylib}.${LIB_MAJOR}.dylib ${DESTDIR}${libdir}/$${i%.dylib}.${LIB_MAJOR}.${LIB_MINOR}.dylib' CLEAN_LIB='' ;; *-*-mingw* | *-*-cygwin*) AC_MSG_RESULT(MinGW / Cygwin) LIB_CFLAGS='' LIB_LDFLAGS='-shared -Wl,--export-all-symbols' LIB_LDFLAGS_INSTALL_NAME='' LIB_PREFIX='' LIB_SUFFIX='${LIB_MAJOR}.dll' LINK_LIB='&& rm -f lib$${out%${LIB_SUFFIX}}.dll.a && ${LN_S} $$out lib$${out%${LIB_SUFFIX}}.dll.a' INSTALL_LIB='&& ${MKDIR_P} ${DESTDIR}${bindir} && ${INSTALL} -m 755 $$i ${DESTDIR}${bindir}/$$i && ${INSTALL} -m 755 lib$${i%${LIB_SUFFIX}}.dll.a ${DESTDIR}${libdir}/lib$${i%${LIB_SUFFIX}}.dll.a' UNINSTALL_LIB='&& rm -f ${DESTDIR}${bindir}/$$i ${DESTDIR}${libdir}/lib$${i%${LIB_SUFFIX}}.dll.a' CLEAN_LIB='${SHARED_LIB}.a ${SHARED_LIB_NOINST}.a' ;; *-*-openbsd* | *-*-mirbsd*) AC_MSG_RESULT(OpenBSD) LIB_CFLAGS='-fPIC -DPIC' LIB_LDFLAGS='-shared' LIB_LDFLAGS_INSTALL_NAME='' LIB_PREFIX='lib' LIB_SUFFIX='.so.${LIB_MAJOR}.${LIB_MINOR}' AS_IF([test x"$enable_rpath" != x"no"], [ LDFLAGS_RPATH='-Wl,-rpath,${libdir}' ]) INSTALL_LIB='&& ${INSTALL} -m 755 $$i ${DESTDIR}${libdir}/$$i' UNINSTALL_LIB='&& rm -f ${DESTDIR}${libdir}/$$i' CLEAN_LIB='' ;; *-*-solaris*) AC_MSG_RESULT(Solaris) LIB_CFLAGS='-fPIC -DPIC' LIB_LDFLAGS='-shared -Wl,-soname=$$out.${LIB_MAJOR}.${LIB_MINOR}' LIB_LDFLAGS_INSTALL_NAME='' LIB_PREFIX='lib' LIB_SUFFIX='.so' AS_IF([test x"$enable_rpath" != x"no"], [ LDFLAGS_RPATH='-Wl,-rpath,${libdir}' ]) INSTALL_LIB='&& ${INSTALL} -m 755 $$i ${DESTDIR}${libdir}/$$i.${LIB_MAJOR}.${LIB_MINOR} && rm -f ${DESTDIR}${libdir}/$$i && ${LN_S} $$i.${LIB_MAJOR}.${LIB_MINOR} ${DESTDIR}${libdir}/$$i' UNINSTALL_LIB='&& rm -f ${DESTDIR}${libdir}/$$i ${DESTDIR}${libdir}/$$i.${LIB_MAJOR}.${LIB_MINOR}' CLEAN_LIB='' ;; *-*-android*) AC_MSG_RESULT(Android) LIB_CFLAGS='-fPIC -DPIC' LIB_LDFLAGS='-shared -Wl,-soname=$$out.${LIB_MAJOR}' LIB_LDFLAGS_INSTALL_NAME='' LIB_PREFIX='lib' LIB_SUFFIX='.so' INSTALL_LIB='&& ${INSTALL} -m 755 $$i ${DESTDIR}${libdir}/$$i.${LIB_MAJOR}.${LIB_MINOR}.${LIB_PATCH} && ${LN_S} -f $$i.${LIB_MAJOR}.${LIB_MINOR}.${LIB_PATCH} ${DESTDIR}${libdir}/$$i.${LIB_MAJOR} && ${LN_S} -f $$i.${LIB_MAJOR}.${LIB_MINOR}.${LIB_PATCH} ${DESTDIR}${libdir}/$$i' UNINSTALL_LIB='&& rm -f ${DESTDIR}${libdir}/$$i ${DESTDIR}${libdir}/$$i.${LIB_MAJOR} ${DESTDIR}${libdir}/$$i.${LIB_MAJOR}.${LIB_MINOR}.${LIB_PATCH}' CLEAN_LIB='' ;; hppa*-*-hpux*) AC_MSG_RESULT([HP-UX (PA-RISC)]) LIB_CFLAGS='-fPIC -DPIC' LIB_LDFLAGS='-shared -Wl,+h,$$out' LIB_LDFLAGS_INSTALL_NAME='' LIB_PREFIX='lib' LIB_SUFFIX='.${LIB_MAJOR}' LINK_LIB='&& rm -f $${out%%.*}.sl && ${LN_S} $$out $${out%%.*}.sl' AS_IF([test x"$enable_rpath" != x"no"], [ LDFLAGS_RPATH='-Wl,+b,${libdir}' ]) INSTALL_LIB='&& ${INSTALL} -m 755 $$i ${DESTDIR}${libdir}/$$i && ${LN_S} -f $$i ${DESTDIR}${libdir}/$${i%%.*}.sl' UNINSTALL_LIB='&& rm -f ${DESTDIR}${libdir}/$$i ${DESTDIR}${libdir}/$${i%%.*}.sl' CLEAN_LIB='' ;; ia64*-*-hpux*) AC_MSG_RESULT([HP-UX (Itanium)]) LIB_CFLAGS='-fPIC -DPIC' LIB_LDFLAGS='-shared -Wl,+h,$$out' LIB_LDFLAGS_INSTALL_NAME='' LIB_PREFIX='lib' LIB_SUFFIX='.${LIB_MAJOR}' LINK_LIB='&& rm -f $${out%%.*}.so && ${LN_S} $$out $${out%%.*}.so' AS_IF([test x"$enable_rpath" != x"no"], [ LDFLAGS_RPATH='-Wl,+b,${libdir}' ]) INSTALL_LIB='&& ${INSTALL} -m 755 $$i ${DESTDIR}${libdir}/$$i && ${LN_S} -f $$i ${DESTDIR}${libdir}/$${i%%.*}.so' UNINSTALL_LIB='&& rm -f ${DESTDIR}${libdir}/$$i ${DESTDIR}${libdir}/$${i%%.*}.so' CLEAN_LIB='' ;; *) AC_MSG_RESULT(ELF) LIB_CFLAGS='-fPIC -DPIC' LIB_LDFLAGS='-shared -Wl,-soname=$$out.${LIB_MAJOR}' LIB_LDFLAGS_INSTALL_NAME='' LIB_PREFIX='lib' LIB_SUFFIX='.so' AS_IF([test x"$enable_rpath" != x"no"], [ LDFLAGS_RPATH='-Wl,-rpath,${libdir}' ]) INSTALL_LIB='&& ${INSTALL} -m 755 $$i ${DESTDIR}${libdir}/$$i.${LIB_MAJOR}.${LIB_MINOR}.${LIB_PATCH} && ${LN_S} -f $$i.${LIB_MAJOR}.${LIB_MINOR}.${LIB_PATCH} ${DESTDIR}${libdir}/$$i.${LIB_MAJOR} && ${LN_S} -f $$i.${LIB_MAJOR}.${LIB_MINOR}.${LIB_PATCH} ${DESTDIR}${libdir}/$$i' UNINSTALL_LIB='&& rm -f ${DESTDIR}${libdir}/$$i ${DESTDIR}${libdir}/$$i.${LIB_MAJOR} ${DESTDIR}${libdir}/$$i.${LIB_MAJOR}.${LIB_MINOR}.${LIB_PATCH}' CLEAN_LIB='' ;; esac AC_SUBST(LIB_CFLAGS) AC_SUBST(LIB_LDFLAGS) AC_SUBST(LIB_LDFLAGS_INSTALL_NAME) AC_SUBST(LIB_PREFIX) AC_SUBST(LIB_SUFFIX) AC_SUBST(LINK_LIB) AC_SUBST(LDFLAGS_RPATH) AC_SUBST(INSTALL_LIB) AC_SUBST(UNINSTALL_LIB) AC_SUBST(CLEAN_LIB) ]) AC_DEFUN([BUILDSYS_FRAMEWORK], [ AC_REQUIRE([AC_CANONICAL_HOST]) AC_REQUIRE([BUILDSYS_CHECK_IOS]) AC_REQUIRE([BUILDSYS_SHARED_LIB]) case "$host_os" in darwin*) FRAMEWORK_LDFLAGS='-dynamiclib -current_version ${LIB_MAJOR}.${LIB_MINOR} -compatibility_version ${LIB_MAJOR}' AS_IF([test x"$host_is_ios" = x"yes"], [ FRAMEWORK_LDFLAGS_INSTALL_NAME='-Wl,-install_name,@executable_path/Frameworks/$$out/$${out%.framework}' ], [ FRAMEWORK_LDFLAGS_INSTALL_NAME='-Wl,-install_name,@executable_path/../Frameworks/$$out/$${out%.framework}' ]) AC_SUBST(FRAMEWORK_LDFLAGS) AC_SUBST(FRAMEWORK_LDFLAGS_INSTALL_NAME) AC_SUBST(FRAMEWORK_LIBS) $1 ;; esac ]) AC_DEFUN([BUILDSYS_PLUGIN], [ AC_REQUIRE([AC_CANONICAL_HOST]) AC_REQUIRE([BUILDSYS_CHECK_IOS]) AC_MSG_CHECKING(for plugin type) case "$host" in *-*-darwin*) AC_MSG_RESULT(Darwin) PLUGIN_CFLAGS='-fPIC -DPIC' PLUGIN_LDFLAGS='-bundle ${PLUGIN_LDFLAGS_BUNDLE_LOADER}' PLUGIN_SUFFIX='.bundle' AS_IF([test x"$host_is_ios" = x"yes"], [ LINK_PLUGIN='rm -fr $$out && ${MKDIR_P} $$out && if test -f Info.plist; then ${INSTALL} -m 644 Info.plist $$out/Info.plist; fi && ${LD} -o $$out/$${out%${PLUGIN_SUFFIX}} ${PLUGIN_OBJS} ${PLUGIN_OBJS_EXTRA} ${PLUGIN_LDFLAGS} ${LDFLAGS} ${LIBS} && ${CODESIGN} -fs ${CODESIGN_IDENTITY} $$out' ], [ LINK_PLUGIN='rm -fr $$out && ${MKDIR_P} $$out/Contents/MacOS && if test -f Info.plist; then ${INSTALL} -m 644 Info.plist $$out/Contents/Info.plist; fi && ${LD} -o $$out/Contents/MacOS/$${out%${PLUGIN_SUFFIX}} ${PLUGIN_OBJS} ${PLUGIN_OBJS_EXTRA} ${PLUGIN_LDFLAGS} ${LDFLAGS} ${LIBS} && ${CODESIGN} -fs ${CODESIGN_IDENTITY} $$out' ]) INSTALL_PLUGIN='&& rm -fr ${DESTDIR}${plugindir}/$$i && cp -R $$i ${DESTDIR}${plugindir}/' UNINSTALL_PLUGIN='&& rm -fr ${DESTDIR}${plugindir}/$$i' ;; *-*-mingw* | *-*-cygwin*) AC_MSG_RESULT(MinGW / Cygwin) PLUGIN_CFLAGS='' PLUGIN_LDFLAGS='-shared -Wl,--export-all-symbols' PLUGIN_SUFFIX='.dll' LINK_PLUGIN='${LD} -o $$out ${PLUGIN_OBJS} ${PLUGIN_OBJS_EXTRA} ${PLUGIN_LDFLAGS} ${LDFLAGS} ${LIBS}' INSTALL_PLUGIN='&& ${INSTALL} -m 755 $$i ${DESTDIR}${plugindir}/$$i' UNINSTALL_PLUGIN='&& rm -f ${DESTDIR}${plugindir}/$$i' ;; hppa*-*-hpux*) AC_MSG_RESULT([HP-UX (PA-RISC)]) PLUGIN_CFLAGS='-fPIC -DPIC' PLUGIN_LDFLAGS='-shared' PLUGIN_SUFFIX='.sl' LINK_PLUGIN='${LD} -o $$out ${PLUGIN_OBJS} ${PLUGIN_OBJS_EXTRA} ${PLUGIN_LDFLAGS} ${LDFLAGS} ${LIBS}' INSTALL_PLUGIN='&& ${INSTALL} -m 755 $$i ${DESTDIR}${plugindir}/$$i' UNINSTALL_PLUGIN='&& rm -f ${DESTDIR}${plugindir}/$$i' ;; *) AC_MSG_RESULT(ELF) PLUGIN_CFLAGS='-fPIC -DPIC' PLUGIN_LDFLAGS='-shared' PLUGIN_SUFFIX='.so' LINK_PLUGIN='${LD} -o $$out ${PLUGIN_OBJS} ${PLUGIN_OBJS_EXTRA} ${PLUGIN_LDFLAGS} ${LDFLAGS} ${LIBS}' INSTALL_PLUGIN='&& ${INSTALL} -m 755 $$i ${DESTDIR}${plugindir}/$$i' UNINSTALL_PLUGIN='&& rm -f ${DESTDIR}${plugindir}/$$i' ;; esac AC_SUBST(PLUGIN_CFLAGS) AC_SUBST(PLUGIN_LDFLAGS) AC_SUBST(PLUGIN_SUFFIX) AC_SUBST(LINK_PLUGIN) AC_SUBST(INSTALL_PLUGIN) AC_SUBST(UNINSTALL_PLUGIN) ]) objfw-1.1.6/build-aux/m4/pkg.m4000066400000000000000000000305761465614216400161070ustar00rootroot00000000000000# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*- # serial 11 (pkg-config-0.29.1) dnl Copyright © 2004 Scott James Remnant . dnl Copyright © 2012-2015 Dan Nicholson dnl dnl This program is free software; you can redistribute it and/or modify dnl it under the terms of the GNU General Public License as published by dnl the Free Software Foundation; either version 2 of the License, or dnl (at your option) any later version. dnl dnl This program is distributed in the hope that it will be useful, but dnl WITHOUT ANY WARRANTY; without even the implied warranty of dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU dnl General Public License for more details. dnl dnl You should have received a copy of the GNU General Public License dnl along with this program; if not, write to the Free Software dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA dnl 02111-1307, USA. dnl dnl As a special exception to the GNU General Public License, if you dnl distribute this file as part of a program that contains a dnl configuration script generated by Autoconf, you may include it under dnl the same distribution terms that you use for the rest of that dnl program. dnl PKG_PREREQ(MIN-VERSION) dnl ----------------------- dnl Since: 0.29 dnl dnl Verify that the version of the pkg-config macros are at least dnl MIN-VERSION. Unlike PKG_PROG_PKG_CONFIG, which checks the user's dnl installed version of pkg-config, this checks the developer's version dnl of pkg.m4 when generating configure. dnl dnl To ensure that this macro is defined, also add: dnl m4_ifndef([PKG_PREREQ], dnl [m4_fatal([must install pkg-config 0.29 or later before running autoconf/autogen])]) dnl dnl See the "Since" comment for each macro you use to see what version dnl of the macros you require. m4_defun([PKG_PREREQ], [m4_define([PKG_MACROS_VERSION], [0.29.1]) m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1, [m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])]) ])dnl PKG_PREREQ dnl PKG_PROG_PKG_CONFIG([MIN-VERSION]) dnl ---------------------------------- dnl Since: 0.16 dnl dnl Search for the pkg-config tool and set the PKG_CONFIG variable to dnl first found in the path. Checks that the version of pkg-config found dnl is at least MIN-VERSION. If MIN-VERSION is not specified, 0.9.0 is dnl used since that's the first version where most current features of dnl pkg-config existed. AC_DEFUN([PKG_PROG_PKG_CONFIG], [m4_pattern_forbid([^_?PKG_[A-Z_]+$]) m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$]) m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$]) AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility]) AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path]) AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path]) if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then AC_PATH_TOOL([PKG_CONFIG], [pkg-config]) fi if test -n "$PKG_CONFIG"; then _pkg_min_version=m4_default([$1], [0.9.0]) AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version]) if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) PKG_CONFIG="" fi fi[]dnl ])dnl PKG_PROG_PKG_CONFIG dnl PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) dnl ------------------------------------------------------------------- dnl Since: 0.18 dnl dnl Check to see whether a particular set of modules exists. Similar to dnl PKG_CHECK_MODULES(), but does not set variables or print errors. dnl dnl Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG]) dnl only at the first occurence in configure.ac, so if the first place dnl it's called might be skipped (such as if it is within an "if", you dnl have to call PKG_CHECK_EXISTS manually AC_DEFUN([PKG_CHECK_EXISTS], [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl if test -n "$PKG_CONFIG" && \ AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then m4_default([$2], [:]) m4_ifvaln([$3], [else $3])dnl fi]) dnl _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES]) dnl --------------------------------------------- dnl Internal wrapper calling pkg-config via PKG_CONFIG and setting dnl pkg_failed based on the result. m4_define([_PKG_CONFIG], [if test -n "$$1"; then pkg_cv_[]$1="$$1" elif test -n "$PKG_CONFIG"; then PKG_CHECK_EXISTS([$3], [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null` test "x$?" != "x0" && pkg_failed=yes ], [pkg_failed=yes]) else pkg_failed=untried fi[]dnl ])dnl _PKG_CONFIG dnl _PKG_SHORT_ERRORS_SUPPORTED dnl --------------------------- dnl Internal check to see if pkg-config supports short errors. AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED], [AC_REQUIRE([PKG_PROG_PKG_CONFIG]) if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then _pkg_short_errors_supported=yes else _pkg_short_errors_supported=no fi[]dnl ])dnl _PKG_SHORT_ERRORS_SUPPORTED dnl PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], dnl [ACTION-IF-NOT-FOUND]) dnl -------------------------------------------------------------- dnl Since: 0.4.0 dnl dnl Note that if there is a possibility the first call to dnl PKG_CHECK_MODULES might not happen, you should be sure to include an dnl explicit call to PKG_PROG_PKG_CONFIG in your configure.ac AC_DEFUN([PKG_CHECK_MODULES], [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl pkg_failed=no AC_MSG_CHECKING([for $1]) _PKG_CONFIG([$1][_CFLAGS], [cflags], [$2]) _PKG_CONFIG([$1][_LIBS], [libs], [$2]) m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS and $1[]_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details.]) if test $pkg_failed = yes; then AC_MSG_RESULT([no]) _PKG_SHORT_ERRORS_SUPPORTED if test $_pkg_short_errors_supported = yes; then $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1` else $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1` fi # Put the nasty error message in config.log where it belongs echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD m4_default([$4], [AC_MSG_ERROR( [Package requirements ($2) were not met: $$1_PKG_ERRORS Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix. _PKG_TEXT])[]dnl ]) elif test $pkg_failed = untried; then AC_MSG_RESULT([no]) m4_default([$4], [AC_MSG_FAILURE( [The pkg-config script could not be found or is too old. Make sure it is in your PATH or set the PKG_CONFIG environment variable to the full path to pkg-config. _PKG_TEXT To get pkg-config, see .])[]dnl ]) else $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS $1[]_LIBS=$pkg_cv_[]$1[]_LIBS AC_MSG_RESULT([yes]) $3 fi[]dnl ])dnl PKG_CHECK_MODULES dnl PKG_CHECK_MODULES_STATIC(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], dnl [ACTION-IF-NOT-FOUND]) dnl --------------------------------------------------------------------- dnl Since: 0.29 dnl dnl Checks for existence of MODULES and gathers its build flags with dnl static libraries enabled. Sets VARIABLE-PREFIX_CFLAGS from --cflags dnl and VARIABLE-PREFIX_LIBS from --libs. dnl dnl Note that if there is a possibility the first call to dnl PKG_CHECK_MODULES_STATIC might not happen, you should be sure to dnl include an explicit call to PKG_PROG_PKG_CONFIG in your dnl configure.ac. AC_DEFUN([PKG_CHECK_MODULES_STATIC], [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl _save_PKG_CONFIG=$PKG_CONFIG PKG_CONFIG="$PKG_CONFIG --static" PKG_CHECK_MODULES($@) PKG_CONFIG=$_save_PKG_CONFIG[]dnl ])dnl PKG_CHECK_MODULES_STATIC dnl PKG_INSTALLDIR([DIRECTORY]) dnl ------------------------- dnl Since: 0.27 dnl dnl Substitutes the variable pkgconfigdir as the location where a module dnl should install pkg-config .pc files. By default the directory is dnl $libdir/pkgconfig, but the default can be changed by passing dnl DIRECTORY. The user can override through the --with-pkgconfigdir dnl parameter. AC_DEFUN([PKG_INSTALLDIR], [m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])]) m4_pushdef([pkg_description], [pkg-config installation directory @<:@]pkg_default[@:>@]) AC_ARG_WITH([pkgconfigdir], [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],, [with_pkgconfigdir=]pkg_default) AC_SUBST([pkgconfigdir], [$with_pkgconfigdir]) m4_popdef([pkg_default]) m4_popdef([pkg_description]) ])dnl PKG_INSTALLDIR dnl PKG_NOARCH_INSTALLDIR([DIRECTORY]) dnl -------------------------------- dnl Since: 0.27 dnl dnl Substitutes the variable noarch_pkgconfigdir as the location where a dnl module should install arch-independent pkg-config .pc files. By dnl default the directory is $datadir/pkgconfig, but the default can be dnl changed by passing DIRECTORY. The user can override through the dnl --with-noarch-pkgconfigdir parameter. AC_DEFUN([PKG_NOARCH_INSTALLDIR], [m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])]) m4_pushdef([pkg_description], [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@]) AC_ARG_WITH([noarch-pkgconfigdir], [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],, [with_noarch_pkgconfigdir=]pkg_default) AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir]) m4_popdef([pkg_default]) m4_popdef([pkg_description]) ])dnl PKG_NOARCH_INSTALLDIR dnl PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE, dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) dnl ------------------------------------------- dnl Since: 0.28 dnl dnl Retrieves the value of the pkg-config variable for the given module. AC_DEFUN([PKG_CHECK_VAR], [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl _PKG_CONFIG([$1], [variable="][$3]["], [$2]) AS_VAR_COPY([$1], [pkg_cv_][$1]) AS_VAR_IF([$1], [""], [$5], [$4])dnl ])dnl PKG_CHECK_VAR dnl PKG_WITH_MODULES(VARIABLE-PREFIX, MODULES, dnl [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND], dnl [DESCRIPTION], [DEFAULT]) dnl ------------------------------------------ dnl dnl Prepare a "--with-" configure option using the lowercase dnl [VARIABLE-PREFIX] name, merging the behaviour of AC_ARG_WITH and dnl PKG_CHECK_MODULES in a single macro. AC_DEFUN([PKG_WITH_MODULES], [ m4_pushdef([with_arg], m4_tolower([$1])) m4_pushdef([description], [m4_default([$5], [build with ]with_arg[ support])]) m4_pushdef([def_arg], [m4_default([$6], [auto])]) m4_pushdef([def_action_if_found], [AS_TR_SH([with_]with_arg)=yes]) m4_pushdef([def_action_if_not_found], [AS_TR_SH([with_]with_arg)=no]) m4_case(def_arg, [yes],[m4_pushdef([with_without], [--without-]with_arg)], [m4_pushdef([with_without],[--with-]with_arg)]) AC_ARG_WITH(with_arg, AS_HELP_STRING(with_without, description[ @<:@default=]def_arg[@:>@]),, [AS_TR_SH([with_]with_arg)=def_arg]) AS_CASE([$AS_TR_SH([with_]with_arg)], [yes],[PKG_CHECK_MODULES([$1],[$2],$3,$4)], [auto],[PKG_CHECK_MODULES([$1],[$2], [m4_n([def_action_if_found]) $3], [m4_n([def_action_if_not_found]) $4])]) m4_popdef([with_arg]) m4_popdef([description]) m4_popdef([def_arg]) ])dnl PKG_WITH_MODULES dnl PKG_HAVE_WITH_MODULES(VARIABLE-PREFIX, MODULES, dnl [DESCRIPTION], [DEFAULT]) dnl ----------------------------------------------- dnl dnl Convenience macro to trigger AM_CONDITIONAL after PKG_WITH_MODULES dnl check._[VARIABLE-PREFIX] is exported as make variable. AC_DEFUN([PKG_HAVE_WITH_MODULES], [ PKG_WITH_MODULES([$1],[$2],,,[$3],[$4]) AM_CONDITIONAL([HAVE_][$1], [test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"]) ])dnl PKG_HAVE_WITH_MODULES dnl PKG_HAVE_DEFINE_WITH_MODULES(VARIABLE-PREFIX, MODULES, dnl [DESCRIPTION], [DEFAULT]) dnl ------------------------------------------------------ dnl dnl Convenience macro to run AM_CONDITIONAL and AC_DEFINE after dnl PKG_WITH_MODULES check. HAVE_[VARIABLE-PREFIX] is exported as make dnl and preprocessor variable. AC_DEFUN([PKG_HAVE_DEFINE_WITH_MODULES], [ PKG_HAVE_WITH_MODULES([$1],[$2],[$3],[$4]) AS_IF([test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"], [AC_DEFINE([HAVE_][$1], 1, [Enable ]m4_tolower([$1])[ support])]) ])dnl PKG_HAVE_DEFINE_WITH_MODULES objfw-1.1.6/buildsys.mk.in000066400000000000000000000714731465614216400154470ustar00rootroot00000000000000# # Copyright (c) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, # 2017, 2018, 2020, 2021, 2022, 2023 # Jonathan Schleifer # # https://fossil.nil.im/buildsys # # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice is present in all copies. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_VERSION = @PACKAGE_VERSION@ AS = @AS@ CC = @CC@ CXX = @CXX@ CPP = @CPP@ DC = @DC@ ERLC = @ERLC@ OBJC = @OBJC@ OBJCXX = @OBJCXX@ AR = @AR@ LD = ${CC} RANLIB = @RANLIB@ PYTHON = @PYTHON@ ASFLAGS = @ASFLAGS@ CFLAGS = @CFLAGS@ CXXFLAGS = @CXXFLAGS@ CPPFLAGS = @CPPFLAGS@ DFLAGS = @DFLAGS@ ERLCFLAGS = @ERLCFLAGS@ OBJCFLAGS = @OBJCFLAGS@ OBJCXXFLAGS = @OBJCXXFLAGS@ LDFLAGS = @LDFLAGS@ LDFLAGS_RPATH = @LDFLAGS_RPATH@ LIBS = @LIBS@ PYTHON_FLAGS = @PYTHON_FLAGS@ PROG_IMPLIB_NEEDED = @PROG_IMPLIB_NEEDED@ PROG_IMPLIB_LDFLAGS = @PROG_IMPLIB_LDFLAGS@ PROG_SUFFIX = @EXEEXT@ LIB_CFLAGS = @LIB_CFLAGS@ LIB_LDFLAGS = @LIB_LDFLAGS@ LIB_LDFLAGS_INSTALL_NAME = @LIB_LDFLAGS_INSTALL_NAME@ LIB_PREFIX = @LIB_PREFIX@ LIB_SUFFIX = @LIB_SUFFIX@ LINK_LIB = @LINK_LIB@ AMIGA_LIB_CFLAGS = @AMIGA_LIB_CFLAGS@ AMIGA_LIB_LDFLAGS = @AMIGA_LIB_LDFLAGS@ PLUGIN_CFLAGS = @PLUGIN_CFLAGS@ PLUGIN_LDFLAGS = @PLUGIN_LDFLAGS@ PLUGIN_SUFFIX = @PLUGIN_SUFFIX@ FRAMEWORK_LDFLAGS = @FRAMEWORK_LDFLAGS@ FRAMEWORK_LDFLAGS_INSTALL_NAME = @FRAMEWORK_LDFLAGS_INSTALL_NAME@ FRAMEWORK_LIBS = @FRAMEWORK_LIBS@ CODESIGN = @CODESIGN@ CODESIGN_IDENTITY ?= - CLEAN_LIB = @CLEAN_LIB@ DEP_ASFLAGS = @DEP_ASFLAGS@ DEP_CFLAGS = @DEP_CFLAGS@ DEP_CXXFLAGS = @DEP_CXXFLAGS@ DEP_OBJCFLAGS = @DEP_OBJCFLAGS@ DEP_OBJCXXFLAGS = @DEP_OBJCXXFLAGS@ LN_S = @LN_S@ MKDIR_P = mkdir -p INSTALL = @INSTALL@ SHELL = @SHELL@ MSGFMT = @MSGFMT@ JAVAC = @JAVAC@ JAVACFLAGS = @JAVACFLAGS@ JAR = @JAR@ RC = @RC@ BUILD_AND_HOST_ARE_DARWIN = @BUILD_AND_HOST_ARE_DARWIN@ prefix = @prefix@ exec_prefix = @exec_prefix@ bindir = @bindir@ libdir = @libdir@ amigalibdir ?= ${prefix}/libs plugindir ?= ${libdir}/${PACKAGE_NAME} datarootdir = @datarootdir@ datadir = @datadir@ includedir = @includedir@ includesubdir ?= ${PACKAGE_NAME} INSTALL_INCLUDES ?= yes localedir = @localedir@ localename ?= ${PACKAGE_NAME} mandir = @mandir@ mansubdir ?= man1 OBJS1 = ${SRCS:.c=.o} OBJS2 = ${OBJS1:.cc=.o} OBJS3 = ${OBJS2:.cxx=.o} OBJS4 = ${OBJS3:.d=.o} OBJS5 = ${OBJS4:.erl=.beam} OBJS6 = ${OBJS5:.java=.class} OBJS7 = ${OBJS6:.m=.o} OBJS8 = ${OBJS7:.mm=.o} OBJS9 = ${OBJS8:.py=.pyc} OBJS10 = ${OBJS9:.rc=.o} OBJS11 = ${OBJS10:.S=.o} OBJS += ${OBJS11:.xpm=.o} LIB_OBJS = ${OBJS:.o=.lib.o} AMIGA_LIB_OBJS = ${OBJS:.o=.amigalib.o} PLUGIN_OBJS = ${OBJS:.o=.plugin.o} DEPS = ${OBJS:.o=.dep} \ ${LIB_OBJS:.o=.dep} \ ${AMIGA_LIB_OBJS:.o=.dep} \ ${PLUGIN_OBJS:.o=.dep} MO_FILES = ${LOCALES:.po=.mo} @SILENT@ .SUFFIXES: .SUFFIXES: .amigalib.o .beam .c .cc .class .cxx .d .erl .lib.o .java \ .mo .m .mm .o .plugin.o .po .py .pyc .rc .S .xpm .PHONY: all subdirs subdirs-after pre-depend depend install \ install-extra uninstall uninstall-extra clean distclean locales \ copy-headers-into-framework ${SUBDIRS} ${SUBDIRS_AFTER} all: ${MAKE} @MAKEFLAGS_SILENT@ pre-all ${MAKE} @MAKEFLAGS_SILENT@ subdirs ${MAKE} @MAKEFLAGS_SILENT@ depend ${MAKE} @MAKEFLAGS_SILENT@ \ ${STATIC_LIB} ${STATIC_LIB_NOINST} \ ${STATIC_PIC_LIB} ${STATIC_PIC_LIB_NOINST} \ ${STATIC_AMIGA_LIB}${STATIC_AMIGA_LIB_NOINST} \ ${SHARED_LIB} ${SHARED_LIB_NOINST} \ ${FRAMEWORK} ${FRAMEWORK_NOINST} \ ${AMIGA_LIB} ${AMIGA_LIB_NOINST} \ ${PLUGIN} ${PLUGIN_NOINST} \ ${PROG} ${PROG_NOINST} \ ${JARFILE} locales ${MAKE} @MAKEFLAGS_SILENT@ subdirs-after ${MAKE} @MAKEFLAGS_SILENT@ post-all pre-all post-all: subdirs: ${SUBDIRS} subdirs-after: ${SUBDIRS_AFTER} ${SUBDIRS} ${SUBDIRS_AFTER}: for i in $@; do \ ${DIR_ENTER}; \ ${MAKE} @MAKEFLAGS_SILENT@ || exit $$?; \ ${DIR_LEAVE}; \ done depend: pre-depend : >.deps for i in "" ${DEPS}; do \ test x"$$i" = x"" && continue; \ echo "-include \$${.CURDIR}/$$i" >>.deps; \ done pre-depend: ${PROG} ${PROG_NOINST}: ${EXT_DEPS} ${OBJS} ${OBJS_EXTRA} ${LINK_STATUS} out="$@"; \ if ${LD} -o $@ ${OBJS} ${OBJS_EXTRA} ${LDFLAGS} ${LIBS}; then \ ${LINK_OK}; \ else \ ${LINK_FAILED}; \ fi ${JARFILE}: ${EXT_DEPS} ${JAR_MANIFEST} ${OBJS} ${OBJS_EXTRA} ${LINK_STATUS} if test x"${JAR_MANIFEST}" != x""; then \ if ${JAR} cfm ${JARFILE} ${JAR_MANIFEST} ${OBJS} \ ${OBJS_EXTRA}; then \ ${LINK_OK}; \ else \ ${LINK_FAILED}; \ fi \ else \ if ${JAR} cf ${JARFILE} ${OBJS} ${OBJS_EXTRA}; then \ ${LINK_OK}; \ else \ ${LINK_FAILED}; \ fi \ fi ${SHARED_LIB} ${SHARED_LIB_NOINST}: ${EXT_DEPS} ${LIB_OBJS} ${LIB_OBJS_EXTRA} ${LINK_STATUS} out="$@"; \ if ${LD} -o $@ ${LIB_OBJS} ${LIB_OBJS_EXTRA} ${LIB_LDFLAGS} \ ${LIB_LDFLAGS_INSTALL_NAME} ${LDFLAGS} ${LIBS} ${LINK_LIB}; then \ ${LINK_OK}; \ else \ ${LINK_FAILED}; \ fi ${FRAMEWORK} ${FRAMEWORK_NOINST}: ${EXT_DEPS} ${LIB_OBJS} ${LIB_OBJS_EXTRA} ${LINK_STATUS} out="$@"; \ if test x"@HOST_IS_IOS@" = x"yes"; then \ if rm -fr $@ && \ ${MAKE} @MAKEFLAGS_SILENT@ \ COPY_HEADERS_IF_SUBDIR=${includesubdir} \ COPY_HEADERS_DESTINATION=$$PWD/$@/Headers \ copy-headers-into-framework && \ if test -f Info.plist; then \ ${INSTALL} -m 644 Info.plist $@/Info.plist; \ fi && \ if test -f module.modulemap; then \ ${MKDIR_P} $@/Modules && \ ${INSTALL} -m 644 module.modulemap \ $@/Modules/module.modulemap; \ fi && \ ${LD} -o $@/$${out%.framework} \ ${LIB_OBJS} ${LIB_OBJS_EXTRA} ${FRAMEWORK_LDFLAGS} \ ${FRAMEWORK_LDFLAGS_INSTALL_NAME} ${LDFLAGS} \ ${FRAMEWORK_LIBS} && \ ${CODESIGN} -fs ${CODESIGN_IDENTITY} $@; then \ ${LINK_OK}; \ else \ rm -fr $$out; false; \ ${LINK_FAILED}; \ fi; \ else \ versiondir="$@/Versions/${LIB_MAJOR}"; \ if rm -fr $@ && \ ${MKDIR_P} $$versiondir && \ ${LN_S} ${LIB_MAJOR} $@/Versions/Current && \ ${MAKE} @MAKEFLAGS_SILENT@ \ COPY_HEADERS_IF_SUBDIR=${includesubdir} \ COPY_HEADERS_DESTINATION=$$PWD/$$versiondir/Headers \ copy-headers-into-framework && \ ${LN_S} Versions/Current/Headers $@/Headers && \ if test -f Info.plist; then \ ${MKDIR_P} $$versiondir/Resources && \ ${INSTALL} -m 644 Info.plist \ $$versiondir/Resources/Info.plist && \ ${LN_S} Versions/Current/Resources $@/Resources; \ fi && \ if test -f module.modulemap; then \ ${MKDIR_P} $$versiondir/Modules && \ ${INSTALL} -m 644 module.modulemap \ $$versiondir/Modules/module.modulemap && \ ${LN_S} Versions/Current/Modules $@/Modules; \ fi && \ ${LD} -o $$versiondir/$${out%.framework} \ ${LIB_OBJS} ${LIB_OBJS_EXTRA} ${FRAMEWORK_LDFLAGS} \ ${FRAMEWORK_LDFLAGS_INSTALL_NAME} ${LDFLAGS} \ ${FRAMEWORK_LIBS} && \ ${LN_S} Versions/Current/$${out%.framework} \ $@/$${out%.framework} && \ ${CODESIGN} -fs ${CODESIGN_IDENTITY} $@; then \ ${LINK_OK}; \ else \ rm -fr $$out; false; \ ${LINK_FAILED}; \ fi; \ fi copy-headers-into-framework: for i in "" ${SUBDIRS} ${SUBDIRS_AFTER}; do \ test x"$$i" = x"" && continue; \ cd $$i || exit 1; \ ${MAKE} @MAKEFLAGS_SILENT@ copy-headers-into-framework || \ exit $$?; \ cd .. || exit 1; \ done if test x"${includesubdir}" = x"${COPY_HEADERS_IF_SUBDIR}"; then \ for i in "" ${INCLUDES}; do \ test x"$$i" = x"" && continue; \ ${MKDIR_P} \ $$(dirname ${COPY_HEADERS_DESTINATION}/$$i) || \ exit $$?; \ ${INSTALL} -m 644 $$i \ ${COPY_HEADERS_DESTINATION}/$$i || exit $$?; \ done \ fi ${AMIGA_LIB} ${AMIGA_LIB_NOINST}: ${EXT_DEPS} ${AMIGA_LIB_OBJS_START} \ ${AMIGA_LIB_OBJS} ${AMIGA_LIB_OBJS_EXTRA} ${LINK_STATUS} if ${LD} -o $@ ${AMIGA_LIB_OBJS_START} ${AMIGA_LIB_OBJS} \ ${AMIGA_LIB_OBJS_EXTRA} ${AMIGA_LIB_LDFLAGS} \ ${AMIGA_LIB_LIBS}; then \ ${LINK_OK}; \ else \ ${LINK_FAILED}; \ fi ${PLUGIN} ${PLUGIN_NOINST}: ${EXT_DEPS} ${PLUGIN_OBJS} ${LINK_STATUS} out="$@"; \ if @LINK_PLUGIN@; then \ ${LINK_OK}; \ else \ rm -fr $$out; false; \ ${LINK_FAILED}; \ fi ${STATIC_LIB} ${STATIC_LIB_NOINST}: ${EXT_DEPS} ${OBJS} ${OBJS_EXTRA} ${LINK_STATUS} rm -f $@ if test x"${BUILD_AND_HOST_ARE_DARWIN}" = x"yes"; then \ if /usr/bin/libtool -static -o $@ ${OBJS} ${OBJS_EXTRA}; then \ ${LINK_OK}; \ else \ rm -f $@; false; \ ${LINK_FAILED}; \ fi; \ else \ out="$@"; \ objs=""; \ ars=""; \ for i in ${OBJS} ${OBJS_EXTRA}; do \ case $$i in \ *.a) \ ars="$$ars $$i" \ ;; \ *.o) \ objs="$$objs $$i" \ ;; \ esac \ done; \ for i in $$ars; do \ dir=".$$(echo $$i | sed 's/\//_/g').objs"; \ rm -fr $$dir; \ mkdir -p $$dir; \ cd $$dir; \ ${AR} x ../$$i; \ for j in *.o; do \ objs="$$objs $$dir/$$j"; \ done; \ cd ..; \ done; \ if ${AR} cr $@ $$objs && ${RANLIB} $@; then \ ${LINK_OK}; \ else \ rm -f $@; false; \ ${LINK_FAILED}; \ fi; \ for i in $$ars; do \ dir=".$$(echo $$i | sed 's/\//_/g').objs"; \ rm -fr $$dir; \ done; \ fi ${STATIC_PIC_LIB} ${STATIC_PIC_LIB_NOINST}: ${EXT_DEPS} ${LIB_OBJS} \ ${LIB_OBJS_EXTRA} ${LINK_STATUS} rm -f $@ if test x"${BUILD_AND_HOST_ARE_DARWIN}" = x"yes"; then \ if /usr/bin/libtool -static -o $@ ${LIB_OBJS} \ ${LIB_OBJS_EXTRA}; then \ ${LINK_OK}; \ else \ rm -f $@; false; \ ${LINK_FAILED}; \ fi; \ else \ out="$@"; \ objs=""; \ ars=""; \ for i in ${LIB_OBJS} ${LIB_OBJS_EXTRA}; do \ case $$i in \ *.a) \ ars="$$ars $$i" \ ;; \ *.o) \ objs="$$objs $$i" \ ;; \ esac \ done; \ for i in $$ars; do \ dir=".$$(echo $$i | sed 's/\//_/g').objs"; \ rm -fr $$dir; \ mkdir -p $$dir; \ cd $$dir; \ ${AR} x ../$$i; \ for j in *.o; do \ objs="$$objs $$dir/$$j"; \ done; \ cd ..; \ done; \ if ${AR} cr $@ $$objs && ${RANLIB} $@; then \ ${LINK_OK}; \ else \ rm -f $@; false; \ ${LINK_FAILED}; \ fi; \ for i in $$ars; do \ dir=".$$(echo $$i | sed 's/\//_/g').objs"; \ rm -fr $$dir; \ done; \ fi ${STATIC_AMIGA_LIB} ${STATIC_AMIGA_LIB_NOINST}: ${EXT_DEPS} ${AMIGA_LIB_OBJS} \ ${AMIGA_LIB_OBJS_EXTRA} ${LINK_STATUS} rm -f $@ out="$@"; \ objs=""; \ ars=""; \ for i in ${AMIGA_LIB_OBJS} ${AMIGA_LIB_OBJS_EXTRA}; do \ case $$i in \ *.a) \ ars="$$ars $$i" \ ;; \ *.o) \ objs="$$objs $$i" \ ;; \ esac \ done; \ for i in $$ars; do \ dir=".$$(echo $$i | sed 's/\//_/g').objs"; \ rm -fr $$dir; \ mkdir -p $$dir; \ cd $$dir; \ ${AR} x ../$$i; \ for j in *.o; do \ objs="$$objs $$dir/$$j"; \ done; \ cd ..; \ done; \ if ${AR} cr $@ $$objs && ${RANLIB} $@; then \ ${LINK_OK}; \ else \ rm -f $@; false; \ ${LINK_FAILED}; \ fi; \ for i in $$ars; do \ dir=".$$(echo $$i | sed 's/\//_/g').objs"; \ rm -fr $$dir; \ done locales: ${MO_FILES} .c.o: ${COMPILE_STATUS} in="$<"; \ out="$@"; \ if ${CC} ${CFLAGS} ${CPPFLAGS} ${CFLAGS_$<} ${CFLAGS_$@} ${DEP_CFLAGS} \ -c -o $@ $<; then \ ${COMPILE_OK}; \ else \ ${COMPILE_FAILED}; \ fi .c.lib.o: ${COMPILE_LIB_STATUS} in="$<"; \ out="$@"; \ if ${CC} ${LIB_CFLAGS} ${CFLAGS} ${CPPFLAGS} ${CFLAGS_$<} ${CFLAGS_$@} \ ${DEP_CFLAGS} -c -o $@ $<; then \ ${COMPILE_LIB_OK}; \ else \ ${COMPILE_LIB_FAILED}; \ fi .c.amigalib.o: ${COMPILE_AMIGA_LIB_STATUS} in="$<"; \ out="$@"; \ if ${CC} ${AMIGA_LIB_CFLAGS} ${CFLAGS} ${CPPFLAGS} ${CFLAGS_$<} \ ${CFLAGS_$@} ${DEP_CFLAGS} -c -o $@ $<; then \ ${COMPILE_AMIGA_LIB_OK}; \ else \ ${COMPILE_AMIGA_LIB_FAILED}; \ fi .c.plugin.o: ${COMPILE_PLUGIN_STATUS} in="$<"; \ out="$@"; \ if ${CC} ${PLUGIN_CFLAGS} ${CFLAGS} ${CPPFLAGS} ${CFLAGS_$<} \ ${CFLAGS_$@} ${DEP_CFLAGS} -c -o $@ $<; then \ ${COMPILE_PLUGIN_OK}; \ else \ ${COMPILE_PLUGIN_FAILED}; \ fi .cc.o .cxx.o: ${COMPILE_STATUS} in="$<"; \ out="$@"; \ if ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${CXXFLAGS_$<} ${CXXFLAGS_$@} \ ${DEP_CXXFLAGS} -c -o $@ $<; then \ ${COMPILE_OK}; \ else \ ${COMPILE_FAILED}; \ fi .cc.lib.o .cxx.lib.o: ${COMPILE_LIB_STATUS} in="$<"; \ out="$@"; \ if ${CXX} ${LIB_CFLAGS} ${CXXFLAGS} ${CPPFLAGS} ${CXXFLAGS_$<} \ ${CXXFLAGS_$@} ${DEP_CXXFLAGS} -c -o $@ $<; then \ ${COMPILE_LIB_OK}; \ else \ ${COMPILE_LIB_FAILED}; \ fi .cc.amigalib.o .cxx.amigalib.o: ${COMPILE_AMIGA_LIB_STATUS} in="$<"; \ out="$@"; \ if ${CXX} ${AMIGA_LIB_CFLAGS} ${CXXFLAGS} ${CPPFLAGS} ${CXXFLAGS_$<} \ ${CXXFLAGS_$@} ${DEP_CXXFLAGS} -c -o $@ $<; then \ ${COMPILE_AMIGA_LIB_OK}; \ else \ ${COMPILE_AMIGA_LIB_FAILED}; \ fi .cc.plugin.o .cxx.plugin.o: ${COMPILE_PLUGIN_STATUS} in="$<"; \ out="$@"; \ if ${CXX} ${PLUGIN_CFLAGS} ${CXXFLAGS} ${CPPFLAGS} ${CXXFLAGS_$<} \ ${CXXFLAGS_$@} ${DEP_CXXFLAGS} -c -o $@ $<; then \ ${COMPILE_PLUGIN_OK}; \ else \ ${COMPILE_PLUGIN_FAILED}; \ fi .d.o: ${COMPILE_STATUS} in="$<"; \ out="$@"; \ if test x"$(basename ${DC})" = x"dmd"; then \ if ${DC} ${DFLAGS} -c -of$@ $<; then \ ${COMPILE_OK}; \ else \ ${COMPILE_FAILED}; \ fi \ else \ if ${DC} ${DFLAGS} -c -o $@ $<; then \ ${COMPILE_OK}; \ else \ ${COMPILE_FAILED}; \ fi \ fi .erl.beam: ${COMPILE_STATUS} in="$<"; \ out="$@"; \ if ${ERLC} ${ERLCFLAGS} -o $@ $<; then \ ${COMPILE_OK}; \ else \ ${COMPILE_FAILED}; \ fi .java.class: ${COMPILE_STATUS} in="$<"; \ out="$@"; \ if ${JAVAC} ${JAVACFLAGS} $<; then \ ${COMPILE_OK}; \ else \ ${COMPILE_FAILED}; \ fi .m.o: ${COMPILE_STATUS} in="$<"; \ out="$@"; \ if ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${OBJCFLAGS_$<} ${OBJCFLAGS_$@} \ ${DEP_OBJCFLAGS} -c -o $@ $<; then \ ${COMPILE_OK}; \ else \ ${COMPILE_FAILED}; \ fi .m.lib.o: ${COMPILE_LIB_STATUS} in="$<"; \ out="$@"; \ if ${OBJC} ${LIB_CFLAGS} ${OBJCFLAGS} ${CPPFLAGS} ${OBJCFLAGS_$<} \ ${OBJCFLAGS_$@} ${DEP_OBJCFLAGS} -c -o $@ $<; then \ ${COMPILE_LIB_OK}; \ else \ ${COMPILE_LIB_FAILED}; \ fi .m.amigalib.o: ${COMPILE_AMIGA_LIB_STATUS} in="$<"; \ out="$@"; \ if ${OBJC} ${AMIGA_LIB_CFLAGS} ${OBJCFLAGS} ${CPPFLAGS} \ ${OBJCFLAGS_$<} ${OBJCFLAGS_$@} ${DEP_OBJCFLAGS} -c -o $@ $<; then \ ${COMPILE_AMIGA_LIB_OK}; \ else \ ${COMPILE_AMIGA_LIB_FAILED}; \ fi .m.plugin.o: ${COMPILE_PLUGIN_STATUS} in="$<"; \ out="$@"; \ if ${OBJC} ${PLUGIN_CFLAGS} ${OBJCFLAGS} ${CPPFLAGS} ${OBJCFLAGS_$<} \ ${OBJCFLAGS_$@} ${DEP_OBJCFLAGS} -c -o $@ $<; then \ ${COMPILE_PLUGIN_OK}; \ else \ ${COMPILE_PLUGIN_FAILED}; \ fi .mm.o: ${COMPILE_STATUS} in="$<"; \ out="$@"; \ if ${OBJCXX} ${OBJCXXFLAGS} ${CPPFLAGS} ${OBJCXXFLAGS_$<} \ ${OBJCXXFLAGS_$@} ${DEP_OBJCXXFLAGS} -c -o $@ $<; then \ ${COMPILE_OK}; \ else \ ${COMPILE_FAILED}; \ fi .mm.lib.o: ${COMPILE_LIB_STATUS} in="$<"; \ out="$@"; \ if ${OBJCXX} ${LIB_CFLAGS} ${OBJCXXFLAGS} ${CPPFLAGS} \ ${OBJCXXFLAGS_$<} ${OBJCXXFLAGS_$@} ${DEP_OBJCXXFLAGS} -c -o $@ \ $<; then \ ${COMPILE_LIB_OK}; \ else \ ${COMPILE_LIB_FAILED}; \ fi .mm.amigalib.o: ${COMPILE_AMIGA_LIB_STATUS} in="$<"; \ out="$@"; \ if ${OBJCXX} ${AMIGA_LIB_CFLAGS} ${OBJCXXFLAGS} ${CPPFLAGS} \ ${OBJCXXFLAGS_$<} ${OBJCXXFLAGS_$@} ${DEP_OBJCXXFLAGS} -c -o $@ \ $<; then \ ${COMPILE_AMIGA_LIB_OK}; \ else \ ${COMPILE_AMIGA_LIB_FAILED}; \ fi .mm.plugin.o: ${COMPILE_PLUGIN_STATUS} in="$<"; \ out="$@"; \ if ${OBJCXX} ${PLUGIN_CFLAGS} ${OBJCXXFLAGS} ${CPPFLAGS} \ ${OBJCXXFLAGS_$<} ${OBJCXXFLAGS_$@} ${DEP_OBJCXXFLAGS} -c -o $@ \ $<; then \ ${COMPILE_PLUGIN_OK}; \ else \ ${COMPILE_PLUGIN_FAILED}; \ fi .po.mo: ${COMPILE_STATUS} in="$<"; \ out="$@"; \ if ${MSGFMT} -c -o $@ $<; then \ ${COMPILE_OK}; \ else \ ${COMPILE_FAILED}; \ fi .py.pyc: ${COMPILE_STATUS} in="$<"; \ out="$@"; \ if ${PYTHON} ${PYTHON_FLAGS} -c \ "import py_compile; py_compile.compile('$<')"; then \ ${COMPILE_OK}; \ else \ ${COMPILE_FAILED}; \ fi .rc.o .rc.lib.o .rc.plugin.o: ${COMPILE_STATUS} in="$<"; \ out="$@"; \ if ${RC} ${RCFLAGS} ${CPPFLAGS} -J rc -O coff -o $@ $<; then \ ${COMPILE_OK}; \ else \ ${COMPILE_FAILED}; \ fi .S.o .S.amigalib.o: ${COMPILE_STATUS} in="$<"; \ out="$@"; \ if ${AS} ${ASFLAGS} ${CPPFLAGS} ${ASFLAGS_$<} ${ASFLAGS_$@} \ ${DEP_ASFLAGS} -c -o $@ $<; then \ ${COMPILE_OK}; \ else \ ${COMPILE_FAILED}; \ fi .S.lib.o: ${COMPILE_LIB_STATUS} in="$<"; \ out="$@"; \ if ${AS} ${LIB_CFLAGS} ${ASFLAGS} ${CPPFLAGS} ${ASFLAGS_$<} \ ${ASFLAGS_$@} ${DEP_ASFLAGS} -c -o $@ $<; then \ ${COMPILE_LIB_OK}; \ else \ ${COMPILE_LIB_FAILED}; \ fi .S.plugin.o: ${COMPILE_PLUGIN_STATUS} in="$<"; \ out="$@"; \ if ${AS} ${PLUGIN_CFLAGS} ${ASFLAGS} ${CPPFLAGS} ${ASFLAGS_$<} \ ${ASFLAGS_$@} ${DEP_ASFLAGS} -c -o $@ $<; then \ ${COMPILE_PLUGIN_OK}; \ else \ ${COMPILE_PLUGIN_FAILED}; \ fi .xpm.o: ${COMPILE_STATUS} in="$<"; \ out="$@"; \ if ${CC} ${CFLAGS} ${CPPFLAGS} ${CFLAGS_$<} ${CFLAGS_$@} -x c -c -o $@ \ $<; then \ ${COMPILE_OK}; \ else \ ${COMPILE_FAILED}; \ fi .xpm.lib.o: ${COMPILE_LIB_STATUS} in="$<"; \ out="$@"; \ if ${CC} ${LIB_CFLAGS} ${CFLAGS} ${CPPFLAGS} ${CFLAGS_$<} ${CFLAGS_$@} \ -x c -c -o $@ $<; then \ ${COMPILE_LIB_OK}; \ else \ ${COMPILE_LIB_FAILED}; \ fi .xpm.amigalib.o: ${COMPILE_AMIGA_LIB_STATUS} in="$<"; \ out="$@"; \ if ${CC} ${AMIGA_LIB_CFLAGS} ${CFLAGS} ${CPPFLAGS} ${CFLAGS_$<} \ ${CFLAGS_$@} -x c -c -o $@ $<; then \ ${COMPILE_AMIGA_LIB_OK}; \ else \ ${COMPILE_AMIGA_LIB_FAILED}; \ fi .xpm.plugin.o: ${COMPILE_PLUGIN_STATUS} in="$<"; \ out="$@"; \ if ${CC} ${PLUGIN_CFLAGS} ${CFLAGS} ${CPPFLAGS} ${CFLAGS_$<} \ ${CFLAGS_$@} -x c -c -o $@ $<; then \ ${COMPILE_PLUGIN_OK}; \ else \ ${COMPILE_PLUGIN_FAILED}; \ fi install: all install-extra for i in "" ${SUBDIRS} ${SUBDIRS_AFTER}; do \ test x"$$i" = x"" && continue; \ ${DIR_ENTER}; \ ${MAKE} @MAKEFLAGS_SILENT@ install || exit $$?; \ ${DIR_LEAVE}; \ done for i in "" ${SHARED_LIB}; do \ test x"$$i" = x"" && continue; \ ${INSTALL_STATUS}; \ if ${MKDIR_P} ${DESTDIR}${libdir} @INSTALL_LIB@; then \ ${INSTALL_OK}; \ else \ ${INSTALL_FAILED}; \ fi \ done for i in "" ${FRAMEWORK}; do \ test x"$$i" = x"" && continue; \ ${INSTALL_STATUS}; \ rm -fr ${DESTDIR}${prefix}/Library/Frameworks/$$i; \ if ${MKDIR_P} ${DESTDIR}${prefix}/Library/Frameworks && \ cp -R $$i ${DESTDIR}${prefix}/Library/Frameworks/; then \ ${INSTALL_OK}; \ else \ ${INSTALL_FAILED}; \ fi \ done for i in "" ${AMIGA_LIB}; do \ test x"$$i" = x"" && continue; \ ${INSTALL_STATUS}; \ if ${MKDIR_P} ${DESTDIR}${amigalibdir} && \ ${INSTALL} -m 755 $$i ${DESTDIR}${amigalibdir}/$$i; then \ ${INSTALL_OK}; \ else \ ${INSTALL_FAILED}; \ fi \ done for i in "" ${STATIC_LIB} ${STATIC_PIC_LIB} ${STATIC_AMIGA_LIB}; do \ test x"$$i" = x"" && continue; \ ${INSTALL_STATUS}; \ if ${MKDIR_P} ${DESTDIR}${libdir} && \ ${INSTALL} -m 644 $$i ${DESTDIR}${libdir}/$$i; then \ ${INSTALL_OK}; \ else \ ${INSTALL_FAILED}; \ fi \ done for i in "" ${PLUGIN}; do \ test x"$$i" = x"" && continue; \ ${INSTALL_STATUS}; \ if ${MKDIR_P} ${DESTDIR}${plugindir} @INSTALL_PLUGIN@; then \ ${INSTALL_OK}; \ else \ ${INSTALL_FAILED}; \ fi \ done for i in "" ${DATA}; do \ test x"$$i" = x"" && continue; \ ${INSTALL_STATUS}; \ if ${MKDIR_P} $$(dirname \ ${DESTDIR}${datadir}/${PACKAGE_NAME}/$$i) && \ ${INSTALL} -m 644 $$i \ ${DESTDIR}${datadir}/${PACKAGE_NAME}/$$i; then \ ${INSTALL_OK}; \ else \ ${INSTALL_FAILED}; \ fi \ done for i in "" ${PROG}; do \ test x"$$i" = x"" && continue; \ ${INSTALL_STATUS}; \ if ${MKDIR_P} ${DESTDIR}${bindir} && \ ${INSTALL} -m 755 $$i ${DESTDIR}${bindir}/$$i; then \ ${INSTALL_OK}; \ else \ ${INSTALL_FAILED}; \ fi \ done if test x"${INSTALL_INCLUDES}" = x"yes"; then \ for i in "" ${INCLUDES}; do \ test x"$$i" = x"" && continue; \ ${INSTALL_STATUS}; \ if ${MKDIR_P} $$(dirname \ ${DESTDIR}${includedir}/${includesubdir}/$$i) && \ ${INSTALL} -m 644 $$i \ ${DESTDIR}${includedir}/${includesubdir}/$$i; then \ ${INSTALL_OK}; \ else \ ${INSTALL_FAILED}; \ fi \ done \ fi for i in "" ${MO_FILES}; do \ test x"$$i" = x"" && continue; \ ${INSTALL_STATUS}; \ dest="${localedir}/$${i%.mo}/LC_MESSAGES/${localename}.mo"; \ dest="${DESTDIR}$$dest"; \ if ${MKDIR_P} ${DESTDIR}${localedir}/$${i%.mo}/LC_MESSAGES && \ ${INSTALL} -m 644 $$i $$dest; then \ ${INSTALL_OK}; \ else \ ${INSTALL_FAILED}; \ fi \ done for i in "" ${MAN}; do \ test x"$$i" = x"" && continue; \ ${INSTALL_STATUS}; \ dest="${DESTDIR}${mandir}/${mansubdir}/$$i"; \ if ${MKDIR_P} ${DESTDIR}${mandir}/${mansubdir} && \ ${INSTALL} -m 644 $$i $$dest; then \ ${INSTALL_OK}; \ else \ ${INSTALL_FAILED}; \ fi \ done install-extra: uninstall: for i in "" ${SUBDIRS} ${SUBDIRS_AFTER}; do \ test x"$$i" = x"" && continue; \ ${DIR_ENTER}; \ ${MAKE} @MAKEFLAGS_SILENT@ uninstall || exit $$?; \ ${DIR_LEAVE}; \ done for i in "" ${SHARED_LIB}; do \ test x"$$i" = x"" && continue; \ if test -f ${DESTDIR}${libdir}/$$i \ -o -f ${DESTDIR}${bindir}/$$i; then \ if : @UNINSTALL_LIB@; then \ ${DELETE_OK}; \ else \ ${DELETE_FAILED}; \ fi \ fi; \ done for i in "" ${FRAMEWORK}; do \ test x"$$i" = x"" && continue; \ if test -d ${DESTDIR}${prefix}/Library/Frameworks/$$i; then \ if rm -fr ${DESTDIR}${prefix}/Library/Frameworks/$$i; \ then \ ${DELETE_OK}; \ else \ ${DELETE_FAILED}; \ fi \ fi \ done rmdir ${DESTDIR}${prefix}/Library/Frameworks >/dev/null 2>&1 || true rmdir ${DESTDIR}${prefix}/Library >/dev/null 2>&1 || true for i in "" ${STATIC_LIB} ${STATIC_PIC_LIB} ${STATIC_AMIGA_LIB}; do \ test x"$$i" = x"" && continue; \ if test -f ${DESTDIR}${libdir}/$$i; then \ if rm -f ${DESTDIR}${libdir}/$$i; then \ ${DELETE_OK}; \ else \ ${DELETE_FAILED}; \ fi \ fi \ done for i in "" ${PLUGIN}; do \ test x"$$i" = x"" && continue; \ if test -e ${DESTDIR}${plugindir}/$$i; then \ if : @UNINSTALL_PLUGIN@; then \ ${DELETE_OK}; \ else \ ${DELETE_FAILED}; \ fi \ fi \ done rmdir ${DESTDIR}${plugindir} >/dev/null 2>&1 || true for i in "" ${DATA}; do \ test x"$$i" = x"" && continue; \ if test -f ${DESTDIR}${datadir}/${PACKAGE_NAME}/$$i; then \ if rm -f ${DESTDIR}${datadir}/${PACKAGE_NAME}/$$i; \ then \ ${DELETE_OK}; \ else \ ${DELETE_FAILED}; \ fi \ fi; \ rmdir "$$(dirname ${DESTDIR}${datadir}/${PACKAGE_NAME}/$$i)" \ >/dev/null 2>&1 || true; \ done rmdir ${DESTDIR}${datadir}/${PACKAGE_NAME} >/dev/null 2>&1 || true for i in "" ${PROG}; do \ test x"$$i" = x"" && continue; \ if test -f ${DESTDIR}${bindir}/$$i; then \ if rm -f ${DESTDIR}${bindir}/$$i; then \ ${DELETE_OK}; \ else \ ${DELETE_FAILED}; \ fi \ fi \ done for i in "" ${INCLUDES}; do \ test x"$$i" = x"" && continue; \ if test -f ${DESTDIR}${includedir}/${includesubdir}/$$i; then \ if rm -f ${DESTDIR}${includedir}/${includesubdir}/$$i; \ then \ ${DELETE_OK}; \ else \ ${DELETE_FAILED}; \ fi \ fi \ done rmdir ${DESTDIR}${includedir}/${includesubdir} >/dev/null 2>&1 || true for i in "" ${MO_FILES}; do \ test x"$$i" = x"" && continue; \ mo="${localedir}/$${i%.mo}/LC_MESSAGES/${localename}.mo"; \ mo="${DESTDIR}$$mo"; \ if test -f $$mo; then \ if rm -f $$mo; then \ ${DELETE_OK}; \ else \ ${DELETE_FAILED}; \ fi \ fi \ done for i in "" ${MAN}; do \ test x"$$i" = x"" && continue; \ if test -f ${DESTDIR}${mandir}/${mansubdir}/$$i; then \ if rm -f ${DESTDIR}${mandir}/${mansubdir}/$$i; then \ ${DELETE_OK}; \ else \ ${DELETE_FAILED}; \ fi \ fi \ done ${MAKE} @MAKEFLAGS_SILENT@ uninstall-extra uninstall-extra: clean: for i in "" ${SUBDIRS} ${SUBDIRS_AFTER}; do \ test x"$$i" = x"" && continue; \ ${DIR_ENTER}; \ ${MAKE} @MAKEFLAGS_SILENT@ clean || exit $$?; \ ${DIR_LEAVE}; \ done : >.deps for i in "" ${DEPS} ${OBJS} ${OBJS_EXTRA} ${LIB_OBJS} \ ${LIB_OBJS_EXTRA} ${AMIGA_LIB_OBJS} ${AMIGA_LIB_OBJS_START} \ ${AMIGA_LIB_OBJS_EXTRA} ${PLUGIN_OBJS} ${PROG} ${PROG_NOINST} \ ${SHARED_LIB} ${SHARED_LIB_NOINST} ${AMIGA_LIB} \ ${AMIGA_LIB_NOINST} ${STATIC_LIB} ${STATIC_LIB_NOINST} \ ${STATIC_PIC_LIB} ${STATIC_PIC_LIB_NOINST} ${STATIC_AMIGA_LIB} \ ${STATIC_AMIGA_LIB_NOINST} ${FRAMEWORK} ${PLUGIN} ${PLUGIN_NOINST} \ ${CLEAN_LIB} ${MO_FILES} ${CLEAN}; do \ test x"$$i" = x"" && continue; \ if test -f $$i -o -d $$i; then \ if rm -fr $$i; then \ ${DELETE_OK}; \ else \ ${DELETE_FAILED}; \ fi \ fi \ done distclean: clean for i in "" ${SUBDIRS} ${SUBDIRS_AFTER}; do \ test x"$$i" = x"" && continue; \ ${DIR_ENTER}; \ ${MAKE} @MAKEFLAGS_SILENT@ distclean || exit $$?; \ ${DIR_LEAVE}; \ done for i in "" ${DISTCLEAN} .deps *~; do \ test x"$$i" = x"" && continue; \ if test -f $$i -o -d $$i; then \ if rm -fr $$i; then \ ${DELETE_OK}; \ else \ ${DELETE_FAILED}; \ fi \ fi \ done print-hierarchy: for i in "" ${SUBDIRS} ${SUBDIRS_AFTER}; do \ test x"$$i" = x"" && continue; \ echo ${PRINT_HIERARCHY_PREFIX}$$i; \ cd $$i || exit $$?; \ ${MAKE} @MAKEFLAGS_SILENT@ PRINT_HIERARCHY_PREFIX=$$i/ \ print-hierarchy || exit $$?; \ cd .. || exit $$?; \ done print-var: printf '%s\n' '${${VAR}}' DIR_ENTER = printf "@TERM_EL@@TERM_SETAF6@Entering directory @TERM_BOLD@%s@TERM_SGR0@@TERM_SETAF6@.@TERM_SGR0@\n" "$$i"; cd $$i || exit $$? DIR_LEAVE = printf "@TERM_EL@@TERM_SETAF6@Leaving directory @TERM_BOLD@%s@TERM_SGR0@@TERM_SETAF6@.@TERM_SGR0@\n" "$$i"; cd .. || exit $$? COMPILE_STATUS = printf "@TERM_EL@@TERM_SETAF3@Compiling @TERM_BOLD@%s@TERM_SGR0@@TERM_SETAF3@...@TERM_SGR0@\r" "$<" COMPILE_OK = printf "@TERM_EL@@TERM_SETAF2@Successfully compiled @TERM_BOLD@%s@TERM_SGR0@@TERM_SETAF2@.@TERM_SGR0@\n" "$<" COMPILE_FAILED = err=$$?; printf "@TERM_EL@@TERM_SETAF1@Failed to compile @TERM_BOLD@%s@TERM_SGR0@@TERM_SETAF1@!@TERM_SGR0@\n" "$<"; exit $$err COMPILE_LIB_STATUS = printf "@TERM_EL@@TERM_SETAF3@Compiling @TERM_BOLD@%s@TERM_SGR0@@TERM_SETAF3@ (lib)...@TERM_SGR0@\r" "$<" COMPILE_LIB_OK = printf "@TERM_EL@@TERM_SETAF2@Successfully compiled @TERM_BOLD@%s@TERM_SGR0@@TERM_SETAF2@ (lib).@TERM_SGR0@\n" "$<" COMPILE_LIB_FAILED = err=$$?; printf "@TERM_EL@@TERM_SETAF1@Failed to compile @TERM_BOLD@%s@TERM_SGR0@@TERM_SETAF1@ (lib)!@TERM_SGR0@\n" "$<"; exit $$err COMPILE_AMIGA_LIB_STATUS = printf "@TERM_EL@@TERM_SETAF3@Compiling @TERM_BOLD@%s@TERM_SGR0@@TERM_SETAF3@ (Amiga lib)...@TERM_SGR0@\r" "$<" COMPILE_AMIGA_LIB_OK = printf "@TERM_EL@@TERM_SETAF2@Successfully compiled @TERM_BOLD@%s@TERM_SGR0@@TERM_SETAF2@ (Amiga lib).@TERM_SGR0@\n" "$<" COMPILE_AMIGA_LIB_FAILED = err=$$?; printf "@TERM_EL@@TERM_SETAF1@Failed to compile @TERM_BOLD@%s@TERM_SGR0@@TERM_SETAF1@ (Amiga lib)!@TERM_SGR0@\n" "$<"; exit $$err COMPILE_PLUGIN_STATUS = printf "@TERM_EL@@TERM_SETAF3@Compiling @TERM_BOLD@%s@TERM_SGR0@@TERM_SETAF3@ (plugin)...@TERM_SGR0@\r" "$<" COMPILE_PLUGIN_OK = printf "@TERM_EL@@TERM_SETAF2@Successfully compiled @TERM_BOLD@%s@TERM_SGR0@@TERM_SETAF2@ (plugin).@TERM_SGR0@\n" "$<" COMPILE_PLUGIN_FAILED = err=$$?; printf "@TERM_EL@@TERM_SETAF1@Failed to compile @TERM_BOLD@%s@TERM_SGR0@@TERM_SETAF1@ (plugin)!@TERM_SGR0@\n" "$<"; exit $$err LINK_STATUS = printf "@TERM_EL@@TERM_SETAF3@Linking @TERM_BOLD@$@@TERM_SGR0@@TERM_SETAF3@...@TERM_SGR0@\r" LINK_OK = printf "@TERM_EL@@TERM_SETAF2@Successfully linked @TERM_BOLD@$@@TERM_SGR0@@TERM_SETAF2@.@TERM_SGR0@\n" LINK_FAILED = err=$$?; printf "@TERM_EL@@TERM_SETAF1@Failed to link @TERM_BOLD@$@@TERM_SGR0@@TERM_SETAF1@!@TERM_SGR0@\n"; exit $$err INSTALL_STATUS = printf "@TERM_EL@@TERM_SETAF3@Installing @TERM_BOLD@%s@TERM_SGR0@@TERM_SETAF3@...@TERM_SGR0@\r" "$$i" INSTALL_OK = printf "@TERM_EL@@TERM_SETAF2@Successfully installed @TERM_BOLD@%s@TERM_SGR0@@TERM_SETAF2@.@TERM_SGR0@\n" "$$i" INSTALL_FAILED = err=$$?; printf "@TERM_EL@@TERM_SETAF1@Failed to install @TERM_BOLD@%s@TERM_SGR0@@TERM_SETAF1@!@TERM_SGR0@\n" "$$i"; exit $$err DELETE_OK = printf "@TERM_EL@@TERM_SETAF4@Deleted @TERM_BOLD@%s@TERM_SGR0@@TERM_SETAF4@.@TERM_SGR0@\n" "$$i" DELETE_FAILED = err=$$?; printf "@TERM_EL@@TERM_SETAF1@Failed to delete @TERM_BOLD@%s@TERM_SGR0@@TERM_SETAF1@!@TERM_SGR0@\n" "$$i"; exit $$err .CURDIR ?= . -include ${.CURDIR}/.deps objfw-1.1.6/config.h.in000066400000000000000000000344221465614216400146670ustar00rootroot00000000000000/* config.h.in. Generated from configure.ac by autoheader. */ /* Define if building universal (internal helper macro) */ #undef AC_APPLE_UNIVERSAL_BUILD /* Define to 1 if you have the `accept4' function. */ #undef HAVE_ACCEPT4 /* Define to 1 if you have the header file. */ #undef HAVE_AFUNIX_H /* Define to 1 if you have the `arc4random' function. */ #undef HAVE_ARC4RANDOM /* Define to 1 if you have the `arc4random_buf' function. */ #undef HAVE_ARC4RANDOM_BUF /* Define to 1 if you have the header file. */ #undef HAVE_ARPA_INET_H /* Whether we have asprintf() */ #undef HAVE_ASPRINTF /* Define to 1 if you have the `asprintf_l' function. */ #undef HAVE_ASPRINTF_L /* Whether we have blx */ #undef HAVE_BLX /* Whether we have bti */ #undef HAVE_BTI /* Define to 1 if you have the header file. */ #undef HAVE_CET_H /* Whether we have support for Codepage 437 */ #undef HAVE_CODEPAGE_437 /* Whether we have support for Codepage 850 */ #undef HAVE_CODEPAGE_850 /* Whether we have support for Codepage 858 */ #undef HAVE_CODEPAGE_858 /* Define to 1 if you have the header file. */ #undef HAVE_COMPLEX_H /* Define to 1 if you have the header file. */ #undef HAVE_DIRENT_H /* Define to 1 if you have the `dladdr' function. */ #undef HAVE_DLADDR /* Define to 1 if you have the header file. */ #undef HAVE_DLFCN_H /* Define to 1 if you have the `dup2' function. */ #undef HAVE_DUP2 /* Whether DWARF exceptions are used */ #undef HAVE_DWARF_EXCEPTIONS /* Whether we have epoll */ #undef HAVE_EPOLL /* Define to 1 if you have the `epoll_create' function. */ #undef HAVE_EPOLL_CREATE /* Define to 1 if you have the `epoll_create1' function. */ #undef HAVE_EPOLL_CREATE1 /* Define to 1 if you have the `execvp' function. */ #undef HAVE_EXECVP /* Define to 1 if you have the `fcntl' function. */ #undef HAVE_FCNTL /* Define to 1 if you have the header file. */ #undef HAVE_FCNTL_H /* Define to 1 if you have the `getrandom' function. */ #undef HAVE_GETRANDOM /* Define to 1 if you have the `gmtime_r' function. */ #undef HAVE_GMTIME_R /* Define to 1 if you have the header file. */ #undef HAVE_GRP_H /* Define to 1 if you have the `if_indextoname' function. */ #undef HAVE_IF_INDEXTONAME /* Define to 1 if you have the `if_nameindex' function. */ #undef HAVE_IF_NAMEINDEX /* Define to 1 if you have the `if_nametoindex' function. */ #undef HAVE_IF_NAMETOINDEX /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H /* Define to 1 if you have the `ioctl' function. */ #undef HAVE_IOCTL /* Define to 1 if you have the `isatty' function. */ #undef HAVE_ISATTY /* Whether we have support for ISO 8859-15 */ #undef HAVE_ISO_8859_15 /* Whether we have support for ISO 8859-2 */ #undef HAVE_ISO_8859_2 /* Whether we have support for ISO 8859-3 */ #undef HAVE_ISO_8859_3 /* Define to 1 if you have the `kill' function. */ #undef HAVE_KILL /* Whether we have support for KOI8-R */ #undef HAVE_KOI8_R /* Whether we have support for KOI8-U */ #undef HAVE_KOI8_U /* Whether we have kqueue */ #undef HAVE_KQUEUE /* Define to 1 if you have the `kqueue1' function. */ #undef HAVE_KQUEUE1 /* Define to 1 if you have the `localtime_r' function. */ #undef HAVE_LOCALTIME_R /* Define to 1 if you have the `lseek64' function. */ #undef HAVE_LSEEK64 /* Define to 1 if you have the `lstat' function. */ #undef HAVE_LSTAT /* Define to 1 if you have the `lstat64' function. */ #undef HAVE_LSTAT64 /* Whether we have support for Mac Roman encoding */ #undef HAVE_MAC_ROMAN /* Define to 1 if you have the `mlock' function. */ #undef HAVE_MLOCK /* Define to 1 if you have the `mmap' function. */ #undef HAVE_MMAP /* Define to 1 if you have the `nanosleep' function. */ #undef HAVE_NANOSLEEP /* Define to 1 if you have the header file. */ #undef HAVE_NETDB_H /* Define to 1 if you have the header file. */ #undef HAVE_NET_IF_ARP_H /* Define to 1 if you have the header file. */ #undef HAVE_NET_IF_DL_H /* Define to 1 if you have the header file. */ #undef HAVE_NET_IF_H /* Define to 1 if you have the header file. */ #undef HAVE_NET_IF_TYPES_H /* Define to 1 if you have the `objc_setAssociatedObject' function. */ #undef HAVE_OBJC_SETASSOCIATEDOBJECT /* Define to 1 if you have the `open64' function. */ #undef HAVE_OPEN64 /* Define to 1 if you have the `paccept' function. */ #undef HAVE_PACCEPT /* Whether we have poll() */ #undef HAVE_POLL /* Define to 1 if you have the header file. */ #undef HAVE_POLL_H /* Define to 1 if you have the `posix_spawnp' function. */ #undef HAVE_POSIX_SPAWNP /* Define to 1 if you have the `pthread_attr_getschedpolicy' function. */ #undef HAVE_PTHREAD_ATTR_GETSCHEDPOLICY /* Whether we have pthread_attr_setinheritsched */ #undef HAVE_PTHREAD_ATTR_SETINHERITSCHED /* Define to 1 if you have the header file. */ #undef HAVE_PTHREAD_NP_H /* Define to 1 if you have the `pthread_setname_np' function. */ #undef HAVE_PTHREAD_SETNAME_NP /* Define to 1 if you have the `pthread_set_name_np' function. */ #undef HAVE_PTHREAD_SET_NAME_NP /* Define to 1 if you have the header file. */ #undef HAVE_PWD_H /* Define to 1 if you have the `random' function. */ #undef HAVE_RANDOM /* Define to 1 if you have the header file. */ #undef HAVE_SECURITY_SECURETRANSPORT_H /* Whether SEH exceptions are used */ #undef HAVE_SEH_EXCEPTIONS /* Whether we have select() or similar */ #undef HAVE_SELECT /* Whether SjLj exceptions are used */ #undef HAVE_SJLJ_EXCEPTIONS /* Define to 1 if you have the header file. */ #undef HAVE_SPAWN_H /* Define to 1 if you have the `SSLCreateContext' function. */ #undef HAVE_SSLCREATECONTEXT /* Define to 1 if you have the `SSL_has_pending' function. */ #undef HAVE_SSL_HAS_PENDING /* Define to 1 if you have the `stat64' function. */ #undef HAVE_STAT64 /* Define to 1 if you have the header file. */ #undef HAVE_STDINT_H /* Define to 1 if you have the header file. */ #undef HAVE_STDIO_H /* Define to 1 if you have the header file. */ #undef HAVE_STDLIB_H /* Define to 1 if you have the `strerror_r' function. */ #undef HAVE_STRERROR_R /* Define to 1 if you have the header file. */ #undef HAVE_STRINGS_H /* Define to 1 if you have the header file. */ #undef HAVE_STRING_H /* Define to 1 if you have the `strtod_l' function. */ #undef HAVE_STRTOD_L /* Define to 1 if you have the `strtof' function. */ #undef HAVE_STRTOF /* Define to 1 if you have the `strtof_l' function. */ #undef HAVE_STRTOF_L /* Define to 1 if `ifr_hwaddr' is a member of `struct ifreq'. */ #undef HAVE_STRUCT_IFREQ_IFR_HWADDR /* Define to 1 if the system has the type `struct lifconf'. */ #undef HAVE_STRUCT_LIFCONF /* Define to 1 if the system has the type `struct sockaddr_dl'. */ #undef HAVE_STRUCT_SOCKADDR_DL /* Define to 1 if `sa_len' is a member of `struct sockaddr'. */ #undef HAVE_STRUCT_SOCKADDR_SA_LEN /* Define to 1 if `sun_len' is a member of `struct sockaddr_un'. */ #undef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN /* Define to 1 if `st_birthtime' is a member of `struct stat'. */ #undef HAVE_STRUCT_STAT_ST_BIRTHTIME /* Define to 1 if you have the `sysconf' function. */ #undef HAVE_SYSCONF /* Define to 1 if you have the header file. */ #undef HAVE_SYSDIR_H /* Define to 1 if you have the `sysdir_start_search_path_enumeration' function. */ #undef HAVE_SYSDIR_START_SEARCH_PATH_ENUMERATION /* Define to 1 if you have the header file. */ #undef HAVE_SYS_IOCTL_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_MMAN_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_SELECT_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_SOCKIO_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_STAT_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TTYCOM_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TYPES_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_UTSNAME_H /* Define to 1 if you have that is POSIX.1 compatible. */ #undef HAVE_SYS_WAIT_H /* Whether we have an implementation for TLS */ #undef HAVE_TLS_SUPPORT /* Define to 1 if you have the `truncf' function. */ #undef HAVE_TRUNCF /* Define to 1 if you have the `uname' function. */ #undef HAVE_UNAME /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H /* Define to 1 if you have the `uselocale' function. */ #undef HAVE_USELOCALE /* Define to 1 if you have the `vfork' function. */ #undef HAVE_VFORK /* Whether we have VFP2 or above */ #undef HAVE_VFP2 /* Whether we have support for Windows-1251 */ #undef HAVE_WINDOWS_1251 /* Whether we have support for Windows-1252 */ #undef HAVE_WINDOWS_1252 /* Define to 1 if you have the header file. */ #undef HAVE_XLOCALE_H /* Define to 1 if you have the `_exit' function. */ #undef HAVE__EXIT /* Define to 1 if you have the `_Unwind_Backtrace' function. */ #undef HAVE__UNWIND_BACKTRACE /* Define to 1 if you have the `_Unwind_GetDataRelBase' function. */ #undef HAVE__UNWIND_GETDATARELBASE /* Define to 1 if you have the `_Unwind_GetTextRelBase' function. */ #undef HAVE__UNWIND_GETTEXTRELBASE /* The major version of ObjFW */ #undef OBJFW_VERSION_MAJOR /* The minor version of ObjFW */ #undef OBJFW_VERSION_MINOR /* Whether we use the Apple ObjC runtime */ #undef OF_APPLE_RUNTIME /* Whether we are big endian */ #undef OF_BIG_ENDIAN /* Whether we are compiling for classic macOS */ #undef OF_CLASSIC_MACOS /* Whether floats are big endian */ #undef OF_FLOAT_BIG_ENDIAN /* Whether we have afunix.h */ #undef OF_HAVE_AFUNIX_H /* Whether we have AppleTalk */ #undef OF_HAVE_APPLETALK /* Whether __atomic_* builtins are available */ #undef OF_HAVE_ATOMIC_BUILTINS /* Whether we have atomic operations */ #undef OF_HAVE_ATOMIC_OPS /* Whether we have __builtin_bswap16 */ #undef OF_HAVE_BUILTIN_BSWAP16 /* Whether we have __builtin_bswap32 */ #undef OF_HAVE_BUILTIN_BSWAP32 /* Whether we have __builtin_bswap64 */ #undef OF_HAVE_BUILTIN_BSWAP64 /* Whether we have chmod() */ #undef OF_HAVE_CHMOD /* Whether we have chown() */ #undef OF_HAVE_CHOWN /* Whether we have files */ #undef OF_HAVE_FILES /* Whether we have inttypes.h */ #undef OF_HAVE_INTTYPES_H /* Whether we have IPv6 */ #undef OF_HAVE_IPV6 /* Whether we have IPX/SPX */ #undef OF_HAVE_IPX /* Whether we have link() */ #undef OF_HAVE_LINK /* Whether we have netatalk/at.h */ #undef OF_HAVE_NETATALK_AT_H /* Whether we have netat/appletalk.h */ #undef OF_HAVE_NETAT_APPLETALK_H /* Whether we have netinet/in.h */ #undef OF_HAVE_NETINET_IN_H /* Whether we have netinet/tcp.h */ #undef OF_HAVE_NETINET_TCP_H /* Whether we have netipx/ipx.h */ #undef OF_HAVE_NETIPX_IPX_H /* Whether we have off64_t */ #undef OF_HAVE_OFF64_T /* Whether we have libkern/OSAtomic.h */ #undef OF_HAVE_OSATOMIC /* Whether we have pipe() */ #undef OF_HAVE_PIPE /* Whether we have pledge() */ #undef OF_HAVE_PLEDGE /* Whether we have plugin support */ #undef OF_HAVE_PLUGINS /* Whether we have pthreads */ #undef OF_HAVE_PTHREADS /* Whether we have pthread spinlocks */ #undef OF_HAVE_PTHREAD_SPINLOCKS /* If pthread mutexes can be recursive */ #undef OF_HAVE_RECURSIVE_PTHREAD_MUTEXES /* Whether we have sched_yield() */ #undef OF_HAVE_SCHED_YIELD /* Whether we have struct sockaddr_storage */ #undef OF_HAVE_SOCKADDR_STORAGE /* Whether we have sockets */ #undef OF_HAVE_SOCKETS /* Whether we have stdnoreturn.h */ #undef OF_HAVE_STDNORETURN_H /* Whether we have subprocesses */ #undef OF_HAVE_SUBPROCESSES /* Whether we have symlink() */ #undef OF_HAVE_SYMLINK /* Whether __sync_* builtins are available */ #undef OF_HAVE_SYNC_BUILTINS /* Whether we have sys/socket.h */ #undef OF_HAVE_SYS_SOCKET_H /* Whether we have sys/types.h */ #undef OF_HAVE_SYS_TYPES_H /* Whether we have sys/un.h */ #undef OF_HAVE_SYS_UN_H /* Whether we have threads */ #undef OF_HAVE_THREADS /* Whether we have threads.h */ #undef OF_HAVE_THREADS_H /* Whether to build with Unicode tables */ #undef OF_HAVE_UNICODE_TABLES /* Whether we have UNIX sockets */ #undef OF_HAVE_UNIX_SOCKETS /* Whether _Thread_local works */ #undef OF_HAVE__THREAD_LOCAL /* Whether __thread works */ #undef OF_HAVE___THREAD /* Whether we are compiling for Nintendo 3DS */ #undef OF_NINTENDO_3DS /* Whether we are compiling for Nintendo DS */ #undef OF_NINTENDO_DS /* Whether we are compiling for Nintendo Switch */ #undef OF_NINTENDO_SWITCH /* Whether no shared library was built */ #undef OF_NO_SHARED /* Whether we use the ObjFW runtime */ #undef OF_OBJFW_RUNTIME /* Whether to use 24 bit selector UIDs */ #undef OF_SELUID24 /* Whether we are building a universal binary */ #undef OF_UNIVERSAL /* Whether we are compiling for Wii */ #undef OF_WII /* Whether we are compiling for Wii U */ #undef OF_WII_U /* Define to the address where bug reports for this package should be sent. */ #undef PACKAGE_BUGREPORT /* Define to the full name of this package. */ #undef PACKAGE_NAME /* Define to the full name and version of this package. */ #undef PACKAGE_STRING /* Define to the one symbol short name of this package. */ #undef PACKAGE_TARNAME /* Define to the home page for this package. */ #undef PACKAGE_URL /* Define to the version of this package. */ #undef PACKAGE_VERSION /* Suffix for plugins */ #undef PLUGIN_SUFFIX /* The size of `double', as computed by sizeof. */ #undef SIZEOF_DOUBLE /* The size of `float', as computed by sizeof. */ #undef SIZEOF_FLOAT /* The size of `uintptr_t', as computed by sizeof. */ #undef SIZEOF_UINTPTR_T /* Maximum value for ssize_t */ #undef SSIZE_MAX /* Define to 1 if all of the C90 standard headers exist (not just the ones required in a freestanding environment). This macro is provided for backward compatibility; new code need not use it. */ #undef STDC_HEADERS /* Whether strerror_r returns char * */ #undef STRERROR_R_RETURNS_CHARP /* Maximum value for uintptr_t */ #undef UINTPTR_MAX /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel). */ #if defined AC_APPLE_UNIVERSAL_BUILD # if defined __BIG_ENDIAN__ # define WORDS_BIGENDIAN 1 # endif #else # ifndef WORDS_BIGENDIAN # undef WORDS_BIGENDIAN # endif #endif objfw-1.1.6/configure000077500000000000000000011240261465614216400145540ustar00rootroot00000000000000#! /bin/sh # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.71 for ObjFW 1.1.6. # # Report bugs to . # # # Copyright (C) 1992-1996, 1998-2017, 2020-2021 Free Software Foundation, # Inc. # # # This configure script is free software; the Free Software Foundation # gives unlimited permission to copy, distribute and modify it. ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh as_nop=: if test ${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1 then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else $as_nop case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi # Reset variables that may have inherited troublesome values from # the environment. # IFS needs to be set, to space, tab, and newline, in precisely that order. # (If _AS_PATH_WALK were called with IFS unset, it would have the # side effect of setting IFS to empty, thus disabling word splitting.) # Quoting is to prevent editors from complaining about space-tab. as_nl=' ' export as_nl IFS=" "" $as_nl" PS1='$ ' PS2='> ' PS4='+ ' # Ensure predictable behavior from utilities with locale-dependent output. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # We cannot yet rely on "unset" to work, but we need these variables # to be unset--not just set to an empty or harmless value--now, to # avoid bugs in old shells (e.g. pre-3.0 UWIN ksh). This construct # also avoids known problems related to "unset" and subshell syntax # in other old shells (e.g. bash 2.01 and pdksh 5.2.14). for as_var in BASH_ENV ENV MAIL MAILPATH CDPATH do eval test \${$as_var+y} \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done # Ensure that fds 0, 1, and 2 are open. if (exec 3>&0) 2>/dev/null; then :; else exec 0&1) 2>/dev/null; then :; else exec 1>/dev/null; fi if (exec 3>&2) ; then :; else exec 2>/dev/null; fi # The user is always right. if ${PATH_SEPARATOR+false} :; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac test -r "$as_dir$0" && as_myself=$as_dir$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as `sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then printf "%s\n" "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Use a proper internal environment variable to ensure we don't fall # into an infinite loop, continuously re-executing ourselves. if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then _as_can_reexec=no; export _as_can_reexec; # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV case $- in # (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. printf "%s\n" "$0: could not re-execute with $CONFIG_SHELL" >&2 exit 255 fi # We don't want this to propagate to other subprocesses. { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="as_nop=: if test \${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1 then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which # is contrary to our usage. Disable this feature. alias -g '\${1+\"\$@\"}'='\"\$@\"' setopt NO_GLOB_SUBST else \$as_nop case \`(set -o) 2>/dev/null\` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi " as_required="as_fn_return () { (exit \$1); } as_fn_success () { as_fn_return 0; } as_fn_failure () { as_fn_return 1; } as_fn_ret_success () { return 0; } as_fn_ret_failure () { return 1; } exitcode=0 as_fn_success || { exitcode=1; echo as_fn_success failed.; } as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } if ( set x; as_fn_ret_success y && test x = \"\$1\" ) then : else \$as_nop exitcode=1; echo positional parameters were not saved. fi test x\$exitcode = x0 || exit 1 blah=\$(echo \$(echo blah)) test x\"\$blah\" = xblah || exit 1 test -x / || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1 test \$(( 1 + 1 )) = 2 || exit 1" if (eval "$as_required") 2>/dev/null then : as_have_required=yes else $as_nop as_have_required=no fi if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null then : else $as_nop as_save_IFS=$IFS; IFS=$PATH_SEPARATOR as_found=false for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac as_found=: case $as_dir in #( /*) for as_base in sh bash ksh sh5; do # Try only shells that exist, to save several forks. as_shell=$as_dir$as_base if { test -f "$as_shell" || test -f "$as_shell.exe"; } && as_run=a "$as_shell" -c "$as_bourne_compatible""$as_required" 2>/dev/null then : CONFIG_SHELL=$as_shell as_have_required=yes if as_run=a "$as_shell" -c "$as_bourne_compatible""$as_suggested" 2>/dev/null then : break 2 fi fi done;; esac as_found=false done IFS=$as_save_IFS if $as_found then : else $as_nop if { test -f "$SHELL" || test -f "$SHELL.exe"; } && as_run=a "$SHELL" -c "$as_bourne_compatible""$as_required" 2>/dev/null then : CONFIG_SHELL=$SHELL as_have_required=yes fi fi if test "x$CONFIG_SHELL" != x then : export CONFIG_SHELL # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV case $- in # (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. printf "%s\n" "$0: could not re-execute with $CONFIG_SHELL" >&2 exit 255 fi if test x$as_have_required = xno then : printf "%s\n" "$0: This script requires a shell more modern than all" printf "%s\n" "$0: the shells that I found on your system." if test ${ZSH_VERSION+y} ; then printf "%s\n" "$0: In particular, zsh $ZSH_VERSION has bugs and should" printf "%s\n" "$0: be upgraded to zsh 4.3.4 or later." else printf "%s\n" "$0: Please tell bug-autoconf@gnu.org and js@nil.im about $0: your system, including any error possibly output before $0: this message. Then install a modern shell, or manually $0: run the script under such a shell if you do have one." fi exit 1 fi fi fi SHELL=${CONFIG_SHELL-/bin/sh} export SHELL # Unset more variables known to interfere with behavior of common tools. CLICOLOR_FORCE= GREP_OPTIONS= unset CLICOLOR_FORCE GREP_OPTIONS ## --------------------- ## ## M4sh Shell Functions. ## ## --------------------- ## # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_nop # --------- # Do nothing but, unlike ":", preserve the value of $?. as_fn_nop () { return $? } as_nop=as_fn_nop # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`printf "%s\n" "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || printf "%s\n" X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p # as_fn_executable_p FILE # ----------------------- # Test if FILE is an executable regular file. as_fn_executable_p () { test -f "$1" && test -x "$1" } # as_fn_executable_p # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null then : eval 'as_fn_append () { eval $1+=\$2 }' else $as_nop as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null then : eval 'as_fn_arith () { as_val=$(( $* )) }' else $as_nop as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith # as_fn_nop # --------- # Do nothing but, unlike ":", preserve the value of $?. as_fn_nop () { return $? } as_nop=as_fn_nop # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi printf "%s\n" "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || printf "%s\n" X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits as_lineno_1=$LINENO as_lineno_1a=$LINENO as_lineno_2=$LINENO as_lineno_2a=$LINENO eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-) sed -n ' p /[$]LINENO/= ' <$as_myself | sed ' s/[$]LINENO.*/&-/ t lineno b :lineno N :loop s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ t loop s/-\n.*// ' >$as_me.lineno && chmod +x "$as_me.lineno" || { printf "%s\n" "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } # If we had to re-execute with $CONFIG_SHELL, we're ensured to have # already done that, so ensure we don't try to do so again and fall # in an infinite loop. This has already happened in practice. _as_can_reexec=no; export _as_can_reexec # Don't try to exec as it changes $[0], causing all sort of problems # (the dirname of $[0] is not the place where we might find the # original and so on. Autoconf is especially sensitive to this). . "./$as_me.lineno" # Exit status is that of the last command. exit } # Determine whether it's possible to make 'echo' print without a newline. # These variables are no longer used directly by Autoconf, but are AC_SUBSTed # for compatibility with existing Makefiles. ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac # For backward compatibility with old third-party macros, we provide # the shell variables $as_echo and $as_echo_n. New code should use # AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively. as_echo='printf %s\n' as_echo_n='printf %s' rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. # In both cases, we have to default to `cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -pR' fi else as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi as_test_x='test -x' as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" # Sed expression to map a string onto a valid variable name. as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" test -n "$DJDIR" || exec 7<&0 &1 # Name of the host. # hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status, # so uname gets run too. ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` # # Initializations. # ac_default_prefix=/usr/local ac_clean_files= ac_config_libobj_dir=. LIBOBJS= cross_compiling=no subdirs= MFLAGS= MAKEFLAGS= # Identity of this package. PACKAGE_NAME='ObjFW' PACKAGE_TARNAME='objfw' PACKAGE_VERSION='1.1.6' PACKAGE_STRING='ObjFW 1.1.6' PACKAGE_BUGREPORT='js@nil.im' PACKAGE_URL='https://objfw.nil.im/' ac_unique_file="src" # Factoring default headers for most tests. ac_includes_default="\ #include #ifdef HAVE_STDIO_H # include #endif #ifdef HAVE_STDLIB_H # include #endif #ifdef HAVE_STRING_H # include #endif #ifdef HAVE_INTTYPES_H # include #endif #ifdef HAVE_STDINT_H # include #endif #ifdef HAVE_STRINGS_H # include #endif #ifdef HAVE_SYS_TYPES_H # include #endif #ifdef HAVE_SYS_STAT_H # include #endif #ifdef HAVE_UNISTD_H # include #endif" ac_header_objc_list= ac_subst_vars='MAKEFLAGS_SILENT SILENT TERM_SETAF6 TERM_SETAF4 TERM_SETAF3 TERM_SETAF2 TERM_SETAF1 TERM_BOLD TERM_SGR0 TERM_EL TPUT AMIGA_LIB_LDFLAGS AMIGA_LIB_CFLAGS DEP_OBJCXXFLAGS DEP_OBJCFLAGS DEP_CXXFLAGS DEP_CFLAGS LTLIBOBJS LIBOBJS TESTS_LIBS OBJFW_OBJCFLAGS OBJFW_CPPFLAGS DEP_ASFLAGS ASFLAGS AS CPP wiiload WRAPPER WINE BIN_PREFIX OF_BLOCK_TESTS_M OBJFWBRIDGE_FRAMEWORK OBJFWBRIDGE_STATIC_LIB OBJFWBRIDGE_SHARED_LIB BRIDGE SUBPROCESS USE_SRCS_SUBPROCESSES OFHTTP_LIBS OFHTTP OFDNS OF_HTTP_CLIENT_TESTS_M OBJFWTLS_FRAMEWORK OBJFWTLS_STATIC_LIB OBJFWTLS_SHARED_LIB TLS_LIBS TLS_CPPFLAGS TLS OF_MBEDTLS_TLS_STREAM_M OF_GNUTLS_TLS_STREAM_M gnutls_LIBS gnutls_CFLAGS PKG_CONFIG_LIBDIR PKG_CONFIG_PATH PKG_CONFIG OF_OPENSSL_TLS_STREAM_M OF_SECURE_TRANSPORT_TLS_STREAM_M OF_SELECT_KERNEL_EVENT_OBSERVER_M OF_POLL_KERNEL_EVENT_OBSERVER_M OF_EPOLL_KERNEL_EVENT_OBSERVER_M OF_KQUEUE_KERNEL_EVENT_OBSERVER_M USE_SRCS_APPLETALK USE_SRCS_IPX USE_SRCS_UNIX_SOCKETS USE_SRCS_SOCKETS OFHASH OFARC OBJFW_NEW USE_SRCS_FILES USE_INCLUDES_ATOMIC OBJC_SYNC USE_SRCS_THREADS ENCODINGS_A ENCODINGS_LIB_A ENCODINGS_SRCS UNICODE_M RUNTIME_ARC_TESTS_M TESTS_STATIC_LIB REEXPORT_RUNTIME_FRAMEWORK REEXPORT_RUNTIME LDFLAGS_REEXPORT RUNTIME_ASSOCIATION_M RUNTIME_INSTANCE_M RUNTIME_AUTORELEASE_M LIBOBJFWRT_DEP_LVL2 LIBOBJFWRT_DEP RUNTIME_LIBS RUNTIME_FRAMEWORK_LIBS OBJFWRT_FRAMEWORK OBJFWRT_STATIC_LIB OBJFWRT_SHARED_LIB RUNTIME USE_SRCS_TAGGED_POINTERS TESTPLUGIN_LIBS TESTPLUGIN USE_SRCS_PLUGINS LOOKUP_ASM_A FORWARDING_A EXCEPTIONS_A OBJFW_STATIC_LIB LIBOBJFW_DEP_LVL2 LIBOBJFW_DEP OBJFW_FRAMEWORK FRAMEWORK_LIBS FRAMEWORK_LDFLAGS_INSTALL_NAME FRAMEWORK_LDFLAGS LOOKUP_ASM_LIB_A FORWARDING_LIB_A EXCEPTIONS_LIB_A OBJFW_SHARED_LIB UNINSTALL_PLUGIN INSTALL_PLUGIN LINK_PLUGIN PLUGIN_SUFFIX PLUGIN_LDFLAGS PLUGIN_CFLAGS CLEAN_LIB UNINSTALL_LIB INSTALL_LIB LDFLAGS_RPATH LINK_LIB LIB_SUFFIX LIB_PREFIX LIB_LDFLAGS_INSTALL_NAME LIB_LDFLAGS LIB_CFLAGS RC RANLIB AR WII_U_TESTS_LIBS CODESIGN HOST_IS_IOS LN_S SED EGREP GREP OBJCPP OBJEXT EXEEXT ac_ct_OBJC CPPFLAGS LDFLAGS OBJCFLAGS OBJC MAP_LDFLAGS USE_SRCS_WINDOWS LIBBASES_M INSTALL_DATA INSTALL_SCRIPT INSTALL_PROGRAM BUILD_AND_HOST_ARE_DARWIN host_os host_vendor host_cpu host build_os build_vendor build_cpu build BUNDLE_SHORT_VERSION BUNDLE_VERSION target_alias host_alias build_alias LIBS ECHO_T ECHO_N ECHO_C DEFS mandir localedir libdir psdir pdfdir dvidir htmldir infodir docdir oldincludedir includedir runstatedir localstatedir sharedstatedir sysconfdir datadir datarootdir libexecdir sbindir bindir program_transform_name prefix exec_prefix PACKAGE_URL PACKAGE_BUGREPORT PACKAGE_STRING PACKAGE_VERSION PACKAGE_TARNAME PACKAGE_NAME PATH_SEPARATOR SHELL' ac_subst_files='' ac_user_opts=' enable_option_checking enable_rpath enable_silent_rules with_wii with_wii_u with_nds with_3ds with_nintendo_switch enable_shared enable_static enable_runtime enable_seluid24 enable_unicode_tables enable_codepage_437 enable_codepage_850 enable_codepage_858 enable_iso_8859_2 enable_iso_8859_3 enable_iso_8859_15 enable_koi8_r enable_koi8_u enable_mac_roman enable_windows_1251 enable_windows_1252 enable_threads enable_compiler_tls enable_files enable_sockets with_tls enable_werror ' ac_precious_vars='build_alias host_alias target_alias OBJC OBJCFLAGS LDFLAGS LIBS CPPFLAGS OBJCPP PKG_CONFIG PKG_CONFIG_PATH PKG_CONFIG_LIBDIR gnutls_CFLAGS gnutls_LIBS' # Initialize some variables set by options. ac_init_help= ac_init_version=false ac_unrecognized_opts= ac_unrecognized_sep= # The variables have the same names as the options, with # dashes changed to underlines. cache_file=/dev/null exec_prefix=NONE no_create= no_recursion= prefix=NONE program_prefix=NONE program_suffix=NONE program_transform_name=s,x,x, silent= site= srcdir= verbose= x_includes=NONE x_libraries=NONE # Installation directory options. # These are left unexpanded so users can "make install exec_prefix=/foo" # and all the variables that are supposed to be based on exec_prefix # by default will actually change. # Use braces instead of parens because sh, perl, etc. also accept them. # (The list follows the same order as the GNU Coding Standards.) bindir='${exec_prefix}/bin' sbindir='${exec_prefix}/sbin' libexecdir='${exec_prefix}/libexec' datarootdir='${prefix}/share' datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' infodir='${datarootdir}/info' htmldir='${docdir}' dvidir='${docdir}' pdfdir='${docdir}' psdir='${docdir}' libdir='${exec_prefix}/lib' localedir='${datarootdir}/locale' mandir='${datarootdir}/man' ac_prev= ac_dashdash= for ac_option do # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then eval $ac_prev=\$ac_option ac_prev= continue fi case $ac_option in *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; *=) ac_optarg= ;; *) ac_optarg=yes ;; esac case $ac_dashdash$ac_option in --) ac_dashdash=yes ;; -bindir | --bindir | --bindi | --bind | --bin | --bi) ac_prev=bindir ;; -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) bindir=$ac_optarg ;; -build | --build | --buil | --bui | --bu) ac_prev=build_alias ;; -build=* | --build=* | --buil=* | --bui=* | --bu=*) build_alias=$ac_optarg ;; -cache-file | --cache-file | --cache-fil | --cache-fi \ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) ac_prev=cache_file ;; -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) cache_file=$ac_optarg ;; --config-cache | -C) cache_file=config.cache ;; -datadir | --datadir | --datadi | --datad) ac_prev=datadir ;; -datadir=* | --datadir=* | --datadi=* | --datad=*) datadir=$ac_optarg ;; -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ | --dataroo | --dataro | --datar) ac_prev=datarootdir ;; -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) datarootdir=$ac_optarg ;; -disable-* | --disable-*) ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: \`$ac_useropt'" ac_useropt_orig=$ac_useropt ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=no ;; -docdir | --docdir | --docdi | --doc | --do) ac_prev=docdir ;; -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) docdir=$ac_optarg ;; -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) ac_prev=dvidir ;; -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) dvidir=$ac_optarg ;; -enable-* | --enable-*) ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: \`$ac_useropt'" ac_useropt_orig=$ac_useropt ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=\$ac_optarg ;; -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ | --exec | --exe | --ex) ac_prev=exec_prefix ;; -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ | --exec=* | --exe=* | --ex=*) exec_prefix=$ac_optarg ;; -gas | --gas | --ga | --g) # Obsolete; use --with-gas. with_gas=yes ;; -help | --help | --hel | --he | -h) ac_init_help=long ;; -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) ac_init_help=recursive ;; -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) ac_init_help=short ;; -host | --host | --hos | --ho) ac_prev=host_alias ;; -host=* | --host=* | --hos=* | --ho=*) host_alias=$ac_optarg ;; -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) ac_prev=htmldir ;; -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ | --ht=*) htmldir=$ac_optarg ;; -includedir | --includedir | --includedi | --included | --include \ | --includ | --inclu | --incl | --inc) ac_prev=includedir ;; -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ | --includ=* | --inclu=* | --incl=* | --inc=*) includedir=$ac_optarg ;; -infodir | --infodir | --infodi | --infod | --info | --inf) ac_prev=infodir ;; -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) infodir=$ac_optarg ;; -libdir | --libdir | --libdi | --libd) ac_prev=libdir ;; -libdir=* | --libdir=* | --libdi=* | --libd=*) libdir=$ac_optarg ;; -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ | --libexe | --libex | --libe) ac_prev=libexecdir ;; -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ | --libexe=* | --libex=* | --libe=*) libexecdir=$ac_optarg ;; -localedir | --localedir | --localedi | --localed | --locale) ac_prev=localedir ;; -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) localedir=$ac_optarg ;; -localstatedir | --localstatedir | --localstatedi | --localstated \ | --localstate | --localstat | --localsta | --localst | --locals) ac_prev=localstatedir ;; -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) localstatedir=$ac_optarg ;; -mandir | --mandir | --mandi | --mand | --man | --ma | --m) ac_prev=mandir ;; -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) mandir=$ac_optarg ;; -nfp | --nfp | --nf) # Obsolete; use --without-fp. with_fp=no ;; -no-create | --no-create | --no-creat | --no-crea | --no-cre \ | --no-cr | --no-c | -n) no_create=yes ;; -no-recursion | --no-recursion | --no-recursio | --no-recursi \ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) no_recursion=yes ;; -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ | --oldin | --oldi | --old | --ol | --o) ac_prev=oldincludedir ;; -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) oldincludedir=$ac_optarg ;; -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) ac_prev=prefix ;; -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) prefix=$ac_optarg ;; -program-prefix | --program-prefix | --program-prefi | --program-pref \ | --program-pre | --program-pr | --program-p) ac_prev=program_prefix ;; -program-prefix=* | --program-prefix=* | --program-prefi=* \ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) program_prefix=$ac_optarg ;; -program-suffix | --program-suffix | --program-suffi | --program-suff \ | --program-suf | --program-su | --program-s) ac_prev=program_suffix ;; -program-suffix=* | --program-suffix=* | --program-suffi=* \ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) program_suffix=$ac_optarg ;; -program-transform-name | --program-transform-name \ | --program-transform-nam | --program-transform-na \ | --program-transform-n | --program-transform- \ | --program-transform | --program-transfor \ | --program-transfo | --program-transf \ | --program-trans | --program-tran \ | --progr-tra | --program-tr | --program-t) ac_prev=program_transform_name ;; -program-transform-name=* | --program-transform-name=* \ | --program-transform-nam=* | --program-transform-na=* \ | --program-transform-n=* | --program-transform-=* \ | --program-transform=* | --program-transfor=* \ | --program-transfo=* | --program-transf=* \ | --program-trans=* | --program-tran=* \ | --progr-tra=* | --program-tr=* | --program-t=*) program_transform_name=$ac_optarg ;; -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) ac_prev=pdfdir ;; -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) pdfdir=$ac_optarg ;; -psdir | --psdir | --psdi | --psd | --ps) ac_prev=psdir ;; -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) psdir=$ac_optarg ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) silent=yes ;; -runstatedir | --runstatedir | --runstatedi | --runstated \ | --runstate | --runstat | --runsta | --runst | --runs \ | --run | --ru | --r) ac_prev=runstatedir ;; -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ | --run=* | --ru=* | --r=*) runstatedir=$ac_optarg ;; -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ | --sbi=* | --sb=*) sbindir=$ac_optarg ;; -sharedstatedir | --sharedstatedir | --sharedstatedi \ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ | --sharedst | --shareds | --shared | --share | --shar \ | --sha | --sh) ac_prev=sharedstatedir ;; -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ | --sha=* | --sh=*) sharedstatedir=$ac_optarg ;; -site | --site | --sit) ac_prev=site ;; -site=* | --site=* | --sit=*) site=$ac_optarg ;; -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) ac_prev=srcdir ;; -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) srcdir=$ac_optarg ;; -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ | --syscon | --sysco | --sysc | --sys | --sy) ac_prev=sysconfdir ;; -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) sysconfdir=$ac_optarg ;; -target | --target | --targe | --targ | --tar | --ta | --t) ac_prev=target_alias ;; -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) target_alias=$ac_optarg ;; -v | -verbose | --verbose | --verbos | --verbo | --verb) verbose=yes ;; -version | --version | --versio | --versi | --vers | -V) ac_init_version=: ;; -with-* | --with-*) ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: \`$ac_useropt'" ac_useropt_orig=$ac_useropt ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=\$ac_optarg ;; -without-* | --without-*) ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: \`$ac_useropt'" ac_useropt_orig=$ac_useropt ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=no ;; --x) # Obsolete; use --with-x. with_x=yes ;; -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ | --x-incl | --x-inc | --x-in | --x-i) ac_prev=x_includes ;; -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) x_includes=$ac_optarg ;; -x-libraries | --x-libraries | --x-librarie | --x-librari \ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) ac_prev=x_libraries ;; -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) x_libraries=$ac_optarg ;; -*) as_fn_error $? "unrecognized option: \`$ac_option' Try \`$0 --help' for more information" ;; *=*) ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` # Reject names that are not valid shell variable names. case $ac_envvar in #( '' | [0-9]* | *[!_$as_cr_alnum]* ) as_fn_error $? "invalid variable name: \`$ac_envvar'" ;; esac eval $ac_envvar=\$ac_optarg export $ac_envvar ;; *) # FIXME: should be removed in autoconf 3.0. printf "%s\n" "$as_me: WARNING: you should use --build, --host, --target" >&2 expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && printf "%s\n" "$as_me: WARNING: invalid host type: $ac_option" >&2 : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" ;; esac done if test -n "$ac_prev"; then ac_option=--`echo $ac_prev | sed 's/_/-/g'` as_fn_error $? "missing argument to $ac_option" fi if test -n "$ac_unrecognized_opts"; then case $enable_option_checking in no) ;; fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; *) printf "%s\n" "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; esac fi # Check all directory arguments for consistency. for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ libdir localedir mandir runstatedir do eval ac_val=\$$ac_var # Remove trailing slashes. case $ac_val in */ ) ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` eval $ac_var=\$ac_val;; esac # Be sure to have absolute directory names. case $ac_val in [\\/$]* | ?:[\\/]* ) continue;; NONE | '' ) case $ac_var in *prefix ) continue;; esac;; esac as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" done # There might be people who depend on the old broken behavior: `$host' # used to hold the argument of --host etc. # FIXME: To remove some day. build=$build_alias host=$host_alias target=$target_alias # FIXME: To remove some day. if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe elif test "x$build_alias" != "x$host_alias"; then cross_compiling=yes fi fi ac_tool_prefix= test -n "$host_alias" && ac_tool_prefix=$host_alias- test "$silent" = yes && exec 6>/dev/null ac_pwd=`pwd` && test -n "$ac_pwd" && ac_ls_di=`ls -di .` && ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || as_fn_error $? "working directory cannot be determined" test "X$ac_ls_di" = "X$ac_pwd_ls_di" || as_fn_error $? "pwd does not report name of working directory" # Find the source files, if location was not specified. if test -z "$srcdir"; then ac_srcdir_defaulted=yes # Try the directory containing this script, then the parent directory. ac_confdir=`$as_dirname -- "$as_myself" || $as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_myself" : 'X\(//\)[^/]' \| \ X"$as_myself" : 'X\(//\)$' \| \ X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || printf "%s\n" X"$as_myself" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` srcdir=$ac_confdir if test ! -r "$srcdir/$ac_unique_file"; then srcdir=.. fi else ac_srcdir_defaulted=no fi if test ! -r "$srcdir/$ac_unique_file"; then test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" fi ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" ac_abs_confdir=`( cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" pwd)` # When building in place, set srcdir=. if test "$ac_abs_confdir" = "$ac_pwd"; then srcdir=. fi # Remove unnecessary trailing slashes from srcdir. # Double slashes in file names in object file debugging info # mess up M-x gdb in Emacs. case $srcdir in */) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; esac for ac_var in $ac_precious_vars; do eval ac_env_${ac_var}_set=\${${ac_var}+set} eval ac_env_${ac_var}_value=\$${ac_var} eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} eval ac_cv_env_${ac_var}_value=\$${ac_var} done # # Report the --help message. # if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF \`configure' configures ObjFW 1.1.6 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. Configuration: -h, --help display this help and exit --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit -q, --quiet, --silent do not print \`checking ...' messages --cache-file=FILE cache test results in FILE [disabled] -C, --config-cache alias for \`--cache-file=config.cache' -n, --no-create do not create output files --srcdir=DIR find the sources in DIR [configure dir or \`..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX [$ac_default_prefix] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] By default, \`make install' will install all the files in \`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify an installation prefix other than \`$ac_default_prefix' using \`--prefix', for instance \`--prefix=\$HOME'. For better control, use the options below. Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root [DATAROOTDIR/doc/objfw] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] --psdir=DIR ps documentation [DOCDIR] _ACEOF cat <<\_ACEOF System types: --build=BUILD configure for building on BUILD [guessed] --host=HOST cross-compile to build programs to run on HOST [BUILD] _ACEOF fi if test -n "$ac_init_help"; then case $ac_init_help in short | recursive ) echo "Configuration of ObjFW 1.1.6:";; esac cat <<\_ACEOF Optional Features: --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --disable-rpath do not use rpath --disable-silent-rules print executed commands during build --disable-shared do not build shared library --enable-static build static library --enable-runtime use the included runtime --enable-seluid24 use 24 bit instead of 16 bit for selector UIDs --disable-unicode-tables Disable Unicode tables --disable-codepage-437 Disables support for Codepage 437 --disable-codepage-850 Disables support for Codepage 850 --disable-codepage-858 Disables support for Codepage 858 --disable-iso-8859-2 Disables support for ISO 8859-2 --disable-iso-8859-3 Disables support for ISO 8859-3 --disable-iso-8859-15 Disables support for ISO 8859-15 --disable-koi8-r Disables support for KOI8-R --disable-koi8-u Disables support for KOI8-U --disable-mac-roman Disables support for Mac Roman encoding --disable-windows-1251 Disables support for Windows-1251 --disable-windows-1252 Disables support for Windows-1252 --disable-threads disable thread support --disable-compiler-tls disable compiler thread local storage --disable-files disable file support --disable-sockets disable socket support --disable-werror do not build with -Werror Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-wii build for Wii --with-wii-u build for Wii U --with-nds build for Nintendo DS --with-3ds build for Nintendo 3DS --with-nintendo-switch build for Nintendo Switch --with-tls enable TLS support using the specified library (yes, openssl, gnutls, securetransport, mbedtls or no) Some influential environment variables: OBJC Objective C compiler command OBJCFLAGS Objective C compiler flags LDFLAGS linker flags, e.g. -L if you have libraries in a nonstandard directory LIBS libraries to pass to the linker, e.g. -l CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if you have headers in a nonstandard directory OBJCPP Objective C preprocessor PKG_CONFIG path to pkg-config utility PKG_CONFIG_PATH directories to add to pkg-config's search path PKG_CONFIG_LIBDIR path overriding pkg-config's built-in search path gnutls_CFLAGS C compiler flags for gnutls, overriding pkg-config gnutls_LIBS linker flags for gnutls, overriding pkg-config Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. Report bugs to . ObjFW home page: . _ACEOF ac_status=$? fi if test "$ac_init_help" = "recursive"; then # If there are subdirs, report their specific --help. for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue test -d "$ac_dir" || { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || continue ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`printf "%s\n" "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`printf "%s\n" "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; esac ;; esac ac_abs_top_builddir=$ac_pwd ac_abs_builddir=$ac_pwd$ac_dir_suffix # for backward compatibility: ac_top_builddir=$ac_top_build_prefix case $srcdir in .) # We are building in place. ac_srcdir=. ac_top_srcdir=$ac_top_builddir_sub ac_abs_top_srcdir=$ac_pwd ;; [\\/]* | ?:[\\/]* ) # Absolute name. ac_srcdir=$srcdir$ac_dir_suffix; ac_top_srcdir=$srcdir ac_abs_top_srcdir=$srcdir ;; *) # Relative name. ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix ac_top_srcdir=$ac_top_build_prefix$srcdir ac_abs_top_srcdir=$ac_pwd/$srcdir ;; esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix cd "$ac_dir" || { ac_status=$?; continue; } # Check for configure.gnu first; this name is used for a wrapper for # Metaconfig's "Configure" on case-insensitive file systems. if test -f "$ac_srcdir/configure.gnu"; then echo && $SHELL "$ac_srcdir/configure.gnu" --help=recursive elif test -f "$ac_srcdir/configure"; then echo && $SHELL "$ac_srcdir/configure" --help=recursive else printf "%s\n" "$as_me: WARNING: no configuration information is in $ac_dir" >&2 fi || ac_status=$? cd "$ac_pwd" || { ac_status=$?; break; } done fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF ObjFW configure 1.1.6 generated by GNU Autoconf 2.71 Copyright (C) 2021 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF exit fi ## ------------------------ ## ## Autoconf initialization. ## ## ------------------------ ## # ac_fn_objc_try_compile LINENO # ----------------------------- # Try to compile conftest.$ac_ext, and return whether this succeeded. ac_fn_objc_try_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack rm -f conftest.$ac_objext conftest.beam if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_objc_werror_flag" || test ! -s conftest.err } && test -s conftest.$ac_objext then : ac_retval=0 else $as_nop printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_objc_try_compile # ac_fn_objc_try_cpp LINENO # ------------------------- # Try to preprocess conftest.$ac_ext, and return whether this succeeded. ac_fn_objc_try_cpp () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if { { ac_try="$ac_cpp conftest.$ac_ext" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } > conftest.i && { test -z "$ac_objc_preproc_warn_flag$ac_objc_werror_flag" || test ! -s conftest.err } then : ac_retval=0 else $as_nop printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_objc_try_cpp # ac_fn_objc_check_header_compile LINENO HEADER VAR INCLUDES # ---------------------------------------------------------- # Tests whether HEADER exists and can be compiled using the include files in # INCLUDES, setting the cache variable VAR accordingly. ac_fn_objc_check_header_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 printf %s "checking for $2... " >&6; } if eval test \${$3+y} then : printf %s "(cached) " >&6 else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 #include <$2> _ACEOF if ac_fn_objc_try_compile "$LINENO" then : eval "$3=yes" else $as_nop eval "$3=no" fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi eval ac_res=\$$3 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 printf "%s\n" "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_objc_check_header_compile # ac_fn_objc_try_link LINENO # -------------------------- # Try to link conftest.$ac_ext, and return whether this succeeded. ac_fn_objc_try_link () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack rm -f conftest.$ac_objext conftest.beam conftest$ac_exeext if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_link") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_objc_werror_flag" || test ! -s conftest.err } && test -s conftest$ac_exeext && { test "$cross_compiling" = yes || test -x conftest$ac_exeext } then : ac_retval=0 else $as_nop printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would # interfere with the next link command; also delete a directory that is # left behind by Apple's compiler. We do this before executing the actions. rm -rf conftest.dSYM conftest_ipa8_conftest.oo eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_objc_try_link # ac_fn_objc_check_func LINENO FUNC VAR # ------------------------------------- # Tests whether FUNC exists, setting the cache variable VAR accordingly ac_fn_objc_check_func () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 printf %s "checking for $2... " >&6; } if eval test \${$3+y} then : printf %s "(cached) " >&6 else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Define $2 to an innocuous variant, in case declares $2. For example, HP-UX 11i declares gettimeofday. */ #define $2 innocuous_$2 /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $2 (); below. */ #include #undef $2 /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char $2 (); /* The GNU C library defines this for functions which it implements to always fail with ENOSYS. Some functions are actually named something starting with __ and the normal name is an alias. */ #if defined __stub_$2 || defined __stub___$2 choke me #endif int main (void) { return $2 (); ; return 0; } _ACEOF if ac_fn_objc_try_link "$LINENO" then : eval "$3=yes" else $as_nop eval "$3=no" fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext fi eval ac_res=\$$3 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 printf "%s\n" "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_objc_check_func # ac_fn_objc_try_run LINENO # ------------------------- # Try to run conftest.$ac_ext, and return whether this succeeded. Assumes that # executables *can* be run. ac_fn_objc_try_run () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; } then : ac_retval=0 else $as_nop printf "%s\n" "$as_me: program exited with status $ac_status" >&5 printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=$ac_status fi rm -rf conftest.dSYM conftest_ipa8_conftest.oo eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_objc_try_run # ac_fn_objc_compute_int LINENO EXPR VAR INCLUDES # ----------------------------------------------- # Tries to find the compile-time value of EXPR in a program that includes # INCLUDES, setting VAR accordingly. Returns whether the value could be # computed ac_fn_objc_compute_int () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if test "$cross_compiling" = yes; then # Depending upon the size, compute the lo and hi bounds. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main (void) { static int test_array [1 - 2 * !(($2) >= 0)]; test_array [0] = 0; return test_array [0]; ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ac_lo=0 ac_mid=0 while :; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main (void) { static int test_array [1 - 2 * !(($2) <= $ac_mid)]; test_array [0] = 0; return test_array [0]; ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ac_hi=$ac_mid; break else $as_nop as_fn_arith $ac_mid + 1 && ac_lo=$as_val if test $ac_lo -le $ac_mid; then ac_lo= ac_hi= break fi as_fn_arith 2 '*' $ac_mid + 1 && ac_mid=$as_val fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext done else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main (void) { static int test_array [1 - 2 * !(($2) < 0)]; test_array [0] = 0; return test_array [0]; ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ac_hi=-1 ac_mid=-1 while :; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main (void) { static int test_array [1 - 2 * !(($2) >= $ac_mid)]; test_array [0] = 0; return test_array [0]; ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ac_lo=$ac_mid; break else $as_nop as_fn_arith '(' $ac_mid ')' - 1 && ac_hi=$as_val if test $ac_mid -le $ac_hi; then ac_lo= ac_hi= break fi as_fn_arith 2 '*' $ac_mid && ac_mid=$as_val fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext done else $as_nop ac_lo= ac_hi= fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext # Binary search between lo and hi bounds. while test "x$ac_lo" != "x$ac_hi"; do as_fn_arith '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo && ac_mid=$as_val cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main (void) { static int test_array [1 - 2 * !(($2) <= $ac_mid)]; test_array [0] = 0; return test_array [0]; ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ac_hi=$ac_mid else $as_nop as_fn_arith '(' $ac_mid ')' + 1 && ac_lo=$as_val fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext done case $ac_lo in #(( ?*) eval "$3=\$ac_lo"; ac_retval=0 ;; '') ac_retval=1 ;; esac else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 static long int longval (void) { return $2; } static unsigned long int ulongval (void) { return $2; } #include #include int main (void) { FILE *f = fopen ("conftest.val", "w"); if (! f) return 1; if (($2) < 0) { long int i = longval (); if (i != ($2)) return 1; fprintf (f, "%ld", i); } else { unsigned long int i = ulongval (); if (i != ($2)) return 1; fprintf (f, "%lu", i); } /* Do not output a trailing newline, as this causes \r\n confusion on some platforms. */ return ferror (f) || fclose (f) != 0; ; return 0; } _ACEOF if ac_fn_objc_try_run "$LINENO" then : echo >>conftest.val; read $3 &5 printf %s "checking for $2... " >&6; } if eval test \${$3+y} then : printf %s "(cached) " >&6 else $as_nop eval "$3=no" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main (void) { if (sizeof ($2)) return 0; ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main (void) { if (sizeof (($2))) return 0; ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : else $as_nop eval "$3=yes" fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi eval ac_res=\$$3 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 printf "%s\n" "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_objc_check_type # ac_fn_objc_check_member LINENO AGGR MEMBER VAR INCLUDES # ------------------------------------------------------- # Tries to find if the field MEMBER exists in type AGGR, after including # INCLUDES, setting cache variable VAR accordingly. ac_fn_objc_check_member () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2.$3" >&5 printf %s "checking for $2.$3... " >&6; } if eval test \${$4+y} then : printf %s "(cached) " >&6 else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $5 int main (void) { static $2 ac_aggr; if (ac_aggr.$3) return 0; ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : eval "$4=yes" else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $5 int main (void) { static $2 ac_aggr; if (sizeof ac_aggr.$3) return 0; ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : eval "$4=yes" else $as_nop eval "$4=no" fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi eval ac_res=\$$4 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 printf "%s\n" "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_objc_check_member ac_configure_args_raw= for ac_arg do case $ac_arg in *\'*) ac_arg=`printf "%s\n" "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; esac as_fn_append ac_configure_args_raw " '$ac_arg'" done case $ac_configure_args_raw in *$as_nl*) ac_safe_unquote= ;; *) ac_unsafe_z='|&;<>()$`\\"*?[ '' ' # This string ends in space, tab. ac_unsafe_a="$ac_unsafe_z#~" ac_safe_unquote="s/ '\\([^$ac_unsafe_a][^$ac_unsafe_z]*\\)'/ \\1/g" ac_configure_args_raw=` printf "%s\n" "$ac_configure_args_raw" | sed "$ac_safe_unquote"`;; esac cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by ObjFW $as_me 1.1.6, which was generated by GNU Autoconf 2.71. Invocation command line was $ $0$ac_configure_args_raw _ACEOF exec 5>>config.log { cat <<_ASUNAME ## --------- ## ## Platform. ## ## --------- ## hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` uname -m = `(uname -m) 2>/dev/null || echo unknown` uname -r = `(uname -r) 2>/dev/null || echo unknown` uname -s = `(uname -s) 2>/dev/null || echo unknown` uname -v = `(uname -v) 2>/dev/null || echo unknown` /usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` /bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` /bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` /usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` /usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` /bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` /bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` _ASUNAME as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac printf "%s\n" "PATH: $as_dir" done IFS=$as_save_IFS } >&5 cat >&5 <<_ACEOF ## ----------- ## ## Core tests. ## ## ----------- ## _ACEOF # Keep a trace of the command line. # Strip out --no-create and --no-recursion so they do not pile up. # Strip out --silent because we don't want to record it for future runs. # Also quote any args containing shell meta-characters. # Make two passes to allow for proper duplicate-argument suppression. ac_configure_args= ac_configure_args0= ac_configure_args1= ac_must_keep_next=false for ac_pass in 1 2 do for ac_arg do case $ac_arg in -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) continue ;; *\'*) ac_arg=`printf "%s\n" "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; esac case $ac_pass in 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; 2) as_fn_append ac_configure_args1 " '$ac_arg'" if test $ac_must_keep_next = true; then ac_must_keep_next=false # Got value, back to normal. else case $ac_arg in *=* | --config-cache | -C | -disable-* | --disable-* \ | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ | -with-* | --with-* | -without-* | --without-* | --x) case "$ac_configure_args0 " in "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; esac ;; -* ) ac_must_keep_next=true ;; esac fi as_fn_append ac_configure_args " '$ac_arg'" ;; esac done done { ac_configure_args0=; unset ac_configure_args0;} { ac_configure_args1=; unset ac_configure_args1;} # When interrupted or exit'd, cleanup temporary files, and complete # config.log. We remove comments because anyway the quotes in there # would cause problems or look ugly. # WARNING: Use '\'' to represent an apostrophe within the trap. # WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. trap 'exit_status=$? # Sanitize IFS. IFS=" "" $as_nl" # Save into config.log some information that might help in debugging. { echo printf "%s\n" "## ---------------- ## ## Cache variables. ## ## ---------------- ##" echo # The following way of writing the cache mishandles newlines in values, ( for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( *${as_nl}ac_space=\ *) sed -n \ "s/'\''/'\''\\\\'\'''\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" ;; #( *) sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) echo printf "%s\n" "## ----------------- ## ## Output variables. ## ## ----------------- ##" echo for ac_var in $ac_subst_vars do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`printf "%s\n" "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac printf "%s\n" "$ac_var='\''$ac_val'\''" done | sort echo if test -n "$ac_subst_files"; then printf "%s\n" "## ------------------- ## ## File substitutions. ## ## ------------------- ##" echo for ac_var in $ac_subst_files do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`printf "%s\n" "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac printf "%s\n" "$ac_var='\''$ac_val'\''" done | sort echo fi if test -s confdefs.h; then printf "%s\n" "## ----------- ## ## confdefs.h. ## ## ----------- ##" echo cat confdefs.h echo fi test "$ac_signal" != 0 && printf "%s\n" "$as_me: caught signal $ac_signal" printf "%s\n" "$as_me: exit $exit_status" } >&5 rm -f core *.core core.conftest.* && rm -f -r conftest* confdefs* conf$$* $ac_clean_files && exit $exit_status ' 0 for ac_signal in 1 2 13 15; do trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal done ac_signal=0 # confdefs.h avoids OS command line length limits that DEFS can exceed. rm -f -r conftest* confdefs.h printf "%s\n" "/* confdefs.h */" > confdefs.h # Predefined preprocessor variables. printf "%s\n" "#define PACKAGE_NAME \"$PACKAGE_NAME\"" >>confdefs.h printf "%s\n" "#define PACKAGE_TARNAME \"$PACKAGE_TARNAME\"" >>confdefs.h printf "%s\n" "#define PACKAGE_VERSION \"$PACKAGE_VERSION\"" >>confdefs.h printf "%s\n" "#define PACKAGE_STRING \"$PACKAGE_STRING\"" >>confdefs.h printf "%s\n" "#define PACKAGE_BUGREPORT \"$PACKAGE_BUGREPORT\"" >>confdefs.h printf "%s\n" "#define PACKAGE_URL \"$PACKAGE_URL\"" >>confdefs.h # Let the site file select an alternate cache file if it wants to. # Prefer an explicitly selected file to automatically selected ones. if test -n "$CONFIG_SITE"; then ac_site_files="$CONFIG_SITE" elif test "x$prefix" != xNONE; then ac_site_files="$prefix/share/config.site $prefix/etc/config.site" else ac_site_files="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" fi for ac_site_file in $ac_site_files do case $ac_site_file in #( */*) : ;; #( *) : ac_site_file=./$ac_site_file ;; esac if test -f "$ac_site_file" && test -r "$ac_site_file"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 printf "%s\n" "$as_me: loading site script $ac_site_file" >&6;} sed 's/^/| /' "$ac_site_file" >&5 . "$ac_site_file" \ || { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "failed to load site script $ac_site_file See \`config.log' for more details" "$LINENO" 5; } fi done if test -r "$cache_file"; then # Some versions of bash will fail to source /dev/null (special files # actually), so we avoid doing that. DJGPP emulates it as a regular file. if test /dev/null != "$cache_file" && test -f "$cache_file"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 printf "%s\n" "$as_me: loading cache $cache_file" >&6;} case $cache_file in [\\/]* | ?:[\\/]* ) . "$cache_file";; *) . "./$cache_file";; esac fi else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 printf "%s\n" "$as_me: creating cache $cache_file" >&6;} >$cache_file fi as_fn_append ac_header_objc_list " stdio.h stdio_h HAVE_STDIO_H" as_fn_append ac_header_objc_list " stdlib.h stdlib_h HAVE_STDLIB_H" as_fn_append ac_header_objc_list " string.h string_h HAVE_STRING_H" as_fn_append ac_header_objc_list " inttypes.h inttypes_h HAVE_INTTYPES_H" as_fn_append ac_header_objc_list " stdint.h stdint_h HAVE_STDINT_H" as_fn_append ac_header_objc_list " strings.h strings_h HAVE_STRINGS_H" as_fn_append ac_header_objc_list " sys/stat.h sys_stat_h HAVE_SYS_STAT_H" as_fn_append ac_header_objc_list " sys/types.h sys_types_h HAVE_SYS_TYPES_H" as_fn_append ac_header_objc_list " unistd.h unistd_h HAVE_UNISTD_H" as_fn_append ac_header_objc_list " dlfcn.h dlfcn_h HAVE_DLFCN_H" as_fn_append ac_header_objc_list " complex.h complex_h HAVE_COMPLEX_H" as_fn_append ac_header_objc_list " sys/ioctl.h sys_ioctl_h HAVE_SYS_IOCTL_H" as_fn_append ac_header_objc_list " sys/ttycom.h sys_ttycom_h HAVE_SYS_TTYCOM_H" # Auxiliary files required by this configure script. ac_aux_files="install-sh config.guess config.sub" # Locations in which to look for auxiliary files. ac_aux_dir_candidates="${srcdir}/build-aux" # Search for a directory containing all of the required auxiliary files, # $ac_aux_files, from the $PATH-style list $ac_aux_dir_candidates. # If we don't find one directory that contains all the files we need, # we report the set of missing files from the *first* directory in # $ac_aux_dir_candidates and give up. ac_missing_aux_files="" ac_first_candidate=: printf "%s\n" "$as_me:${as_lineno-$LINENO}: looking for aux files: $ac_aux_files" >&5 as_save_IFS=$IFS; IFS=$PATH_SEPARATOR as_found=false for as_dir in $ac_aux_dir_candidates do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac as_found=: printf "%s\n" "$as_me:${as_lineno-$LINENO}: trying $as_dir" >&5 ac_aux_dir_found=yes ac_install_sh= for ac_aux in $ac_aux_files do # As a special case, if "install-sh" is required, that requirement # can be satisfied by any of "install-sh", "install.sh", or "shtool", # and $ac_install_sh is set appropriately for whichever one is found. if test x"$ac_aux" = x"install-sh" then if test -f "${as_dir}install-sh"; then printf "%s\n" "$as_me:${as_lineno-$LINENO}: ${as_dir}install-sh found" >&5 ac_install_sh="${as_dir}install-sh -c" elif test -f "${as_dir}install.sh"; then printf "%s\n" "$as_me:${as_lineno-$LINENO}: ${as_dir}install.sh found" >&5 ac_install_sh="${as_dir}install.sh -c" elif test -f "${as_dir}shtool"; then printf "%s\n" "$as_me:${as_lineno-$LINENO}: ${as_dir}shtool found" >&5 ac_install_sh="${as_dir}shtool install -c" else ac_aux_dir_found=no if $ac_first_candidate; then ac_missing_aux_files="${ac_missing_aux_files} install-sh" else break fi fi else if test -f "${as_dir}${ac_aux}"; then printf "%s\n" "$as_me:${as_lineno-$LINENO}: ${as_dir}${ac_aux} found" >&5 else ac_aux_dir_found=no if $ac_first_candidate; then ac_missing_aux_files="${ac_missing_aux_files} ${ac_aux}" else break fi fi fi done if test "$ac_aux_dir_found" = yes; then ac_aux_dir="$as_dir" break fi ac_first_candidate=false as_found=false done IFS=$as_save_IFS if $as_found then : else $as_nop as_fn_error $? "cannot find required auxiliary files:$ac_missing_aux_files" "$LINENO" 5 fi # These three variables are undocumented and unsupported, # and are intended to be withdrawn in a future Autoconf release. # They can cause serious problems if a builder's source tree is in a directory # whose full name contains unusual characters. if test -f "${ac_aux_dir}config.guess"; then ac_config_guess="$SHELL ${ac_aux_dir}config.guess" fi if test -f "${ac_aux_dir}config.sub"; then ac_config_sub="$SHELL ${ac_aux_dir}config.sub" fi if test -f "$ac_aux_dir/configure"; then ac_configure="$SHELL ${ac_aux_dir}configure" fi # Check that the precious variables saved in the cache have kept the same # value. ac_cache_corrupted=false for ac_var in $ac_precious_vars; do eval ac_old_set=\$ac_cv_env_${ac_var}_set eval ac_new_set=\$ac_env_${ac_var}_set eval ac_old_val=\$ac_cv_env_${ac_var}_value eval ac_new_val=\$ac_env_${ac_var}_value case $ac_old_set,$ac_new_set in set,) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 printf "%s\n" "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} ac_cache_corrupted=: ;; ,set) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 printf "%s\n" "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} ac_cache_corrupted=: ;; ,);; *) if test "x$ac_old_val" != "x$ac_new_val"; then # differences in whitespace do not lead to failure. ac_old_val_w=`echo x $ac_old_val` ac_new_val_w=`echo x $ac_new_val` if test "$ac_old_val_w" != "$ac_new_val_w"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 printf "%s\n" "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} ac_cache_corrupted=: else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 printf "%s\n" "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} eval $ac_var=\$ac_old_val fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 printf "%s\n" "$as_me: former value: \`$ac_old_val'" >&2;} { printf "%s\n" "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 printf "%s\n" "$as_me: current value: \`$ac_new_val'" >&2;} fi;; esac # Pass precious variables to config.status. if test "$ac_new_set" = set; then case $ac_new_val in *\'*) ac_arg=$ac_var=`printf "%s\n" "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; *) ac_arg=$ac_var=$ac_new_val ;; esac case " $ac_configure_args " in *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. *) as_fn_append ac_configure_args " '$ac_arg'" ;; esac fi done if $ac_cache_corrupted; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 printf "%s\n" "$as_me: error: changes in the environment can compromise the build" >&2;} as_fn_error $? "run \`${MAKE-make} distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 fi ## -------------------- ## ## Main body of script. ## ## -------------------- ## ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu printf "%s\n" "#define OBJFW_VERSION_MAJOR 1" >>confdefs.h printf "%s\n" "#define OBJFW_VERSION_MINOR 1" >>confdefs.h BUNDLE_VERSION=1.1.6 BUNDLE_SHORT_VERSION=1.1 for i in configure.ac build-aux/m4/*; do if test $i -nt configure then : as_fn_error $? "$i is newer than configure! Run ./autogen.sh!" "$LINENO" 5 fi done # Make sure we can run config.sub. $SHELL "${ac_aux_dir}config.sub" sun4 >/dev/null 2>&1 || as_fn_error $? "cannot run $SHELL ${ac_aux_dir}config.sub" "$LINENO" 5 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking build system type" >&5 printf %s "checking build system type... " >&6; } if test ${ac_cv_build+y} then : printf %s "(cached) " >&6 else $as_nop ac_build_alias=$build_alias test "x$ac_build_alias" = x && ac_build_alias=`$SHELL "${ac_aux_dir}config.guess"` test "x$ac_build_alias" = x && as_fn_error $? "cannot guess build type; you must specify one" "$LINENO" 5 ac_cv_build=`$SHELL "${ac_aux_dir}config.sub" $ac_build_alias` || as_fn_error $? "$SHELL ${ac_aux_dir}config.sub $ac_build_alias failed" "$LINENO" 5 fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5 printf "%s\n" "$ac_cv_build" >&6; } case $ac_cv_build in *-*-*) ;; *) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;; esac build=$ac_cv_build ac_save_IFS=$IFS; IFS='-' set x $ac_cv_build shift build_cpu=$1 build_vendor=$2 shift; shift # Remember, the first character of IFS is used to create $*, # except with old shells: build_os=$* IFS=$ac_save_IFS case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking host system type" >&5 printf %s "checking host system type... " >&6; } if test ${ac_cv_host+y} then : printf %s "(cached) " >&6 else $as_nop if test "x$host_alias" = x; then ac_cv_host=$ac_cv_build else ac_cv_host=`$SHELL "${ac_aux_dir}config.sub" $host_alias` || as_fn_error $? "$SHELL ${ac_aux_dir}config.sub $host_alias failed" "$LINENO" 5 fi fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5 printf "%s\n" "$ac_cv_host" >&6; } case $ac_cv_host in *-*-*) ;; *) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;; esac host=$ac_cv_host ac_save_IFS=$IFS; IFS='-' set x $ac_cv_host shift host_cpu=$1 host_vendor=$2 shift; shift # Remember, the first character of IFS is used to create $*, # except with old shells: host_os=$* IFS=$ac_save_IFS case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac # Find a good install program. We prefer a C program (faster), # so one script is as good as another. But avoid the broken or # incompatible versions: # SysV /etc/install, /usr/sbin/install # SunOS /usr/etc/install # IRIX /sbin/install # AIX /bin/install # AmigaOS /C/install, which installs bootblocks on floppy discs # AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag # AFS /usr/afsws/bin/install, which mishandles nonexistent args # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" # OS/2's system install, which has a completely different semantic # ./install, which can be erroneously created by make from ./install.sh. # Reject install programs that cannot install multiple files. { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5 printf %s "checking for a BSD-compatible install... " >&6; } if test -z "$INSTALL"; then if test ${ac_cv_path_install+y} then : printf %s "(cached) " >&6 else $as_nop as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac # Account for fact that we put trailing slashes in our PATH walk. case $as_dir in #(( ./ | /[cC]/* | \ /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \ /usr/ucb/* ) ;; *) # OSF1 and SCO ODT 3.0 have their own names for install. # Don't use installbsd from OSF since it installs stuff as root # by default. for ac_prog in ginstall scoinst install; do for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_prog$ac_exec_ext"; then if test $ac_prog = install && grep dspmsg "$as_dir$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # AIX install. It has an incompatible calling convention. : elif test $ac_prog = install && grep pwplus "$as_dir$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # program-specific install script used by HP pwplus--don't use. : else rm -rf conftest.one conftest.two conftest.dir echo one > conftest.one echo two > conftest.two mkdir conftest.dir if "$as_dir$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir/" && test -s conftest.one && test -s conftest.two && test -s conftest.dir/conftest.one && test -s conftest.dir/conftest.two then ac_cv_path_install="$as_dir$ac_prog$ac_exec_ext -c" break 3 fi fi fi done done ;; esac done IFS=$as_save_IFS rm -rf conftest.one conftest.two conftest.dir fi if test ${ac_cv_path_install+y}; then INSTALL=$ac_cv_path_install else # As a last resort, use the slow shell script. Don't cache a # value for INSTALL within a source directory, because that will # break other packages using the cache if that directory is # removed, or if the value is a relative name. INSTALL=$ac_install_sh fi fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5 printf "%s\n" "$INSTALL" >&6; } # Use test -z because SunOS4 sh mishandles braces in ${var-val}. # It thinks the first close brace ends the variable substitution. test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' # Check whether --enable-rpath was given. if test ${enable_rpath+y} then : enableval=$enable_rpath; fi # Check whether --enable-silent-rules was given. if test ${enable_silent_rules+y} then : enableval=$enable_silent_rules; fi case "$build_os" in darwin*) case "$host_os" in darwin*) BUILD_AND_HOST_ARE_DARWIN=yes ;; esac ;; esac case "$INSTALL" in ./build-aux/install-sh*) INSTALL="$PWD/$INSTALL" ;; esac check_pedantic="yes" case "$host" in arm-*-riscos*) if test x"$OBJCFLAGS" = x"" then : OBJCFLAGS="-O2 -g" fi flags="-mfloat-abi=softfp -mfpu=vfp -mlibscl" ASFLAGS="$ASFLAGS -mfloat-abi=softfp -mfpu=vfp" OBJCFLAGS="$OBJCFLAGS $flags" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flags" LDFLAGS="$LDFLAGS $flags" enable_shared="no" enable_threads="no" enable_sockets="no" enable_files="no" ;; m68k-*-amigaos*) if test x"$OBJCFLAGS" = x"" then : OBJCFLAGS="-O0 -g" fi OBJCFLAGS="$OBJCFLAGS -noixemul" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS -noixemul" CPPFLAGS="$CPPFLAGS -D__NO_NET_API" LDFLAGS="$LDFLAGS -noixemul" LIBS="$LIBS -ldebug" enable_files="yes" # Required for reading ENV: enable_shared="no" with_tls="no" LIBBASES_M=libbases.m ;; powerpc-*-amigaos*) CPPFLAGS="$CPPFLAGS -D__USE_INLINE__" enable_files="yes" # Required for reading ENV: enable_shared="no" with_tls="no" LIBBASES_M=libbases.m ;; *-morphos*) if test x"$OBJCFLAGS" = x"" then : OBJCFLAGS="-O2 -g" fi OBJCFLAGS="$OBJCFLAGS -noixemul" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS -noixemul" LDFLAGS="$LDFLAGS -noixemul" LIBS="$LIBS -ldebug" enable_files="yes" # Required for reading ENV: enable_shared="no" LIBBASES_M=libbases.m ;; *-msdosdjgpp*) enable_shared="no" enable_threads="no" enable_sockets="no" ;; *-*-mingw*) LDFLAGS="$LDFLAGS -Wl,--allow-multiple-definition" LIBS="$LIBS -lversion" USE_SRCS_WINDOWS='${SRCS_WINDOWS}' ;; *-psp-*) if test x"$DEVKITPSP" = x"" then : as_fn_error $? "DEVKITPSP is not set! Please set DEVKITPSP." "$LINENO" 5 fi if test x"$OBJCFLAGS" = x"" then : OBJCFLAGS="-O2" fi OBJCFLAGS="$OBJCFLAGS -G0" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS -G0" CPPFLAGS="$CPPFLAGS -I$DEVKITPSP/psp/sdk/include" LDFLAGS="$LDFLAGS -G0" LIBS="$LIBS -L$DEVKITPSP/psp/sdk/lib -lpspdebug -lpspdisplay" LIBS="$LIBS -lpspge -lpspctrl -lpspsdk -lc -lpspnet" LIBS="$LIBS -lpspnet_inet -lpspnet_apctl -lpspnet_resolver" LIBS="$LIBS -lpsputility -lpspuser -lpspkernel -lgcc -lpsplibc" enable_shared="no" enable_threads="no" # TODO enable_sockets="no" # TODO check_pedantic="no" MAP_LDFLAGS='-Wl,-Map,$@.map' ;; hppa*-*-hpux*) if test x"$OBJCFLAGS" = x"" then : OBJCFLAGS="-O2" fi OBJCFLAGS="$OBJCFLAGS -include inttypes.h" LIBS="$LIBS -latomic" ;; *-*-mint*) enable_shared="no" enable_threads="no" # TODO with_tls="no" ;; *-apple-macos*) enable_shared="no" enable_threads="no" # TODO enable_sockets="no" # TODO printf "%s\n" "#define OF_CLASSIC_MACOS 1" >>confdefs.h ;; esac if test x"$host_os" = x"msdosdjgpp" -a x"$build_os" = x"msdosdjgpp" then : : ${AR:=ar.exe} : ${GREP:=grep.exe} : ${RANLIB:=ranlib.exe} fi ac_ext=m ac_cpp='$OBJCPP $CPPFLAGS' ac_compile='$OBJC -c $OBJCFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$OBJC -o conftest$ac_exeext $OBJCFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_objc_compiler_gnu case "$host_os" in morphos*) potential_compilers="gcc" ;; *) potential_compilers="clang egcc gcc" ;; esac ac_ext=m ac_cpp='$OBJCPP $CPPFLAGS' ac_compile='$OBJC -c $OBJCFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$OBJC -o conftest$ac_exeext $OBJCFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_objc_compiler_gnu if test -n "$ac_tool_prefix"; then for ac_prog in $potential_compilers do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_OBJC+y} then : printf %s "(cached) " >&6 else $as_nop if test -n "$OBJC"; then ac_cv_prog_OBJC="$OBJC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_OBJC="$ac_tool_prefix$ac_prog" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi OBJC=$ac_cv_prog_OBJC if test -n "$OBJC"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $OBJC" >&5 printf "%s\n" "$OBJC" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi test -n "$OBJC" && break done fi if test -z "$OBJC"; then ac_ct_OBJC=$OBJC for ac_prog in $potential_compilers do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_OBJC+y} then : printf %s "(cached) " >&6 else $as_nop if test -n "$ac_ct_OBJC"; then ac_cv_prog_ac_ct_OBJC="$ac_ct_OBJC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_OBJC="$ac_prog" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_OBJC=$ac_cv_prog_ac_ct_OBJC if test -n "$ac_ct_OBJC"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJC" >&5 printf "%s\n" "$ac_ct_OBJC" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi test -n "$ac_ct_OBJC" && break done if test "x$ac_ct_OBJC" = x; then OBJC="gcc" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OBJC=$ac_ct_OBJC fi fi # Provide some information about the compiler. printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for Objective C compiler version" >&5 set X $ac_compile ac_compiler=$2 for ac_option in --version -v -V -qversion; do { { ac_try="$ac_compiler $ac_option >&5" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_compiler $ac_option >&5") 2>conftest.err ac_status=$? if test -s conftest.err; then sed '10a\ ... rest of stderr output deleted ... 10q' conftest.err >conftest.er1 cat conftest.er1 >&5 fi rm -f conftest.er1 conftest.err printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } done cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" # Try to create an executable without -o first, disregard a.out. # It will help us diagnose broken compilers, and finding out an intuition # of exeext. { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the Objective C compiler works" >&5 printf %s "checking whether the Objective C compiler works... " >&6; } ac_link_default=`printf "%s\n" "$ac_link" | sed 's/ -o *conftest[^ ]*//'` # The possible output files: ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" ac_rmfiles= for ac_file in $ac_files do case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; * ) ac_rmfiles="$ac_rmfiles $ac_file";; esac done rm -f $ac_rmfiles if { { ac_try="$ac_link_default" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_link_default") 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } then : # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. # So ignore a value of `no', otherwise this would lead to `EXEEXT = no' # in a Makefile. We should not override ac_cv_exeext if it was cached, # so that the user can short-circuit this test for compilers unknown to # Autoconf. for ac_file in $ac_files '' do test -f "$ac_file" || continue case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; [ab].out ) # We found the default executable, but exeext='' is most # certainly right. break;; *.* ) if test ${ac_cv_exeext+y} && test "$ac_cv_exeext" != no; then :; else ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` fi # We set ac_cv_exeext here because the later test for it is not # safe: cross compilers may not add the suffix if given an `-o' # argument, so we may need to know it at that point already. # Even if this section looks crufty: it has the advantage of # actually working. break;; * ) break;; esac done test "$ac_cv_exeext" = no && ac_cv_exeext= else $as_nop ac_file='' fi if test -z "$ac_file" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "Objective C compiler cannot create executables See \`config.log' for more details" "$LINENO" 5; } else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for Objective C compiler default output file name" >&5 printf %s "checking for Objective C compiler default output file name... " >&6; } { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 printf "%s\n" "$ac_file" >&6; } ac_exeext=$ac_cv_exeext rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out ac_clean_files=$ac_clean_files_save { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 printf %s "checking for suffix of executables... " >&6; } if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } then : # If both `conftest.exe' and `conftest' are `present' (well, observable) # catch `conftest.exe'. For instance with Cygwin, `ls conftest' will # work properly (i.e., refer to `conftest.exe'), while it won't with # `rm'. for ac_file in conftest.exe conftest conftest.*; do test -f "$ac_file" || continue case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` break;; * ) break;; esac done else $as_nop { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of executables: cannot compile and link See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest conftest$ac_cv_exeext { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 printf "%s\n" "$ac_cv_exeext" >&6; } rm -f conftest.$ac_ext EXEEXT=$ac_cv_exeext ac_exeext=$EXEEXT cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main (void) { FILE *f = fopen ("conftest.out", "w"); return ferror (f) || fclose (f) != 0; ; return 0; } _ACEOF ac_clean_files="$ac_clean_files conftest.out" # Check that the compiler produces executables we can run. If not, either # the compiler is broken, or we cross compile. { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 printf %s "checking whether we are cross compiling... " >&6; } if test "$cross_compiling" != yes; then { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if { ac_try='./conftest$ac_cv_exeext' { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then cross_compiling=no else if test "$cross_compiling" = maybe; then cross_compiling=yes else { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "cannot run Objective C compiled programs. If you meant to cross compile, use \`--host'. See \`config.log' for more details" "$LINENO" 5; } fi fi fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 printf "%s\n" "$cross_compiling" >&6; } rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out ac_clean_files=$ac_clean_files_save { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 printf %s "checking for suffix of object files... " >&6; } if test ${ac_cv_objext+y} then : printf %s "(cached) " >&6 else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF rm -f conftest.o conftest.obj if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } then : for ac_file in conftest.o conftest.obj conftest.*; do test -f "$ac_file" || continue; case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;; *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` break;; esac done else $as_nop printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of object files: cannot compile See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest.$ac_cv_objext conftest.$ac_ext fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 printf "%s\n" "$ac_cv_objext" >&6; } OBJEXT=$ac_cv_objext ac_objext=$OBJEXT { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports GNU Objective C" >&5 printf %s "checking whether the compiler supports GNU Objective C... " >&6; } if test ${ac_cv_objc_compiler_gnu+y} then : printf %s "(cached) " >&6 else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { #ifndef __GNUC__ choke me #endif ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ac_compiler_gnu=yes else $as_nop ac_compiler_gnu=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ac_cv_objc_compiler_gnu=$ac_compiler_gnu fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objc_compiler_gnu" >&5 printf "%s\n" "$ac_cv_objc_compiler_gnu" >&6; } ac_compiler_gnu=$ac_cv_objc_compiler_gnu if test $ac_compiler_gnu = yes; then GOBJC=yes else GOBJC= fi ac_test_OBJCFLAGS=${OBJCFLAGS+y} ac_save_OBJCFLAGS=$OBJCFLAGS { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $OBJC accepts -g" >&5 printf %s "checking whether $OBJC accepts -g... " >&6; } if test ${ac_cv_prog_objc_g+y} then : printf %s "(cached) " >&6 else $as_nop ac_save_objc_werror_flag=$ac_objc_werror_flag ac_objc_werror_flag=yes ac_cv_prog_objc_g=no OBJCFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ac_cv_prog_objc_g=yes else $as_nop OBJCFLAGS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : else $as_nop ac_objc_werror_flag=$ac_save_objc_werror_flag OBJCFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ac_cv_prog_objc_g=yes fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ac_objc_werror_flag=$ac_save_objc_werror_flag fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_objc_g" >&5 printf "%s\n" "$ac_cv_prog_objc_g" >&6; } if test $ac_test_OBJCFLAGS; then OBJCFLAGS=$ac_save_OBJCFLAGS elif test $ac_cv_prog_objc_g = yes; then if test "$GOBJC" = yes; then OBJCFLAGS="-g -O2" else OBJCFLAGS="-g" fi else if test "$GOBJC" = yes; then OBJCFLAGS="-O2" else OBJCFLAGS= fi fi ac_ext=m ac_cpp='$OBJCPP $CPPFLAGS' ac_compile='$OBJC -c $OBJCFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$OBJC -o conftest$ac_exeext $OBJCFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_objc_compiler_gnu ac_ext=m ac_cpp='$OBJCPP $CPPFLAGS' ac_compile='$OBJC -c $OBJCFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$OBJC -o conftest$ac_exeext $OBJCFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_objc_compiler_gnu { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to run the Objective C preprocessor" >&5 printf %s "checking how to run the Objective C preprocessor... " >&6; } if test -z "$OBJCPP"; then if test ${ac_cv_prog_OBJCPP+y} then : printf %s "(cached) " >&6 else $as_nop # Double quotes because $OBJC needs to be expanded for OBJCPP in "$OBJC -E" cpp /lib/cpp do ac_preproc_ok=false for ac_objc_preproc_warn_flag in '' yes do # Use a header file that comes with gcc, so configuring glibc # with a fresh cross-compiler works. # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. "Syntax error" is here to catch this case. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include Syntax error _ACEOF if ac_fn_objc_try_cpp "$LINENO" then : else $as_nop # Broken: fails on valid input. continue fi rm -f conftest.err conftest.i conftest.$ac_ext # OK, works on sane cases. Now check whether nonexistent headers # can be detected and how. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if ac_fn_objc_try_cpp "$LINENO" then : # Broken: success on invalid input. continue else $as_nop # Passes both tests. ac_preproc_ok=: break fi rm -f conftest.err conftest.i conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. rm -f conftest.i conftest.err conftest.$ac_ext if $ac_preproc_ok then : break fi done ac_cv_prog_OBJCPP=$OBJCPP fi OBJCPP=$ac_cv_prog_OBJCPP else ac_cv_prog_OBJCPP=$OBJCPP fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $OBJCPP" >&5 printf "%s\n" "$OBJCPP" >&6; } ac_preproc_ok=false for ac_objc_preproc_warn_flag in '' yes do # Use a header file that comes with gcc, so configuring glibc # with a fresh cross-compiler works. # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. "Syntax error" is here to catch this case. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include Syntax error _ACEOF if ac_fn_objc_try_cpp "$LINENO" then : else $as_nop # Broken: fails on valid input. continue fi rm -f conftest.err conftest.i conftest.$ac_ext # OK, works on sane cases. Now check whether nonexistent headers # can be detected and how. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if ac_fn_objc_try_cpp "$LINENO" then : # Broken: success on invalid input. continue else $as_nop # Passes both tests. ac_preproc_ok=: break fi rm -f conftest.err conftest.i conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. rm -f conftest.i conftest.err conftest.$ac_ext if $ac_preproc_ok then : else $as_nop { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "Objective C preprocessor \"$OBJCPP\" fails sanity check See \`config.log' for more details" "$LINENO" 5; } fi ac_ext=m ac_cpp='$OBJCPP $CPPFLAGS' ac_compile='$OBJC -c $OBJCFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$OBJC -o conftest$ac_exeext $OBJCFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_objc_compiler_gnu { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 printf %s "checking for grep that handles long lines and -e... " >&6; } if test ${ac_cv_path_GREP+y} then : printf %s "(cached) " >&6 else $as_nop if test -z "$GREP"; then ac_path_GREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_prog in grep ggrep do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_GREP="$as_dir$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_GREP" || continue # Check for GNU ac_path_GREP and select it if it is found. # Check for GNU $ac_path_GREP case `"$ac_path_GREP" --version 2>&1` in *GNU*) ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; *) ac_count=0 printf %s 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" printf "%s\n" 'GREP' >> "conftest.nl" "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_GREP_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_GREP_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_GREP"; then as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 fi else ac_cv_path_GREP=$GREP fi fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 printf "%s\n" "$ac_cv_path_GREP" >&6; } GREP="$ac_cv_path_GREP" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 printf %s "checking for egrep... " >&6; } if test ${ac_cv_path_EGREP+y} then : printf %s "(cached) " >&6 else $as_nop if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 then ac_cv_path_EGREP="$GREP -E" else if test -z "$EGREP"; then ac_path_EGREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_prog in egrep do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_EGREP="$as_dir$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_EGREP" || continue # Check for GNU ac_path_EGREP and select it if it is found. # Check for GNU $ac_path_EGREP case `"$ac_path_EGREP" --version 2>&1` in *GNU*) ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; *) ac_count=0 printf %s 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" printf "%s\n" 'EGREP' >> "conftest.nl" "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_EGREP_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_EGREP_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_EGREP"; then as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 fi else ac_cv_path_EGREP=$EGREP fi fi fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 printf "%s\n" "$ac_cv_path_EGREP" >&6; } EGREP="$ac_cv_path_EGREP" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5 printf %s "checking for a sed that does not truncate output... " >&6; } if test ${ac_cv_path_SED+y} then : printf %s "(cached) " >&6 else $as_nop ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ for ac_i in 1 2 3 4 5 6 7; do ac_script="$ac_script$as_nl$ac_script" done echo "$ac_script" 2>/dev/null | sed 99q >conftest.sed { ac_script=; unset ac_script;} if test -z "$SED"; then ac_path_SED_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_prog in sed gsed do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_SED="$as_dir$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_SED" || continue # Check for GNU ac_path_SED and select it if it is found. # Check for GNU $ac_path_SED case `"$ac_path_SED" --version 2>&1` in *GNU*) ac_cv_path_SED="$ac_path_SED" ac_path_SED_found=:;; *) ac_count=0 printf %s 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" printf "%s\n" '' >> "conftest.nl" "$ac_path_SED" -f conftest.sed < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_SED_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_SED="$ac_path_SED" ac_path_SED_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_SED_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_SED"; then as_fn_error $? "no acceptable sed could be found in \$PATH" "$LINENO" 5 fi else ac_cv_path_SED=$SED fi fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5 printf "%s\n" "$ac_cv_path_SED" >&6; } SED="$ac_cv_path_SED" rm -f conftest.sed { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether ln -s works" >&5 printf %s "checking whether ln -s works... " >&6; } LN_S=$as_ln_s if test "$LN_S" = "ln -s"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no, using $LN_S" >&5 printf "%s\n" "no, using $LN_S" >&6; } fi case "$host_os" in darwin*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether host is iOS" >&5 printf %s "checking whether host is iOS... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #if (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) || \ (defined(TARGET_OS_SIMULATOR) && \ TARGET_OS_SIMULATOR) yes #endif _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "yes" >/dev/null 2>&1 then : host_is_ios="yes" HOST_IS_IOS=yes else $as_nop host_is_ios="no" fi rm -rf conftest* { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $host_is_ios" >&5 printf "%s\n" "$host_is_ios" >&6; } if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}codesign", so it can be a program name with args. set dummy ${ac_tool_prefix}codesign; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_CODESIGN+y} then : printf %s "(cached) " >&6 else $as_nop if test -n "$CODESIGN"; then ac_cv_prog_CODESIGN="$CODESIGN" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_CODESIGN="${ac_tool_prefix}codesign" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CODESIGN=$ac_cv_prog_CODESIGN if test -n "$CODESIGN"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CODESIGN" >&5 printf "%s\n" "$CODESIGN" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi fi if test -z "$ac_cv_prog_CODESIGN"; then ac_ct_CODESIGN=$CODESIGN # Extract the first word of "codesign", so it can be a program name with args. set dummy codesign; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_CODESIGN+y} then : printf %s "(cached) " >&6 else $as_nop if test -n "$ac_ct_CODESIGN"; then ac_cv_prog_ac_ct_CODESIGN="$ac_ct_CODESIGN" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CODESIGN="codesign" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_CODESIGN=$ac_cv_prog_ac_ct_CODESIGN if test -n "$ac_ct_CODESIGN"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CODESIGN" >&5 printf "%s\n" "$ac_ct_CODESIGN" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi if test "x$ac_ct_CODESIGN" = x; then CODESIGN="" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CODESIGN=$ac_ct_CODESIGN fi else CODESIGN="$ac_cv_prog_CODESIGN" fi ;; esac # Check whether --with-wii was given. if test ${with_wii+y} then : withval=$with_wii; fi if test x"$with_wii" = x"yes" then : if test x"$DEVKITPRO" = x"" then : as_fn_error $? "DEVKITPRO is not set! Please set DEVKITPRO." "$LINENO" 5 fi flags="-mrvl -mcpu=750 -meabi -mhard-float" OBJCFLAGS="$OBJCFLAGS $flags" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flags" CPPFLAGS="$CPPFLAGS -DGEKKO -I$DEVKITPRO/libogc/include" OBJFW_CPPFLAGS="$OBJFW_CPPFLAGS -DGEKKO -I\$DEVKITPRO/libogc/include" LDFLAGS="$LDFLAGS -mrvl -mcpu=750 -meabi -mhard-float" LIBS="$LIBS -L$DEVKITPRO/libogc/lib/wii -lfat -logc" TESTS_LIBS="$TESTS_LIBS -lwiiuse -lbte" enable_shared="no" enable_threads="no" # TODO with_tls="no" printf "%s\n" "#define OF_WII 1" >>confdefs.h MAP_LDFLAGS='-Wl,-Map,$@.map' fi # Check whether --with-wii-u was given. if test ${with_wii_u+y} then : withval=$with_wii_u; fi if test x"$with_wii_u" = x"yes" then : if test x"$DEVKITPRO" = x"" then : as_fn_error $? "DEVKITPRO is not set! Please set DEVKITPRO." "$LINENO" 5 fi flags="-mcpu=750 -meabi -mhard-float" OBJCFLAGS="$OBJCFLAGS $flags" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flags" CPPFLAGS="-isystem $DEVKITPRO/wut/include -D__WIIU__ -D__WUT__" OBJFW_CPPFLAGS="$OBJFW_CPPFLAGS -isystem \$DEVKITPRO/wut/include" OBJFW_CPPFLAGS="$OBJFW_CPPFLAGS -D__WIIU__ -D__WUT__" LDFLAGS="-specs=$DEVKITPRO/wut/share/wut.specs" LIBS="-L$DEVKITPRO/wut/lib -L$DEVKITPRO/wut/lib/stubs -lwut" enable_files="no" # TODO enable_shared="no" # TODO enable_threads="no" # TODO enable_sockets="no" # TODO printf "%s\n" "#define OF_WII_U 1" >>confdefs.h MAP_LDFLAGS='-Wl,-Map,$@.map' # Repetition of libraries is required for Wii U, as otherwise it cannot # find main. Just moving -lobjfwtest later doesn't work either, as then # the linker cannot find ObjFW symbols. So the only solution is to list # everything twice, but hide it behind a variable because listing it # twice causes a warning on macOS. WII_U_TESTS_LIBS='-lobjfwtest ${TESTS_LIBS} ${LIBS}' fi # Check whether --with-nds was given. if test ${with_nds+y} then : withval=$with_nds; fi if test x"$with_nds" = x"yes" then : if test x"$DEVKITPRO" = x"" then : as_fn_error $? "DEVKITPRO is not set! Please set DEVKITPRO." "$LINENO" 5 fi flags="-march=armv5te -mtune=arm946e-s -mthumb -mthumb-interwork" OBJCFLAGS="$OBJCFLAGS $flags" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flags" CPPFLAGS="$CPPFLAGS -DARM9 -I$DEVKITPRO/libnds/include" OBJFW_CPPFLAGS="$OBJFW_CPPFLAGS -DARM9 -I\$DEVKITPRO/libnds/include" ASFLAGS="$ASFLAGS -march=armv5te" LDFLAGS="$LDFLAGS -specs=ds_arm9.specs" LIBS="$LIBS -L$DEVKITPRO/libnds/lib -lfilesystem -lfat -lnds9" enable_shared="no" enable_threads="no" # TODO enable_sockets="no" # TODO check_pedantic="no" printf "%s\n" "#define OF_NINTENDO_DS 1" >>confdefs.h MAP_LDFLAGS='-Wl,-Map,$@.map' fi # Check whether --with-3ds was given. if test ${with_3ds+y} then : withval=$with_3ds; fi if test x"$with_3ds" = x"yes" then : if test x"$DEVKITPRO" = x"" then : as_fn_error $? "DEVKITPRO is not set! Please set DEVKITPRO." "$LINENO" 5 fi flags="-march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft" flags="$flags -mword-relocations" OBJCFLAGS="$OBJCFLAGS $flags" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flags" CPPFLAGS="$CPPFLAGS -DARM11 -I$DEVKITPRO/libctru/include" OBJFW_CPPFLAGS="$OBJFW_CPPFLAGS -DARM11 -I\$DEVKITPRO/libctru/include" ASFLAGS="$ASFLAGS -march=armv6k" LDFLAGS="$LDFLAGS -specs=3dsx.specs -march=armv6k -mtune=mpcore" LDFLAGS="$LDFLAGS -mfloat-abi=hard -mtp=soft -mword-relocations" LIBS="$LIBS -L$DEVKITPRO/libctru/lib -lctru" enable_shared="no" enable_threads="no" # TODO with_tls="no" check_pedantic="no" printf "%s\n" "#define OF_NINTENDO_3DS 1" >>confdefs.h MAP_LDFLAGS='-Wl,-Map,$@.map' fi # Check whether --with-nintendo-switch was given. if test ${with_nintendo_switch+y} then : withval=$with_nintendo_switch; fi if test x"$with_nintendo_switch" = x"yes" then : if test x"$DEVKITPRO" = x"" then : as_fn_error $? "DEVKITPRO is not set! Please set DEVKITPRO." "$LINENO" 5 fi flags="-march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE" OBJCFLAGS="$OBJCFLAGS $flags" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flags" CPPFLAGS="$CPPFLAGS -D__SWITCH__ -I$DEVKITPRO/libnx/include" OBJFW_CPPFLAGS="$OBJFW_CPPFLAGS -D__SWITCH__ -I$DEVKITPRO/libnx/include" ASFLAGS="$ASFLAGS $flags" LDFLAGS="$LDFLAGS -specs=$DEVKITPRO/libnx/switch.specs $flags" LIBS="$LIBS -L$DEVKITPRO/libnx/lib -lnx" enable_shared="no" enable_threads="yes" enable_sockets="no" # TODO check_pedantic="no" printf "%s\n" "#define OF_NINTENDO_SWITCH 1" >>confdefs.h fi CPP="$OBJCPP" CPPFLAGS="$CPPFLAGS $OBJCPPFLAGS -DOF_COMPILING_OBJFW" flags="-fexceptions -fobjc-exceptions -funwind-tables" flags="$flags -fconstant-string-class=OFConstantString" OBJCFLAGS="$OBJCFLAGS -Wall $flags" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flags" LDFLAGS="$LDFLAGS -fexceptions" case "$OBJC" in *clang*) case "$host" in mips*-*-*) ASFLAGS="$ASFLAGS -no-integrated-as" OBJCFLAGS="$OBJCFLAGS -integrated-as" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS -integrated-as" ;; i?86-*-darwin* | x86_64-*-darwin*) ;; sparc64-*-*openbsd*) flag="-integrated-as" OBJCFLAGS="$OBJCFLAGS $flag" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flag" ;; esac ;; esac { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether Objective C compiler accepts -std=gnu11" >&5 printf %s "checking whether Objective C compiler accepts -std=gnu11... " >&6; } if test ${ax_cv_objc_flags__std_gnu11+y} then : printf %s "(cached) " >&6 else $as_nop ax_save_FLAGS=$OBJCFLAGS OBJCFLAGS="-std=gnu11" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ax_cv_objc_flags__std_gnu11=yes else $as_nop ax_cv_objc_flags__std_gnu11=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext OBJCFLAGS=$ax_save_FLAGS fi eval ax_check_compiler_flags=$ax_cv_objc_flags__std_gnu11 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_check_compiler_flags" >&5 printf "%s\n" "$ax_check_compiler_flags" >&6; } if test "x$ax_check_compiler_flags" = xyes; then OBJCFLAGS="$OBJCFLAGS -std=gnu11" else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether Objective C compiler accepts -std=gnu1x" >&5 printf %s "checking whether Objective C compiler accepts -std=gnu1x... " >&6; } if test ${ax_cv_objc_flags__std_gnu1x+y} then : printf %s "(cached) " >&6 else $as_nop ax_save_FLAGS=$OBJCFLAGS OBJCFLAGS="-std=gnu1x" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ax_cv_objc_flags__std_gnu1x=yes else $as_nop ax_cv_objc_flags__std_gnu1x=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext OBJCFLAGS=$ax_save_FLAGS fi eval ax_check_compiler_flags=$ax_cv_objc_flags__std_gnu1x { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_check_compiler_flags" >&5 printf "%s\n" "$ax_check_compiler_flags" >&6; } if test "x$ax_check_compiler_flags" = xyes; then OBJCFLAGS="$OBJCFLAGS -std=gnu1x" else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether Objective C compiler accepts -std=gnu99" >&5 printf %s "checking whether Objective C compiler accepts -std=gnu99... " >&6; } if test ${ax_cv_objc_flags__std_gnu99+y} then : printf %s "(cached) " >&6 else $as_nop ax_save_FLAGS=$OBJCFLAGS OBJCFLAGS="-std=gnu99" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ax_cv_objc_flags__std_gnu99=yes else $as_nop ax_cv_objc_flags__std_gnu99=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext OBJCFLAGS=$ax_save_FLAGS fi eval ax_check_compiler_flags=$ax_cv_objc_flags__std_gnu99 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_check_compiler_flags" >&5 printf "%s\n" "$ax_check_compiler_flags" >&6; } if test "x$ax_check_compiler_flags" = xyes; then OBJCFLAGS="$OBJCFLAGS -std=gnu99" else : fi fi fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether Objective C compiler accepts -pipe" >&5 printf %s "checking whether Objective C compiler accepts -pipe... " >&6; } if test ${ax_cv_objc_flags__pipe+y} then : printf %s "(cached) " >&6 else $as_nop ax_save_FLAGS=$OBJCFLAGS OBJCFLAGS="-pipe" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ax_cv_objc_flags__pipe=yes else $as_nop ax_cv_objc_flags__pipe=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext OBJCFLAGS=$ax_save_FLAGS fi eval ax_check_compiler_flags=$ax_cv_objc_flags__pipe { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_check_compiler_flags" >&5 printf "%s\n" "$ax_check_compiler_flags" >&6; } if test "x$ax_check_compiler_flags" = xyes; then OBJCFLAGS="$OBJCFLAGS -pipe" else : fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether Objective C compiler accepts -fno-common" >&5 printf %s "checking whether Objective C compiler accepts -fno-common... " >&6; } if test ${ax_cv_objc_flags__fno_common+y} then : printf %s "(cached) " >&6 else $as_nop ax_save_FLAGS=$OBJCFLAGS OBJCFLAGS="-fno-common" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ax_cv_objc_flags__fno_common=yes else $as_nop ax_cv_objc_flags__fno_common=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext OBJCFLAGS=$ax_save_FLAGS fi eval ax_check_compiler_flags=$ax_cv_objc_flags__fno_common { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_check_compiler_flags" >&5 printf "%s\n" "$ax_check_compiler_flags" >&6; } if test "x$ax_check_compiler_flags" = xyes; then OBJCFLAGS="$OBJCFLAGS -fno-common" else : fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether Objective C compiler accepts -Xclang -fno-constant-cfstrings" >&5 printf %s "checking whether Objective C compiler accepts -Xclang -fno-constant-cfstrings... " >&6; } if test ${ax_cv_objc_flags__Xclang__fno_constant_cfstrings+y} then : printf %s "(cached) " >&6 else $as_nop ax_save_FLAGS=$OBJCFLAGS OBJCFLAGS="-Xclang -fno-constant-cfstrings" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ax_cv_objc_flags__Xclang__fno_constant_cfstrings=yes else $as_nop ax_cv_objc_flags__Xclang__fno_constant_cfstrings=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext OBJCFLAGS=$ax_save_FLAGS fi eval ax_check_compiler_flags=$ax_cv_objc_flags__Xclang__fno_constant_cfstrings { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_check_compiler_flags" >&5 printf "%s\n" "$ax_check_compiler_flags" >&6; } if test "x$ax_check_compiler_flags" = xyes; then flag="-Xclang -fno-constant-cfstrings" OBJCFLAGS="$OBJCFLAGS $flag" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flag" else : fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether Objective C compiler accepts -Wsign-compare -Werror" >&5 printf %s "checking whether Objective C compiler accepts -Wsign-compare -Werror... " >&6; } if test ${ax_cv_objc_flags__Wsign_compare__Werror+y} then : printf %s "(cached) " >&6 else $as_nop ax_save_FLAGS=$OBJCFLAGS OBJCFLAGS="-Wsign-compare -Werror" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ax_cv_objc_flags__Wsign_compare__Werror=yes else $as_nop ax_cv_objc_flags__Wsign_compare__Werror=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext OBJCFLAGS=$ax_save_FLAGS fi eval ax_check_compiler_flags=$ax_cv_objc_flags__Wsign_compare__Werror { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_check_compiler_flags" >&5 printf "%s\n" "$ax_check_compiler_flags" >&6; } if test "x$ax_check_compiler_flags" = xyes; then OBJCFLAGS="$OBJCFLAGS -Wsign-compare" else : fi if test x"$with_nds" != x"yes" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether Objective C compiler accepts -Wshadow -Werror" >&5 printf %s "checking whether Objective C compiler accepts -Wshadow -Werror... " >&6; } if test ${ax_cv_objc_flags__Wshadow__Werror+y} then : printf %s "(cached) " >&6 else $as_nop ax_save_FLAGS=$OBJCFLAGS OBJCFLAGS="-Wshadow -Werror" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ax_cv_objc_flags__Wshadow__Werror=yes else $as_nop ax_cv_objc_flags__Wshadow__Werror=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext OBJCFLAGS=$ax_save_FLAGS fi eval ax_check_compiler_flags=$ax_cv_objc_flags__Wshadow__Werror { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_check_compiler_flags" >&5 printf "%s\n" "$ax_check_compiler_flags" >&6; } if test "x$ax_check_compiler_flags" = xyes; then OBJCFLAGS="$OBJCFLAGS -Wshadow" else : fi fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether Objective C compiler accepts -Wshorten-64-to-32 -Werror" >&5 printf %s "checking whether Objective C compiler accepts -Wshorten-64-to-32 -Werror... " >&6; } if test ${ax_cv_objc_flags__Wshorten_64_to_32__Werror+y} then : printf %s "(cached) " >&6 else $as_nop ax_save_FLAGS=$OBJCFLAGS OBJCFLAGS="-Wshorten-64-to-32 -Werror" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ax_cv_objc_flags__Wshorten_64_to_32__Werror=yes else $as_nop ax_cv_objc_flags__Wshorten_64_to_32__Werror=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext OBJCFLAGS=$ax_save_FLAGS fi eval ax_check_compiler_flags=$ax_cv_objc_flags__Wshorten_64_to_32__Werror { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_check_compiler_flags" >&5 printf "%s\n" "$ax_check_compiler_flags" >&6; } if test "x$ax_check_compiler_flags" = xyes; then OBJCFLAGS="$OBJCFLAGS -Wshorten-64-to-32" else : fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether Objective C compiler accepts -Wundeclared-selector -Werror" >&5 printf %s "checking whether Objective C compiler accepts -Wundeclared-selector -Werror... " >&6; } if test ${ax_cv_objc_flags__Wundeclared_selector__Werror+y} then : printf %s "(cached) " >&6 else $as_nop ax_save_FLAGS=$OBJCFLAGS OBJCFLAGS="-Wundeclared-selector -Werror" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ax_cv_objc_flags__Wundeclared_selector__Werror=yes else $as_nop ax_cv_objc_flags__Wundeclared_selector__Werror=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext OBJCFLAGS=$ax_save_FLAGS fi eval ax_check_compiler_flags=$ax_cv_objc_flags__Wundeclared_selector__Werror { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_check_compiler_flags" >&5 printf "%s\n" "$ax_check_compiler_flags" >&6; } if test "x$ax_check_compiler_flags" = xyes; then OBJCFLAGS="$OBJCFLAGS -Wundeclared-selector" else : fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether Objective C compiler accepts -Wsemicolon-before-method-body -Werror" >&5 printf %s "checking whether Objective C compiler accepts -Wsemicolon-before-method-body -Werror... " >&6; } if test ${ax_cv_objc_flags__Wsemicolon_before_method_body__Werror+y} then : printf %s "(cached) " >&6 else $as_nop ax_save_FLAGS=$OBJCFLAGS OBJCFLAGS="-Wsemicolon-before-method-body -Werror" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ax_cv_objc_flags__Wsemicolon_before_method_body__Werror=yes else $as_nop ax_cv_objc_flags__Wsemicolon_before_method_body__Werror=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext OBJCFLAGS=$ax_save_FLAGS fi eval ax_check_compiler_flags=$ax_cv_objc_flags__Wsemicolon_before_method_body__Werror { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_check_compiler_flags" >&5 printf "%s\n" "$ax_check_compiler_flags" >&6; } if test "x$ax_check_compiler_flags" = xyes; then OBJCFLAGS="$OBJCFLAGS -Wsemicolon-before-method-body" else : fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether Objective C compiler accepts -Wobjc-missing-property-synthesis -Werror" >&5 printf %s "checking whether Objective C compiler accepts -Wobjc-missing-property-synthesis -Werror... " >&6; } if test ${ax_cv_objc_flags__Wobjc_missing_property_synthesis__Werror+y} then : printf %s "(cached) " >&6 else $as_nop ax_save_FLAGS=$OBJCFLAGS OBJCFLAGS="-Wobjc-missing-property-synthesis -Werror" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ax_cv_objc_flags__Wobjc_missing_property_synthesis__Werror=yes else $as_nop ax_cv_objc_flags__Wobjc_missing_property_synthesis__Werror=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext OBJCFLAGS=$ax_save_FLAGS fi eval ax_check_compiler_flags=$ax_cv_objc_flags__Wobjc_missing_property_synthesis__Werror { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_check_compiler_flags" >&5 printf "%s\n" "$ax_check_compiler_flags" >&6; } if test "x$ax_check_compiler_flags" = xyes; then OBJCFLAGS="$OBJCFLAGS -Wobjc-missing-property-synthesis" else : fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether Objective C compiler accepts -Wmissing-method-return-type -Werror" >&5 printf %s "checking whether Objective C compiler accepts -Wmissing-method-return-type -Werror... " >&6; } if test ${ax_cv_objc_flags__Wmissing_method_return_type__Werror+y} then : printf %s "(cached) " >&6 else $as_nop ax_save_FLAGS=$OBJCFLAGS OBJCFLAGS="-Wmissing-method-return-type -Werror" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ax_cv_objc_flags__Wmissing_method_return_type__Werror=yes else $as_nop ax_cv_objc_flags__Wmissing_method_return_type__Werror=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext OBJCFLAGS=$ax_save_FLAGS fi eval ax_check_compiler_flags=$ax_cv_objc_flags__Wmissing_method_return_type__Werror { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_check_compiler_flags" >&5 printf "%s\n" "$ax_check_compiler_flags" >&6; } if test "x$ax_check_compiler_flags" = xyes; then OBJCFLAGS="$OBJCFLAGS -Wmissing-method-return-type" else : fi case "$host" in m68k-*-amigaos*) OBJCFLAGS="$OBJCFLAGS -Wno-pointer-sign" ;; esac { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether Objective C compiler supports properties" >&5 printf %s "checking whether Objective C compiler supports properties... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef __has_attribute # if __has_attribute(objc_root_class) __attribute__((__objc_root_class__)) # endif #endif @interface Foo { id bar; } @property (nonatomic, retain) id bar; @end int main (void) { Foo *foo = (id)0; [foo setBar: (id)0]; foo = [foo bar]; ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } as_fn_error $? "Compiler does not support properties!" "$LINENO" 5 fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}ar", so it can be a program name with args. set dummy ${ac_tool_prefix}ar; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_AR+y} then : printf %s "(cached) " >&6 else $as_nop if test -n "$AR"; then ac_cv_prog_AR="$AR" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_AR="${ac_tool_prefix}ar" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi AR=$ac_cv_prog_AR if test -n "$AR"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $AR" >&5 printf "%s\n" "$AR" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi fi if test -z "$ac_cv_prog_AR"; then ac_ct_AR=$AR # Extract the first word of "ar", so it can be a program name with args. set dummy ar; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_AR+y} then : printf %s "(cached) " >&6 else $as_nop if test -n "$ac_ct_AR"; then ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_AR="ar" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_AR=$ac_cv_prog_ac_ct_AR if test -n "$ac_ct_AR"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5 printf "%s\n" "$ac_ct_AR" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi if test "x$ac_ct_AR" = x; then AR="" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac AR=$ac_ct_AR fi else AR="$ac_cv_prog_AR" fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. set dummy ${ac_tool_prefix}ranlib; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_RANLIB+y} then : printf %s "(cached) " >&6 else $as_nop if test -n "$RANLIB"; then ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi RANLIB=$ac_cv_prog_RANLIB if test -n "$RANLIB"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5 printf "%s\n" "$RANLIB" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi fi if test -z "$ac_cv_prog_RANLIB"; then ac_ct_RANLIB=$RANLIB # Extract the first word of "ranlib", so it can be a program name with args. set dummy ranlib; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_RANLIB+y} then : printf %s "(cached) " >&6 else $as_nop if test -n "$ac_ct_RANLIB"; then ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_RANLIB="ranlib" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB if test -n "$ac_ct_RANLIB"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5 printf "%s\n" "$ac_ct_RANLIB" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi if test "x$ac_ct_RANLIB" = x; then RANLIB=":" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac RANLIB=$ac_ct_RANLIB fi else RANLIB="$ac_cv_prog_RANLIB" fi case "$host_os" in mingw*) if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}windres", so it can be a program name with args. set dummy ${ac_tool_prefix}windres; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_RC+y} then : printf %s "(cached) " >&6 else $as_nop if test -n "$RC"; then ac_cv_prog_RC="$RC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_RC="${ac_tool_prefix}windres" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi RC=$ac_cv_prog_RC if test -n "$RC"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $RC" >&5 printf "%s\n" "$RC" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi fi if test -z "$ac_cv_prog_RC"; then ac_ct_RC=$RC # Extract the first word of "windres", so it can be a program name with args. set dummy windres; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_RC+y} then : printf %s "(cached) " >&6 else $as_nop if test -n "$ac_ct_RC"; then ac_cv_prog_ac_ct_RC="$ac_ct_RC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_RC="windres" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_RC=$ac_cv_prog_ac_ct_RC if test -n "$ac_ct_RC"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RC" >&5 printf "%s\n" "$ac_ct_RC" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi if test "x$ac_ct_RC" = x; then RC="" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac RC=$ac_ct_RC fi else RC="$ac_cv_prog_RC" fi ;; esac # Check whether --enable-shared was given. if test ${enable_shared+y} then : enableval=$enable_shared; fi if test x"$enable_shared" != x"no" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for shared library type" >&5 printf %s "checking for shared library type... " >&6; } case "$host" in *-*-darwin*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: Darwin" >&5 printf "%s\n" "Darwin" >&6; } LIB_CFLAGS='-fPIC -DPIC' LIB_LDFLAGS='-dynamiclib -current_version ${LIB_MAJOR}.${LIB_MINOR} -compatibility_version ${LIB_MAJOR}' LIB_LDFLAGS_INSTALL_NAME='-Wl,-install_name,${libdir}/$${out%.dylib}.${LIB_MAJOR}.dylib' LIB_PREFIX='lib' LIB_SUFFIX='.dylib' if test x"$enable_rpath" != x"no" then : LDFLAGS_RPATH='-Wl,-rpath,${libdir}' fi INSTALL_LIB='&& ${INSTALL} -m 755 $$i ${DESTDIR}${libdir}/$${i%.dylib}.${LIB_MAJOR}.${LIB_MINOR}.dylib && ${LN_S} -f $${i%.dylib}.${LIB_MAJOR}.${LIB_MINOR}.dylib ${DESTDIR}${libdir}/$${i%.dylib}.${LIB_MAJOR}.dylib && ${LN_S} -f $${i%.dylib}.${LIB_MAJOR}.${LIB_MINOR}.dylib ${DESTDIR}${libdir}/$$i' UNINSTALL_LIB='&& rm -f ${DESTDIR}${libdir}/$$i ${DESTDIR}${libdir}/$${i%.dylib}.${LIB_MAJOR}.dylib ${DESTDIR}${libdir}/$${i%.dylib}.${LIB_MAJOR}.${LIB_MINOR}.dylib' CLEAN_LIB='' ;; *-*-mingw* | *-*-cygwin*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: MinGW / Cygwin" >&5 printf "%s\n" "MinGW / Cygwin" >&6; } LIB_CFLAGS='' LIB_LDFLAGS='-shared -Wl,--export-all-symbols' LIB_LDFLAGS_INSTALL_NAME='' LIB_PREFIX='' LIB_SUFFIX='${LIB_MAJOR}.dll' LINK_LIB='&& rm -f lib$${out%${LIB_SUFFIX}}.dll.a && ${LN_S} $$out lib$${out%${LIB_SUFFIX}}.dll.a' INSTALL_LIB='&& ${MKDIR_P} ${DESTDIR}${bindir} && ${INSTALL} -m 755 $$i ${DESTDIR}${bindir}/$$i && ${INSTALL} -m 755 lib$${i%${LIB_SUFFIX}}.dll.a ${DESTDIR}${libdir}/lib$${i%${LIB_SUFFIX}}.dll.a' UNINSTALL_LIB='&& rm -f ${DESTDIR}${bindir}/$$i ${DESTDIR}${libdir}/lib$${i%${LIB_SUFFIX}}.dll.a' CLEAN_LIB='${SHARED_LIB}.a ${SHARED_LIB_NOINST}.a' ;; *-*-openbsd* | *-*-mirbsd*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: OpenBSD" >&5 printf "%s\n" "OpenBSD" >&6; } LIB_CFLAGS='-fPIC -DPIC' LIB_LDFLAGS='-shared' LIB_LDFLAGS_INSTALL_NAME='' LIB_PREFIX='lib' LIB_SUFFIX='.so.${LIB_MAJOR}.${LIB_MINOR}' if test x"$enable_rpath" != x"no" then : LDFLAGS_RPATH='-Wl,-rpath,${libdir}' fi INSTALL_LIB='&& ${INSTALL} -m 755 $$i ${DESTDIR}${libdir}/$$i' UNINSTALL_LIB='&& rm -f ${DESTDIR}${libdir}/$$i' CLEAN_LIB='' ;; *-*-solaris*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: Solaris" >&5 printf "%s\n" "Solaris" >&6; } LIB_CFLAGS='-fPIC -DPIC' LIB_LDFLAGS='-shared -Wl,-soname=$$out.${LIB_MAJOR}.${LIB_MINOR}' LIB_LDFLAGS_INSTALL_NAME='' LIB_PREFIX='lib' LIB_SUFFIX='.so' if test x"$enable_rpath" != x"no" then : LDFLAGS_RPATH='-Wl,-rpath,${libdir}' fi INSTALL_LIB='&& ${INSTALL} -m 755 $$i ${DESTDIR}${libdir}/$$i.${LIB_MAJOR}.${LIB_MINOR} && rm -f ${DESTDIR}${libdir}/$$i && ${LN_S} $$i.${LIB_MAJOR}.${LIB_MINOR} ${DESTDIR}${libdir}/$$i' UNINSTALL_LIB='&& rm -f ${DESTDIR}${libdir}/$$i ${DESTDIR}${libdir}/$$i.${LIB_MAJOR}.${LIB_MINOR}' CLEAN_LIB='' ;; *-*-android*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: Android" >&5 printf "%s\n" "Android" >&6; } LIB_CFLAGS='-fPIC -DPIC' LIB_LDFLAGS='-shared -Wl,-soname=$$out.${LIB_MAJOR}' LIB_LDFLAGS_INSTALL_NAME='' LIB_PREFIX='lib' LIB_SUFFIX='.so' INSTALL_LIB='&& ${INSTALL} -m 755 $$i ${DESTDIR}${libdir}/$$i.${LIB_MAJOR}.${LIB_MINOR}.${LIB_PATCH} && ${LN_S} -f $$i.${LIB_MAJOR}.${LIB_MINOR}.${LIB_PATCH} ${DESTDIR}${libdir}/$$i.${LIB_MAJOR} && ${LN_S} -f $$i.${LIB_MAJOR}.${LIB_MINOR}.${LIB_PATCH} ${DESTDIR}${libdir}/$$i' UNINSTALL_LIB='&& rm -f ${DESTDIR}${libdir}/$$i ${DESTDIR}${libdir}/$$i.${LIB_MAJOR} ${DESTDIR}${libdir}/$$i.${LIB_MAJOR}.${LIB_MINOR}.${LIB_PATCH}' CLEAN_LIB='' ;; hppa*-*-hpux*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: HP-UX (PA-RISC)" >&5 printf "%s\n" "HP-UX (PA-RISC)" >&6; } LIB_CFLAGS='-fPIC -DPIC' LIB_LDFLAGS='-shared -Wl,+h,$$out' LIB_LDFLAGS_INSTALL_NAME='' LIB_PREFIX='lib' LIB_SUFFIX='.${LIB_MAJOR}' LINK_LIB='&& rm -f $${out%%.*}.sl && ${LN_S} $$out $${out%%.*}.sl' if test x"$enable_rpath" != x"no" then : LDFLAGS_RPATH='-Wl,+b,${libdir}' fi INSTALL_LIB='&& ${INSTALL} -m 755 $$i ${DESTDIR}${libdir}/$$i && ${LN_S} -f $$i ${DESTDIR}${libdir}/$${i%%.*}.sl' UNINSTALL_LIB='&& rm -f ${DESTDIR}${libdir}/$$i ${DESTDIR}${libdir}/$${i%%.*}.sl' CLEAN_LIB='' ;; ia64*-*-hpux*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: HP-UX (Itanium)" >&5 printf "%s\n" "HP-UX (Itanium)" >&6; } LIB_CFLAGS='-fPIC -DPIC' LIB_LDFLAGS='-shared -Wl,+h,$$out' LIB_LDFLAGS_INSTALL_NAME='' LIB_PREFIX='lib' LIB_SUFFIX='.${LIB_MAJOR}' LINK_LIB='&& rm -f $${out%%.*}.so && ${LN_S} $$out $${out%%.*}.so' if test x"$enable_rpath" != x"no" then : LDFLAGS_RPATH='-Wl,+b,${libdir}' fi INSTALL_LIB='&& ${INSTALL} -m 755 $$i ${DESTDIR}${libdir}/$$i && ${LN_S} -f $$i ${DESTDIR}${libdir}/$${i%%.*}.so' UNINSTALL_LIB='&& rm -f ${DESTDIR}${libdir}/$$i ${DESTDIR}${libdir}/$${i%%.*}.so' CLEAN_LIB='' ;; *) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ELF" >&5 printf "%s\n" "ELF" >&6; } LIB_CFLAGS='-fPIC -DPIC' LIB_LDFLAGS='-shared -Wl,-soname=$$out.${LIB_MAJOR}' LIB_LDFLAGS_INSTALL_NAME='' LIB_PREFIX='lib' LIB_SUFFIX='.so' if test x"$enable_rpath" != x"no" then : LDFLAGS_RPATH='-Wl,-rpath,${libdir}' fi INSTALL_LIB='&& ${INSTALL} -m 755 $$i ${DESTDIR}${libdir}/$$i.${LIB_MAJOR}.${LIB_MINOR}.${LIB_PATCH} && ${LN_S} -f $$i.${LIB_MAJOR}.${LIB_MINOR}.${LIB_PATCH} ${DESTDIR}${libdir}/$$i.${LIB_MAJOR} && ${LN_S} -f $$i.${LIB_MAJOR}.${LIB_MINOR}.${LIB_PATCH} ${DESTDIR}${libdir}/$$i' UNINSTALL_LIB='&& rm -f ${DESTDIR}${libdir}/$$i ${DESTDIR}${libdir}/$$i.${LIB_MAJOR} ${DESTDIR}${libdir}/$$i.${LIB_MAJOR}.${LIB_MINOR}.${LIB_PATCH}' CLEAN_LIB='' ;; esac { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for plugin type" >&5 printf %s "checking for plugin type... " >&6; } case "$host" in *-*-darwin*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: Darwin" >&5 printf "%s\n" "Darwin" >&6; } PLUGIN_CFLAGS='-fPIC -DPIC' PLUGIN_LDFLAGS='-bundle ${PLUGIN_LDFLAGS_BUNDLE_LOADER}' PLUGIN_SUFFIX='.bundle' if test x"$host_is_ios" = x"yes" then : LINK_PLUGIN='rm -fr $$out && ${MKDIR_P} $$out && if test -f Info.plist; then ${INSTALL} -m 644 Info.plist $$out/Info.plist; fi && ${LD} -o $$out/$${out%${PLUGIN_SUFFIX}} ${PLUGIN_OBJS} ${PLUGIN_OBJS_EXTRA} ${PLUGIN_LDFLAGS} ${LDFLAGS} ${LIBS} && ${CODESIGN} -fs ${CODESIGN_IDENTITY} $$out' else $as_nop LINK_PLUGIN='rm -fr $$out && ${MKDIR_P} $$out/Contents/MacOS && if test -f Info.plist; then ${INSTALL} -m 644 Info.plist $$out/Contents/Info.plist; fi && ${LD} -o $$out/Contents/MacOS/$${out%${PLUGIN_SUFFIX}} ${PLUGIN_OBJS} ${PLUGIN_OBJS_EXTRA} ${PLUGIN_LDFLAGS} ${LDFLAGS} ${LIBS} && ${CODESIGN} -fs ${CODESIGN_IDENTITY} $$out' fi INSTALL_PLUGIN='&& rm -fr ${DESTDIR}${plugindir}/$$i && cp -R $$i ${DESTDIR}${plugindir}/' UNINSTALL_PLUGIN='&& rm -fr ${DESTDIR}${plugindir}/$$i' ;; *-*-mingw* | *-*-cygwin*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: MinGW / Cygwin" >&5 printf "%s\n" "MinGW / Cygwin" >&6; } PLUGIN_CFLAGS='' PLUGIN_LDFLAGS='-shared -Wl,--export-all-symbols' PLUGIN_SUFFIX='.dll' LINK_PLUGIN='${LD} -o $$out ${PLUGIN_OBJS} ${PLUGIN_OBJS_EXTRA} ${PLUGIN_LDFLAGS} ${LDFLAGS} ${LIBS}' INSTALL_PLUGIN='&& ${INSTALL} -m 755 $$i ${DESTDIR}${plugindir}/$$i' UNINSTALL_PLUGIN='&& rm -f ${DESTDIR}${plugindir}/$$i' ;; hppa*-*-hpux*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: HP-UX (PA-RISC)" >&5 printf "%s\n" "HP-UX (PA-RISC)" >&6; } PLUGIN_CFLAGS='-fPIC -DPIC' PLUGIN_LDFLAGS='-shared' PLUGIN_SUFFIX='.sl' LINK_PLUGIN='${LD} -o $$out ${PLUGIN_OBJS} ${PLUGIN_OBJS_EXTRA} ${PLUGIN_LDFLAGS} ${LDFLAGS} ${LIBS}' INSTALL_PLUGIN='&& ${INSTALL} -m 755 $$i ${DESTDIR}${plugindir}/$$i' UNINSTALL_PLUGIN='&& rm -f ${DESTDIR}${plugindir}/$$i' ;; *) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ELF" >&5 printf "%s\n" "ELF" >&6; } PLUGIN_CFLAGS='-fPIC -DPIC' PLUGIN_LDFLAGS='-shared' PLUGIN_SUFFIX='.so' LINK_PLUGIN='${LD} -o $$out ${PLUGIN_OBJS} ${PLUGIN_OBJS_EXTRA} ${PLUGIN_LDFLAGS} ${LDFLAGS} ${LIBS}' INSTALL_PLUGIN='&& ${INSTALL} -m 755 $$i ${DESTDIR}${plugindir}/$$i' UNINSTALL_PLUGIN='&& rm -f ${DESTDIR}${plugindir}/$$i' ;; esac OBJFW_SHARED_LIB='${LIB_PREFIX}objfw${LIB_SUFFIX}' EXCEPTIONS_LIB_A="exceptions.lib.a" FORWARDING_LIB_A="forwarding.lib.a" LOOKUP_ASM_LIB_A="lookup-asm.lib.a" case "$host_os" in darwin*) FRAMEWORK_LDFLAGS='-dynamiclib -current_version ${LIB_MAJOR}.${LIB_MINOR} -compatibility_version ${LIB_MAJOR}' if test x"$host_is_ios" = x"yes" then : FRAMEWORK_LDFLAGS_INSTALL_NAME='-Wl,-install_name,@executable_path/Frameworks/$$out/$${out%.framework}' else $as_nop FRAMEWORK_LDFLAGS_INSTALL_NAME='-Wl,-install_name,@executable_path/../Frameworks/$$out/$${out%.framework}' fi OBJFW_FRAMEWORK="ObjFW.framework" build_framework="yes" ;; esac else $as_nop printf "%s\n" "#define OF_NO_SHARED 1" >>confdefs.h LIBOBJFW_DEP="../src/libobjfw.a" LIBOBJFW_DEP_LVL2="../../src/libobjfw.a" fi if test x"$build_framework" = x"yes" then : TESTS_LIBS="-framework ObjFW \${RUNTIME_FRAMEWORK_LIBS} $TESTS_LIBS" TESTS_LIBS="-F../src -F../src/runtime $TESTS_LIBS" else $as_nop TESTS_LIBS="\${RUNTIME_LIBS} $TESTS_LIBS" TESTS_LIBS="-L../src/runtime $TESTS_LIBS" TESTS_LIBS="-L../src -lobjfw $TESTS_LIBS" fi # Check whether --enable-static was given. if test ${enable_static+y} then : enableval=$enable_static; fi if test x"$enable_shared" = x"no" then : enable_static="yes" fi if test x"$enable_static" = x"yes" then : OBJFW_STATIC_LIB="libobjfw.a" EXCEPTIONS_A="exceptions.a" FORWARDING_A="forwarding.a" LOOKUP_ASM_A="lookup-asm.a" fi printf "%s\n" "#define PLUGIN_SUFFIX \"$PLUGIN_SUFFIX\"" >>confdefs.h if test x"$enable_files" != x"no" -a x"$PLUGIN_SUFFIX" != x"" then : USE_SRCS_PLUGINS='${SRCS_PLUGINS}' TESTPLUGIN="plugin" printf "%s\n" "#define OF_HAVE_PLUGINS 1" >>confdefs.h ac_config_files="$ac_config_files tests/plugin/Info.plist" if test x"$build_framework" = x"yes" then : TESTPLUGIN_LIBS="-F../../src -F../../src/runtime" TESTPLUGIN_LIBS="$TESTPLUGIN_LIBS -framework ObjFW" TESTPLUGIN_LIBS="$TESTPLUGIN_LIBS \${RUNTIME_FRAMEWORK_LIBS}" else $as_nop TESTPLUGIN_LIBS="-L../../src -L../../src/runtime" TESTPLUGIN_LIBS="$TESTPLUGIN_LIBS -lobjfw \${RUNTIME_LIBS}" fi fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether we need -D_GNU_SOURCE" >&5 printf %s "checking whether we need -D_GNU_SOURCE... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #if defined(__GLIBC__) || defined(__MINGW32__) || \ defined(__NEWLIB__) || defined(__MORPHOS__) || defined(__MINT__) egrep_cpp_yes #endif _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "egrep_cpp_yes" >/dev/null 2>&1 then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } CPPFLAGS="-D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 $CPPFLAGS" CPPFLAGS="-D_GNU_SOURCE $CPPFLAGS" gnu_source="yes" else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi rm -rf conftest* case "$host_os" in solaris*) CPPFLAGS="-D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS $CPPFLAGS" ;; esac objc_runtime="ObjFW runtime" ac_header= ac_cache= for ac_item in $ac_header_objc_list do if test $ac_cache; then ac_fn_objc_check_header_compile "$LINENO" $ac_header ac_cv_header_$ac_cache "$ac_includes_default" if eval test \"x\$ac_cv_header_$ac_cache\" = xyes; then printf "%s\n" "#define $ac_item 1" >> confdefs.h fi ac_header= ac_cache= elif test $ac_header; then ac_cache=$ac_item else ac_header=$ac_item fi done if test $ac_cv_header_stdlib_h = yes && test $ac_cv_header_string_h = yes then : printf "%s\n" "#define STDC_HEADERS 1" >>confdefs.h fi ac_fn_objc_check_header_compile "$LINENO" "objc/objc.h" "ac_cv_header_objc_objc_h" "$ac_includes_default" if test "x$ac_cv_header_objc_objc_h" = xyes then : fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking which Objective C runtime to use" >&5 printf %s "checking which Objective C runtime to use... " >&6; } # Check whether --enable-runtime was given. if test ${enable_runtime+y} then : enableval=$enable_runtime; fi # Check whether --enable-seluid24 was given. if test ${enable_seluid24+y} then : enableval=$enable_seluid24; fi if test x"$enable_runtime" != x"yes" then : if test x"$ac_cv_header_objc_objc_h" = x"yes" then : cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #import #ifdef OBJC_BOOL_DEFINED egrep_cpp_yes #endif _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "egrep_cpp_yes" >/dev/null 2>&1 then : objc_runtime="Apple runtime" else $as_nop : fi rm -rf conftest* fi fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $objc_runtime" >&5 printf "%s\n" "$objc_runtime" >&6; } case "$objc_runtime" in "ObjFW runtime") printf "%s\n" "#define OF_OBJFW_RUNTIME 1" >>confdefs.h USE_SRCS_TAGGED_POINTERS='${SRCS_TAGGED_POINTERS}' { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether -fobjc-runtime=objfw is supported" >&5 printf %s "checking whether -fobjc-runtime=objfw is supported... " >&6; } old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -Xclang -fobjc-runtime=objfw" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef __has_attribute # if __has_attribute(objc_root_class) __attribute__((__objc_root_class__)) # endif #endif @interface Test + (void)test; @end @implementation Test + (void)test { } @end void * objc_msg_lookup(void *obj, void *sel) { return (void *)0; } void __objc_exec_class(void *module) { } int main (void) { [Test test]; ; return 0; } _ACEOF if ac_fn_objc_try_link "$LINENO" then : OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS -Xclang -fobjc-runtime=objfw" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } else $as_nop OBJCFLAGS="$old_OBJCFLAGS -fgnu-runtime" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS -fgnu-runtime" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } old_compiler="yes" fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext RUNTIME="runtime" ac_config_files="$ac_config_files src/runtime/Info.plist" if test x"$enable_shared" != x"no" then : OBJFWRT_SHARED_LIB='${LIB_PREFIX}objfwrt${LIB_SUFFIX}' fi if test x"$enable_static" = x"yes" then : OBJFWRT_STATIC_LIB="libobjfwrt.a" fi if test x"$build_framework" = x"yes" then : OBJFWRT_FRAMEWORK="ObjFWRT.framework" RUNTIME_FRAMEWORK_LIBS="-framework ObjFWRT" fi RUNTIME_LIBS="-lobjfwrt" if test x"$enable_shared" = x"no" then : LIBOBJFWRT_DEP="../src/runtime/libobjfwrt.a" LIBOBJFWRT_DEP_LVL2="../../src/runtime/libobjfwrt.a" fi if test x"$enable_seluid24" = x"yes" then : printf "%s\n" "#define OF_SELUID24 1" >>confdefs.h fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for exception type" >&5 printf %s "checking for exception type... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ extern void foo(); int main (void) { @try { foo(); } @finally { foo(); } ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : if $SED 's/[^[:print:]]//g' /dev/null then : exception_type="DWARF" fi if $SED 's/[^[:print:]]//g' /dev/null then : exception_type="SjLj" fi if $SED 's/[^[:print:]]//g' /dev/null then : exception_type="SEH" fi case "$exception_type" in DWARF) printf "%s\n" "#define HAVE_DWARF_EXCEPTIONS 1" >>confdefs.h raise_exception="_Unwind_RaiseException" ;; SjLj) printf "%s\n" "#define HAVE_SJLJ_EXCEPTIONS 1" >>confdefs.h raise_exception="_Unwind_SjLj_RaiseException" ;; SEH) printf "%s\n" "#define HAVE_SEH_EXCEPTIONS 1" >>confdefs.h raise_exception="_Unwind_RaiseException" ;; *) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unknown" >&5 printf "%s\n" "unknown" >&6; } as_fn_error $? "Exception type not detected!" "$LINENO" 5 ;; esac { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $exception_type" >&5 printf "%s\n" "$exception_type" >&6; } else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: exceptions unavailable!" >&5 printf "%s\n" "exceptions unavailable!" >&6; } as_fn_error $? "Exceptions not accepted by compiler!" "$LINENO" 5 fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext as_ac_Search=`printf "%s\n" "ac_cv_search_$raise_exception" | $as_tr_sh` { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for library containing $raise_exception" >&5 printf %s "checking for library containing $raise_exception... " >&6; } if eval test \${$as_ac_Search+y} then : printf %s "(cached) " >&6 else $as_nop ac_func_search_save_LIBS=$LIBS cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ char $raise_exception (); int main (void) { return $raise_exception (); ; return 0; } _ACEOF for ac_lib in '' c++abi gcc_s gcc unwind do if test -z "$ac_lib"; then ac_res="none required" else ac_res=-l$ac_lib LIBS="-l$ac_lib -lpthread $ac_func_search_save_LIBS" fi if ac_fn_objc_try_link "$LINENO" then : eval "$as_ac_Search=\$ac_res" fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext if eval test \${$as_ac_Search+y} then : break fi done if eval test \${$as_ac_Search+y} then : else $as_nop eval "$as_ac_Search=no" fi rm conftest.$ac_ext LIBS=$ac_func_search_save_LIBS fi eval ac_res=\$$as_ac_Search { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 printf "%s\n" "$ac_res" >&6; } eval ac_res=\$$as_ac_Search if test "$ac_res" != no then : test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" if test x"$ac_lib" = x"c++abi" then : LIBS="$LIBS -lpthread" fi else $as_nop as_fn_error $? "$raise_exception missing!" "$LINENO" 5 fi ac_fn_objc_check_func "$LINENO" "_Unwind_GetDataRelBase" "ac_cv_func__Unwind_GetDataRelBase" if test "x$ac_cv_func__Unwind_GetDataRelBase" = xyes then : printf "%s\n" "#define HAVE__UNWIND_GETDATARELBASE 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "_Unwind_GetTextRelBase" "ac_cv_func__Unwind_GetTextRelBase" if test "x$ac_cv_func__Unwind_GetTextRelBase" = xyes then : printf "%s\n" "#define HAVE__UNWIND_GETTEXTRELBASE 1" >>confdefs.h fi ;; "Apple runtime") printf "%s\n" "#define OF_APPLE_RUNTIME 1" >>confdefs.h { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for objc_msgSend in -lobjc" >&5 printf %s "checking for objc_msgSend in -lobjc... " >&6; } if test ${ac_cv_lib_objc_objc_msgSend+y} then : printf %s "(cached) " >&6 else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-lobjc $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ char objc_msgSend (); int main (void) { return objc_msgSend (); ; return 0; } _ACEOF if ac_fn_objc_try_link "$LINENO" then : ac_cv_lib_objc_objc_msgSend=yes else $as_nop ac_cv_lib_objc_objc_msgSend=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_objc_objc_msgSend" >&5 printf "%s\n" "$ac_cv_lib_objc_objc_msgSend" >&6; } if test "x$ac_cv_lib_objc_objc_msgSend" = xyes then : RUNTIME_LIBS="-lobjc" RUNTIME_FRAMEWORK_LIBS="-lobjc" else $as_nop as_fn_error $? "libobjc not found!" "$LINENO" 5 fi old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -lobjc" ac_fn_objc_check_func "$LINENO" "objc_autoreleasePoolPush" "ac_cv_func_objc_autoreleasePoolPush" if test "x$ac_cv_func_objc_autoreleasePoolPush" = xyes then : else $as_nop RUNTIME_AUTORELEASE_M="runtime/autorelease.m" fi ac_fn_objc_check_func "$LINENO" "objc_constructInstance" "ac_cv_func_objc_constructInstance" if test "x$ac_cv_func_objc_constructInstance" = xyes then : else $as_nop RUNTIME_INSTANCE_M="runtime/instance.m" fi for ac_func in objc_setAssociatedObject do : ac_fn_objc_check_func "$LINENO" "objc_setAssociatedObject" "ac_cv_func_objc_setAssociatedObject" if test "x$ac_cv_func_objc_setAssociatedObject" = xyes then : printf "%s\n" "#define HAVE_OBJC_SETASSOCIATEDOBJECT 1" >>confdefs.h else $as_nop RUNTIME_ASSOCIATION_M="runtime/association.m" fi done OBJCFLAGS="$old_OBJCFLAGS" ;; esac case "$host_os" in mint*) ;; hpux*) ;; *) ac_fn_objc_check_func "$LINENO" "_Unwind_Backtrace" "ac_cv_func__Unwind_Backtrace" if test "x$ac_cv_func__Unwind_Backtrace" = xyes then : printf "%s\n" "#define HAVE__UNWIND_BACKTRACE 1" >>confdefs.h fi ;; esac case "$host_os" in darwin*) LDFLAGS_REEXPORT="-Wl,-reexport-lobjfw" if test x"$objc_runtime" = x"Apple runtime" then : REEXPORT_RUNTIME="-Wl,-reexport-lobjc" REEXPORT_RUNTIME_FRAMEWORK="-Wl,-reexport-lobjc" LDFLAGS="$LDFLAGS -Wl,-U,_NSFoundationVersionNumber" fi if test x"$objc_runtime" = x"ObjFW runtime" then : if test x"$exception_type" = x"DWARF" then : LDFLAGS="$LDFLAGS -Wl,-U,___gxx_personality_v0" fi if test x"$exception_type" = x"SjLj" then : LDFLAGS="$LDFLAGS -Wl,-U,___gxx_personality_sj0" fi REEXPORT_RUNTIME="-Wl,-reexport-lobjfwrt" REEXPORT_RUNTIME_FRAMEWORK="-Wl,-reexport_framework,ObjFWRT" fi ac_fn_objc_check_header_compile "$LINENO" "sysdir.h" "ac_cv_header_sysdir_h" "$ac_includes_default" if test "x$ac_cv_header_sysdir_h" = xyes then : printf "%s\n" "#define HAVE_SYSDIR_H 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "sysdir_start_search_path_enumeration" "ac_cv_func_sysdir_start_search_path_enumeration" if test "x$ac_cv_func_sysdir_start_search_path_enumeration" = xyes then : printf "%s\n" "#define HAVE_SYSDIR_START_SEARCH_PATH_ENUMERATION 1" >>confdefs.h fi if test x"$host_is_ios" = x"yes" then : TESTS_STATIC_LIB=tests.a TESTS_LIBS="$TESTS_LIBS -framework CoreFoundation" fi ;; esac { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether Objective C compiler supports ARC" >&5 printf %s "checking whether Objective C compiler supports ARC... " >&6; } old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -fobjc-arc -fobjc-arc-exceptions" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef __has_attribute # if __has_attribute(objc_root_class) __attribute__((__objc_root_class__)) # endif #endif @interface Foo { struct objc_class *_isa; } + (id)alloc; @end @implementation Foo + (id)alloc { return (id)0; } @end int main (void) { __weak id foo = [Foo alloc]; (void)foo; ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } RUNTIME_ARC_TESTS_M=RuntimeARCTests.m else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext OBJCFLAGS="$old_OBJCFLAGS" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether byte ordering is bigendian" >&5 printf %s "checking whether byte ordering is bigendian... " >&6; } if test ${ac_cv_c_bigendian+y} then : printf %s "(cached) " >&6 else $as_nop ac_cv_c_bigendian=unknown # See if we're dealing with a universal compiler. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifndef __APPLE_CC__ not a universal capable compiler #endif typedef int dummy; _ACEOF if ac_fn_objc_try_compile "$LINENO" then : # Check for potential -arch flags. It is not universal unless # there are at least two -arch flags with different values. ac_arch= ac_prev= for ac_word in $CC $CFLAGS $CPPFLAGS $LDFLAGS; do if test -n "$ac_prev"; then case $ac_word in i?86 | x86_64 | ppc | ppc64) if test -z "$ac_arch" || test "$ac_arch" = "$ac_word"; then ac_arch=$ac_word else ac_cv_c_bigendian=universal break fi ;; esac ac_prev= elif test "x$ac_word" = "x-arch"; then ac_prev=arch fi done fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext if test $ac_cv_c_bigendian = unknown; then # See if sys/param.h defines the BYTE_ORDER macro. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include int main (void) { #if ! (defined BYTE_ORDER && defined BIG_ENDIAN \ && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \ && LITTLE_ENDIAN) bogus endian macros #endif ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : # It does; now see whether it defined to BIG_ENDIAN or not. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include int main (void) { #if BYTE_ORDER != BIG_ENDIAN not big endian #endif ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ac_cv_c_bigendian=yes else $as_nop ac_cv_c_bigendian=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi if test $ac_cv_c_bigendian = unknown; then # See if defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris). cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main (void) { #if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN) bogus endian macros #endif ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : # It does; now see whether it defined to _BIG_ENDIAN or not. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main (void) { #ifndef _BIG_ENDIAN not big endian #endif ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ac_cv_c_bigendian=yes else $as_nop ac_cv_c_bigendian=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi if test $ac_cv_c_bigendian = unknown; then # Compile a test program. if test "$cross_compiling" = yes then : # Try to guess by grepping values from an object file. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ unsigned short int ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 }; unsigned short int ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 }; int use_ascii (int i) { return ascii_mm[i] + ascii_ii[i]; } unsigned short int ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 }; unsigned short int ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 }; int use_ebcdic (int i) { return ebcdic_mm[i] + ebcdic_ii[i]; } extern int foo; int main (void) { return use_ascii (foo) == use_ebcdic (foo); ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : if grep BIGenDianSyS conftest.$ac_objext >/dev/null; then ac_cv_c_bigendian=yes fi if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then if test "$ac_cv_c_bigendian" = unknown; then ac_cv_c_bigendian=no else # finding both strings is unlikely to happen, but who knows? ac_cv_c_bigendian=unknown fi fi fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default int main (void) { /* Are we little or big endian? From Harbison&Steele. */ union { long int l; char c[sizeof (long int)]; } u; u.l = 1; return u.c[sizeof (long int) - 1] == 1; ; return 0; } _ACEOF if ac_fn_objc_try_run "$LINENO" then : ac_cv_c_bigendian=no else $as_nop ac_cv_c_bigendian=yes fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_bigendian" >&5 printf "%s\n" "$ac_cv_c_bigendian" >&6; } case $ac_cv_c_bigendian in #( yes) printf "%s\n" "#define OF_BIG_ENDIAN 1" >>confdefs.h ;; #( no) ;; #( universal) printf "%s\n" "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h ;; #( *) as_fn_error $? "unknown endianness presetting ac_cv_c_bigendian=no (or yes) will help" "$LINENO" 5 ;; esac if test x"$ac_cv_c_bigendian" = x"universal" then : printf "%s\n" "#define OF_UNIVERSAL 1" >>confdefs.h fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for SSIZE_MAX" >&5 printf %s "checking for SSIZE_MAX... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #ifdef SSIZE_MAX egrep_cpp_yes #endif _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "egrep_cpp_yes" >/dev/null 2>&1 then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } printf "%s\n" "#define SSIZE_MAX (SIZE_MAX / 2)" >>confdefs.h fi rm -rf conftest* { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for UINTPTR_MAX" >&5 printf %s "checking for UINTPTR_MAX... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #ifdef UINTPTR_MAX egrep_cpp_yes #endif _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "egrep_cpp_yes" >/dev/null 2>&1 then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } # The cast to long int works around a bug in the HP C Compiler # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. # This bug is HP SR number 8606223364. { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking size of uintptr_t" >&5 printf %s "checking size of uintptr_t... " >&6; } if test ${ac_cv_sizeof_uintptr_t+y} then : printf %s "(cached) " >&6 else $as_nop if ac_fn_objc_compute_int "$LINENO" "(long int) (sizeof (uintptr_t))" "ac_cv_sizeof_uintptr_t" "$ac_includes_default" then : else $as_nop if test "$ac_cv_type_uintptr_t" = yes; then { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "cannot compute sizeof (uintptr_t) See \`config.log' for more details" "$LINENO" 5; } else ac_cv_sizeof_uintptr_t=0 fi fi fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_uintptr_t" >&5 printf "%s\n" "$ac_cv_sizeof_uintptr_t" >&6; } printf "%s\n" "#define SIZEOF_UINTPTR_T $ac_cv_sizeof_uintptr_t" >>confdefs.h printf "%s\n" "#define UINTPTR_MAX (SIZEOF_UINTPTR_T * CHAR_BIT)" >>confdefs.h fi rm -rf conftest* ac_fn_objc_check_header_compile "$LINENO" "inttypes.h" "ac_cv_header_inttypes_h" "$ac_includes_default" if test "x$ac_cv_header_inttypes_h" = xyes then : printf "%s\n" "#define OF_HAVE_INTTYPES_H 1" >>confdefs.h fi ac_fn_objc_check_header_compile "$LINENO" "sys/types.h" "ac_cv_header_sys_types_h" "$ac_includes_default" if test "x$ac_cv_header_sys_types_h" = xyes then : printf "%s\n" "#define OF_HAVE_SYS_TYPES_H 1" >>confdefs.h fi ac_fn_objc_check_header_compile "$LINENO" "stdnoreturn.h" "ac_cv_header_stdnoreturn_h" "$ac_includes_default" if test "x$ac_cv_header_stdnoreturn_h" = xyes then : printf "%s\n" "#define OF_HAVE_STDNORETURN_H 1" >>confdefs.h fi ac_fn_objc_check_type "$LINENO" "wchar_t" "ac_cv_type_wchar_t" "$ac_includes_default" if test "x$ac_cv_type_wchar_t" = xyes then : fi ac_fn_objc_check_header_compile "$LINENO" "wchar.h" "ac_cv_header_wchar_h" "$ac_includes_default" if test "x$ac_cv_header_wchar_h" = xyes then : fi # The cast to long int works around a bug in the HP C Compiler # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. # This bug is HP SR number 8606223364. { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking size of float" >&5 printf %s "checking size of float... " >&6; } if test ${ac_cv_sizeof_float+y} then : printf %s "(cached) " >&6 else $as_nop if ac_fn_objc_compute_int "$LINENO" "(long int) (sizeof (float))" "ac_cv_sizeof_float" "$ac_includes_default" then : else $as_nop if test "$ac_cv_type_float" = yes; then { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "cannot compute sizeof (float) See \`config.log' for more details" "$LINENO" 5; } else ac_cv_sizeof_float=0 fi fi fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_float" >&5 printf "%s\n" "$ac_cv_sizeof_float" >&6; } printf "%s\n" "#define SIZEOF_FLOAT $ac_cv_sizeof_float" >>confdefs.h # The cast to long int works around a bug in the HP C Compiler # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. # This bug is HP SR number 8606223364. { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking size of double" >&5 printf %s "checking size of double... " >&6; } if test ${ac_cv_sizeof_double+y} then : printf %s "(cached) " >&6 else $as_nop if ac_fn_objc_compute_int "$LINENO" "(long int) (sizeof (double))" "ac_cv_sizeof_double" "$ac_includes_default" then : else $as_nop if test "$ac_cv_type_double" = yes; then { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "cannot compute sizeof (double) See \`config.log' for more details" "$LINENO" 5; } else ac_cv_sizeof_double=0 fi fi fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_double" >&5 printf "%s\n" "$ac_cv_sizeof_double" >&6; } printf "%s\n" "#define SIZEOF_DOUBLE $ac_cv_sizeof_double" >>confdefs.h if test x"$ac_cv_sizeof_float" != x"4" -o x"$ac_cv_sizeof_double" != x"8" then : as_fn_error $? "Floating point implementation does not conform to IEEE 754!" "$LINENO" 5 fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for floating point endianess" >&5 printf %s "checking for floating point endianess... " >&6; } fp_endianess="unknown" if test x"$ac_cv_c_bigendian" != x"universal" then : cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ double endianess = 2.993700760838795055656993580068609688772747263874402942272934826871811872228512759832626847251963763755836687759498519784550143745834860002945223766052808125982053455555265216112722718870586961456110693379343178124592311441022662940307099598578775368547768968914916965731708568179631324904813506101190853720749196062963892799499230635163056742330563321122389331703618066046034494287335316842529021563862331183541255013987734473643350285400060357711238514186776429325214739886098119655678483017894951556639821088508565036657794343031121375178126860889964700274558728491825977274341798997758923017217660272136611938897932105874133412726223468780517578125e-259; _ACEOF if ac_fn_objc_try_compile "$LINENO" then : if $SED 's/[^[:print:]]//g' /dev/null then : printf "%s\n" "#define OF_FLOAT_BIG_ENDIAN 1" >>confdefs.h fp_endianess="big endian" else $as_nop if $SED 's/[^[:print:]]//g' \ /dev/null then : fp_endianess="little endian" fi fi fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext else $as_nop fp_endianess="universal" fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $fp_endianess" >&5 printf "%s\n" "$fp_endianess" >&6; } if test x"$fp_endianess" = x"unknown" then : as_fn_error $? "Floating point implementation does not conform to IEEE 754!" "$LINENO" 5 fi case "$host_cpu" in arm* | earm*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for blx" >&5 printf %s "checking for blx... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { #if !defined(__arm64__) && !defined(__arch64__) && \ !defined(__ARM64_ARCH_8__) __asm__ __volatile__ ( "blx r12" ); #endif ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : printf "%s\n" "#define HAVE_BLX 1" >>confdefs.h { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for VFP2 or above" >&5 printf %s "checking for VFP2 or above... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { #if !defined(__arm64__) && !defined(__aarch64__) && \ !defined(__ARM64_ARCH_8__) __asm__ __volatile__ ( "vstmdb sp!, {d0-d7}" ); #endif ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : printf "%s\n" "#define HAVE_VFP2 1" >>confdefs.h { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;; aarch64* | arm64*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for bti" >&5 printf %s "checking for bti... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { __asm__ __volatile__ ("bti c"); ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : printf "%s\n" "#define HAVE_BTI 1" >>confdefs.h { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;; i?86 | x86_64) ac_fn_objc_check_header_compile "$LINENO" "cet.h" "ac_cv_header_cet_h" "$ac_includes_default" if test "x$ac_cv_header_cet_h" = xyes then : printf "%s\n" "#define HAVE_CET_H 1" >>confdefs.h fi ;; esac { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for fmod in -lm" >&5 printf %s "checking for fmod in -lm... " >&6; } if test ${ac_cv_lib_m_fmod+y} then : printf %s "(cached) " >&6 else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-lm $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ char fmod (); int main (void) { return fmod (); ; return 0; } _ACEOF if ac_fn_objc_try_link "$LINENO" then : ac_cv_lib_m_fmod=yes else $as_nop ac_cv_lib_m_fmod=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_m_fmod" >&5 printf "%s\n" "$ac_cv_lib_m_fmod" >&6; } if test "x$ac_cv_lib_m_fmod" = xyes then : LIBS="$LIBS -lm" fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for creal in -lcomplex" >&5 printf %s "checking for creal in -lcomplex... " >&6; } if test ${ac_cv_lib_complex_creal+y} then : printf %s "(cached) " >&6 else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-lcomplex $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ char creal (); int main (void) { return creal (); ; return 0; } _ACEOF if ac_fn_objc_try_link "$LINENO" then : ac_cv_lib_complex_creal=yes else $as_nop ac_cv_lib_complex_creal=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_complex_creal" >&5 printf "%s\n" "$ac_cv_lib_complex_creal" >&6; } if test "x$ac_cv_lib_complex_creal" = xyes then : TESTS_LIBS="$TESTS_LIBS -lcomplex" fi ac_fn_objc_check_func "$LINENO" "strtof" "ac_cv_func_strtof" if test "x$ac_cv_func_strtof" = xyes then : printf "%s\n" "#define HAVE_STRTOF 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "truncf" "ac_cv_func_truncf" if test "x$ac_cv_func_truncf" = xyes then : printf "%s\n" "#define HAVE_TRUNCF 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "asprintf" "ac_cv_func_asprintf" if test "x$ac_cv_func_asprintf" = xyes then : case "$host" in *-*-mint*) have_asprintf="no" ;; *-*-mingw*) have_asprintf="no" ;; *-psp-*) have_asprintf="no" ;; *) have_asprintf="yes" printf "%s\n" "#define HAVE_ASPRINTF 1" >>confdefs.h ;; esac else $as_nop have_asprintf="no" fi # Check whether --enable-unicode-tables was given. if test ${enable_unicode_tables+y} then : enableval=$enable_unicode_tables; fi if test x"$enable_unicode_tables" != x"no" then : printf "%s\n" "#define OF_HAVE_UNICODE_TABLES 1" >>confdefs.h UNICODE_M="unicode.m" fi ENCODINGS_SRCS="" # Check whether --enable-codepage-437 was given. if test ${enable_codepage_437+y} then : enableval=$enable_codepage_437; fi if test x"$enable_codepage_437" != x"no" then : printf "%s\n" "#define HAVE_CODEPAGE_437 1" >>confdefs.h ENCODINGS_SRCS="$ENCODINGS_SRCS codepage-437.m" fi # Check whether --enable-codepage-850 was given. if test ${enable_codepage_850+y} then : enableval=$enable_codepage_850; fi if test x"$enable_codepage_850" != x"no" then : printf "%s\n" "#define HAVE_CODEPAGE_850 1" >>confdefs.h ENCODINGS_SRCS="$ENCODINGS_SRCS codepage-850.m" fi # Check whether --enable-codepage-858 was given. if test ${enable_codepage_858+y} then : enableval=$enable_codepage_858; fi if test x"$enable_codepage_858" != x"no" then : printf "%s\n" "#define HAVE_CODEPAGE_858 1" >>confdefs.h ENCODINGS_SRCS="$ENCODINGS_SRCS codepage-858.m" fi # Check whether --enable-iso-8859-2 was given. if test ${enable_iso_8859_2+y} then : enableval=$enable_iso_8859_2; fi if test x"$enable_iso_8859_2" != x"no" then : printf "%s\n" "#define HAVE_ISO_8859_2 1" >>confdefs.h ENCODINGS_SRCS="$ENCODINGS_SRCS iso-8859-2.m" fi # Check whether --enable-iso-8859-3 was given. if test ${enable_iso_8859_3+y} then : enableval=$enable_iso_8859_3; fi if test x"$enable_iso_8859_3" != x"no" then : printf "%s\n" "#define HAVE_ISO_8859_3 1" >>confdefs.h ENCODINGS_SRCS="$ENCODINGS_SRCS iso-8859-3.m" fi # Check whether --enable-iso-8859-15 was given. if test ${enable_iso_8859_15+y} then : enableval=$enable_iso_8859_15; fi if test x"$enable_iso_8859_15" != x"no" then : printf "%s\n" "#define HAVE_ISO_8859_15 1" >>confdefs.h ENCODINGS_SRCS="$ENCODINGS_SRCS iso-8859-15.m" fi # Check whether --enable-koi8-r was given. if test ${enable_koi8_r+y} then : enableval=$enable_koi8_r; fi if test x"$enable_koi8_r" != x"no" then : printf "%s\n" "#define HAVE_KOI8_R 1" >>confdefs.h ENCODINGS_SRCS="$ENCODINGS_SRCS koi8-r.m" fi # Check whether --enable-koi8-u was given. if test ${enable_koi8_u+y} then : enableval=$enable_koi8_u; fi if test x"$enable_koi8_u" != x"no" then : printf "%s\n" "#define HAVE_KOI8_U 1" >>confdefs.h ENCODINGS_SRCS="$ENCODINGS_SRCS koi8-u.m" fi # Check whether --enable-mac-roman was given. if test ${enable_mac_roman+y} then : enableval=$enable_mac_roman; fi if test x"$enable_mac_roman" != x"no" then : printf "%s\n" "#define HAVE_MAC_ROMAN 1" >>confdefs.h ENCODINGS_SRCS="$ENCODINGS_SRCS mac-roman.m" fi # Check whether --enable-windows-1251 was given. if test ${enable_windows_1251+y} then : enableval=$enable_windows_1251; fi if test x"$enable_windows_1251" != x"no" then : printf "%s\n" "#define HAVE_WINDOWS_1251 1" >>confdefs.h ENCODINGS_SRCS="$ENCODINGS_SRCS windows-1251.m" fi # Check whether --enable-windows-1252 was given. if test ${enable_windows_1252+y} then : enableval=$enable_windows_1252; fi if test x"$enable_windows_1252" != x"no" then : printf "%s\n" "#define HAVE_WINDOWS_1252 1" >>confdefs.h ENCODINGS_SRCS="$ENCODINGS_SRCS windows-1252.m" fi if test x"$ENCODINGS_SRCS" = x"" then : ENCODINGS_SRCS="dummy.m" fi if test x"$enable_shared" != x"no" then : ENCODINGS_LIB_A="encodings.lib.a" fi if test x"$enable_static" = x"yes" -o x"$enable_shared" = x"no" then : ENCODINGS_A="encodings.a" fi for ac_func in arc4random arc4random_buf getrandom random do : as_ac_var=`printf "%s\n" "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_objc_check_func "$LINENO" "$ac_func" "$as_ac_var" if eval test \"x\$"$as_ac_var"\" = x"yes" then : cat >>confdefs.h <<_ACEOF #define `printf "%s\n" "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF break fi done if test x"$host_os" != x"morphos" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 printf %s "checking for dlopen in -ldl... " >&6; } if test ${ac_cv_lib_dl_dlopen+y} then : printf %s "(cached) " >&6 else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-ldl $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ char dlopen (); int main (void) { return dlopen (); ; return 0; } _ACEOF if ac_fn_objc_try_link "$LINENO" then : ac_cv_lib_dl_dlopen=yes else $as_nop ac_cv_lib_dl_dlopen=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 printf "%s\n" "$ac_cv_lib_dl_dlopen" >&6; } if test "x$ac_cv_lib_dl_dlopen" = xyes then : LIBS="$LIBS -ldl" fi fi case "$host_os" in netbsd*) ;; *) ac_fn_objc_check_func "$LINENO" "dladdr" "ac_cv_func_dladdr" if test "x$ac_cv_func_dladdr" = xyes then : printf "%s\n" "#define HAVE_DLADDR 1" >>confdefs.h fi ;; esac ac_fn_objc_check_header_compile "$LINENO" "sys/mman.h" "ac_cv_header_sys_mman_h" "$ac_includes_default" if test "x$ac_cv_header_sys_mman_h" = xyes then : printf "%s\n" "#define HAVE_SYS_MMAN_H 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "mmap" "ac_cv_func_mmap" if test "x$ac_cv_func_mmap" = xyes then : printf "%s\n" "#define HAVE_MMAP 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "mlock" "ac_cv_func_mlock" if test "x$ac_cv_func_mlock" = xyes then : printf "%s\n" "#define HAVE_MLOCK 1" >>confdefs.h fi # Check whether --enable-threads was given. if test ${enable_threads+y} then : enableval=$enable_threads; fi if test x"$enable_threads" != x"no" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for threads" >&5 printf %s "checking for threads... " >&6; } case "$host_os" in amigaos* | morphos*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: Amiga" >&5 printf "%s\n" "Amiga" >&6; } have_amiga_threads="yes" ;; mingw*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: WinAPI" >&5 printf "%s\n" "WinAPI" >&6; } ;; *) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: POSIX" >&5 printf "%s\n" "POSIX" >&6; } { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether Objective C compiler accepts -Wp,-pthread" >&5 printf %s "checking whether Objective C compiler accepts -Wp,-pthread... " >&6; } if test ${ax_cv_objc_flags__Wp+y} then : printf %s "(cached) " >&6 else $as_nop ax_save_FLAGS=$OBJCFLAGS OBJCFLAGS="-Wp,-pthread" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ax_cv_objc_flags__Wp=yes else $as_nop ax_cv_objc_flags__Wp=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext OBJCFLAGS=$ax_save_FLAGS fi eval ax_check_compiler_flags=$ax_cv_objc_flags__Wp { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_check_compiler_flags" >&5 printf "%s\n" "$ax_check_compiler_flags" >&6; } if test "x$ax_check_compiler_flags" = xyes; then CPPFLAGS="$CPPFLAGS -Wp,-pthread" else CPPFLAGS="$CPPFLAGS -D_REENTRANT -D_THREAD_SAFE" fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for main in -lpthread" >&5 printf %s "checking for main in -lpthread... " >&6; } if test ${ac_cv_lib_pthread_main+y} then : printf %s "(cached) " >&6 else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-lpthread $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { return main (); ; return 0; } _ACEOF if ac_fn_objc_try_link "$LINENO" then : ac_cv_lib_pthread_main=yes else $as_nop ac_cv_lib_pthread_main=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread_main" >&5 printf "%s\n" "$ac_cv_lib_pthread_main" >&6; } if test "x$ac_cv_lib_pthread_main" = xyes then : LIBS="$LIBS -lpthread" fi cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main (void) { pthread_create(NULL, NULL, NULL, NULL); ; return 0; } _ACEOF if ac_fn_objc_try_link "$LINENO" then : else $as_nop as_fn_error $? "No supported threads found!" "$LINENO" 5 fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext printf "%s\n" "#define OF_HAVE_PTHREADS 1" >>confdefs.h cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main (void) { pthread_mutexattr_t attr; pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : printf "%s\n" "#define OF_HAVE_RECURSIVE_PTHREAD_MUTEXES 1" >>confdefs.h fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ac_fn_objc_check_func "$LINENO" "pthread_spin_lock" "ac_cv_func_pthread_spin_lock" if test "x$ac_cv_func_pthread_spin_lock" = xyes then : have_spinlocks="yes" printf "%s\n" "#define OF_HAVE_PTHREAD_SPINLOCKS 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "sched_yield" "ac_cv_func_sched_yield" if test "x$ac_cv_func_sched_yield" = xyes then : printf "%s\n" "#define OF_HAVE_SCHED_YIELD 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "pthread_attr_getschedpolicy" "ac_cv_func_pthread_attr_getschedpolicy" if test "x$ac_cv_func_pthread_attr_getschedpolicy" = xyes then : printf "%s\n" "#define HAVE_PTHREAD_ATTR_GETSCHEDPOLICY 1" >>confdefs.h fi old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -Werror" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for pthread_attr_setinheritsched" >&5 printf %s "checking for pthread_attr_setinheritsched... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main (void) { pthread_attr_setinheritsched( (pthread_attr_t *)-1, 0); ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } printf "%s\n" "#define HAVE_PTHREAD_ATTR_SETINHERITSCHED 1" >>confdefs.h else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext OBJCFLAGS="$old_OBJCFLAGS" ac_fn_objc_check_header_compile "$LINENO" "pthread_np.h" "ac_cv_header_pthread_np_h" "#include " if test "x$ac_cv_header_pthread_np_h" = xyes then : printf "%s\n" "#define HAVE_PTHREAD_NP_H 1" >>confdefs.h fi for ac_func in pthread_set_name_np pthread_setname_np do : as_ac_var=`printf "%s\n" "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_objc_check_func "$LINENO" "$ac_func" "$as_ac_var" if eval test \"x\$"$as_ac_var"\" = x"yes" then : cat >>confdefs.h <<_ACEOF #define `printf "%s\n" "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF break fi done ;; esac printf "%s\n" "#define OF_HAVE_THREADS 1" >>confdefs.h USE_SRCS_THREADS='${SRCS_THREADS}' OBJC_SYNC=objc_sync # Check whether --enable-compiler-tls was given. if test ${enable_compiler_tls+y} then : enableval=$enable_compiler_tls; fi case "$host" in aarch64*-*-android*) enable_compiler_tls="no" ;; m68k-*-amigaos* | powerpc-*-amigaos*) enable_compiler_tls="no" ;; *-*-mingw*) enable_compiler_tls="no" ;; *-*-morphos*) enable_compiler_tls="no" ;; esac if test x"$enable_compiler_tls" != x"no" then : ac_fn_objc_check_header_compile "$LINENO" "threads.h" "ac_cv_header_threads_h" "$ac_includes_default" if test "x$ac_cv_header_threads_h" = xyes then : printf "%s\n" "#define OF_HAVE_THREADS_H 1" >>confdefs.h fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether _Thread_local works" >&5 printf %s "checking whether _Thread_local works... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ static _Thread_local int x = 0; int main (void) { x++; ; return 0; } _ACEOF if ac_fn_objc_try_link "$LINENO" then : if test x"$enable_shared" != x"no" then : old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -fPIC" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ static _Thread_local int x = 0; int main (void) { x++; ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } printf "%s\n" "#define OF_HAVE__THREAD_LOCAL 1" >>confdefs.h have_thread_local="yes" else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext OBJCFLAGS="$old_OBJCFLAGS" else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } printf "%s\n" "#define OF_HAVE__THREAD_LOCAL 1" >>confdefs.h have_thread_local="yes" fi else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext if test x"$have_thread_local" != x"yes" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether __thread works" >&5 printf %s "checking whether __thread works... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* * It seems __thread is buggy with * GCC 4.1 */ #if __GNUC__ == 4 && __GNUC_MINOR__ < 2 # error buggy #endif __thread int x = 0; int main (void) { x++; ; return 0; } _ACEOF if ac_fn_objc_try_link "$LINENO" then : if test x"$enable_shared" != x"no" then : old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -fPIC" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ __thread int x = 0; int main (void) { x++; ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } printf "%s\n" "#define OF_HAVE___THREAD 1" >>confdefs.h else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext OBJCFLAGS="$old_OBJCFLAGS" else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } printf "%s\n" "#define OF_HAVE___THREAD 1" >>confdefs.h fi else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext fi fi atomic_ops="none" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether we have an atomic ops assembly implementation" >&5 printf %s "checking whether we have an atomic ops assembly implementation... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #if defined(__GNUC__) && (defined(__i386__) || \ defined(__x86_64__) || defined(__amd64__)) || \ ((defined(__ppc__) || defined(__PPC__) || \ defined(__powerpc__)) && !defined(__APPLE_CC__)) egrep_cpp_yes #endif _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "egrep_cpp_yes" >/dev/null 2>&1 then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } atomic_ops="assembly implementation" else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi rm -rf conftest* { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether __atomic_* works" >&5 printf %s "checking whether __atomic_* works... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include int main (void) { int32_t i, j; if (__atomic_add_fetch(&i, 1, __ATOMIC_RELAXED)) j = __atomic_sub_fetch(&i, 1, __ATOMIC_RELAXED); while (!__atomic_compare_exchange_n(&i, &j, 1, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED)); __atomic_thread_fence(__ATOMIC_SEQ_CST); ; return 0; } _ACEOF if ac_fn_objc_try_link "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } test x"$atomic_ops" = x"none" && \ atomic_ops="__atomic_* builtins" printf "%s\n" "#define OF_HAVE_ATOMIC_BUILTINS 1" >>confdefs.h else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether __sync_* works" >&5 printf %s "checking whether __sync_* works... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main (void) { int32_t i, j; if (__sync_add_and_fetch(&i, 1)) j = __sync_sub_and_fetch(&i, 1); while (!__sync_bool_compare_and_swap(&i, 0, 1)); ; return 0; } _ACEOF if ac_fn_objc_try_link "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } test x"$atomic_ops" = x"none" && \ atomic_ops="__sync_* builtins" printf "%s\n" "#define OF_HAVE_SYNC_BUILTINS 1" >>confdefs.h else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext ac_fn_objc_check_header_compile "$LINENO" "libkern/OSAtomic.h" "ac_cv_header_libkern_OSAtomic_h" "$ac_includes_default" if test "x$ac_cv_header_libkern_OSAtomic_h" = xyes then : test x"$atomic_ops" = x"none" && atomic_ops="libkern/OSAtomic.h" printf "%s\n" "#define OF_HAVE_OSATOMIC 1" >>confdefs.h fi else $as_nop atomic_ops="not needed" fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for atomic operations" >&5 printf %s "checking for atomic operations... " >&6; } if test x"$atomic_ops" != x"none" then : printf "%s\n" "#define OF_HAVE_ATOMIC_OPS 1" >>confdefs.h USE_INCLUDES_ATOMIC='${INCLUDES_ATOMIC}' fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $atomic_ops" >&5 printf "%s\n" "$atomic_ops" >&6; } # Check whether --enable-files was given. if test ${enable_files+y} then : enableval=$enable_files; fi if test x"$enable_files" != x"no" then : printf "%s\n" "#define OF_HAVE_FILES 1" >>confdefs.h USE_SRCS_FILES='${SRCS_FILES}' OBJFW_NEW="objfw-new" OFARC="ofarc" OFHASH="ofhash" case "$host_os" in msdosdjgpp*) ;; *) ac_fn_objc_check_type "$LINENO" "off64_t" "ac_cv_type_off64_t" "$ac_includes_default" if test "x$ac_cv_type_off64_t" = xyes then : printf "%s\n" "#define OF_HAVE_OFF64_T 1" >>confdefs.h ac_fn_objc_check_func "$LINENO" "lseek64" "ac_cv_func_lseek64" if test "x$ac_cv_func_lseek64" = xyes then : printf "%s\n" "#define HAVE_LSEEK64 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "lstat64" "ac_cv_func_lstat64" if test "x$ac_cv_func_lstat64" = xyes then : printf "%s\n" "#define HAVE_LSTAT64 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "open64" "ac_cv_func_open64" if test "x$ac_cv_func_open64" = xyes then : printf "%s\n" "#define HAVE_OPEN64 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "stat64" "ac_cv_func_stat64" if test "x$ac_cv_func_stat64" = xyes then : printf "%s\n" "#define HAVE_STAT64 1" >>confdefs.h fi fi ;; esac ac_fn_objc_check_header_compile "$LINENO" "pwd.h" "ac_cv_header_pwd_h" "$ac_includes_default" if test "x$ac_cv_header_pwd_h" = xyes then : printf "%s\n" "#define HAVE_PWD_H 1" >>confdefs.h fi ac_fn_objc_check_header_compile "$LINENO" "grp.h" "ac_cv_header_grp_h" "$ac_includes_default" if test "x$ac_cv_header_grp_h" = xyes then : printf "%s\n" "#define HAVE_GRP_H 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "chmod" "ac_cv_func_chmod" if test "x$ac_cv_func_chmod" = xyes then : printf "%s\n" "#define OF_HAVE_CHMOD 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "chown" "ac_cv_func_chown" if test "x$ac_cv_func_chown" = xyes then : printf "%s\n" "#define OF_HAVE_CHOWN 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "link" "ac_cv_func_link" if test "x$ac_cv_func_link" = xyes then : printf "%s\n" "#define OF_HAVE_LINK 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "symlink" "ac_cv_func_symlink" if test "x$ac_cv_func_symlink" = xyes then : printf "%s\n" "#define OF_HAVE_SYMLINK 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "lstat" "ac_cv_func_lstat" if test "x$ac_cv_func_lstat" = xyes then : printf "%s\n" "#define HAVE_LSTAT 1" >>confdefs.h fi ac_fn_objc_check_member "$LINENO" "struct stat" "st_birthtime" "ac_cv_member_struct_stat_st_birthtime" " #include " if test "x$ac_cv_member_struct_stat_st_birthtime" = xyes then : printf "%s\n" "#define HAVE_STRUCT_STAT_ST_BIRTHTIME 1" >>confdefs.h fi fi ac_fn_objc_check_header_compile "$LINENO" "dirent.h" "ac_cv_header_dirent_h" "$ac_includes_default" if test "x$ac_cv_header_dirent_h" = xyes then : printf "%s\n" "#define HAVE_DIRENT_H 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "sysconf" "ac_cv_func_sysconf" if test "x$ac_cv_func_sysconf" = xyes then : printf "%s\n" "#define HAVE_SYSCONF 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "gmtime_r" "ac_cv_func_gmtime_r" if test "x$ac_cv_func_gmtime_r" = xyes then : printf "%s\n" "#define HAVE_GMTIME_R 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "localtime_r" "ac_cv_func_localtime_r" if test "x$ac_cv_func_localtime_r" = xyes then : printf "%s\n" "#define HAVE_LOCALTIME_R 1" >>confdefs.h fi case "$host_os" in amigaos* | morphos*) ;; *) ac_fn_objc_check_header_compile "$LINENO" "fcntl.h" "ac_cv_header_fcntl_h" "$ac_includes_default" if test "x$ac_cv_header_fcntl_h" = xyes then : printf "%s\n" "#define HAVE_FCNTL_H 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "fcntl" "ac_cv_func_fcntl" if test "x$ac_cv_func_fcntl" = xyes then : printf "%s\n" "#define HAVE_FCNTL 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "nanosleep" "ac_cv_func_nanosleep" if test "x$ac_cv_func_nanosleep" = xyes then : printf "%s\n" "#define HAVE_NANOSLEEP 1" >>confdefs.h fi ;; esac ac_fn_objc_check_header_compile "$LINENO" "xlocale.h" "ac_cv_header_xlocale_h" "$ac_includes_default" if test "x$ac_cv_header_xlocale_h" = xyes then : printf "%s\n" "#define HAVE_XLOCALE_H 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "strtod_l" "ac_cv_func_strtod_l" if test "x$ac_cv_func_strtod_l" = xyes then : printf "%s\n" "#define HAVE_STRTOD_L 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "strtof_l" "ac_cv_func_strtof_l" if test "x$ac_cv_func_strtof_l" = xyes then : printf "%s\n" "#define HAVE_STRTOF_L 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "asprintf_l" "ac_cv_func_asprintf_l" if test "x$ac_cv_func_asprintf_l" = xyes then : printf "%s\n" "#define HAVE_ASPRINTF_L 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "uselocale" "ac_cv_func_uselocale" if test "x$ac_cv_func_uselocale" = xyes then : printf "%s\n" "#define HAVE_USELOCALE 1" >>confdefs.h fi if test x"$gnu_source" != x"yes" -a \( \ x"$ac_cv_func_strtod_l" = x"yes" -o x"$ac_cv_func_strtof_l" = x"yes" -o \ x"$ac_cv_func_asprintf_l" = x"yes" \) then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether *_l functions need _GNU_SOURCE" >&5 printf %s "checking whether *_l functions need _GNU_SOURCE... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #include #ifdef HAVE_XLOCALE_H # include #endif int main (void) { #ifdef HAVE_STRTOD_L (void)strtod_l; #endif #ifdef HAVE_STRTOF_L (void)strtof_l; #endif #ifdef HAVE_ASPRINTF_L (void)asprintf_l; #endif ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } CPPFLAGS="-D_GNU_SOURCE $CPPFLAGS" fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi for ac_func in strerror_r do : ac_fn_objc_check_func "$LINENO" "strerror_r" "ac_cv_func_strerror_r" if test "x$ac_cv_func_strerror_r" = xyes then : printf "%s\n" "#define HAVE_STRERROR_R 1" >>confdefs.h { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for return type of strerror_r" >&5 printf %s "checking for return type of strerror_r... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include int main (void) { switch (strerror_r(0, NULL, 0)) { case 0:; } ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: int" >&5 printf "%s\n" "int" >&6; } else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: char *" >&5 printf "%s\n" "char *" >&6; } printf "%s\n" "#define STRERROR_R_RETURNS_CHARP 1" >>confdefs.h fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi done ac_fn_objc_check_header_compile "$LINENO" "sys/utsname.h" "ac_cv_header_sys_utsname_h" "$ac_includes_default" if test "x$ac_cv_header_sys_utsname_h" = xyes then : printf "%s\n" "#define HAVE_SYS_UTSNAME_H 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "uname" "ac_cv_func_uname" if test "x$ac_cv_func_uname" = xyes then : printf "%s\n" "#define HAVE_UNAME 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "pipe" "ac_cv_func_pipe" if test "x$ac_cv_func_pipe" = xyes then : printf "%s\n" "#define OF_HAVE_PIPE 1" >>confdefs.h fi # Check whether --enable-sockets was given. if test ${enable_sockets+y} then : enableval=$enable_sockets; fi if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}pkg-config", so it can be a program name with args. set dummy ${ac_tool_prefix}pkg-config; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_path_PKG_CONFIG+y} then : printf %s "(cached) " >&6 else $as_nop case $PKG_CONFIG in [\\/]* | ?:[\\/]*) ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path. ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_path_PKG_CONFIG="$as_dir$ac_word$ac_exec_ext" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS ;; esac fi PKG_CONFIG=$ac_cv_path_PKG_CONFIG if test -n "$PKG_CONFIG"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $PKG_CONFIG" >&5 printf "%s\n" "$PKG_CONFIG" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi fi if test -z "$ac_cv_path_PKG_CONFIG"; then ac_pt_PKG_CONFIG=$PKG_CONFIG # Extract the first word of "pkg-config", so it can be a program name with args. set dummy pkg-config; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_path_ac_pt_PKG_CONFIG+y} then : printf %s "(cached) " >&6 else $as_nop case $ac_pt_PKG_CONFIG in [\\/]* | ?:[\\/]*) ac_cv_path_ac_pt_PKG_CONFIG="$ac_pt_PKG_CONFIG" # Let the user override the test with a path. ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_path_ac_pt_PKG_CONFIG="$as_dir$ac_word$ac_exec_ext" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS ;; esac fi ac_pt_PKG_CONFIG=$ac_cv_path_ac_pt_PKG_CONFIG if test -n "$ac_pt_PKG_CONFIG"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_pt_PKG_CONFIG" >&5 printf "%s\n" "$ac_pt_PKG_CONFIG" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi if test "x$ac_pt_PKG_CONFIG" = x; then PKG_CONFIG="" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac PKG_CONFIG=$ac_pt_PKG_CONFIG fi else PKG_CONFIG="$ac_cv_path_PKG_CONFIG" fi fi if test -n "$PKG_CONFIG"; then _pkg_min_version=0.9.0 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking pkg-config is at least version $_pkg_min_version" >&5 printf %s "checking pkg-config is at least version $_pkg_min_version... " >&6; } if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } PKG_CONFIG="" fi fi if test x"$enable_sockets" != x"no" then : printf "%s\n" "#define OF_HAVE_SOCKETS 1" >>confdefs.h USE_SRCS_SOCKETS='${SRCS_SOCKETS}' case "$host_os" in amigaos* | morphos*) ;; haiku*) LIBS="$LIBS -lnetwork" ;; mingw*) LIBS="$LIBS -lws2_32 -liphlpapi" ;; *) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for socket in -lsocket" >&5 printf %s "checking for socket in -lsocket... " >&6; } if test ${ac_cv_lib_socket_socket+y} then : printf %s "(cached) " >&6 else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-lsocket $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ char socket (); int main (void) { return socket (); ; return 0; } _ACEOF if ac_fn_objc_try_link "$LINENO" then : ac_cv_lib_socket_socket=yes else $as_nop ac_cv_lib_socket_socket=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_socket_socket" >&5 printf "%s\n" "$ac_cv_lib_socket_socket" >&6; } if test "x$ac_cv_lib_socket_socket" = xyes then : LIBS="$LIBS -lsocket" fi ;; esac ac_fn_objc_check_header_compile "$LINENO" "sys/socket.h" "ac_cv_header_sys_socket_h" "$ac_includes_default" if test "x$ac_cv_header_sys_socket_h" = xyes then : printf "%s\n" "#define OF_HAVE_SYS_SOCKET_H 1" >>confdefs.h fi ac_fn_objc_check_member "$LINENO" "struct sockaddr" "sa_len" "ac_cv_member_struct_sockaddr_sa_len" " #ifdef OF_HAVE_SYS_TYPES_H # include #endif #ifdef OF_HAVE_SYS_SOCKET_H # include #endif #ifdef _WIN32 # include #endif " if test "x$ac_cv_member_struct_sockaddr_sa_len" = xyes then : printf "%s\n" "#define HAVE_STRUCT_SOCKADDR_SA_LEN 1" >>confdefs.h fi ac_fn_objc_check_type "$LINENO" "struct sockaddr_storage" "ac_cv_type_struct_sockaddr_storage" " #ifdef OF_HAVE_SYS_TYPES_H # include #endif #ifdef OF_HAVE_SYS_SOCKET_H # include #endif #ifdef _WIN32 # include #endif " if test "x$ac_cv_type_struct_sockaddr_storage" = xyes then : printf "%s\n" "#define OF_HAVE_SOCKADDR_STORAGE 1" >>confdefs.h fi ac_fn_objc_check_header_compile "$LINENO" "netinet/in.h" "ac_cv_header_netinet_in_h" "$ac_includes_default" if test "x$ac_cv_header_netinet_in_h" = xyes then : printf "%s\n" "#define OF_HAVE_NETINET_IN_H 1" >>confdefs.h fi ac_fn_objc_check_header_compile "$LINENO" "netinet/tcp.h" "ac_cv_header_netinet_tcp_h" "$ac_includes_default" if test "x$ac_cv_header_netinet_tcp_h" = xyes then : printf "%s\n" "#define OF_HAVE_NETINET_TCP_H 1" >>confdefs.h fi ac_fn_objc_check_header_compile "$LINENO" "arpa/inet.h" "ac_cv_header_arpa_inet_h" "$ac_includes_default" if test "x$ac_cv_header_arpa_inet_h" = xyes then : printf "%s\n" "#define HAVE_ARPA_INET_H 1" >>confdefs.h fi ac_fn_objc_check_header_compile "$LINENO" "netdb.h" "ac_cv_header_netdb_h" "$ac_includes_default" if test "x$ac_cv_header_netdb_h" = xyes then : printf "%s\n" "#define HAVE_NETDB_H 1" >>confdefs.h fi ac_fn_objc_check_header_compile "$LINENO" "sys/sockio.h" "ac_cv_header_sys_sockio_h" "$ac_includes_default" if test "x$ac_cv_header_sys_sockio_h" = xyes then : printf "%s\n" "#define HAVE_SYS_SOCKIO_H 1" >>confdefs.h fi ac_fn_objc_check_header_compile "$LINENO" "net/if.h" "ac_cv_header_net_if_h" " #ifdef OF_HAVE_SYS_SOCKET_H # include #endif " if test "x$ac_cv_header_net_if_h" = xyes then : printf "%s\n" "#define HAVE_NET_IF_H 1" >>confdefs.h fi ac_fn_objc_check_header_compile "$LINENO" "net/if_arp.h" "ac_cv_header_net_if_arp_h" "$ac_includes_default" if test "x$ac_cv_header_net_if_arp_h" = xyes then : printf "%s\n" "#define HAVE_NET_IF_ARP_H 1" >>confdefs.h fi ac_fn_objc_check_header_compile "$LINENO" "net/if_dl.h" "ac_cv_header_net_if_dl_h" "$ac_includes_default" if test "x$ac_cv_header_net_if_dl_h" = xyes then : printf "%s\n" "#define HAVE_NET_IF_DL_H 1" >>confdefs.h fi ac_fn_objc_check_header_compile "$LINENO" "net/if_types.h" "ac_cv_header_net_if_types_h" "$ac_includes_default" if test "x$ac_cv_header_net_if_types_h" = xyes then : printf "%s\n" "#define HAVE_NET_IF_TYPES_H 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "if_indextoname" "ac_cv_func_if_indextoname" if test "x$ac_cv_func_if_indextoname" = xyes then : printf "%s\n" "#define HAVE_IF_INDEXTONAME 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "if_nametoindex" "ac_cv_func_if_nametoindex" if test "x$ac_cv_func_if_nametoindex" = xyes then : printf "%s\n" "#define HAVE_IF_NAMETOINDEX 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "if_nameindex" "ac_cv_func_if_nameindex" if test "x$ac_cv_func_if_nameindex" = xyes then : printf "%s\n" "#define HAVE_IF_NAMEINDEX 1" >>confdefs.h fi ac_fn_objc_check_type "$LINENO" "struct sockaddr_dl" "ac_cv_type_struct_sockaddr_dl" " #ifdef HAVE_SYS_TYPES_H # include #endif #ifdef HAVE_NET_IF_DL_H # include #endif " if test "x$ac_cv_type_struct_sockaddr_dl" = xyes then : printf "%s\n" "#define HAVE_STRUCT_SOCKADDR_DL 1" >>confdefs.h fi ac_fn_objc_check_type "$LINENO" "struct lifconf" "ac_cv_type_struct_lifconf" " #ifdef HAVE_NET_IF_H # include #endif " if test "x$ac_cv_type_struct_lifconf" = xyes then : printf "%s\n" "#define HAVE_STRUCT_LIFCONF 1" >>confdefs.h fi ac_fn_objc_check_member "$LINENO" "struct ifreq" "ifr_hwaddr" "ac_cv_member_struct_ifreq_ifr_hwaddr" " #ifdef HAVE_NET_IF_H # include #endif " if test "x$ac_cv_member_struct_ifreq_ifr_hwaddr" = xyes then : printf "%s\n" "#define HAVE_STRUCT_IFREQ_IFR_HWADDR 1" >>confdefs.h fi ac_fn_objc_check_header_compile "$LINENO" "sys/un.h" "ac_cv_header_sys_un_h" "$ac_includes_default" if test "x$ac_cv_header_sys_un_h" = xyes then : printf "%s\n" "#define OF_HAVE_SYS_UN_H 1" >>confdefs.h fi ac_fn_objc_check_member "$LINENO" "struct sockaddr_in6" "sin6_addr" "ac_cv_member_struct_sockaddr_in6_sin6_addr" " #ifdef _WIN32 typedef int BOOL; #endif #ifdef OF_HAVE_NETINET_IN_H # include #endif #ifdef _WIN32 # ifdef __MINGW32__ # include <_mingw.h> # ifdef __MINGW64_VERSION_MAJOR # include # endif # endif # include # include #endif " if test "x$ac_cv_member_struct_sockaddr_in6_sin6_addr" = xyes then : cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef _WIN32 typedef int BOOL; #endif #ifdef OF_HAVE_SYS_SOCKET_H # include #endif #ifdef _WIN32 # ifdef __MINGW32__ # include <_mingw.h> # ifdef __MINGW64_VERSION_MAJOR # include # endif # endif # include # include #endif #ifdef AF_INET6 egrep_cpp_yes #endif _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "egrep_cpp_yes" >/dev/null 2>&1 then : printf "%s\n" "#define OF_HAVE_IPV6 1" >>confdefs.h fi rm -rf conftest* else $as_nop : fi for ac_header in afunix.h do : ac_fn_objc_check_header_compile "$LINENO" "afunix.h" "ac_cv_header_afunix_h" " #ifdef _WIN32 # include #endif " if test "x$ac_cv_header_afunix_h" = xyes then : printf "%s\n" "#define HAVE_AFUNIX_H 1" >>confdefs.h printf "%s\n" "#define OF_HAVE_AFUNIX_H 1" >>confdefs.h fi done ac_fn_objc_check_member "$LINENO" "struct sockaddr_un" "sun_path" "ac_cv_member_struct_sockaddr_un_sun_path" " #ifdef OF_HAVE_SYS_TYPES_H # include #endif #ifdef OF_HAVE_SYS_UN_H # include #endif #ifdef _WIN32 # include #endif #ifdef HAVE_AFUNIX_H # include #endif #ifdef __morphos__ # error MorphOS has the struct but does not support it #endif #ifdef __MINT__ # error Gives invalid argument at runtime #endif " if test "x$ac_cv_member_struct_sockaddr_un_sun_path" = xyes then : printf "%s\n" "#define OF_HAVE_UNIX_SOCKETS 1" >>confdefs.h USE_SRCS_UNIX_SOCKETS='${SRCS_UNIX_SOCKETS}' ac_fn_objc_check_member "$LINENO" "struct sockaddr_un" "sun_len" "ac_cv_member_struct_sockaddr_un_sun_len" " #ifdef OF_HAVE_SYS_TYPES_H # include #endif #ifdef OF_HAVE_SYS_UN_H # include #endif #ifdef _WIN32 # include #endif #ifdef HAVE_AFUNIX_H # include #endif " if test "x$ac_cv_member_struct_sockaddr_un_sun_len" = xyes then : printf "%s\n" "#define HAVE_STRUCT_SOCKADDR_UN_SUN_LEN 1" >>confdefs.h fi fi ac_fn_objc_check_header_compile "$LINENO" "netipx/ipx.h" "ac_cv_header_netipx_ipx_h" "$ac_includes_default" if test "x$ac_cv_header_netipx_ipx_h" = xyes then : printf "%s\n" "#define OF_HAVE_NETIPX_IPX_H 1" >>confdefs.h fi ac_fn_objc_check_member "$LINENO" "struct sockaddr_ipx" "sipx_network" "ac_cv_member_struct_sockaddr_ipx_sipx_network" " #ifdef _WIN32 typedef int BOOL; #endif #ifdef HAVE_SYS_TYPES_H # include #endif #ifdef OF_HAVE_NETIPX_IPX_H # include #endif #ifdef _WIN32 # ifdef __MINGW32__ # include <_mingw.h> # ifdef __MINGW64_VERSION_MAJOR # include # endif # endif # include # include #endif " if test "x$ac_cv_member_struct_sockaddr_ipx_sipx_network" = xyes then : else $as_nop ac_fn_objc_check_member "$LINENO" "struct sockaddr_ipx" "sa_netnum" "ac_cv_member_struct_sockaddr_ipx_sa_netnum" " #ifdef _WIN32 typedef int BOOL; #endif #ifdef HAVE_SYS_TYPES_H # include #endif #ifdef OF_HAVE_NETIPX_IPX_H # include #endif #ifdef _WIN32 # ifdef __MINGW32__ # include <_mingw.h> # ifdef __MINGW64_VERSION_MAJOR # include # endif # endif # include # include #endif " if test "x$ac_cv_member_struct_sockaddr_ipx_sa_netnum" = xyes then : else $as_nop ac_fn_objc_check_member "$LINENO" "struct sockaddr_ipx" "sipx_addr.x_port" "ac_cv_member_struct_sockaddr_ipx_sipx_addr_x_port" " #ifdef HAVE_SYS_TYPES_H # include #endif #ifdef OF_HAVE_NETIPX_IPX_H # include #endif " if test "x$ac_cv_member_struct_sockaddr_ipx_sipx_addr_x_port" = xyes then : fi fi fi if test x"$ac_cv_member_struct_sockaddr_ipx_sipx_network" = x"yes" \ -o x"$ac_cv_member_struct_sockaddr_ipx_sa_netnum" = x"yes" -o \ x"$ac_cv_member_struct_sockaddr_ipx_sipx_addr_x_port" = x"yes" then : cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef _WIN32 typedef int BOOL; #endif #ifdef OF_HAVE_SYS_SOCKET_H # include #endif #ifdef _WIN32 # ifdef __MINGW32__ # include <_mingw.h> # ifdef __MINGW64_VERSION_MAJOR # include # endif # endif # include # include #endif #ifdef AF_IPX egrep_cpp_yes #endif _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "egrep_cpp_yes" >/dev/null 2>&1 then : printf "%s\n" "#define OF_HAVE_IPX 1" >>confdefs.h USE_SRCS_IPX='${SRCS_IPX}' fi rm -rf conftest* fi ac_fn_objc_check_header_compile "$LINENO" "netat/appletalk.h" "ac_cv_header_netat_appletalk_h" "$ac_includes_default" if test "x$ac_cv_header_netat_appletalk_h" = xyes then : printf "%s\n" "#define OF_HAVE_NETAT_APPLETALK_H 1" >>confdefs.h fi ac_fn_objc_check_header_compile "$LINENO" "netatalk/at.h" "ac_cv_header_netatalk_at_h" "$ac_includes_default" if test "x$ac_cv_header_netatalk_at_h" = xyes then : printf "%s\n" "#define OF_HAVE_NETATALK_AT_H 1" >>confdefs.h fi ac_fn_objc_check_member "$LINENO" "struct sockaddr_at" "sat_addr" "ac_cv_member_struct_sockaddr_at_sat_addr" " #ifdef _WIN32 typedef int BOOL; #endif #ifdef OF_HAVE_SYS_TYPES_H # include #endif #if defined(OF_HAVE_NETAT_APPLETALK_H) # include #elif defined(OF_HAVE_NETATALK_AT_H) # include #endif #ifdef _WIN32 # ifdef __MINGW32__ # include <_mingw.h> # ifdef __MINGW64_VERSION_MAJOR # include # endif # endif # include # include #endif " if test "x$ac_cv_member_struct_sockaddr_at_sat_addr" = xyes then : else $as_nop ac_fn_objc_check_member "$LINENO" "struct sockaddr_at" "sat_net" "ac_cv_member_struct_sockaddr_at_sat_net" " #ifdef _WIN32 typedef int BOOL; #endif #ifdef OF_HAVE_SYS_TYPES_H # include #endif #if defined(OF_HAVE_NETAT_APPLETALK_H) # include #elif defined(OF_HAVE_NETATALK_AT_H) # include #endif #ifdef _WIN32 # ifdef __MINGW32__ # include <_mingw.h> # ifdef __MINGW64_VERSION_MAJOR # include # endif # endif # include # include #endif " if test "x$ac_cv_member_struct_sockaddr_at_sat_net" = xyes then : fi fi if test x"$ac_cv_member_struct_sockaddr_at_sat_addr" = x"yes" \ -o x"$ac_cv_member_struct_sockaddr_at_sat_net" = x"yes" then : cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef _WIN32 typedef int BOOL; #endif #ifdef OF_HAVE_SYS_SOCKET_H # include #endif #ifdef _WIN32 # ifdef __MINGW32__ # include <_mingw.h> # ifdef __MINGW64_VERSION_MAJOR # include # endif # endif # include # include #endif #ifdef AF_APPLETALK egrep_cpp_yes #endif _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "egrep_cpp_yes" >/dev/null 2>&1 then : printf "%s\n" "#define OF_HAVE_APPLETALK 1" >>confdefs.h USE_SRCS_APPLETALK='${SRCS_APPLETALK}' fi rm -rf conftest* fi for ac_func in paccept accept4 do : as_ac_var=`printf "%s\n" "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_objc_check_func "$LINENO" "$ac_func" "$as_ac_var" if eval test \"x\$"$as_ac_var"\" = x"yes" then : cat >>confdefs.h <<_ACEOF #define `printf "%s\n" "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF break fi done for ac_func in kqueue1 kqueue do : as_ac_var=`printf "%s\n" "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_objc_check_func "$LINENO" "$ac_func" "$as_ac_var" if eval test \"x\$"$as_ac_var"\" = x"yes" then : cat >>confdefs.h <<_ACEOF #define `printf "%s\n" "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF printf "%s\n" "#define HAVE_KQUEUE 1" >>confdefs.h OF_KQUEUE_KERNEL_EVENT_OBSERVER_M="OFKqueueKernelEventObserver.m" break fi done for ac_func in epoll_create1 epoll_create do : as_ac_var=`printf "%s\n" "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_objc_check_func "$LINENO" "$ac_func" "$as_ac_var" if eval test \"x\$"$as_ac_var"\" = x"yes" then : cat >>confdefs.h <<_ACEOF #define `printf "%s\n" "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF printf "%s\n" "#define HAVE_EPOLL 1" >>confdefs.h OF_EPOLL_KERNEL_EVENT_OBSERVER_M="OFEpollKernelEventObserver.m" break fi done if test x"$with_wii" = x"yes" then : printf "%s\n" "#define HAVE_POLL 1" >>confdefs.h OF_POLL_KERNEL_EVENT_OBSERVER_M="OFPollKernelEventObserver.m" else $as_nop ac_fn_objc_check_header_compile "$LINENO" "poll.h" "ac_cv_header_poll_h" "$ac_includes_default" if test "x$ac_cv_header_poll_h" = xyes then : printf "%s\n" "#define HAVE_POLL_H 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "poll" "ac_cv_func_poll" if test "x$ac_cv_func_poll" = xyes then : printf "%s\n" "#define HAVE_POLL 1" >>confdefs.h OF_POLL_KERNEL_EVENT_OBSERVER_M="OFPollKernelEventObserver.m" fi fi case "$host_os" in amigaos* | mingw* | morphos*) printf "%s\n" "#define HAVE_SELECT 1" >>confdefs.h OF_SELECT_KERNEL_EVENT_OBSERVER_M="OFSelectKernelEventObserver.m" ;; *) ac_fn_objc_check_header_compile "$LINENO" "sys/select.h" "ac_cv_header_sys_select_h" "$ac_includes_default" if test "x$ac_cv_header_sys_select_h" = xyes then : printf "%s\n" "#define HAVE_SYS_SELECT_H 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "select" "ac_cv_func_select" if test "x$ac_cv_func_select" = xyes then : printf "%s\n" "#define HAVE_SELECT 1" >>confdefs.h OF_SELECT_KERNEL_EVENT_OBSERVER_M="OFSelectKernelEventObserver.m" fi ;; esac # Check whether --with-tls was given. if test ${with_tls+y} then : withval=$with_tls; fi if test x"$with_tls" = x"" then : with_tls="yes" fi tls_support="no" if test x"$with_tls" = x"securetransport" \ -o x"$with_tls" = x"yes" then : for ac_header in Security/SecureTransport.h do : ac_fn_objc_check_header_compile "$LINENO" "Security/SecureTransport.h" "ac_cv_header_Security_SecureTransport_h" "$ac_includes_default" if test "x$ac_cv_header_Security_SecureTransport_h" = xyes then : printf "%s\n" "#define HAVE_SECURITY_SECURETRANSPORT_H 1" >>confdefs.h old_LIBS="$LIBS" LIBS="-framework Security -framework Foundation $LIBS" ac_fn_objc_check_func "$LINENO" "SSLHandshake" "ac_cv_func_SSLHandshake" if test "x$ac_cv_func_SSLHandshake" = xyes then : tls_support="Secure Transport" TLS_LIBS="-framework Foundation $TLS_LIBS" TLS_LIBS="-framework Security $TLS_LIBS" OF_SECURE_TRANSPORT_TLS_STREAM_M="OFSecureTransportTLSStream.m" ac_fn_objc_check_func "$LINENO" "SSLCreateContext" "ac_cv_func_SSLCreateContext" if test "x$ac_cv_func_SSLCreateContext" = xyes then : printf "%s\n" "#define HAVE_SSLCREATECONTEXT 1" >>confdefs.h fi fi LIBS="$old_LIBS" fi done fi if test x"$with_tls" = x"openssl" \ -o \( x"$with_tls" = x"yes" -a x"$tls_support" = x"no" \) then : case "$host_os" in morphos*) ssl="ssl_shared" crypto="crypto_shared" ;; *) ssl="ssl" crypto="crypto" ;; esac as_ac_Lib=`printf "%s\n" "ac_cv_lib_$ssl""_SSL_set1_host" | $as_tr_sh` { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for SSL_set1_host in -l$ssl" >&5 printf %s "checking for SSL_set1_host in -l$ssl... " >&6; } if eval test \${$as_ac_Lib+y} then : printf %s "(cached) " >&6 else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-l$ssl -l$crypto $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ char SSL_set1_host (); int main (void) { return SSL_set1_host (); ; return 0; } _ACEOF if ac_fn_objc_try_link "$LINENO" then : eval "$as_ac_Lib=yes" else $as_nop eval "$as_ac_Lib=no" fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi eval ac_res=\$$as_ac_Lib { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 printf "%s\n" "$ac_res" >&6; } if eval test \"x\$"$as_ac_Lib"\" = x"yes" then : ac_fn_objc_check_header_compile "$LINENO" "openssl/ssl.h" "ac_cv_header_openssl_ssl_h" "$ac_includes_default" if test "x$ac_cv_header_openssl_ssl_h" = xyes then : tls_support="OpenSSL" TLS_LIBS="-l$ssl -l$crypto $TLS_LIBS" OF_OPENSSL_TLS_STREAM_M="OFOpenSSLTLSStream.m" old_LIBS="$LIBS" LIBS="$TLS_LIBS $LIBS" ac_fn_objc_check_func "$LINENO" "SSL_has_pending" "ac_cv_func_SSL_has_pending" if test "x$ac_cv_func_SSL_has_pending" = xyes then : printf "%s\n" "#define HAVE_SSL_HAS_PENDING 1" >>confdefs.h fi LIBS="$old_LIBS" fi fi fi if test x"$with_tls" = x"gnutls" \ -o \( x"$with_tls" = x"yes" -a x"$tls_support" = x"no" \) then : pkg_failed=no { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for gnutls" >&5 printf %s "checking for gnutls... " >&6; } if test -n "$gnutls_CFLAGS"; then pkg_cv_gnutls_CFLAGS="$gnutls_CFLAGS" elif test -n "$PKG_CONFIG"; then if test -n "$PKG_CONFIG" && \ { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gnutls >= 3.5.0\""; } >&5 ($PKG_CONFIG --exists --print-errors "gnutls >= 3.5.0") 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then pkg_cv_gnutls_CFLAGS=`$PKG_CONFIG --cflags "gnutls >= 3.5.0" 2>/dev/null` test "x$?" != "x0" && pkg_failed=yes else pkg_failed=yes fi else pkg_failed=untried fi if test -n "$gnutls_LIBS"; then pkg_cv_gnutls_LIBS="$gnutls_LIBS" elif test -n "$PKG_CONFIG"; then if test -n "$PKG_CONFIG" && \ { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gnutls >= 3.5.0\""; } >&5 ($PKG_CONFIG --exists --print-errors "gnutls >= 3.5.0") 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then pkg_cv_gnutls_LIBS=`$PKG_CONFIG --libs "gnutls >= 3.5.0" 2>/dev/null` test "x$?" != "x0" && pkg_failed=yes else pkg_failed=yes fi else pkg_failed=untried fi if test $pkg_failed = yes; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then _pkg_short_errors_supported=yes else _pkg_short_errors_supported=no fi if test $_pkg_short_errors_supported = yes; then gnutls_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "gnutls >= 3.5.0" 2>&1` else gnutls_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "gnutls >= 3.5.0" 2>&1` fi # Put the nasty error message in config.log where it belongs echo "$gnutls_PKG_ERRORS" >&5 : elif test $pkg_failed = untried; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } : else gnutls_CFLAGS=$pkg_cv_gnutls_CFLAGS gnutls_LIBS=$pkg_cv_gnutls_LIBS { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } tls_support="GnuTLS" TLS_CPPFLAGS="$gnutls_CFLAGS $TLS_CPPFLAGS" TLS_LIBS="$gnutls_LIBS $TLS_LIBS" OF_GNUTLS_TLS_STREAM_M="OFGnuTLSTLSStream.m" fi fi if test x"$with_tls" = x"mbedtls" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for mbedtls_net_init in -lmbedtls" >&5 printf %s "checking for mbedtls_net_init in -lmbedtls... " >&6; } if test ${ac_cv_lib_mbedtls_mbedtls_net_init+y} then : printf %s "(cached) " >&6 else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-lmbedtls -lmbedx509 -lmbedcrypto $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ char mbedtls_net_init (); int main (void) { return mbedtls_net_init (); ; return 0; } _ACEOF if ac_fn_objc_try_link "$LINENO" then : ac_cv_lib_mbedtls_mbedtls_net_init=yes else $as_nop ac_cv_lib_mbedtls_mbedtls_net_init=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_mbedtls_mbedtls_net_init" >&5 printf "%s\n" "$ac_cv_lib_mbedtls_mbedtls_net_init" >&6; } if test "x$ac_cv_lib_mbedtls_mbedtls_net_init" = xyes then : ac_fn_objc_check_header_compile "$LINENO" "mbedtls/ssl.h" "ac_cv_header_mbedtls_ssl_h" "$ac_includes_default" if test "x$ac_cv_header_mbedtls_ssl_h" = xyes then : tls_support="Mbed TLS" TLS_LIBS="-lmbedx509 -lmbedcrypto $TLS_LIBS" TLS_LIBS="-lmbedtls $TLS_LIBS" OF_MBEDTLS_TLS_STREAM_M="OFMbedTLSTLSStream.m" fi fi fi if test x"$tls_support" != x"no" then : TLS="tls" printf "%s\n" "#define HAVE_TLS_SUPPORT 1" >>confdefs.h ac_config_files="$ac_config_files src/tls/Info.plist" OFARC_LIBS="-lobjfwtls $TLS_LIBS $OFARC_LIBS" OFHASH_LIBS="-lobjfwtls $TLS_LIBS $OFHASH_LIBS" OFHTTP_LIBS="-lobjfwtls $TLS_LIBS $OFHTTP_LIBS" if test x"$enable_shared" != x"no" then : OBJFWTLS_SHARED_LIB='${LIB_PREFIX}objfwtls${LIB_SUFFIX}' fi if test x"$enable_static" = x"yes" \ -o x"$enable_shared" = x"no" then : OBJFWTLS_STATIC_LIB="libobjfwtls.a" fi if test x"$build_framework" = x"yes" then : OBJFWTLS_FRAMEWORK="ObjFWTLS.framework" fi fi if test x"$with_tls" != x"no" -a x"$tls_support" = x"no" then : as_fn_error $? "No TLS implementation was found. Please install OpenSSL, GnuTLS, Mbed TLS or use --without-tls." "$LINENO" 5 fi if test x"$enable_threads" != x"no" then : OF_HTTP_CLIENT_TESTS_M="OFHTTPClientTests.m" fi OFDNS="ofdns" if test x"$enable_files" != x"no" then : OFHTTP="ofhttp" fi fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for __builtin_bswap16" >&5 printf %s "checking for __builtin_bswap16... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #include int main (void) { uint16_t i = errno; printf("%d", (int)__builtin_bswap16(i)); ; return 0; } _ACEOF if ac_fn_objc_try_link "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } printf "%s\n" "#define OF_HAVE_BUILTIN_BSWAP16 1" >>confdefs.h else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for __builtin_bswap32" >&5 printf %s "checking for __builtin_bswap32... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #include int main (void) { uint32_t i = errno; printf("%d", (int)__builtin_bswap32(i)); ; return 0; } _ACEOF if ac_fn_objc_try_link "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } printf "%s\n" "#define OF_HAVE_BUILTIN_BSWAP32 1" >>confdefs.h else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for __builtin_bswap64" >&5 printf %s "checking for __builtin_bswap64... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #include int main (void) { uint64_t i = errno; printf("%d", (int)__builtin_bswap64(i)); ; return 0; } _ACEOF if ac_fn_objc_try_link "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } printf "%s\n" "#define OF_HAVE_BUILTIN_BSWAP64 1" >>confdefs.h else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext case "$host_os" in darwin*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether we are compiling for macOS" >&5 printf %s "checking whether we are compiling for macOS... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #if (!defined(TARGET_OS_IPHONE) || !TARGET_OS_IPHONE) && \ (!defined(TARGET_OS_SIMULATOR) || !TARGET_OS_SIMULATOR) egrep_cpp_yes #endif _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "egrep_cpp_yes" >/dev/null 2>&1 then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } have_subprocesses="no" fi rm -rf conftest* ;; mingw*) have_subprocesses="yes" ;; msdosdjgpp*) have_subprocesses="no" ;; esac if test x"$have_subprocesses" = x"" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for sys/wait.h that is POSIX.1 compatible" >&5 printf %s "checking for sys/wait.h that is POSIX.1 compatible... " >&6; } if test ${ac_cv_header_sys_wait_h+y} then : printf %s "(cached) " >&6 else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #ifndef WEXITSTATUS # define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8) #endif #ifndef WIFEXITED # define WIFEXITED(stat_val) (((stat_val) & 255) == 0) #endif int main (void) { int s; wait (&s); s = WIFEXITED (s) ? WEXITSTATUS (s) : 1; ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : ac_cv_header_sys_wait_h=yes else $as_nop ac_cv_header_sys_wait_h=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_sys_wait_h" >&5 printf "%s\n" "$ac_cv_header_sys_wait_h" >&6; } if test $ac_cv_header_sys_wait_h = yes; then printf "%s\n" "#define HAVE_SYS_WAIT_H 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "kill" "ac_cv_func_kill" if test "x$ac_cv_func_kill" = xyes then : printf "%s\n" "#define HAVE_KILL 1" >>confdefs.h fi for ac_func in posix_spawnp do : ac_fn_objc_check_func "$LINENO" "posix_spawnp" "ac_cv_func_posix_spawnp" if test "x$ac_cv_func_posix_spawnp" = xyes then : printf "%s\n" "#define HAVE_POSIX_SPAWNP 1" >>confdefs.h if test x"$ac_cv_func_kill" = x"yes" then : for ac_header in spawn.h do : ac_fn_objc_check_header_compile "$LINENO" "spawn.h" "ac_cv_header_spawn_h" "$ac_includes_default" if test "x$ac_cv_header_spawn_h" = xyes then : printf "%s\n" "#define HAVE_SPAWN_H 1" >>confdefs.h have_subprocesses="yes" fi done fi fi done if test x"$have_subprocesses" = x"" then : for ac_func in vfork dup2 execvp _exit do : as_ac_var=`printf "%s\n" "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_objc_check_func "$LINENO" "$ac_func" "$as_ac_var" if eval test \"x\$"$as_ac_var"\" = x"yes" then : cat >>confdefs.h <<_ACEOF #define `printf "%s\n" "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF if test x"$ac_cv_func_vfork" = x"yes" \ -a x"$ac_cv_func_pipe" = x"yes" \ -a x"$ac_cv_func_dup2" = x"yes" \ -a x"$ac_cv_func_execvp" = x"yes" \ -a x"$ac_cv_func_kill" = x"yes" \ -a x"$ac_cv_func__exit" = x"yes" then : have_subprocesses="yes" fi else $as_nop break fi done fi fi if test x"$have_subprocesses" = x"yes" then : USE_SRCS_SUBPROCESSES='${SRCS_SUBPROCESSES}' SUBPROCESS="subprocess" printf "%s\n" "#define OF_HAVE_SUBPROCESSES 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "ioctl" "ac_cv_func_ioctl" if test "x$ac_cv_func_ioctl" = xyes then : printf "%s\n" "#define HAVE_IOCTL 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "isatty" "ac_cv_func_isatty" if test "x$ac_cv_func_isatty" = xyes then : printf "%s\n" "#define HAVE_ISATTY 1" >>confdefs.h fi ac_fn_objc_check_func "$LINENO" "pledge" "ac_cv_func_pledge" if test "x$ac_cv_func_pledge" = xyes then : printf "%s\n" "#define OF_HAVE_PLEDGE 1" >>confdefs.h fi if test x"$objc_runtime" = x"Apple runtime" then : ac_fn_objc_check_header_compile "$LINENO" "Foundation/NSObject.h" "ac_cv_header_Foundation_NSObject_h" "$ac_includes_default" if test "x$ac_cv_header_Foundation_NSObject_h" = xyes then : BRIDGE="bridge" ac_config_files="$ac_config_files src/bridge/Info.plist" if test x"$enable_shared" != x"no" then : OBJFWBRIDGE_SHARED_LIB='${LIB_PREFIX}objfwbridge${LIB_SUFFIX}' fi if test x"$enable_static" = x"yes" \ -o x"$enable_shared" = x"no" then : OBJFWBRIDGE_STATIC_LIB="libobjfwbridge.a" fi if test x"$build_framework" = x"yes" then : OBJFWBRIDGE_FRAMEWORK="ObjFWBridge.framework" fi fi fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether Objective C compiler supports blocks" >&5 printf %s "checking whether Objective C compiler supports blocks... " >&6; } old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -Xclang -fblocks" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { int (^foo)(int bar); foo = ^ (int bar) { return 0; } ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS -Xclang -fblocks" OF_BLOCK_TESTS_M="OFBlockTests.m" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } OBJCFLAGS="$old_OBJCFLAGS" fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext if test x"$GOBJC" = x"yes" then : OBJCFLAGS="$OBJCFLAGS -Wwrite-strings -Wpointer-arith" # Check whether --enable-werror was given. if test ${enable_werror+y} then : enableval=$enable_werror; fi if test x"$enable_werror" = x"yes" then : OBJCFLAGS="$OBJCFLAGS -Werror" fi old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -Werror" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether we need -Wno-strict-aliasing due to GCC bugs" >&5 printf %s "checking whether we need -Wno-strict-aliasing due to GCC bugs... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef __has_attribute # if __has_attribute(objc_root_class) __attribute__((__objc_root_class__)) # endif #endif @interface Foo { struct objc_class *_isa; } @end static struct { struct objc_class *_isa; } object; int main (void) { Foo *test = (Foo *)&object; (void)test; /* Get rid of unused variable warning */ ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } OBJCFLAGS="$old_OBJCFLAGS" else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } OBJCFLAGS="$old_OBJCFLAGS -Wno-strict-aliasing" fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -Werror" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether we need -Wno-unused-property-ivar due to Clang bugs" >&5 printf %s "checking whether we need -Wno-unused-property-ivar due to Clang bugs... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef __has_attribute # if __has_attribute(objc_root_class) __attribute__((__objc_root_class__)) # endif #endif @interface Foo { struct objc_class *_isa; Foo *_foo; } @property (readonly, nonatomic) Foo *foo; + (Foo *)foo; @end @implementation Foo @synthesize foo = _foo; + (Foo *)foo { return (Foo *)0; } @end _ACEOF if ac_fn_objc_try_compile "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } OBJCFLAGS="$old_OBJCFLAGS" else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } OBJCFLAGS="$old_OBJCFLAGS -Wno-unused-property-ivar" fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -Wcast-align -Werror" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether -Wcast-align is buggy" >&5 printf %s "checking whether -Wcast-align is buggy... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef __has_attribute # if __has_attribute(objc_root_class) __attribute__((__objc_root_class__)) # endif #endif @interface Foo { struct objc_class *_isa; } @end @implementation Foo - (void)foo { struct objc_class *c = _isa; (void)c; } @end _ACEOF if ac_fn_objc_try_compile "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } OBJCFLAGS="$old_OBJCFLAGS -Wcast-align" else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } OBJCFLAGS="$old_OBJCFLAGS" fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -Wunreachable-code -Werror" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether -Wunreachable-code can be used" >&5 printf %s "checking whether -Wunreachable-code can be used... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include struct objc_selector; typedef const struct objc_selector *SEL; #ifdef __has_attribute # if __has_attribute(objc_root_class) __attribute__((__objc_root_class__)) # endif #endif @interface Object - (void)doesNotRecognizeSelector: (SEL)selector #ifdef __clang__ __attribute__((__noreturn__)) #endif ; - (void)dealloc; @end @interface Foo: Object @end void test(void) { if (sizeof(int) == 4) __asm__ (""); else if (sizeof(int) == 8) __asm__ (""); else abort(); } /* * Unfortunately, this cannot be shorter, as it only * works when it is used inside a macro. */ #ifdef __clang__ # define OF_DEALLOC_UNSUPPORTED \ [self doesNotRecognizeSelector: _cmd]; \ \ abort(); \ \ _Pragma("clang diagnostic push"); \ _Pragma("clang diagnostic ignored \ \"-Wunreachable-code\""); \ [super dealloc]; \ _Pragma("clang diagnostic pop"); #else # define OF_DEALLOC_UNSUPPORTED \ [self doesNotRecognizeSelector: _cmd]; \ \ abort(); \ \ [super dealloc]; #endif @implementation Foo - (void)dealloc { OF_DEALLOC_UNSUPPORTED } @end _ACEOF if ac_fn_objc_try_compile "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } OBJCFLAGS="$old_OBJCFLAGS -Wunreachable-code" else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } OBJCFLAGS="$old_OBJCFLAGS" fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -Wdocumentation -Werror" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether -Wdocumentation works correctly" >&5 printf %s "checking whether -Wdocumentation works correctly... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /** * @class Test conftest.m conftest.m */ #ifdef __has_attribute # if __has_attribute(objc_root_class) __attribute__((__objc_root_class__)) # endif #endif @interface Test @end /** * @struct Foo conftest.m conftest.m */ typedef struct {} Foo; _ACEOF if ac_fn_objc_try_compile "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } OBJCFLAGS="$old_OBJCFLAGS -Wdocumentation" else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } OBJCFLAGS="$old_OBJCFLAGS" fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext if test x"$check_pedantic" = x"yes" then : old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -pedantic -Werror" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether -pedantic is buggy" >&5 printf %s "checking whether -pedantic is buggy... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #ifdef __has_attribute # if __has_attribute(objc_root_class) __attribute__((__objc_root_class__)) # endif #endif @interface Foo { void *foo; } @end @interface Bar: Foo - (void)assert; @end @implementation Bar - (void)assert { /* * Some versions of glibc break with * -pedantic when using assert. */ assert(1); } @end _ACEOF if ac_fn_objc_try_compile "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } OBJCFLAGS="$old_OBJCFLAGS -pedantic" else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } OBJCFLAGS="$old_OBJCFLAGS" fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -Werror" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether we need -Wno-strict-prototypes" >&5 printf %s "checking whether we need -Wno-strict-prototypes... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main (void) { signal(SIGINT, SIG_DFL); ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } OBJCFLAGS="$old_OBJCFLAGS" else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } OBJCFLAGS="$old_OBJCFLAGS -Wno-strict-prototypes" fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext if test x"$ac_cv_header_complex_h" = x"yes" then : old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -Werror" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether we need -Wno-gnu-imaginary-constant" >&5 printf %s "checking whether we need -Wno-gnu-imaginary-constant... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main (void) { complex float f = 0.5 + 0.5 * I; (void)f; ; return 0; } _ACEOF if ac_fn_objc_try_compile "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } OBJCFLAGS="$old_OBJCFLAGS" else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } OBJCFLAGS="$old_OBJCFLAGS -Wno-gnu-imaginary-constant" fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi if test x"$cross_compiling" = x"yes" then : BIN_PREFIX="${host_alias}-" case "$host" in i?86-*-mingw*) # Extract the first word of "wine", so it can be a program name with args. set dummy wine; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_WINE+y} then : printf %s "(cached) " >&6 else $as_nop if test -n "$WINE"; then ac_cv_prog_WINE="$WINE" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_WINE="wine" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi WINE=$ac_cv_prog_WINE if test -n "$WINE"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $WINE" >&5 printf "%s\n" "$WINE" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi ;; x86_64-*-mingw*) # Extract the first word of "wine64", so it can be a program name with args. set dummy wine64; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_WINE+y} then : printf %s "(cached) " >&6 else $as_nop if test -n "$WINE"; then ac_cv_prog_WINE="$WINE" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_WINE="wine64" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi WINE=$ac_cv_prog_WINE if test -n "$WINE"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $WINE" >&5 printf "%s\n" "$WINE" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi ;; esac if test x"$WINE" != x"" then : WRAPPER="$WINE" fi if test x"$with_wii" = x"yes" then : # Extract the first word of "wiiload", so it can be a program name with args. set dummy wiiload; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_wiiload+y} then : printf %s "(cached) " >&6 else $as_nop if test -n "$wiiload"; then ac_cv_prog_wiiload="$wiiload" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_wiiload="wiiload" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi wiiload=$ac_cv_prog_wiiload if test -n "$wiiload"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $wiiload" >&5 printf "%s\n" "$wiiload" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi if test x"$wiiload" != x"" then : WRAPPER="$wiiload" fi fi fi AS=$OBJC DEP_ASFLAGS='${DEP_OBJCFLAGS}' ac_config_files="$ac_config_files buildsys.mk extra.mk src/Info.plist tests/Info.plist utils/objfw-config" ac_config_headers="$ac_config_headers config.h src/objfw-defs.h" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure # scripts and configure runs, see configure's option --config-cache. # It is not useful on other systems. If it contains results you don't # want to keep, you may remove or edit it. # # config.status only pays attention to the cache file if you give it # the --recheck option to rerun configure. # # `ac_cv_env_foo' variables (set or unset) will be overridden when # loading this file, other *unset* `ac_cv_foo' will be assigned the # following values. _ACEOF # The following way of writing the cache mishandles newlines in values, # but we know of no workaround that is simple, portable, and efficient. # So, we kill variables containing newlines. # Ultrix sh set writes to stderr and can't be redirected directly, # and sets the high bit in the cache file unless we assign to the vars. ( for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space=' '; set) 2>&1` in #( *${as_nl}ac_space=\ *) # `set' does not quote correctly, so add quotes: double-quote # substitution turns \\\\ into \\, and sed turns \\ into \. sed -n \ "s/'/'\\\\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" ;; #( *) # `set' quotes correctly as required by POSIX, so do not add quotes. sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) | sed ' /^ac_cv_env_/b end t clear :clear s/^\([^=]*\)=\(.*[{}].*\)$/test ${\1+y} || &/ t end s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ :end' >>confcache if diff "$cache_file" confcache >/dev/null 2>&1; then :; else if test -w "$cache_file"; then if test "x$cache_file" != "x/dev/null"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 printf "%s\n" "$as_me: updating cache $cache_file" >&6;} if test ! -f "$cache_file" || test -h "$cache_file"; then cat confcache >"$cache_file" else case $cache_file in #( */* | ?:*) mv -f confcache "$cache_file"$$ && mv -f "$cache_file"$$ "$cache_file" ;; #( *) mv -f confcache "$cache_file" ;; esac fi fi else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 printf "%s\n" "$as_me: not updating unwritable cache $cache_file" >&6;} fi fi rm -f confcache test "x$prefix" = xNONE && prefix=$ac_default_prefix # Let make expand exec_prefix. test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' DEFS=-DHAVE_CONFIG_H ac_libobjs= ac_ltlibobjs= U= for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue # 1. Remove the extension, and $U if already installed. ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' ac_i=`printf "%s\n" "$ac_i" | sed "$ac_script"` # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR # will be set to the directory where LIBOBJS objects are built. as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext" as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo' done LIBOBJS=$ac_libobjs LTLIBOBJS=$ac_ltlibobjs if test x"$GCC" = x"yes" then : DEP_CFLAGS='-MD -MF $${out%.o}.dep' fi if test x"$GXX" = x"yes" then : DEP_CXXFLAGS='-MD -MF $${out%.o}.dep' fi if test x"$GOBJC" = x"yes" then : DEP_OBJCFLAGS='-MD -MF $${out%.o}.dep' fi if test x"$GOBJCXX" = x"yes" then : DEP_OBJCXXFLAGS='-MD -MF $${out%.o}.dep' fi case "$build_os" in morphos*) ;; *) # Extract the first word of "tput", so it can be a program name with args. set dummy tput; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_path_TPUT+y} then : printf %s "(cached) " >&6 else $as_nop case $TPUT in [\\/]* | ?:[\\/]*) ac_cv_path_TPUT="$TPUT" # Let the user override the test with a path. ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_path_TPUT="$as_dir$ac_word$ac_exec_ext" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS ;; esac fi TPUT=$ac_cv_path_TPUT if test -n "$TPUT"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $TPUT" >&5 printf "%s\n" "$TPUT" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi ;; esac if test x"$TPUT" != x"" then : if x=$($TPUT el 2>/dev/null); then TERM_EL="$x" else TERM_EL="$($TPUT ce 2>/dev/null)" fi if x=$($TPUT sgr0 2>/dev/null); then TERM_SGR0="$x" else TERM_SGR0="$($TPUT me 2>/dev/null)" fi if x=$($TPUT bold 2>/dev/null); then TERM_BOLD="$x" else TERM_BOLD="$($TPUT md 2>/dev/null)" fi if x=$($TPUT setaf 1 2>/dev/null); then TERM_SETAF1="$x" TERM_SETAF2="$($TPUT setaf 2 2>/dev/null)" TERM_SETAF3="$($TPUT setaf 3 2>/dev/null)" TERM_SETAF4="$($TPUT setaf 4 2>/dev/null)" TERM_SETAF6="$($TPUT setaf 6 2>/dev/null)" elif x=$($TPUT setaf 1 0 0 2>/dev/null); then TERM_SETAF1="$x" TERM_SETAF2="$($TPUT setaf 2 0 0 2>/dev/null)" TERM_SETAF3="$($TPUT setaf 3 0 0 2>/dev/null)" TERM_SETAF4="$($TPUT setaf 4 0 0 2>/dev/null)" TERM_SETAF6="$($TPUT setaf 6 0 0 2>/dev/null)" else TERM_SETAF1="$($TPUT AF 1 2>/dev/null)" TERM_SETAF2="$($TPUT AF 2 2>/dev/null)" TERM_SETAF3="$($TPUT AF 3 2>/dev/null)" TERM_SETAF4="$($TPUT AF 4 2>/dev/null)" TERM_SETAF6="$($TPUT AF 6 2>/dev/null)" fi fi if test x"$enable_silent_rules" != x"no" then : SILENT='.SILENT:' MAKEFLAGS_SILENT='-s' fi : "${CONFIG_STATUS=./config.status}" ac_write_fail=0 ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files $CONFIG_STATUS" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 printf "%s\n" "$as_me: creating $CONFIG_STATUS" >&6;} as_write_fail=0 cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 #! $SHELL # Generated by $as_me. # Run this file to recreate the current configuration. # Compiler output produced by configure, useful for debugging # configure, is in config.log if it exists. debug=false ac_cs_recheck=false ac_cs_silent=false SHELL=\${CONFIG_SHELL-$SHELL} export SHELL _ASEOF cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh as_nop=: if test ${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1 then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else $as_nop case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi # Reset variables that may have inherited troublesome values from # the environment. # IFS needs to be set, to space, tab, and newline, in precisely that order. # (If _AS_PATH_WALK were called with IFS unset, it would have the # side effect of setting IFS to empty, thus disabling word splitting.) # Quoting is to prevent editors from complaining about space-tab. as_nl=' ' export as_nl IFS=" "" $as_nl" PS1='$ ' PS2='> ' PS4='+ ' # Ensure predictable behavior from utilities with locale-dependent output. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # We cannot yet rely on "unset" to work, but we need these variables # to be unset--not just set to an empty or harmless value--now, to # avoid bugs in old shells (e.g. pre-3.0 UWIN ksh). This construct # also avoids known problems related to "unset" and subshell syntax # in other old shells (e.g. bash 2.01 and pdksh 5.2.14). for as_var in BASH_ENV ENV MAIL MAILPATH CDPATH do eval test \${$as_var+y} \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done # Ensure that fds 0, 1, and 2 are open. if (exec 3>&0) 2>/dev/null; then :; else exec 0&1) 2>/dev/null; then :; else exec 1>/dev/null; fi if (exec 3>&2) ; then :; else exec 2>/dev/null; fi # The user is always right. if ${PATH_SEPARATOR+false} :; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac test -r "$as_dir$0" && as_myself=$as_dir$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as `sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then printf "%s\n" "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi printf "%s\n" "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null then : eval 'as_fn_append () { eval $1+=\$2 }' else $as_nop as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null then : eval 'as_fn_arith () { as_val=$(( $* )) }' else $as_nop as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || printf "%s\n" X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits # Determine whether it's possible to make 'echo' print without a newline. # These variables are no longer used directly by Autoconf, but are AC_SUBSTed # for compatibility with existing Makefiles. ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac # For backward compatibility with old third-party macros, we provide # the shell variables $as_echo and $as_echo_n. New code should use # AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively. as_echo='printf %s\n' as_echo_n='printf %s' rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. # In both cases, we have to default to `cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -pR' fi else as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`printf "%s\n" "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || printf "%s\n" X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi # as_fn_executable_p FILE # ----------------------- # Test if FILE is an executable regular file. as_fn_executable_p () { test -f "$1" && test -x "$1" } # as_fn_executable_p as_test_x='test -x' as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" # Sed expression to map a string onto a valid variable name. as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" exec 6>&1 ## ----------------------------------- ## ## Main body of $CONFIG_STATUS script. ## ## ----------------------------------- ## _ASEOF test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Save the log message, to keep $0 and so on meaningful, and to # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" This file was extended by ObjFW $as_me 1.1.6, which was generated by GNU Autoconf 2.71. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS CONFIG_LINKS = $CONFIG_LINKS CONFIG_COMMANDS = $CONFIG_COMMANDS $ $0 $@ on `(hostname || uname -n) 2>/dev/null | sed 1q` " _ACEOF case $ac_config_files in *" "*) set x $ac_config_files; shift; ac_config_files=$*;; esac case $ac_config_headers in *" "*) set x $ac_config_headers; shift; ac_config_headers=$*;; esac cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 # Files that config.status was made for. config_files="$ac_config_files" config_headers="$ac_config_headers" _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 ac_cs_usage="\ \`$as_me' instantiates files and other configuration actions from templates according to the current configuration. Unless the files and actions are specified as TAGs, all are instantiated by default. Usage: $0 [OPTION]... [TAG]... -h, --help print this help, then exit -V, --version print version number and configuration settings, then exit --config print configuration, then exit -q, --quiet, --silent do not print progress messages -d, --debug don't remove temporary files --recheck update $as_me by reconfiguring in the same conditions --file=FILE[:TEMPLATE] instantiate the configuration file FILE --header=FILE[:TEMPLATE] instantiate the configuration header FILE Configuration files: $config_files Configuration headers: $config_headers Report bugs to . ObjFW home page: ." _ACEOF ac_cs_config=`printf "%s\n" "$ac_configure_args" | sed "$ac_safe_unquote"` ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\''/g"` cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config='$ac_cs_config_escaped' ac_cs_version="\\ ObjFW config.status 1.1.6 configured by $0, generated by GNU Autoconf 2.71, with options \\"\$ac_cs_config\\" Copyright (C) 2021 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." ac_pwd='$ac_pwd' srcdir='$srcdir' INSTALL='$INSTALL' test -n "\$AWK" || AWK=awk _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # The default lists apply if the user does not specify any file. ac_need_defaults=: while test $# != 0 do case $1 in --*=?*) ac_option=`expr "X$1" : 'X\([^=]*\)='` ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` ac_shift=: ;; --*=) ac_option=`expr "X$1" : 'X\([^=]*\)='` ac_optarg= ac_shift=: ;; *) ac_option=$1 ac_optarg=$2 ac_shift=shift ;; esac case $ac_option in # Handling of the options. -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) ac_cs_recheck=: ;; --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) printf "%s\n" "$ac_cs_version"; exit ;; --config | --confi | --conf | --con | --co | --c ) printf "%s\n" "$ac_cs_config"; exit ;; --debug | --debu | --deb | --de | --d | -d ) debug=: ;; --file | --fil | --fi | --f ) $ac_shift case $ac_optarg in *\'*) ac_optarg=`printf "%s\n" "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; '') as_fn_error $? "missing file argument" ;; esac as_fn_append CONFIG_FILES " '$ac_optarg'" ac_need_defaults=false;; --header | --heade | --head | --hea ) $ac_shift case $ac_optarg in *\'*) ac_optarg=`printf "%s\n" "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; esac as_fn_append CONFIG_HEADERS " '$ac_optarg'" ac_need_defaults=false;; --he | --h) # Conflict between --help and --header as_fn_error $? "ambiguous option: \`$1' Try \`$0 --help' for more information.";; --help | --hel | -h ) printf "%s\n" "$ac_cs_usage"; exit ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil | --si | --s) ac_cs_silent=: ;; # This is an error. -*) as_fn_error $? "unrecognized option: \`$1' Try \`$0 --help' for more information." ;; *) as_fn_append ac_config_targets " $1" ac_need_defaults=false ;; esac shift done ac_configure_extra_args= if $ac_cs_silent; then exec 6>/dev/null ac_configure_extra_args="$ac_configure_extra_args --silent" fi _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 if \$ac_cs_recheck; then set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion shift \printf "%s\n" "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' export CONFIG_SHELL exec "\$@" fi _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 exec 5>>config.log { echo sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX ## Running $as_me. ## _ASBOX printf "%s\n" "$ac_log" } >&5 _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Handling of arguments. for ac_config_target in $ac_config_targets do case $ac_config_target in "tests/plugin/Info.plist") CONFIG_FILES="$CONFIG_FILES tests/plugin/Info.plist" ;; "src/runtime/Info.plist") CONFIG_FILES="$CONFIG_FILES src/runtime/Info.plist" ;; "src/tls/Info.plist") CONFIG_FILES="$CONFIG_FILES src/tls/Info.plist" ;; "src/bridge/Info.plist") CONFIG_FILES="$CONFIG_FILES src/bridge/Info.plist" ;; "buildsys.mk") CONFIG_FILES="$CONFIG_FILES buildsys.mk" ;; "extra.mk") CONFIG_FILES="$CONFIG_FILES extra.mk" ;; "src/Info.plist") CONFIG_FILES="$CONFIG_FILES src/Info.plist" ;; "tests/Info.plist") CONFIG_FILES="$CONFIG_FILES tests/Info.plist" ;; "utils/objfw-config") CONFIG_FILES="$CONFIG_FILES utils/objfw-config" ;; "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; "src/objfw-defs.h") CONFIG_HEADERS="$CONFIG_HEADERS src/objfw-defs.h" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; esac done # If the user did not use the arguments to specify the items to instantiate, # then the envvar interface is used. Set only those that are not. # We use the long form for the default assignment because of an extremely # bizarre bug on SunOS 4.1.3. if $ac_need_defaults; then test ${CONFIG_FILES+y} || CONFIG_FILES=$config_files test ${CONFIG_HEADERS+y} || CONFIG_HEADERS=$config_headers fi # Have a temporary directory for convenience. Make it in the build tree # simply because there is no reason against having it here, and in addition, # creating and moving files from /tmp can sometimes cause problems. # Hook for its removal unless debugging. # Note that there is a small window in which the directory will not be cleaned: # after its creation but before its name has been assigned to `$tmp'. $debug || { tmp= ac_tmp= trap 'exit_status=$? : "${ac_tmp:=$tmp}" { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status ' 0 trap 'as_fn_exit 1' 1 2 13 15 } # Create a (secure) tmp directory for tmp files. { tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && test -d "$tmp" } || { tmp=./conf$$-$RANDOM (umask 077 && mkdir "$tmp") } || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5 ac_tmp=$tmp # Set up the scripts for CONFIG_FILES section. # No need to generate them if there are no CONFIG_FILES. # This happens for instance with `./config.status config.h'. if test -n "$CONFIG_FILES"; then ac_cr=`echo X | tr X '\015'` # On cygwin, bash can eat \r inside `` if the user requested igncr. # But we know of no other shell where ac_cr would be empty at this # point, so we can use a bashism as a fallback. if test "x$ac_cr" = x; then eval ac_cr=\$\'\\r\' fi ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null` if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then ac_cs_awk_cr='\\r' else ac_cs_awk_cr=$ac_cr fi echo 'BEGIN {' >"$ac_tmp/subs1.awk" && _ACEOF { echo "cat >conf$$subs.awk <<_ACEOF" && echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' && echo "_ACEOF" } >conf$$subs.sh || as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'` ac_delim='%!_!# ' for ac_last_try in false false false false false :; do . ./conf$$subs.sh || as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X` if test $ac_delim_n = $ac_delim_num; then break elif $ac_last_try; then as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 else ac_delim="$ac_delim!$ac_delim _$ac_delim!! " fi done rm -f conf$$subs.sh cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK && _ACEOF sed -n ' h s/^/S["/; s/!.*/"]=/ p g s/^[^!]*!// :repl t repl s/'"$ac_delim"'$// t delim :nl h s/\(.\{148\}\)..*/\1/ t more1 s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/ p n b repl :more1 s/["\\]/\\&/g; s/^/"/; s/$/"\\/ p g s/.\{148\}// t nl :delim h s/\(.\{148\}\)..*/\1/ t more2 s/["\\]/\\&/g; s/^/"/; s/$/"/ p b :more2 s/["\\]/\\&/g; s/^/"/; s/$/"\\/ p g s/.\{148\}// t delim ' >$CONFIG_STATUS || ac_write_fail=1 rm -f conf$$subs.awk cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 _ACAWK cat >>"\$ac_tmp/subs1.awk" <<_ACAWK && for (key in S) S_is_set[key] = 1 FS = "" } { line = $ 0 nfields = split(line, field, "@") substed = 0 len = length(field[1]) for (i = 2; i < nfields; i++) { key = field[i] keylen = length(key) if (S_is_set[key]) { value = S[key] line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3) len += length(value) + length(field[++i]) substed = 1 } else len += 1 + keylen } print line } _ACAWK _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g" else cat fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \ || as_fn_error $? "could not setup config files machinery" "$LINENO" 5 _ACEOF # VPATH may cause trouble with some makes, so we remove sole $(srcdir), # ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and # trailing colons and then remove the whole line if VPATH becomes empty # (actually we leave an empty line to preserve line numbers). if test "x$srcdir" = x.; then ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{ h s/// s/^/:/ s/[ ]*$/:/ s/:\$(srcdir):/:/g s/:\${srcdir}:/:/g s/:@srcdir@:/:/g s/^:*// s/:*$// x s/\(=[ ]*\).*/\1/ G s/\n// s/^[^=]*=[ ]*$// }' fi cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 fi # test -n "$CONFIG_FILES" # Set up the scripts for CONFIG_HEADERS section. # No need to generate them if there are no CONFIG_HEADERS. # This happens for instance with `./config.status Makefile'. if test -n "$CONFIG_HEADERS"; then cat >"$ac_tmp/defines.awk" <<\_ACAWK || BEGIN { _ACEOF # Transform confdefs.h into an awk script `defines.awk', embedded as # here-document in config.status, that substitutes the proper values into # config.h.in to produce config.h. # Create a delimiter string that does not exist in confdefs.h, to ease # handling of long lines. ac_delim='%!_!# ' for ac_last_try in false false :; do ac_tt=`sed -n "/$ac_delim/p" confdefs.h` if test -z "$ac_tt"; then break elif $ac_last_try; then as_fn_error $? "could not make $CONFIG_HEADERS" "$LINENO" 5 else ac_delim="$ac_delim!$ac_delim _$ac_delim!! " fi done # For the awk script, D is an array of macro values keyed by name, # likewise P contains macro parameters if any. Preserve backslash # newline sequences. ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]* sed -n ' s/.\{148\}/&'"$ac_delim"'/g t rset :rset s/^[ ]*#[ ]*define[ ][ ]*/ / t def d :def s/\\$// t bsnl s/["\\]/\\&/g s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ D["\1"]=" \3"/p s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2"/p d :bsnl s/["\\]/\\&/g s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ D["\1"]=" \3\\\\\\n"\\/p t cont s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p t cont d :cont n s/.\{148\}/&'"$ac_delim"'/g t clear :clear s/\\$// t bsnlc s/["\\]/\\&/g; s/^/"/; s/$/"/p d :bsnlc s/["\\]/\\&/g; s/^/"/; s/$/\\\\\\n"\\/p b cont ' >$CONFIG_STATUS || ac_write_fail=1 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 for (key in D) D_is_set[key] = 1 FS = "" } /^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ { line = \$ 0 split(line, arg, " ") if (arg[1] == "#") { defundef = arg[2] mac1 = arg[3] } else { defundef = substr(arg[1], 2) mac1 = arg[2] } split(mac1, mac2, "(") #) macro = mac2[1] prefix = substr(line, 1, index(line, defundef) - 1) if (D_is_set[macro]) { # Preserve the white space surrounding the "#". print prefix "define", macro P[macro] D[macro] next } else { # Replace #undef with comments. This is necessary, for example, # in the case of _POSIX_SOURCE, which is predefined and required # on some systems where configure will not decide to define it. if (defundef == "undef") { print "/*", prefix defundef, macro, "*/" next } } } { print } _ACAWK _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 as_fn_error $? "could not setup config headers machinery" "$LINENO" 5 fi # test -n "$CONFIG_HEADERS" eval set X " :F $CONFIG_FILES :H $CONFIG_HEADERS " shift for ac_tag do case $ac_tag in :[FHLC]) ac_mode=$ac_tag; continue;; esac case $ac_mode$ac_tag in :[FHL]*:*);; :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;; :[FH]-) ac_tag=-:-;; :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; esac ac_save_IFS=$IFS IFS=: set x $ac_tag IFS=$ac_save_IFS shift ac_file=$1 shift case $ac_mode in :L) ac_source=$1;; :[FH]) ac_file_inputs= for ac_f do case $ac_f in -) ac_f="$ac_tmp/stdin";; *) # Look for the file first in the build tree, then in the source tree # (if the path is not absolute). The absolute path cannot be DOS-style, # because $ac_f cannot contain `:'. test -f "$ac_f" || case $ac_f in [\\/$]*) false;; *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; esac || as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;; esac case $ac_f in *\'*) ac_f=`printf "%s\n" "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac as_fn_append ac_file_inputs " '$ac_f'" done # Let's still pretend it is `configure' which instantiates (i.e., don't # use $as_me), people would be surprised to read: # /* config.h. Generated by config.status. */ configure_input='Generated from '` printf "%s\n" "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' `' by configure.' if test x"$ac_file" != x-; then configure_input="$ac_file. $configure_input" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 printf "%s\n" "$as_me: creating $ac_file" >&6;} fi # Neutralize special characters interpreted by sed in replacement strings. case $configure_input in #( *\&* | *\|* | *\\* ) ac_sed_conf_input=`printf "%s\n" "$configure_input" | sed 's/[\\\\&|]/\\\\&/g'`;; #( *) ac_sed_conf_input=$configure_input;; esac case $ac_tag in *:-:* | *:-) cat >"$ac_tmp/stdin" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; esac ;; esac ac_dir=`$as_dirname -- "$ac_file" || $as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$ac_file" : 'X\(//\)[^/]' \| \ X"$ac_file" : 'X\(//\)$' \| \ X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || printf "%s\n" X"$ac_file" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` as_dir="$ac_dir"; as_fn_mkdir_p ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`printf "%s\n" "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`printf "%s\n" "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; esac ;; esac ac_abs_top_builddir=$ac_pwd ac_abs_builddir=$ac_pwd$ac_dir_suffix # for backward compatibility: ac_top_builddir=$ac_top_build_prefix case $srcdir in .) # We are building in place. ac_srcdir=. ac_top_srcdir=$ac_top_builddir_sub ac_abs_top_srcdir=$ac_pwd ;; [\\/]* | ?:[\\/]* ) # Absolute name. ac_srcdir=$srcdir$ac_dir_suffix; ac_top_srcdir=$srcdir ac_abs_top_srcdir=$srcdir ;; *) # Relative name. ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix ac_top_srcdir=$ac_top_build_prefix$srcdir ac_abs_top_srcdir=$ac_pwd/$srcdir ;; esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix case $ac_mode in :F) # # CONFIG_FILE # case $INSTALL in [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;; esac _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # If the template does not know about datarootdir, expand it. # FIXME: This hack should be removed a few years after 2.60. ac_datarootdir_hack=; ac_datarootdir_seen= ac_sed_dataroot=' /datarootdir/ { p q } /@datadir@/p /@docdir@/p /@infodir@/p /@localedir@/p /@mandir@/p' case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in *datarootdir*) ac_datarootdir_seen=yes;; *@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 printf "%s\n" "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_datarootdir_hack=' s&@datadir@&$datadir&g s&@docdir@&$docdir&g s&@infodir@&$infodir&g s&@localedir@&$localedir&g s&@mandir@&$mandir&g s&\\\${datarootdir}&$datarootdir&g' ;; esac _ACEOF # Neutralize VPATH when `$srcdir' = `.'. # Shell code in configure.ac might set extrasub. # FIXME: do we really want to maintain this feature? cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_sed_extra="$ac_vpsub $extrasub _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 :t /@[a-zA-Z_][a-zA-Z_0-9]*@/!b s|@configure_input@|$ac_sed_conf_input|;t t s&@top_builddir@&$ac_top_builddir_sub&;t t s&@top_build_prefix@&$ac_top_build_prefix&;t t s&@srcdir@&$ac_srcdir&;t t s&@abs_srcdir@&$ac_abs_srcdir&;t t s&@top_srcdir@&$ac_top_srcdir&;t t s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t s&@builddir@&$ac_builddir&;t t s&@abs_builddir@&$ac_abs_builddir&;t t s&@abs_top_builddir@&$ac_abs_top_builddir&;t t s&@INSTALL@&$ac_INSTALL&;t t $ac_datarootdir_hack " eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \ >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5 test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } && { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \ "$ac_tmp/out"`; test -z "$ac_out"; } && { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&5 printf "%s\n" "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&2;} rm -f "$ac_tmp/stdin" case $ac_file in -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";; *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";; esac \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; :H) # # CONFIG_HEADER # if test x"$ac_file" != x-; then { printf "%s\n" "/* $configure_input */" >&1 \ && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" } >"$ac_tmp/config.h" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 if diff "$ac_file" "$ac_tmp/config.h" >/dev/null 2>&1; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5 printf "%s\n" "$as_me: $ac_file is unchanged" >&6;} else rm -f "$ac_file" mv "$ac_tmp/config.h" "$ac_file" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 fi else printf "%s\n" "/* $configure_input */" >&1 \ && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \ || as_fn_error $? "could not create -" "$LINENO" 5 fi ;; esac done # for ac_tag as_fn_exit 0 _ACEOF ac_clean_files=$ac_clean_files_save test $ac_write_fail = 0 || as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5 # configure is writing to config.log, and then calls config.status. # config.status does its own redirection, appending to config.log. # Unfortunately, on DOS this fails, as config.log is still kept open # by configure, so config.status won't be able to write to it; its # output is simply discarded. So we exec the FD to /dev/null, # effectively closing config.log, so it can be properly (re)opened and # appended to by config.status. When coming back to configure, we # need to make the FD available again. if test "$no_create" != yes; then ac_cs_success=: ac_config_status_args= test "$silent" = yes && ac_config_status_args="$ac_config_status_args --quiet" exec 5>/dev/null $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false exec 5>>config.log # Use ||, not &&, to avoid exiting from the if with $? = 1, which # would make configure fail if this is the last instruction. $ac_cs_success || as_fn_exit 1 fi if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 printf "%s\n" "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} fi if test x"$old_compiler" = x"yes" then : echo printf " ** Note: Your compiler does not seem to " echo "accept -fobjc-runtime=objfw." printf " ** To get optimal performance, you should install " echo "Clang >= 3.2" printf " ** (or the latest Clang release to be able to use all " echo "features)." echo fi if test x"$enable_threads" != x"no" -a x"$atomic_ops" = x"none" \ -a x"$have_spinlocks" != x"yes" -a x"$have_amiga_threads" != x"yes" then : echo printf " ** Warning: You have enabled threads, but neither atomic " echo "operations nor" printf " ** spinlocks are available. Expect *very* poor performance, " echo "as a mutex will" printf " ** be locked for every retain and release! If you don't " echo "need threads, try" echo " ** --disable-threads to work around this problem." echo fi objfw-1.1.6/configure.ac000066400000000000000000001672531465614216400151430ustar00rootroot00000000000000AC_INIT(ObjFW, 1.1.6, js@nil.im, objfw, https://objfw.nil.im/) AC_CONFIG_SRCDIR(src) AC_CONFIG_AUX_DIR(build-aux) AC_CONFIG_MACRO_DIR(build-aux/m4) AC_DEFINE(OBJFW_VERSION_MAJOR, 1, [The major version of ObjFW]) AC_DEFINE(OBJFW_VERSION_MINOR, 1, [The minor version of ObjFW]) AC_SUBST(BUNDLE_VERSION, 1.1.6) AC_SUBST(BUNDLE_SHORT_VERSION, 1.1) for i in configure.ac build-aux/m4/*; do AS_IF([test $i -nt configure], [ AC_MSG_ERROR([$i is newer than configure! Run ./autogen.sh!]) ]) done BUILDSYS_INIT AC_CANONICAL_HOST dnl Used to disable checking for -pedantic on some platforms where it's broken check_pedantic="yes" case "$host" in arm-*-riscos*) AS_IF([test x"$OBJCFLAGS" = x""], [OBJCFLAGS="-O2 -g"]) flags="-mfloat-abi=softfp -mfpu=vfp -mlibscl" ASFLAGS="$ASFLAGS -mfloat-abi=softfp -mfpu=vfp" OBJCFLAGS="$OBJCFLAGS $flags" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flags" LDFLAGS="$LDFLAGS $flags" enable_shared="no" enable_threads="no" enable_sockets="no" enable_files="no" ;; m68k-*-amigaos*) AS_IF([test x"$OBJCFLAGS" = x""], [OBJCFLAGS="-O0 -g"]) OBJCFLAGS="$OBJCFLAGS -noixemul" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS -noixemul" CPPFLAGS="$CPPFLAGS -D__NO_NET_API" LDFLAGS="$LDFLAGS -noixemul" LIBS="$LIBS -ldebug" enable_files="yes" # Required for reading ENV: enable_shared="no" with_tls="no" AC_SUBST(LIBBASES_M, libbases.m) ;; powerpc-*-amigaos*) CPPFLAGS="$CPPFLAGS -D__USE_INLINE__" enable_files="yes" # Required for reading ENV: enable_shared="no" with_tls="no" AC_SUBST(LIBBASES_M, libbases.m) ;; *-morphos*) AS_IF([test x"$OBJCFLAGS" = x""], [OBJCFLAGS="-O2 -g"]) OBJCFLAGS="$OBJCFLAGS -noixemul" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS -noixemul" LDFLAGS="$LDFLAGS -noixemul" LIBS="$LIBS -ldebug" enable_files="yes" # Required for reading ENV: enable_shared="no" AC_SUBST(LIBBASES_M, libbases.m) ;; *-msdosdjgpp*) enable_shared="no" enable_threads="no" enable_sockets="no" ;; *-*-mingw*) LDFLAGS="$LDFLAGS -Wl,--allow-multiple-definition" LIBS="$LIBS -lversion" AC_SUBST(USE_SRCS_WINDOWS, '${SRCS_WINDOWS}') ;; *-psp-*) AS_IF([test x"$DEVKITPSP" = x""], [ AC_MSG_ERROR([DEVKITPSP is not set! Please set DEVKITPSP.]) ]) AS_IF([test x"$OBJCFLAGS" = x""], [OBJCFLAGS="-O2"]) OBJCFLAGS="$OBJCFLAGS -G0" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS -G0" CPPFLAGS="$CPPFLAGS -I$DEVKITPSP/psp/sdk/include" LDFLAGS="$LDFLAGS -G0" LIBS="$LIBS -L$DEVKITPSP/psp/sdk/lib -lpspdebug -lpspdisplay" LIBS="$LIBS -lpspge -lpspctrl -lpspsdk -lc -lpspnet" LIBS="$LIBS -lpspnet_inet -lpspnet_apctl -lpspnet_resolver" LIBS="$LIBS -lpsputility -lpspuser -lpspkernel -lgcc -lpsplibc" enable_shared="no" enable_threads="no" # TODO enable_sockets="no" # TODO check_pedantic="no" AC_SUBST(MAP_LDFLAGS, ['-Wl,-Map,$@.map']) ;; hppa*-*-hpux*) dnl Don't default to -g: It creates errors from the assembler and breaks dnl exceptions. AS_IF([test x"$OBJCFLAGS" = x""], [OBJCFLAGS="-O2"]) dnl HP-UX 11.11's inttypes.h defines UINTPTR_MAX etc. to nothing. GCC's dnl stdint.h defines those correctly, but if inttypes.h gets included dnl after something included stdint.h, it gets broken again. Therefore, dnl always include inttypes.h as the very first thing. dnl We need to put this into OBJCFLAGS and not CPPFLAGS as CPPFLAGS are dnl also used for .S files. OBJCFLAGS="$OBJCFLAGS -include inttypes.h" dnl We need -latomic for GCC's atomics to work. LIBS="$LIBS -latomic" ;; *-*-mint*) enable_shared="no" enable_threads="no" # TODO with_tls="no" ;; *-apple-macos*) enable_shared="no" enable_threads="no" # TODO enable_sockets="no" # TODO AC_DEFINE(OF_CLASSIC_MACOS, 1, [Whether we are compiling for classic macOS]) ;; esac AS_IF([test x"$host_os" = x"msdosdjgpp" -a x"$build_os" = x"msdosdjgpp"], [ dnl Hack to make configure find these on DOS. : ${AR:=ar.exe} : ${GREP:=grep.exe} : ${RANLIB:=ranlib.exe} ]) AC_LANG([Objective C]) case "$host_os" in morphos*) dnl Don't use clang on MorphOS - it does not support baserel, which is dnl required for the .library. potential_compilers="gcc" ;; *) potential_compilers="clang egcc gcc" ;; esac AC_PROG_OBJC($potential_compilers) AC_PROG_OBJCPP AC_PROG_EGREP AC_PROG_SED AC_PROG_LN_S BUILDSYS_CHECK_IOS AC_ARG_WITH(wii, AS_HELP_STRING([--with-wii], [build for Wii])) AS_IF([test x"$with_wii" = x"yes"], [ AS_IF([test x"$DEVKITPRO" = x""], [ AC_MSG_ERROR([DEVKITPRO is not set! Please set DEVKITPRO.]) ]) flags="-mrvl -mcpu=750 -meabi -mhard-float" OBJCFLAGS="$OBJCFLAGS $flags" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flags" CPPFLAGS="$CPPFLAGS -DGEKKO -I$DEVKITPRO/libogc/include" OBJFW_CPPFLAGS="$OBJFW_CPPFLAGS -DGEKKO -I\$DEVKITPRO/libogc/include" LDFLAGS="$LDFLAGS -mrvl -mcpu=750 -meabi -mhard-float" LIBS="$LIBS -L$DEVKITPRO/libogc/lib/wii -lfat -logc" TESTS_LIBS="$TESTS_LIBS -lwiiuse -lbte" enable_shared="no" enable_threads="no" # TODO with_tls="no" AC_DEFINE(OF_WII, 1, [Whether we are compiling for Wii]) AC_SUBST(MAP_LDFLAGS, ['-Wl,-Map,$@.map']) ]) AC_ARG_WITH(wii-u, AS_HELP_STRING([--with-wii-u], [build for Wii U])) AS_IF([test x"$with_wii_u" = x"yes"], [ AS_IF([test x"$DEVKITPRO" = x""], [ AC_MSG_ERROR([DEVKITPRO is not set! Please set DEVKITPRO.]) ]) flags="-mcpu=750 -meabi -mhard-float" OBJCFLAGS="$OBJCFLAGS $flags" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flags" CPPFLAGS="-isystem $DEVKITPRO/wut/include -D__WIIU__ -D__WUT__" OBJFW_CPPFLAGS="$OBJFW_CPPFLAGS -isystem \$DEVKITPRO/wut/include" OBJFW_CPPFLAGS="$OBJFW_CPPFLAGS -D__WIIU__ -D__WUT__" LDFLAGS="-specs=$DEVKITPRO/wut/share/wut.specs" LIBS="-L$DEVKITPRO/wut/lib -L$DEVKITPRO/wut/lib/stubs -lwut" enable_files="no" # TODO enable_shared="no" # TODO enable_threads="no" # TODO enable_sockets="no" # TODO AC_DEFINE(OF_WII_U, 1, [Whether we are compiling for Wii U]) AC_SUBST(MAP_LDFLAGS, ['-Wl,-Map,$@.map']) # Repetition of libraries is required for Wii U, as otherwise it cannot # find main. Just moving -lobjfwtest later doesn't work either, as then # the linker cannot find ObjFW symbols. So the only solution is to list # everything twice, but hide it behind a variable because listing it # twice causes a warning on macOS. AC_SUBST(WII_U_TESTS_LIBS, '-lobjfwtest ${TESTS_LIBS} ${LIBS}') ]) AC_ARG_WITH(nds, AS_HELP_STRING([--with-nds], [build for Nintendo DS])) AS_IF([test x"$with_nds" = x"yes"], [ AS_IF([test x"$DEVKITPRO" = x""], [ AC_MSG_ERROR([DEVKITPRO is not set! Please set DEVKITPRO.]) ]) flags="-march=armv5te -mtune=arm946e-s -mthumb -mthumb-interwork" OBJCFLAGS="$OBJCFLAGS $flags" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flags" CPPFLAGS="$CPPFLAGS -DARM9 -I$DEVKITPRO/libnds/include" OBJFW_CPPFLAGS="$OBJFW_CPPFLAGS -DARM9 -I\$DEVKITPRO/libnds/include" ASFLAGS="$ASFLAGS -march=armv5te" LDFLAGS="$LDFLAGS -specs=ds_arm9.specs" LIBS="$LIBS -L$DEVKITPRO/libnds/lib -lfilesystem -lfat -lnds9" enable_shared="no" enable_threads="no" # TODO enable_sockets="no" # TODO check_pedantic="no" AC_DEFINE(OF_NINTENDO_DS, 1, [Whether we are compiling for Nintendo DS]) AC_SUBST(MAP_LDFLAGS, ['-Wl,-Map,$@.map']) ]) AC_ARG_WITH(3ds, AS_HELP_STRING([--with-3ds], [build for Nintendo 3DS])) AS_IF([test x"$with_3ds" = x"yes"], [ AS_IF([test x"$DEVKITPRO" = x""], [ AC_MSG_ERROR([DEVKITPRO is not set! Please set DEVKITPRO.]) ]) flags="-march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft" flags="$flags -mword-relocations" OBJCFLAGS="$OBJCFLAGS $flags" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flags" CPPFLAGS="$CPPFLAGS -DARM11 -I$DEVKITPRO/libctru/include" OBJFW_CPPFLAGS="$OBJFW_CPPFLAGS -DARM11 -I\$DEVKITPRO/libctru/include" ASFLAGS="$ASFLAGS -march=armv6k" LDFLAGS="$LDFLAGS -specs=3dsx.specs -march=armv6k -mtune=mpcore" LDFLAGS="$LDFLAGS -mfloat-abi=hard -mtp=soft -mword-relocations" LIBS="$LIBS -L$DEVKITPRO/libctru/lib -lctru" enable_shared="no" enable_threads="no" # TODO with_tls="no" check_pedantic="no" AC_DEFINE(OF_NINTENDO_3DS, 1, [Whether we are compiling for Nintendo 3DS]) AC_SUBST(MAP_LDFLAGS, ['-Wl,-Map,$@.map']) ]) AC_ARG_WITH(nintendo-switch, AS_HELP_STRING([--with-nintendo-switch], [build for Nintendo Switch])) AS_IF([test x"$with_nintendo_switch" = x"yes"], [ AS_IF([test x"$DEVKITPRO" = x""], [ AC_MSG_ERROR([DEVKITPRO is not set! Please set DEVKITPRO.]) ]) flags="-march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE" OBJCFLAGS="$OBJCFLAGS $flags" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flags" CPPFLAGS="$CPPFLAGS -D__SWITCH__ -I$DEVKITPRO/libnx/include" OBJFW_CPPFLAGS="$OBJFW_CPPFLAGS -D__SWITCH__ -I$DEVKITPRO/libnx/include" ASFLAGS="$ASFLAGS $flags" LDFLAGS="$LDFLAGS -specs=$DEVKITPRO/libnx/switch.specs $flags" LIBS="$LIBS -L$DEVKITPRO/libnx/lib -lnx" enable_shared="no" enable_threads="yes" enable_sockets="no" # TODO check_pedantic="no" AC_DEFINE(OF_NINTENDO_SWITCH, 1, [Whether we are compiling for Nintendo Switch]) ]) CPP="$OBJCPP" CPPFLAGS="$CPPFLAGS $OBJCPPFLAGS -DOF_COMPILING_OBJFW" flags="-fexceptions -fobjc-exceptions -funwind-tables" flags="$flags -fconstant-string-class=OFConstantString" OBJCFLAGS="$OBJCFLAGS -Wall $flags" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flags" dnl amiga-gcc requires -fexceptions in LDFLAGS in order to link in the glue code dnl for registering the frames. LDFLAGS="$LDFLAGS -fexceptions" case "$OBJC" in *clang*) case "$host" in mips*-*-*) dnl Clang generates MIPS assembly not accepted by GNU as, dnl however, Clang's integrated assembler doesn't accept dnl everything used in ObjFW's assembly files. Therefore, use dnl the integrated assembler for ObjC files, but not for dnl assembly files. ASFLAGS="$ASFLAGS -no-integrated-as" OBJCFLAGS="$OBJCFLAGS -integrated-as" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS -integrated-as" ;; i?86-*-darwin* | x86_64-*-darwin*) dnl Don't use -no-integrated-as on Darwin. It breaks building dnl for the iOS simulator. ;; sparc64-*-*openbsd*) dnl Clang generates assembly output on SPARC64 that OpenBSD's dnl assembler does not accept. flag="-integrated-as" OBJCFLAGS="$OBJCFLAGS $flag" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flag" ;; esac ;; esac AX_CHECK_COMPILER_FLAGS(-std=gnu11, [ OBJCFLAGS="$OBJCFLAGS -std=gnu11" ], [ AX_CHECK_COMPILER_FLAGS(-std=gnu1x, [ OBJCFLAGS="$OBJCFLAGS -std=gnu1x" ], [ AX_CHECK_COMPILER_FLAGS(-std=gnu99, [OBJCFLAGS="$OBJCFLAGS -std=gnu99"]) ]) ]) AX_CHECK_COMPILER_FLAGS(-pipe, [OBJCFLAGS="$OBJCFLAGS -pipe"]) AX_CHECK_COMPILER_FLAGS(-fno-common, [OBJCFLAGS="$OBJCFLAGS -fno-common"]) AX_CHECK_COMPILER_FLAGS(-Xclang -fno-constant-cfstrings, [ flag="-Xclang -fno-constant-cfstrings" OBJCFLAGS="$OBJCFLAGS $flag" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flag" ]) AX_CHECK_COMPILER_FLAGS([-Wsign-compare -Werror], [OBJCFLAGS="$OBJCFLAGS -Wsign-compare"]) AS_IF([test x"$with_nds" != x"yes"], [ AX_CHECK_COMPILER_FLAGS([-Wshadow -Werror], [OBJCFLAGS="$OBJCFLAGS -Wshadow"]) ]) AX_CHECK_COMPILER_FLAGS([-Wshorten-64-to-32 -Werror], [OBJCFLAGS="$OBJCFLAGS -Wshorten-64-to-32"]) AX_CHECK_COMPILER_FLAGS([-Wundeclared-selector -Werror], [OBJCFLAGS="$OBJCFLAGS -Wundeclared-selector"]) AX_CHECK_COMPILER_FLAGS([-Wsemicolon-before-method-body -Werror], [OBJCFLAGS="$OBJCFLAGS -Wsemicolon-before-method-body"]) AX_CHECK_COMPILER_FLAGS([-Wobjc-missing-property-synthesis -Werror], [OBJCFLAGS="$OBJCFLAGS -Wobjc-missing-property-synthesis"]) AX_CHECK_COMPILER_FLAGS([-Wmissing-method-return-type -Werror], [OBJCFLAGS="$OBJCFLAGS -Wmissing-method-return-type"]) case "$host" in m68k-*-amigaos*) dnl The inline headers generate code that triggers -Wpointer-sign. OBJCFLAGS="$OBJCFLAGS -Wno-pointer-sign" ;; esac AC_MSG_CHECKING(whether Objective C compiler supports properties) AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([ #ifdef __has_attribute # if __has_attribute(objc_root_class) __attribute__((__objc_root_class__)) # endif #endif @interface Foo { id bar; } @property (nonatomic, retain) id bar; @end ], [[ Foo *foo = (id)0; [foo setBar: (id)0]; foo = [foo bar]; ]]) ], [ AC_MSG_RESULT(yes) ], [ AC_MSG_RESULT(no) AC_MSG_ERROR(Compiler does not support properties!) ]) AC_CHECK_TOOL(AR, ar) AC_PROG_RANLIB case "$host_os" in mingw*) AC_CHECK_TOOL(RC, windres) ;; esac AC_ARG_ENABLE(shared, AS_HELP_STRING([--disable-shared], [do not build shared library])) AS_IF([test x"$enable_shared" != x"no"], [ BUILDSYS_SHARED_LIB BUILDSYS_PLUGIN AC_SUBST(OBJFW_SHARED_LIB, '${LIB_PREFIX}objfw${LIB_SUFFIX}') AC_SUBST(EXCEPTIONS_LIB_A, "exceptions.lib.a") AC_SUBST(FORWARDING_LIB_A, "forwarding.lib.a") AC_SUBST(LOOKUP_ASM_LIB_A, "lookup-asm.lib.a") BUILDSYS_FRAMEWORK([ AC_SUBST(OBJFW_FRAMEWORK, "ObjFW.framework") build_framework="yes" ]) ], [ AC_DEFINE(OF_NO_SHARED, 1, [Whether no shared library was built]) AC_SUBST(LIBOBJFW_DEP, "../src/libobjfw.a") AC_SUBST(LIBOBJFW_DEP_LVL2, "../../src/libobjfw.a") ]) AS_IF([test x"$build_framework" = x"yes"], [ TESTS_LIBS="-framework ObjFW \${RUNTIME_FRAMEWORK_LIBS} $TESTS_LIBS" TESTS_LIBS="-F../src -F../src/runtime $TESTS_LIBS" ], [ TESTS_LIBS="\${RUNTIME_LIBS} $TESTS_LIBS" TESTS_LIBS="-L../src/runtime $TESTS_LIBS" TESTS_LIBS="-L../src -lobjfw $TESTS_LIBS" ]) AC_ARG_ENABLE(static, AS_HELP_STRING([--enable-static], [build static library])) AS_IF([test x"$enable_shared" = x"no"], [ enable_static="yes" ]) AS_IF([test x"$enable_static" = x"yes"], [ AC_SUBST(OBJFW_STATIC_LIB, "libobjfw.a") AC_SUBST(EXCEPTIONS_A, "exceptions.a") AC_SUBST(FORWARDING_A, "forwarding.a") AC_SUBST(LOOKUP_ASM_A, "lookup-asm.a") ]) AC_DEFINE_UNQUOTED(PLUGIN_SUFFIX, "$PLUGIN_SUFFIX", [Suffix for plugins]) AS_IF([test x"$enable_files" != x"no" -a x"$PLUGIN_SUFFIX" != x""], [ AC_SUBST(USE_SRCS_PLUGINS, '${SRCS_PLUGINS}') AC_SUBST(TESTPLUGIN, "plugin") AC_DEFINE(OF_HAVE_PLUGINS, 1, [Whether we have plugin support]) AC_CONFIG_FILES(tests/plugin/Info.plist) AS_IF([test x"$build_framework" = x"yes"], [ TESTPLUGIN_LIBS="-F../../src -F../../src/runtime" TESTPLUGIN_LIBS="$TESTPLUGIN_LIBS -framework ObjFW" TESTPLUGIN_LIBS="$TESTPLUGIN_LIBS \${RUNTIME_FRAMEWORK_LIBS}" ], [ TESTPLUGIN_LIBS="-L../../src -L../../src/runtime" TESTPLUGIN_LIBS="$TESTPLUGIN_LIBS -lobjfw \${RUNTIME_LIBS}" ]) AC_SUBST(TESTPLUGIN_LIBS) ]) AC_MSG_CHECKING(whether we need -D_GNU_SOURCE) AC_EGREP_CPP(egrep_cpp_yes, [ #include #if defined(__GLIBC__) || defined(__MINGW32__) || \ defined(__NEWLIB__) || defined(__MORPHOS__) || defined(__MINT__) egrep_cpp_yes #endif ], [ AC_MSG_RESULT(yes) CPPFLAGS="-D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 $CPPFLAGS" CPPFLAGS="-D_GNU_SOURCE $CPPFLAGS" gnu_source="yes" ], [ AC_MSG_RESULT(no) ]) case "$host_os" in solaris*) CPPFLAGS="-D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS $CPPFLAGS" ;; esac objc_runtime="ObjFW runtime" AC_CHECK_HEADER(objc/objc.h) AC_MSG_CHECKING(which Objective C runtime to use) AC_ARG_ENABLE(runtime, AS_HELP_STRING([--enable-runtime], [use the included runtime])) AC_ARG_ENABLE(seluid24, AS_HELP_STRING([--enable-seluid24], [use 24 bit instead of 16 bit for selector UIDs])) AS_IF([test x"$enable_runtime" != x"yes"], [ AS_IF([test x"$ac_cv_header_objc_objc_h" = x"yes"], [ AC_EGREP_CPP(egrep_cpp_yes, [ #import #ifdef OBJC_BOOL_DEFINED egrep_cpp_yes #endif ], [ objc_runtime="Apple runtime" ], [ dnl We don't want the GNU runtime : ]) ]) ]) AC_MSG_RESULT($objc_runtime) case "$objc_runtime" in "ObjFW runtime") AC_DEFINE(OF_OBJFW_RUNTIME, 1, [Whether we use the ObjFW runtime]) AC_SUBST(USE_SRCS_TAGGED_POINTERS, '${SRCS_TAGGED_POINTERS}') AC_MSG_CHECKING([whether -fobjc-runtime=objfw is supported]) old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -Xclang -fobjc-runtime=objfw" AC_LINK_IFELSE([ AC_LANG_PROGRAM([ #ifdef __has_attribute # if __has_attribute(objc_root_class) __attribute__((__objc_root_class__)) # endif #endif @interface Test + (void)test; @end @implementation Test + (void)test { } @end void * objc_msg_lookup(void *obj, void *sel) { return (void *)0; } void __objc_exec_class(void *module) { } ], [[ [Test test]; ]]) ], [ OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS -Xclang -fobjc-runtime=objfw" AC_MSG_RESULT(yes) ], [ OBJCFLAGS="$old_OBJCFLAGS -fgnu-runtime" OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS -fgnu-runtime" AC_MSG_RESULT(no) old_compiler="yes" ]) AC_SUBST(RUNTIME, "runtime") AC_CONFIG_FILES(src/runtime/Info.plist) AS_IF([test x"$enable_shared" != x"no"], [ AC_SUBST(OBJFWRT_SHARED_LIB, '${LIB_PREFIX}objfwrt${LIB_SUFFIX}') ]) AS_IF([test x"$enable_static" = x"yes"], [ AC_SUBST(OBJFWRT_STATIC_LIB, "libobjfwrt.a") ]) AS_IF([test x"$build_framework" = x"yes"], [ AC_SUBST(OBJFWRT_FRAMEWORK, "ObjFWRT.framework") AC_SUBST(RUNTIME_FRAMEWORK_LIBS, "-framework ObjFWRT") ]) AC_SUBST(RUNTIME_LIBS, "-lobjfwrt") AS_IF([test x"$enable_shared" = x"no"], [ AC_SUBST(LIBOBJFWRT_DEP, "../src/runtime/libobjfwrt.a") AC_SUBST(LIBOBJFWRT_DEP_LVL2, "../../src/runtime/libobjfwrt.a") ]) AS_IF([test x"$enable_seluid24" = x"yes"], [ AC_DEFINE(OF_SELUID24, 1, [Whether to use 24 bit selector UIDs]) ]) AC_MSG_CHECKING(for exception type) AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([ extern void foo(); ], [ @try { foo(); } @finally { foo(); } ]) ], [ AS_IF([$SED 's/[[^[:print:]]]//g' /dev/null], [ exception_type="DWARF" ]) AS_IF([$SED 's/[[^[:print:]]]//g' /dev/null], [ exception_type="SjLj" ]) AS_IF([$SED 's/[[^[:print:]]]//g' /dev/null], [ exception_type="SEH" ]) case "$exception_type" in DWARF) AC_DEFINE(HAVE_DWARF_EXCEPTIONS, 1, [Whether DWARF exceptions are used]) raise_exception="_Unwind_RaiseException" ;; SjLj) AC_DEFINE(HAVE_SJLJ_EXCEPTIONS, 1, [Whether SjLj exceptions are used]) raise_exception="_Unwind_SjLj_RaiseException" ;; SEH) AC_DEFINE(HAVE_SEH_EXCEPTIONS, 1, [Whether SEH exceptions are used]) raise_exception="_Unwind_RaiseException" ;; *) AC_MSG_RESULT(unknown) AC_MSG_ERROR([Exception type not detected!]) ;; esac AC_MSG_RESULT($exception_type) ], [ AC_MSG_RESULT(exceptions unavailable!) AC_MSG_ERROR([Exceptions not accepted by compiler!]) ]) AC_SEARCH_LIBS($raise_exception, [c++abi gcc_s gcc unwind], [ dnl c++abi requires pthread on OpenBSD AS_IF([test x"$ac_lib" = x"c++abi"], [LIBS="$LIBS -lpthread"]) ], [ AC_MSG_ERROR([$raise_exception missing!]) ], [-lpthread]) AC_CHECK_FUNCS(_Unwind_GetDataRelBase _Unwind_GetTextRelBase) ;; "Apple runtime") AC_DEFINE(OF_APPLE_RUNTIME, 1, [Whether we use the Apple ObjC runtime]) AC_CHECK_LIB(objc, objc_msgSend, [ AC_SUBST(RUNTIME_LIBS, "-lobjc") AC_SUBST(RUNTIME_FRAMEWORK_LIBS, "-lobjc") ], [ AC_MSG_ERROR([libobjc not found!]) ]) old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -lobjc" AC_CHECK_FUNC(objc_autoreleasePoolPush, [], [ AC_SUBST(RUNTIME_AUTORELEASE_M, "runtime/autorelease.m") ]) AC_CHECK_FUNC(objc_constructInstance, [], [ AC_SUBST(RUNTIME_INSTANCE_M, "runtime/instance.m") ]) AC_CHECK_FUNCS(objc_setAssociatedObject, [], [ AC_SUBST(RUNTIME_ASSOCIATION_M, "runtime/association.m") ]) OBJCFLAGS="$old_OBJCFLAGS" ;; esac case "$host_os" in mint*) dnl _Unwind_Backtrace crashes on MiNT ;; hpux*) dnl _Unwind_Backtrace() returns complete garbage on HP-UX. ;; *) AC_CHECK_FUNCS(_Unwind_Backtrace) ;; esac case "$host_os" in darwin*) AC_SUBST(LDFLAGS_REEXPORT, ["-Wl,-reexport-lobjfw"]) AS_IF([test x"$objc_runtime" = x"Apple runtime"], [ AC_SUBST(REEXPORT_RUNTIME, ["-Wl,-reexport-lobjc"]) AC_SUBST(REEXPORT_RUNTIME_FRAMEWORK, ["-Wl,-reexport-lobjc"]) LDFLAGS="$LDFLAGS -Wl,-U,_NSFoundationVersionNumber" ]) AS_IF([test x"$objc_runtime" = x"ObjFW runtime"], [ AS_IF([test x"$exception_type" = x"DWARF"], [ LDFLAGS="$LDFLAGS -Wl,-U,___gxx_personality_v0" ]) AS_IF([test x"$exception_type" = x"SjLj"], [ LDFLAGS="$LDFLAGS -Wl,-U,___gxx_personality_sj0" ]) AC_SUBST(REEXPORT_RUNTIME, ["-Wl,-reexport-lobjfwrt"]) AC_SUBST(REEXPORT_RUNTIME_FRAMEWORK, ["-Wl,-reexport_framework,ObjFWRT"]) ]) AC_CHECK_HEADERS(sysdir.h) AC_CHECK_FUNCS(sysdir_start_search_path_enumeration) AS_IF([test x"$host_is_ios" = x"yes"], [ AC_SUBST(TESTS_STATIC_LIB, tests.a) TESTS_LIBS="$TESTS_LIBS -framework CoreFoundation" ]) ;; esac AC_MSG_CHECKING(whether Objective C compiler supports ARC) old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -fobjc-arc -fobjc-arc-exceptions" AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([ #ifdef __has_attribute # if __has_attribute(objc_root_class) __attribute__((__objc_root_class__)) # endif #endif @interface Foo { struct objc_class *_isa; } + (id)alloc; @end @implementation Foo + (id)alloc { return (id)0; } @end ], [[ __weak id foo = [Foo alloc]; (void)foo; ]]) ], [ AC_MSG_RESULT(yes) AC_SUBST(RUNTIME_ARC_TESTS_M, RuntimeARCTests.m) ], [ AC_MSG_RESULT(no) ]) OBJCFLAGS="$old_OBJCFLAGS" AC_C_BIGENDIAN([ AC_DEFINE(OF_BIG_ENDIAN, 1, [Whether we are big endian]) ]) AS_IF([test x"$ac_cv_c_bigendian" = x"universal"], [ AC_DEFINE(OF_UNIVERSAL, 1, [Whether we are building a universal binary]) ]) AC_MSG_CHECKING(for SSIZE_MAX) AC_EGREP_CPP(egrep_cpp_yes, [ #include #include #ifdef SSIZE_MAX egrep_cpp_yes #endif ], [ AC_MSG_RESULT(yes) ], [ AC_MSG_RESULT(no) AC_DEFINE(SSIZE_MAX, [(SIZE_MAX / 2)], [Maximum value for ssize_t]) ]) AC_MSG_CHECKING(for UINTPTR_MAX) AC_EGREP_CPP(egrep_cpp_yes, [ #include #include #ifdef UINTPTR_MAX egrep_cpp_yes #endif ], [ AC_MSG_RESULT(yes) ], [ AC_MSG_RESULT(no) AC_CHECK_SIZEOF(uintptr_t) AC_DEFINE(UINTPTR_MAX, [(SIZEOF_UINTPTR_T * CHAR_BIT)], [Maximum value for uintptr_t]) ]) AC_CHECK_HEADER(inttypes.h, [AC_DEFINE(OF_HAVE_INTTYPES_H, 1, [Whether we have inttypes.h])]) AC_CHECK_HEADER(sys/types.h, [AC_DEFINE(OF_HAVE_SYS_TYPES_H, 1, [Whether we have sys/types.h])]) AC_CHECK_HEADER(stdnoreturn.h, [AC_DEFINE(OF_HAVE_STDNORETURN_H, 1, [Whether we have stdnoreturn.h])]) AC_CHECK_TYPE(wchar_t) AC_CHECK_HEADER(wchar.h) AC_CHECK_SIZEOF(float) AC_CHECK_SIZEOF(double) AS_IF([test x"$ac_cv_sizeof_float" != x"4" -o x"$ac_cv_sizeof_double" != x"8"], [AC_MSG_ERROR( [Floating point implementation does not conform to IEEE 754!])]) AC_MSG_CHECKING(for floating point endianess) fp_endianess="unknown" AS_IF([test x"$ac_cv_c_bigendian" != x"universal"], [ AC_COMPILE_IFELSE([ AC_LANG_SOURCE([ double endianess = 2.993700760838795055656993580068609688772747263874402942272934826871811872228512759832626847251963763755836687759498519784550143745834860002945223766052808125982053455555265216112722718870586961456110693379343178124592311441022662940307099598578775368547768968914916965731708568179631324904813506101190853720749196062963892799499230635163056742330563321122389331703618066046034494287335316842529021563862331183541255013987734473643350285400060357711238514186776429325214739886098119655678483017894951556639821088508565036657794343031121375178126860889964700274558728491825977274341798997758923017217660272136611938897932105874133412726223468780517578125e-259; ]) ], [ AS_IF([$SED 's/[[^[:print:]]]//g' /dev/null], [ AC_DEFINE(OF_FLOAT_BIG_ENDIAN, 1, [Whether floats are big endian]) fp_endianess="big endian" ], [ AS_IF([$SED 's/[[^[:print:]]]//g' \ /dev/null], [ fp_endianess="little endian" ]) ]) ]) ], [ fp_endianess="universal" ]) AC_MSG_RESULT($fp_endianess) AS_IF([test x"$fp_endianess" = x"unknown"], [ AC_MSG_ERROR( [Floating point implementation does not conform to IEEE 754!])]) case "$host_cpu" in arm* | earm*) AC_MSG_CHECKING(for blx) AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([], [ #if !defined(__arm64__) && !defined(__arch64__) && \ !defined(__ARM64_ARCH_8__) __asm__ __volatile__ ( "blx r12" ); #endif ]) ], [ AC_DEFINE(HAVE_BLX, 1, [Whether we have blx]) AC_MSG_RESULT(yes) ], [ AC_MSG_RESULT(no) ]) AC_MSG_CHECKING(for VFP2 or above) AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([], [ #if !defined(__arm64__) && !defined(__aarch64__) && \ !defined(__ARM64_ARCH_8__) __asm__ __volatile__ ( "vstmdb sp!, {d0-d7}" ); #endif ]) ], [ AC_DEFINE(HAVE_VFP2, 1, [Whether we have VFP2 or above]) AC_MSG_RESULT(yes) ], [ AC_MSG_RESULT(no) ]) ;; aarch64* | arm64*) AC_MSG_CHECKING(for bti) AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([], [ __asm__ __volatile__ ("bti c"); ]) ], [ AC_DEFINE(HAVE_BTI, 1, [Whether we have bti]) AC_MSG_RESULT(yes) ], [ AC_MSG_RESULT(no) ]) ;; i?86 | x86_64) AC_CHECK_HEADERS(cet.h) ;; esac AC_CHECK_LIB(m, fmod, LIBS="$LIBS -lm") AC_CHECK_LIB(complex, creal, TESTS_LIBS="$TESTS_LIBS -lcomplex") AC_CHECK_FUNCS(strtof truncf) AC_CHECK_FUNC(asprintf, [ case "$host" in *-*-mint*) dnl asprintf is not in headers have_asprintf="no" ;; *-*-mingw*) dnl asprintf from MinGW is broken on older Windows versions have_asprintf="no" ;; *-psp-*) dnl asprintf is broken on the PSP have_asprintf="no" ;; *) have_asprintf="yes" AC_DEFINE(HAVE_ASPRINTF, 1, [Whether we have asprintf()]) ;; esac ], [ have_asprintf="no" ]) AC_ARG_ENABLE(unicode-tables, AS_HELP_STRING([--disable-unicode-tables], [Disable Unicode tables])) AS_IF([test x"$enable_unicode_tables" != x"no"], [ AC_DEFINE(OF_HAVE_UNICODE_TABLES, 1, [Whether to build with Unicode tables]) AC_SUBST(UNICODE_M, "unicode.m") ]) ENCODINGS_SRCS="" AC_DEFUN([ENCODING_FLAG], [ AC_ARG_ENABLE($1, AS_HELP_STRING([--disable-$1], [Disables support for $3])) AS_IF([test x"$enable_$2" != x"no"], [ AC_DEFINE($4, 1, [Whether we have support for $3]) ENCODINGS_SRCS="$ENCODINGS_SRCS $1.m" ]) ]) ENCODING_FLAG(codepage-437, codepage_437, [Codepage 437], HAVE_CODEPAGE_437) ENCODING_FLAG(codepage-850, codepage_850, [Codepage 850], HAVE_CODEPAGE_850) ENCODING_FLAG(codepage-858, codepage_858, [Codepage 858], HAVE_CODEPAGE_858) ENCODING_FLAG(iso-8859-2, iso_8859_2, [ISO 8859-2], HAVE_ISO_8859_2) ENCODING_FLAG(iso-8859-3, iso_8859_3, [ISO 8859-3], HAVE_ISO_8859_3) ENCODING_FLAG(iso-8859-15, iso_8859_15, [ISO 8859-15], HAVE_ISO_8859_15) ENCODING_FLAG(koi8-r, koi8_r, [KOI8-R], HAVE_KOI8_R) ENCODING_FLAG(koi8-u, koi8_u, [KOI8-U], HAVE_KOI8_U) ENCODING_FLAG(mac-roman, mac_roman, [Mac Roman encoding], HAVE_MAC_ROMAN) ENCODING_FLAG(windows-1251, windows_1251, [Windows-1251], HAVE_WINDOWS_1251) ENCODING_FLAG(windows-1252, windows_1252, [Windows-1252], HAVE_WINDOWS_1252) AS_IF([test x"$ENCODINGS_SRCS" = x""], [ ENCODINGS_SRCS="dummy.m" ]) AC_SUBST(ENCODINGS_SRCS) AS_IF([test x"$enable_shared" != x"no"], [ AC_SUBST(ENCODINGS_LIB_A, "encodings.lib.a") ]) AS_IF([test x"$enable_static" = x"yes" -o x"$enable_shared" = x"no"], [ AC_SUBST(ENCODINGS_A, "encodings.a") ]) AC_CHECK_FUNCS(arc4random arc4random_buf getrandom random, break) AS_IF([test x"$host_os" != x"morphos"], [ AC_CHECK_LIB(dl, dlopen, LIBS="$LIBS -ldl") ]) AC_CHECK_HEADERS_ONCE(dlfcn.h) case "$host_os" in netbsd*) dnl dladdr exists on NetBSD, but it is completely broken. dnl When using it with code that uses __thread, it freezes the process dnl so that it has to be killed using SIGKILL. dnl When disabling __thread, it doesn't freeze, but all symbols are dnl wrong. ;; *) AC_CHECK_FUNCS(dladdr) ;; esac AC_CHECK_HEADERS(sys/mman.h) AC_CHECK_FUNCS(mmap mlock) AC_ARG_ENABLE(threads, AS_HELP_STRING([--disable-threads], [disable thread support])) AS_IF([test x"$enable_threads" != x"no"], [ AC_MSG_CHECKING(for threads) case "$host_os" in amigaos* | morphos*) AC_MSG_RESULT(Amiga) have_amiga_threads="yes" ;; mingw*) AC_MSG_RESULT(WinAPI) ;; *) AC_MSG_RESULT(POSIX) dnl Use -Wp, as we only use it for the preprocessor. AX_CHECK_COMPILER_FLAGS([-Wp,-pthread], [ CPPFLAGS="$CPPFLAGS -Wp,-pthread" ], [ CPPFLAGS="$CPPFLAGS -D_REENTRANT -D_THREAD_SAFE" ]) AC_CHECK_LIB(pthread, main, LIBS="$LIBS -lpthread") AC_LINK_IFELSE([ AC_LANG_PROGRAM([ #include ], [ pthread_create(NULL, NULL, NULL, NULL); ]) ], [], [ AC_MSG_ERROR(No supported threads found!) ]) AC_DEFINE(OF_HAVE_PTHREADS, 1, [Whether we have pthreads]) AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([ #include ], [ pthread_mutexattr_t attr; pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); ]) ], [ AC_DEFINE(OF_HAVE_RECURSIVE_PTHREAD_MUTEXES, 1, [If pthread mutexes can be recursive]) ]) AC_CHECK_FUNC(pthread_spin_lock, [ have_spinlocks="yes" AC_DEFINE(OF_HAVE_PTHREAD_SPINLOCKS, 1, [Whether we have pthread spinlocks]) ]) AC_CHECK_FUNC(sched_yield, [ AC_DEFINE(OF_HAVE_SCHED_YIELD, 1, [Whether we have sched_yield()]) ]) AC_CHECK_FUNCS(pthread_attr_getschedpolicy) old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -Werror" AC_MSG_CHECKING(for pthread_attr_setinheritsched) AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([ #include ], [ pthread_attr_setinheritsched( (pthread_attr_t *)-1, 0); ]) ], [ AC_MSG_RESULT(yes) AC_DEFINE(HAVE_PTHREAD_ATTR_SETINHERITSCHED, 1, [Whether we have pthread_attr_setinheritsched]) ], [ AC_MSG_RESULT(no) ]) OBJCFLAGS="$old_OBJCFLAGS" AC_CHECK_HEADERS(pthread_np.h, [], [], [#include ]) AC_CHECK_FUNCS(pthread_set_name_np pthread_setname_np, break) ;; esac AC_DEFINE(OF_HAVE_THREADS, 1, [Whether we have threads]) AC_SUBST(USE_SRCS_THREADS, '${SRCS_THREADS}') AC_SUBST(OBJC_SYNC, objc_sync) AC_ARG_ENABLE(compiler-tls, AS_HELP_STRING([--disable-compiler-tls], [disable compiler thread local storage])) case "$host" in aarch64*-*-android*) dnl Compiler TLS is broken on AArch64 Android with Clang enable_compiler_tls="no" ;; m68k-*-amigaos* | powerpc-*-amigaos*) dnl Compiler TLS is broken on AmigaOS enable_compiler_tls="no" ;; *-*-mingw*) dnl Causes emutls to be pulled in, which pulls in winpthread. enable_compiler_tls="no" ;; *-*-morphos*) dnl Compiler TLS needs helpers that we don't want in the dnl .library enable_compiler_tls="no" ;; esac AS_IF([test x"$enable_compiler_tls" != x"no"], [ AC_CHECK_HEADER(threads.h, [ AC_DEFINE(OF_HAVE_THREADS_H, 1, [Whether we have threads.h]) ]) AC_MSG_CHECKING(whether _Thread_local works) AC_LINK_IFELSE([ AC_LANG_PROGRAM([ static _Thread_local int x = 0; ], [ x++; ]) ], [ AS_IF([test x"$enable_shared" != x"no"], [ old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -fPIC" AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([ static _Thread_local int x = 0; ], [ x++; ]) ], [ AC_MSG_RESULT(yes) AC_DEFINE(OF_HAVE__THREAD_LOCAL, 1, [Whether _Thread_local works]) have_thread_local="yes" ], [ AC_MSG_RESULT(no) ]) OBJCFLAGS="$old_OBJCFLAGS" ], [ AC_MSG_RESULT(yes) AC_DEFINE(OF_HAVE__THREAD_LOCAL, 1, [Whether _Thread_local works]) have_thread_local="yes" ]) ], [ AC_MSG_RESULT(no) ]) AS_IF([test x"$have_thread_local" != x"yes"], [ AC_MSG_CHECKING(whether __thread works) AC_LINK_IFELSE([ AC_LANG_PROGRAM([ /* * It seems __thread is buggy with * GCC 4.1 */ #if __GNUC__ == 4 && __GNUC_MINOR__ < 2 # error buggy #endif __thread int x = 0; ], [ x++; ]) ], [ AS_IF([test x"$enable_shared" != x"no"], [ old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -fPIC" AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([ __thread int x = 0; ], [ x++; ]) ], [ AC_MSG_RESULT(yes) AC_DEFINE(OF_HAVE___THREAD, 1, [Whether __thread works] ) ], [ AC_MSG_RESULT(no) ]) OBJCFLAGS="$old_OBJCFLAGS" ], [ AC_MSG_RESULT(yes) AC_DEFINE(OF_HAVE___THREAD, 1, [Whether __thread works]) ]) ], [ AC_MSG_RESULT(no) ]) ]) ]) atomic_ops="none" AC_MSG_CHECKING(whether we have an atomic ops assembly implementation) AC_EGREP_CPP(egrep_cpp_yes, [ #if defined(__GNUC__) && (defined(__i386__) || \ defined(__x86_64__) || defined(__amd64__)) || \ ((defined(__ppc__) || defined(__PPC__) || \ defined(__powerpc__)) && !defined(__APPLE_CC__)) egrep_cpp_yes #endif ], [ AC_MSG_RESULT(yes) atomic_ops="assembly implementation" ], [ AC_MSG_RESULT(no) ]) AC_MSG_CHECKING(whether __atomic_* works) AC_LINK_IFELSE([ AC_LANG_PROGRAM([ #include #include ], [ int32_t i, j; if (__atomic_add_fetch(&i, 1, __ATOMIC_RELAXED)) j = __atomic_sub_fetch(&i, 1, __ATOMIC_RELAXED); while (!__atomic_compare_exchange_n(&i, &j, 1, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED)); __atomic_thread_fence(__ATOMIC_SEQ_CST); ]) ], [ AC_MSG_RESULT(yes) test x"$atomic_ops" = x"none" && \ atomic_ops="__atomic_* builtins" AC_DEFINE(OF_HAVE_ATOMIC_BUILTINS, 1, [Whether __atomic_* builtins are available]) ], [ AC_MSG_RESULT(no) ]) AC_MSG_CHECKING(whether __sync_* works) AC_LINK_IFELSE([ AC_LANG_PROGRAM([ #include ], [ int32_t i, j; if (__sync_add_and_fetch(&i, 1)) j = __sync_sub_and_fetch(&i, 1); while (!__sync_bool_compare_and_swap(&i, 0, 1)); ]) ], [ AC_MSG_RESULT(yes) test x"$atomic_ops" = x"none" && \ atomic_ops="__sync_* builtins" AC_DEFINE(OF_HAVE_SYNC_BUILTINS, 1, [Whether __sync_* builtins are available]) ], [ AC_MSG_RESULT(no) ]) AC_CHECK_HEADER(libkern/OSAtomic.h, [ test x"$atomic_ops" = x"none" && atomic_ops="libkern/OSAtomic.h" AC_DEFINE(OF_HAVE_OSATOMIC, 1, [Whether we have libkern/OSAtomic.h]) ]) ], [ dnl We can only have one thread - therefore everything is atomic atomic_ops="not needed" ]) AC_MSG_CHECKING(for atomic operations) AS_IF([test x"$atomic_ops" != x"none"], [ AC_DEFINE(OF_HAVE_ATOMIC_OPS, 1, [Whether we have atomic operations]) AC_SUBST(USE_INCLUDES_ATOMIC, '${INCLUDES_ATOMIC}') ]) AC_MSG_RESULT($atomic_ops) AC_ARG_ENABLE(files, AS_HELP_STRING([--disable-files], [disable file support])) AS_IF([test x"$enable_files" != x"no"], [ AC_DEFINE(OF_HAVE_FILES, 1, [Whether we have files]) AC_SUBST(USE_SRCS_FILES, '${SRCS_FILES}') AC_SUBST(OBJFW_NEW, "objfw-new") AC_SUBST(OFARC, "ofarc") AC_SUBST(OFHASH, "ofhash") case "$host_os" in msdosdjgpp*) dnl DJGPP has the type, but it's not really usable. ;; *) AC_CHECK_TYPE(off64_t, [ AC_DEFINE(OF_HAVE_OFF64_T, 1, [Whether we have off64_t]) AC_CHECK_FUNCS([lseek64 lstat64 open64 stat64]) ]) ;; esac AC_CHECK_HEADERS([pwd.h grp.h]) AC_CHECK_FUNC(chmod, [ AC_DEFINE(OF_HAVE_CHMOD, 1, [Whether we have chmod()]) ]) AC_CHECK_FUNC(chown, [ AC_DEFINE(OF_HAVE_CHOWN, 1, [Whether we have chown()]) ]) AC_CHECK_FUNC(link, [ AC_DEFINE(OF_HAVE_LINK, 1, [Whether we have link()]) ]) AC_CHECK_FUNC(symlink, [ AC_DEFINE(OF_HAVE_SYMLINK, 1, [Whether we have symlink()]) ]) AC_CHECK_FUNCS([lstat]) AC_CHECK_MEMBERS([struct stat.st_birthtime], [], [], [ #include ]) ]) AC_CHECK_HEADERS(dirent.h) AC_CHECK_FUNCS([sysconf gmtime_r localtime_r]) case "$host_os" in amigaos* | morphos*) dnl We don't want fcntl() or nanosleep() on AmigaOS / MorphOS, despite dnl a symbol existing. The reason is that we cannot use fcntl() for dnl sockets and that nanosleep() is yet another function that uses dnl errno, so would need to be passed from the linklib. ;; *) AC_CHECK_HEADERS(fcntl.h) AC_CHECK_FUNCS([fcntl nanosleep]) ;; esac AC_CHECK_HEADERS(xlocale.h) AC_CHECK_FUNCS([strtod_l strtof_l asprintf_l uselocale]) AS_IF([test x"$gnu_source" != x"yes" -a \( \ x"$ac_cv_func_strtod_l" = x"yes" -o x"$ac_cv_func_strtof_l" = x"yes" -o \ x"$ac_cv_func_asprintf_l" = x"yes" \)], [ AC_MSG_CHECKING(whether *_l functions need _GNU_SOURCE) AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([ #include #include #include #ifdef HAVE_XLOCALE_H # include #endif ], [ #ifdef HAVE_STRTOD_L (void)strtod_l; #endif #ifdef HAVE_STRTOF_L (void)strtof_l; #endif #ifdef HAVE_ASPRINTF_L (void)asprintf_l; #endif ]) ], [ AC_MSG_RESULT(no) ], [ AC_MSG_RESULT(yes) CPPFLAGS="-D_GNU_SOURCE $CPPFLAGS" ]) ]) dnl This check needs to happen after the above, as _GNU_SOURCE can change the dnl return type. AC_CHECK_FUNCS(strerror_r, [ AC_MSG_CHECKING(for return type of strerror_r) AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([ #include #include ], [ switch (strerror_r(0, NULL, 0)) { case 0:; } ]) ], [ AC_MSG_RESULT(int) ], [ AC_MSG_RESULT(char *) AC_DEFINE(STRERROR_R_RETURNS_CHARP, 1, [Whether strerror_r returns char *]) ]) ]) AC_CHECK_HEADERS(sys/utsname.h) AC_CHECK_FUNCS(uname) AC_CHECK_FUNC(pipe, [ AC_DEFINE(OF_HAVE_PIPE, 1, [Whether we have pipe()]) ]) AC_ARG_ENABLE(sockets, AS_HELP_STRING([--disable-sockets], [disable socket support])) AS_IF([test x"$enable_sockets" != x"no"], [ AC_DEFINE(OF_HAVE_SOCKETS, 1, [Whether we have sockets]) AC_SUBST(USE_SRCS_SOCKETS, '${SRCS_SOCKETS}') case "$host_os" in amigaos* | morphos*) ;; haiku*) LIBS="$LIBS -lnetwork" ;; mingw*) LIBS="$LIBS -lws2_32 -liphlpapi" ;; *) AC_CHECK_LIB(socket, socket, LIBS="$LIBS -lsocket") ;; esac AC_CHECK_HEADER(sys/socket.h, [ AC_DEFINE(OF_HAVE_SYS_SOCKET_H, 1, [Whether we have sys/socket.h]) ]) AC_CHECK_MEMBERS([struct sockaddr.sa_len], [], [], [ #ifdef OF_HAVE_SYS_TYPES_H # include #endif #ifdef OF_HAVE_SYS_SOCKET_H # include #endif #ifdef _WIN32 # include #endif ]) AC_CHECK_TYPE([struct sockaddr_storage], [ AC_DEFINE(OF_HAVE_SOCKADDR_STORAGE, 1, [Whether we have struct sockaddr_storage]) ], [], [ #ifdef OF_HAVE_SYS_TYPES_H # include #endif #ifdef OF_HAVE_SYS_SOCKET_H # include #endif #ifdef _WIN32 # include #endif ]) AC_CHECK_HEADER(netinet/in.h, [ AC_DEFINE(OF_HAVE_NETINET_IN_H, 1, [Whether we have netinet/in.h]) ]) AC_CHECK_HEADER(netinet/tcp.h, [ AC_DEFINE(OF_HAVE_NETINET_TCP_H, 1, [Whether we have netinet/tcp.h]) ]) AC_CHECK_HEADERS([arpa/inet.h netdb.h sys/sockio.h]) AC_CHECK_HEADERS([net/if.h], [], [], [ #ifdef OF_HAVE_SYS_SOCKET_H # include #endif ]) AC_CHECK_HEADERS([net/if_arp.h net/if_dl.h net/if_types.h]) AC_CHECK_FUNCS([if_indextoname if_nametoindex if_nameindex]) AC_CHECK_TYPES([struct sockaddr_dl], [], [], [ #ifdef HAVE_SYS_TYPES_H # include #endif #ifdef HAVE_NET_IF_DL_H # include #endif ]) AC_CHECK_TYPES([struct lifconf], [], [], [ #ifdef HAVE_NET_IF_H # include #endif ]) AC_CHECK_MEMBERS([struct ifreq.ifr_hwaddr], [], [], [ #ifdef HAVE_NET_IF_H # include #endif ]) AC_CHECK_HEADER(sys/un.h, [ AC_DEFINE(OF_HAVE_SYS_UN_H, 1, [Whether we have sys/un.h]) ]) AC_CHECK_MEMBER([struct sockaddr_in6.sin6_addr], [ AC_EGREP_CPP(egrep_cpp_yes, [ #ifdef _WIN32 typedef int BOOL; #endif #ifdef OF_HAVE_SYS_SOCKET_H # include #endif #ifdef _WIN32 # ifdef __MINGW32__ # include <_mingw.h> # ifdef __MINGW64_VERSION_MAJOR # include # endif # endif # include # include #endif #ifdef AF_INET6 egrep_cpp_yes #endif ], [ AC_DEFINE(OF_HAVE_IPV6, 1, [Whether we have IPv6]) ]) ], [ dnl Work around a bug in autoconf 2.61 that creates a broken dnl configure if this branch is empty. : ], [ #ifdef _WIN32 typedef int BOOL; #endif #ifdef OF_HAVE_NETINET_IN_H # include #endif #ifdef _WIN32 # ifdef __MINGW32__ # include <_mingw.h> # ifdef __MINGW64_VERSION_MAJOR # include # endif # endif # include # include #endif ]) AC_CHECK_HEADERS(afunix.h, [ AC_DEFINE(OF_HAVE_AFUNIX_H, 1, [Whether we have afunix.h]) ], [], [ #ifdef _WIN32 # include #endif ]) AC_CHECK_MEMBER(struct sockaddr_un.sun_path, [ AC_DEFINE(OF_HAVE_UNIX_SOCKETS, 1, [Whether we have UNIX sockets]) AC_SUBST(USE_SRCS_UNIX_SOCKETS, '${SRCS_UNIX_SOCKETS}') AC_CHECK_MEMBERS(struct sockaddr_un.sun_len, [], [], [ #ifdef OF_HAVE_SYS_TYPES_H # include #endif #ifdef OF_HAVE_SYS_UN_H # include #endif #ifdef _WIN32 # include #endif #ifdef HAVE_AFUNIX_H # include #endif ]) ], [], [ #ifdef OF_HAVE_SYS_TYPES_H # include #endif #ifdef OF_HAVE_SYS_UN_H # include #endif #ifdef _WIN32 # include #endif #ifdef HAVE_AFUNIX_H # include #endif #ifdef __morphos__ # error MorphOS has the struct but does not support it #endif #ifdef __MINT__ # error Gives invalid argument at runtime #endif ]) AC_CHECK_HEADER(netipx/ipx.h, [ AC_DEFINE(OF_HAVE_NETIPX_IPX_H, 1, [Whether we have netipx/ipx.h]) ]) AC_CHECK_MEMBER(struct sockaddr_ipx.sipx_network, [], [ AC_CHECK_MEMBER(struct sockaddr_ipx.sa_netnum, [], [ AC_CHECK_MEMBER(struct sockaddr_ipx.sipx_addr.x_port, [], [], [ #ifdef HAVE_SYS_TYPES_H # include #endif #ifdef OF_HAVE_NETIPX_IPX_H # include #endif ]) ], [ #ifdef _WIN32 typedef int BOOL; #endif #ifdef HAVE_SYS_TYPES_H # include #endif #ifdef OF_HAVE_NETIPX_IPX_H # include #endif #ifdef _WIN32 # ifdef __MINGW32__ # include <_mingw.h> # ifdef __MINGW64_VERSION_MAJOR # include # endif # endif # include # include #endif ]) ], [ #ifdef _WIN32 typedef int BOOL; #endif #ifdef HAVE_SYS_TYPES_H # include #endif #ifdef OF_HAVE_NETIPX_IPX_H # include #endif #ifdef _WIN32 # ifdef __MINGW32__ # include <_mingw.h> # ifdef __MINGW64_VERSION_MAJOR # include # endif # endif # include # include #endif ]) AS_IF([test x"$ac_cv_member_struct_sockaddr_ipx_sipx_network" = x"yes" \ -o x"$ac_cv_member_struct_sockaddr_ipx_sa_netnum" = x"yes" -o \ x"$ac_cv_member_struct_sockaddr_ipx_sipx_addr_x_port" = x"yes"], [ AC_EGREP_CPP(egrep_cpp_yes, [ #ifdef _WIN32 typedef int BOOL; #endif #ifdef OF_HAVE_SYS_SOCKET_H # include #endif #ifdef _WIN32 # ifdef __MINGW32__ # include <_mingw.h> # ifdef __MINGW64_VERSION_MAJOR # include # endif # endif # include # include #endif #ifdef AF_IPX egrep_cpp_yes #endif ], [ AC_DEFINE(OF_HAVE_IPX, 1, [Whether we have IPX/SPX]) AC_SUBST(USE_SRCS_IPX, '${SRCS_IPX}') ]) ]) AC_CHECK_HEADER(netat/appletalk.h, [ AC_DEFINE(OF_HAVE_NETAT_APPLETALK_H, 1, [Whether we have netat/appletalk.h]) ]) AC_CHECK_HEADER(netatalk/at.h, [ AC_DEFINE(OF_HAVE_NETATALK_AT_H, 1, [Whether we have netatalk/at.h]) ]) AC_CHECK_MEMBER(struct sockaddr_at.sat_addr, [], [ AC_CHECK_MEMBER(struct sockaddr_at.sat_net, [], [], [ #ifdef _WIN32 typedef int BOOL; #endif #ifdef OF_HAVE_SYS_TYPES_H # include #endif #if defined(OF_HAVE_NETAT_APPLETALK_H) # include #elif defined(OF_HAVE_NETATALK_AT_H) # include #endif #ifdef _WIN32 # ifdef __MINGW32__ # include <_mingw.h> # ifdef __MINGW64_VERSION_MAJOR # include # endif # endif # include # include #endif ]) ], [ #ifdef _WIN32 typedef int BOOL; #endif #ifdef OF_HAVE_SYS_TYPES_H # include #endif #if defined(OF_HAVE_NETAT_APPLETALK_H) # include #elif defined(OF_HAVE_NETATALK_AT_H) # include #endif #ifdef _WIN32 # ifdef __MINGW32__ # include <_mingw.h> # ifdef __MINGW64_VERSION_MAJOR # include # endif # endif # include # include #endif ]) AS_IF([test x"$ac_cv_member_struct_sockaddr_at_sat_addr" = x"yes" \ -o x"$ac_cv_member_struct_sockaddr_at_sat_net" = x"yes"], [ AC_EGREP_CPP(egrep_cpp_yes, [ #ifdef _WIN32 typedef int BOOL; #endif #ifdef OF_HAVE_SYS_SOCKET_H # include #endif #ifdef _WIN32 # ifdef __MINGW32__ # include <_mingw.h> # ifdef __MINGW64_VERSION_MAJOR # include # endif # endif # include # include #endif #ifdef AF_APPLETALK egrep_cpp_yes #endif ], [ AC_DEFINE(OF_HAVE_APPLETALK, 1, [Whether we have AppleTalk]) AC_SUBST(USE_SRCS_APPLETALK, '${SRCS_APPLETALK}') ]) ]) AC_CHECK_FUNCS(paccept accept4, break) AC_CHECK_FUNCS(kqueue1 kqueue, [ AC_DEFINE(HAVE_KQUEUE, 1, [Whether we have kqueue]) AC_SUBST(OF_KQUEUE_KERNEL_EVENT_OBSERVER_M, "OFKqueueKernelEventObserver.m") break ]) AC_CHECK_FUNCS(epoll_create1 epoll_create, [ AC_DEFINE(HAVE_EPOLL, 1, [Whether we have epoll]) AC_SUBST(OF_EPOLL_KERNEL_EVENT_OBSERVER_M, "OFEpollKernelEventObserver.m") break ]) AS_IF([test x"$with_wii" = x"yes"], [ AC_DEFINE(HAVE_POLL, 1, [Whether we have poll()]) AC_SUBST(OF_POLL_KERNEL_EVENT_OBSERVER_M, "OFPollKernelEventObserver.m") ], [ AC_CHECK_HEADERS(poll.h) AC_CHECK_FUNC(poll, [ AC_DEFINE(HAVE_POLL, 1, [Whether we have poll()]) AC_SUBST(OF_POLL_KERNEL_EVENT_OBSERVER_M, "OFPollKernelEventObserver.m") ]) ]) case "$host_os" in amigaos* | mingw* | morphos*) AC_DEFINE(HAVE_SELECT, 1, [Whether we have select() or similar]) AC_SUBST(OF_SELECT_KERNEL_EVENT_OBSERVER_M, "OFSelectKernelEventObserver.m") ;; *) AC_CHECK_HEADERS(sys/select.h) AC_CHECK_FUNC(select, [ AC_DEFINE(HAVE_SELECT, 1, [Whether we have select() or similar]) AC_SUBST(OF_SELECT_KERNEL_EVENT_OBSERVER_M, "OFSelectKernelEventObserver.m") ]) ;; esac AC_ARG_WITH(tls, AS_HELP_STRING([--with-tls], [ enable TLS support using the specified library (yes, openssl, gnutls, securetransport, mbedtls or no)])) AS_IF([test x"$with_tls" = x""], [with_tls="yes"]) tls_support="no" AS_IF([test x"$with_tls" = x"securetransport" \ -o x"$with_tls" = x"yes"], [ AC_CHECK_HEADERS(Security/SecureTransport.h, [ old_LIBS="$LIBS" LIBS="-framework Security -framework Foundation $LIBS" AC_CHECK_FUNC(SSLHandshake, [ tls_support="Secure Transport" TLS_LIBS="-framework Foundation $TLS_LIBS" TLS_LIBS="-framework Security $TLS_LIBS" AC_SUBST(OF_SECURE_TRANSPORT_TLS_STREAM_M, "OFSecureTransportTLSStream.m") AC_CHECK_FUNCS(SSLCreateContext) ], []) LIBS="$old_LIBS" ]) ]) AS_IF([test x"$with_tls" = x"openssl" \ -o \( x"$with_tls" = x"yes" -a x"$tls_support" = x"no" \)], [ case "$host_os" in morphos*) ssl="ssl_shared" crypto="crypto_shared" ;; *) ssl="ssl" crypto="crypto" ;; esac AC_CHECK_LIB($ssl, SSL_set1_host, [ AC_CHECK_HEADER(openssl/ssl.h, [ tls_support="OpenSSL" TLS_LIBS="-l$ssl -l$crypto $TLS_LIBS" AC_SUBST(OF_OPENSSL_TLS_STREAM_M, "OFOpenSSLTLSStream.m") old_LIBS="$LIBS" LIBS="$TLS_LIBS $LIBS" AC_CHECK_FUNCS(SSL_has_pending) LIBS="$old_LIBS" ]) ], [], [-l$crypto]) ]) AS_IF([test x"$with_tls" = x"gnutls" \ -o \( x"$with_tls" = x"yes" -a x"$tls_support" = x"no" \)], [ PKG_CHECK_MODULES(gnutls, [gnutls >= 3.5.0], [ tls_support="GnuTLS" TLS_CPPFLAGS="$gnutls_CFLAGS $TLS_CPPFLAGS" TLS_LIBS="$gnutls_LIBS $TLS_LIBS" AC_SUBST(OF_GNUTLS_TLS_STREAM_M, "OFGnuTLSTLSStream.m") ], [ dnl Disable default action-if-not-found, which exits dnl configure with an error. : ]) ]) AS_IF([test x"$with_tls" = x"mbedtls"], [ AC_CHECK_LIB(mbedtls, mbedtls_net_init, [ AC_CHECK_HEADER(mbedtls/ssl.h, [ tls_support="Mbed TLS" TLS_LIBS="-lmbedx509 -lmbedcrypto $TLS_LIBS" TLS_LIBS="-lmbedtls $TLS_LIBS" AC_SUBST(OF_MBEDTLS_TLS_STREAM_M, "OFMbedTLSTLSStream.m") ]) ], [], [-lmbedx509 -lmbedcrypto]) ]) AS_IF([test x"$tls_support" != x"no"], [ AC_SUBST(TLS, "tls") AC_SUBST(TLS_CPPFLAGS) AC_SUBST(TLS_LIBS) AC_DEFINE(HAVE_TLS_SUPPORT, 1, [Whether we have an implementation for TLS]) AC_CONFIG_FILES(src/tls/Info.plist) OFARC_LIBS="-lobjfwtls $TLS_LIBS $OFARC_LIBS" OFHASH_LIBS="-lobjfwtls $TLS_LIBS $OFHASH_LIBS" OFHTTP_LIBS="-lobjfwtls $TLS_LIBS $OFHTTP_LIBS" AS_IF([test x"$enable_shared" != x"no"], [ AC_SUBST(OBJFWTLS_SHARED_LIB, '${LIB_PREFIX}objfwtls${LIB_SUFFIX}') ]) AS_IF([test x"$enable_static" = x"yes" \ -o x"$enable_shared" = x"no"], [ AC_SUBST(OBJFWTLS_STATIC_LIB, "libobjfwtls.a") ]) AS_IF([test x"$build_framework" = x"yes"], [ AC_SUBST(OBJFWTLS_FRAMEWORK, "ObjFWTLS.framework") ]) ]) AS_IF([test x"$with_tls" != x"no" -a x"$tls_support" = x"no"], [ AC_MSG_ERROR(m4_normalize([ No TLS implementation was found. Please install OpenSSL, GnuTLS, Mbed TLS or use --without-tls. ])) ]) AS_IF([test x"$enable_threads" != x"no"], [ AC_SUBST(OF_HTTP_CLIENT_TESTS_M, "OFHTTPClientTests.m") ]) AC_SUBST(OFDNS, "ofdns") AS_IF([test x"$enable_files" != x"no"], [ AC_SUBST(OFHTTP, "ofhttp") AC_SUBST(OFHTTP_LIBS) ]) ]) AC_DEFUN([CHECK_BUILTIN_BSWAP], [ AC_MSG_CHECKING(for __builtin_bswap$1) AC_LINK_IFELSE([ AC_LANG_PROGRAM([ #include #include #include ], [ uint$1_t i = errno; printf("%d", (int)__builtin_bswap$1(i)); ]) ], [ AC_MSG_RESULT(yes) AC_DEFINE(OF_HAVE_BUILTIN_BSWAP$1, 1, [Whether we have __builtin_bswap$1]) ], [ AC_MSG_RESULT(no) ]) ]) CHECK_BUILTIN_BSWAP(16) CHECK_BUILTIN_BSWAP(32) CHECK_BUILTIN_BSWAP(64) case "$host_os" in darwin*) AC_MSG_CHECKING(whether we are compiling for macOS) AC_EGREP_CPP(egrep_cpp_yes, [ #include #if (!defined(TARGET_OS_IPHONE) || !TARGET_OS_IPHONE) && \ (!defined(TARGET_OS_SIMULATOR) || !TARGET_OS_SIMULATOR) egrep_cpp_yes #endif ], [ AC_MSG_RESULT(yes) ], [ AC_MSG_RESULT(no) have_subprocesses="no" ]) ;; mingw*) have_subprocesses="yes" ;; msdosdjgpp*) have_subprocesses="no" ;; esac AS_IF([test x"$have_subprocesses" = x""], [ AC_HEADER_SYS_WAIT AC_CHECK_FUNCS(kill) AC_CHECK_FUNCS(posix_spawnp, [ AS_IF([test x"$ac_cv_func_kill" = x"yes"], [ AC_CHECK_HEADERS(spawn.h, [have_subprocesses="yes"]) ]) ]) AS_IF([test x"$have_subprocesses" = x""], [ AC_CHECK_FUNCS([vfork dup2 execvp _exit], [ AS_IF([test x"$ac_cv_func_vfork" = x"yes" \ -a x"$ac_cv_func_pipe" = x"yes" \ -a x"$ac_cv_func_dup2" = x"yes" \ -a x"$ac_cv_func_execvp" = x"yes" \ -a x"$ac_cv_func_kill" = x"yes" \ -a x"$ac_cv_func__exit" = x"yes"], [ have_subprocesses="yes" ]) ], [ break ]) ]) ]) AS_IF([test x"$have_subprocesses" = x"yes"], [ AC_SUBST(USE_SRCS_SUBPROCESSES, '${SRCS_SUBPROCESSES}') AC_SUBST(SUBPROCESS, "subprocess") AC_DEFINE(OF_HAVE_SUBPROCESSES, 1, [Whether we have subprocesses]) ]) AC_CHECK_HEADERS_ONCE([complex.h sys/ioctl.h sys/ttycom.h]) AC_CHECK_FUNCS(ioctl isatty) AC_CHECK_FUNC(pledge, [ AC_DEFINE(OF_HAVE_PLEDGE, 1, [Whether we have pledge()]) ]) AS_IF([test x"$objc_runtime" = x"Apple runtime"], [ AC_CHECK_HEADER(Foundation/NSObject.h, [ AC_SUBST(BRIDGE, "bridge") AC_CONFIG_FILES(src/bridge/Info.plist) AS_IF([test x"$enable_shared" != x"no"], [ AC_SUBST(OBJFWBRIDGE_SHARED_LIB, '${LIB_PREFIX}objfwbridge${LIB_SUFFIX}') ]) AS_IF([test x"$enable_static" = x"yes" \ -o x"$enable_shared" = x"no"], [ AC_SUBST(OBJFWBRIDGE_STATIC_LIB, "libobjfwbridge.a") ]) AS_IF([test x"$build_framework" = x"yes"], [ AC_SUBST(OBJFWBRIDGE_FRAMEWORK, "ObjFWBridge.framework") ]) ]) ]) dnl This needs to be after all other header checks, as they include unistd.h, dnl which in old glibc versions uses __block. This is worked around in the code dnl by providing a wrapper for unistd.h which takes care of this. AC_MSG_CHECKING(whether Objective C compiler supports blocks) old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -Xclang -fblocks" AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([], [ int (^foo)(int bar); foo = ^ (int bar) { return 0; } ]) ], [ OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS -Xclang -fblocks" AC_SUBST(OF_BLOCK_TESTS_M, "OFBlockTests.m") AC_MSG_RESULT(yes) ], [ AC_MSG_RESULT(no) OBJCFLAGS="$old_OBJCFLAGS" ]) AS_IF([test x"$GOBJC" = x"yes"], [ OBJCFLAGS="$OBJCFLAGS -Wwrite-strings -Wpointer-arith" AC_ARG_ENABLE(werror, AS_HELP_STRING([--disable-werror], [do not build with -Werror])) AS_IF([test x"$enable_werror" = x"yes"], [ OBJCFLAGS="$OBJCFLAGS -Werror" ]) old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -Werror" AC_MSG_CHECKING(whether we need -Wno-strict-aliasing due to GCC bugs) AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([ #ifdef __has_attribute # if __has_attribute(objc_root_class) __attribute__((__objc_root_class__)) # endif #endif @interface Foo { struct objc_class *_isa; } @end static struct { struct objc_class *_isa; } object; ], [ Foo *test = (Foo *)&object; (void)test; /* Get rid of unused variable warning */ ]) ], [ AC_MSG_RESULT(no) OBJCFLAGS="$old_OBJCFLAGS" ], [ AC_MSG_RESULT(yes) OBJCFLAGS="$old_OBJCFLAGS -Wno-strict-aliasing" ]) old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -Werror" AC_MSG_CHECKING( whether we need -Wno-unused-property-ivar due to Clang bugs) AC_COMPILE_IFELSE([ AC_LANG_SOURCE([ #ifdef __has_attribute # if __has_attribute(objc_root_class) __attribute__((__objc_root_class__)) # endif #endif @interface Foo { struct objc_class *_isa; Foo *_foo; } @property (readonly, nonatomic) Foo *foo; + (Foo *)foo; @end @implementation Foo @synthesize foo = _foo; + (Foo *)foo { return (Foo *)0; } @end ]) ], [ AC_MSG_RESULT(no) OBJCFLAGS="$old_OBJCFLAGS" ], [ AC_MSG_RESULT(yes) OBJCFLAGS="$old_OBJCFLAGS -Wno-unused-property-ivar" ]) old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -Wcast-align -Werror" AC_MSG_CHECKING(whether -Wcast-align is buggy) AC_COMPILE_IFELSE([ AC_LANG_SOURCE([ #ifdef __has_attribute # if __has_attribute(objc_root_class) __attribute__((__objc_root_class__)) # endif #endif @interface Foo { struct objc_class *_isa; } @end @implementation Foo - (void)foo { struct objc_class *c = _isa; (void)c; } @end ]) ], [ AC_MSG_RESULT(no) OBJCFLAGS="$old_OBJCFLAGS -Wcast-align" ], [ AC_MSG_RESULT(yes) OBJCFLAGS="$old_OBJCFLAGS" ]) old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -Wunreachable-code -Werror" AC_MSG_CHECKING(whether -Wunreachable-code can be used) AC_COMPILE_IFELSE([ AC_LANG_SOURCE([[ #include struct objc_selector; typedef const struct objc_selector *SEL; #ifdef __has_attribute # if __has_attribute(objc_root_class) __attribute__((__objc_root_class__)) # endif #endif @interface Object - (void)doesNotRecognizeSelector: (SEL)selector #ifdef __clang__ __attribute__((__noreturn__)) #endif ; - (void)dealloc; @end @interface Foo: Object @end void test(void) { if (sizeof(int) == 4) __asm__ (""); else if (sizeof(int) == 8) __asm__ (""); else abort(); } /* * Unfortunately, this cannot be shorter, as it only * works when it is used inside a macro. */ #ifdef __clang__ # define OF_DEALLOC_UNSUPPORTED \ [self doesNotRecognizeSelector: _cmd]; \ \ abort(); \ \ _Pragma("clang diagnostic push"); \ _Pragma("clang diagnostic ignored \ \"-Wunreachable-code\""); \ [super dealloc]; \ _Pragma("clang diagnostic pop"); #else # define OF_DEALLOC_UNSUPPORTED \ [self doesNotRecognizeSelector: _cmd]; \ \ abort(); \ \ [super dealloc]; #endif @implementation Foo - (void)dealloc { OF_DEALLOC_UNSUPPORTED } @end ]]) ], [ AC_MSG_RESULT(yes) OBJCFLAGS="$old_OBJCFLAGS -Wunreachable-code" ], [ AC_MSG_RESULT(no) OBJCFLAGS="$old_OBJCFLAGS" ]) old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -Wdocumentation -Werror" AC_MSG_CHECKING(whether -Wdocumentation works correctly) AC_COMPILE_IFELSE([ AC_LANG_SOURCE([ /** * @class Test conftest.m conftest.m */ #ifdef __has_attribute # if __has_attribute(objc_root_class) __attribute__((__objc_root_class__)) # endif #endif @interface Test @end /** * @struct Foo conftest.m conftest.m */ typedef struct {} Foo; ]) ], [ AC_MSG_RESULT(yes) OBJCFLAGS="$old_OBJCFLAGS -Wdocumentation" ], [ AC_MSG_RESULT(no) OBJCFLAGS="$old_OBJCFLAGS" ]) AS_IF([test x"$check_pedantic" = x"yes"], [ old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -pedantic -Werror" AC_MSG_CHECKING(whether -pedantic is buggy) AC_COMPILE_IFELSE([ AC_LANG_SOURCE([ #include #include #ifdef __has_attribute # if __has_attribute(objc_root_class) __attribute__((__objc_root_class__)) # endif #endif @interface Foo { void *foo; } @end @interface Bar: Foo - (void)assert; @end @implementation Bar - (void)assert { /* * Some versions of glibc break with * -pedantic when using assert. */ assert(1); } @end ]) ], [ AC_MSG_RESULT(no) OBJCFLAGS="$old_OBJCFLAGS -pedantic" ], [ AC_MSG_RESULT(yes) OBJCFLAGS="$old_OBJCFLAGS" ]) ]) old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -Werror" AC_MSG_CHECKING(whether we need -Wno-strict-prototypes) AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([ #include ], [ signal(SIGINT, SIG_DFL); ]) ], [ AC_MSG_RESULT(no) OBJCFLAGS="$old_OBJCFLAGS" ], [ AC_MSG_RESULT(yes) OBJCFLAGS="$old_OBJCFLAGS -Wno-strict-prototypes" ]) AS_IF([test x"$ac_cv_header_complex_h" = x"yes"], [ old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -Werror" AC_MSG_CHECKING(whether we need -Wno-gnu-imaginary-constant) AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([ #include ], [ complex float f = 0.5 + 0.5 * I; (void)f; ]) ], [ AC_MSG_RESULT(no) OBJCFLAGS="$old_OBJCFLAGS" ], [ AC_MSG_RESULT(yes) OBJCFLAGS="$old_OBJCFLAGS -Wno-gnu-imaginary-constant" ]) ]) ]) AS_IF([test x"$cross_compiling" = x"yes"], [ AC_SUBST(BIN_PREFIX, "${host_alias}-") case "$host" in i?86-*-mingw*) AC_CHECK_PROG(WINE, wine, wine) ;; x86_64-*-mingw*) AC_CHECK_PROG(WINE, wine64, wine64) ;; esac AS_IF([test x"$WINE" != x""], [AC_SUBST(WRAPPER, "$WINE")]) AS_IF([test x"$with_wii" = x"yes"], [ dnl Keep this lowercase, as WIILOAD is a variable used by dnl wiiload and thus likely already set by the user to something dnl that is not the path of the wiiload binary. AC_CHECK_PROG(wiiload, wiiload, wiiload) AS_IF([test x"$wiiload" != x""], [ AC_SUBST(WRAPPER, "$wiiload") ]) ]) ]) dnl We don't call AC_PROG_CPP, but only AC_PROG_OBJCPP and set CPP to OBJCPP dnl and add OBJCPPFLAGS to CPPFLAGS, thus we need to AC_SUBST these ourself. AC_SUBST(CPP) AC_SUBST(CPPFLAGS) dnl We use the ObjC compiler as our assembler AC_SUBST(AS, $OBJC) AC_SUBST(ASFLAGS) AC_SUBST(DEP_ASFLAGS, '${DEP_OBJCFLAGS}') AC_SUBST(OBJFW_CPPFLAGS) AC_SUBST(OBJFW_OBJCFLAGS) AC_SUBST(TESTS_LIBS) AC_CONFIG_FILES([ buildsys.mk extra.mk src/Info.plist tests/Info.plist utils/objfw-config ]) AC_CONFIG_HEADERS([config.h src/objfw-defs.h]) AC_OUTPUT AS_IF([test x"$old_compiler" = x"yes"], [ echo printf " ** Note: Your compiler does not seem to " echo "accept -fobjc-runtime=objfw." printf " ** To get optimal performance, you should install " echo "Clang >= 3.2" printf " ** (or the latest Clang release to be able to use all " echo "features)." echo ]) AS_IF([test x"$enable_threads" != x"no" -a x"$atomic_ops" = x"none" \ -a x"$have_spinlocks" != x"yes" -a x"$have_amiga_threads" != x"yes"], [ echo printf " ** Warning: You have enabled threads, but neither atomic " echo "operations nor" printf " ** spinlocks are available. Expect *very* poor performance, " echo "as a mutex will" printf " ** be locked for every retain and release! If you don't " echo "need threads, try" echo " ** --disable-threads to work around this problem." echo ]) objfw-1.1.6/extra.mk.in000066400000000000000000000065471465614216400147340ustar00rootroot00000000000000OBJFW_SHARED_LIB = @OBJFW_SHARED_LIB@ OBJFW_STATIC_LIB = @OBJFW_STATIC_LIB@ OBJFW_FRAMEWORK = @OBJFW_FRAMEWORK@ OBJFW_LIB_MAJOR = 1 OBJFW_LIB_MINOR = 1 OBJFW_LIB_PATCH = 3 OBJFW_LIB_MAJOR_MINOR = ${OBJFW_LIB_MAJOR}.${OBJFW_LIB_MINOR} OBJFWRT_SHARED_LIB = @OBJFWRT_SHARED_LIB@ OBJFWRT_STATIC_LIB = @OBJFWRT_STATIC_LIB@ OBJFWRT_FRAMEWORK = @OBJFWRT_FRAMEWORK@ OBJFWRT_LIB_MAJOR = 1 OBJFWRT_LIB_MINOR = 1 OBJFWRT_LIB_PATCH = 3 OBJFWRT_LIB_MAJOR_MINOR = ${OBJFWRT_LIB_MAJOR}.${OBJFWRT_LIB_MINOR} OBJFWBRIDGE_SHARED_LIB = @OBJFWBRIDGE_SHARED_LIB@ OBJFWBRIDGE_STATIC_LIB = @OBJFWBRIDGE_STATIC_LIB@ OBJFWBRIDGE_FRAMEWORK = @OBJFWBRIDGE_FRAMEWORK@ OBJFWBRIDGE_LIB_MAJOR = 1 OBJFWBRIDGE_LIB_MINOR = 0 OBJFWBRIDGE_LIB_PATCH = 0 OBJFWTLS_SHARED_LIB = @OBJFWTLS_SHARED_LIB@ OBJFWTLS_STATIC_LIB = @OBJFWTLS_STATIC_LIB@ OBJFWTLS_FRAMEWORK = @OBJFWTLS_FRAMEWORK@ OBJFWTLS_LIB_MAJOR = 1 OBJFWTLS_LIB_MINOR = 0 OBJFWTLS_LIB_PATCH = 2 BIN_PREFIX = @BIN_PREFIX@ BRIDGE = @BRIDGE@ CVINCLUDE_INLINE_H = @CVINCLUDE_INLINE_H@ ENCODINGS_A = @ENCODINGS_A@ ENCODINGS_LIB_A = @ENCODINGS_LIB_A@ ENCODINGS_SRCS = @ENCODINGS_SRCS@ EXCEPTIONS_A = @EXCEPTIONS_A@ EXCEPTIONS_LIB_A = @EXCEPTIONS_LIB_A@ FORWARDING_A = @FORWARDING_A@ FORWARDING_LIB_A = @FORWARDING_LIB_A@ LIBBASES_M = @LIBBASES_M@ LIBOBJFWRT_DEP = @LIBOBJFWRT_DEP@ LIBOBJFWRT_DEP_LVL2 = @LIBOBJFWRT_DEP_LVL2@ LIBOBJFW_DEP = @LIBOBJFW_DEP@ LIBOBJFW_DEP_LVL2 = @LIBOBJFW_DEP_LVL2@ LOOKUP_ASM_A = @LOOKUP_ASM_A@ LOOKUP_ASM_LIB_A = @LOOKUP_ASM_LIB_A@ MAP_LDFLAGS = @MAP_LDFLAGS@ OBJC_SYNC = @OBJC_SYNC@ OBJFW_NEW = @OBJFW_NEW@ OFARC = @OFARC@ OFARC_LIBS = @OFARC_LIBS@ OFDNS = @OFDNS@ OFHASH = @OFHASH@ OFHASH_LIBS = @OFHTTP_LIBS@ OFHTTP = @OFHTTP@ OFHTTP_LIBS = @OFHTTP_LIBS@ OF_BLOCK_TESTS_M = @OF_BLOCK_TESTS_M@ OF_EPOLL_KERNEL_EVENT_OBSERVER_M = @OF_EPOLL_KERNEL_EVENT_OBSERVER_M@ OF_GNUTLS_TLS_STREAM_M = @OF_GNUTLS_TLS_STREAM_M@ OF_HTTP_CLIENT_TESTS_M = @OF_HTTP_CLIENT_TESTS_M@ OF_KQUEUE_KERNEL_EVENT_OBSERVER_M = @OF_KQUEUE_KERNEL_EVENT_OBSERVER_M@ OF_MBEDTLS_TLS_STREAM_M = @OF_MBEDTLS_TLS_STREAM_M@ OF_OPENSSL_TLS_STREAM_M = @OF_OPENSSL_TLS_STREAM_M@ OF_POLL_KERNEL_EVENT_OBSERVER_M = @OF_POLL_KERNEL_EVENT_OBSERVER_M@ OF_SECURE_TRANSPORT_TLS_STREAM_M = @OF_SECURE_TRANSPORT_TLS_STREAM_M@ OF_SELECT_KERNEL_EVENT_OBSERVER_M = @OF_SELECT_KERNEL_EVENT_OBSERVER_M@ REEXPORT_RUNTIME = @REEXPORT_RUNTIME@ REEXPORT_RUNTIME_FRAMEWORK = @REEXPORT_RUNTIME_FRAMEWORK@ RUNTIME = @RUNTIME@ RUNTIME_ARC_TESTS_M = @RUNTIME_ARC_TESTS_M@ RUNTIME_ASSOCIATION_M = @RUNTIME_ASSOCIATION_M@ RUNTIME_AUTORELEASE_M = @RUNTIME_AUTORELEASE_M@ RUNTIME_FRAMEWORK_LIBS = @RUNTIME_FRAMEWORK_LIBS@ RUNTIME_INSTANCE_M = @RUNTIME_INSTANCE_M@ RUNTIME_LIBS = @RUNTIME_LIBS@ SUBPROCESS = @SUBPROCESS@ TESTPLUGIN = @TESTPLUGIN@ TESTPLUGIN_LIBS = @TESTPLUGIN_LIBS@ TESTS_LIBS = @TESTS_LIBS@ TESTS_STATIC_LIB = @TESTS_STATIC_LIB@ TLS = @TLS@ TLS_CPPFLAGS = @TLS_CPPFLAGS@ TLS_LIBS = @TLS_LIBS@ UNICODE_M = @UNICODE_M@ USE_INCLUDES_ATOMIC = @USE_INCLUDES_ATOMIC@ USE_SRCS_APPLETALK = @USE_SRCS_APPLETALK@ USE_SRCS_FILES = @USE_SRCS_FILES@ USE_SRCS_IPX = @USE_SRCS_IPX@ USE_SRCS_PLUGINS = @USE_SRCS_PLUGINS@ USE_SRCS_SOCKETS = @USE_SRCS_SOCKETS@ USE_SRCS_SUBPROCESSES = @USE_SRCS_SUBPROCESSES@ USE_SRCS_TAGGED_POINTERS = @USE_SRCS_TAGGED_POINTERS@ USE_SRCS_THREADS = @USE_SRCS_THREADS@ USE_SRCS_UNIX_SOCKETS = @USE_SRCS_UNIX_SOCKETS@ USE_SRCS_WINDOWS = @USE_SRCS_WINDOWS@ WII_U_TESTS_LIBS = @WII_U_TESTS_LIBS@ WRAPPER = @WRAPPER@ objfw-1.1.6/generators/000077500000000000000000000000001465614216400150105ustar00rootroot00000000000000objfw-1.1.6/generators/unicode/000077500000000000000000000000001465614216400164365ustar00rootroot00000000000000objfw-1.1.6/generators/unicode/Makefile000066400000000000000000000052741465614216400201060ustar00rootroot00000000000000include ../../extra.mk PROG_NOINST = gen_tables${PROG_SUFFIX} SRCS = TableGenerator.m include ../../buildsys.mk .PHONY: run run: all rm -f libobjfw.so.${OBJFW_LIB_MAJOR} rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} rm -f objfw${OBJFW_LIB_MAJOR}.dll libobjfw.${OBJFW_LIB_MAJOR}.dylib rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR} rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} rm -f objfwrt${OBJFWRT_LIB_MAJOR}.dll rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib if test -f ../../src/libobjfw.so; then \ ${LN_S} ../../src/libobjfw.so libobjfw.so.${OBJFW_LIB_MAJOR}; \ ${LN_S} ../../src/libobjfw.so \ libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ elif test -f ../../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; then \ ${LN_S} ../../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} \ libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ fi if test -f ../../src/objfw${OBJFW_LIB_MAJOR}.dll; then \ ${LN_S} ../../src/objfw${OBJFW_LIB_MAJOR}.dll \ objfw${OBJFW_LIB_MAJOR}.dll; \ fi if test -f ../../src/libobjfw.dylib; then \ ${LN_S} ../../src/libobjfw.dylib \ libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ fi if test -f ../../src/runtime/libobjfwrt.so; then \ ${LN_S} ../../src/runtime/libobjfwrt.so \ libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ ${LN_S} ../../src/runtime/libobjfwrt.so \ libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ elif test -f ../../src/runtime/libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; then \ ${LN_S} ../../src/runtime/libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ fi if test -f ../../src/runtime/objfwrt${OBJFWRT_LIB_MAJOR}.dll; then \ ${LN_S} ../../src/runtime/objfwrt${OBJFWRT_LIB_MAJOR}.dll \ objfwrt${OBJFWRT_LIB_MAJOR}.dll; \ fi if test -f ../../src/runtime/libobjfwrt.dylib; then \ ${LN_S} ../../src/runtime/libobjfwrt.dylib \ libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ fi LD_LIBRARY_PATH=.$${LD_LIBRARY_PATH+:}$$LD_LIBRARY_PATH \ DYLD_FRAMEWORK_PATH=../../src:../../src/runtime$${DYLD_FRAMEWORK_PATH+:}$$DYLD_FRAMEWORK_PATH \ DYLD_LIBRARY_PATH=.$${DYLD_LIBRARY_PATH+:}$$DYLD_LIBRARY_PATH \ LIBRARY_PATH=.$${LIBRARY_PATH+:}$$LIBRARY_PATH \ ASAN_OPTIONS=allocator_may_return_null=1 \ ${WRAPPER} ./${PROG_NOINST}; EXIT=$$?; \ rm -f libobjfw.so.${OBJFW_LIB_MAJOR}; \ rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ rm -f objfw${OBJFW_LIB_MAJOR}.dll; \ rm -f libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ rm -f objfwrt${OBJFWRT_LIB_MAJOR}.dll; \ rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ exit $$EXIT CPPFLAGS += -I../../src -I../../src/exceptions -I../../src/runtime -I../.. LIBS := -L../../src -lobjfw -L../../src/runtime ${RUNTIME_LIBS} ${LIBS} LD = ${OBJC} objfw-1.1.6/generators/unicode/TableGenerator.h000066400000000000000000000031131465614216400215030ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFHTTPClient.h" @class OFString; @interface TableGenerator: OFObject { OFHTTPClient *_HTTPClient; OFUnichar _uppercaseTable[0x110000]; OFUnichar _lowercaseTable[0x110000]; OFUnichar _titlecaseTable[0x110000]; OFUnichar _caseFoldingTable[0x110000]; char _uppercaseTableUsed[0x1100]; char _lowercaseTableUsed[0x1100]; char _titlecaseTableUsed[0x1100]; char _caseFoldingTableUsed[0x1100]; size_t _uppercaseTableSize; size_t _lowercaseTableSize; size_t _titlecaseTableSize; size_t _caseFoldingTableSize; enum { stateUnicodeData, stateCaseFolding } _state; } - (void)parseUnicodeData: (OFHTTPResponse *)response; - (void)parseCaseFolding: (OFHTTPResponse *)response; - (void)writeFiles; - (void)writeTablesToFile: (OFString *)path; - (void)writeHeaderToFile: (OFString *)path; @end objfw-1.1.6/generators/unicode/TableGenerator.m000066400000000000000000000322431465614216400215160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFApplication.h" #import "OFArray.h" #import "OFFile.h" #import "OFHTTPClient.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" #import "OFIRI.h" #import "OFStdIOStream.h" #import "OFString.h" #import "OFOutOfRangeException.h" #import "TableGenerator.h" #import "copyright.h" static OFString *const unicodeDataIRI = @"http://www.unicode.org/Public/UNIDATA/UnicodeData.txt"; static OFString *const caseFoldingIRI = @"http://www.unicode.org/Public/UNIDATA/CaseFolding.txt"; OF_APPLICATION_DELEGATE(TableGenerator) @implementation TableGenerator - (instancetype)init { self = [super init]; @try { _HTTPClient = [[OFHTTPClient alloc] init]; _HTTPClient.delegate = self; _uppercaseTableSize = SIZE_MAX; _lowercaseTableSize = SIZE_MAX; _titlecaseTableSize = SIZE_MAX; _caseFoldingTableSize = SIZE_MAX; } @catch (id e) { [self release]; @throw e; } return self; } - (void)applicationDidFinishLaunching: (OFNotification *)notification { OFHTTPRequest *request; [OFStdOut writeString: @"Downloading UnicodeData.txt…"]; _state = stateUnicodeData; request = [OFHTTPRequest requestWithIRI: [OFIRI IRIWithString: unicodeDataIRI]]; [_HTTPClient asyncPerformRequest: request]; } - (void)client: (OFHTTPClient *)client didPerformRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response exception: (id)exception { if (exception != nil) @throw exception; [OFStdOut writeLine: @" done"]; switch (_state) { case stateUnicodeData: [self parseUnicodeData: response]; break; case stateCaseFolding: [self parseCaseFolding: response]; break; } } - (void)parseUnicodeData: (OFHTTPResponse *)response { OFString *line; OFHTTPRequest *request; [OFStdOut writeString: @"Parsing UnicodeData.txt…"]; while ((line = [response readLine]) != nil) { void *pool2; OFArray OF_GENERIC(OFString *) *components; OFUnichar codePoint; if (line.length == 0) continue; pool2 = objc_autoreleasePoolPush(); components = [line componentsSeparatedByString: @";"]; if (components.count != 15) { OFLog(@"Invalid line: %@\n", line); [OFApplication terminateWithStatus: 1]; } codePoint = (OFUnichar)[[components objectAtIndex: 0] unsignedLongLongValueWithBase: 16]; if (codePoint > 0x10FFFF) @throw [OFOutOfRangeException exception]; _uppercaseTable[codePoint] = (OFUnichar)[[components objectAtIndex: 12] unsignedLongLongValueWithBase: 16]; _lowercaseTable[codePoint] = (OFUnichar)[[components objectAtIndex: 13] unsignedLongLongValueWithBase: 16]; _titlecaseTable[codePoint] = (OFUnichar)[[components objectAtIndex: 14] unsignedLongLongValueWithBase: 16]; objc_autoreleasePoolPop(pool2); } [OFStdOut writeLine: @" done"]; [OFStdOut writeString: @"Downloading CaseFolding.txt…"]; _state = stateCaseFolding; request = [OFHTTPRequest requestWithIRI: [OFIRI IRIWithString: caseFoldingIRI]]; [_HTTPClient asyncPerformRequest: request]; } - (void)parseCaseFolding: (OFHTTPResponse *)response { OFString *line; [OFStdOut writeString: @"Parsing CaseFolding.txt…"]; while ((line = [response readLine]) != nil) { void *pool2; OFArray OF_GENERIC(OFString *) *components; OFUnichar codePoint; if (line.length == 0 || [line hasPrefix: @"#"]) continue; pool2 = objc_autoreleasePoolPush(); components = [line componentsSeparatedByString: @"; "]; if (components.count != 4) { OFLog(@"Invalid line: %s\n", line); [OFApplication terminateWithStatus: 1]; } if (![[components objectAtIndex: 1] isEqual: @"S"] && ![[components objectAtIndex: 1] isEqual: @"C"]) continue; codePoint = (OFUnichar)[[components objectAtIndex: 0] unsignedLongLongValueWithBase: 16]; if (codePoint > 0x10FFFF) @throw [OFOutOfRangeException exception]; _caseFoldingTable[codePoint] = (OFUnichar)[[components objectAtIndex: 2] unsignedLongLongValueWithBase: 16]; objc_autoreleasePoolPop(pool2); } [OFStdOut writeLine: @" done"]; [self writeFiles]; } - (void)writeFiles { OFIRI *IRI; [OFStdOut writeString: @"Writing files…"]; IRI = [OFIRI fileIRIWithPath: @"../../src/unicode.m"]; [self writeTablesToFile: IRI.fileSystemRepresentation]; IRI = [OFIRI fileIRIWithPath: @"../../src/unicode.h"]; [self writeHeaderToFile: IRI.fileSystemRepresentation]; [OFStdOut writeLine: @" done"]; [OFApplication terminate]; } - (void)writeTablesToFile: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFFile *file = [OFFile fileWithPath: path mode: @"w"]; [file writeString: COPYRIGHT @"#include \"config.h\"\n" @"\n" @"#import \"unicode.h\"\n" @"\n" @"static const OFUnichar emptyPage[0x100] = { 0 };\n" @"\n"]; /* Write uppercasePage%u */ for (OFUnichar i = 0; i < 0x110000; i += 0x100) { bool isEmpty = true; for (OFUnichar j = i; j < i + 0x100; j++) { if (_uppercaseTable[j] != 0) { isEmpty = false; _uppercaseTableSize = i >> 8; _uppercaseTableUsed[_uppercaseTableSize] = 1; break; } } if (!isEmpty) { void *pool2 = objc_autoreleasePoolPush(); [file writeFormat: @"static const OFUnichar " @"uppercasePage%u[0x100] = {\n", i >> 8]; for (OFUnichar j = i; j < i + 0x100; j += 8) [file writeFormat: @"\t%u, %u, %u, %u, %u, %u, %u, %u,\n", _uppercaseTable[j], _uppercaseTable[j + 1], _uppercaseTable[j + 2], _uppercaseTable[j + 3], _uppercaseTable[j + 4], _uppercaseTable[j + 5], _uppercaseTable[j + 6], _uppercaseTable[j + 7]]; [file writeString: @"};\n\n"]; objc_autoreleasePoolPop(pool2); } } /* Write lowercasePage%u */ for (OFUnichar i = 0; i < 0x110000; i += 0x100) { bool isEmpty = true; for (OFUnichar j = i; j < i + 0x100; j++) { if (_lowercaseTable[j] != 0) { isEmpty = false; _lowercaseTableSize = i >> 8; _lowercaseTableUsed[_lowercaseTableSize] = 1; break; } } if (!isEmpty) { void *pool2 = objc_autoreleasePoolPush(); [file writeFormat: @"static const OFUnichar " @"lowercasePage%u[0x100] = {\n", i >> 8]; for (OFUnichar j = i; j < i + 0x100; j += 8) [file writeFormat: @"\t%u, %u, %u, %u, %u, %u, %u, %u,\n", _lowercaseTable[j], _lowercaseTable[j + 1], _lowercaseTable[j + 2], _lowercaseTable[j + 3], _lowercaseTable[j + 4], _lowercaseTable[j + 5], _lowercaseTable[j + 6], _lowercaseTable[j + 7]]; [file writeString: @"};\n\n"]; objc_autoreleasePoolPop(pool2); } } /* Write titlecasePage%u if it does NOT match uppercasePage%u */ for (OFUnichar i = 0; i < 0x110000; i += 0x100) { bool isEmpty = true; for (OFUnichar j = i; j < i + 0x100; j++) { if (_titlecaseTable[j] != 0) { isEmpty = !memcmp(_uppercaseTable + i, _titlecaseTable + i, 256 * sizeof(OFUnichar)); _titlecaseTableSize = i >> 8; _titlecaseTableUsed[_titlecaseTableSize] = (isEmpty ? 2 : 1); break; } } if (!isEmpty) { void *pool2 = objc_autoreleasePoolPush(); [file writeFormat: @"static const OFUnichar " @"titlecasePage%u[0x100] = {\n", i >> 8]; for (OFUnichar j = i; j < i + 0x100; j += 8) [file writeFormat: @"\t%u, %u, %u, %u, %u, %u, %u, %u,\n", _titlecaseTable[j], _titlecaseTable[j + 1], _titlecaseTable[j + 2], _titlecaseTable[j + 3], _titlecaseTable[j + 4], _titlecaseTable[j + 5], _titlecaseTable[j + 6], _titlecaseTable[j + 7]]; [file writeString: @"};\n\n"]; objc_autoreleasePoolPop(pool2); } } /* Write caseFoldingPage%u if it does NOT match lowercasePage%u */ for (OFUnichar i = 0; i < 0x110000; i += 0x100) { bool isEmpty = true; for (OFUnichar j = i; j < i + 0x100; j++) { if (_caseFoldingTable[j] != 0) { isEmpty = !memcmp(_lowercaseTable + i, _caseFoldingTable + i, 256 * sizeof(OFUnichar)); _caseFoldingTableSize = i >> 8; _caseFoldingTableUsed[_caseFoldingTableSize] = (isEmpty ? 2 : 1); break; } } if (!isEmpty) { void *pool2 = objc_autoreleasePoolPush(); [file writeFormat: @"static const OFUnichar " @"caseFoldingPage%u[0x100] = {\n", i >> 8]; for (OFUnichar j = i; j < i + 0x100; j += 8) [file writeFormat: @"\t%u, %u, %u, %u, %u, %u, %u, %u,\n", _caseFoldingTable[j], _caseFoldingTable[j + 1], _caseFoldingTable[j + 2], _caseFoldingTable[j + 3], _caseFoldingTable[j + 4], _caseFoldingTable[j + 5], _caseFoldingTable[j + 6], _caseFoldingTable[j + 7]]; [file writeString: @"};\n\n"]; objc_autoreleasePoolPop(pool2); } } /* * Those are currently set to the last index. * But from now on, we need the size. */ _uppercaseTableSize++; _lowercaseTableSize++; _titlecaseTableSize++; _caseFoldingTableSize++; /* Write _OFUnicodeUppercaseTable */ [file writeFormat: @"const OFUnichar *const " @"_OFUnicodeUppercaseTable[0x%X] = {\n\t", _uppercaseTableSize]; for (OFUnichar i = 0; i < _uppercaseTableSize; i++) { if (_uppercaseTableUsed[i]) [file writeFormat: @"uppercasePage%u", i]; else [file writeString: @"emptyPage"]; if (i + 1 < _uppercaseTableSize) { if ((i + 1) % 4 == 0) [file writeString: @",\n\t"]; else [file writeString: @", "]; } } [file writeString: @"\n};\n\n"]; /* Write _OFUnicodeLowercaseTable */ [file writeFormat: @"const OFUnichar *const " @"_OFUnicodeLowercaseTable[0x%X] = {\n\t", _lowercaseTableSize]; for (OFUnichar i = 0; i < _lowercaseTableSize; i++) { if (_lowercaseTableUsed[i]) [file writeFormat: @"lowercasePage%u", i]; else [file writeString: @"emptyPage"]; if (i + 1 < _lowercaseTableSize) { if ((i + 1) % 4 == 0) [file writeString: @",\n\t"]; else [file writeString: @", "]; } } [file writeString: @"\n};\n\n"]; /* Write _OFUnicodeTitlecaseTable */ [file writeFormat: @"const OFUnichar *const " @"_OFUnicodeTitlecaseTable[0x%X] = {\n\t", _titlecaseTableSize]; for (OFUnichar i = 0; i < _titlecaseTableSize; i++) { if (_titlecaseTableUsed[i] == 1) [file writeFormat: @"titlecasePage%u", i]; else if (_titlecaseTableUsed[i] == 2) [file writeFormat: @"uppercasePage%u", i]; else [file writeString: @"emptyPage"]; if (i + 1 < _titlecaseTableSize) { if ((i + 1) % 4 == 0) [file writeString: @",\n\t"]; else [file writeString: @", "]; } } [file writeString: @"\n};\n\n"]; /* Write _OFUnicodeCaseFoldingTable */ [file writeFormat: @"const OFUnichar *const " @"_OFUnicodeCaseFoldingTable[0x%X] = {\n\t", _caseFoldingTableSize]; for (OFUnichar i = 0; i < _caseFoldingTableSize; i++) { if (_caseFoldingTableUsed[i] == 1) [file writeFormat: @"caseFoldingPage%u", i]; else if (_caseFoldingTableUsed[i] == 2) [file writeFormat: @"lowercasePage%u", i]; else [file writeString: @"emptyPage"]; if (i + 1 < _caseFoldingTableSize) { if ((i + 1) % 3 == 0) [file writeString: @",\n\t"]; else [file writeString: @", "]; } } [file writeString: @"\n};\n\n"]; objc_autoreleasePoolPop(pool); } - (void)writeHeaderToFile: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFFile *file = [OFFile fileWithPath: path mode: @"w"]; [file writeString: COPYRIGHT @"#import \"OFString.h\"\n\n"]; [file writeFormat: @"#define _OFUnicodeUppercaseTableSize 0x%X\n" @"#define _OFUnicodeLowercaseTableSize 0x%X\n" @"#define _OFUnicodeTitlecaseTableSize 0x%X\n" @"#define _OFUnicodeCaseFoldingTableSize 0x%X\n\n", _uppercaseTableSize, _lowercaseTableSize, _titlecaseTableSize, _caseFoldingTableSize]; [file writeString: @"#ifdef __cplusplus\n" @"extern \"C\" {\n" @"#endif\n" @"extern const OFUnichar *const _Nonnull\n" @" _OFUnicodeUppercaseTable[_OFUnicodeUppercaseTableSize] " @"OF_VISIBILITY_HIDDEN;\n" @"extern const OFUnichar *const _Nonnull\n" @" _OFUnicodeLowercaseTable[_OFUnicodeLowercaseTableSize] " @"OF_VISIBILITY_HIDDEN;\n" @"extern const OFUnichar *const _Nonnull\n" @" _OFUnicodeTitlecaseTable[_OFUnicodeTitlecaseTableSize] " @"OF_VISIBILITY_HIDDEN;\n" @"extern const OFUnichar *const _Nonnull\n" @" _OFUnicodeCaseFoldingTable[_OFUnicodeCaseFoldingTableSize]\n" @" OF_VISIBILITY_HIDDEN;\n" @"#ifdef __cplusplus\n" @"}\n" @"#endif\n"]; objc_autoreleasePoolPop(pool); } @end objfw-1.1.6/generators/unicode/copyright.h000066400000000000000000000035121465614216400206200ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFString.h" #define COPYRIGHT \ @"/*\n" \ @" * Copyright (c) 2008-2024 Jonathan Schleifer \n" \ @" *\n" \ @" * All rights reserved.\n" \ @" *\n" \ @" * This program is free software: you can redistribute it " \ @"and/or modify it\n" \ @" * under the terms of the GNU Lesser General Public License " \ @"version 3.0 only,\n" \ @" * as published by the Free Software Foundation.\n" \ @" *\n" \ @" * This program is distributed in the hope that it will be " \ @"useful, but WITHOUT\n" \ @" * ANY WARRANTY; without even the implied warranty of " \ @"MERCHANTABILITY or\n" \ @" * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General " \ @"Public License\n" \ @" * version 3.0 for more details.\n" \ @" *\n" \ @" * You should have received a copy of the GNU Lesser General " \ @"Public License\n" \ @" * version 3.0 along with this program. If not, see\n" \ @" * .\n" \ @" */\n" \ @"\n" objfw-1.1.6/misc/000077500000000000000000000000001465614216400135725ustar00rootroot00000000000000objfw-1.1.6/misc/keys.asc000066400000000000000000000303371465614216400152430ustar00rootroot00000000000000-----BEGIN PGP PUBLIC KEY BLOCK----- mDMEWtyz7hYJKwYBBAHaRw8BAQdAsw2r74WiB54Nr73sY2sxBLu0RUges2iPeBor 1Wc6Cre0O0pvbmF0aGFuIFNjaGxlaWZlciAoQ29tbWl0IFNpZ25pbmcgS2V5IDIw MTgpIDxqc0BoZWFwLnpvbmU+iJkEExYKAEECGwMHCwoNDAgLBwYVCgkICwMFFgMC AQACHgECF4AWIQTGxY7C74kJHg4TzVjYOna/43Y0XgUCXESzpAUJAWlRNgAKCRDY Ona/43Y0XhA1AP4nIiBUL2nMtkDJSbSb0/kbyIoTNhRXtlI4crYIqfs07gD+NMdH HzMnGtHkpaX7GAqVTeTiThZUnTGNMwnV9aerQQe0OkpvbmF0aGFuIFNjaGxlaWZl ciAoT2JqRlcgU2lnbmluZyBLZXkgMjAxOCkgPGpzQGhlYXAuem9uZT6ImQQTFgoA QQIbAwcLCg0MCAsHBhUKCQgLAwUWAwIBAAIeAQIXgBYhBMbFjsLviQkeDhPNWNg6 dr/jdjReBQJcRLOoBQkBaVE2AAoJENg6dr/jdjReDVoBANvkIYUTLemog3UhjZYh Zdvq9Axd63L2lnpzm+For3tNAP9GmJwbq/oi8E0mAwesbvQYY/R4NOOKIdV7rkVj JzoeCJgzBFxA+ccWCSsGAQQB2kcPAQEHQIe0NK4nnagyINx6Z2DJt4lUzv7a7e6x PLifEvo1iQVptDpKb25hdGhhbiBTY2hsZWlmZXIgKE9iakZXIFNpZ25pbmcgS2V5 IDIwMTkpIDxqc0BoZWFwLnpvbmU+iJkEExYKAEEWIQQtKx7sQXauZ6pvl2B50hGJ otRwjQUCXED55wIbAwUJAeEzgAcLCg0MCAsHBhUKCQgLAwUWAwIBAAIeAQIXgAAK CRB50hGJotRwjeuIAP9wQ8r+13S0ZHPmOkeVQNqpVdvszisfszQKNRrkKrS7fgEA AF4eI4IXb13x5hHvzYn2DMMe2ugx6LoCdzYcVlvFFQ60O0pvbmF0aGFuIFNjaGxl aWZlciAoQ29tbWl0IFNpZ25pbmcgS2V5IDIwMTkpIDxqc0BoZWFwLnpvbmU+iJkE ExYKAEEWIQQtKx7sQXauZ6pvl2B50hGJotRwjQUCXED5xwIbAwUJAeEzgAcLCg0M CAsHBhUKCQgLAwUWAwIBAAIeAQIXgAAKCRB50hGJotRwjXTdAP4oYHIg5+LBhfO+ SNSQl008KH35KmyO4xtZPKfcbWjXcgD/dWVqZDjUYkCs/0oprdJDZPRBIB5QQhjc 1un38+eCiAeYMwReJFsBFgkrBgEEAdpHDwEBB0CjTf7buaAeNxgLpbv9/j4UgcjJ Z97STkAaM7Xac+Dg1rQ3Sm9uYXRoYW4gU2NobGVpZmVyIChPYmpGVyBTaWduaW5n IEtleSAyMDIwKSA8anNAbmlsLmltPoiZBBMWCgBBFiEEMOaUj6yAQrWMtKlu4rzO azXhr4sFAl4kWykCGwMFCQHhM4AHCwoNDAgLBwYVCgkICwMFFgMCAQACHgECF4AA CgkQ4rzOazXhr4tQAgD+P45Nx/YGk2Q/JzBz+cbsdtcha7IehgXulltd3xLjdwsB AMoefVWwHOJa7q10ZRxDN48kDGD+kiqvSdIvKRGuLmMAiQIzBBMBCgAdFiEEbR7C JpvAtUWci6kgz9q0H4KSzu4FAl6KMHcACgkQz9q0H4KSzu7HLBAAo2it0ci2HuJT 1+x1n74dBI5nwKak15OoABW37vxt10gMdm1wo9hq0cJorXdQmE07pMWpMmz883Yg ayqTXyEJJydVqq3rgR1zcEKOGpiJT6azRfGxcvsNh8bMto9dC6cVVmknydyvNTg7 3TpofPmRlH8W8gt8w55EiO3Lk4RJODzGhCOrDxbR1o9rF39fUHj+g3NB7grK/TTt dZvomOS+mcM+pANYivOTmMc5mn0mEVua3F6wRvUck8ij2JFTvJ5GV3xie6JIDa2h l/hM2BLx2XRrwjnD+kig/CjpoFEP8bzc+epHb6ODAt2SQ5i4Zx30TFWiVeeljX1Q zFq5pfJr3nbHQNhkzsu3uWXfqUu1M6mBadzYmLYLDgVFLFKdwhBgbvInr39UAtwE Yl70NoqgVswPzWSkAyrLWs0+2XUXZlyhFxNaOqheWE7VQv/DPYDBPXrim3f5Alv2 PtQJ2BXDvl1PyDg6Ckg6Pe6XoVKPJwMYsiWZOrsnRRJzeQWa1zFsVWX+CYINPiEY v4Ls2OFGZj67tzNU8Wf2EFbNmm/V82sXrPeu0iqcJ99aaxZw+tk+h5WS0BiXceZ9 J6dRKo2qHJJAq0FJnAt+6NRam1KYAknd9y6g5S2bRqiI1wJminmksbSLQ5wmeunl EynylSIJx+UbXBYVbvmpLWZFFRUKBM60OEpvbmF0aGFuIFNjaGxlaWZlciAoQ29t bWl0IFNpZ25pbmcgS2V5IDIwMjApIDxqc0BuaWwuaW0+iJkEExYKAEEWIQQw5pSP rIBCtYy0qW7ivM5rNeGviwUCXiRbAQIbAwUJAeEzgAcLCg0MCAsHBhUKCQgLAwUW AwIBAAIeAQIXgAAKCRDivM5rNeGvi4HuAPsEi38R7E8716m2ua2KvFB3CClSCsVT tZjbIQBEHzQ/iAD/UEZtjaNUW/Mf8vFExbnqFes0dwF0p6PzQ0GLix12JQKJAjME EwEKAB0WIQRtHsImm8C1RZyLqSDP2rQfgpLO7gUCXoowgQAKCRDP2rQfgpLO7jtA D/403WskqoPnw+woWaeCPZcTU1LQ/o5baUUxbQDWTAUNav3hzDxBDQ1yPacZhwBu ea6SNnrEZwc5wd5TPozh9sXday3vqDe6R9/AT+MokxJT3EWptTXmcawRSyDdFNZr V8KJqfDjRNkv9Iqxsjjp9fD5Vw8zVC/KIr0JOq2oxzjU+Wukk94NhSOU2LDRaQLV 8vMpXZRpVJh30+7rq46sTzhZqB5AsTdBykFOsTl9LRmRJXnLjdK/4U7uhoj5ntfR QzPUG3mmbHf5RlGoQIFq2Byop0MiGVWjHI93C5OU7fyjfnARnENOqCgUxs+yXauY J+wngqdJroGEo/5kgbJxpTksuK9zQ3DDtE1p5y48qct0gvw3hYz1UGvpEQ2/Prcy 1q0Nc4hzQ2zrG9jO5971KW2alUT5lrILos17ZJlN5pI8NHhat7T9RX82ziB1fQKG OzbSjxT8gXasy9gbMh8w9zm1prZ1+VRQT8JGLYPHM6mZID20F1q5cRLT41UyTjSe zzStci/zo/dQKFKaTX9KesTSwVS9Zlo7yldUgH+lWyaSjF9VCrjyNI3YbEJ+/Fqt rwxAp8kzFviOd7R5F4zAJBRwgfQNI46v9F3X9KpaTeuuJhm4KvyqPRE/0G0ond8G yJYePoL3jMhfl50163cO69TGXyJmvKwATEa1xRU8n9lE9bg4BF4kWwESCisGAQQB l1UBBQEBB0Cc6UB0PD0kppdYyeJV3uXSuXk7stS6si393JPKFX2wMgMBCAeIfgQY FgoAJhYhBDDmlI+sgEK1jLSpbuK8zms14a+LBQJeJFsBAhsMBQkB4TOAAAoJEOK8 zms14a+L7UoBAJkNXZsY3zHeiSQ23YeaABQUTtpjWb0o6xljq3PXR/hEAP44Rvf3 hTkPPDuMCJelOxzkvr83upYCIyIpP5HpzqFWBpkCDQReih1/ARAAuXxV9zzoO2UY YlXdNlNSxu9iJKH/RySUzIPtCWVxUfsI1NOo2ByhxxGWpATRye61Lm6cAU+tvEXj saKpTi4i9WSy6m6xuLLqQrpDrbVOlazzM1MRQcqGK2wFPtNKV9qz+oOdPXK9a2Rl gI2iwQh6AjCjq8oa3T1MtDF4D3uGBE+Fn9g+gryAf/TZ8gKWyYd8UZwtrlFLC7nq 8gSj2hFiRYTAPGy8GhcdyKvD0cP2xiFlpJmzCn5B+i9a5i3EJDcbfcc0BSyqxkz2 BY8bymw4kTt5e8Bmf4KdzK5OE4w3PFPiMq+Z3LVohQCI2CRh1wGw6lzntU5nqJ0c eD2YV9C8dHwVEN1Vu2M5mXkoe9q4iLWETppxchrQWVAWZWCOeElNxdOrW/uhxpdX RmzTMuCIHolB4VhszS+Wr3Uj98DWa9n/cPZpvRdVdXmy95G9ocp+uBozQEjdmLOm rqPUUbE/WLUO/tRFqp6w6QVfh81G5omLo5VWlxCODK8OjOR4/rfCH28I75bjrm9H pIYtSasVG1/XSV+ilv3PCwadftz8BR5iE0JJtk8NtI1jOvPrIe5d9hJ9109xk/r9 one51VLFFQDsNJexCswjD25xgpqnhZBd0yOtcE9+6hiENLZ0DFrKZSJjNC7xY/ts K9usWwm3CBx2VFi+GpjL04Apo9ooPA0AEQEAAbQeSm9uYXRoYW4gU2NobGVpZmVy IDxqc0BuaWwuaW0+iQJbBBMBCgBFAhsDAh4BAheACAsJCg0MCAsHBhUKCQgLAwUW AwIBAAIZARYhBG0ewiabwLVFnIupIM/atB+Cks7uBQJj6WbtBQkJIbBuAAoJEM/a tB+Cks7u1qUP+gLBceY67YURSNLLCO+L537Xukf2eYlzJzUvBI1nYv8C94dQcmSa sBcAsg2ELfKE6GD1/7VwHQHwclpa3kSX55V6+Ep3VUSR7+2fqz4Ahr10FeOpjS5C Ir51C44mAjeTkkmPIqhOWSoZyg2RxUZOAUZyFqpLDPFGrRTGmuEFnP1tXOAn3TR2 xllK9iAbB9ZcJ+MHEz+rVW5yj3XY8/QW1kcsWIA6qV7eHPP4Y8tEIoefvsU5g188 uHIhxWhB0Xd52VMxd32yiKRgPp9z+6e4PQ+XULv5oGiqR17XKMtMIfAe6kiDYXWT HpqOHnOekVPuqTsjAFttgKeCEzbyit6HIFlqoXjoj23eTFQEi2qiSLCRDm2uGZJI hAL5YeHPaNa82dg6YNCGD8FFSwP+hhXMaQ7zB2jB8smX9A9C+nHCKCFF4ba1RRNq sFRziE2YuY+KX6bQKz6AZ7OxB16YAx75e4J/H/Si8bqm+1EKc6Xpg7uVjYYNH+dr j4qvNsTf4tLr3FAm5tSRCdZkSlilS+565J4PInBVjcLnlRAxh1X1RJGVuFuueVdM 6joGmsPDnwdv8NOvy+4LvBHWkPLm3FVZE9fyDem+0SDooTpvFEuSRfna8agJB5kH zA532hu1dEX/XJMCCJT4RBYy7KOVXqcjrLn/TqRiBZKPK4QbmC/JjdKJiQEiBBAB CAAMBQJj6WgVBQMAEnUAAAoJEJcQuJvKV618c0IIAKLZVwWsgQWBjtjaIsXKUhoo 5HBwNpsNCnWAyUj0ayspkvM+hh5fa70s4Mj4oRdCd44X1iDHQw2bV6PVA+TvqkY2 NV7iL30Vqpyt50qreUz9qCdEittaFIkRNk2qkQB89cKTrrLDu2k80NZdV4sAAJKu XFUOEecZVv5D3gYSKDQJ0lTUzSyS4cC5wdSpeEFRTVXpOQOI32mRM9BxmjtDSBct fnHSWYoE+IoC+OPqDvbbP4TRz3UYjAz5lbLSL5BnlHxZDG2NryH9tUn+/wnJd41m weKZidDO/AUQ9eKKaIsgzCXAjrLjKcgBBANn1yXl+YAr7J8GFdiGkVznYhGjmAW0 IkpvbmF0aGFuIFNjaGxlaWZlciA8anNATmV0QlNELm9yZz6JAlgEEwEKAEICGwMI CwkKDQwICwcGFQoJCAsDBRYDAgEAAh4BAheAFiEEbR7CJpvAtUWci6kgz9q0H4KS zu4FAmPpZvIFCQkhsG4ACgkQz9q0H4KSzu4/nRAAk5+6zavoleNtZ0/l9xs0lwwq sENTfdWqp19YvkiQTWz0gDvRoxKbXHI4HK25th0rBu77ryQYjKrRjXhEZrNq2k6f hTBwJ1sbsDceksaHRlUlVgn112gf6B/iKG3JpLxuFxuMS4ndN9z7H67t2RWDY/+M qSgaNFWXQtfmtC3tfV8e5etZScVO8w+0Wed6MjGjA76crgVWXm2hGCokEk7+0uNd VmFC+cPEBMixgAHqZvM+Gu3pZvHgV50Ybczalx/6KV2W37MsaX6iRUCCpnnoAAxN pWo2Z2LIBVaoO9nuzO8pgF8dRdxwq3Px/RpseHtEUY4v1/aylB4z1joI7sWPqXOR 3QlRmCd2O36kCiLIvm9OQ5tmjmW9T+t/gcCzq5pHDNIx8D50urqnUH+WU/WaT5fp uM6VifBpSZslTuRavc6kxa7kuGCrsBtVOzlMCxSVAqSgMMm4vVxJm20pYIItHHTZ TXEehnLEst/EdEAmLmHO2Qch/qUh2i0w5+4pwjY1pIOVP8Si3xbxtoN6PIM/UBEP fBQGB4NzljQwISdUUSGiWn7pcun350IsCjnC2c+tJQ/lHjhrJjZ+aMAi7OSV6g9P pjFrz+z9UmTP0QUeBSNGBqAWgvC4okGgFr4cf9H01FbZPNkWIfZYPZ1Nv3apxNOx lpzSHcURnFhXPJDlqNC0IkpvbmF0aGFuIFNjaGxlaWZlciA8anNAcGtnc3JjLm9y Zz6JAlgEEwEKAEICGwMICwkKDQwICwcGFQoJCAsDBRYDAgEAAh4BAheAFiEEbR7C JpvAtUWci6kgz9q0H4KSzu4FAmPpZvcFCQkhsG4ACgkQz9q0H4KSzu4TrxAAnWBr gJnU96KbYRS7KkpUzeLeaLrHK5LIhaJ7rVxVrOo+x5Ey2NjGJKoTxC9UAfITCfO9 9vsycp3Gb9fJnowieuQ1y1MFCrYLPPLOfNxh4Jc9GZK64DlexrsXvDhx84wgN+el rnjuatm9LUJWe5czWKiAnoki/u+SGFVxwOUtND205I4go/8FtY8rZ1P3VEGiXeZq hjNOodDoGEGZJwQIycN5YCrweYPwM+p80ZbzkWGB+Ov3lOO+omMf7NQ3LFtueV0J Nq7SjmNESYLm1Gg2NFHZp4D12sSUfHTvNVJBr1qCJggQs2mefRB/aKcS4i9Ajmfk i7TkEwutDMX6rOCZRppYpS8N6aYoiAOZHQmffk8bdi0RBGVSxR+04IwpYObUbDIZ US2exkiaDB0tFeguIlgHU/V+3GWEUDF4AhQLbSYkEwUc65FstULrDCRfegFoUBsY 9D+qPYnsNOlTRlalR8hZaQlwZLAuZx0kn+YGxs+9z2UhgMExRtCM/3FRpDuiFJGs QML2DUArYZeh7JyJy0m9PIt59wg5wnHUyCLop8g1gn6Wh22/R/Le6CEusJsO2qiM oE6PSB89g3nhsvUadRpYOP9eZS0aoRgNPLp+qigthgEV9fvSADHtAvsaLYpQ+wjr O+Ih57Y2MrU8mPehwqGz17Ur58VcI65qXTkZpni5Ag0EXoodfwEQAPc4JUVqZGxS KtipZKGewKuNyqASMq8gNwL7ToSni5cTuQLa9YU+5Zo/BX3OEJkXp+MNN3Y1wFxV cPBZsYpBAx3apWhi0Fki+zdPjTmRE7QcFE+UE17OnnFReb93G2ErSiY+BzsfbW/3 dMjLfLhrVjJktLA9pGMoR483jI6rIVEBa6TikoMo8b790Ulo0xicl6ehFhQVUGN4 CfovBjCZ9CIX6dmRGaB/FMyOXgXWsx5+UilTgJhRHbJnggw6U1H8lk/WhJzCyLyY Tg+YkHx3WwAF37pR6g1XACMQEdumCLxW21ELC5D4aX0QejM8oIDf/xw5mHcgB0xg 07FmRbyiZheg+CSPgwHWW/K6urw/G04SbYxnk1/kPA66x6Fss3BxTuJOYmEZqklV Np2KfJdEiBECftRRWIbZu2zFOMGK1olPIOgsKdJvaATkgeYSxjCu9+o4vY1yGXtz BEwBfIUkU2B33QzWLq+I61WeVbqRC6k0SYBKiQK/uQJSVYuEtNJ8pttYxdYkyY+r s0yCZHlTlJcYKhAdMi1Gbh2L6WbzsHIHfmdraWqcv7EEuVacjrgerdk3ezOQspC5 Gfa6pLEmOoF/ctwg/uoGCyhnWBmHiuLdN7F4+z6BHBoqHU1i3z2oUJ3tHDoVnEmh jYNOgIs7UgKxXiuczMJT4gpNM35ym32hABEBAAGJAjwEGAEKACYCGwwWIQRtHsIm m8C1RZyLqSDP2rQfgpLO7gUCY+lnIwUJCSGwpAAKCRDP2rQfgpLO7oIlD/4oLDMH qTzdDIXjM9x5U4ENBeGwUKHEkKeRduXuj0pZTnWTHmdXD3RPbG1EfGJU3PVBudZU iEREibNaEYM5VFuDwMw51qw7Ox8j4r+RtP+8AI0zpRdababPP1/A4ap+xwReTWVM /CFF3VekqeElgxSjM6luFPNDdwyBNavOLtbrWhmyclw3DLB03ZtS0sPvu0hXTnp4 nbuWdsPOxGIomb9UF0IplMPm5ChjkZaypKY75P1k5Il+AZFWEi5YB6y8yl1gmOxY 3pnKCJWcoGsaEoxREqHH/tZAeI299u8aE8Gjl+ZxGunuPDMUd8OSlE8MI3osnWU4 7rbVueWqJ4CG3OcYJP8Vj1Ygy68R5xBL5ku3ddv5oI2ZIDkqTBFKJQnhWMUX6Trz e7US0jSdVFv4fYf3aHDJ0afc9RsKebPgbfN3FWak03zInVqdXRrraa410qz8fKBI 1CKalErJN7/dpXu3vfJJ2TgYcgAN9N0lY+YFQ834qpDk6KOTYzvIMJASVIJ1gjvl iE94hE6FYuHU9DlwYL3/qbOOb6lLIFHxaeQ95ZZR+raPyi1FGVGXV8oZI5f2Uzxo LYyioTRjgC0cr9aIK56ZQ5I/npwuEYSL/8oIWdRrYGQT0FFQQAnhhkd61DuPt3GA fhsY1fGkPo/YC3yulOJt98FIMg/lRlYfOrxIbLkCDQReiiM/ARAAwIzaby43las5 ApAWVw4MxCIpdY9S0tKUBgF4koKKkgUQ20KzI395LctZ6TwRSaBp9df/Wi9JtXe3 bkt46ASjq8CCMggVptq80KyhnVMYDJD8mH+gFjUdlxTgILg1tnYwt01oBIMh8T1c EUQ2kcWkDbIRnrrSkVxh+ntu8aqZaF9E9iScPbNO8V5qIGCTfeFti1IUfClQ10Cs dANPxVngzttHs7eg+ddwZdiwxb7vxKy1/juqWTNFcHYd4XQ8MIuedXliHpvI5quf MbFvOmX6xxxoXTL/efGoA/zCM6/BcM2ul1o/prJTauRuVKawE3mcMpTrubN+usf6 QEUohxsxCvxVqGcJVAU5286Hv0Kc2jzqcWqEfiyjCJI0vwCzFk3sRbuawlDuC535 paR23QC/ClSCghMzfRRnN4OpJQjzgc6yOZ3ydqmF5UeqGrgZhrW+O92jBb1XqGFV zTOYHvLNJCQ0Cj53fiYpju4Pdf2BWvDo1oSoKbrvSd3DUyXlgN2Ar6t3X2uz7HhL 2496v3BoIOqzzcdvpCaDZjDdrw8SHpp45u9qrzMPKEIdqy4u5KjsKjuCZKczy4pc u44+JjDzNJRik0Ppf2AUJLBCnik6prZIttbCfGsvid7SR5sZZgjbGk/fuQCF/tQt aksvsIqb598/sTzNVBGkp6qWttTkPs8AEQEAAYkCPAQYAQoAJgIbIBYhBG0ewiab wLVFnIupIM/atB+Cks7uBQJj6WcnBQkJIarkAAoJEM/atB+Cks7uei8QAIa+BrMi fmLTSLe09CnGvacepKNao6UqSHwbmf6Tonv9rOU2EquKyCW/0YK53WGO6fnPE7FV 8JYDWxecBvtLjj+hloEHJ/wliYwd4W3FOuGnb/E9mzQgyKdWcSBIxreZLdD7xZ5B iv3VLeKyx+xnJ99dC2+MBuL6CBk+gmzwri7/hkYG9GQW9TJEe7qi8D87iTN1YkXl cJXdDcqapEZxv8+nAa5E4gTmLlXnKYNidC6+9gtnGpCRZtSpLwX0pMVY27w9sthU Acnx5N3AwS7rCodqnU3ANa5a00wbWOmZ90qbofRX9RC3qkfoisr62bRELY7KFt7M VTV0YBTCPHFeP+bubyOOyUe1OJsCvWJfIhJm87qjS37WXxYDUU+KHGN4MX9LDvTS xy+h30Ba0XFfU1fgNtIvVR+MrrIGACq5VU2uSyBQLmIkgcusUComEx77mETE92Mw ROJfy1O5VGsNDr61xIu72MjKAlukwgwX/qQ7i8Flyf8N++J7fETf/4DHXxNS9imV JTVxHfvIWpclRfdUCZB6R1Ihv+n1T+yx/FroTxQ5wuilV7+0r2DhrW6Q0YISoWv5 L1sfohVZCXF7EQgteax0/86WSboerrWQmfGk0k4SjKhBJK1O8Jhh2tk8OmlUz6Fs 7MhFJ5NGASlFL7p0W5iB3qWYwn52sEBaI8VpmDMEYBW6BBYJKwYBBAHaRw8BAQdA WWTgOvzlX/x5OiYhMLK72aKOMvr0g6KIaynmN2YMp5O0M0pvbmF0aGFuIFNjaGxl aWZlciAoQ29tbWl0IFNpZ25pbmcgS2V5KSA8anNAbmlsLmltPoiaBBMWCgBCAhsD CAsJCg0MCAsHBhUKCQgLAwUWAwIBAAIeAQIXgBYhBAzGrFQcetxzPGQWEGNnA1dz lTEvBQJj6WYYBQkFtN+UAAoJEGNnA1dzlTEvXKQBAPQ4mbtEmbuMbfpeV3pMP8bO 1OhOB4/Thx4tUrrV7JcjAQCveLdvBrB+cSh+DA7edl6/XWfafCT0qrzRFhaoEZhx Dbg4BGAVugQSCisGAQQBl1UBBQEBB0A2sxWorhv9BEE+urAmX5GBUfcCdta9Un6E t5wEG5jLVAMBCAeIfgQYFgoAJgIbDBYhBAzGrFQcetxzPGQWEGNnA1dzlTEvBQJj 6WYtBQkFtN+pAAoJEGNnA1dzlTEvi+8BANiiPjamWJ3iSeMEaaYPoZXNZ7NAHlK0 UUgQvB/osfQWAP9NKXMO7P5R/K+D2nRE/Ndmk0lqBykzumouPVuR21pYB5gzBGWW /sEWCSsGAQQB2kcPAQEHQAujl3ehBqKz3PFMW+rl8/d/1KS7Skx00xYU6xsLout+ tDhKb25hdGhhbiBTY2hsZWlmZXIgKENvbW1pdCBTaWduaW5nIEtleSAyMDI0KSA8 anNAbmlsLmltPoiaBBMWCgBCFiEEYy4qTb/j80NaLyG/lClu8uyb5oMFAmWW/sEC GwMFCQHhM4AICwkKDQwICwcGFQoJCAsDBRYDAgEAAh4FAheAAAoJEJQpbvLsm+aD g10BAP5MpkFbauicEGNTUJnmfbWZsGmmOTov7nG3ylVPp6UpAP4jIbm0Nz5L0+1B vA35PeZfJ8z2dIcuKPKkCgxbv55NAIkCNwQTAQoAIRYhBG0ewiabwLVFnIupIM/a tB+Cks7uBQJllwC0AwUBeAAKCRDP2rQfgpLO7sktEACdIKHR7vTHKgokw/6j2zwd Na3sBt0jC7tsqA7xbfobwMR3yoVnD49T4zHlW5MwKaQBsTkwI9pS4qbaPsX7VoXV 5I8UpWPbXeDnofO9B+sO55ybVrGf1Fb2PmykZ85dgEe168hL0c5UX+9zCXjfFTHa GAxRmTrYKP0h+jYZJns1QK3KZEWh0pkqJz5oOLELqeZS2GMGn1PQjmbzz72/korZ sUswS5sDBbMVeusCWuNeY6FJZ6ziv97geu+uWe7ppwv25rebEKJgsuaIqDuAT2Gg 3NgrubfXFVLlDxjuYdaO+ieBQur5z8UPaSzEYlF2p7/cut24A8WV/d3D5dX3XO/g AuEMkyAws9zOeY3NMMfkHEZsuX0AetH7cOQYyAUIlpye30OxeoZgO4Cl3G5q95sk Q4i/LpzNERq+JydmniPMbM/TL8p87RYr/bidO+0KeHwRzsesVu2ae1xO/ZRSyqny un5RZblS9QY1H3xUgKQWpMLxJGXr6n+9eRThRsrTK/JH6GFpkFnjmMpuxquAw32w PdxGWDUUE35pC4f0X/6rL8IBf32spXG+mKbBLTJkSkteSM26Uff4zVFludQU+N06 c6XFX7eBpbhhHhsCabOskGFXXS0bdi6NcZgazm1I4rhqrT+pQFHDOZg/dgl5cND/ Q4zqQ9Xrv/iV6ljHHAPYGrg4BGWW/sESCisGAQQBl1UBBQEBB0CTeGWS64rbAwJz Sioh6y0Urd5/pGIj5UEdyAFrjhiKDgMBCAeIfgQYFgoAJhYhBGMuKk2/4/NDWi8h v5QpbvLsm+aDBQJllv7BAhsMBQkB4TOAAAoJEJQpbvLsm+aDv0sBAIFCR1MA+d7V ll+AxWH/k2ghgfJ661e88iaoG7qUyve5APsFQbV5thutm99chCp8Sc+fulHNtrKJ WBymwZqetu7HBg== =mVJw -----END PGP PUBLIC KEY BLOCK----- objfw-1.1.6/src/000077500000000000000000000000001465614216400134265ustar00rootroot00000000000000objfw-1.1.6/src/Info.plist.in000066400000000000000000000012331465614216400160020ustar00rootroot00000000000000 CFBundleExecutable ObjFW CFBundleName ObjFW CFBundleIdentifier im.nil.objfw CFBundleInfoDictionaryVersion 6.0 CFBundlePackageType FMWK CFBundleVersion @BUNDLE_VERSION@ CFBundleShortVersionString @BUNDLE_SHORT_VERSION@ MinimumOSVersion 9.0 objfw-1.1.6/src/Makefile000066400000000000000000000173121465614216400150720ustar00rootroot00000000000000include ../extra.mk SUBDIRS = ${RUNTIME} exceptions encodings forwarding SUBDIRS_AFTER = ${BRIDGE} ${TLS} test DISTCLEAN = Info.plist objfw-defs.h SHARED_LIB = ${OBJFW_SHARED_LIB} STATIC_LIB = ${OBJFW_STATIC_LIB} FRAMEWORK = ${OBJFW_FRAMEWORK} LIB_MAJOR = ${OBJFW_LIB_MAJOR} LIB_MINOR = ${OBJFW_LIB_MINOR} LIB_PATCH = ${OBJFW_LIB_PATCH} SRCS = OFApplication.m \ OFArray.m \ OFBlock.m \ OFCharacterSet.m \ OFColor.m \ OFConstantString.m \ OFCountedSet.m \ OFData.m \ OFData+CryptographicHashing.m \ OFData+MessagePackParsing.m \ OFDate.m \ OFDictionary.m \ OFEnumerator.m \ OFFileManager.m \ OFGZIPStream.m \ OFHMAC.m \ OFINICategory.m \ OFINIFile.m \ OFIRI.m \ OFIRIHandler.m \ OFInflate64Stream.m \ OFInflateStream.m \ OFInvocation.m \ OFLHAArchive.m \ OFLHAArchiveEntry.m \ OFList.m \ OFLocale.m \ OFMD5Hash.m \ OFMapTable.m \ OFMatrix4x4.m \ OFMemoryStream.m \ OFMessagePackExtension.m \ OFMethodSignature.m \ OFMutableArray.m \ OFMutableData.m \ OFMutableDictionary.m \ OFMutableIRI.m \ OFMutableLHAArchiveEntry.m \ OFMutablePair.m \ OFMutableSet.m \ OFMutableString.m \ OFMutableTarArchiveEntry.m \ OFMutableTriple.m \ OFMutableZIPArchiveEntry.m \ OFMutableZooArchiveEntry.m \ OFNotification.m \ OFNotificationCenter.m \ OFNull.m \ OFNumber.m \ OFObject.m \ OFObject+KeyValueCoding.m \ OFOnce.m \ OFOptionsParser.m \ OFPBKDF2.m \ OFPair.m \ OFRIPEMD160Hash.m \ OFRunLoop.m \ OFSHA1Hash.m \ OFSHA224Hash.m \ OFSHA224Or256Hash.m \ OFSHA256Hash.m \ OFSHA384Hash.m \ OFSHA384Or512Hash.m \ OFSHA512Hash.m \ OFScrypt.m \ OFSecureData.m \ OFSeekableStream.m \ OFSet.m \ OFSettings.m \ OFSortedList.m \ OFStdIOStream.m \ OFStream.m \ OFString.m \ OFString+CryptographicHashing.m \ OFString+JSONParsing.m \ OFString+PercentEncoding.m \ OFString+PropertyListParsing.m \ OFString+XMLEscaping.m \ OFString+XMLUnescaping.m \ OFSystemInfo.m \ OFTarArchive.m \ OFTarArchiveEntry.m \ OFThread.m \ OFTimer.m \ OFTriple.m \ OFUUID.m \ OFValue.m \ OFXMLAttribute.m \ OFXMLCDATA.m \ OFXMLCharacters.m \ OFXMLComment.m \ OFXMLElement.m \ OFXMLElementBuilder.m \ OFXMLNode.m \ OFXMLParser.m \ OFXMLProcessingInstruction.m \ OFZIPArchive.m \ OFZIPArchiveEntry.m \ OFZooArchive.m \ OFZooArchiveEntry.m \ ${USE_SRCS_FILES} \ ${USE_SRCS_PLUGINS} \ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_SUBPROCESSES} \ ${USE_SRCS_THREADS} \ ${USE_SRCS_WINDOWS} SRCS_FILES = OFFile.m \ OFString+PathAdditions.m SRCS_PLUGINS = OFPlugin.m SRCS_SOCKETS = OFAAAADNSResourceRecord.m \ OFADNSResourceRecord.m \ OFCNAMEDNSResourceRecord.m \ OFDNSQuery.m \ OFDNSResolver.m \ OFDNSResourceRecord.m \ OFDNSResponse.m \ OFDatagramSocket.m \ OFHINFODNSResourceRecord.m \ OFHTTPClient.m \ OFHTTPCookie.m \ OFHTTPCookieManager.m \ OFHTTPRequest.m \ OFHTTPResponse.m \ OFHTTPServer.m \ OFLOCDNSResourceRecord.m \ OFMXDNSResourceRecord.m \ OFNSDNSResourceRecord.m \ OFPTRDNSResourceRecord.m \ OFRPDNSResourceRecord.m \ OFSOADNSResourceRecord.m \ OFSRVDNSResourceRecord.m \ OFSequencedPacketSocket.m \ OFSocket.m \ OFStreamSocket.m \ OFSystemInfo+NetworkInterfaces.m \ OFTCPSocket.m \ OFTLSStream.m \ OFTXTDNSResourceRecord.m \ OFUDPSocket.m \ OFURIDNSResourceRecord.m \ ${USE_SRCS_APPLETALK} \ ${USE_SRCS_IPX} \ ${USE_SRCS_UNIX_SOCKETS} SRCS_APPLETALK = OFDDPSocket.m SRCS_IPX = OFIPXSocket.m \ OFSPXSocket.m \ OFSPXStreamSocket.m SRCS_UNIX_SOCKETS = OFUNIXDatagramSocket.m \ OFUNIXStreamSocket.m SRCS_SUBPROCESSES = OFSubprocess.m SRCS_THREADS = OFCondition.m \ OFMutex.m \ OFPlainCondition.m \ OFPlainMutex.m \ OFPlainThread.m \ OFRecursiveMutex.m \ OFTLSKey.m SRCS_WINDOWS = OFWindowsRegistryKey.m INCLUDES_ATOMIC = OFAtomic.h \ platform/GCC4/OFAtomic.h \ platform/GCC4.7/OFAtomic.h \ platform/PowerPC/OFAtomic.h \ platform/macOS/OFAtomic.h \ platform/x86/OFAtomic.h INCLUDES := ${SRCS:.m=.h} \ OFArchiveEntry.h \ OFCollection.h \ OFCryptographicHash.h \ OFJSONRepresentation.h \ OFKernelEventObserver.h \ OFKeyValueCoding.h \ OFLocking.h \ OFMessagePackRepresentation.h \ OFMutableArchiveEntry.h \ ObjFW.h \ macros.h \ objfw-defs.h \ platform.h \ ${USE_INCLUDES_ATOMIC} SRCS += OFASPrintF.m \ OFArchiveIRIHandler.m \ OFBase64.m \ OFBitSetCharacterSet.m \ OFCRC16.m \ OFCRC32.m \ OFConcreteArray.m \ OFConcreteColor.m \ OFConcreteCountedSet.m \ OFConcreteData.m \ OFConcreteDate.m \ OFConcreteDictionary.m \ OFConcreteMutableArray.m \ OFConcreteMutableData.m \ OFConcreteMutableDictionary.m \ OFConcreteMutableSet.m \ OFConcreteNumber.m \ OFConcreteSet.m \ OFConcreteSubarray.m \ OFConcreteValue.m \ OFEmbeddedIRIHandler.m \ OFHuffmanTree.m \ OFINIFileSettings.m \ OFInvertedCharacterSet.m \ OFLHADecompressingStream.m \ OFMutableUTF8String.m \ OFRangeCharacterSet.m \ OFSandbox.m \ OFStrFTime.m \ OFStrPTime.m \ OFSubarray.m \ OFSubdata.m \ OFUTF8String.m \ ${LIBBASES_M} \ ${RUNTIME_ASSOCIATION_M} \ ${RUNTIME_AUTORELEASE_M} \ ${RUNTIME_INSTANCE_M} \ ${UNICODE_M} \ ${USE_SRCS_TAGGED_POINTERS} SRCS_FILES += OFFileIRIHandler.m SRCS_SOCKETS += OFAsyncIPSocketConnector.m \ OFDNSResolverSettings.m \ ${OF_EPOLL_KERNEL_EVENT_OBSERVER_M} \ OFHTTPIRIHandler.m \ OFHostAddressResolver.m \ OFKernelEventObserver.m \ ${OF_KQUEUE_KERNEL_EVENT_OBSERVER_M} \ ${OF_POLL_KERNEL_EVENT_OBSERVER_M} \ ${OF_SELECT_KERNEL_EVENT_OBSERVER_M} \ OFTCPSocketSOCKS5Connector.m SRCS_TAGGED_POINTERS = OFTaggedPointerColor.m \ OFTaggedPointerDate.m \ OFTaggedPointerNumber.m SRCS_WINDOWS += platform/Windows/OFWin32ConsoleStdIOStream.m \ versioninfo.rc OBJS_EXTRA = exceptions/exceptions.a \ encodings/encodings.a \ forwarding/forwarding.a LIB_OBJS_EXTRA = exceptions/exceptions.lib.a \ encodings/encodings.lib.a \ forwarding/forwarding.lib.a include ../buildsys.mk CPPFLAGS += -I. -I.. -Iexceptions -Iruntime LD = ${OBJC} FRAMEWORK_LIBS := -Fruntime \ ${RUNTIME_FRAMEWORK_LIBS} \ ${REEXPORT_RUNTIME_FRAMEWORK} \ ${LIBS} LIBS := -Lruntime ${RUNTIME_LIBS} ${REEXPORT_RUNTIME} ${LIBS} RCFLAGS = --use-temp-file \ -DOBJFW_LIB_MAJOR=${OBJFW_LIB_MAJOR} \ -DOBJFW_LIB_MINOR=${OBJFW_LIB_MINOR} \ -DOBJFW_LIB_VERSION=\"${OBJFW_LIB_MAJOR}.${OBJFW_LIB_MINOR}\" \ -DOBJFW_SHARED_LIB=\"${OBJFW_SHARED_LIB}\" uninstall-extra: for i in platform/GCC4 platform/GCC4.7 platform/PowerPC platform/macOS \ platform/x86 platform ""; do \ if test -d ${DESTDIR}${includedir}/${includesubdir}/$$i; then \ rmdir ${DESTDIR}${includedir}/${includesubdir}/$$i; \ fi; \ done objfw-1.1.6/src/OFAAAADNSResourceRecord.h000066400000000000000000000035221465614216400177250ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFDNSResourceRecord.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFAAAADNSResourceRecord \ * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h * * @brief A class representing a DNS resource record. */ OF_SUBCLASSING_RESTRICTED @interface OFAAAADNSResourceRecord: OFDNSResourceRecord { OFSocketAddress _address; } /** * @brief The IPv6 address of the resource record. */ @property (readonly, nonatomic) const OFSocketAddress *address; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFAAAADNSResourceRecord with the * specified name, class, address and time to live. * * @param name The name for the resource record * @param address The address for the resource record * @param TTL The time to live for the resource record * @return An initialized OFAAAADNSResourceRecord */ - (instancetype)initWithName: (OFString *)name address: (const OFSocketAddress *)address TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFAAAADNSResourceRecord.m000066400000000000000000000045741465614216400177420ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFAAAADNSResourceRecord.h" @implementation OFAAAADNSResourceRecord - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name address: (const OFSocketAddress *)address TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: OFDNSClassIN recordType: OFDNSRecordTypeAAAA TTL: TTL]; _address = *address; return self; } - (const OFSocketAddress *)address { return &_address; } - (bool)isEqual: (id)object { OFAAAADNSResourceRecord *record; if (object == self) return true; if (![object isKindOfClass: [OFAAAADNSResourceRecord class]]) return false; record = object; if (record->_name != _name && ![record->_name isEqual: _name]) return false; if (record->_DNSClass != _DNSClass) return false; if (record->_recordType != _recordType) return false; if (!OFSocketAddressEqual(&record->_address, &_address)) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddByte(&hash, _DNSClass >> 8); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType >> 8); OFHashAddByte(&hash, _recordType); OFHashAddHash(&hash, OFSocketAddressHash(&_address)); OFHashFinalize(&hash); return hash; } - (OFString *)description { return [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tAddress = %@\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFSocketAddressString(&_address), _TTL]; } @end objfw-1.1.6/src/OFADNSResourceRecord.h000066400000000000000000000035021465614216400174200ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFDNSResourceRecord.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFADNSResourceRecord OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h * * @brief A class representing an A DNS resource record. */ OF_SUBCLASSING_RESTRICTED @interface OFADNSResourceRecord: OFDNSResourceRecord { OFSocketAddress _address; } /** * @brief The IPv4 address of the resource record. */ @property (readonly, nonatomic) const OFSocketAddress *address; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFADNSResourceRecord with the * specified name, class, address and time to live. * * @param name The name for the resource record * @param address The address for the resource record * @param TTL The time to live for the resource record * @return An initialized OFADNSResourceRecord */ - (instancetype)initWithName: (OFString *)name address: (const OFSocketAddress *)address TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFADNSResourceRecord.m000066400000000000000000000045551465614216400174360ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFADNSResourceRecord.h" @implementation OFADNSResourceRecord - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name address: (const OFSocketAddress *)address TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: OFDNSClassIN recordType: OFDNSRecordTypeA TTL: TTL]; _address = *address; return self; } - (const OFSocketAddress *)address { return &_address; } - (bool)isEqual: (id)object { OFADNSResourceRecord *record; if (object == self) return true; if (![object isKindOfClass: [OFADNSResourceRecord class]]) return false; record = object; if (record->_name != _name && ![record->_name isEqual: _name]) return false; if (record->_DNSClass != _DNSClass) return false; if (record->_recordType != _recordType) return false; if (!OFSocketAddressEqual(&record->_address, &_address)) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddByte(&hash, _DNSClass >> 8); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType >> 8); OFHashAddByte(&hash, _recordType); OFHashAddHash(&hash, OFSocketAddressHash(&_address)); OFHashFinalize(&hash); return hash; } - (OFString *)description { return [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tAddress = %@\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFSocketAddressString(&_address), _TTL]; } @end objfw-1.1.6/src/OFASPrintF.h000066400000000000000000000021601465614216400154510ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif #include #import "macros.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif extern int _OFVASPrintF( char *_Nullable *_Nonnull, const char *_Nonnull, va_list) OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFASPrintF.m000066400000000000000000000413431465614216400154640ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #include #include #include #ifdef HAVE_WCHAR_H # include #endif #if defined(HAVE_ASPRINTF_L) || defined(HAVE_USELOCALE) # include #endif #ifdef HAVE_XLOCALE_H # include #endif #ifdef OF_HAVE_SYS_TYPES_H # include #endif #import "OFASPrintF.h" #import "OFString.h" #import "OFLocale.h" #import "OFInitializationFailedException.h" #define maxSubformatLen 64 #ifndef HAVE_ASPRINTF /* * (v)asprintf might be declared, but HAVE_ASPRINTF not defined because * configure determined it is broken. In this case, we must make sure there is * no name clash. */ # define asprintf asprintf_ # define vasprintf vasprintf_ #endif struct Context { const char *format; size_t formatLen; char subformat[maxSubformatLen + 1]; size_t subformatLen; va_list arguments; char *buffer; size_t bufferLen; size_t i, last; enum { stateString, stateFormatFlags, stateFormatFieldWidth, stateFormatLengthModifier, stateFormatConversionSpecifier } state; enum { lengthModifierNone, lengthModifierHH, lengthModifierH, lengthModifierL, lengthModifierLL, lengthModifierJ, lengthModifierZ, lengthModifierT, lengthModifierCapitalL } lengthModifier; bool useLocale; }; #if defined(HAVE_ASPRINTF_L) || defined(HAVE_USELOCALE) static locale_t cLocale; OF_CONSTRUCTOR() { if ((cLocale = newlocale(LC_ALL_MASK, "C", NULL)) == NULL) @throw [OFInitializationFailedException exception]; } #endif #ifndef HAVE_ASPRINTF static int vasprintf(char **string, const char *format, va_list arguments) { int length; size_t bufferLength = 128; *string = NULL; for (;;) { free(*string); if ((*string = malloc(bufferLength)) == NULL) return -1; length = vsnprintf(*string, bufferLength - 1, format, arguments); if (length >= 0 && (size_t)length < bufferLength - 1) break; if (bufferLength > INT_MAX / 2) { free(*string); return -1; } bufferLength <<= 1; } if (length > 0 && (size_t)length != bufferLength - 1) { char *resized = realloc(*string, length + 1); /* Ignore if making it smaller failed. */ if (resized != NULL) *string = resized; } return length; } static int asprintf(char **string, const char *format, ...) { int ret; va_list arguments; va_start(arguments, format); ret = vasprintf(string, format, arguments); va_end(arguments); return ret; } #endif static bool appendString(struct Context *ctx, const char *append, size_t appendLen) { char *newBuf; if (appendLen == 0) return true; if ((newBuf = realloc(ctx->buffer, ctx->bufferLen + appendLen + 1)) == NULL) return false; memcpy(newBuf + ctx->bufferLen, append, appendLen); ctx->buffer = newBuf; ctx->bufferLen += appendLen; return true; } static bool appendSubformat(struct Context *ctx, const char *subformat, size_t subformatLen) { if (ctx->subformatLen + subformatLen > maxSubformatLen) return false; memcpy(ctx->subformat + ctx->subformatLen, subformat, subformatLen); ctx->subformatLen += subformatLen; ctx->subformat[ctx->subformatLen] = 0; return true; } static bool stringState(struct Context *ctx) { if (ctx->format[ctx->i] == '%') { if (ctx->i > 0) if (!appendString(ctx, ctx->format + ctx->last, ctx->i - ctx->last)) return false; if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; ctx->last = ctx->i + 1; ctx->state = stateFormatFlags; } return true; } static bool formatFlagsState(struct Context *ctx) { switch (ctx->format[ctx->i]) { case '-': case '+': case ' ': case '#': case '0': if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; break; case ',': /* ObjFW extension: Use decimal point from locale */ ctx->useLocale = true; break; default: ctx->state = stateFormatFieldWidth; ctx->i--; break; } return true; } static bool formatFieldWidthState(struct Context *ctx) { if ((ctx->format[ctx->i] >= '0' && ctx->format[ctx->i] <= '9') || ctx->format[ctx->i] == '*' || ctx->format[ctx->i] == '.') { if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; } else { ctx->state = stateFormatLengthModifier; ctx->i--; } return true; } static bool formatLengthModifierState(struct Context *ctx) { /* Only one allowed */ switch (ctx->format[ctx->i]) { case 'h': /* and also hh */ if (ctx->formatLen > ctx->i + 1 && ctx->format[ctx->i + 1] == 'h') { if (!appendSubformat(ctx, ctx->format + ctx->i, 2)) return false; ctx->i++; ctx->lengthModifier = lengthModifierHH; } else { if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; ctx->lengthModifier = lengthModifierH; } break; case 'l': /* and also ll */ if (ctx->formatLen > ctx->i + 1 && ctx->format[ctx->i + 1] == 'l') { #ifndef OF_WINDOWS if (!appendSubformat(ctx, ctx->format + ctx->i, 2)) return false; #else if (!appendSubformat(ctx, "I64", 3)) return false; #endif ctx->i++; ctx->lengthModifier = lengthModifierLL; } else { if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; ctx->lengthModifier = lengthModifierL; } break; case 'j': #if defined(OF_WINDOWS) if (!appendSubformat(ctx, "I64", 3)) return false; #elif defined(_NEWLIB_VERSION) || defined(OF_HPUX) if (!appendSubformat(ctx, "ll", 2)) return false; #else if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; #endif ctx->lengthModifier = lengthModifierJ; break; case 'z': #if defined(OF_WINDOWS) if (sizeof(size_t) == 8) if (!appendSubformat(ctx, "I64", 3)) return false; #elif defined(_NEWLIB_VERSION) || defined(OF_HPUX) if (!appendSubformat(ctx, "l", 1)) return false; #else if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; #endif ctx->lengthModifier = lengthModifierZ; break; case 't': #if defined(OF_WINDOWS) if (sizeof(ptrdiff_t) == 8) if (!appendSubformat(ctx, "I64", 3)) return false; #elif defined(_NEWLIB_VERSION) || defined(OF_HPUX) if (!appendSubformat(ctx, "l", 1)) return false; #else if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; #endif ctx->lengthModifier = lengthModifierT; break; case 'L': if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; ctx->lengthModifier = lengthModifierCapitalL; break; #ifdef OF_WINDOWS case 'I': /* win32 strangeness (I64 instead of ll or j) */ if (ctx->formatLen > ctx->i + 2 && ctx->format[ctx->i + 1] == '6' && ctx->format[ctx->i + 2] == '4') { if (!appendSubformat(ctx, ctx->format + ctx->i, 3)) return false; ctx->i += 2; ctx->lengthModifier = lengthModifierLL; } else ctx->i--; break; #endif #ifdef OF_IOS case 'q': /* iOS uses this for PRI?64 */ if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; ctx->lengthModifier = lengthModifierLL; break; #endif default: ctx->i--; break; } ctx->state = stateFormatConversionSpecifier; return true; } static bool formatConversionSpecifierState(struct Context *ctx) { char *tmp = NULL; int tmpLen = 0; #if !defined(HAVE_ASPRINTF_L) && !defined(HAVE_USELOCALE) OFString *point; #endif if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; switch (ctx->format[ctx->i]) { case '@': if (ctx->lengthModifier != lengthModifierNone) return false; ctx->subformat[ctx->subformatLen - 1] = 's'; @try { id object; if ((object = va_arg(ctx->arguments, id)) != nil) { void *pool = objc_autoreleasePoolPush(); tmpLen = asprintf(&tmp, ctx->subformat, [object description].UTF8String); objc_autoreleasePoolPop(pool); } else tmpLen = asprintf(&tmp, ctx->subformat, "(nil)"); } @catch (id e) { free(ctx->buffer); @throw e; } break; case 'C': if (ctx->lengthModifier != lengthModifierNone) return false; ctx->subformat[ctx->subformatLen - 1] = 's'; { char buffer[5]; size_t len = _OFUTF8StringEncode( va_arg(ctx->arguments, OFUnichar), buffer); if (len == 0) return false; buffer[len] = 0; tmpLen = asprintf(&tmp, ctx->subformat, buffer); } break; case 'S': if (ctx->lengthModifier != lengthModifierNone) return false; ctx->subformat[ctx->subformatLen - 1] = 's'; { const OFUnichar *arg = va_arg(ctx->arguments, const OFUnichar *); size_t j, len = OFUTF32StringLength(arg); char *buffer; if (SIZE_MAX / 4 < len || (SIZE_MAX / 4) - len < 1) return false; if ((buffer = malloc((len * 4) + 1)) == NULL) return false; j = 0; for (size_t i = 0; i < len; i++) { size_t clen = _OFUTF8StringEncode(arg[i], buffer + j); if (clen == 0) { free(buffer); return false; } j += clen; } buffer[j] = 0; tmpLen = asprintf(&tmp, ctx->subformat, buffer); free(buffer); } break; case 'd': case 'i': switch (ctx->lengthModifier) { case lengthModifierNone: case lengthModifierHH: case lengthModifierH: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, int)); break; case lengthModifierL: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, long)); break; case lengthModifierLL: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, long long)); break; case lengthModifierJ: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, intmax_t)); break; case lengthModifierZ: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, ssize_t)); break; case lengthModifierT: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, ptrdiff_t)); break; default: return false; } break; case 'o': case 'u': case 'x': case 'X': switch (ctx->lengthModifier) { case lengthModifierNone: case lengthModifierHH: case lengthModifierH: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, unsigned int)); break; case lengthModifierL: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, unsigned long)); break; case lengthModifierLL: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, unsigned long long)); break; case lengthModifierJ: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, uintmax_t)); break; case lengthModifierZ: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, size_t)); break; case lengthModifierT: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, ptrdiff_t)); break; default: return false; } break; case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': case 'a': case 'A': switch (ctx->lengthModifier) { case lengthModifierNone: case lengthModifierL: #if defined(HAVE_ASPRINTF_L) if (!ctx->useLocale) tmpLen = asprintf_l(&tmp, cLocale, ctx->subformat, va_arg(ctx->arguments, double)); else #elif defined(HAVE_USELOCALE) if (!ctx->useLocale) { locale_t previousLocale = uselocale(cLocale); tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, double)); uselocale(previousLocale); } else #endif tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, double)); break; case lengthModifierCapitalL: #if defined(HAVE_ASPRINTF_L) if (!ctx->useLocale) tmpLen = asprintf_l(&tmp, cLocale, ctx->subformat, va_arg(ctx->arguments, long double)); else #elif defined(HAVE_USELOCALE) if (!ctx->useLocale) { locale_t previousLocale = uselocale(cLocale); tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, long double)); uselocale(previousLocale); } else #endif tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, long double)); break; default: return false; } #if !defined(HAVE_ASPRINTF_L) && !defined(HAVE_USELOCALE) if (tmpLen == -1) return false; /* * If there's no asprintf_l and no uselocale, we have no other * choice than to use this ugly hack to replace the locale's * decimal point back to ".". */ point = [OFLocale decimalSeparator]; if (!ctx->useLocale && point != nil && ![point isEqual: @"."]) { void *pool = objc_autoreleasePoolPush(); char *tmp2; @try { OFMutableString *tmpStr = [OFMutableString stringWithUTF8String: tmp length: tmpLen]; [tmpStr replaceOccurrencesOfString: point withString: @"."]; if (tmpStr.UTF8StringLength > INT_MAX) return false; tmpLen = (int)tmpStr.UTF8StringLength; tmp2 = malloc(tmpLen); memcpy(tmp2, tmpStr.UTF8String, tmpLen); } @finally { free(tmp); objc_autoreleasePoolPop(pool); } tmp = tmp2; } #endif break; case 'c': switch (ctx->lengthModifier) { case lengthModifierNone: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, int)); break; case lengthModifierL: #ifdef HAVE_WCHAR_H # if WINT_MAX >= INT_MAX tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, wint_t)); # else tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, int)); # endif break; #endif default: return false; } break; case 's': switch (ctx->lengthModifier) { case lengthModifierNone: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, const char *)); break; #ifdef HAVE_WCHAR_T case lengthModifierL: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, const wchar_t *)); break; #endif default: return false; } break; case 'p': if (ctx->lengthModifier != lengthModifierNone) return false; tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, void *)); break; case 'n': switch (ctx->lengthModifier) { case lengthModifierNone: *va_arg(ctx->arguments, int *) = (int)ctx->bufferLen; break; case lengthModifierHH: *va_arg(ctx->arguments, signed char *) = (signed char)ctx->bufferLen; break; case lengthModifierH: *va_arg(ctx->arguments, short *) = (short)ctx->bufferLen; break; case lengthModifierL: *va_arg(ctx->arguments, long *) = (long)ctx->bufferLen; break; case lengthModifierLL: *va_arg(ctx->arguments, long long *) = (long long)ctx->bufferLen; break; case lengthModifierJ: *va_arg(ctx->arguments, intmax_t *) = (intmax_t)ctx->bufferLen; break; case lengthModifierZ: *va_arg(ctx->arguments, size_t *) = (size_t)ctx->bufferLen; break; case lengthModifierT: *va_arg(ctx->arguments, ptrdiff_t *) = (ptrdiff_t)ctx->bufferLen; break; default: return false; } break; case '%': if (ctx->lengthModifier != lengthModifierNone) return false; if (!appendString(ctx, "%", 1)) return false; break; default: return false; } if (tmpLen == -1) return false; if (tmp != NULL) { if (!appendString(ctx, tmp, tmpLen)) { free(tmp); return false; } free(tmp); } memset(ctx->subformat, 0, maxSubformatLen); ctx->subformatLen = 0; ctx->lengthModifier = lengthModifierNone; ctx->useLocale = false; ctx->last = ctx->i + 1; ctx->state = stateString; return true; } static bool (*states[])(struct Context *) = { stringState, formatFlagsState, formatFieldWidthState, formatLengthModifierState, formatConversionSpecifierState }; int _OFVASPrintF(char **string, const char *format, va_list arguments) { struct Context ctx; ctx.format = format; ctx.formatLen = strlen(format); memset(ctx.subformat, 0, maxSubformatLen + 1); ctx.subformatLen = 0; va_copy(ctx.arguments, arguments); ctx.bufferLen = 0; ctx.last = 0; ctx.state = stateString; ctx.lengthModifier = lengthModifierNone; ctx.useLocale = false; if ((ctx.buffer = malloc(1)) == NULL) return -1; for (ctx.i = 0; ctx.i < ctx.formatLen; ctx.i++) { if (!states[ctx.state](&ctx)) { free(ctx.buffer); return -1; } } if (ctx.state != stateString) { free(ctx.buffer); return -1; } if (!appendString(&ctx, ctx.format + ctx.last, ctx.formatLen - ctx.last)) { free(ctx.buffer); return -1; } ctx.buffer[ctx.bufferLen] = 0; *string = ctx.buffer; return (ctx.bufferLen <= INT_MAX ? (int)ctx.bufferLen : -1); } objfw-1.1.6/src/OFApplication.h000066400000000000000000000217251465614216400162760ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include #import "OFObject.h" #import "OFNotification.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFArray OF_GENERIC(ObjectType); @class OFDictionary OF_GENERIC(KeyType, ObjectType); @class OFMutableArray OF_GENERIC(ObjectType); @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); @class OFSandbox; @class OFString; /** * @brief A notification that will be sent when the application did finish * launching. */ extern const OFNotificationName OFApplicationDidFinishLaunchingNotification; /** * @brief A notification that will be sent when the application will terminate. */ extern const OFNotificationName OFApplicationWillTerminateNotification; /** * @brief Specify the class to be used as the application delegate. * * An instance of this class will be created and act as the application * delegate. * * For example, it can be used like this: * * @code * // In MyAppDelegate.h: * @interface MyAppDelegate: OFObject * @end * * // In MyAppDelegate.m: * OF_APPLICATION_DELEGATE(MyAppDelegate) * * @implementation MyAppDelegate * - (void)applicationDidFinishLaunching: (OFNotification *)notification * { * [OFApplication terminate]; * } * @end * @endcode */ #define OF_APPLICATION_DELEGATE(class_) \ int \ main(int argc, char *argv[]) \ { \ return OFApplicationMain(&argc, &argv, \ (class_ *)[[class_ alloc] init]); \ } #ifdef OF_HAVE_PLEDGE # define OF_HAVE_SANDBOX #endif /** * @protocol OFApplicationDelegate OFApplication.h ObjFW/OFApplication.h * * @brief A protocol for delegates of OFApplication. * * @note Signals are not available on AmigaOS! */ @protocol OFApplicationDelegate /** * @brief A method which is called when the application was initialized and is * running now. * * @param notification A notification with name * OFApplicationDidFinishLaunchingNotification */ - (void)applicationDidFinishLaunching: (OFNotification *)notification; @optional /** * @brief A method which is called when the application will terminate. * * @param notification A notification with name * OFApplicationWillTerminateNotification */ - (void)applicationWillTerminate: (OFNotification *)notification; /** * @brief A method which is called when the application received a SIGINT. * * @warning You are not allowed to send any messages inside this method, as * message dispatching is not signal-safe! You are only allowed to do * signal-safe operations like setting a variable or calling a * signal-safe function! */ - (void)applicationDidReceiveSIGINT; #ifdef SIGHUP /** * @brief A method which is called when the application received a SIGHUP. * * This signal is not available on Windows. * * @warning You are not allowed to send any messages inside this method, as * message dispatching is not signal-safe! You are only allowed to do * signal-safe operations like setting a variable or calling a * signal-safe function! */ - (void)applicationDidReceiveSIGHUP; #endif #ifdef SIGUSR1 /** * @brief A method which is called when the application received a SIGUSR1. * * This signal is not available on Windows. * * @warning You are not allowed to send any messages inside this method, as * message dispatching is not signal-safe! You are only allowed to do * signal-safe operations like setting a variable or calling a * signal-safe function! */ - (void)applicationDidReceiveSIGUSR1; #endif #ifdef SIGUSR2 /** * @brief A method which is called when the application received a SIGUSR2. * * This signal is not available on Windows. * * @warning You are not allowed to send any messages inside this method, as * message dispatching is not signal-safe! You are only allowed to do * signal-safe operations like setting a variable or calling a * signal-safe function! */ - (void)applicationDidReceiveSIGUSR2; #endif @end /** * @class OFApplication OFApplication.h ObjFW/OFApplication.h * * @brief A class which represents the application as an object. * * In order to create a new OFApplication, you should create a class conforming * to the optional @ref OFApplicationDelegate protocol and put * `OF_APPLICATION_DELEGATE(NameOfYourClass)` in the .m file of that class. * * When the application is about to be terminated, * @ref OFApplicationDelegate#applicationWillTerminate: will be called on the * delegate and an @ref OFApplicationWillTerminateNotification will be sent. */ OF_SUBCLASSING_RESTRICTED @interface OFApplication: OFObject { OFString *_programName; OFArray OF_GENERIC(OFString *) *_arguments; OFMutableDictionary OF_GENERIC(OFString *, OFString *) *_environment; int *_argc; char ***_argv; id _Nullable _delegate; void (*_Nullable _SIGINTHandler)(id, SEL); #ifndef OF_WINDOWS void (*_Nullable _SIGHUPHandler)(id, SEL); void (*_Nullable _SIGUSR1Handler)(id, SEL); void (*_Nullable _SIGUSR2Handler)(id, SEL); #endif #ifdef OF_HAVE_SANDBOX OFSandbox *_Nullable _activeSandbox; OFSandbox *_Nullable _activeSandboxForChildProcesses; #endif } #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nullable, nonatomic) OFApplication *sharedApplication; @property (class, readonly, nullable, nonatomic) OFString *programName; @property (class, readonly, nullable, nonatomic) OFArray OF_GENERIC(OFString *) *arguments; @property (class, readonly, nullable, nonatomic) OFDictionary OF_GENERIC(OFString *, OFString *) *environment; #endif /** * @brief The name of the program (argv[0]). */ @property (readonly, nonatomic) OFString *programName; /** * @brief The arguments passed to the application. */ @property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *arguments; /** * @brief The environment of the application. */ @property (readonly, nonatomic) OFDictionary OF_GENERIC(OFString *, OFString *) *environment; /** * @brief The delegate of the application. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id delegate; #ifdef OF_HAVE_SANDBOX @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFSandbox *activeSandbox; @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFSandbox *activeSandboxForChildProcesses; #endif /** * @brief Returns the only OFApplication instance in the application. * * @return The only OFApplication instance in the application */ + (nullable OFApplication *)sharedApplication; /** * @brief Returns the name of the program (argv[0]). * * @return The name of the program (argv[0]) */ + (nullable OFString *)programName; /** * @brief Returns the arguments passed to the application. * * @return The arguments passed to the application */ + (nullable OFArray OF_GENERIC(OFString *) *)arguments; /** * @brief Returns the environment of the application. * * @return The environment of the application */ + (nullable OFDictionary OF_GENERIC(OFString *, OFString *) *)environment; /** * @brief Terminates the application with the EXIT_SUCCESS status. */ + (void)terminate OF_NO_RETURN; /** * @brief Terminates the application with the specified status. * * @param status The status with which the application will terminate */ + (void)terminateWithStatus: (int)status OF_NO_RETURN; #ifdef OF_HAVE_SANDBOX + (void)of_activateSandbox: (OFSandbox *)sandbox; + (void)of_activateSandboxForChildProcesses: (OFSandbox *)sandbox; #endif - (instancetype)init OF_UNAVAILABLE; /** * @brief Gets argc and argv. * * @param argc A pointer where a pointer to argc should be stored * @param argv A pointer where a pointer to argv should be stored */ - (void)getArgumentCount: (int *_Nonnull *_Nonnull)argc andArgumentValues: (char *_Nullable *_Nonnull *_Nonnull[_Nonnull])argv; /** * @brief Terminates the application. */ - (void)terminate OF_NO_RETURN; /** * @brief Terminates the application with the specified status. * * @param status The status with which the application will terminate */ - (void)terminateWithStatus: (int)status OF_NO_RETURN; #ifdef OF_HAVE_SANDBOX - (void)of_activateSandbox: (OFSandbox *)sandbox; - (void)of_activateSandboxForChildProcesses: (OFSandbox *)sandbox; #endif @end #ifdef __cplusplus extern "C" { #endif extern int OFApplicationMain(int *_Nonnull, char *_Nullable *_Nonnull[_Nonnull], id ); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFApplication.m000066400000000000000000000407061465614216400163030ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #include #include #include #include "unistd_wrapper.h" #import "OFApplication.h" #import "OFArray.h" #import "OFDictionary.h" #ifdef OF_AMIGAOS # import "OFFile.h" # import "OFFileManager.h" #endif #import "OFLocale.h" #import "OFNotificationCenter.h" #import "OFPair.h" #import "OFRunLoop+Private.h" #import "OFRunLoop.h" #import "OFSandbox.h" #import "OFStdIOStream.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFThread+Private.h" #import "OFThread.h" #import "OFActivateSandboxFailedException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #if defined(OF_MACOS) # include #elif defined(OF_WINDOWS) # include extern int _CRT_glob; extern void __wgetmainargs(int *, wchar_t ***, wchar_t ***, int, int *); #elif defined(OF_AMIGAOS) # define Class IntuitionClass # include # include # undef Class #elif !defined(OF_IOS) extern char **environ; #endif #ifdef OF_PSP # include # include #endif #ifdef OF_NINTENDO_DS # define asm __asm__ # include # undef asm #endif OF_DIRECT_MEMBERS @interface OFApplication () - (instancetype)of_init OF_METHOD_FAMILY(init); - (void)of_setArgumentCount: (int *)argc andArgumentValues: (char **[])argv; #ifdef OF_WINDOWS - (void)of_setArgumentCount: (int *)argc andArgumentValues: (char **[])argv andWideArgumentCount: (int)wargc andWideArgumentValues: (wchar_t *[])wargv; #endif - (void)of_run; @end const OFNotificationName OFApplicationDidFinishLaunchingNotification = @"OFApplicationDidFinishLaunchingNotification"; const OFNotificationName OFApplicationWillTerminateNotification = @"OFApplicationWillTerminateNotification"; static OFApplication *app = nil; static void atexitHandler(void) { id delegate = app.delegate; OFNotification *notification = [OFNotification notificationWithName: OFApplicationWillTerminateNotification object: app]; if ([delegate respondsToSelector: @selector(applicationWillTerminate:)]) [delegate applicationWillTerminate: notification]; [delegate release]; [[OFNotificationCenter defaultCenter] postNotification: notification]; #if defined(OF_HAVE_THREADS) && defined(OF_HAVE_SOCKETS) && \ defined(OF_AMIGAOS) && !defined(OF_MORPHOS) _OFSocketDeinit(); #endif } int OFApplicationMain(int *argc, char **argv[], id delegate) { [OFLocale currentLocale]; app = [[OFApplication alloc] of_init]; #ifdef OF_WINDOWS if ([OFSystemInfo isWindowsNT]) { wchar_t **wargv, **wenvp; int wargc, si = 0; __wgetmainargs(&wargc, &wargv, &wenvp, _CRT_glob, &si); [app of_setArgumentCount: argc andArgumentValues: argv andWideArgumentCount: wargc andWideArgumentValues: wargv]; } else #endif [app of_setArgumentCount: argc andArgumentValues: argv]; app.delegate = delegate; [app of_run]; [delegate release]; return 0; } @implementation OFApplication @synthesize programName = _programName, arguments = _arguments; @synthesize environment = _environment; #ifdef OF_HAVE_SANDBOX @synthesize activeSandbox = _activeSandbox; @synthesize activeSandboxForChildProcesses = _activeSandboxForChildProcesses; #endif #define SIGNAL_HANDLER(signal) \ static void \ handle##signal(int sig) \ { \ app->_##signal##Handler(app->_delegate, \ @selector(applicationDidReceive##signal)); \ } SIGNAL_HANDLER(SIGINT) #ifdef SIGHUP SIGNAL_HANDLER(SIGHUP) #endif #ifdef SIGUSR1 SIGNAL_HANDLER(SIGUSR1) #endif #ifdef SIGUSR2 SIGNAL_HANDLER(SIGUSR2) #endif #undef SIGNAL_HANDLER + (OFApplication *)sharedApplication { return app; } + (OFString *)programName { return app.programName; } + (OFArray *)arguments { return app.arguments; } + (OFDictionary *)environment { return app.environment; } + (void)terminate { [self terminateWithStatus: EXIT_SUCCESS]; OF_UNREACHABLE } + (void)terminateWithStatus: (int)status { #ifndef OF_PSP exit(status); OF_UNREACHABLE #else sceKernelExitGame(); OF_UNREACHABLE #endif } #ifdef OF_HAVE_SANDBOX + (void)of_activateSandbox: (OFSandbox *)sandbox { [app of_activateSandbox: sandbox]; } + (void)of_activateSandboxForChildProcesses: (OFSandbox *)sandbox { [app of_activateSandboxForChildProcesses: sandbox]; } #endif - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)of_init { self = [super init]; @try { _environment = [[OFMutableDictionary alloc] init]; atexit(atexitHandler); #if defined(OF_WINDOWS) if ([OFSystemInfo isWindowsNT]) { OFChar16 *env, *env0; env = env0 = GetEnvironmentStringsW(); while (*env != 0) { void *pool = objc_autoreleasePoolPush(); OFString *tmp, *key, *value; size_t length, pos; length = OFUTF16StringLength(env); tmp = [OFString stringWithUTF16String: env length: length]; env += length + 1; /* * cmd.exe seems to add some special variables * which start with a "=", even though variable * names are not allowed to contain a "=". */ if ([tmp hasPrefix: @"="]) { objc_autoreleasePoolPop(pool); continue; } pos = [tmp rangeOfString: @"="].location; if (pos == OFNotFound) { OFLog(@"Warning: Invalid environment " "variable: %@", tmp); continue; } key = [tmp substringToIndex: pos]; value = [tmp substringFromIndex: pos + 1]; [_environment setObject: value forKey: key]; objc_autoreleasePoolPop(pool); } FreeEnvironmentStringsW(env0); } else { char *env, *env0; env = env0 = GetEnvironmentStringsA(); while (*env != 0) { void *pool = objc_autoreleasePoolPush(); OFString *tmp, *key, *value; size_t length, pos; length = strlen(env); tmp = [OFString stringWithCString: env encoding: [OFLocale encoding] length: length]; env += length + 1; /* * cmd.exe seems to add some special variables * which start with a "=", even though variable * names are not allowed to contain a "=". */ if ([tmp hasPrefix: @"="]) { objc_autoreleasePoolPop(pool); continue; } pos = [tmp rangeOfString: @"="].location; if (pos == OFNotFound) { OFLog(@"Warning: Invalid environment " "variable: %@", tmp); continue; } key = [tmp substringToIndex: pos]; value = [tmp substringFromIndex: pos + 1]; [_environment setObject: value forKey: key]; objc_autoreleasePoolPop(pool); } FreeEnvironmentStringsA(env0); } #elif defined(OF_AMIGAOS) void *pool = objc_autoreleasePoolPush(); OFFileManager *fileManager = [OFFileManager defaultManager]; OFArray *envContents = [fileManager contentsOfDirectoryAtPath: @"ENV:"]; OFStringEncoding encoding = [OFLocale encoding]; struct Process *proc; struct LocalVar *firstLocalVar; for (OFString *name in envContents) { void *pool2 = objc_autoreleasePoolPush(); OFString *path, *value; OFFile *file; if ([name containsString: @"."]) continue; path = [@"ENV:" stringByAppendingString: name]; if ([fileManager directoryExistsAtPath: path]) continue; file = [OFFile fileWithPath: path mode: @"r"]; value = [file readLineWithEncoding: encoding]; if (value != nil) [_environment setObject: value forKey: name]; objc_autoreleasePoolPop(pool2); } /* Local variables override global variables */ proc = (struct Process *)FindTask(NULL); firstLocalVar = (struct LocalVar *)proc->pr_LocalVars.mlh_Head; for (struct LocalVar *iter = firstLocalVar; iter->lv_Node.ln_Succ != NULL; iter = (struct LocalVar *)iter->lv_Node.ln_Succ) { # ifdef OF_AMIGAOS4 int32 length; # else ULONG length; # endif OFString *key, *value; if (iter->lv_Node.ln_Type != LV_VAR || iter->lv_Flags & GVF_BINARY_VAR) continue; for (length = 0; length < iter->lv_Len; length++) if (iter->lv_Value[length] == 0) break; key = [OFString stringWithCString: iter->lv_Node.ln_Name encoding: encoding]; value = [OFString stringWithCString: (const char *)iter->lv_Value encoding: encoding length: length]; [_environment setObject: value forKey: key]; } objc_autoreleasePoolPop(pool); #elif !defined(OF_IOS) # ifndef OF_MACOS char **env = environ; # else char **env = *_NSGetEnviron(); # endif if (env != NULL) { OFStringEncoding encoding = [OFLocale encoding]; for (; *env != NULL; env++) { void *pool = objc_autoreleasePoolPush(); OFString *key, *value; char *sep; if ((sep = strchr(*env, '=')) == NULL) { OFLog(@"Warning: Invalid environment " "variable: %s", *env); continue; } key = [OFString stringWithCString: *env encoding: encoding length: sep - *env]; value = [OFString stringWithCString: sep + 1 encoding: encoding]; [_environment setObject: value forKey: key]; objc_autoreleasePoolPop(pool); } } #else /* * iOS does not provide environ and Apple does not allow using * _NSGetEnviron on iOS. Therefore, we just get a few common * variables from the environment which applications might * expect. */ void *pool = objc_autoreleasePoolPush(); char *env; if ((env = getenv("HOME")) != NULL) { OFString *home = [[[OFString alloc] initWithUTF8StringNoCopy: env freeWhenDone: false] autorelease]; [_environment setObject: home forKey: @"HOME"]; } if ((env = getenv("PATH")) != NULL) { OFString *path = [[[OFString alloc] initWithUTF8StringNoCopy: env freeWhenDone: false] autorelease]; [_environment setObject: path forKey: @"PATH"]; } if ((env = getenv("SHELL")) != NULL) { OFString *shell = [[[OFString alloc] initWithUTF8StringNoCopy: env freeWhenDone: false] autorelease]; [_environment setObject: shell forKey: @"SHELL"]; } if ((env = getenv("TMPDIR")) != NULL) { OFString *tmpdir = [[[OFString alloc] initWithUTF8StringNoCopy: env freeWhenDone: false] autorelease]; [_environment setObject: tmpdir forKey: @"TMPDIR"]; } if ((env = getenv("USER")) != NULL) { OFString *user = [[[OFString alloc] initWithUTF8StringNoCopy: env freeWhenDone: false] autorelease]; [_environment setObject: user forKey: @"USER"]; } objc_autoreleasePoolPop(pool); #endif [_environment makeImmutable]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_arguments release]; [_environment release]; [super dealloc]; } - (void)of_setArgumentCount: (int *)argc andArgumentValues: (char **[])argv { void *pool = objc_autoreleasePoolPush(); OFMutableArray *arguments; OFStringEncoding encoding; _argc = argc; _argv = argv; encoding = [OFLocale encoding]; #ifndef OF_NINTENDO_DS if (*argc > 0) { #else if (__system_argv->argvMagic == ARGV_MAGIC && __system_argv->argc > 0) { #endif _programName = [[OFString alloc] initWithCString: (*argv)[0] encoding: encoding]; arguments = [[OFMutableArray alloc] init]; _arguments = arguments; for (int i = 1; i < *argc; i++) [arguments addObject: [OFString stringWithCString: (*argv)[i] encoding: encoding]]; [arguments makeImmutable]; } objc_autoreleasePoolPop(pool); } #ifdef OF_WINDOWS - (void)of_setArgumentCount: (int *)argc andArgumentValues: (char **[])argv andWideArgumentCount: (int)wargc andWideArgumentValues: (wchar_t *[])wargv { void *pool = objc_autoreleasePoolPush(); OFMutableArray *arguments; _argc = argc; _argv = argv; if (wargc > 0) { _programName = [[OFString alloc] initWithUTF16String: wargv[0]]; arguments = [[OFMutableArray alloc] init]; for (int i = 1; i < wargc; i++) [arguments addObject: [OFString stringWithUTF16String: wargv[i]]]; [arguments makeImmutable]; _arguments = arguments; } objc_autoreleasePoolPop(pool); } #endif - (void)getArgumentCount: (int **)argc andArgumentValues: (char ****)argv { *argc = _argc; *argv = _argv; } - (id )delegate { return _delegate; } - (void)setDelegate: (id )delegate { #define REGISTER_SIGNAL(sig) \ if ([delegate respondsToSelector: \ @selector(applicationDidReceive##sig)]) { \ _##sig##Handler = (void (*)(id, SEL))[(id)delegate \ methodForSelector: \ @selector(applicationDidReceive##sig)]; \ signal(sig, handle##sig); \ } else { \ _##sig##Handler = NULL; \ signal(sig, (void (*)(int))SIG_DFL); \ } _delegate = delegate; REGISTER_SIGNAL(SIGINT) #ifdef SIGHUP REGISTER_SIGNAL(SIGHUP) #endif #ifdef SIGUSR1 REGISTER_SIGNAL(SIGUSR1) #endif #ifdef SIGUSR2 REGISTER_SIGNAL(SIGUSR2) #endif #undef REGISTER_SIGNAL } - (void)of_run { void *pool = objc_autoreleasePoolPush(); OFRunLoop *runLoop; OFNotification *notification; #ifdef OF_HAVE_THREADS [OFThread of_createMainThread]; runLoop = [OFRunLoop currentRunLoop]; #else runLoop = [[[OFRunLoop alloc] init] autorelease]; #endif [OFRunLoop of_setMainRunLoop: runLoop]; objc_autoreleasePoolPop(pool); /* * Note: runLoop is still valid after the release of the pool, as * of_setMainRunLoop: retained it. However, we only have a weak * reference to it now, whereas we had a strong reference before. */ pool = objc_autoreleasePoolPush(); notification = [OFNotification notificationWithName: OFApplicationDidFinishLaunchingNotification object: app]; [[OFNotificationCenter defaultCenter] postNotification: notification]; [_delegate applicationDidFinishLaunching: notification]; objc_autoreleasePoolPop(pool); [runLoop run]; } - (void)terminate { [self.class terminate]; OF_UNREACHABLE } - (void)terminateWithStatus: (int)status { [self.class terminateWithStatus: status]; OF_UNREACHABLE } #ifdef OF_HAVE_SANDBOX - (void)of_activateSandbox: (OFSandbox *)sandbox { # ifdef OF_HAVE_PLEDGE void *pool = objc_autoreleasePoolPush(); OFStringEncoding encoding = [OFLocale encoding]; OFArray OF_GENERIC(OFSandboxUnveilPath) *unveiledPaths; size_t unveiledPathsCount; const char *promises; if (_activeSandbox != nil && sandbox != _activeSandbox) @throw [OFInvalidArgumentException exception]; unveiledPaths = sandbox.unveiledPaths; unveiledPathsCount = unveiledPaths.count; for (size_t i = sandbox->_unveiledPathsIndex; i < unveiledPathsCount; i++) { OFSandboxUnveilPath unveiledPath = [unveiledPaths objectAtIndex: i]; OFString *path = unveiledPath.firstObject; OFString *permissions = unveiledPath.secondObject; if (path == nil || permissions == nil) @throw [OFInvalidArgumentException exception]; unveil([path cStringWithEncoding: encoding], [permissions cStringWithEncoding: encoding]); } sandbox->_unveiledPathsIndex = unveiledPathsCount; promises = [sandbox.pledgeString cStringWithEncoding: encoding]; if (pledge(promises, NULL) != 0) @throw [OFActivateSandboxFailedException exceptionWithSandbox: sandbox errNo: errno]; objc_autoreleasePoolPop(pool); if (_activeSandbox == nil) _activeSandbox = [sandbox retain]; # endif } - (void)of_activateSandboxForChildProcesses: (OFSandbox *)sandbox { # ifdef OF_HAVE_PLEDGE void *pool = objc_autoreleasePoolPush(); const char *promises; if (_activeSandboxForChildProcesses != nil && sandbox != _activeSandboxForChildProcesses) @throw [OFInvalidArgumentException exception]; if (sandbox.unveiledPaths.count != 0) @throw [OFInvalidArgumentException exception]; promises = [sandbox.pledgeString cStringWithEncoding: [OFLocale encoding]]; if (pledge(NULL, promises) != 0) @throw [OFActivateSandboxFailedException exceptionWithSandbox: sandbox errNo: errno]; objc_autoreleasePoolPop(pool); if (_activeSandboxForChildProcesses == nil) _activeSandboxForChildProcesses = [sandbox retain]; # endif } #endif @end objfw-1.1.6/src/OFArchiveEntry.h000066400000000000000000000046021465614216400164310ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @class OFDate; @class OFNumber; /** * @protocol OFArchiveEntry OFArchiveEntry.h ObjFW/OFArchiveEntry.h * * @brief A class which represents an entry in an archive. */ @protocol OFArchiveEntry /** * @brief The file name of the entry. */ @property (readonly, copy, nonatomic) OFString *fileName; /** * @brief The compressed size of the entry's file. */ @property (readonly, nonatomic) unsigned long long compressedSize; /** * @brief The uncompressed size of the entry's file. */ @property (readonly, nonatomic) unsigned long long uncompressedSize; @optional /** * @brief The modification date of the file. */ @property (readonly, retain, nonatomic) OFDate *modificationDate; /** * @brief The comment of the entry's file. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *fileComment; /** * @brief The POSIX permissions of the file. */ @property OF_NULLABLE_PROPERTY (readonly, retain, nonatomic) OFNumber *POSIXPermissions; /** * @brief The file owner's account ID. */ @property OF_NULLABLE_PROPERTY (readonly, retain, nonatomic) OFNumber *ownerAccountID; /** * @brief The file owner's group account ID. */ @property OF_NULLABLE_PROPERTY (readonly, retain, nonatomic) OFNumber *groupOwnerAccountID; /** * @brief The file owner's account name. */ @property OF_NULLABLE_PROPERTY (readonly, retain, nonatomic) OFString *ownerAccountName; /** * @brief The file owner's group account name. */ @property OF_NULLABLE_PROPERTY (readonly, retain, nonatomic) OFString *groupOwnerAccountName; @end OF_ASSUME_NONNULL_END #import "OFMutableArchiveEntry.h" objfw-1.1.6/src/OFArchiveIRIHandler.h000066400000000000000000000020151465614216400172450ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFIRIHandler.h" OF_ASSUME_NONNULL_BEGIN @interface OFArchiveIRIHandler: OFIRIHandler @end #ifdef __cplusplus extern "C" { #endif extern OFIRI *_OFArchiveIRIHandlerIRIForFileInArchive(OFString *, OFString *, OFIRI *) OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFArchiveIRIHandler.m000066400000000000000000000132621465614216400172600ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFArchiveIRIHandler.h" #import "OFCharacterSet.h" #import "OFGZIPStream.h" #import "OFIRI.h" #import "OFLHAArchive.h" #import "OFStream.h" #import "OFTarArchive.h" #import "OFZIPArchive.h" #import "OFZooArchive.h" #import "OFInvalidArgumentException.h" #import "OFOpenItemFailedException.h" @interface OFArchiveIRIHandlerPathAllowedCharacterSet: OFCharacterSet { OFCharacterSet *_characterSet; bool (*_characterIsMember)(id, SEL, OFUnichar); } @end static OFCharacterSet *pathAllowedCharacters; static void initPathAllowedCharacters(void) { pathAllowedCharacters = [[OFArchiveIRIHandlerPathAllowedCharacterSet alloc] init]; } @implementation OFArchiveIRIHandler - (OFStream *)openItemAtIRI: (OFIRI *)IRI mode: (OFString *)mode { void *pool = objc_autoreleasePoolPush(); OFString *scheme = IRI.scheme; OFString *percentEncodedPath, *path; size_t pos; OFIRI *archiveIRI; OFStream *stream; if (IRI.host != nil || IRI.port != nil || IRI.user != nil || IRI.password != nil || IRI.query != nil || IRI.fragment != nil) @throw [OFInvalidArgumentException exception]; if (![mode isEqual: @"r"]) /* * Writing has some implications that are not decided yet: Will * it always append to an archive? What happens if the file * already exists? */ @throw [OFInvalidArgumentException exception]; /* * GZIP only compresses one file and thus has no path inside an * archive. */ if ([scheme isEqual: @"gzip"]) { stream = [OFIRIHandler openItemAtIRI: [OFIRI IRIWithString: IRI.path] mode: mode]; stream = [OFGZIPStream streamWithStream: stream mode: mode]; goto end; } percentEncodedPath = IRI.percentEncodedPath; pos = [percentEncodedPath rangeOfString: @"!" options: OFStringSearchBackwards].location; if (pos == OFNotFound) @throw [OFInvalidArgumentException exception]; archiveIRI = [OFIRI IRIWithString: [percentEncodedPath substringWithRange: OFMakeRange(0, pos)] .stringByRemovingPercentEncoding]; path = [percentEncodedPath substringWithRange: OFMakeRange(pos + 1, percentEncodedPath.length - pos - 1)] .stringByRemovingPercentEncoding; if ([scheme isEqual: @"lha"]) { OFLHAArchive *archive = [OFLHAArchive archiveWithIRI: archiveIRI mode: mode]; OFLHAArchiveEntry *entry; while ((entry = [archive nextEntry]) != nil) { if ([entry.fileName isEqual: path]) { stream = [archive streamForReadingCurrentEntry]; goto end; } } @throw [OFOpenItemFailedException exceptionWithIRI: IRI mode: mode errNo: ENOENT]; } else if ([scheme isEqual: @"tar"]) { OFTarArchive *archive = [OFTarArchive archiveWithIRI: archiveIRI mode: mode]; OFTarArchiveEntry *entry; while ((entry = [archive nextEntry]) != nil) { if ([entry.fileName isEqual: path]) { stream = [archive streamForReadingCurrentEntry]; goto end; } } @throw [OFOpenItemFailedException exceptionWithIRI: IRI mode: mode errNo: ENOENT]; } else if ([scheme isEqual: @"zip"]) { OFZIPArchive *archive = [OFZIPArchive archiveWithIRI: archiveIRI mode: mode]; stream = [archive streamForReadingFile: path]; } else if ([scheme isEqual: @"zoo"]) { OFZooArchive *archive = [OFZooArchive archiveWithIRI: archiveIRI mode: mode]; OFZooArchiveEntry *entry; while ((entry = [archive nextEntry]) != nil) { if ([entry.fileName isEqual: path]) { stream = [archive streamForReadingCurrentEntry]; goto end; } } @throw [OFOpenItemFailedException exceptionWithIRI: IRI mode: mode errNo: ENOENT]; } else @throw [OFInvalidArgumentException exception]; end: stream = [stream retain]; objc_autoreleasePoolPop(pool); return [stream autorelease]; } @end @implementation OFArchiveIRIHandlerPathAllowedCharacterSet - (instancetype)init { self = [super init]; @try { _characterSet = [[OFCharacterSet IRIPathAllowedCharacterSet] retain]; _characterIsMember = (bool (*)(id, SEL, OFUnichar)) [_characterSet methodForSelector: @selector(characterIsMember:)]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_characterSet release]; [super dealloc]; } - (bool)characterIsMember: (OFUnichar)character { return (character != '!' && _characterIsMember(_characterSet, @selector(characterIsMember:), character)); } @end OFIRI * _OFArchiveIRIHandlerIRIForFileInArchive(OFString *scheme, OFString *pathInArchive, OFIRI *archiveIRI) { static OFOnceControl onceControl = OFOnceControlInitValue; OFMutableIRI *ret = [OFMutableIRI IRIWithScheme: scheme]; void *pool = objc_autoreleasePoolPush(); OFOnce(&onceControl, initPathAllowedCharacters); pathInArchive = [pathInArchive stringByAddingPercentEncodingWithAllowedCharacters: pathAllowedCharacters]; ret.percentEncodedPath = [OFString stringWithFormat: @"%@!%@", archiveIRI.string, pathInArchive]; [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } objfw-1.1.6/src/OFArray+Private.h000066400000000000000000000021111465614216400165030ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFArray.h" OF_ASSUME_NONNULL_BEGIN OF_DIRECT_MEMBERS @interface OFArrayEnumerator: OFEnumerator { OFArray *_array; size_t _count; unsigned long _mutations; unsigned long *_Nullable _mutationsPtr; size_t _position; } - (instancetype)initWithArray: (OFArray *)data mutationsPtr: (nullable unsigned long *)mutationsPtr; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFArray.h000066400000000000000000000367601465614216400151160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif #include #import "OFObject.h" #import "OFCollection.h" #import "OFEnumerator.h" #import "OFJSONRepresentation.h" #import "OFMessagePackRepresentation.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFString; /** * @brief Options for joining the objects of an array. * * This is a bit mask. */ typedef enum { /** Skip empty components */ OFArraySkipEmptyComponents = 1 } OFArrayJoinOptions; /** * @brief Options for sorting an array. * * This is a bit mask. */ typedef enum { /** Sort the array descending */ OFArraySortDescending = 1 } OFArraySortOptions; #ifdef OF_HAVE_BLOCKS /** * @brief A block for enumerating an OFArray. * * @param object The current object * @param index The index of the current object * @param stop A pointer to a variable that can be set to true to stop the * enumeration */ typedef void (^OFArrayEnumerationBlock)(id object, size_t index, bool *stop); /** * @brief A block for filtering an OFArray. * * @param object The object to inspect * @param index The index of the object to inspect * @return Whether the object should be in the filtered array */ typedef bool (^OFArrayFilterBlock)(id object, size_t index); /** * @brief A block for mapping objects to objects in an OFArray. * * @param object The object to map * @param index The index of the object to map * @return The object to map to */ typedef id _Nonnull (^OFArrayMapBlock)(id object, size_t index); /** * @brief A block for folding an OFArray. * * @param left The object to which the object has been folded so far * @param right The object that should be added to the left object * @return The left and right side folded into one object */ typedef id _Nullable (^OFArrayFoldBlock)(id _Nullable left, id right); #endif /** * @class OFArray OFArray.h ObjFW/OFArray.h * * @brief An abstract class for storing objects in an array. * * @note Subclasses must implement @ref count and @ref objectAtIndex:. */ @interface OFArray OF_GENERIC(ObjectType): OFObject #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # define ObjectType id #endif /** * @brief The objects of the array as a C array. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. */ @property (readonly, nonatomic) ObjectType const __unsafe_unretained _Nonnull *_Nonnull objects; /** * @brief The first object of the array or `nil`. * * @warning The returned object is *not* retained and autoreleased for * performance reasons! */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) ObjectType firstObject; /** * @brief The last object of the array or `nil`. * * @warning The returned object is *not* retained and autoreleased for * performance reasons! */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) ObjectType lastObject; /** * @brief The array sorted in ascending order. */ @property (readonly, nonatomic) OFArray OF_GENERIC(ObjectType) *sortedArray; /** * @brief The array with the order reversed. */ @property (readonly, nonatomic) OFArray OF_GENERIC(ObjectType) *reversedArray; /** * @brief Creates a new OFArray. * * @return A new autoreleased OFArray */ + (instancetype)array; /** * @brief Creates a new OFArray with the specified object. * * @param object An object * @return A new autoreleased OFArray */ + (instancetype)arrayWithObject: (ObjectType)object; /** * @brief Creates a new OFArray with the specified objects, terminated by `nil`. * * @param firstObject The first object in the array * @return A new autoreleased OFArray */ + (instancetype)arrayWithObjects: (ObjectType)firstObject, ... OF_SENTINEL; /** * @brief Creates a new OFArray with the objects from the specified array. * * @param array An array * @return A new autoreleased OFArray */ + (instancetype)arrayWithArray: (OFArray OF_GENERIC(ObjectType) *)array; /** * @brief Creates a new OFArray with the objects from the specified C array of * the specified length. * * @param objects A C array of objects * @param count The length of the C array * @return A new autoreleased OFArray */ + (instancetype)arrayWithObjects: (ObjectType const _Nonnull *_Nonnull)objects count: (size_t)count; /** * @brief Initializes an OFArray with no objects. * * @return An initialized OFArray */ - (instancetype)init OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an OFArray with the specified object. * * @param object An object * @return An initialized OFArray */ - (instancetype)initWithObject: (ObjectType)object; /** * @brief Initializes an OFArray with the specified objects. * * @param firstObject The first object * @return An initialized OFArray */ - (instancetype)initWithObjects: (ObjectType)firstObject, ... OF_SENTINEL; /** * @brief Initializes an OFArray with the specified object and a va_list. * * @param firstObject The first object * @param arguments A va_list * @return An initialized OFArray */ - (instancetype)initWithObject: (ObjectType)firstObject arguments: (va_list)arguments; /** * @brief Initializes an OFArray with the objects from the specified array. * * @param array An array * @return An initialized OFArray */ - (instancetype)initWithArray: (OFArray OF_GENERIC(ObjectType) *)array; /** * @brief Initializes an OFArray with the objects from the specified C array of * the specified length. * * @param objects A C array of objects * @param count The length of the C array * @return An initialized OFArray */ - (instancetype)initWithObjects: (ObjectType const _Nonnull *_Nonnull)objects count: (size_t)count OF_DESIGNATED_INITIALIZER; /** * @brief Returns an OFEnumerator to enumerate through all objects of the array. * * @return An OFEnumerator to enumerate through all objects of the array */ - (OFEnumerator OF_GENERIC(ObjectType) *)objectEnumerator; /** * @brief Returns the object at the specified index in the array. * * @warning The returned object is *not* retained and autoreleased for * performance reasons! * * @param index The index of the object to return * @return The object at the specified index in the array */ - (ObjectType)objectAtIndex: (size_t)index; - (ObjectType)objectAtIndexedSubscript: (size_t)index; /** * @brief Returns the value for the specified key * * A new array with the value for the specified key for each object is * returned. * * The special key `@count` can be used to retrieve the count as an OFNumber. * * @note Any nil values are replaced with @ref OFNull! * * @param key The key of the value to return * @return The value for the specified key */ - (nullable id)valueForKey: (OFString *)key; /** * @brief Set the value for the specified key * * @ref setValue:forKey: is called for each object in the array. * * @note A @ref OFNull value is translated to nil! * * @param value The value for the specified key * @param key The key of the value to set */ - (void)setValue: (nullable id)value forKey: (OFString *)key; /** * @brief Copies the objects at the specified range to the specified buffer. * * @param buffer The buffer to copy the objects to * @param range The range to copy */ - (void)getObjects: (ObjectType __unsafe_unretained _Nonnull *_Nonnull)buffer inRange: (OFRange)range; /** * @brief Returns the index of the first object that is equivalent to the * specified object or `OFNotFound` if it was not found. * * @param object The object whose index is returned * @return The index of the first object equivalent to the specified object * or `OFNotFound` if it was not found */ - (size_t)indexOfObject: (ObjectType)object; /** * @brief Returns the index of the first object that has the same address as the * specified object or `OFNotFound` if it was not found. * * @param object The object whose index is returned * @return The index of the first object that has the same address as * the specified object or `OFNotFound` if it was not found */ - (size_t)indexOfObjectIdenticalTo: (ObjectType)object; /** * @brief Checks whether the array contains an object equal to the specified * object. * * @param object The object which is checked for being in the array * @return A boolean whether the array contains the specified object */ - (bool)containsObject: (ObjectType)object; /** * @brief Checks whether the array contains an object with the specified * address. * * @param object The object which is checked for being in the array * @return A boolean whether the array contains an object with the specified * address */ - (bool)containsObjectIdenticalTo: (ObjectType)object; /** * @brief Returns the objects in the specified range as a new OFArray. * * @param range The range for the subarray * @return The subarray as a new autoreleased OFArray */ - (OFArray OF_GENERIC(ObjectType) *)objectsInRange: (OFRange)range; /** * @brief Creates a string by joining all objects of the array. * * @param separator The string with which the objects should be joined * @return A string containing all objects joined by the separator */ - (OFString *)componentsJoinedByString: (OFString *)separator; /** * @brief Creates a string by joining all objects of the array. * * @param separator The string with which the objects should be joined * @param options Options according to which the objects should be joined * @return A string containing all objects joined by the separator */ - (OFString *)componentsJoinedByString: (OFString *)separator options: (OFArrayJoinOptions)options; /** * @brief Creates a string by calling the selector on all objects of the array * and joining the strings returned by calling the selector. * * @param separator The string with which the objects should be joined * @param selector The selector to perform on the objects * @return A string containing all objects joined by the separator */ - (OFString *)componentsJoinedByString: (OFString *)separator usingSelector: (SEL)selector; /** * @brief Creates a string by calling the selector on all objects of the array * and joining the strings returned by calling the selector. * * @param separator The string with which the objects should be joined * @param selector The selector to perform on the objects * @param options Options according to which the objects should be joined * @return A string containing all objects joined by the separator */ - (OFString *)componentsJoinedByString: (OFString *)separator usingSelector: (SEL)selector options: (OFArrayJoinOptions)options; /** * @brief Performs the specified selector on all objects in the array. * * @param selector The selector to perform on all objects in the array */ - (void)makeObjectsPerformSelector: (SEL)selector; /** * @brief Performs the specified selector on all objects in the array with the * specified object. * * @param selector The selector to perform on all objects in the array * @param object The object to perform the selector with on all objects in the * array */ - (void)makeObjectsPerformSelector: (SEL)selector withObject: (nullable id)object; /** * @brief Returns a copy of the array sorted using the specified selector and * options. * * @param selector The selector to use to sort the array. It's signature * should be the same as that of -[compare:]. * @param options The options to use when sorting the array * @return A sorted copy of the array */ - (OFArray OF_GENERIC(ObjectType) *) sortedArrayUsingSelector: (SEL)selector options: (OFArraySortOptions)options; /** * @brief Returns a copy of the array sorted using the specified function and * options. * * @param compare The function to use to sort the array * @param context Context passed to the function to compare * @param options The options to use when sorting the array * @return A sorted copy of the array */ - (OFArray OF_GENERIC(ObjectType) *) sortedArrayUsingFunction: (OFCompareFunction)compare context: (nullable void *)context options: (OFArraySortOptions)options; #ifdef OF_HAVE_BLOCKS /** * @brief Returns a copy of the array sorted using the specified selector and * options. * * @param comparator The comparator to use to sort the array * @param options The options to use when sorting the array * @return A sorted copy of the array */ - (OFArray OF_GENERIC(ObjectType) *) sortedArrayUsingComparator: (OFComparator)comparator options: (OFArraySortOptions)options; #endif /** * @brief Creates a new array with the specified object added. * * @param object The object to add * @return A new array with the specified object added */ - (OFArray OF_GENERIC(ObjectType) *)arrayByAddingObject: (ObjectType)object; /** * @brief Creates a new array with the objects from the specified array added. * * @param array The array with objects to add * @return A new array with the objects from the specified array added */ - (OFArray OF_GENERIC(ObjectType) *)arrayByAddingObjectsFromArray: (OFArray OF_GENERIC(ObjectType) *)array; #ifdef OF_HAVE_BLOCKS /** * @brief Executes a block for each object. * * @param block The block to execute for each object */ - (void)enumerateObjectsUsingBlock: (OFArrayEnumerationBlock)block; /** * @brief Creates a new array, mapping each object using the specified block. * * @param block A block which maps an object for each object * @return A new, autoreleased OFArray */ - (OFArray *)mappedArrayUsingBlock: (OFArrayMapBlock)block; /** * @brief Creates a new array, only containing the objects for which the block * returns true. * * @param block A block which determines if the object should be in the new * array * @return A new, autoreleased OFArray */ - (OFArray OF_GENERIC(ObjectType) *)filteredArrayUsingBlock: (OFArrayFilterBlock)block; /** * @brief Folds the array to a single object using the specified block. * * If the array is empty, it will return `nil`. * * If there is only one object in the array, that object will be returned and * the block will not be invoked. * * If there are at least two objects, the block is invoked for each object * except the first, where left is always to what the array has already been * folded and right what should be added to left. * * @param block A block which folds two objects into one, which is called for * all objects except the first * @return The array folded to a single object */ - (nullable id)foldUsingBlock: (OFArrayFoldBlock)block; #endif #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # undef ObjectType #endif @end OF_ASSUME_NONNULL_END #import "OFMutableArray.h" #if !defined(NSINTEGER_DEFINED) && !__has_feature(modules) /* Required for array literals to work */ @compatibility_alias NSArray OFArray; #endif objfw-1.1.6/src/OFArray.m000066400000000000000000000451221465614216400151130ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "OFArray.h" #import "OFArray+Private.h" #import "OFConcreteArray.h" #import "OFData.h" #import "OFNull.h" #import "OFString.h" #import "OFSubarray.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" static struct { Class isa; } placeholder; @interface OFArray () - (OFString *) of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options depth: (size_t)depth; @end @interface OFPlaceholderArray: OFArray @end @implementation OFPlaceholderArray #ifdef __clang__ /* We intentionally don't call into super, so silence the warning. */ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunknown-pragmas" # pragma clang diagnostic ignored "-Wobjc-designated-initializers" #endif - (instancetype)init { return (id)[[OFConcreteArray alloc] init]; } - (instancetype)initWithObject: (id)object { return (id)[[OFConcreteArray alloc] initWithObject: object]; } - (instancetype)initWithObjects: (id)firstObject, ... { id ret; va_list arguments; va_start(arguments, firstObject); ret = [[OFConcreteArray alloc] initWithObject: firstObject arguments: arguments]; va_end(arguments); return ret; } - (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments { return (id)[[OFConcreteArray alloc] initWithObject: firstObject arguments: arguments]; } - (instancetype)initWithArray: (OFArray *)array { return (id)[[OFConcreteArray alloc] initWithArray: array]; } - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { return (id)[[OFConcreteArray alloc] initWithObjects: objects count: count]; } #ifdef __clang__ # pragma clang diagnostic pop #endif OF_SINGLETON_METHODS @end @implementation OFArray + (void)initialize { if (self == [OFArray class]) object_setClass((id)&placeholder, [OFPlaceholderArray class]); } + (instancetype)alloc { if (self == [OFArray class]) return (id)&placeholder; return [super alloc]; } + (instancetype)array { return [[[self alloc] init] autorelease]; } + (instancetype)arrayWithObject: (id)object { return [[[self alloc] initWithObject: object] autorelease]; } + (instancetype)arrayWithObjects: (id)firstObject, ... { id ret; va_list arguments; va_start(arguments, firstObject); ret = [[[self alloc] initWithObject: firstObject arguments: arguments] autorelease]; va_end(arguments); return ret; } + (instancetype)arrayWithArray: (OFArray *)array { return [[[self alloc] initWithArray: array] autorelease]; } + (instancetype)arrayWithObjects: (id const *)objects count: (size_t)count { return [[[self alloc] initWithObjects: objects count: count] autorelease]; } - (instancetype)init { if ([self isMemberOfClass: [OFArray class]] || [self isMemberOfClass: [OFMutableArray class]]) { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @throw e; } abort(); } return [super init]; } - (instancetype)initWithObject: (id)object { return [self initWithObjects: &object count: 1]; } - (instancetype)initWithObjects: (id)firstObject, ... { id ret; va_list arguments; va_start(arguments, firstObject); ret = [self initWithObject: firstObject arguments: arguments]; va_end(arguments); return ret; } - (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments { size_t count = 1; va_list argumentsCopy; id *objects; if (firstObject == nil) return [self init]; va_copy(argumentsCopy, arguments); while (va_arg(argumentsCopy, id) != nil) count++; @try { objects = OFAllocMemory(count, sizeof(id)); } @catch (id e) { [self release]; @throw e; } @try { objects[0] = firstObject; for (size_t i = 1; i < count; i++) { objects[i] = va_arg(arguments, id); OFEnsure(objects[i] != nil); } self = [self initWithObjects: objects count: count]; } @finally { OFFreeMemory(objects); } return self; } - (instancetype)initWithArray: (OFArray *)array { id *objects; size_t count; @try { count = array.count; objects = OFAllocMemory(count, sizeof(id)); [array getObjects: objects inRange: OFMakeRange(0, count)]; } @catch (id e) { [self release]; @throw e; } @try { self = [self initWithObjects: objects count: count]; } @finally { OFFreeMemory(objects); } return self; } #ifdef __clang__ /* We intentionally don't call into super, so silence the warning. */ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunknown-pragmas" # pragma clang diagnostic ignored "-Wobjc-designated-initializers" #endif - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { OF_INVALID_INIT_METHOD } #ifdef __clang__ # pragma clang diagnostic pop #endif - (size_t)count { OF_UNRECOGNIZED_SELECTOR } - (void)getObjects: (id *)buffer inRange: (OFRange)range { for (size_t i = 0; i < range.length; i++) buffer[i] = [self objectAtIndex: range.location + i]; } - (id const *)objects { size_t count = self.count; id *buffer = OFAllocMemory(count, sizeof(id)); id const *ret; @try { [self getObjects: buffer inRange: OFMakeRange(0, count)]; ret = [[OFData dataWithItemsNoCopy: buffer count: count itemSize: sizeof(id) freeWhenDone: true] items]; } @catch (id e) { OFFreeMemory(buffer); @throw e; } return ret; } - (id)copy { return [self retain]; } - (id)mutableCopy { return [[OFMutableArray alloc] initWithArray: self]; } - (id)objectAtIndex: (size_t)idx { OF_UNRECOGNIZED_SELECTOR } - (id)objectAtIndexedSubscript: (size_t)idx { return [self objectAtIndex: idx]; } - (id)valueForKey: (OFString *)key { id ret; if ([key isEqual: @"@count"]) return [super valueForKey: @"count"]; ret = [OFMutableArray arrayWithCapacity: self.count]; for (id object in self) { id value = [object valueForKey: key]; if (value == nil) value = [OFNull null]; [ret addObject: value]; } [ret makeImmutable]; return ret; } - (void)setValue: (id)value forKey: (OFString *)key { for (id object in self) [object setValue: value forKey: key]; } - (size_t)indexOfObject: (id)object { size_t i = 0; if (object == nil) return OFNotFound; for (id objectIter in self) { if ([objectIter isEqual: object]) return i; i++; } return OFNotFound; } - (size_t)indexOfObjectIdenticalTo: (id)object { size_t i = 0; if (object == nil) return OFNotFound; for (id objectIter in self) { if (objectIter == object) return i; i++; } return OFNotFound; } - (bool)containsObject: (id)object { return ([self indexOfObject: object] != OFNotFound); } - (bool)containsObjectIdenticalTo: (id)object { return ([self indexOfObjectIdenticalTo: object] != OFNotFound); } - (id)firstObject { if (self.count > 0) return [self objectAtIndex: 0]; return nil; } - (id)lastObject { size_t count = self.count; if (count > 0) return [self objectAtIndex: count - 1]; return nil; } - (OFArray *)objectsInRange: (OFRange)range { OFArray *ret; id *buffer; if (range.length > SIZE_MAX - range.location || range.location + range.length < self.count) @throw [OFOutOfRangeException exception]; if (![self isKindOfClass: [OFMutableArray class]]) return [[[OFSubarray alloc] initWithArray: self range: range] autorelease]; buffer = OFAllocMemory(range.length, sizeof(*buffer)); @try { [self getObjects: buffer inRange: range]; ret = [OFArray arrayWithObjects: buffer count: range.length]; } @finally { OFFreeMemory(buffer); } return ret; } - (OFString *)componentsJoinedByString: (OFString *)separator { return [self componentsJoinedByString: separator usingSelector: @selector(description) options: 0]; } - (OFString *)componentsJoinedByString: (OFString *)separator options: (OFArrayJoinOptions)options { return [self componentsJoinedByString: separator usingSelector: @selector(description) options: options]; } - (OFString *)componentsJoinedByString: (OFString *)separator usingSelector: (SEL)selector { return [self componentsJoinedByString: separator usingSelector: selector options: 0]; } - (OFString *)componentsJoinedByString: (OFString *)separator usingSelector: (SEL)selector options: (OFArrayJoinOptions)options { OFMutableString *ret; if (separator == nil) @throw [OFInvalidArgumentException exception]; if (self.count == 0) return @""; if (self.count == 1) { OFString *component = [[self objectAtIndex: 0] performSelector: selector]; if (component == nil) @throw [OFInvalidArgumentException exception]; return component; } ret = [OFMutableString string]; if (options & OFArraySkipEmptyComponents) { for (id object in self) { void *pool = objc_autoreleasePoolPush(); OFString *component = [object performSelector: selector]; if (component == nil) @throw [OFInvalidArgumentException exception]; if (component.length > 0) { if (ret.length > 0) [ret appendString: separator]; [ret appendString: component]; } objc_autoreleasePoolPop(pool); } } else { bool first = true; for (id object in self) { void *pool = objc_autoreleasePoolPush(); OFString *component = [object performSelector: selector]; if (component == nil) @throw [OFInvalidArgumentException exception]; if OF_UNLIKELY (first) first = false; else [ret appendString: separator]; [ret appendString: component]; objc_autoreleasePoolPop(pool); } } [ret makeImmutable]; return ret; } - (bool)isEqual: (id)object { /* FIXME: Optimize (for example, buffer of 16 for each) */ OFArray *otherArray; size_t count; if (object == self) return true; if (![object isKindOfClass: [OFArray class]]) return false; otherArray = object; count = self.count; if (count != otherArray.count) return false; for (size_t i = 0; i < count; i++) if (![[self objectAtIndex: i] isEqual: [otherArray objectAtIndex: i]]) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); for (id object in self) OFHashAddHash(&hash, [object hash]); OFHashFinalize(&hash); return hash; } - (OFString *)description { void *pool; OFMutableString *ret; if (self.count == 0) return @"()"; pool = objc_autoreleasePoolPush(); ret = [[self componentsJoinedByString: @",\n"] mutableCopy]; @try { [ret insertString: @"(\n" atIndex: 0]; [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @"\n)"]; } @catch (id e) { [ret release]; @throw e; } objc_autoreleasePoolPop(pool); [ret makeImmutable]; return [ret autorelease]; } - (OFString *)JSONRepresentation { return [self of_JSONRepresentationWithOptions: 0 depth: 0]; } - (OFString *)JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options { return [self of_JSONRepresentationWithOptions: options depth: 0]; } - (OFString *) of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options depth: (size_t)depth { OFMutableString *JSON = [OFMutableString stringWithString: @"["]; void *pool = objc_autoreleasePoolPush(); size_t i, count = self.count; if (options & OFJSONRepresentationOptionPretty) { OFMutableString *indentation = [OFMutableString string]; for (i = 0; i < depth; i++) [indentation appendString: @"\t"]; [JSON appendString: @"\n"]; i = 0; for (id object in self) { void *pool2 = objc_autoreleasePoolPush(); [JSON appendString: indentation]; [JSON appendString: @"\t"]; [JSON appendString: [object of_JSONRepresentationWithOptions: options depth: depth + 1]]; if (++i < count) [JSON appendString: @",\n"]; else [JSON appendString: @"\n"]; objc_autoreleasePoolPop(pool2); } [JSON appendString: indentation]; } else { i = 0; for (id object in self) { void *pool2 = objc_autoreleasePoolPush(); [JSON appendString: [object of_JSONRepresentationWithOptions: options depth: depth + 1]]; if (++i < count) [JSON appendString: @","]; objc_autoreleasePoolPop(pool2); } } [JSON appendString: @"]"]; [JSON makeImmutable]; objc_autoreleasePoolPop(pool); return JSON; } - (OFData *)messagePackRepresentation { OFMutableData *data; size_t i, count; void *pool; data = [OFMutableData data]; count = self.count; if (count <= 15) { uint8_t tmp = 0x90 | ((uint8_t)count & 0xF); [data addItem: &tmp]; } else if (count <= UINT16_MAX) { uint8_t type = 0xDC; uint16_t tmp = OFToBigEndian16((uint16_t)count); [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (count <= UINT32_MAX) { uint8_t type = 0xDD; uint32_t tmp = OFToBigEndian32((uint32_t)count); [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exception]; pool = objc_autoreleasePoolPush(); i = 0; for (id object in self) { void *pool2 = objc_autoreleasePoolPush(); OFData *child; i++; child = [object messagePackRepresentation]; [data addItems: child.items count: child.count]; objc_autoreleasePoolPop(pool2); } OFAssert(i == count); [data makeImmutable]; objc_autoreleasePoolPop(pool); return data; } - (void)makeObjectsPerformSelector: (SEL)selector { for (id object in self) [object performSelector: selector]; } - (void)makeObjectsPerformSelector: (SEL)selector withObject: (id)object { for (id objectIter in self) [objectIter performSelector: selector withObject: object]; } - (OFArray *)sortedArray { OFMutableArray *new = [[self mutableCopy] autorelease]; [new sort]; [new makeImmutable]; return new; } - (OFArray *)sortedArrayUsingSelector: (SEL)selector options: (OFArraySortOptions)options { OFMutableArray *new = [[self mutableCopy] autorelease]; [new sortUsingSelector: selector options: options]; [new makeImmutable]; return new; } - (OFArray *)sortedArrayUsingFunction: (OFCompareFunction)compare context: (void *)context options: (OFArraySortOptions)options { OFMutableArray *new = [[self mutableCopy] autorelease]; [new sortUsingFunction: compare context: context options: options]; [new makeImmutable]; return new; } #ifdef OF_HAVE_BLOCKS - (OFArray *)sortedArrayUsingComparator: (OFComparator)comparator options: (OFArraySortOptions)options { OFMutableArray *new = [[self mutableCopy] autorelease]; [new sortUsingComparator: comparator options: options]; [new makeImmutable]; return new; } #endif - (OFArray *)reversedArray { OFMutableArray *new = [[self mutableCopy] autorelease]; [new reverse]; [new makeImmutable]; return new; } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count { static unsigned long dummyMutations; OFRange range = OFMakeRange(state->state, count); if (range.length > SIZE_MAX - range.location) @throw [OFOutOfRangeException exception]; if (range.location + range.length > self.count) range.length = self.count - range.location; [self getObjects: objects inRange: range]; if (range.location + range.length > ULONG_MAX) @throw [OFOutOfRangeException exception]; state->state = (unsigned long)(range.location + range.length); state->itemsPtr = objects; state->mutationsPtr = &dummyMutations; return (int)range.length; } - (OFEnumerator *)objectEnumerator { return [[[OFArrayEnumerator alloc] initWithArray: self mutationsPtr: NULL] autorelease]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (OFArrayEnumerationBlock)block { size_t i = 0; bool stop = false; for (id object in self) { block(object, i++, &stop); if (stop) break; } } #endif - (OFArray *)arrayByAddingObject: (id)object { OFMutableArray *ret; if (object == nil) @throw [OFInvalidArgumentException exception]; ret = [[self mutableCopy] autorelease]; [ret addObject: object]; [ret makeImmutable]; return ret; } - (OFArray *)arrayByAddingObjectsFromArray: (OFArray *)array { OFMutableArray *ret = [[self mutableCopy] autorelease]; [ret addObjectsFromArray: array]; [ret makeImmutable]; return ret; } #ifdef OF_HAVE_BLOCKS - (OFArray *)mappedArrayUsingBlock: (OFArrayMapBlock)block { OFArray *ret; size_t count = self.count; id *tmp = OFAllocMemory(count, sizeof(id)); @try { [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { tmp[idx] = block(object, idx); }]; ret = [OFArray arrayWithObjects: tmp count: count]; } @finally { OFFreeMemory(tmp); } return ret; } - (OFArray *)filteredArrayUsingBlock: (OFArrayFilterBlock)block { OFArray *ret; size_t count = self.count; id *tmp = OFAllocMemory(count, sizeof(id)); @try { __block size_t i = 0; [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { if (block(object, idx)) tmp[i++] = object; }]; ret = [OFArray arrayWithObjects: tmp count: i]; } @finally { OFFreeMemory(tmp); } return ret; } - (id)foldUsingBlock: (OFArrayFoldBlock)block { size_t count = self.count; __block id current; if (count == 0) return nil; if (count == 1) return [[[self objectAtIndex: 0] retain] autorelease]; [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { id new; if (idx == 0) { current = [object retain]; return; } @try { new = [block(current, object) retain]; } @finally { [current release]; } current = new; }]; return [current autorelease]; } #endif @end @implementation OFArrayEnumerator - (instancetype)initWithArray: (OFArray *)array mutationsPtr: (unsigned long *)mutationsPtr { self = [super init]; _array = [array retain]; _count = [array count]; _mutations = (mutationsPtr != NULL ? *mutationsPtr : 0); _mutationsPtr = mutationsPtr; return self; } - (void)dealloc { [_array release]; [super dealloc]; } - (id)nextObject { if (_mutationsPtr != NULL && *_mutationsPtr != _mutations) @throw [OFEnumerationMutationException exceptionWithObject: _array]; if (_position < _count) return [_array objectAtIndex: _position++]; return nil; } @end objfw-1.1.6/src/OFAsyncIPSocketConnector.h000066400000000000000000000033031465614216400203550ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFDNSResolver.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" OF_ASSUME_NONNULL_BEGIN @protocol OFAsyncIPSocketConnecting - (bool)of_createSocketForAddress: (const OFSocketAddress *)address errNo: (int *)errNo; - (bool)of_connectSocketToAddress: (const OFSocketAddress *)address errNo: (int *)errNo; - (void)of_closeSocket; @end @interface OFAsyncIPSocketConnector: OFObject { id _socket; OFString *_host; uint16_t _port; id _Nullable _delegate; id _Nullable _block; id _Nullable _exception; OFData *_Nullable _socketAddresses; size_t _socketAddressesIndex; } - (instancetype)initWithSocket: (id)sock host: (OFString *)host port: (uint16_t)port delegate: (nullable id)delegate block: (nullable id)block; - (void)didConnect; - (void)tryNextAddressWithRunLoopMode: (OFRunLoopMode)runLoopMode; - (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFAsyncIPSocketConnector.m000066400000000000000000000137251465614216400203730ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFAsyncIPSocketConnector.h" #import "OFData.h" #import "OFTCPSocket.h" #import "OFThread.h" #import "OFTimer.h" #import "OFConnectIPSocketFailedException.h" #import "OFInvalidFormatException.h" @implementation OFAsyncIPSocketConnector - (instancetype)initWithSocket: (id)sock host: (OFString *)host port: (uint16_t)port delegate: (id)delegate block: (id)block { self = [super init]; @try { _socket = [sock retain]; _host = [host copy]; _port = port; _delegate = [delegate retain]; _block = [block copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_socket release]; [_host release]; [_delegate release]; [_block release]; [_exception release]; [_socketAddresses release]; [super dealloc]; } - (void)didConnect { if (_exception == nil) [_socket setCanBlock: true]; #ifdef OF_HAVE_BLOCKS if (_block != NULL) { if ([_socket isKindOfClass: [OFTCPSocket class]]) ((OFTCPSocketAsyncConnectBlock)_block)(_exception); else OFEnsure(0); } else { #endif if ([_delegate respondsToSelector: @selector(socket:didConnectToHost:port:exception:)]) [_delegate socket: _socket didConnectToHost: _host port: _port exception: _exception]; #ifdef OF_HAVE_BLOCKS } #endif } - (void)of_socketDidConnect: (id)sock exception: (id)exception { if (exception != nil) { /* * self might be retained only by the pending async requests, * which we're about to cancel. */ [[self retain] autorelease]; [sock cancelAsyncRequests]; [sock of_closeSocket]; if (_socketAddressesIndex >= _socketAddresses.count) { _exception = [exception retain]; [self didConnect]; } else { /* * We must not call it before returning, as otherwise * the new socket would be removed from the queue upon * return. */ OFRunLoop *runLoop = [OFRunLoop currentRunLoop]; SEL selector = @selector(tryNextAddressWithRunLoopMode:); OFTimer *timer = [OFTimer timerWithTimeInterval: 0 target: self selector: selector object: runLoop.currentMode repeats: false]; [runLoop addTimer: timer forMode: runLoop.currentMode]; } return; } [self didConnect]; } - (id)of_connectionFailedExceptionForErrNo: (int)errNo { return [OFConnectIPSocketFailedException exceptionWithHost: _host port: _port socket: _socket errNo: errNo]; } - (void)tryNextAddressWithRunLoopMode: (OFRunLoopMode)runLoopMode { OFSocketAddress address = *(const OFSocketAddress *) [_socketAddresses itemAtIndex: _socketAddressesIndex++]; int errNo; OFSocketAddressSetIPPort(&address, _port); if (![_socket of_createSocketForAddress: &address errNo: &errNo]) { if (_socketAddressesIndex >= _socketAddresses.count) { _exception = [[OFConnectIPSocketFailedException alloc] initWithHost: _host port: _port socket: _socket errNo: errNo]; [self didConnect]; return; } [self tryNextAddressWithRunLoopMode: runLoopMode]; return; } #if defined(OF_NINTENDO_3DS) || defined(OF_WII) /* * On Wii and 3DS, connect() fails if non-blocking is enabled. * * Additionally, on Wii, there is no getsockopt(), so it would not be * possible to get the error (or success) after connecting anyway. * * So for now, connecting is blocking on Wii and 3DS. * * FIXME: Use a different thread as a work around. */ [_socket setCanBlock: true]; #else [_socket setCanBlock: false]; #endif if (![_socket of_connectSocketToAddress: &address errNo: &errNo]) { #if !defined(OF_NINTENDO_3DS) && !defined(OF_WII) # ifdef OF_WINDOWS if (errNo == EINPROGRESS || errNo == EWOULDBLOCK) { # else if (errNo == EINPROGRESS) { # endif [OFRunLoop of_addAsyncConnectForSocket: _socket mode: runLoopMode delegate: self]; return; } else { #endif [_socket of_closeSocket]; if (_socketAddressesIndex >= _socketAddresses.count) { _exception = [[OFConnectIPSocketFailedException alloc] initWithHost: _host port: _port socket: _socket errNo: errNo]; [self didConnect]; return; } [self tryNextAddressWithRunLoopMode: runLoopMode]; return; #if !defined(OF_NINTENDO_3DS) && !defined(OF_WII) } #endif } #if defined(OF_NINTENDO_3DS) || defined(OF_WII) [_socket setCanBlock: false]; #endif [self didConnect]; } - (void)resolver: (OFDNSResolver *)resolver didResolveHost: (OFString *)host addresses: (OFData *)addresses exception: (id)exception { if (exception != nil) { _exception = [exception retain]; [self didConnect]; return; } _socketAddresses = [addresses copy]; [self tryNextAddressWithRunLoopMode: [OFRunLoop currentRunLoop].currentMode]; } - (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode { @try { OFSocketAddress address = OFSocketAddressParseIP(_host, _port); _socketAddresses = [[OFData alloc] initWithItems: &address count: 1 itemSize: sizeof(address)]; [self tryNextAddressWithRunLoopMode: runLoopMode]; return; } @catch (OFInvalidFormatException *e) { } [[OFThread DNSResolver] asyncResolveAddressesForHost: _host addressFamily: OFSocketAddressFamilyAny runLoopMode: runLoopMode delegate: self]; } @end objfw-1.1.6/src/OFAtomic.h000066400000000000000000000074161465614216400152500ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include #import "macros.h" #ifndef OF_HAVE_ATOMIC_OPS # error No atomic operations available! #endif #if !defined(OF_HAVE_THREADS) static OF_INLINE int OFAtomicIntAdd(volatile int *_Nonnull p, int i) { return (*p += i); } static OF_INLINE int32_t OFAtomicInt32Add(volatile int32_t *_Nonnull p, int32_t i) { return (*p += i); } static OF_INLINE void *_Nullable OFAtomicPointerAdd(void *volatile _Nullable *_Nonnull p, intptr_t i) { return (*(char *volatile *)p += i); } static OF_INLINE int OFAtomicIntSubtract(volatile int *_Nonnull p, int i) { return (*p -= i); } static OF_INLINE int32_t OFAtomicInt32Subtract(volatile int32_t *_Nonnull p, int32_t i) { return (*p -= i); } static OF_INLINE void *_Nullable OFAtomicPointerSubtract(void *volatile _Nullable *_Nonnull p, intptr_t i) { return (*(char *volatile *)p -= i); } static OF_INLINE int OFAtomicIntIncrease(volatile int *_Nonnull p) { return ++*p; } static OF_INLINE int32_t OFAtomicInt32Increase(volatile int32_t *_Nonnull p) { return ++*p; } static OF_INLINE int OFAtomicIntDecrease(volatile int *_Nonnull p) { return --*p; } static OF_INLINE int32_t OFAtomicInt32Decrease(volatile int32_t *_Nonnull p) { return --*p; } static OF_INLINE unsigned int OFAtomicIntOr(volatile unsigned int *_Nonnull p, unsigned int i) { return (*p |= i); } static OF_INLINE uint32_t OFAtomicInt32Or(volatile uint32_t *_Nonnull p, uint32_t i) { return (*p |= i); } static OF_INLINE unsigned int OFAtomicIntAnd(volatile unsigned int *_Nonnull p, unsigned int i) { return (*p &= i); } static OF_INLINE uint32_t OFAtomicInt32And(volatile uint32_t *_Nonnull p, uint32_t i) { return (*p &= i); } static OF_INLINE unsigned int OFAtomicIntXor(volatile unsigned int *_Nonnull p, unsigned int i) { return (*p ^= i); } static OF_INLINE uint32_t OFAtomicInt32Xor(volatile uint32_t *_Nonnull p, uint32_t i) { return (*p ^= i); } static OF_INLINE bool OFAtomicIntCompareAndSwap(volatile int *_Nonnull p, int o, int n) { if (*p == o) { *p = n; return true; } return false; } static OF_INLINE bool OFAtomicInt32CompareAndSwap(volatile int32_t *_Nonnull p, int32_t o, int32_t n) { if (*p == o) { *p = n; return true; } return false; } static OF_INLINE bool OFAtomicPointerCompareAndSwap(void *volatile _Nullable *_Nonnull p, void *_Nullable o, void *_Nullable n) { if (*p == o) { *p = n; return true; } return false; } static OF_INLINE void OFMemoryBarrier(void) { /* nop */ } static OF_INLINE void OFAcquireMemoryBarrier(void) { /* nop */ } static OF_INLINE void OFReleaseMemoryBarrier(void) { /* nop */ } #elif (defined(OF_AMD64) || defined(OF_X86)) && defined(__GNUC__) # import "platform/x86/OFAtomic.h" #elif defined(OF_POWERPC) && defined(__GNUC__) && !defined(__APPLE_CC__) && \ !defined(OF_AIX) # import "platform/PowerPC/OFAtomic.h" #elif defined(OF_HAVE_ATOMIC_BUILTINS) # import "platform/GCC4.7/OFAtomic.h" #elif defined(OF_HAVE_SYNC_BUILTINS) # import "platform/GCC4/OFAtomic.h" #elif defined(OF_HAVE_OSATOMIC) # import "platform/macOS/OFAtomic.h" #else # error No atomic operations available! #endif objfw-1.1.6/src/OFBase64.h000066400000000000000000000022741465614216400150550ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif #import "macros.h" OF_ASSUME_NONNULL_BEGIN @class OFString; @class OFMutableData; #ifdef __cplusplus extern "C" { #endif extern OFString *_OFBase64Encode(const void *, size_t) OF_VISIBILITY_HIDDEN; extern bool _OFBase64Decode(OFMutableData *, const char *, size_t) OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFBase64.m000066400000000000000000000077251465614216400150700ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFBase64.h" #import "OFString.h" #import "OFData.h" static const unsigned char encodeTable[64] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' }; static const signed char decodeTable[128] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, 0, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 }; OFString * _OFBase64Encode(const void *data, size_t length) { OFMutableString *ret = [OFMutableString string]; uint8_t *buffer = (uint8_t *)data; size_t i; uint8_t rest; char tb[4]; uint32_t sb; rest = length % 3; for (i = 0; i < length - rest; i += 3) { sb = (buffer[i] << 16) | (buffer[i + 1] << 8) | buffer[i + 2]; tb[0] = encodeTable[(sb & 0xFC0000) >> 18]; tb[1] = encodeTable[(sb & 0x03F000) >> 12]; tb[2] = encodeTable[(sb & 0x000FC0) >> 6]; tb[3] = encodeTable[sb & 0x00003F]; [ret appendCString: tb encoding: OFStringEncodingASCII length: 4]; } switch (rest) { case 1: tb[0] = encodeTable[buffer[i] >> 2]; tb[1] = encodeTable[(buffer[i] & 3) << 4]; tb[2] = tb[3] = '='; [ret appendCString: tb encoding: OFStringEncodingASCII length: 4]; break; case 2: sb = (buffer[i] << 16) | (buffer[i + 1] << 8); tb[0] = encodeTable[(sb & 0xFC0000) >> 18]; tb[1] = encodeTable[(sb & 0x03F000) >> 12]; tb[2] = encodeTable[(sb & 0x000FC0) >> 6]; tb[3] = '='; [ret appendCString: tb encoding: OFStringEncodingASCII length: 4]; break; } [ret makeImmutable]; return ret; } bool _OFBase64Decode(OFMutableData *data, const char *string, size_t length) { const uint8_t *buffer = (const uint8_t *)string; size_t i; if ((length & 3) != 0) return false; if (data.itemSize != 1) return false; for (i = 0; i < length; i += 4) { uint32_t sb = 0; uint8_t count = 3; char db[3]; int8_t tmp; if (buffer[i] > 0x7F || buffer[i + 1] > 0x7F || buffer[i + 2] > 0x7F || buffer[i + 3] > 0x7F) return false; if (buffer[i] == '=' || buffer[i + 1] == '=' || (buffer[i + 2] == '=' && buffer[i + 3] != '=')) return false; if (buffer[i + 2] == '=') count--; if (buffer[i + 3] == '=') count--; if ((tmp = decodeTable[buffer[i]]) == -1) return false; sb |= tmp << 18; if ((tmp = decodeTable[buffer[i + 1]]) == -1) return false; sb |= tmp << 12; if ((tmp = decodeTable[buffer[i + 2]]) == -1) return false; sb |= tmp << 6; if ((tmp = decodeTable[buffer[i + 3]]) == -1) return false; sb |= tmp; db[0] = (sb & 0xFF0000) >> 16; db[1] = (sb & 0x00FF00) >> 8; db[2] = sb & 0x0000FF; [data addItems: db count: count]; } return true; } objfw-1.1.6/src/OFBitSetCharacterSet.h000066400000000000000000000016111465614216400175060ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFCharacterSet.h" OF_ASSUME_NONNULL_BEGIN @interface OFBitSetCharacterSet: OFCharacterSet { unsigned char *_bitset; size_t _size; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFBitSetCharacterSet.m000066400000000000000000000036011465614216400175140ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFBitSetCharacterSet.h" #import "OFString.h" #import "OFOutOfRangeException.h" @implementation OFBitSetCharacterSet - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithCharactersInString: (OFString *)string { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); const OFUnichar *characters = string.characters; size_t length = string.length; for (size_t i = 0; i < length; i++) { OFUnichar c = characters[i]; if (c / CHAR_BIT >= _size) { size_t newSize; if (UINT32_MAX - c < 1) @throw [OFOutOfRangeException exception]; newSize = OFRoundUpToPowerOf2(CHAR_BIT, c + 1) / CHAR_BIT; _bitset = OFResizeMemory(_bitset, newSize, 1); memset(_bitset + _size, '\0', newSize - _size); _size = newSize; } OFBitsetSet(_bitset, c); } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { OFFreeMemory(_bitset); [super dealloc]; } - (bool)characterIsMember: (OFUnichar)character { if (character / CHAR_BIT >= _size) return false; return OFBitsetIsSet(_bitset, character); } @end objfw-1.1.6/src/OFBlock.h000066400000000000000000000043701465614216400150620ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFBlock OFBlock.h ObjFW/OFBlock.h * * @brief The class for all blocks, since all blocks are also objects. */ @interface OFBlock: OFObject + (instancetype)alloc OF_UNAVAILABLE; - (instancetype)init OF_UNAVAILABLE; @end OF_SUBCLASSING_RESTRICTED @interface OFStackBlock: OFBlock @end OF_SUBCLASSING_RESTRICTED @interface OFGlobalBlock: OFBlock @end OF_SUBCLASSING_RESTRICTED @interface OFMallocBlock: OFBlock @end #ifdef __cplusplus extern "C" { #endif extern void *_Nullable _Block_copy(const void *_Nullable); extern void _Block_release(const void *_Nullable); # if defined(OF_WINDOWS) && \ (defined(OF_NO_SHARED) || defined(OF_COMPILING_OBJFW)) /* * Clang has implicit declarations for these, but they are dllimport. When * compiling ObjFW itself or using it as a static library, these need to be * dllexport. Interestingly, this still works when using it as a shared library. */ extern __declspec(dllexport) struct objc_class _NSConcreteStackBlock; extern __declspec(dllexport) struct objc_class _NSConcreteGlobalBlock; extern __declspec(dllexport) void _Block_object_assign(void *, const void *, const int); extern __declspec(dllexport) void _Block_object_dispose(const void *, const int); # endif #ifdef __cplusplus } #endif #ifndef Block_copy # define Block_copy(...) \ ((__typeof__(__VA_ARGS__))_Block_copy((const void *)(__VA_ARGS__))) #endif #ifndef Block_release # define Block_release(...) _Block_release((const void *)(__VA_ARGS__)) #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFBlock.m000066400000000000000000000300101465614216400150550ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #include #import "OFBlock.h" #ifdef OF_HAVE_ATOMIC_OPS # import "OFAtomic.h" #endif #ifdef OF_HAVE_THREADS # import "OFPlainMutex.h" #endif #import "OFString.h" #import "OFAllocFailedException.h" #import "OFInitializationFailedException.h" #if defined(OF_OBJFW_RUNTIME) # import "runtime/private.h" #endif struct Block { Class isa; int flags; int reserved; void (*invoke)(void *block, ...); struct { unsigned long reserved; unsigned long size; void (*_Nullable copyHelper)(void *dest, void *src); void (*_Nullable disposeHelper)(void *src); const char *signature; } *descriptor; }; struct Byref { Class isa; struct Byref *forwarding; int flags; int size; void (*keepByref)(void *dest, void *src); void (*disposeByref)(void *); }; enum { OFBlockHasCopyDispose = (1 << 25), OFBlockHasCtor = (1 << 26), OFBlockIsGlobal = (1 << 28), OFBlockHasStret = (1 << 29), OFBlockHasSignature = (1 << 30) }; #define OFBlockRefCountMask 0xFFFF enum { OFBlockFieldIsObject = 3, OFBlockFieldIsBlock = 7, OFBlockFieldIsByref = 8, OFBlockFieldIsWeak = 16, OFBlockByrefCaller = 128 }; @protocol RetainRelease - (instancetype)retain; - (void)release; @end #ifdef OF_OBJFW_RUNTIME /* Begin of ObjC module */ static struct objc_class _NSConcreteStackBlock_metaclass = { Nil, Nil, "OFStackBlock", 8, OBJC_CLASS_INFO_METACLASS, sizeof(_NSConcreteStackBlock_metaclass), NULL, NULL }; struct objc_class _NSConcreteStackBlock = { &_NSConcreteStackBlock_metaclass, (Class)(void *)"OFBlock", "OFStackBlock", 8, OBJC_CLASS_INFO_CLASS, sizeof(struct Block), NULL, NULL }; static struct objc_class _NSConcreteGlobalBlock_metaclass = { Nil, Nil, "OFGlobalBlock", 8, OBJC_CLASS_INFO_METACLASS, sizeof(_NSConcreteGlobalBlock_metaclass), NULL, NULL }; struct objc_class _NSConcreteGlobalBlock = { &_NSConcreteGlobalBlock_metaclass, (Class)(void *)"OFBlock", "OFGlobalBlock", 8, OBJC_CLASS_INFO_CLASS, sizeof(struct Block), NULL, NULL }; static struct objc_class _NSConcreteMallocBlock_metaclass = { Nil, Nil, "OFMallocBlock", 8, OBJC_CLASS_INFO_METACLASS, sizeof(_NSConcreteMallocBlock_metaclass), NULL, NULL }; struct objc_class _NSConcreteMallocBlock = { &_NSConcreteMallocBlock_metaclass, (Class)(void *)"OFBlock", "OFMallocBlock", 8, OBJC_CLASS_INFO_CLASS, sizeof(struct Block), NULL, NULL }; static struct { unsigned long unknown; struct objc_selector *selectorRefs; uint16_t classDefsCount, categoryDefsCount; void *defs[4]; } symtab = { 0, NULL, 3, 0, { &_NSConcreteStackBlock, &_NSConcreteGlobalBlock, &_NSConcreteMallocBlock, NULL } }; static struct _objc_module module = { 8, sizeof(module), NULL, (struct objc_symtab *)&symtab }; OF_CONSTRUCTOR() { __objc_exec_class(&module); } /* End of ObjC module */ #elif defined(OF_APPLE_RUNTIME) extern Class objc_initializeClassPair(Class, const char *, Class, Class); struct class { struct class *isa, *superclass; const char *name; long version, info, instanceSize; struct ivar_list *iVars; struct method_list **methodList; struct cache *cache; struct protocol_list *protocols; const char *iVarLayout; struct class_ext *ext; }; struct class _NSConcreteStackBlock; struct class _NSConcreteGlobalBlock; struct class _NSConcreteMallocBlock; # if defined(__OBJC2__) && !defined(OF_POWERPC64) struct class _NSConcreteStackBlock_metaclass; struct class _NSConcreteGlobalBlock_metaclass; struct class _NSConcreteMallocBlock_metaclass; # endif #endif static struct { Class isa; } allocFailedException; #ifndef OF_HAVE_ATOMIC_OPS # define numSpinlocks 8 /* needs to be a power of 2 */ # define SPINLOCK_HASH(p) ((uintptr_t)p >> 4) & (numSpinlocks - 1) static OFSpinlock blockSpinlocks[numSpinlocks]; static OFSpinlock byrefSpinlocks[numSpinlocks]; #endif void * _Block_copy(const void *block_) { struct Block *block = (struct Block *)block_; if ([(id)block isMemberOfClass: (Class)&_NSConcreteStackBlock]) { struct Block *copy; if ((copy = malloc(block->descriptor->size)) == NULL) { object_setClass((id)&allocFailedException, [OFAllocFailedException class]); @throw (OFAllocFailedException *)&allocFailedException; } memcpy(copy, block, block->descriptor->size); object_setClass((id)copy, (Class)&_NSConcreteMallocBlock); copy->flags++; if (block->flags & OFBlockHasCopyDispose) block->descriptor->copyHelper(copy, block); return copy; } if ([(id)block isMemberOfClass: (Class)&_NSConcreteMallocBlock]) { #ifdef OF_HAVE_ATOMIC_OPS OFAtomicIntIncrease(&block->flags); #else unsigned hash = SPINLOCK_HASH(block); OFEnsure(OFSpinlockLock(&blockSpinlocks[hash]) == 0); block->flags++; OFEnsure(OFSpinlockUnlock(&blockSpinlocks[hash]) == 0); #endif } return block; } void _Block_release(const void *block_) { struct Block *block = (struct Block *)block_; if (object_getClass((id)block) != (Class)&_NSConcreteMallocBlock) return; #ifdef OF_HAVE_ATOMIC_OPS if ((OFAtomicIntDecrease(&block->flags) & OFBlockRefCountMask) == 0) { if (block->flags & OFBlockHasCopyDispose) block->descriptor->disposeHelper(block); free(block); } #else unsigned hash = SPINLOCK_HASH(block); OFEnsure(OFSpinlockLock(&blockSpinlocks[hash]) == 0); if ((--block->flags & OFBlockRefCountMask) == 0) { OFEnsure(OFSpinlockUnlock(&blockSpinlocks[hash]) == 0); if (block->flags & OFBlockHasCopyDispose) block->descriptor->disposeHelper(block); free(block); return; } OFEnsure(OFSpinlockUnlock(&blockSpinlocks[hash]) == 0); #endif } void _Block_object_assign(void *dst_, const void *src_, const int flags_) { int flags = flags_ & (OFBlockFieldIsBlock | OFBlockFieldIsObject | OFBlockFieldIsByref); if (src_ == NULL) return; switch (flags) { case OFBlockFieldIsBlock: *(struct Block **)dst_ = _Block_copy(src_); break; case OFBlockFieldIsObject: if (!(flags_ & OFBlockByrefCaller)) *(id *)dst_ = [(id)src_ retain]; break; case OFBlockFieldIsByref:; struct Byref *src = (struct Byref *)src_; struct Byref **dst = (struct Byref **)dst_; src = src->forwarding; if ((src->flags & OFBlockRefCountMask) == 0) { if ((*dst = malloc(src->size)) == NULL) { object_setClass((id)&allocFailedException, [OFAllocFailedException class]); @throw (OFAllocFailedException *) &allocFailedException; } memcpy(*dst, src, src->size); (*dst)->flags = ((*dst)->flags & ~OFBlockRefCountMask) | 1; (*dst)->forwarding = *dst; if (src->flags & OFBlockHasCopyDispose) src->keepByref(*dst, src); #ifdef OF_HAVE_ATOMIC_OPS if (!OFAtomicPointerCompareAndSwap( (void **)&src->forwarding, src, *dst)) { src->disposeByref(*dst); free(*dst); *dst = src->forwarding; } #else unsigned hash = SPINLOCK_HASH(src); OFEnsure(OFSpinlockLock(&byrefSpinlocks[hash]) == 0); if (src->forwarding == src) src->forwarding = *dst; else { src->disposeByref(*dst); free(*dst); *dst = src->forwarding; } OFEnsure(OFSpinlockUnlock(&byrefSpinlocks[hash]) == 0); #endif } else *dst = src; #ifdef OF_HAVE_ATOMIC_OPS OFAtomicIntIncrease(&(*dst)->flags); #else unsigned hash = SPINLOCK_HASH(*dst); OFEnsure(OFSpinlockLock(&byrefSpinlocks[hash]) == 0); (*dst)->flags++; OFEnsure(OFSpinlockUnlock(&byrefSpinlocks[hash]) == 0); #endif break; } } void _Block_object_dispose(const void *object_, const int flags_) { const int flags = flags_ & (OFBlockFieldIsBlock | OFBlockFieldIsObject | OFBlockFieldIsByref); if (object_ == NULL) return; switch (flags) { case OFBlockFieldIsBlock: _Block_release(object_); break; case OFBlockFieldIsObject: if (!(flags_ & OFBlockByrefCaller)) [(id)object_ release]; break; case OFBlockFieldIsByref:; struct Byref *object = (struct Byref *)object_; object = object->forwarding; #ifdef OF_HAVE_ATOMIC_OPS if ((OFAtomicIntDecrease(&object->flags) & OFBlockRefCountMask) == 0) { if (object->flags & OFBlockHasCopyDispose) object->disposeByref(object); free(object); } #else unsigned hash = SPINLOCK_HASH(object); OFEnsure(OFSpinlockLock(&byrefSpinlocks[hash]) == 0); if ((--object->flags & OFBlockRefCountMask) == 0) { OFEnsure(OFSpinlockUnlock(&byrefSpinlocks[hash]) == 0); if (object->flags & OFBlockHasCopyDispose) object->disposeByref(object); free(object); } OFEnsure(OFSpinlockUnlock(&byrefSpinlocks[hash]) == 0); #endif break; } } @implementation OFBlock + (void)load { #ifndef OF_HAVE_ATOMIC_OPS for (size_t i = 0; i < numSpinlocks; i++) if (OFSpinlockNew(&blockSpinlocks[i]) != 0 || OFSpinlockNew(&byrefSpinlocks[i]) != 0) @throw [OFInitializationFailedException exceptionWithClass: self]; #endif #ifdef OF_APPLE_RUNTIME Class tmp; # if defined(__OBJC2__) && !defined(OF_POWERPC64) tmp = objc_initializeClassPair(self, "OFStackBlock", (Class)&_NSConcreteStackBlock, (Class)&_NSConcreteStackBlock_metaclass); if (tmp == Nil) @throw [OFInitializationFailedException exceptionWithClass: self]; objc_registerClassPair(tmp); tmp = objc_initializeClassPair(self, "OFGlobalBlock", (Class)&_NSConcreteGlobalBlock, (Class)&_NSConcreteGlobalBlock_metaclass); if (tmp == Nil) @throw [OFInitializationFailedException exceptionWithClass: self]; objc_registerClassPair(tmp); tmp = objc_initializeClassPair([OFBlock class], "OFMallocBlock", (Class)&_NSConcreteMallocBlock, (Class)&_NSConcreteMallocBlock_metaclass); if (tmp == Nil) @throw [OFInitializationFailedException exceptionWithClass: self]; objc_registerClassPair(tmp); # else /* * There is no objc_initializeClassPair in 10.5. * However, objc_allocateClassPair does not register the new class with * the subclass in the ObjC1 runtime like the ObjC2 runtime does, so * this workaround should be fine. */ if ((tmp = objc_allocateClassPair(self, "OFStackBlock", 0)) == NULL) @throw [OFInitializationFailedException exceptionWithClass: self]; memcpy(&_NSConcreteStackBlock, tmp, sizeof(_NSConcreteStackBlock)); free(tmp); objc_registerClassPair((Class)&_NSConcreteStackBlock); if ((tmp = objc_allocateClassPair(self, "OFGlobalBlock", 0)) == NULL) @throw [OFInitializationFailedException exceptionWithClass: self]; memcpy(&_NSConcreteGlobalBlock, tmp, sizeof(_NSConcreteGlobalBlock)); free(tmp); objc_registerClassPair((Class)&_NSConcreteGlobalBlock); if ((tmp = objc_allocateClassPair(self, "OFMallocBlock", 0)) == NULL) @throw [OFInitializationFailedException exceptionWithClass: self]; memcpy(&_NSConcreteMallocBlock, tmp, sizeof(_NSConcreteMallocBlock)); free(tmp); objc_registerClassPair((Class)&_NSConcreteMallocBlock); # endif #endif } + (instancetype)alloc { OF_UNRECOGNIZED_SELECTOR } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)retain { if ([self isMemberOfClass: (Class)&_NSConcreteMallocBlock]) return Block_copy(self); return self; } - (id)copy { return Block_copy(self); } - (instancetype)autorelease { if ([self isMemberOfClass: (Class)&_NSConcreteMallocBlock]) return [super autorelease]; return self; } - (unsigned int)retainCount { if ([self isMemberOfClass: (Class)&_NSConcreteMallocBlock]) return ((struct Block *)self)->flags & OFBlockRefCountMask; return OFMaxRetainCount; } - (void)release { if ([self isMemberOfClass: (Class)&_NSConcreteMallocBlock]) Block_release(self); } - (void)dealloc { OF_DEALLOC_UNSUPPORTED } @end objfw-1.1.6/src/OFCNAMEDNSResourceRecord.h000066400000000000000000000036101465614216400200630ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFDNSResourceRecord.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFCNAMEDNSResourceRecord \ * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h * * @brief A class representing a CNAME DNS resource record. */ OF_SUBCLASSING_RESTRICTED @interface OFCNAMEDNSResourceRecord: OFDNSResourceRecord { OFString *_alias; } /** * @brief The alias of the resource record. */ @property (readonly, nonatomic) OFString *alias; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFCNAMEDNSResourceRecord with the * specified name, class, alias and time to live. * * @param name The name for the resource record * @param DNSClass The class code for the resource record * @param alias The alias for the resource record * @param TTL The time to live for the resource record * @return An initialized OFCNAMEDNSResourceRecord */ - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass alias: (OFString *)alias TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFCNAMEDNSResourceRecord.m000066400000000000000000000047741465614216400201040ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFCNAMEDNSResourceRecord.h" @implementation OFCNAMEDNSResourceRecord @synthesize alias = _alias; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass alias: (OFString *)alias TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: DNSClass recordType: OFDNSRecordTypeCNAME TTL: TTL]; @try { _alias = [alias copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_alias release]; [super dealloc]; } - (bool)isEqual: (id)object { OFCNAMEDNSResourceRecord *record; if (object == self) return true; if (![object isKindOfClass: [OFCNAMEDNSResourceRecord class]]) return false; record = object; if (record->_name != _name && ![record->_name isEqual: _name]) return false; if (record->_DNSClass != _DNSClass) return false; if (record->_recordType != _recordType) return false; if (record->_alias != _alias && ![record->_alias isEqual: _alias]) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddByte(&hash, _DNSClass >> 8); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType >> 8); OFHashAddByte(&hash, _recordType); OFHashAddHash(&hash, _alias.hash); OFHashFinalize(&hash); return hash; } - (OFString *)description { return [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tClass = %@\n" @"\tAlias = %@\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFDNSClassName(_DNSClass), _alias, _TTL]; } @end objfw-1.1.6/src/OFCRC16.h000066400000000000000000000020461465614216400146040ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif #import "macros.h" #ifdef __cplusplus extern "C" { #endif extern uint16_t _OFCRC16(uint16_t crc, const void *_Nonnull bytes, size_t length) OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif objfw-1.1.6/src/OFCRC16.m000066400000000000000000000021051465614216400146050ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFCRC16.h" static const uint16_t CRC16Magic = 0xA001; uint16_t _OFCRC16(uint16_t CRC, const void *bytes_, size_t length) { const unsigned char *bytes = bytes_; for (size_t i = 0; i < length; i++) { CRC ^= bytes[i]; for (uint8_t j = 0; j < 8; j++) CRC = (CRC >> 1) ^ (CRC16Magic & (~(CRC & 1) + 1)); } return CRC; } objfw-1.1.6/src/OFCRC32.h000066400000000000000000000020461465614216400146020ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif #import "macros.h" #ifdef __cplusplus extern "C" { #endif extern uint32_t _OFCRC32(uint32_t crc, const void *_Nonnull bytes, size_t length) OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif objfw-1.1.6/src/OFCRC32.m000066400000000000000000000021111465614216400146000ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFCRC32.h" static const uint32_t CRC32Magic = 0xEDB88320; uint32_t _OFCRC32(uint32_t CRC, const void *bytes_, size_t length) { const unsigned char *bytes = bytes_; for (size_t i = 0; i < length; i++) { CRC ^= bytes[i]; for (uint8_t j = 0; j < 8; j++) CRC = (CRC >> 1) ^ (CRC32Magic & (~(CRC & 1) + 1)); } return CRC; } objfw-1.1.6/src/OFCharacterSet.h000066400000000000000000000056301465614216400164000ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFCharacterSet OFCharacterSet.h ObjFW/OFCharacterSet.h * * @brief A class cluster representing a character set. * * @note Subclasses must implement @ref characterIsMember:. */ @interface OFCharacterSet: OFObject { OF_RESERVE_IVARS(OFCharacterSet, 4) } #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nonatomic) OFCharacterSet *whitespaceCharacterSet; #endif /** * @brief The inverted set, containing only the characters that do not exist in * the receiver. */ @property (readonly, nonatomic) OFCharacterSet *invertedSet; /** * @brief Creates a new character set containing the characters of the * specified string. * * @param characters The characters for the character set * @return A new OFCharacterSet */ + (instancetype)characterSetWithCharactersInString: (OFString *)characters; /** * @brief Creates a new character set containing the characters in the specified * range. * * @param range The range of characters for the character set * @return A new OFCharacterSet */ + (instancetype)characterSetWithRange: (OFRange)range; /** * @brief A character set containing all Unicode characters in the category * `Zs` plus CHARACTER TABULATION (U+0009). */ + (OFCharacterSet *)whitespaceCharacterSet; /** * @brief Initializes an already allocated character set with the characters of * the specified string. * * @param characters The characters for the character set * @return An initialized OFCharacterSet */ - (instancetype)initWithCharactersInString: (OFString *)characters; /** * @brief Initializes an already allocated character set with the characters in * the specified range. * * @param range The range of characters for the character set * @return An initialized OFCharacterSet */ - (instancetype)initWithRange: (OFRange)range; /** * @brief Returns whether the specified character is a member of the character * set. * * @param character The character that is checked for being a member of the * character set * @return Whether the specified character is a member of the character set. */ - (bool)characterIsMember: (OFUnichar)character; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFCharacterSet.m000066400000000000000000000065741465614216400164150ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFCharacterSet.h" #import "OFBitSetCharacterSet.h" #import "OFInvertedCharacterSet.h" #import "OFOnce.h" #import "OFRangeCharacterSet.h" @interface OFPlaceholderCharacterSet: OFCharacterSet @end @interface OFWhitespaceCharacterSet: OFCharacterSet @end static struct { Class isa; } placeholder; static OFCharacterSet *whitespaceCharacterSet = nil; static void initWhitespaceCharacterSet(void) { whitespaceCharacterSet = [[OFWhitespaceCharacterSet alloc] init]; } @implementation OFPlaceholderCharacterSet - (instancetype)init { return (id)[[OFBitSetCharacterSet alloc] init]; } - (instancetype)initWithCharactersInString: (OFString *)characters { return (id)[[OFBitSetCharacterSet alloc] initWithCharactersInString: characters]; } - (instancetype)initWithRange: (OFRange)range { return (id)[[OFRangeCharacterSet alloc] initWithRange: range]; } OF_SINGLETON_METHODS @end @implementation OFCharacterSet + (void)initialize { if (self == [OFCharacterSet class]) object_setClass((id)&placeholder, [OFPlaceholderCharacterSet class]); } + (instancetype)alloc { if (self == [OFCharacterSet class]) return (id)&placeholder; return [super alloc]; } + (instancetype)characterSetWithCharactersInString: (OFString *)characters { return [[[self alloc] initWithCharactersInString: characters] autorelease]; } + (instancetype)characterSetWithRange: (OFRange)range { return [[[self alloc] initWithRange: range] autorelease]; } + (OFCharacterSet *)whitespaceCharacterSet { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, initWhitespaceCharacterSet); return whitespaceCharacterSet; } - (instancetype)init { if ([self isMemberOfClass: [OFCharacterSet class]]) { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @throw e; } abort(); } return [super init]; } - (instancetype)initWithCharactersInString: (OFString *)characters { OF_INVALID_INIT_METHOD } - (instancetype)initWithRange: (OFRange)range { OF_INVALID_INIT_METHOD } - (bool)characterIsMember: (OFUnichar)character { OF_UNRECOGNIZED_SELECTOR } - (OFCharacterSet *)invertedSet { return [[[OFInvertedCharacterSet alloc] initWithCharacterSet: self] autorelease]; } @end @implementation OFWhitespaceCharacterSet - (bool)characterIsMember: (OFUnichar)character { switch (character) { case 0x0009: case 0x0020: case 0x00A0: case 0x1680: case 0x2000: case 0x2001: case 0x2002: case 0x2003: case 0x2004: case 0x2005: case 0x2006: case 0x2007: case 0x2008: case 0x2009: case 0x200A: case 0x202F: case 0x205F: case 0x3000: return true; default: return false; } } OF_SINGLETON_METHODS @end objfw-1.1.6/src/OFCollection.h000066400000000000000000000025661465614216400161300ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFEnumerator.h" OF_ASSUME_NONNULL_BEGIN /** * @protocol OFCollection OFCollection.h ObjFW/OFCollection.h * * @brief A protocol with methods common for all collections. */ @protocol OFCollection /** * @brief The number of objects in the collection */ @property (readonly, nonatomic) size_t count; /** * @brief Checks whether the collection contains an object equal to the * specified object. * * @param object The object which is checked for being in the collection * @return A boolean whether the collection contains the specified object */ - (bool)containsObject: (id)object; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFColor.h000066400000000000000000000137751465614216400151170ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFColor OFColor.h ObjFW/OFColor.h * * @brief A class for storing a color. */ @interface OFColor: OFObject #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nonatomic) OFColor *black; @property (class, readonly, nonatomic) OFColor *silver; @property (class, readonly, nonatomic) OFColor *gray; @property (class, readonly, nonatomic) OFColor *grey OF_DEPRECATED(ObjFW, 1, 1, "Use gray instead"); @property (class, readonly, nonatomic) OFColor *white; @property (class, readonly, nonatomic) OFColor *maroon; @property (class, readonly, nonatomic) OFColor *red; @property (class, readonly, nonatomic) OFColor *purple; @property (class, readonly, nonatomic) OFColor *fuchsia; @property (class, readonly, nonatomic) OFColor *green; @property (class, readonly, nonatomic) OFColor *lime; @property (class, readonly, nonatomic) OFColor *olive; @property (class, readonly, nonatomic) OFColor *yellow; @property (class, readonly, nonatomic) OFColor *navy; @property (class, readonly, nonatomic) OFColor *blue; @property (class, readonly, nonatomic) OFColor *teal; @property (class, readonly, nonatomic) OFColor *aqua; #endif /** * @brief Creates a new color with the specified red, green, blue and alpha * value. * * @param red The red value of the color, between 0.0 and 1.0 * @param green The green value of the color, between 0.0 and 1.0 * @param blue The blue value of the color, between 0.0 and 1.0 * @param alpha The alpha value of the color, between 0.0 and 1.0 * @return A new color with the specified red, green, blue and alpha value */ + (instancetype)colorWithRed: (float)red green: (float)green blue: (float)blue alpha: (float)alpha; /** * @brief Returns the HTML color `black`. * * The RGBA value is (0, 0, 0, 1). * * @return The HTML color `black` */ + (OFColor *)black; /** * @brief Returns the HTML color `silver`. * * The RGBA value is (0.75, 0.75, 0.75, 1). * * @return The HTML color `silver` */ + (OFColor *)silver; /** * @brief Returns the HTML color `gray`. * * The RGBA value is (0.5, 0.5, 0.5, 1). * * @return The HTML color `gray` */ + (OFColor *)gray; /** * @brief Returns the HTML color `gray`. * * @deprecated Use @ref gray instead. * * The RGBA value is (0.5, 0.5, 0.5, 1). * * @return The HTML color `gray` */ + (OFColor *)grey OF_DEPRECATED(ObjFW, 1, 1, "Use gray instead"); /** * @brief Returns the HTML color `white`. * * The RGBA value is (1, 1, 1, 1). * * @return The HTML color `white` */ + (OFColor *)white; /** * @brief Returns the HTML color `maroon`. * * The RGBA value is (0.5, 0, 0, 1). * * @return The HTML color `maroon` */ + (OFColor *)maroon; /** * @brief Returns the HTML color `red`. * * The RGBA value is (1, 0, 0, 1). * * @return The HTML color `red` */ + (OFColor *)red; /** * @brief Returns the HTML color `purple`. * * The RGBA value is (0.5, 0, 0.5, 1). * * @return The HTML color `purple` */ + (OFColor *)purple; /** * @brief Returns the HTML color `fuchsia`. * * The RGBA value is (1, 0, 1, 1). * * @return The HTML color `fuchsia` */ + (OFColor *)fuchsia; /** * @brief Returns the HTML color `green`. * * The RGBA value is (0, 0.5, 0, 1). * * @return The HTML color `green` */ + (OFColor *)green; /** * @brief Returns the HTML color `lime`. * * The RGBA value is (0, 1, 0, 1). * * @return The HTML color `lime` */ + (OFColor *)lime; /** * @brief Returns the HTML color `olive`. * * The RGBA value is (0.5, 0.5, 0, 1). * * @return The HTML color `olive` */ + (OFColor *)olive; /** * @brief Returns the HTML color `yellow`. * * The RGBA value is (1, 1, 0, 1). * * @return The HTML color `yellow` */ + (OFColor *)yellow; /** * @brief Returns the HTML color `navy`. * * The RGBA value is (0, 0, 0.5, 1). * * @return The HTML color `navy` */ + (OFColor *)navy; /** * @brief Returns the HTML color `blue`. * * The RGBA value is (0, 0, 1, 1). * * @return The HTML color `blue` */ + (OFColor *)blue; /** * @brief Returns the HTML color `teal`. * * The RGBA value is (0, 0.5, 0.5, 1). * * @return The HTML color `teal` */ + (OFColor *)teal; /** * @brief Returns the HTML color `aqua`. * * The RGBA value is (0, 1, 1, 1). * * @return The HTML color `aqua` */ + (OFColor *)aqua; /** * @brief Initializes an already allocated color with the specified red, green, * blue and alpha value. * * @param red The red value of the color, between 0.0 and 1.0 * @param green The green value of the color, between 0.0 and 1.0 * @param blue The blue value of the color, between 0.0 and 1.0 * @param alpha The alpha value of the color, between 0.0 and 1.0 * @return A color initialized with the specified red, green, blue and alpha * value */ - (instancetype)initWithRed: (float)red green: (float)green blue: (float)blue alpha: (float)alpha; /** * @brief Returns the red, green, blue and alpha value of the color. * * @param red A pointer to store the red value of the color * @param green A pointer to store the green value of the color * @param blue A pointer to store the blue value of the color * @param alpha An optional pointer to store the alpha of the color */ - (void)getRed: (float *)red green: (float *)green blue: (float *)blue alpha: (nullable float *)alpha; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFColor.m000066400000000000000000000134541465614216400151160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFColor.h" #import "OFConcreteColor.h" #import "OFOnce.h" #import "OFString.h" #import "OFTaggedPointerColor.h" @interface OFPlaceholderColor: OFColor @end @interface OFConcreteColorSingleton: OFConcreteColor @end static struct { Class isa; } placeholder; #ifdef OF_OBJFW_RUNTIME static const float allowedImprecision = 0.0000001; #endif @implementation OFPlaceholderColor - (instancetype)initWithRed: (float)red green: (float)green blue: (float)blue alpha: (float)alpha { #ifdef OF_OBJFW_RUNTIME uint8_t redInt = roundf(red * 255); uint8_t greenInt = roundf(green * 255); uint8_t blueInt = roundf(blue * 255); if (fabsf(red * 255 - redInt) < allowedImprecision && fabsf(green * 255 - greenInt) < allowedImprecision && fabsf(blue * 255 - blueInt) < allowedImprecision && alpha == 1) { id ret = [OFTaggedPointerColor colorWithRed: redInt green: greenInt blue: blueInt]; if (ret != nil) return ret; } #endif return (id)[[OFConcreteColor alloc] initWithRed: red green: green blue: blue alpha: alpha]; } OF_SINGLETON_METHODS @end @implementation OFConcreteColorSingleton OF_SINGLETON_METHODS @end @implementation OFColor + (void)initialize { if (self == [OFColor class]) object_setClass((id)&placeholder, [OFPlaceholderColor class]); } + (instancetype)alloc { if (self == [OFColor class]) return (id)&placeholder; return [super alloc]; } #define PREDEFINED_COLOR(name, redValue, greenValue, blueValue) \ static OFColor *name##Color = nil; \ \ static void \ initPredefinedColor_##name(void) \ { \ name##Color = [[OFConcreteColorSingleton alloc] \ initWithRed: redValue \ green: greenValue \ blue: blueValue \ alpha: 1]; \ } \ \ + (OFColor *)name \ { \ static OFOnceControl onceControl = OFOnceControlInitValue; \ OFOnce(&onceControl, initPredefinedColor_##name); \ \ return name##Color; \ } PREDEFINED_COLOR(black, 0.00f, 0.00f, 0.00f) PREDEFINED_COLOR(silver, 0.75f, 0.75f, 0.75f) PREDEFINED_COLOR(gray, 0.50f, 0.50f, 0.50f) PREDEFINED_COLOR(white, 1.00f, 1.00f, 1.00f) PREDEFINED_COLOR(maroon, 0.50f, 0.00f, 0.00f) PREDEFINED_COLOR(red, 1.00f, 0.00f, 0.00f) PREDEFINED_COLOR(purple, 0.50f, 0.00f, 0.50f) PREDEFINED_COLOR(fuchsia, 1.00f, 0.00f, 1.00f) PREDEFINED_COLOR(green, 0.00f, 0.50f, 0.00f) PREDEFINED_COLOR(lime, 0.00f, 1.00f, 0.00f) PREDEFINED_COLOR(olive, 0.50f, 0.50f, 0.00f) PREDEFINED_COLOR(yellow, 1.00f, 1.00f, 0.00f) PREDEFINED_COLOR(navy, 0.00f, 0.00f, 0.50f) PREDEFINED_COLOR(blue, 0.00f, 0.00f, 1.00f) PREDEFINED_COLOR(teal, 0.00f, 0.50f, 0.50f) PREDEFINED_COLOR(aqua, 0.00f, 1.00f, 1.00f) + (OFColor *)grey { return [self gray]; } + (instancetype)colorWithRed: (float)red green: (float)green blue: (float)blue alpha: (float)alpha { return [[[self alloc] initWithRed: red green: green blue: blue alpha: alpha] autorelease]; } - (instancetype)initWithRed: (float)red green: (float)green blue: (float)blue alpha: (float)alpha { if ([self isMemberOfClass: [OFColor class]]) { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @throw e; } abort(); } return [super init]; } - (bool)isEqual: (id)object { OFColor *other; float red, green, blue, alpha; float otherRed, otherGreen, otherBlue, otherAlpha; if (object == self) return true; if (![object isKindOfClass: [OFColor class]]) return false; other = object; [self getRed: &red green: &green blue: &blue alpha: &alpha]; [other getRed: &otherRed green: &otherGreen blue: &otherBlue alpha: &otherAlpha]; if (otherRed != red) return false; if (otherGreen != green) return false; if (otherBlue != blue) return false; if (otherAlpha != alpha) return false; return true; } - (unsigned long)hash { float red, green, blue, alpha; unsigned long hash; float tmp; [self getRed: &red green: &green blue: &blue alpha: &alpha]; OFHashInit(&hash); tmp = OFToLittleEndianFloat(red); for (uint_fast8_t i = 0; i < sizeof(float); i++) OFHashAddByte(&hash, ((char *)&tmp)[i]); tmp = OFToLittleEndianFloat(green); for (uint_fast8_t i = 0; i < sizeof(float); i++) OFHashAddByte(&hash, ((char *)&tmp)[i]); tmp = OFToLittleEndianFloat(blue); for (uint_fast8_t i = 0; i < sizeof(float); i++) OFHashAddByte(&hash, ((char *)&tmp)[i]); tmp = OFToLittleEndianFloat(alpha); for (uint_fast8_t i = 0; i < sizeof(float); i++) OFHashAddByte(&hash, ((char *)&tmp)[i]); OFHashFinalize(&hash); return hash; } - (void)getRed: (float *)red green: (float *)green blue: (float *)blue alpha: (float *)alpha { OF_UNRECOGNIZED_SELECTOR } - (OFString *)description { float red, green, blue, alpha; [self getRed: &red green: &green blue: &blue alpha: &alpha]; return [OFString stringWithFormat: @"<%@ red=%f green=%f blue=%f alpha=%f>", self.class, red, green, blue, alpha]; } @end objfw-1.1.6/src/OFConcreteArray.h000066400000000000000000000015751465614216400165750ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFArray.h" OF_ASSUME_NONNULL_BEGIN @class OFMutableData; @interface OFConcreteArray: OFArray { OFMutableData *_array; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFConcreteArray.m000066400000000000000000000147171465614216400166040ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFConcreteArray.h" #import "OFConcreteMutableArray.h" #import "OFConcreteSubarray.h" #import "OFData.h" #import "OFString.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" @implementation OFConcreteArray - (instancetype)init { self = [super init]; @try { _array = [[OFMutableData alloc] initWithItemSize: sizeof(id)]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithObject: (id)object { self = [self init]; @try { if (object == nil) @throw [OFInvalidArgumentException exception]; [_array addItem: &object]; [object retain]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments { self = [self init]; @try { id object; [_array addItem: &firstObject]; [firstObject retain]; while ((object = va_arg(arguments, id)) != nil) { [_array addItem: &object]; [object retain]; } } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithArray: (OFArray *)array { id const *objects; size_t count; self = [super init]; if (array == nil) return self; @try { objects = array.objects; count = array.count; _array = [[OFMutableData alloc] initWithItemSize: sizeof(id) capacity: count]; } @catch (id e) { [self release]; @throw e; } @try { for (size_t i = 0; i < count; i++) [objects[i] retain]; [_array addItems: objects count: count]; } @catch (id e) { for (size_t i = 0; i < count; i++) [objects[i] release]; /* Prevent double-release of objects */ [_array release]; _array = nil; [self release]; @throw e; } return self; } - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { self = [super init]; @try { bool ok = true; for (size_t i = 0; i < count; i++) { if (objects[i] == nil) ok = false; [objects[i] retain]; } if (!ok) @throw [OFInvalidArgumentException exception]; _array = [[OFMutableData alloc] initWithItemSize: sizeof(id) capacity: count]; [_array addItems: objects count: count]; } @catch (id e) { for (size_t i = 0; i < count; i++) [objects[i] release]; [self release]; @throw e; } return self; } - (size_t)count { return _array.count; } - (id const *)objects { return _array.items; } - (id)objectAtIndex: (size_t)idx { return *((id *)[_array itemAtIndex: idx]); } - (id)objectAtIndexedSubscript: (size_t)idx { return *((id *)[_array itemAtIndex: idx]); } - (void)getObjects: (id *)buffer inRange: (OFRange)range { id const *objects = _array.items; size_t count = _array.count; if (range.length > SIZE_MAX - range.location || range.location + range.length > count) @throw [OFOutOfRangeException exception]; for (size_t i = 0; i < range.length; i++) buffer[i] = objects[range.location + i]; } - (size_t)indexOfObject: (id)object { id const *objects; size_t count; if (object == nil) return OFNotFound; objects = _array.items; count = _array.count; for (size_t i = 0; i < count; i++) if ([objects[i] isEqual: object]) return i; return OFNotFound; } - (size_t)indexOfObjectIdenticalTo: (id)object { id const *objects; size_t count; if (object == nil) return OFNotFound; objects = _array.items; count = _array.count; for (size_t i = 0; i < count; i++) if (objects[i] == object) return i; return OFNotFound; } - (OFArray *)objectsInRange: (OFRange)range { if (range.length > SIZE_MAX - range.location || range.location + range.length > _array.count) @throw [OFOutOfRangeException exception]; if ([self isKindOfClass: [OFMutableArray class]]) return [OFArray arrayWithObjects: (id *)_array.items + range.location count: range.length]; return [[[OFConcreteSubarray alloc] initWithArray: self range: range] autorelease]; } - (bool)isEqual: (id)object { OFArray *otherArray; id const *objects, *otherObjects; size_t count; if (object == self) return true; if (![object isKindOfClass: [OFConcreteArray class]] && ![object isKindOfClass: [OFConcreteMutableArray class]]) return [super isEqual: object]; otherArray = object; count = _array.count; if (count != otherArray.count) return false; objects = _array.items; otherObjects = otherArray.objects; for (size_t i = 0; i < count; i++) if (![objects[i] isEqual: otherObjects[i]]) return false; return true; } - (unsigned long)hash { id const *objects = _array.items; size_t count = _array.count; unsigned long hash; OFHashInit(&hash); for (size_t i = 0; i < count; i++) OFHashAddHash(&hash, [objects[i] hash]); OFHashFinalize(&hash); return hash; } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count_ { static unsigned long dummyMutations; size_t count = _array.count; if (count > INT_MAX) /* * Use the implementation from OFArray, which is slower, but can * enumerate in chunks. */ return [super countByEnumeratingWithState: state objects: objects count: count_]; if (state->state >= count) return 0; state->state = (unsigned long)count; state->itemsPtr = (id *)_array.items; state->mutationsPtr = &dummyMutations; return (int)count; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (OFArrayEnumerationBlock)block { id const *objects = _array.items; size_t count = _array.count; bool stop = false; for (size_t i = 0; i < count && !stop; i++) block(objects[i], i, &stop); } #endif - (void)dealloc { id const *objects = _array.items; size_t count = _array.count; for (size_t i = 0; i < count; i++) [objects[i] release]; [_array release]; [super dealloc]; } @end objfw-1.1.6/src/OFConcreteColor.h000066400000000000000000000015621465614216400165710ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFColor.h" OF_ASSUME_NONNULL_BEGIN @interface OFConcreteColor: OFColor { float _red, _green, _blue, _alpha; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFConcreteColor.m000066400000000000000000000027731465614216400166030ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFConcreteColor.h" #import "OFInvalidArgumentException.h" @implementation OFConcreteColor - (instancetype)initWithRed: (float)red green: (float)green blue: (float)blue alpha: (float)alpha { self = [super init]; @try { if (red < 0.0 || red > 1.0 || green < 0.0 || green > 1.0 || blue < 0.0 || blue > 1.0 || alpha < 0.0 || alpha > 1.0) @throw [OFInvalidArgumentException exception]; _red = red; _green = green; _blue = blue; _alpha = alpha; } @catch (id e) { [self release]; @throw e; } return self; } - (void)getRed: (float *)red green: (float *)green blue: (float *)blue alpha: (float *)alpha { *red = _red; *green = _green; *blue = _blue; if (alpha != NULL) *alpha = _alpha; } @end objfw-1.1.6/src/OFConcreteCountedSet.h000066400000000000000000000016111465614216400175630ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFCountedSet.h" OF_ASSUME_NONNULL_BEGIN @class OFMapTable; @interface OFConcreteCountedSet: OFCountedSet { OFMapTable *_mapTable; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFConcreteCountedSet.m000066400000000000000000000073101465614216400175720ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFConcreteCountedSet.h" #import "OFArray.h" #import "OFConcreteMutableSet.h" #import "OFMapTable.h" #import "OFString.h" #import "OFXMLAttribute.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFEnumerationMutationException.h" #import "OFOutOfRangeException.h" @implementation OFConcreteCountedSet + (void)initialize { if (self == [OFConcreteCountedSet class]) [self inheritMethodsFromClass: [OFConcreteMutableSet class]]; } - (instancetype)initWithSet: (OFSet *)set { self = [self init]; @try { void *pool = objc_autoreleasePoolPush(); if ([set isKindOfClass: [OFCountedSet class]]) { OFCountedSet *countedSet = (OFCountedSet *)set; for (id object in countedSet) { size_t count = [countedSet countForObject: object]; for (size_t i = 0; i < count; i++) [self addObject: object]; } } else for (id object in set) [self addObject: object]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithArray: (OFArray *)array { self = [self init]; @try { id const *objects = array.objects; size_t count = array.count; for (size_t i = 0; i < count; i++) [self addObject: objects[i]]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { self = [self init]; @try { for (size_t i = 0; i < count; i++) [self addObject: objects[i]]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments { self = [self init]; @try { id object; [self addObject: firstObject]; while ((object = va_arg(arguments, id)) != nil) [self addObject: object]; } @catch (id e) { [self release]; @throw e; } return self; } - (size_t)countForObject: (id)object { return (size_t)(uintptr_t)[_mapTable objectForKey: object]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsAndCountUsingBlock: (OFCountedSetEnumerationBlock)block { @try { [_mapTable enumerateKeysAndObjectsUsingBlock: ^ (void *key, void *object, bool *stop) { block(key, (size_t)(uintptr_t)object, stop); }]; } @catch (OFEnumerationMutationException *e) { @throw [OFEnumerationMutationException exceptionWithObject: self]; } } #endif - (void)addObject: (id)object { size_t count = (size_t)(uintptr_t)[_mapTable objectForKey: object]; if (SIZE_MAX - count < 1 || UINTPTR_MAX - count < 1) @throw [OFOutOfRangeException exception]; [_mapTable setObject: (void *)(uintptr_t)(count + 1) forKey: object]; } - (void)removeObject: (id)object { size_t count = (size_t)(uintptr_t)[_mapTable objectForKey: object]; if (count == 0) return; count--; if (count > 0) [_mapTable setObject: (void *)(uintptr_t)count forKey: object]; else [_mapTable removeObjectForKey: object]; } - (void)removeAllObjects { [_mapTable removeAllObjects]; } - (void)makeImmutable { } @end objfw-1.1.6/src/OFConcreteData.h000066400000000000000000000016501465614216400163620ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFData.h" OF_ASSUME_NONNULL_BEGIN @interface OFConcreteData: OFData { unsigned char *_Nullable _items; size_t _capacity, _count, _itemSize; bool _freeWhenDone; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFConcreteData.m000066400000000000000000000045071465614216400163730ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "OFConcreteData.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" @implementation OFConcreteData - (instancetype)init { return [self initWithItemSize: 1]; } - (instancetype)initWithItemSize: (size_t)itemSize { self = [super init]; @try { if (itemSize == 0) @throw [OFInvalidArgumentException exception]; _itemSize = itemSize; _freeWhenDone = true; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithItems: (const void *)items count: (size_t)count itemSize: (size_t)itemSize { self = [super init]; @try { if (itemSize == 0) @throw [OFInvalidArgumentException exception]; _items = OFAllocMemory(count, itemSize); _capacity = _count = count; _itemSize = itemSize; _freeWhenDone = true; memcpy(_items, items, count * itemSize); } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithItemsNoCopy: (void *)items count: (size_t)count itemSize: (size_t)itemSize freeWhenDone: (bool)freeWhenDone { self = [super init]; @try { if (itemSize == 0) @throw [OFInvalidArgumentException exception]; _items = (unsigned char *)items; _capacity = _count = count; _itemSize = itemSize; _freeWhenDone = freeWhenDone; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_freeWhenDone) OFFreeMemory(_items); [super dealloc]; } - (size_t)count { return _count; } - (size_t)itemSize { return _itemSize; } - (const void *)items { return _items; } @end objfw-1.1.6/src/OFConcreteDate.h000066400000000000000000000015451465614216400163710ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFDate.h" OF_ASSUME_NONNULL_BEGIN @interface OFConcreteDate: OFDate { OFTimeInterval _seconds; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFConcreteDate.m000066400000000000000000000020031465614216400163640ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFConcreteDate.h" @implementation OFConcreteDate - (instancetype)initWithTimeIntervalSince1970: (OFTimeInterval)seconds { self = [super initWithTimeIntervalSince1970: seconds]; _seconds = seconds; return self; } - (OFTimeInterval)timeIntervalSince1970 { return _seconds; } @end objfw-1.1.6/src/OFConcreteDictionary.h000066400000000000000000000017331465614216400176200ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFDictionary.h" OF_ASSUME_NONNULL_BEGIN @class OFMapTable; @class OFMapTableEnumerator; @interface OFConcreteDictionary: OFDictionary { OFMapTable *_mapTable; } - (instancetype)initWithCapacity: (size_t)capacity; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFConcreteDictionary.m000066400000000000000000000167331465614216400176330ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFConcreteDictionary.h" #import "OFArray.h" #import "OFConcreteMutableDictionary.h" #import "OFMapTable+Private.h" #import "OFMapTable.h" #import "OFString.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" static void * copy(void *object) { return [(id)object copy]; } static void * retain(void *object) { return [(id)object retain]; } static void release(void *object) { [(id)object release]; } static unsigned long hash(void *object) { return [(id)object hash]; } static bool equal(void *object1, void *object2) { return [(id)object1 isEqual: (id)object2]; } static const OFMapTableFunctions keyFunctions = { .retain = copy, .release = release, .hash = hash, .equal = equal }; static const OFMapTableFunctions objectFunctions = { .retain = retain, .release = release, .hash = hash, .equal = equal }; @implementation OFConcreteDictionary - (instancetype)init { return [self initWithCapacity: 0]; } - (instancetype)initWithCapacity: (size_t)capacity { self = [super init]; @try { _mapTable = [[OFMapTable alloc] initWithKeyFunctions: keyFunctions objectFunctions: objectFunctions capacity: capacity]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithDictionary: (OFDictionary *)dictionary { size_t count; if (dictionary == nil) return [self init]; if ([dictionary isKindOfClass: [OFConcreteDictionary class]] || [dictionary isKindOfClass: [OFConcreteMutableDictionary class]]) { self = [super init]; @try { OFConcreteDictionary *dictionary_ = (OFConcreteDictionary *)dictionary; _mapTable = [dictionary_->_mapTable copy]; } @catch (id e) { [self release]; @throw e; } return self; } @try { count = dictionary.count; } @catch (id e) { [self release]; @throw e; } self = [self initWithCapacity: count]; @try { void *pool = objc_autoreleasePoolPush(); OFEnumerator *keyEnumerator, *objectEnumerator; id key, object; keyEnumerator = [dictionary keyEnumerator]; objectEnumerator = [dictionary objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) [_mapTable setObject: object forKey: key]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithObject: (id)object forKey: (id)key { self = [self initWithCapacity: 1]; @try { [_mapTable setObject: object forKey: key]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithObjects: (id const *)objects forKeys: (id const *)keys count: (size_t)count { self = [self initWithCapacity: count]; @try { size_t i; for (i = 0; i < count; i++) [_mapTable setObject: objects[i] forKey: keys[i]]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithKey: (id)firstKey arguments: (va_list)arguments { self = [super init]; @try { va_list argumentsCopy; id key, object; size_t i, count; va_copy(argumentsCopy, arguments); if (firstKey == nil) @throw [OFInvalidArgumentException exception]; key = firstKey; if ((object = va_arg(arguments, id)) == nil) @throw [OFInvalidArgumentException exception]; count = 1; for (; va_arg(argumentsCopy, id) != nil; count++); if (count % 2 != 0) @throw [OFInvalidArgumentException exception]; count /= 2; _mapTable = [[OFMapTable alloc] initWithKeyFunctions: keyFunctions objectFunctions: objectFunctions capacity: count]; [_mapTable setObject: object forKey: key]; for (i = 1; i < count; i++) { key = va_arg(arguments, id); object = va_arg(arguments, id); if (key == nil || object == nil) @throw [OFInvalidArgumentException exception]; [_mapTable setObject: object forKey: key]; } } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_mapTable release]; [super dealloc]; } - (id)objectForKey: (id)key { return [_mapTable objectForKey: key]; } - (size_t)count { return _mapTable.count; } - (bool)isEqual: (id)object { OFConcreteDictionary *dictionary; if (object == self) return true; if (![object isKindOfClass: [OFConcreteDictionary class]] && ![object isKindOfClass: [OFConcreteMutableDictionary class]]) return [super isEqual: object]; dictionary = (OFConcreteDictionary *)object; return [dictionary->_mapTable isEqual: _mapTable]; } - (bool)containsObject: (id)object { return [_mapTable containsObject: object]; } - (bool)containsObjectIdenticalTo: (id)object { return [_mapTable containsObjectIdenticalTo: object]; } - (OFArray *)allKeys { OFArray *ret; id *keys; size_t count; count = _mapTable.count; keys = OFAllocMemory(count, sizeof(*keys)); @try { void *pool = objc_autoreleasePoolPush(); OFMapTableEnumerator *enumerator; void **keyPtr; size_t i; i = 0; enumerator = [_mapTable keyEnumerator]; while ((keyPtr = [enumerator nextObject]) != NULL) { OFAssert(i < count); keys[i++] = (id)*keyPtr; } objc_autoreleasePoolPop(pool); ret = [OFArray arrayWithObjects: keys count: count]; } @finally { OFFreeMemory(keys); } return ret; } - (OFArray *)allObjects { OFArray *ret; id *objects; size_t count; count = _mapTable.count; objects = OFAllocMemory(count, sizeof(*objects)); @try { void *pool = objc_autoreleasePoolPush(); OFMapTableEnumerator *enumerator; void **objectPtr; size_t i; i = 0; enumerator = [_mapTable objectEnumerator]; while ((objectPtr = [enumerator nextObject]) != NULL) { OFAssert(i < count); objects[i++] = (id)*objectPtr; } objc_autoreleasePoolPop(pool); ret = [OFArray arrayWithObjects: objects count: count]; } @finally { OFFreeMemory(objects); } return ret; } - (OFEnumerator *)keyEnumerator { return [[[OFMapTableEnumeratorWrapper alloc] initWithEnumerator: [_mapTable keyEnumerator] object: self] autorelease]; } - (OFEnumerator *)objectEnumerator { return [[[OFMapTableEnumeratorWrapper alloc] initWithEnumerator: [_mapTable objectEnumerator] object: self] autorelease]; } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count { return [_mapTable countByEnumeratingWithState: state objects: objects count: count]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateKeysAndObjectsUsingBlock: (OFDictionaryEnumerationBlock)block { @try { [_mapTable enumerateKeysAndObjectsUsingBlock: ^ (void *key, void *object, bool *stop) { block(key, object, stop); }]; } @catch (OFEnumerationMutationException *e) { @throw [OFEnumerationMutationException exceptionWithObject: self]; } } #endif - (unsigned long)hash { return _mapTable.hash; } @end objfw-1.1.6/src/OFConcreteMutableArray.h000066400000000000000000000016461465614216400201060ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFArray.h" OF_ASSUME_NONNULL_BEGIN @class OFMutableData; @interface OFConcreteMutableArray: OFMutableArray { OFMutableData *_array; unsigned long _mutations; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFConcreteMutableArray.m000066400000000000000000000173471465614216400201200ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFConcreteMutableArray.h" #import "OFConcreteArray.h" #import "OFArray+Private.h" #import "OFData.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" @implementation OFConcreteMutableArray + (void)initialize { if (self == [OFConcreteMutableArray class]) [self inheritMethodsFromClass: [OFConcreteArray class]]; } - (instancetype)initWithCapacity: (size_t)capacity { self = [super init]; @try { _array = [[OFMutableData alloc] initWithItemSize: sizeof(id) capacity: capacity]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)addObject: (id)object { if (object == nil) @throw [OFInvalidArgumentException exception]; [_array addItem: &object]; [object retain]; _mutations++; } - (void)insertObject: (id)object atIndex: (size_t)idx { if (object == nil) @throw [OFInvalidArgumentException exception]; @try { [_array insertItem: &object atIndex: idx]; } @catch (OFOutOfRangeException *e) { @throw [OFOutOfRangeException exception]; } [object retain]; _mutations++; } - (void)insertObjectsFromArray: (OFArray *)array atIndex: (size_t)idx { id const *objects = array.objects; size_t count = array.count; @try { [_array insertItems: objects atIndex: idx count: count]; } @catch (OFOutOfRangeException *e) { @throw [OFOutOfRangeException exception]; } for (size_t i = 0; i < count; i++) [objects[i] retain]; _mutations++; } - (void)replaceObject: (id)oldObject withObject: (id)newObject { id *objects; size_t count; if (oldObject == nil || newObject == nil) @throw [OFInvalidArgumentException exception]; objects = _array.mutableItems; count = _array.count; for (size_t i = 0; i < count; i++) { if ([objects[i] isEqual: oldObject]) { [newObject retain]; [objects[i] release]; objects[i] = newObject; } } } - (void)replaceObjectAtIndex: (size_t)idx withObject: (id)object { id *objects; id oldObject; if (object == nil) @throw [OFInvalidArgumentException exception]; objects = _array.mutableItems; if (idx >= _array.count) @throw [OFOutOfRangeException exception]; oldObject = objects[idx]; objects[idx] = [object retain]; [oldObject release]; } - (void)replaceObjectIdenticalTo: (id)oldObject withObject: (id)newObject { id *objects; size_t count; if (oldObject == nil || newObject == nil) @throw [OFInvalidArgumentException exception]; objects = _array.mutableItems; count = _array.count; for (size_t i = 0; i < count; i++) { if (objects[i] == oldObject) { [newObject retain]; [objects[i] release]; objects[i] = newObject; return; } } } - (void)removeObject: (id)object { id const *objects; size_t count; if (object == nil) @throw [OFInvalidArgumentException exception]; objects = _array.items; count = _array.count; for (size_t i = 0; i < count; i++) { if ([objects[i] isEqual: object]) { id tmp = objects[i]; [_array removeItemAtIndex: i]; _mutations++; [tmp release]; objects = _array.items; i--; count--; continue; } } } - (void)removeObjectIdenticalTo: (id)object { id const *objects; size_t count; if (object == nil) @throw [OFInvalidArgumentException exception]; objects = _array.items; count = _array.count; for (size_t i = 0; i < count; i++) { if (objects[i] == object) { [_array removeItemAtIndex: i]; _mutations++; [object release]; objects = _array.items; i--; count--; continue; } } } - (void)removeObjectAtIndex: (size_t)idx { #ifndef __clang_analyzer__ id object = [self objectAtIndex: idx]; [_array removeItemAtIndex: idx]; [object release]; _mutations++; #endif } - (void)removeAllObjects { id const *objects = _array.items; size_t count = _array.count; for (size_t i = 0; i < count; i++) [objects[i] release]; [_array removeAllItems]; } - (void)removeObjectsInRange: (OFRange)range { id const *objects = _array.items; size_t count = _array.count; id *copy; if (range.length > SIZE_MAX - range.location || range.location >= count || range.length > count - range.location) @throw [OFOutOfRangeException exception]; copy = OFAllocMemory(range.length, sizeof(*copy)); memcpy(copy, objects + range.location, range.length * sizeof(id)); @try { [_array removeItemsInRange: range]; _mutations++; for (size_t i = 0; i < range.length; i++) [copy[i] release]; } @finally { OFFreeMemory(copy); } } - (void)removeLastObject { #ifndef __clang_analyzer__ size_t count = _array.count; id object; if (count == 0) return; object = [self objectAtIndex: count - 1]; [_array removeLastItem]; [object release]; _mutations++; #endif } - (void)exchangeObjectAtIndex: (size_t)idx1 withObjectAtIndex: (size_t)idx2 { id *objects = _array.mutableItems; size_t count = _array.count; id tmp; if (idx1 >= count || idx2 >= count) @throw [OFOutOfRangeException exception]; tmp = objects[idx1]; objects[idx1] = objects[idx2]; objects[idx2] = tmp; } - (void)reverse { id *objects = _array.mutableItems; size_t i, j, count = _array.count; if (count == 0 || count == 1) return; for (i = 0, j = count - 1; i < j; i++, j--) { id tmp = objects[i]; objects[i] = objects[j]; objects[j] = tmp; } } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count_ { size_t count = _array.count; if (count > INT_MAX) { /* * Use the implementation from OFArray (OFMutableArray does not * have one), which is slower, but can enumerate in chunks, and * set the mutations pointer. */ int ret = [super countByEnumeratingWithState: state objects: objects count: count_]; state->mutationsPtr = &_mutations; return ret; } if (state->state >= count) return 0; state->state = (unsigned long)count; state->itemsPtr = (id *)_array.items; state->mutationsPtr = &_mutations; return (int)count; } - (OFEnumerator *)objectEnumerator { return [[[OFArrayEnumerator alloc] initWithArray: self mutationsPtr: &_mutations] autorelease]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (OFArrayEnumerationBlock)block { id const *objects = _array.items; size_t count = _array.count; bool stop = false; unsigned long mutations = _mutations; for (size_t i = 0; i < count && !stop; i++) { if (_mutations != mutations) @throw [OFEnumerationMutationException exceptionWithObject: self]; block(objects[i], i, &stop); } } - (void)replaceObjectsUsingBlock: (OFArrayReplaceBlock)block { id *objects = _array.mutableItems; size_t count = _array.count; unsigned long mutations = _mutations; for (size_t i = 0; i < count; i++) { id new; if (_mutations != mutations) @throw [OFEnumerationMutationException exceptionWithObject: self]; new = block(objects[i], i); if (new == nil) @throw [OFInvalidArgumentException exception]; if (new != objects[i]) { [objects[i] release]; objects[i] = [new retain]; } } } #endif - (void)makeImmutable { object_setClass(self, [OFConcreteArray class]); } @end objfw-1.1.6/src/OFConcreteMutableData.h000066400000000000000000000016751465614216400177030ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFMutableData.h" OF_ASSUME_NONNULL_BEGIN @interface OFConcreteMutableData: OFMutableData { unsigned char *_Nullable _items; size_t _capacity, _count, _itemSize; bool _freeWhenDone; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFConcreteMutableData.m000066400000000000000000000106551465614216400177060ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "OFConcreteMutableData.h" #import "OFConcreteData.h" #import "OFInvalidArgumentException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" @implementation OFConcreteMutableData + (void)initialize { if (self == [OFConcreteMutableData class]) [self inheritMethodsFromClass: [OFConcreteData class]]; } - (instancetype)initWithItemSize: (size_t)itemSize capacity: (size_t)capacity { self = [super init]; @try { if (itemSize == 0) @throw [OFInvalidArgumentException exception]; _items = OFAllocMemory(capacity, itemSize); _itemSize = itemSize; _capacity = capacity; _freeWhenDone = true; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithItemsNoCopy: (void *)items count: (size_t)count itemSize: (size_t)itemSize freeWhenDone: (bool)freeWhenDone { self = [self initWithItems: items count: count itemSize: itemSize]; if (freeWhenDone) OFFreeMemory(items); return self; } - (void *)mutableItems { return _items; } - (void)addItem: (const void *)item { if (SIZE_MAX - _count < 1) @throw [OFOutOfRangeException exception]; if (_count + 1 > _capacity) { _items = OFResizeMemory(_items, _count + 1, _itemSize); _capacity = _count + 1; } memcpy(_items + _count * _itemSize, item, _itemSize); _count++; } - (void)addItems: (const void *)items count: (size_t)count { if (count > SIZE_MAX - _count) @throw [OFOutOfRangeException exception]; if (_count + count > _capacity) { _items = OFResizeMemory(_items, _count + count, _itemSize); _capacity = _count + count; } memcpy(_items + _count * _itemSize, items, count * _itemSize); _count += count; } - (void)insertItems: (const void *)items atIndex: (size_t)idx count: (size_t)count { if (count > SIZE_MAX - _count || idx > _count) @throw [OFOutOfRangeException exception]; if (_count + count > _capacity) { _items = OFResizeMemory(_items, _count + count, _itemSize); _capacity = _count + count; } memmove(_items + (idx + count) * _itemSize, _items + idx * _itemSize, (_count - idx) * _itemSize); memcpy(_items + idx * _itemSize, items, count * _itemSize); _count += count; } - (void)increaseCountBy: (size_t)count { if (count > SIZE_MAX - _count) @throw [OFOutOfRangeException exception]; if (_count + count > _capacity) { _items = OFResizeMemory(_items, _count + count, _itemSize); _capacity = _count + count; } memset(_items + _count * _itemSize, '\0', count * _itemSize); _count += count; } - (void)removeItemsInRange: (OFRange)range { if (range.length > SIZE_MAX - range.location || range.location + range.length > _count) @throw [OFOutOfRangeException exception]; memmove(_items + range.location * _itemSize, _items + (range.location + range.length) * _itemSize, (_count - range.location - range.length) * _itemSize); _count -= range.length; @try { _items = OFResizeMemory(_items, _count, _itemSize); _capacity = _count; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } - (void)removeLastItem { if (_count == 0) return; _count--; @try { _items = OFResizeMemory(_items, _count, _itemSize); _capacity = _count; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only made it smaller */ } } - (void)removeAllItems { OFFreeMemory(_items); _items = NULL; _count = 0; _capacity = 0; } - (void)makeImmutable { if (_capacity != _count) { @try { _items = OFResizeMemory(_items, _count, _itemSize); _capacity = _count; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only made it smaller */ } } object_setClass(self, [OFConcreteData class]); } @end objfw-1.1.6/src/OFConcreteMutableDictionary.h000066400000000000000000000016271465614216400211340ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFDictionary.h" OF_ASSUME_NONNULL_BEGIN @class OFMapTable; @interface OFConcreteMutableDictionary: OFMutableDictionary { OFMapTable *_mapTable; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFConcreteMutableDictionary.m000066400000000000000000000034121465614216400211330ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFConcreteMutableDictionary.h" #import "OFConcreteDictionary.h" #import "OFMapTable.h" #import "OFEnumerationMutationException.h" #import "OFOutOfRangeException.h" @implementation OFConcreteMutableDictionary + (void)initialize { if (self == [OFConcreteMutableDictionary class]) [self inheritMethodsFromClass: [OFConcreteDictionary class]]; } - (void)setObject: (id)object forKey: (id)key { [_mapTable setObject: object forKey: key]; } - (void)removeObjectForKey: (id)key { [_mapTable removeObjectForKey: key]; } - (void)removeAllObjects { [_mapTable removeAllObjects]; } #ifdef OF_HAVE_BLOCKS - (void)replaceObjectsUsingBlock: (OFDictionaryReplaceBlock)block { @try { [_mapTable replaceObjectsUsingBlock: ^ void *(void *key, void *object) { return block(key, object); }]; } @catch (OFEnumerationMutationException *e) { @throw [OFEnumerationMutationException exceptionWithObject: self]; } } #endif - (void)makeImmutable { object_setClass(self, [OFConcreteDictionary class]); } @end objfw-1.1.6/src/OFConcreteMutableSet.h000066400000000000000000000016111465614216400175530ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFMutableSet.h" OF_ASSUME_NONNULL_BEGIN @class OFMapTable; @interface OFConcreteMutableSet: OFMutableSet { OFMapTable *_mapTable; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFConcreteMutableSet.m000066400000000000000000000024241465614216400175630ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFConcreteMutableSet.h" #import "OFConcreteSet.h" #import "OFMapTable.h" @implementation OFConcreteMutableSet + (void)initialize { if (self == [OFConcreteMutableSet class]) [self inheritMethodsFromClass: [OFConcreteSet class]]; } - (void)addObject: (id)object { [_mapTable setObject: (void *)1 forKey: object]; } - (void)removeObject: (id)object { [_mapTable removeObjectForKey: object]; } - (void)removeAllObjects { [_mapTable removeAllObjects]; } - (void)makeImmutable { object_setClass(self, [OFConcreteSet class]); } @end objfw-1.1.6/src/OFConcreteNumber.h000066400000000000000000000017001465614216400167350ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFNumber.h" OF_ASSUME_NONNULL_BEGIN @interface OFConcreteNumber: OFNumber { union { double float_; long long signed_; unsigned long long unsigned_; } _value; char _typeEncoding; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFConcreteNumber.m000066400000000000000000000127421465614216400167520ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFConcreteNumber.h" #import "OFInvalidFormatException.h" static bool isUnsigned(OFNumber *number) { switch (*number.objCType) { case 'B': case 'C': case 'S': case 'I': case 'L': case 'Q': return true; default: return false; } } static bool isSigned(OFNumber *number) { switch (*number.objCType) { case 'c': case 's': case 'i': case 'l': case 'q': return true; default: return false; } } static bool isFloat(OFNumber *number) { switch (*number.objCType) { case 'f': case 'd': return true; default: return false; } } @implementation OFConcreteNumber - (instancetype)initWithBytes: (const void *)bytes objCType: (const char *)objCType { #define CASE(type, method) \ if (strcmp(objCType, @encode(type)) == 0) { \ type value; \ memcpy(&value, bytes, sizeof(type)); \ return [self method value]; \ } CASE(bool, initWithBool:) CASE(signed char, initWithChar:) CASE(short, initWithShort:) CASE(int, initWithInt:) CASE(long, initWithLong:) CASE(long long, initWithLongLong:) CASE(unsigned char, initWithUnsignedChar:) CASE(unsigned short, initWithUnsignedShort:) CASE(unsigned int, initWithUnsignedInt:) CASE(unsigned long, initWithUnsignedLong:) CASE(unsigned long long, initWithUnsignedLongLong:) CASE(float, initWithFloat:) CASE(double, initWithDouble:) [self release]; @throw [OFInvalidFormatException exception]; } - (instancetype)initWithBool: (bool)value { self = [super initWithBytes: &value objCType: @encode(bool)]; _value.unsigned_ = value; _typeEncoding = *@encode(bool); return self; } - (instancetype)initWithChar: (signed char)value { self = [super initWithBytes: &value objCType: @encode(signed char)]; _value.signed_ = value; _typeEncoding = *@encode(signed char); return self; } - (instancetype)initWithShort: (short)value { self = [super initWithBytes: &value objCType: @encode(short)]; _value.signed_ = value; _typeEncoding = *@encode(short); return self; } - (instancetype)initWithInt: (int)value { self = [super initWithBytes: &value objCType: @encode(int)]; _value.signed_ = value; _typeEncoding = *@encode(int); return self; } - (instancetype)initWithLong: (long)value { self = [super initWithBytes: &value objCType: @encode(long)]; _value.signed_ = value; _typeEncoding = *@encode(long); return self; } - (instancetype)initWithLongLong: (long long)value { self = [super initWithBytes: &value objCType: @encode(long long)]; _value.signed_ = value; _typeEncoding = *@encode(long long); return self; } - (instancetype)initWithUnsignedChar: (unsigned char)value { self = [super initWithBytes: &value objCType: @encode(unsigned char)]; _value.unsigned_ = value; _typeEncoding = *@encode(unsigned long); return self; } - (instancetype)initWithUnsignedShort: (unsigned short)value { self = [super initWithBytes: &value objCType: @encode(unsigned short)]; _value.unsigned_ = value; _typeEncoding = *@encode(unsigned short); return self; } - (instancetype)initWithUnsignedInt: (unsigned int)value { self = [super initWithBytes: &value objCType: @encode(unsigned int)]; _value.unsigned_ = value; _typeEncoding = *@encode(unsigned int); return self; } - (instancetype)initWithUnsignedLong: (unsigned long)value { self = [super initWithBytes: &value objCType: @encode(unsigned long)]; _value.unsigned_ = value; _typeEncoding = *@encode(unsigned long); return self; } - (instancetype)initWithUnsignedLongLong: (unsigned long long)value { self = [super initWithBytes: &value objCType: @encode(unsigned long long)]; _value.unsigned_ = value; _typeEncoding = *@encode(unsigned long long); return self; } - (instancetype)initWithFloat: (float)value { self = [super initWithBytes: &value objCType: @encode(float)]; _value.float_ = value; _typeEncoding = *@encode(float); return self; } - (instancetype)initWithDouble: (double)value { self = [super initWithBytes: &value objCType: @encode(double)]; _value.float_ = value; _typeEncoding = *@encode(double); return self; } - (const char *)objCType { return &_typeEncoding; } - (long long)longLongValue { if (isFloat(self)) return _value.float_; else if (isSigned(self)) return _value.signed_; else if (isUnsigned(self)) return _value.unsigned_; else @throw [OFInvalidFormatException exception]; } - (unsigned long long)unsignedLongLongValue { if (isFloat(self)) return _value.float_; else if (isSigned(self)) return _value.signed_; else if (isUnsigned(self)) return _value.unsigned_; else @throw [OFInvalidFormatException exception]; } - (double)doubleValue { if (isFloat(self)) return _value.float_; else if (isSigned(self)) return _value.signed_; else if (isUnsigned(self)) return _value.unsigned_; else @throw [OFInvalidFormatException exception]; } @end objfw-1.1.6/src/OFConcreteSet.h000066400000000000000000000016511465614216400162450ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFSet.h" OF_ASSUME_NONNULL_BEGIN @class OFMapTable; @interface OFConcreteSet: OFSet { OFMapTable *_mapTable; } - (instancetype)initWithCapacity: (size_t)capacity; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFConcreteSet.m000066400000000000000000000122141465614216400162470ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFConcreteSet.h" #import "OFArray.h" #import "OFConcreteCountedSet.h" #import "OFConcreteMutableSet.h" #import "OFMapTable+Private.h" #import "OFMapTable.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFEnumerationMutationException.h" static void * retain(void *object) { return [(id)object retain]; } static void release(void *object) { [(id)object release]; } static unsigned long hash(void *object) { return [(id)object hash]; } static bool equal(void *object1, void *object2) { return [(id)object1 isEqual: (id)object2]; } static const OFMapTableFunctions keyFunctions = { .retain = retain, .release = release, .hash = hash, .equal = equal }; static const OFMapTableFunctions objectFunctions = { NULL }; @implementation OFConcreteSet - (instancetype)init { return [self initWithCapacity: 0]; } - (instancetype)initWithCapacity: (size_t)capacity { self = [super init]; @try { _mapTable = [[OFMapTable alloc] initWithKeyFunctions: keyFunctions objectFunctions: objectFunctions capacity: capacity]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithSet: (OFSet *)set { size_t count; if (set == nil) return [self init]; @try { count = set.count; } @catch (id e) { [self release]; @throw e; } self = [self initWithCapacity: count]; @try { for (id object in set) [_mapTable setObject: (void *)1 forKey: object]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithArray: (OFArray *)array { size_t count; if (array == nil) return self; @try { count = array.count; } @catch (id e) { [self release]; @throw e; } self = [self initWithCapacity: count]; @try { for (id object in array) [_mapTable setObject: (void *)1 forKey: object]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { self = [self initWithCapacity: count]; @try { for (size_t i = 0; i < count; i++) [_mapTable setObject: (void *)1 forKey: objects[i]]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments { self = [super init]; @try { id object; va_list argumentsCopy; size_t count; va_copy(argumentsCopy, arguments); for (count = 1; va_arg(argumentsCopy, id) != nil; count++); _mapTable = [[OFMapTable alloc] initWithKeyFunctions: keyFunctions objectFunctions: objectFunctions capacity: count]; [_mapTable setObject: (void *)1 forKey: firstObject]; while ((object = va_arg(arguments, id)) != nil) [_mapTable setObject: (void *)1 forKey: object]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_mapTable release]; [super dealloc]; } - (size_t)count { return [_mapTable count]; } - (bool)containsObject: (id)object { if (object == nil) return false; return ([_mapTable objectForKey: object] != nil); } - (bool)isEqual: (id)object { OFConcreteSet *set; if (object == self) return true; if (![object isKindOfClass: [OFConcreteSet class]] && ![object isKindOfClass: [OFConcreteMutableSet class]] && ![object isKindOfClass: [OFConcreteCountedSet class]]) return [super isEqual: object]; set = object; return [set->_mapTable isEqual: _mapTable]; } - (id)anyObject { void *pool = objc_autoreleasePoolPush(); void **objectPtr; id object; objectPtr = [[_mapTable keyEnumerator] nextObject]; if (objectPtr == NULL) { objc_autoreleasePoolPop(pool); return nil; } object = [(id)*objectPtr retain]; objc_autoreleasePoolPop(pool); return [object autorelease]; } - (OFEnumerator *)objectEnumerator { return [[[OFMapTableEnumeratorWrapper alloc] initWithEnumerator: [_mapTable keyEnumerator] object: self] autorelease]; } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count { return [_mapTable countByEnumeratingWithState: state objects: objects count: count]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (OFSetEnumerationBlock)block { @try { [_mapTable enumerateKeysAndObjectsUsingBlock: ^ (void *key, void *object, bool *stop) { block(key, stop); }]; } @catch (OFEnumerationMutationException *e) { @throw [OFEnumerationMutationException exceptionWithObject: self]; } } #endif @end objfw-1.1.6/src/OFConcreteSubarray.h000066400000000000000000000015231465614216400173000ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFSubarray.h" OF_ASSUME_NONNULL_BEGIN @interface OFConcreteSubarray: OFSubarray @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFConcreteSubarray.m000066400000000000000000000033171465614216400173100ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFConcreteSubarray.h" #import "OFConcreteArray.h" #import "OFConcreteMutableArray.h" @implementation OFConcreteSubarray - (const id *)objects { return _array.objects + _range.location; } - (bool)isEqual: (id)object { OFArray *otherArray; id const *objects, *otherObjects; if (object == self) return true; if (![object isKindOfClass: [OFConcreteArray class]] && ![object isKindOfClass: [OFConcreteMutableArray class]]) return [super isEqual: object]; otherArray = object; if (_range.length != otherArray.count) return false; objects = self.objects; otherObjects = otherArray.objects; for (size_t i = 0; i < _range.length; i++) if (![objects[i] isEqual: otherObjects[i]]) return false; return true; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (OFArrayEnumerationBlock)block { id const *objects = self.objects; bool stop = false; for (size_t i = 0; i < _range.length && !stop; i++) block(objects[i], i, &stop); } #endif @end objfw-1.1.6/src/OFConcreteValue.h000066400000000000000000000015761465614216400165740ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFValue.h" OF_ASSUME_NONNULL_BEGIN @interface OFConcreteValue: OFValue { size_t _size; void *_bytes; char *_objCType; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFConcreteValue.m000066400000000000000000000030131465614216400165650ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFConcreteValue.h" #import "OFMethodSignature.h" #import "OFString.h" #import "OFOutOfRangeException.h" @implementation OFConcreteValue - (instancetype)initWithBytes: (const void *)bytes objCType: (const char *)objCType { self = [super initWithBytes: bytes objCType: objCType]; @try { _size = OFSizeOfTypeEncoding(objCType); _objCType = _OFStrDup(objCType); _bytes = OFAllocMemory(1, _size); memcpy(_bytes, bytes, _size); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { OFFreeMemory(_bytes); OFFreeMemory(_objCType); [super dealloc]; } - (const char *)objCType { return _objCType; } - (void)getValue: (void *)value size: (size_t)size { if (size != _size) @throw [OFOutOfRangeException exception]; memcpy(value, _bytes, _size); } @end objfw-1.1.6/src/OFCondition.h000066400000000000000000000114141465614216400157530ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFMutex.h" #import "OFPlainCondition.h" OF_ASSUME_NONNULL_BEGIN @class OFDate; /** * @class OFCondition OFCondition.h ObjFW/OFCondition.h * * @brief A class implementing a condition variable for thread synchronization. */ OF_SUBCLASSING_RESTRICTED @interface OFCondition: OFMutex { OFPlainCondition _condition; bool _conditionInitialized; } /** * @brief Creates a new condition. * * @return A new, autoreleased OFCondition */ + (instancetype)condition; /** * @brief Blocks the current thread until another thread calls @ref signal or * @ref broadcast. * * @note Waiting might have been interrupted by a signal. It is thus recommended * to check the condition again after @ref wait returned! * * @throw OFWaitForConditionFailedException Waiting for the condition failed */ - (void)wait; #if defined(OF_AMIGAOS) || defined(DOXYGEN) /** * @brief Blocks the current thread until another thread calls @ref signal, * @ref broadcast or an Exec Signal is received. * * @note This is only available on AmigaOS! * * @param signalMask A pointer to a signal mask of Exec Signals to receive. * This is modified and set to the mask of signals received. * @throw OFWaitForConditionFailedException Waiting for the condition failed */ - (void)waitForConditionOrExecSignal: (ULONG *)signalMask; #endif /** * @brief Blocks the current thread until another thread calls @ref signal, * @ref broadcast or the timeout is reached. * * @note Waiting might have been interrupted by a signal. It is thus recommended * to check the condition again after @ref waitForTimeInterval: returned! * * @param timeInterval The time interval until the timeout is reached * @return Whether the condition has been signaled * @throw OFWaitForConditionFailedException Waiting for the condition failed */ - (bool)waitForTimeInterval: (OFTimeInterval)timeInterval; #if defined(OF_AMIGAOS) || defined(DOXYGEN) /** * @brief Blocks the current thread until another thread calls @ref signal, * @ref broadcast, the timeout is reached or an Exec Signal is received. * * @note This is only available on AmigaOS! * * @param timeInterval The time interval until the timeout is reached * @param signalMask A pointer to a signal mask of Exec Signals to receive. * This is modified and set to the mask of signals received. * @return Whether the condition has been signaled or a signal received * @throw OFWaitForConditionFailedException Waiting for the condition failed */ - (bool)waitForTimeInterval: (OFTimeInterval)timeInterval orExecSignal: (ULONG *)signalMask; #endif /** * @brief Blocks the current thread until another thread calls @ref signal, * @ref broadcast or the timeout is reached. * * @note Waiting might have been interrupted by a signal. It is thus recommended * to check the condition again after @ref waitUntilDate: returned! * * @param date The date at which the timeout is reached * @return Whether the condition has been signaled * @throw OFWaitForConditionFailedException Waiting for the condition failed */ - (bool)waitUntilDate: (OFDate *)date; #if defined(OF_AMIGAOS) || defined(DOXYGEN) /** * @brief Blocks the current thread until another thread calls @ref signal, * @ref broadcast, the timeout is reached or an Exec Signal is received. * * @note This is only available on AmigaOS! * * @param date The date at which the timeout is reached * @param signalMask A pointer to a signal mask of Exec Signals to receive. * This is modified and set to the mask of signals received. * @return Whether the condition has been signaled or a signal received * @throw OFWaitForConditionFailedException Waiting for the condition failed */ - (bool)waitUntilDate: (OFDate *)date orExecSignal: (ULONG *)signalMask; #endif /** * @brief Signals the next waiting thread to continue. * * @throw OFSignalConditionFailedException Signaling the condition failed */ - (void)signal; /** * @brief Signals all threads to continue. * * @throw OFBroadcastConditionFailedException Broadcasting the condition failed */ - (void)broadcast; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFCondition.m000066400000000000000000000070231465614216400157610ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFCondition.h" #import "OFDate.h" #import "OFString.h" #import "OFBroadcastConditionFailedException.h" #import "OFConditionStillWaitingException.h" #import "OFInitializationFailedException.h" #import "OFSignalConditionFailedException.h" #import "OFWaitForConditionFailedException.h" @implementation OFCondition + (instancetype)condition { return [[[self alloc] init] autorelease]; } - (instancetype)init { self = [super init]; if (OFPlainConditionNew(&_condition) != 0) { Class c = self.class; [self release]; @throw [OFInitializationFailedException exceptionWithClass: c]; } _conditionInitialized = true; return self; } - (void)dealloc { if (_conditionInitialized) { int error = OFPlainConditionFree(&_condition); if (error != 0) { OFEnsure(error == EBUSY); @throw [OFConditionStillWaitingException exceptionWithCondition: self]; } } [super dealloc]; } - (void)wait { int error = OFPlainConditionWait(&_condition, &_mutex); if (error != 0) @throw [OFWaitForConditionFailedException exceptionWithCondition: self errNo: error]; } #ifdef OF_AMIGAOS - (void)waitForConditionOrExecSignal: (ULONG *)signalMask { int error = OFPlainConditionWaitOrExecSignal(&_condition, &_mutex, signalMask); if (error != 0) @throw [OFWaitForConditionFailedException exceptionWithCondition: self errNo: error]; } #endif - (bool)waitForTimeInterval: (OFTimeInterval)timeInterval { int error = OFPlainConditionTimedWait(&_condition, &_mutex, timeInterval); if (error == ETIMEDOUT) return false; if (error != 0) @throw [OFWaitForConditionFailedException exceptionWithCondition: self errNo: error]; return true; } #ifdef OF_AMIGAOS - (bool)waitForTimeInterval: (OFTimeInterval)timeInterval orExecSignal: (ULONG *)signalMask { int error = OFPlainConditionTimedWaitOrExecSignal(&_condition, &_mutex, timeInterval, signalMask); if (error == ETIMEDOUT) return false; if (error != 0) @throw [OFWaitForConditionFailedException exceptionWithCondition: self errNo: error]; return true; } #endif - (bool)waitUntilDate: (OFDate *)date { return [self waitForTimeInterval: date.timeIntervalSinceNow]; } #ifdef OF_AMIGAOS - (bool)waitUntilDate: (OFDate *)date orExecSignal: (ULONG *)signalMask { return [self waitForTimeInterval: date.timeIntervalSinceNow orExecSignal: signalMask]; } #endif - (void)signal { int error = OFPlainConditionSignal(&_condition); if (error != 0) @throw [OFSignalConditionFailedException exceptionWithCondition: self errNo: error]; } - (void)broadcast { int error = OFPlainConditionBroadcast(&_condition); if (error != 0) @throw [OFBroadcastConditionFailedException exceptionWithCondition: self errNo: error]; } @end objfw-1.1.6/src/OFConstantString.h000066400000000000000000000024161465614216400170070ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFString.h" OF_ASSUME_NONNULL_BEGIN #if !defined(OF_CONSTANT_STRING_M) && \ defined(OF_APPLE_RUNTIME) && !defined(__OBJC2__) # ifdef __cplusplus extern "C" { # endif extern void *_OFConstantStringClassReference; # ifdef __cplusplus } # endif #endif /** * @class OFConstantString OFConstantString.h ObjFW/OFConstantString.h * * @brief A class for storing constant strings using the `@""` literal. */ OF_SUBCLASSING_RESTRICTED @interface OFConstantString: OFString { char *_cString; unsigned int _cStringLength; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFConstantString.m000066400000000000000000000303201465614216400170070ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #define OF_CONSTANT_STRING_M #include "config.h" #include #include #import "OFConstantString.h" #import "OFUTF8String.h" #import "OFInitializationFailedException.h" #import "OFInvalidEncodingException.h" #import "OFOutOfMemoryException.h" #if defined(OF_APPLE_RUNTIME) && !defined(__OBJC2__) # import struct { struct class *isa, *superclass; const char *name; long version, info, instanceSize; struct ivar_list *iVars; struct method_list **methodList; struct cache *cache; struct protocol_list *protocols; const char *iVarLayout; struct class_ext *ext; } _OFConstantStringClassReference; #endif @interface OFConstantUTF8String: OFUTF8String @end @implementation OFConstantUTF8String + (instancetype)alloc { OF_UNRECOGNIZED_SELECTOR } OF_SINGLETON_METHODS @end @implementation OFConstantString + (void)load { #if defined(OF_APPLE_RUNTIME) && !defined(__OBJC2__) /* * objc_setFutureClass suddenly stopped working as OFConstantString * became more complex. So the only solution is to make * _OFConstantStringClassReference the actual class, but there is no * objc_initializeClassPair in 10.5. However, objc_allocateClassPair * does not register the new class with the subclass in the ObjC1 * runtime like the ObjC2 runtime does, so this workaround should be * fine. */ Class class; if ((class = objc_allocateClassPair(self, "OFConstantString_hack", 0)) == NULL) @throw [OFInitializationFailedException exceptionWithClass: self]; memcpy(&_OFConstantStringClassReference, class, sizeof(_OFConstantStringClassReference)); free(class); objc_registerClassPair((Class)&_OFConstantStringClassReference); #endif } - (void)finishInitialization { @synchronized (self) { struct OFUTF8StringIvars *ivars; if ([self isMemberOfClass: [OFConstantUTF8String class]]) return; ivars = OFAllocZeroedMemory(1, sizeof(*ivars)); ivars->cString = _cString; ivars->cStringLength = _cStringLength; switch (_OFUTF8StringCheck(ivars->cString, ivars->cStringLength, &ivars->length)) { case 1: ivars->isUTF8 = true; break; case -1: OFFreeMemory(ivars); @throw [OFInvalidEncodingException exception]; } _cString = (char *)ivars; object_setClass(self, [OFConstantUTF8String class]); } } + (instancetype)alloc { OF_UNRECOGNIZED_SELECTOR } OF_SINGLETON_METHODS /* * In all following methods, the constant string is converted to an * OFConstantUTF8String and the message sent again. */ /* From protocol OFCopying */ - (id)copy { [self finishInitialization]; return [self copy]; } /* From protocol OFMutableCopying */ - (id)mutableCopy { [self finishInitialization]; return [self mutableCopy]; } /* From protocol OFComparing, but overridden in OFString */ - (OFComparisonResult)compare: (OFString *)string { [self finishInitialization]; return [self compare: string]; } /* From OFObject, but reimplemented in OFString */ - (bool)isEqual: (id)object { [self finishInitialization]; return [self isEqual: object]; } - (unsigned long)hash { [self finishInitialization]; return self.hash; } - (OFString *)description { [self finishInitialization]; return self.description; } /* From OFString */ - (const char *)UTF8String { [self finishInitialization]; return self.UTF8String; } - (size_t)getCString: (char *)cString_ maxLength: (size_t)maxLength encoding: (OFStringEncoding)encoding { [self finishInitialization]; return [self getCString: cString_ maxLength: maxLength encoding: encoding]; } - (const char *)cStringWithEncoding: (OFStringEncoding)encoding { [self finishInitialization]; return [self cStringWithEncoding: encoding]; } - (size_t)length { [self finishInitialization]; return self.length; } - (size_t)UTF8StringLength { [self finishInitialization]; return self.UTF8StringLength; } - (size_t)cStringLengthWithEncoding: (OFStringEncoding)encoding { [self finishInitialization]; return [self cStringLengthWithEncoding: encoding]; } - (OFComparisonResult)caseInsensitiveCompare: (OFString *)string { [self finishInitialization]; return [self caseInsensitiveCompare: string]; } - (OFUnichar)characterAtIndex: (size_t)idx { [self finishInitialization]; return [self characterAtIndex: idx]; } - (void)getCharacters: (OFUnichar *)buffer inRange: (OFRange)range { [self finishInitialization]; [self getCharacters: buffer inRange: range]; } - (OFRange)rangeOfString: (OFString *)string { [self finishInitialization]; return [self rangeOfString: string]; } - (OFRange)rangeOfString: (OFString *)string options: (OFStringSearchOptions)options { [self finishInitialization]; return [self rangeOfString: string options: options]; } - (OFRange)rangeOfString: (OFString *)string options: (OFStringSearchOptions)options range: (OFRange)range { [self finishInitialization]; return [self rangeOfString: string options: options range: range]; } - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet { [self finishInitialization]; return [self indexOfCharacterFromSet: characterSet]; } - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet options: (OFStringSearchOptions)options { [self finishInitialization]; return [self indexOfCharacterFromSet: characterSet options: options]; } - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet options: (OFStringSearchOptions)options range: (OFRange)range { [self finishInitialization]; return [self indexOfCharacterFromSet: characterSet options: options range: range]; } - (bool)containsString: (OFString *)string { [self finishInitialization]; return [self containsString: string]; } - (OFString *)substringFromIndex: (size_t)idx { [self finishInitialization]; return [self substringFromIndex: idx]; } - (OFString *)substringToIndex: (size_t)idx { [self finishInitialization]; return [self substringToIndex: idx]; } - (OFString *)substringWithRange: (OFRange)range { [self finishInitialization]; return [self substringWithRange: range]; } - (OFString *)stringByAppendingString: (OFString *)string { [self finishInitialization]; return [self stringByAppendingString: string]; } - (OFString *)stringByAppendingFormat: (OFConstantString *)format arguments: (va_list)arguments { [self finishInitialization]; return [self stringByAppendingFormat: format arguments: arguments]; } - (OFString *)stringByAppendingPathComponent: (OFString *)component { [self finishInitialization]; return [self stringByAppendingPathComponent: component]; } - (OFString *)stringByAppendingPathExtension: (OFString *)extension { [self finishInitialization]; return [self stringByAppendingPathExtension: extension]; } - (OFString *)stringByReplacingOccurrencesOfString: (OFString *)string withString: (OFString *)replacement { [self finishInitialization]; return [self stringByReplacingOccurrencesOfString: string withString: replacement]; } - (OFString *)stringByReplacingOccurrencesOfString: (OFString *)string withString: (OFString *)replacement options: (int)options range: (OFRange)range { [self finishInitialization]; return [self stringByReplacingOccurrencesOfString: string withString: replacement options: options range: range]; } - (OFString *)uppercaseString { [self finishInitialization]; return self.uppercaseString; } - (OFString *)lowercaseString { [self finishInitialization]; return self.lowercaseString; } - (OFString *)capitalizedString { [self finishInitialization]; return self.capitalizedString; } - (OFString *)stringByDeletingLeadingWhitespaces { [self finishInitialization]; return self.stringByDeletingLeadingWhitespaces; } - (OFString *)stringByDeletingTrailingWhitespaces { [self finishInitialization]; return self.stringByDeletingTrailingWhitespaces; } - (OFString *)stringByDeletingEnclosingWhitespaces { [self finishInitialization]; return self.stringByDeletingEnclosingWhitespaces; } - (bool)hasPrefix: (OFString *)prefix { [self finishInitialization]; return [self hasPrefix: prefix]; } - (bool)hasSuffix: (OFString *)suffix { [self finishInitialization]; return [self hasSuffix: suffix]; } - (OFArray *)componentsSeparatedByString: (OFString *)delimiter { [self finishInitialization]; return [self componentsSeparatedByString: delimiter]; } - (OFArray *)componentsSeparatedByString: (OFString *)delimiter options: (OFStringSeparationOptions)options { [self finishInitialization]; return [self componentsSeparatedByString: delimiter options: options]; } - (OFArray *) componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet { [self finishInitialization]; return [self componentsSeparatedByCharactersInSet: characterSet]; } - (OFArray *) componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet options: (OFStringSeparationOptions)options { [self finishInitialization]; return [self componentsSeparatedByCharactersInSet: characterSet options: options]; } - (OFArray *)pathComponents { [self finishInitialization]; return self.pathComponents; } - (OFString *)lastPathComponent { [self finishInitialization]; return self.lastPathComponent; } - (OFString *)stringByDeletingLastPathComponent { [self finishInitialization]; return self.stringByDeletingLastPathComponent; } - (long long)longLongValue { [self finishInitialization]; return self.longLongValue; } - (long long)longLongValueWithBase: (unsigned char)base { [self finishInitialization]; return [self longLongValueWithBase: base]; } - (unsigned long long)unsignedLongLongValue { [self finishInitialization]; return self.unsignedLongLongValue; } - (unsigned long long)unsignedLongLongValueWithBase: (unsigned char)base { [self finishInitialization]; return [self unsignedLongLongValueWithBase: base]; } - (float)floatValue { [self finishInitialization]; return self.floatValue; } - (double)doubleValue { [self finishInitialization]; return self.doubleValue; } - (const OFUnichar *)characters { [self finishInitialization]; return self.characters; } - (const OFChar16 *)UTF16String { [self finishInitialization]; return self.UTF16String; } - (const OFChar16 *)UTF16StringWithByteOrder: (OFByteOrder)byteOrder { [self finishInitialization]; return [self UTF16StringWithByteOrder: byteOrder]; } - (size_t)UTF16StringLength { [self finishInitialization]; return self.UTF16StringLength; } - (const OFChar32 *)UTF32String { [self finishInitialization]; return self.UTF32String; } - (const OFChar32 *)UTF32StringWithByteOrder: (OFByteOrder)byteOrder { [self finishInitialization]; return [self UTF32StringWithByteOrder: byteOrder]; } - (OFData *)dataWithEncoding: (OFStringEncoding)encoding { [self finishInitialization]; return [self dataWithEncoding: encoding]; } #ifdef OF_WINDOWS - (OFString *)stringByExpandingWindowsEnvironmentStrings { [self finishInitialization]; return self.stringByExpandingWindowsEnvironmentStrings; } #endif #ifdef OF_HAVE_FILES - (void)writeToFile: (OFString *)path { [self finishInitialization]; [self writeToFile: path]; } - (void)writeToFile: (OFString *)path encoding: (OFStringEncoding)encoding { [self finishInitialization]; [self writeToFile: path encoding: encoding]; } #endif - (void)writeToIRI: (OFIRI *)IRI { [self finishInitialization]; [self writeToIRI: IRI]; } - (void)writeToIRI: (OFIRI *)IRI encoding: (OFStringEncoding)encoding { [self finishInitialization]; [self writeToIRI: IRI encoding: encoding]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateLinesUsingBlock: (OFStringLineEnumerationBlock)block { [self finishInitialization]; [self enumerateLinesUsingBlock: block]; } #endif @end objfw-1.1.6/src/OFCountedSet.h000066400000000000000000000041501465614216400161010ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFSet.h" OF_ASSUME_NONNULL_BEGIN /** @file */ #ifdef OF_HAVE_BLOCKS /** * @brief A block for enumerating an OFCountedSet. * * @param object The current object * @param count The count of the object * @param stop A pointer to a variable that can be set to true to stop the * enumeration */ typedef void (^OFCountedSetEnumerationBlock)(id object, size_t count, bool *stop); #endif /** * @class OFCountedSet OFCountedSet.h ObjFW/OFCountedSet.h * * @brief An abstract class for a mutable unordered set of objects, counting how * often it contains an object. * * @note Subclasses must implement @ref countForObject: as well as all methods * of @ref OFSet and @ref OFMutableSet that need to be implemented. */ @interface OFCountedSet OF_GENERIC(ObjectType): OFMutableSet OF_GENERIC(ObjectType) #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # define ObjectType id #endif /** * @brief Returns how often the object is in the set. * * @return How often the object is in the set */ - (size_t)countForObject: (ObjectType)object; #ifdef OF_HAVE_BLOCKS /** * @brief Executes a block for each object in the set. * * @param block The block to execute for each object in the set */ - (void)enumerateObjectsAndCountUsingBlock: (OFCountedSetEnumerationBlock)block; #endif #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # undef ObjectType #endif @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFCountedSet.m000066400000000000000000000113021465614216400161030ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFCountedSet.h" #import "OFConcreteCountedSet.h" #import "OFNumber.h" #import "OFString.h" static struct { Class isa; } placeholder; @interface OFPlaceholderCountedSet: OFCountedSet @end @implementation OFPlaceholderCountedSet #ifdef __clang__ /* We intentionally don't call into super, so silence the warning. */ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunknown-pragmas" # pragma clang diagnostic ignored "-Wobjc-designated-initializers" #endif - (instancetype)init { return (id)[[OFConcreteCountedSet alloc] init]; } - (instancetype)initWithSet: (OFSet *)set { return (id)[[OFConcreteCountedSet alloc] initWithSet: set]; } - (instancetype)initWithArray: (OFArray *)array { return (id)[[OFConcreteCountedSet alloc] initWithArray: array]; } - (instancetype)initWithObjects: (id)firstObject, ... { id ret; va_list arguments; va_start(arguments, firstObject); ret = [[OFConcreteCountedSet alloc] initWithObject: firstObject arguments: arguments]; va_end(arguments); return ret; } - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { return (id)[[OFConcreteCountedSet alloc] initWithObjects: objects count: count]; } - (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments { return (id)[[OFConcreteCountedSet alloc] initWithObject: firstObject arguments: arguments]; } #ifdef __clang__ # pragma clang diagnostic pop #endif OF_SINGLETON_METHODS @end @implementation OFCountedSet + (void)initialize { if (self == [OFCountedSet class]) object_setClass((id)&placeholder, [OFPlaceholderCountedSet class]); } + (instancetype)alloc { if (self == [OFCountedSet class]) return (id)&placeholder; return [super alloc]; } - (size_t)countForObject: (id)object { OF_UNRECOGNIZED_SELECTOR } - (OFString *)description { OFMutableString *ret; void *pool; size_t i, count = self.count; if (count == 0) return @"{()}"; ret = [OFMutableString stringWithString: @"{(\n"]; pool = objc_autoreleasePoolPush(); i = 0; for (id object in self) { void *pool2 = objc_autoreleasePoolPush(); [ret appendString: object]; [ret appendFormat: @": %zu", [self countForObject: object]]; if (++i < count) [ret appendString: @",\n"]; objc_autoreleasePoolPop(pool2); } [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @"\n)}"]; [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } - (id)copy { return [[OFCountedSet alloc] initWithSet: self]; } - (id)mutableCopy { return [[OFCountedSet alloc] initWithSet: self]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsAndCountUsingBlock: (OFCountedSetEnumerationBlock)block { [self enumerateObjectsUsingBlock: ^ (id object, bool *stop) { block(object, [self countForObject: object], stop); }]; } #endif - (void)minusSet: (OFSet *)set { void *pool = objc_autoreleasePoolPush(); if ([set isKindOfClass: [OFCountedSet class]]) { OFCountedSet *countedSet = (OFCountedSet *)set; for (id object in countedSet) { size_t count = [countedSet countForObject: object]; for (size_t i = 0; i < count; i++) [self removeObject: object]; } } else for (id object in set) [self removeObject: object]; objc_autoreleasePoolPop(pool); } - (void)unionSet: (OFSet *)set { void *pool = objc_autoreleasePoolPush(); if ([set isKindOfClass: [OFCountedSet class]]) { OFCountedSet *countedSet = (OFCountedSet *)set; for (id object in countedSet) { size_t count = [countedSet countForObject: object]; for (size_t i = 0; i < count; i++) [self addObject: object]; } } else for (id object in set) [self addObject: object]; objc_autoreleasePoolPop(pool); } - (void)removeAllObjects { void *pool = objc_autoreleasePoolPush(); OFSet *copy = [[self copy] autorelease]; for (id object in copy) { size_t count = [self countForObject: object]; for (size_t i = 0; i < count; i++) [self removeObject: object]; } objc_autoreleasePoolPop(pool); } @end objfw-1.1.6/src/OFCryptographicHash.h000066400000000000000000000073731465614216400174600ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN /** * @protocol OFCryptographicHash \ * OFCryptographicHash.h ObjFW/OFCryptographicHash.h * * @brief A protocol for classes providing cryptographic hash functions. * * A cryptographic hash implementing this protocol can be copied. The entire * state is copied, allowing to calculate a new hash from there. This is * especially useful for generating many hashes with a common prefix. */ @protocol OFCryptographicHash #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nonatomic) size_t digestSize; @property (class, readonly, nonatomic) size_t blockSize; #endif /** * @brief The digest size of the cryptographic hash, in bytes. */ @property (readonly, nonatomic) size_t digestSize; /** * @brief The block size of the cryptographic hash, in bytes. */ @property (readonly, nonatomic) size_t blockSize; /** * @brief Whether data may be stored in swappable memory. */ @property (readonly, nonatomic) bool allowsSwappableMemory; /** * @brief A boolean whether the hash has already been calculated. */ @property (readonly, nonatomic, getter=isCalculated) bool calculated; /** * @brief A buffer containing the cryptographic hash. * * The size of the buffer depends on the hash used. The buffer is part of the * receiver's memory pool. * * @throw OFHashNotCalculatedException The hash hasn't been calculated yet */ @property (readonly, nonatomic) const unsigned char *digest OF_RETURNS_INNER_POINTER; /** * @brief Creates a new cryptographic hash. * * @return A new autoreleased cryptographic hash */ + (instancetype)hashWithAllowsSwappableMemory: (bool)allowsSwappableMemory; /** * @brief Returns the digest size of the cryptographic hash, in bytes. * * @return The digest size of the cryptographic hash, in bytes */ + (size_t)digestSize; /** * @brief Returns the block size of the cryptographic hash, in bytes. * * @return The block size of the cryptographic hash, in bytes */ + (size_t)blockSize; /** * @brief Initializes an already allocated cryptographic hash. * * @return An initialized cryptographic hash */ - (instancetype)initWithAllowsSwappableMemory: (bool)allowsSwappableMemory; - (instancetype)init OF_UNAVAILABLE; /** * @brief Adds a buffer to the cryptographic hash to be calculated. * * @param buffer The buffer which should be included into the calculation * @param length The length of the buffer * @throw OFHashAlreadyCalculatedException The hash has already been calculated */ - (void)updateWithBuffer: (const void *)buffer length: (size_t)length; /** * @brief Performs the final calculation of the cryptographic hash. * * @throw OFHashAlreadyCalculatedException The hash has already been calculated */ - (void)calculate; /** * @brief Resets all state so that a new hash can be calculated. * * @warning This invalidates any pointer previously returned by @ref digest. If * you are still interested in the previous digest, you need to memcpy * it yourself before calling @ref reset! */ - (void)reset; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFDDPSocket.h000066400000000000000000000067471465614216400156220ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFDatagramSocket.h" OF_ASSUME_NONNULL_BEGIN @class OFString; @class OFDictionary OF_GENERIC(KeyType, ObjectType); /** * @protocol OFDDPSocketDelegate OFDDPSocket.h ObjFW/OFDDPSocket.h * * @brief A delegate for OFDDPSocket. */ @protocol OFDDPSocketDelegate @end /** * @class OFDDPSocket OFDDPSocket.h ObjFW/OFDDPSocket.h * * @brief A class which provides methods to create and use AppleTalk DDP * sockets. * * Addresses are of type @ref OFSocketAddress. You can use * @ref OFSocketAddressMakeAppleTalk to create an address or * @ref OFSocketAddressAppleTalkNetwork to get the AppleTalk network, * @ref OFSocketAddressAppleTalkNode to get the AppleTalk node and * @ref OFSocketAddressAppleTalkPort to get the port (sometimes also called * socket number). * * @note On some systems, packets received with the wrong protocol type just * get filtered by the kernel, however, on other systems, the packet is * queued up and will raise an @ref OFReadFailedException with the * @ref OFReadFailedException#errNo set to `ENOMSG` when being received. * * @warning Even though the OFCopying protocol is implemented, it does *not* * return an independent copy of the socket, but instead retains it. * This is so that the socket can be used as a key for a dictionary, * so context can be associated with a socket. Using a socket in more * than one thread at the same time is not thread-safe, even if copy * was called to create one "instance" for every thread! */ @interface OFDDPSocket: OFDatagramSocket { #if !defined(OF_MACOS) && !defined(OF_WINDOWS) uint8_t _protocolType; #endif OF_RESERVE_IVARS(OFDDPSocket, 4) } /** * @brief The delegate for asynchronous operations on the socket. * * @note The delegate is retained for as long as asynchronous operations are * still ongoing. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id delegate; /** * @brief Bind the socket to the specified network, node and port. * * @param network The network to bind to. 0 means any. * @param node The node to bind to. 0 means "this node". * @param port The port to bind to. 0 means to pick one and return it via the * returned socket address. * @param protocolType The DDP protocol type to use. Must not be 0. If you want * to use DDP directly and not a protocol built on top of * it, use 11 for compatibility with Open Transport. * @return The address on which this socket can be reached * @throw OFBindDDPSockeFailedException Binding failed * @throw OFAlreadyOpenException The socket is already bound */ - (OFSocketAddress)bindToNetwork: (uint16_t)network node: (uint8_t)node port: (uint8_t)port protocolType: (uint8_t)protocolType; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFDDPSocket.m000066400000000000000000000171121465614216400156130ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #ifdef HAVE_FCNTL_H # include #endif #import "OFDDPSocket.h" #import "OFDictionary.h" #import "OFNumber.h" #import "OFPair.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFAlreadyOpenException.h" #import "OFBindDDPSocketFailedException.h" #import "OFGetOptionFailedException.h" #import "OFInvalidArgumentException.h" #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFSetOptionFailedException.h" #import "OFWriteFailedException.h" #ifdef HAVE_NET_IF_H # include #endif #ifdef HAVE_SYS_IOCTL_H # include #endif #ifdef OF_HAVE_NETAT_APPLETALK_H # include # include /* Unfortulately, there is no struct for the following in userland headers */ struct ATInterfaceConfig { char interfaceName[16]; unsigned int flags; struct at_addr address, router; unsigned short netStart, netEnd; at_nvestr_t zoneName; }; #endif @implementation OFDDPSocket @dynamic delegate; - (OFSocketAddress)bindToNetwork: (uint16_t)network node: (uint8_t)node port: (uint8_t)port protocolType: (uint8_t)protocolType { #ifdef OF_MACOS const int one = 1; struct ATInterfaceConfig config = { { 0 } }; #endif OFSocketAddress address; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) int flags; #endif if (protocolType == 0) @throw [OFInvalidArgumentException exception]; if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyOpenException exceptionWithObject: self]; address = OFSocketAddressMakeAppleTalk(network, node, port); #if defined(OF_MACOS) if ((_socket = socket(address.sockaddr.at.sat_family, SOCK_RAW | SOCK_CLOEXEC, protocolType)) == OFInvalidSocketHandle) #elif defined(OF_WINDOWS) if ((_socket = socket(address.sockaddr.at.sat_family, SOCK_DGRAM | SOCK_CLOEXEC, ATPROTO_BASE + protocolType)) == OFInvalidSocketHandle) #else if ((_socket = socket(address.sockaddr.at.sat_family, SOCK_DGRAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle) #endif @throw [OFBindDDPSocketFailedException exceptionWithNetwork: network node: node port: port protocolType: protocolType socket: self errNo: _OFSocketErrNo()]; _canBlock = true; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); #endif if (bind(_socket, (struct sockaddr *)&address.sockaddr, address.length) != 0) { int errNo = _OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindDDPSocketFailedException exceptionWithNetwork: network node: node port: port protocolType: protocolType socket: self errNo: errNo]; } memset(&address, 0, sizeof(address)); address.family = OFSocketAddressFamilyAppleTalk; address.length = (socklen_t)sizeof(address.sockaddr); if (_OFGetSockName(_socket, (struct sockaddr *)&address.sockaddr, &address.length) != 0) { int errNo = _OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindDDPSocketFailedException exceptionWithNetwork: network node: node port: port protocolType: protocolType socket: self errNo: errNo]; } if (address.sockaddr.at.sat_family != AF_APPLETALK) { closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindDDPSocketFailedException exceptionWithNetwork: network node: node port: port protocolType: protocolType socket: self errNo: EAFNOSUPPORT]; } #ifdef OF_MACOS if (setsockopt(_socket, ATPROTO_NONE, DDP_STRIPHDR, &one, sizeof(one)) != 0 || ioctl(_socket, _IOWR('a', 2, struct ATInterfaceConfig), &config) != 0) @throw [OFBindDDPSocketFailedException exceptionWithNetwork: network node: node port: port protocolType: protocolType socket: self errNo: _OFSocketErrNo()]; OFSocketAddressSetAppleTalkNetwork(&address, config.address.s_net); OFSocketAddressSetAppleTalkNode(&address, config.address.s_node); #endif #if !defined(OF_MACOS) && !defined(OF_WINDOWS) _protocolType = protocolType; #endif return address; } /* * Everybody but macOS and Windows is probably using a netatalk-compatible * implementation, which includes the protocol type as the first byte of the * data instead of considering it part of the header. * * The following overrides prepend the protocol type when sending and compare * and strip it when receiving. * * Unfortunately, the downside of this is that the only way to handle receiving * a packet with the wrong protocol type is to throw an exception with errNo * ENOMSG, while macOS and Windows just filter those out in the kernel. * Returning 0 would mean this is indistinguishable from an empty packet, so it * has to be an exception. */ #if !defined(OF_MACOS) && !defined(OF_WINDOWS) - (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length sender: (OFSocketAddress *)sender { ssize_t ret; uint8_t protocolType; struct iovec iov[2] = { { &protocolType, 1 }, { buffer, length } }; struct msghdr msg = { .msg_name = (sender != NULL ? (struct sockaddr *)&sender->sockaddr : NULL), .msg_namelen = (sender != NULL ? (socklen_t)sizeof(sender->sockaddr) : 0), .msg_iov = iov, .msg_iovlen = 2 }; if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; if ((ret = recvmsg(_socket, &msg, 0)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: _OFSocketErrNo()]; if (ret < 1 || protocolType != _protocolType) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: ENOMSG]; if (sender != NULL) { sender->length = msg.msg_namelen; sender->family = OFSocketAddressFamilyAppleTalk; } return ret - 1; } - (void)sendBuffer: (const void *)buffer length: (size_t)length receiver: (const OFSocketAddress *)receiver { struct iovec iov[2] = { { &_protocolType, 1 }, { (void *)buffer, length } }; struct msghdr msg = { .msg_name = (struct sockaddr *)&receiver->sockaddr, .msg_namelen = receiver->length, .msg_iov = iov, .msg_iovlen = 2 }; ssize_t bytesWritten; if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; if ((bytesWritten = sendmsg(_socket, &msg, 0)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: _OFSocketErrNo()]; if ((size_t)bytesWritten != length + 1) { bytesWritten--; if (bytesWritten < 0) bytesWritten = 0; @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: bytesWritten errNo: 0]; } } #endif @end objfw-1.1.6/src/OFDNSQuery.h000066400000000000000000000043351465614216400155030ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFDNSResourceRecord.h" OF_ASSUME_NONNULL_BEGIN @class OFString; /** * @class OFDNSQuery OFDNSQuery.h ObjFW/OFDNSQuery.h * * @brief A class representing a DNS query. */ OF_SUBCLASSING_RESTRICTED @interface OFDNSQuery: OFObject { OFString *_domainName; OFDNSClass _DNSClass; OFDNSRecordType _recordType; } /** * @brief The domain name of the query. */ @property (readonly, nonatomic) OFString *domainName; /** * @brief The DNS class of the query. */ @property (readonly, nonatomic) OFDNSClass DNSClass; /** * @brief The record type of the query. */ @property (readonly, nonatomic) OFDNSRecordType recordType; /** * @brief Creates a new, autoreleased OFDNSQuery. * * @param domainName The domain name to query * @param DNSClass The DNS class of the query * @param recordType The record type of the query * @return A new, autoreleased OFDNSQuery */ + (instancetype)queryWithDomainName: (OFString *)domainName DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType; /** * @brief Initializes an already allocated OFDNSQuery. * * @param domainName The domain name to query * @param DNSClass The DNS class of the query * @param recordType The record type of the query * @return An initialized OFDNSQuery */ - (instancetype)initWithDomainName: (OFString *)domainName DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFDNSQuery.m000066400000000000000000000051741465614216400155120ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFDNSQuery.h" #import "OFString.h" @implementation OFDNSQuery @synthesize domainName = _domainName, DNSClass = _DNSClass; @synthesize recordType = _recordType; + (instancetype)queryWithDomainName: (OFString *)domainName DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType { return [[[self alloc] initWithDomainName: domainName DNSClass: DNSClass recordType: recordType] autorelease]; } - (instancetype)initWithDomainName: (OFString *)domainName DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); if (![domainName hasSuffix: @"."]) domainName = [domainName stringByAppendingString: @"."]; _domainName = [domainName.lowercaseString copy]; _DNSClass = DNSClass; _recordType = recordType; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_domainName release]; [super dealloc]; } - (bool)isEqual: (id)object { OFDNSQuery *query; if (object == self) return true; if (![object isKindOfClass: [OFDNSQuery class]]) return false; query = object; if (query->_domainName != _domainName && ![query->_domainName isEqual: _domainName]) return false; if (query->_DNSClass != _DNSClass) return false; if (query->_recordType != _recordType) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _domainName.hash); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType); OFHashFinalize(&hash); return hash; } - (id)copy { return [self retain]; } - (OFString *)description { return [OFString stringWithFormat: @"<%@ %@ %@ %@>", self.className, _domainName, OFDNSClassName(_DNSClass), OFDNSRecordTypeName(_recordType)]; } @end objfw-1.1.6/src/OFDNSResolver.h000066400000000000000000000245241465614216400162010ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFDNSQuery.h" #import "OFDNSResourceRecord.h" #import "OFDNSResponse.h" #import "OFRunLoop.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN #define OFDNSResolverBufferLength 512 @class OFArray OF_GENERIC(ObjectType); @class OFDNSResolver; @class OFDNSResolverContext; @class OFDNSResolverSettings; @class OFDate; @class OFDictionary OF_GENERIC(KeyType, ObjectType); @class OFMutableArray OF_GENERIC(ObjectType); @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); @class OFNumber; @class OFPair OF_GENERIC(FirstType, SecondType); @class OFTCPSocket; @class OFUDPSocket; /** * @enum OFDNSResolverErrorCode OFDNSResolver.h ObjFW/OFDNSResolver.h * * @brief An enum describing why resolving a host failed. */ typedef enum { /** An unknown error */ OFDNSResolverErrorCodeUnknown, /** The query timed out */ OFDNSResolverErrorCodeTimeout, /** The query was canceled */ OFDNSResolverErrorCodeCanceled, /** * No result for the specified host with the specified type and class. * * This is only used in situations where this is an error, e.g. when * trying to connect to a host. */ OFDNSResolverErrorCodeNoResult, /** The server considered the query to be malformed */ OFDNSResolverErrorCodeServerInvalidFormat, /** The server was unable to process due to an internal error */ OFDNSResolverErrorCodeServerFailure, /** The server returned an error that the domain does not exist */ OFDNSResolverErrorCodeServerNameError, /** The server does not have support for the requested query */ OFDNSResolverErrorCodeServerNotImplemented, /** The server refused the query */ OFDNSResolverErrorCodeServerRefused, /** There was no name server to query */ OFDNSResolverErrorCodeNoNameServer } OFDNSResolverErrorCode; /** * @protocol OFDNSResolverQueryDelegate OFDNSResolver.h ObjFW/OFDNSResolver.h * * @brief A delegate for performed DNS queries. */ @protocol OFDNSResolverQueryDelegate /** * @brief This method is called when a DNS resolver performed a query. * * @param resolver The acting resolver * @param query The query performed by the resolver * @param response The response from the DNS server, or nil on error * @param exception An exception that happened during resolving, or nil on * success */ - (void)resolver: (OFDNSResolver *)resolver didPerformQuery: (OFDNSQuery *)query response: (nullable OFDNSResponse *)response exception: (nullable id)exception; @end /** * @protocol OFDNSResolverQueryDelegate OFDNSResolver.h ObjFW/OFDNSResolver.h * * @brief A delegate for resolved hosts. */ @protocol OFDNSResolverHostDelegate /** * @brief This method is called when a DNS resolver resolved a host to * addresses. * * @param resolver The acting resolver * @param host The host the resolver resolved * @param addresses OFData containing several OFSocketAddress * @param exception The exception that occurred during resolving, or nil on * success */ - (void)resolver: (OFDNSResolver *)resolver didResolveHost: (OFString *)host addresses: (nullable OFData *)addresses exception: (nullable id)exception; @end /** * @class OFDNSResolver OFDNSResolver.h ObjFW/OFDNSResolver.h * * @brief A class for resolving DNS names. * * @note If you change any of the properties, make sure to set * @ref configReloadInterval to 0, as otherwise your changes will be * reverted back to the system configuration on the next periodic config * reload. */ OF_SUBCLASSING_RESTRICTED @interface OFDNSResolver: OFObject { OFDNSResolverSettings *_settings; OFUDPSocket *_IPv4Socket; #ifdef OF_HAVE_IPV6 OFUDPSocket *_IPv6Socket; #endif char _buffer[OFDNSResolverBufferLength]; OFMutableDictionary OF_GENERIC(OFNumber *, OFDNSResolverContext *) *_queries; OFMutableDictionary OF_GENERIC(OFTCPSocket *, OFDNSResolverContext *) *_TCPQueries; OFMutableDictionary OF_GENERIC(OFDNSQuery *, OFPair OF_GENERIC(OFDate *, OFDNSResponse *) *) *_cache; OFMutableArray OF_GENERIC(OFString *) *_lastNameServers; OFTimeInterval _lastCacheCleanup; } /** * @brief A dictionary of static hosts. * * This dictionary is checked before actually looking up a host. * * @warning If you change this, you need to set @ref configReloadInterval to 0 * to disable reloading the config after some time. If you don't, the * config will be reloaded and your change overridden. */ @property (copy, nonatomic) OFDictionary OF_GENERIC(OFString *, OFArray OF_GENERIC(OFString *) *) *staticHosts; /** * @brief An array of name servers to use. * * The name servers are tried in order. * * @warning If you change this, you need to set @ref configReloadInterval to 0 * to disable reloading the config after some time. If you don't, the * config will be reloaded and your change overridden. */ @property (copy, nonatomic) OFArray OF_GENERIC(OFString *) *nameServers; /** * @brief The local domain. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *localDomain; /** * @brief The domains to search for queries for short names. * * @warning If you change this, you need to set @ref configReloadInterval to 0 * to disable reloading the config after some time. If you don't, the * config will be reloaded and your change overridden. */ @property (copy, nonatomic) OFArray OF_GENERIC(OFString *) *searchDomains; /** * @brief The timeout, in seconds, after which the next name server should be * tried. * * @warning If you change this, you need to set @ref configReloadInterval to 0 * to disable reloading the config after some time. If you don't, the * config will be reloaded and your change overridden. */ @property (nonatomic) OFTimeInterval timeout; /** * @brief The number of attempts before giving up to resolve a host. * * Trying all name servers once is considered a single attempt. * * @warning If you change this, you need to set @ref configReloadInterval to 0 * to disable reloading the config after some time. If you don't, the * config will be reloaded and your change overridden. */ @property (nonatomic) unsigned int maxAttempts; /** * @brief The minimum number of dots for a name to be considered absolute. * * @warning If you change this, you need to set @ref configReloadInterval to 0 * to disable reloading the config after some time. If you don't, the * config will be reloaded and your change overridden. */ @property (nonatomic) unsigned int minNumberOfDotsInAbsoluteName; /** * @brief Whether the resolver forces TCP to talk to a name server. * * @warning If you change this, you need to set @ref configReloadInterval to 0 * to disable reloading the config after some time. If you don't, the * config will be reloaded and your change overridden. */ @property (nonatomic) bool forcesTCP; /** * @brief The interval in seconds in which the config should be reloaded. * * Setting this to 0 disables config reloading. * * @warning If you change this to anything other than 0, the config will be * reloaded eventually, which in turn can override the config * reloading interval itself again. */ @property (nonatomic) OFTimeInterval configReloadInterval; /** * @brief Creates a new, autoreleased OFDNSResolver. */ + (instancetype)resolver; /** * @brief Initializes an already allocated OFDNSResolver. */ - (instancetype)init; /** * @brief Asynchronously performs the specified query. * * @param query The query to perform * @param delegate The delegate to use for callbacks */ - (void)asyncPerformQuery: (OFDNSQuery *)query delegate: (id )delegate; /** * @brief Asynchronously performs the specified query. * * @param query The query to perform * @param runLoopMode The run loop mode in which to resolve * @param delegate The delegate to use for callbacks */ - (void)asyncPerformQuery: (OFDNSQuery *)query runLoopMode: (OFRunLoopMode)runLoopMode delegate: (id )delegate; /** * @brief Asynchronously resolves the specified host to socket addresses. * * @param host The host to resolve * @param delegate The delegate to use for callbacks */ - (void)asyncResolveAddressesForHost: (OFString *)host delegate: (id )delegate; /** * @brief Asynchronously resolves the specified host to socket addresses. * * @param host The host to resolve * @param addressFamily The desired socket address family * @param delegate The delegate to use for callbacks */ - (void)asyncResolveAddressesForHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily delegate: (id )delegate; /** * @brief Asynchronously resolves the specified host to socket addresses. * * @param host The host to resolve * @param addressFamily The desired socket address family * @param runLoopMode The run loop mode in which to resolve * @param delegate The delegate to use for callbacks */ - (void)asyncResolveAddressesForHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily runLoopMode: (OFRunLoopMode)runLoopMode delegate: (id )delegate; /** * @brief Synchronously resolves the specified host to socket addresses. * * @param host The host to resolve * @param addressFamily The desired socket address family * @return OFData containing several OFSocketAddress * @throw OFInvalidServerResponseException The received response was invalid * @throw OFTruncatedDataException The received response was truncated */ - (OFData *)resolveAddressesForHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily; /** * @brief Closes all sockets and cancels all ongoing queries. */ - (void)close; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFDNSResolver.m000066400000000000000000001106661465614216400162110ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFDNSResolver.h" #import "OFArray.h" #import "OFDNSQuery.h" #import "OFDNSResolverSettings.h" #import "OFDNSResponse.h" #import "OFData.h" #import "OFDate.h" #import "OFDictionary.h" #import "OFHostAddressResolver.h" #import "OFNumber.h" #import "OFPair.h" #import "OFString.h" #import "OFTCPSocket.h" #import "OFTimer.h" #import "OFUDPSocket.h" #import "OFUDPSocket+Private.h" #import "OFDNSQueryFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFInvalidServerResponseException.h" #import "OFNotImplementedException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #ifndef SOCK_DNS # define SOCK_DNS 0 #endif static const size_t bufferLength = OFDNSResolverBufferLength; static const size_t maxDNSResponseLength = 65536; /* * RFC 1035 doesn't specify if pointers to pointers are allowed, and if so how * many. Since it's unspecified, we have to assume that it might happen, but we * also want to limit it to avoid DoS. Limiting it to 16 levels of pointers and * immediately rejecting pointers to itself seems like a fair balance. */ static const uint_fast8_t maxAllowedPointers = 16; @interface OFDNSResolver () - (void)of_contextTimedOut: (OFDNSResolverContext *)context; @end OF_DIRECT_MEMBERS @interface OFDNSResolverContext: OFObject { @public OFDNSQuery *_query; OFNumber *_ID; OFDNSResolverSettings *_settings; size_t _nameServersIndex; unsigned int _attempt; id _delegate; OFData *_queryData; OFSocketAddress _usedNameServer; OFTCPSocket *_TCPSocket; OFMutableData *_TCPQueryData; void *_TCPBuffer; size_t _responseLength; OFTimer *_cancelTimer; } - (instancetype)initWithQuery: (OFDNSQuery *)query ID: (OFNumber *)ID settings: (OFDNSResolverSettings *)settings delegate: (id )delegate; @end static OFString * parseString(const unsigned char *buffer, size_t length, size_t *i) { uint8_t stringLength; OFString *string; if (*i >= length) @throw [OFTruncatedDataException exception]; stringLength = buffer[(*i)++]; if (*i + stringLength > length) @throw [OFTruncatedDataException exception]; string = [OFString stringWithUTF8String: (char *)&buffer[*i] length: stringLength]; *i += stringLength; return string; } static OFString * parseName(const unsigned char *buffer, size_t length, size_t *i, uint_fast8_t pointerLevel) { OFMutableArray *components = [OFMutableArray array]; uint8_t componentLength; do { OFString *component; if (*i >= length) @throw [OFTruncatedDataException exception]; componentLength = buffer[(*i)++]; if (componentLength & 0xC0) { size_t j; OFString *suffix; if (pointerLevel == 0) @throw [OFInvalidServerResponseException exception]; if (*i >= length) @throw [OFTruncatedDataException exception]; j = ((componentLength & 0x3F) << 8) | buffer[(*i)++]; if (j == *i - 2) /* Pointing to itself?! */ @throw [OFInvalidServerResponseException exception]; suffix = parseName(buffer, length, &j, pointerLevel - 1); if (components.count == 0) return suffix; else { [components addObject: suffix]; return [components componentsJoinedByString: @"."]; } } if (*i + componentLength > length) @throw [OFTruncatedDataException exception]; component = [OFString stringWithUTF8String: (char *)&buffer[*i] length: componentLength]; *i += componentLength; [components addObject: component]; } while (componentLength > 0); return [components componentsJoinedByString: @"."]; } static OF_KINDOF(OFDNSResourceRecord *) parseResourceRecord(OFString *name, OFDNSClass DNSClass, OFDNSRecordType recordType, uint32_t TTL, const unsigned char *buffer, size_t length, size_t i, uint16_t dataLength) { if (recordType == OFDNSRecordTypeA && DNSClass == OFDNSClassIN) { OFSocketAddress address; if (dataLength != 4) @throw [OFInvalidServerResponseException exception]; memset(&address, 0, sizeof(address)); address.family = OFSocketAddressFamilyIPv4; address.length = sizeof(address.sockaddr.in); address.sockaddr.in.sin_family = AF_INET; memcpy(&address.sockaddr.in.sin_addr.s_addr, buffer + i, 4); return [[[OFADNSResourceRecord alloc] initWithName: name address: &address TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeNS) { size_t j = i; OFString *authoritativeHost = parseName(buffer, length, &j, maxAllowedPointers); if (j != i + dataLength) @throw [OFInvalidServerResponseException exception]; return [[[OFNSDNSResourceRecord alloc] initWithName: name DNSClass: DNSClass authoritativeHost: authoritativeHost TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeCNAME) { size_t j = i; OFString *alias = parseName(buffer, length, &j, maxAllowedPointers); if (j != i + dataLength) @throw [OFInvalidServerResponseException exception]; return [[[OFCNAMEDNSResourceRecord alloc] initWithName: name DNSClass: DNSClass alias: alias TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeSOA) { size_t j = i; OFString *primaryNameServer = parseName(buffer, length, &j, maxAllowedPointers); OFString *responsiblePerson; uint32_t serialNumber, refreshInterval, retryInterval; uint32_t expirationInterval, minTTL; if (j > i + dataLength) @throw [OFInvalidServerResponseException exception]; responsiblePerson = parseName(buffer, length, &j, maxAllowedPointers); if (dataLength - (j - i) != 20) @throw [OFInvalidServerResponseException exception]; serialNumber = (buffer[j] << 24) | (buffer[j + 1] << 16) | (buffer[j + 2] << 8) | buffer[j + 3]; refreshInterval = (buffer[j + 4] << 24) | (buffer[j + 5] << 16) | (buffer[j + 6] << 8) | buffer[j + 7]; retryInterval = (buffer[j + 8] << 24) | (buffer[j + 9] << 16) | (buffer[j + 10] << 8) | buffer[j + 11]; expirationInterval = (buffer[j + 12] << 24) | (buffer[j + 13] << 16) | (buffer[j + 14] << 8) | buffer[j + 15]; minTTL = (buffer[j + 16] << 24) | (buffer[j + 17] << 16) | (buffer[j + 18] << 8) | buffer[j + 19]; return [[[OFSOADNSResourceRecord alloc] initWithName: name DNSClass: DNSClass primaryNameServer: primaryNameServer responsiblePerson: responsiblePerson serialNumber: serialNumber refreshInterval: refreshInterval retryInterval: retryInterval expirationInterval: expirationInterval minTTL: minTTL TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypePTR) { size_t j = i; OFString *domainName = parseName(buffer, length, &j, maxAllowedPointers); if (j != i + dataLength) @throw [OFInvalidServerResponseException exception]; return [[[OFPTRDNSResourceRecord alloc] initWithName: name DNSClass: DNSClass domainName: domainName TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeHINFO) { size_t j = i; OFString *CPU = parseString(buffer, length, &j); OFString *OS; if (j > i + dataLength) @throw [OFInvalidServerResponseException exception]; OS = parseString(buffer, length, &j); if (j != i + dataLength) @throw [OFInvalidServerResponseException exception]; return [[[OFHINFODNSResourceRecord alloc] initWithName: name DNSClass: DNSClass CPU: CPU OS: OS TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeMX) { uint16_t preference; size_t j; OFString *mailExchange; if (dataLength < 2) @throw [OFInvalidServerResponseException exception]; preference = (buffer[i] << 8) | buffer[i + 1]; j = i + 2; mailExchange = parseName(buffer, length, &j, maxAllowedPointers); if (j != i + dataLength) @throw [OFInvalidServerResponseException exception]; return [[[OFMXDNSResourceRecord alloc] initWithName: name DNSClass: DNSClass preference: preference mailExchange: mailExchange TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeTXT) { OFMutableArray *textStrings = [OFMutableArray array]; while (dataLength > 0) { uint_fast8_t stringLength = buffer[i++]; dataLength--; if (stringLength > dataLength) @throw [OFInvalidServerResponseException exception]; [textStrings addObject: [OFData dataWithItems: buffer + i count: stringLength]]; i += stringLength; dataLength -= stringLength; } [textStrings makeImmutable]; return [[[OFTXTDNSResourceRecord alloc] initWithName: name DNSClass: DNSClass textStrings: textStrings TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeRP) { size_t j = i; OFString *mailbox = parseName(buffer, length, &j, maxAllowedPointers); OFString *TXTDomainName; if (j > i + dataLength) @throw [OFInvalidServerResponseException exception]; TXTDomainName = parseName(buffer, length, &j, maxAllowedPointers); if (j != i + dataLength) @throw [OFInvalidServerResponseException exception]; return [[[OFRPDNSResourceRecord alloc] initWithName: name DNSClass: DNSClass mailbox: mailbox TXTDomainName: TXTDomainName TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeAAAA && DNSClass == OFDNSClassIN) { OFSocketAddress address; if (dataLength != 16) @throw [OFInvalidServerResponseException exception]; memset(&address, 0, sizeof(address)); address.family = OFSocketAddressFamilyIPv6; address.length = sizeof(address.sockaddr.in6); #ifdef AF_INET6 address.sockaddr.in6.sin6_family = AF_INET6; #else address.sockaddr.in6.sin6_family = AF_UNSPEC; #endif memcpy(address.sockaddr.in6.sin6_addr.s6_addr, buffer + i, 16); return [[[OFAAAADNSResourceRecord alloc] initWithName: name address: &address TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeLOC) { uint8_t size, horizontalPrecision, verticalPrecision; uint32_t latitude, longitude, altitude; if (dataLength < 16 || buffer[i] != 0) @throw [OFInvalidServerResponseException exception]; size = buffer[i + 1]; horizontalPrecision = buffer[i + 2]; verticalPrecision = buffer[i + 3]; latitude = (buffer[i + 4] << 24) | (buffer[i + 5] << 16) | (buffer[i + 6] << 8) | buffer[i + 7]; longitude = (buffer[i + 8] << 24) | (buffer[i + 9] << 16) | (buffer[i + 10] << 8) | buffer[i + 11]; altitude = (buffer[i + 12] << 24) | (buffer[i + 13] << 16) | (buffer[i + 14] << 8) | buffer[i + 15]; return [[[OFLOCDNSResourceRecord alloc] initWithName: name DNSClass: DNSClass size: size horizontalPrecision: horizontalPrecision verticalPrecision: verticalPrecision latitude: latitude longitude: longitude altitude: altitude TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeSRV && DNSClass == OFDNSClassIN) { uint16_t priority, weight, port; size_t j; OFString *target; if (dataLength < 6) @throw [OFInvalidServerResponseException exception]; priority = (buffer[i] << 8) | buffer[i + 1]; weight = (buffer[i + 2] << 8) | buffer[i + 3]; port = (buffer[i + 4] << 8) | buffer[i + 5]; j = i + 6; target = parseName(buffer, length, &j, maxAllowedPointers); if (j != i + dataLength) @throw [OFInvalidServerResponseException exception]; return [[[OFSRVDNSResourceRecord alloc] initWithName: name priority: priority weight: weight target: target port: port TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeURI) { uint16_t priority, weight; OFString *target; if (dataLength < 4) @throw [OFInvalidServerResponseException exception]; priority = (buffer[i] << 8) | buffer[i + 1]; weight = (buffer[i + 2] << 8) | buffer[i + 3]; target = [OFString stringWithUTF8String: (char *)buffer + i + 4 length: dataLength - 4]; return [[[OFURIDNSResourceRecord alloc] initWithName: name DNSClass: DNSClass priority: priority weight: weight target: target TTL: TTL] autorelease]; } else return [[[OFDNSResourceRecord alloc] initWithName: name DNSClass: DNSClass recordType: recordType TTL: TTL] autorelease]; } static OFDictionary * parseSection(const unsigned char *buffer, size_t length, size_t *i, uint_fast16_t count) { OFMutableDictionary *ret = [OFMutableDictionary dictionary]; OFEnumerator OF_GENERIC(OFMutableArray *) *objectEnumerator; OFMutableArray *array; for (uint_fast16_t j = 0; j < count; j++) { OFString *name = parseName(buffer, length, i, maxAllowedPointers).lowercaseString; OFDNSClass DNSClass; OFDNSRecordType recordType; uint32_t TTL; uint16_t dataLength; OFDNSResourceRecord *record; if (*i + 10 > length) @throw [OFTruncatedDataException exception]; recordType = (buffer[*i] << 8) | buffer[*i + 1]; DNSClass = (buffer[*i + 2] << 8) | buffer[*i + 3]; TTL = (buffer[*i + 4] << 24) | (buffer[*i + 5] << 16) | (buffer[*i + 6] << 8) | buffer[*i + 7]; dataLength = (buffer[*i + 8] << 8) | buffer[*i + 9]; *i += 10; if (*i + dataLength > length) @throw [OFTruncatedDataException exception]; record = parseResourceRecord(name, DNSClass, recordType, TTL, buffer, length, *i, dataLength); *i += dataLength; array = [ret objectForKey: name]; if (array == nil) { array = [OFMutableArray array]; [ret setObject: array forKey: name]; } [array addObject: record]; } objectEnumerator = [ret objectEnumerator]; while ((array = [objectEnumerator nextObject]) != nil) [array makeImmutable]; [ret makeImmutable]; return ret; } static bool containsExpiredRecord(OFDNSResponseRecords responseRecords, uint32_t age) { OFEnumerator *enumerator = [responseRecords objectEnumerator]; OFArray OF_GENERIC(OFDNSResourceRecord *) *records; while ((records = [enumerator nextObject]) != nil) for (OFDNSResourceRecord *record in records) if (record.TTL < age) return true; return false; } @implementation OFDNSResolverContext - (instancetype)initWithQuery: (OFDNSQuery *)query ID: (OFNumber *)ID settings: (OFDNSResolverSettings *)settings delegate: (id )delegate { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFMutableData *queryData; uint16_t tmp; _query = [query copy]; _ID = [ID retain]; _settings = [settings copy]; _delegate = [delegate retain]; queryData = [OFMutableData dataWithCapacity: 512]; /* Header */ tmp = OFToBigEndian16(_ID.unsignedShortValue); [queryData addItems: &tmp count: 2]; /* RD */ tmp = OFToBigEndian16(1u << 8); [queryData addItems: &tmp count: 2]; /* QDCOUNT */ tmp = OFToBigEndian16(1); [queryData addItems: &tmp count: 2]; /* ANCOUNT, NSCOUNT and ARCOUNT */ [queryData increaseCountBy: 6]; /* Question */ /* QNAME */ for (OFString *component in [_query.domainName componentsSeparatedByString: @"."]) { size_t length = component.UTF8StringLength; uint8_t length8; if (length > 63 || queryData.count + length > 512) @throw [OFOutOfRangeException exception]; length8 = (uint8_t)length; [queryData addItem: &length8]; [queryData addItems: component.UTF8String count: length]; } /* QTYPE */ tmp = OFToBigEndian16(_query.recordType); [queryData addItems: &tmp count: 2]; /* QCLASS */ tmp = OFToBigEndian16(_query.DNSClass); [queryData addItems: &tmp count: 2]; [queryData makeImmutable]; _queryData = [queryData copy]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_query release]; [_ID release]; [_settings release]; [_delegate release]; [_queryData release]; [_TCPSocket release]; [_TCPQueryData release]; OFFreeMemory(_TCPBuffer); [_cancelTimer release]; [super dealloc]; } @end @implementation OFDNSResolver #ifdef OF_AMIGAOS + (void)initialize { if (self != [OFDNSResolver class]) return; if (!_OFSocketInit()) @throw [OFInitializationFailedException exceptionWithClass: self]; } #endif + (instancetype)resolver { return [[[self alloc] init] autorelease]; } - (instancetype)init { self = [super init]; @try { _settings = [[OFDNSResolverSettings alloc] init]; _queries = [[OFMutableDictionary alloc] init]; _TCPQueries = [[OFMutableDictionary alloc] init]; _cache = [[OFMutableDictionary alloc] init]; [_settings reload]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [self close]; [_settings release]; [_IPv4Socket cancelAsyncRequests]; [_IPv4Socket release]; #ifdef OF_HAVE_IPV6 [_IPv6Socket cancelAsyncRequests]; [_IPv6Socket release]; #endif [_queries release]; [_TCPQueries release]; [_cache release]; [_lastNameServers release]; [super dealloc]; } - (OFDictionary *)staticHosts { return _settings->_staticHosts; } - (void)setStaticHosts: (OFDictionary *)staticHosts { OFDictionary *old = _settings->_staticHosts; _settings->_staticHosts = [staticHosts copy]; [old release]; } - (OFArray *)nameServers { return _settings->_nameServers; } - (void)setNameServers: (OFArray *)nameServers { OFArray *old = _settings->_nameServers; _settings->_nameServers = [nameServers copy]; [old release]; } - (OFString *)localDomain { return _settings->_localDomain; } - (OFArray *)searchDomains { return _settings->_searchDomains; } - (void)setSearchDomains: (OFArray *)searchDomains { OFArray *old = _settings->_searchDomains; _settings->_searchDomains = [searchDomains copy]; [old release]; } - (OFTimeInterval)timeout { return _settings->_timeout; } - (void)setTimeout: (OFTimeInterval)timeout { _settings->_timeout = timeout; } - (unsigned int)maxAttempts { return _settings->_maxAttempts; } - (void)setMaxAttempts: (unsigned int)maxAttempts { _settings->_maxAttempts = maxAttempts; } - (unsigned int)minNumberOfDotsInAbsoluteName { return _settings->_minNumberOfDotsInAbsoluteName; } - (void)setMinNumberOfDotsInAbsoluteName: (unsigned int)minNumberOfDotsInAbsoluteName { _settings->_minNumberOfDotsInAbsoluteName = minNumberOfDotsInAbsoluteName; } - (bool)forcesTCP { return _settings->_forcesTCP; } - (void)setForcesTCP: (bool)forcesTCP { _settings->_forcesTCP = forcesTCP; } - (OFTimeInterval)configReloadInterval { return _settings->_configReloadInterval; } - (void)setConfigReloadInterval: (OFTimeInterval)configReloadInterval { _settings->_configReloadInterval = configReloadInterval; } - (void)of_sendQueryForContext: (OFDNSResolverContext *)context runLoopMode: (OFRunLoopMode)runLoopMode { OFUDPSocket *sock; OFString *nameServer; [_queries setObject: context forKey: context->_ID]; [context->_cancelTimer invalidate]; [context->_cancelTimer release]; context->_cancelTimer = nil; context->_cancelTimer = [[OFTimer alloc] initWithFireDate: [OFDate dateWithTimeIntervalSinceNow: context->_settings->_timeout] interval: context->_settings->_timeout target: self selector: @selector(of_contextTimedOut:) object: context repeats: false]; [[OFRunLoop currentRunLoop] addTimer: context->_cancelTimer forMode: runLoopMode]; nameServer = [context->_settings->_nameServers objectAtIndex: context->_nameServersIndex]; if (context->_settings->_forcesTCP) { OFEnsure(context->_TCPSocket == nil); context->_TCPSocket = [[OFTCPSocket alloc] init]; [_TCPQueries setObject: context forKey: context->_TCPSocket]; context->_TCPSocket.delegate = self; [context->_TCPSocket asyncConnectToHost: nameServer port: 53 runLoopMode: runLoopMode]; return; } context->_usedNameServer = OFSocketAddressParseIP(nameServer, 53); switch (context->_usedNameServer.family) { #ifdef OF_HAVE_IPV6 case OFSocketAddressFamilyIPv6: if (_IPv6Socket == nil) { OFSocketAddress address = OFSocketAddressParseIPv6(@"::", 0); _IPv6Socket = [[OFUDPSocket alloc] init]; [_IPv6Socket of_bindToAddress: &address extraType: SOCK_DNS]; @try { _IPv6Socket.canBlock = false; } @catch (OFNotImplementedException *e) { /* Can't do anything about it... */ } _IPv6Socket.delegate = self; } sock = _IPv6Socket; break; #endif case OFSocketAddressFamilyIPv4: if (_IPv4Socket == nil) { OFSocketAddress address = OFSocketAddressParseIPv4(@"0.0.0.0", 0); _IPv4Socket = [[OFUDPSocket alloc] init]; [_IPv4Socket of_bindToAddress: &address extraType: SOCK_DNS]; @try { _IPv4Socket.canBlock = false; } @catch (OFNotImplementedException *e) { /* Can't do anything about it... */ } _IPv4Socket.delegate = self; } sock = _IPv4Socket; break; default: @throw [OFInvalidArgumentException exception]; } [sock asyncSendData: context->_queryData receiver: &context->_usedNameServer runLoopMode: runLoopMode]; [sock asyncReceiveIntoBuffer: _buffer length: bufferLength runLoopMode: runLoopMode]; } - (void)of_cleanUpCache { OFTimeInterval now = [[OFDate date] timeIntervalSince1970]; OFMutableArray *removeList; if (_lastNameServers != _settings->_nameServers && ![_lastNameServers isEqual: _settings->_nameServers]) { OFArray *old = _lastNameServers; _lastNameServers = [_settings->_nameServers copy]; [old release]; [_cache removeAllObjects]; return; } if (now - _lastCacheCleanup < 1) return; _lastCacheCleanup = now; removeList = [OFMutableArray arrayWithCapacity: _cache.count]; for (OFDNSQuery *query in _cache) { OFPair OF_GENERIC(OFDate *, OFDNSResponse *) *entry = [_cache objectForKey: query]; uint32_t age = (uint32_t)now - (uint32_t)[entry.firstObject timeIntervalSince1970]; OFDNSResponse *response = entry.secondObject; if (containsExpiredRecord(response.answerRecords, age) || containsExpiredRecord(response.authorityRecords, age) || containsExpiredRecord(response.additionalRecords, age)) [removeList addObject: query]; } for (OFDNSQuery *query in removeList) [_cache removeObjectForKey: query]; } - (void)asyncPerformQuery: (OFDNSQuery *)query delegate: (id )delegate { [self asyncPerformQuery: query runLoopMode: OFDefaultRunLoopMode delegate: delegate]; } - (void)asyncPerformQuery: (OFDNSQuery *)query runLoopMode: (OFRunLoopMode)runLoopMode delegate: (id )delegate { void *pool = objc_autoreleasePoolPush(); OFNumber *ID; OFDNSResolverContext *context; OFPair OF_GENERIC(OFDate *, OFDNSResponse *) *cacheEntry; [self of_cleanUpCache]; if ((cacheEntry = [_cache objectForKey: query]) != nil) { uint32_t age = (uint32_t)-[cacheEntry.firstObject timeIntervalSinceNow]; OFDNSResponse *response = cacheEntry.secondObject; if (!containsExpiredRecord(response.answerRecords, age) && !containsExpiredRecord(response.authorityRecords, age) && !containsExpiredRecord(response.additionalRecords, age)) { OFTimer *timer = [OFTimer timerWithTimeInterval: 0 target: delegate selector: @selector(resolver: didPerformQuery:response: exception:) object: self object: query object: response object: nil repeats: false]; [[OFRunLoop currentRunLoop] addTimer: timer forMode: runLoopMode]; objc_autoreleasePoolPop(pool); return; } } /* Random, unused ID */ do { ID = [OFNumber numberWithUnsignedShort: OFRandom16()]; } while ([_queries objectForKey: ID] != nil); if (query.domainName.UTF8StringLength > 253) @throw [OFOutOfRangeException exception]; if (_settings->_nameServers.count == 0) { id exception = [OFDNSQueryFailedException exceptionWithQuery: query errorCode: OFDNSResolverErrorCodeNoNameServer]; [delegate resolver: self didPerformQuery: query response: nil exception: exception]; return; } context = [[[OFDNSResolverContext alloc] initWithQuery: query ID: ID settings: _settings delegate: delegate] autorelease]; [self of_sendQueryForContext: context runLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } - (void)of_contextTimedOut: (OFDNSResolverContext *)context { OFRunLoopMode runLoopMode = [OFRunLoop currentRunLoop].currentMode; OFDNSQueryFailedException *exception; if (context->_TCPSocket != nil) { context->_TCPSocket.delegate = nil; [context->_TCPSocket cancelAsyncRequests]; [_TCPQueries removeObjectForKey: context->_TCPSocket]; [context->_TCPSocket release]; context->_TCPSocket = nil; context->_responseLength = 0; } if (context->_nameServersIndex + 1 < context->_settings->_nameServers.count) { context->_nameServersIndex++; [self of_sendQueryForContext: context runLoopMode: runLoopMode]; return; } if (++context->_attempt < context->_settings->_maxAttempts) { context->_nameServersIndex = 0; [self of_sendQueryForContext: context runLoopMode: runLoopMode]; return; } context = [[context retain] autorelease]; [_queries removeObjectForKey: context->_ID]; /* * Cancel any pending queries, to avoid a send being still pending and * trying to access the query once it no longer exists. */ [_IPv4Socket cancelAsyncRequests]; [_IPv4Socket asyncReceiveIntoBuffer: _buffer length: bufferLength]; #ifdef OF_HAVE_IPV6 [_IPv6Socket cancelAsyncRequests]; [_IPv6Socket asyncReceiveIntoBuffer: _buffer length: bufferLength]; #endif exception = [OFDNSQueryFailedException exceptionWithQuery: context->_query errorCode: OFDNSResolverErrorCodeTimeout]; [context->_delegate resolver: self didPerformQuery: context->_query response: nil exception: exception]; } - (bool)of_handleResponseBuffer: (unsigned char *)buffer length: (size_t)length sender: (const OFSocketAddress *)sender { OFDictionary *answerRecords = nil, *authorityRecords = nil; OFDictionary *additionalRecords = nil; OFDNSResponse *response = nil; id exception = nil; OFNumber *ID; OFDNSResolverContext *context; if (length < 2) /* We can't get the ID to get the context. Ignore packet. */ return true; ID = [OFNumber numberWithUnsignedShort: (buffer[0] << 8) | buffer[1]]; context = [[[_queries objectForKey: ID] retain] autorelease]; if (context == nil) return true; if (context->_TCPSocket != nil) { if ([_TCPQueries objectForKey: context->_TCPSocket] != context) return true; } else if (sender == NULL || !OFSocketAddressEqual(sender, &context->_usedNameServer)) return true; [context->_cancelTimer invalidate]; [context->_cancelTimer release]; context->_cancelTimer = nil; [_queries removeObjectForKey: ID]; @try { OFDNSResolverErrorCode errorCode = 0; bool tryNextNameServer = false; const unsigned char *queryDataBuffer; size_t i; uint16_t numQuestions, numAnswers, numAuthorityRecords; uint16_t numAdditionalRecords; if (length < 12) @throw [OFTruncatedDataException exception]; if (context->_queryData.itemSize != 1 || context->_queryData.count < 12) @throw [OFInvalidArgumentException exception]; queryDataBuffer = context->_queryData.items; /* QR */ if ((buffer[2] & 0x80) == 0) @throw [OFInvalidServerResponseException exception]; /* Opcode */ if ((buffer[2] & 0x78) != (queryDataBuffer[2] & 0x78)) @throw [OFInvalidServerResponseException exception]; /* TC */ if (buffer[2] & 0x02) { OFRunLoopMode runLoopMode; if (context->_settings->_forcesTCP) @throw [OFTruncatedDataException exception]; context->_settings->_forcesTCP = true; runLoopMode = [OFRunLoop currentRunLoop].currentMode; [self of_sendQueryForContext: context runLoopMode: runLoopMode]; return false; } /* RCODE */ switch (buffer[3] & 0x0F) { case 0: break; case 1: errorCode = OFDNSResolverErrorCodeServerInvalidFormat; break; case 2: errorCode = OFDNSResolverErrorCodeServerFailure; tryNextNameServer = true; break; case 3: errorCode = OFDNSResolverErrorCodeServerNameError; break; case 4: errorCode = OFDNSResolverErrorCodeServerNotImplemented; tryNextNameServer = true; break; case 5: errorCode = OFDNSResolverErrorCodeServerRefused; tryNextNameServer = true; break; default: errorCode = OFDNSResolverErrorCodeUnknown; tryNextNameServer = true; break; } if (tryNextNameServer) { if (context->_nameServersIndex + 1 < context->_settings->_nameServers.count) { OFRunLoopMode runLoopMode = [OFRunLoop currentRunLoop].currentMode; context->_nameServersIndex++; [self of_sendQueryForContext: context runLoopMode: runLoopMode]; return false; } } if (buffer[3] & 0x0F) @throw [OFDNSQueryFailedException exceptionWithQuery: context->_query errorCode: errorCode]; numQuestions = (buffer[4] << 8) | buffer[5]; numAnswers = (buffer[6] << 8) | buffer[7]; numAuthorityRecords = (buffer[8] << 8) | buffer[9]; numAdditionalRecords = (buffer[10] << 8) | buffer[11]; i = 12; /* * Skip over the questions - we use the ID to identify the * query. * * TODO: Compare to our query, just in case? */ for (uint_fast16_t j = 0; j < numQuestions; j++) { parseName(buffer, length, &i, maxAllowedPointers); i += 4; } answerRecords = parseSection(buffer, length, &i, numAnswers); authorityRecords = parseSection(buffer, length, &i, numAuthorityRecords); additionalRecords = parseSection(buffer, length, &i, numAdditionalRecords); response = [OFDNSResponse responseWithDomainName: context->_query.domainName answerRecords: answerRecords authorityRecords: authorityRecords additionalRecords: additionalRecords]; } @catch (id e) { exception = e; } if (exception != nil) response = nil; [self of_cleanUpCache]; if (response != nil) [_cache setObject: [OFPair pairWithFirstObject: [OFDate date] secondObject: response] forKey: context->_query]; else [_cache removeObjectForKey: context->_query]; [context->_delegate resolver: self didPerformQuery: context->_query response: response exception: exception]; return false; } - (bool)socket: (OFDatagramSocket *)sock didReceiveIntoBuffer: (void *)buffer length: (size_t)length sender: (const OFSocketAddress *)sender exception: (id)exception { if (exception != nil) return true; return [self of_handleResponseBuffer: buffer length: length sender: sender]; } - (void)socket: (OFTCPSocket *)sock didConnectToHost: (OFString *)host port: (uint16_t)port exception: (id)exception { OFDNSResolverContext *context = [_TCPQueries objectForKey: sock]; OFEnsure(context != nil); if (exception != nil) { /* * TODO: Handle error immediately instead of waiting for the * timer to try the next nameserver or to retry. */ [_TCPQueries removeObjectForKey: context->_TCPSocket]; [context->_TCPSocket release]; context->_TCPSocket = nil; context->_responseLength = 0; return; } if (context->_TCPQueryData == nil) { size_t queryDataCount = context->_queryData.count; uint16_t tmp; if (queryDataCount > UINT16_MAX) @throw [OFOutOfRangeException exception]; context->_TCPQueryData = [[OFMutableData alloc] initWithCapacity: queryDataCount + 2]; tmp = OFToBigEndian16(queryDataCount); [context->_TCPQueryData addItems: &tmp count: sizeof(tmp)]; [context->_TCPQueryData addItems: context->_queryData.items count: queryDataCount]; } [sock asyncWriteData: context->_TCPQueryData]; } - (OFData *)stream: (OFStream *)stream didWriteData: (OFData *)data bytesWritten: (size_t)bytesWritten exception: (id)exception { OFTCPSocket *sock = (OFTCPSocket *)stream; OFDNSResolverContext *context = [_TCPQueries objectForKey: sock]; OFEnsure(context != nil); if (exception != nil) { /* * TODO: Handle error immediately instead of waiting for the * timer to try the next nameserver or to retry. */ [_TCPQueries removeObjectForKey: context->_TCPSocket]; [context->_TCPSocket release]; context->_TCPSocket = nil; context->_responseLength = 0; return nil; } if (context->_TCPBuffer == nil) context->_TCPBuffer = OFAllocMemory(maxDNSResponseLength, 1); [sock asyncReadIntoBuffer: context->_TCPBuffer exactLength: 2]; return nil; } - (bool)stream: (OFStream *)stream didReadIntoBuffer: (void *)buffer length: (size_t)length exception: (id)exception { OFTCPSocket *sock = (OFTCPSocket *)stream; OFDNSResolverContext *context = [_TCPQueries objectForKey: sock]; OFEnsure(context != nil); if (exception != nil) { /* * TODO: Handle error immediately instead of waiting for the * timer to try the next nameserver or to retry. */ goto done; } if (context->_responseLength == 0) { unsigned char *ucBuffer = buffer; OFEnsure(length == 2); context->_responseLength = (ucBuffer[0] << 8) | ucBuffer[1]; if (context->_responseLength > maxDNSResponseLength) @throw [OFOutOfRangeException exception]; if (context->_responseLength == 0) goto done; [sock asyncReadIntoBuffer: context->_TCPBuffer exactLength: context->_responseLength]; return false; } if (length != context->_responseLength) /* * The connection was closed before we received the entire * response. */ goto done; [self of_handleResponseBuffer: buffer length: length sender: NULL]; done: [_TCPQueries removeObjectForKey: context->_TCPSocket]; [context->_TCPSocket release]; context->_TCPSocket = nil; context->_responseLength = 0; return false; } - (void)asyncResolveAddressesForHost: (OFString *)host delegate: (id )delegate { [self asyncResolveAddressesForHost: host addressFamily: OFSocketAddressFamilyAny runLoopMode: OFDefaultRunLoopMode delegate: delegate]; } - (void)asyncResolveAddressesForHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily delegate: (id )delegate { [self asyncResolveAddressesForHost: host addressFamily: addressFamily runLoopMode: OFDefaultRunLoopMode delegate: delegate]; } - (void)asyncResolveAddressesForHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily runLoopMode: (OFRunLoopMode)runLoopMode delegate: (id )delegate { void *pool = objc_autoreleasePoolPush(); OFHostAddressResolver *resolver = [[[OFHostAddressResolver alloc] initWithHost: host addressFamily: addressFamily resolver: self settings: _settings runLoopMode: runLoopMode delegate: delegate] autorelease]; [resolver asyncResolve]; objc_autoreleasePoolPop(pool); } - (OFData *)resolveAddressesForHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily { void *pool = objc_autoreleasePoolPush(); OFHostAddressResolver *resolver = [[[OFHostAddressResolver alloc] initWithHost: host addressFamily: addressFamily resolver: self settings: _settings runLoopMode: nil delegate: nil] autorelease]; OFData *addresses = [resolver resolve]; [addresses retain]; objc_autoreleasePoolPop(pool); return [addresses autorelease]; } - (void)close { void *pool = objc_autoreleasePoolPush(); OFEnumerator OF_GENERIC(OFDNSResolverContext *) *enumerator; OFDNSResolverContext *context; [_IPv4Socket cancelAsyncRequests]; [_IPv4Socket release]; _IPv4Socket = nil; #ifdef OF_HAVE_IPV6 [_IPv6Socket cancelAsyncRequests]; [_IPv6Socket release]; _IPv6Socket = nil; #endif enumerator = [_queries objectEnumerator]; while ((context = [enumerator nextObject]) != nil) { OFDNSQueryFailedException *exception; exception = [OFDNSQueryFailedException exceptionWithQuery: context->_query errorCode: OFDNSResolverErrorCodeCanceled]; [context->_delegate resolver: self didPerformQuery: context->_query response: nil exception: exception]; } [_queries removeAllObjects]; objc_autoreleasePoolPop(pool); } @end objfw-1.1.6/src/OFDNSResolverSettings.h000066400000000000000000000025731465614216400177220ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFDate; @class OFDictionary OF_GENERIC(KeyType, ObjectType); @interface OFDNSResolverSettings: OFObject { @public OFDictionary OF_GENERIC(OFString *, OFArray OF_GENERIC(OFString *) *) *_staticHosts; OFArray OF_GENERIC(OFString *) *_nameServers; OFString *_Nullable _localDomain; OFArray OF_GENERIC(OFString *) *_searchDomains; OFTimeInterval _timeout; unsigned int _maxAttempts, _minNumberOfDotsInAbsoluteName; bool _forcesTCP; OFTimeInterval _configReloadInterval; @protected OFDate *_lastConfigReload; } - (void)reload; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFDNSResolverSettings.m000066400000000000000000000442001465614216400177200ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "unistd_wrapper.h" #import "OFDNSResolverSettings.h" #import "OFArray.h" #import "OFCharacterSet.h" #import "OFDate.h" #import "OFDictionary.h" #ifdef OF_HAVE_FILES # import "OFFile.h" # import "OFFileManager.h" #endif #import "OFLocale.h" #import "OFSocket+Private.h" #import "OFString.h" #ifdef OF_WINDOWS # import "OFWindowsRegistryKey.h" #endif #import "OFInvalidFormatException.h" #import "OFOpenItemFailedException.h" #ifdef OF_WINDOWS # import "OFOpenWindowsRegistryKeyFailedException.h" #endif #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFUndefinedKeyException.h" #ifdef OF_WINDOWS # define interface struct # include # undef interface #endif #ifdef OF_NINTENDO_3DS /* Newer versions of libctru started using id as a parameter name. */ # define id id_3ds # include <3ds.h> # undef id #endif #if defined(OF_AMIGAOS_M68K) || defined(OF_AMIGAOS4) # define Class IntuitionClass # include # undef Class #endif #ifdef OF_MORPHOS # include # include # include #endif #if defined(OF_HAIKU) # define HOSTS_PATH @"/system/settings/network/hosts" # define RESOLV_CONF_PATH @"/system/settings/network/resolv.conf" #else # define HOSTS_PATH @"/etc/hosts" # define RESOLV_CONF_PATH @"/etc/resolv.conf" #endif #ifndef HOST_NAME_MAX # define HOST_NAME_MAX 255 #endif #ifndef OF_WII static OFString * domainFromHostname(OFString *hostname) { OFString *ret; if (hostname == nil) return nil; @try { OFSocketAddressParseIP(hostname, 0); /* * If we are still here, the host name is a valid IP address. * We can't use that as local domain. */ ret = nil; } @catch (OFInvalidFormatException *e) { /* Not an IP address -> we can use it if it contains a dot. */ size_t pos = [hostname rangeOfString: @"."].location; if (pos != OFNotFound) ret = [hostname substringFromIndex: pos + 1]; else ret = nil; } return ret; } #endif #if !defined(OF_WII) && !defined(OF_MORPHOS) static OFString * obtainHostname(void) { char hostname[HOST_NAME_MAX + 1]; if (gethostname(hostname, HOST_NAME_MAX + 1) != 0) return nil; return [OFString stringWithCString: hostname encoding: [OFLocale encoding]]; } #endif #ifdef OF_AMIGAOS_M68K static bool assignExists(const char *assign) { struct DosList *list = LockDosList(LDF_ASSIGNS | LDF_READ); bool found = (FindDosEntry(list, assign, LDF_ASSIGNS) != NULL); UnLockDosList(LDF_ASSIGNS | LDF_READ); return found; } #endif #ifdef OF_MORPHOS static OFString * arexxCommand(const char *port, const char *command) { struct Library *RexxSysBase; struct MsgPort *replyPort = NULL; struct RexxMsg *msg = NULL; if ((RexxSysBase = OpenLibrary("rexxsyslib.library", 36)) == NULL) return nil; @try { struct MsgPort *rexxPort; if ((replyPort = CreateMsgPort()) == NULL) return nil; if ((msg = CreateRexxMsg(replyPort, NULL, port)) == NULL) return nil; msg->rm_Action = RXCOMM | RXFF_RESULT; if ((msg->rm_Args[0] = (char *)CreateArgstring( command, strlen(command))) == NULL) return nil; Forbid(); if ((rexxPort = FindPort(port)) == NULL) { Permit(); return nil; } PutMsg(rexxPort, &msg->rm_Node); Permit(); WaitPort(replyPort); GetMsg(replyPort); if (msg->rm_Result1 != RC_OK || msg->rm_Result2 == 0) return nil; return [OFString stringWithCString: (char *)msg->rm_Result2 encoding: [OFLocale encoding]]; } @finally { if (msg != NULL) { if (msg->rm_Args[0] != NULL) DeleteArgstring(msg->rm_Args[0]); if (msg->rm_Result2 != 0) DeleteArgstring((char *)msg->rm_Result2); DeleteRexxMsg(msg); } if (replyPort != NULL) DeleteMsgPort(replyPort); CloseLibrary(RexxSysBase); } } static OFArray OF_GENERIC(OFString *) * parseNetStackArray(OFString *string) { if (![string hasPrefix: @"["] || ![string hasSuffix: @"]"]) return nil; string = [string substringWithRange: OFMakeRange(1, string.length - 2)]; return [string componentsSeparatedByString: @"|"]; } #endif @implementation OFDNSResolverSettings - (void)dealloc { [_staticHosts release]; [_nameServers release]; [_localDomain release]; [_searchDomains release]; [_lastConfigReload release]; [super dealloc]; } - (id)copy { OFDNSResolverSettings *copy = [[OFDNSResolverSettings alloc] init]; @try { copy->_staticHosts = [_staticHosts copy]; copy->_nameServers = [_nameServers copy]; copy->_localDomain = [_localDomain copy]; copy->_searchDomains = [_searchDomains copy]; copy->_timeout = _timeout; copy->_maxAttempts = _maxAttempts; copy->_minNumberOfDotsInAbsoluteName = _minNumberOfDotsInAbsoluteName; copy->_forcesTCP = _forcesTCP; copy->_configReloadInterval = _configReloadInterval; copy->_lastConfigReload = [_lastConfigReload copy]; } @catch (id e) { [copy release]; @throw e; } return copy; } - (void)setDefaults { [_staticHosts release]; _staticHosts = nil; [_nameServers release]; _nameServers = nil; [_localDomain release]; _localDomain = nil; [_searchDomains release]; _searchDomains = nil; _timeout = 2; _maxAttempts = 3; _minNumberOfDotsInAbsoluteName = 1; _forcesTCP = false; #ifndef OF_NINTENDO_3DS _configReloadInterval = 2; #else _configReloadInterval = 0; #endif } #if defined(OF_HAVE_FILES) && !defined(OF_MORPHOS) && !defined(OF_NINTENDO_3DS) - (void)parseHosts: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFCharacterSet *whitespaceCharacterSet = [OFCharacterSet whitespaceCharacterSet]; OFCharacterSet *commentCharacters = [OFCharacterSet characterSetWithCharactersInString: @"#;"]; OFMutableDictionary *staticHosts; OFFile *file; OFString *line; @try { file = [OFFile fileWithPath: path mode: @"r"]; } @catch (OFOpenItemFailedException *e) { objc_autoreleasePoolPop(pool); return; } staticHosts = [OFMutableDictionary dictionary]; while ((line = [file readLineWithEncoding: [OFLocale encoding]]) != nil) { OFArray *components, *hosts; size_t pos; OFString *address; pos = [line indexOfCharacterFromSet: commentCharacters]; if (pos != OFNotFound) line = [line substringToIndex: pos]; components = [line componentsSeparatedByCharactersInSet: whitespaceCharacterSet options: OFStringSkipEmptyComponents]; if (components.count < 2) continue; address = components.firstObject; hosts = [components objectsInRange: OFMakeRange(1, components.count - 1)]; for (OFString *host in hosts) { OFMutableArray *addresses; host = host.lowercaseString; addresses = [staticHosts objectForKey: host]; if (addresses == nil) { addresses = [OFMutableArray array]; [staticHosts setObject: addresses forKey: host]; } [addresses addObject: address]; } } for (OFMutableArray *addresses in [staticHosts objectEnumerator]) [addresses makeImmutable]; [staticHosts makeImmutable]; _staticHosts = [staticHosts copy]; objc_autoreleasePoolPop(pool); } # ifndef OF_WINDOWS - (void)parseResolvConfOption: (OFString *)option { @try { if ([option hasPrefix: @"ndots:"]) { unsigned long long number; option = [option substringFromIndex: 6]; number = option.unsignedLongLongValue; if (number > UINT_MAX) @throw [OFOutOfRangeException exception]; _minNumberOfDotsInAbsoluteName = (unsigned int)number; } else if ([option hasPrefix: @"timeout:"]) { option = [option substringFromIndex: 8]; _timeout = option.unsignedLongLongValue; } else if ([option hasPrefix: @"attempts:"]) { unsigned long long number; option = [option substringFromIndex: 9]; number = option.unsignedLongLongValue; if (number > UINT_MAX) @throw [OFOutOfRangeException exception]; _maxAttempts = (unsigned int)number; } else if ([option hasPrefix: @"reload-period:"]) { option = [option substringFromIndex: 14]; _configReloadInterval = option.unsignedLongLongValue; } else if ([option isEqual: @"tcp"]) _forcesTCP = true; } @catch (OFInvalidFormatException *e) { } } - (void)parseResolvConf: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFCharacterSet *whitespaceCharacterSet = [OFCharacterSet whitespaceCharacterSet]; OFCharacterSet *commentCharacters = [OFCharacterSet characterSetWithCharactersInString: @"#;"]; OFMutableArray *nameServers = [[_nameServers mutableCopy] autorelease]; OFFile *file; OFString *line; @try { file = [OFFile fileWithPath: path mode: @"r"]; } @catch (OFOpenItemFailedException *e) { objc_autoreleasePoolPop(pool); return; } if (nameServers == nil) nameServers = [OFMutableArray array]; while ((line = [file readLineWithEncoding: [OFLocale encoding]]) != nil) { void *pool2 = objc_autoreleasePoolPush(); size_t pos; OFArray *components, *arguments; OFString *option; pos = [line indexOfCharacterFromSet: commentCharacters]; if (pos != OFNotFound) line = [line substringToIndex: pos]; components = [line componentsSeparatedByCharactersInSet: whitespaceCharacterSet options: OFStringSkipEmptyComponents]; if (components.count < 2) { objc_autoreleasePoolPop(pool2); continue; } option = [components.firstObject lowercaseString]; arguments = [components objectsInRange: OFMakeRange(1, components.count - 1)]; if ([option isEqual: @"nameserver"]) { if (arguments.count != 1) { objc_autoreleasePoolPop(pool2); continue; } [nameServers addObject: arguments.firstObject]; } else if ([option isEqual: @"domain"]) { if (arguments.count != 1) { objc_autoreleasePoolPop(pool2); continue; } [_localDomain release]; _localDomain = [arguments.firstObject copy]; } else if ([option isEqual: @"search"]) { [_searchDomains release]; _searchDomains = [arguments copy]; } else if ([option isEqual: @"options"]) for (OFString *argument in arguments) [self parseResolvConfOption: argument]; objc_autoreleasePoolPop(pool2); } [nameServers makeImmutable]; [_nameServers release]; _nameServers = [nameServers copy]; objc_autoreleasePoolPop(pool); } # endif #endif #ifdef OF_WINDOWS - (void)obtainWindowsSystemConfig { OFStringEncoding encoding = [OFLocale encoding]; OFMutableArray *nameServers; /* * We need more space than FIXED_INFO in case we have more than one * name server, but we also want it to be properly aligned, meaning we * can't just get a buffer of bytes. Thus, we just get space for 8. */ FIXED_INFO fixedInfo[8]; ULONG length = sizeof(fixedInfo); PIP_ADDR_STRING iter; if (GetNetworkParams(fixedInfo, &length) != ERROR_SUCCESS) return; nameServers = [OFMutableArray array]; for (iter = &fixedInfo->DnsServerList; iter != NULL; iter = iter->Next) { OFString *nameServer = [OFString stringWithCString: iter->IpAddress.String encoding: encoding]; if (nameServer.length > 0) [nameServers addObject: nameServer]; } if (nameServers.count > 0) { [nameServers makeImmutable]; _nameServers = [nameServers copy]; } if (fixedInfo->DomainName[0] != '\0') _localDomain = [[OFString alloc] initWithCString: fixedInfo->DomainName encoding: encoding]; } #endif #ifdef OF_MORPHOS - (void)obtainMorphOSSystemConfig { void *pool = objc_autoreleasePoolPush(); OFMutableDictionary *staticHosts; _nameServers = [parseNetStackArray(arexxCommand("NETSTACK", "QUERY NAMESERVERS")) copy]; _localDomain = [domainFromHostname(arexxCommand("NETSTACK", "QUERY HOSTNAME")) copy]; _searchDomains = [parseNetStackArray(arexxCommand("NETSTACK", "QUERY DOMAINS")) copy]; staticHosts = [OFMutableDictionary dictionary]; for (OFString *entry in parseNetStackArray(arexxCommand("NETSTACK", "QUERY HOSTS"))) { OFArray *components = [entry componentsSeparatedByString: @" "]; OFString *address; OFArray *hosts; if (components.count < 2) continue; address = components.firstObject; hosts = [components objectsInRange: OFMakeRange(1, components.count - 1)]; for (OFString *host in hosts) { OFMutableArray *addresses; host = host.lowercaseString; addresses = [staticHosts objectForKey: host]; if (addresses == nil) { addresses = [OFMutableArray array]; [staticHosts setObject: addresses forKey: host]; } [addresses addObject: address]; } } for (OFMutableArray *addresses in [staticHosts objectEnumerator]) [addresses makeImmutable]; [staticHosts makeImmutable]; _staticHosts = [staticHosts copy]; objc_autoreleasePoolPop(pool); } #endif #if defined(OF_AMIGAOS_M68K) || defined(OF_AMIGAOS4) - (bool)obtainRoadshowSystemConfig { OFMutableArray *nameServers; OFStringEncoding encoding; struct List *nameServerList; char buffer[MAXHOSTNAMELEN]; LONG hasDNSAPI; if (SocketBaseTags(SBTM_GETREF(SBTC_HAVE_DNS_API), (ULONG)&hasDNSAPI, TAG_END) != 0 || !hasDNSAPI) return false; nameServers = [OFMutableArray array]; encoding = [OFLocale encoding]; nameServerList = ObtainDomainNameServerList(); if (nameServerList == NULL) @throw [OFOutOfMemoryException exception]; @try { struct DomainNameServerNode *iter = (struct DomainNameServerNode *)&nameServerList->lh_Head; while (iter->dnsn_MinNode.mln_Succ != NULL) { if (iter->dnsn_UseCount != 0 && iter->dnsn_Address != NULL) { OFString *address = [OFString stringWithCString: iter->dnsn_Address encoding: encoding]; [nameServers addObject: address]; } iter = (struct DomainNameServerNode *) iter->dnsn_MinNode.mln_Succ; } } @finally { ReleaseDomainNameServerList(nameServerList); } if (nameServers.count > 0) { [nameServers makeImmutable]; _nameServers = [nameServers copy]; } if (GetDefaultDomainName(buffer, sizeof(buffer))) _localDomain = [[OFString alloc] initWithCString: buffer encoding: encoding]; return true; } #endif #ifdef OF_NINTENDO_3DS - (void)obtainNintendo3DSSytemConfig { OFMutableArray *nameServers = [OFMutableArray array]; union { /* * For some unknown reason, this needs a 336 bytes buffer and * always returns 336 bytes. */ char bytes[336]; SOCU_DNSTableEntry entries[2]; } buffer; socklen_t optLen = sizeof(buffer); if (SOCU_GetNetworkOpt(SOL_CONFIG, NETOPT_DNS_TABLE, &buffer, &optLen) != 0) return; /* * We're fine if this gets smaller in a future release (unlikely), as * long as two entries still fit. */ if (optLen < sizeof(buffer.entries)) return; for (uint_fast8_t i = 0; i < 2; i++) { uint32_t ip = OFFromBigEndian32(buffer.entries[i].ip.s_addr); if (ip == 0) continue; [nameServers addObject: [OFString stringWithFormat: @"%u.%u.%u.%u", (ip >> 24) & 0xFF, (ip >> 16) & 0xFF, (ip >> 8) & 0xFF, ip & 0xFF]]; } if (nameServers.count > 0) { [nameServers makeImmutable]; _nameServers = [nameServers copy]; } } #endif - (void)reload { #ifdef OF_WINDOWS OFString *path = nil; #endif #if (defined(OF_AMIGAOS_M68K) || defined(OF_AMIGAOS4)) && defined(OF_HAVE_FILES) OFFileManager *fileManager = [OFFileManager defaultManager]; #endif void *pool; /* * TODO: Rather than reparsing every time, check what actually changed * (mtime) and only reset those. */ if (_lastConfigReload != nil && _configReloadInterval > 0 && _lastConfigReload.timeIntervalSinceNow < _configReloadInterval) return; pool = objc_autoreleasePoolPush(); [self setDefaults]; #if defined(OF_WINDOWS) # ifdef OF_HAVE_FILES @try { OFWindowsRegistryKey *key; key = [[OFWindowsRegistryKey localMachineKey] openSubkeyAtPath: @"SYSTEM\\CurrentControlSet\\Services\\" @"Tcpip\\Parameters" accessRights: KEY_QUERY_VALUE options: 0]; path = [[[key stringForValueNamed: @"DataBasePath"] stringByAppendingPathComponent: @"hosts"] stringByExpandingWindowsEnvironmentStrings]; } @catch (OFOpenWindowsRegistryKeyFailedException *e) { /* Ignore */ } @catch (OFUndefinedKeyException *e) { /* Ignore */ } if (path != nil) [self parseHosts: path]; # endif [self obtainWindowsSystemConfig]; #elif defined(OF_MORPHOS) [self obtainMorphOSSystemConfig]; #elif defined(OF_AMIGAOS_M68K) || defined(OF_AMIGAOS4) # ifdef OF_HAVE_FILES if (![self obtainRoadshowSystemConfig]) { if (assignExists("AmiTCP")) /* * FIXME: The installer puts it there, but theoretically * it could also be in AmiTCP:db/netdb or any of * the files included there. */ [self parseResolvConf: @"AmiTCP:db/netdb-myhost"]; } if ([fileManager fileExistsAtPath: @"DEVS:Internet/hosts"]) [self parseHosts: @"DEVS:Internet/hosts"]; else if (assignExists("AmiTCP")) [self parseHosts: @"AmiTCP:db/hosts"]; # else [self obtainRoadshowSystemConfig]; # endif #elif defined(OF_NINTENDO_3DS) [self obtainNintendo3DSSytemConfig]; #elif defined(OF_HAVE_FILES) [self parseHosts: HOSTS_PATH]; [self parseResolvConf: RESOLV_CONF_PATH]; #endif if (_staticHosts == nil) { OFArray *localhost = #ifdef OF_HAVE_IPV6 [OFArray arrayWithObjects: @"::1", @"127.0.0.1", nil]; #else [OFArray arrayWithObject: @"127.0.0.1"]; #endif _staticHosts = [[OFDictionary alloc] initWithObject: localhost forKey: @"localhost"]; } if (_nameServers == nil) #ifdef OF_HAVE_IPV6 _nameServers = [[OFArray alloc] initWithObjects: @"127.0.0.1", @"::1", nil]; #else _nameServers = [[OFArray alloc] initWithObject: @"127.0.0.1"]; #endif #if !defined(OF_WII) && !defined(OF_MORPHOS) if (_localDomain == nil) _localDomain = [domainFromHostname(obtainHostname()) copy]; #endif if (_searchDomains == nil) { if (_localDomain != nil) _searchDomains = [[OFArray alloc] initWithObject: _localDomain]; else _searchDomains = [[OFArray alloc] init]; } objc_autoreleasePoolPop(pool); } @end objfw-1.1.6/src/OFDNSResourceRecord.h000066400000000000000000000113331465614216400173200ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFSocket.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFArray OF_GENERIC(ObjectType); @class OFData; /** * @brief The DNS class. */ typedef enum { /** IN */ OFDNSClassIN = 1, /** Any class. Only for queries. */ OFDNSClassAny = 255, } OFDNSClass; /** * @brief The type of a DNS resource record. */ typedef enum { /** A */ OFDNSRecordTypeA = 1, /** NS */ OFDNSRecordTypeNS = 2, /** CNAME */ OFDNSRecordTypeCNAME = 5, /** SOA */ OFDNSRecordTypeSOA = 6, /** PTR */ OFDNSRecordTypePTR = 12, /** HINFO */ OFDNSRecordTypeHINFO = 13, /** MX */ OFDNSRecordTypeMX = 15, /** TXT */ OFDNSRecordTypeTXT = 16, /** RP */ OFDNSRecordTypeRP = 17, /** AAAA */ OFDNSRecordTypeAAAA = 28, /** LOC */ OFDNSRecordTypeLOC = 29, /** SRV */ OFDNSRecordTypeSRV = 33, /** All types. Only for queries. */ OFDNSRecordTypeAll = 255, /** URI */ OFDNSRecordTypeURI = 256, } OFDNSRecordType; /** * @class OFDNSResourceRecord OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h * * @brief A class representing a DNS resource record. */ @interface OFDNSResourceRecord: OFObject { OFString *_name; OFDNSClass _DNSClass; OFDNSRecordType _recordType; uint32_t _TTL; OF_RESERVE_IVARS(OFDNSResourceRecord, 4) } /** * @brief The domain name to which the resource record belongs. */ @property (readonly, nonatomic) OFString *name; /** * @brief The DNS class. */ @property (readonly, nonatomic) OFDNSClass DNSClass; /** * @brief The resource record type code. */ @property (readonly, nonatomic) OFDNSRecordType recordType; /** * @brief The number of seconds after which the resource record should be * discarded from the cache. */ @property (readonly, nonatomic) uint32_t TTL; /** * @brief Initializes an already allocated OFDNSResourceRecord with the * specified name, class, type, data and time to live. * * @param name The name for the resource record * @param DNSClass The class code for the resource record * @param recordType The type code for the resource record * @param TTL The time to live for the resource record * @return An initialized OFDNSResourceRecord */ - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end #ifdef __cplusplus extern "C" { #endif /** * @brief Returns the name for the specified OFDNSClass. * * @param DNSClass The OFDNSClass to return the name for * @return The name for the specified OFDNSClass */ extern OFString *_Nonnull OFDNSClassName(OFDNSClass DNSClass); /** * @brief Returns the name for the specified OFDNSRecordType. * * @param recordType The OFDNSRecordType to return the name for * @return The name for the specified OFDNSRecordType */ extern OFString *_Nonnull OFDNSRecordTypeName(OFDNSRecordType recordType); /** * @brief Parses the specified string as an @ref OFDNSClass. * * @param string The string to parse as an @ref OFDNSClass * @return The parsed OFDNSClass * @throw OFInvalidFormatException The specified string is not valid DNS class */ extern OFDNSClass OFDNSClassParseName(OFString *_Nonnull string); /** * @brief Parses the specified string as an @ref OFDNSRecordType. * * @param string The string to parse as an @ref OFDNSRecordType * @return The parsed OFDNSRecordType * @throw OFInvalidFormatException The specified string is not valid DNS class */ extern OFDNSRecordType OFDNSRecordTypeParseName(OFString *_Nonnull string); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END #import "OFAAAADNSResourceRecord.h" #import "OFADNSResourceRecord.h" #import "OFCNAMEDNSResourceRecord.h" #import "OFHINFODNSResourceRecord.h" #import "OFLOCDNSResourceRecord.h" #import "OFMXDNSResourceRecord.h" #import "OFNSDNSResourceRecord.h" #import "OFPTRDNSResourceRecord.h" #import "OFRPDNSResourceRecord.h" #import "OFSOADNSResourceRecord.h" #import "OFSRVDNSResourceRecord.h" #import "OFTXTDNSResourceRecord.h" #import "OFURIDNSResourceRecord.h" objfw-1.1.6/src/OFDNSResourceRecord.m000066400000000000000000000104111465614216400173210ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFDNSResourceRecord.h" #import "OFArray.h" #import "OFData.h" #import "OFInvalidFormatException.h" OFString * OFDNSClassName(OFDNSClass DNSClass) { switch (DNSClass) { case OFDNSClassIN: return @"IN"; case OFDNSClassAny: return @"any"; default: return [OFString stringWithFormat: @"%u", DNSClass]; } } OFString * OFDNSRecordTypeName(OFDNSRecordType recordType) { switch (recordType) { case OFDNSRecordTypeA: return @"A"; case OFDNSRecordTypeNS: return @"NS"; case OFDNSRecordTypeCNAME: return @"CNAME"; case OFDNSRecordTypeSOA: return @"SOA"; case OFDNSRecordTypePTR: return @"PTR"; case OFDNSRecordTypeHINFO: return @"HINFO"; case OFDNSRecordTypeMX: return @"MX"; case OFDNSRecordTypeTXT: return @"TXT"; case OFDNSRecordTypeRP: return @"RP"; case OFDNSRecordTypeAAAA: return @"AAAA"; case OFDNSRecordTypeLOC: return @"LOC"; case OFDNSRecordTypeSRV: return @"SRV"; case OFDNSRecordTypeAll: return @"all"; case OFDNSRecordTypeURI: return @"URI"; default: return [OFString stringWithFormat: @"%u", recordType]; } } OFDNSClass OFDNSClassParseName(OFString *string) { void *pool = objc_autoreleasePoolPush(); OFDNSClass DNSClass; string = string.uppercaseString; if ([string isEqual: @"IN"]) DNSClass = OFDNSClassIN; else { DNSClass = (OFDNSClass)[string unsignedLongLongValueWithBase: 0]; } objc_autoreleasePoolPop(pool); return DNSClass; } OFDNSRecordType OFDNSRecordTypeParseName(OFString *string) { void *pool = objc_autoreleasePoolPush(); OFDNSRecordType recordType; string = string.uppercaseString; if ([string isEqual: @"A"]) recordType = OFDNSRecordTypeA; else if ([string isEqual: @"NS"]) recordType = OFDNSRecordTypeNS; else if ([string isEqual: @"CNAME"]) recordType = OFDNSRecordTypeCNAME; else if ([string isEqual: @"SOA"]) recordType = OFDNSRecordTypeSOA; else if ([string isEqual: @"PTR"]) recordType = OFDNSRecordTypePTR; else if ([string isEqual: @"HINFO"]) recordType = OFDNSRecordTypeHINFO; else if ([string isEqual: @"MX"]) recordType = OFDNSRecordTypeMX; else if ([string isEqual: @"TXT"]) recordType = OFDNSRecordTypeTXT; else if ([string isEqual: @"RP"]) recordType = OFDNSRecordTypeRP; else if ([string isEqual: @"AAAA"]) recordType = OFDNSRecordTypeAAAA; else if ([string isEqual: @"LOC"]) recordType = OFDNSRecordTypeLOC; else if ([string isEqual: @"SRV"]) recordType = OFDNSRecordTypeSRV; else if ([string isEqual: @"ALL"]) recordType = OFDNSRecordTypeAll; else if ([string isEqual: @"URI"]) recordType = OFDNSRecordTypeURI; else { recordType = (OFDNSRecordType)[string unsignedLongLongValueWithBase: 0]; } objc_autoreleasePoolPop(pool); return recordType; } @implementation OFDNSResourceRecord @synthesize name = _name, DNSClass = _DNSClass, recordType = _recordType; @synthesize TTL = _TTL; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { self = [super init]; @try { _name = [name copy]; _DNSClass = DNSClass; _recordType = recordType; _TTL = TTL; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_name release]; [super dealloc]; } - (id)copy { return [self retain]; } - (OFString *)description { return [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tClass = %@\n" @"\tType = %@\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFDNSClassName(_DNSClass), OFDNSRecordTypeName(_recordType), _TTL]; } @end objfw-1.1.6/src/OFDNSResponse.h000066400000000000000000000066751465614216400162050ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFDNSResourceRecord.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFDictionary OF_GENERIC(KeyType, ObjectType); typedef OFDictionary OF_GENERIC(OFString *, OFArray OF_GENERIC( OF_KINDOF(OFDNSResourceRecord *)) *) *OFDNSResponseRecords; /** * @class OFDNSResponse OFDNSResponse.h ObjFW/OFDNSResponse.h * * @brief A class storing a response from @ref OFDNSResolver. */ OF_SUBCLASSING_RESTRICTED @interface OFDNSResponse: OFObject { OFString *_domainName; OFDNSResponseRecords _answerRecords, _authorityRecords; OFDNSResponseRecords _additionalRecords; } /** * @brief The domain name of the response. */ @property (readonly, nonatomic) OFString *domainName; /** * @brief The answer records of the response. * * This is a dictionary with the key being the domain name and the value being * an array of @ref OFDNSResourceRecord. */ @property (readonly, nonatomic) OFDNSResponseRecords answerRecords; /** * @brief The authority records of the response. * * This is a dictionary with the key being the domain name and the value being * an array of @ref OFDNSResourceRecord. */ @property (readonly, nonatomic) OFDNSResponseRecords authorityRecords; /** * @brief The additional records of the response. * * This is a dictionary with the key being the domain name and the value being * an array of @ref OFDNSResourceRecord. */ @property (readonly, nonatomic) OFDNSResponseRecords additionalRecords; /** * @brief Creates a new, autoreleased OFDNSResponse. * * @param domainName The domain name the response is for * @param answerRecords The answer records of the response * @param authorityRecords The authority records of the response * @param additionalRecords The additional records of the response * @return A new, autoreleased OFDNSResponse */ + (instancetype)responseWithDomainName: (OFString *)domainName answerRecords: (OFDNSResponseRecords)answerRecords authorityRecords: (OFDNSResponseRecords)authorityRecords additionalRecords: (OFDNSResponseRecords)additionalRecords; /** * @brief Initializes an already allocated OFDNSResponse. * * @param domainName The domain name the response is for * @param answerRecords The answer records of the response * @param authorityRecords The authority records of the response * @param additionalRecords The additional records of the response * @return An initialized OFDNSResponse */ - (instancetype)initWithDomainName: (OFString *)domainName answerRecords: (OFDNSResponseRecords)answerRecords authorityRecords: (OFDNSResponseRecords)authorityRecords additionalRecords: (OFDNSResponseRecords)additionalRecords OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFDNSResponse.m000066400000000000000000000075541465614216400162070ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFDNSResponse.h" #import "OFDictionary.h" #import "OFString.h" @implementation OFDNSResponse @synthesize domainName = _domainName, answerRecords = _answerRecords; @synthesize authorityRecords = _authorityRecords; @synthesize additionalRecords = _additionalRecords; + (instancetype)responseWithDomainName: (OFString *)domainName answerRecords: (OFDNSResponseRecords)answerRecords authorityRecords: (OFDNSResponseRecords)authorityRecords additionalRecords: (OFDNSResponseRecords)additionalRecords { return [[[self alloc] initWithDomainName: domainName answerRecords: answerRecords authorityRecords: authorityRecords additionalRecords: additionalRecords] autorelease]; } - (instancetype)initWithDomainName: (OFString *)domainName answerRecords: (OFDNSResponseRecords)answerRecords authorityRecords: (OFDNSResponseRecords)authorityRecords additionalRecords: (OFDNSResponseRecords)additionalRecords { self = [super init]; @try { _domainName = [domainName copy]; _answerRecords = [answerRecords copy]; _authorityRecords = [authorityRecords copy]; _additionalRecords = [additionalRecords copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_domainName release]; [_answerRecords release]; [_authorityRecords release]; [_additionalRecords release]; [super dealloc]; } - (bool)isEqual: (id)object { OFDNSResponse *response; if (object == self) return true; if (![object isKindOfClass: [OFDNSResponse class]]) return false; response = object; if (response->_domainName != _domainName && ![response->_domainName isEqual: _domainName]) return false; if (response->_answerRecords != _answerRecords && ![response->_answerRecords isEqual: _answerRecords]) return false; if (response->_authorityRecords != _authorityRecords && ![response->_authorityRecords isEqual: _authorityRecords]) return false; if (response->_additionalRecords != _additionalRecords && ![response->_additionalRecords isEqual: _additionalRecords]) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _domainName.hash); OFHashAddHash(&hash, [_answerRecords hash]); OFHashAddHash(&hash, [_authorityRecords hash]); OFHashAddHash(&hash, [_additionalRecords hash]); OFHashFinalize(&hash); return hash; } - (OFString *)description { OFString *answerRecords = [_answerRecords.description stringByReplacingOccurrencesOfString: @"\n" withString: @"\n\t"]; OFString *authorityRecords = [_authorityRecords.description stringByReplacingOccurrencesOfString: @"\n" withString: @"\n\t"]; OFString *additionalRecords = [_additionalRecords.description stringByReplacingOccurrencesOfString: @"\n" withString: @"\n\t"]; return [OFString stringWithFormat: @"<%@:\n" @"\tDomain name = %@\n" @"\tAnswer records = %@\n" @"\tAuthority records = %@\n" @"\tAdditional records = %@\n" @">", self.className, _domainName, answerRecords, authorityRecords, additionalRecords]; } @end objfw-1.1.6/src/OFData+CryptographicHashing.h000066400000000000000000000035301465614216400210120ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFData.h" OF_ASSUME_NONNULL_BEGIN @class OFString; #ifdef __cplusplus extern "C" { #endif extern int _OFData_CryptographicHashing_reference OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif @interface OFData (CryptographicHashing) /** * @brief The MD5 hash of the data as a string. */ @property (readonly, nonatomic) OFString *stringByMD5Hashing; /** * @brief The RIPEMD-160 hash of the data as a string. */ @property (readonly, nonatomic) OFString *stringByRIPEMD160Hashing; /** * @brief The SHA-1 hash of the data as a string. */ @property (readonly, nonatomic) OFString *stringBySHA1Hashing; /** * @brief The SHA-224 hash of the data as a string. */ @property (readonly, nonatomic) OFString *stringBySHA224Hashing; /** * @brief The SHA-256 hash of the data as a string. */ @property (readonly, nonatomic) OFString *stringBySHA256Hashing; /** * @brief The SHA-384 hash of the data as a string. */ @property (readonly, nonatomic) OFString *stringBySHA384Hashing; /** * @brief The SHA-512 hash of the data as a string. */ @property (readonly, nonatomic) OFString *stringBySHA512Hashing; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFData+CryptographicHashing.m000066400000000000000000000050501465614216400210160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFData+CryptographicHashing.h" #import "OFString.h" #import "OFCryptographicHash.h" #import "OFMD5Hash.h" #import "OFRIPEMD160Hash.h" #import "OFSHA1Hash.h" #import "OFSHA224Hash.h" #import "OFSHA256Hash.h" #import "OFSHA384Hash.h" #import "OFSHA512Hash.h" int _OFData_CryptographicHashing_reference; @implementation OFData (CryptographicHashing) static OFString * stringByHashing(Class class, OFData *self) { void *pool = objc_autoreleasePoolPush(); id hash = [class hashWithAllowsSwappableMemory: true]; size_t digestSize = [class digestSize]; const unsigned char *digest; char cString[digestSize * 2]; [hash updateWithBuffer: self.items length: self.count * self.itemSize]; [hash calculate]; digest = hash.digest; for (size_t i = 0; i < digestSize; i++) { uint8_t high, low; high = digest[i] >> 4; low = digest[i] & 0x0F; cString[i * 2] = (high > 9 ? high - 10 + 'a' : high + '0'); cString[i * 2 + 1] = (low > 9 ? low - 10 + 'a' : low + '0'); } objc_autoreleasePoolPop(pool); return [OFString stringWithCString: cString encoding: OFStringEncodingASCII length: digestSize * 2]; } - (OFString *)stringByMD5Hashing { return stringByHashing([OFMD5Hash class], self); } - (OFString *)stringByRIPEMD160Hashing { return stringByHashing([OFRIPEMD160Hash class], self); } - (OFString *)stringBySHA1Hashing { return stringByHashing([OFSHA1Hash class], self); } - (OFString *)stringBySHA224Hashing { return stringByHashing([OFSHA224Hash class], self); } - (OFString *)stringBySHA256Hashing { return stringByHashing([OFSHA256Hash class], self); } - (OFString *)stringBySHA384Hashing { return stringByHashing([OFSHA384Hash class], self); } - (OFString *)stringBySHA512Hashing { return stringByHashing([OFSHA512Hash class], self); } @end objfw-1.1.6/src/OFData+MessagePackParsing.h000066400000000000000000000040621465614216400204020ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFData.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif extern int _OFData_MessagePackParsing_reference OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif @interface OFData (MessagePackParsing) /** * @brief The data interpreted as MessagePack representation and parsed as an * object. * * @throw OFInvalidFormatException The MessagePack representation contained in * the data contained an invalid format * @throw OFTruncatedDataException The MessagePack representation contained in * the data is truncated * @throw OFOutOfRangeException The depth limit has been exceeded */ @property (readonly, nonatomic) id objectByParsingMessagePack; /** * @brief Parses the MessagePack representation and returns it as an object. * * @param depthLimit The maximum depth the parser should accept (defaults to 32 * if not specified, 0 means no limit (insecure!)) * @return The MessagePack representation as an object * @throw OFInvalidFormatException The MessagePack representation contained in * the data contained an invalid format * @throw OFTruncatedDataException The MessagePack representation contained in * the data is truncated * @throw OFOutOfRangeException The depth limit has been exceeded */ - (id)objectByParsingMessagePackWithDepthLimit: (size_t)depthLimit; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFData+MessagePackParsing.m000066400000000000000000000322321465614216400204070ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFData+MessagePackParsing.h" #import "OFArray.h" #import "OFDate.h" #import "OFDictionary.h" #import "OFMessagePackExtension.h" #import "OFNull.h" #import "OFNumber.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" int _OFData_MessagePackParsing_reference; static size_t parseObject(const unsigned char *buffer, size_t length, id *object, size_t depthLimit); static uint16_t readUInt16(const unsigned char *buffer) { return ((uint16_t)buffer[0] << 8) | buffer[1]; } static uint32_t readUInt32(const unsigned char *buffer) { return ((uint32_t)buffer[0] << 24) | ((uint32_t)buffer[1] << 16) | ((uint32_t)buffer[2] << 8) | buffer[3]; } static uint64_t readUInt64(const unsigned char *buffer) { return ((uint64_t)buffer[0] << 56) | ((uint64_t)buffer[1] << 48) | ((uint64_t)buffer[2] << 40) | ((uint64_t)buffer[3] << 32) | ((uint64_t)buffer[4] << 24) | ((uint64_t)buffer[5] << 16) | ((uint64_t)buffer[6] << 8) | buffer[7]; } static size_t parseArray(const unsigned char *buffer, size_t length, id *object, size_t count, size_t depthLimit) { void *pool; size_t pos = 0; if (--depthLimit == 0) @throw [OFOutOfRangeException exception]; /* * Don't use capacity! For data and strings, this is safe, as we can * check if we still have enough bytes left. For an array however, we * can't know this, as every child can be more than one byte. */ *object = [OFMutableArray array]; for (size_t i = 0; i < count; i++) { id child; pool = objc_autoreleasePoolPush(); pos += parseObject(buffer + pos, length - pos, &child, depthLimit); [*object addObject: child]; objc_autoreleasePoolPop(pool); } return pos; } static size_t parseTable(const unsigned char *buffer, size_t length, id *object, size_t count, size_t depthLimit) { void *pool; size_t pos = 0; if (--depthLimit == 0) @throw [OFOutOfRangeException exception]; /* * Don't use capacity! For data and strings, this is safe, as we can * check if we still have enough bytes left. For a dictionary however, * we can't know this, as every key / value can be more than one byte. */ *object = [OFMutableDictionary dictionary]; for (size_t i = 0; i < count; i++) { id key, value; pool = objc_autoreleasePoolPush(); pos += parseObject(buffer + pos, length - pos, &key, depthLimit); pos += parseObject(buffer + pos, length - pos, &value, depthLimit); [*object setObject: value forKey: key]; objc_autoreleasePoolPop(pool); } return pos; } static OFDate * createDate(OFData *data) { switch (data.count) { case 4: { uint32_t timestamp; memcpy(×tamp, data.items, 4); timestamp = OFFromBigEndian32(timestamp); return [OFDate dateWithTimeIntervalSince1970: timestamp]; } case 8: { uint64_t combined; memcpy(&combined, data.items, 8); combined = OFFromBigEndian64(combined); return [OFDate dateWithTimeIntervalSince1970: (double)(combined & 0x3FFFFFFFF) + (double)(combined >> 34) / 1000000000]; } case 12: { uint32_t nanoseconds; int64_t seconds; memcpy(&nanoseconds, data.items, 4); memcpy(&seconds, (char *)data.items + 4, 8); nanoseconds = OFFromBigEndian32(nanoseconds); seconds = OFFromBigEndian64(seconds); return [OFDate dateWithTimeIntervalSince1970: (double)seconds + (double)nanoseconds / 1000000000]; } default: @throw [OFInvalidFormatException exception]; } } static id createExtension(int8_t type, OFData *data) { switch (type) { case -1: return createDate(data); default: return [OFMessagePackExtension extensionWithType: type data: data]; } } static size_t parseObject(const unsigned char *buffer, size_t length, id *object, size_t depthLimit) { size_t count; OFData *data; if (length < 1) @throw [OFTruncatedDataException exception]; /* positive fixint */ if ((buffer[0] & 0x80) == 0) { *object = [OFNumber numberWithUnsignedChar: buffer[0] & 0x7F]; return 1; } /* negative fixint */ if ((buffer[0] & 0xE0) == 0xE0) { *object = [OFNumber numberWithChar: ((int8_t)(buffer[0] & 0x1F)) - 32]; return 1; } /* fixstr */ if ((buffer[0] & 0xE0) == 0xA0) { count = buffer[0] & 0x1F; if (length < count + 1) @throw [OFTruncatedDataException exception]; *object = [OFString stringWithUTF8String: (const char *)buffer + 1 length: count]; return count + 1; } /* fixarray */ if ((buffer[0] & 0xF0) == 0x90) return parseArray(buffer + 1, length - 1, object, buffer[0] & 0xF, depthLimit) + 1; /* fixmap */ if ((buffer[0] & 0xF0) == 0x80) return parseTable(buffer + 1, length - 1, object, buffer[0] & 0xF, depthLimit) + 1; /* Prefix byte */ switch (buffer[0]) { /* Unsigned integers */ case 0xCC: /* uint8 */ if (length < 2) @throw [OFTruncatedDataException exception]; *object = [OFNumber numberWithUnsignedChar: buffer[1]]; return 2; case 0xCD: /* uint 16 */ if (length < 3) @throw [OFTruncatedDataException exception]; *object = [OFNumber numberWithUnsignedShort: readUInt16(buffer + 1)]; return 3; case 0xCE: /* uint 32 */ if (length < 5) @throw [OFTruncatedDataException exception]; *object = [OFNumber numberWithUnsignedLong: readUInt32(buffer + 1)]; return 5; case 0xCF: /* uint 64 */ if (length < 9) @throw [OFTruncatedDataException exception]; *object = [OFNumber numberWithUnsignedLongLong: readUInt64(buffer + 1)]; return 9; /* Signed integers */ case 0xD0: /* int 8 */ if (length < 2) @throw [OFTruncatedDataException exception]; *object = [OFNumber numberWithChar: (int8_t)buffer[1]]; return 2; case 0xD1: /* int 16 */ if (length < 3) @throw [OFTruncatedDataException exception]; *object = [OFNumber numberWithShort: (int16_t)readUInt16(buffer + 1)]; return 3; case 0xD2: /* int 32 */ if (length < 5) @throw [OFTruncatedDataException exception]; *object = [OFNumber numberWithLong: (int32_t)readUInt32(buffer + 1)]; return 5; case 0xD3: /* int 64 */ if (length < 9) @throw [OFTruncatedDataException exception]; *object = [OFNumber numberWithLongLong: (int64_t)readUInt64(buffer + 1)]; return 9; /* Floating point */ case 0xCA:; /* float 32 */ float f; if (length < 5) @throw [OFTruncatedDataException exception]; memcpy(&f, buffer + 1, 4); *object = [OFNumber numberWithFloat: OFFromBigEndianFloat(f)]; return 5; case 0xCB:; /* float 64 */ double d; if (length < 9) @throw [OFTruncatedDataException exception]; memcpy(&d, buffer + 1, 8); *object = [OFNumber numberWithDouble: OFFromBigEndianDouble(d)]; return 9; /* nil */ case 0xC0: *object = [OFNull null]; return 1; /* false */ case 0xC2: *object = [OFNumber numberWithBool: false]; return 1; /* true */ case 0xC3: *object = [OFNumber numberWithBool: true]; return 1; /* Data */ case 0xC4: /* bin 8 */ if (length < 2) @throw [OFTruncatedDataException exception]; count = buffer[1]; if (length < count + 2) @throw [OFTruncatedDataException exception]; *object = [OFData dataWithItems: buffer + 2 count: count]; return count + 2; case 0xC5: /* bin 16 */ if (length < 3) @throw [OFTruncatedDataException exception]; count = readUInt16(buffer + 1); if (length < count + 3) @throw [OFTruncatedDataException exception]; *object = [OFData dataWithItems: buffer + 3 count: count]; return count + 3; case 0xC6: /* bin 32 */ if (length < 5) @throw [OFTruncatedDataException exception]; count = readUInt32(buffer + 1); if (length < count + 5) @throw [OFTruncatedDataException exception]; *object = [OFData dataWithItems: buffer + 5 count: count]; return count + 5; /* Extensions */ case 0xC7: /* ext 8 */ if (length < 3) @throw [OFTruncatedDataException exception]; count = buffer[1]; if (length < count + 3) @throw [OFTruncatedDataException exception]; data = [[OFData alloc] initWithItems: buffer + 3 count: count]; @try { *object = createExtension(buffer[2], data); } @finally { [data release]; } return count + 3; case 0xC8: /* ext 16 */ if (length < 4) @throw [OFTruncatedDataException exception]; count = readUInt16(buffer + 1); if (length < count + 4) @throw [OFTruncatedDataException exception]; data = [[OFData alloc] initWithItems: buffer + 4 count: count]; @try { *object = createExtension(buffer[3], data); } @finally { [data release]; } return count + 4; case 0xC9: /* ext 32 */ if (length < 6) @throw [OFTruncatedDataException exception]; count = readUInt32(buffer + 1); if (length < count + 6) @throw [OFTruncatedDataException exception]; data = [[OFData alloc] initWithItems: buffer + 6 count: count]; @try { *object = createExtension(buffer[5], data); } @finally { [data release]; } return count + 6; case 0xD4: /* fixext 1 */ if (length < 3) @throw [OFTruncatedDataException exception]; data = [[OFData alloc] initWithItems: buffer + 2 count: 1]; @try { *object = createExtension(buffer[1], data); } @finally { [data release]; } return 3; case 0xD5: /* fixext 2 */ if (length < 4) @throw [OFTruncatedDataException exception]; data = [[OFData alloc] initWithItems: buffer + 2 count: 2]; @try { *object = createExtension(buffer[1], data); } @finally { [data release]; } return 4; case 0xD6: /* fixext 4 */ if (length < 6) @throw [OFTruncatedDataException exception]; data = [[OFData alloc] initWithItems: buffer + 2 count: 4]; @try { *object = createExtension(buffer[1], data); } @finally { [data release]; } return 6; case 0xD7: /* fixext 8 */ if (length < 10) @throw [OFTruncatedDataException exception]; data = [[OFData alloc] initWithItems: buffer + 2 count: 8]; @try { *object = createExtension(buffer[1], data); } @finally { [data release]; } return 10; case 0xD8: /* fixext 16 */ if (length < 18) @throw [OFTruncatedDataException exception]; data = [[OFData alloc] initWithItems: buffer + 2 count: 16]; @try { *object = createExtension(buffer[1], data); } @finally { [data release]; } return 18; /* Strings */ case 0xD9: /* str 8 */ if (length < 2) @throw [OFTruncatedDataException exception]; count = buffer[1]; if (length < count + 2) @throw [OFTruncatedDataException exception]; *object = [OFString stringWithUTF8String: (const char *)buffer + 2 length: count]; return count + 2; case 0xDA: /* str 16 */ if (length < 3) @throw [OFTruncatedDataException exception]; count = readUInt16(buffer + 1); if (length < count + 3) @throw [OFTruncatedDataException exception]; *object = [OFString stringWithUTF8String: (const char *)buffer + 3 length: count]; return count + 3; case 0xDB: /* str 32 */ if (length < 5) @throw [OFTruncatedDataException exception]; count = readUInt32(buffer + 1); if (length < count + 5) @throw [OFTruncatedDataException exception]; *object = [OFString stringWithUTF8String: (const char *)buffer + 5 length: count]; return count + 5; /* Arrays */ case 0xDC: /* array 16 */ if (length < 3) @throw [OFTruncatedDataException exception]; return parseArray(buffer + 3, length - 3, object, readUInt16(buffer + 1), depthLimit) + 3; case 0xDD: /* array 32 */ if (length < 5) @throw [OFTruncatedDataException exception]; return parseArray(buffer + 5, length - 5, object, readUInt32(buffer + 1), depthLimit) + 5; /* Maps */ case 0xDE: /* map 16 */ if (length < 3) @throw [OFTruncatedDataException exception]; return parseTable(buffer + 3, length - 3, object, readUInt16(buffer + 1), depthLimit) + 3; case 0xDF: /* map 32 */ if (length < 5) @throw [OFTruncatedDataException exception]; return parseTable(buffer + 5, length - 5, object, readUInt32(buffer + 1), depthLimit) + 5; default: @throw [OFInvalidFormatException exception]; } } @implementation OFData (MessagePackParsing) - (id)objectByParsingMessagePack { return [self objectByParsingMessagePackWithDepthLimit: 32]; } - (id)objectByParsingMessagePackWithDepthLimit: (size_t)depthLimit { void *pool = objc_autoreleasePoolPush(); size_t count = self.count; id object; if (self.itemSize != 1) @throw [OFInvalidArgumentException exception]; if (parseObject(self.items, count, &object, depthLimit) != count) @throw [OFInvalidFormatException exception]; [object retain]; objc_autoreleasePoolPop(pool); return [object autorelease]; } @end objfw-1.1.6/src/OFData.h000066400000000000000000000262111465614216400146770ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFMessagePackRepresentation.h" /*! @file */ OF_ASSUME_NONNULL_BEGIN @class OFIRI; @class OFString; /** * @brief Options for searching in data. * * This is a bit mask. */ typedef enum { /** Search backwards in the data */ OFDataSearchBackwards = 1 } OFDataSearchOptions; /** * @class OFData OFData.h ObjFW/OFData.h * * @brief A class for storing arbitrary data in an array. */ @interface OFData: OFObject /** * @brief The size of a single item in the OFData in bytes. */ @property (readonly, nonatomic) size_t itemSize; /** * @brief The number of items in the OFData. */ @property (readonly, nonatomic) size_t count; /** * @brief All elements of the OFData as a C array. * * @warning The pointer is only valid until the OFData is changed! */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) const void *items OF_RETURNS_INNER_POINTER; /** * @brief The first item of the OFData or `NULL`. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) const void *firstItem OF_RETURNS_INNER_POINTER; /** * @brief The last item of the OFData or `NULL`. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) const void *lastItem OF_RETURNS_INNER_POINTER; /** * @brief The string representation of the data. * * The string representation is a hex dump of the data, grouped by itemSize * bytes. */ @property (readonly, nonatomic) OFString *stringRepresentation; /** * @brief A string containing the data in Base64 encoding. */ @property (readonly, nonatomic) OFString *stringByBase64Encoding; /** * @brief Creates a new OFData that is empty with an item size of 1. * * @return A new autoreleased OFData */ + (instancetype)data; /** * @brief Creates a new OFData that is empty with the specified item size. * * @param itemSize The size of a single element in the OFData * @return A new autoreleased OFData */ + (instancetype)dataWithItemSize: (size_t)itemSize; /** * @brief Creates a new OFData with the specified `count` items of size 1. * * @param items The items to store in the OFData * @param count The number of items * @return A new autoreleased OFData */ + (instancetype)dataWithItems: (const void *)items count: (size_t)count; /** * @brief Creates a new OFData with the specified `count` items of the * specified size. * * @param items The items to store in the OFData * @param count The number of items * @param itemSize The item size of a single item in bytes * @return A new autoreleased OFData */ + (instancetype)dataWithItems: (const void *)items count: (size_t)count itemSize: (size_t)itemSize; /** * @brief Creates a new OFData with the specified `count` items of size 1 by * taking over ownership of the specified items pointer. * * If initialization fails for whatever reason, the passed memory is *not* * freed if `freeWhenDone` is true. * * @param items The items to store in the OFData * @param count The number of items * @param freeWhenDone Whether to free the pointer when it is no longer needed * by the OFData * @return A new autoreleased OFData */ + (instancetype)dataWithItemsNoCopy: (void *)items count: (size_t)count freeWhenDone: (bool)freeWhenDone; /** * @brief Creates a new OFData with the specified `count` items of the * specified size by taking ownership of the specified items pointer. * * If initialization fails for whatever reason, the passed memory is *not* * freed if `freeWhenDone` is true. * * @param items The items to store in the OFData * @param count The number of items * @param itemSize The item size of a single item in bytes * @param freeWhenDone Whether to free the pointer when it is no longer needed * by the OFData * @return A new autoreleased OFData */ + (instancetype)dataWithItemsNoCopy: (void *)items count: (size_t)count itemSize: (size_t)itemSize freeWhenDone: (bool)freeWhenDone; #ifdef OF_HAVE_FILES /** * @brief Creates a new OFData with an item size of 1, containing the data of * the specified file. * * @param path The path of the file * @return A new autoreleased OFData */ + (instancetype)dataWithContentsOfFile: (OFString *)path; #endif /** * @brief Creates a new OFData with an item size of 1, containing the data of * the specified IRI. * * @param IRI The IRI to the contents for the OFData * @return A new autoreleased OFData */ + (instancetype)dataWithContentsOfIRI: (OFIRI *)IRI; /** * @brief Creates a new OFData with an item size of 1, containing the data of * the hex string representation. * * @param string The hex string representation of the data * @return A new autoreleased OFData * @throw OFInvalidFormatException The specified string is not correctly * formatted */ + (instancetype)dataWithStringRepresentation: (OFString *)string; /** * @brief Creates a new OFData with an item size of 1, containing the data of * the Base64-encoded string. * * @param string The string with the Base64-encoded data * @return A new autoreleased OFData * @throw OFInvalidFormatException The specified string is not correctly * formatted */ + (instancetype)dataWithBase64EncodedString: (OFString *)string; /** * @brief Initializes an already allocated OFData to be empty with an item size * of 1. * * @return An initialized OFData */ - (instancetype)init; /** * @brief Initializes an already allocated OFData to be empty with the * specified item size. * * @param itemSize The size of a single element in the OFData * @return An initialized OFData */ - (instancetype)initWithItemSize: (size_t)itemSize; /** * @brief Initializes an already allocated OFData with the specified `count` * items of size 1. * * @param items The items to store in the OFData * @param count The number of items * @return An initialized OFData */ - (instancetype)initWithItems: (const void *)items count: (size_t)count; /** * @brief Initializes an already allocated OFData with the specified `count` * items of the specified size. * * @param items The items to store in the OFData * @param count The number of items * @param itemSize The item size of a single item in bytes * @return An initialized OFData */ - (instancetype)initWithItems: (const void *)items count: (size_t)count itemSize: (size_t)itemSize; /** * @brief Initializes an already allocated OFData with the specified `count` * items of size 1 by taking over ownership of the specified items * pointer. * * If initialization fails for whatever reason, the passed memory is *not* * freed if `freeWhenDone` is true. * * @param items The items to store in the OFData * @param count The number of items * @param freeWhenDone Whether to free the pointer when it is no longer needed * by the OFData * @return An initialized OFData */ - (instancetype)initWithItemsNoCopy: (void *)items count: (size_t)count freeWhenDone: (bool)freeWhenDone; /** * @brief Initializes an already allocated OFData with the specified `count` * items of the specified size by taking ownership of the specified * items pointer. * * If initialization fails for whatever reason, the passed memory is *not* * freed if `freeWhenDone` is true. * * @param items The items to store in the OFData * @param count The number of items * @param itemSize The item size of a single item in bytes * @param freeWhenDone Whether to free the pointer when it is no longer needed * by the OFData * @return An initialized OFData */ - (instancetype)initWithItemsNoCopy: (void *)items count: (size_t)count itemSize: (size_t)itemSize freeWhenDone: (bool)freeWhenDone; #ifdef OF_HAVE_FILES /** * @brief Initializes an already allocated OFData with an item size of 1, * containing the data of the specified file. * * @param path The path of the file * @return An initialized OFData */ - (instancetype)initWithContentsOfFile: (OFString *)path; #endif /** * @brief Initializes an already allocated OFData with an item size of 1, * containing the data of the specified IRI. * * @param IRI The IRI to the contents for the OFData * @return A new autoreleased OFData */ - (instancetype)initWithContentsOfIRI: (OFIRI *)IRI; /** * @brief Initializes an already allocated OFData with an item size of 1, * containing the data of the hex string representation. * * @param string The hex string representation of the data * @return A new autoreleased OFData * @throw OFInvalidFormatException The specified string is not correctly * formatted */ - (instancetype)initWithStringRepresentation: (OFString *)string; /** * @brief Initializes an already allocated OFData with an item size of 1, * containing the data of the Base64-encoded string. * * @param string The string with the Base64-encoded data * @return An initialized OFData * @throw OFInvalidFormatException The specified string is not correctly * formatted */ - (instancetype)initWithBase64EncodedString: (OFString *)string; /** * @brief Compares the data to other data. * * @param data Data to compare the data to * @return The result of the comparison */ - (OFComparisonResult)compare: (OFData *)data; /** * @brief Returns a specific item of the OFData. * * @param index The number of the item to return * @return The specified item of the OFData */ - (const void *)itemAtIndex: (size_t)index OF_RETURNS_INNER_POINTER; /** * @brief Returns the data in the specified range as a new OFData. * * @param range The range of the data for the new OFData * @return The data in the specified range as a new OFData */ - (OFData *)subdataWithRange: (OFRange)range; /** * @brief Returns the range of the data. * * @param data The data to search for * @param options Options modifying search behavior * @param range The range in which to search * @return The range of the first occurrence of the data or a range with * `OFNotFound` as start position if it was not found. */ - (OFRange)rangeOfData: (OFData *)data options: (OFDataSearchOptions)options range: (OFRange)range; #ifdef OF_HAVE_FILES /** * @brief Writes the OFData into the specified file. * * @param path The path of the file to write to */ - (void)writeToFile: (OFString *)path; #endif /** * @brief Writes the OFData to the specified IRI. * * @param IRI The IRI to write to */ - (void)writeToIRI: (OFIRI *)IRI; @end OF_ASSUME_NONNULL_END #import "OFMutableData.h" #import "OFData+CryptographicHashing.h" #import "OFData+MessagePackParsing.h" objfw-1.1.6/src/OFData.m000066400000000000000000000377011465614216400147120ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #include #import "OFData.h" #import "OFBase64.h" #import "OFConcreteData.h" #import "OFDictionary.h" #ifdef OF_HAVE_FILES # import "OFFile.h" # import "OFFileManager.h" #endif #import "OFIRI.h" #import "OFIRIHandler.h" #import "OFStream.h" #import "OFString.h" #import "OFSubdata.h" #import "OFSystemInfo.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" static struct { Class isa; } placeholder; @interface OFPlaceholderData: OFString @end /* References for static linking */ void OF_VISIBILITY_HIDDEN _references_to_categories_of_OFData(void) { _OFData_CryptographicHashing_reference = 1; _OFData_MessagePackParsing_reference = 1; } @implementation OFPlaceholderData - (instancetype)init { return (id)[[OFConcreteData alloc] init]; } - (instancetype)initWithItemSize: (size_t)itemSize { return (id)[[OFConcreteData alloc] initWithItemSize: itemSize]; } - (instancetype)initWithItems: (const void *)items count: (size_t)count { return (id)[[OFConcreteData alloc] initWithItems: items count: count]; } - (instancetype)initWithItems: (const void *)items count: (size_t)count itemSize: (size_t)itemSize { return (id)[[OFConcreteData alloc] initWithItems: items count: count itemSize: itemSize]; } - (instancetype)initWithItemsNoCopy: (void *)items count: (size_t)count freeWhenDone: (bool)freeWhenDone { return (id)[[OFConcreteData alloc] initWithItemsNoCopy: items count: count freeWhenDone: freeWhenDone]; } - (instancetype)initWithItemsNoCopy: (void *)items count: (size_t)count itemSize: (size_t)itemSize freeWhenDone: (bool)freeWhenDone { return (id)[[OFConcreteData alloc] initWithItemsNoCopy: items count: count itemSize: itemSize freeWhenDone: freeWhenDone]; } #ifdef OF_HAVE_FILES - (instancetype)initWithContentsOfFile: (OFString *)path { return (id)[[OFConcreteData alloc] initWithContentsOfFile: path]; } #endif - (instancetype)initWithContentsOfIRI: (OFIRI *)IRI { return (id)[[OFConcreteData alloc] initWithContentsOfIRI: IRI]; } - (instancetype)initWithStringRepresentation: (OFString *)string { return (id)[[OFConcreteData alloc] initWithStringRepresentation: string]; } - (instancetype)initWithBase64EncodedString: (OFString *)string { return (id)[[OFConcreteData alloc] initWithBase64EncodedString: string]; } OF_SINGLETON_METHODS @end @implementation OFData + (void)initialize { if (self == [OFData class]) object_setClass((id)&placeholder, [OFPlaceholderData class]); } + (instancetype)alloc { if (self == [OFData class]) return (id)&placeholder; return [super alloc]; } + (instancetype)data { return [[[self alloc] init] autorelease]; } + (instancetype)dataWithItemSize: (size_t)itemSize { return [[[self alloc] initWithItemSize: itemSize] autorelease]; } + (instancetype)dataWithItems: (const void *)items count: (size_t)count { return [[[self alloc] initWithItems: items count: count] autorelease]; } + (instancetype)dataWithItems: (const void *)items count: (size_t)count itemSize: (size_t)itemSize { return [[[self alloc] initWithItems: items count: count itemSize: itemSize] autorelease]; } + (instancetype)dataWithItemsNoCopy: (void *)items count: (size_t)count freeWhenDone: (bool)freeWhenDone { return [[[self alloc] initWithItemsNoCopy: items count: count freeWhenDone: freeWhenDone] autorelease]; } + (instancetype)dataWithItemsNoCopy: (void *)items count: (size_t)count itemSize: (size_t)itemSize freeWhenDone: (bool)freeWhenDone { return [[[self alloc] initWithItemsNoCopy: items count: count itemSize: itemSize freeWhenDone: freeWhenDone] autorelease]; } #ifdef OF_HAVE_FILES + (instancetype)dataWithContentsOfFile: (OFString *)path { return [[[self alloc] initWithContentsOfFile: path] autorelease]; } #endif + (instancetype)dataWithContentsOfIRI: (OFIRI *)IRI { return [[[self alloc] initWithContentsOfIRI: IRI] autorelease]; } + (instancetype)dataWithStringRepresentation: (OFString *)string { return [[[self alloc] initWithStringRepresentation: string] autorelease]; } + (instancetype)dataWithBase64EncodedString: (OFString *)string { return [[[self alloc] initWithBase64EncodedString: string] autorelease]; } - (instancetype)init { if ([self isMemberOfClass: [OFData class]] || [self isMemberOfClass: [OFMutableData class]]) { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @throw e; } abort(); } return [super init]; } - (instancetype)initWithItemSize: (size_t)itemSize { OF_INVALID_INIT_METHOD } - (instancetype)initWithItems: (const void *)items count: (size_t)count { return [self initWithItems: items count: count itemSize: 1]; } - (instancetype)initWithItems: (const void *)items count: (size_t)count itemSize: (size_t)itemSize { OF_INVALID_INIT_METHOD } - (instancetype)initWithItemsNoCopy: (void *)items count: (size_t)count freeWhenDone: (bool)freeWhenDone { return [self initWithItemsNoCopy: items count: count itemSize: 1 freeWhenDone: freeWhenDone]; } - (instancetype)initWithItemsNoCopy: (void *)items count: (size_t)count itemSize: (size_t)itemSize freeWhenDone: (bool)freeWhenDone { OF_INVALID_INIT_METHOD } #ifdef OF_HAVE_FILES - (instancetype)initWithContentsOfFile: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFIRI *IRI; @try { IRI = [OFIRI fileIRIWithPath: path isDirectory: false]; } @catch (id e) { [self release]; @throw e; } self = [self initWithContentsOfIRI: IRI]; objc_autoreleasePoolPop(pool); return self; } #endif - (instancetype)initWithContentsOfIRI: (OFIRI *)IRI { char *items = NULL, *buffer = NULL; size_t count = 0; @try { void *pool = objc_autoreleasePoolPush(); OFStream *stream = [OFIRIHandler openItemAtIRI: IRI mode: @"r"]; size_t pageSize; pageSize = [OFSystemInfo pageSize]; buffer = OFAllocMemory(1, pageSize); while (!stream.atEndOfStream) { size_t length = [stream readIntoBuffer: buffer length: pageSize]; if (SIZE_MAX - count < length) @throw [OFOutOfRangeException exception]; items = OFResizeMemory(items, count + length, 1); memcpy(items + count, buffer, length); count += length; } objc_autoreleasePoolPop(pool); } @catch (id e) { OFFreeMemory(items); [self release]; @throw e; } @finally { OFFreeMemory(buffer); } @try { self = [self initWithItemsNoCopy: items count: count freeWhenDone: true]; } @catch (id e) { OFFreeMemory(items); @throw e; } return self; } - (instancetype)initWithStringRepresentation: (OFString *)string { char *items = NULL; size_t count = 0; @try { const char *cString; count = [string cStringLengthWithEncoding: OFStringEncodingASCII]; if (count % 2 != 0) @throw [OFInvalidFormatException exception]; count /= 2; items = OFAllocMemory(count, 1); cString = [string cStringWithEncoding: OFStringEncodingASCII]; for (size_t i = 0; i < count; i++) { uint8_t c1 = cString[2 * i]; uint8_t c2 = cString[2 * i + 1]; uint8_t byte; if (c1 >= '0' && c1 <= '9') byte = (c1 - '0') << 4; else if (c1 >= 'a' && c1 <= 'f') byte = (c1 - 'a' + 10) << 4; else if (c1 >= 'A' && c1 <= 'F') byte = (c1 - 'A' + 10) << 4; else @throw [OFInvalidFormatException exception]; if (c2 >= '0' && c2 <= '9') byte |= c2 - '0'; else if (c2 >= 'a' && c2 <= 'f') byte |= c2 - 'a' + 10; else if (c2 >= 'A' && c2 <= 'F') byte |= c2 - 'A' + 10; else @throw [OFInvalidFormatException exception]; items[i] = byte; } } @catch (id e) { OFFreeMemory(items); [self release]; @throw e; } @try { self = [self initWithItemsNoCopy: items count: count freeWhenDone: true]; } @catch (id e) { OFFreeMemory(items); @throw e; } return self; } - (instancetype)initWithBase64EncodedString: (OFString *)string { void *pool = objc_autoreleasePoolPush(); OFMutableData *data; @try { data = [OFMutableData data]; if (!_OFBase64Decode(data, [string cStringWithEncoding: OFStringEncodingASCII], [string cStringLengthWithEncoding: OFStringEncodingASCII])) @throw [OFInvalidFormatException exception]; } @catch (id e) { [self release]; @throw e; } /* Avoid copying if the class already matches. */ if (data.class == self.class) { [self release]; self = [data retain]; objc_autoreleasePoolPop(pool); return self; } /* * Make it immutable and avoid copying if the class already matches * after that. */ @try { [data makeImmutable]; } @catch (id e) { [self release]; @throw e; } if (data.class == self.class) { [self release]; self = [data retain]; objc_autoreleasePoolPop(pool); return self; } self = [self initWithItems: data.items count: data.count]; objc_autoreleasePoolPop(pool); return self; } - (size_t)count { OF_UNRECOGNIZED_SELECTOR } - (size_t)itemSize { OF_UNRECOGNIZED_SELECTOR } - (const void *)items { OF_UNRECOGNIZED_SELECTOR } - (const void *)itemAtIndex: (size_t)idx { if (idx >= self.count) @throw [OFOutOfRangeException exception]; return (const unsigned char *)self.items + idx * self.itemSize; } - (const void *)firstItem { const void *items = self.items; if (items == NULL || self.count == 0) return NULL; return items; } - (const void *)lastItem { const unsigned char *items = self.items; size_t count = self.count; if (items == NULL || count == 0) return NULL; return items + (count - 1) * self.itemSize; } - (id)copy { return [self retain]; } - (id)mutableCopy { return [[OFMutableData alloc] initWithItems: self.items count: self.count itemSize: self.itemSize]; } - (bool)isEqual: (id)object { size_t count, itemSize; OFData *data; if (object == self) return true; if (![object isKindOfClass: [OFData class]]) return false; count = self.count; itemSize = self.itemSize; data = object; if (data.count != count || data.itemSize != itemSize) return false; if (memcmp(data.items, self.items, count * itemSize) != 0) return false; return true; } - (OFComparisonResult)compare: (OFData *)data { int comparison; size_t count, dataCount, minCount; if (![data isKindOfClass: [OFData class]]) @throw [OFInvalidArgumentException exception]; if (data.itemSize != self.itemSize) @throw [OFInvalidArgumentException exception]; count = self.count; dataCount = data.count; minCount = (count > dataCount ? dataCount : count); if ((comparison = memcmp(self.items, data.items, minCount * self.itemSize)) == 0) { if (count > dataCount) return OFOrderedDescending; if (count < dataCount) return OFOrderedAscending; return OFOrderedSame; } if (comparison > 0) return OFOrderedDescending; else return OFOrderedAscending; } - (unsigned long)hash { const unsigned char *items = self.items; size_t count = self.count, itemSize = self.itemSize; unsigned long hash; OFHashInit(&hash); for (size_t i = 0; i < count * itemSize; i++) OFHashAddByte(&hash, items[i]); OFHashFinalize(&hash); return hash; } - (OFData *)subdataWithRange: (OFRange)range { if (range.length > SIZE_MAX - range.location || range.location + range.length > self.count) @throw [OFOutOfRangeException exception]; if (![self isKindOfClass: [OFMutableData class]]) return [[[OFSubdata alloc] initWithData: self range: range] autorelease]; return [OFData dataWithItems: (const unsigned char *)self.items + (range.location * self.itemSize) count: self.count itemSize: self.itemSize]; } - (OFString *)description { OFMutableString *ret = [OFMutableString stringWithString: @"<"]; const unsigned char *items = self.items; size_t count = self.count, itemSize = self.itemSize; for (size_t i = 0; i < count; i++) { if (i > 0) [ret appendString: @" "]; for (size_t j = 0; j < itemSize; j++) [ret appendFormat: @"%02x", items[i * itemSize + j]]; } [ret appendString: @">"]; [ret makeImmutable]; return ret; } - (OFString *)stringRepresentation { OFMutableString *ret = [OFMutableString string]; const unsigned char *items = self.items; size_t count = self.count, itemSize = self.itemSize; for (size_t i = 0; i < count; i++) for (size_t j = 0; j < itemSize; j++) [ret appendFormat: @"%02x", items[i * itemSize + j]]; [ret makeImmutable]; return ret; } - (OFString *)stringByBase64Encoding { return _OFBase64Encode(self.items, self.count * self.itemSize); } - (OFRange)rangeOfData: (OFData *)data options: (OFDataSearchOptions)options range: (OFRange)range { const unsigned char *items = self.items; size_t count = self.count, itemSize = self.itemSize; const char *search; size_t searchLength; if (range.length > SIZE_MAX - range.location || range.location + range.length > count) @throw [OFOutOfRangeException exception]; if (data == nil || data.itemSize != itemSize) @throw [OFInvalidArgumentException exception]; if ((searchLength = data.count) == 0) return OFMakeRange(0, 0); if (searchLength > range.length) return OFMakeRange(OFNotFound, 0); search = data.items; if (options & OFDataSearchBackwards) { for (size_t i = range.length - searchLength;; i--) { if (memcmp(items + i * itemSize, search, searchLength * itemSize) == 0) return OFMakeRange(i, searchLength); /* No match and we're at the last item */ if (i == 0) break; } } else { for (size_t i = range.location; i <= range.length - searchLength; i++) if (memcmp(items + i * itemSize, search, searchLength * itemSize) == 0) return OFMakeRange(i, searchLength); } return OFMakeRange(OFNotFound, 0); } #ifdef OF_HAVE_FILES - (void)writeToFile: (OFString *)path { OFFile *file = [[OFFile alloc] initWithPath: path mode: @"w"]; @try { [file writeBuffer: self.items length: self.count * self.itemSize]; } @finally { [file release]; } } #endif - (void)writeToIRI: (OFIRI *)IRI { void *pool = objc_autoreleasePoolPush(); [[OFIRIHandler openItemAtIRI: IRI mode: @"w"] writeData: self]; objc_autoreleasePoolPop(pool); } - (OFData *)messagePackRepresentation { OFMutableData *data; size_t count; if (self.itemSize != 1) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; count = self.count; if (count <= UINT8_MAX) { uint8_t type = 0xC4; uint8_t tmp = (uint8_t)count; data = [OFMutableData dataWithCapacity: count + 2]; [data addItem: &type]; [data addItem: &tmp]; } else if (count <= UINT16_MAX) { uint8_t type = 0xC5; uint16_t tmp = OFToBigEndian16((uint16_t)count); data = [OFMutableData dataWithCapacity: count + 3]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (count <= UINT32_MAX) { uint8_t type = 0xC6; uint32_t tmp = OFToBigEndian32((uint32_t)count); data = [OFMutableData dataWithCapacity: count + 5]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exception]; [data addItems: self.items count: count]; [data makeImmutable]; return data; } @end objfw-1.1.6/src/OFDatagramSocket.h000066400000000000000000000272671465614216400167330ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFKernelEventObserver.h" #import "OFRunLoop.h" #import "OFSocket.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFData; @class OFDatagramSocket; #ifdef OF_HAVE_BLOCKS /** * @brief A block which is called when a packet has been received. * * @param length The length of the packet * @param sender The address of the sender of the packet * @param exception An exception which occurred while receiving or `nil` on * success * @return A bool whether the same block should be used for the next receive */ typedef bool (^OFDatagramSocketAsyncReceiveBlock)(size_t length, const OFSocketAddress *_Nonnull sender, id _Nullable exception); /** * @brief A block which is called when a packet has been sent. * * @param exception An exception which occurred while reading or `nil` on * success * @return The data to repeat the send with or nil if it should not repeat */ typedef OFData *_Nullable (^OFDatagramSocketAsyncSendDataBlock)( id _Nullable exception); #endif /** * @protocol OFDatagramSocketDelegate OFDatagramSocket.h \ * ObjFW/OFDatagramSocket.h * * @brief A delegate for OFDatagramSocket. */ @protocol OFDatagramSocketDelegate @optional /** * @brief This method is called when a packet has been received. * * @param socket The datagram socket which received a packet * @param buffer The buffer the packet has been written to * @param length The length of the packet * @param sender The address of the sender of the packet * @param exception An exception that occurred while receiving, or nil on * success * @return A bool whether the same block should be used for the next receive */ - (bool)socket: (OFDatagramSocket *)socket didReceiveIntoBuffer: (void *)buffer length: (size_t)length sender: (const OFSocketAddress *_Nonnull)sender exception: (nullable id)exception; /** * @brief This method is called when a packet has been sent. * * @param socket The datagram socket which sent a packet * @param data The data which was sent * @param receiver The receiver for the packet * @param exception An exception that occurred while sending, or nil on success * @return The data to repeat the send with or nil if it should not repeat */ - (nullable OFData *)socket: (OFDatagramSocket *)socket didSendData: (OFData *)data receiver: (const OFSocketAddress *_Nonnull)receiver exception: (nullable id)exception; @end /** * @class OFDatagramSocket OFDatagramSocket.h ObjFW/OFDatagramSocket.h * * @brief A base class for datagram sockets. * * @warning Even though the OFCopying protocol is implemented, it does *not* * return an independent copy of the socket, but instead retains it. * This is so that the socket can be used as a key for a dictionary, * so context can be associated with a socket. Using a socket in more * than one thread at the same time is not thread-safe, even if copy * was called to create one "instance" for every thread! */ @interface OFDatagramSocket: OFObject { OFSocketHandle _socket; #ifdef OF_AMIGAOS LONG _socketID; int _family; /* unused, reserved for ABI stability */ #endif bool _canBlock; #ifdef OF_WII bool _canSendToBroadcastAddresses; #endif id _Nullable _delegate; OF_RESERVE_IVARS(OFDatagramSocket, 4) } /** * @brief Whether the socket can block. * * By default, a socket can block. * * @throw OFGetOptionFailedException The option could not be retrieved * @throw OFSetOptionFailedException The option could not be set */ @property (nonatomic) bool canBlock; /** * @brief Whether the socket can send to broadcast addresses. * * @throw OFGetOptionFailedException The option could not be retrieved * @throw OFSetOptionFailedException The option could not be set */ @property (nonatomic) bool canSendToBroadcastAddresses; /** * @brief The delegate for asynchronous operations on the socket. * * @note The delegate is retained for as long as asynchronous operations are * still ongoing. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id delegate; /** * @brief Returns a new, autoreleased OFDatagramSocket. * * @return A new, autoreleased OFDatagramSocket */ + (instancetype)socket; /** * @brief Receives a datagram and stores it into the specified buffer. * * If the buffer is too small, the datagram is truncated. * * @param buffer The buffer to write the datagram to * @param length The length of the buffer * @param sender A pointer to an @ref OFSocketAddress, which will be set to the * address of the sender * @return The length of the received datagram * @throw OFReadFailedException Receiving failed * @throw OFNotOpenException The socket is not open */ - (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length sender: (nullable OFSocketAddress *)sender; /** * @brief Asynchronously receives a datagram and stores it into the specified * buffer. * * If the buffer is too small, the datagram is truncated. * * @param buffer The buffer to write the datagram to * @param length The length of the buffer */ - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length; /** * @brief Asynchronously receives a datagram and stores it into the specified * buffer. * * If the buffer is too small, the datagram is truncated. * * @param buffer The buffer to write the datagram to * @param length The length of the buffer * @param runLoopMode The run loop mode in which to perform the asynchronous * receive */ - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously receives a datagram and stores it into the specified * buffer. * * If the buffer is too small, the datagram is truncated. * * @param buffer The buffer to write the datagram to * @param length The length of the buffer * @param block The block to call when the datagram has been received. If the * block returns true, it will be called again with the same * buffer and maximum length when more datagrams have been * received. If you want the next method in the queue to handle * the datagram received next, you need to return false from the * method. */ - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length block: (OFDatagramSocketAsyncReceiveBlock)block; /** * @brief Asynchronously receives a datagram and stores it into the specified * buffer. * * If the buffer is too small, the datagram is truncated. * * @param buffer The buffer to write the datagram to * @param length The length of the buffer * @param runLoopMode The run loop mode in which to perform the asynchronous * receive * @param block The block to call when the datagram has been received. If the * block returns true, it will be called again with the same * buffer and maximum length when more datagrams have been * received. If you want the next method in the queue to handle * the datagram received next, you need to return false from the * method. */ - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode block: (OFDatagramSocketAsyncReceiveBlock)block; #endif /** * @brief Sends the specified datagram to the specified address. * * @param buffer The buffer to send as a datagram * @param length The length of the buffer * @param receiver A pointer to an @ref OFSocketAddress to which the datagram * should be sent * @throw OFWriteFailedException Sending failed * @throw OFNotOpenException The socket is not open */ - (void)sendBuffer: (const void *)buffer length: (size_t)length receiver: (const OFSocketAddress *)receiver; /** * @brief Asynchronously sends the specified datagram to the specified address. * * @param data The data to send as a datagram * @param receiver A pointer to an @ref OFSocketAddress to which the datagram * should be sent. The receiver is copied. */ - (void)asyncSendData: (OFData *)data receiver: (const OFSocketAddress *)receiver; /** * @brief Asynchronously sends the specified datagram to the specified address. * * @param data The data to send as a datagram * @param receiver A pointer to an @ref OFSocketAddress to which the datagram * should be sent. The receiver is copied. * @param runLoopMode The run loop mode in which to perform the asynchronous * send */ - (void)asyncSendData: (OFData *)data receiver: (const OFSocketAddress *)receiver runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously sends the specified datagram to the specified address. * * @param data The data to send as a datagram * @param receiver A pointer to an @ref OFSocketAddress to which the datagram * should be sent. The receiver is copied. * @param block The block to call when the packet has been sent. It should * return the data for the next send with the same callback or nil * if it should not repeat. */ - (void)asyncSendData: (OFData *)data receiver: (const OFSocketAddress *)receiver block: (OFDatagramSocketAsyncSendDataBlock)block; /** * @brief Asynchronously sends the specified datagram to the specified address. * * @param data The data to send as a datagram * @param receiver A pointer to an @ref OFSocketAddress to which the datagram * should be sent. The receiver is copied. * @param runLoopMode The run loop mode in which to perform the asynchronous * send * @param block The block to call when the packet has been sent. It should * return the data for the next send with the same callback or nil * if it should not repeat. */ - (void)asyncSendData: (OFData *)data receiver: (const OFSocketAddress *)receiver runLoopMode: (OFRunLoopMode)runLoopMode block: (OFDatagramSocketAsyncSendDataBlock)block; #endif /** * @brief Releases the socket from the current thread. * * This is necessary on some platforms in order to allow a different thread to * use the socket, e.g. on AmigaOS, but you should call it on all operating * systems before using the socket from a different thread. * * After calling this method, you must no longer use the socket until * @ref obtainSocketForCurrentThread has been called. */ - (void)releaseSocketFromCurrentThread; /** * @brief Obtains the socket for the current thread. * * This is necessary on some platforms in order to allow a different thread to * use the socket, e.g. on AmigaOS, but you should call it on all operating * systems before using the socket from a different thread. * * You must only call this method after @ref releaseSocketFromCurrentThread has * been called from a different thread. */ - (void)obtainSocketForCurrentThread; /** * @brief Cancels all pending asynchronous requests on the socket. */ - (void)cancelAsyncRequests; /** * @brief Closes the socket so that it can neither receive nor send any more * datagrams. * * @throw OFNotOpenException The socket is not open */ - (void)close; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFDatagramSocket.m000066400000000000000000000253471465614216400167350ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #ifndef _XOPEN_SOURCE_EXTENDED # define _XOPEN_SOURCE_EXTENDED #endif #define _HPUX_ALT_XOPEN_SOCKET_API #include #ifdef HAVE_FCNTL_H # include #endif #import "OFDatagramSocket.h" #import "OFData.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFAlreadyOpenException.h" #import "OFGetOptionFailedException.h" #import "OFInitializationFailedException.h" #import "OFNotOpenException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFSetOptionFailedException.h" #import "OFSetOptionFailedException.h" #import "OFWriteFailedException.h" #if defined(OF_AMIGAOS) && !defined(UNIQUE_ID) # define UNIQUE_ID -1 #endif @implementation OFDatagramSocket @synthesize delegate = _delegate; + (void)initialize { if (self != [OFDatagramSocket class]) return; if (!_OFSocketInit()) @throw [OFInitializationFailedException exceptionWithClass: self]; } + (instancetype)socket { return [[[self alloc] init] autorelease]; } - (instancetype)init { self = [super init]; @try { if (self.class == [OFDatagramSocket class]) { [self doesNotRecognizeSelector: _cmd]; abort(); } _socket = OFInvalidSocketHandle; #ifdef OF_HAVE_AMIGAOS _socketID = -1; #endif _canBlock = true; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_socket != OFInvalidSocketHandle) [self close]; [super dealloc]; } - (id)copy { return [self retain]; } - (bool)canBlock { return _canBlock; } - (void)setCanBlock: (bool)canBlock { #if defined(HAVE_FCNTL) int flags = fcntl(_socket, F_GETFL, 0); if (flags == -1) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: errno]; if (canBlock) flags &= ~O_NONBLOCK; else flags |= O_NONBLOCK; if (fcntl(_socket, F_SETFL, flags) == -1) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: errno]; _canBlock = canBlock; #elif defined(OF_WINDOWS) u_long v = !canBlock; if (ioctlsocket(_socket, FIONBIO, &v) == SOCKET_ERROR) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: _OFSocketErrNo()]; _canBlock = canBlock; #else OF_UNRECOGNIZED_SELECTOR #endif } - (void)setCanSendToBroadcastAddresses: (bool)canSendToBroadcastAddresses { int v = canSendToBroadcastAddresses; if (setsockopt(_socket, SOL_SOCKET, SO_BROADCAST, (char *)&v, (socklen_t)sizeof(v)) != 0) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: _OFSocketErrNo()]; #ifdef OF_WII _canSendToBroadcastAddresses = canSendToBroadcastAddresses; #endif } - (bool)canSendToBroadcastAddresses { #ifndef OF_WII int v; socklen_t len = sizeof(v); if (getsockopt(_socket, SOL_SOCKET, SO_BROADCAST, (char *)&v, &len) != 0 || len != sizeof(v)) @throw [OFGetOptionFailedException exceptionWithObject: self errNo: _OFSocketErrNo()]; return v; #else return _canSendToBroadcastAddresses; #endif } - (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length sender: (OFSocketAddress *)sender { ssize_t ret; if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; if (sender != NULL) sender->length = (socklen_t)sizeof(sender->sockaddr); #ifndef OF_WINDOWS if ((ret = recvfrom(_socket, buffer, length, 0, (sender != NULL ? (struct sockaddr *)&sender->sockaddr : NULL), (sender != NULL ? &sender->length : NULL))) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: _OFSocketErrNo()]; #else if (length > INT_MAX) @throw [OFOutOfRangeException exception]; if ((ret = recvfrom(_socket, buffer, (int)length, 0, (sender != NULL ? (struct sockaddr *)&sender->sockaddr : NULL), (sender != NULL ? &sender->length : NULL))) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: _OFSocketErrNo()]; #endif if (sender != NULL) { struct sockaddr *sa = (struct sockaddr *)&sender->sockaddr; if (sender->length >= (socklen_t)sizeof(sa->sa_family)) { switch (sa->sa_family) { case AF_INET: sender->family = OFSocketAddressFamilyIPv4; break; #ifdef OF_HAVE_IPV6 case AF_INET6: sender->family = OFSocketAddressFamilyIPv6; break; #endif #ifdef OF_HAVE_UNIX_SOCKETS case AF_UNIX: sender->family = OFSocketAddressFamilyUNIX; break; #endif #ifdef OF_HAVE_IPX case AF_IPX: sender->family = OFSocketAddressFamilyIPX; break; #endif #ifdef OF_HAVE_APPLETALK case AF_APPLETALK: sender->family = OFSocketAddressFamilyAppleTalk; break; #endif default: sender->family = OFSocketAddressFamilyUnknown; break; } } else sender->family = OFSocketAddressFamilyUnknown; } return ret; } - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length { [self asyncReceiveIntoBuffer: buffer length: length runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode { [OFRunLoop of_addAsyncReceiveForDatagramSocket: self buffer: buffer length: length mode: runLoopMode # ifdef OF_HAVE_BLOCKS block: NULL # endif delegate: _delegate]; } #ifdef OF_HAVE_BLOCKS - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length block: (OFDatagramSocketAsyncReceiveBlock)block { [self asyncReceiveIntoBuffer: buffer length: length runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode block: (OFDatagramSocketAsyncReceiveBlock)block { [OFRunLoop of_addAsyncReceiveForDatagramSocket: self buffer: buffer length: length mode: runLoopMode block: block delegate: nil]; } #endif - (void)sendBuffer: (const void *)buffer length: (size_t)length receiver: (const OFSocketAddress *)receiver { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; #ifndef OF_WINDOWS ssize_t bytesWritten; if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = sendto(_socket, (void *)buffer, length, 0, (struct sockaddr *)&receiver->sockaddr, receiver->length)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: _OFSocketErrNo()]; #else int bytesWritten; if (length > INT_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = sendto(_socket, buffer, (int)length, 0, (struct sockaddr *)&receiver->sockaddr, receiver->length)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: _OFSocketErrNo()]; #endif if ((size_t)bytesWritten != length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: bytesWritten errNo: 0]; } - (void)asyncSendData: (OFData *)data receiver: (const OFSocketAddress *)receiver { [self asyncSendData: data receiver: receiver runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncSendData: (OFData *)data receiver: (const OFSocketAddress *)receiver runLoopMode: (OFRunLoopMode)runLoopMode { [OFRunLoop of_addAsyncSendForDatagramSocket: self data: data receiver: receiver mode: runLoopMode # ifdef OF_HAVE_BLOCKS block: NULL # endif delegate: _delegate]; } #ifdef OF_HAVE_BLOCKS - (void)asyncSendData: (OFData *)data receiver: (const OFSocketAddress *)receiver block: (OFDatagramSocketAsyncSendDataBlock)block { [self asyncSendData: data receiver: receiver runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncSendData: (OFData *)data receiver: (const OFSocketAddress *)receiver runLoopMode: (OFRunLoopMode)runLoopMode block: (OFDatagramSocketAsyncSendDataBlock)block { [OFRunLoop of_addAsyncSendForDatagramSocket: self data: data receiver: receiver mode: runLoopMode block: block delegate: nil]; } #endif - (void)cancelAsyncRequests { [OFRunLoop of_cancelAsyncRequestsForObject: self mode: OFDefaultRunLoopMode]; } - (int)fileDescriptorForReading { #ifndef OF_WINDOWS return _socket; #else if (_socket == OFInvalidSocketHandle) return -1; if (_socket > INT_MAX) @throw [OFOutOfRangeException exception]; return (int)_socket; #endif } - (int)fileDescriptorForWriting { #ifndef OF_WINDOWS return _socket; #else if (_socket == OFInvalidSocketHandle) return -1; if (_socket > INT_MAX) @throw [OFOutOfRangeException exception]; return (int)_socket; #endif } - (void)releaseSocketFromCurrentThread { #ifdef OF_AMIGAOS if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; if ((_socketID = ReleaseSocket(_socket, UNIQUE_ID)) == -1) { switch (Errno()) { case ENOMEM: @throw [OFOutOfMemoryException exceptionWithRequestedSize: 0]; case EBADF: @throw [OFNotOpenException exceptionWithObject: self]; default: OFEnsure(0); } } _socket = OFInvalidSocketHandle; #endif } - (void)obtainSocketForCurrentThread { #ifdef OF_AMIGAOS if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyOpenException exceptionWithObject: self]; if (_socketID == -1) @throw [OFNotOpenException exceptionWithObject: self]; /* * FIXME: We should store these, but that requires changing all * subclasses. This only becomes a problem if IPv6 support ever * gets added. */ _socket = ObtainSocket(_socketID, AF_INET, SOCK_DGRAM, 0); if (_socket == OFInvalidSocketHandle) @throw [OFInitializationFailedException exceptionWithClass: self.class]; _socketID = -1; #endif } - (void)close { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; closesocket(_socket); _socket = OFInvalidSocketHandle; } @end objfw-1.1.6/src/OFDate.h000066400000000000000000000241031465614216400147010ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFMessagePackRepresentation.h" OF_ASSUME_NONNULL_BEGIN @class OFString; @class OFConstantString; /** * @class OFDate OFDate.h ObjFW/OFDate.h * * @brief A class for storing, accessing and comparing dates. */ @interface OFDate: OFObject #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nonatomic) OFDate *distantFuture; @property (class, readonly, nonatomic) OFDate *distantPast; #endif /** * @brief The microsecond of the date. */ @property (readonly, nonatomic) unsigned long microsecond; /** * @brief The second of the date. */ @property (readonly, nonatomic) unsigned char second; /** * @brief The minute of the date. */ @property (readonly, nonatomic) unsigned char minute; /** * @brief The minute of the date in local time. */ @property (readonly, nonatomic) unsigned char localMinute; /** * @brief The hour of the date. */ @property (readonly, nonatomic) unsigned char hour; /** * @brief The hour of the date in local time. */ @property (readonly, nonatomic) unsigned char localHour; /** * @brief The day of the month of the date. */ @property (readonly, nonatomic) unsigned char dayOfMonth; /** * @brief The day of the month of the date in local time. */ @property (readonly, nonatomic) unsigned char localDayOfMonth; /** * @brief The month of the year of the date. */ @property (readonly, nonatomic) unsigned char monthOfYear; /** * @brief The month of the year of the date in local time. */ @property (readonly, nonatomic) unsigned char localMonthOfYear; /** * @brief The year of the date. */ @property (readonly, nonatomic) unsigned short year; /** * @brief The year of the date in local time. */ @property (readonly, nonatomic) unsigned short localYear; /** * @brief The day of the week of the date. */ @property (readonly, nonatomic) unsigned char dayOfWeek; /** * @brief The day of the week of the date in local time. */ @property (readonly, nonatomic) unsigned char localDayOfWeek; /** * @brief The day of the year of the date. */ @property (readonly, nonatomic) unsigned short dayOfYear; /** * @brief The day of the year of the date in local time. */ @property (readonly, nonatomic) unsigned short localDayOfYear; /** * @brief The seconds since 1970-01-01T00:00:00Z. */ @property (readonly, nonatomic) OFTimeInterval timeIntervalSince1970; /** * @brief The seconds the date is in the future. */ @property (readonly, nonatomic) OFTimeInterval timeIntervalSinceNow; /** * @brief Creates a new OFDate with the current date and time. * * @return A new, autoreleased OFDate with the current date and time */ + (instancetype)date; /** * @brief Creates a new OFDate with the specified date and time since * 1970-01-01T00:00:00Z. * * @param seconds The seconds since 1970-01-01T00:00:00Z * @return A new, autoreleased OFDate with the specified date and time */ + (instancetype)dateWithTimeIntervalSince1970: (OFTimeInterval)seconds; /** * @brief Creates a new OFDate with the specified date and time since now. * * @param seconds The seconds since now * @return A new, autoreleased OFDate with the specified date and time */ + (instancetype)dateWithTimeIntervalSinceNow: (OFTimeInterval)seconds; /** * @brief Creates a new OFDate with the specified string in the specified * format. * * The time zone used is UTC. See @ref dateWithLocalDateString:format: if you * want local time. * * See the man page for `strftime` for information on the format. * * @warning The format is currently limited to the following format specifiers: * %%a, %%b, %%d, %%e, %%H, %%m, %%M, %%S, %%y, %%Y, %%z, %%, %%n and * %%t. * * @param string The string describing the date * @param format The format of the string describing the date * @return A new, autoreleased OFDate with the specified date and time * @throw OFInvalidFormatException The specified format is invalid */ + (instancetype)dateWithDateString: (OFString *)string format: (OFString *)format; /** * @brief Creates a new OFDate with the specified string in the specified * format. * * See the man page for `strftime` for information on the format. * * @warning The format is currently limited to the following format specifiers: * %%a, %%b, %%d, %%e, %%H, %%m, %%M, %%S, %%y, %%Y, %%z, %%, %%n and * %%t. * * @param string The string describing the date * @param format The format of the string describing the date * @return A new, autoreleased OFDate with the specified date and time * @throw OFInvalidFormatException The specified format is invalid */ + (instancetype)dateWithLocalDateString: (OFString *)string format: (OFString *)format; /** * @brief Returns a date in the distant future. * * The date is system-dependent. * * @return A date in the distant future */ + (instancetype)distantFuture; /** * @brief Returns a date in the distant past. * * The date is system-dependent. * * @return A date in the distant past */ + (instancetype)distantPast; /** * @brief Initializes an already allocated OFDate with the specified date and * time since 1970-01-01T00:00:00Z. * * @param seconds The seconds since 1970-01-01T00:00:00Z * @return An initialized OFDate with the specified date and time */ - (instancetype)initWithTimeIntervalSince1970: (OFTimeInterval)seconds OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated OFDate with the specified date and * time since now. * * @param seconds The seconds since now * @return An initialized OFDate with the specified date and time */ - (instancetype)initWithTimeIntervalSinceNow: (OFTimeInterval)seconds; /** * @brief Initializes an already allocated OFDate with the specified string in * the specified format. * * The time zone used is UTC. If a time zone is specified anyway, an * OFInvalidFormatException is thrown. See @ref initWithLocalDateString:format: * if you want to specify a time zone. * * See the man page for `strftime` for information on the format. * * @warning The format is currently limited to the following format specifiers: * %%d, %%e, %%H, %%m, %%M, %%S, %%y, %%Y, %%, %%n and %%t. * * @param string The string describing the date * @param format The format of the string describing the date * @return An initialized OFDate with the specified date and time * @throw OFInvalidFormatException The specified format is invalid */ - (instancetype)initWithDateString: (OFString *)string format: (OFString *)format; /** * @brief Initializes an already allocated OFDate with the specified string in * the specified format. * * If no time zone is specified, local time is assumed. * * See the man page for `strftime` for information on the format. * * @warning The format is currently limited to the following format specifiers: * %%d, %%e, %%H, %%m, %%M, %%S, %%y, %%Y, %%, %%n and %%t. * * @param string The string describing the date * @param format The format of the string describing the date * @return An initialized OFDate with the specified date and time * @throw OFInvalidFormatException The specified format is invalid */ - (instancetype)initWithLocalDateString: (OFString *)string format: (OFString *)format; /** * @brief Compares the date to another date. * * @param date The date to compare the date to * @return The result of the comparison */ - (OFComparisonResult)compare: (OFDate *)date; /** * @brief Creates a string of the date with the specified format. * * See the man page for `strftime` for information on the format. * * @warning The format is currently limited to the following format specifiers: * %%a, %%b, %%d, %%e, %%H, %%m, %%M, %%S, %%y, %%Y, %%z, %%, %%n and * %%t. * * @param format The format for the date string * @return A new, autoreleased OFString * @throw OFInvalidFormatException The specified format is invalid */ - (OFString *)dateStringWithFormat: (OFConstantString *)format; /** * @brief Creates a string of the local date with the specified format. * * See the man page for `strftime` for information on the format. * * @warning The format is currently limited to the following format specifiers: * %%a, %%b, %%d, %%e, %%H, %%m, %%M, %%S, %%y, %%Y, %%z, %%, %%n and * %%t. * * @param format The format for the date string * @return A new, autoreleased OFString * @throw OFInvalidFormatException The specified format is invalid */ - (OFString *)localDateStringWithFormat: (OFConstantString *)format; /** * @brief Returns the earlier of the two dates. * * If the argument is `nil`, it returns the receiver. * * @param otherDate Another date * @return The earlier date of the two dates */ - (OFDate *)earlierDate: (nullable OFDate *)otherDate; /** * @brief Returns the later of the two dates. * * If the argument is `nil`, it returns the receiver. * * @param otherDate Another date * @return The later date of the two dates */ - (OFDate *)laterDate: (nullable OFDate *)otherDate; /** * @brief Returns the seconds the receiver is after the date. * * @param otherDate Date date to generate the difference with receiver * @return The seconds the receiver is after the date. */ - (OFTimeInterval)timeIntervalSinceDate: (OFDate *)otherDate; /** * @brief Creates a new date with the specified time interval added. * * @param seconds The seconds after the date * @return A new, autoreleased OFDate */ - (OFDate *)dateByAddingTimeInterval: (OFTimeInterval)seconds; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFDate.m000066400000000000000000000430131465614216400147070ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #define OF_DATE_M #include "config.h" #include #include #include #include #import "OFDate.h" #import "OFConcreteDate.h" #import "OFData.h" #import "OFDictionary.h" #import "OFMessagePackExtension.h" #ifdef OF_HAVE_THREADS # import "OFMutex.h" #endif #import "OFStrFTime.h" #import "OFStrPTime.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFTaggedPointerDate.h" #import "OFXMLAttribute.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #if defined(OF_AMIGAOS_M68K) || defined(OF_MINT) /* amiga-gcc and freemint-gcc do not have trunc() */ # define trunc(x) ((int64_t)(x)) #endif @interface OFPlaceholderDate: OFDate @end @interface OFConcreteDateSingleton: OFConcreteDate @end static struct { Class isa; } placeholder; static OFConcreteDateSingleton *zeroDate, *distantFuture, *distantPast; static void initZeroDate(void) { zeroDate = [[OFConcreteDateSingleton alloc] initWithTimeIntervalSince1970: 0]; } static void initDistantFuture(void) { distantFuture = [[OFConcreteDateSingleton alloc] initWithTimeIntervalSince1970: 64060588800.0]; } static void initDistantPast(void) { distantPast = [[OFConcreteDateSingleton alloc] initWithTimeIntervalSince1970: -62167219200.0]; } static OFTimeInterval now(void) { struct timeval tv; OFTimeInterval seconds; OFEnsure(gettimeofday(&tv, NULL) == 0); seconds = tv.tv_sec; seconds += (OFTimeInterval)tv.tv_usec / 1000000; return seconds; } #if (!defined(HAVE_GMTIME_R) || !defined(HAVE_LOCALTIME_R)) && \ defined(OF_HAVE_THREADS) static OFMutex *mutex; static void releaseMutex(void) { [mutex release]; } #endif #ifdef OF_WINDOWS static __time64_t (*_mktime64FuncPtr)(struct tm *); #endif #ifdef HAVE_GMTIME_R # define GMTIME_RET(field) \ OFTimeInterval timeInterval = self.timeIntervalSince1970; \ time_t seconds = (time_t)timeInterval; \ struct tm tm; \ \ if (seconds != trunc(timeInterval)) \ @throw [OFOutOfRangeException exception]; \ \ if (gmtime_r(&seconds, &tm) == NULL) \ @throw [OFOutOfRangeException exception]; \ \ return tm.field; # define LOCALTIME_RET(field) \ OFTimeInterval timeInterval = self.timeIntervalSince1970; \ time_t seconds = (time_t)timeInterval; \ struct tm tm; \ \ if (seconds != trunc(timeInterval)) \ @throw [OFOutOfRangeException exception]; \ \ if (localtime_r(&seconds, &tm) == NULL) \ @throw [OFOutOfRangeException exception]; \ \ return tm.field; #else # ifdef OF_HAVE_THREADS # define GMTIME_RET(field) \ OFTimeInterval timeInterval = self.timeIntervalSince1970; \ time_t seconds = (time_t)timeInterval; \ struct tm *tm; \ \ if (seconds != trunc(timeInterval)) \ @throw [OFOutOfRangeException exception]; \ \ [mutex lock]; \ \ @try { \ if ((tm = gmtime(&seconds)) == NULL) \ @throw [OFOutOfRangeException exception]; \ \ return tm->field; \ } @finally { \ [mutex unlock]; \ } # define LOCALTIME_RET(field) \ OFTimeInterval timeInterval = self.timeIntervalSince1970; \ time_t seconds = (time_t)timeInterval; \ struct tm *tm; \ \ if (seconds != trunc(timeInterval)) \ @throw [OFOutOfRangeException exception]; \ \ [mutex lock]; \ \ @try { \ if ((tm = localtime(&seconds)) == NULL) \ @throw [OFOutOfRangeException exception]; \ \ return tm->field; \ } @finally { \ [mutex unlock]; \ } # else # define GMTIME_RET(field) \ OFTimeInterval timeInterval = self.timeIntervalSince1970; \ time_t seconds = (time_t)timeInterval; \ struct tm *tm; \ \ if (seconds != trunc(timeInterval)) \ @throw [OFOutOfRangeException exception]; \ \ if ((tm = gmtime(&seconds)) == NULL) \ @throw [OFOutOfRangeException exception]; \ \ return tm->field; # define LOCALTIME_RET(field) \ OFTimeInterval timeInterval = self.timeIntervalSince1970; \ time_t seconds = (time_t)timeInterval; \ struct tm *tm; \ \ if (seconds != trunc(timeInterval)) \ @throw [OFOutOfRangeException exception]; \ \ if ((tm = localtime(&seconds)) == NULL) \ @throw [OFOutOfRangeException exception]; \ \ return tm->field; # endif #endif static int monthToDayOfYear[12] = { 0, 31, 31 + 28, 31 + 28 + 31, 31 + 28 + 31 + 30, 31 + 28 + 31 + 30 + 31, 31 + 28 + 31 + 30 + 31 + 30, 31 + 28 + 31 + 30 + 31 + 30 + 31, 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31, 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30, 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31, 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30, }; static double tmAndTzToTime(const struct tm *tm, short tz) { double seconds; /* Years */ seconds = (int64_t)(tm->tm_year - 70) * 31536000; /* Days of leap years, excluding the year to look at */ seconds += (((tm->tm_year + 1899) / 4) - 492) * 86400; seconds -= (((tm->tm_year + 1899) / 100) - 19) * 86400; seconds += (((tm->tm_year + 1899) / 400) - 4) * 86400; /* Leap day */ if (tm->tm_mon >= 2 && (((tm->tm_year + 1900) % 4 == 0 && (tm->tm_year + 1900) % 100 != 0) || (tm->tm_year + 1900) % 400 == 0)) seconds += 86400; /* Months */ if (tm->tm_mon < 0 || tm->tm_mon > 12) @throw [OFInvalidFormatException exception]; seconds += monthToDayOfYear[tm->tm_mon] * 86400; /* Days */ seconds += (tm->tm_mday - 1) * 86400; /* Hours */ seconds += tm->tm_hour * 3600; /* Minutes */ seconds += tm->tm_min * 60; /* Seconds */ seconds += tm->tm_sec; /* Time zone */ seconds += -(double)tz * 60; return seconds; } @implementation OFConcreteDateSingleton OF_SINGLETON_METHODS @end @implementation OFPlaceholderDate #ifdef __clang__ /* We intentionally don't call into super, so silence the warning. */ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunknown-pragmas" # pragma clang diagnostic ignored "-Wobjc-designated-initializers" #endif - (instancetype)initWithTimeIntervalSince1970: (OFTimeInterval)seconds { #if defined(OF_OBJFW_RUNTIME) && UINTPTR_MAX == UINT64_MAX uint64_t value; #endif if (seconds == 0) { static OFOnceControl once = OFOnceControlInitValue; OFOnce(&once, initZeroDate); return (id)zeroDate; } #if defined(OF_OBJFW_RUNTIME) && UINTPTR_MAX == UINT64_MAX value = OFFromBigEndian64(OFBitConvertDoubleToUInt64( OFToBigEndianDouble(seconds))); /* Almost all dates fall into this range. */ if (value & (UINT64_C(4) << 60)) { id ret = [OFTaggedPointerDate dateWithUInt64TimeIntervalSince1970: value]; if (ret != nil) return ret; } #endif return (id)[[OFConcreteDate alloc] initWithTimeIntervalSince1970: seconds]; } #ifdef __clang__ # pragma clang diagnostic pop #endif OF_SINGLETON_METHODS @end @implementation OFDate + (void)initialize { #ifdef OF_WINDOWS HMODULE module; #endif if (self != [OFDate class]) return; object_setClass((id)&placeholder, [OFPlaceholderDate class]); #if (!defined(HAVE_GMTIME_R) || !defined(HAVE_LOCALTIME_R)) && \ defined(OF_HAVE_THREADS) mutex = [[OFMutex alloc] init]; atexit(releaseMutex); #endif #ifdef OF_WINDOWS if ((module = GetModuleHandle("msvcrt.dll")) != NULL) _mktime64FuncPtr = (__time64_t (*)(struct tm *)) GetProcAddress(module, "_mktime64"); #endif } + (instancetype)alloc { if (self == [OFDate class]) return (id)&placeholder; return [super alloc]; } + (instancetype)date { return [[[self alloc] init] autorelease]; } + (instancetype)dateWithTimeIntervalSince1970: (OFTimeInterval)seconds { return [[[self alloc] initWithTimeIntervalSince1970: seconds] autorelease]; } + (instancetype)dateWithTimeIntervalSinceNow: (OFTimeInterval)seconds { return [[[self alloc] initWithTimeIntervalSinceNow: seconds] autorelease]; } + (instancetype)dateWithDateString: (OFString *)string format: (OFString *)format { return [[[self alloc] initWithDateString: string format: format] autorelease]; } + (instancetype)dateWithLocalDateString: (OFString *)string format: (OFString *)format { return [[[self alloc] initWithLocalDateString: string format: format] autorelease]; } + (instancetype)distantFuture { static OFOnceControl once = OFOnceControlInitValue; OFOnce(&once, initDistantFuture); return distantFuture; } + (instancetype)distantPast { static OFOnceControl once = OFOnceControlInitValue; OFOnce(&once, initDistantPast); return distantPast; } - (instancetype)init { return [self initWithTimeIntervalSince1970: now()]; } - (instancetype)initWithTimeIntervalSince1970: (OFTimeInterval)seconds { if ([self isMemberOfClass: [OFDate class]]) { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @throw e; } abort(); } return [super init]; } - (instancetype)initWithTimeIntervalSinceNow: (OFTimeInterval)seconds { return [self initWithTimeIntervalSince1970: now() + seconds]; } - (instancetype)initWithDateString: (OFString *)string format: (OFString *)format { void *pool = objc_autoreleasePoolPush(); const char *UTF8String = string.UTF8String; struct tm tm = { .tm_isdst = -1 }; short tz = 0; if (_OFStrPTime(UTF8String, format.UTF8String, &tm, &tz) != UTF8String + string.UTF8StringLength) @throw [OFInvalidFormatException exception]; objc_autoreleasePoolPop(pool); return [self initWithTimeIntervalSince1970: tmAndTzToTime(&tm, tz)]; } - (instancetype)initWithLocalDateString: (OFString *)string format: (OFString *)format { void *pool = objc_autoreleasePoolPush(); const char *UTF8String = string.UTF8String; struct tm tm = { .tm_isdst = -1 }; /* * _OFStrPTime() can never set this to SHRT_MAX, no matter what is * passed to it, so this is a safe way to figure out if the date * contains a time zone. */ short tz = SHRT_MAX; OFTimeInterval seconds; if (_OFStrPTime(UTF8String, format.UTF8String, &tm, &tz) != UTF8String + string.UTF8StringLength) @throw [OFInvalidFormatException exception]; if (tz == SHRT_MAX) { #ifdef OF_WINDOWS if (_mktime64FuncPtr != NULL) { if ((seconds = _mktime64FuncPtr(&tm)) == -1) @throw [OFInvalidFormatException exception]; } else { #endif if ((seconds = mktime(&tm)) == -1) @throw [OFInvalidFormatException exception]; #ifdef OF_WINDOWS } #endif } else seconds = tmAndTzToTime(&tm, tz); objc_autoreleasePoolPop(pool); return [self initWithTimeIntervalSince1970: seconds]; } - (bool)isEqual: (id)object { OFDate *otherDate; if (object == self) return true; if (![object isKindOfClass: [OFDate class]]) return false; otherDate = object; if (otherDate.timeIntervalSince1970 != self.timeIntervalSince1970) return false; return true; } - (unsigned long)hash { unsigned long hash; double tmp; OFHashInit(&hash); tmp = OFToLittleEndianDouble(self.timeIntervalSince1970); for (size_t i = 0; i < sizeof(double); i++) OFHashAddByte(&hash, ((char *)&tmp)[i]); OFHashFinalize(&hash); return hash; } - (id)copy { return [self retain]; } - (OFComparisonResult)compare: (OFDate *)date { if (![date isKindOfClass: [OFDate class]]) @throw [OFInvalidArgumentException exception]; if (self.timeIntervalSince1970 < date.timeIntervalSince1970) return OFOrderedAscending; if (self.timeIntervalSince1970 > date.timeIntervalSince1970) return OFOrderedDescending; return OFOrderedSame; } - (OFString *)description { return [self dateStringWithFormat: @"%Y-%m-%dT%H:%M:%S%z"]; } - (OFData *)messagePackRepresentation { void *pool = objc_autoreleasePoolPush(); OFTimeInterval timeInterval = self.timeIntervalSince1970; int64_t seconds = (int64_t)timeInterval; uint32_t nanoseconds = (uint32_t)((timeInterval - trunc(timeInterval)) * 1000000000); OFData *ret; if (seconds >= 0 && seconds < 0x400000000) { if (seconds <= UINT32_MAX && nanoseconds == 0) { uint32_t seconds32 = (uint32_t)seconds; OFData *data; seconds32 = OFToBigEndian32(seconds32); data = [OFData dataWithItems: &seconds32 count: sizeof(seconds32)]; ret = [[OFMessagePackExtension extensionWithType: -1 data: data] messagePackRepresentation]; } else { uint64_t combined = ((uint64_t)nanoseconds << 34) | (uint64_t)seconds; OFData *data; combined = OFToBigEndian64(combined); data = [OFData dataWithItems: &combined count: sizeof(combined)]; ret = [[OFMessagePackExtension extensionWithType: -1 data: data] messagePackRepresentation]; } } else { OFMutableData *data = [OFMutableData dataWithCapacity: 12]; nanoseconds = OFToBigEndian32(nanoseconds); [data addItems: &nanoseconds count: sizeof(nanoseconds)]; seconds = OFToBigEndian64(seconds); [data addItems: &seconds count: sizeof(seconds)]; ret = [[OFMessagePackExtension extensionWithType: -1 data: data] messagePackRepresentation]; } [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (unsigned long)microsecond { OFTimeInterval timeInterval = self.timeIntervalSince1970; return (unsigned long)((timeInterval - trunc(timeInterval)) * 1000000); } - (unsigned char)second { GMTIME_RET(tm_sec) } - (unsigned char)minute { GMTIME_RET(tm_min) } - (unsigned char)localMinute { LOCALTIME_RET(tm_min) } - (unsigned char)hour { GMTIME_RET(tm_hour) } - (unsigned char)localHour { LOCALTIME_RET(tm_hour) } - (unsigned char)dayOfMonth { GMTIME_RET(tm_mday) } - (unsigned char)localDayOfMonth { LOCALTIME_RET(tm_mday) } - (unsigned char)monthOfYear { GMTIME_RET(tm_mon + 1) } - (unsigned char)localMonthOfYear { LOCALTIME_RET(tm_mon + 1) } - (unsigned short)year { GMTIME_RET(tm_year + 1900) } - (unsigned short)localYear { LOCALTIME_RET(tm_year + 1900) } - (unsigned char)dayOfWeek { GMTIME_RET(tm_wday) } - (unsigned char)localDayOfWeek { LOCALTIME_RET(tm_wday) } - (unsigned short)dayOfYear { GMTIME_RET(tm_yday + 1) } - (unsigned short)localDayOfYear { LOCALTIME_RET(tm_yday + 1) } - (OFString *)dateStringWithFormat: (OFConstantString *)format { OFString *ret; OFTimeInterval timeInterval = self.timeIntervalSince1970; time_t seconds = (time_t)timeInterval; struct tm tm; size_t pageSize; char *buffer; if (seconds != trunc(timeInterval)) @throw [OFOutOfRangeException exception]; #ifdef HAVE_GMTIME_R if (gmtime_r(&seconds, &tm) == NULL) @throw [OFOutOfRangeException exception]; #else # ifdef OF_HAVE_THREADS [mutex lock]; @try { # endif struct tm *tmp; if ((tmp = gmtime(&seconds)) == NULL) @throw [OFOutOfRangeException exception]; tm = *tmp; # ifdef OF_HAVE_THREADS } @finally { [mutex unlock]; } # endif #endif pageSize = [OFSystemInfo pageSize]; buffer = OFAllocMemory(1, pageSize); @try { if (_OFStrFTime(buffer, pageSize, format.UTF8String, &tm, 0) == 0) @throw [OFOutOfRangeException exception]; ret = [OFString stringWithUTF8String: buffer]; } @finally { OFFreeMemory(buffer); } return ret; } - (OFString *)localDateStringWithFormat: (OFConstantString *)format { OFString *ret; OFTimeInterval timeInterval = self.timeIntervalSince1970; time_t seconds = (time_t)timeInterval; struct tm tm; size_t pageSize; char *buffer; if (seconds != trunc(timeInterval)) @throw [OFOutOfRangeException exception]; #ifdef HAVE_LOCALTIME_R if (localtime_r(&seconds, &tm) == NULL) @throw [OFOutOfRangeException exception]; #else # ifdef OF_HAVE_THREADS [mutex lock]; @try { # endif struct tm *tmp; if ((tmp = localtime(&seconds)) == NULL) @throw [OFOutOfRangeException exception]; tm = *tmp; # ifdef OF_HAVE_THREADS } @finally { [mutex unlock]; } # endif #endif pageSize = [OFSystemInfo pageSize]; buffer = OFAllocMemory(1, pageSize); @try { if (_OFStrFTime(buffer, pageSize, format.UTF8String, &tm, 0) == 0) @throw [OFOutOfRangeException exception]; ret = [OFString stringWithUTF8String: buffer]; } @finally { OFFreeMemory(buffer); } return ret; } - (OFDate *)earlierDate: (OFDate *)otherDate { if (otherDate == nil) return self; if ([self compare: otherDate] == OFOrderedDescending) return otherDate; return self; } - (OFDate *)laterDate: (OFDate *)otherDate { if (otherDate == nil) return self; if ([self compare: otherDate] == OFOrderedAscending) return otherDate; return self; } - (OFTimeInterval)timeIntervalSince1970 { OF_UNRECOGNIZED_SELECTOR } - (OFTimeInterval)timeIntervalSinceDate: (OFDate *)otherDate { return self.timeIntervalSince1970 - otherDate.timeIntervalSince1970; } - (OFTimeInterval)timeIntervalSinceNow { struct timeval t; OFTimeInterval seconds; OFEnsure(gettimeofday(&t, NULL) == 0); seconds = t.tv_sec; seconds += (OFTimeInterval)t.tv_usec / 1000000; return self.timeIntervalSince1970 - seconds; } - (OFDate *)dateByAddingTimeInterval: (OFTimeInterval)seconds { return [OFDate dateWithTimeIntervalSince1970: self.timeIntervalSince1970 + seconds]; } @end objfw-1.1.6/src/OFDictionary.h000066400000000000000000000235001465614216400161310ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif #include #import "OFObject.h" #import "OFCollection.h" #import "OFEnumerator.h" #import "OFJSONRepresentation.h" #import "OFMessagePackRepresentation.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); #ifdef OF_HAVE_BLOCKS /** * @brief A block for enumerating an OFDictionary. * * @param key The current key * @param object The object for the current key * @param stop A pointer to a variable that can be set to true to stop the * enumeration. */ typedef void (^OFDictionaryEnumerationBlock)(id key, id object, bool *stop); /** * @brief A block for filtering an OFDictionary. * * @param key The key to inspect * @param object The object for the key to inspect * @return Whether the object should be in the filtered dictionary. */ typedef bool (^OFDictionaryFilterBlock)(id key, id object); /** * @brief A block for mapping keys to objects in an OFDictionary. * * @param key The key to map * @param object The current object for the key * @return The object to map the key to */ typedef id _Nonnull (^OFDictionaryMapBlock)(id key, id object); #endif /** * @class OFDictionary OFDictionary.h ObjFW/OFDictionary.h * * @brief An abstract class for storing objects in a dictionary. * * Keys are copied and thus must conform to the OFCopying protocol. * * @note Fast enumeration on a dictionary enumerates through the keys of the * dictionary. * * @note Subclasses must implement @ref objectForKey:, @ref count and * @ref keyEnumerator. */ @interface OFDictionary OF_GENERIC(KeyType, ObjectType): OFObject #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # define KeyType id # define ObjectType id #endif /** * @brief An array of all keys. */ @property (readonly, nonatomic) OFArray OF_GENERIC(KeyType) *allKeys; /** * @brief An array of all objects. */ @property (readonly, nonatomic) OFArray OF_GENERIC(ObjectType) *allObjects; /** * @brief Creates a new OFDictionary. * * @return A new autoreleased OFDictionary */ + (instancetype)dictionary; /** * @brief Creates a new OFDictionary with the specified dictionary. * * @param dictionary An OFDictionary * @return A new autoreleased OFDictionary */ + (instancetype)dictionaryWithDictionary: (OFDictionary OF_GENERIC(KeyType, ObjectType) *)dictionary; /** * @brief Creates a new OFDictionary with the specified key and object. * * @param key The key * @param object The object * @return A new autoreleased OFDictionary */ + (instancetype)dictionaryWithObject: (ObjectType)object forKey: (KeyType)key; /** * @brief Creates a new OFDictionary with the specified keys and objects. * * @param keys An array of keys * @param objects An array of objects * @return A new autoreleased OFDictionary */ + (instancetype)dictionaryWithObjects: (OFArray OF_GENERIC(ObjectType) *)objects forKeys: (OFArray OF_GENERIC(KeyType) *)keys; /** * @brief Creates a new OFDictionary with the specified keys and objects. * * @param keys An array of keys * @param objects An array of objects * @param count The number of objects in the arrays * @return A new autoreleased OFDictionary */ + (instancetype) dictionaryWithObjects: (ObjectType const _Nonnull *_Nonnull)objects forKeys: (KeyType const _Nonnull *_Nonnull)keys count: (size_t)count; /** * @brief Creates a new OFDictionary with the specified keys objects. * * @param firstKey The first key * @return A new autoreleased OFDictionary */ + (instancetype)dictionaryWithKeysAndObjects: (KeyType)firstKey, ... OF_SENTINEL; /** * @brief Initializes an already allocated OFDictionary to be empty. * * @return An initialized OFDictionary */ - (instancetype)init OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated OFDictionary with the specified * OFDictionary. * * @param dictionary An OFDictionary * @return An initialized OFDictionary */ - (instancetype)initWithDictionary: (OFDictionary OF_GENERIC(KeyType, ObjectType) *)dictionary; /** * @brief Initializes an already allocated OFDictionary with the specified key * and object. * * @param key The key * @param object The object * @return An initialized OFDictionary */ - (instancetype)initWithObject: (ObjectType)object forKey: (KeyType)key; /** * @brief Initializes an already allocated OFDictionary with the specified keys * and objects. * * @param keys An array of keys * @param objects An array of objects * @return An initialized OFDictionary */ - (instancetype)initWithObjects: (OFArray OF_GENERIC(ObjectType) *)objects forKeys: (OFArray OF_GENERIC(KeyType) *)keys; /** * @brief Initializes an already allocated OFDictionary with the specified keys * and objects. * * @param keys An array of keys * @param objects An array of objects * @param count The number of objects in the arrays * @return An initialized OFDictionary */ - (instancetype)initWithObjects: (ObjectType const _Nonnull *_Nonnull)objects forKeys: (KeyType const _Nonnull *_Nonnull)keys count: (size_t)count OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated OFDictionary with the specified keys * and objects. * * @param firstKey The first key * @return An initialized OFDictionary */ - (instancetype)initWithKeysAndObjects: (KeyType)firstKey, ... OF_SENTINEL; /** * @brief Initializes an already allocated OFDictionary with the specified key * and va_list. * * @param firstKey The first key * @param arguments A va_list of the other arguments * @return An initialized OFDictionary */ - (instancetype)initWithKey: (KeyType)firstKey arguments: (va_list)arguments; /** * @brief Returns the object for the given key or `nil` if the key was not * found. * * @warning The returned object is *not* retained and autoreleased for * performance reasons! * * @param key The key whose object should be returned * @return The object for the given key or `nil` if the key was not found */ - (nullable ObjectType)objectForKey: (KeyType)key; - (nullable ObjectType)objectForKeyedSubscript: (KeyType)key; /** * @brief Returns the value for the given key or `nil` if the key was not * found. * * This is equivalent to @ref objectForKey:. * * The special key `@count` can be used to retrieve the count as an OFNumber. * * @param key The key whose value should be returned * @return The value for the given key or `nil` if the key was not found */ - (nullable id)valueForKey: (OFString *)key; /** * @brief Sets a value for a key. * * This is equivalent to OFMutableDictionary#setObject:forKey:. * * @param key The key to set * @param value The value to set the key to * @throw OFUndefinedKeyException The dictionary is immutable */ - (void)setValue: (nullable id)value forKey: (OFString *)key; /** * @brief Checks whether the dictionary contains an object equal to the * specified object. * * @param object The object which is checked for being in the dictionary * @return A boolean whether the dictionary contains the specified object */ - (bool)containsObject: (ObjectType)object; /** * @brief Checks whether the dictionary contains an object with the specified * address. * * @param object The object which is checked for being in the dictionary * @return A boolean whether the dictionary contains an object with the * specified address */ - (bool)containsObjectIdenticalTo: (ObjectType)object; /** * @brief Returns an OFEnumerator to enumerate through the dictionary's keys. * * @return An OFEnumerator to enumerate through the dictionary's keys */ - (OFEnumerator OF_GENERIC(KeyType) *)keyEnumerator; /** * @brief Returns an OFEnumerator to enumerate through the dictionary's objects. * * @return An OFEnumerator to enumerate through the dictionary's objects */ - (OFEnumerator OF_GENERIC(ObjectType) *)objectEnumerator; #ifdef OF_HAVE_BLOCKS /** * @brief Executes a block for each key / object pair. * * @param block The block to execute for each key / object pair. */ - (void)enumerateKeysAndObjectsUsingBlock: (OFDictionaryEnumerationBlock)block; /** * @brief Creates a new dictionary, mapping each object using the specified * block. * * @param block A block which maps an object for each object * @return A new autoreleased OFDictionary */ - (OFDictionary OF_GENERIC(KeyType, id) *) mappedDictionaryUsingBlock: (OFDictionaryMapBlock)block; /** * @brief Creates a new dictionary, only containing the objects for which the * block returns true. * * @param block A block which determines if the object should be in the new * dictionary * @return A new autoreleased OFDictionary */ - (OFDictionary OF_GENERIC(KeyType, ObjectType) *) filteredDictionaryUsingBlock: (OFDictionaryFilterBlock)block; #endif #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # undef KeyType # undef ObjectType #endif @end OF_ASSUME_NONNULL_END #import "OFMutableDictionary.h" #if !defined(NSINTEGER_DEFINED) && !__has_feature(modules) /* Required for dictionary literals to work */ @compatibility_alias NSDictionary OFDictionary; #endif objfw-1.1.6/src/OFDictionary.m000066400000000000000000000440711465614216400161440ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFDictionary.h" #import "OFArray.h" #import "OFCharacterSet.h" #import "OFConcreteDictionary.h" #import "OFData.h" #import "OFEnumerator.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" #import "OFUndefinedKeyException.h" static struct { Class isa; } placeholder; @interface OFDictionary () - (OFString *) of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options depth: (size_t)depth; @end @interface OFPlaceholderDictionary: OFDictionary @end OF_DIRECT_MEMBERS @interface OFDictionaryObjectEnumerator: OFEnumerator { OFDictionary *_dictionary; OFEnumerator *_keyEnumerator; } - (instancetype)initWithDictionary: (OFDictionary *)dictionary; @end @implementation OFPlaceholderDictionary #ifdef __clang__ /* We intentionally don't call into super, so silence the warning. */ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunknown-pragmas" # pragma clang diagnostic ignored "-Wobjc-designated-initializers" #endif - (instancetype)init { return (id)[[OFConcreteDictionary alloc] init]; } - (instancetype)initWithDictionary: (OFDictionary *)dictionary { return (id)[[OFConcreteDictionary alloc] initWithDictionary: dictionary]; } - (instancetype)initWithObject: (id)object forKey: (id)key { return (id)[[OFConcreteDictionary alloc] initWithObject: object forKey: key]; } - (instancetype)initWithObjects: (OFArray *)objects forKeys: (OFArray *)keys { return (id)[[OFConcreteDictionary alloc] initWithObjects: objects forKeys: keys]; } - (instancetype)initWithObjects: (id const *)objects forKeys: (id const *)keys count: (size_t)count { return (id)[[OFConcreteDictionary alloc] initWithObjects: objects forKeys: keys count: count]; } - (instancetype)initWithKeysAndObjects: (id )firstKey, ... { id ret; va_list arguments; va_start(arguments, firstKey); ret = [[OFConcreteDictionary alloc] initWithKey: firstKey arguments: arguments]; va_end(arguments); return ret; } - (instancetype)initWithKey: (id )firstKey arguments: (va_list)arguments { return (id)[[OFConcreteDictionary alloc] initWithKey: firstKey arguments: arguments]; } #ifdef __clang__ # pragma clang diagnostic pop #endif OF_SINGLETON_METHODS @end @implementation OFDictionary + (void)initialize { if (self == [OFDictionary class]) object_setClass((id)&placeholder, [OFPlaceholderDictionary class]); } + (instancetype)alloc { if (self == [OFDictionary class]) return (id)&placeholder; return [super alloc]; } + (instancetype)dictionary { return [[[self alloc] init] autorelease]; } + (instancetype)dictionaryWithDictionary: (OFDictionary *)dictionary { return [[(OFDictionary *)[self alloc] initWithDictionary: dictionary] autorelease]; } + (instancetype)dictionaryWithObject: (id)object forKey: (id)key { return [[[self alloc] initWithObject: object forKey: key] autorelease]; } + (instancetype)dictionaryWithObjects: (OFArray *)objects forKeys: (OFArray *)keys { return [[[self alloc] initWithObjects: objects forKeys: keys] autorelease]; } + (instancetype)dictionaryWithObjects: (id const *)objects forKeys: (id const *)keys count: (size_t)count { return [[[self alloc] initWithObjects: objects forKeys: keys count: count] autorelease]; } + (instancetype)dictionaryWithKeysAndObjects: (id)firstKey, ... { id ret; va_list arguments; va_start(arguments, firstKey); ret = [[[self alloc] initWithKey: firstKey arguments: arguments] autorelease]; va_end(arguments); return ret; } - (instancetype)init { if ([self isMemberOfClass: [OFDictionary class]] || [self isMemberOfClass: [OFMutableDictionary class]]) { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @throw e; } abort(); } return [super init]; } - (instancetype)initWithDictionary: (OFDictionary *)dictionary { void *pool = objc_autoreleasePoolPush(); id const *objects, *keys; size_t count; @try { OFArray *objects_ = [dictionary.objectEnumerator allObjects]; OFArray *keys_ = [dictionary.keyEnumerator allObjects]; count = dictionary.count; if (count != keys_.count || count != objects_.count) @throw [OFInvalidArgumentException exception]; objects = objects_.objects; keys = keys_.objects; } @catch (id e) { [self release]; @throw e; } @try { self = [self initWithObjects: objects forKeys: keys count: count]; } @finally { objc_autoreleasePoolPop(pool); } return self; } - (instancetype)initWithObject: (id)object forKey: (id)key { @try { if (key == nil || object == nil) @throw [OFInvalidArgumentException exception]; } @catch (id e) { [self release]; @throw e; } return [self initWithObjects: &object forKeys: &key count: 1]; } - (instancetype)initWithObjects: (OFArray *)objects_ forKeys: (OFArray *)keys_ { void *pool = objc_autoreleasePoolPush(); id const *objects, *keys; size_t count; @try { count = objects_.count; if (count != keys_.count) @throw [OFInvalidArgumentException exception]; objects = objects_.objects; keys = keys_.objects; } @catch (id e) { [self release]; @throw e; } self = [self initWithObjects: objects forKeys: keys count: count]; objc_autoreleasePoolPop(pool); return self; } #ifdef __clang__ /* We intentionally don't call into super, so silence the warning. */ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunknown-pragmas" # pragma clang diagnostic ignored "-Wobjc-designated-initializers" #endif - (instancetype)initWithObjects: (id const *)objects forKeys: (id const *)keys count: (size_t)count { OF_INVALID_INIT_METHOD } #ifdef __clang__ # pragma clang diagnostic pop #endif - (instancetype)initWithKeysAndObjects: (id)firstKey, ... { id ret; va_list arguments; va_start(arguments, firstKey); ret = [self initWithKey: firstKey arguments: arguments]; va_end(arguments); return ret; } - (instancetype)initWithKey: (id)firstKey arguments: (va_list)arguments { size_t count = 1; id *objects = NULL, *keys = NULL; va_list argumentsCopy; if (firstKey == nil) return [self init]; va_copy(argumentsCopy, arguments); while (va_arg(argumentsCopy, id) != nil) count++; @try { size_t i = 0; id key, object; if (count % 2 != 0) @throw [OFInvalidArgumentException exception]; count /= 2; objects = OFAllocMemory(count, sizeof(id)); keys = OFAllocMemory(count, sizeof(id)); keys[i] = firstKey; objects[i] = va_arg(arguments, id); if (objects[i] == nil) @throw [OFInvalidArgumentException exception]; i++; while ((key = va_arg(arguments, id)) != nil && (object = va_arg(arguments, id)) != nil) { OFEnsure(i < count); objects[i] = object; keys[i] = key; i++; } } @catch (id e) { OFFreeMemory(objects); OFFreeMemory(keys); [self release]; @throw e; } @try { self = [self initWithObjects: objects forKeys: keys count: count]; } @finally { OFFreeMemory(objects); OFFreeMemory(keys); } return self; } - (id)objectForKey: (id)key { OF_UNRECOGNIZED_SELECTOR } - (id)objectForKeyedSubscript: (id)key { return [self objectForKey: key]; } - (id)valueForKey: (OFString *)key { if ([key isEqual: @"@count"]) return [super valueForKey: @"count"]; return [self objectForKey: key]; } - (void)setValue: (id)value forKey: (OFString *)key { if (![self isKindOfClass: [OFMutableDictionary class]]) @throw [OFUndefinedKeyException exceptionWithObject: self key: key value: value]; [(OFMutableDictionary *)self setObject: value forKey: key]; } - (size_t)count { OF_UNRECOGNIZED_SELECTOR } - (id)copy { return [self retain]; } - (id)mutableCopy { return [[OFMutableDictionary alloc] initWithDictionary: self]; } - (bool)isEqual: (id)object { OFDictionary *otherDictionary; void *pool; OFEnumerator *keyEnumerator, *objectEnumerator; id key; if (object == self) return true; if (![object isKindOfClass: [OFDictionary class]]) return false; otherDictionary = object; if (otherDictionary.count != self.count) return false; pool = objc_autoreleasePoolPush(); keyEnumerator = [self keyEnumerator]; objectEnumerator = [self objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { id otherObject = [otherDictionary objectForKey: key]; if (otherObject == nil || ![otherObject isEqual: object]) { objc_autoreleasePoolPop(pool); return false; } } objc_autoreleasePoolPop(pool); return true; } - (bool)containsObject: (id)object { void *pool; OFEnumerator *enumerator; id currentObject; if (object == nil) return false; pool = objc_autoreleasePoolPush(); enumerator = [self objectEnumerator]; while ((currentObject = [enumerator nextObject]) != nil) { if ([currentObject isEqual: object]) { objc_autoreleasePoolPop(pool); return true; } } objc_autoreleasePoolPop(pool); return false; } - (bool)containsObjectIdenticalTo: (id)object { void *pool; OFEnumerator *enumerator; id currentObject; if (object == nil) return false; pool = objc_autoreleasePoolPush(); enumerator = [self objectEnumerator]; while ((currentObject = [enumerator nextObject]) != nil) { if (currentObject == object) { objc_autoreleasePoolPop(pool); return true; } } objc_autoreleasePoolPop(pool); return false; } - (OFArray *)allKeys { OFMutableArray *ret = [OFMutableArray arrayWithCapacity: self.count]; for (id key in self) [ret addObject: key]; [ret makeImmutable]; return ret; } - (OFArray *)allObjects { OFMutableArray *ret = [OFMutableArray arrayWithCapacity: self.count]; void *pool = objc_autoreleasePoolPush(); OFEnumerator *enumerator = [self objectEnumerator]; id object; while ((object = [enumerator nextObject]) != nil) [ret addObject: object]; [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } - (OFEnumerator *)keyEnumerator { OF_UNRECOGNIZED_SELECTOR } - (OFEnumerator *)objectEnumerator { return [[[OFDictionaryObjectEnumerator alloc] initWithDictionary: self] autorelease]; } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count { static unsigned long dummyMutations; OFEnumerator *enumerator; int i; memcpy(&enumerator, state->extra, sizeof(enumerator)); if (enumerator == nil) { enumerator = [self keyEnumerator]; memcpy(state->extra, &enumerator, sizeof(enumerator)); } state->itemsPtr = objects; state->mutationsPtr = &dummyMutations; for (i = 0; i < count; i++) { id object = [enumerator nextObject]; if (object == nil) return i; objects[i] = object; } return i; } #ifdef OF_HAVE_BLOCKS - (void)enumerateKeysAndObjectsUsingBlock: (OFDictionaryEnumerationBlock)block { bool stop = false; for (id key in self) { block(key, [self objectForKey: key], &stop); if (stop) break; } } - (OFDictionary *)mappedDictionaryUsingBlock: (OFDictionaryMapBlock)block { OFMutableDictionary *new = [OFMutableDictionary dictionary]; [self enumerateKeysAndObjectsUsingBlock: ^ (id key, id object, bool *stop) { [new setObject: block(key, object) forKey: key]; }]; [new makeImmutable]; return new; } - (OFDictionary *)filteredDictionaryUsingBlock: (OFDictionaryFilterBlock)block { OFMutableDictionary *new = [OFMutableDictionary dictionary]; [self enumerateKeysAndObjectsUsingBlock: ^ (id key, id object, bool *stop) { if (block(key, object)) [new setObject: object forKey: key]; }]; [new makeImmutable]; return new; } #endif - (unsigned long)hash { void *pool = objc_autoreleasePoolPush(); OFEnumerator *keyEnumerator = [self keyEnumerator]; OFEnumerator *objectEnumerator = [self objectEnumerator]; id key, object; unsigned long hash = 0; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { hash ^= [key hash]; hash ^= [object hash]; } objc_autoreleasePoolPop(pool); return hash; } - (OFString *)description { OFMutableString *ret; void *pool; OFEnumerator *keyEnumerator, *objectEnumerator; OFObject *key, *object; size_t i, count = self.count; if (count == 0) return @"{}"; ret = [OFMutableString stringWithString: @"{\n"]; pool = objc_autoreleasePoolPush(); keyEnumerator = [self keyEnumerator]; objectEnumerator = [self objectEnumerator]; i = 0; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { void *pool2 = objc_autoreleasePoolPush(); [ret appendString: key.description]; [ret appendString: @" = "]; [ret appendString: object.description]; if (++i < count) [ret appendString: @";\n"]; objc_autoreleasePoolPop(pool2); } [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @";\n}"]; [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } - (OFString *)JSONRepresentation { return [self of_JSONRepresentationWithOptions: 0 depth: 0]; } - (OFString *)JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options { return [self of_JSONRepresentationWithOptions: options depth: 0]; } - (OFString *) of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options depth: (size_t)depth { OFMutableString *JSON = [OFMutableString stringWithString: @"{"]; void *pool = objc_autoreleasePoolPush(); OFEnumerator *keyEnumerator = [self keyEnumerator]; OFEnumerator *objectEnumerator = [self objectEnumerator]; size_t i, count = self.count; id key, object; if (options & OFJSONRepresentationOptionPretty) { OFMutableString *indentation = [OFMutableString string]; for (i = 0; i < depth; i++) [indentation appendString: @"\t"]; [JSON appendString: @"\n"]; i = 0; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { void *pool2 = objc_autoreleasePoolPush(); int identifierOptions = options | OFJSONRepresentationOptionIsIdentifier; if (![key isKindOfClass: [OFString class]]) @throw [OFInvalidArgumentException exception]; [JSON appendString: indentation]; [JSON appendString: @"\t"]; [JSON appendString: [key of_JSONRepresentationWithOptions: identifierOptions depth: depth + 1]]; [JSON appendString: @": "]; [JSON appendString: [object of_JSONRepresentationWithOptions: options depth: depth + 1]]; if (++i < count) [JSON appendString: @",\n"]; else [JSON appendString: @"\n"]; objc_autoreleasePoolPop(pool2); } [JSON appendString: indentation]; } else { i = 0; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { void *pool2 = objc_autoreleasePoolPush(); int identifierOptions = options | OFJSONRepresentationOptionIsIdentifier; if (![key isKindOfClass: [OFString class]]) @throw [OFInvalidArgumentException exception]; [JSON appendString: [key of_JSONRepresentationWithOptions: identifierOptions depth: depth + 1]]; [JSON appendString: @":"]; [JSON appendString: [object of_JSONRepresentationWithOptions: options depth: depth + 1]]; if (++i < count) [JSON appendString: @","]; objc_autoreleasePoolPop(pool2); } } [JSON appendString: @"}"]; [JSON makeImmutable]; objc_autoreleasePoolPop(pool); return JSON; } - (OFData *)messagePackRepresentation { OFMutableData *data; size_t i, count; void *pool; OFEnumerator *keyEnumerator, *objectEnumerator; id key, object; data = [OFMutableData data]; count = self.count; if (count <= 15) { uint8_t tmp = 0x80 | ((uint8_t)count & 0xF); [data addItem: &tmp]; } else if (count <= UINT16_MAX) { uint8_t type = 0xDE; uint16_t tmp = OFToBigEndian16((uint16_t)count); [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (count <= UINT32_MAX) { uint8_t type = 0xDF; uint32_t tmp = OFToBigEndian32((uint32_t)count); [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exception]; pool = objc_autoreleasePoolPush(); i = 0; keyEnumerator = [self keyEnumerator]; objectEnumerator = [self objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { void *pool2 = objc_autoreleasePoolPush(); OFData *child; i++; child = key.messagePackRepresentation; [data addItems: child.items count: child.count]; child = object.messagePackRepresentation; [data addItems: child.items count: child.count]; objc_autoreleasePoolPop(pool2); } OFAssert(i == count); [data makeImmutable]; objc_autoreleasePoolPop(pool); return data; } @end @implementation OFDictionaryObjectEnumerator - (instancetype)initWithDictionary: (OFDictionary *)dictionary { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); _dictionary = [dictionary retain]; _keyEnumerator = [[_dictionary keyEnumerator] retain]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_dictionary release]; [_keyEnumerator release]; [super dealloc]; } - (id)nextObject { id key = [_keyEnumerator nextObject]; id object; if (key == nil) return nil; if ((object = [_dictionary objectForKey: key]) == nil) @throw [OFInvalidArgumentException exception]; return object; } @end objfw-1.1.6/src/OFEmbeddedIRIHandler.h000066400000000000000000000027321465614216400173630ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFIRIHandler.h" OF_ASSUME_NONNULL_BEGIN @interface OFEmbeddedIRIHandler: OFIRIHandler @end #ifdef __cplusplus extern "C" { #endif /** * @brief Register a file for the `embedded:` IRI scheme. * * Usually, you should not use the directly, but rather generate a source file * for a file to be embedded using the `objfw-embed` tool. * * @param path The path to the file under the `embedded:` scheme. This is not * retained, so you must either pass a constant string or pass a * string that is already retained! * @param bytes The raw bytes for the file * @param size The size of the file */ extern void OFRegisterEmbeddedFile(OFString *path, const uint8_t *bytes, size_t size); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFEmbeddedIRIHandler.m000066400000000000000000000062341465614216400173710ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #include #import "OFEmbeddedIRIHandler.h" #import "OFIRI.h" #import "OFMemoryStream.h" #import "OFInvalidArgumentException.h" #import "OFOpenItemFailedException.h" #ifdef OF_HAVE_THREADS # import "OFOnce.h" # import "OFPlainMutex.h" #endif static struct EmbeddedFile { OFString *path; const uint8_t *bytes; size_t size; } *embeddedFiles = NULL; static size_t numEmbeddedFiles = 0; #ifdef OF_HAVE_THREADS static OFPlainMutex mutex; static OFOnceControl mutexOnceControl = OFOnceControlInitValue; static void initMutex(void) { OFEnsure(OFPlainMutexNew(&mutex) == 0); } #endif void OFRegisterEmbeddedFile(OFString *path, const uint8_t *bytes, size_t size) { #ifdef OF_HAVE_THREADS OFOnce(&mutexOnceControl, initMutex); OFEnsure(OFPlainMutexLock(&mutex) == 0); #endif embeddedFiles = realloc(embeddedFiles, sizeof(*embeddedFiles) * (numEmbeddedFiles + 1)); OFEnsure(embeddedFiles != NULL); embeddedFiles[numEmbeddedFiles].path = path; embeddedFiles[numEmbeddedFiles].bytes = bytes; embeddedFiles[numEmbeddedFiles].size = size; numEmbeddedFiles++; #ifdef OF_HAVE_THREADS OFEnsure(OFPlainMutexUnlock(&mutex) == 0); #endif } @implementation OFEmbeddedIRIHandler #ifdef OF_HAVE_THREADS + (void)initialize { if (self == [OFEmbeddedIRIHandler class]) OFOnce(&mutexOnceControl, initMutex); } #endif - (OFStream *)openItemAtIRI: (OFIRI *)IRI mode: (OFString *)mode { OFString *path; if (![IRI.scheme isEqual: @"embedded"] || IRI.host.length > 0 || IRI.port != nil || IRI.user != nil || IRI.password != nil || IRI.query != nil || IRI.fragment != nil) @throw [OFInvalidArgumentException exception]; if (![mode isEqual: @"r"]) @throw [OFOpenItemFailedException exceptionWithIRI: IRI mode: mode errNo: EROFS]; if ((path = IRI.path) == nil) { @throw [OFInvalidArgumentException exception]; } #ifdef OF_HAVE_THREADS OFEnsure(OFPlainMutexLock(&mutex) == 0); @try { #endif for (size_t i = 0; i < numEmbeddedFiles; i++) { if (![embeddedFiles[i].path isEqual: path]) continue; return [OFMemoryStream streamWithMemoryAddress: (void *) embeddedFiles[i].bytes size: embeddedFiles[i].size writable: false]; } #ifdef OF_HAVE_THREADS } @finally { OFEnsure(OFPlainMutexUnlock(&mutex) == 0); } #endif @throw [OFOpenItemFailedException exceptionWithIRI: IRI mode: mode errNo: ENOENT]; } @end objfw-1.1.6/src/OFEnumerator.h000066400000000000000000000076501465614216400161550ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFEnumerator OF_GENERIC(ObjectType); /** * @protocol OFEnumeration OFEnumerator.h ObjFW/OFEnumerator.h * * @brief A protocol for getting an enumerator for the object. * * If the class conforming to OFEnumeration is using lightweight generics, the * only method, @ref objectEnumerator, should be overridden to use lightweight * generics. */ @protocol OFEnumeration /** * @brief Returns an OFEnumerator to enumerate through all objects of the * collection. * * @return An OFEnumerator to enumerate through all objects of the collection */ - (OFEnumerator *)objectEnumerator; @end /* * This needs to be exactly like this because it's hard-coded in the compiler. * * We need this bad check to see if we already imported Cocoa, which defines * this as well. */ /** * @struct OFFastEnumerationState OFEnumerator.h ObjFW/OFEnumerator.h * * @brief State information for fast enumerations. */ typedef struct { /** Arbitrary state information for the enumeration */ unsigned long state; /** Pointer to a C array of objects to return */ id __unsafe_unretained _Nullable *_Nullable itemsPtr; /** Arbitrary state information to detect mutations */ unsigned long *_Nullable mutationsPtr; /** Additional arbitrary state information */ unsigned long extra[5]; } OFFastEnumerationState; #ifndef NSINTEGER_DEFINED typedef OFFastEnumerationState NSFastEnumerationState; #endif /** * @protocol OFFastEnumeration OFEnumerator.h ObjFW/OFEnumerator.h * * @brief A protocol for fast enumeration. * * The OFFastEnumeration protocol needs to be implemented by all classes * supporting fast enumeration. */ @protocol OFFastEnumeration /** * @brief A method which is called by the code produced by the compiler when * doing a fast enumeration. * * @param state Context information for the enumeration * @param objects A pointer to an array where to put the objects * @param count The number of objects that can be stored at objects * @return The number of objects returned in objects or 0 when the enumeration * finished. * @throw OFEnumerationMutationException The object was mutated during * enumeration */ - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id __unsafe_unretained _Nonnull *_Nonnull) objects count: (int)count; @end /** * @class OFEnumerator OFEnumerator.h ObjFW/OFEnumerator.h * * @brief A class which provides methods to enumerate through collections. */ @interface OFEnumerator OF_GENERIC(ObjectType): OFObject #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # define ObjectType id #endif /** * @brief Returns the next object or `nil` if there is none left. * * @return The next object or `nil` if there is none left * @throw OFEnumerationMutationException The object was mutated during * enumeration */ - (nullable ObjectType)nextObject; /** * @brief Returns an array of all remaining objects in the collection. * * @return An array of all remaining objects in the collection. */ - (OFArray OF_GENERIC(ObjectType) *)allObjects; #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # undef ObjectType #endif @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFEnumerator.m000066400000000000000000000033641465614216400161600ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFEnumerator.h" #import "OFArray.h" @implementation OFEnumerator - (instancetype)init { if ([self isMemberOfClass: [OFEnumerator class]]) { @try { [self doesNotRecognizeSelector: _cmd]; abort(); } @catch (id e) { [self release]; @throw e; } } return [super init]; } - (id)nextObject { OF_UNRECOGNIZED_SELECTOR } - (OFArray *)allObjects { OFMutableArray *ret = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); id object; while ((object = [self nextObject]) != nil) [ret addObject: object]; [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count { static unsigned long dummyMutations; int i; state->itemsPtr = objects; state->mutationsPtr = &dummyMutations; for (i = 0; i < count; i++) { id object = [self nextObject]; if (object == nil) return i; objects[i] = object; } return i; } @end objfw-1.1.6/src/OFEpollKernelEventObserver.h000066400000000000000000000016571465614216400207630ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFKernelEventObserver.h" OF_ASSUME_NONNULL_BEGIN @class OFMapTable; @interface OFEpollKernelEventObserver: OFKernelEventObserver { int _epfd; OFMapTable *_FDToEvents; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFEpollKernelEventObserver.m000066400000000000000000000135401465614216400207620ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #ifdef HAVE_FCNTL_H # include #endif #include "unistd_wrapper.h" #include #import "OFEpollKernelEventObserver.h" #import "OFArray.h" #import "OFMapTable.h" #import "OFNull.h" #import "OFInitializationFailedException.h" #import "OFObserveKernelEventsFailedException.h" #define eventListSize 64 static const OFMapTableFunctions mapFunctions = { NULL }; @implementation OFEpollKernelEventObserver - (instancetype)init { self = [super init]; @try { struct epoll_event event; #ifdef HAVE_EPOLL_CREATE1 if ((_epfd = epoll_create1(EPOLL_CLOEXEC)) == -1) @throw [OFInitializationFailedException exceptionWithClass: self.class]; #else int flags; if ((_epfd = epoll_create(1)) == -1) @throw [OFInitializationFailedException exceptionWithClass: self.class]; if ((flags = fcntl(_epfd, F_GETFD, 0)) != -1) fcntl(_epfd, F_SETFD, flags | FD_CLOEXEC); #endif _FDToEvents = [[OFMapTable alloc] initWithKeyFunctions: mapFunctions objectFunctions: mapFunctions]; memset(&event, 0, sizeof(event)); event.events = EPOLLIN; event.data.ptr = [OFNull null]; if (epoll_ctl(_epfd, EPOLL_CTL_ADD, _cancelFD[0], &event) == -1) @throw [OFInitializationFailedException exceptionWithClass: self.class]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { close(_epfd); [_FDToEvents release]; [super dealloc]; } - (void)of_addObject: (id)object fileDescriptor: (int)fd events: (int)addEvents OF_DIRECT { struct epoll_event event; intptr_t events; events = (intptr_t)[_FDToEvents objectForKey: (void *)((intptr_t)fd + 1)]; memset(&event, 0, sizeof(event)); event.events = (int)events | addEvents; event.data.ptr = object; if (epoll_ctl(_epfd, (events == 0 ? EPOLL_CTL_ADD : EPOLL_CTL_MOD), fd, &event) == -1) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: errno]; [_FDToEvents setObject: (void *)(events | addEvents) forKey: (void *)((intptr_t)fd + 1)]; } - (void)of_removeObject: (id)object fileDescriptor: (int)fd events: (int)removeEvents OF_DIRECT { intptr_t events; events = (intptr_t)[_FDToEvents objectForKey: (void *)((intptr_t)fd + 1)]; events &= ~removeEvents; if (events == 0) { if (epoll_ctl(_epfd, EPOLL_CTL_DEL, fd, NULL) == -1) /* * When an async connect fails, it seems the socket is * automatically removed from epoll, meaning ENOENT is * returned when we try to remove it after it failed. */ if (errno != ENOENT) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: errno]; [_FDToEvents removeObjectForKey: (void *)((intptr_t)fd + 1)]; } else { struct epoll_event event; memset(&event, 0, sizeof(event)); event.events = (int)events; event.data.ptr = object; if (epoll_ctl(_epfd, EPOLL_CTL_MOD, fd, &event) == -1) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: errno]; [_FDToEvents setObject: (void *)events forKey: (void *)((intptr_t)fd + 1)]; } } - (void)addObjectForReading: (id )object { [self of_addObject: object fileDescriptor: object.fileDescriptorForReading events: EPOLLIN]; [super addObjectForReading: object]; } - (void)addObjectForWriting: (id )object { [self of_addObject: object fileDescriptor: object.fileDescriptorForWriting events: EPOLLOUT]; [super addObjectForWriting: object]; } - (void)removeObjectForReading: (id )object { [self of_removeObject: object fileDescriptor: object.fileDescriptorForReading events: EPOLLIN]; [super removeObjectForReading: object]; } - (void)removeObjectForWriting: (id )object { [self of_removeObject: object fileDescriptor: object.fileDescriptorForWriting events: EPOLLOUT]; [super removeObjectForWriting: object]; } - (void)observeForTimeInterval: (OFTimeInterval)timeInterval { OFNull *nullObject = [OFNull null]; struct epoll_event eventList[eventListSize]; int events; if ([self of_processReadBuffers]) return; events = epoll_wait(_epfd, eventList, eventListSize, (timeInterval != -1 ? timeInterval * 1000 : -1)); if (events < 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: errno]; for (int i = 0; i < events; i++) { if (eventList[i].events & EPOLLIN) { void *pool = objc_autoreleasePoolPush(); if (eventList[i].data.ptr == nullObject) { char buffer; OFEnsure(read(_cancelFD[0], &buffer, 1) == 1); continue; } if ([_delegate respondsToSelector: @selector(objectIsReadyForReading:)]) [_delegate objectIsReadyForReading: eventList[i].data.ptr]; objc_autoreleasePoolPop(pool); } if (eventList[i].events & EPOLLOUT) { void *pool = objc_autoreleasePoolPush(); if ([_delegate respondsToSelector: @selector(objectIsReadyForWriting:)]) [_delegate objectIsReadyForWriting: eventList[i].data.ptr]; objc_autoreleasePoolPop(pool); } } } @end objfw-1.1.6/src/OFFile.h000066400000000000000000000101731465614216400147050ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFSeekableStream.h" #import "OFKernelEventObserver.h" #ifndef OF_AMIGAOS # define OF_FILE_HANDLE_IS_FD typedef int OFFileHandle; static const OFFileHandle OFInvalidFileHandle = -1; #else typedef struct _OFFileHandle *OFFileHandle; static const OFFileHandle OFInvalidFileHandle = NULL; #endif OF_ASSUME_NONNULL_BEGIN /** * @class OFFile OFFile.h ObjFW/OFFile.h * * @brief A class which provides methods to read and write files. */ OF_SUBCLASSING_RESTRICTED @interface OFFile: OFSeekableStream #ifdef OF_FILE_HANDLE_IS_FD #endif { OFFileHandle _handle; bool _initialized, _atEndOfStream; } /** * @brief Creates a new OFFile with the specified path and mode. * * @param path The path to the file to open as a string * @param mode The mode in which the file should be opened. * @n * Possible modes are: * Mode | Description * ---------------|------------------------------------- * `r` | Read-only * `r+` | Read-write * `w` | Write-only, create or truncate * `wx` | Write-only, create or fail, exclusive * `w+` | Read-write, create or truncate * `w+x` | Read-write, create or fail, exclusive * `a` | Write-only, create or append * `a+` | Read-write, create or append * @return A new autoreleased OFFile * @throw OFOpenItemFailedException Opening the file failed */ + (instancetype)fileWithPath: (OFString *)path mode: (OFString *)mode; /** * @brief Creates a new OFFile with the specified native file handle. * * @param handle A native file handle. If OF_FILE_HANDLE_IS_FD is defined, this * is a file descriptor. The handle is closed when the OFFile * object is deallocated! * @return A new autoreleased OFFile */ + (instancetype)fileWithHandle: (OFFileHandle)handle; /** * @brief Initializes an already allocated OFFile. * * @param path The path to the file to open as a string * @param mode The mode in which the file should be opened.@n * Possible modes are: * Mode | Description * ---------------|------------------------------------- * `r` | read-only * `rb` | read-only, binary * `r+` | read-write * `rb+` or `r+b` | read-write, binary * `w` | write-only, create, truncate * `wb` | write-only, create, truncate, binary * `w` | read-write, create, truncate * `wb+` or `w+b` | read-write, create, truncate, binary * `a` | write-only, create, append * `ab` | write-only, create, append, binary * `a+` | read-write, create, append * `ab+` or `a+b` | read-write, create, append, binary * @return An initialized OFFile * @throw OFOpenItemFailedException Opening the file failed */ - (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode; /** * @brief Initializes an already allocated OFFile. * * @param handle A native file handle. If OF_FILE_HANDLE_IS_FD is defined, this * is a file descriptor. The handle is closed when the OFFile * object is deallocated! * @return An initialized OFFile */ - (instancetype)initWithHandle: (OFFileHandle)handle OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFFile.m000066400000000000000000000276531465614216400147250ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #ifndef _LARGEFILE64_SOURCE # define _LARGEFILE64_SOURCE 1 #endif #include #ifdef HAVE_FCNTL_H # include #endif #include "unistd_wrapper.h" #ifdef HAVE_SYS_STAT_H # include #endif #import "OFFile.h" #import "OFLocale.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFNotOpenException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFSeekFailedException.h" #import "OFWriteFailedException.h" #ifdef OF_WINDOWS # include #endif #ifdef OF_AMIGAOS # define Class IntuitionClass # include # include # undef Class #endif #ifdef OF_WII # include #endif #ifdef OF_NINTENDO_DS # include # include #endif #ifdef OF_NINTENDO_SWITCH # define id nx_id # include # undef id #endif #ifndef O_BINARY # define O_BINARY 0 #endif #ifndef O_CLOEXEC # define O_CLOEXEC 0 #endif #ifndef O_EXCL # define O_EXCL 0 #endif #ifndef O_EXLOCK # define O_EXLOCK 0 #endif #ifndef OF_AMIGAOS # define closeHandle(h) close(h) #else static struct _OFFileHandle { struct _OFFileHandle *previous, *next; BPTR handle; bool append; } *firstHandle = NULL; static void closeHandle(OFFileHandle handle) { Close(handle->handle); Forbid(); if (handle->previous != NULL) handle->previous->next = handle->next; if (handle->next != NULL) handle->next->previous = handle->previous; if (firstHandle == handle) firstHandle = handle->next; Permit(); OFFreeMemory(handle); } OF_DESTRUCTOR() { for (OFFileHandle iter = firstHandle; iter != NULL; iter = iter->next) Close(iter->handle); } #endif #ifndef OF_AMIGAOS static int parseMode(const char *mode) { if (strcmp(mode, "r") == 0) return O_RDONLY; if (strcmp(mode, "r+") == 0) return O_RDWR; if (strcmp(mode, "w") == 0) return O_WRONLY | O_CREAT | O_TRUNC; if (strcmp(mode, "wx") == 0) return O_WRONLY | O_CREAT | O_EXCL | O_EXLOCK; if (strcmp(mode, "w+") == 0) return O_RDWR | O_CREAT | O_TRUNC; if (strcmp(mode, "w+x") == 0) return O_RDWR | O_CREAT | O_EXCL | O_EXLOCK; if (strcmp(mode, "a") == 0) return O_WRONLY | O_CREAT | O_APPEND; if (strcmp(mode, "a+") == 0) return O_RDWR | O_CREAT | O_APPEND; return -1; } #else static int parseMode(const char *mode, bool *append) { *append = false; if (strcmp(mode, "r") == 0) return MODE_OLDFILE; if (strcmp(mode, "r+") == 0) return MODE_OLDFILE; if (strcmp(mode, "w") == 0) return MODE_NEWFILE; if (strcmp(mode, "wx") == 0) return MODE_NEWFILE; if (strcmp(mode, "w+") == 0) return MODE_NEWFILE; if (strcmp(mode, "w+x") == 0) return MODE_NEWFILE; if (strcmp(mode, "a") == 0) { *append = true; return MODE_READWRITE; } if (strcmp(mode, "a+") == 0) { *append = true; return MODE_READWRITE; } return -1; } #endif @implementation OFFile + (void)initialize { if (self != [OFFile class]) return; #ifdef OF_WII if (!fatInitDefault()) @throw [OFInitializationFailedException exceptionWithClass: self]; #endif #ifdef OF_NINTENDO_DS if (!nitroFSInit(NULL)) @throw [OFInitializationFailedException exceptionWithClass: self]; #endif #ifdef OF_NINTENDO_SWITCH if (R_SUCCEEDED(romfsInit())) /* * Errors are intentionally ignored, as it's possible we just * have no romfs. */ atexit((void (*)(void))romfsExit); #endif } + (instancetype)fileWithPath: (OFString *)path mode: (OFString *)mode { return [[[self alloc] initWithPath: path mode: mode] autorelease]; } + (instancetype)fileWithHandle: (OFFileHandle)handle { return [[[self alloc] initWithHandle: handle] autorelease]; } - (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode { OFFileHandle handle; @try { void *pool = objc_autoreleasePoolPush(); int flags; #ifndef OF_AMIGAOS if ((flags = parseMode(mode.UTF8String)) == -1) @throw [OFInvalidArgumentException exception]; flags |= O_BINARY | O_CLOEXEC; # ifdef OF_WINDOWS if ([OFSystemInfo isWindowsNT]) handle = _wopen(path.UTF16String, flags, _S_IREAD | _S_IWRITE); else # endif # ifdef HAVE_OPEN64 handle = open64( [path cStringWithEncoding: [OFLocale encoding]], flags, 0666); # else handle = open( [path cStringWithEncoding: [OFLocale encoding]], flags, 0666); # endif if (handle == -1) @throw [OFOpenItemFailedException exceptionWithPath: path mode: mode errNo: errno]; #else handle = OFAllocMemory(1, sizeof(*handle)); @try { if ((flags = parseMode(mode.UTF8String, &handle->append)) == -1) @throw [OFInvalidArgumentException exception]; if ((handle->handle = Open([path cStringWithEncoding: [OFLocale encoding]], flags)) == 0) { int errNo; switch (IoErr()) { case ERROR_OBJECT_IN_USE: case ERROR_DISK_NOT_VALIDATED: errNo = EBUSY; break; case ERROR_OBJECT_NOT_FOUND: errNo = ENOENT; break; case ERROR_DISK_WRITE_PROTECTED: errNo = EROFS; break; case ERROR_WRITE_PROTECTED: case ERROR_READ_PROTECTED: errNo = EACCES; break; default: errNo = 0; break; } @throw [OFOpenItemFailedException exceptionWithPath: path mode: mode errNo: errNo]; } if (handle->append) { # if defined(OF_MORPHOS) if (Seek64(handle->handle, 0, OFFSET_END) == -1) { # elif defined(OF_AMIGAOS4) if (ChangeFilePosition(handle->handle, 0, OFFSET_END) == -1) { # else if (Seek(handle->handle, 0, OFFSET_END) == -1) { # endif Close(handle->handle); @throw [OFOpenItemFailedException exceptionWithPath: path mode: mode errNo: EIO]; } } Forbid(); handle->previous = NULL; handle->next = firstHandle; if (firstHandle != NULL) firstHandle->previous = handle; firstHandle = handle; Permit(); } @catch (id e) { OFFreeMemory(handle); @throw e; } #endif objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @try { self = [self initWithHandle: handle]; } @catch (id e) { closeHandle(handle); @throw e; } return self; } - (instancetype)initWithHandle: (OFFileHandle)handle { self = [super init]; _handle = handle; _initialized = true; return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (bool)lowlevelIsAtEndOfStream { if (_handle == OFInvalidFileHandle) @throw [OFNotOpenException exceptionWithObject: self]; return _atEndOfStream; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { ssize_t ret; if (_handle == OFInvalidFileHandle) @throw [OFNotOpenException exceptionWithObject: self]; #if defined(OF_WINDOWS) if (length > UINT_MAX) @throw [OFOutOfRangeException exception]; if ((ret = read(_handle, buffer, (unsigned int)length)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: errno]; #elif defined(OF_AMIGAOS) if (length > LONG_MAX) @throw [OFOutOfRangeException exception]; if ((ret = Read(_handle->handle, buffer, length)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: EIO]; #else if ((ret = read(_handle, buffer, length)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: errno]; #endif if (ret == 0) _atEndOfStream = true; return ret; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { if (_handle == OFInvalidFileHandle) @throw [OFNotOpenException exceptionWithObject: self]; #if defined(OF_WINDOWS) int bytesWritten; if (length > INT_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = write(_handle, buffer, (int)length)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: errno]; #elif defined(OF_AMIGAOS) LONG bytesWritten; if (length > LONG_MAX) @throw [OFOutOfRangeException exception]; if (_handle->append) { # if defined(OF_MORPHOS) if (Seek64(_handle->handle, 0, OFFSET_END) == -1) # elif defined(OF_AMIGAOS4) if (ChangeFilePosition(_handle->handle, 0, OFFSET_END) == -1) # else if (Seek(_handle->handle, 0, OFFSET_END) == -1) # endif @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: EIO]; } if ((bytesWritten = Write(_handle->handle, (void *)buffer, length)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: EIO]; #else ssize_t bytesWritten; if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = write(_handle, buffer, length)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: errno]; #endif return (size_t)bytesWritten; } - (OFStreamOffset)lowlevelSeekToOffset: (OFStreamOffset)offset whence: (OFSeekWhence)whence { OFStreamOffset ret; if (_handle == OFInvalidFileHandle) @throw [OFNotOpenException exceptionWithObject: self]; #ifndef OF_AMIGAOS int translatedWhence; switch (whence) { case OFSeekSet: translatedWhence = SEEK_SET; break; case OFSeekCurrent: translatedWhence = SEEK_CUR; break; case OFSeekEnd: translatedWhence = SEEK_END; break; default: @throw [OFSeekFailedException exceptionWithStream: self offset: offset whence: whence errNo: EINVAL]; } # if defined(OF_WINDOWS) ret = _lseeki64(_handle, offset, translatedWhence); # elif defined(HAVE_LSEEK64) ret = lseek64(_handle, offset, translatedWhence); # else ret = lseek(_handle, offset, translatedWhence); # endif if (ret == -1) @throw [OFSeekFailedException exceptionWithStream: self offset: offset whence: whence errNo: errno]; #else LONG translatedWhence; switch (whence) { case OFSeekSet: translatedWhence = OFFSET_BEGINNING; break; case OFSeekCurrent: translatedWhence = OFFSET_CURRENT; break; case OFSeekEnd: translatedWhence = OFFSET_END; break; default: @throw [OFSeekFailedException exceptionWithStream: self offset: offset whence: whence errNo: EINVAL]; } # if defined(OF_MORPHOS) if ((ret = Seek64(_handle->handle, offset, translatedWhence)) == 1) # elif defined(OF_AMIGAOS4) if ((ret = ChangeFilePosition(_handle->handle, offset, translatedWhence)) == 1) # else if ((ret = Seek(_handle->handle, offset, translatedWhence)) == 1) # endif @throw [OFSeekFailedException exceptionWithStream: self offset: offset whence: whence errNo: EINVAL]; #endif _atEndOfStream = false; return ret; } #ifdef OF_FILE_HANDLE_IS_FD - (int)fileDescriptorForReading { return _handle; } - (int)fileDescriptorForWriting { return _handle; } #endif - (void)close { if (_handle == OFInvalidFileHandle) @throw [OFNotOpenException exceptionWithObject: self]; closeHandle(_handle); _handle = OFInvalidFileHandle; [super close]; } - (void)dealloc { if (_initialized && _handle != OFInvalidFileHandle) [self close]; [super dealloc]; } @end objfw-1.1.6/src/OFFileIRIHandler.h000066400000000000000000000016231465614216400165470ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFIRIHandler.h" OF_ASSUME_NONNULL_BEGIN @interface OFFileIRIHandler: OFIRIHandler + (bool)of_directoryExistsAtPath: (OFString *)path OF_DIRECT; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFFileIRIHandler.m000066400000000000000000001417011465614216400165560ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #ifndef _LARGEFILE64_SOURCE # define _LARGEFILE64_SOURCE 1 #endif #include #include #ifdef HAVE_DIRENT_H # include #endif #include "unistd_wrapper.h" #include "platform.h" #ifdef HAVE_SYS_STAT_H # include #endif #include #if defined(OF_LINUX) || defined(OF_MACOS) # include #endif #if defined(OF_FREEBSD) || defined(OF_NETBSD) # include #endif #ifdef OF_HAIKU # include #endif #ifdef OF_DJGPP # include #endif #ifdef HAVE_FCNTL_H # include #endif #ifdef HAVE_PWD_H # include #endif #ifdef HAVE_GRP_H # include #endif #import "OFFileIRIHandler.h" #import "OFArray.h" #import "OFData.h" #import "OFDate.h" #import "OFFile.h" #import "OFFileManager.h" #import "OFIRI.h" #import "OFLocale.h" #import "OFNumber.h" #import "OFSystemInfo.h" #ifdef OF_HAVE_THREADS # import "OFMutex.h" #endif #import "OFCreateDirectoryFailedException.h" #import "OFCreateSymbolicLinkFailedException.h" #import "OFGetItemAttributesFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFLinkItemFailedException.h" #import "OFMoveItemFailedException.h" #import "OFNotImplementedException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFRemoveItemFailedException.h" #import "OFSetItemAttributesFailedException.h" #ifdef OF_WINDOWS # include # include # include # include #endif #ifdef OF_AMIGAOS # define Class IntuitionClass # include # include # include # undef Class # ifdef OF_AMIGAOS4 # define DeleteFile(path) Delete(path) # endif #endif #if defined(OF_WINDOWS) || defined(OF_AMIGAOS) typedef struct { OFStreamOffset st_size; unsigned int st_mode; OFTimeInterval st_atime, st_mtime, st_ctime; # ifdef OF_WINDOWS # define HAVE_STRUCT_STAT_ST_BIRTHTIME OFTimeInterval st_birthtime; DWORD fileAttributes; # endif } Stat; #elif defined(HAVE_STAT64) typedef struct stat64 Stat; #else typedef struct stat Stat; #endif #ifdef OF_WINDOWS # define S_IFLNK 0x10000 # define S_ISLNK(mode) (mode & S_IFLNK) #endif #if defined(OF_FILE_MANAGER_SUPPORTS_OWNER) && defined(OF_HAVE_THREADS) static OFMutex *passwdMutex; static void releasePasswdMutex(void) { [passwdMutex release]; } #endif #if defined(OF_HAVE_THREADS) && !defined(__GLIBC__) && !defined(OF_WINDOWS) static OFMutex *readdirMutex; static void releaseReaddirMutex(void) { [readdirMutex release]; } #endif #ifdef OF_WINDOWS static WINAPI BOOLEAN (*createSymbolicLinkWFuncPtr)(LPCWSTR, LPCWSTR, DWORD); static WINAPI BOOLEAN (*createHardLinkWFuncPtr)(LPCWSTR, LPCWSTR, LPSECURITY_ATTRIBUTES); #endif #ifdef OF_FREEBSD static const char *namespaces[] = EXTATTR_NAMESPACE_NAMES; static int numNamespaces = sizeof(namespaces) / sizeof(*namespaces); #endif #ifdef OF_WINDOWS static OFTimeInterval filetimeToTimeInterval(const FILETIME *filetime) { return (double)((int64_t)filetime->dwHighDateTime << 32 | filetime->dwLowDateTime) / 10000000.0 - 11644473600.0; } static FILETIME timeIntervalToFiletime(OFTimeInterval timeInterval) { uint64_t timestamp = (uint64_t)((timeInterval + 11644473600.0) * 10000000.0); FILETIME filetime = { .dwHighDateTime = timestamp >> 32, .dwLowDateTime = timestamp & 0xFFFFFFFF }; return filetime; } static int lastError(void) { switch (GetLastError()) { case ERROR_FILE_NOT_FOUND: case ERROR_PATH_NOT_FOUND: case ERROR_NO_MORE_FILES: return ENOENT; case ERROR_ACCESS_DENIED: return EACCES; case ERROR_PRIVILEGE_NOT_HELD: return EPERM; case ERROR_DIRECTORY: return ENOTDIR; case ERROR_NOT_READY: return EBUSY; default: return EIO; } } #endif #ifdef OF_AMIGAOS static int lastError(void) { switch (IoErr()) { case ERROR_DELETE_PROTECTED: case ERROR_READ_PROTECTED: case ERROR_WRITE_PROTECTED: return EACCES; case ERROR_DISK_NOT_VALIDATED: case ERROR_OBJECT_IN_USE: return EBUSY; case ERROR_OBJECT_EXISTS: return EEXIST; case ERROR_DIR_NOT_FOUND: case ERROR_NO_MORE_ENTRIES: case ERROR_OBJECT_NOT_FOUND: return ENOENT; case ERROR_NO_FREE_STORE: return ENOMEM; case ERROR_DISK_FULL: return ENOSPC; case ERROR_DIRECTORY_NOT_EMPTY: return ENOTEMPTY; case ERROR_DISK_WRITE_PROTECTED: return EROFS; case ERROR_RENAME_ACROSS_DEVICES: return EXDEV; default: return EIO; } } #endif static int statWrapper(OFString *path, Stat *buffer) { #if defined(OF_WINDOWS) WIN32_FILE_ATTRIBUTE_DATA data; bool success; if ([OFSystemInfo isWindowsNT]) success = GetFileAttributesExW(path.UTF16String, GetFileExInfoStandard, &data); else success = GetFileAttributesExA( [path cStringWithEncoding: [OFLocale encoding]], GetFileExInfoStandard, &data); if (!success) return lastError(); buffer->st_size = (uint64_t)data.nFileSizeHigh << 32 | data.nFileSizeLow; if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) buffer->st_mode = S_IFDIR; else if (data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) { /* * No need to use A functions in this branch: This is only * available on NTFS (and hence Windows NT) anyway. */ WIN32_FIND_DATAW findData; HANDLE findHandle; if ((findHandle = FindFirstFileW(path.UTF16String, &findData)) == INVALID_HANDLE_VALUE) return lastError(); @try { if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) /* Race? Indicate to try again. */ return EAGAIN; buffer->st_mode = (findData.dwReserved0 == IO_REPARSE_TAG_SYMLINK ? S_IFLNK : S_IFREG); } @finally { FindClose(findHandle); } } else buffer->st_mode = S_IFREG; buffer->st_mode |= (data.dwFileAttributes & FILE_ATTRIBUTE_READONLY ? (S_IRUSR | S_IXUSR) : (S_IRUSR | S_IWUSR | S_IXUSR)); buffer->st_atime = filetimeToTimeInterval(&data.ftLastAccessTime); buffer->st_mtime = filetimeToTimeInterval(&data.ftLastWriteTime); buffer->st_ctime = buffer->st_birthtime = filetimeToTimeInterval(&data.ftCreationTime); buffer->fileAttributes = data.dwFileAttributes; return 0; #elif defined(OF_AMIGAOS) BPTR lock; # ifdef OF_AMIGAOS4 struct ExamineData *ed; # else struct FileInfoBlock fib; # endif OFTimeInterval timeInterval; struct Locale *locale; struct DateStamp *date; if ((lock = Lock([path cStringWithEncoding: [OFLocale encoding]], SHARED_LOCK)) == 0) return lastError(); # if defined(OF_MORPHOS) if (!Examine64(lock, &fib, TAG_DONE)) { # elif defined(OF_AMIGAOS4) if ((ed = ExamineObjectTags(EX_FileLockInput, lock, TAG_END)) == NULL) { # else if (!Examine(lock, &fib)) { # endif int error = lastError(); UnLock(lock); return error; } UnLock(lock); # if defined(OF_MORPHOS) buffer->st_size = fib.fib_Size64; # elif defined(OF_AMIGAOS4) buffer->st_size = ed->FileSize; # else buffer->st_size = fib.fib_Size; # endif # ifdef OF_AMIGAOS4 buffer->st_mode = (EXD_IS_DIRECTORY(ed) ? S_IFDIR : S_IFREG); # else buffer->st_mode = (fib.fib_DirEntryType > 0 ? S_IFDIR : S_IFREG); # endif timeInterval = 252460800; /* 1978-01-01 */ locale = OpenLocale(NULL); /* * FIXME: This does not take DST into account. But unfortunately, there * is no way to figure out if DST was in effect when the file was * modified. */ timeInterval += locale->loc_GMTOffset * 60.0; CloseLocale(locale); # ifdef OF_AMIGAOS4 date = &ed->Date; # else date = &fib.fib_Date; # endif timeInterval += date->ds_Days * 86400.0; timeInterval += date->ds_Minute * 60.0; timeInterval += date->ds_Tick / (OFTimeInterval)TICKS_PER_SECOND; buffer->st_atime = buffer->st_mtime = buffer->st_ctime = timeInterval; # ifdef OF_AMIGAOS4 FreeDosObject(DOS_EXAMINEDATA, ed); # endif return 0; #elif defined(HAVE_STAT64) if (stat64([path cStringWithEncoding: [OFLocale encoding]], buffer) != 0) return errno; return 0; #else if (stat([path cStringWithEncoding: [OFLocale encoding]], buffer) != 0) return errno; return 0; #endif } static int lstatWrapper(OFString *path, Stat *buffer) { #if defined(HAVE_LSTAT) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS) && \ !defined(OF_NINTENDO_3DS) && !defined(OF_WII) # ifdef HAVE_LSTAT64 if (lstat64([path cStringWithEncoding: [OFLocale encoding]], buffer) != 0) return errno; # else if (lstat([path cStringWithEncoding: [OFLocale encoding]], buffer) != 0) return errno; # endif return 0; #else return statWrapper(path, buffer); #endif } #if defined(OF_FREEBSD) || defined(OF_NETBSD) static void parseAttributeName(OFString **name, int *namespace) { size_t pos = [*name rangeOfString: @"."].location; OFString *namespaceName; const char *cNamespace; if (pos == OFNotFound) @throw [OFInvalidArgumentException exception]; namespaceName = [*name substringToIndex: pos]; cNamespace = [namespaceName cStringWithEncoding: [OFLocale encoding]]; *name = [*name substringFromIndex: pos + 1]; # if defined(OF_FREEBSD) for (int i = 0; i < numNamespaces; i++) { if (strcmp(namespaces[i], cNamespace) == 0) { *namespace = i; return; } } @throw [OFInvalidArgumentException exception]; # elif defined(OF_NETBSD) if (extattr_string_to_namespace(cNamespace, namespace) == -1) @throw [OFInvalidArgumentException exception]; # endif } #endif static void setTypeAttribute(OFMutableFileAttributes attributes, Stat *s) { if (S_ISREG(s->st_mode)) [attributes setObject: OFFileTypeRegular forKey: OFFileType]; else if (S_ISDIR(s->st_mode)) [attributes setObject: OFFileTypeDirectory forKey: OFFileType]; #ifdef S_ISLNK else if (S_ISLNK(s->st_mode)) [attributes setObject: OFFileTypeSymbolicLink forKey: OFFileType]; #endif #ifdef S_ISFIFO else if (S_ISFIFO(s->st_mode)) [attributes setObject: OFFileTypeFIFO forKey: OFFileType]; #endif #ifdef S_ISCHR else if (S_ISCHR(s->st_mode)) [attributes setObject: OFFileTypeCharacterSpecial forKey: OFFileType]; #endif #ifdef S_ISBLK else if (S_ISBLK(s->st_mode)) [attributes setObject: OFFileTypeBlockSpecial forKey: OFFileType]; #endif #ifdef S_ISSOCK else if (S_ISSOCK(s->st_mode)) [attributes setObject: OFFileTypeSocket forKey: OFFileType]; #endif else [attributes setObject: OFFileTypeUnknown forKey: OFFileType]; } static void setDateAttributes(OFMutableFileAttributes attributes, Stat *s) { /* FIXME: We could be more precise on some OSes */ [attributes setObject: [OFDate dateWithTimeIntervalSince1970: s->st_atime] forKey: OFFileLastAccessDate]; [attributes setObject: [OFDate dateWithTimeIntervalSince1970: s->st_mtime] forKey: OFFileModificationDate]; [attributes setObject: [OFDate dateWithTimeIntervalSince1970: s->st_ctime] forKey: OFFileStatusChangeDate]; #ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME [attributes setObject: [OFDate dateWithTimeIntervalSince1970: s->st_birthtime] forKey: OFFileCreationDate]; #endif } static void setOwnerAndGroupAttributes(OFMutableFileAttributes attributes, Stat *s) { #ifdef OF_FILE_MANAGER_SUPPORTS_OWNER [attributes setObject: [NSNumber numberWithUnsignedLong: s->st_uid] forKey: OFFileOwnerAccountID]; [attributes setObject: [NSNumber numberWithUnsignedLong: s->st_gid] forKey: OFFileGroupOwnerAccountID]; # ifdef OF_HAVE_THREADS [passwdMutex lock]; @try { # endif OFStringEncoding encoding = [OFLocale encoding]; struct passwd *passwd = getpwuid(s->st_uid); struct group *group_ = getgrgid(s->st_gid); if (passwd != NULL) { OFString *owner = [OFString stringWithCString: passwd->pw_name encoding: encoding]; [attributes setObject: owner forKey: OFFileOwnerAccountName]; } if (group_ != NULL) { OFString *group = [OFString stringWithCString: group_->gr_name encoding: encoding]; [attributes setObject: group forKey: OFFileGroupOwnerAccountName]; } # ifdef OF_HAVE_THREADS } @finally { [passwdMutex unlock]; } # endif #endif } #ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS static void setSymbolicLinkDestinationAttribute(OFMutableFileAttributes attributes, OFIRI *IRI) { OFString *path = IRI.fileSystemRepresentation; # ifdef OF_WINDOWS HANDLE handle; OFString *destination; if (createSymbolicLinkWFuncPtr == NULL) return; if ((handle = CreateFileW(path.UTF16String, 0, (FILE_SHARE_READ | FILE_SHARE_WRITE), NULL, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT, NULL)) == INVALID_HANDLE_VALUE) @throw [OFGetItemAttributesFailedException exceptionWithIRI: IRI errNo: lastError()]; @try { union { char bytes[MAXIMUM_REPARSE_DATA_BUFFER_SIZE]; REPARSE_DATA_BUFFER data; } buffer; DWORD size; wchar_t *tmp; if (!DeviceIoControl(handle, FSCTL_GET_REPARSE_POINT, NULL, 0, buffer.bytes, MAXIMUM_REPARSE_DATA_BUFFER_SIZE, &size, NULL)) @throw [OFGetItemAttributesFailedException exceptionWithIRI: IRI errNo: lastError()]; if (buffer.data.ReparseTag != IO_REPARSE_TAG_SYMLINK) @throw [OFGetItemAttributesFailedException exceptionWithIRI: IRI errNo: lastError()]; # define slrb buffer.data.SymbolicLinkReparseBuffer tmp = slrb.PathBuffer + (slrb.SubstituteNameOffset / sizeof(wchar_t)); destination = [OFString stringWithUTF16String: tmp length: slrb.SubstituteNameLength / sizeof(wchar_t)]; [attributes setObject: OFFileTypeSymbolicLink forKey: OFFileType]; [attributes setObject: destination forKey: OFFileSymbolicLinkDestination]; # undef slrb } @finally { CloseHandle(handle); } # elif defined(OF_HURD) OFStringEncoding encoding = [OFLocale encoding]; int fd; OFMutableData *destinationData; OFString *destination; fd = open([path cStringWithEncoding: encoding], O_RDONLY | O_NOLINK); if (fd == -1) @throw [OFGetItemAttributesFailedException exceptionWithIRI: IRI errNo: errno]; @try { char buffer[512]; ssize_t length; destinationData = [OFMutableData data]; while ((length = read(fd, buffer, 512)) > 0) [destinationData addItems: buffer count: length]; } @finally { close(fd); } destination = [OFString stringWithCString: destinationData.items encoding: encoding length: destinationData.count]; [attributes setObject: destination forKey: OFFileSymbolicLinkDestination]; # else OFStringEncoding encoding = [OFLocale encoding]; char destinationC[PATH_MAX]; ssize_t length; OFString *destination; length = readlink([path cStringWithEncoding: encoding], destinationC, PATH_MAX); if (length < 0) @throw [OFGetItemAttributesFailedException exceptionWithIRI: IRI errNo: errno]; destination = [OFString stringWithCString: destinationC encoding: encoding length: length]; [attributes setObject: destination forKey: OFFileSymbolicLinkDestination]; # endif } #endif #ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES static void setExtendedAttributes(OFMutableFileAttributes attributes, OFIRI *IRI) { OFString *path = IRI.fileSystemRepresentation; OFStringEncoding encoding = [OFLocale encoding]; const char *cPath = [path cStringWithEncoding: encoding]; OFMutableArray *names = nil; # if defined(OF_LINUX) || defined(OF_MACOS) # if defined(OF_LINUX) ssize_t size = llistxattr(cPath, NULL, 0); # elif defined(OF_MACOS) ssize_t size = listxattr(cPath, NULL, 0, XATTR_NOFOLLOW); # endif char *list; if (size < 0) return; list = OFAllocMemory(1, size); @try { char *name; # if defined(OF_LINUX) if ((size = llistxattr(cPath, list, size)) < 0) # elif defined(OF_MACOS) if ((size = listxattr(cPath, list, size, XATTR_NOFOLLOW)) < 0) # endif return; names = [OFMutableArray array]; name = list; while (size > 0) { size_t length = strlen(name); [names addObject: [OFString stringWithCString: name encoding: encoding length: length]]; name += length + 1; size -= length + 1; } } @finally { OFFreeMemory(list); } # elif defined(OF_FREEBSD) || defined(OF_NETBSD) names = [OFMutableArray array]; # if defined(OF_FREEBSD) for (int i = 0; i < numNamespaces; i++) { int namespace = i; const char *cNamespace = namespaces[i]; # elif defined(OF_NETBSD) for (size_t i = 0; extattr_namespaces[i] != 0; i++) { int namespace = extattr_namespaces[i]; char *cNamespace; # endif ssize_t size; char *list; if ((size = extattr_list_link(cPath, namespace, NULL, 0)) < 0) continue; list = OFAllocMemory(1, size); @try { OFString *namespaceName; char *iter; if ((size = extattr_list_link(cPath, namespace, list, size)) < 0) continue; # ifdef OF_NETBSD if (extattr_namespace_to_string(namespace, &cNamespace) == -1) continue; # endif namespaceName = [OFString stringWithCString: cNamespace encoding: encoding]; iter = list; while (size > 0) { ssize_t length = *(unsigned char *)iter; OFString *name; iter++; size--; if (length > size) @throw [OFOutOfRangeException exception]; name = [OFString stringWithCString: iter encoding: encoding length: length]; name = [OFString stringWithFormat: @"%@.%@", namespaceName, name]; [names addObject: name]; iter += length; size -= length; } } @finally { OFFreeMemory(list); } } # elif defined(OF_HAIKU) DIR *dir = fs_open_attr_dir(cPath); if (dir == NULL) return; @try { struct dirent *dirent; names = [OFMutableArray array]; while ((dirent = fs_read_attr_dir(dir)) != NULL) [names addObject: [OFString stringWithCString: dirent->d_name encoding: encoding]]; } @finally { fs_close_attr_dir(dir); } # endif [names makeImmutable]; [attributes setObject: names forKey: OFFileExtendedAttributesNames]; } #endif @implementation OFFileIRIHandler + (void)initialize { #ifdef OF_WINDOWS HMODULE module; #endif if (self != [OFFileIRIHandler class]) return; #if defined(OF_FILE_MANAGER_SUPPORTS_OWNER) && defined(OF_HAVE_THREADS) passwdMutex = [[OFMutex alloc] init]; atexit(releasePasswdMutex); #endif #if defined(OF_HAVE_THREADS) && !defined(__GLIBC__) && !defined(OF_WINDOWS) readdirMutex = [[OFMutex alloc] init]; atexit(releaseReaddirMutex); #endif #ifdef OF_WINDOWS if ((module = GetModuleHandleA("kernel32.dll")) != NULL) { createSymbolicLinkWFuncPtr = (WINAPI BOOLEAN (*)(LPCWSTR, LPCWSTR, DWORD)) GetProcAddress(module, "CreateSymbolicLinkW"); createHardLinkWFuncPtr = (WINAPI BOOLEAN (*)(LPCWSTR, LPCWSTR, LPSECURITY_ATTRIBUTES)) GetProcAddress(module, "CreateHardLinkW"); } #endif /* * Make sure OFFile is initialized. * On some systems, this is needed to initialize the file system driver. */ [OFFile class]; } + (bool)of_directoryExistsAtPath: (OFString *)path { Stat s; if (statWrapper(path, &s) != 0) return false; return S_ISDIR(s.st_mode); } - (OFStream *)openItemAtIRI: (OFIRI *)IRI mode: (OFString *)mode { void *pool = objc_autoreleasePoolPush(); OFFile *file; @try { file = [OFFile fileWithPath: IRI.fileSystemRepresentation mode: mode]; } @catch (OFOpenItemFailedException *e) { /* The thrown one has a path instead of an IRI set. */ @throw [OFOpenItemFailedException exceptionWithIRI: IRI mode: mode errNo: e.errNo]; } [file retain]; objc_autoreleasePoolPop(pool); return [file autorelease]; } - (OFFileAttributes)attributesOfItemAtIRI: (OFIRI *)IRI { OFMutableFileAttributes ret = [OFMutableDictionary dictionary]; void *pool = objc_autoreleasePoolPush(); OFString *path; int error; Stat s; if (IRI == nil) @throw [OFInvalidArgumentException exception]; if (![[IRI scheme] isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; path = IRI.fileSystemRepresentation; if ((error = lstatWrapper(path, &s)) != 0) @throw [OFGetItemAttributesFailedException exceptionWithIRI: IRI errNo: error]; if (s.st_size < 0) @throw [OFOutOfRangeException exception]; [ret setObject: [NSNumber numberWithUnsignedLongLong: s.st_size] forKey: OFFileSize]; setTypeAttribute(ret, &s); [ret setObject: [NSNumber numberWithUnsignedLong: s.st_mode] forKey: OFFilePOSIXPermissions]; setOwnerAndGroupAttributes(ret, &s); setDateAttributes(ret, &s); #ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS if (S_ISLNK(s.st_mode)) setSymbolicLinkDestinationAttribute(ret, IRI); #endif #ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES setExtendedAttributes(ret, IRI); #endif objc_autoreleasePoolPop(pool); return ret; } - (void)of_setLastAccessDate: (OFDate *)lastAccessDate andModificationDate: (OFDate *)modificationDate ofItemAtIRI: (OFIRI *)IRI attributes: (OFFileAttributes)attributes OF_DIRECT { OFString *path = IRI.fileSystemRepresentation; OFFileAttributeKey attributeKey = (modificationDate != nil ? OFFileModificationDate : OFFileLastAccessDate); if (lastAccessDate == nil) lastAccessDate = modificationDate; if (modificationDate == nil) modificationDate = lastAccessDate; #if defined(OF_WINDOWS) FILETIME accessTime = timeIntervalToFiletime( lastAccessDate.timeIntervalSince1970); FILETIME modificationTime = timeIntervalToFiletime( modificationDate.timeIntervalSince1970); HANDLE handle; if ([OFSystemInfo isWindowsNT]) handle = CreateFileW(path.UTF16String, FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); else handle = CreateFileA( [path cStringWithEncoding: [OFLocale encoding]], FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (handle == NULL) @throw [OFSetItemAttributesFailedException exceptionWithIRI: IRI attributes: attributes failedAttribute: attributeKey errNo: lastError()]; if (!SetFileTime(handle, NULL, &accessTime, &modificationTime)) { int errNo = lastError(); CloseHandle(handle); @throw [OFSetItemAttributesFailedException exceptionWithIRI: IRI attributes: attributes failedAttribute: attributeKey errNo: errNo]; } CloseHandle(handle); #elif defined(OF_AMIGAOS) /* AmigaOS does not support access time. */ OFTimeInterval modificationTime = modificationDate.timeIntervalSince1970; struct Locale *locale; struct DateStamp date; modificationTime -= 252460800; /* 1978-01-01 */ if (modificationTime < 0) @throw [OFOutOfRangeException exception]; locale = OpenLocale(NULL); /* * FIXME: This does not take DST into account. But unfortunately, there * is no way to figure out if DST should be in effect for the * timestamp. */ modificationTime -= locale->loc_GMTOffset * 60.0; CloseLocale(locale); date.ds_Days = modificationTime / 86400; date.ds_Minute = ((LONG)modificationTime % 86400) / 60; date.ds_Tick = fmod(modificationTime, 60) * TICKS_PER_SECOND; # ifdef OF_AMIGAOS4 if (!SetDate([path cStringWithEncoding: [OFLocale encoding]], &date) != 0) # else if (!SetFileDate([path cStringWithEncoding: [OFLocale encoding]], &date) != 0) # endif @throw [OFSetItemAttributesFailedException exceptionWithIRI: IRI attributes: attributes failedAttribute: attributeKey errNo: lastError()]; #else OFTimeInterval lastAccessTime = lastAccessDate.timeIntervalSince1970; OFTimeInterval modificationTime = modificationDate.timeIntervalSince1970; struct timeval times[2] = { { .tv_sec = (time_t)lastAccessTime, .tv_usec = (int)((lastAccessTime - (time_t)lastAccessTime) * 1000000) }, { .tv_sec = (time_t)modificationTime, .tv_usec = (int)((modificationTime - (time_t)modificationTime) * 1000000) }, }; if (utimes([path cStringWithEncoding: [OFLocale encoding]], times) != 0) @throw [OFSetItemAttributesFailedException exceptionWithIRI: IRI attributes: attributes failedAttribute: attributeKey errNo: errno]; #endif } - (void)of_setPOSIXPermissions: (OFNumber *)permissions ofItemAtIRI: (OFIRI *)IRI attributes: (OFFileAttributes)attributes OF_DIRECT { #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS mode_t mode = (mode_t)permissions.unsignedLongValue; OFString *path = IRI.fileSystemRepresentation; int status; # ifdef OF_WINDOWS if ([OFSystemInfo isWindowsNT]) status = _wchmod(path.UTF16String, mode); else # endif status = chmod( [path cStringWithEncoding: [OFLocale encoding]], mode); if (status != 0) @throw [OFSetItemAttributesFailedException exceptionWithIRI: IRI attributes: attributes failedAttribute: OFFilePOSIXPermissions errNo: errno]; #else OF_UNRECOGNIZED_SELECTOR #endif } - (void)of_setOwnerAccountName: (OFString *)owner andGroupOwnerAccountName: (OFString *)group ofItemAtIRI: (OFIRI *)IRI attributeKey: (OFFileAttributeKey)attributeKey attributes: (OFFileAttributes)attributes OF_DIRECT { #ifdef OF_FILE_MANAGER_SUPPORTS_OWNER OFString *path = IRI.fileSystemRepresentation; uid_t uid = -1; gid_t gid = -1; OFStringEncoding encoding; if (owner == nil && group == nil) @throw [OFInvalidArgumentException exception]; encoding = [OFLocale encoding]; # ifdef OF_HAVE_THREADS [passwdMutex lock]; @try { # endif if (owner != nil) { struct passwd *passwd; if ((passwd = getpwnam([owner cStringWithEncoding: encoding])) == NULL) @throw [OFSetItemAttributesFailedException exceptionWithIRI: IRI attributes: attributes failedAttribute: attributeKey errNo: errno]; uid = passwd->pw_uid; } if (group != nil) { struct group *group_; if ((group_ = getgrnam([group cStringWithEncoding: encoding])) == NULL) @throw [OFSetItemAttributesFailedException exceptionWithIRI: IRI attributes: attributes failedAttribute: attributeKey errNo: errno]; gid = group_->gr_gid; } # ifdef OF_HAVE_THREADS } @finally { [passwdMutex unlock]; } # endif if (chown([path cStringWithEncoding: encoding], uid, gid) != 0) @throw [OFSetItemAttributesFailedException exceptionWithIRI: IRI attributes: attributes failedAttribute: attributeKey errNo: errno]; #else OF_UNRECOGNIZED_SELECTOR #endif } - (void)setAttributes: (OFFileAttributes)attributes ofItemAtIRI: (OFIRI *)IRI { void *pool = objc_autoreleasePoolPush(); OFEnumerator OF_GENERIC(OFFileAttributeKey) *keyEnumerator; OFEnumerator *objectEnumerator; OFFileAttributeKey key; id object; OFDate *lastAccessDate, *modificationDate; if (IRI == nil) @throw [OFInvalidArgumentException exception]; if (![IRI.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; keyEnumerator = [attributes keyEnumerator]; objectEnumerator = [attributes objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { if ([key isEqual: OFFileModificationDate] || [key isEqual: OFFileLastAccessDate]) continue; else if ([key isEqual: OFFilePOSIXPermissions]) [self of_setPOSIXPermissions: object ofItemAtIRI: IRI attributes: attributes]; else if ([key isEqual: OFFileOwnerAccountName]) [self of_setOwnerAccountName: object andGroupOwnerAccountName: nil ofItemAtIRI: IRI attributeKey: key attributes: attributes]; else if ([key isEqual: OFFileGroupOwnerAccountName]) [self of_setOwnerAccountName: nil andGroupOwnerAccountName: object ofItemAtIRI: IRI attributeKey: key attributes: attributes]; else @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; } lastAccessDate = [attributes objectForKey: OFFileLastAccessDate]; modificationDate = [attributes objectForKey: OFFileModificationDate]; if (lastAccessDate != nil || modificationDate != nil) [self of_setLastAccessDate: lastAccessDate andModificationDate: modificationDate ofItemAtIRI: IRI attributes: attributes]; objc_autoreleasePoolPop(pool); } - (bool)fileExistsAtIRI: (OFIRI *)IRI { void *pool = objc_autoreleasePoolPush(); Stat s; bool ret; if (IRI == nil) @throw [OFInvalidArgumentException exception]; if (![IRI.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; ret = (statWrapper(IRI.fileSystemRepresentation, &s) == 0); objc_autoreleasePoolPop(pool); return ret; } - (bool)directoryExistsAtIRI: (OFIRI *)IRI { void *pool = objc_autoreleasePoolPush(); Stat s; bool ret; if (IRI == nil) @throw [OFInvalidArgumentException exception]; if (![IRI.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; if (statWrapper(IRI.fileSystemRepresentation, &s) != 0) { objc_autoreleasePoolPop(pool); return false; } ret = S_ISDIR(s.st_mode); objc_autoreleasePoolPop(pool); return ret; } - (void)createDirectoryAtIRI: (OFIRI *)IRI { void *pool = objc_autoreleasePoolPush(); OFString *path; if (IRI == nil) @throw [OFInvalidArgumentException exception]; if (![IRI.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; path = IRI.fileSystemRepresentation; #if defined(OF_WINDOWS) int status; if ([OFSystemInfo isWindowsNT]) status = _wmkdir(path.UTF16String); else status = _mkdir( [path cStringWithEncoding: [OFLocale encoding]]); if (status != 0) @throw [OFCreateDirectoryFailedException exceptionWithIRI: IRI errNo: errno]; #elif defined(OF_AMIGAOS) BPTR lock; if ((lock = CreateDir( [path cStringWithEncoding: [OFLocale encoding]])) == 0) @throw [OFCreateDirectoryFailedException exceptionWithIRI: IRI errNo: lastError()]; UnLock(lock); #else if (mkdir([path cStringWithEncoding: [OFLocale encoding]], 0777) != 0) @throw [OFCreateDirectoryFailedException exceptionWithIRI: IRI errNo: errno]; #endif objc_autoreleasePoolPop(pool); } - (OFArray OF_GENERIC(OFIRI *) *)contentsOfDirectoryAtIRI: (OFIRI *)IRI { OFMutableArray *IRIs = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); OFString *path; if (IRI == nil) @throw [OFInvalidArgumentException exception]; if (![IRI.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; path = IRI.fileSystemRepresentation; #if defined(OF_WINDOWS) HANDLE handle; path = [path stringByAppendingString: @"\\*"]; if ([OFSystemInfo isWindowsNT]) { WIN32_FIND_DATAW fd; if ((handle = FindFirstFileW(path.UTF16String, &fd)) == INVALID_HANDLE_VALUE) @throw [OFOpenItemFailedException exceptionWithIRI: IRI mode: nil errNo: lastError()]; @try { do { OFString *file; if (wcscmp(fd.cFileName, L".") == 0 || wcscmp(fd.cFileName, L"..") == 0) continue; file = [[OFString alloc] initWithUTF16String: fd.cFileName]; @try { [IRIs addObject: [IRI IRIByAppendingPathComponent: file]]; } @finally { [file release]; } } while (FindNextFileW(handle, &fd)); if (GetLastError() != ERROR_NO_MORE_FILES) @throw [OFReadFailedException exceptionWithObject: self requestedLength: 0 errNo: lastError()]; } @finally { FindClose(handle); } } else { OFStringEncoding encoding = [OFLocale encoding]; WIN32_FIND_DATA fd; if ((handle = FindFirstFileA( [path cStringWithEncoding: encoding], &fd)) == INVALID_HANDLE_VALUE) @throw [OFOpenItemFailedException exceptionWithIRI: IRI mode: nil errNo: lastError()]; @try { do { OFString *file; if (strcmp(fd.cFileName, ".") == 0 || strcmp(fd.cFileName, "..") == 0) continue; file = [[OFString alloc] initWithCString: fd.cFileName encoding: encoding]; @try { [IRIs addObject: [IRI IRIByAppendingPathComponent: file]]; } @finally { [file release]; } } while (FindNextFileA(handle, &fd)); if (GetLastError() != ERROR_NO_MORE_FILES) @throw [OFReadFailedException exceptionWithObject: self requestedLength: 0 errNo: lastError()]; } @finally { FindClose(handle); } } #elif defined(OF_AMIGAOS) OFStringEncoding encoding = [OFLocale encoding]; BPTR lock; if ((lock = Lock([path cStringWithEncoding: encoding], SHARED_LOCK)) == 0) @throw [OFOpenItemFailedException exceptionWithIRI: IRI mode: nil errNo: lastError()]; @try { # ifdef OF_AMIGAOS4 struct ExamineData *ed; APTR context; if ((context = ObtainDirContextTags(EX_FileLockInput, lock, EX_DoCurrentDir, TRUE, EX_DataFields, EXF_NAME, TAG_END)) == NULL) @throw [OFOpenItemFailedException exceptionWithIRI: IRI mode: nil errNo: lastError()]; @try { while ((ed = ExamineDir(context)) != NULL) { OFString *file = [[OFString alloc] initWithCString: ed->Name encoding: encoding]; @try { [IRIs addObject: [IRI IRIByAppendingPathComponent: file]]; } @finally { [file release]; } } } @finally { ReleaseDirContext(context); } # else struct FileInfoBlock fib; if (!Examine(lock, &fib)) @throw [OFOpenItemFailedException exceptionWithIRI: IRI mode: nil errNo: lastError()]; while (ExNext(lock, &fib)) { OFString *file = [[OFString alloc] initWithCString: fib.fib_FileName encoding: encoding]; @try { [IRIs addObject: [IRI IRIByAppendingPathComponent: file]]; } @finally { [file release]; } } # endif if (IoErr() != ERROR_NO_MORE_ENTRIES) @throw [OFReadFailedException exceptionWithObject: self requestedLength: 0 errNo: lastError()]; } @finally { UnLock(lock); } #else OFStringEncoding encoding = [OFLocale encoding]; DIR *dir; if ((dir = opendir([path cStringWithEncoding: encoding])) == NULL) @throw [OFOpenItemFailedException exceptionWithIRI: IRI mode: nil errNo: errno]; # if defined(OF_HAVE_THREADS) && !defined(__GLIBC__) @try { [readdirMutex lock]; } @catch (id e) { closedir(dir); @throw e; } # endif @try { for (;;) { struct dirent *dirent; OFString *file; errno = 0; if ((dirent = readdir(dir)) == NULL) { if (errno == 0) break; else @throw [OFReadFailedException exceptionWithObject: self requestedLength: 0 errNo: errno]; } if (strcmp(dirent->d_name, ".") == 0 || strcmp(dirent->d_name, "..") == 0) continue; file = [[OFString alloc] initWithCString: dirent->d_name encoding: encoding]; @try { [IRIs addObject: [IRI IRIByAppendingPathComponent: file]]; } @finally { [file release]; } } } @finally { closedir(dir); # if defined(OF_HAVE_THREADS) && !defined(__GLIBC__) [readdirMutex unlock]; # endif } #endif [IRIs makeImmutable]; objc_autoreleasePoolPop(pool); return IRIs; } - (void)removeItemAtIRI: (OFIRI *)IRI { void *pool = objc_autoreleasePoolPush(); OFString *path; int error; Stat s; if (IRI == nil) @throw [OFInvalidArgumentException exception]; if (![IRI.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; path = IRI.fileSystemRepresentation; if ((error = lstatWrapper(path, &s)) != 0) @throw [OFRemoveItemFailedException exceptionWithIRI: IRI errNo: error]; if (S_ISDIR(s.st_mode)) { OFArray OF_GENERIC(OFIRI *) *contents; @try { contents = [self contentsOfDirectoryAtIRI: IRI]; } @catch (id e) { /* * Only convert exceptions to * OFRemoveItemFailedException that have an errNo * property. This covers all I/O related exceptions * from the operations used to remove an item, all * others should be left as is. */ if ([e respondsToSelector: @selector(errNo)]) @throw [OFRemoveItemFailedException exceptionWithIRI: IRI errNo: [e errNo]]; @throw e; } for (OFIRI *item in contents) { void *pool2 = objc_autoreleasePoolPush(); [self removeItemAtIRI: item]; objc_autoreleasePoolPop(pool2); } #ifndef OF_AMIGAOS int status; # ifdef OF_WINDOWS if ([OFSystemInfo isWindowsNT]) status = _wrmdir(path.UTF16String); else # endif status = rmdir( [path cStringWithEncoding: [OFLocale encoding]]); if (status != 0) @throw [OFRemoveItemFailedException exceptionWithIRI: IRI errNo: errno]; } else { int status; # ifdef OF_WINDOWS if ([OFSystemInfo isWindowsNT]) status = _wunlink(path.UTF16String); else # endif status = unlink( [path cStringWithEncoding: [OFLocale encoding]]); if (status != 0) @throw [OFRemoveItemFailedException exceptionWithIRI: IRI errNo: errno]; #endif } #ifdef OF_AMIGAOS if (!DeleteFile([path cStringWithEncoding: [OFLocale encoding]])) @throw [OFRemoveItemFailedException exceptionWithIRI: IRI errNo: lastError()]; #endif objc_autoreleasePoolPop(pool); } #ifdef OF_FILE_MANAGER_SUPPORTS_LINKS - (void)linkItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination { void *pool = objc_autoreleasePoolPush(); OFString *sourcePath, *destinationPath; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; if (![source.scheme isEqual: _scheme] || ![destination.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; sourcePath = source.fileSystemRepresentation; destinationPath = destination.fileSystemRepresentation; # ifndef OF_WINDOWS OFStringEncoding encoding = [OFLocale encoding]; if (link([sourcePath cStringWithEncoding: encoding], [destinationPath cStringWithEncoding: encoding]) != 0) @throw [OFLinkItemFailedException exceptionWithSourceIRI: source destinationIRI: destination errNo: errno]; # else if (createHardLinkWFuncPtr == NULL) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; if (!createHardLinkWFuncPtr(destinationPath.UTF16String, sourcePath.UTF16String, NULL)) @throw [OFLinkItemFailedException exceptionWithSourceIRI: source destinationIRI: destination errNo: lastError()]; # endif objc_autoreleasePoolPop(pool); } #endif #ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS - (void)createSymbolicLinkAtIRI: (OFIRI *)IRI withDestinationPath: (OFString *)target { void *pool = objc_autoreleasePoolPush(); OFString *path; if (IRI == nil || target == nil) @throw [OFInvalidArgumentException exception]; if (![IRI.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; path = IRI.fileSystemRepresentation; # ifndef OF_WINDOWS OFStringEncoding encoding = [OFLocale encoding]; if (symlink([target cStringWithEncoding: encoding], [path cStringWithEncoding: encoding]) != 0) @throw [OFCreateSymbolicLinkFailedException exceptionWithIRI: IRI target: target errNo: errno]; # else if (createSymbolicLinkWFuncPtr == NULL) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; if (!createSymbolicLinkWFuncPtr(path.UTF16String, target.UTF16String, 0)) @throw [OFCreateSymbolicLinkFailedException exceptionWithIRI: IRI target: target errNo: lastError()]; # endif objc_autoreleasePoolPop(pool); } #endif - (bool)moveItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination { void *pool; if (![source.scheme isEqual: _scheme] || ![destination.scheme isEqual: _scheme]) return false; if ([self fileExistsAtIRI: destination]) @throw [OFMoveItemFailedException exceptionWithSourceIRI: source destinationIRI: destination errNo: EEXIST]; pool = objc_autoreleasePoolPush(); #ifdef OF_AMIGAOS OFStringEncoding encoding = [OFLocale encoding]; if (!Rename([source.fileSystemRepresentation cStringWithEncoding: encoding], [destination.fileSystemRepresentation cStringWithEncoding: encoding])) @throw [OFMoveItemFailedException exceptionWithSourceIRI: source destinationIRI: destination errNo: lastError()]; #else int status; # ifdef OF_WINDOWS if ([OFSystemInfo isWindowsNT]) status = _wrename(source.fileSystemRepresentation.UTF16String, destination.fileSystemRepresentation.UTF16String); else { # endif OFStringEncoding encoding = [OFLocale encoding]; status = rename([source.fileSystemRepresentation cStringWithEncoding: encoding], [destination.fileSystemRepresentation cStringWithEncoding: encoding]); # ifdef OF_WINDOWS } # endif if (status != 0) @throw [OFMoveItemFailedException exceptionWithSourceIRI: source destinationIRI: destination errNo: errno]; #endif objc_autoreleasePoolPop(pool); return true; } #ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES - (void)getExtendedAttributeData: (OFData **)data andType: (id *)type forName: (OFString *)name ofItemAtIRI: (OFIRI *)IRI { void *pool = objc_autoreleasePoolPush(); OFString *path = IRI.fileSystemRepresentation; OFStringEncoding encoding = [OFLocale encoding]; const char *cPath = [path cStringWithEncoding: encoding]; void *value = NULL; # if defined(OF_LINUX) || defined(OF_MACOS) const char *cName = [name cStringWithEncoding: encoding]; # if defined(OF_LINUX) ssize_t size = lgetxattr(cPath, cName, NULL, 0); # elif defined(OF_MACOS) ssize_t size = getxattr(cPath, cName, NULL, 0, 0, XATTR_NOFOLLOW); # endif if (size < 0) @throw [OFGetItemAttributesFailedException exceptionWithIRI: IRI errNo: errno]; value = OFAllocMemory(1, size); @try { # if defined(OF_LINUX) if ((size = lgetxattr(cPath, cName, value, size)) < 0) # elif defined(OF_MACOS) if ((size = getxattr(cPath, cName, value, size, 0, XATTR_NOFOLLOW)) < 0) # endif @throw [OFGetItemAttributesFailedException exceptionWithIRI: IRI errNo: errno]; *data = [OFData dataWithItemsNoCopy: value count: size freeWhenDone: true]; value = NULL; } @finally { OFFreeMemory(value); } if (type != NULL) *type = nil; # elif defined(OF_FREEBSD) || defined(OF_NETBSD) int namespace; const char *cName; ssize_t size; parseAttributeName(&name, &namespace); cName = [name cStringWithEncoding: encoding]; if ((size = extattr_get_link(cPath, namespace, cName, NULL, 0)) < 0) @throw [OFGetItemAttributesFailedException exceptionWithIRI: IRI errNo: errno]; value = OFAllocMemory(1, size); @try { if ((size = extattr_get_link(cPath, namespace, cName, value, size)) < 0) @throw [OFGetItemAttributesFailedException exceptionWithIRI: IRI errNo: errno]; *data = [OFData dataWithItemsNoCopy: value count: size freeWhenDone: true]; value = NULL; } @finally { OFFreeMemory(value); } if (type != NULL) *type = nil; # elif defined(OF_HAIKU) const char *cName = [name cStringWithEncoding: encoding]; int fd = open(cPath, O_RDONLY); struct attr_info info; if (fd == -1) @throw [OFGetItemAttributesFailedException exceptionWithIRI: IRI errNo: errno]; @try { if (fs_stat_attr(fd, cName, &info) != 0) @throw [OFGetItemAttributesFailedException exceptionWithIRI: IRI errNo: errno]; if (info.size < 0 || info.size > SSIZE_MAX) @throw [OFOutOfRangeException exception]; value = OFAllocMemory(1, (size_t)info.size); errno = 0; if (fs_read_attr(fd, cName, B_ANY_TYPE, 0, value, (size_t)info.size) != (ssize_t)info.size) @throw [OFGetItemAttributesFailedException exceptionWithIRI: IRI errNo: errno]; *data = [OFData dataWithItemsNoCopy: value count: (size_t)info.size freeWhenDone: true]; value = NULL; if (type != NULL) *type = [OFNumber numberWithUnsignedLong: info.type]; } @finally { OFFreeMemory(value); close(fd); } # endif [*data retain]; if (type != NULL) [*type retain]; objc_autoreleasePoolPop(pool); [*data autorelease]; if (type != NULL) [*type autorelease]; } - (void)setExtendedAttributeData: (OFData *)data andType: (id)type forName: (OFString *)name ofItemAtIRI: (OFIRI *)IRI { void *pool = objc_autoreleasePoolPush(); OFString *path = IRI.fileSystemRepresentation; OFStringEncoding encoding = [OFLocale encoding]; const char *cPath = [path cStringWithEncoding: encoding]; size_t size = data.count * data.itemSize; # if defined(OF_LINUX) || defined(OF_MACOS) const char *cName = [name cStringWithEncoding: encoding]; if (type != nil) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; # if defined(OF_LINUX) if (lsetxattr(cPath, cName, data.items, size, 0) != 0) { # elif defined(OF_MACOS) if (setxattr(cPath, cName, data.items, size, 0, XATTR_NOFOLLOW) != 0) { # endif int errNo = errno; /* TODO: Add an attribute (prefix?) for extended attributes? */ @throw [OFSetItemAttributesFailedException exceptionWithIRI: IRI attributes: [OFDictionary dictionary] failedAttribute: @"" errNo: errNo]; } # elif defined(OF_FREEBSD) || defined(OF_NETBSD) int namespace; const char *cName; if (size > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if (type != nil) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; parseAttributeName(&name, &namespace); cName = [name cStringWithEncoding: encoding]; if (extattr_set_link(cPath, namespace, cName, data.items, size) != (ssize_t)size) { int errNo = errno; /* TODO: Add an attribute (prefix?) for extended attributes? */ @throw [OFSetItemAttributesFailedException exceptionWithIRI: IRI attributes: [OFDictionary dictionary] failedAttribute: @"" errNo: errNo]; } # elif defined(OF_HAIKU) const char *cName = [name cStringWithEncoding: encoding]; unsigned long long typeInt; int fd; if (type != nil && ![type isKindOfClass: [OFNumber class]]) @throw [OFInvalidArgumentException exception]; typeInt = (type != nil ? [type unsignedLongLongValue] : 0); if (typeInt > UINT32_MAX) @throw [OFInvalidArgumentException exception]; if (size > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if ((fd = open(cPath, O_WRONLY)) == -1) { int errNo = errno; /* TODO: Add an attribute (prefix?) for extended attributes? */ @throw [OFSetItemAttributesFailedException exceptionWithIRI: IRI attributes: [OFDictionary dictionary] failedAttribute: @"" errNo: errNo]; } @try { if (fs_write_attr(fd, cName, (uint32_t)typeInt, 0, data.items, size) != (ssize_t)size) { int errNo = errno; /* * TODO: Add an attribute (prefix?) for extended * attributes? */ @throw [OFSetItemAttributesFailedException exceptionWithIRI: IRI attributes: [OFDictionary dictionary] failedAttribute: @"" errNo: errNo]; } } @finally { close(fd); } # endif objc_autoreleasePoolPop(pool); } - (void)removeExtendedAttributeForName: (OFString *)name ofItemAtIRI: (OFIRI *)IRI { void *pool = objc_autoreleasePoolPush(); OFString *path = IRI.fileSystemRepresentation; OFStringEncoding encoding = [OFLocale encoding]; const char *cPath = [path cStringWithEncoding: encoding]; # if defined(OF_LINUX) || defined(OF_MACOS) const char *cName = [name cStringWithEncoding: encoding]; # if defined(OF_LINUX) if (lremovexattr(cPath, cName) != 0) { # elif defined(OF_MACOS) if (removexattr(cPath, cName, XATTR_NOFOLLOW) != 0) { # endif int errNo = errno; /* TODO: Add an attribute (prefix?) for extended attributes? */ @throw [OFSetItemAttributesFailedException exceptionWithIRI: IRI attributes: [OFDictionary dictionary] failedAttribute: @"" errNo: errNo]; } # elif defined(OF_FREEBSD) || defined(OF_NETBSD) int namespace; const char *cName; parseAttributeName(&name, &namespace); cName = [name cStringWithEncoding: encoding]; if (extattr_delete_link(cPath, namespace, cName) != 0) { int errNo = errno; /* TODO: Add an attribute (prefix?) for extended attributes? */ @throw [OFSetItemAttributesFailedException exceptionWithIRI: IRI attributes: [OFDictionary dictionary] failedAttribute: @"" errNo: errNo]; } # elif defined(OF_HAIKU) const char *cName = [name cStringWithEncoding: encoding]; int fd; if ((fd = open(cPath, O_WRONLY)) == -1) { int errNo = errno; /* TODO: Add an attribute (prefix?) for extended attributes? */ @throw [OFSetItemAttributesFailedException exceptionWithIRI: IRI attributes: [OFDictionary dictionary] failedAttribute: @"" errNo: errNo]; } @try { if (fs_remove_attr(fd, cName) != 0) { int errNo = errno; /* * TODO: Add an attribute (prefix?) for extended * attributes? */ @throw [OFSetItemAttributesFailedException exceptionWithIRI: IRI attributes: [OFDictionary dictionary] failedAttribute: @"" errNo: errNo]; } } @finally { close(fd); } # endif objc_autoreleasePoolPop(pool); } #endif @end objfw-1.1.6/src/OFFileManager.h000066400000000000000000001016561465614216400162070ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFDictionary.h" OF_ASSUME_NONNULL_BEGIN /** @file */ #ifdef OF_HAVE_FILES # if (defined(OF_HAVE_CHMOD) && !defined(OF_AMIGAOS)) || defined(DOXYGEN) # define OF_FILE_MANAGER_SUPPORTS_PERMISSIONS # endif # if (defined(OF_HAVE_CHOWN) && !defined(OF_AMIGAOS)) || defined(DOXYGEN) # define OF_FILE_MANAGER_SUPPORTS_OWNER # endif # if (defined(OF_HAVE_LINK) && !defined(OF_AMIGAOS) && !defined(OF_HAIKU)) || \ defined(OF_WINDOWS) || defined(DOXYGEN) # define OF_FILE_MANAGER_SUPPORTS_LINKS # endif # if (defined(OF_HAVE_SYMLINK) && !defined(OF_AMIGAOS)) || \ defined(OF_WINDOWS) || defined(DOXYGEN) # define OF_FILE_MANAGER_SUPPORTS_SYMLINKS # endif # if defined(OF_LINUX) || defined(OF_MACOS) || defined(OF_FREEBSD) || \ defined(OF_NETBSD) || defined(OF_HAIKU) || defined(DOXYGEN) # define OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES # endif #endif @class OFArray OF_GENERIC(ObjectType); @class OFConstantString; @class OFDate; @class OFIRI; @class OFString; /** * @brief A key for a file attribute in the file attributes dictionary. * * Possible keys for file IRIs are: * * * @ref OFFileSize * * @ref OFFileType * * @ref OFFilePOSIXPermissions * * @ref OFFileOwnerAccountID * * @ref OFFileGroupOwnerAccountID * * @ref OFFileOwnerAccountName * * @ref OFFileGroupOwnerAccountName * * @ref OFFileLastAccessDate * * @ref OFFileModificationDate * * @ref OFFileStatusChangeDate * * @ref OFFileCreationDate * * @ref OFFileSymbolicLinkDestination * * @ref OFFileExtendedAttributesNames * * Other IRI schemes might not have all keys and might have keys not listed. */ typedef OFConstantString *OFFileAttributeKey; /** * @brief The type of a file. * * Possibles values for file IRIs are: * * * @ref OFFileTypeRegular * * @ref OFFileTypeDirectory * * @ref OFFileTypeSymbolicLink * * @ref OFFileTypeFIFO * * @ref OFFileTypeCharacterSpecial * * @ref OFFileTypeBlockSpecial * * @ref OFFileTypeSocket * * @ref OFFileTypeUnknown * * Other IRI schemes might not have all types and might have types not listed. */ typedef OFConstantString *OFFileAttributeType; /** * @brief A dictionary mapping keys of type @ref OFFileAttributeKey to their * attribute values. */ typedef OFDictionary OF_GENERIC(OFFileAttributeKey, id) *OFFileAttributes; /** * @brief A mutable dictionary mapping keys of type @ref OFFileAttributeKey to * their attribute values. */ typedef OFMutableDictionary OF_GENERIC(OFFileAttributeKey, id) *OFMutableFileAttributes; #ifdef __cplusplus extern "C" { #endif /** * @brief The size of the file as an @ref OFNumber. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#fileSize. */ extern const OFFileAttributeKey OFFileSize; /** * @brief The type of the file. * * The corresponding value is of type @ref OFFileAttributeType. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#fileType. */ extern const OFFileAttributeKey OFFileType; /** * @brief The POSIX permissions of the file as an @ref OFNumber. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#filePOSIXPermissions. */ extern const OFFileAttributeKey OFFilePOSIXPermissions; /** * @brief The account ID of the owner of the file as an @ref OFNumber. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#fileOwnerAccountID. */ extern const OFFileAttributeKey OFFileOwnerAccountID; /** * @brief The account ID of the group owner of the file as an @ref OFNumber. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#fileGroupOwnerAccountID. */ extern const OFFileAttributeKey OFFileGroupOwnerAccountID; /** * @brief The account name of the owner of the file as an OFString. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#fileOwnerAccountName. */ extern const OFFileAttributeKey OFFileOwnerAccountName; /** * @brief The account name of the group owner of the file as an OFString. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#fileGroupOwnerAccountName. */ extern const OFFileAttributeKey OFFileGroupOwnerAccountName; /** * @brief The last access date of the file as an @ref OFDate. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#fileLastAccessDate. */ extern const OFFileAttributeKey OFFileLastAccessDate; /** * @brief The last modification date of the file as an @ref OFDate. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#fileModificationDate. */ extern const OFFileAttributeKey OFFileModificationDate; /** * @brief The last status change date of the file as an @ref OFDate. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#fileStatusChangeDate. */ extern const OFFileAttributeKey OFFileStatusChangeDate; /** * @brief The creation date of the file as an @ref OFDate. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#fileCreationDate. */ extern const OFFileAttributeKey OFFileCreationDate; /** * @brief The destination of a symbolic link as an @ref OFString. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#fileSymbolicLinkDestination. */ extern const OFFileAttributeKey OFFileSymbolicLinkDestination; /** * @brief The names of the extended attributes as an @ref OFArray of * @ref OFString. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#fileExtendedAttributesNames. */ extern const OFFileAttributeKey OFFileExtendedAttributesNames; /** * @brief A regular file. */ extern const OFFileAttributeType OFFileTypeRegular; /** * @brief A directory. */ extern const OFFileAttributeType OFFileTypeDirectory; /** * @brief A symbolic link. */ extern const OFFileAttributeType OFFileTypeSymbolicLink; /** * @brief A FIFO. */ extern const OFFileAttributeType OFFileTypeFIFO; /** * @brief A character special file. */ extern const OFFileAttributeType OFFileTypeCharacterSpecial; /** * @brief A block special file. */ extern const OFFileAttributeType OFFileTypeBlockSpecial; /** * @brief A socket. */ extern const OFFileAttributeType OFFileTypeSocket; /** * @brief An unknown file type. * * This is different from not having an @ref OFFileType at all in that it means * that retrieving file types is supported, but the particular file type is * unknown. */ extern const OFFileAttributeType OFFileTypeUnknown; #ifdef __cplusplus } #endif /** * @class OFFileManager OFFileManager.h ObjFW/OFFileManager.h * * @brief A class which provides management for files, e.g. reading contents of * directories, deleting files, renaming files, etc. */ #ifndef OF_FILE_MANAGER_M OF_SUBCLASSING_RESTRICTED #endif @interface OFFileManager: OFObject #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nonatomic) OFFileManager *defaultManager; #endif #ifdef OF_HAVE_FILES /** * @brief The path of the current working directory. * * @throw OFGetCurrentDirectoryFailedException Couldn't get current directory */ @property (readonly, nonatomic) OFString *currentDirectoryPath; /** * @brief The IRI of the current working directory. * * @throw OFGetCurrentDirectoryFailedException Couldn't get current directory */ @property (readonly, nonatomic) OFIRI *currentDirectoryIRI; #endif /** * @brief Returns the default file manager. */ + (OFFileManager *)defaultManager; #ifdef OF_HAVE_FILES /** * @brief Returns the attributes for the item at the specified path. * * @param path The path to return the attributes for * @return A dictionary of attributes for the specified path, with the keys of * type @ref OFFileAttributeKey * @throw OFGetItemAttributesFailedException Failed to get the attributes of * the item */ - (OFFileAttributes)attributesOfItemAtPath: (OFString *)path; #endif /** * @brief Returns the attributes for the item at the specified IRI. * * @param IRI The IRI to return the attributes for * @return A dictionary of attributes for the specified IRI, with the keys of * type @ref OFFileAttributeKey * @throw OFGetItemAttributesFailedException Failed to get the attributes of * the item * @throw OFUnsupportedProtocolException No handler is registered for the IRI's * scheme */ - (OFFileAttributes)attributesOfItemAtIRI: (OFIRI *)IRI; #ifdef OF_HAVE_FILES /** * @brief Sets the attributes for the item at the specified path. * * All attributes not part of the dictionary are left unchanged. * * @param attributes The attributes to set for the specified path * @param path The path of the item to set the attributes for * @throw OFSetItemAttributesFailedException Failed to set the attributes of * the item * @throw OFNotImplementedException Setting one or more of the specified * attributes is not implemented for the * specified item */ - (void)setAttributes: (OFFileAttributes)attributes ofItemAtPath: (OFString *)path; #endif /** * @brief Sets the attributes for the item at the specified IRI. * * All attributes not part of the dictionary are left unchanged. * * @param attributes The attributes to set for the specified IRI * @param IRI The IRI of the item to set the attributes for * @throw OFSetItemAttributesFailedException Failed to set the attributes of * the item * @throw OFUnsupportedProtocolException No handler is registered for the IRI's * scheme * @throw OFNotImplementedException Setting one or more of the specified * attributes is not implemented for the * specified item */ - (void)setAttributes: (OFFileAttributes)attributes ofItemAtIRI: (OFIRI *)IRI; #ifdef OF_HAVE_FILES /** * @brief Checks whether a file exists at the specified path. * * @param path The path to check * @return A boolean whether there is a file at the specified path */ - (bool)fileExistsAtPath: (OFString *)path; #endif /** * @brief Checks whether a file exists at the specified IRI. * * @param IRI The IRI to check * @return A boolean whether there is a file at the specified IRI * @throw OFUnsupportedProtocolException No handler is registered for the IRI's * scheme */ - (bool)fileExistsAtIRI: (OFIRI *)IRI; #ifdef OF_HAVE_FILES /** * @brief Checks whether a directory exists at the specified path. * * @param path The path to check * @return A boolean whether there is a directory at the specified path */ - (bool)directoryExistsAtPath: (OFString *)path; #endif /** * @brief Checks whether a directory exists at the specified IRI. * * @param IRI The IRI to check * @return A boolean whether there is a directory at the specified IRI * @throw OFUnsupportedProtocolException No handler is registered for the IRI's * scheme */ - (bool)directoryExistsAtIRI: (OFIRI *)IRI; #ifdef OF_HAVE_FILES /** * @brief Creates a directory at the specified path. * * @param path The path of the directory to create * @throw OFCreateDirectoryFailedException Creating the directory failed */ - (void)createDirectoryAtPath: (OFString *)path; /** * @brief Creates a directory at the specified path. * * @param path The path of the directory to create * @param createParents Whether to create the parents of the directory * @throw OFCreateDirectoryFailedException Creating the directory or one of its * parents failed */ - (void)createDirectoryAtPath: (OFString *)path createParents: (bool)createParents; #endif /** * @brief Creates a directory at the specified IRI. * * @param IRI The IRI of the directory to create * @throw OFCreateDirectoryFailedException Creating the directory failed * @throw OFUnsupportedProtocolException No handler is registered for the IRI's * scheme */ - (void)createDirectoryAtIRI: (OFIRI *)IRI; /** * @brief Creates a directory at the specified IRI. * * @param IRI The IRI of the directory to create * @param createParents Whether to create the parents of the directory * @throw OFCreateDirectoryFailedException Creating the directory or one of its * parents failed * @throw OFUnsupportedProtocolException No handler is registered for the IRI's * scheme */ - (void)createDirectoryAtIRI: (OFIRI *)IRI createParents: (bool)createParents; #ifdef OF_HAVE_FILES /** * @brief Returns an array with the items in the specified directory. * * @note `.` and `..` are not part of the returned array. * * @param path The path to the directory whose items should be returned * @return An array of OFString with the items in the specified directory * @throw OFOpenItemFailedException Opening the directory failed * @throw OFReadFailedException Reading from the directory failed */ - (OFArray OF_GENERIC(OFString *) *)contentsOfDirectoryAtPath: (OFString *)path; #endif /** * @brief Returns an array with the IRIs of the items in the specified * directory. * * @note `.` and `..` are not part of the returned array. * * @param IRI The IRI to the directory whose items should be returned * @return An array with the IRIs of the items in the specified directory * @throw OFOpenItemFailedException Opening the directory failed * @throw OFReadFailedException Reading from the directory failed * @throw OFUnsupportedProtocolException No handler is registered for the IRI's * scheme */ - (OFArray OF_GENERIC(OFIRI *) *)contentsOfDirectoryAtIRI: (OFIRI *)IRI; #ifdef OF_HAVE_FILES /** * @brief Returns an array with all subpaths of the specified directory. * * @note `.` and `..` (of the directory itself or any subdirectory) are not * part of the returned array. * * @param path The path to the directory whose subpaths should be returned * @return An array of OFString with the subpaths of the specified directory */ - (OFArray OF_GENERIC(OFString *) *)subpathsOfDirectoryAtPath: (OFString *)path; /** * @brief Changes the current working directory. * * @param path The new directory to change to * @throw OFChangeCurrentDirectoryFailedException Changing the current working * directory failed */ - (void)changeCurrentDirectoryPath: (OFString *)path; /** * @brief Changes the current working directory. * * @param IRI The new directory to change to * @throw OFChangeCurrentDirectoryFailedException Changing the current working * directory failed */ - (void)changeCurrentDirectoryIRI: (OFIRI *)IRI; /** * @brief Copies a file, directory or symbolic link (if supported by the OS). * * The destination path must be a full path, which means it must include the * name of the item. * * If an item already exists, the copy operation fails. This is also the case * if a directory is copied and an item already exists in the destination * directory. * * @param source The file, directory or symbolic link to copy * @param destination The destination path * @throw OFCopyItemFailedException Copying failed * @throw OFCreateDirectoryFailedException Creating a destination directory * failed */ - (void)copyItemAtPath: (OFString *)source toPath: (OFString *)destination; #endif /** * @brief Copies a file, directory or symbolic link (if supported by the OS). * * The destination IRI must have a full path, which means it must include the * name of the item. * * If an item already exists, the copy operation fails. This is also the case * if a directory is copied and an item already exists in the destination * directory. * * @param source The file, directory or symbolic link to copy * @param destination The destination IRI * @throw OFCopyItemFailedException Copying failed * @throw OFCreateDirectoryFailedException Creating a destination directory * failed * @throw OFUnsupportedProtocolException No handler is registered for either of * the IRI's scheme */ - (void)copyItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination; #ifdef OF_HAVE_FILES /** * @brief Moves an item. * * The destination path must be a full path, which means it must include the * name of the item. * * If the destination is on a different logical device, the source will be * copied to the destination using @ref copyItemAtPath:toPath: and the source * removed using @ref removeItemAtPath:. * * @param source The item to rename * @param destination The new name for the item * @throw OFMoveItemFailedException Moving failed * @throw OFCopyItemFailedException Copying (to move between different devices) * failed * @throw OFRemoveItemFailedException Removing the source after copying to the * destination (to move between different * devices) failed * @throw OFCreateDirectoryFailedException Creating a destination directory * failed */ - (void)moveItemAtPath: (OFString *)source toPath: (OFString *)destination; #endif /** * @brief Moves an item. * * The destination IRI must have a full path, which means it must include the * name of the item. * * If the destination is on a different logical device or uses a different * scheme, the source will be copied to the destination using * @ref copyItemAtIRI:toIRI: and the source removed using @ref removeItemAtIRI:. * * @param source The item to rename * @param destination The new name for the item * @throw OFMoveItemFailedException Moving failed * @throw OFCopyItemFailedException Copying (to move between different devices) * failed * @throw OFRemoveItemFailedException Removing the source after copying to the * destination (to move between different * devices) failed * @throw OFCreateDirectoryFailedException Creating a destination directory * failed * @throw OFUnsupportedProtocolException No handler is registered for either of * the IRI's scheme */ - (void)moveItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination; #ifdef OF_HAVE_FILES /** * @brief Removes the item at the specified path. * * If the item at the specified path is a directory, it is removed recursively. * * @param path The path to the item which should be removed * @throw OFRemoveItemFailedException Removing the item failed */ - (void)removeItemAtPath: (OFString *)path; #endif /** * @brief Removes the item at the specified IRI. * * If the item at the specified IRI is a directory, it is removed recursively. * * @param IRI The IRI to the item which should be removed * @throw OFRemoveItemFailedException Removing the item failed * @throw OFUnsupportedProtocolException No handler is registered for the IRI's * scheme */ - (void)removeItemAtIRI: (OFIRI *)IRI; #ifdef OF_FILE_MANAGER_SUPPORTS_LINKS /** * @brief Creates a hard link for the specified item. * * The destination path must be a full path, which means it must include the * name of the item. * * This method is not available on some systems. * * @param source The path to the item for which a link should be created * @param destination The path to the item which should link to the source * @throw OFLinkItemFailedException Linking the item failed * @throw OFNotImplementedException Hardlinks are not implemented for the * specified IRI */ - (void)linkItemAtPath: (OFString *)source toPath: (OFString *)destination; #endif /** * @brief Creates a hard link for the specified item. * * The destination IRI must have a full path, which means it must include the * name of the item. * * This method is not available for all IRIs. * * @param source The IRI to the item for which a link should be created * @param destination The IRI to the item which should link to the source * @throw OFLinkItemFailedException Linking the item failed * @throw OFUnsupportedProtocolException No handler is registered for the IRI's * scheme * @throw OFNotImplementedException Hardlinks are not implemented for the * specified IRI */ - (void)linkItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination; #ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS /** * @brief Creates a symbolic link for an item. * * The destination path must be a full path, which means it must include the * name of the item. * * This method is not available on some systems. * * @note On Windows, this requires at least Windows Vista and administrator * privileges! * * @param path The path to the item which should symbolically link to the target * @param target The target of the symbolic link * @throw OFCreateSymbolicLinkFailedException Creating the symbolic link failed * @throw OFNotImplementedException Symbolic links are not implemented for the * specified IRI */ - (void)createSymbolicLinkAtPath: (OFString *)path withDestinationPath: (OFString *)target; #endif /** * @brief Creates a symbolic link for an item. * * The destination IRI must have a full path, which means it must include the * name of the item. * * This method is not available for all IRIs. * * @note For file IRIs on Windows, this requires at least Windows Vista and * administrator privileges! * * @param IRI The IRI to the item which should symbolically link to the target * @param target The target of the symbolic link * @throw OFOFCreateSymbolicLinkFailedException Creating a symbolic link failed * @throw OFUnsupportedProtocolException No handler is registered for the IRI's * scheme */ - (void)createSymbolicLinkAtIRI: (OFIRI *)IRI withDestinationPath: (OFString *)target; #ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES /** * @brief Returns the extended attribute data for the specified name of the * item at the specified path. * * This method is not available on some systems. * * @param name The name of the extended attribute * @param path The path of the item to return the extended attribute from * @return The extended attribute data for the specified name of the item at * the specified IRI * @throw OFGetItemAttributesFailedException Getting the extended attribute * failed * @throw OFNotImplementedException Getting extended attributes is not * implemented for the specified item */ - (OFData *)extendedAttributeDataForName: (OFString *)name ofItemAtPath: (OFString *)path; /** * @brief Gets the extended attribute data and type for the specified name * of the item at the specified path. * * This method is not available on some systems. * * @param data A pointer to `OFData *` that gets set to the data of the * extended attribute * @param type A pointer to `id` that gets set to the type of the extended * attribute, if not `NULL`. Gets set to `nil` if the extended * attribute has no type. The type of the type depends on the * system. * @param name The name of the extended attribute * @param path The path of the item to return the extended attribute from * @throw OFGetItemAttributesFailedException Getting the extended attribute * failed * @throw OFNotImplementedException Getting extended attributes is not * implemented for the specified item */ - (void)getExtendedAttributeData: (OFData *_Nonnull *_Nonnull)data andType: (id _Nullable *_Nullable)type forName: (OFString *)name ofItemAtPath: (OFString *)path; #endif /** * @brief Returns the extended attribute data for the specified name of the * item at the specified IRI. * * This method is not available for all IRIs. * * @param name The name of the extended attribute * @param IRI The IRI of the item to return the extended attribute from * @return The extended attribute data for the specified name of the item at * the specified IRI * @throw OFGetItemAttributesFailedException Getting the extended attribute * failed * @throw OFUnsupportedProtocolException No handler is registered for the IRI's * scheme * @throw OFNotImplementedException Getting extended attributes is not * implemented for the specified item */ - (OFData *)extendedAttributeDataForName: (OFString *)name ofItemAtIRI: (OFIRI *)IRI; /** * @brief Gets the extended attribute data and type for the specified name * of the item at the specified IRI. * * This method is not available for all IRIs. * * @param data A pointer to `OFData *` that gets set to the data of the * extended attribute * @param type A pointer to `id` that gets set to the type of the extended * attribute, if not `NULL`. Gets set to `nil` if the extended * attribute has no type. The type of the type depends on the IRI * handler. * @param name The name of the extended attribute * @param IRI The IRI of the item to return the extended attribute from * @throw OFGetItemAttributesFailedException Getting the extended attribute * failed * @throw OFUnsupportedProtocolException No handler is registered for the IRI's * scheme * @throw OFNotImplementedException Getting extended attributes is not * implemented for the specified item */ - (void)getExtendedAttributeData: (OFData *_Nonnull *_Nonnull)data andType: (id _Nullable *_Nullable)type forName: (OFString *)name ofItemAtIRI: (OFIRI *)IRI; #ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES /** * @brief Sets the extended attribute data for the specified name of the item * at the specified path. * * This method is not available on some systems. * * @param data The data for the extended attribute * @param name The name of the extended attribute * @param path The path of the item to set the extended attribute on * @throw OFSetItemAttributesFailedException Setting the extended attribute * failed * @throw OFNotImplementedException Setting extended attributes is not * implemented for the specified item */ - (void)setExtendedAttributeData: (OFData *)data forName: (OFString *)name ofItemAtPath: (OFString *)path; /** * @brief Sets the extended attribute data for the specified name of the item * at the specified path. * * This method is not available on some systems. * * @param data The data for the extended attribute * @param type The type for the extended attribute. `nil` does not mean to keep * the existing type, but to set it to no type. The type of the * type depends on the system. * @param name The name of the extended attribute * @param path The path of the item to set the extended attribute on * @throw OFSetItemAttributesFailedException Setting the extended attribute * failed * @throw OFNotImplementedException Setting extended attributes is not * implemented for the specified item or a * type was specified and typed extended * attributes are not supported */ - (void)setExtendedAttributeData: (OFData *)data andType: (nullable id)type forName: (OFString *)name ofItemAtPath: (OFString *)path; #endif /** * @brief Sets the extended attribute data for the specified name of the item * at the specified IRI. * * This method is not available for all IRIs. * * @param data The data for the extended attribute * @param name The name of the extended attribute * @param IRI The IRI of the item to set the extended attribute on * @throw OFSetItemAttributesFailedException Setting the extended attribute * failed * @throw OFUnsupportedProtocolException No handler is registered for the IRI's * scheme * @throw OFNotImplementedException Setting extended attributes is not * implemented for the specified item */ - (void)setExtendedAttributeData: (OFData *)data forName: (OFString *)name ofItemAtIRI: (OFIRI *)IRI; /** * @brief Sets the extended attribute data for the specified name of the item * at the specified IRI. * * This method is not available for all IRIs. * * @param data The data for the extended attribute * @param type The type for the extended attribute. `nil` does not mean to keep * the existing type, but to set it to no type. The type of the * type depends on the IRI handler. * @param name The name of the extended attribute * @param IRI The IRI of the item to set the extended attribute on * @throw OFSetItemAttributesFailedException Setting the extended attribute * failed * @throw OFUnsupportedProtocolException No handler is registered for the IRI's * scheme * @throw OFNotImplementedException Setting extended attributes is not * implemented for the specified item or a * type was specified and typed extended * attributes are not supported */ - (void)setExtendedAttributeData: (OFData *)data andType: (nullable id)type forName: (OFString *)name ofItemAtIRI: (OFIRI *)IRI; #ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES /** * @brief Removes the extended attribute for the specified name of the item at * the specified path. * * This method is not available on some systems. * * @param name The name of the extended attribute to remove * @param path The path of the item to remove the extended attribute from * @throw OFSetItemAttributesFailedException Removing the extended attribute * failed * @throw OFNotImplementedException Removing extended attributes is not * implemented for the specified item */ - (void)removeExtendedAttributeForName: (OFString *)name ofItemAtPath: (OFString *)path; #endif /** * @brief Removes the extended attribute for the specified name of the item at * the specified IRI. * * This method is not available for all IRIs. * * @param name The name of the extended attribute to remove * @param IRI The IRI of the item to remove the extended attribute from * @throw OFSetItemAttributesFailedException Removing the extended attribute * failed * @throw OFUnsupportedProtocolException No handler is registered for the IRI's * scheme * @throw OFNotImplementedException Removing extended attributes is not * implemented for the specified item */ - (void)removeExtendedAttributeForName: (OFString *)name ofItemAtIRI: (OFIRI *)IRI; @end @interface OFDictionary (FileAttributes) /** * @brief The @ref OFFileSize key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) unsigned long long fileSize; /** * @brief The @ref OFFileType key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) OFFileAttributeType fileType; /** * @brief The @ref OFFilePOSIXPermissions key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) unsigned long filePOSIXPermissions; /** * @brief The @ref OFFileOwnerAccountID key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) unsigned long fileOwnerAccountID; /** * @brief The @ref OFFileGroupOwnerAccountID key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) unsigned long fileGroupOwnerAccountID; /** * @brief The @ref OFFileOwnerAccountName key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) OFString *fileOwnerAccountName; /** * @brief The @ref OFFileGroupOwnerAccountName key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) OFString *fileGroupOwnerAccountName; /** * @brief The @ref OFFileLastAccessDate key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) OFDate *fileLastAccessDate; /** * @brief The @ref OFFileModificationDate key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) OFDate *fileModificationDate; /** * @brief The @ref OFFileStatusChangeDate key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) OFDate *fileStatusChangeDate; /** * @brief The @ref OFFileCreationDate key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) OFDate *fileCreationDate; /** * @brief The @ref OFFileSymbolicLinkDestination key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) OFString *fileSymbolicLinkDestination; /** * @brief The @ref OFFileExtendedAttributesNames key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *fileExtendedAttributesNames; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFFileManager.m000066400000000000000000000672551465614216400162220ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #define OF_FILE_MANAGER_M #include #include #include "unistd_wrapper.h" #include "platform.h" #ifdef OF_DJGPP # include #endif #ifdef OF_PSP # include #endif #import "OFArray.h" #import "OFData.h" #import "OFDate.h" #import "OFDictionary.h" #ifdef OF_HAVE_FILES # import "OFFile.h" #endif #import "OFFileManager.h" #import "OFIRI.h" #import "OFIRIHandler.h" #import "OFLocale.h" #import "OFNumber.h" #import "OFStream.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFChangeCurrentDirectoryFailedException.h" #import "OFCopyItemFailedException.h" #import "OFCreateDirectoryFailedException.h" #import "OFGetCurrentDirectoryFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFMoveItemFailedException.h" #import "OFNotImplementedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFRemoveItemFailedException.h" #import "OFGetItemAttributesFailedException.h" #import "OFUndefinedKeyException.h" #import "OFUnsupportedProtocolException.h" #ifdef OF_WINDOWS # include # include # include #endif #ifdef OF_AMIGAOS # define Class IntuitionClass # include # include # undef Class #endif #ifdef OF_MINT # include #endif @interface OFDefaultFileManager: OFFileManager @end #ifdef OF_AMIGAOS4 # define CurrentDir(lock) SetCurrentDir(lock) #endif #include "OFFileManagerConstants.inc" static OFFileManager *defaultManager; #ifdef OF_AMIGAOS static bool dirChanged = false; static BPTR originalDirLock = 0; OF_DESTRUCTOR() { if (dirChanged) UnLock(CurrentDir(originalDirLock)); } #endif static id attributeForKeyOrException(OFFileAttributes attributes, OFFileAttributeKey key) { id object = [attributes objectForKey: key]; if (object == nil) @throw [OFUndefinedKeyException exceptionWithObject: attributes key: key]; return object; } @implementation OFFileManager + (void)initialize { if (self != [OFFileManager class]) return; #ifdef OF_HAVE_FILES /* * Make sure OFFile is initialized. * On some systems, this is needed to initialize the file system driver. */ [OFFile class]; #endif defaultManager = [[OFDefaultFileManager alloc] init]; } + (OFFileManager *)defaultManager { return defaultManager; } #ifdef OF_HAVE_FILES - (OFString *)currentDirectoryPath { # if defined(OF_WINDOWS) OFString *ret; if ([OFSystemInfo isWindowsNT]) { wchar_t *buffer = _wgetcwd(NULL, 0); @try { ret = [OFString stringWithUTF16String: buffer]; } @finally { free(buffer); } } else { char *buffer = _getcwd(NULL, 0); @try { ret = [OFString stringWithCString: buffer encoding: [OFLocale encoding]]; } @finally { free(buffer); } } return ret; # elif defined(OF_AMIGAOS) char buffer[512]; if (!NameFromLock(((struct Process *)FindTask(NULL))->pr_CurrentDir, buffer, 512)) { if (IoErr() == ERROR_LINE_TOO_LONG) @throw [OFOutOfRangeException exception]; return nil; } return [OFString stringWithCString: buffer encoding: [OFLocale encoding]]; # elif defined(OF_GLIBC) char *buffer; OFString *path; if ((buffer = getcwd(NULL, 0)) == NULL) @throw [OFGetCurrentDirectoryFailedException exceptionWithErrNo: errno]; @try { path = [OFString stringWithCString: buffer encoding: [OFLocale encoding]]; } @finally { free(buffer); } return path; # else char buffer[PATH_MAX]; if ((getcwd(buffer, PATH_MAX)) == NULL) @throw [OFGetCurrentDirectoryFailedException exceptionWithErrNo: errno]; # ifdef OF_DJGPP /* * For some reason, getcwd() returns forward slashes on DJGPP, even * though the native format is to use backwards slashes. */ for (char *tmp = buffer; *tmp != '\0'; tmp++) if (*tmp == '/') *tmp = '\\'; # endif return [OFString stringWithCString: buffer encoding: [OFLocale encoding]]; # endif } - (OFIRI *)currentDirectoryIRI { void *pool = objc_autoreleasePoolPush(); OFIRI *ret; ret = [OFIRI fileIRIWithPath: self.currentDirectoryPath isDirectory: true]; ret = [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } #endif - (OFFileAttributes)attributesOfItemAtIRI: (OFIRI *)IRI { OFIRIHandler *IRIHandler; if (IRI == nil) @throw [OFInvalidArgumentException exception]; if ((IRIHandler = [OFIRIHandler handlerForIRI: IRI]) == nil) @throw [OFUnsupportedProtocolException exceptionWithIRI: IRI]; return [IRIHandler attributesOfItemAtIRI: IRI]; } #ifdef OF_HAVE_FILES - (OFFileAttributes)attributesOfItemAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFFileAttributes ret; ret = [self attributesOfItemAtIRI: [OFIRI fileIRIWithPath: path isDirectory: false]]; ret = [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } #endif - (void)setAttributes: (OFFileAttributes)attributes ofItemAtIRI: (OFIRI *)IRI { OFIRIHandler *IRIHandler; if (IRI == nil) @throw [OFInvalidArgumentException exception]; if ((IRIHandler = [OFIRIHandler handlerForIRI: IRI]) == nil) @throw [OFUnsupportedProtocolException exceptionWithIRI: IRI]; [IRIHandler setAttributes: attributes ofItemAtIRI: IRI]; } #ifdef OF_HAVE_FILES - (void)setAttributes: (OFFileAttributes)attributes ofItemAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); [self setAttributes: attributes ofItemAtIRI: [OFIRI fileIRIWithPath: path isDirectory: false]]; objc_autoreleasePoolPop(pool); } #endif - (bool)fileExistsAtIRI: (OFIRI *)IRI { OFIRIHandler *IRIHandler; if (IRI == nil) @throw [OFInvalidArgumentException exception]; if ((IRIHandler = [OFIRIHandler handlerForIRI: IRI]) == nil) @throw [OFUnsupportedProtocolException exceptionWithIRI: IRI]; return [IRIHandler fileExistsAtIRI: IRI]; } #ifdef OF_HAVE_FILES - (bool)fileExistsAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); bool ret; ret = [self fileExistsAtIRI: [OFIRI fileIRIWithPath: path isDirectory: false]]; objc_autoreleasePoolPop(pool); return ret; } #endif - (bool)directoryExistsAtIRI: (OFIRI *)IRI { OFIRIHandler *IRIHandler; if (IRI == nil) @throw [OFInvalidArgumentException exception]; if ((IRIHandler = [OFIRIHandler handlerForIRI: IRI]) == nil) @throw [OFUnsupportedProtocolException exceptionWithIRI: IRI]; return [IRIHandler directoryExistsAtIRI: IRI]; } #ifdef OF_HAVE_FILES - (bool)directoryExistsAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); bool ret; ret = [self directoryExistsAtIRI: [OFIRI fileIRIWithPath: path isDirectory: true]]; objc_autoreleasePoolPop(pool); return ret; } #endif - (void)createDirectoryAtIRI: (OFIRI *)IRI { void *pool = objc_autoreleasePoolPush(); OFIRIHandler *IRIHandler; if (IRI == nil) @throw [OFInvalidArgumentException exception]; if ((IRIHandler = [OFIRIHandler handlerForIRI: IRI]) == nil) @throw [OFUnsupportedProtocolException exceptionWithIRI: IRI]; [IRIHandler createDirectoryAtIRI: IRI]; objc_autoreleasePoolPop(pool); } - (void)createDirectoryAtIRI: (OFIRI *)IRI createParents: (bool)createParents { void *pool = objc_autoreleasePoolPush(); OFMutableIRI *mutableIRI; OFArray OF_GENERIC(OFString *) *components; OFMutableArray OF_GENERIC(OFIRI *) *componentIRIs; size_t componentIRIsCount; ssize_t i; if (IRI == nil) @throw [OFInvalidArgumentException exception]; if (!createParents) { [self createDirectoryAtIRI: IRI]; objc_autoreleasePoolPop(pool); return; } /* * Try blindly creating the directory first. * * The reason for this is that we might be sandboxed, so attempting to * create any of the parent directories will fail, while creating the * directory itself will work. */ if ([self directoryExistsAtIRI: IRI]) { objc_autoreleasePoolPop(pool); return; } @try { [self createDirectoryAtIRI: IRI]; objc_autoreleasePoolPop(pool); return; } @catch (OFCreateDirectoryFailedException *e) { /* * If we didn't fail because any of the parents is missing, * there is no point in trying to create the parents. */ if (e.errNo != ENOENT) @throw e; } /* * Because we might be sandboxed (and for remote IRIs don't even know * anything at all), we generate the IRI for every component. We then * iterate them in reverse order until we find the first existing * directory, and then create subdirectories from there. */ mutableIRI = [[IRI mutableCopy] autorelease]; mutableIRI.percentEncodedPath = @"/"; components = IRI.pathComponents; componentIRIs = [OFMutableArray arrayWithCapacity: components.count]; for (OFString *component in components) { [mutableIRI appendPathComponent: component]; if (![mutableIRI.percentEncodedPath isEqual: @"/"]) [componentIRIs addObject: [[mutableIRI copy] autorelease]]; } componentIRIsCount = componentIRIs.count; for (i = componentIRIsCount - 1; i > 0; i--) { if ([self directoryExistsAtIRI: [componentIRIs objectAtIndex: i]]) break; } if (++i == (ssize_t)componentIRIsCount) { /* * The IRI exists, even though before we made sure it did not. * That means it was created in the meantime by something else, * so we're done here. */ objc_autoreleasePoolPop(pool); return; } for (; i < (ssize_t)componentIRIsCount; i++) [self createDirectoryAtIRI: [componentIRIs objectAtIndex: i]]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_FILES - (void)createDirectoryAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); [self createDirectoryAtIRI: [OFIRI fileIRIWithPath: path isDirectory: true]]; objc_autoreleasePoolPop(pool); } - (void)createDirectoryAtPath: (OFString *)path createParents: (bool)createParents { void *pool = objc_autoreleasePoolPush(); [self createDirectoryAtIRI: [OFIRI fileIRIWithPath: path isDirectory: true] createParents: createParents]; objc_autoreleasePoolPop(pool); } #endif - (OFArray OF_GENERIC(OFIRI *) *)contentsOfDirectoryAtIRI: (OFIRI *)IRI { OFIRIHandler *IRIHandler; if (IRI == nil) @throw [OFInvalidArgumentException exception]; if ((IRIHandler = [OFIRIHandler handlerForIRI: IRI]) == nil) @throw [OFUnsupportedProtocolException exceptionWithIRI: IRI]; return [IRIHandler contentsOfDirectoryAtIRI: IRI]; } #ifdef OF_HAVE_FILES - (OFArray OF_GENERIC(OFString *) *)contentsOfDirectoryAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFArray OF_GENERIC(OFIRI *) *IRIs; OFMutableArray OF_GENERIC(OFString *) *ret; IRIs = [self contentsOfDirectoryAtIRI: [OFIRI fileIRIWithPath: path isDirectory: true]]; ret = [OFMutableArray arrayWithCapacity: IRIs.count]; for (OFIRI *IRI in IRIs) [ret addObject: IRI.lastPathComponent]; [ret makeImmutable]; ret = [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFArray OF_GENERIC(OFString *) *)subpathsOfDirectoryAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFMutableArray OF_GENERIC(OFString *) *ret = [OFMutableArray arrayWithObject: path]; for (OFString *subpath in [self contentsOfDirectoryAtPath: path]) { void *pool2 = objc_autoreleasePoolPush(); OFString *fullSubpath = [path stringByAppendingPathComponent: subpath]; OFFileAttributes attributes = [self attributesOfItemAtPath: fullSubpath]; if ([attributes.fileType isEqual: OFFileTypeDirectory]) [ret addObjectsFromArray: [self subpathsOfDirectoryAtPath: fullSubpath]]; else [ret addObject: fullSubpath]; objc_autoreleasePoolPop(pool2); } [ret makeImmutable]; ret = [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (void)changeCurrentDirectoryPath: (OFString *)path { if (path == nil) @throw [OFInvalidArgumentException exception]; # ifdef OF_AMIGAOS BPTR lock, oldLock; if ((lock = Lock([path cStringWithEncoding: [OFLocale encoding]], SHARED_LOCK)) == 0) { int errNo; switch (IoErr()) { case ERROR_OBJECT_IN_USE: case ERROR_DISK_NOT_VALIDATED: errNo = EBUSY; break; case ERROR_OBJECT_NOT_FOUND: errNo = ENOENT; break; default: errNo = 0; break; } @throw [OFChangeCurrentDirectoryFailedException exceptionWithPath: path errNo: errNo]; } oldLock = CurrentDir(lock); if (!dirChanged) originalDirLock = oldLock; else UnLock(oldLock); dirChanged = true; # else int status; # ifdef OF_WINDOWS if ([OFSystemInfo isWindowsNT]) status = _wchdir(path.UTF16String); else # endif status = chdir( [path cStringWithEncoding: [OFLocale encoding]]); if (status != 0) @throw [OFChangeCurrentDirectoryFailedException exceptionWithPath: path errNo: errno]; # endif } - (void)changeCurrentDirectoryIRI: (OFIRI *)IRI { void *pool = objc_autoreleasePoolPush(); [self changeCurrentDirectoryPath: IRI.fileSystemRepresentation]; objc_autoreleasePoolPop(pool); } - (void)copyItemAtPath: (OFString *)source toPath: (OFString *)destination { void *pool = objc_autoreleasePoolPush(); [self copyItemAtIRI: [OFIRI fileIRIWithPath: source isDirectory: false] toIRI: [OFIRI fileIRIWithPath: destination isDirectory: false]]; objc_autoreleasePoolPop(pool); } #endif - (void)copyItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination { void *pool; OFIRIHandler *IRIHandler; OFFileAttributes attributes; OFFileAttributeType type; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); if ((IRIHandler = [OFIRIHandler handlerForIRI: source]) == nil) @throw [OFUnsupportedProtocolException exceptionWithIRI: source]; if ([IRIHandler copyItemAtIRI: source toIRI: destination]) return; if ([self fileExistsAtIRI: destination]) @throw [OFCopyItemFailedException exceptionWithSourceIRI: source destinationIRI: destination errNo: EEXIST]; @try { attributes = [self attributesOfItemAtIRI: source]; } @catch (OFGetItemAttributesFailedException *e) { @throw [OFCopyItemFailedException exceptionWithSourceIRI: source destinationIRI: destination errNo: e.errNo]; } type = attributes.fileType; if ([type isEqual: OFFileTypeDirectory]) { OFArray OF_GENERIC(OFIRI *) *contents; @try { [self createDirectoryAtIRI: destination]; @try { OFFileAttributeKey key = OFFilePOSIXPermissions; OFNumber *permissions = [attributes objectForKey: key]; OFFileAttributes destinationAttributes; if (permissions != nil) { destinationAttributes = [OFDictionary dictionaryWithObject: permissions forKey: key]; [self setAttributes: destinationAttributes ofItemAtIRI: destination]; } } @catch (OFNotImplementedException *e) { } contents = [self contentsOfDirectoryAtIRI: source]; } @catch (id e) { /* * Only convert exceptions to OFCopyItemFailedException * that have an errNo property. This covers all I/O * related exceptions from the operations used to copy * an item, all others should be left as is. */ if ([e respondsToSelector: @selector(errNo)]) @throw [OFCopyItemFailedException exceptionWithSourceIRI: source destinationIRI: destination errNo: [e errNo]]; @throw e; } for (OFIRI *item in contents) { void *pool2 = objc_autoreleasePoolPush(); OFIRI *destinationIRI = [destination IRIByAppendingPathComponent: item.lastPathComponent]; [self copyItemAtIRI: item toIRI: destinationIRI]; objc_autoreleasePoolPop(pool2); } } else if ([type isEqual: OFFileTypeRegular]) { size_t pageSize = [OFSystemInfo pageSize]; OFStream *sourceStream = nil; OFStream *destinationStream = nil; char *buffer; buffer = OFAllocMemory(1, pageSize); @try { sourceStream = [OFIRIHandler openItemAtIRI: source mode: @"r"]; destinationStream = [OFIRIHandler openItemAtIRI: destination mode: @"w"]; while (!sourceStream.atEndOfStream) { size_t length; length = [sourceStream readIntoBuffer: buffer length: pageSize]; [destinationStream writeBuffer: buffer length: length]; } @try { OFFileAttributeKey key = OFFilePOSIXPermissions; OFNumber *permissions = [attributes objectForKey: key]; OFFileAttributes destinationAttributes; if (permissions != nil) { destinationAttributes = [OFDictionary dictionaryWithObject: permissions forKey: key]; [self setAttributes: destinationAttributes ofItemAtIRI: destination]; } } @catch (OFNotImplementedException *e) { } } @catch (id e) { /* * Only convert exceptions to OFCopyItemFailedException * that have an errNo property. This covers all I/O * related exceptions from the operations used to copy * an item, all others should be left as is. */ if ([e respondsToSelector: @selector(errNo)]) @throw [OFCopyItemFailedException exceptionWithSourceIRI: source destinationIRI: destination errNo: [e errNo]]; @throw e; } @finally { [sourceStream close]; [destinationStream close]; OFFreeMemory(buffer); } } else if ([type isEqual: OFFileTypeSymbolicLink]) { @try { OFString *linkDestination = attributes.fileSymbolicLinkDestination; [self createSymbolicLinkAtIRI: destination withDestinationPath: linkDestination]; } @catch (id e) { /* * Only convert exceptions to OFCopyItemFailedException * that have an errNo property. This covers all I/O * related exceptions from the operations used to copy * an item, all others should be left as is. */ if ([e respondsToSelector: @selector(errNo)]) @throw [OFCopyItemFailedException exceptionWithSourceIRI: source destinationIRI: destination errNo: [e errNo]]; @throw e; } } else @throw [OFCopyItemFailedException exceptionWithSourceIRI: source destinationIRI: destination errNo: EINVAL]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_FILES - (void)moveItemAtPath: (OFString *)source toPath: (OFString *)destination { void *pool = objc_autoreleasePoolPush(); [self moveItemAtIRI: [OFIRI fileIRIWithPath: source isDirectory: false] toIRI: [OFIRI fileIRIWithPath: destination isDirectory: false]]; objc_autoreleasePoolPop(pool); } #endif - (void)moveItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination { void *pool; OFIRIHandler *IRIHandler; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); if ((IRIHandler = [OFIRIHandler handlerForIRI: source]) == nil) @throw [OFUnsupportedProtocolException exceptionWithIRI: source]; @try { if ([IRIHandler moveItemAtIRI: source toIRI: destination]) return; } @catch (OFMoveItemFailedException *e) { if (e.errNo != EXDEV) @throw e; } if ([self fileExistsAtIRI: destination]) @throw [OFMoveItemFailedException exceptionWithSourceIRI: source destinationIRI: destination errNo: EEXIST]; @try { [self copyItemAtIRI: source toIRI: destination]; } @catch (OFCopyItemFailedException *e) { [self removeItemAtIRI: destination]; @throw [OFMoveItemFailedException exceptionWithSourceIRI: source destinationIRI: destination errNo: e.errNo]; } @try { [self removeItemAtIRI: source]; } @catch (OFRemoveItemFailedException *e) { @throw [OFMoveItemFailedException exceptionWithSourceIRI: source destinationIRI: destination errNo: e.errNo]; } objc_autoreleasePoolPop(pool); } - (void)removeItemAtIRI: (OFIRI *)IRI { OFIRIHandler *IRIHandler; if (IRI == nil) @throw [OFInvalidArgumentException exception]; if ((IRIHandler = [OFIRIHandler handlerForIRI: IRI]) == nil) @throw [OFUnsupportedProtocolException exceptionWithIRI: IRI]; [IRIHandler removeItemAtIRI: IRI]; } #ifdef OF_HAVE_FILES - (void)removeItemAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); [self removeItemAtIRI: [OFIRI fileIRIWithPath: path isDirectory: false]]; objc_autoreleasePoolPop(pool); } #endif - (void)linkItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination { void *pool = objc_autoreleasePoolPush(); OFIRIHandler *IRIHandler; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; if (![destination.scheme isEqual: source.scheme]) @throw [OFInvalidArgumentException exception]; IRIHandler = [OFIRIHandler handlerForIRI: source]; if (IRIHandler == nil) @throw [OFUnsupportedProtocolException exceptionWithIRI: source]; [IRIHandler linkItemAtIRI: source toIRI: destination]; objc_autoreleasePoolPop(pool); } #ifdef OF_FILE_MANAGER_SUPPORTS_LINKS - (void)linkItemAtPath: (OFString *)source toPath: (OFString *)destination { void *pool = objc_autoreleasePoolPush(); [self linkItemAtIRI: [OFIRI fileIRIWithPath: source isDirectory: false] toIRI: [OFIRI fileIRIWithPath: destination isDirectory: false]]; objc_autoreleasePoolPop(pool); } #endif - (void)createSymbolicLinkAtIRI: (OFIRI *)IRI withDestinationPath: (OFString *)target { void *pool = objc_autoreleasePoolPush(); OFIRIHandler *IRIHandler; if (IRI == nil || target == nil) @throw [OFInvalidArgumentException exception]; IRIHandler = [OFIRIHandler handlerForIRI: IRI]; if (IRIHandler == nil) @throw [OFUnsupportedProtocolException exceptionWithIRI: IRI]; [IRIHandler createSymbolicLinkAtIRI: IRI withDestinationPath: target]; objc_autoreleasePoolPop(pool); } #ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS - (void)createSymbolicLinkAtPath: (OFString *)path withDestinationPath: (OFString *)target { void *pool = objc_autoreleasePoolPush(); [self createSymbolicLinkAtIRI: [OFIRI fileIRIWithPath: path isDirectory: false] withDestinationPath: target]; objc_autoreleasePoolPop(pool); } #endif - (OFData *)extendedAttributeDataForName: (OFString *)name ofItemAtIRI: (OFIRI *)IRI { OFData *data; [self getExtendedAttributeData: &data andType: NULL forName: name ofItemAtIRI: IRI]; return data; } - (void)getExtendedAttributeData: (OFData **)data andType: (id *)type forName: (OFString *)name ofItemAtIRI: (OFIRI *)IRI { void *pool = objc_autoreleasePoolPush(); OFIRIHandler *IRIHandler; if (IRI == nil) @throw [OFInvalidArgumentException exception]; if ((IRIHandler = [OFIRIHandler handlerForIRI: IRI]) == nil) @throw [OFUnsupportedProtocolException exceptionWithIRI: IRI]; [IRIHandler getExtendedAttributeData: data andType: type forName: name ofItemAtIRI: IRI]; [*data retain]; if (type != NULL) [*type retain]; objc_autoreleasePoolPop(pool); [*data autorelease]; if (type != NULL) [*type autorelease]; } #ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES - (OFData *)extendedAttributeDataForName: (OFString *)name ofItemAtPath: (OFString *)path { OFData *data; [self getExtendedAttributeData: &data andType: NULL forName: name ofItemAtPath: path]; return data; } - (void)getExtendedAttributeData: (OFData **)data andType: (id *)type forName: (OFString *)name ofItemAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); [self getExtendedAttributeData: data andType: type forName: name ofItemAtIRI: [OFIRI fileIRIWithPath: path isDirectory: false]]; [*data retain]; if (type != NULL) [*type retain]; objc_autoreleasePoolPop(pool); [*data autorelease]; if (type != NULL) [*type autorelease]; } #endif - (void)setExtendedAttributeData: (OFData *)data forName: (OFString *)name ofItemAtIRI: (OFIRI *)IRI { [self setExtendedAttributeData: data andType: nil forName: name ofItemAtIRI: IRI]; } - (void)setExtendedAttributeData: (OFData *)data andType: (id)type forName: (OFString *)name ofItemAtIRI: (OFIRI *)IRI { OFIRIHandler *IRIHandler; if (IRI == nil) @throw [OFInvalidArgumentException exception]; if ((IRIHandler = [OFIRIHandler handlerForIRI: IRI]) == nil) @throw [OFUnsupportedProtocolException exceptionWithIRI: IRI]; [IRIHandler setExtendedAttributeData: data andType: type forName: name ofItemAtIRI: IRI]; } #ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES - (void)setExtendedAttributeData: (OFData *)data forName: (OFString *)name ofItemAtPath: (OFString *)path { [self setExtendedAttributeData: data andType: nil forName: name ofItemAtPath: path]; } - (void)setExtendedAttributeData: (OFData *)data andType: (id)type forName: (OFString *)name ofItemAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); [self setExtendedAttributeData: data andType: type forName: name ofItemAtIRI: [OFIRI fileIRIWithPath: path isDirectory: false]]; objc_autoreleasePoolPop(pool); } #endif - (void)removeExtendedAttributeForName: (OFString *)name ofItemAtIRI: (OFIRI *)IRI { OFIRIHandler *IRIHandler; if (IRI == nil) @throw [OFInvalidArgumentException exception]; if ((IRIHandler = [OFIRIHandler handlerForIRI: IRI]) == nil) @throw [OFUnsupportedProtocolException exceptionWithIRI: IRI]; [IRIHandler removeExtendedAttributeForName: name ofItemAtIRI: IRI]; } #ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES - (void)removeExtendedAttributeForName: (OFString *)name ofItemAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); [self removeExtendedAttributeForName: name ofItemAtIRI: [OFIRI fileIRIWithPath: path isDirectory: false]]; objc_autoreleasePoolPop(pool); } #endif @end @implementation OFDefaultFileManager OF_SINGLETON_METHODS @end @implementation OFDictionary (FileAttributes) - (unsigned long long)fileSize { return [attributeForKeyOrException(self, OFFileSize) unsignedLongLongValue]; } - (OFFileAttributeType)fileType { return attributeForKeyOrException(self, OFFileType); } - (unsigned long)filePOSIXPermissions { return [attributeForKeyOrException(self, OFFilePOSIXPermissions) unsignedLongValue]; } - (unsigned long)fileOwnerAccountID { return [attributeForKeyOrException(self, OFFileOwnerAccountID) unsignedLongValue]; } - (unsigned long)fileGroupOwnerAccountID { return [attributeForKeyOrException(self, OFFileGroupOwnerAccountID) unsignedLongValue]; } - (OFString *)fileOwnerAccountName { return attributeForKeyOrException(self, OFFileOwnerAccountName); } - (OFString *)fileGroupOwnerAccountName { return attributeForKeyOrException(self, OFFileGroupOwnerAccountName); } - (OFDate *)fileLastAccessDate { return attributeForKeyOrException(self, OFFileLastAccessDate); } - (OFDate *)fileModificationDate { return attributeForKeyOrException(self, OFFileModificationDate); } - (OFDate *)fileStatusChangeDate { return attributeForKeyOrException(self, OFFileStatusChangeDate); } - (OFDate *)fileCreationDate { return attributeForKeyOrException(self, OFFileCreationDate); } - (OFString *)fileSymbolicLinkDestination { return attributeForKeyOrException(self, OFFileSymbolicLinkDestination); } - (OFArray OF_GENERIC(OFString *) *)fileExtendedAttributesNames { return attributeForKeyOrException(self, OFFileExtendedAttributesNames); } @end objfw-1.1.6/src/OFFileManagerConstants.inc000066400000000000000000000044101465614216400204140ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ const OFFileAttributeKey OFFileSize = @"OFFileSize"; const OFFileAttributeKey OFFileType = @"OFFileType"; const OFFileAttributeKey OFFilePOSIXPermissions = @"OFFilePOSIXPermissions"; const OFFileAttributeKey OFFileOwnerAccountID = @"OFFileOwnerAccountID"; const OFFileAttributeKey OFFileGroupOwnerAccountID = @"OFFileGroupOwnerAccountID"; const OFFileAttributeKey OFFileOwnerAccountName = @"OFFileOwnerAccountName"; const OFFileAttributeKey OFFileGroupOwnerAccountName = @"OFFileGroupOwnerAccountName"; const OFFileAttributeKey OFFileLastAccessDate = @"OFFileLastAccessDate"; const OFFileAttributeKey OFFileModificationDate = @"OFFileModificationDate"; const OFFileAttributeKey OFFileStatusChangeDate = @"OFFileStatusChangeDate"; const OFFileAttributeKey OFFileCreationDate = @"OFFileCreationDate"; const OFFileAttributeKey OFFileSymbolicLinkDestination = @"OFFileSymbolicLinkDestination"; const OFFileAttributeKey OFFileExtendedAttributesNames = @"OFFileExtendedAttributesNames"; const OFFileAttributeType OFFileTypeRegular = @"OFFileTypeRegular"; const OFFileAttributeType OFFileTypeDirectory = @"OFFileTypeDirectory"; const OFFileAttributeType OFFileTypeSymbolicLink = @"OFFileTypeSymbolicLink"; const OFFileAttributeType OFFileTypeFIFO = @"OFFileTypeFIFO"; const OFFileAttributeType OFFileTypeCharacterSpecial = @"OFFileTypeCharacterSpecial"; const OFFileAttributeType OFFileTypeBlockSpecial = @"OFFileTypeBlockSpecial"; const OFFileAttributeType OFFileTypeSocket = @"OFFileTypeSocket"; const OFFileAttributeType OFFileTypeUnknown = @"OFFileTypeUnknown"; objfw-1.1.6/src/OFGZIPStream.h000066400000000000000000000101251465614216400157500ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFStream.h" #import "OFDate.h" @class OFInflateStream; OF_ASSUME_NONNULL_BEGIN /** * @brief The operating system on which compressed the data. */ typedef enum { OFGZIPStreamOperatingSystemFAT = 0, OFGZIPStreamOperatingSystemAmiga = 1, OFGZIPStreamOperatingSystemVMS = 2, OFGZIPStreamOperatingSystemUNIX = 3, OFGZIPStreamOperatingSystemVM_CMS = 4, OFGZIPStreamOperatingSystemAtariTOS = 5, OFGZIPStreamOperatingSystemHPFS = 6, OFGZIPStreamOperatingSystemMacintosh = 7, OFGZIPStreamOperatingSystemZSystem = 8, OFGZIPStreamOperatingSystemCPM = 9, OFGZIPStreamOperatingSystemTOPS20 = 10, OFGZIPStreamOperatingSystemNTFS = 11, OFGZIPStreamOperatingSystemQDO = 12, OFGZIPStreamOperatingSystemAcornRISCOS = 13, OFGZIPStreamOperatingSystemUnknown = 255 } OFGZIPStreamOperatingSystem; /** * @class OFGZIPStream OFGZIPStream.h ObjFW/OFGZIPStream.h * * @brief A class that handles GZIP compression and decompression transparently * for an underlying stream. */ OF_SUBCLASSING_RESTRICTED @interface OFGZIPStream: OFStream { OFStream *_stream; OFInflateStream *_Nullable _inflateStream; enum { OFGZIPStreamStateID1, OFGZIPStreamStateID2, OFGZIPStreamStateCompressionMethod, OFGZIPStreamStateFlags, OFGZIPStreamStateModificationDate, OFGZIPStreamStateExtraFlags, OFGZIPStreamStateOperatingSystem, OFGZIPStreamStateExtraLength, OFGZIPStreamStateExtra, OFGZIPStreamStateName, OFGZIPStreamStateComment, OFGZIPStreamStateHeaderCRC16, OFGZIPStreamStateData, OFGZIPStreamStateCRC32, OFGZIPStreamStateUncompressedSize } _state; enum { OFGZIPStreamFlagText = 0x01, OFGZIPStreamFlagHeaderCRC16 = 0x02, OFGZIPStreamFlagExtra = 0x04, OFGZIPStreamFlagName = 0x08, OFGZIPStreamFlagComment = 0x10 } _flags; uint8_t _extraFlags; OFGZIPStreamOperatingSystem _operatingSystemMadeOn; size_t _bytesRead; uint8_t _buffer[4]; OFDate *_Nullable _modificationDate; uint16_t _extraLength; uint32_t _CRC32, _uncompressedSize; } /** * @brief The operating system on which the data was compressed. * * This property is only guaranteed to be available once @ref atEndOfStream is * true. */ @property (readonly, nonatomic) OFGZIPStreamOperatingSystem operatingSystemMadeOn; /** * @brief The modification date of the original file. * * This property is only guaranteed to be available once @ref atEndOfStream is * true. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFDate *modificationDate; /** * @brief Creates a new OFGZIPStream with the specified underlying stream. * * @param stream The underlying stream for the OFGZIPStream * @param mode The mode for the OFGZIPStream. Valid modes are "r" for reading * and "w" for writing. * @return A new, autoreleased OFGZIPStream */ + (instancetype)streamWithStream: (OFStream *)stream mode: (OFString *)mode; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFGZIPStream with the specified * underlying stream. * * @param stream The underlying stream for the OFGZIPStream * @param mode The mode for the OFGZIPStream. Valid modes are "r" for reading * and "w" for writing. * @return An initialized OFGZIPStream */ - (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFGZIPStream.m000066400000000000000000000177241465614216400157710ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFGZIPStream.h" #import "OFCRC32.h" #import "OFDate.h" #import "OFInflateStream.h" #import "OFChecksumMismatchException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFTruncatedDataException.h" @implementation OFGZIPStream @synthesize operatingSystemMadeOn = _operatingSystemMadeOn; @synthesize modificationDate = _modificationDate; + (instancetype)streamWithStream: (OFStream *)stream mode: (OFString *)mode { return [[[self alloc] initWithStream: stream mode: mode] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode { self = [super init]; @try { if (![mode isEqual: @"r"]) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: nil]; _stream = [stream retain]; _operatingSystemMadeOn = OFGZIPStreamOperatingSystemUnknown; _CRC32 = ~0; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_stream != nil) [self close]; [_inflateStream release]; [_modificationDate release]; [super dealloc]; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; for (;;) { uint8_t byte; uint32_t CRC32, uncompressedSize; /* * The inflate stream might have overread, causing _stream to * be at the end, but the inflate stream will unread it once it * has reached the end. Hence only check it if the state is not * OFGZIPStreamStateData. */ if (_state != OFGZIPStreamStateData && _stream.atEndOfStream) { if (_state != OFGZIPStreamStateID1) @throw [OFTruncatedDataException exception]; return 0; } switch (_state) { case OFGZIPStreamStateID1: case OFGZIPStreamStateID2: case OFGZIPStreamStateCompressionMethod: if ([_stream readIntoBuffer: &byte length: 1] < 1) return 0; if ((_state == OFGZIPStreamStateID1 && byte != 0x1F) || (_state == OFGZIPStreamStateID2 && byte != 0x8B) || (_state == OFGZIPStreamStateCompressionMethod && byte != 8)) @throw [OFInvalidFormatException exception]; _state++; break; case OFGZIPStreamStateFlags: if ([_stream readIntoBuffer: &byte length: 1] < 1) return 0; _flags = byte; _state++; break; case OFGZIPStreamStateModificationDate: _bytesRead += [_stream readIntoBuffer: _buffer + _bytesRead length: 4 - _bytesRead]; if (_bytesRead < 4) return 0; [_modificationDate release]; _modificationDate = nil; _modificationDate = [[OFDate alloc] initWithTimeIntervalSince1970: (_buffer[3] << 24) | (_buffer[2] << 16) | (_buffer[1] << 8) | _buffer[0]]; _bytesRead = 0; _state++; break; case OFGZIPStreamStateExtraFlags: if ([_stream readIntoBuffer: &byte length: 1] < 1) return 0; _extraFlags = byte; _state++; break; case OFGZIPStreamStateOperatingSystem: if ([_stream readIntoBuffer: &byte length: 1] < 1) return 0; _operatingSystemMadeOn = byte; _state++; break; case OFGZIPStreamStateExtraLength: if (!(_flags & OFGZIPStreamFlagExtra)) { _state += 2; break; } _bytesRead += [_stream readIntoBuffer: _buffer + _bytesRead length: 2 - _bytesRead]; if (_bytesRead < 2) return 0; _extraLength = (_buffer[1] << 8) | _buffer[0]; _bytesRead = 0; _state++; break; case OFGZIPStreamStateExtra: { char tmp[512]; size_t toRead = _extraLength - _bytesRead; if (toRead > 512) toRead = 512; _bytesRead += [_stream readIntoBuffer: tmp length: toRead]; } if (_bytesRead < _extraLength) return 0; _bytesRead = 0; _state++; break; case OFGZIPStreamStateName: if (!(_flags & OFGZIPStreamFlagName)) { _state++; break; } do { if ([_stream readIntoBuffer: &byte length: 1] < 1) return 0; } while (byte != 0); _state++; break; case OFGZIPStreamStateComment: if (!(_flags & OFGZIPStreamFlagComment)) { _state++; break; } do { if ([_stream readIntoBuffer: &byte length: 1] < 1) return 0; } while (byte != 0); _state++; break; case OFGZIPStreamStateHeaderCRC16: if (!(_flags & OFGZIPStreamFlagHeaderCRC16)) { _state++; break; } _bytesRead += [_stream readIntoBuffer: _buffer + _bytesRead length: 2 - _bytesRead]; if (_bytesRead < 2) return 0; /* * Header CRC16 is not checked, as I could not find a * single file in the wild that actually has a header * CRC16 - and thus no file to test against. */ _bytesRead = 0; _state++; break; case OFGZIPStreamStateData: if (_inflateStream == nil) _inflateStream = [[OFInflateStream alloc] initWithStream: _stream]; if (!_inflateStream.atEndOfStream) { size_t bytesRead = [_inflateStream readIntoBuffer: buffer length: length]; _CRC32 = _OFCRC32(_CRC32, buffer, bytesRead); _uncompressedSize += bytesRead; return bytesRead; } [_inflateStream release]; _inflateStream = nil; _state++; break; case OFGZIPStreamStateCRC32: _bytesRead += [_stream readIntoBuffer: _buffer + _bytesRead length: 4 - _bytesRead]; if (_bytesRead < 4) return 0; CRC32 = ((uint32_t)_buffer[3] << 24) | (_buffer[2] << 16) | (_buffer[1] << 8) | _buffer[0]; if (~_CRC32 != CRC32) { OFString *actual = [OFString stringWithFormat: @"%08" PRIX32, ~_CRC32]; OFString *expected = [OFString stringWithFormat: @"%08" PRIX32, CRC32]; @throw [OFChecksumMismatchException exceptionWithActualChecksum: actual expectedChecksum: expected]; } _bytesRead = 0; _CRC32 = ~0; _state++; break; case OFGZIPStreamStateUncompressedSize: _bytesRead += [_stream readIntoBuffer: _buffer + _bytesRead length: 4 - _bytesRead]; if (_bytesRead < 4) return 0; uncompressedSize = (_buffer[3] << 24) | (_buffer[2] << 16) | (_buffer[1] << 8) | _buffer[0]; if (_uncompressedSize != uncompressedSize) { OFString *actual = [OFString stringWithFormat: @"%" PRIu32, _uncompressedSize]; OFString *expected = [OFString stringWithFormat: @"%" PRIu32, uncompressedSize]; @throw [OFChecksumMismatchException exceptionWithActualChecksum: actual expectedChecksum: expected]; } _bytesRead = 0; _uncompressedSize = 0; _state = OFGZIPStreamStateID1; break; } } } - (bool)lowlevelIsAtEndOfStream { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; /* * The inflate stream might have overread, causing _stream to be at the * end, but the inflate stream will unread it once it has reached the * end. */ if (_state == OFGZIPStreamStateData && !_inflateStream.atEndOfStream) return false; return _stream.atEndOfStream; } - (bool)lowlevelHasDataInReadBuffer { if (_state == OFGZIPStreamStateData) return _inflateStream.hasDataInReadBuffer; else return _stream.hasDataInReadBuffer; } - (void)close { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; [_stream release]; _stream = nil; [super close]; } @end objfw-1.1.6/src/OFHINFODNSResourceRecord.h000066400000000000000000000041521465614216400201050ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFDNSResourceRecord.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFHINFODNSResourceRecord \ * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h * * @brief A class representing an HINFO DNS resource record. */ OF_SUBCLASSING_RESTRICTED @interface OFHINFODNSResourceRecord: OFDNSResourceRecord { OFString *_CPU, *_OS; } /** * @brief The CPU of the host info of the resource record. */ @property (readonly, nonatomic) OFString *CPU; /** * @brief The OS of the host info of the resource record. */ @property (readonly, nonatomic) OFString *OS; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFHINFODNSResourceRecord with the * specified name, class, domain name and time to live. * * @param name The name for the resource record * @param DNSClass The class code for the resource record * @param CPU The CPU of the host info for the resource record * @param OS The OS of the host info for the resource record * @param TTL The time to live for the resource record * @return An initialized OFHINFODNSResourceRecord */ - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass CPU: (OFString *)CPU OS: (OFString *)OS TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFHINFODNSResourceRecord.m000066400000000000000000000052431465614216400201140ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFHINFODNSResourceRecord.h" @implementation OFHINFODNSResourceRecord @synthesize CPU = _CPU, OS = _OS; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass CPU: (OFString *)CPU OS: (OFString *)OS TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: DNSClass recordType: OFDNSRecordTypeHINFO TTL: TTL]; @try { _CPU = [CPU copy]; _OS = [OS copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_CPU release]; [_OS release]; [super dealloc]; } - (bool)isEqual: (id)object { OFHINFODNSResourceRecord *record; if (object == self) return true; if (![object isKindOfClass: [OFHINFODNSResourceRecord class]]) return false; record = object; if (record->_name != _name && ![record->_name isEqual: _name]) return false; if (record->_DNSClass != _DNSClass) return false; if (record->_recordType != _recordType) return false; if (record->_CPU != _CPU && ![record->_CPU isEqual: _CPU]) return false; if (record->_OS != _OS && ![record->_OS isEqual: _OS]) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddByte(&hash, _DNSClass >> 8); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType >> 8); OFHashAddByte(&hash, _recordType); OFHashAddHash(&hash, _CPU.hash); OFHashAddHash(&hash, _OS.hash); OFHashFinalize(&hash); return hash; } - (OFString *)description { return [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tClass = %@\n" @"\tCPU = %@\n" @"\tOS = %@\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFDNSClassName(_DNSClass), _CPU, _OS, _TTL]; } @end objfw-1.1.6/src/OFHMAC.h000066400000000000000000000104351465614216400145370ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFCryptographicHash.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFHMAC OFHMAC.h ObjFW/OFHMAC.h * * @brief A class which provides methods to calculate an HMAC. */ OF_SUBCLASSING_RESTRICTED @interface OFHMAC: OFObject { Class _hashClass; bool _allowsSwappableMemory; id _Nullable _outerHash, _innerHash; id _Nullable _outerHashCopy, _innerHashCopy; bool _calculated; } /** * @brief The class for the cryptographic hash used by the HMAC. */ @property (readonly, nonatomic) Class hashClass; /** * @brief Whether data may be stored in swappable memory. */ @property (readonly, nonatomic) bool allowsSwappableMemory; /** * @brief A buffer containing the HMAC. * * The size of the buffer depends on the hash used. The buffer is part of the * receiver's memory pool. * * @throw OFHashNotCalculatedException The HMAC hasn't been calculated yet */ @property (readonly, nonatomic) const unsigned char *digest OF_RETURNS_INNER_POINTER; /** * @brief The size of the digest. */ @property (readonly, nonatomic) size_t digestSize; /** * @brief Returns a new OFHMAC with the specified hashing algorithm. * * @param hashClass The class of the hashing algorithm * @param allowsSwappableMemory Whether data may be stored in swappable memory * @return A new, autoreleased OFHMAC */ + (instancetype)HMACWithHashClass: (Class )hashClass allowsSwappableMemory: (bool)allowsSwappableMemory; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initialized an already allocated OFHMAC with the specified hashing * algorithm. * * @param hashClass The class of the hashing algorithm * @param allowsSwappableMemory Whether data may be stored in swappable memory * @return An initialized OFHMAC */ - (instancetype)initWithHashClass: (Class )hashClass allowsSwappableMemory: (bool)allowsSwappableMemory OF_DESIGNATED_INITIALIZER; /** * @brief Sets the key for the HMAC. * * @note This resets the HMAC! * * @warning This invalidates any pointer previously returned by @ref digest. If * you are still interested in the previous digest, you need to memcpy * it yourself before calling @ref setKey:length:! * * @param key The key for the HMAC * @param length The length of the key for the HMAC */ - (void)setKey: (const void *)key length: (size_t)length; /** * @brief Adds a buffer to the HMAC to be calculated. * * @param buffer The buffer which should be included into the calculation * @param length The length of the buffer * @throw OFHashAlreadyCalculatedException The HMAC has already been calculated */ - (void)updateWithBuffer: (const void *)buffer length: (size_t)length; /** * @brief Performs the final calculation of the HMAC. * * @throw OFHashAlreadyCalculatedException The HMAC has already been calculated */ - (void)calculate; /** * @brief Resets the HMAC so that it can be calculated for a new message. * * @note This does not reset the key so that a new HMAC with the same key can * be calculated efficiently. If you want to reset both, use * @ref setKey:length:. * * @warning This invalidates any pointer previously returned by @ref digest. If * you are still interested in the previous digest, you need to memcpy * it yourself before calling @ref reset! */ - (void)reset; /** * @brief This is like @ref reset, but also zeroes the hashed key and all state. * * @warning After calling this, you *must* set a new key before reusing the * HMAC! */ - (void)zero; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFHMAC.m000066400000000000000000000116331465614216400145450ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFHMAC.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFHashNotCalculatedException.h" #import "OFInvalidArgumentException.h" @implementation OFHMAC @synthesize hashClass = _hashClass; @synthesize allowsSwappableMemory = _allowsSwappableMemory; + (instancetype)HMACWithHashClass: (Class )class allowsSwappableMemory: (bool)allowsSwappableMemory { return [[[self alloc] initWithHashClass: class allowsSwappableMemory: allowsSwappableMemory] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithHashClass: (Class )class allowsSwappableMemory: (bool)allowsSwappableMemory { self = [super init]; _hashClass = class; _allowsSwappableMemory = allowsSwappableMemory; return self; } - (void)dealloc { [_outerHash release]; [_innerHash release]; [_outerHashCopy release]; [_innerHashCopy release]; [super dealloc]; } - (void)setKey: (const void *)key length: (size_t)length { void *pool = objc_autoreleasePoolPush(); size_t blockSize = [_hashClass blockSize]; OFSecureData *outerKeyPad = [OFSecureData dataWithCount: blockSize allowsSwappableMemory: _allowsSwappableMemory]; OFSecureData *innerKeyPad = [OFSecureData dataWithCount: blockSize allowsSwappableMemory: _allowsSwappableMemory]; unsigned char *outerKeyPadItems = outerKeyPad.mutableItems; unsigned char *innerKeyPadItems = innerKeyPad.mutableItems; [_outerHash release]; [_innerHash release]; [_outerHashCopy release]; [_innerHashCopy release]; _outerHash = _innerHash = _outerHashCopy = _innerHashCopy = nil; @try { if (length > blockSize) { id hash = [_hashClass hashWithAllowsSwappableMemory: _allowsSwappableMemory]; [hash updateWithBuffer: key length: length]; [hash calculate]; length = hash.digestSize; if OF_UNLIKELY (length > blockSize) length = blockSize; memcpy(outerKeyPadItems, hash.digest, length); memcpy(innerKeyPadItems, hash.digest, length); } else { memcpy(outerKeyPadItems, key, length); memcpy(innerKeyPadItems, key, length); } memset(outerKeyPadItems + length, 0, blockSize - length); memset(innerKeyPadItems + length, 0, blockSize - length); for (size_t i = 0; i < blockSize; i++) { outerKeyPadItems[i] ^= 0x5C; innerKeyPadItems[i] ^= 0x36; } _outerHash = [[_hashClass hashWithAllowsSwappableMemory: _allowsSwappableMemory] retain]; _innerHash = [[_hashClass hashWithAllowsSwappableMemory: _allowsSwappableMemory] retain]; [_outerHash updateWithBuffer: outerKeyPadItems length: blockSize]; [_innerHash updateWithBuffer: innerKeyPadItems length: blockSize]; } @catch (id e) { [outerKeyPad zero]; [innerKeyPad zero]; @throw e; } objc_autoreleasePoolPop(pool); _outerHashCopy = [_outerHash copy]; _innerHashCopy = [_innerHash copy]; _calculated = false; } - (void)updateWithBuffer: (const void *)buffer length: (size_t)length { if (_innerHash == nil) @throw [OFInvalidArgumentException exception]; if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; [_innerHash updateWithBuffer: buffer length: length]; } - (void)calculate { if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; if (_outerHash == nil || _innerHash == nil) @throw [OFInvalidArgumentException exception]; [_innerHash calculate]; [_outerHash updateWithBuffer: _innerHash.digest length: _innerHash.digestSize]; [_outerHash calculate]; _calculated = true; } - (const unsigned char *)digest { if (!_calculated) @throw [OFHashNotCalculatedException exceptionWithObject: self]; return _outerHash.digest; } - (size_t)digestSize { return [_hashClass digestSize]; } - (void)reset { [_outerHash release]; [_innerHash release]; _outerHash = _innerHash = nil; _outerHash = [_outerHashCopy copy]; _innerHash = [_innerHashCopy copy]; _calculated = false; } - (void)zero { [_outerHash release]; [_innerHash release]; [_outerHashCopy release]; [_innerHashCopy release]; _outerHash = _innerHash = _outerHashCopy = _innerHashCopy = nil; _calculated = false; } @end objfw-1.1.6/src/OFHTTPClient.h000066400000000000000000000206171465614216400157500ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif OF_ASSUME_NONNULL_BEGIN @class OFDictionary OF_GENERIC(KeyType, ObjectType); @class OFHTTPClient; @class OFHTTPRequest; @class OFHTTPResponse; @class OFIRI; @class OFStream; @class OFTCPSocket; @class OFTLSStream; /** * @protocol OFHTTPClientDelegate OFHTTPClient.h ObjFW/OFHTTPClient.h * * @brief A delegate for OFHTTPClient. */ @protocol OFHTTPClientDelegate /** * @brief A callback which is called when an @ref OFHTTPClient performed a * request. * * @param client The OFHTTPClient which performed the request * @param request The request the OFHTTPClient performed * @param response The response to the request performed, or nil on error * @param exception An exception if the request failed, or nil on success */ - (void)client: (OFHTTPClient *)client didPerformRequest: (OFHTTPRequest *)request response: (nullable OFHTTPResponse *)response exception: (nullable id)exception; @optional /** * @brief A callback which is called when an @ref OFHTTPClient creates a TCP * socket. * * This can be used to tell the socket about a SOCKS5 proxy it should use for * this connection. * * @param client The OFHTTPClient that created a TCP socket * @param TCPSocket The socket created by the OFHTTPClient * @param request The request for which the TCP socket was created */ - (void)client: (OFHTTPClient *)client didCreateTCPSocket: (OFTCPSocket *)TCPSocket request: (OFHTTPRequest *)request; /** * @brief A callback which is called when an @ref OFHTTPClient creates a TLS * stream. * * This can be used to tell the TLS stream about a client certificate it should * use before performing the TLS handshake. * * @param client The OFHTTPClient that created a TLS stream * @param TLSStream The TLS stream created by the OFHTTPClient * @param request The request for which the TLS stream was created */ - (void)client: (OFHTTPClient *)client didCreateTLSStream: (OFTLSStream *)TLSStream request: (OFHTTPRequest *)request; /** * @brief A callback which is called when an @ref OFHTTPClient wants to send * the body for a request. * * @param client The OFHTTPClient that wants to send the body * @param requestBody A stream into which the body of the request should be * written * @param request The request for which the OFHTTPClient wants to send the body */ - (void)client: (OFHTTPClient *)client wantsRequestBody: (OFStream *)requestBody request: (OFHTTPRequest *)request; /** * @brief A callback which is called when an @ref OFHTTPClient received headers. * * @param client The OFHTTPClient which received the headers * @param headers The headers received * @param statusCode The status code received * @param request The request for which the headers and status code have been * received */ - (void)client: (OFHTTPClient *)client didReceiveHeaders: (OFDictionary OF_GENERIC(OFString *, OFString *) *)headers statusCode: (short)statusCode request: (OFHTTPRequest *)request; /** * @brief A callback which is called when an @ref OFHTTPClient wants to follow * a redirect. * * If you want to get the headers and data for each redirect, set the number of * redirects to 0 and perform a new OFHTTPClient for each redirect. However, * this callback will not be called then and you have to look at the status code * to detect a redirect. * * This callback will only be called if the OFHTTPClient will follow a * redirect. If the maximum number of redirects has been reached already, this * callback will not be called. * * @param client The OFHTTPClient which wants to follow a redirect * @param IRI The IRI to which it will follow a redirect * @param statusCode The status code for the redirection * @param request The request for which the OFHTTPClient wants to redirect. * You are allowed to change the request's headers from this * callback and they will be used when following the redirect * (e.g. to set the cookies for the new IRI), however, keep in * mind that this will change the request you originally passed. * @param response The response indicating the redirect * @return A boolean whether the OFHTTPClient should follow the redirect */ - (bool)client: (OFHTTPClient *)client shouldFollowRedirectToIRI: (OFIRI *)IRI statusCode: (short)statusCode request: (OFHTTPRequest *)request response: (OFHTTPResponse *)response; @end /** * @class OFHTTPClient OFHTTPClient.h ObjFW/OFHTTPClient.h * * @brief A class for performing HTTP requests. */ OF_SUBCLASSING_RESTRICTED @interface OFHTTPClient: OFObject { #ifdef OF_HTTP_CLIENT_M @public #endif OFObject *_Nullable _delegate; bool _allowsInsecureRedirects, _inProgress; OFStream *_Nullable _stream; OFIRI *_Nullable _lastIRI; bool _lastWasHEAD; OFHTTPResponse *_Nullable _lastResponse; } /** * @brief The delegate of the HTTP request. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) OFObject *delegate; /** * @brief Whether the HTTP client allows redirects from HTTPS to HTTP. */ @property (nonatomic) bool allowsInsecureRedirects; /** * @brief Creates a new OFHTTPClient. * * @return A new, autoreleased OFHTTPClient */ + (instancetype)client; /** * @brief Synchronously performs the specified HTTP request. * * @note You must not change the delegate while a synchronous request is * running! If you want to change the delegate during the request, * perform an asynchronous request instead! * * @param request The request to perform * @return The OFHTTPResponse for the request * @throw OFHTTPRequestFailedException The HTTP request failed * @throw OFInvalidServerResponseException The server sent an invalid response * @throw OFUnsupportedVersionException The server responded in an unsupported * version * @throw OFAlreadyOpenException The client is already performing a request */ - (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request; /** * @brief Synchronously performs the specified HTTP request. * * @note You must not change the delegate while a synchronous request is * running! If you want to change the delegate during the request, * perform an asynchronous request instead! * * @param request The request to perform * @param redirects The maximum number of redirects after which no further * attempt is done to follow the redirect, but instead the * redirect is treated as an OFHTTPResponse * @return The OFHTTPResponse for the request * @throw OFHTTPRequestFailedException The HTTP request failed * @throw OFInvalidServerResponseException The server sent an invalid response * @throw OFUnsupportedVersionException The server responded in an unsupported * version * @throw OFAlreadyOpenException The client is already performing a request */ - (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request redirects: (unsigned int)redirects; /** * @brief Asynchronously performs the specified HTTP request. * * @param request The request to perform * @throw OFAlreadyOpenException The client is already performing a request */ - (void)asyncPerformRequest: (OFHTTPRequest *)request; /** * @brief Asynchronously performs the specified HTTP request. * * @param request The request to perform * @param redirects The maximum number of redirects after which no further * attempt is done to follow the redirect, but instead the * redirect is treated as an OFHTTPResponse * @throw OFAlreadyOpenException The client is already performing a request */ - (void)asyncPerformRequest: (OFHTTPRequest *)request redirects: (unsigned int)redirects; /** * @brief Closes connections that are still open due to keep-alive. */ - (void)close; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFHTTPClient.m000066400000000000000000000746121465614216400157610ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #define OF_HTTP_CLIENT_M #include "config.h" #include #include #import "OFHTTPClient.h" #import "OFData.h" #import "OFDictionary.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" #import "OFIRI.h" #import "OFKernelEventObserver.h" #import "OFNumber.h" #import "OFRunLoop.h" #import "OFString.h" #import "OFTCPSocket.h" #import "OFTLSStream.h" #import "OFAlreadyOpenException.h" #import "OFHTTPRequestFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFInvalidServerResponseException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" #import "OFUnsupportedVersionException.h" #import "OFWriteFailedException.h" static const unsigned int defaultRedirects = 10; OF_DIRECT_MEMBERS @interface OFHTTPClientRequestHandler: OFObject { @public OFHTTPClient *_client; OFHTTPRequest *_request; unsigned int _redirects; bool _firstLine; OFString *_version; short _status; OFMutableDictionary OF_GENERIC(OFString *, OFString *) *_serverHeaders; } - (instancetype)initWithClient: (OFHTTPClient *)client request: (OFHTTPRequest *)request redirects: (unsigned int)redirects; - (void)start; - (void)closeAndReconnect; @end OF_DIRECT_MEMBERS @interface OFHTTPClientRequestBodyStream: OFStream { OFHTTPClientRequestHandler *_handler; OFStream *_stream; bool _chunked; unsigned long long _toWrite; bool _atEndOfStream; } - (instancetype)initWithHandler: (OFHTTPClientRequestHandler *)handler stream: (OFStream *)stream; @end OF_DIRECT_MEMBERS @interface OFHTTPClientResponse: OFHTTPResponse { OFStream *_stream; bool _hasContentLength, _chunked, _keepAlive; bool _atEndOfStream, _setAtEndOfStream; long long _toRead; } @property (nonatomic, setter=of_setKeepAlive:) bool of_keepAlive; - (instancetype)initWithStream: (OFStream *)stream; @end OF_DIRECT_MEMBERS @interface OFHTTPClientSyncPerformer: OFObject { OFHTTPClient *_client; OFObject *_delegate; OFHTTPResponse *_response; } - (instancetype)initWithClient: (OFHTTPClient *)client; - (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request redirects: (unsigned int)redirects; @end static OFString * constructRequestString(OFHTTPRequest *request) { void *pool = objc_autoreleasePoolPush(); OFHTTPRequestMethod method = request.method; OFIRI *IRI = request.IRI.IRIByAddingPercentEncodingForUnicodeCharacters; OFString *path; OFString *user = IRI.user, *password = IRI.password; OFMutableString *requestString; OFMutableDictionary OF_GENERIC(OFString *, OFString *) *headers; bool hasContentLength, chunked; OFEnumerator OF_GENERIC(OFString *) *keyEnumerator, *objectEnumerator; OFString *key, *object; if (IRI.path.length > 0) path = IRI.percentEncodedPath; else path = @"/"; requestString = [OFMutableString stringWithFormat: @"%@ %@", OFHTTPRequestMethodString(method), path]; if (IRI.query != nil) { [requestString appendString: @"?"]; [requestString appendString: IRI.percentEncodedQuery]; } [requestString appendString: @" HTTP/"]; [requestString appendString: request.protocolVersionString]; [requestString appendString: @"\r\n"]; headers = [[request.headers mutableCopy] autorelease]; if (headers == nil) headers = [OFMutableDictionary dictionary]; if ([headers objectForKey: @"Host"] == nil) { OFNumber *port = IRI.port; if (port != nil) { OFString *host = [OFString stringWithFormat: @"%@:%@", IRI.percentEncodedHost, port]; [headers setObject: host forKey: @"Host"]; } else [headers setObject: IRI.percentEncodedHost forKey: @"Host"]; } if ((user.length > 0 || password.length > 0) && [headers objectForKey: @"Authorization"] == nil) { OFMutableData *authorizationData = [OFMutableData data]; OFString *authorization; [authorizationData addItems: user.UTF8String count: user.UTF8StringLength]; [authorizationData addItem: ":"]; [authorizationData addItems: password.UTF8String count: password.UTF8StringLength]; authorization = [OFString stringWithFormat: @"Basic %@", authorizationData.stringByBase64Encoding]; [headers setObject: authorization forKey: @"Authorization"]; } if ([headers objectForKey: @"User-Agent"] == nil) [headers setObject: @"OFHTTPClient (ObjFW's HTTP client class " @")" forKey: @"User-Agent"]; if (request.protocolVersion.major == 1 && request.protocolVersion.minor == 0 && [headers objectForKey: @"Connection"] == nil) [headers setObject: @"keep-alive" forKey: @"Connection"]; hasContentLength = ([headers objectForKey: @"Content-Length"] != nil); chunked = [[headers objectForKey: @"Transfer-Encoding"] isEqual: @"chunked"]; if ((hasContentLength || chunked) && [headers objectForKey: @"Content-Type"] == nil) [headers setObject: @"application/x-www-form-" @"urlencoded; charset=UTF-8" forKey: @"Content-Type"]; keyEnumerator = [headers keyEnumerator]; objectEnumerator = [headers objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) [requestString appendFormat: @"%@: %@\r\n", key, object]; [requestString appendString: @"\r\n"]; [requestString retain]; objc_autoreleasePoolPop(pool); return [requestString autorelease]; } static OF_INLINE void normalizeKey(char *str_) { unsigned char *str = (unsigned char *)str_; bool firstLetter = true; while (*str != '\0') { if (!OFASCIIIsAlpha(*str)) { firstLetter = true; str++; continue; } *str = (firstLetter ? OFASCIIToUpper(*str) : OFASCIIToLower(*str)); firstLetter = false; str++; } } static bool defaultShouldFollow(OFHTTPRequestMethod method, short statusCode) { bool follow; /* * 301, 302 and 307 should only redirect with user confirmation if the * request method is not GET or HEAD. Asking the delegate and getting * true returned is considered user confirmation. */ if (method == OFHTTPRequestMethodGet || method == OFHTTPRequestMethodHead) follow = true; /* 303 should always be redirected and converted to a GET request. */ else if (statusCode == 303) follow = true; else follow = false; return follow; } @implementation OFHTTPClientRequestHandler - (instancetype)initWithClient: (OFHTTPClient *)client request: (OFHTTPRequest *)request redirects: (unsigned int)redirects { self = [super init]; @try { _client = [client retain]; _request = [request retain]; _redirects = redirects; _serverHeaders = [[OFMutableDictionary alloc] init]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_client release]; [_request release]; [_version release]; [_serverHeaders release]; [super dealloc]; } - (void)raiseException: (id)exception { [_client close]; _client->_inProgress = false; [_client->_delegate client: _client didPerformRequest: _request response: nil exception: exception]; } - (void)createResponseWithStreamOrThrow: (OFStream *)stream { OFIRI *IRI = _request.IRI; OFHTTPClientResponse *response; OFString *connectionHeader; bool keepAlive; OFString *location; id exception; response = [[[OFHTTPClientResponse alloc] initWithStream: stream] autorelease]; response.protocolVersionString = _version; response.statusCode = _status; response.headers = _serverHeaders; connectionHeader = [_serverHeaders objectForKey: @"Connection"]; if ([_version isEqual: @"1.1"]) { if (connectionHeader != nil) keepAlive = [connectionHeader isEqual: @"close"]; else keepAlive = true; } else { if (connectionHeader != nil) keepAlive = ([connectionHeader caseInsensitiveCompare: @"keep-alive"] == OFOrderedSame); else keepAlive = false; } if (keepAlive) { response.of_keepAlive = true; _client->_stream = [stream retain]; _client->_lastIRI = [IRI copy]; _client->_lastWasHEAD = (_request.method == OFHTTPRequestMethodHead); _client->_lastResponse = [response retain]; } if (_redirects > 0 && (_status == 301 || _status == 302 || _status == 303 || _status == 307) && (location = [_serverHeaders objectForKey: @"Location"]) != nil) { bool follow = true; OFIRI *newIRI; OFString *newIRIScheme; newIRI = [OFIRI IRIWithString: location relativeToIRI: IRI]; newIRIScheme = newIRI.scheme; if ([newIRIScheme caseInsensitiveCompare: @"http"] != OFOrderedSame && [newIRIScheme caseInsensitiveCompare: @"https"] != OFOrderedSame) follow = false; if (!_client->_allowsInsecureRedirects && [IRI.scheme caseInsensitiveCompare: @"https"] == OFOrderedSame && [newIRIScheme caseInsensitiveCompare: @"http"] == OFOrderedSame) follow = false; if (follow && [_client->_delegate respondsToSelector: @selector(client:shouldFollowRedirectToIRI:statusCode: request:response:)]) follow = [_client->_delegate client: _client shouldFollowRedirectToIRI: newIRI statusCode: _status request: _request response: response]; else if (follow) follow = defaultShouldFollow(_request.method, _status); if (follow) { OFDictionary OF_GENERIC(OFString *, OFString *) *headers = _request.headers; OFHTTPRequest *newRequest = [[_request copy] autorelease]; OFMutableDictionary *newHeaders = [[headers mutableCopy] autorelease]; if (![newIRI.host isEqual: IRI.host]) [newHeaders removeObjectForKey: @"Host"]; /* * 303 means the request should be converted to a GET * request before redirection. This also means stripping * the entity of the request. */ if (_status == 303) { for (OFString *key in headers) if ([key hasPrefix: @"Content-"] || [key hasPrefix: @"Transfer-"]) [newHeaders removeObjectForKey: key]; newRequest.method = OFHTTPRequestMethodGet; } newRequest.IRI = newIRI; newRequest.headers = newHeaders; _client->_inProgress = false; [_client asyncPerformRequest: newRequest redirects: _redirects - 1]; return; } } _client->_inProgress = false; if (_status / 100 != 2) exception = [OFHTTPRequestFailedException exceptionWithRequest: _request response: response]; else exception = nil; [_client->_delegate performSelector: @selector(client:didPerformRequest: response:exception:) withObject: _client withObject: _request withObject: response withObject: exception afterDelay: 0]; } - (void)createResponseWithStream: (OFStream *)stream { @try { [self createResponseWithStreamOrThrow: stream]; } @catch (id e) { [self raiseException: e]; } } - (bool)handleFirstLine: (OFString *)line { long long status; /* * It's possible that the write succeeds on a connection that is * keep-alive, but the connection has already been closed by the remote * end due to a timeout. In this case, we need to reconnect. */ if (line == nil) { [self closeAndReconnect]; return false; } if (![line hasPrefix: @"HTTP/"] || line.length < 9 || [line characterAtIndex: 8] != ' ') @throw [OFInvalidServerResponseException exception]; _version = [[line substringWithRange: OFMakeRange(5, 3)] copy]; if (![_version isEqual: @"1.0"] && ![_version isEqual: @"1.1"]) @throw [OFUnsupportedVersionException exceptionWithVersion: _version]; status = [line substringWithRange: OFMakeRange(9, 3)].longLongValue; if (status < 0 || status > 599) @throw [OFInvalidServerResponseException exception]; _status = (short)status; return true; } - (bool)handleServerHeader: (OFString *)line stream: (OFStream *)stream { OFString *key, *value, *old; const char *lineC, *tmp; char *keyC; if (line == nil) @throw [OFInvalidServerResponseException exception]; if (line.length == 0) { [_serverHeaders makeImmutable]; if ([_client->_delegate respondsToSelector: @selector(client: didReceiveHeaders:statusCode:request:)]) [_client->_delegate client: _client didReceiveHeaders: _serverHeaders statusCode: _status request: _request]; stream.delegate = nil; [self performSelector: @selector(createResponseWithStream:) withObject: stream afterDelay: 0]; return false; } lineC = line.UTF8String; if ((tmp = strchr(lineC, ':')) == NULL) @throw [OFInvalidServerResponseException exception]; keyC = OFAllocMemory(tmp - lineC + 1, 1); memcpy(keyC, lineC, tmp - lineC); keyC[tmp - lineC] = '\0'; normalizeKey(keyC); @try { key = [OFString stringWithUTF8StringNoCopy: keyC freeWhenDone: true]; } @catch (id e) { OFFreeMemory(keyC); @throw e; } do { tmp++; } while (*tmp == ' '); value = [OFString stringWithUTF8String: tmp]; old = [_serverHeaders objectForKey: key]; if (old != nil) value = [old stringByAppendingFormat: @",%@", value]; [_serverHeaders setObject: value forKey: key]; return true; } - (bool)stream: (OFStream *)stream didReadLine: (OFString *)line exception: (id)exception { bool ret; if (exception != nil) { if ([exception isKindOfClass: [OFInvalidEncodingException class]]) exception = [OFInvalidServerResponseException exception]; [self raiseException: exception]; return false; } @try { if (_firstLine) { _firstLine = false; ret = [self handleFirstLine: line]; } else ret = [self handleServerHeader: line stream: stream]; } @catch (id e) { [self raiseException: e]; ret = false; } return ret; } - (OFString *)stream: (OFStream *)stream didWriteString: (OFString *)string encoding: (OFStringEncoding)encoding bytesWritten: (size_t)bytesWritten exception: (id)exception { OFDictionary OF_GENERIC(OFString *, OFString *) *headers; bool chunked; if (exception != nil) { if ([exception isKindOfClass: [OFWriteFailedException class]] && ([exception errNo] == ECONNRESET || [exception errNo] == EPIPE)) { /* In case a keep-alive connection timed out */ [self closeAndReconnect]; return nil; } [self raiseException: exception]; return nil; } _firstLine = true; headers = _request.headers; chunked = [[headers objectForKey: @"Transfer-Encoding"] isEqual: @"chunked"]; if (chunked || [headers objectForKey: @"Content-Length"] != nil) { stream.delegate = nil; OFStream *requestBody = [[[OFHTTPClientRequestBodyStream alloc] initWithHandler: self stream: stream] autorelease]; if ([_client->_delegate respondsToSelector: @selector(client:wantsRequestBody:request:)]) [_client->_delegate client: _client wantsRequestBody: requestBody request: _request]; } else [stream asyncReadLine]; return nil; } - (void)handleStream: (OFStream *)stream { /* * As a work around for a bug with split packets in lighttpd when using * HTTPS, we construct the complete request in a buffer string and then * send it all at once. * * We do not use the streams's write buffer in case we need to resend * the entire request (e.g. in case a keep-alive connection timed out). */ @try { [stream asyncWriteString: constructRequestString(_request)]; } @catch (id e) { [self raiseException: e]; return; } } - (void)socket: (OFTCPSocket *)sock didConnectToHost: (OFString *)host port: (uint16_t)port exception: (id)exception { if (exception != nil) { [self raiseException: exception]; return; } if ([_client->_delegate respondsToSelector: @selector(client:didCreateTCPSocket:request:)]) [_client->_delegate client: _client didCreateTCPSocket: sock request: _request]; if ([_request.IRI.scheme caseInsensitiveCompare: @"https"] == OFOrderedSame) { OFTLSStream *stream; @try { stream = [OFTLSStream streamWithStream: sock]; } @catch (OFNotImplementedException *e) { [self raiseException: [OFUnsupportedProtocolException exceptionWithIRI: _request.IRI]]; return; } if ([_client->_delegate respondsToSelector: @selector(client:didCreateTLSStream:request:)]) [_client->_delegate client: _client didCreateTLSStream: stream request: _request]; stream.delegate = self; [stream asyncPerformClientHandshakeWithHost: _request.IRI .IRIByAddingPercentEncodingForUnicodeCharacters.host]; } else { sock.delegate = self; [self performSelector: @selector(handleStream:) withObject: sock afterDelay: 0]; } } - (void)stream: (OFTLSStream *)stream didPerformClientHandshakeWithHost: (OFString *)host exception: (id)exception { if (exception != nil) { [self raiseException: exception]; return; } [self performSelector: @selector(handleStream:) withObject: stream afterDelay: 0]; } - (void)start { OFIRI *IRI = _request.IRI; OFStream *stream; /* Can we reuse the last socket? */ if (_client->_stream != nil && !_client->_stream.atEndOfStream && [_client->_lastIRI.scheme isEqual: IRI.scheme] && [_client->_lastIRI.host isEqual: IRI.host] && (_client->_lastIRI.port == IRI.port || [_client->_lastIRI.port isEqual: IRI.port]) && (_client->_lastWasHEAD || _client->_lastResponse.atEndOfStream)) { /* * Set _stream to nil, so that in case of an error it won't be * reused. If everything is successful, we set _stream again * at the end. */ stream = [_client->_stream autorelease]; _client->_stream = nil; [_client->_lastIRI release]; _client->_lastIRI = nil; [_client->_lastResponse release]; _client->_lastResponse = nil; stream.delegate = self; [self performSelector: @selector(handleStream:) withObject: stream afterDelay: 0]; } else [self closeAndReconnect]; } - (void)closeAndReconnect { @try { OFIRI *IRI = _request.IRI.IRIByAddingPercentEncodingForUnicodeCharacters; OFTCPSocket *sock; uint16_t port; OFNumber *IRIPort; [_client close]; sock = [OFTCPSocket socket]; if ([IRI.scheme caseInsensitiveCompare: @"https"] == OFOrderedSame) port = 443; else port = 80; IRIPort = IRI.port; if (IRIPort != nil) port = IRIPort.unsignedShortValue; sock.delegate = self; [sock asyncConnectToHost: IRI.host port: port]; } @catch (id e) { [self raiseException: e]; } } @end @implementation OFHTTPClientRequestBodyStream - (instancetype)initWithHandler: (OFHTTPClientRequestHandler *)handler stream: (OFStream *)stream { self = [super init]; @try { OFDictionary OF_GENERIC(OFString *, OFString *) *headers; OFString *transferEncoding, *contentLengthString; _handler = [handler retain]; _stream = [stream retain]; headers = _handler->_request.headers; transferEncoding = [headers objectForKey: @"Transfer-Encoding"]; _chunked = [transferEncoding isEqual: @"chunked"]; contentLengthString = [headers objectForKey: @"Content-Length"]; if (contentLengthString != nil) { if (_chunked || contentLengthString.length == 0) @throw [OFInvalidArgumentException exception]; _toWrite = contentLengthString.unsignedLongLongValue; } else if (!_chunked) @throw [OFInvalidArgumentException exception]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_stream != nil) [self close]; [_handler release]; [super dealloc]; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { /* TODO: Use non-blocking writes */ if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; /* * We must not send a chunk of size 0, as that would end the body. We * always ignore writing 0 bytes to still allow writing 0 bytes after * the end of stream. */ if (length == 0) return 0; if (_atEndOfStream) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: ENOTCONN]; if (_chunked) [_stream writeFormat: @"%zX\r\n", length]; else if (length > _toWrite) @throw [OFOutOfRangeException exception]; [_stream writeBuffer: buffer length: length]; if (_chunked) [_stream writeString: @"\r\n"]; if (!_chunked) { _toWrite -= length; if (_toWrite == 0) _atEndOfStream = true; } return length; } - (bool)lowlevelIsAtEndOfStream { return _atEndOfStream; } - (void)close { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (_chunked) [_stream writeString: @"0\r\n\r\n"]; else if (_toWrite > 0) @throw [OFTruncatedDataException exception]; _stream.delegate = _handler; [_stream asyncReadLine]; [_stream release]; _stream = nil; [super close]; } - (int)fileDescriptorForWriting { return ((OFStream *)_stream) .fileDescriptorForWriting; } @end @implementation OFHTTPClientResponse @synthesize of_keepAlive = _keepAlive; - (instancetype)initWithStream: (OFStream *)stream { self = [super init]; _stream = [stream retain]; return self; } - (void)dealloc { if (_stream != nil) [self close]; [super dealloc]; } - (void)setHeaders: (OFDictionary *)headers { OFString *contentLength; super.headers = headers; _chunked = [[headers objectForKey: @"Transfer-Encoding"] isEqual: @"chunked"]; contentLength = [headers objectForKey: @"Content-Length"]; if (contentLength != nil) { if (_chunked || contentLength.length == 0) @throw [OFInvalidServerResponseException exception]; _hasContentLength = true; @try { unsigned long long toRead = contentLength.unsignedLongLongValue; if (toRead > LLONG_MAX) @throw [OFOutOfRangeException exception]; _toRead = (long long)toRead; } @catch (OFInvalidFormatException *e) { @throw [OFInvalidServerResponseException exception]; } } } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (!_hasContentLength && !_chunked) return [_stream readIntoBuffer: buffer length: length]; if (_atEndOfStream) return 0; if (_stream.atEndOfStream) @throw [OFTruncatedDataException exception]; /* Content-Length */ if (!_chunked) { size_t ret; if (length > (unsigned long long)_toRead) length = (size_t)_toRead; ret = [_stream readIntoBuffer: buffer length: length]; if (ret > length) @throw [OFOutOfRangeException exception]; _toRead -= ret; if (_toRead == 0) _atEndOfStream = true; return ret; } /* Chunked */ if (_toRead == -2) { char tmp[2]; switch ([_stream readIntoBuffer: tmp length: 2]) { case 2: _toRead++; if (tmp[1] != '\n') @throw [OFInvalidServerResponseException exception]; case 1: _toRead++; if (tmp[0] != '\r') @throw [OFInvalidServerResponseException exception]; } if (_setAtEndOfStream && _toRead == 0) _atEndOfStream = true; return 0; } else if (_toRead == -1) { char tmp; if ([_stream readIntoBuffer: &tmp length: 1] == 1) { _toRead++; if (tmp != '\n') @throw [OFInvalidServerResponseException exception]; } if (_setAtEndOfStream && _toRead == 0) _atEndOfStream = true; return 0; } else if (_toRead > 0) { if (length > (unsigned long long)_toRead) length = (size_t)_toRead; length = [_stream readIntoBuffer: buffer length: length]; _toRead -= length; if (_toRead == 0) _toRead = -2; return length; } else { void *pool = objc_autoreleasePoolPush(); OFString *line; size_t pos; @try { line = [_stream tryReadLine]; } @catch (OFInvalidEncodingException *e) { @throw [OFInvalidServerResponseException exception]; } if (line == nil) return 0; pos = [line rangeOfString: @";"].location; if (pos != OFNotFound) line = [line substringToIndex: pos]; if (line.length < 1) { /* * We have read the empty string because the stream is * at end of stream. */ if (_stream.atEndOfStream && pos == OFNotFound) @throw [OFTruncatedDataException exception]; else @throw [OFInvalidServerResponseException exception]; } @try { unsigned long long toRead = [line unsignedLongLongValueWithBase: 16]; if (toRead > LLONG_MAX) @throw [OFOutOfRangeException exception]; _toRead = (long long)toRead; } @catch (OFInvalidFormatException *e) { @throw [OFInvalidServerResponseException exception]; } if (_toRead == 0) { _setAtEndOfStream = true; _toRead = -2; } objc_autoreleasePoolPop(pool); return 0; } } - (bool)lowlevelIsAtEndOfStream { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (!_hasContentLength && !_chunked) return _stream.atEndOfStream; return _atEndOfStream; } - (int)fileDescriptorForReading { if (_stream == nil) return -1; return ((OFStream *)_stream) .fileDescriptorForReading; } - (bool)lowlevelHasDataInReadBuffer { return _stream.hasDataInReadBuffer; } - (void)close { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; _atEndOfStream = false; [_stream release]; _stream = nil; [super close]; } @end @implementation OFHTTPClientSyncPerformer - (instancetype)initWithClient: (OFHTTPClient *)client { self = [super init]; @try { _client = [client retain]; _delegate = client.delegate; _client.delegate = self; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { _client.delegate = _delegate; [_client release]; [super dealloc]; } - (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request redirects: (unsigned int)redirects { [_client asyncPerformRequest: request redirects: redirects]; [[OFRunLoop currentRunLoop] run]; return _response; } - (void)client: (OFHTTPClient *)client didPerformRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response exception: (id)exception { if (exception != nil) { /* * Restore the delegate - we're giving up, but not reaching the * release of the autorelease pool that contains us, so * resetting it via -[dealloc] might be too late. */ _client.delegate = _delegate; @throw exception; } [[OFRunLoop currentRunLoop] stop]; [_response release]; _response = [response retain]; [_delegate client: client didPerformRequest: request response: response exception: nil]; } - (void)client: (OFHTTPClient *)client didCreateTCPSocket: (OFTCPSocket *)TCPSocket request: (OFHTTPRequest *)request { if ([_delegate respondsToSelector: @selector(client:didCreateTCPSocket:request:)]) [_delegate client: client didCreateTCPSocket: TCPSocket request: request]; } - (void)client: (OFHTTPClient *)client didCreateTLSStream: (OFTLSStream *)TLSStream request: (OFHTTPRequest *)request { if ([_delegate respondsToSelector: @selector(client:didCreateTLSStream:request:)]) [_delegate client: client didCreateTLSStream: TLSStream request: request]; } - (void)client: (OFHTTPClient *)client wantsRequestBody: (OFStream *)body request: (OFHTTPRequest *)request { if ([_delegate respondsToSelector: @selector(client:wantsRequestBody:request:)]) [_delegate client: client wantsRequestBody: body request: request]; } - (void)client: (OFHTTPClient *)client didReceiveHeaders: (OFDictionary OF_GENERIC(OFString *, OFString *) *)headers statusCode: (short)statusCode request: (OFHTTPRequest *)request { if ([_delegate respondsToSelector: @selector(client:didReceiveHeaders:statusCode:request:)]) [_delegate client: client didReceiveHeaders: headers statusCode: statusCode request: request]; } - (bool)client: (OFHTTPClient *)client shouldFollowRedirectToIRI: (OFIRI *)IRI statusCode: (short)statusCode request: (OFHTTPRequest *)request response: (OFHTTPResponse *)response { if ([_delegate respondsToSelector: @selector( client:shouldFollowRedirectToIRI:statusCode:request:response:)]) return [_delegate client: client shouldFollowRedirectToIRI: IRI statusCode: statusCode request: request response: response]; else return defaultShouldFollow(request.method, statusCode); } @end @implementation OFHTTPClient @synthesize delegate = _delegate; @synthesize allowsInsecureRedirects = _allowsInsecureRedirects; + (instancetype)client { return [[[self alloc] init] autorelease]; } - (void)dealloc { [self close]; [super dealloc]; } - (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request { return [self performRequest: request redirects: defaultRedirects]; } - (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request redirects: (unsigned int)redirects { void *pool = objc_autoreleasePoolPush(); OFHTTPClientSyncPerformer *syncPerformer = [[[OFHTTPClientSyncPerformer alloc] initWithClient: self] autorelease]; OFHTTPResponse *response = [syncPerformer performRequest: request redirects: redirects]; [response retain]; objc_autoreleasePoolPop(pool); return [response autorelease]; } - (void)asyncPerformRequest: (OFHTTPRequest *)request { [self asyncPerformRequest: request redirects: defaultRedirects]; } - (void)asyncPerformRequest: (OFHTTPRequest *)request redirects: (unsigned int)redirects { void *pool = objc_autoreleasePoolPush(); OFIRI *IRI = request.IRI; OFString *scheme = IRI.scheme; if ([scheme caseInsensitiveCompare: @"http"] != OFOrderedSame && [scheme caseInsensitiveCompare: @"https"] != OFOrderedSame) @throw [OFUnsupportedProtocolException exceptionWithIRI: IRI]; if (_inProgress) @throw [OFAlreadyOpenException exceptionWithObject: self]; _inProgress = true; [[[[OFHTTPClientRequestHandler alloc] initWithClient: self request: request redirects: redirects] autorelease] start]; objc_autoreleasePoolPop(pool); } - (void)close { [_stream release]; _stream = nil; [_lastIRI release]; _lastIRI = nil; [_lastResponse release]; _lastResponse = nil; } @end objfw-1.1.6/src/OFHTTPCookie.h000066400000000000000000000074431465614216400157450ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFDate; @class OFDictionary OF_GENERIC(KeyType, ObjectType); @class OFIRI; @class OFMutableArray OF_GENERIC(ObjectType); /** * @class OFHTTPCookie OFHTTPCookie.h ObjFW/OFHTTPCookie.h * * @brief A class for storing and manipulating HTTP cookies. */ OF_SUBCLASSING_RESTRICTED @interface OFHTTPCookie: OFObject { OFString *_name, *_value, *_domain, *_path; OFDate *_Nullable _expires; bool _secure, _HTTPOnly; OFMutableArray OF_GENERIC(OFString *) *_extensions; } /** * @brief The name of the cookie. */ @property (copy, nonatomic) OFString *name; /** * @brief The value of the cookie. */ @property (copy, nonatomic) OFString *value; /** * @brief The domain for the cookie. */ @property (copy, nonatomic) OFString *domain; /** * @brief The path for the cookie. */ @property (copy, nonatomic) OFString *path; /** * @brief The date when the cookie expires. */ @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFDate *expires; /** * @brief Whether the cookie is only to be used with HTTPS. */ @property (nonatomic, getter=isSecure) bool secure; /** * @brief Whether the cookie is only to be accessed through HTTP. */ @property (nonatomic, getter=isHTTPOnly) bool HTTPOnly; /** * @brief An array of other attributes. */ @property (readonly, nonatomic) OFMutableArray OF_GENERIC(OFString *) *extensions; /** * @brief Parses the specified response header fields for the specified IRI and * returns an array of cookies. * * @param headerFields The response header fields to parse * @param IRI The IRI for the response header fields to parse * @return An array of cookies * @throw OFInvalidFormatException The specified response header has an invalid * format */ + (OFArray OF_GENERIC(OFHTTPCookie *) *)cookiesWithResponseHeaderFields: (OFDictionary OF_GENERIC(OFString *, OFString *) *)headerFields forIRI: (OFIRI *)IRI; /** * @brief Returns the request header fields for the specified cookies. * * @param cookies The cookies to return the request header fields for * @return The request header fields for the specified cookies */ + (OFDictionary *)requestHeaderFieldsWithCookies: (OFArray OF_GENERIC(OFHTTPCookie *) *)cookies; /** * @brief Create a new cookie with the specified name and value. * * @param name The name of the cookie * @param value The value of the cookie * @param domain The domain for the cookie * @return A new, autoreleased OFHTTPCookie */ + (instancetype)cookieWithName: (OFString *)name value: (OFString *)value domain: (OFString *)domain; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated new cookie with the specified name * and value. * * @param name The name of the cookie * @param value The value of the cookie * @param domain The domain for the cookie * @return An initialized OFHTTPCookie */ - (instancetype)initWithName: (OFString *)name value: (OFString *)value domain: (OFString *)domain OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFHTTPCookie.m000066400000000000000000000244541465614216400157530ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFHTTPCookie.h" #import "OFArray.h" #import "OFDate.h" #import "OFDictionary.h" #import "OFIRI.h" #import "OFInvalidFormatException.h" static void handleAttribute(OFHTTPCookie *cookie, OFString *name, OFString *value) { OFString *lowercaseName = name.lowercaseString; if (value != nil) { if ([lowercaseName isEqual: @"expires"]) { OFDate *date = [OFDate dateWithDateString: value format: @"%a, %d %b %Y %H:%M:%S %z"]; cookie.expires = date; } else if ([lowercaseName isEqual: @"max-age"]) { OFDate *date = [OFDate dateWithTimeIntervalSinceNow: value.unsignedLongLongValue]; cookie.expires = date; } else if ([lowercaseName isEqual: @"domain"]) cookie.domain = value; else if ([lowercaseName isEqual: @"path"]) cookie.path = value; else [cookie.extensions addObject: [OFString stringWithFormat: @"%@=%@", name, value]]; } else { if ([lowercaseName isEqual: @"secure"]) cookie.secure = true; else if ([lowercaseName isEqual: @"httponly"]) cookie.HTTPOnly = true; else if (name.length > 0) [cookie.extensions addObject: name]; } } @implementation OFHTTPCookie @synthesize name = _name, value = _value, domain = _domain, path = _path; @synthesize expires = _expires, secure = _secure, HTTPOnly = _HTTPOnly; @synthesize extensions = _extensions; + (OFArray OF_GENERIC(OFHTTPCookie *) *)cookiesWithResponseHeaderFields: (OFDictionary OF_GENERIC(OFString *, OFString *) *)headerFields forIRI: (OFIRI *)IRI { OFMutableArray OF_GENERIC(OFHTTPCookie *) *ret = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); OFString *string = [headerFields objectForKey: @"Set-Cookie"]; OFString *domain = IRI.IRIByAddingPercentEncodingForUnicodeCharacters .host; const OFUnichar *characters = string.characters; size_t length = string.length, last = 0; enum { statePreName, stateName, stateExpectValue, stateValue, stateQuotedValue, statePostQuotedValue, statePreAttrName, stateAttrName, stateAttrValue } state = statePreName; OFString *name = nil, *value = nil; for (size_t i = 0; i < length; i++) { switch (state) { case statePreName: if (characters[i] != ' ') { state = stateName; last = i; i--; } break; case stateName: if (characters[i] == '=') { name = [string substringWithRange: OFMakeRange(last, i - last)]; state = stateExpectValue; } break; case stateExpectValue: if (characters[i] == '"') { state = stateQuotedValue; last = i + 1; } else { state = stateValue; last = i; } i--; break; case stateValue: if (characters[i] == ';' || characters[i] == ',') { value = [string substringWithRange: OFMakeRange(last, i - last)]; [ret addObject: [OFHTTPCookie cookieWithName: name value: value domain: domain]]; state = (characters[i] == ';' ? statePreAttrName : statePreName); } break; case stateQuotedValue: if (characters[i] == '"') { value = [string substringWithRange: OFMakeRange(last, i - last)]; [ret addObject: [OFHTTPCookie cookieWithName: name value: value domain: domain]]; state = statePostQuotedValue; } break; case statePostQuotedValue: if (characters[i] == ';') state = statePreAttrName; else if (characters[i] == ',') state = statePreName; else @throw [OFInvalidFormatException exception]; break; case statePreAttrName: if (characters[i] != ' ') { state = stateAttrName; last = i; i--; } break; case stateAttrName: if (characters[i] == '=') { name = [string substringWithRange: OFMakeRange(last, i - last)]; state = stateAttrValue; last = i + 1; } else if (characters[i] == ';' || characters[i] == ',') { name = [string substringWithRange: OFMakeRange(last, i - last)]; handleAttribute(ret.lastObject, name, nil); state = (characters[i] == ';' ? statePreAttrName : statePreName); } break; case stateAttrValue: if (characters[i] == ';' || characters[i] == ',') { value = [string substringWithRange: OFMakeRange(last, i - last)]; /* * Expires often contains a comma, even though * the comma is used as a separator for * concatenating headers as per RFC 2616, * meaning RFC 6265 contradicts RFC 2616. * Solve this by special casing this. */ if (characters[i] == ',' && [name caseInsensitiveCompare: @"expires"] == OFOrderedSame && value.length == 3 && ([value isEqual: @"Mon"] || [value isEqual: @"Tue"] || [value isEqual: @"Wed"] || [value isEqual: @"Thu"] || [value isEqual: @"Fri"] || [value isEqual: @"Sat"] || [value isEqual: @"Sun"])) break; handleAttribute(ret.lastObject, name, value); state = (characters[i] == ';' ? statePreAttrName : statePreName); } break; } } switch (state) { case statePreName: case statePostQuotedValue: case statePreAttrName: break; case stateName: case stateQuotedValue: @throw [OFInvalidFormatException exception]; break; case stateValue: value = [string substringWithRange: OFMakeRange(last, length - last)]; [ret addObject: [OFHTTPCookie cookieWithName: name value: value domain: domain]]; break; /* We end up here if the cookie is just foo= */ case stateExpectValue: [ret addObject: [OFHTTPCookie cookieWithName: name value: @"" domain: domain]]; break; case stateAttrName: if (last != length) { name = [string substringWithRange: OFMakeRange(last, length - last)]; handleAttribute(ret.lastObject, name, nil); } break; case stateAttrValue: value = [string substringWithRange: OFMakeRange(last, length - last)]; handleAttribute(ret.lastObject, name, value); break; } objc_autoreleasePoolPop(pool); return ret; } + (OFDictionary *)requestHeaderFieldsWithCookies: (OFArray OF_GENERIC(OFHTTPCookie *) *)cookies { OFDictionary OF_GENERIC(OFString *, OFString *) *ret; void *pool; OFMutableString *cookieString; bool first = true; if (cookies.count == 0) return [OFDictionary dictionary]; pool = objc_autoreleasePoolPush(); cookieString = [OFMutableString string]; for (OFHTTPCookie *cookie in cookies) { if OF_UNLIKELY (first) first = false; else [cookieString appendString: @"; "]; [cookieString appendString: cookie.name]; [cookieString appendString: @"="]; [cookieString appendString: cookie.value]; } ret = [[OFDictionary alloc] initWithObject: cookieString forKey: @"Cookie"]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } + (instancetype)cookieWithName: (OFString *)name value: (OFString *)value domain: (OFString *)domain { return [[[self alloc] initWithName: name value: value domain: domain] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name value: (OFString *)value domain: (OFString *)domain { self = [super init]; @try { _name = [name copy]; _value = [value copy]; _domain = [domain copy]; _path = @"/"; _extensions = [[OFMutableArray alloc] init]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_name release]; [_value release]; [_domain release]; [_path release]; [_expires release]; [_extensions release]; [super dealloc]; } - (bool)isEqual: (id)object { OFHTTPCookie *cookie; if (object == self) return true; if (![object isKindOfClass: [OFHTTPCookie class]]) return false; cookie = object; if (![cookie->_name isEqual: _name]) return false; if (![cookie->_value isEqual: _value]) return false; if (cookie->_domain != _domain && ![cookie->_domain isEqual: _domain]) return false; if (cookie->_path != _path && ![cookie->_path isEqual: _path]) return false; if (cookie->_expires != _expires && ![cookie->_expires isEqual: _expires]) return false; if (cookie->_secure != _secure) return false; if (cookie->_HTTPOnly != _HTTPOnly) return false; if (cookie->_extensions != _extensions && ![cookie->_extensions isEqual: _extensions]) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddHash(&hash, _value.hash); OFHashAddHash(&hash, _domain.hash); OFHashAddHash(&hash, _path.hash); OFHashAddHash(&hash, _expires.hash); OFHashAddByte(&hash, _secure); OFHashAddByte(&hash, _HTTPOnly); OFHashAddHash(&hash, _extensions.hash); OFHashFinalize(&hash); return hash; } - (id)copy { OFHTTPCookie *copy = [[OFHTTPCookie alloc] initWithName: _name value: _value domain: _domain]; @try { copy->_path = [_path copy]; copy->_expires = [_expires copy]; copy->_secure = _secure; copy->_HTTPOnly = _HTTPOnly; [copy->_extensions addObjectsFromArray: _extensions]; } @catch (id e) { [copy release]; @throw e; } return copy; } - (OFString *)description { OFMutableString *ret = [OFMutableString stringWithFormat: @"%@=%@", _name, _value]; void *pool = objc_autoreleasePoolPush(); [ret appendFormat: @"; Domain=%@; Path=%@", _domain, _path]; if (_expires != nil) [ret appendString: [_expires dateStringWithFormat: @"; Expires=%a, %d %b %Y " @"%H:%M:%S +0000"]]; if (_secure) [ret appendString: @"; Secure"]; if (_HTTPOnly) [ret appendString: @"; HTTPOnly"]; if (_extensions.count > 0) [ret appendFormat: @"; %@", [_extensions componentsJoinedByString: @"; "]]; objc_autoreleasePoolPop(pool); [ret makeImmutable]; return ret; } @end objfw-1.1.6/src/OFHTTPCookieManager.h000066400000000000000000000050131465614216400172270ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFHTTPCookie; @class OFIRI; @class OFMutableArray OF_GENERIC(ObjectType); /** * @class OFHTTPCookieManager OFHTTPCookieManager.h ObjFW/OFHTTPCookieManager.h * * @brief A class for managing cookies for multiple domains. */ OF_SUBCLASSING_RESTRICTED @interface OFHTTPCookieManager: OFObject { OFMutableArray OF_GENERIC(OFHTTPCookie *) *_cookies; } /** * @brief All cookies known to the cookie manager. */ @property (readonly, nonatomic) OFArray OF_GENERIC(OFHTTPCookie *) *cookies; /** * @brief Create a new cookie manager. * * @return A new, autoreleased OFHTTPCookieManager */ + (instancetype)manager; /** * @brief Adds the specified cookie for the specified IRI. * * @warning This modifies the cookie (e.g. it sets the domain if it is unset)! * If you do not want this, pass a copy! * * @param cookie The cookie to add to the manager * @param IRI The IRI for which the cookie should be added */ - (void)addCookie: (OFHTTPCookie *)cookie forIRI: (OFIRI *)IRI; /** * @brief Adds the specified cookies for the specified IRI. * * @warning This modifies the cookies (e.g. it sets the domain if it is unset)! * If you do not want this, pass copies! * * @param cookies An array of cookies to add to the manager * @param IRI The IRI for which the cookies should be added */ - (void)addCookies: (OFArray OF_GENERIC(OFHTTPCookie *) *)cookies forIRI: (OFIRI *)IRI; /** * @brief Returns the cookies for the specified IRI. * * @param IRI The IRI for which the cookies should be returned * @return The cookies for the specified IRI */ - (OFArray OF_GENERIC(OFHTTPCookie *) *)cookiesForIRI: (OFIRI *)IRI; /** * @brief Purges all expired cookies. */ - (void)purgeExpiredCookies; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFHTTPCookieManager.m000066400000000000000000000104651465614216400172430ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFHTTPCookieManager.h" #import "OFArray.h" #import "OFDate.h" #import "OFHTTPCookie.h" #import "OFIRI.h" @implementation OFHTTPCookieManager + (instancetype)manager { return [[[self alloc] init] autorelease]; } - (instancetype)init { self = [super init]; @try { _cookies = [[OFMutableArray alloc] init]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_cookies release]; [super dealloc]; } - (OFArray OF_GENERIC(OFHTTPCookie *) *)cookies { return [[_cookies copy] autorelease]; } - (void)addCookie: (OFHTTPCookie *)cookie forIRI: (OFIRI *)IRI { void *pool = objc_autoreleasePoolPush(); OFString *cookieDomain, *IRIHost; size_t i; IRI = IRI.IRIByAddingPercentEncodingForUnicodeCharacters; if (![cookie.path hasPrefix: @"/"]) cookie.path = @"/"; if (cookie.secure && [IRI.scheme caseInsensitiveCompare: @"https"] != OFOrderedSame) { objc_autoreleasePoolPop(pool); return; } cookieDomain = cookie.domain.lowercaseString; cookie.domain = cookieDomain; IRIHost = IRI.host.lowercaseString; if (![cookieDomain isEqual: IRIHost]) { IRIHost = [@"." stringByAppendingString: IRIHost]; if (![cookieDomain hasSuffix: IRIHost]) { objc_autoreleasePoolPop(pool); return; } } i = 0; for (OFHTTPCookie *iter in _cookies) { if ([iter.name isEqual: cookie.name] && [iter.domain isEqual: cookie.domain] && [iter.path isEqual: cookie.path]) { [_cookies replaceObjectAtIndex: i withObject: cookie]; objc_autoreleasePoolPop(pool); return; } i++; } [_cookies addObject: cookie]; objc_autoreleasePoolPop(pool); } - (void)addCookies: (OFArray OF_GENERIC(OFHTTPCookie *) *)cookies forIRI: (OFIRI *)IRI { for (OFHTTPCookie *cookie in cookies) [self addCookie: cookie forIRI: IRI]; } - (OFArray OF_GENERIC(OFHTTPCookie *) *)cookiesForIRI: (OFIRI *)IRI { OFMutableArray *ret = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); IRI = IRI.IRIByAddingPercentEncodingForUnicodeCharacters; for (OFHTTPCookie *cookie in _cookies) { void *pool2; OFDate *expires; OFString *cookieDomain, *IRIHost, *cookiePath, *IRIPath; bool match; expires = cookie.expires; if (expires != nil && expires.timeIntervalSinceNow <= 0) continue; if (cookie.secure && [IRI.scheme caseInsensitiveCompare: @"https"] != OFOrderedSame) continue; pool2 = objc_autoreleasePoolPush(); cookieDomain = cookie.domain.lowercaseString; IRIHost = IRI.host.lowercaseString; if ([cookieDomain hasPrefix: @"."]) { if ([IRIHost hasSuffix: cookieDomain]) match = true; else { cookieDomain = [cookieDomain substringFromIndex: 1]; match = [cookieDomain isEqual: IRIHost]; } } else match = [cookieDomain isEqual: IRIHost]; if (!match) { objc_autoreleasePoolPop(pool2); continue; } cookiePath = cookie.path; IRIPath = IRI.path; if (![cookiePath isEqual: @"/"]) { if ([cookiePath isEqual: IRIPath]) match = true; else { if (![cookiePath hasSuffix: @"/"]) cookiePath = [cookiePath stringByAppendingString: @"/"]; match = [IRIPath hasPrefix: cookiePath]; } if (!match) { objc_autoreleasePoolPop(pool2); continue; } } [ret addObject: cookie]; } [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } - (void)purgeExpiredCookies { for (size_t i = 0, count = _cookies.count; i < count; i++) { OFDate *expires = [[_cookies objectAtIndex: i] expires]; if (expires != nil && expires.timeIntervalSinceNow <= 0) { [_cookies removeObjectAtIndex: i]; i--; count--; continue; } } } @end objfw-1.1.6/src/OFHTTPIRIHandler.h000066400000000000000000000015251465614216400164500ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFIRIHandler.h" OF_ASSUME_NONNULL_BEGIN @interface OFHTTPIRIHandler: OFIRIHandler @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFHTTPIRIHandler.m000066400000000000000000000023651465614216400164600ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFHTTPIRIHandler.h" #import "OFHTTPClient.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" @implementation OFHTTPIRIHandler - (OFStream *)openItemAtIRI: (OFIRI *)IRI mode: (OFString *)mode { void *pool = objc_autoreleasePoolPush(); OFHTTPClient *client = [OFHTTPClient client]; OFHTTPRequest *request = [OFHTTPRequest requestWithIRI: IRI]; OFHTTPResponse *response = [client performRequest: request]; [response retain]; objc_autoreleasePoolPop(pool); return [response autorelease]; } @end objfw-1.1.6/src/OFHTTPRequest.h000066400000000000000000000125561465614216400161650ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFSocket.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @class OFData; @class OFDictionary OF_GENERIC(KeyType, ObjectType); @class OFIRI; @class OFString; /** @file */ /** * @brief The type of an HTTP request. */ typedef enum { /** OPTIONS */ OFHTTPRequestMethodOptions, /** GET */ OFHTTPRequestMethodGet, /** HEAD */ OFHTTPRequestMethodHead, /** POST */ OFHTTPRequestMethodPost, /** PUT */ OFHTTPRequestMethodPut, /** DELETE */ OFHTTPRequestMethodDelete, /** TRACE */ OFHTTPRequestMethodTrace, /** CONNECT */ OFHTTPRequestMethodConnect } OFHTTPRequestMethod; /** * @struct OFHTTPRequestProtocolVersion OFHTTPRequest.h ObjFW/OFHTTPRequest.h * * @brief The HTTP version of the HTTP request. */ typedef struct OF_BOXABLE OFHTTPRequestProtocolVersion { /** The major of the HTTP version */ unsigned char major; /** The minor of the HTTP version */ unsigned char minor; } OFHTTPRequestProtocolVersion; /** * @class OFHTTPRequest OFHTTPRequest.h ObjFW/OFHTTPRequest.h * * @brief A class for storing HTTP requests. */ OF_SUBCLASSING_RESTRICTED @interface OFHTTPRequest: OFObject { OFIRI *_IRI; OFHTTPRequestMethod _method; OFHTTPRequestProtocolVersion _protocolVersion; OFDictionary OF_GENERIC(OFString *, OFString *) *_Nullable _headers; OFSocketAddress _remoteAddress; bool _hasRemoteAddress; } /** * @brief The IRI of the HTTP request. */ @property (copy, nonatomic) OFIRI *IRI; /** * @brief The protocol version of the HTTP request. * * @throw OFUnsupportedVersionException The specified version cannot be set * because it is not supported */ @property (nonatomic) OFHTTPRequestProtocolVersion protocolVersion; /** * @brief The protocol version of the HTTP request as a string. * * @throw OFUnsupportedVersionException The specified version cannot be set * because it is not supported * @throw OFInvalidFormatException The specified version cannot be set because * it is not in a valid format */ @property (copy, nonatomic) OFString *protocolVersionString; /** * @brief The request method of the HTTP request. */ @property (nonatomic) OFHTTPRequestMethod method; /** * @brief The headers for the HTTP request. */ @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFDictionary OF_GENERIC(OFString *, OFString *) *headers; /** * @brief The remote address from which the request originates. * * @note The setter creates a copy of the remote address. */ @property OF_NULLABLE_PROPERTY (nonatomic) const OFSocketAddress *remoteAddress; /** * @brief Creates a new OFHTTPRequest with the specified IRI. * * @param IRI The IRI for the request * @return A new, autoreleased OFHTTPRequest */ + (instancetype)requestWithIRI: (OFIRI *)IRI; /** * @brief Initializes an already allocated OFHTTPRequest with the specified IRI. * * @param IRI The IRI for the request * @return An initialized OFHTTPRequest */ - (instancetype)initWithIRI: (OFIRI *)IRI; - (instancetype)init OF_UNAVAILABLE; @end #ifdef __cplusplus extern "C" { #endif /** * @brief Returns a string describing the specified request method. * * @param method The request method which should be described as a string * @return A string describing the specified request method */ extern OFString *_Nullable OFHTTPRequestMethodString( OFHTTPRequestMethod method); /** * @brief Returns the request method for the specified string. * * @param string The string for which the request method should be returned * @return The request method for the specified string * @throw OFInvalidFormatException The specified string is not a valid HTTP * request method */ extern OFHTTPRequestMethod OFHTTPRequestMethodParseString(OFString *string); /** * @brief Returns a C string describing the specified request method. * * @deprecated Use @ref OFHTTPRequestMethodString instead. * * @param method The request method which should be described as a C string * @return A C string describing the specified request method */ extern const char *_Nullable OFHTTPRequestMethodName(OFHTTPRequestMethod method) OF_DEPRECATED(ObjFW, 1, 1, "Use OFHTTPRequestMethodString instead"); /** * @brief Returns the request method for the specified string. * * @deprecated Use @ref OFHTTPRequestMethodParseString instead. * * @param string The string for which the request method should be returned * @return The request method for the specified string * @throw OFInvalidFormatException The specified string is not a valid HTTP * request method */ extern OFHTTPRequestMethod OFHTTPRequestMethodParseName(OFString *string) OF_DEPRECATED(ObjFW, 1, 1, "Use OFHTTPRequestMethodParseString instead"); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFHTTPRequest.m000066400000000000000000000150221465614216400161610ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFHTTPRequest.h" #import "OFArray.h" #import "OFData.h" #import "OFDictionary.h" #import "OFIRI.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "OFUnsupportedVersionException.h" OFString * OFHTTPRequestMethodString(OFHTTPRequestMethod method) { switch (method) { case OFHTTPRequestMethodOptions: return @"OPTIONS"; case OFHTTPRequestMethodGet: return @"GET"; case OFHTTPRequestMethodHead: return @"HEAD"; case OFHTTPRequestMethodPost: return @"POST"; case OFHTTPRequestMethodPut: return @"PUT"; case OFHTTPRequestMethodDelete: return @"DELETE"; case OFHTTPRequestMethodTrace: return @"TRACE"; case OFHTTPRequestMethodConnect: return @"CONNECT"; } return nil; } OFHTTPRequestMethod OFHTTPRequestMethodParseString(OFString *string) { if ([string isEqual: @"OPTIONS"]) return OFHTTPRequestMethodOptions; if ([string isEqual: @"GET"]) return OFHTTPRequestMethodGet; if ([string isEqual: @"HEAD"]) return OFHTTPRequestMethodHead; if ([string isEqual: @"POST"]) return OFHTTPRequestMethodPost; if ([string isEqual: @"PUT"]) return OFHTTPRequestMethodPut; if ([string isEqual: @"DELETE"]) return OFHTTPRequestMethodDelete; if ([string isEqual: @"TRACE"]) return OFHTTPRequestMethodTrace; if ([string isEqual: @"CONNECT"]) return OFHTTPRequestMethodConnect; @throw [OFInvalidFormatException exception]; } /* Deprecated */ const char * OFHTTPRequestMethodName(OFHTTPRequestMethod method) { return OFHTTPRequestMethodString(method).UTF8String; } /* Deprecated */ OFHTTPRequestMethod OFHTTPRequestMethodParseName(OFString *string) { return OFHTTPRequestMethodParseString(string); } @implementation OFHTTPRequest @synthesize IRI = _IRI, method = _method, headers = _headers; + (instancetype)requestWithIRI: (OFIRI *)IRI { return [[[self alloc] initWithIRI: IRI] autorelease]; } - (instancetype)initWithIRI: (OFIRI *)IRI { self = [super init]; @try { _IRI = [IRI copy]; _method = OFHTTPRequestMethodGet; _protocolVersion.major = 1; _protocolVersion.minor = 1; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_IRI release]; [_headers release]; [super dealloc]; } - (void)setRemoteAddress: (const OFSocketAddress *)remoteAddress { _hasRemoteAddress = (remoteAddress != NULL); if (_hasRemoteAddress) _remoteAddress = *remoteAddress; } - (const OFSocketAddress *)remoteAddress { if (_hasRemoteAddress) return &_remoteAddress; return NULL; } - (id)copy { OFHTTPRequest *copy = [[OFHTTPRequest alloc] initWithIRI: _IRI]; @try { copy->_method = _method; copy->_protocolVersion = _protocolVersion; copy.headers = _headers; copy.remoteAddress = self.remoteAddress; } @catch (id e) { [copy release]; @throw e; } return copy; } - (bool)isEqual: (id)object { OFHTTPRequest *request; if (object == self) return true; if (![object isKindOfClass: [OFHTTPRequest class]]) return false; request = object; if (request->_method != _method || request->_protocolVersion.major != _protocolVersion.major || request->_protocolVersion.minor != _protocolVersion.minor || ![request->_IRI isEqual: _IRI] || ![request->_headers isEqual: _headers]) return false; if (request.remoteAddress != self.remoteAddress && !OFSocketAddressEqual(request.remoteAddress, self.remoteAddress)) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddByte(&hash, _method); OFHashAddByte(&hash, _protocolVersion.major); OFHashAddByte(&hash, _protocolVersion.minor); OFHashAddHash(&hash, _IRI.hash); OFHashAddHash(&hash, _headers.hash); if (_hasRemoteAddress) OFHashAddHash(&hash, OFSocketAddressHash(&_remoteAddress)); OFHashFinalize(&hash); return hash; } - (void)setProtocolVersion: (OFHTTPRequestProtocolVersion)protocolVersion { if (protocolVersion.major != 1 || protocolVersion.minor > 1) @throw [OFUnsupportedVersionException exceptionWithVersion: [OFString stringWithFormat: @"%hhu.%hhu", protocolVersion.major, protocolVersion.minor]]; _protocolVersion = protocolVersion; } - (OFHTTPRequestProtocolVersion)protocolVersion { return _protocolVersion; } - (void)setProtocolVersionString: (OFString *)string { void *pool = objc_autoreleasePoolPush(); OFArray *components = [string componentsSeparatedByString: @"."]; unsigned long long major, minor; OFHTTPRequestProtocolVersion protocolVersion; if (components.count != 2) @throw [OFInvalidFormatException exception]; major = [components.firstObject unsignedLongLongValue]; minor = [components.lastObject unsignedLongLongValue]; if (major > UCHAR_MAX || minor > UCHAR_MAX) @throw [OFOutOfRangeException exception]; protocolVersion.major = (unsigned char)major; protocolVersion.minor = (unsigned char)minor; self.protocolVersion = protocolVersion; objc_autoreleasePoolPop(pool); } - (OFString *)protocolVersionString { return [OFString stringWithFormat: @"%hhu.%hhu", _protocolVersion.major, _protocolVersion.minor]; } - (OFString *)description { void *pool = objc_autoreleasePoolPush(); OFString *method = OFHTTPRequestMethodString(_method); OFString *indentedHeaders, *remoteAddress, *ret; indentedHeaders = [_headers.description stringByReplacingOccurrencesOfString: @"\n" withString: @"\n\t"]; if (_hasRemoteAddress) remoteAddress = OFSocketAddressString(&_remoteAddress); else remoteAddress = nil; ret = [[OFString alloc] initWithFormat: @"<%@:\n\tIRI = %@\n" @"\tMethod = %@\n" @"\tHeaders = %@\n" @"\tRemote address = %@\n" @">", self.class, _IRI, method, indentedHeaders, remoteAddress]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @end objfw-1.1.6/src/OFHTTPResponse.h000066400000000000000000000057521465614216400163330ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFStream.h" #import "OFHTTPRequest.h" OF_ASSUME_NONNULL_BEGIN @class OFDictionary OF_GENERIC(KeyType, ObjectType); @class OFArray OF_GENERIC(ObjectType); /** * @class OFHTTPResponse OFHTTPResponse.h ObjFW/OFHTTPResponse.h * * @brief A class for representing an HTTP request response as a stream. */ #if !defined(OF_HTTP_CLIENT_M) && !defined(OF_HTTP_SERVER_M) OF_SUBCLASSING_RESTRICTED #endif @interface OFHTTPResponse: OFStream { OFHTTPRequestProtocolVersion _protocolVersion; short _statusCode; OFDictionary OF_GENERIC(OFString *, OFString *) *_headers; } /** * @brief The protocol version of the HTTP request response. * * @throw OFUnsupportedVersionException The specified version cannot be set * because it is not supported */ @property (nonatomic) OFHTTPRequestProtocolVersion protocolVersion; /** * @brief The protocol version of the HTTP request response as a string. * * @throw OFUnsupportedVersionException The specified version cannot be set * because it is not supported * @throw OFInvalidFormatException The specified version cannot be set because * it is not in a valid format */ @property (copy, nonatomic) OFString *protocolVersionString; /** * @brief The status code of the response to the HTTP request. */ @property (nonatomic) short statusCode; /** * @brief The headers of the response to the HTTP request. */ @property (copy, nonatomic) OFDictionary OF_GENERIC(OFString *, OFString *) *headers; /** * @brief Read the response as a string, trying to detect the encoding and * falling back to the specified encoding if not detectable. * * @return The response as a string */ - (OFString *)readString; /** * @brief Read the response as a string, trying to detect the encoding and * falling back to the specified encoding if not detectable. * * @return The response as a string */ - (OFString *)readStringWithEncoding: (OFStringEncoding)encoding; @end #ifdef __cplusplus extern "C" { #endif /** * @brief Returns a description string for the specified HTTP status code. * * @param code The HTTP status code to return a description string for * @return A description string for the specified HTTP status code */ extern OFString *_Nonnull OFHTTPStatusCodeString(short code); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFHTTPResponse.m000066400000000000000000000202661465614216400163350ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFHTTPResponse.h" #import "OFString.h" #import "OFDictionary.h" #import "OFArray.h" #import "OFData.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedVersionException.h" OFString * OFHTTPStatusCodeString(short code) { switch (code) { case 100: return @"Continue"; case 101: return @"Switching Protocols"; case 200: return @"OK"; case 201: return @"Created"; case 202: return @"Accepted"; case 203: return @"Non-Authoritative Information"; case 204: return @"No Content"; case 205: return @"Reset Content"; case 206: return @"Partial Content"; case 300: return @"Multiple Choices"; case 301: return @"Moved Permanently"; case 302: return @"Found"; case 303: return @"See Other"; case 304: return @"Not Modified"; case 305: return @"Use Proxy"; case 307: return @"Temporary Redirect"; case 400: return @"Bad Request"; case 401: return @"Unauthorized"; case 402: return @"Payment Required"; case 403: return @"Forbidden"; case 404: return @"Not Found"; case 405: return @"Method Not Allowed"; case 406: return @"Not Acceptable"; case 407: return @"Proxy Authentication Required"; case 408: return @"Request Timeout"; case 409: return @"Conflict"; case 410: return @"Gone"; case 411: return @"Length Required"; case 412: return @"Precondition Failed"; case 413: return @"Request Entity Too Large"; case 414: return @"Request-URI Too Long"; case 415: return @"Unsupported Media Type"; case 416: return @"Requested Range Not Satisfiable"; case 417: return @"Expectation Failed"; case 500: return @"Internal Server Error"; case 501: return @"Not Implemented"; case 502: return @"Bad Gateway"; case 503: return @"Service Unavailable"; case 504: return @"Gateway Timeout"; case 505: return @"HTTP Version Not Supported"; default: return @"(unknown)"; } } static OFStringEncoding encodingForContentType(OFString *contentType) { const char *UTF8String = contentType.UTF8String; size_t last, length = contentType.UTF8StringLength; enum { stateType, stateBeforeParamName, stateParamName, stateParamValueOrQuote, stateParamValue, stateParamQuotedValue, stateAfterParamValue } state = stateType; OFString *name = nil, *value = nil, *charset = nil; OFStringEncoding ret; last = 0; for (size_t i = 0; i < length; i++) { switch (state) { case stateType: if (UTF8String[i] == ';') { state = stateBeforeParamName; last = i + 1; } break; case stateBeforeParamName: if (UTF8String[i] == ' ') last = i + 1; else { state = stateParamName; i--; } break; case stateParamName: if (UTF8String[i] == '=') { name = [OFString stringWithUTF8String: UTF8String + last length: i - last]; state = stateParamValueOrQuote; last = i + 1; } break; case stateParamValueOrQuote: if (UTF8String[i] == '"') { state = stateParamQuotedValue; last = i + 1; } else { state = stateParamValue; i--; } break; case stateParamValue: if (UTF8String[i] == ';') { value = [OFString stringWithUTF8String: UTF8String + last length: i - last]; value = value.stringByDeletingTrailingWhitespaces; if ([name isEqual: @"charset"]) charset = value; state = stateBeforeParamName; last = i + 1; } break; case stateParamQuotedValue: if (UTF8String[i] == '"') { value = [OFString stringWithUTF8String: UTF8String + last length: i - last]; if ([name isEqual: @"charset"]) charset = value; state = stateAfterParamValue; } break; case stateAfterParamValue: if (UTF8String[i] == ';') { state = stateBeforeParamName; last = i + 1; } else if (UTF8String[i] != ' ') return OFStringEncodingAutodetect; break; } } if (state == stateParamValue) { value = [OFString stringWithUTF8String: UTF8String + last length: length - last]; value = value.stringByDeletingTrailingWhitespaces; if ([name isEqual: @"charset"]) charset = value; } ret = OFStringEncodingAutodetect; if (charset != nil) { @try { ret = OFStringEncodingParseName(charset); } @catch (OFInvalidArgumentException *e) { } } return ret; } @implementation OFHTTPResponse @synthesize statusCode = _statusCode, headers = _headers; - (instancetype)init { self = [super init]; @try { _protocolVersion.major = 1; _protocolVersion.minor = 1; _headers = [[OFDictionary alloc] init]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_headers release]; [super dealloc]; } - (void)setProtocolVersion: (OFHTTPRequestProtocolVersion)protocolVersion { if (protocolVersion.major != 1 || protocolVersion.minor > 1) @throw [OFUnsupportedVersionException exceptionWithVersion: [OFString stringWithFormat: @"%hhu.%hhu", protocolVersion.major, protocolVersion.minor]]; _protocolVersion = protocolVersion; } - (OFHTTPRequestProtocolVersion)protocolVersion { return _protocolVersion; } - (void)setProtocolVersionString: (OFString *)string { void *pool = objc_autoreleasePoolPush(); OFArray *components = [string componentsSeparatedByString: @"."]; unsigned long long major, minor; OFHTTPRequestProtocolVersion protocolVersion; if (components.count != 2) @throw [OFInvalidFormatException exception]; major = [components.firstObject unsignedLongLongValue]; minor = [components.lastObject unsignedLongLongValue]; if (major > UCHAR_MAX || minor > UCHAR_MAX) @throw [OFOutOfRangeException exception]; protocolVersion.major = (unsigned char)major; protocolVersion.minor = (unsigned char)minor; self.protocolVersion = protocolVersion; objc_autoreleasePoolPop(pool); } - (OFString *)protocolVersionString { return [OFString stringWithFormat: @"%hhu.%hhu", _protocolVersion.major, _protocolVersion.minor]; } - (OFString *)readString { return [self readStringWithEncoding: OFStringEncodingAutodetect]; } - (OFString *)readStringWithEncoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFString *contentType, *contentLengthString, *ret; OFData *data; if (encoding == OFStringEncodingAutodetect && (contentType = [_headers objectForKey: @"Content-Type"]) != nil) encoding = encodingForContentType(contentType); if (encoding == OFStringEncodingAutodetect) encoding = OFStringEncodingUTF8; data = [self readDataUntilEndOfStream]; contentLengthString = [_headers objectForKey: @"Content-Length"]; if (contentLengthString != nil) { unsigned long long contentLength = contentLengthString.unsignedLongLongValue; if (contentLength > SIZE_MAX) @throw [OFOutOfRangeException exception]; if (data.count != (size_t)contentLength) @throw [OFTruncatedDataException exception]; } ret = [[OFString alloc] initWithCString: (char *)data.items encoding: encoding length: data.count]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)description { void *pool = objc_autoreleasePoolPush(); OFString *indentedHeaders, *ret; indentedHeaders = [_headers.description stringByReplacingOccurrencesOfString: @"\n" withString: @"\n\t"]; ret = [[OFString alloc] initWithFormat: @"<%@:\n" @"\tStatus code = %hd\n" @"\tHeaders = %@\n" @">", self.class, _statusCode, indentedHeaders]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @end objfw-1.1.6/src/OFHTTPServer.h000066400000000000000000000125051465614216400157750ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif OF_ASSUME_NONNULL_BEGIN @class OFArray; @class OFHTTPRequest; @class OFHTTPResponse; @class OFHTTPServer; @class OFStream; @class OFTCPSocket; /** * @protocol OFHTTPServerDelegate OFHTTPServer.h ObjFW/OFHTTPServer.h * * @brief A delegate for OFHTTPServer. */ @protocol OFHTTPServerDelegate /** * @brief This method is called when the HTTP server received a request from a * client. * * @param server The HTTP server which received the request * @param request The request the HTTP server received * @param requestBody A stream to read the body of the request from, if any * @param response The response the server will send to the client */ - (void)server: (OFHTTPServer *)server didReceiveRequest: (OFHTTPRequest *)request requestBody: (nullable OFStream *)requestBody response: (OFHTTPResponse *)response; @optional /** * @brief This method is called when the HTTP server's listening socket * encountered an exception. * * @param server The HTTP server which encountered an exception * @param exception The exception which occurred on the HTTP server's listening * socket * @return Whether to continue listening. If you return false, existing * connections will still be handled and you can start accepting new * connections again by calling @ref OFHTTPServer#start again. */ - (bool)server: (OFHTTPServer *)server didReceiveExceptionOnListeningSocket: (id)exception; /** * @brief This method is called when a socket for a client encountered an * exception. * * This can happen when the OFHTTPServer tries to properly close the * connection. If no headers have been sent yet, it will send headers, and if * chunked transfer encoding was used, it will send a chunk of size 0. However, * if the other end already closed the connection before that, this will raise * an exception. * * @param server The HTTP server which encountered an exception * @param response The response for which the exception occurred * @param request The request for the response for which the exception occurred * @param exception The exception which occurred */ - (void)server: (OFHTTPServer *)server didReceiveExceptionForResponse: (OFHTTPResponse *)response request: (OFHTTPRequest *)request exception: (id)exception; @end /** * @class OFHTTPServer OFHTTPServer.h ObjFW/OFHTTPServer.h * * @brief A class for creating a simple HTTP server inside of applications. */ OF_SUBCLASSING_RESTRICTED @interface OFHTTPServer: OFObject { OFString *_Nullable _host; uint16_t _port; id _Nullable _delegate; OFString *_Nullable _name; OFTCPSocket *_Nullable _listeningSocket; #ifdef OF_HAVE_THREADS size_t _numberOfThreads, _nextThreadIndex; OFArray *_threadPool; #endif } /** * @brief The host on which the HTTP server will listen. * * @throw OFAlreadyOpenException The host could not be set because @ref start * had already been called */ @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *host; /** * @brief The port on which the HTTP server will listen. * * @throw OFAlreadyOpenException The port could not be set because @ref start * had already been called */ @property (nonatomic) uint16_t port; /** * @brief The delegate for the HTTP server. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id delegate; #ifdef OF_HAVE_THREADS /** * @brief The number of threads the OFHTTPServer should use. * * If this is larger than 1 (the default), one thread will be used to accept * incoming connections and all others will be used to handle connections. * * For maximum CPU utilization, set this to `[OFSystemInfo numberOfCPUs] + 1`. * * @throw OFAlreadyOpenException The number of threads could not be set because * @ref start had already been called */ @property (nonatomic) size_t numberOfThreads; #endif /** * @brief The server name the server presents to clients. * * Setting it to `nil` means no `Server` header will be sent, unless one is * specified in the response headers. */ @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *name; /** * @brief Creates a new HTTP server. * * @return A new HTTP server */ + (instancetype)server; /** * @brief Starts the HTTP server in the current thread's run loop. * * @throw OFAlreadyOpenException The server had already been started */ - (void)start; /** * @brief Stops the HTTP server, meaning it will not accept any new incoming * connections, but still handle existing connections until they are * finished or timed out. */ - (void)stop; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFHTTPServer.m000066400000000000000000000475311465614216400160110ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #define OF_HTTP_SERVER_M #include "config.h" #include #include #include #import "OFHTTPServer.h" #import "OFArray.h" #import "OFData.h" #import "OFDate.h" #import "OFDictionary.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" #import "OFIRI.h" #import "OFNumber.h" #import "OFSocket+Private.h" #import "OFTCPSocket.h" #import "OFThread.h" #import "OFTimer.h" #import "OFAlreadyOpenException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFNotOpenException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" #import "OFWriteFailedException.h" /* * FIXME: Key normalization replaces headers like "DNT" with "Dnt". * FIXME: Errors are not reported to the user. */ @interface OFHTTPServer () @end OF_DIRECT_MEMBERS @interface OFHTTPServerResponse: OFHTTPResponse { OFStreamSocket *_socket; OFHTTPServer *_server; OFHTTPRequest *_request; bool _chunked, _headersSent; } - (instancetype)initWithSocket: (OFStreamSocket *)sock server: (OFHTTPServer *)server request: (OFHTTPRequest *)request; @end OF_DIRECT_MEMBERS @interface OFHTTPServerConnection: OFObject { @public OFStreamSocket *_socket; OFHTTPServer *_server; OFTimer *_timer; enum { stateAwaitingProlog, stateParsingHeaders, stateSendResponse } _state; uint8_t _HTTPMinorVersion; OFHTTPRequestMethod _method; OFString *_host, *_path; uint16_t _port; OFMutableDictionary *_headers; size_t _contentLength; OFStream *_requestBody; } - (instancetype)initWithSocket: (OFStreamSocket *)sock server: (OFHTTPServer *)server; - (bool)parseProlog: (OFString *)line; - (bool)parseHeaders: (OFString *)line; - (bool)sendErrorAndClose: (short)statusCode; - (void)createResponse; @end OF_DIRECT_MEMBERS @interface OFHTTPServerRequestBodyStream: OFStream { OFStreamSocket *_socket; bool _chunked; long long _toRead; bool _atEndOfStream, _setAtEndOfStream; } - (instancetype)initWithSocket: (OFStreamSocket *)sock chunked: (bool)chunked contentLength: (unsigned long long)contentLength; @end #ifdef OF_HAVE_THREADS OF_DIRECT_MEMBERS @interface OFHTTPServerThread: OFThread - (void)stop; @end #endif static OFString * normalizedKey(OFString *key) { char *cString = _OFStrDup(key.UTF8String); unsigned char *tmp = (unsigned char *)cString; bool firstLetter = true; OFString *ret; while (*tmp != '\0') { if (!OFASCIIIsAlpha(*tmp)) { firstLetter = true; tmp++; continue; } *tmp = (firstLetter ? OFASCIIToUpper(*tmp) : OFASCIIToLower(*tmp)); firstLetter = false; tmp++; } @try { ret = [OFString stringWithUTF8StringNoCopy: cString freeWhenDone: true]; } @catch (id e) { OFFreeMemory(cString); @throw e; } return ret; } @implementation OFHTTPServerResponse - (instancetype)initWithSocket: (OFStreamSocket *)sock server: (OFHTTPServer *)server request: (OFHTTPRequest *)request { self = [super init]; _statusCode = 500; _socket = [sock retain]; _server = [server retain]; _request = [request retain]; return self; } - (void)dealloc { if (_socket != nil) [self close]; [_server release]; [_request release]; [super dealloc]; } - (void)of_sendHeaders { void *pool = objc_autoreleasePoolPush(); OFMutableDictionary OF_GENERIC(OFString *, OFString *) *headers; OFEnumerator *keyEnumerator, *valueEnumerator; OFString *key, *value; [_socket writeFormat: @"HTTP/%@ %hd %@\r\n", self.protocolVersionString, _statusCode, OFHTTPStatusCodeString(_statusCode)]; headers = [[_headers mutableCopy] autorelease]; if ([headers objectForKey: @"Date"] == nil) { OFString *date = [[OFDate date] dateStringWithFormat: @"%a, %d %b %Y %H:%M:%S GMT"]; [headers setObject: date forKey: @"Date"]; } if ([headers objectForKey: @"Server"] == nil) { OFString *name = _server.name; if (name != nil) [headers setObject: name forKey: @"Server"]; } keyEnumerator = [headers keyEnumerator]; valueEnumerator = [headers objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (value = [valueEnumerator nextObject]) != nil) [_socket writeFormat: @"%@: %@\r\n", key, value]; [_socket writeString: @"\r\n"]; _headersSent = true; _chunked = [[headers objectForKey: @"Transfer-Encoding"] isEqual: @"chunked"]; objc_autoreleasePoolPop(pool); } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { /* TODO: Use non-blocking writes */ void *pool; if (_socket == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (!_headersSent) [self of_sendHeaders]; if (!_chunked) { @try { [_socket writeBuffer: buffer length: length]; } @catch (OFWriteFailedException *e) { if (e.errNo == EWOULDBLOCK || e.errNo == EAGAIN) return e.bytesWritten; @throw e; } return length; } pool = objc_autoreleasePoolPush(); [_socket writeString: [OFString stringWithFormat: @"%zX\r\n", length]]; objc_autoreleasePoolPop(pool); [_socket writeBuffer: buffer length: length]; [_socket writeString: @"\r\n"]; return length; } - (void)close { if (_socket == nil) @throw [OFNotOpenException exceptionWithObject: self]; @try { if (!_headersSent) [self of_sendHeaders]; if (_chunked) [_socket writeString: @"0\r\n\r\n"]; } @catch (OFWriteFailedException *e) { id delegate = _server.delegate; if ([delegate respondsToSelector: @selector(server: didReceiveExceptionForResponse:request:exception:)]) [delegate server: _server didReceiveExceptionForResponse: self request: _request exception: e]; } [_socket release]; _socket = nil; [super close]; } - (int)fileDescriptorForWriting { if (_socket == nil) return -1; return _socket.fileDescriptorForWriting; } @end @implementation OFHTTPServerConnection - (instancetype)initWithSocket: (OFStreamSocket *)sock server: (OFHTTPServer *)server { self = [super init]; @try { _socket = [sock retain]; _server = [server retain]; _timer = [[OFTimer scheduledTimerWithTimeInterval: 10 target: _socket selector: @selector( cancelAsyncRequests) repeats: false] retain]; _state = stateAwaitingProlog; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_socket release]; [_server release]; [_timer invalidate]; [_timer release]; [_host release]; [_path release]; [_headers release]; [_requestBody release]; [super dealloc]; } - (bool)stream: (OFStream *)sock didReadLine: (OFString *)line exception: (id)exception { if (line == nil || exception != nil) return false; @try { switch (_state) { case stateAwaitingProlog: return [self parseProlog: line]; case stateParsingHeaders: return [self parseHeaders: line]; default: return false; } } @catch (OFWriteFailedException *e) { return false; } OFEnsure(0); } - (bool)parseProlog: (OFString *)line { OFString *method; OFMutableString *path; size_t pos; @try { OFString *version = [line substringWithRange: OFMakeRange(line.length - 9, 9)]; OFUnichar tmp; if (![version hasPrefix: @" HTTP/1."]) return [self sendErrorAndClose: 505]; tmp = [version characterAtIndex: 8]; if (tmp < '0' || tmp > '9') return [self sendErrorAndClose: 400]; _HTTPMinorVersion = (uint8_t)(tmp - '0'); } @catch (OFOutOfRangeException *e) { return [self sendErrorAndClose: 400]; } pos = [line rangeOfString: @" "].location; if (pos == OFNotFound) return [self sendErrorAndClose: 400]; method = [line substringToIndex: pos]; @try { _method = OFHTTPRequestMethodParseString(method); } @catch (OFInvalidArgumentException *e) { return [self sendErrorAndClose: 405]; } @try { OFRange range = OFMakeRange(pos + 1, line.length - pos - 10); path = [[[line substringWithRange: range] mutableCopy] autorelease]; } @catch (OFOutOfRangeException *e) { return [self sendErrorAndClose: 400]; } [path deleteEnclosingWhitespaces]; [path makeImmutable]; if (![path hasPrefix: @"/"]) return [self sendErrorAndClose: 400]; _headers = [[OFMutableDictionary alloc] init]; _path = [path copy]; _state = stateParsingHeaders; return true; } - (bool)parseHeaders: (OFString *)line { OFString *key, *value, *old; size_t pos; if (line.length == 0) { bool chunked = [[_headers objectForKey: @"Transfer-Encoding"] isEqual: @"chunked"]; OFString *contentLengthString = [_headers objectForKey: @"Content-Length"]; unsigned long long contentLength = 0; if (contentLengthString != nil) { if (chunked || contentLengthString.length == 0) return [self sendErrorAndClose: 400]; @try { contentLength = contentLengthString.unsignedLongLongValue; } @catch (OFInvalidFormatException *e) { return [self sendErrorAndClose: 400]; } } if (chunked || contentLengthString != nil) { [_requestBody release]; _requestBody = nil; _requestBody = [[OFHTTPServerRequestBodyStream alloc] initWithSocket: _socket chunked: chunked contentLength: contentLength]; [_timer invalidate]; [_timer release]; _timer = nil; } _state = stateSendResponse; [self createResponse]; return false; } pos = [line rangeOfString: @":"].location; if (pos == OFNotFound) return [self sendErrorAndClose: 400]; key = [line substringToIndex: pos]; value = [line substringFromIndex: pos + 1]; key = normalizedKey(key.stringByDeletingTrailingWhitespaces); value = value.stringByDeletingLeadingWhitespaces; old = [_headers objectForKey: key]; if (old != nil) value = [old stringByAppendingFormat: @",%@", value]; [_headers setObject: value forKey: key]; if ([key isEqual: @"Host"]) { pos = [value rangeOfString: @":" options: OFStringSearchBackwards].location; if (pos != OFNotFound) { [_host release]; _host = [[value substringToIndex: pos] retain]; @try { unsigned long long portTmp = [value substringFromIndex: pos + 1] .unsignedLongLongValue; if (portTmp < 1 || portTmp > UINT16_MAX) return [self sendErrorAndClose: 400]; _port = (uint16_t)portTmp; } @catch (OFInvalidFormatException *e) { return [self sendErrorAndClose: 400]; } } else { [_host release]; _host = [value retain]; _port = 80; } } return true; } - (bool)sendErrorAndClose: (short)statusCode { OFString *date = [[OFDate date] dateStringWithFormat: @"%a, %d %b %Y %H:%M:%S GMT"]; [_socket writeFormat: @"HTTP/1.1 %hd %@\r\n" @"Date: %@\r\n" @"Server: %@\r\n" @"\r\n", statusCode, OFHTTPStatusCodeString(statusCode), date, _server.name]; return false; } - (void)createResponse { void *pool = objc_autoreleasePoolPush(); OFMutableIRI *IRI; OFHTTPRequest *request; OFHTTPServerResponse *response; size_t pos; [_timer invalidate]; [_timer release]; _timer = nil; if (_host == nil || _port == 0) { if (_HTTPMinorVersion > 0) { [self sendErrorAndClose: 400]; return; } [_host release]; _host = [_server.host copy]; _port = [_server port]; } IRI = [OFMutableIRI IRIWithScheme: @"http"]; IRI.host = _host; if (_port != 80) IRI.port = [OFNumber numberWithUnsignedShort: _port]; @try { if ((pos = [_path rangeOfString: @"?"].location) != OFNotFound) { OFString *path, *query; path = [_path substringToIndex: pos]; query = [_path substringFromIndex: pos + 1]; IRI.percentEncodedPath = path; IRI.percentEncodedQuery = query; } else IRI.percentEncodedPath = _path; } @catch (OFInvalidFormatException *e) { objc_autoreleasePoolPop(pool); [self sendErrorAndClose: 400]; return; } [IRI makeImmutable]; request = [OFHTTPRequest requestWithIRI: IRI]; request.method = _method; request.protocolVersion = (OFHTTPRequestProtocolVersion){ 1, _HTTPMinorVersion }; request.headers = _headers; request.remoteAddress = _socket.remoteAddress; response = [[[OFHTTPServerResponse alloc] initWithSocket: _socket server: _server request: request] autorelease]; [_server.delegate server: _server didReceiveRequest: request requestBody: _requestBody response: response]; objc_autoreleasePoolPop(pool); } @end @implementation OFHTTPServerRequestBodyStream - (instancetype)initWithSocket: (OFStreamSocket *)sock chunked: (bool)chunked contentLength: (unsigned long long)contentLength { self = [super init]; @try { if (contentLength > LLONG_MAX) @throw [OFOutOfRangeException exception]; _socket = [sock retain]; _chunked = chunked; _toRead = (long long)contentLength; if (_chunked && _toRead > 0) @throw [OFInvalidArgumentException exception]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_socket != nil) [self close]; [super dealloc]; } - (bool)lowlevelIsAtEndOfStream { return _atEndOfStream; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { if (_socket == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (_atEndOfStream) return 0; if (_socket.atEndOfStream) @throw [OFTruncatedDataException exception]; /* Content-Length */ if (!_chunked) { size_t ret; if (length > (unsigned long long)_toRead) length = (size_t)_toRead; ret = [_socket readIntoBuffer: buffer length: length]; _toRead -= ret; if (_toRead == 0) _atEndOfStream = true; return ret; } /* Chunked */ if (_toRead == -2) { char tmp[2]; switch ([_socket readIntoBuffer: tmp length: 2]) { case 2: _toRead++; if (tmp[1] != '\n') @throw [OFInvalidFormatException exception]; case 1: _toRead++; if (tmp[0] != '\r') @throw [OFInvalidFormatException exception]; } if (_setAtEndOfStream && _toRead == 0) _atEndOfStream = true; return 0; } else if (_toRead == -1) { char tmp; if ([_socket readIntoBuffer: &tmp length: 1] == 1) { _toRead++; if (tmp != '\n') @throw [OFInvalidFormatException exception]; } if (_setAtEndOfStream && _toRead == 0) _atEndOfStream = true; return 0; } else if (_toRead > 0) { if (length > (unsigned long long)_toRead) length = (size_t)_toRead; length = [_socket readIntoBuffer: buffer length: length]; _toRead -= length; if (_toRead == 0) _toRead = -2; return length; } else { void *pool = objc_autoreleasePoolPush(); OFString *line; size_t pos; unsigned long long toRead; @try { line = [_socket tryReadLine]; } @catch (OFInvalidEncodingException *e) { @throw [OFInvalidFormatException exception]; } if (line == nil) return 0; pos = [line rangeOfString: @";"].location; if (pos != OFNotFound) line = [line substringToIndex: pos]; if (line.length < 1) { /* * We have read the empty string because the socket is * at end of stream. */ if (_socket.atEndOfStream && pos == OFNotFound) @throw [OFTruncatedDataException exception]; else @throw [OFInvalidFormatException exception]; } toRead = [line unsignedLongLongValueWithBase: 16]; if (toRead > LLONG_MAX) @throw [OFOutOfRangeException exception]; _toRead = (long long)toRead; if (_toRead == 0) { _setAtEndOfStream = true; _toRead = -2; } objc_autoreleasePoolPop(pool); return 0; } } - (bool)lowlevelHasDataInReadBuffer { return _socket.hasDataInReadBuffer; } - (int)fileDescriptorForReading { return _socket.fileDescriptorForReading; } - (void)close { if (_socket == nil) @throw [OFNotOpenException exceptionWithObject: self]; [_socket release]; _socket = nil; [super close]; } @end #ifdef OF_HAVE_THREADS @implementation OFHTTPServerThread - (void)stop { [[OFRunLoop currentRunLoop] stop]; [self join]; } @end #endif @implementation OFHTTPServer @synthesize delegate = _delegate, name = _name; + (instancetype)server { return [[[self alloc] init] autorelease]; } - (instancetype)init { self = [super init]; _name = @"OFHTTPServer (ObjFW's HTTP server class " @")"; #ifdef OF_HAVE_THREADS _numberOfThreads = 1; #endif return self; } - (void)dealloc { [self stop]; [_host release]; [_listeningSocket release]; [_name release]; [super dealloc]; } - (void)setHost: (OFString *)host { OFString *old; if (_listeningSocket != nil) @throw [OFAlreadyOpenException exceptionWithObject: self]; old = _host; _host = [host copy]; [old release]; } - (OFString *)host { return _host; } - (void)setPort: (uint16_t)port { if (_listeningSocket != nil) @throw [OFAlreadyOpenException exceptionWithObject: self]; _port = port; } - (uint16_t)port { return _port; } #ifdef OF_HAVE_THREADS - (void)setNumberOfThreads: (size_t)numberOfThreads { if (numberOfThreads == 0) @throw [OFInvalidArgumentException exception]; if (_listeningSocket != nil) @throw [OFAlreadyOpenException exceptionWithObject: self]; _numberOfThreads = numberOfThreads; } - (size_t)numberOfThreads { return _numberOfThreads; } #endif - (void)start { void *pool = objc_autoreleasePoolPush(); OFSocketAddress address; if (_host == nil) @throw [OFInvalidArgumentException exception]; if (_listeningSocket != nil) @throw [OFAlreadyOpenException exceptionWithObject: self]; _listeningSocket = [[OFTCPSocket alloc] init]; address = [_listeningSocket bindToHost: _host port: _port]; _port = OFSocketAddressIPPort(&address); [_listeningSocket listen]; #ifdef OF_HAVE_THREADS if (_numberOfThreads > 1) { OFMutableArray *threads = [OFMutableArray arrayWithCapacity: _numberOfThreads - 1]; for (size_t i = 1; i < _numberOfThreads; i++) { OFHTTPServerThread *thread = [OFHTTPServerThread thread]; thread.supportsSockets = true; [thread start]; [threads addObject: thread]; } [threads makeImmutable]; _threadPool = [threads copy]; } #endif _listeningSocket.delegate = self; [_listeningSocket asyncAccept]; objc_autoreleasePoolPop(pool); } - (void)stop { [_listeningSocket cancelAsyncRequests]; [_listeningSocket release]; _listeningSocket = nil; #ifdef OF_HAVE_THREADS for (OFHTTPServerThread *thread in _threadPool) [thread stop]; [_threadPool release]; _threadPool = nil; #endif } - (void)of_handleAcceptedSocket: (OFStreamSocket *)acceptedSocket { OFHTTPServerConnection *connection = [[[OFHTTPServerConnection alloc] initWithSocket: acceptedSocket server: self] autorelease]; acceptedSocket.delegate = connection; [acceptedSocket asyncReadLine]; } - (bool)socket: (OFStreamSocket *)sock didAcceptSocket: (OFStreamSocket *)acceptedSocket exception: (id)exception { if (exception != nil) { if (![_delegate respondsToSelector: @selector(server:didReceiveExceptionOnListeningSocket:)]) return false; return [_delegate server: self didReceiveExceptionOnListeningSocket: exception]; } #ifdef OF_HAVE_THREADS if (_numberOfThreads > 1) { OFHTTPServerThread *thread = [_threadPool objectAtIndex: _nextThreadIndex]; if (++_nextThreadIndex >= _numberOfThreads - 1) _nextThreadIndex = 0; [self performSelector: @selector(of_handleAcceptedSocket:) onThread: thread withObject: acceptedSocket waitUntilDone: false]; } else #endif [self of_handleAcceptedSocket: acceptedSocket]; return true; } @end objfw-1.1.6/src/OFHostAddressResolver.h000066400000000000000000000033611465614216400177740ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFDNSResolver.h" #import "OFRunLoop.h" #import "OFSocket.h" OF_ASSUME_NONNULL_BEGIN @class OFDNSResolverSettings; @class OFDNSResourceRecord; @class OFMutableArray OF_GENERIC(ObjectType); @class OFMutableData; @class OFString; @interface OFHostAddressResolver: OFObject { OFString *_host; OFSocketAddressFamily _addressFamily; OFDNSResolver *_resolver; OFDNSResolverSettings *_settings; OFRunLoopMode _Nullable _runLoopMode; id _Nullable _delegate; bool _isFQDN; size_t _searchDomainIndex; unsigned int _numExpectedResponses; OFMutableData *_addresses; } - (instancetype)initWithHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily resolver: (OFDNSResolver *)resolver settings: (OFDNSResolverSettings *)settings runLoopMode: (nullable OFRunLoopMode)runLoopMode delegate: (nullable id )delegate; - (void)asyncResolve; - (OFData *)resolve; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFHostAddressResolver.m000066400000000000000000000231731465614216400200040ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFHostAddressResolver.h" #import "OFArray.h" #import "OFDNSResolver.h" #import "OFDNSResolverSettings.h" #import "OFData.h" #import "OFDate.h" #import "OFDictionary.h" #import "OFRunLoop.h" #import "OFString.h" #import "OFTimer.h" #import "OFDNSQueryFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFResolveHostFailedException.h" @interface OFHostAddressResolverDelegate: OFObject { @public bool _done; OFData *_addresses; id _exception; } @end static const OFRunLoopMode resolveRunLoopMode = @"OFHostAddressResolverResolveRunLoopMode"; static bool isFQDN(OFString *host, unsigned int minNumberOfDotsInAbsoluteName) { const char *UTF8String; size_t length; unsigned int dots; if ([host hasSuffix: @"."]) return true; UTF8String = host.UTF8String; length = host.UTF8StringLength; dots = 0; for (size_t i = 0; i < length; i++) if (UTF8String[i] == '.') dots++; return (dots >= minNumberOfDotsInAbsoluteName); } static bool addressForRecord(OF_KINDOF(OFDNSResourceRecord *) record, const OFSocketAddress **address, OFSocketAddressFamily addressFamily) { switch ([record recordType]) { #ifdef OF_HAVE_IPV6 case OFDNSRecordTypeAAAA: if (addressFamily != OFSocketAddressFamilyIPv6 && addressFamily != OFSocketAddressFamilyAny) return false; break; #endif case OFDNSRecordTypeA: if (addressFamily != OFSocketAddressFamilyIPv4 && addressFamily != OFSocketAddressFamilyAny) return false; break; default: return false; } *address = [record address]; return true; } static void callDelegateInMode(OFRunLoopMode runLoopMode, id delegate, OFDNSResolver *resolver, OFString *host, OFData *addresses, id exception) { SEL selector = @selector(resolver:didResolveHost:addresses:exception:); if ([delegate respondsToSelector: selector]) { OFTimer *timer = [OFTimer timerWithTimeInterval: 0 target: delegate selector: selector object: resolver object: host object: addresses object: exception repeats: false]; [[OFRunLoop currentRunLoop] addTimer: timer forMode: runLoopMode]; } } @implementation OFHostAddressResolver: OFObject - (instancetype)initWithHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily resolver: (OFDNSResolver *)resolver settings: (OFDNSResolverSettings *)settings runLoopMode: (OFRunLoopMode)runLoopMode delegate: (id )delegate { self = [super init]; @try { _host = [host copy]; _addressFamily = addressFamily; _resolver = [resolver retain]; _settings = [settings copy]; _runLoopMode = [runLoopMode copy]; _delegate = [delegate retain]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_host release]; [_resolver release]; [_settings release]; [_runLoopMode release]; [_delegate release]; [_addresses release]; [super dealloc]; } - (void)sendQueries { OFString *domainName; if (!_isFQDN) { OFString *searchDomain = @""; if (_searchDomainIndex < _settings->_searchDomains.count) searchDomain = [_settings->_searchDomains objectAtIndex: _searchDomainIndex]; domainName = [OFString stringWithFormat: @"%@.%@", _host, searchDomain]; } else domainName = _host; #ifdef OF_HAVE_IPV6 if (_addressFamily == OFSocketAddressFamilyIPv6 || _addressFamily == OFSocketAddressFamilyAny) { OFDNSQuery *query = [OFDNSQuery queryWithDomainName: domainName DNSClass: OFDNSClassIN recordType: OFDNSRecordTypeAAAA]; _numExpectedResponses++; [_resolver asyncPerformQuery: query runLoopMode: _runLoopMode delegate: self]; } #endif if (_addressFamily == OFSocketAddressFamilyIPv4 || _addressFamily == OFSocketAddressFamilyAny) { OFDNSQuery *query = [OFDNSQuery queryWithDomainName: domainName DNSClass: OFDNSClassIN recordType: OFDNSRecordTypeA]; _numExpectedResponses++; [_resolver asyncPerformQuery: query runLoopMode: _runLoopMode delegate: self]; } } - (void)resolver: (OFDNSResolver *)resolver didPerformQuery: (OFDNSQuery *)query response: (OFDNSResponse *)response exception: (id)exception { _numExpectedResponses--; if ([exception isKindOfClass: [OFDNSQueryFailedException class]] && [exception errorCode] == OFDNSResolverErrorCodeServerNameError && !_isFQDN && _numExpectedResponses == 0 && _addresses.count == 0 && _searchDomainIndex + 1 < _settings->_searchDomains.count) { _searchDomainIndex++; [self sendQueries]; return; } for (OF_KINDOF(OFDNSResourceRecord *) record in [response.answerRecords objectForKey: query.domainName]) { const OFSocketAddress *address = NULL; OFDNSQuery *CNAMEQuery; if ([record DNSClass] != OFDNSClassIN) continue; if (addressForRecord(record, &address, _addressFamily)) { [_addresses addItem: address]; continue; } if ([record recordType] != OFDNSRecordTypeCNAME) continue; /* FIXME: Check if it's already in answers */ CNAMEQuery = [OFDNSQuery queryWithDomainName: [record alias] DNSClass: OFDNSClassIN recordType: query.recordType]; _numExpectedResponses++; [_resolver asyncPerformQuery: CNAMEQuery runLoopMode: _runLoopMode delegate: self]; } if (_numExpectedResponses > 0) return; [_addresses makeImmutable]; if (_addresses.count == 0) { [_addresses release]; _addresses = nil; if ([exception isKindOfClass: [OFDNSQueryFailedException class]]) exception = [OFResolveHostFailedException exceptionWithHost: _host addressFamily: _addressFamily errorCode: [exception errorCode]]; if (exception == nil) exception = [OFResolveHostFailedException exceptionWithHost: _host addressFamily: _addressFamily errorCode: OFDNSResolverErrorCodeNoResult]; } else exception = nil; if ([_delegate respondsToSelector: @selector(resolver:didResolveHost:addresses:exception:)]) [_delegate resolver: _resolver didResolveHost: _host addresses: _addresses exception: exception]; } - (void)asyncResolve { void *pool = objc_autoreleasePoolPush(); OFArray OF_GENERIC(OFString *) *aliases; @try { OFSocketAddress address = OFSocketAddressParseIP(_host, 0); OFData *addresses = nil; id exception = nil; if (_addressFamily == address.family || _addressFamily == OFSocketAddressFamilyAny) addresses = [OFData dataWithItems: &address count: 1 itemSize: sizeof(address)]; else exception = [OFInvalidArgumentException exception]; callDelegateInMode(_runLoopMode, _delegate, _resolver, _host, addresses, exception); objc_autoreleasePoolPop(pool); return; } @catch (OFInvalidFormatException *e) { } if ((aliases = [_settings->_staticHosts objectForKey: _host.lowercaseString]) != nil) { OFMutableData *addresses = [OFMutableData dataWithItemSize: sizeof(OFSocketAddress)]; id exception = nil; for (OFString *alias in aliases) { OFSocketAddress address; @try { address = OFSocketAddressParseIP(alias, 0); } @catch (OFInvalidFormatException *e) { continue; } if (_addressFamily != address.family && _addressFamily != OFSocketAddressFamilyAny) continue; [addresses addItem: &address]; } [addresses makeImmutable]; if (addresses.count == 0) { addresses = nil; exception = [OFResolveHostFailedException exceptionWithHost: _host addressFamily: _addressFamily errorCode: OFDNSResolverErrorCodeNoResult]; } callDelegateInMode(_runLoopMode, _delegate, _resolver, _host, addresses, exception); objc_autoreleasePoolPop(pool); return; } _isFQDN = isFQDN(_host, _settings->_minNumberOfDotsInAbsoluteName); _addresses = [[OFMutableData alloc] initWithItemSize: sizeof(OFSocketAddress)]; [self sendQueries]; objc_autoreleasePoolPop(pool); } - (OFData *)resolve { void *pool = objc_autoreleasePoolPush(); OFRunLoop *runLoop = [OFRunLoop currentRunLoop]; OFHostAddressResolverDelegate *delegate; OFData *ret; delegate = [[[OFHostAddressResolverDelegate alloc] init] autorelease]; _runLoopMode = [resolveRunLoopMode copy]; _delegate = [delegate retain]; [self asyncResolve]; while (!delegate->_done) [runLoop runMode: resolveRunLoopMode beforeDate: nil]; /* Cleanup */ [runLoop runMode: resolveRunLoopMode beforeDate: [OFDate date]]; if (delegate->_exception != nil) @throw delegate->_exception; ret = [delegate->_addresses copy]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @end @implementation OFHostAddressResolverDelegate - (void)dealloc { [_addresses release]; [_exception release]; [super dealloc]; } - (void)resolver: (OFDNSResolver *)resolver didResolveHost: (OFString *)host addresses: (OFData *)addresses exception: (id)exception { _addresses = [addresses copy]; _exception = [exception retain]; _done = true; } @end objfw-1.1.6/src/OFHuffmanTree.h000066400000000000000000000036051465614216400162340ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include #include #import "macros.h" #import "OFInvalidFormatException.h" OF_ASSUME_NONNULL_BEGIN typedef struct _OFHuffmanTree { struct _OFHuffmanTree *_Nullable leaves[2]; uint16_t value; } *OFHuffmanTree; /* Inlined for performance. */ static OF_INLINE bool _OFHuffmanTreeWalk(id _Nullable stream, bool (*bitReader)(id _Nullable, uint16_t *_Nonnull, uint8_t), OFHuffmanTree _Nonnull *_Nonnull tree, uint16_t *_Nonnull value) { OFHuffmanTree iter = *tree; uint16_t bits; while (iter->value == 0xFFFF) { if OF_UNLIKELY (!bitReader(stream, &bits, 1)) { *tree = iter; return false; } if OF_UNLIKELY (iter->leaves[bits] == NULL) @throw [OFInvalidFormatException exception]; iter = iter->leaves[bits]; } *value = iter->value; return true; } #ifdef __cplusplus extern "C" { #endif extern OFHuffmanTree _Nonnull _OFHuffmanTreeNew(uint8_t lengths[_Nonnull], uint16_t count) OF_VISIBILITY_HIDDEN; extern OFHuffmanTree _Nonnull _OFHuffmanTreeNewSingle(uint16_t value) OF_VISIBILITY_HIDDEN; extern void _OFHuffmanTreeFree(OFHuffmanTree _Nonnull tree) OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFHuffmanTree.m000066400000000000000000000053641465614216400162450ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "OFHuffmanTree.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" static OFHuffmanTree newTree(void) { OFHuffmanTree tree; tree = OFAllocMemory(1, sizeof(*tree)); tree->leaves[0] = tree->leaves[1] = NULL; tree->value = 0xFFFF; return tree; } static void treeInsert(OFHuffmanTree tree, uint16_t code, uint8_t length, uint16_t value) { while (length > 0) { uint8_t bit; length--; bit = (code & (1u << length)) >> length; if (tree->leaves[bit] == NULL) tree->leaves[bit] = newTree(); tree = tree->leaves[bit]; } tree->value = value; } OFHuffmanTree _OFHuffmanTreeNew(uint8_t lengths[], uint16_t count) { OFHuffmanTree tree; uint16_t *lengthCount = NULL; uint16_t code, maxCode = 0, *nextCode = NULL; uint_fast8_t maxBit = 0; @try { for (uint16_t i = 0; i < count; i++) { uint_fast8_t length = lengths[i]; if OF_UNLIKELY (length > maxBit) { lengthCount = OFResizeMemory(lengthCount, length + 1, sizeof(uint16_t)); nextCode = OFResizeMemory(nextCode, length + 1, sizeof(uint16_t)); for (uint_fast8_t j = maxBit + 1; j <= length; j++) { lengthCount[j] = 0; nextCode[j] = 0; } maxBit = length; } if (length > 0) { lengthCount[length]++; maxCode = i; } } code = 0; for (size_t i = 1; i <= maxBit; i++) { code = (code + lengthCount[i - 1]) << 1; nextCode[i] = code; } tree = newTree(); for (uint16_t i = 0; i <= maxCode; i++) { uint8_t length = lengths[i]; if (length > 0) treeInsert(tree, nextCode[length]++, length, i); } } @finally { OFFreeMemory(lengthCount); OFFreeMemory(nextCode); } return tree; } OFHuffmanTree _OFHuffmanTreeNewSingle(uint16_t value) { OFHuffmanTree tree = newTree(); tree->value = value; return tree; } void _OFHuffmanTreeFree(OFHuffmanTree tree) { for (uint_fast8_t i = 0; i < 2; i++) if OF_LIKELY (tree->leaves[i] != NULL) _OFHuffmanTreeFree(tree->leaves[i]); OFFreeMemory(tree); } objfw-1.1.6/src/OFINICategory+Private.h000066400000000000000000000021401465614216400175440ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFINICategory.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @class OFStream; OF_DIRECT_MEMBERS @interface OFINICategory () - (instancetype)of_initWithName: (OFString *)name OF_METHOD_FAMILY(init); - (void)of_parseLine: (OFString *)line; - (bool)of_writeToStream: (OFStream *)stream encoding: (OFStringEncoding)encoding first: (bool)first; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFINICategory.h000066400000000000000000000204231465614216400161420ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFMutableArray OF_GENERIC(ObjectType); @class OFString; /** * @class OFINICategory OFINICategory.h ObjFW/OFINICategory.h * * @brief A class for representing a category of an INI file. */ OF_SUBCLASSING_RESTRICTED @interface OFINICategory: OFObject { OFString *_name; OFMutableArray *_lines; } /** * @brief The name of the INI category */ @property (copy, nonatomic) OFString *name; - (instancetype)init OF_UNAVAILABLE; /** * @brief Returns the string for the specified key, or `nil` if it does not * exist. * * If the specified key is a multi-key (see @ref arrayValueForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the string should be returned * @return The string for the specified key, or `nil` if it does not exist */ - (nullable OFString *)stringValueForKey: (OFString *)key; /** * @brief Returns the string for the specified key or the specified default * value if it does not exist. * * If the specified key is a multi-key (see @ref arrayValueForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the string should be returned * @param defaultValue The value to return if the key does not exist * @return The string for the specified key or the specified default value if * it does not exist */ - (nullable OFString *)stringValueForKey: (OFString *)key defaultValue: (nullable OFString *)defaultValue; /** * @brief Returns the long long value for the specified key or the specified * default value if it does not exist. * * If the specified key is a multi-key (see @ref arrayValueForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the long long should be returned * @param defaultValue The value to return if the key does not exist * @return The long long for the specified key or the specified default value * if it does not exist * @throw OFInvalidFormatException The specified key is not in the correct * format for a long long */ - (long long)longLongValueForKey: (OFString *)key defaultValue: (long long)defaultValue; /** * @brief Returns the bool value for the specified key or the specified default * value if it does not exist. * * If the specified key is a multi-key (see @ref arrayValueForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the bool should be returned * @param defaultValue The value to return if the key does not exist * @return The bool for the specified key or the specified default value if it * does not exist * @throw OFInvalidFormatException The specified key is not in the correct * format for a bool */ - (bool)boolValueForKey: (OFString *)key defaultValue: (bool)defaultValue; /** * @brief Returns the float value for the specified key or the specified default * value if it does not exist. * * If the specified key is a multi-key (see @ref arrayValueForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the float should be returned * @param defaultValue The value to return if the key does not exist * @return The float for the specified key or the specified default value if it * does not exist * @throw OFInvalidFormatException The specified key is not in the correct * format for a float */ - (float)floatValueForKey: (OFString *)key defaultValue: (float)defaultValue; /** * @brief Returns the double value for the specified key or the specified * default value if it does not exist. * * If the specified key is a multi-key (see @ref arrayValueForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the double should be returned * @param defaultValue The value to return if the key does not exist * @return The double for the specified key or the specified default value if * it does not exist * @throw OFInvalidFormatException The specified key is not in the correct * format for a double */ - (double)doubleValueForKey: (OFString *)key defaultValue: (double)defaultValue; /** * @brief Returns an array of strings for the specified multi-key, or an empty * array if the key does not exist. * * A multi-key is a key which exists several times in the same category. Each * occurrence of the key/value pair adds the respective value to the array. * * @param key The multi-key for which the array should be returned * @return The array for the specified key, or an empty array if it does not * exist */ - (OFArray OF_GENERIC(OFString *) *)arrayValueForKey: (OFString *)key; /** * @brief Sets the value of the specified key to the specified string. * * If the specified key is a multi-key (see @ref arrayValueForKey:), the value * of the first key/value pair found is changed. * * @param stringValue The string to which the key should be set * @param key The key for which the new value should be set */ - (void)setStringValue: (OFString *)stringValue forKey: (OFString *)key; /** * @brief Sets the value of the specified key to the specified long long. * * If the specified key is a multi-key (see @ref arrayValueForKey:), the value * of the first key/value pair found is changed. * * @param longLongValue The long long to which the key should be set * @param key The key for which the new value should be set */ - (void)setLongLongValue: (long long)longLongValue forKey: (OFString *)key; /** * @brief Sets the value of the specified key to the specified bool. * * If the specified key is a multi-key (see @ref arrayValueForKey:), the value * of the first key/value pair found is changed. * * @param boolValue The bool to which the key should be set * @param key The key for which the new value should be set */ - (void)setBoolValue: (bool)boolValue forKey: (OFString *)key; /** * @brief Sets the value of the specified key to the specified float. * * If the specified key is a multi-key (see @ref arrayValueForKey:), the value * of the first key/value pair found is changed. * * @param floatValue The float to which the key should be set * @param key The key for which the new value should be set */ - (void)setFloatValue: (float)floatValue forKey: (OFString *)key; /** * @brief Sets the value of the specified key to the specified double. * * If the specified key is a multi-key (see @ref arrayValueForKey:), the value * of the first key/value pair found is changed. * * @param doubleValue The double to which the key should be set * @param key The key for which the new value should be set */ - (void)setDoubleValue: (double)doubleValue forKey: (OFString *)key; /** * @brief Sets the specified multi-key to the specified array of strings. * * It replaces the first occurrence of the multi-key with several key/value * pairs and removes all following occurrences. If the multi-key does not exist * yet, it is appended to the section. * * See also @ref arrayValueForKey: for more information about multi-keys. * * @param arrayValue The array of strings to which the multi-key should be set * @param key The multi-key for which the new values should be set */ - (void)setArrayValue: (OFArray OF_GENERIC(OFString *) *)arrayValue forKey: (OFString *)key; /** * @brief Removes the value for the specified key * * If the specified key is a multi-key (see @ref arrayValueForKey:), all * key/value pairs matching the specified key are removed. * * @param key The key of the value to remove */ - (void)removeValueForKey: (OFString *)key; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFINICategory.m000066400000000000000000000257151465614216400161600ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFINICategory.h" #import "OFINICategory+Private.h" #import "OFArray.h" #import "OFString.h" #import "OFStream.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" @interface OFINICategoryPair: OFObject { @public OFString *_key, *_value; } @end @interface OFINICategoryComment: OFObject { @public OFString *_comment; } @end static OFString * escapeString(OFString *string) { OFMutableString *mutableString; /* FIXME: Optimize */ if (![string hasPrefix: @" "] && ![string hasPrefix: @"\t"] && ![string hasPrefix: @"\f"] && ![string hasSuffix: @" "] && ![string hasSuffix: @"\t"] && ![string hasSuffix: @"\f"] && ![string containsString: @"\""]) return string; mutableString = [[string mutableCopy] autorelease]; [mutableString replaceOccurrencesOfString: @"\\" withString: @"\\\\"]; [mutableString replaceOccurrencesOfString: @"\f" withString: @"\\f"]; [mutableString replaceOccurrencesOfString: @"\r" withString: @"\\r"]; [mutableString replaceOccurrencesOfString: @"\n" withString: @"\\n"]; [mutableString replaceOccurrencesOfString: @"\"" withString: @"\\\""]; [mutableString insertString: @"\"" atIndex: 0]; [mutableString appendString: @"\""]; [mutableString makeImmutable]; return mutableString; } static OFString * unescapeString(OFString *string) { OFMutableString *mutableString; if (![string hasPrefix: @"\""] || ![string hasSuffix: @"\""]) return string; string = [string substringWithRange: OFMakeRange(1, string.length - 2)]; mutableString = [[string mutableCopy] autorelease]; [mutableString replaceOccurrencesOfString: @"\\f" withString: @"\f"]; [mutableString replaceOccurrencesOfString: @"\\r" withString: @"\r"]; [mutableString replaceOccurrencesOfString: @"\\n" withString: @"\n"]; [mutableString replaceOccurrencesOfString: @"\\\"" withString: @"\""]; [mutableString replaceOccurrencesOfString: @"\\\\" withString: @"\\"]; [mutableString makeImmutable]; return mutableString; } @implementation OFINICategoryPair - (void)dealloc { [_key release]; [_value release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"%@ = %@", _key, _value]; } @end @implementation OFINICategoryComment - (void)dealloc { [_comment release]; [super dealloc]; } - (OFString *)description { return [[_comment copy] autorelease]; } @end @implementation OFINICategory @synthesize name = _name; - (instancetype)of_initWithName: (OFString *)name OF_DIRECT { self = [super init]; @try { _name = [name copy]; _lines = [[OFMutableArray alloc] init]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_name release]; [_lines release]; [super dealloc]; } - (void)of_parseLine: (OFString *)line { if (![line hasPrefix: @";"]) { OFINICategoryPair *pair = [[[OFINICategoryPair alloc] init] autorelease]; OFString *key, *value; size_t pos; if ((pos = [line rangeOfString: @"="].location) == OFNotFound) @throw [OFInvalidFormatException exception]; key = unescapeString([line substringToIndex: pos] .stringByDeletingEnclosingWhitespaces); value = unescapeString([line substringFromIndex: pos + 1] .stringByDeletingEnclosingWhitespaces); pair->_key = [key copy]; pair->_value = [value copy]; [_lines addObject: pair]; } else { OFINICategoryComment *comment = [[[OFINICategoryComment alloc] init] autorelease]; comment->_comment = [line copy]; [_lines addObject: comment]; } } - (OFString *)stringValueForKey: (OFString *)key { return [self stringValueForKey: key defaultValue: nil]; } - (OFString *)stringValueForKey: (OFString *)key defaultValue: (OFString *)defaultValue { for (id line in _lines) { OFINICategoryPair *pair; if (![line isKindOfClass: [OFINICategoryPair class]]) continue; pair = line; if ([pair->_key isEqual: key]) return [[pair->_value copy] autorelease]; } return defaultValue; } - (long long)longLongValueForKey: (OFString *)key defaultValue: (long long)defaultValue { void *pool = objc_autoreleasePoolPush(); OFString *value = [self stringValueForKey: key defaultValue: nil]; long long ret; if (value != nil) ret = [value longLongValueWithBase: 0]; else ret = defaultValue; objc_autoreleasePoolPop(pool); return ret; } - (bool)boolValueForKey: (OFString *)key defaultValue: (bool)defaultValue { void *pool = objc_autoreleasePoolPush(); OFString *value = [self stringValueForKey: key defaultValue: nil]; bool ret; if (value != nil) { if ([value isEqual: @"true"]) ret = true; else if ([value isEqual: @"false"]) ret = false; else @throw [OFInvalidFormatException exception]; } else ret = defaultValue; objc_autoreleasePoolPop(pool); return ret; } - (float)floatValueForKey: (OFString *)key defaultValue: (float)defaultValue { void *pool = objc_autoreleasePoolPush(); OFString *value = [self stringValueForKey: key defaultValue: nil]; float ret; if (value != nil) ret = value.floatValue; else ret = defaultValue; objc_autoreleasePoolPop(pool); return ret; } - (double)doubleValueForKey: (OFString *)key defaultValue: (double)defaultValue { void *pool = objc_autoreleasePoolPush(); OFString *value = [self stringValueForKey: key defaultValue: nil]; double ret; if (value != nil) ret = value.doubleValue; else ret = defaultValue; objc_autoreleasePoolPop(pool); return ret; } - (OFArray OF_GENERIC(OFString *) *)arrayValueForKey: (OFString *)key { OFMutableArray *ret = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); for (id line in _lines) { OFINICategoryPair *pair; if (![line isKindOfClass: [OFINICategoryPair class]]) continue; pair = line; if ([pair->_key isEqual: key]) [ret addObject: [[pair->_value copy] autorelease]]; } objc_autoreleasePoolPop(pool); [ret makeImmutable]; return ret; } - (void)setStringValue: (OFString *)string forKey: (OFString *)key { void *pool = objc_autoreleasePoolPush(); OFINICategoryPair *pair; for (id line in _lines) { if (![line isKindOfClass: [OFINICategoryPair class]]) continue; pair = line; if ([pair->_key isEqual: key]) { OFString *old = pair->_value; pair->_value = [string copy]; [old release]; objc_autoreleasePoolPop(pool); return; } } pair = [[[OFINICategoryPair alloc] init] autorelease]; pair->_key = nil; pair->_value = nil; @try { pair->_key = [key copy]; pair->_value = [string copy]; [_lines addObject: pair]; } @catch (id e) { [pair->_key release]; [pair->_value release]; @throw e; } objc_autoreleasePoolPop(pool); } - (void)setLongLongValue: (long long)longLongValue forKey: (OFString *)key { void *pool = objc_autoreleasePoolPush(); [self setStringValue: [OFString stringWithFormat: @"%lld", longLongValue] forKey: key]; objc_autoreleasePoolPop(pool); } - (void)setBoolValue: (bool)boolValue forKey: (OFString *)key { [self setStringValue: (boolValue ? @"true" : @"false") forKey: key]; } - (void)setFloatValue: (float)floatValue forKey: (OFString *)key { void *pool = objc_autoreleasePoolPush(); [self setStringValue: [OFString stringWithFormat: @"%g", floatValue] forKey: key]; objc_autoreleasePoolPop(pool); } - (void)setDoubleValue: (double)doubleValue forKey: (OFString *)key { void *pool = objc_autoreleasePoolPush(); [self setStringValue: [OFString stringWithFormat: @"%g", doubleValue] forKey: key]; objc_autoreleasePoolPop(pool); } - (void)setArrayValue: (OFArray OF_GENERIC(OFString *) *)arrayValue forKey: (OFString *)key { void *pool; OFMutableArray *pairs; id const *lines; size_t count; bool replaced; if (arrayValue.count == 0) { [self removeValueForKey: key]; return; } pool = objc_autoreleasePoolPush(); pairs = [OFMutableArray arrayWithCapacity: arrayValue.count]; for (OFString *string in arrayValue) { OFINICategoryPair *pair; if (![string isKindOfClass: [OFString class]]) @throw [OFInvalidArgumentException exception]; pair = [[[OFINICategoryPair alloc] init] autorelease]; pair->_key = [key copy]; pair->_value = [string copy]; [pairs addObject: pair]; } lines = _lines.objects; count = _lines.count; replaced = false; for (size_t i = 0; i < count; i++) { OFINICategoryPair *pair; if (![lines[i] isKindOfClass: [OFINICategoryPair class]]) continue; pair = lines[i]; if ([pair->_key isEqual: key]) { [_lines removeObjectAtIndex: i]; if (!replaced) { [_lines insertObjectsFromArray: pairs atIndex: i]; replaced = true; /* Continue after inserted pairs */ i += arrayValue.count - 1; } else i--; /* Continue at same position */ lines = _lines.objects; count = _lines.count; continue; } } if (!replaced) [_lines addObjectsFromArray: pairs]; objc_autoreleasePoolPop(pool); } - (void)removeValueForKey: (OFString *)key { void *pool = objc_autoreleasePoolPush(); id const *lines = _lines.objects; size_t count = _lines.count; for (size_t i = 0; i < count; i++) { OFINICategoryPair *pair; if (![lines[i] isKindOfClass: [OFINICategoryPair class]]) continue; pair = lines[i]; if ([pair->_key isEqual: key]) { [_lines removeObjectAtIndex: i]; lines = _lines.objects; count = _lines.count; i--; /* Continue at same position */ continue; } } objc_autoreleasePoolPop(pool); } - (bool)of_writeToStream: (OFStream *)stream encoding: (OFStringEncoding)encoding first: (bool)first { if (_lines.count == 0) return false; if (first) [stream writeFormat: @"[%@]\r\n", _name]; else [stream writeFormat: @"\r\n[%@]\r\n", _name]; for (id line in _lines) { if ([line isKindOfClass: [OFINICategoryComment class]]) { OFINICategoryComment *comment = line; [stream writeFormat: @"%@\r\n", comment->_comment]; } else if ([line isKindOfClass: [OFINICategoryPair class]]) { OFINICategoryPair *pair = line; OFString *key = escapeString(pair->_key); OFString *value = escapeString(pair->_value); OFString *tmp = [OFString stringWithFormat: @"%@=%@\r\n", key, value]; [stream writeString: tmp encoding: encoding]; } else @throw [OFInvalidArgumentException exception]; } return true; } - (OFString *)description { return [OFString stringWithFormat: @"<%@ \"%@\": %@>", self.class, _name, _lines]; } @end objfw-1.1.6/src/OFINIFile.h000066400000000000000000000102761465614216400152510ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFString.h" #import "OFINICategory.h" OF_ASSUME_NONNULL_BEGIN @class OFIRI; @class OFMutableArray OF_GENERIC(ObjectType); /** * @class OFINIFile OFINIFile.h ObjFW/OFINIFile.h * * @brief A class for reading, creating and modifying INI files. */ OF_SUBCLASSING_RESTRICTED @interface OFINIFile: OFObject { OFMutableArray OF_GENERIC(OFINICategory *) *_categories; } /** * @brief All categories in the INI file. */ @property (readonly, nonatomic) OFArray OF_GENERIC(OFINICategory *) *categories; /** * @brief Creates a new OFINIFile with the contents of the specified file. * * @param IRI The IRI to the file whose contents the OFINIFile should contain * * @return A new, autoreleased OFINIFile with the contents of the specified file * @throw OFInvalidFormatException The format of the specified INI file is * invalid * @throw OFInvalidEncodingException The INI file is not in the specified * encoding */ + (instancetype)fileWithIRI: (OFIRI *)IRI; /** * @brief Creates a new OFINIFile with the contents of the specified file in * the specified encoding. * * @param IRI The IRI to the file whose contents the OFINIFile should contain * @param encoding The encoding of the specified file * @return A new, autoreleased OFINIFile with the contents of the specified file * @throw OFInvalidFormatException The format of the specified INI file is * invalid * @throw OFInvalidEncodingException The INI file is not in the specified * encoding */ + (instancetype)fileWithIRI: (OFIRI *)IRI encoding: (OFStringEncoding)encoding; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFINIFile with the contents of the * specified file. * * @param IRI The IRI to the file whose contents the OFINIFile should contain * * @return An initialized OFINIFile with the contents of the specified file * @throw OFInvalidFormatException The format of the specified INI file is * invalid * @throw OFInvalidEncodingException The INI file is not in the specified * encoding */ - (instancetype)initWithIRI: (OFIRI *)IRI; /** * @brief Initializes an already allocated OFINIFile with the contents of the * specified file in the specified encoding. * * @param IRI The IRI to the file whose contents the OFINIFile should contain * @param encoding The encoding of the specified file * @return An initialized OFINIFile with the contents of the specified file * @throw OFInvalidFormatException The format of the specified INI file is * invalid * @throw OFInvalidEncodingException The INI file is not in the specified * encoding */ - (instancetype)initWithIRI: (OFIRI *)IRI encoding: (OFStringEncoding)encoding OF_DESIGNATED_INITIALIZER; /** * @brief Returns an @ref OFINICategory for the category with the specified * name. * * @param name The name of the category for which an @ref OFINICategory should * be returned * * @return An @ref OFINICategory for the category with the specified name */ - (OFINICategory *)categoryForName: (OFString *)name; /** * @brief Writes the contents of the OFINIFile to a file. * * @param IRI The IRI of the file to write to */ - (void)writeToIRI: (OFIRI *)IRI; /** * @brief Writes the contents of the OFINIFile to a file in the specified * encoding. * * @param IRI The IRI of the file to write to * @param encoding The encoding to use */ - (void)writeToIRI: (OFIRI *)IRI encoding: (OFStringEncoding)encoding; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFINIFile.m000066400000000000000000000103101465614216400152430ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFINIFile.h" #import "OFArray.h" #import "OFINICategory+Private.h" #import "OFINICategory.h" #import "OFIRI.h" #import "OFIRIHandler.h" #import "OFStream.h" #import "OFString.h" #import "OFInvalidFormatException.h" #import "OFOpenItemFailedException.h" OF_DIRECT_MEMBERS @interface OFINIFile () - (void)of_parseIRI: (OFIRI *)IRI encoding: (OFStringEncoding)encoding; @end static bool isWhitespaceLine(OFString *line) { const char *cString = line.UTF8String; size_t length = line.UTF8StringLength; for (size_t i = 0; i < length; i++) if (!OFASCIIIsSpace(cString[i])) return false; return true; } @implementation OFINIFile @synthesize categories = _categories; + (instancetype)fileWithIRI: (OFIRI *)IRI { return [[[self alloc] initWithIRI: IRI] autorelease]; } + (instancetype)fileWithIRI: (OFIRI *)IRI encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithIRI: IRI encoding: encoding] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithIRI: (OFIRI *)IRI { return [self initWithIRI: IRI encoding: OFStringEncodingAutodetect]; } - (instancetype)initWithIRI: (OFIRI *)IRI encoding: (OFStringEncoding)encoding { self = [super init]; @try { _categories = [[OFMutableArray alloc] init]; [self of_parseIRI: IRI encoding: encoding]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_categories release]; [super dealloc]; } - (OFINICategory *)categoryForName: (OFString *)name { void *pool = objc_autoreleasePoolPush(); OFINICategory *category; for (category in _categories) if ([category.name isEqual: name]) return category; category = [[[OFINICategory alloc] of_initWithName: name] autorelease]; [_categories addObject: category]; objc_autoreleasePoolPop(pool); return category; } - (void)of_parseIRI: (OFIRI *)IRI encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFStream *file; OFINICategory *category = nil; OFString *line; if (encoding == OFStringEncodingAutodetect) encoding = OFStringEncodingUTF8; @try { file = [OFIRIHandler openItemAtIRI: IRI mode: @"r"]; } @catch (OFOpenItemFailedException *e) { /* Handle missing file like an empty file */ if (e.errNo == ENOENT) return; @throw e; } while ((line = [file readLineWithEncoding: encoding]) != nil) { if (isWhitespaceLine(line)) continue; if ([line hasPrefix: @"["]) { OFString *categoryName; if (![line hasSuffix: @"]"]) @throw [OFInvalidFormatException exception]; categoryName = [line substringWithRange: OFMakeRange(1, line.length - 2)]; category = [[[OFINICategory alloc] of_initWithName: categoryName] autorelease]; [_categories addObject: category]; } else { if (category == nil) @throw [OFInvalidFormatException exception]; [category of_parseLine: line]; } } objc_autoreleasePoolPop(pool); } - (void)writeToIRI: (OFIRI *)IRI { [self writeToIRI: IRI encoding: OFStringEncodingUTF8]; } - (void)writeToIRI: (OFIRI *)IRI encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFStream *file = [OFIRIHandler openItemAtIRI: IRI mode: @"w"]; bool first = true; for (OFINICategory *category in _categories) if ([category of_writeToStream: file encoding: encoding first: first]) first = false; objc_autoreleasePoolPop(pool); } - (OFString *)description { return [OFString stringWithFormat: @"<%@: %@>", self.class, _categories]; } @end objfw-1.1.6/src/OFINIFileSettings.h000066400000000000000000000016601465614216400167670ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFSettings.h" OF_ASSUME_NONNULL_BEGIN @class OFINIFile; @class OFIRI; @class OFString; @interface OFINIFileSettings: OFSettings { OFIRI *_fileIRI; OFINIFile *_INIFile; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFINIFileSettings.m000066400000000000000000000145151465614216400167770ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFINIFileSettings.h" #import "OFArray.h" #import "OFINIFile.h" #import "OFIRI.h" #import "OFString.h" #import "OFSystemInfo.h" @implementation OFINIFileSettings - (instancetype)initWithApplicationName: (OFString *)applicationName { self = [super initWithApplicationName: applicationName]; @try { void *pool = objc_autoreleasePoolPush(); OFString *fileName; fileName = [applicationName stringByAppendingString: @".ini"]; _fileIRI = [[[OFSystemInfo userConfigIRI] IRIByAppendingPathComponent: fileName] copy]; _INIFile = [[OFINIFile alloc] initWithIRI: _fileIRI]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_fileIRI release]; [_INIFile release]; [super dealloc]; } - (void)of_getCategory: (OFString **)category andKey: (OFString **)key forPath: (OFString *)path OF_DIRECT { size_t pos = [path rangeOfString: @"." options: OFStringSearchBackwards].location; if (pos == OFNotFound) { *category = @""; *key = path; return; } *category = [path substringToIndex: pos]; *key = [path substringFromIndex: pos + 1]; } - (void)setString: (OFString *)string forPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; [self of_getCategory: &category andKey: &key forPath: path]; [[_INIFile categoryForName: category] setStringValue: string forKey: key]; objc_autoreleasePoolPop(pool); } - (void)setLongLong: (long long)longLong forPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; [self of_getCategory: &category andKey: &key forPath: path]; [[_INIFile categoryForName: category] setLongLongValue: longLong forKey: key]; objc_autoreleasePoolPop(pool); } - (void)setBool: (bool)bool_ forPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; [self of_getCategory: &category andKey: &key forPath: path]; [[_INIFile categoryForName: category] setBoolValue: bool_ forKey: key]; objc_autoreleasePoolPop(pool); } - (void)setFloat: (float)float_ forPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; [self of_getCategory: &category andKey: &key forPath: path]; [[_INIFile categoryForName: category] setFloatValue: float_ forKey: key]; objc_autoreleasePoolPop(pool); } - (void)setDouble: (double)double_ forPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; [self of_getCategory: &category andKey: &key forPath: path]; [[_INIFile categoryForName: category] setDoubleValue: double_ forKey: key]; objc_autoreleasePoolPop(pool); } - (void)setStringArray: (OFArray OF_GENERIC(OFString *) *)array forPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; [self of_getCategory: &category andKey: &key forPath: path]; [[_INIFile categoryForName: category] setArrayValue: array forKey: key]; objc_autoreleasePoolPop(pool); } - (OFString *)stringForPath: (OFString *)path defaultValue: (OFString *)defaultValue { void *pool = objc_autoreleasePoolPush(); OFString *category, *key, *ret; [self of_getCategory: &category andKey: &key forPath: path]; ret = [[_INIFile categoryForName: category] stringValueForKey: key defaultValue: defaultValue]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (long long)longLongForPath: (OFString *)path defaultValue: (long long)defaultValue { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; long long ret; [self of_getCategory: &category andKey: &key forPath: path]; ret = [[_INIFile categoryForName: category] longLongValueForKey: key defaultValue: defaultValue]; objc_autoreleasePoolPop(pool); return ret; } - (bool)boolForPath: (OFString *)path defaultValue: (bool)defaultValue { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; bool ret; [self of_getCategory: &category andKey: &key forPath: path]; ret = [[_INIFile categoryForName: category] boolValueForKey: key defaultValue: defaultValue]; objc_autoreleasePoolPop(pool); return ret; } - (float)floatForPath: (OFString *)path defaultValue: (float)defaultValue { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; float ret; [self of_getCategory: &category andKey: &key forPath: path]; ret = [[_INIFile categoryForName: category] floatValueForKey: key defaultValue: defaultValue]; objc_autoreleasePoolPop(pool); return ret; } - (double)doubleForPath: (OFString *)path defaultValue: (double)defaultValue { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; double ret; [self of_getCategory: &category andKey: &key forPath: path]; ret = [[_INIFile categoryForName: category] doubleValueForKey: key defaultValue: defaultValue]; objc_autoreleasePoolPop(pool); return ret; } - (OFArray OF_GENERIC(OFString *) *)stringArrayForPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; OFArray *ret; [self of_getCategory: &category andKey: &key forPath: path]; ret = [[_INIFile categoryForName: category] arrayValueForKey: key]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (void)removeValueForPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; [self of_getCategory: &category andKey: &key forPath: path]; [[_INIFile categoryForName: category] removeValueForKey: key]; objc_autoreleasePoolPop(pool); } - (void)save { [_INIFile writeToIRI: _fileIRI]; } @end objfw-1.1.6/src/OFIPXSocket.h000066400000000000000000000061141465614216400156370ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFDatagramSocket.h" OF_ASSUME_NONNULL_BEGIN @class OFString; /** * @protocol OFIPXSocketDelegate OFIPXSocket.h ObjFW/OFIPXSocket.h * * @brief A delegate for OFIPXSocket. */ @protocol OFIPXSocketDelegate @end /** * @class OFIPXSocket OFIPXSocket.h ObjFW/OFIPXSocket.h * * @brief A class which provides methods to create and use IPX sockets. * * Addresses are of type @ref OFSocketAddress. You can use * @ref OFSocketAddressMakeIPX to create an address or * @ref OFSocketAddressIPXNetwork to get the IPX network, * @ref OFSocketAddressGetIPXNode to get the IPX node and * @ref OFSocketAddressIPXPort to get the port (sometimes also called * socket number). * * @warning Even though the OFCopying protocol is implemented, it does *not* * return an independent copy of the socket, but instead retains it. * This is so that the socket can be used as a key for a dictionary, * so context can be associated with a socket. Using a socket in more * than one thread at the same time is not thread-safe, even if copy * was called to create one "instance" for every thread! */ @interface OFIPXSocket: OFDatagramSocket { #ifndef OF_WINDOWS uint8_t _packetType; #endif OF_RESERVE_IVARS(OFIPXSocket, 4) } /** * @brief The delegate for asynchronous operations on the socket. * * @note The delegate is retained for as long as asynchronous operations are * still ongoing. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id delegate; /** * @brief Bind the socket to the specified network, node and port with the * specified packet type. * * @param network The IPX network to bind to. 0 means the current network. * @param node The IPX network to bind to. An all zero node means the * computer's node. * @param port The port (sometimes called socket number) to bind to. 0 means to * pick one and return via the returned socket address. * @param packetType The packet type to use on the socket * @return The address on which this socket can be reached * @throw OFBindIPXSocketFailedException Binding failed * @throw OFAlreadyOpenException The socket is already bound */ - (OFSocketAddress) bindToNetwork: (uint32_t)network node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port packetType: (uint8_t)packetType; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFIPXSocket.m000066400000000000000000000075701465614216400156530ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #ifdef HAVE_FCNTL_H # include #endif #import "OFIPXSocket.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFAlreadyOpenException.h" #import "OFBindIPXSocketFailedException.h" #ifndef NSPROTO_IPX # define NSPROTO_IPX 0 #endif @implementation OFIPXSocket @dynamic delegate; - (OFSocketAddress)bindToNetwork: (uint32_t)network node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port packetType: (uint8_t)packetType { OFSocketAddress address; int protocol = 0; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) int flags; #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyOpenException exceptionWithObject: self]; address = OFSocketAddressMakeIPX(network, node, port); #if defined(OF_WINDOWS) || defined(OF_FREEBSD) protocol = NSPROTO_IPX + packetType; #else _packetType = address.sockaddr.ipx.sipx_type = packetType; #endif if ((_socket = socket(address.sockaddr.ipx.sipx_family, SOCK_DGRAM | SOCK_CLOEXEC, protocol)) == OFInvalidSocketHandle) @throw [OFBindIPXSocketFailedException exceptionWithNetwork: network node: node port: port packetType: packetType socket: self errNo: _OFSocketErrNo()]; _canBlock = true; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); #endif if (bind(_socket, (struct sockaddr *)&address.sockaddr, address.length) != 0) { int errNo = _OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindIPXSocketFailedException exceptionWithNetwork: network node: node port: port packetType: packetType socket: self errNo: errNo]; } memset(&address, 0, sizeof(address)); address.family = OFSocketAddressFamilyIPX; address.length = (socklen_t)sizeof(address.sockaddr); if (_OFGetSockName(_socket, (struct sockaddr *)&address.sockaddr, &address.length) != 0) { int errNo = _OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindIPXSocketFailedException exceptionWithNetwork: network node: node port: port packetType: packetType socket: self errNo: errNo]; } if (address.sockaddr.ipx.sipx_family != AF_IPX) { closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindIPXSocketFailedException exceptionWithNetwork: network node: node port: port packetType: packetType socket: self errNo: EAFNOSUPPORT]; } return address; } #if !defined(OF_WINDOWS) && !defined(OF_FREEBSD) - (void)sendBuffer: (const void *)buffer length: (size_t)length receiver: (const OFSocketAddress *)receiver { OFSocketAddress fixedReceiver; memcpy(&fixedReceiver, receiver, sizeof(fixedReceiver)); /* If it's not IPX, no fix-up needed - it will fail anyway. */ if (fixedReceiver.family == OFSocketAddressFamilyIPX) fixedReceiver.sockaddr.ipx.sipx_type = _packetType; [super sendBuffer: buffer length: length receiver: &fixedReceiver]; } #endif @end objfw-1.1.6/src/OFIRI+Private.h000066400000000000000000000015501465614216400160560ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFIRI.h" OF_ASSUME_NONNULL_BEGIN @interface OFIRI () - (instancetype)of_init OF_METHOD_FAMILY(init); @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFIRI.h000066400000000000000000000303501465614216400144500ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFCharacterSet.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFDictionary OF_GENERIC(KeyType, ObjectType); @class OFNumber; @class OFPair OF_GENERIC(FirstType, SecondType); @class OFString; /** * @class OFIRI OFIRI.h ObjFW/OFIRI.h * * @brief A class for representing IRIs, URIs, URLs and URNs, for parsing them * as well as accessing parts of them. * * This class follows RFC 3976 and RFC 3987. */ @interface OFIRI: OFObject { OFString *_scheme; OFString *_Nullable _percentEncodedHost; OFNumber *_Nullable _port; OFString *_Nullable _percentEncodedUser; OFString *_Nullable _percentEncodedPassword; OFString *_percentEncodedPath; OFString *_Nullable _percentEncodedQuery; OFString *_Nullable _percentEncodedFragment; OF_RESERVE_IVARS(OFIRI, 4) } /** * @brief The scheme part of the IRI. */ @property (readonly, copy, nonatomic) OFString *scheme; /** * @brief The host part of the IRI. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *host; /** * @brief The host part of the IRI in percent-encoded form. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *percentEncodedHost; /** * @brief The port part of the IRI. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFNumber *port; /** * @brief The user part of the IRI. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *user; /** * @brief The user part of the IRI in percent-encoded form. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *percentEncodedUser; /** * @brief The password part of the IRI. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *password; /** * @brief The password part of the IRI in percent-encoded form. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *percentEncodedPassword; /** * @brief The path part of the IRI. */ @property (readonly, copy, nonatomic) OFString *path; /** * @brief The path part of the IRI in percent-encoded form. */ @property (readonly, copy, nonatomic) OFString *percentEncodedPath; /** * @brief The path of the IRI split into components. * * The first component must always be `/` to designate the root. */ @property (readonly, copy, nonatomic) OFArray OF_GENERIC(OFString *) *pathComponents; /** * @brief The last path component of the IRI. * * Returns the empty string if the path is the root. */ @property (readonly, copy, nonatomic) OFString *lastPathComponent; /** * @brief The path extension of the IRI. */ @property (readonly, copy, nonatomic) OFString *pathExtension; /** * @brief The query part of the IRI. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *query; /** * @brief The query part of the IRI in percent-encoded form. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *percentEncodedQuery; /** * @brief The query part of the IRI as an array. * * For example, a query like `key1=value1&key2=value2` would correspond to the * following array: * * @[ * [OFPair pairWithFirstObject: @"key1" secondObject: @"value1"], * [OFPair pairWithFirstObject: @"key2" secondObject: @"value2"], * ] * * @throw OFInvalidFormatException The query is not in the correct format */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, OFString *) *) *queryItems; /** * @brief The fragment part of the IRI. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *fragment; /** * @brief The fragment part of the IRI in percent-encoded form. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *percentEncodedFragment; /** * @brief The IRI as a string. */ @property (readonly, nonatomic) OFString *string; /** * @brief The IRI with relative subpaths resolved. */ @property (readonly, nonatomic) OFIRI *IRIByStandardizingPath; /** * @brief The IRI with the last path component deleted. */ @property (readonly, nonatomic) OFIRI *IRIByDeletingLastPathComponent; /** * @brief The IRI with the path extension deleted. */ @property (readonly, nonatomic) OFIRI *IRIByDeletingPathExtension; /** * @brief The IRI with percent-encoding added for all Unicode characters. */ @property (readonly, nonatomic) OFIRI *IRIByAddingPercentEncodingForUnicodeCharacters; #ifdef OF_HAVE_FILES /** * @brief The local file system representation for a file IRI. * * @note This only exists for IRIs with the file scheme and throws an exception * otherwise. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *fileSystemRepresentation; #endif /** * @brief Creates a new IRI with the specified string. * * @param string A string describing an IRI * @return A new, autoreleased OFIRI * @throw OFInvalidFormatException The specified string is not a valid IRI * string */ + (instancetype)IRIWithString: (OFString *)string; /** * @brief Creates a new IRI with the specified string relative to the * specified IRI. * * @param string A string describing a relative or absolute IRI * @param IRI An IRI to which the string is relative * @return A new, autoreleased OFIRI * @throw OFInvalidFormatException The specified string is not a valid IRI * string */ + (instancetype)IRIWithString: (OFString *)string relativeToIRI: (OFIRI *)IRI; #ifdef OF_HAVE_FILES /** * @brief Creates a new IRI with the specified local file path. * * If a directory exists at the specified path, a slash is appended if there is * no slash yet. * * @param path The local file path * @return A new, autoreleased OFIRI * @throw OFInvalidFormatException The specified path is not a valid path */ + (instancetype)fileIRIWithPath: (OFString *)path; /** * @brief Creates a new IRI with the specified local file path. * * @param path The local file path * @param isDirectory Whether the path is a directory, in which case a slash is * appended if there is no slash yet * @return An initialized OFIRI */ + (instancetype)fileIRIWithPath: (OFString *)path isDirectory: (bool)isDirectory; #endif /** * @brief Initializes an already allocated OFIRI with the specified string. * * @param string A string describing an IRI * @return An initialized OFIRI * @throw OFInvalidFormatException The specified string is not a valid IRI * string */ - (instancetype)initWithString: (OFString *)string; /** * @brief Initializes an already allocated OFIRI with the specified string and * relative IRI. * * @param string A string describing a relative or absolute IRI * @param IRI An IRI to which the string is relative * @return An initialized OFIRI * @throw OFInvalidFormatException The specified string is not a valid IRI * string */ - (instancetype)initWithString: (OFString *)string relativeToIRI: (OFIRI *)IRI; #ifdef OF_HAVE_FILES /** * @brief Initializes an already allocated OFIRI with the specified local file * path. * * If a directory exists at the specified path, a slash is appended if there is * no slash yet. * * @param path The local file path * @return An initialized OFIRI * @throw OFInvalidFormatException The specified path is not a valid path */ - (instancetype)initFileIRIWithPath: (OFString *)path; /** * @brief Initializes an already allocated OFIRI with the specified local file * path. * * @param path The local file path * @param isDirectory Whether the path is a directory, in which case a slash is * appended if there is no slash yet * @return An initialized OFIRI */ - (instancetype)initFileIRIWithPath: (OFString *)path isDirectory: (bool)isDirectory; #endif - (instancetype)init OF_UNAVAILABLE; /** * @brief Returns a new IRI with the specified path component appended. * * If the IRI is a file IRI, the file system is queried whether the appended * component is a directory. * * @param component The path component to append. If it starts with the slash, * the component is not appended, but replaces the path * instead. * @return A new IRI with the specified path component appended */ - (OFIRI *)IRIByAppendingPathComponent: (OFString *)component; /** * @brief Returns a new IRI with the specified path component appended. * * @param component The path component to append. If it starts with the slash, * the component is not appended, but replaces the path * instead. * @param isDirectory Whether the appended component is a directory, meaning * that the IRI path should have a trailing slash * @return A new IRI with the specified path component appended */ - (OFIRI *)IRIByAppendingPathComponent: (OFString *)component isDirectory: (bool)isDirectory; /** * @brief Returns a new IRI with the specified path extension appended. * * @param extension The path extension to append * @return A new IRI with the specified path extension appended. */ - (OFIRI *)IRIByAppendingPathExtension: (OFString *)extension; @end @interface OFCharacterSet (IRICharacterSets) #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nonatomic) OFCharacterSet *IRISchemeAllowedCharacterSet; @property (class, readonly, nonatomic) OFCharacterSet *IRIHostAllowedCharacterSet; @property (class, readonly, nonatomic) OFCharacterSet *IRIUserAllowedCharacterSet; @property (class, readonly, nonatomic) OFCharacterSet *IRIPasswordAllowedCharacterSet; @property (class, readonly, nonatomic) OFCharacterSet *IRIPathAllowedCharacterSet; @property (class, readonly, nonatomic) OFCharacterSet *IRIQueryAllowedCharacterSet; @property (class, readonly, nonatomic) OFCharacterSet *IRIQueryKeyValueAllowedCharacterSet; @property (class, readonly, nonatomic) OFCharacterSet *IRIFragmentAllowedCharacterSet; #endif /** * @brief Returns the characters allowed in the scheme part of an IRI. * * @return The characters allowed in the scheme part of an IRI. */ + (OFCharacterSet *)IRISchemeAllowedCharacterSet; /** * @brief Returns the characters allowed in the host part of an IRI. * * @return The characters allowed in the host part of an IRI. */ + (OFCharacterSet *)IRIHostAllowedCharacterSet; /** * @brief Returns the characters allowed in the user part of an IRI. * * @return The characters allowed in the user part of an IRI. */ + (OFCharacterSet *)IRIUserAllowedCharacterSet; /** * @brief Returns the characters allowed in the password part of an IRI. * * @return The characters allowed in the password part of an IRI. */ + (OFCharacterSet *)IRIPasswordAllowedCharacterSet; /** * @brief Returns the characters allowed in the path part of an IRI. * * @return The characters allowed in the path part of an IRI. */ + (OFCharacterSet *)IRIPathAllowedCharacterSet; /** * @brief Returns the characters allowed in the query part of an IRI. * * @return The characters allowed in the query part of an IRI. */ + (OFCharacterSet *)IRIQueryAllowedCharacterSet; /** * @brief Returns the characters allowed in a key/value in the query part of a * IRI. * * @return The characters allowed in a key/value in the query part of an IRI. */ + (OFCharacterSet *)IRIQueryKeyValueAllowedCharacterSet; /** * @brief Returns the characters allowed in the fragment part of an IRI. * * @return The characters allowed in the fragment part of an IRI. */ + (OFCharacterSet *)IRIFragmentAllowedCharacterSet; @end #ifdef __cplusplus extern "C" { #endif extern bool _OFIRIIsIPv6Host(OFString *host) OF_VISIBILITY_HIDDEN; extern void _OFIRIVerifyIsEscaped(OFString *, OFCharacterSet *, bool) OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END #import "OFMutableIRI.h" objfw-1.1.6/src/OFIRI.m000066400000000000000000000757121465614216400144700ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "OFIRI.h" #import "OFArray.h" #import "OFDictionary.h" #ifdef OF_HAVE_FILES # import "OFFileManager.h" # import "OFFileIRIHandler.h" #endif #import "OFNumber.h" #import "OFOnce.h" #import "OFPair.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" @interface OFIRIAllowedCharacterSetBase: OFCharacterSet @end @interface OFIRIAllowedCharacterSet: OFIRIAllowedCharacterSetBase @end @interface OFIRISchemeAllowedCharacterSet: OFIRIAllowedCharacterSetBase @end @interface OFIRIPathAllowedCharacterSet: OFIRIAllowedCharacterSetBase @end @interface OFIRIQueryAllowedCharacterSet: OFIRIAllowedCharacterSetBase @end @interface OFIRIQueryKeyValueAllowedCharacterSet: OFIRIAllowedCharacterSetBase @end @interface OFIRIFragmentAllowedCharacterSet: OFIRIAllowedCharacterSetBase @end OF_DIRECT_MEMBERS @interface OFInvertedCharacterSetWithoutPercent: OFCharacterSet { OFCharacterSet *_characterSet; bool (*_characterIsMember)(id, SEL, OFUnichar); } - (instancetype)initWithCharacterSet: (OFCharacterSet *)characterSet; @end static OFCharacterSet *IRIAllowedCharacterSet = nil; static OFCharacterSet *IRISchemeAllowedCharacterSet = nil; static OFCharacterSet *IRIPathAllowedCharacterSet = nil; static OFCharacterSet *IRIQueryAllowedCharacterSet = nil; static OFCharacterSet *IRIQueryKeyValueAllowedCharacterSet = nil; static OFCharacterSet *IRIFragmentAllowedCharacterSet = nil; static OFOnceControl IRIAllowedCharacterSetOnce = OFOnceControlInitValue; static void initIRIAllowedCharacterSet(void) { IRIAllowedCharacterSet = [[OFIRIAllowedCharacterSet alloc] init]; } static void initIRISchemeAllowedCharacterSet(void) { IRISchemeAllowedCharacterSet = [[OFIRISchemeAllowedCharacterSet alloc] init]; } static void initIRIPathAllowedCharacterSet(void) { IRIPathAllowedCharacterSet = [[OFIRIPathAllowedCharacterSet alloc] init]; } static void initIRIQueryAllowedCharacterSet(void) { IRIQueryAllowedCharacterSet = [[OFIRIQueryAllowedCharacterSet alloc] init]; } static void initIRIQueryKeyValueAllowedCharacterSet(void) { IRIQueryKeyValueAllowedCharacterSet = [[OFIRIQueryKeyValueAllowedCharacterSet alloc] init]; } static void initIRIFragmentAllowedCharacterSet(void) { IRIFragmentAllowedCharacterSet = [[OFIRIFragmentAllowedCharacterSet alloc] init]; } bool _OFIRIIsIPv6Host(OFString *host) { const char *UTF8String = host.UTF8String; bool hasColon = false; while (*UTF8String != '\0') { if (!OFASCIIIsDigit(*UTF8String) && *UTF8String != ':' && (*UTF8String < 'a' || *UTF8String > 'f') && (*UTF8String < 'A' || *UTF8String > 'F')) return false; if (*UTF8String == ':') hasColon = true; UTF8String++; } return hasColon; } static bool isUnicode(OFUnichar character) { if (character >= 0xA0 && character <= 0xD7FF) return true; if (character >= 0xF900 && character <= 0xFDCF) return true; if (character >= 0xFDF0 && character <= 0xFFEF) return true; if (character >= 0x10000 && character <= 0x1FFFD) return true; if (character >= 0x20000 && character <= 0x2FFFD) return true; if (character >= 0x30000 && character <= 0x3FFFD) return true; if (character >= 0x40000 && character <= 0x4FFFD) return true; if (character >= 0x50000 && character <= 0x5FFFD) return true; if (character >= 0x60000 && character <= 0x6FFFD) return true; if (character >= 0x70000 && character <= 0x7FFFD) return true; if (character >= 0x80000 && character <= 0x8FFFD) return true; if (character >= 0x90000 && character <= 0x9FFFD) return true; if (character >= 0xA0000 && character <= 0xAFFFD) return true; if (character >= 0xB0000 && character <= 0xBFFFD) return true; if (character >= 0xC0000 && character <= 0xCFFFD) return true; if (character >= 0xD0000 && character <= 0xDFFFD) return true; if (character >= 0xE0000 && character <= 0xEFFFD) return true; return false; } static bool isUnicodePrivate(OFUnichar character) { if (character >= 0xE00 && character <= 0xF8FF) return true; if (character >= 0xF0000 && character <= 0xFFFFD) return true; if (character >= 0x100000 && character <= 0x10FFFD) return true; return false; } @implementation OFIRIAllowedCharacterSetBase OF_SINGLETON_METHODS @end @implementation OFIRIAllowedCharacterSet - (bool)characterIsMember: (OFUnichar)character { if (character < CHAR_MAX && OFASCIIIsAlnum(character)) return true; if (isUnicode(character)) return true; switch (character) { case '-': case '.': case '_': case '~': case '!': case '$': case '&': case '\'': case '(': case ')': case '*': case '+': case ',': case ';': case '=': return true; default: return false; } } @end @implementation OFIRISchemeAllowedCharacterSet - (bool)characterIsMember: (OFUnichar)character { if (character < CHAR_MAX && OFASCIIIsAlnum(character)) return true; switch (character) { case '+': case '-': case '.': return true; default: return false; } } @end @implementation OFIRIPathAllowedCharacterSet - (bool)characterIsMember: (OFUnichar)character { if (character < CHAR_MAX && OFASCIIIsAlnum(character)) return true; if (isUnicode(character)) return true; switch (character) { case '-': case '.': case '_': case '~': case '!': case '$': case '&': case '\'': case '(': case ')': case '*': case '+': case ',': case ';': case '=': case ':': case '@': case '/': return true; default: return false; } } @end @implementation OFIRIQueryAllowedCharacterSet - (bool)characterIsMember: (OFUnichar)character { if (character < CHAR_MAX && OFASCIIIsAlnum(character)) return true; if (isUnicode(character) || isUnicodePrivate(character)) return true; switch (character) { case '-': case '.': case '_': case '~': case '!': case '$': case '&': case '\'': case '(': case ')': case '*': case '+': case ',': case ';': case '=': case ':': case '@': case '/': case '?': return true; default: return false; } } @end @implementation OFIRIQueryKeyValueAllowedCharacterSet - (bool)characterIsMember: (OFUnichar)character { if (character < CHAR_MAX && OFASCIIIsAlnum(character)) return true; if (isUnicode(character) || isUnicodePrivate(character)) return true; switch (character) { case '-': case '.': case '_': case '~': case '!': case '$': case '\'': case '(': case ')': case '*': case '+': case ',': case ';': case ':': case '@': case '/': case '?': return true; default: return false; } } @end @implementation OFIRIFragmentAllowedCharacterSet - (bool)characterIsMember: (OFUnichar)character { if (character < CHAR_MAX && OFASCIIIsAlnum(character)) return true; if (isUnicode(character)) return true; switch (character) { case '-': case '.': case '_': case '~': case '!': case '$': case '&': case '\'': case '(': case ')': case '*': case '+': case ',': case ';': case '=': case ':': case '@': case '/': case '?': return true; default: return false; } } @end @implementation OFInvertedCharacterSetWithoutPercent - (instancetype)initWithCharacterSet: (OFCharacterSet *)characterSet { self = [super init]; @try { _characterSet = [characterSet retain]; _characterIsMember = (bool (*)(id, SEL, OFUnichar)) [_characterSet methodForSelector: @selector(characterIsMember:)]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_characterSet release]; [super dealloc]; } - (bool)characterIsMember: (OFUnichar)character { return (character != '%' && !_characterIsMember(_characterSet, @selector(characterIsMember:), character)); } @end void _OFIRIVerifyIsEscaped(OFString *string, OFCharacterSet *characterSet, bool allowPercent) { void *pool = objc_autoreleasePoolPush(); if (allowPercent) characterSet = [[[OFInvertedCharacterSetWithoutPercent alloc] initWithCharacterSet: characterSet] autorelease]; else characterSet = characterSet.invertedSet; if ([string indexOfCharacterFromSet: characterSet] != OFNotFound) @throw [OFInvalidFormatException exception]; objc_autoreleasePoolPop(pool); } @implementation OFCharacterSet (IRICharacterSets) + (OFCharacterSet *)IRISchemeAllowedCharacterSet { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, initIRISchemeAllowedCharacterSet); return IRISchemeAllowedCharacterSet; } + (OFCharacterSet *)IRIHostAllowedCharacterSet { OFOnce(&IRIAllowedCharacterSetOnce, initIRIAllowedCharacterSet); return IRIAllowedCharacterSet; } + (OFCharacterSet *)IRIUserAllowedCharacterSet { OFOnce(&IRIAllowedCharacterSetOnce, initIRIAllowedCharacterSet); return IRIAllowedCharacterSet; } + (OFCharacterSet *)IRIPasswordAllowedCharacterSet { OFOnce(&IRIAllowedCharacterSetOnce, initIRIAllowedCharacterSet); return IRIAllowedCharacterSet; } + (OFCharacterSet *)IRIPathAllowedCharacterSet { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, initIRIPathAllowedCharacterSet); return IRIPathAllowedCharacterSet; } + (OFCharacterSet *)IRIQueryAllowedCharacterSet { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, initIRIQueryAllowedCharacterSet); return IRIQueryAllowedCharacterSet; } + (OFCharacterSet *)IRIQueryKeyValueAllowedCharacterSet { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, initIRIQueryKeyValueAllowedCharacterSet); return IRIQueryKeyValueAllowedCharacterSet; } + (OFCharacterSet *)IRIFragmentAllowedCharacterSet { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, initIRIFragmentAllowedCharacterSet); return IRIFragmentAllowedCharacterSet; } @end @implementation OFIRI + (instancetype)IRI { return [[[self alloc] init] autorelease]; } + (instancetype)IRIWithString: (OFString *)string { return [[[self alloc] initWithString: string] autorelease]; } + (instancetype)IRIWithString: (OFString *)string relativeToIRI: (OFIRI *)IRI { return [[[self alloc] initWithString: string relativeToIRI: IRI] autorelease]; } #ifdef OF_HAVE_FILES + (instancetype)fileIRIWithPath: (OFString *)path { return [[[self alloc] initFileIRIWithPath: path] autorelease]; } + (instancetype)fileIRIWithPath: (OFString *)path isDirectory: (bool)isDirectory { return [[[self alloc] initFileIRIWithPath: path isDirectory: isDirectory] autorelease]; } #endif static void parseUserInfo(OFIRI *self, const char *UTF8String, size_t length) { const char *colon; if ((colon = memchr(UTF8String, ':', length)) != NULL) { self->_percentEncodedUser = [[OFString alloc] initWithUTF8String: UTF8String length: colon - UTF8String]; self->_percentEncodedPassword = [[OFString alloc] initWithUTF8String: colon + 1 length: length - (colon - UTF8String) - 1]; _OFIRIVerifyIsEscaped(self->_percentEncodedPassword, [OFCharacterSet IRIPasswordAllowedCharacterSet], true); } else self->_percentEncodedUser = [[OFString alloc] initWithUTF8String: UTF8String length: length]; _OFIRIVerifyIsEscaped(self->_percentEncodedUser, [OFCharacterSet IRIUserAllowedCharacterSet], true); } static void parseHostPort(OFIRI *self, const char *UTF8String, size_t length) { OFString *portString; if (*UTF8String == '[') { const char *end = memchr(UTF8String, ']', length); if (end == NULL) @throw [OFInvalidFormatException exception]; for (const char *iter = UTF8String + 1; iter < end; iter++) if (!OFASCIIIsDigit(*iter) && *iter != ':' && (*iter < 'a' || *iter > 'f') && (*iter < 'A' || *iter > 'F')) @throw [OFInvalidFormatException exception]; self->_percentEncodedHost = [[OFString alloc] initWithUTF8String: UTF8String length: end - UTF8String + 1]; length -= (end - UTF8String) + 1; UTF8String = end + 1; } else { const char *colon = memchr(UTF8String, ':', length); if (colon != NULL) { self->_percentEncodedHost = [[OFString alloc] initWithUTF8String: UTF8String length: colon - UTF8String]; length -= colon - UTF8String; UTF8String = colon; } else { self->_percentEncodedHost = [[OFString alloc] initWithUTF8String: UTF8String length: length]; UTF8String += length; length = 0; } _OFIRIVerifyIsEscaped(self->_percentEncodedHost, [OFCharacterSet IRIHostAllowedCharacterSet], true); } if (length == 0) return; if (length <= 1 || *UTF8String != ':') @throw [OFInvalidFormatException exception]; UTF8String++; length--; for (size_t i = 0; i < length; i++) if (!OFASCIIIsDigit(UTF8String[i])) @throw [OFInvalidFormatException exception]; portString = [OFString stringWithUTF8String: UTF8String length: length]; if (portString.unsignedLongLongValue > 65535) @throw [OFInvalidFormatException exception]; self->_port = [[OFNumber alloc] initWithUnsignedShort: (unsigned short)portString.unsignedLongLongValue]; } static size_t parseAuthority(OFIRI *self, const char *UTF8String, size_t length) { size_t ret; const char *slash, *at; if ((slash = memchr(UTF8String, '/', length)) != NULL) length = slash - UTF8String; ret = length; if ((at = memchr(UTF8String, '@', length)) != NULL) { parseUserInfo(self, UTF8String, at - UTF8String); length -= at - UTF8String + 1; UTF8String = at + 1; } parseHostPort(self, UTF8String, length); return ret; } static void parsePathQueryFragment(const char *UTF8String, size_t length, OFString **pathString, OFString **queryString, OFString **fragmentString) { const char *fragment, *query; if ((fragment = memchr(UTF8String, '#', length)) != NULL) { *fragmentString = [OFString stringWithUTF8String: fragment + 1 length: length - (fragment - UTF8String) - 1]; _OFIRIVerifyIsEscaped(*fragmentString, [OFCharacterSet IRIQueryAllowedCharacterSet], true); length = fragment - UTF8String; } if ((query = memchr(UTF8String, '?', length)) != NULL) { *queryString = [OFString stringWithUTF8String: query + 1 length: length - (query - UTF8String) - 1]; _OFIRIVerifyIsEscaped(*queryString, [OFCharacterSet IRIFragmentAllowedCharacterSet], true); length = query - UTF8String; } *pathString = [OFString stringWithUTF8String: UTF8String length: length]; _OFIRIVerifyIsEscaped(*pathString, [OFCharacterSet IRIPathAllowedCharacterSet], true); } - (instancetype)initWithString: (OFString *)string { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); const char *UTF8String = string.UTF8String; size_t length = string.UTF8StringLength; const char *colon; OFString *path, *query = nil, *fragment = nil; if ((colon = strchr(UTF8String, ':')) == NULL || colon - UTF8String < 1 || !OFASCIIIsAlpha(UTF8String[0])) @throw [OFInvalidFormatException exception]; _scheme = [[[OFString stringWithUTF8String: UTF8String length: colon - UTF8String] lowercaseString] copy]; _OFIRIVerifyIsEscaped(_scheme, [OFCharacterSet IRISchemeAllowedCharacterSet], false); length -= colon - UTF8String + 1; UTF8String = colon + 1; if (length >= 2 && UTF8String[0] == '/' && UTF8String[1] == '/') { size_t authorityLength; UTF8String += 2; length -= 2; authorityLength = parseAuthority(self, UTF8String, length); UTF8String += authorityLength; length -= authorityLength; if (length > 0) OFEnsure(UTF8String[0] == '/'); } parsePathQueryFragment(UTF8String, length, &path, &query, &fragment); _percentEncodedPath = [path copy]; _percentEncodedQuery = [query copy]; _percentEncodedFragment = [fragment copy]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } static bool isAbsolute(OFString *string) { void *pool = objc_autoreleasePoolPush(); @try { const char *UTF8String = string.UTF8String; size_t length = string.UTF8StringLength; if (length < 1) return false; if (!OFASCIIIsAlpha(UTF8String[0])) return false; for (size_t i = 1; i < length; i++) { if (UTF8String[i] == ':') return true; if (!OFASCIIIsAlnum(UTF8String[i]) && UTF8String[i] != '+' && UTF8String[i] != '-' && UTF8String[i] != '.') return false; } } @finally { objc_autoreleasePoolPop(pool); } return false; } static OFString * merge(OFString *base, OFString *path) { OFMutableArray *components; if (base.length == 0) base = @"/"; components = [[[base componentsSeparatedByString: @"/"] mutableCopy] autorelease]; if (components.count == 1) [components addObject: path]; else [components replaceObjectAtIndex: components.count - 1 withObject: path]; return [components componentsJoinedByString: @"/"]; } - (instancetype)initWithString: (OFString *)string relativeToIRI: (OFIRI *)IRI { bool absolute; @try { absolute = isAbsolute(string); } @catch (id e) { [self release]; @throw e; } if (absolute) return [self initWithString: string]; self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); const char *UTF8String = string.UTF8String; size_t length = string.UTF8StringLength; bool hasAuthority = false; OFString *path, *query = nil, *fragment = nil; _scheme = [IRI->_scheme copy]; if (length >= 2 && UTF8String[0] == '/' && UTF8String[1] == '/') { size_t authorityLength; hasAuthority = true; UTF8String += 2; length -= 2; authorityLength = parseAuthority(self, UTF8String, length); UTF8String += authorityLength; length -= authorityLength; if (length > 0) OFEnsure(UTF8String[0] == '/'); } else { _percentEncodedHost = [IRI->_percentEncodedHost copy]; _port = [IRI->_port copy]; _percentEncodedUser = [IRI->_percentEncodedUser copy]; _percentEncodedPassword = [IRI->_percentEncodedPassword copy]; } parsePathQueryFragment(UTF8String, length, &path, &query, &fragment); _percentEncodedFragment = [fragment copy]; if (hasAuthority) { _percentEncodedPath = [path copy]; _percentEncodedQuery = [query copy]; } else { if (path.length == 0) { _percentEncodedPath = [IRI->_percentEncodedPath copy]; _percentEncodedQuery = (query != nil ? [query copy] : [IRI->_percentEncodedQuery copy]); } else { if ([path hasPrefix: @"/"]) _percentEncodedPath = [path copy]; else _percentEncodedPath = [merge( IRI->_percentEncodedPath, path) copy]; _percentEncodedQuery = [query copy]; } } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } #ifdef OF_HAVE_FILES - (instancetype)initFileIRIWithPath: (OFString *)path { bool isDirectory; @try { void *pool = objc_autoreleasePoolPush(); isDirectory = [path of_isDirectoryPath]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } self = [self initFileIRIWithPath: path isDirectory: isDirectory]; return self; } - (instancetype)initFileIRIWithPath: (OFString *)path isDirectory: (bool)isDirectory { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFString *percentEncodedHost = nil; if (!path.absolutePath) { OFString *currentDirectoryPath = [OFFileManager defaultManager].currentDirectoryPath; path = [currentDirectoryPath stringByAppendingPathComponent: path]; path = path.stringByStandardizingPath; } path = [path of_pathToIRIPathWithPercentEncodedHost: &percentEncodedHost]; _percentEncodedHost = [percentEncodedHost copy]; if (isDirectory && ![path hasSuffix: @"/"]) path = [path stringByAppendingString: @"/"]; _scheme = @"file"; _percentEncodedPath = [[path stringByAddingPercentEncodingWithAllowedCharacters: [OFCharacterSet IRIPathAllowedCharacterSet]] copy]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } #endif - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)of_init { return [super init]; } - (void)dealloc { [_scheme release]; [_percentEncodedHost release]; [_port release]; [_percentEncodedUser release]; [_percentEncodedPassword release]; [_percentEncodedPath release]; [_percentEncodedQuery release]; [_percentEncodedFragment release]; [super dealloc]; } - (bool)isEqual: (id)object { OFIRI *IRI; if (object == self) return true; if (![object isKindOfClass: [OFIRI class]]) return false; IRI = object; if (![IRI->_scheme isEqual: _scheme]) return false; if (IRI->_percentEncodedHost != _percentEncodedHost && ![IRI->_percentEncodedHost isEqual: _percentEncodedHost]) return false; if (IRI->_port != _port && ![IRI->_port isEqual: _port]) return false; if (IRI->_percentEncodedUser != _percentEncodedUser && ![IRI->_percentEncodedUser isEqual: _percentEncodedUser]) return false; if (IRI->_percentEncodedPassword != _percentEncodedPassword && ![IRI->_percentEncodedPassword isEqual: _percentEncodedPassword]) return false; if (![IRI->_percentEncodedPath isEqual: _percentEncodedPath]) return false; if (IRI->_percentEncodedQuery != _percentEncodedQuery && ![IRI->_percentEncodedQuery isEqual: _percentEncodedQuery]) return false; if (IRI->_percentEncodedFragment != _percentEncodedFragment && ![IRI->_percentEncodedFragment isEqual: _percentEncodedFragment]) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _scheme.hash); OFHashAddHash(&hash, _percentEncodedHost.hash); OFHashAddHash(&hash, _port.hash); OFHashAddHash(&hash, _percentEncodedUser.hash); OFHashAddHash(&hash, _percentEncodedPassword.hash); OFHashAddHash(&hash, _percentEncodedPath.hash); OFHashAddHash(&hash, _percentEncodedQuery.hash); OFHashAddHash(&hash, _percentEncodedFragment.hash); OFHashFinalize(&hash); return hash; } - (OFString *)scheme { return _scheme; } - (OFString *)host { if ([_percentEncodedHost hasPrefix: @"["] && [_percentEncodedHost hasSuffix: @"]"]) { OFString *host = [_percentEncodedHost substringWithRange: OFMakeRange(1, _percentEncodedHost.length - 2)]; if (!_OFIRIIsIPv6Host(host)) @throw [OFInvalidArgumentException exception]; return host; } return _percentEncodedHost.stringByRemovingPercentEncoding; } - (OFString *)percentEncodedHost { return _percentEncodedHost; } - (OFNumber *)port { return _port; } - (OFString *)user { return _percentEncodedUser.stringByRemovingPercentEncoding; } - (OFString *)percentEncodedUser { return _percentEncodedUser; } - (OFString *)password { return _percentEncodedPassword.stringByRemovingPercentEncoding; } - (OFString *)percentEncodedPassword { return _percentEncodedPassword; } - (OFString *)path { return _percentEncodedPath.stringByRemovingPercentEncoding; } - (OFString *)percentEncodedPath { return _percentEncodedPath; } - (OFArray *)pathComponents { void *pool = objc_autoreleasePoolPush(); #ifdef OF_HAVE_FILES bool isFile = [_scheme isEqual: @"file"]; #endif OFMutableArray *ret; size_t count; #ifdef OF_HAVE_FILES if (isFile) { OFString *path = [_percentEncodedPath of_IRIPathToPathWithPercentEncodedHost: nil]; ret = [[path.pathComponents mutableCopy] autorelease]; if (![ret.firstObject isEqual: @"/"]) [ret insertObject: @"/" atIndex: 0]; } else #endif ret = [[[_percentEncodedPath componentsSeparatedByString: @"/"] mutableCopy] autorelease]; count = ret.count; if (count > 0 && [ret.firstObject length] == 0) [ret replaceObjectAtIndex: 0 withObject: @"/"]; for (size_t i = 0; i < count; i++) { OFString *component = [ret objectAtIndex: i]; #ifdef OF_HAVE_FILES if (isFile) component = [component of_pathComponentToIRIPathComponent]; #endif component = component.stringByRemovingPercentEncoding; [ret replaceObjectAtIndex: i withObject: component]; } [ret makeImmutable]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)lastPathComponent { void *pool = objc_autoreleasePoolPush(); OFString *path = _percentEncodedPath; const char *UTF8String, *lastComponent; size_t length; OFString *ret; if ([path isEqual: @"/"]) { objc_autoreleasePoolPop(pool); return @"/"; } if ([path hasSuffix: @"/"]) path = [path substringToIndex: path.length - 1]; UTF8String = lastComponent = path.UTF8String; length = path.UTF8StringLength; for (size_t i = 1; i <= length; i++) { if (UTF8String[length - i] == '/') { lastComponent = UTF8String + (length - i) + 1; break; } } ret = [OFString stringWithUTF8String: lastComponent length: length - (lastComponent - UTF8String)]; ret = [ret.stringByRemovingPercentEncoding retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)pathExtension { void *pool = objc_autoreleasePoolPush(); OFString *ret, *fileName; size_t pos; fileName = self.lastPathComponent; pos = [fileName rangeOfString: @"." options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return @""; } ret = [fileName substringFromIndex: pos + 1]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)query { return _percentEncodedQuery.stringByRemovingPercentEncoding; } - (OFString *)percentEncodedQuery { return _percentEncodedQuery; } - (OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, OFString *) *) *)queryItems { void *pool; OFArray OF_GENERIC(OFString *) *pairs; OFMutableArray OF_GENERIC(OFPair OF_GENERIC(OFString *, OFString *) *) *ret; if (_percentEncodedQuery == nil) return nil; pool = objc_autoreleasePoolPush(); pairs = [_percentEncodedQuery componentsSeparatedByString: @"&"]; ret = [OFMutableArray arrayWithCapacity: pairs.count]; for (OFString *pair in pairs) { OFArray *parts = [pair componentsSeparatedByString: @"="]; OFString *name, *value; if (parts.count != 2) @throw [OFInvalidFormatException exception]; name = [[parts objectAtIndex: 0] stringByRemovingPercentEncoding]; value = [[parts objectAtIndex: 1] stringByRemovingPercentEncoding]; [ret addObject: [OFPair pairWithFirstObject: name secondObject: value]]; } [ret makeImmutable]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)fragment { return _percentEncodedFragment.stringByRemovingPercentEncoding; } - (OFString *)percentEncodedFragment { return _percentEncodedFragment; } - (id)copy { return [self retain]; } - (id)mutableCopy { OFIRI *copy = [[OFMutableIRI alloc] initWithScheme: _scheme]; @try { copy->_percentEncodedHost = [_percentEncodedHost copy]; copy->_port = [_port copy]; copy->_percentEncodedUser = [_percentEncodedUser copy]; copy->_percentEncodedPassword = [_percentEncodedPassword copy]; copy->_percentEncodedPath = [_percentEncodedPath copy]; copy->_percentEncodedQuery = [_percentEncodedQuery copy]; copy->_percentEncodedFragment = [_percentEncodedFragment copy]; } @catch (id e) { [copy release]; @throw e; } return copy; } - (OFString *)string { OFMutableString *ret = [OFMutableString string]; [ret appendFormat: @"%@:", _scheme]; if (_percentEncodedHost != nil || _port != nil || _percentEncodedUser != nil || _percentEncodedPassword != nil) [ret appendString: @"//"]; if (_percentEncodedUser != nil && _percentEncodedPassword != nil) [ret appendFormat: @"%@:%@@", _percentEncodedUser, _percentEncodedPassword]; else if (_percentEncodedUser != nil) [ret appendFormat: @"%@@", _percentEncodedUser]; if (_percentEncodedHost != nil) [ret appendString: _percentEncodedHost]; if (_port != nil) [ret appendFormat: @":%@", _port]; [ret appendString: _percentEncodedPath]; if (_percentEncodedQuery != nil) [ret appendFormat: @"?%@", _percentEncodedQuery]; if (_percentEncodedFragment != nil) [ret appendFormat: @"#%@", _percentEncodedFragment]; [ret makeImmutable]; return ret; } #ifdef OF_HAVE_FILES - (OFString *)fileSystemRepresentation { void *pool = objc_autoreleasePoolPush(); OFString *path; if (![_scheme isEqual: @"file"]) @throw [OFInvalidArgumentException exception]; if (![_percentEncodedPath hasPrefix: @"/"]) @throw [OFInvalidFormatException exception]; path = [self.path of_IRIPathToPathWithPercentEncodedHost: _percentEncodedHost]; [path retain]; objc_autoreleasePoolPop(pool); return [path autorelease]; } #endif - (OFIRI *)IRIByAppendingPathComponent: (OFString *)component { OFMutableIRI *IRI = [[self mutableCopy] autorelease]; [IRI appendPathComponent: component]; [IRI makeImmutable]; return IRI; } - (OFIRI *)IRIByAppendingPathComponent: (OFString *)component isDirectory: (bool)isDirectory { OFMutableIRI *IRI = [[self mutableCopy] autorelease]; [IRI appendPathComponent: component isDirectory: isDirectory]; [IRI makeImmutable]; return IRI; } - (OFIRI *)IRIByDeletingLastPathComponent { OFMutableIRI *IRI = [[self mutableCopy] autorelease]; [IRI deleteLastPathComponent]; [IRI makeImmutable]; return IRI; } - (OFIRI *)IRIByAppendingPathExtension: (OFString *)extension { OFMutableIRI *IRI = [[self mutableCopy] autorelease]; [IRI appendPathExtension: extension]; [IRI makeImmutable]; return IRI; } - (OFIRI *)IRIByDeletingPathExtension { OFMutableIRI *IRI = [[self mutableCopy] autorelease]; [IRI deletePathExtension]; [IRI makeImmutable]; return IRI; } - (OFIRI *)IRIByStandardizingPath { OFMutableIRI *IRI = [[self mutableCopy] autorelease]; [IRI standardizePath]; [IRI makeImmutable]; return IRI; } - (OFIRI *)IRIByAddingPercentEncodingForUnicodeCharacters { OFMutableIRI *IRI = [[self mutableCopy] autorelease]; void *pool = objc_autoreleasePoolPush(); OFCharacterSet *ASCII = [OFCharacterSet characterSetWithRange: OFMakeRange(0, 0x80)]; IRI.percentEncodedHost = [_percentEncodedHost stringByAddingPercentEncodingWithAllowedCharacters: ASCII]; IRI.percentEncodedUser = [_percentEncodedUser stringByAddingPercentEncodingWithAllowedCharacters: ASCII]; IRI.percentEncodedPassword = [_percentEncodedPassword stringByAddingPercentEncodingWithAllowedCharacters: ASCII]; IRI.percentEncodedPath = [_percentEncodedPath stringByAddingPercentEncodingWithAllowedCharacters: ASCII]; IRI.percentEncodedQuery = [_percentEncodedQuery stringByAddingPercentEncodingWithAllowedCharacters: ASCII]; IRI.percentEncodedFragment = [_percentEncodedFragment stringByAddingPercentEncodingWithAllowedCharacters: ASCII]; [IRI makeImmutable]; objc_autoreleasePoolPop(pool); return IRI; } - (OFString *)description { return [OFString stringWithFormat: @"<%@: %@>", self.class, self.string]; } @end objfw-1.1.6/src/OFIRIHandler.h000066400000000000000000000370211465614216400157500ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFFileManager.h" #import "OFObject.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFData; @class OFDate; @class OFIRI; @class OFStream; /** * @class OFIRIHandler OFIRIHandler.h ObjFW/OFIRIHandler.h * * @brief A handler for an IRI scheme. */ @interface OFIRIHandler: OFObject { OFString *_scheme; OF_RESERVE_IVARS(OFIRIHandler, 4) } /** * @brief The scheme this OFIRIHandler handles. */ @property (readonly, nonatomic) OFString *scheme; /** * @brief Registers the specified class as the handler for the specified scheme. * * If the same class is specified for two schemes, one instance of it is * created per scheme. * * @param class_ The class to register as the handler for the specified scheme * @param scheme The scheme for which to register the handler * @return Whether the class was successfully registered. If a handler for the * same scheme is already registered, registration fails. */ + (bool)registerClass: (Class)class_ forScheme: (OFString *)scheme; /** * @brief Returns the handler for the specified IRI. * * @return The handler for the specified IRI. * @throw OFUnsupportedProtocolException The specified IRI is not supported */ + (OFIRIHandler *)handlerForIRI: (OFIRI *)IRI; /** * @brief Opens the item at the specified IRI. * * @param IRI The IRI of the item which should be opened * @param mode The mode in which the file should be opened.@n * Possible modes are: * @n * Mode | Description * ---------------|------------------------------------- * `r` | Read-only * `r+` | Read-write * `w` | Write-only, create or truncate * `wx` | Write-only, create or fail, exclusive * `w+` | Read-write, create or truncate * `w+x` | Read-write, create or fail, exclusive * `a` | Write-only, create or append * `a+` | Read-write, create or append * @n * The handler is allowed to not implement all modes and is also * allowed to implement additional, scheme-specific modes. * @return The opened stream if it was successfully opened * @throw OFOpenItemFailedException Opening the item failed * @throw OFUnsupportedProtocolException The specified IRI is not supported */ + (OFStream *)openItemAtIRI: (OFIRI *)IRI mode: (OFString *)mode; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes the handler for the specified scheme. * * @param scheme The scheme to initialize for * @return An initialized IRI handler */ - (instancetype)initWithScheme: (OFString *)scheme OF_DESIGNATED_INITIALIZER; /** * @brief Opens the item at the specified IRI. * * @param IRI The IRI of the item which should be opened * @param mode The mode in which the file should be opened.@n * Possible modes are: * @n * Mode | Description * ---------------|------------------------------------- * `r` | Read-only * `r+` | Read-write * `w` | Write-only, create or truncate * `wx` | Write-only, create or fail, exclusive * `w+` | Read-write, create or truncate * `w+x` | Read-write, create or fail, exclusive * `a` | Write-only, create or append * `a+` | Read-write, create or append * @n * The handler is allowed to not implement all modes and is also * allowed to implement additional, scheme-specific modes. * @return The opened stream if it was successfully opened * @throw OFOpenItemFailedException Opening the item failed * @throw OFUnsupportedProtocolException The specified IRI is not supported by * the handler */ - (OFStream *)openItemAtIRI: (OFIRI *)IRI mode: (OFString *)mode; /** * @brief Returns the attributes for the item at the specified IRI. * * @param IRI The IRI to return the attributes for * @return A dictionary of attributes for the specified IRI, with the keys of * type @ref OFFileAttributeKey * @throw OFGetItemAttributesFailedException Failed to get the attributes of * the item * @throw OFUnsupportedProtocolException The handler cannot handle the IRI's * scheme */ - (OFFileAttributes)attributesOfItemAtIRI: (OFIRI *)IRI; /** * @brief Sets the attributes for the item at the specified IRI. * * All attributes not part of the dictionary are left unchanged. * * @param attributes The attributes to set for the specified IRI * @param IRI The IRI of the item to set the attributes for * @@throw OFSetItemAttributesFailedException Failed to set the attributes of * the item * @throw OFUnsupportedProtocolException The handler cannot handle the IRI's * scheme * @throw OFNotImplementedException Setting one or more of the specified * attributes is not implemented for the * specified item */ - (void)setAttributes: (OFFileAttributes)attributes ofItemAtIRI: (OFIRI *)IRI; /** * @brief Checks whether a file exists at the specified IRI. * * @param IRI The IRI to check * @return A boolean whether there is a file at the specified IRI * @throw OFUnsupportedProtocolException The handler cannot handle the IRI's * scheme */ - (bool)fileExistsAtIRI: (OFIRI *)IRI; /** * @brief Checks whether a directory exists at the specified IRI. * * @param IRI The IRI to check * @return A boolean whether there is a directory at the specified IRI * @throw OFUnsupportedProtocolException The handler cannot handle the IRI's * scheme */ - (bool)directoryExistsAtIRI: (OFIRI *)IRI; /** * @brief Creates a directory at the specified IRI. * * @param IRI The IRI of the directory to create * @throw OFCreateDirectoryFailedException Creating the directory failed * @throw OFUnsupportedProtocolException The handler cannot handle the IRI's * scheme */ - (void)createDirectoryAtIRI: (OFIRI *)IRI; /** * @brief Returns an array with the IRIs of the items in the specified * directory. * * @note `.` and `..` are not part of the returned array. * * @param IRI The IRI to the directory whose items should be returned * @return An array with the IRIs of the items in the specified directory * @throw OFOpenItemFailedException Opening the directory failed * @throw OFReadFailedException Reading from the directory failed * @throw OFUnsupportedProtocolException The handler cannot handle the IRI's * scheme */ - (OFArray OF_GENERIC(OFIRI *) *)contentsOfDirectoryAtIRI: (OFIRI *)IRI; /** * @brief Removes the item at the specified IRI. * * If the item at the specified IRI is a directory, it is removed recursively. * * @param IRI The IRI to the item which should be removed * @throw OFRemoveItemFailedException Removing the item failed * @throw OFUnsupportedProtocolException The handler cannot handle the IRI's * scheme */ - (void)removeItemAtIRI: (OFIRI *)IRI; /** * @brief Creates a hard link for the specified item. * * The destination IRI must have a full path, which means it must include the * name of the item. * * This method is not available for all IRIs. * * @param source The IRI to the item for which a link should be created * @param destination The IRI to the item which should link to the source * @throw OFLinkItemFailedException Linking the item failed * @throw OFUnsupportedProtocolException The handler cannot handle the scheme * of one of the IRIs * @throw OFNotImplementedException Hardlinks are not implemented for the * specified IRI */ - (void)linkItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination; /** * @brief Creates a symbolic link for an item. * * The destination IRI must have a full path, which means it must include the * name of the item. * * This method is not available for all IRIs. * * @note On Windows, this requires at least Windows Vista and administrator * privileges! * * @param IRI The IRI to the item which should symbolically link to the target * @param target The target of the symbolic link * @throw OFCreateSymbolicLinkFailed Creating a symbolic link failed * @throw OFUnsupportedProtocolException The handler cannot handle the IRI's * scheme */ - (void)createSymbolicLinkAtIRI: (OFIRI *)IRI withDestinationPath: (OFString *)target; /** * @brief Tries to efficiently copy an item. If a copy would only be possible * by reading the entire item and then writing it, it returns false. * * The destination IRI must have a full path, which means it must include the * name of the item. * * If an item already exists, the copy operation fails. This is also the case * if a directory is copied and an item already exists in the destination * directory. * * @param source The file, directory or symbolic link to copy * @param destination The destination IRI * @return True if an efficient copy was performed, false if an efficient copy * was not possible. Note that errors while performing a copy are * reported via exceptions and not by returning false! * @throw OFCopyItemFailedException Copying failed * @throw OFUnsupportedProtocolException The handler cannot handle the IRI's * scheme */ - (bool)copyItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination; /** * @brief Tries to efficiently move an item. If a move would only be possible * by copying the source and deleting it, it returns false. * * The destination IRI must have a full path, which means it must include the * name of the item. * * If the destination is on a different logical device or uses a different * scheme, an efficient move is not possible and false is returned. * * @param source The item to rename * @param destination The new name for the item * @return True if an efficient move was performed, false if an efficient move * was not possible. Note that errors while performing a move are * reported via exceptions and not by returning false! * @throw OFMoveItemFailedException Moving failed * @throw OFUnsupportedProtocolException The handler cannot handle the IRI's * scheme */ - (bool)moveItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination; /** * @brief Returns the extended attribute data for the specified name of the * item at the specified IRI. * * @deprecated Use @ref getExtendedAttributeData:andType:forName:ofItemAtIRI: * instead. * * This method is not available for all IRIs. * * @param name The name of the extended attribute * @param IRI The IRI of the item to return the extended attribute from * @return The extended attribute data for the specified name of the item at * the specified IRI * @throw OFGetItemAttributesFailedException Getting the extended attribute * failed * @throw OFUnsupportedProtocolException The handler cannot handle the IRI's * scheme * @throw OFNotImplementedException Getting extended attributes is not * implemented for the specified item */ - (OFData *)extendedAttributeDataForName: (OFString *)name ofItemAtIRI: (OFIRI *)IRI OF_DEPRECATED(ObjFW, 1, 1, "Use -[getExtendedAttributeData:andType:forName:ofItemAtIRI:] instead"); /** * @brief Gets the extended attribute data and type for the specified name * of the item at the specified IRI. * * This method is not available for all IRIs. * * @param data A pointer to `OFData *` that gets set to the data of the * extended attribute * @param type A pointer to `id` that gets set to the type of the extended * attribute, if not `NULL`. Gets set to `nil` if the extended * attribute has no type. The type of the type depends on the IRI * handler. * @param name The name of the extended attribute * @param IRI The IRI of the item to return the extended attribute from * @throw OFGetItemAttributesFailedException Getting the extended attribute * failed * @throw OFUnsupportedProtocolException The handler cannot handle the IRI's * scheme * @throw OFNotImplementedException Getting extended attributes is not * implemented for the specified item */ - (void)getExtendedAttributeData: (OFData *_Nonnull *_Nonnull)data andType: (id _Nullable *_Nullable)type forName: (OFString *)name ofItemAtIRI: (OFIRI *)IRI; /** * @brief Sets the extended attribute data for the specified name of the item * at the specified IRI. * * @deprecated Use @ref setExtendedAttributeData:andType:forName:ofItemAtIRI: * instead. * * This method is not available for all IRIs. * * @param data The data for the extended attribute * @param name The name of the extended attribute * @param IRI The IRI of the item to set the extended attribute on * @throw OFSetItemAttributesFailedException Setting the extended attribute * failed * @throw OFUnsupportedProtocolException The handler cannot handle the IRI's * scheme * @throw OFNotImplementedException Setting extended attributes is not * implemented for the specified item */ - (void)setExtendedAttributeData: (OFData *)data forName: (OFString *)name ofItemAtIRI: (OFIRI *)IRI OF_DEPRECATED(ObjFW, 1, 1, "Use -[setExtendedAttributeData:andType:forName:ofItemAtIRI:] instead"); /** * @brief Sets the extended attribute data and type for the specified name of * the item at the specified IRI. * * This method is not available for all IRIs. * Not all IRIs support a non-nil type. * * @param data The data for the extended attribute * @param type The type for the extended attribute. `nil` does not mean to keep * the existing type, but to set it to no type. The type of the * type depends on the IRI handler. * @param name The name of the extended attribute * @param IRI The IRI of the item to set the extended attribute on * @throw OFSetItemAttributesFailedException Setting the extended attribute * failed * @throw OFUnsupportedProtocolException The handler cannot handle the IRI's * scheme * @throw OFNotImplementedException Setting extended attributes is not * implemented for the specified item or a * type was specified and typed extended * attributes are not supported */ - (void)setExtendedAttributeData: (OFData *)data andType: (nullable id)type forName: (OFString *)name ofItemAtIRI: (OFIRI *)IRI; /** * @brief Removes the extended attribute for the specified name of the item at * the specified IRI. * * This method is not available for all IRIs. * * @param name The name of the extended attribute to remove * @param IRI The IRI of the item to remove the extended attribute from * @throw OFSetItemAttributesFailedException Removing the extended attribute * failed * @throw OFUnsupportedProtocolException The handler cannot handle the IRI's * scheme * @throw OFNotImplementedException Removing extended attributes is not * implemented for the specified item */ - (void)removeExtendedAttributeForName: (OFString *)name ofItemAtIRI: (OFIRI *)IRI; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFIRIHandler.m000066400000000000000000000162071465614216400157600ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFIRIHandler.h" #import "OFDictionary.h" #import "OFIRI.h" #import "OFNumber.h" #ifdef OF_HAVE_THREADS # import "OFMutex.h" #endif #import "OFArchiveIRIHandler.h" #import "OFEmbeddedIRIHandler.h" #ifdef OF_HAVE_FILES # import "OFFileIRIHandler.h" #endif #if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS) # import "OFHTTPIRIHandler.h" #endif #import "OFUnsupportedProtocolException.h" static OFMutableDictionary OF_GENERIC(OFString *, OFIRIHandler *) *handlers; #ifdef OF_HAVE_THREADS static OFMutex *mutex; static void releaseMutex(void) { [mutex release]; } #endif @implementation OFIRIHandler @synthesize scheme = _scheme; + (void)initialize { if (self != [OFIRIHandler class]) return; handlers = [[OFMutableDictionary alloc] init]; #ifdef OF_HAVE_THREADS mutex = [[OFMutex alloc] init]; atexit(releaseMutex); #endif [self registerClass: [OFEmbeddedIRIHandler class] forScheme: @"embedded"]; #ifdef OF_HAVE_FILES [self registerClass: [OFFileIRIHandler class] forScheme: @"file"]; #endif #if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS) [self registerClass: [OFHTTPIRIHandler class] forScheme: @"http"]; [self registerClass: [OFHTTPIRIHandler class] forScheme: @"https"]; #endif [self registerClass: [OFArchiveIRIHandler class] forScheme: @"gzip"]; [self registerClass: [OFArchiveIRIHandler class] forScheme: @"lha"]; [self registerClass: [OFArchiveIRIHandler class] forScheme: @"tar"]; [self registerClass: [OFArchiveIRIHandler class] forScheme: @"zip"]; [self registerClass: [OFArchiveIRIHandler class] forScheme: @"zoo"]; } + (bool)registerClass: (Class)class forScheme: (OFString *)scheme { #ifdef OF_HAVE_THREADS [mutex lock]; @try { #endif OFIRIHandler *handler; if ([handlers objectForKey: scheme] != nil) return false; handler = [[class alloc] initWithScheme: scheme]; @try { [handlers setObject: handler forKey: scheme]; } @finally { [handler release]; } #ifdef OF_HAVE_THREADS } @finally { [mutex unlock]; } #endif return true; } + (OFIRIHandler *)handlerForIRI: (OFIRI *)IRI { OF_KINDOF(OFIRIHandler *) handler; #ifdef OF_HAVE_THREADS [mutex lock]; @try { #endif handler = [handlers objectForKey: IRI.scheme]; #ifdef OF_HAVE_THREADS } @finally { [mutex unlock]; } #endif if (handler == nil) @throw [OFUnsupportedProtocolException exceptionWithIRI: IRI]; return handler; } + (OFStream *)openItemAtIRI: (OFIRI *)IRI mode: (OFString *)mode { return [[self handlerForIRI: IRI] openItemAtIRI: IRI mode: mode]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithScheme: (OFString *)scheme { self = [super init]; @try { _scheme = [scheme copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_scheme release]; [super dealloc]; } - (OFStream *)openItemAtIRI: (OFIRI *)IRI mode: (OFString *)mode { OF_UNRECOGNIZED_SELECTOR } - (OFFileAttributes)attributesOfItemAtIRI: (OFIRI *)IRI { OF_UNRECOGNIZED_SELECTOR } - (void)setAttributes: (OFFileAttributes)attributes ofItemAtIRI: (OFIRI *)IRI { OF_UNRECOGNIZED_SELECTOR } - (bool)fileExistsAtIRI: (OFIRI *)IRI { OF_UNRECOGNIZED_SELECTOR } - (bool)directoryExistsAtIRI: (OFIRI *)IRI { OF_UNRECOGNIZED_SELECTOR } - (void)createDirectoryAtIRI: (OFIRI *)IRI { OF_UNRECOGNIZED_SELECTOR } - (OFArray OF_GENERIC(OFIRI *) *)contentsOfDirectoryAtIRI: (OFIRI *)IRI { OF_UNRECOGNIZED_SELECTOR } - (void)removeItemAtIRI: (OFIRI *)IRI { OF_UNRECOGNIZED_SELECTOR } - (void)linkItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination { OF_UNRECOGNIZED_SELECTOR } - (void)createSymbolicLinkAtIRI: (OFIRI *)destination withDestinationPath: (OFString *)source { OF_UNRECOGNIZED_SELECTOR } - (bool)copyItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination { return false; } - (bool)moveItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination { return false; } - (OFData *)extendedAttributeDataForName: (OFString *)name ofItemAtIRI: (OFIRI *)IRI { OFData *data; [self getExtendedAttributeData: &data andType: NULL forName: name ofItemAtIRI: IRI]; return data; } - (void)getExtendedAttributeData: (OFData **)data andType: (id *)type forName: (OFString *)name ofItemAtIRI: (OFIRI *)IRI { /* * Only call into -[extendedAttributeDataForName:ofItemAtIRI:] if it * has been overridden. This is to be backwards-compatible to * subclasses that predate the introduction of * -[getExtendedAttributeData:andType:forName:ofItemAtIRI:]. * Without this check, this would result in an infinite loop. */ SEL selector = @selector(extendedAttributeDataForName:ofItemAtIRI:); if (class_getMethodImplementation(object_getClass(self), selector) != class_getMethodImplementation([OFIRIHandler class], selector)) { /* * Use -[performSelector:withObject:withObject:] to avoid * deprecation warning. This entire thing is purely for * backwards compatibility. */ *data = [self performSelector: selector withObject: name withObject: IRI]; if (type != NULL) *type = nil; return; } OF_UNRECOGNIZED_SELECTOR } - (void)setExtendedAttributeData: (OFData *)data forName: (OFString *)name ofItemAtIRI: (OFIRI *)IRI { [self setExtendedAttributeData: data andType: nil forName: name ofItemAtIRI: IRI]; } - (void)setExtendedAttributeData: (OFData *)data andType: (id)type forName: (OFString *)name ofItemAtIRI: (OFIRI *)IRI { if (type == nil) { /* * Only call into * -[setExtendedAttributeData:forName:ofItemAtIRI:] if it has * been overridden. This is to be backwards-compatible to * subclasses that predate the introduction of * -[setExtendedAttributeData:andType:forName:ofItemAtIRI:]. * Without this check, this would result in an infinite loop. */ SEL selector = @selector(setExtendedAttributeData:forName:ofItemAtIRI:); if (class_getMethodImplementation(object_getClass(self), selector) != class_getMethodImplementation([OFIRIHandler class], selector)) { /* * Use * -[performSelector:withObject:withObject:withObject:] * to avoid deprecation warning. This entire thing is * purely for backwards compatibility. */ [self performSelector: selector withObject: data withObject: name withObject: IRI]; return; } } OF_UNRECOGNIZED_SELECTOR } - (void)removeExtendedAttributeForName: (OFString *)name ofItemAtIRI: (OFIRI *)IRI { OF_UNRECOGNIZED_SELECTOR } @end objfw-1.1.6/src/OFInflate64Stream.h000066400000000000000000000063571465614216400167470ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFStream.h" #import "OFKernelEventObserver.h" OF_ASSUME_NONNULL_BEGIN #define OFInflate64StreamBufferSize 4096 /** * @class OFInflate64Stream OFInflate64Stream.h ObjFW/OFInflate64Stream.h * * @note This class only conforms to OFReadyForReadingObserving if the * underlying stream does so, too. * * @brief A class that handles Deflate decompression transparently for an * underlying stream. */ OF_SUBCLASSING_RESTRICTED @interface OFInflate64Stream: OFStream { OFStream *_stream; unsigned char _buffer[OFInflate64StreamBufferSize]; uint16_t _bufferIndex, _bufferLength; uint8_t _byte; uint8_t _bitIndex, _savedBitsLength; uint16_t _savedBits; unsigned char *_Nullable _slidingWindow; uint16_t _slidingWindowIndex, _slidingWindowMask; int _state; union { struct { uint8_t position; uint8_t length[4]; } uncompressedHeader; struct { uint16_t position, length; } uncompressed; struct { struct _OFHuffmanTree *_Nullable litLenTree; struct _OFHuffmanTree *_Nullable distTree; struct _OFHuffmanTree *_Nullable codeLenTree; struct _OFHuffmanTree *_Nullable treeIter; uint8_t *_Nullable lengths; uint16_t receivedCount; uint8_t value, litLenCodesCount, distCodesCount; uint8_t codeLenCodesCount; } huffmanTree; struct { struct _OFHuffmanTree *_Nullable litLenTree; struct _OFHuffmanTree *_Nullable distTree; struct _OFHuffmanTree *_Nullable treeIter; int state; uint16_t value, length, distance, extraBits; } huffman; } _context; bool _inLastBlock, _atEndOfStream; } /** * @brief The underlying stream of the inflate stream. * * Setting this can be useful if the the data to be inflated is coming from * multiple streams, such as split across multiple files. */ @property (retain, nonatomic) OFStream *underlyingStream; /** * @brief Creates a new OFInflate64Stream with the specified underlying stream. * * @param stream The underlying stream to which compressed data is written or * from which compressed data is read * @return A new, autoreleased OFInflate64Stream */ + (instancetype)streamWithStream: (OFStream *)stream; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFInflate64Stream with the specified * underlying stream. * * @param stream The underlying stream to which compressed data is written or * from which compressed data is read * @return A initialized OFInflate64Stream */ - (instancetype)initWithStream: (OFStream *)stream OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFInflate64Stream.m000066400000000000000000000014271465614216400167450ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #define OF_INFLATE64_STREAM_M #include "OFInflateStream.m" objfw-1.1.6/src/OFInflateStream.h000066400000000000000000000063331465614216400165670ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFStream.h" #import "OFKernelEventObserver.h" OF_ASSUME_NONNULL_BEGIN #define OFInflateStreamBufferSize 4096 /** * @class OFInflateStream OFInflateStream.h ObjFW/OFInflateStream.h * * @note This class only conforms to OFReadyForReadingObserving if the * underlying stream does so, too. * * @brief A class that handles Deflate decompression transparently for an * underlying stream. */ OF_SUBCLASSING_RESTRICTED @interface OFInflateStream: OFStream { OFStream *_stream; unsigned char _buffer[OFInflateStreamBufferSize]; uint16_t _bufferIndex, _bufferLength; uint8_t _byte; uint8_t _bitIndex, _savedBitsLength; uint16_t _savedBits; unsigned char *_Nullable _slidingWindow; uint16_t _slidingWindowIndex, _slidingWindowMask; int _state; union { struct { uint8_t position; uint8_t length[4]; } uncompressedHeader; struct { uint16_t position, length; } uncompressed; struct { struct _OFHuffmanTree *_Nullable litLenTree; struct _OFHuffmanTree *_Nullable distTree; struct _OFHuffmanTree *_Nullable codeLenTree; struct _OFHuffmanTree *_Nullable treeIter; uint8_t *_Nullable lengths; uint16_t receivedCount; uint8_t value, litLenCodesCount, distCodesCount; uint8_t codeLenCodesCount; } huffmanTree; struct { struct _OFHuffmanTree *_Nullable litLenTree; struct _OFHuffmanTree *_Nullable distTree; struct _OFHuffmanTree *_Nullable treeIter; int state; uint16_t value, length, distance, extraBits; } huffman; } _context; bool _inLastBlock, _atEndOfStream; } /** * @brief The underlying stream of the inflate stream. * * Setting this can be useful if the the data to be inflated is coming from * multiple streams, such as split across multiple files. */ @property (retain, nonatomic) OFStream *underlyingStream; /** * @brief Creates a new OFInflateStream with the specified underlying stream. * * @param stream The underlying stream to which compressed data is written or * from which compressed data is read * @return A new, autoreleased OFInflateStream */ + (instancetype)streamWithStream: (OFStream *)stream; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFInflateStream with the specified * underlying stream. * * @param stream The underlying stream to which compressed data is written or * from which compressed data is read * @return A initialized OFInflateStream */ - (instancetype)initWithStream: (OFStream *)stream OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFInflateStream.m000066400000000000000000000416771465614216400166060ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #ifndef OF_INFLATE64_STREAM_M # import "OFInflateStream.h" #else # import "OFInflate64Stream.h" # define OFInflateStream OFInflate64Stream #endif #import "OFHuffmanTree.h" #import "OFInitializationFailedException.h" #import "OFInvalidFormatException.h" #import "OFNotOpenException.h" #import "OFOutOfMemoryException.h" #ifndef OF_INFLATE64_STREAM_M # define bufferSize OFInflateStreamBufferSize #else # define bufferSize OFInflate64StreamBufferSize #endif enum State { stateBlockHeader, stateUncompressedBlockHeader, stateUncompressedBlock, stateHuffmanTree, stateHuffmanBlock }; enum HuffmanState { huffmanStateWriteValue, huffmanStateAwaitCode, huffmanStateAwaitLengthExtraBits, huffmanStateAwaitDistance, huffmanStateAwaitDistanceExtraBits, huffmanStateProcessPair }; #ifndef OF_INFLATE64_STREAM_M static const uint8_t numDistanceCodes = 30; static const uint8_t lengthCodes[29] = { /* indices are -257, values -3 */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 255 }; static const uint8_t lengthExtraBits[29] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0 }; static const uint16_t distanceCodes[30] = { 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577 }; static const uint8_t distanceExtraBits[30] = { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13 }; #else static const uint8_t numDistanceCodes = 32; static const uint8_t lengthCodes[29] = { /* indices are -257, values -3 */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 0 }; static const uint8_t lengthExtraBits[29] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 16 }; static const uint16_t distanceCodes[32] = { 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 32769, 49153 }; static const uint8_t distanceExtraBits[32] = { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14 }; #endif static const uint8_t codeLengthsOrder[19] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }; static OFHuffmanTree fixedLitLenTree, fixedDistTree; @implementation OFInflateStream @synthesize underlyingStream = _stream; static OF_INLINE bool tryReadBits(OFInflateStream *stream, uint16_t *bits, uint8_t count) { uint16_t ret = stream->_savedBits; OFAssert(stream->_savedBitsLength < count); for (uint_fast8_t i = stream->_savedBitsLength; i < count; i++) { if OF_UNLIKELY (stream->_bitIndex == 8) { if OF_LIKELY (stream->_bufferIndex < stream->_bufferLength) stream->_byte = stream->_buffer[stream->_bufferIndex++]; else { size_t length = [stream->_stream readIntoBuffer: stream->_buffer length: bufferSize]; if OF_UNLIKELY (length < 1) { stream->_savedBits = ret; stream->_savedBitsLength = i; return false; } stream->_byte = stream->_buffer[0]; stream->_bufferIndex = 1; stream->_bufferLength = (uint16_t)length; } stream->_bitIndex = 0; } ret |= ((stream->_byte >> stream->_bitIndex++) & 1) << i; } stream->_savedBits = 0; stream->_savedBitsLength = 0; *bits = ret; return true; } + (void)initialize { uint8_t lengths[288]; if (self != [OFInflateStream class]) return; for (uint16_t i = 0; i <= 143; i++) lengths[i] = 8; for (uint16_t i = 144; i <= 255; i++) lengths[i] = 9; for (uint16_t i = 256; i <= 279; i++) lengths[i] = 7; for (uint16_t i = 280; i <= 287; i++) lengths[i] = 8; fixedLitLenTree = _OFHuffmanTreeNew(lengths, 288); for (uint16_t i = 0; i <= 31; i++) lengths[i] = 5; fixedDistTree = _OFHuffmanTreeNew(lengths, 32); } + (instancetype)streamWithStream: (OFStream *)stream { return [[[self alloc] initWithStream: stream] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithStream: (OFStream *)stream { self = [super init]; @try { _stream = [stream retain]; /* 0-7 address the bit, 8 means fetch next byte */ _bitIndex = 8; #ifdef OF_INFLATE64_STREAM_M _slidingWindowMask = 0xFFFF; #else _slidingWindowMask = 0x7FFF; #endif _slidingWindow = OFAllocZeroedMemory(_slidingWindowMask + 1, 1); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_stream != nil) [self close]; OFFreeMemory(_slidingWindow); if (_state == stateHuffmanTree) { OFFreeMemory(_context.huffmanTree.lengths); if (_context.huffmanTree.codeLenTree != NULL) _OFHuffmanTreeFree(_context.huffmanTree.codeLenTree); } if (_state == stateHuffmanTree || _state == stateHuffmanBlock) { if (_context.huffman.litLenTree != fixedLitLenTree) _OFHuffmanTreeFree(_context.huffman.litLenTree); if (_context.huffman.distTree != fixedDistTree) _OFHuffmanTreeFree(_context.huffman.distTree); } [super dealloc]; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer_ length: (size_t)length { unsigned char *buffer = buffer_; uint16_t bits = 0, tmp, value = 0; size_t bytesWritten = 0; unsigned char *slidingWindow; uint16_t slidingWindowIndex; if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (_atEndOfStream) return 0; start: switch ((enum State)_state) { case stateBlockHeader: if OF_UNLIKELY (_inLastBlock) { [_stream unreadFromBuffer: _buffer + _bufferIndex length: _bufferLength - _bufferIndex]; _bufferIndex = _bufferLength = 0; _atEndOfStream = true; return bytesWritten; } if OF_UNLIKELY (!tryReadBits(self, &bits, 3)) return bytesWritten; _inLastBlock = (bits & 1); switch (bits >> 1) { case 0: /* No compression */ _state = stateUncompressedBlockHeader; _bitIndex = 8; _context.uncompressedHeader.position = 0; memset(_context.uncompressedHeader.length, 0, 4); break; case 1: /* Fixed Huffman */ _state = stateHuffmanBlock; _context.huffman.state = huffmanStateAwaitCode; _context.huffman.litLenTree = fixedLitLenTree; _context.huffman.distTree = fixedDistTree; _context.huffman.treeIter = fixedLitLenTree; break; case 2: /* Dynamic Huffman */ _state = stateHuffmanTree; _context.huffmanTree.lengths = NULL; _context.huffmanTree.receivedCount = 0; _context.huffmanTree.value = 0xFE; _context.huffmanTree.litLenCodesCount = 0xFF; _context.huffmanTree.distCodesCount = 0xFF; _context.huffmanTree.codeLenCodesCount = 0xFF; break; default: @throw [OFInvalidFormatException exception]; } goto start; case stateUncompressedBlockHeader: #define CTX _context.uncompressedHeader /* FIXME: This can be done more efficiently than unreading */ [_stream unreadFromBuffer: _buffer + _bufferIndex length: _bufferLength - _bufferIndex]; _bufferIndex = _bufferLength = 0; CTX.position += [_stream readIntoBuffer: CTX.length + CTX.position length: 4 - CTX.position]; if OF_UNLIKELY (CTX.position < 4) return bytesWritten; if OF_UNLIKELY ((CTX.length[0] | (CTX.length[1] << 8)) != (uint16_t)~(CTX.length[2] | (CTX.length[3] << 8))) @throw [OFInvalidFormatException exception]; _state = stateUncompressedBlock; /* * Do not reorder! _context.uncompressed.position and * _context.uncompressedHeader.length overlap! */ _context.uncompressed.length = CTX.length[0] | (CTX.length[1] << 8); _context.uncompressed.position = 0; goto start; #undef CTX case stateUncompressedBlock: #define CTX _context.uncompressed if OF_UNLIKELY (length == 0) return bytesWritten; tmp = (length < (size_t)CTX.length - CTX.position ? (uint16_t)length : CTX.length - CTX.position); tmp = (uint16_t)[_stream readIntoBuffer: buffer + bytesWritten length: tmp]; if OF_UNLIKELY (tmp == 0) return bytesWritten; slidingWindow = _slidingWindow; slidingWindowIndex = _slidingWindowIndex; for (uint_fast16_t i = 0; i < tmp; i++) { slidingWindow[slidingWindowIndex] = buffer[bytesWritten + i]; slidingWindowIndex = (slidingWindowIndex + 1) & _slidingWindowMask; } _slidingWindowIndex = slidingWindowIndex; length -= tmp; bytesWritten += tmp; CTX.position += tmp; if OF_UNLIKELY (CTX.position == CTX.length) _state = stateBlockHeader; goto start; #undef CTX case stateHuffmanTree: #define CTX _context.huffmanTree if OF_LIKELY (CTX.value == 0xFE) { if OF_LIKELY (CTX.litLenCodesCount == 0xFF) { if OF_UNLIKELY (!tryReadBits(self, &bits, 5)) return bytesWritten; if OF_UNLIKELY (bits > 29) @throw [OFInvalidFormatException exception]; CTX.litLenCodesCount = bits; } if OF_LIKELY (CTX.distCodesCount == 0xFF) { if OF_UNLIKELY (!tryReadBits(self, &bits, 5)) return bytesWritten; CTX.distCodesCount = bits; } if OF_LIKELY (CTX.codeLenCodesCount == 0xFF) { if OF_UNLIKELY (!tryReadBits(self, &bits, 4)) return bytesWritten; CTX.codeLenCodesCount = bits; } if OF_LIKELY (CTX.lengths == NULL) CTX.lengths = OFAllocZeroedMemory(19, 1); for (uint16_t i = CTX.receivedCount; i < CTX.codeLenCodesCount + 4; i++) { if OF_UNLIKELY (!tryReadBits(self, &bits, 3)) { CTX.receivedCount = i; return bytesWritten; } CTX.lengths[codeLengthsOrder[i]] = bits; } CTX.codeLenTree = _OFHuffmanTreeNew(CTX.lengths, 19); CTX.treeIter = CTX.codeLenTree; OFFreeMemory(CTX.lengths); CTX.lengths = NULL; CTX.receivedCount = 0; CTX.value = 0xFF; } if OF_LIKELY (CTX.lengths == NULL) CTX.lengths = OFAllocMemory( CTX.litLenCodesCount + CTX.distCodesCount + 258, 1); for (uint16_t i = CTX.receivedCount; i < CTX.litLenCodesCount + CTX.distCodesCount + 258;) { uint8_t j, count; if OF_LIKELY (CTX.value == 0xFF) { if OF_UNLIKELY (!_OFHuffmanTreeWalk(self, tryReadBits, &CTX.treeIter, &value)) { CTX.receivedCount = i; return bytesWritten; } CTX.treeIter = CTX.codeLenTree; if (value < 16) { CTX.lengths[i++] = value; continue; } } else value = CTX.value; switch (value) { case 16: if OF_UNLIKELY (i < 1) @throw [OFInvalidFormatException exception]; if OF_UNLIKELY (!tryReadBits(self, &bits, 2)) { CTX.receivedCount = i; CTX.value = value; return bytesWritten; } value = CTX.lengths[i - 1]; count = bits + 3; break; case 17: if OF_UNLIKELY (!tryReadBits(self, &bits, 3)) { CTX.receivedCount = i; CTX.value = value; return bytesWritten; } value = 0; count = bits + 3; break; case 18: if OF_UNLIKELY (!tryReadBits(self, &bits, 7)) { CTX.receivedCount = i; CTX.value = value; return bytesWritten; } value = 0; count = bits + 11; break; default: @throw [OFInvalidFormatException exception]; } if OF_UNLIKELY (i + count > CTX.litLenCodesCount + CTX.distCodesCount + 258) @throw [OFInvalidFormatException exception]; for (j = 0; j < count; j++) CTX.lengths[i++] = value; CTX.value = 0xFF; } _OFHuffmanTreeFree(CTX.codeLenTree); CTX.codeLenTree = NULL; CTX.litLenTree = _OFHuffmanTreeNew(CTX.lengths, CTX.litLenCodesCount + 257); CTX.distTree = _OFHuffmanTreeNew( CTX.lengths + CTX.litLenCodesCount + 257, CTX.distCodesCount + 1); OFFreeMemory(CTX.lengths); /* * litLenTree and distTree are at the same location in * _context.huffman and _context.huffmanTree, thus no need to * set them. */ _state = stateHuffmanBlock; _context.huffman.state = huffmanStateAwaitCode; _context.huffman.treeIter = CTX.litLenTree; goto start; #undef CTX case stateHuffmanBlock: #define CTX _context.huffman for (;;) { uint8_t extraBits, lengthCodeIndex; if OF_UNLIKELY (CTX.state == huffmanStateWriteValue) { if OF_UNLIKELY (length == 0) return bytesWritten; buffer[bytesWritten++] = CTX.value; length--; _slidingWindow[_slidingWindowIndex] = CTX.value; _slidingWindowIndex = (_slidingWindowIndex + 1) & _slidingWindowMask; CTX.state = huffmanStateAwaitCode; CTX.treeIter = CTX.litLenTree; } if OF_UNLIKELY (CTX.state == huffmanStateAwaitLengthExtraBits) { if OF_UNLIKELY (!tryReadBits(self, &bits, CTX.extraBits)) return bytesWritten; CTX.length += bits; CTX.state = huffmanStateAwaitDistance; CTX.treeIter = CTX.distTree; } /* Distance of length distance pair */ if (CTX.state == huffmanStateAwaitDistance) { if OF_UNLIKELY (!_OFHuffmanTreeWalk(self, tryReadBits, &CTX.treeIter, &value)) return bytesWritten; if OF_UNLIKELY (value >= numDistanceCodes) @throw [OFInvalidFormatException exception]; CTX.distance = distanceCodes[value]; extraBits = distanceExtraBits[value]; if (extraBits > 0) { if OF_UNLIKELY (!tryReadBits(self, &bits, extraBits)) { #define HSADEB huffmanStateAwaitDistanceExtraBits CTX.state = HSADEB; #undef HSADEB CTX.extraBits = extraBits; return bytesWritten; } CTX.distance += bits; } CTX.state = huffmanStateProcessPair; } else if (CTX.state == huffmanStateAwaitDistanceExtraBits) { if OF_UNLIKELY (!tryReadBits(self, &bits, CTX.extraBits)) return bytesWritten; CTX.distance += bits; CTX.state = huffmanStateProcessPair; } /* Length distance pair */ if (CTX.state == huffmanStateProcessPair) { for (uint_fast16_t j = 0; j < CTX.length; j++) { uint16_t idx; if OF_UNLIKELY (length == 0) { CTX.length -= j; return bytesWritten; } idx = (_slidingWindowIndex - CTX.distance) & _slidingWindowMask; value = _slidingWindow[idx]; buffer[bytesWritten++] = value; length--; _slidingWindow[_slidingWindowIndex] = value; _slidingWindowIndex = (_slidingWindowIndex + 1) & _slidingWindowMask; } CTX.state = huffmanStateAwaitCode; CTX.treeIter = CTX.litLenTree; } if OF_UNLIKELY (!_OFHuffmanTreeWalk(self, tryReadBits, &CTX.treeIter, &value)) return bytesWritten; /* End of block */ if OF_UNLIKELY (value == 256) { if (CTX.litLenTree != fixedLitLenTree) _OFHuffmanTreeFree(CTX.litLenTree); if (CTX.distTree != fixedDistTree) _OFHuffmanTreeFree(CTX.distTree); _state = stateBlockHeader; goto start; } /* Literal byte */ if OF_LIKELY (value < 256) { if OF_UNLIKELY (length == 0) { CTX.state = huffmanStateWriteValue; CTX.value = value; return bytesWritten; } buffer[bytesWritten++] = value; length--; _slidingWindow[_slidingWindowIndex] = value; _slidingWindowIndex = (_slidingWindowIndex + 1) & _slidingWindowMask; CTX.treeIter = CTX.litLenTree; continue; } if OF_UNLIKELY (value > 285) @throw [OFInvalidFormatException exception]; /* Length of length distance pair */ lengthCodeIndex = value - 257; CTX.length = lengthCodes[lengthCodeIndex] + 3; extraBits = lengthExtraBits[lengthCodeIndex]; if (extraBits > 0) { if OF_UNLIKELY (!tryReadBits(self, &bits, extraBits)) { CTX.extraBits = extraBits; CTX.state = huffmanStateAwaitLengthExtraBits; return bytesWritten; } CTX.length += bits; } CTX.treeIter = CTX.distTree; CTX.state = huffmanStateAwaitDistance; } break; #undef CTX } OF_UNREACHABLE } - (bool)lowlevelIsAtEndOfStream { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; return _atEndOfStream; } - (int)fileDescriptorForReading { return ((id )_stream) .fileDescriptorForReading; } - (bool)lowlevelHasDataInReadBuffer { return (_stream.hasDataInReadBuffer || _bufferLength - _bufferIndex > 0); } - (void)close { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; /* Give back our buffer to the stream, in case it's shared */ [_stream unreadFromBuffer: _buffer + _bufferIndex length: _bufferLength - _bufferIndex]; _bufferIndex = _bufferLength = 0; [_stream release]; _stream = nil; [super close]; } @end objfw-1.1.6/src/OFInvertedCharacterSet.h000066400000000000000000000017731465614216400201050ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFCharacterSet.h" OF_ASSUME_NONNULL_BEGIN @interface OFInvertedCharacterSet: OFCharacterSet { OFCharacterSet *_characterSet; bool (*_characterIsMember)(id, SEL, OFUnichar); } - (instancetype)initWithCharacterSet: (OFCharacterSet *)characterSet; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFInvertedCharacterSet.m000066400000000000000000000030501465614216400201000ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFInvertedCharacterSet.h" #import "OFString.h" #import "OFOutOfRangeException.h" @implementation OFInvertedCharacterSet - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithCharacterSet: (OFCharacterSet *)characterSet { self = [super init]; @try { _characterSet = [characterSet retain]; _characterIsMember = (bool (*)(id, SEL, OFUnichar)) [_characterSet methodForSelector: @selector(characterIsMember:)]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_characterSet release]; [super dealloc]; } - (bool)characterIsMember: (OFUnichar)character { return !_characterIsMember(_characterSet, @selector(characterIsMember:), character); } - (OFCharacterSet *)invertedSet { return [[_characterSet retain] autorelease]; } @end objfw-1.1.6/src/OFInvocation.h000066400000000000000000000052021465614216400161340ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN @class OFMethodSignature; @class OFMutableArray OF_GENERIC(ObjectType); @class OFMutableData; /** * @class OFInvocation OFInvocation.h ObjFW/OFInvocation.h * * @brief A class for storing and accessing invocations, and invoking them. */ OF_SUBCLASSING_RESTRICTED @interface OFInvocation: OFObject { OFMethodSignature *_methodSignature; OFMutableArray OF_GENERIC(OFMutableData *) *_arguments; OFMutableData *_returnValue; } /** * @brief The method signature for the invocation. */ @property (readonly, nonatomic) OFMethodSignature *methodSignature; /** * @brief Creates a new invocation with the specified method signature. * * @param signature The method signature for the invocation * @return A new, autoreleased OFInvocation */ + (instancetype)invocationWithMethodSignature: (OFMethodSignature *)signature; /** * @brief Initializes an already allocated invocation with the specified method * signature. * * @param signature The method signature for the invocation * @return An initialized OFInvocation */ - (instancetype)initWithMethodSignature: (OFMethodSignature *)signature; /** * @brief Sets the argument for the specified index. * * @param buffer The buffer in which the argument is stored * @param index The index of the argument to set */ - (void)setArgument: (const void *)buffer atIndex: (size_t)index; /** * @brief Gets the argument for the specified index. * * @param buffer The buffer in which the argument is stored * @param index The index of the argument to get */ - (void)getArgument: (void *)buffer atIndex: (size_t)index; /** * @brief Sets the return value. * * @param buffer The buffer in which the return value is stored */ - (void)setReturnValue: (const void *)buffer; /** * @brief Gets the return value. * * @param buffer The buffer in which the return value is stored */ - (void)getReturnValue: (void *)buffer; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFInvocation.m000066400000000000000000000054111465614216400161430ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFInvocation.h" #import "OFArray.h" #import "OFData.h" #import "OFMethodSignature.h" @implementation OFInvocation @synthesize methodSignature = _methodSignature; + (instancetype)invocationWithMethodSignature: (OFMethodSignature *)signature { return [[[self alloc] initWithMethodSignature: signature] autorelease]; } - (instancetype)initWithMethodSignature: (OFMethodSignature *)signature { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); size_t numberOfArguments = signature.numberOfArguments; const char *typeEncoding; size_t typeSize; _methodSignature = [signature retain]; _arguments = [[OFMutableArray alloc] init]; for (size_t i = 0; i < numberOfArguments; i++) { OFMutableData *data; typeEncoding = [_methodSignature argumentTypeAtIndex: i]; typeSize = OFSizeOfTypeEncoding(typeEncoding); data = [OFMutableData dataWithItemSize: typeSize capacity: 1]; [data increaseCountBy: 1]; [_arguments addObject: data]; } typeEncoding = _methodSignature.methodReturnType; typeSize = OFSizeOfTypeEncoding(typeEncoding); if (typeSize > 0) { _returnValue = [[OFMutableData alloc] initWithItemSize: typeSize capacity: 1]; [_returnValue increaseCountBy: 1]; } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_methodSignature release]; [_arguments release]; [_returnValue release]; [super dealloc]; } - (void)setArgument: (const void *)buffer atIndex: (size_t)idx { OFMutableData *data = [_arguments objectAtIndex: idx]; memcpy(data.mutableItems, buffer, data.itemSize); } - (void)getArgument: (void *)buffer atIndex: (size_t)idx { OFData *data = [_arguments objectAtIndex: idx]; memcpy(buffer, data.items, data.itemSize); } - (void)setReturnValue: (const void *)buffer { memcpy(_returnValue.mutableItems, buffer, _returnValue.itemSize); } - (void)getReturnValue: (void *)buffer { memcpy(buffer, _returnValue.items, _returnValue.itemSize); } @end objfw-1.1.6/src/OFJSONRepresentation.h000066400000000000000000000040031465614216400175150ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" @class OFString; OF_ASSUME_NONNULL_BEGIN /** * @brief Options to change the behavior when creating a JSON representation. */ typedef enum { /** Optimize for readability */ OFJSONRepresentationOptionPretty = 0x01, /** Generate JSON5 */ OFJSONRepresentationOptionJSON5 = 0x02, OFJSONRepresentationOptionIsIdentifier = 0x10 } OFJSONRepresentationOptions; /** * @protocol OFJSONRepresentation * OFJSONRepresentation.h ObjFW/OFJSONRepresentation.h * * @brief A protocol implemented by classes that support encoding to a JSON * representation. * * @warning Although this method can be called directly on classes other than * OFArray and OFDictionary, this will generate invalid JSON, as JSON * requires all data to be encapsulated in an array or a dictionary! */ @protocol OFJSONRepresentation /** * @brief The JSON representation of the object as a string. */ @property (readonly, nonatomic) OFString *JSONRepresentation; /** * @brief Returns the JSON representation of the object as a string. * * @param options The options to use when creating a JSON representation * @return The JSON representation of the object as a string */ - (OFString *)JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFKernelEventObserver.h000066400000000000000000000174271465614216400177710ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #ifdef OF_HAVE_SOCKETS # import "OFSocket.h" #endif #ifdef OF_AMIGAOS # include # include #endif OF_ASSUME_NONNULL_BEGIN @class OFMutableArray OF_GENERIC(ObjectType); @class OFDate; #ifdef OF_HAVE_THREADS @class OFMutex; #endif @class OFMutableData; /** * @protocol OFKernelEventObserverDelegate * OFKernelEventObserver.h ObjFW/OFKernelEventObserver.h * * @brief A protocol that needs to be implemented by delegates for * OFKernelEventObserver. */ @protocol OFKernelEventObserverDelegate @optional /** * @brief This callback is called when an object did get ready for reading. * * @note If the object is a subclass of @ref OFStream and * @ref OFStream#tryReadLine or @ref OFStream#tryReadUntilDelimiter: * has been called on the stream, this callback will not be called again * until new data has been received, even though there is still data in * the cache. The reason for this is to prevent spinning in a loop when * there is an incomplete string in the cache. Once the string has been * completed, the callback will be called again as long there is data in * the cache. * * @param object The object which did become ready for reading */ - (void)objectIsReadyForReading: (id)object; /** * @brief This callback is called when an object did get ready for writing. * * @param object The object which did become ready for writing */ - (void)objectIsReadyForWriting: (id)object; #if defined(OF_AMIGAOS) || defined(DOXYGEN) /** * @brief This callback is called when an Exec Signal was received. * * @note This is only available on AmigaOS! */ - (void)execSignalWasReceived: (ULONG)signalMask; #endif @end /** * @protocol OFReadyForReadingObserving * OFKernelEventObserver.h ObjFW/OFKernelEventObserver.h * * @brief This protocol is implemented by classes which can be observed for * readiness for reading by OFKernelEventObserver. */ @protocol OFReadyForReadingObserving /** * @brief The file descriptor for reading that should be checked by the * OFKernelEventObserver. */ @property (readonly, nonatomic) int fileDescriptorForReading; @end /** * @protocol OFReadyForWritingObserving * OFKernelEventObserver.h ObjFW/OFKernelEventObserver.h * * @brief This protocol is implemented by classes which can be observed for * readiness for writing by OFKernelEventObserver. */ @protocol OFReadyForWritingObserving /** * @brief The file descriptor for writing that should be checked by the * OFKernelEventObserver. */ @property (readonly, nonatomic) int fileDescriptorForWriting; @end #ifdef OF_HAVE_SOCKETS /** * @class OFKernelEventObserver * OFKernelEventObserver.h ObjFW/OFKernelEventObserver.h * * @brief A class that can observe multiple kernel events (e.g. streams being * ready to read) at once. * * @note Currently, Win32 can only observe TCP and UDP sockets! */ @interface OFKernelEventObserver: OFObject { OFMutableArray OF_GENERIC(id ) *_readObjects; OFMutableArray OF_GENERIC(id ) *_writeObjects; id _Nullable _delegate; # if defined(OF_AMIGAOS) struct Task *_waitingTask; ULONG _cancelSignal; # elif defined(OF_HAVE_PIPE) int _cancelFD[2]; # else OFSocketHandle _cancelFD[2]; struct sockaddr_in _cancelAddr; # endif # ifdef OF_AMIGAOS ULONG _execSignalMask; # endif OF_RESERVE_IVARS(OFKernelEventObserver, 4) } /** * @brief The delegate for the OFKernelEventObserver. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id delegate; # if defined(OF_AMIGAOS) || defined(DOXYGEN) /** * @brief A mask of Exec Signals to wait for. * * @note This is only available on AmigaOS! */ @property (nonatomic) ULONG execSignalMask; # endif /** * @brief Creates a new OFKernelEventObserver. * * @return A new, autoreleased OFKernelEventObserver */ + (instancetype)observer; /** * @brief Adds an object to observe for reading. * * This is also used to observe a listening socket for incoming connections, * which then triggers a read event for the observed object. * * If there is an @ref observe call blocking, it will be canceled. The reason * for this is to prevent blocking even though the newly added object is ready. * * @param object The object to observe for reading * @throw OFObserveKernelEventsFailedException Adding the object for observing * failed */ - (void)addObjectForReading: (id )object; /** * @brief Adds an object to observe for writing. * * If there is an @ref observe call blocking, it will be canceled. The reason * for this is to prevent blocking even though the newly added object is ready. * * @param object The object to observe for writing * @throw OFObserveKernelEventsFailedException Adding the object for observing * failed */ - (void)addObjectForWriting: (id )object; /** * @brief Removes an object to observe for reading. * * If there is an @ref observe call blocking, it will be canceled. The reason * for this is to prevent the removed object from still being observed. * * @param object The object to remove from observing for reading * @throw OFObserveKernelEventsFailedException Removing the object for observing * failed */ - (void)removeObjectForReading: (id )object; /** * @brief Removes an object to observe for writing. * * If there is an @ref observe call blocking, it will be canceled. The reason * for this is to prevent the removed object from still being observed. * * @param object The object to remove from observing for writing * @throw OFObserveKernelEventsFailedException Removing the object for observing * failed */ - (void)removeObjectForWriting: (id )object; /** * @brief Observes all objects and blocks until an event happens on an object. * * @throw OFObserveKernelEventsFailedException Observing for kernel events * failed */ - (void)observe; /** * @brief Observes all objects until an event happens on an object or the * timeout is reached. * * @param timeInterval The time to wait for an event, in seconds * @throw OFObserveKernelEventsFailedException Observing for kernel events * failed */ - (void)observeForTimeInterval: (OFTimeInterval)timeInterval; /** * @brief Observes all objects until an event happens on an object or the * specified date is reached. * * @param date The until which to observe * @throw OFObserveKernelEventsFailedException Observing for kernel events * failed */ - (void)observeUntilDate: (OFDate *)date; /** * @brief Cancels the currently blocking observe call. * * This is the only method that can and should be called from another thread * than the one using the observer. */ - (void)cancel; /** * @brief This method should be called by subclasses in @ref observeUntilDate: * as the first thing to handle all sockets that currently have data in * the read buffer. */ - (bool)of_processReadBuffers; @end #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFKernelEventObserver.m000066400000000000000000000147751465614216400200010ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFKernelEventObserver.h" #import "OFArray.h" #import "OFData.h" #import "OFDate.h" #ifdef HAVE_EPOLL # import "OFEpollKernelEventObserver.h" #endif #ifdef HAVE_KQUEUE # import "OFKqueueKernelEventObserver.h" #endif #ifdef HAVE_POLL # import "OFPollKernelEventObserver.h" #endif #ifdef HAVE_SELECT # import "OFSelectKernelEventObserver.h" #endif #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFStream.h" #import "OFStream+Private.h" #ifndef OF_HAVE_PIPE # import "OFStreamSocket.h" #endif #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" #ifdef OF_AMIGAOS # define Class IntuitionClass # include # undef Class #endif @implementation OFKernelEventObserver @synthesize delegate = _delegate; #ifdef OF_AMIGAOS @synthesize execSignalMask = _execSignalMask; #endif + (void)initialize { if (self != [OFKernelEventObserver class]) return; if (!_OFSocketInit()) @throw [OFInitializationFailedException exceptionWithClass: self]; } + (instancetype)observer { return [[[self alloc] init] autorelease]; } + (instancetype)alloc { if (self == [OFKernelEventObserver class]) #if defined(HAVE_KQUEUE) return [OFKqueueKernelEventObserver alloc]; #elif defined(HAVE_EPOLL) return [OFEpollKernelEventObserver alloc]; #elif defined(HAVE_POLL) return [OFPollKernelEventObserver alloc]; #elif defined(HAVE_SELECT) return [OFSelectKernelEventObserver alloc]; #else # error No kqueue / epoll / poll / select found! #endif return [super alloc]; } - (instancetype)init { self = [super init]; @try { #if !defined(OF_HAVE_PIPE) && !defined(OF_WII) && !defined(OF_AMIGAOS) && \ !defined(OF_NINTENDO_3DS) socklen_t cancelAddrLen; #endif _readObjects = [[OFMutableArray alloc] init]; _writeObjects = [[OFMutableArray alloc] init]; #if defined(OF_HAVE_PIPE) && !defined(OF_AMIGAOS) if (pipe(_cancelFD)) @throw [OFInitializationFailedException exceptionWithClass: self.class]; #elif !defined(OF_AMIGAOS) _cancelFD[0] = _cancelFD[1] = socket(AF_INET, SOCK_DGRAM, 0); if (_cancelFD[0] == OFInvalidSocketHandle) @throw [OFInitializationFailedException exceptionWithClass: self.class]; _cancelAddr.sin_family = AF_INET; _cancelAddr.sin_port = 0; _cancelAddr.sin_addr.s_addr = inet_addr((void *)"127.0.0.1"); # ifdef OF_WII _cancelAddr.sin_len = 8; # endif # if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) if (bind(_cancelFD[0], (struct sockaddr *)&_cancelAddr, sizeof(_cancelAddr)) != 0) @throw [OFInitializationFailedException exceptionWithClass: self.class]; cancelAddrLen = sizeof(_cancelAddr); if (_OFGetSockName(_cancelFD[0], (struct sockaddr *)&_cancelAddr, &cancelAddrLen) != 0) @throw [OFInitializationFailedException exceptionWithClass: self.class]; # else for (;;) { uint16_t rnd = 0; int ret; while (rnd < 1024) rnd = (uint16_t)rand(); _cancelAddr.sin_port = OFToBigEndian16(rnd); ret = bind(_cancelFD[0], (struct sockaddr *)&_cancelAddr, sizeof(_cancelAddr)); if (ret == 0) break; if (_OFSocketErrNo() != EADDRINUSE) @throw [OFInitializationFailedException exceptionWithClass: self.class]; } # endif #endif } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { #if defined(OF_HAVE_PIPE) && !defined(OF_AMIGAOS) close(_cancelFD[0]); if (_cancelFD[1] != _cancelFD[0]) close(_cancelFD[1]); #elif !defined(OF_AMIGAOS) closesocket(_cancelFD[0]); if (_cancelFD[1] != _cancelFD[0]) closesocket(_cancelFD[1]); #endif [_readObjects release]; [_writeObjects release]; [super dealloc]; } - (void)addObjectForReading: (id )object { [_readObjects addObject: object]; } - (void)addObjectForWriting: (id )object { [_writeObjects addObject: object]; } - (void)removeObjectForReading: (id )object { [_readObjects removeObjectIdenticalTo: object]; } - (void)removeObjectForWriting: (id )object { [_writeObjects removeObjectIdenticalTo: object]; } - (bool)of_processReadBuffers { void *pool = objc_autoreleasePoolPush(); bool foundInReadBuffer = false; for (id object in [[_readObjects copy] autorelease]) { void *pool2; if (![object isKindOfClass: [OFStream class]]) continue; pool2 = objc_autoreleasePoolPush(); if ([object hasDataInReadBuffer] && (![object of_isWaitingForDelimiter] || [object lowlevelHasDataInReadBuffer])) { if ([_delegate respondsToSelector: @selector(objectIsReadyForReading:)]) [_delegate objectIsReadyForReading: object]; foundInReadBuffer = true; } objc_autoreleasePoolPop(pool2); } objc_autoreleasePoolPop(pool); /* * As long as we have data in the read buffer for any stream, we don't * want to block. */ return foundInReadBuffer; } - (void)observe { [self observeForTimeInterval: -1]; } - (void)observeForTimeInterval: (OFTimeInterval)timeInterval { OF_UNRECOGNIZED_SELECTOR } - (void)observeUntilDate: (OFDate *)date { [self observeForTimeInterval: date.timeIntervalSinceNow]; } - (void)cancel { #if defined(OF_AMIGAOS) Forbid(); if (_waitingTask != NULL) { Signal(_waitingTask, (1ul << _cancelSignal)); _waitingTask = NULL; } Permit(); #elif defined(OF_HAVE_PIPE) do { if (write(_cancelFD[1], "", 1) == 1) break; OFEnsure(errno == EINTR); } while (true); #elif defined(OF_WII) do { if (sendto(_cancelFD[1], "", 1, 0, (struct sockaddr *)&_cancelAddr, 8) == 1) break; OFEnsure(_OFSocketErrNo() == EINTR); } while (true); #else do { if (sendto(_cancelFD[1], (void *)"", 1, 0, (struct sockaddr *)&_cancelAddr, sizeof(_cancelAddr)) == 1) break; OFEnsure(_OFSocketErrNo() == EINTR); } while (true); #endif } @end objfw-1.1.6/src/OFKeyValueCoding.h000066400000000000000000000070311465614216400166760ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "macros.h" @class OFString; OF_ASSUME_NONNULL_BEGIN /** * @protocol OFKeyValueCoding OFKeyValueCoding.h ObjFW/OFKeyValueCoding.h * * @brief A protocol for Key Value Coding. * * Key Value Coding makes it possible to access properties dynamically using * the interface described by this protocol. */ @protocol OFKeyValueCoding /** * @brief Returns the value for the specified key. * * @param key The key of the value to return * @return The value for the specified key * @throw OFUndefinedKeyException The specified key does not exist and * @ref valueForUndefinedKey: was not overridden */ - (nullable id)valueForKey: (OFString *)key; /** * @brief Returns the value for the specified key path. * * @param keyPath The key path of the value to return * @return The value for the specified key path * @throw OFUndefinedKeyException The specified key does not exist and * @ref valueForUndefinedKey: was not overridden */ - (nullable id)valueForKeyPath: (OFString *)keyPath; /** * @brief This is called by @ref valueForKey: if the specified key does not * exist. * * By default, this throws an @ref OFUndefinedKeyException. * * @param key The undefined key of the value to return * @return The value for the specified undefined key * @throw OFUndefinedKeyException The specified key does not exist */ - (nullable id)valueForUndefinedKey: (OFString *)key; /** * @brief Set the value for the specified key. * * @param value The value for the specified key * @param key The key of the value to set * @throw OFUndefinedKeyException The specified key does not exist and * @ref setValue:forUndefinedKey: was not * overridden */ - (void)setValue: (nullable id)value forKey: (OFString *)key; /** * @brief Set the value for the specified key path. * * @param value The value for the specified key path * @param keyPath The key path of the value to set * @throw OFUndefinedKeyException The specified key does not exist and * @ref setValue:forUndefinedKey: was not * overridden */ - (void)setValue: (nullable id)value forKeyPath: (OFString *)keyPath; /** * @brief This is called by @ref setValue:forKey: if the specified key does not * exist. * * By default, this throws an @ref OFUndefinedKeyException. * * @param value The value for the specified undefined key * @param key The undefined key of the value to set * @throw OFUndefinedKeyException The specified key does not exist */ - (void)setValue: (nullable id)value forUndefinedKey: (OFString *)key; /** * @brief This is called by @ref setValue:forKey: if the specified key is a * scalar, but the value specified is `nil`. * * By default, this throws an @ref OFInvalidArgumentException. * * @param key The key for which the value `nil` was specified */ - (void)setNilValueForKey: (OFString *)key; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFKqueueKernelEventObserver.h000066400000000000000000000016701465614216400211420ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFKernelEventObserver.h" OF_ASSUME_NONNULL_BEGIN @class OFMutableArray OF_GENERIC(ObjectType); @interface OFKqueueKernelEventObserver: OFKernelEventObserver { int _kernelQueue; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFKqueueKernelEventObserver.m000066400000000000000000000127001465614216400211430ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #ifdef HAVE_FCNTL_H # include #endif #include "unistd_wrapper.h" #include #include #include #import "OFKqueueKernelEventObserver.h" #import "OFArray.h" #import "OFInitializationFailedException.h" #import "OFObserveKernelEventsFailedException.h" #import "OFOutOfRangeException.h" #define eventListSize 64 @implementation OFKqueueKernelEventObserver - (instancetype)init { self = [super init]; @try { struct kevent event; #ifdef HAVE_KQUEUE1 if ((_kernelQueue = kqueue1(O_CLOEXEC)) == -1) @throw [OFInitializationFailedException exceptionWithClass: self.class]; #else int flags; if ((_kernelQueue = kqueue()) == -1) @throw [OFInitializationFailedException exceptionWithClass: self.class]; if ((flags = fcntl(_kernelQueue, F_GETFD, 0)) != -1) fcntl(_kernelQueue, F_SETFD, flags | FD_CLOEXEC); #endif EV_SET(&event, _cancelFD[0], EVFILT_READ, EV_ADD, 0, 0, 0); if (kevent(_kernelQueue, &event, 1, NULL, 0, NULL) != 0) @throw [OFInitializationFailedException exceptionWithClass: self.class]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { close(_kernelQueue); [super dealloc]; } - (void)addObjectForReading: (id )object { struct kevent event; memset(&event, 0, sizeof(event)); event.ident = object.fileDescriptorForReading; event.filter = EVFILT_READ; event.flags = EV_ADD; /* * Ugly hack required for NetBSD: NetBSD used `intptr_t` for udata, but * switched this to `void *` in NetBSD 10. */ event.udata = (__typeof__(event.udata))object; if (kevent(_kernelQueue, &event, 1, NULL, 0, NULL) != 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: errno]; [super addObjectForReading: object]; } - (void)addObjectForWriting: (id )object { struct kevent event; memset(&event, 0, sizeof(event)); event.ident = object.fileDescriptorForWriting; event.filter = EVFILT_WRITE; event.flags = EV_ADD; /* * Ugly hack required for NetBSD: NetBSD used `intptr_t` for udata, but * switched this to `void *` in NetBSD 10. */ event.udata = (__typeof__(event.udata))object; if (kevent(_kernelQueue, &event, 1, NULL, 0, NULL) != 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: errno]; [super addObjectForWriting: object]; } - (void)removeObjectForReading: (id )object { struct kevent event; memset(&event, 0, sizeof(event)); event.ident = object.fileDescriptorForReading; event.filter = EVFILT_READ; event.flags = EV_DELETE; if (kevent(_kernelQueue, &event, 1, NULL, 0, NULL) != 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: errno]; [super removeObjectForReading: object]; } - (void)removeObjectForWriting: (id )object { struct kevent event; memset(&event, 0, sizeof(event)); event.ident = object.fileDescriptorForWriting; event.filter = EVFILT_WRITE; event.flags = EV_DELETE; if (kevent(_kernelQueue, &event, 1, NULL, 0, NULL) != 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: errno]; [super removeObjectForWriting: object]; } - (void)observeForTimeInterval: (OFTimeInterval)timeInterval { struct timespec timeout; struct kevent eventList[eventListSize]; int events; if ([self of_processReadBuffers]) return; timeout.tv_sec = (time_t)timeInterval; timeout.tv_nsec = (long)((timeInterval - timeout.tv_sec) * 1000000000); events = kevent(_kernelQueue, NULL, 0, eventList, eventListSize, (timeInterval != -1 ? &timeout : NULL)); if (events < 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: errno]; for (int i = 0; i < events; i++) { void *pool; if (eventList[i].flags & EV_ERROR) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: (int)eventList[i].data]; if (eventList[i].ident == (uintptr_t)_cancelFD[0]) { char buffer; OFAssert(eventList[i].filter == EVFILT_READ); OFEnsure(read(_cancelFD[0], &buffer, 1) == 1); continue; } pool = objc_autoreleasePoolPush(); switch (eventList[i].filter) { case EVFILT_READ: if ([_delegate respondsToSelector: @selector(objectIsReadyForReading:)]) [_delegate objectIsReadyForReading: (id)eventList[i].udata]; break; case EVFILT_WRITE: if ([_delegate respondsToSelector: @selector(objectIsReadyForWriting:)]) [_delegate objectIsReadyForWriting: (id)eventList[i].udata]; break; default: OFAssert(0); } objc_autoreleasePoolPop(pool); } } @end objfw-1.1.6/src/OFLHAArchive.h000066400000000000000000000133171465614216400157370ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFLHAArchiveEntry.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @class OFIRI; @class OFStream; /** * @class OFLHAArchive OFLHAArchive.h ObjFW/OFLHAArchive.h * * @brief A class for accessing and manipulating LHA files. */ OF_SUBCLASSING_RESTRICTED @interface OFLHAArchive: OFObject { OFStream *_stream; uint_least8_t _mode; OFStringEncoding _encoding; OFLHAArchiveEntry *_Nullable _currentEntry; #ifdef OF_LHA_ARCHIVE_M @public #endif OFStream *_Nullable _lastReturnedStream; @protected bool _hasWritten; } /** * @brief The encoding to use for the archive. Defaults to UTF-8. */ @property (nonatomic) OFStringEncoding encoding; /** * @brief Creates a new OFLHAArchive object with the specified stream. * * @param stream A stream from which the LHA archive will be read. * For read and append mode, this needs to be an OFSeekableStream. * @param mode The mode for the LHA file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return A new, autoreleased OFLHAArchive */ + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode; /** * @brief Creates a new OFLHAArchive object with the specified file. * * @param IRI The IRI to the LHA file * @param mode The mode for the LHA file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return A new, autoreleased OFLHAArchive */ + (instancetype)archiveWithIRI: (OFIRI *)IRI mode: (OFString *)mode; /** * @brief Creates an IRI for accessing the specified file within the specified * LHA archive. * * @param path The path of the file within the archive * @param IRI The IRI of the archive * @return An IRI for accessing the specified file within the specified LHA * archive */ + (OFIRI *)IRIForFilePath: (OFString *)path inArchiveWithIRI: (OFIRI *)IRI; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFLHAArchive object with the * specified stream. * * @param stream A stream from which the LHA archive will be read. * For read and append mode, this needs to be an OFSeekableStream. * @param mode The mode for the LHA file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return An initialized OFLHAArchive */ - (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated OFLHAArchive object with the * specified file. * * @param IRI The IRI to the LHA file * @param mode The mode for the LHA file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return An initialized OFLHAArchive */ - (instancetype)initWithIRI: (OFIRI *)IRI mode: (OFString *)mode; /** * @brief Returns the next entry from the LHA archive or `nil` if all entries * have been read. * * @note This is only available in read mode. * * @warning Calling @ref nextEntry will invalidate all streams returned by * @ref streamForReadingCurrentEntry or * @ref streamForWritingEntry:! Reading from or writing to an * invalidated stream will throw an @ref OFReadFailedException or * @ref OFWriteFailedException! * * @return The next entry from the LHA archive or `nil` if all entries have * been read * @throw OFInvalidFormatException The archive's format is invalid * @throw OFUnsupportedVersionException The archive's format is of an * unsupported version * @throw OFTruncatedDataException The archive was truncated */ - (nullable OFLHAArchiveEntry *)nextEntry; /** * @brief Returns a stream for reading the current entry. * * @note This is only available in read mode. * * @note The returned stream conforms to @ref OFReadyForReadingObserving if the * underlying stream does so, too. * * @return A stream for reading the current entry */ - (OFStream *)streamForReadingCurrentEntry; /** * @brief Returns a stream for writing the specified entry. * * @note This is only available in write and append mode. * * @note The uncompressed size, compressed size and CRC16 of the specified * entry are ignored. * * @note The returned stream conforms to @ref OFReadyForWritingObserving if the * underlying stream does so, too. * * @warning Calling @ref streamForWritingEntry: will invalidate all streams * returned by @ref streamForReadingCurrentEntry or * @ref streamForWritingEntry:! Reading from or writing to an * invalidated stream will throw an @ref OFReadFailedException or * @ref OFWriteFailedException! * * @param entry The entry for which a stream for writing should be returned * @return A stream for writing the specified entry */ - (OFStream *)streamForWritingEntry: (OFLHAArchiveEntry *)entry; /** * @brief Closes the OFLHAArchive. * * @throw OFNotOpenException The archive is not open */ - (void)close; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFLHAArchive.m000066400000000000000000000343261465614216400157470ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #define OF_LHA_ARCHIVE_M #include "config.h" #include #import "OFLHAArchive.h" #import "OFLHAArchiveEntry.h" #import "OFLHAArchiveEntry+Private.h" #import "OFArchiveIRIHandler.h" #import "OFCRC16.h" #import "OFIRI.h" #import "OFIRIHandler.h" #import "OFKernelEventObserver.h" #import "OFLHADecompressingStream.h" #import "OFSeekableStream.h" #import "OFStream.h" #import "OFString.h" #import "OFChecksumMismatchException.h" #import "OFInvalidArgumentException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedVersionException.h" #import "OFWriteFailedException.h" enum { modeRead, modeWrite, modeAppend }; OF_DIRECT_MEMBERS @interface OFLHAArchiveFileReadStream: OFStream { OFLHAArchive *_archive; OFStream *_stream, *_decompressedStream; OFLHAArchiveEntry *_entry; unsigned long long _toRead; uint16_t _CRC16; bool _atEndOfStream, _skipped; } - (instancetype)of_initWithArchive: (OFLHAArchive *)archive stream: (OFStream *)stream entry: (OFLHAArchiveEntry *)entry; - (void)of_skip; @end OF_DIRECT_MEMBERS @interface OFLHAArchiveFileWriteStream: OFStream { OFLHAArchive *_archive; OFMutableLHAArchiveEntry *_entry; OFStringEncoding _encoding; OFSeekableStream *_stream; OFStreamOffset _headerOffset; uint64_t _bytesWritten; uint16_t _CRC16; } - (instancetype)of_initWithArchive: (OFLHAArchive *)archive stream: (OFSeekableStream *)stream entry: (OFLHAArchiveEntry *)entry encoding: (OFStringEncoding)encoding; @end @implementation OFLHAArchive @synthesize encoding = _encoding; + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode { return [[[self alloc] initWithStream: stream mode: mode] autorelease]; } + (instancetype)archiveWithIRI: (OFIRI *)IRI mode: (OFString *)mode { return [[[self alloc] initWithIRI: IRI mode: mode] autorelease]; } + (OFIRI *)IRIForFilePath: (OFString *)path inArchiveWithIRI: (OFIRI *)IRI { return _OFArchiveIRIHandlerIRIForFileInArchive(@"lha", path, IRI); } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode { self = [super init]; @try { _stream = [stream retain]; if ([mode isEqual: @"r"]) _mode = modeRead; else if ([mode isEqual: @"w"]) _mode = modeWrite; else if ([mode isEqual: @"a"]) _mode = modeAppend; else @throw [OFInvalidArgumentException exception]; if ((_mode == modeWrite || _mode == modeAppend) && ![_stream isKindOfClass: [OFSeekableStream class]]) @throw [OFInvalidArgumentException exception]; if (_mode == modeAppend) /* * Only works with properly zero-terminated files that * have no trailing garbage. Unfortunately there is no * good way to check for this other than reading the * entire archive. */ [(OFSeekableStream *)_stream seekToOffset: -1 whence: OFSeekEnd]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithIRI: (OFIRI *)IRI mode: (OFString *)mode { void *pool = objc_autoreleasePoolPush(); OFStream *stream; @try { if ([mode isEqual: @"a"]) stream = [OFIRIHandler openItemAtIRI: IRI mode: @"r+"]; else stream = [OFIRIHandler openItemAtIRI: IRI mode: mode]; } @catch (id e) { [self release]; @throw e; } self = [self initWithStream: stream mode: mode]; objc_autoreleasePoolPop(pool); return self; } - (void)dealloc { if (_stream != nil) [self close]; [_currentEntry release]; [super dealloc]; } - (OFLHAArchiveEntry *)nextEntry { char header[21]; size_t headerLen; if (_mode != modeRead) @throw [OFInvalidArgumentException exception]; if (_currentEntry != nil && _lastReturnedStream == nil) { /* * No read stream was created since the last call to * -[nextEntry]. Create it so that we can properly skip the * data. */ void *pool = objc_autoreleasePoolPush(); [self streamForReadingCurrentEntry]; objc_autoreleasePoolPop(pool); } [_currentEntry release]; _currentEntry = nil; [(OFLHAArchiveFileReadStream *)_lastReturnedStream of_skip]; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } _lastReturnedStream = nil; for (headerLen = 0; headerLen < 21;) { if (_stream.atEndOfStream) { if (headerLen == 0) return nil; if (headerLen == 1 && header[0] == 0) return nil; @throw [OFTruncatedDataException exception]; } headerLen += [_stream readIntoBuffer: header + headerLen length: 21 - headerLen]; } /* * Some archives have trailing garbage after the single byte 0 * termination. However, a level 2 header uses 2 bytes for the size, so * could just have a header size that is a multiple of 256. Therefore, * consider it only the end of the archive if what follows would not be * a level 2 header. */ if (header[0] == 0 && header[20] != 2) return nil; _currentEntry = [[OFLHAArchiveEntry alloc] of_initWithHeader: header stream: _stream encoding: _encoding]; return _currentEntry; } - (OFStream *)streamForReadingCurrentEntry { if (_mode != modeRead) @throw [OFInvalidArgumentException exception]; if (_currentEntry == nil) @throw [OFInvalidArgumentException exception]; _lastReturnedStream = [[[OFLHAArchiveFileReadStream alloc] of_initWithArchive: self stream: _stream entry: _currentEntry] autorelease]; [_currentEntry release]; _currentEntry = nil; return _lastReturnedStream; } - (OFStream *)streamForWritingEntry: (OFLHAArchiveEntry *)entry { OFString *compressionMethod; if (_mode != modeWrite && _mode != modeAppend) @throw [OFInvalidArgumentException exception]; compressionMethod = entry.compressionMethod; if (![compressionMethod isEqual: @"-lh0-"] && ![compressionMethod isEqual: @"-lhd-"]) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } _lastReturnedStream = nil; _lastReturnedStream = [[[OFLHAArchiveFileWriteStream alloc] of_initWithArchive: self stream: (OFSeekableStream *)_stream entry: entry encoding: _encoding] autorelease]; _hasWritten = true; return _lastReturnedStream; } - (void)close { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } /* LHA archives should be terminated with a header of size 0 */ if (_hasWritten) [_stream writeBuffer: "" length: 1]; _lastReturnedStream = nil; [_stream release]; _stream = nil; } @end @implementation OFLHAArchiveFileReadStream - (instancetype)of_initWithArchive: (OFLHAArchive *)archive stream: (OFStream *)stream entry: (OFLHAArchiveEntry *)entry { self = [super init]; @try { OFString *compressionMethod; _archive = [archive retain]; _stream = [stream retain]; compressionMethod = entry.compressionMethod; if ([compressionMethod isEqual: @"-lh4-"] || [compressionMethod isEqual: @"-lh5-"]) _decompressedStream = [[OFLHADecompressingStream alloc] of_initWithStream: stream distanceBits: 4 dictionaryBits: 14]; else if ([compressionMethod isEqual: @"-lh6-"]) _decompressedStream = [[OFLHADecompressingStream alloc] of_initWithStream: stream distanceBits: 5 dictionaryBits: 16]; else if ([compressionMethod isEqual: @"-lh7-"]) _decompressedStream = [[OFLHADecompressingStream alloc] of_initWithStream: stream distanceBits: 5 dictionaryBits: 17]; else if ([compressionMethod isEqual: @"-lhx-"]) _decompressedStream = [[OFLHADecompressingStream alloc] of_initWithStream: stream distanceBits: 5 dictionaryBits: 20]; else if ([compressionMethod isEqual: @"-lh0-"] || [compressionMethod isEqual: @"-lhd-"] || [compressionMethod isEqual: @"-lz4-"] || [compressionMethod isEqual: @"-pm0-"]) _decompressedStream = [stream retain]; else @throw [OFUnsupportedVersionException exceptionWithVersion: compressionMethod]; _entry = [entry copy]; _toRead = entry.uncompressedSize; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_stream != nil && _decompressedStream != nil) [self close]; [_entry release]; if (_archive->_lastReturnedStream == self) _archive->_lastReturnedStream = nil; [_archive release]; [super dealloc]; } - (bool)lowlevelIsAtEndOfStream { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; return _atEndOfStream; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { size_t ret; if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (_atEndOfStream) return 0; if (_stream.atEndOfStream && !_decompressedStream.hasDataInReadBuffer) @throw [OFTruncatedDataException exception]; if (length > _toRead) length = (size_t)_toRead; ret = [_decompressedStream readIntoBuffer: buffer length: length]; _toRead -= ret; _CRC16 = _OFCRC16(_CRC16, buffer, ret); if (_toRead == 0) { _atEndOfStream = true; if (_CRC16 != _entry.CRC16) { OFString *actualChecksum = [OFString stringWithFormat: @"%04" @PRIX16, _CRC16]; OFString *expectedChecksum = [OFString stringWithFormat: @"%04" @PRIX16, _entry.CRC16]; @throw [OFChecksumMismatchException exceptionWithActualChecksum: actualChecksum expectedChecksum: expectedChecksum]; } } return ret; } - (bool)hasDataInReadBuffer { return (super.hasDataInReadBuffer || _decompressedStream.hasDataInReadBuffer); } - (int)fileDescriptorForReading { return ((id )_decompressedStream) .fileDescriptorForReading; } - (void)of_skip { OFStream *stream; unsigned long long toRead; if (_stream == nil || _skipped) return; stream = _stream; toRead = _toRead; /* * Get the number of consumed bytes and directly read from the * compressed stream, to make skipping much faster. */ if ([_decompressedStream isKindOfClass: [OFLHADecompressingStream class]]) { OFLHADecompressingStream *decompressingStream = (OFLHADecompressingStream *)_decompressedStream; [decompressingStream close]; toRead = _entry.compressedSize - decompressingStream.bytesConsumed; stream = _stream; } if ([stream isKindOfClass: [OFSeekableStream class]] && toRead < LLONG_MAX && (long long)toRead == (OFStreamOffset)toRead) [(OFSeekableStream *)stream seekToOffset: (OFStreamOffset)toRead whence: OFSeekCurrent]; else { while (toRead > 0) { char buffer[512]; unsigned long long min = toRead; if (min > 512) min = 512; toRead -= [stream readIntoBuffer: buffer length: (size_t)min]; } } _toRead = 0; _skipped = true; } - (void)close { if (_stream == nil || _decompressedStream == nil) @throw [OFNotOpenException exceptionWithObject: self]; [self of_skip]; [_stream release]; _stream = nil; [_decompressedStream release]; _decompressedStream = nil; [super close]; } @end @implementation OFLHAArchiveFileWriteStream - (instancetype)of_initWithArchive: (OFLHAArchive *)archive stream: (OFSeekableStream *)stream entry: (OFLHAArchiveEntry *)entry encoding: (OFStringEncoding)encoding { self = [super init]; @try { _archive = [archive retain]; _entry = [entry mutableCopy]; _encoding = encoding; _headerOffset = [stream seekToOffset: 0 whence: OFSeekCurrent]; [_entry of_writeToStream: stream encoding: _encoding]; /* * Retain stream last, so that -[close] called by -[dealloc] * doesn't write in case of an error. */ _stream = [stream retain]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_stream != nil) [self close]; [_entry release]; if (_archive->_lastReturnedStream == self) _archive->_lastReturnedStream = nil; [_archive release]; [super dealloc]; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (UINT64_MAX - _bytesWritten < length) @throw [OFOutOfRangeException exception]; @try { [_stream writeBuffer: buffer length: length]; } @catch (OFWriteFailedException *e) { OFEnsure(e.bytesWritten <= length); _bytesWritten += (uint64_t)e.bytesWritten; _CRC16 = _OFCRC16(_CRC16, buffer, e.bytesWritten); if (e.errNo == EWOULDBLOCK || e.errNo == EAGAIN) return e.bytesWritten; @throw e; } _bytesWritten += (uint64_t)length; _CRC16 = _OFCRC16(_CRC16, buffer, length); return length; } - (bool)lowlevelIsAtEndOfStream { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; return _stream.atEndOfStream; } - (int)fileDescriptorForWriting { return ((id )_stream) .fileDescriptorForWriting; } - (void)close { OFStreamOffset offset; if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; _entry.uncompressedSize = _bytesWritten; _entry.compressedSize = _bytesWritten; _entry.CRC16 = _CRC16; offset = [_stream seekToOffset: 0 whence: OFSeekCurrent]; [_stream seekToOffset: _headerOffset whence: OFSeekSet]; [_entry of_writeToStream: _stream encoding: _encoding]; [_stream seekToOffset: offset whence: OFSeekSet]; [_stream release]; _stream = nil; [super close]; } @end objfw-1.1.6/src/OFLHAArchiveEntry+Private.h000066400000000000000000000022101465614216400203550ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFLHAArchive.h" OF_ASSUME_NONNULL_BEGIN @interface OFLHAArchiveEntry () - (instancetype)of_init OF_METHOD_FAMILY(init); - (instancetype)of_initWithHeader: (char [_Nonnull 21])header stream: (OFStream *)stream encoding: (OFStringEncoding)encoding OF_METHOD_FAMILY(init) OF_DIRECT; - (void)of_writeToStream: (OFStream *)stream encoding: (OFStringEncoding)encoding OF_DIRECT; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFLHAArchiveEntry.h000066400000000000000000000045751465614216400167670ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFArchiveEntry.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFData; @class OFDate; @class OFMutableArray OF_GENERIC(ObjectType); @class OFNumber; @class OFString; /** * @class OFLHAArchiveEntry OFLHAArchiveEntry.h ObjFW/OFLHAArchiveEntry.h * * @brief A class which represents an entry in an LHA archive. */ @interface OFLHAArchiveEntry: OFObject { OFString *_fileName, *_Nullable _directoryName, *_compressionMethod; unsigned long long _compressedSize, _uncompressedSize; OFDate *_modificationDate; uint8_t _headerLevel; uint16_t _CRC16; uint8_t _operatingSystemIdentifier; OFString *_Nullable _fileComment; OFNumber *_Nullable _POSIXPermissions, *_Nullable _ownerAccountID; OFNumber *_Nullable _groupOwnerAccountID; OFString *_Nullable _ownerAccountName; OFString *_Nullable _groupOwnerAccountName; OFMutableArray OF_GENERIC(OFData *) *_extensions; OF_RESERVE_IVARS(OFLHAArchiveEntry, 4) } /** * @brief The compression method of the entry. */ @property (readonly, copy, nonatomic) OFString *compressionMethod; /** * @brief The LHA level of the file. */ @property (readonly, nonatomic) uint8_t headerLevel; /** * @brief The CRC16 of the file. */ @property (readonly, nonatomic) uint16_t CRC16; /** * @brief The operating system identifier of the file. */ @property (readonly, nonatomic) uint8_t operatingSystemIdentifier; /** * @brief The LHA extensions of the file. */ @property (readonly, copy, nonatomic) OFArray OF_GENERIC(OFData *) *extensions; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END #import "OFMutableLHAArchiveEntry.h" objfw-1.1.6/src/OFLHAArchiveEntry.m000066400000000000000000000542341465614216400167710ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFLHAArchiveEntry.h" #import "OFLHAArchiveEntry+Private.h" #import "OFArray.h" #import "OFCRC16.h" #import "OFData.h" #import "OFDate.h" #import "OFNumber.h" #import "OFSeekableStream.h" #import "OFStream.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "OFUnsupportedVersionException.h" static OFDate * parseMSDOSDate(uint32_t MSDOSDate) { uint16_t year = ((MSDOSDate & 0xFE000000) >> 25) + 1980; uint8_t month = (MSDOSDate & 0x1E00000) >> 21; uint8_t day = (MSDOSDate & 0x1F); uint8_t hour = (MSDOSDate & 0xF800) >> 11; uint8_t minute = (MSDOSDate & 0x7E0) >> 5; uint8_t second = (MSDOSDate & 0x1F) << 1; OFString *dateString; dateString = [OFString stringWithFormat: @"%04u-%02u-%02u %02u:%02u:%02u", year, month, day, hour, minute, second]; return [OFDate dateWithLocalDateString: dateString format: @"%Y-%m-%d %H:%M:%S"]; } @implementation OFLHAArchiveEntry static void parseFileNameExtension(OFLHAArchiveEntry *entry, OFData *extension, OFStringEncoding encoding) { [entry->_fileName release]; entry->_fileName = nil; entry->_fileName = [[OFString alloc] initWithCString: (char *)extension.items + 1 encoding: encoding length: [extension count] - 1]; } static void parseDirectoryNameExtension(OFLHAArchiveEntry *entry, OFData *extension, OFStringEncoding encoding) { void *pool = objc_autoreleasePoolPush(); OFMutableData *data = [[extension mutableCopy] autorelease]; char *items = data.mutableItems; size_t count = data.count; OFMutableString *directoryName; for (size_t i = 1; i < count; i++) if (items[i] == '\xFF') items[i] = '/'; directoryName = [OFMutableString stringWithCString: items + 1 encoding: encoding length: count - 1]; if (![directoryName hasSuffix: @"/"]) [directoryName appendString: @"/"]; [directoryName makeImmutable]; [entry->_directoryName release]; entry->_directoryName = nil; entry->_directoryName = [directoryName copy]; objc_autoreleasePoolPop(pool); } static void parseCommentExtension(OFLHAArchiveEntry *entry, OFData *extension, OFStringEncoding encoding) { [entry->_fileComment release]; entry->_fileComment = nil; entry->_fileComment = [[OFString alloc] initWithCString: (char *)extension.items + 1 encoding: encoding length: extension.count - 1]; } static void parsePermissionsExtension(OFLHAArchiveEntry *entry, OFData *extension, OFStringEncoding encoding) { uint16_t POSIXPermissions; if (extension.count != 3) @throw [OFInvalidFormatException exception]; memcpy(&POSIXPermissions, (char *)extension.items + 1, 2); POSIXPermissions = OFFromLittleEndian16(POSIXPermissions); [entry->_POSIXPermissions release]; entry->_POSIXPermissions = nil; entry->_POSIXPermissions = [[OFNumber alloc] initWithUnsignedShort: POSIXPermissions]; } static void parseGIDUIDExtension(OFLHAArchiveEntry *entry, OFData *extension, OFStringEncoding encoding) { uint16_t ownerAccountID, groupOwnerAccountID; if (extension.count != 5) @throw [OFInvalidFormatException exception]; memcpy(&groupOwnerAccountID, (char *)extension.items + 1, 2); groupOwnerAccountID = OFFromLittleEndian16(groupOwnerAccountID); memcpy(&ownerAccountID, (char *)extension.items + 3, 2); ownerAccountID = OFFromLittleEndian16(ownerAccountID); [entry->_groupOwnerAccountID release]; entry->_groupOwnerAccountID = nil; [entry->_ownerAccountID release]; entry->_ownerAccountID = nil; entry->_groupOwnerAccountID = [[OFNumber alloc] initWithUnsignedShort: groupOwnerAccountID]; entry->_ownerAccountID = [[OFNumber alloc] initWithUnsignedShort: ownerAccountID]; } static void parseGroupExtension(OFLHAArchiveEntry *entry, OFData *extension, OFStringEncoding encoding) { [entry->_groupOwnerAccountName release]; entry->_groupOwnerAccountName = nil; entry->_groupOwnerAccountName = [[OFString alloc] initWithCString: (char *)extension.items + 1 encoding: encoding length: extension.count - 1]; } static void parseOwnerExtension(OFLHAArchiveEntry *entry, OFData *extension, OFStringEncoding encoding) { [entry->_ownerAccountName release]; entry->_ownerAccountName = nil; entry->_ownerAccountName = [[OFString alloc] initWithCString: (char *)extension.items + 1 encoding: encoding length: extension.count - 1]; } static void parseModificationDateExtension(OFLHAArchiveEntry *entry, OFData *extension, OFStringEncoding encoding) { uint32_t modificationDate; if (extension.count != 5) @throw [OFInvalidFormatException exception]; memcpy(&modificationDate, (char *)extension.items + 1, 4); modificationDate = OFFromLittleEndian32(modificationDate); [entry->_modificationDate release]; entry->_modificationDate = nil; entry->_modificationDate = [[OFDate alloc] initWithTimeIntervalSince1970: modificationDate]; } static void parseFileSizeExtension(OFLHAArchiveEntry *entry, OFData *extension, OFStringEncoding encoding) { uint64_t tmp; if (extension.count != 17) @throw [OFInvalidFormatException exception]; memcpy(&tmp, (char *)extension.items + 1, 8); entry->_compressedSize = OFFromLittleEndian64(tmp); memcpy(&tmp, (char *)extension.items + 9, 8); entry->_uncompressedSize = OFFromLittleEndian64(tmp); } static bool parseExtension(OFLHAArchiveEntry *entry, OFData *extension, OFStringEncoding encoding, bool allowFileName) { void (*function)(OFLHAArchiveEntry *, OFData *, OFStringEncoding) = NULL; switch (*(char *)[extension itemAtIndex: 0]) { case 0x01: if (allowFileName) function = parseFileNameExtension; break; case 0x02: function = parseDirectoryNameExtension; break; case 0x3F: function = parseCommentExtension; break; case 0x42: function = parseFileSizeExtension; break; case 0x50: function = parsePermissionsExtension; break; case 0x51: function = parseGIDUIDExtension; break; case 0x52: function = parseGroupExtension; break; case 0x53: function = parseOwnerExtension; break; case 0x54: function = parseModificationDateExtension; break; } if (function == NULL) return false; function(entry, extension, encoding); return true; } static size_t readExtensions(OFLHAArchiveEntry *entry, OFStream *stream, OFStringEncoding encoding, bool allowFileName) { size_t consumed = 0; for (;;) { uint32_t size; OFData *extension; if (entry->_headerLevel == 3) { size = [stream readLittleEndianInt32]; consumed += 4; } else { size = [stream readLittleEndianInt16]; consumed += 2; } if (size == 0) break; if (size < 2 || (entry->_headerLevel == 3 && size < 4)) @throw [OFInvalidFormatException exception]; extension = [stream readDataWithCount: size - (entry->_headerLevel == 3 ? 4 : 2)]; consumed += extension.count; if (!parseExtension(entry, extension, encoding, allowFileName)) [entry->_extensions addObject: extension]; if (entry->_headerLevel == 1) { if (entry->_compressedSize < size) @throw [OFInvalidFormatException exception]; entry->_compressedSize -= size; } } return consumed; } static void getFileNameAndDirectoryName(OFLHAArchiveEntry *entry, OFStringEncoding encoding, const char **fileName, size_t *fileNameLength, const char **directoryName, size_t *directoryNameLength) { OFMutableData *data; char *cString; size_t length; size_t pos; /* * We use OFMutableData to have an autoreleased buffer that we can * return indirectly. */ data = [OFMutableData dataWithItems: [entry->_directoryName cStringWithEncoding: encoding] count: [entry->_directoryName cStringLengthWithEncoding: encoding]]; [data addItems: [entry->_fileName cStringWithEncoding: encoding] count: [entry->_fileName cStringLengthWithEncoding: encoding]]; cString = data.mutableItems; length = data.count; pos = 0; for (size_t i = 0; i < length; i++) { if (cString[i] == '/' || cString[i] == '\\') { cString[i] = '\xFF'; pos = i + 1; } } *fileName = cString + pos; *fileNameLength = length - pos; *directoryName = cString; *directoryNameLength = pos; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)of_init { self = [super init]; @try { _compressionMethod = @"-lh0-"; _modificationDate = [[OFDate alloc] init]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)of_initWithHeader: (char [21])header stream: (OFStream *)stream encoding: (OFStringEncoding)encoding { self = [super init]; @try { uint32_t date; memcpy(&_compressedSize, header + 7, 4); _compressedSize = OFFromLittleEndian32((uint32_t)_compressedSize); memcpy(&_uncompressedSize, header + 11, 4); _uncompressedSize = OFFromLittleEndian32((uint32_t)_uncompressedSize); memcpy(&date, header + 15, 4); date = OFFromLittleEndian32(date); _headerLevel = header[20]; _extensions = [[OFMutableArray alloc] init]; switch (_headerLevel) { case 0: case 1:; void *pool = objc_autoreleasePoolPush(); uint8_t extendedAreaSize; uint8_t fileNameLength; OFString *tmp; if (header[0] < (21 - 2) + 1 + 2) @throw [OFInvalidFormatException exception]; _modificationDate = [parseMSDOSDate(date) retain]; fileNameLength = [stream readInt8]; tmp = [stream readStringWithLength: fileNameLength encoding: encoding]; tmp = [tmp stringByReplacingOccurrencesOfString: @"\\" withString: @"/"]; _fileName = [tmp copy]; _CRC16 = [stream readLittleEndianInt16]; extendedAreaSize = header[0] - (21 - 2) - 1 - fileNameLength - 2; if (_headerLevel == 1) { if (extendedAreaSize < 3) @throw [OFInvalidFormatException exception]; _operatingSystemIdentifier = [stream readInt8]; /* * 1 for the operating system identifier, 2 * because we don't want to skip the size of * the next extended header. */ extendedAreaSize -= 1 + 2; } /* Skip extended area */ if ([stream isKindOfClass: [OFSeekableStream class]]) [(OFSeekableStream *)stream seekToOffset: extendedAreaSize whence: OFSeekCurrent]; else { char buffer[256]; while (extendedAreaSize > 0) extendedAreaSize -= [stream readIntoBuffer: buffer length: extendedAreaSize]; } if (_headerLevel == 1) readExtensions(self, stream, encoding, false); objc_autoreleasePoolPop(pool); break; case 2: case 3:; uint32_t padding = 0; _modificationDate = [[OFDate alloc] initWithTimeIntervalSince1970: date]; _CRC16 = [stream readLittleEndianInt16]; _operatingSystemIdentifier = [stream readInt8]; if (_headerLevel == 3) /* Size of entire header */ padding = [stream readLittleEndianInt32]; else padding = (header[1] << 8) | header[0]; /* * 21 for header, 2 for CRC16, 1 for operating system * identifier. */ padding -= 21 + 2 + 1; padding -= readExtensions(self, stream, encoding, true); /* Skip padding */ if ([stream isKindOfClass: [OFSeekableStream class]]) [(OFSeekableStream *)stream seekToOffset: padding whence: OFSeekCurrent]; else { while (padding > 0) { char buffer[512]; size_t min = padding; if (min > 512) min = 512; padding -= [stream readIntoBuffer: buffer length: min]; } } break; default:; OFString *version = [OFString stringWithFormat: @"%u", _headerLevel]; @throw [OFUnsupportedVersionException exceptionWithVersion: version]; } if (_fileName == nil) @throw [OFInvalidFormatException exception]; _compressionMethod = [[OFString alloc] initWithCString: header + 2 encoding: OFStringEncodingASCII length: 5]; [_extensions makeImmutable]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_compressionMethod release]; [_fileName release]; [_directoryName release]; [_modificationDate release]; [_fileComment release]; [_POSIXPermissions release]; [_ownerAccountID release]; [_groupOwnerAccountID release]; [_ownerAccountName release]; [_groupOwnerAccountName release]; [_extensions release]; [super dealloc]; } - (id)copy { return [self retain]; } - (id)mutableCopy { OFLHAArchiveEntry *copy = [[OFMutableLHAArchiveEntry alloc] initWithFileName: _fileName]; @try { [copy->_compressionMethod release]; copy->_compressionMethod = nil; [copy->_modificationDate release]; copy->_modificationDate = nil; copy->_directoryName = [_directoryName copy]; copy->_compressionMethod = [_compressionMethod copy]; copy->_compressedSize = _compressedSize; copy->_uncompressedSize = _uncompressedSize; copy->_modificationDate = [_modificationDate copy]; copy->_headerLevel = _headerLevel; copy->_CRC16 = _CRC16; copy->_operatingSystemIdentifier = _operatingSystemIdentifier; copy->_fileComment = [_fileComment copy]; copy->_POSIXPermissions = [_POSIXPermissions retain]; copy->_ownerAccountID = [_ownerAccountID retain]; copy->_groupOwnerAccountID = [_groupOwnerAccountID retain]; copy->_ownerAccountName = [_ownerAccountName copy]; copy->_groupOwnerAccountName = [_groupOwnerAccountName copy]; copy->_extensions = [_extensions copy]; } @catch (id e) { [copy release]; @throw e; } return copy; } - (OFString *)fileName { if (_directoryName == nil) return _fileName; return [_directoryName stringByAppendingString: _fileName]; } - (OFString *)compressionMethod { return _compressionMethod; } - (unsigned long long)compressedSize { return _compressedSize; } - (unsigned long long)uncompressedSize { return _uncompressedSize; } - (OFDate *)modificationDate { return _modificationDate; } - (uint8_t)headerLevel { return _headerLevel; } - (uint16_t)CRC16 { return _CRC16; } - (uint8_t)operatingSystemIdentifier { return _operatingSystemIdentifier; } - (OFString *)fileComment { return _fileComment; } - (OFNumber *)POSIXPermissions { return _POSIXPermissions; } - (OFNumber *)ownerAccountID { return _ownerAccountID; } - (OFNumber *)groupOwnerAccountID { return _groupOwnerAccountID; } - (OFString *)ownerAccountName { return _ownerAccountName; } - (OFString *)groupOwnerAccountName { return _groupOwnerAccountName; } - (OFArray OF_GENERIC(OFData *) *)extensions { return _extensions; } - (void)of_writeToStream: (OFStream *)stream encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFMutableData *data = [OFMutableData dataWithCapacity: 24]; const char *fileName, *directoryName; size_t fileNameLength, directoryNameLength; uint16_t tmp16; uint32_t tmp32; uint64_t tmp64; size_t headerSize; if ([_compressionMethod cStringLengthWithEncoding: OFStringEncodingASCII] != 5) @throw [OFInvalidArgumentException exception]; getFileNameAndDirectoryName(self, encoding, &fileName, &fileNameLength, &directoryName, &directoryNameLength); if (fileNameLength > UINT16_MAX - 3 || directoryNameLength > UINT16_MAX - 3 || _compressedSize > UINT64_MAX || _uncompressedSize > UINT64_MAX) @throw [OFOutOfRangeException exception]; /* Length. Filled in after we're done. */ [data increaseCountBy: 2]; [data addItems: [_compressionMethod cStringWithEncoding: OFStringEncodingASCII] count: 5]; tmp32 = OFToLittleEndian32((uint32_t)_compressedSize); [data addItems: &tmp32 count: sizeof(tmp32)]; tmp32 = OFToLittleEndian32((uint32_t)_uncompressedSize); [data addItems: &tmp32 count: sizeof(tmp32)]; tmp32 = OFToLittleEndian32( (uint32_t)_modificationDate.timeIntervalSince1970); [data addItems: &tmp32 count: sizeof(tmp32)]; /* Reserved */ [data increaseCountBy: 1]; /* Header level */ [data addItem: "\x02"]; /* CRC16 */ tmp16 = OFToLittleEndian16(_CRC16); [data addItems: &tmp16 count: sizeof(tmp16)]; /* Operating system identifier */ [data addItem: "U"]; /* Common header. Contains CRC16, which is written at the end. */ tmp16 = OFToLittleEndian16(5); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItem: "\x00"]; [data increaseCountBy: 2]; tmp16 = OFToLittleEndian16((uint16_t)fileNameLength + 3); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItem: "\x01"]; [data addItems: fileName count: fileNameLength]; if (directoryNameLength > 0) { tmp16 = OFToLittleEndian16((uint16_t)directoryNameLength + 3); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItem: "\x02"]; [data addItems: directoryName count: directoryNameLength]; } if (_fileComment != nil) { size_t fileCommentLength = [_fileComment cStringLengthWithEncoding: encoding]; if (fileCommentLength > UINT16_MAX - 3) @throw [OFOutOfRangeException exception]; tmp16 = OFToLittleEndian16((uint16_t)fileCommentLength + 3); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItem: "\x3F"]; [data addItems: [_fileComment cStringWithEncoding: encoding] count: fileCommentLength]; } /* * Always include the file size extension, as the header can be written * with size 0 initially and then rewritten with the actual size in * case the data to be archived is being streamed - but for that we * need to make sure we always have the space. */ tmp16 = OFToLittleEndian16(19); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItem: "\x42"]; tmp64 = OFToLittleEndian64(_compressedSize); [data addItems: &tmp64 count: sizeof(tmp64)]; tmp64 = OFToLittleEndian64(_uncompressedSize); [data addItems: &tmp64 count: sizeof(tmp64)]; if (_POSIXPermissions != nil) { tmp16 = OFToLittleEndian16(5); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItem: "\x50"]; tmp16 = OFToLittleEndian16(_POSIXPermissions.unsignedShortValue); [data addItems: &tmp16 count: sizeof(tmp16)]; } if (_ownerAccountID != nil || _groupOwnerAccountID != nil) { if (_ownerAccountID == nil || _groupOwnerAccountID == nil) @throw [OFInvalidArgumentException exception]; tmp16 = OFToLittleEndian16(7); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItem: "\x51"]; tmp16 = OFToLittleEndian16( _groupOwnerAccountID.unsignedShortValue); [data addItems: &tmp16 count: sizeof(tmp16)]; tmp16 = OFToLittleEndian16(_ownerAccountID.unsignedShortValue); [data addItems: &tmp16 count: sizeof(tmp16)]; } if (_groupOwnerAccountName != nil) { size_t length = [_groupOwnerAccountName cStringLengthWithEncoding: encoding]; if (length > UINT16_MAX - 3) @throw [OFOutOfRangeException exception]; tmp16 = OFToLittleEndian16((uint16_t)length + 3); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItem: "\x52"]; [data addItems: [_groupOwnerAccountName cStringWithEncoding: encoding] count: length]; } if (_ownerAccountName != nil) { size_t length = [_ownerAccountName cStringLengthWithEncoding: encoding]; if (length > UINT16_MAX - 3) @throw [OFOutOfRangeException exception]; tmp16 = OFToLittleEndian16((uint16_t)length + 3); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItem: "\x53"]; [data addItems: [_ownerAccountName cStringWithEncoding: encoding] count: length]; } for (OFData *extension in _extensions) { size_t extensionLength = extension.count; if (extension.itemSize != 1) @throw [OFInvalidArgumentException exception]; if (extensionLength > UINT16_MAX - 2) @throw [OFOutOfRangeException exception]; tmp16 = OFToLittleEndian16((uint16_t)extensionLength + 2); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItems: extension.items count: extension.count]; } /* Zero-length extension to terminate */ [data increaseCountBy: 2]; /* * Some implementations only check the first byte to see if the end of * the archive has been reached, which is 0 for every multiple of 256. * Add one byte of padding to avoid this. */ if ((data.count & 0xFF) == 0) [data increaseCountBy: 1]; headerSize = data.count; if (headerSize > UINT16_MAX) @throw [OFOutOfRangeException exception]; /* Now fill in the size and CRC16 for the entire header */ tmp16 = OFToLittleEndian16(headerSize); memcpy([data mutableItemAtIndex: 0], &tmp16, sizeof(tmp16)); tmp16 = _OFCRC16(0, data.items, data.count); tmp16 = OFToLittleEndian16(tmp16); memcpy([data mutableItemAtIndex: 27], &tmp16, sizeof(tmp16)); [stream writeData: data]; objc_autoreleasePoolPop(pool); } - (OFString *)description { void *pool = objc_autoreleasePoolPush(); OFString *POSIXPermissions = nil; OFString *extensions = [_extensions.description stringByReplacingOccurrencesOfString: @"\n" withString: @"\n\t"]; OFString *ret; if (_POSIXPermissions != nil) POSIXPermissions = [OFString stringWithFormat: @"%ho", _POSIXPermissions.unsignedShortValue]; ret = [OFString stringWithFormat: @"<%@:\n" @"\tFile name = %@\n" @"\tCompression method = %@\n" @"\tCompressed size = %llu\n" @"\tUncompressed size = %llu\n" @"\tModification date = %@\n" @"\tHeader level = %u\n" @"\tCRC16 = %04" @PRIX16 @"\n" @"\tOperating system identifier = %c\n" @"\tComment = %@\n" @"\tPOSIX permissions = %@\n" @"\tOwner account ID = %@\n" @"\tGroup owner account ID = %@\n" @"\tOwner account name = %@\n" @"\tGroup owner accounut name = %@\n" @"\tExtensions: %@" @">", self.class, self.fileName, _compressionMethod, _compressedSize, _uncompressedSize, _modificationDate, _headerLevel, _CRC16, _operatingSystemIdentifier, _fileComment, POSIXPermissions, _ownerAccountID, _groupOwnerAccountID, _ownerAccountName, _groupOwnerAccountName, extensions]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @end objfw-1.1.6/src/OFLHADecompressingStream.h000066400000000000000000000034531465614216400203340ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFStream.h" #import "OFHuffmanTree.h" OF_ASSUME_NONNULL_BEGIN #define OFLHADecompressingStreamBufferSize 4096 OF_DIRECT_MEMBERS @interface OFLHADecompressingStream: OFStream { OFStream *_stream; uint8_t _distanceBits, _dictionaryBits; unsigned char _buffer[OFLHADecompressingStreamBufferSize]; uint32_t _bytesConsumed; uint16_t _bufferIndex, _bufferLength; uint8_t _byte; uint8_t _bitIndex, _savedBitsLength; uint16_t _savedBits; unsigned char *_slidingWindow; uint32_t _slidingWindowIndex, _slidingWindowMask; int _state; uint16_t _symbolsLeft; OFHuffmanTree _Nullable _codeLenTree; OFHuffmanTree _Nullable _litLenTree; OFHuffmanTree _Nullable _distTree; OFHuffmanTree _Nullable _treeIter; uint16_t _codesCount, _codesReceived; bool _currentIsExtendedLength, _skip; uint8_t *_Nullable _codesLengths; uint16_t _length; uint32_t _distance; } @property (readonly, nonatomic) uint32_t bytesConsumed; - (instancetype)of_initWithStream: (OFStream *)stream distanceBits: (uint8_t)distanceBits dictionaryBits: (uint8_t)dictionaryBits; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFLHADecompressingStream.m000066400000000000000000000302041465614216400203330ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFLHADecompressingStream.h" #import "OFKernelEventObserver.h" #import "OFHuffmanTree.h" #import "OFInvalidFormatException.h" #import "OFNotOpenException.h" enum State { stateBlockHeader, stateCodeLenCodesCount, stateCodeLenTree, stateCodeLenTreeSingle, stateLitLenCodesCount, stateLitLenTree, stateLitLenTreeSingle, stateDistCodesCount, stateDistTree, stateDistTreeSingle, stateBlockLitLen, stateBlockDistLength, stateBlockDistLengthExtra, stateBlockLenDistPair }; @implementation OFLHADecompressingStream @synthesize bytesConsumed = _bytesConsumed; static OF_INLINE bool tryReadBits(OFLHADecompressingStream *stream, uint16_t *bits, uint8_t count) { uint16_t ret = stream->_savedBits; OFAssert(stream->_savedBitsLength < count); for (uint_fast8_t i = stream->_savedBitsLength; i < count; i++) { if OF_UNLIKELY (stream->_bitIndex == 8) { if OF_LIKELY (stream->_bufferIndex < stream->_bufferLength) stream->_byte = stream->_buffer[stream->_bufferIndex++]; else { const size_t bufferLength = OFLHADecompressingStreamBufferSize; size_t length = [stream->_stream readIntoBuffer: stream->_buffer length: bufferLength]; stream->_bytesConsumed += (uint32_t)length; if OF_UNLIKELY (length < 1) { stream->_savedBits = ret; stream->_savedBitsLength = i; return false; } stream->_byte = stream->_buffer[0]; stream->_bufferIndex = 1; stream->_bufferLength = (uint16_t)length; } stream->_bitIndex = 0; } ret = (ret << 1) | ((stream->_byte >> (7 - stream->_bitIndex++)) & 1); } stream->_savedBits = 0; stream->_savedBitsLength = 0; *bits = ret; return true; } - (instancetype)of_initWithStream: (OFStream *)stream distanceBits: (uint8_t)distanceBits dictionaryBits: (uint8_t)dictionaryBits { self = [super init]; @try { _stream = [stream retain]; /* 0-7 address the bit, 8 means fetch next byte */ _bitIndex = 8; _distanceBits = distanceBits; _dictionaryBits = dictionaryBits; _slidingWindowMask = (1u << dictionaryBits) - 1; _slidingWindow = OFAllocMemory(_slidingWindowMask + 1, 1); memset(_slidingWindow, ' ', _slidingWindowMask + 1); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_stream != nil) [self close]; OFFreeMemory(_slidingWindow); if (_codeLenTree != NULL) _OFHuffmanTreeFree(_codeLenTree); if (_litLenTree != NULL) _OFHuffmanTreeFree(_litLenTree); if (_distTree != NULL) _OFHuffmanTreeFree(_distTree); OFFreeMemory(_codesLengths); [super dealloc]; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer_ length: (size_t)length { unsigned char *buffer = buffer_; uint16_t bits = 0, value = 0; size_t bytesWritten = 0; if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (_stream.atEndOfStream && _bufferLength - _bufferIndex == 0 && _state == stateBlockHeader) return 0; start: switch ((enum State)_state) { case stateBlockHeader: if OF_UNLIKELY (!tryReadBits(self, &bits, 16)) return bytesWritten; _symbolsLeft = bits; _state = stateCodeLenCodesCount; goto start; case stateCodeLenCodesCount: if OF_UNLIKELY (!tryReadBits(self, &bits, 5)) return bytesWritten; if OF_UNLIKELY (bits > 20) @throw [OFInvalidFormatException exception]; if OF_UNLIKELY (bits == 0) { _state = stateCodeLenTreeSingle; goto start; } _codesCount = bits; _codesReceived = 0; _codesLengths = OFAllocZeroedMemory(bits, 1); _skip = true; _state = stateCodeLenTree; goto start; case stateCodeLenTree: while (_codesReceived < _codesCount) { if OF_UNLIKELY (_currentIsExtendedLength) { if OF_UNLIKELY (!tryReadBits(self, &bits, 1)) return bytesWritten; if OF_UNLIKELY (bits == 0) { _codesReceived++; _currentIsExtendedLength = false; continue; } _codesLengths[_codesReceived]++; continue; } if OF_UNLIKELY (_codesReceived == 3 && _skip) { if OF_UNLIKELY (!tryReadBits(self, &bits, 2)) return bytesWritten; if OF_UNLIKELY (_codesReceived + bits > _codesCount) @throw [OFInvalidFormatException exception]; for (uint_fast8_t j = 0; j < bits; j++) _codesLengths[_codesReceived++] = 0; _skip = false; continue; } if OF_UNLIKELY (!tryReadBits(self, &bits, 3)) return bytesWritten; _codesLengths[_codesReceived] = bits; if OF_UNLIKELY (bits == 7) { _currentIsExtendedLength = true; continue; } else _codesReceived++; } _codeLenTree = _OFHuffmanTreeNew(_codesLengths, _codesCount); OFFreeMemory(_codesLengths); _codesLengths = NULL; _state = stateLitLenCodesCount; goto start; case stateCodeLenTreeSingle: if OF_UNLIKELY (!tryReadBits(self, &bits, 5)) return bytesWritten; _codeLenTree = _OFHuffmanTreeNewSingle(bits); _state = stateLitLenCodesCount; goto start; case stateLitLenCodesCount: if OF_UNLIKELY (!tryReadBits(self, &bits, 9)) return bytesWritten; if OF_UNLIKELY (bits > 510) @throw [OFInvalidFormatException exception]; if OF_UNLIKELY (bits == 0) { _OFHuffmanTreeFree(_codeLenTree); _codeLenTree = NULL; _state = stateLitLenTreeSingle; goto start; } _codesCount = bits; _codesReceived = 0; _codesLengths = OFAllocZeroedMemory(bits, 1); _skip = false; _treeIter = _codeLenTree; _state = stateLitLenTree; goto start; case stateLitLenTree: while (_codesReceived < _codesCount) { if OF_UNLIKELY (_skip) { uint16_t skipCount; switch (_codesLengths[_codesReceived]) { case 0: skipCount = 1; break; case 1: if OF_UNLIKELY (!tryReadBits(self, &bits, 4)) return bytesWritten; skipCount = bits + 3; break; case 2: if OF_UNLIKELY (!tryReadBits(self, &bits, 9)) return bytesWritten; skipCount = bits + 20; break; default: OFEnsure(0); } if OF_UNLIKELY (_codesReceived + skipCount > _codesCount) @throw [OFInvalidFormatException exception]; for (uint_fast16_t j = 0; j < skipCount; j++) _codesLengths[_codesReceived++] = 0; _skip = false; continue; } if (!_OFHuffmanTreeWalk(self, tryReadBits, &_treeIter, &value)) return bytesWritten; _treeIter = _codeLenTree; if (value < 3) { _codesLengths[_codesReceived] = value; _skip = true; } else _codesLengths[_codesReceived++] = value - 2; } _litLenTree = _OFHuffmanTreeNew(_codesLengths, _codesCount); OFFreeMemory(_codesLengths); _codesLengths = NULL; _OFHuffmanTreeFree(_codeLenTree); _codeLenTree = NULL; _state = stateDistCodesCount; goto start; case stateLitLenTreeSingle: if OF_UNLIKELY (!tryReadBits(self, &bits, 9)) return bytesWritten; _litLenTree = _OFHuffmanTreeNewSingle(bits); _state = stateDistCodesCount; goto start; case stateDistCodesCount: if OF_UNLIKELY (!tryReadBits(self, &bits, _distanceBits)) return bytesWritten; if OF_UNLIKELY (bits > _dictionaryBits) @throw [OFInvalidFormatException exception]; if OF_UNLIKELY (bits == 0) { _state = stateDistTreeSingle; goto start; } _codesCount = bits; _codesReceived = 0; _codesLengths = OFAllocZeroedMemory(bits, 1); _treeIter = _codeLenTree; _state = stateDistTree; goto start; case stateDistTree: while (_codesReceived < _codesCount) { if OF_UNLIKELY (_currentIsExtendedLength) { if OF_UNLIKELY (!tryReadBits(self, &bits, 1)) return bytesWritten; if OF_UNLIKELY (bits == 0) { _codesReceived++; _currentIsExtendedLength = false; continue; } _codesLengths[_codesReceived]++; continue; } if OF_UNLIKELY (!tryReadBits(self, &bits, 3)) return bytesWritten; _codesLengths[_codesReceived] = bits; if OF_UNLIKELY (bits == 7) { _currentIsExtendedLength = true; continue; } else _codesReceived++; } _distTree = _OFHuffmanTreeNew(_codesLengths, _codesCount); OFFreeMemory(_codesLengths); _codesLengths = NULL; _treeIter = _litLenTree; _state = stateBlockLitLen; goto start; case stateDistTreeSingle: if OF_UNLIKELY (!tryReadBits(self, &bits, _distanceBits)) return bytesWritten; _distTree = _OFHuffmanTreeNewSingle(bits); _treeIter = _litLenTree; _state = stateBlockLitLen; goto start; case stateBlockLitLen: if OF_UNLIKELY (_symbolsLeft == 0) { _OFHuffmanTreeFree(_litLenTree); _OFHuffmanTreeFree(_distTree); _litLenTree = _distTree = NULL; _state = stateBlockHeader; /* * We must return here, as there is no indication * whether this was the last block. Whoever called this * method needs to check if everything has been read * already and only call read again if that is not the * case. * * We must also unread the buffer, in case this was the * last block and something else follows, e.g. another * LHA header. */ [_stream unreadFromBuffer: _buffer + _bufferIndex length: _bufferLength - _bufferIndex]; _bytesConsumed -= _bufferLength - _bufferIndex; _bufferIndex = _bufferLength = 0; return bytesWritten; } if OF_UNLIKELY (length == 0) return bytesWritten; if OF_UNLIKELY (!_OFHuffmanTreeWalk(self, tryReadBits, &_treeIter, &value)) return bytesWritten; if OF_LIKELY (value < 256) { buffer[bytesWritten++] = value; length--; _slidingWindow[_slidingWindowIndex] = value; _slidingWindowIndex = (_slidingWindowIndex + 1) & _slidingWindowMask; _symbolsLeft--; _treeIter = _litLenTree; } else { _length = value - 253; _treeIter = _distTree; _state = stateBlockDistLength; } goto start; case stateBlockDistLength: if OF_UNLIKELY (!_OFHuffmanTreeWalk(self, tryReadBits, &_treeIter, &value)) return bytesWritten; _distance = value; _state = (value < 2 ? stateBlockLenDistPair : stateBlockDistLengthExtra); goto start; case stateBlockDistLengthExtra: if OF_UNLIKELY (!tryReadBits(self, &bits, _distance - 1)) return bytesWritten; _distance = bits + (1u << (_distance - 1)); _state = stateBlockLenDistPair; goto start; case stateBlockLenDistPair: for (uint_fast16_t i = 0; i < _length; i++) { uint32_t idx; if OF_UNLIKELY (length == 0) { _length -= i; return bytesWritten; } idx = (_slidingWindowIndex - _distance - 1) & _slidingWindowMask; value = _slidingWindow[idx]; buffer[bytesWritten++] = value; length--; _slidingWindow[_slidingWindowIndex] = value; _slidingWindowIndex = (_slidingWindowIndex + 1) & _slidingWindowMask; } _symbolsLeft--; _treeIter = _litLenTree; _state = stateBlockLitLen; goto start; } OF_UNREACHABLE } - (bool)lowlevelIsAtEndOfStream { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; return (_stream.atEndOfStream && _bufferLength - _bufferIndex == 0 && _state == stateBlockHeader); } - (int)fileDescriptorForReading { return ((id )_stream) .fileDescriptorForReading; } - (bool)lowlevelHasDataInReadBuffer { return (_stream.hasDataInReadBuffer || _bufferLength - _bufferIndex > 0); } - (void)close { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; /* Give back our buffer to the stream, in case it's shared */ [_stream unreadFromBuffer: _buffer + _bufferIndex length: _bufferLength - _bufferIndex]; _bytesConsumed -= _bufferLength - _bufferIndex; _bufferIndex = _bufferLength = 0; [_stream release]; _stream = nil; [super close]; } @end objfw-1.1.6/src/OFLOCDNSResourceRecord.h000066400000000000000000000066031465614216400176620ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFDNSResourceRecord.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFLOCDNSResourceRecord \ * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h * * @brief A class representing an LOC DNS resource record. */ OF_SUBCLASSING_RESTRICTED @interface OFLOCDNSResourceRecord: OFDNSResourceRecord { uint8_t _size, _horizontalPrecision, _verticalPrecision; uint32_t _latitude, _longitude, _altitude; } /** * @brief The diameter in centimeters of a sphere enclosing the position, * encoded as per RFC 1876. */ @property (readonly, nonatomic) uint8_t size; /** * @brief The horizontal precision in centimeters, encoded as per RFC 1876. */ @property (readonly, nonatomic) uint8_t horizontalPrecision; /** * @brief The vertical precision in centimeters, encoded as per RFC 1876. */ @property (readonly, nonatomic) uint8_t verticalPrecision; /** * @brief The latitude in thousands of a second of an arc. */ @property (readonly, nonatomic) uint32_t latitude; /** * @brief The longitude in thousands of a second of an arc. */ @property (readonly, nonatomic) uint32_t longitude; /** * @brief The altitude in centimeters from a base of 100000 meters below the * GPS reference. */ @property (readonly, nonatomic) uint32_t altitude; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFLOCDNSResourceRecord with the * specified name, class, domain name and time to live. * * @param name The name for the resource record * @param DNSClass The class code for the resource record * @param size The diameter in centimeters of a sphere enclosing the position, * encoded as per RFC 1876 * @param horizontalPrecision The horizontal precision in centimeters, encoded * as per RFC 1876 * @param verticalPrecision The vertical precision in centimeters, encoded as * per RFC 1876 * @param latitude The latitude in thousands of a second of an arc * @param longitude The longitude in thousands of a second of an arc * @param altitude The altitude in centimeters from a base of 100000 meters * below the GPS reference * @param TTL The time to live for the resource record * @return An initialized OFLOCDNSResourceRecord */ - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass size: (uint8_t)size horizontalPrecision: (uint8_t)horizontalPrecision verticalPrecision: (uint8_t)verticalPrecision latitude: (uint32_t)latitude longitude: (uint32_t)longitude altitude: (uint32_t)altitude TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFLOCDNSResourceRecord.m000066400000000000000000000102561465614216400176660ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFLOCDNSResourceRecord.h" @implementation OFLOCDNSResourceRecord @synthesize size = _size, horizontalPrecision = _horizontalPrecision; @synthesize verticalPrecision = _verticalPrecision, latitude = _latitude; @synthesize longitude = _longitude, altitude = _altitude; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass size: (uint8_t)size horizontalPrecision: (uint8_t)horizontalPrecision verticalPrecision: (uint8_t)verticalPrecision latitude: (uint32_t)latitude longitude: (uint32_t)longitude altitude: (uint32_t)altitude TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: DNSClass recordType: OFDNSRecordTypeLOC TTL: TTL]; @try { _size = size; _horizontalPrecision = horizontalPrecision; _verticalPrecision = verticalPrecision; _latitude = latitude; _longitude = longitude; _altitude = altitude; } @catch (id e) { [self release]; @throw e; } return self; } - (bool)isEqual: (id)object { OFLOCDNSResourceRecord *record; if (object == self) return true; if (![object isKindOfClass: [OFLOCDNSResourceRecord class]]) return false; record = object; if (record->_name != _name && ![record->_name isEqual: _name]) return false; if (record->_DNSClass != _DNSClass) return false; if (record->_recordType != _recordType) return false; if (record->_size != _size) return false; if (record->_horizontalPrecision != _horizontalPrecision) return false; if (record->_verticalPrecision != _verticalPrecision) return false; if (record->_latitude != _latitude) return false; if (record->_longitude != _longitude) return false; if (record->_altitude != _altitude) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddByte(&hash, _DNSClass >> 8); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType >> 8); OFHashAddByte(&hash, _recordType); OFHashAddByte(&hash, _size); OFHashAddByte(&hash, _horizontalPrecision); OFHashAddByte(&hash, _verticalPrecision); OFHashAddByte(&hash, _latitude >> 24); OFHashAddByte(&hash, _latitude >> 16); OFHashAddByte(&hash, _latitude >> 8); OFHashAddByte(&hash, _latitude); OFHashAddByte(&hash, _longitude >> 24); OFHashAddByte(&hash, _longitude >> 16); OFHashAddByte(&hash, _longitude >> 8); OFHashAddByte(&hash, _longitude); OFHashAddByte(&hash, _altitude >> 24); OFHashAddByte(&hash, _altitude >> 16); OFHashAddByte(&hash, _altitude >> 8); OFHashAddByte(&hash, _altitude); OFHashFinalize(&hash); return hash; } - (OFString *)description { return [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tClass = %@\n" @"\tSize = %ue%u\n" @"\tHorizontal precision = %ue%u\n" @"\tVertical precision = %ue%u\n" @"\tLatitude = %f\n" @"\tLongitude = %f\n" @"\tAltitude = %f\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFDNSClassName(_DNSClass), _size >> 4, _size & 0xF, _horizontalPrecision >> 4, _horizontalPrecision & 0xF, _verticalPrecision >> 4, _verticalPrecision & 0xF, ((double)_latitude - 2147483648) / 3600000, ((double)_longitude - 2147483648) / 3600000, ((double)_altitude - 10000000) / 100, _TTL]; } @end objfw-1.1.6/src/OFList.h000066400000000000000000000137211465614216400147430ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFCollection.h" #import "OFEnumerator.h" OF_ASSUME_NONNULL_BEGIN /** @file */ /* * Make clang's -Wdocumentation shut up about about using @struct on something * it thinks is not a struct. Doxygen requires it this way. */ #ifdef __clang__ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wdocumentation" #endif /** * @struct OFListItem OFList.h ObjFW/OFList.h * * @brief A list item. * * See @ref OFListItemNext, @ref OFListItemPrevious and @ref OFListItemObject. */ typedef struct _OFListItem *OFListItem; #ifdef __clang__ # pragma clang diagnostic pop #endif #ifdef __cplusplus extern "C" { #endif /*! * @brief Returns the next list item of the list item. * * @param listItem The list item for which the next list item should be returned * @return The next list item of the list item */ extern OFListItem _Nullable OFListItemNext(OFListItem _Nonnull listItem); /*! * @brief Returns the previous list item of the list item. * * @param listItem The list item for which the previous list item should be * returned * @return The previous list item of the list item */ extern OFListItem _Nullable OFListItemPrevious(OFListItem _Nonnull listItem); /*! * @brief Returns the object of the list item. * * @warning The returned object is not retained and autoreleased - this is the * caller's responsibility! * * @param listItem The list item for which the object should be returned * @return The object of the list item */ extern id _Nonnull OFListItemObject(OFListItem _Nonnull listItem); #ifdef __cplusplus } #endif /** * @class OFList OFList.h ObjFW/OFList.h * * @brief A class which provides easy to use double-linked lists. */ @interface OFList OF_GENERIC(ObjectType): OFObject #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # define ObjectType id #endif { OFListItem _Nullable _firstListItem; OFListItem _Nullable _lastListItem; size_t _count; unsigned long _mutations; OF_RESERVE_IVARS(OFList, 4) } /** * @brief The first list object of the list. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFListItem firstListItem; /** * @brief The first object of the list or `nil`. * * @warning The returned object is *not* retained and autoreleased for * performance reasons! */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) ObjectType firstObject; /** * @brief The last list object of the list. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFListItem lastListItem; /** * @brief The last object of the list or `nil`. * * @warning The returned object is *not* retained and autoreleased for * performance reasons! */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) ObjectType lastObject; /** * @brief Creates a new OFList. * * @return A new autoreleased OFList */ + (instancetype)list; /** * @brief Appends an object to the list. * * @param object The object to append * @return An OFListItem, needed to identify the object inside the list. * For example, if you want to remove an object from the list, you need * its OFListItem. */ - (OFListItem)appendObject: (ObjectType)object; /** * @brief Prepends an object to the list. * * @param object The object to prepend * @return An OFListItem, needed to identify the object inside the list. * For example, if you want to remove an object from the list, you need * its OFListItem. */ - (OFListItem)prependObject: (ObjectType)object; /** * @brief Inserts an object before another list object. * * @param object The object to insert * @param listItem The OFListItem of the object before which it should be * inserted * @return An OFListItem, needed to identify the object inside the list. * For example, if you want to remove an object from the list, you need * its OFListItem. */ - (OFListItem)insertObject: (ObjectType)object beforeListItem: (OFListItem)listItem; /** * @brief Inserts an object after another list object. * * @param object The object to insert * @param listItem The OFListItem of the object after which it should be * inserted * @return An OFListItem, needed to identify the object inside the list. * For example, if you want to remove an object from the list, you need * its OFListItem. */ - (OFListItem)insertObject: (ObjectType)object afterListItem: (OFListItem)listItem; /** * @brief Removes the object with the specified list object from the list. * * @param listItem The list object returned by append / prepend */ - (void)removeListItem: (OFListItem)listItem; /** * @brief Checks whether the list contains an object equal to the specified * object. * * @param object The object which is checked for being in the list * @return A boolean whether the list contains the specified object */ - (bool)containsObject: (ObjectType)object; /** * @brief Checks whether the list contains an object with the specified address. * * @param object The object which is checked for being in the list * @return A boolean whether the list contains an object with the specified * address */ - (bool)containsObjectIdenticalTo: (ObjectType)object; /** * @brief Removes all objects from the list. */ - (void)removeAllObjects; #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # undef ObjectType #endif @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFList.m000066400000000000000000000200751465614216400147500ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFList.h" #import "OFString.h" #import "OFArray.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" struct _OFListItem { struct _OFListItem *previous, *next; id object; }; OF_DIRECT_MEMBERS @interface OFListEnumerator: OFEnumerator { OFList *_list; OFListItem _Nullable _current; unsigned long _mutations; unsigned long *_Nullable _mutationsPtr; } - (instancetype)initWithList: (OFList *)list mutationsPointer: (unsigned long *)mutationsPtr; @end OFListItem OFListItemNext(OFListItem listItem) { return listItem->next; } OFListItem OFListItemPrevious(OFListItem listItem) { return listItem->previous; } id OFListItemObject(OFListItem listItem) { return listItem->object; } @implementation OFList @synthesize firstListItem = _firstListItem, lastListItem = _lastListItem; + (instancetype)list { return [[[self alloc] init] autorelease]; } - (void)dealloc { OFListItem next; for (OFListItem iter = _firstListItem; iter != NULL; iter = next) { [iter->object release]; next = iter->next; OFFreeMemory(iter); } [super dealloc]; } - (OFListItem)appendObject: (id)object { OFListItem listItem = OFAllocMemory(1, sizeof(*listItem)); listItem->object = [object retain]; listItem->next = NULL; listItem->previous = _lastListItem; if (_lastListItem != NULL) _lastListItem->next = listItem; _lastListItem = listItem; if (_firstListItem == NULL) _firstListItem = listItem; _count++; _mutations++; return listItem; } - (OFListItem)prependObject: (id)object { OFListItem listItem = OFAllocMemory(1, sizeof(*listItem)); listItem->object = [object retain]; listItem->next = _firstListItem; listItem->previous = NULL; if (_firstListItem != NULL) _firstListItem->previous = listItem; _firstListItem = listItem; if (_lastListItem == NULL) _lastListItem = listItem; _count++; _mutations++; return listItem; } - (OFListItem)insertObject: (id)object beforeListItem: (OFListItem)listItem { OFListItem newListItem = OFAllocMemory(1, sizeof(*newListItem)); newListItem->object = [object retain]; newListItem->next = listItem; newListItem->previous = listItem->previous; if (listItem->previous != NULL) listItem->previous->next = newListItem; listItem->previous = newListItem; if (listItem == _firstListItem) _firstListItem = newListItem; _count++; _mutations++; return newListItem; } - (OFListItem)insertObject: (id)object afterListItem: (OFListItem)listItem { OFListItem newListItem = OFAllocMemory(1, sizeof(*newListItem)); newListItem->object = [object retain]; newListItem->next = listItem->next; newListItem->previous = listItem; if (listItem->next != NULL) listItem->next->previous = newListItem; listItem->next = newListItem; if (listItem == _lastListItem) _lastListItem = newListItem; _count++; _mutations++; return newListItem; } - (void)removeListItem: (OFListItem)listItem { if (listItem->previous != NULL) listItem->previous->next = listItem->next; if (listItem->next != NULL) listItem->next->previous = listItem->previous; if (_firstListItem == listItem) _firstListItem = listItem->next; if (_lastListItem == listItem) _lastListItem = listItem->previous; _count--; _mutations++; [listItem->object release]; OFFreeMemory(listItem); } - (id)firstObject { return (_firstListItem != NULL ? _firstListItem->object : nil); } - (id)lastObject { return (_lastListItem != NULL ? _lastListItem->object : nil); } - (size_t)count { return _count; } - (bool)isEqual: (id)object { OFList *list; OFListItem iter, iter2; if (object == self) return true; if (![object isKindOfClass: [OFList class]]) return false; list = object; if (list.count != _count) return false; for (iter = _firstListItem, iter2 = list.firstListItem; iter != NULL && iter2 != NULL; iter = iter->next, iter2 = iter2->next) if (![iter->object isEqual: iter2->object]) return false; /* One is bigger than the other even though we checked the count */ OFAssert(iter == NULL && iter2 == NULL); return true; } - (bool)containsObject: (id)object { if (_count == 0) return false; for (OFListItem iter = _firstListItem; iter != NULL; iter = iter->next) if ([iter->object isEqual: object]) return true; return false; } - (bool)containsObjectIdenticalTo: (id)object { if (_count == 0) return false; for (OFListItem iter = _firstListItem; iter != NULL; iter = iter->next) if (iter->object == object) return true; return false; } - (void)removeAllObjects { OFListItem next; _mutations++; for (OFListItem iter = _firstListItem; iter != NULL; iter = next) { [iter->object release]; next = iter->next; OFFreeMemory(iter); } _firstListItem = _lastListItem = NULL; } - (id)copy { OFList *copy = [[[self class] alloc] init]; OFListItem listItem = NULL, previous = NULL; @try { for (OFListItem iter = _firstListItem; iter != NULL; iter = iter->next) { listItem = OFAllocMemory(1, sizeof(*listItem)); listItem->object = [iter->object retain]; listItem->next = NULL; listItem->previous = previous; if (copy->_firstListItem == NULL) copy->_firstListItem = listItem; if (previous != NULL) previous->next = listItem; copy->_count++; previous = listItem; } } @catch (id e) { [copy release]; @throw e; } copy->_lastListItem = listItem; return copy; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); for (OFListItem iter = _firstListItem; iter != NULL; iter = iter->next) OFHashAddHash(&hash, [iter->object hash]); OFHashFinalize(&hash); return hash; } - (OFString *)description { OFMutableString *ret; if (_count == 0) return @"[]"; ret = [OFMutableString stringWithString: @"[\n"]; for (OFListItem iter = _firstListItem; iter != NULL; iter = iter->next) { void *pool = objc_autoreleasePoolPush(); [ret appendString: [iter->object description]]; if (iter->next != NULL) [ret appendString: @",\n"]; objc_autoreleasePoolPop(pool); } [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @"\n]"]; [ret makeImmutable]; return ret; } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count { OFListItem listItem; memcpy(&listItem, state->extra, sizeof(listItem)); state->itemsPtr = objects; state->mutationsPtr = &_mutations; if (state->state == 0) { listItem = _firstListItem; state->state = 1; } for (int i = 0; i < count; i++) { if (listItem == NULL) return i; objects[i] = listItem->object; listItem = listItem->next; } memcpy(state->extra, &listItem, sizeof(listItem)); return count; } - (OFEnumerator *)objectEnumerator { return [[[OFListEnumerator alloc] initWithList: self mutationsPointer: &_mutations] autorelease]; } @end @implementation OFListEnumerator - (instancetype)initWithList: (OFList *)list mutationsPointer: (unsigned long *)mutationsPtr { self = [super init]; _list = [list retain]; _current = _list.firstListItem; _mutations = *mutationsPtr; _mutationsPtr = mutationsPtr; return self; } - (void)dealloc { [_list release]; [super dealloc]; } - (id)nextObject { id ret; if (*_mutationsPtr != _mutations) @throw [OFEnumerationMutationException exceptionWithObject: _list]; if (_current == NULL) return nil; ret = _current->object; _current = _current->next; return ret; } @end objfw-1.1.6/src/OFLocale.h000066400000000000000000000155731465614216400152360ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @class OFIRI; /** @file */ /** * @def OF_LOCALIZED * * @brief Returns the localized string for the specified ID with the specified * arguments inserted. * * @param ID The ID of the localized string to retrieve * @return The localized string with the specified arguments replaced * @throw OFInvalidFormatException The string (either the fallback or the * localized one) contains an invalid format */ #define OF_LOCALIZED(ID, ...) \ [[OFLocale currentLocale] localizedStringForID: ID \ fallback: __VA_ARGS__, nil] @class OFMutableArray OF_GENERIC(ObjectType); @class OFDictionary OF_GENERIC(KeyType, ObjectType); /** * @class OFLocale OFLocale.h ObjFW/OFLocale.h * * @brief A class for querying the locale and retrieving localized strings. */ OF_SUBCLASSING_RESTRICTED @interface OFLocale: OFObject { OFString *_Nullable _languageCode, *_Nullable _countryCode; OFStringEncoding _encoding; OFString *_decimalSeparator; OFMutableArray OF_GENERIC(OFDictionary OF_GENERIC(OFString *, id) *) *_localizedStrings; } #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nullable, nonatomic) OFLocale *currentLocale; @property (class, readonly, nullable, nonatomic) OFString *languageCode; @property (class, readonly, nullable, nonatomic) OFString *countryCode; @property (class, readonly, nonatomic) OFStringEncoding encoding; @property (class, readonly, nullable, nonatomic) OFString *decimalSeparator; #endif /** * @brief The language code of the locale for messages. * * If the language is unknown, it is `nil`. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *languageCode; /** * @brief The country code of the locale for messages. * * If the territory is unknown, it is `nil`. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *countryCode; /** * @brief The native 8-bit string encoding of the locale for messages. * * This is useful to encode strings correctly for passing them to operating * system calls. * * If the native 8-bit encoding is unknown, UTF-8 is assumed. */ @property (readonly, nonatomic) OFStringEncoding encoding; /** * @brief The decimal separator of the locale. */ @property (readonly, nonatomic) OFString *decimalSeparator; /** * @brief Returns the current OFLocale. * * @note If you don't use @ref OFApplication, you need to call this as early as * possible to initialize the locale! * * @return The current OFLocale instance */ + (nullable OFLocale *)currentLocale; /** * @brief Returns the language code of the locale. * * If the language is unknown, `nil` is returned. * * @return The language code of the locale. */ + (nullable OFString *)languageCode; /** * @brief Returns the country code of the locale. * * If the country is unknown, `nil` is returned. * * @return The country code of the locale. */ + (nullable OFString *)countryCode; /** * @brief Returns the native 8-bit string encoding for the locale. * * This is useful to encode strings correctly for passing them to operating * system calls. * * If the native 8-bit encoding is unknown, UTF-8 is assumed. * * @return The native 8-bit string encoding for the locale */ + (OFStringEncoding)encoding; /** * @brief Returns the decimal point of the system's locale. * * @return The decimal point of the system's locale */ + (nullable OFString *)decimalSeparator; /** * @brief Adds a directory to scan for localizations. * * @param IRI The IRI to the directory to scan for localizations */ + (void)addLocalizationDirectoryIRI: (OFIRI *)IRI; - (instancetype)init OF_DEPRECATED(ObjFW, 1, 1, "Manually creating an OFLocale " "is no longer necessary. Use +[OFLocale currentLocale] instead."); /** * @brief Adds a directory to scan for localizations. * * @param IRI The IRI to the directory to scan for localizations */ - (void)addLocalizationDirectoryIRI: (OFIRI *)IRI; /** * @brief Returns the localized string for the specified ID, using the fallback * string if it cannot be looked up or is missing. * * @note This takes a variadic argument, terminated by `nil`, that consists of * pairs of variable names and variable values, which will be replaced * inside the localized string. For example, you can pass * `@"name", @"foo", nil`, causing `%[name]` to be replaced with `foo` in * the localized string. * * @note Generally, you want to use @ref OF_LOCALIZED instead, which also takes * care of the `nil` sentinel automatically. * * @param ID The ID for the localized string * @param fallback The fallback to use in case the localized string cannot be * looked up or is missing. This can also be an array and use * plural scripting, just like with the JSON localization files. * @return The localized string */ - (OFString *)localizedStringForID: (OFConstantString *)ID fallback: (id)fallback, ... OF_SENTINEL; /** * @brief Returns the localized string for the specified ID, using the fallback * string if it cannot be looked up or is missing. * * @note This takes a variadic argument, terminated by `nil` and passed as * va_list, that consists of pairs of variable names and variable values, * which will be replaced inside the localized string. For example, you * can pass `@"name", @"foo", nil`, causing `%[name]` to be replaced with * `foo` in the localized string. * * @note Generally, you want to use @ref OF_LOCALIZED instead, which also takes * care of the `nil` sentinel automatically. * * @param ID The ID for the localized string * @param fallback The fallback to use in case the localized string cannot be * looked up or is missing. This can also be an array and use * plural scripting, just like with the JSON localization files. * @param arguments A va_list of arguments, consisting of pairs of variable * names and values to replace in the localized string, * terminated with `nil` * @return The localized string * @throw OFInvalidFormatException The string (either the fallback or the * localized one) contains an invalid format */ - (OFString *)localizedStringForID: (OFConstantString *)ID fallback: (id)fallback arguments: (va_list)arguments; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFLocale.m000066400000000000000000000403401465614216400152310ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFLocale.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFIRI.h" #import "OFNumber.h" #import "OFString.h" #import "OFOnce.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOpenItemFailedException.h" #ifdef OF_AMIGAOS # define Class IntuitionClass # include # include # include # undef Class #endif @interface OFLocale () - (instancetype)of_init OF_METHOD_FAMILY(init); @end static OFOnceControl initLocaleControl = OFOnceControlInitValue; static OFLocale *currentLocale = nil; static OFDictionary *operatorPrecedences = nil; static void initLocale(void) { currentLocale = [[OFLocale alloc] of_init]; } #ifndef OF_AMIGAOS static void parseLocale(char *locale, OFStringEncoding *encoding, OFString **languageCode, OFString **countryCode) { locale = _OFStrDup(locale); @try { OFStringEncoding enc = OFStringEncodingASCII; char *tmp; /* We don't care for extras behind the @ */ if ((tmp = strrchr(locale, '@')) != NULL) *tmp = '\0'; /* Encoding */ if ((tmp = strrchr(locale, '.')) != NULL) { *tmp++ = '\0'; @try { if (encoding != NULL) *encoding = OFStringEncodingParseName( [OFString stringWithCString: tmp encoding: enc]); } @catch (OFInvalidArgumentException *e) { } } /* Country code */ if ((tmp = strrchr(locale, '_')) != NULL) { *tmp++ = '\0'; if (countryCode != NULL) *countryCode = [OFString stringWithCString: tmp encoding: enc]; } if (languageCode != NULL) *languageCode = [OFString stringWithCString: locale encoding: enc]; } @finally { OFFreeMemory(locale); } } #endif static bool evaluateCondition(OFString *condition_, OFDictionary *variables) { OFMutableString *condition = [[condition_ mutableCopy] autorelease]; OFMutableArray *tokens, *operators, *stack; /* Empty condition is the fallback that's always true */ if (condition.length == 0) return true; /* * Dirty hack to allow not needing spaces after "!" or "(" and spaces * before ")". * TODO: Replace with a proper tokenizer. */ [condition replaceOccurrencesOfString: @"!" withString: @"! "]; [condition replaceOccurrencesOfString: @"(" withString: @"( "]; [condition replaceOccurrencesOfString: @")" withString: @" )"]; /* Substitute variables and convert to RPN first */ tokens = [OFMutableArray array]; operators = [OFMutableArray array]; for (OFString *token in [condition componentsSeparatedByString: @" " options: OFStringSkipEmptyComponents]) { unsigned precedence; OFUnichar c; if ([token isEqual: @"("]) { [operators addObject: @"("]; continue; } if ([token isEqual: @")"]) { for (;;) { OFString *operator = operators.lastObject; if (operator == nil) @throw [OFInvalidFormatException exception]; if ([operator isEqual: @"("]) { [operators removeLastObject]; break; } [tokens addObject: operator]; [operators removeLastObject]; } continue; } precedence = [[operatorPrecedences objectForKey: token] unsignedIntValue]; if (precedence > 0) { for (;;) { OFNumber *operator = operators.lastObject; unsigned otherPrecedence; if (operator == nil || [operator isEqual: @"("]) break; otherPrecedence = [[operatorPrecedences objectForKey: operator] unsignedIntValue]; if (otherPrecedence >= precedence) break; [tokens addObject: operator]; [operators removeLastObject]; } [operators addObject: token]; continue; } c = [token characterAtIndex: 0]; if ((c < '0' || c > '9') && c != '-') if ((token = [variables objectForKey: token]) == nil) @throw [OFInvalidFormatException exception]; [tokens addObject: [OFNumber numberWithDouble: token.doubleValue]]; } for (size_t i = operators.count; i > 0; i--) { OFString *operator = [operators objectAtIndex: i - 1]; if ([operator isEqual: @"("]) @throw [OFInvalidFormatException exception]; [tokens addObject: operator]; } /* Evaluate RPN */ stack = [OFMutableArray array]; for (id token in tokens) { unsigned precedence = [[operatorPrecedences objectForKey: token] unsignedIntValue]; id var, first, second; size_t stackSize; /* Only unary operators have precedence 1 */ if (precedence > 1) { stackSize = stack.count; first = [stack objectAtIndex: stackSize - 2]; second = [stack objectAtIndex: stackSize - 1]; if ([token isEqual: @"=="]) var = [OFNumber numberWithBool: [first isEqual: second]]; else if ([token isEqual: @"!="]) var = [OFNumber numberWithBool: ![first isEqual: second]]; else if ([token isEqual: @"<"]) var = [OFNumber numberWithBool: [first compare: second] == OFOrderedAscending]; else if ([token isEqual: @"<="]) var = [OFNumber numberWithBool: [first compare: second] != OFOrderedDescending]; else if ([token isEqual: @">"]) var = [OFNumber numberWithBool: [first compare: second] == OFOrderedDescending]; else if ([token isEqual: @">="]) var = [OFNumber numberWithBool: [first compare: second] != OFOrderedAscending]; else if ([token isEqual: @"+"]) var = [OFNumber numberWithDouble: [first doubleValue] + [second doubleValue]]; else if ([token isEqual: @"%"]) var = [OFNumber numberWithLongLong: [first longLongValue] % [second longLongValue]]; else if ([token isEqual: @"&&"]) var = [OFNumber numberWithBool: [first boolValue] && [second boolValue]]; else if ([token isEqual: @"||"]) var = [OFNumber numberWithBool: [first boolValue] || [second boolValue]]; else OFEnsure(0); [stack replaceObjectAtIndex: stackSize - 2 withObject: var]; [stack removeLastObject]; } else if (precedence == 1) { stackSize = stack.count; first = stack.lastObject; if ([token isEqual: @"!"]) var = [OFNumber numberWithBool: ![first boolValue]]; else if ([token isEqual: @"is_real"]) var = [OFNumber numberWithBool: ([first doubleValue] != [first longLongValue])]; else OFEnsure(0); [stack replaceObjectAtIndex: stackSize - 1 withObject: var]; } else [stack addObject: token]; } if (stack.count != 1) @throw [OFInvalidFormatException exception]; return [stack.firstObject boolValue]; } static OFString * evaluateConditionals(OFArray *conditions, OFDictionary *variables) { for (OFDictionary *dictionary in conditions) { OFString *condition, *value; bool found = false; for (OFString *key in dictionary) { if (found) @throw [OFInvalidFormatException exception]; condition = key; value = [dictionary objectForKey: key]; if (![condition isKindOfClass: [OFString class]] || ![value isKindOfClass: [OFString class]]) @throw [OFInvalidFormatException exception]; found = true; } if (!found) @throw [OFInvalidFormatException exception]; if (evaluateCondition(condition, variables)) return value; } /* Need to have a fallback as the last one. */ @throw [OFInvalidFormatException exception]; } static OFString * evaluateArray(OFArray *array, OFDictionary *variables) { OFMutableString *string = [OFMutableString string]; for (id object in array) { if ([object isKindOfClass: [OFString class]]) [string appendString: object]; else if ([object isKindOfClass: [OFArray class]]) [string appendString: evaluateConditionals(object, variables)]; else @throw [OFInvalidFormatException exception]; } [string makeImmutable]; return string; } @implementation OFLocale @synthesize languageCode = _languageCode, countryCode = _countryCode; @synthesize encoding = _encoding, decimalSeparator = _decimalSeparator; + (void)initialize { void *pool; OFNumber *one, *two, *three, *four; if (self != [OFLocale class]) return; pool = objc_autoreleasePoolPush(); /* 1 is also used to denote a unary operator. */ one = [OFNumber numberWithUnsignedInt: 1]; two = [OFNumber numberWithUnsignedInt: 2]; three = [OFNumber numberWithUnsignedInt: 3]; four = [OFNumber numberWithUnsignedInt: 4]; operatorPrecedences = [[OFDictionary alloc] initWithKeysAndObjects: @"==", two, @"!=", two, @"<", two, @"<=", two, @">", two, @">=", two, @"+", two, @"%", two, @"&&", three, @"||", four, @"!", one, @"is_real", one, nil]; objc_autoreleasePoolPop(pool); } + (OFLocale *)currentLocale { OFOnce(&initLocaleControl, initLocale); return currentLocale; } + (OFString *)languageCode { OFOnce(&initLocaleControl, initLocale); return currentLocale.languageCode; } + (OFString *)countryCode { OFOnce(&initLocaleControl, initLocale); return currentLocale.countryCode; } + (OFStringEncoding)encoding { OFOnce(&initLocaleControl, initLocale); return currentLocale.encoding; } + (OFString *)decimalSeparator { OFOnce(&initLocaleControl, initLocale); return currentLocale.decimalSeparator; } + (void)addLocalizationDirectoryIRI: (OFIRI *)IRI { [currentLocale addLocalizationDirectoryIRI: IRI]; } - (instancetype)init { /* * In the past, applications not using OFApplication were required to * create an instance of OFLocale manually. This is no longer needed * and +[currentLocale] creates the singleton. However, in order to not * break old applications, this method needs to just return the * singleton now. */ [self release]; return [OFLocale currentLocale]; } - (instancetype)of_init { self = [super init]; @try { #ifndef OF_AMIGAOS char *locale, *messagesLocale = NULL; # ifdef OF_MSDOS _encoding = OFStringEncodingCodepage437; # else _encoding = OFStringEncodingUTF8; # endif _decimalSeparator = @"."; _localizedStrings = [[OFMutableArray alloc] init]; if ((locale = setlocale(LC_ALL, "")) != NULL) _decimalSeparator = [[OFString alloc] initWithCString: localeconv()->decimal_point encoding: _encoding]; # ifdef LC_MESSAGES messagesLocale = setlocale(LC_MESSAGES, ""); # endif if (messagesLocale == NULL) messagesLocale = locale; if (messagesLocale != NULL) { void *pool = objc_autoreleasePoolPush(); parseLocale(messagesLocale, &_encoding, &_languageCode, &_countryCode); [_languageCode retain]; [_countryCode retain]; objc_autoreleasePoolPop(pool); } #else void *pool = objc_autoreleasePoolPush(); char buffer[32]; struct Locale *locale; /* * Returns an empty string on MorphOS + libnix, but still * applies it so that printf etc. work as expected. */ setlocale(LC_ALL, ""); # if defined(OF_MORPHOS) if (GetVar("CODEPAGE", buffer, sizeof(buffer), 0) > 0) { # elif defined(OF_AMIGAOS4) if (GetVar("Charset", buffer, sizeof(buffer), 0) > 0) { # else if (0) { # endif OFStringEncoding ASCII = OFStringEncodingASCII; @try { _encoding = OFStringEncodingParseName( [OFString stringWithCString: buffer encoding: ASCII]); } @catch (OFInvalidArgumentException *e) { _encoding = OFStringEncodingISO8859_1; } } else _encoding = OFStringEncodingISO8859_1; /* * Get it via localeconv() instead of from the Locale struct, * to make sure we and printf etc. have the same expectations. */ _decimalSeparator = [[OFString alloc] initWithCString: localeconv()->decimal_point encoding: _encoding]; _localizedStrings = [[OFMutableArray alloc] init]; if (GetVar("Language", buffer, sizeof(buffer), 0) > 0) _languageCode = [[OFString alloc] initWithCString: buffer encoding: _encoding]; if ((locale = OpenLocale(NULL)) != NULL) { @try { uint32_t countryCode; size_t length; countryCode = OFToBigEndian32(locale->loc_CountryCode); for (length = 0; length < 4; length++) if (((char *)&countryCode)[length] == 0) break; _countryCode = [[OFString alloc] initWithCString: (char *)&countryCode encoding: _encoding length: length]; } @finally { CloseLocale(locale); } } objc_autoreleasePoolPop(pool); #endif } @catch (id e) { [self release]; @throw e; } return self; } OF_SINGLETON_METHODS - (void)addLocalizationDirectoryIRI: (OFIRI *)IRI { void *pool; OFIRI *mapIRI, *localizationIRI; OFString *languageCode, *countryCode, *localizationFile; OFDictionary *map; if (_languageCode == nil) return; pool = objc_autoreleasePoolPush(); mapIRI = [IRI IRIByAppendingPathComponent: @"localizations.json"]; @try { map = [[OFString stringWithContentsOfIRI: mapIRI] objectByParsingJSON]; } @catch (OFOpenItemFailedException *e) { objc_autoreleasePoolPop(pool); return; } languageCode = _languageCode.lowercaseString; countryCode = _countryCode.lowercaseString; if (countryCode == nil) countryCode = @""; localizationFile = [[map objectForKey: languageCode] objectForKey: countryCode]; if (localizationFile == nil) localizationFile = [[map objectForKey: languageCode] objectForKey: @""]; if (localizationFile == nil) { objc_autoreleasePoolPop(pool); return; } localizationIRI = [IRI IRIByAppendingPathComponent: [localizationFile stringByAppendingString: @".json"]]; [_localizedStrings addObject: [[OFString stringWithContentsOfIRI: localizationIRI] objectByParsingJSON]]; objc_autoreleasePoolPop(pool); } - (OFString *)localizedStringForID: (OFConstantString *)ID fallback: (id)fallback, ... { OFString *ret; va_list args; va_start(args, fallback); ret = [self localizedStringForID: ID fallback: fallback arguments: args]; va_end(args); return ret; } - (OFString *)localizedStringForID: (OFConstantString *)ID fallback: (id)fallback arguments: (va_list)arguments { OFMutableString *ret = [OFMutableString string]; void *pool = objc_autoreleasePoolPush(); OFMutableDictionary *variables; OFConstantString *name; const char *UTF8String = NULL; size_t last, UTF8StringLength; int state = 0; variables = [OFMutableDictionary dictionary]; while ((name = va_arg(arguments, OFConstantString *)) != nil) [variables setObject: va_arg(arguments, id) forKey: name]; for (OFDictionary *strings in _localizedStrings) { id string = [strings objectForKey: ID]; if (string == nil) continue; if ([string isKindOfClass: [OFArray class]]) string = evaluateArray(string, variables); UTF8String = [string UTF8String]; UTF8StringLength = [string UTF8StringLength]; break; } if (UTF8String == NULL) { if ([fallback isKindOfClass: [OFArray class]]) fallback = evaluateArray(fallback, variables); UTF8String = [fallback UTF8String]; UTF8StringLength = [fallback UTF8StringLength]; } state = 0; last = 0; for (size_t i = 0; i < UTF8StringLength; i++) { switch (state) { case 0: if (UTF8String[i] == '%') { [ret appendUTF8String: UTF8String + last length: i - last]; last = i + 1; state = 1; } break; case 1: if (UTF8String[i] == '[') { last = i + 1; state = 2; } else { [ret appendString: @"%"]; state = 0; } break; case 2: if (UTF8String[i] == ']') { OFString *var = [OFString stringWithUTF8String: UTF8String + last length: i - last]; OFString *value = [variables objectForKey: var]; if (value != nil) [ret appendString: value.description]; last = i + 1; state = 0; } break; } } switch (state) { case 1: [ret appendString: @"%"]; /* Explicit fall-through */ case 0: [ret appendUTF8String: UTF8String + last length: UTF8StringLength - last]; break; } objc_autoreleasePoolPop(pool); [ret makeImmutable]; return ret; } @end objfw-1.1.6/src/OFLocking.h000066400000000000000000000027341465614216400154200ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN /** * @protocol OFLocking OFLocking.h ObjFW/OFLocking.h * * @brief A protocol for locks. */ @protocol OFLocking /** * @brief The name of the lock. */ @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *name; /** * @brief Locks the lock. * * @throw OFLockFailedException Acquiring the lock failed */ - (void)lock; /** * @brief Tries to lock the lock. * * @return A boolean whether the lock could be locked * * @throw OFLockFailedException The lock could not be acquired for another * reason than it already being held */ - (bool)tryLock; /** * @brief Unlocks the lock. * * @throw OFUnlockFailedException Releasing the lock failed */ - (void)unlock; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFMD5Hash.h000066400000000000000000000024001465614216400152110ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFCryptographicHash.h" OF_ASSUME_NONNULL_BEGIN @class OFSecureData; /** * @class OFMD5Hash OFMD5Hash.h ObjFW/OFMD5Hash.h * * @brief A class which provides methods to create an MD5 hash. */ OF_SUBCLASSING_RESTRICTED @interface OFMD5Hash: OFObject { OFSecureData *_iVarsData; struct { uint32_t state[4]; uint64_t bits; union { unsigned char bytes[64]; uint32_t words[16]; } buffer; size_t bufferLength; } *_iVars; bool _allowsSwappableMemory; bool _calculated; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFMD5Hash.m000066400000000000000000000150471465614216400152310ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFMD5Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFHashNotCalculatedException.h" #import "OFOutOfRangeException.h" static const size_t digestSize = 16; static const size_t blockSize = 64; OF_DIRECT_MEMBERS @interface OFMD5Hash () - (void)of_resetState; @end #define F(a, b, c) (((a) & (b)) | (~(a) & (c))) #define G(a, b, c) (((a) & (c)) | ((b) & ~(c))) #define H(a, b, c) ((a) ^ (b) ^ (c)) #define I(a, b, c) ((b) ^ ((a) | ~(c))) static const uint32_t table[] = { 0xD76AA478, 0xE8C7B756, 0x242070DB, 0xC1BDCEEE, 0xF57C0FAF, 0x4787C62A, 0xA8304613, 0xFD469501, 0x698098D8, 0x8B44F7AF, 0xFFFF5BB1, 0x895CD7BE, 0x6B901122, 0xFD987193, 0xA679438E, 0x49B40821, 0xF61E2562, 0xC040B340, 0x265E5A51, 0xE9B6C7AA, 0xD62F105D, 0x02441453, 0xD8A1E681, 0xE7D3FBC8, 0x21E1CDE6, 0xC33707D6, 0xF4D50D87, 0x455A14ED, 0xA9E3E905, 0xFCEFA3F8, 0x676F02D9, 0x8D2A4C8A, 0xFFFA3942, 0x8771F681, 0x6D9D6122, 0xFDE5380C, 0xA4BEEA44, 0x4BDECFA9, 0xF6BB4B60, 0xBEBFBC70, 0x289B7EC6, 0xEAA127FA, 0xD4EF3085, 0x04881D05, 0xD9D4D039, 0xE6DB99E5, 0x1FA27CF8, 0xC4AC5665, 0xF4292244, 0x432AFF97, 0xAB9423A7, 0xFC93A039, 0x655B59C3, 0x8F0CCC92, 0xFFEFF47D, 0x85845DD1, 0x6FA87E4F, 0xFE2CE6E0, 0xA3014314, 0x4E0811A1, 0xF7537E82, 0xBD3AF235, 0x2AD7D2BB, 0xEB86D391 }; static const uint8_t wordOrder[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9 }; static const uint8_t rotateBits[] = { 7, 12, 17, 22, 5, 9, 14, 20, 4, 11, 16, 23, 6, 10, 15, 21 }; static OF_INLINE void byteSwapVectorIfBE(uint32_t *vector, uint_fast8_t length) { #ifdef OF_BIG_ENDIAN for (uint_fast8_t i = 0; i < length; i++) vector[i] = OFByteSwap32(vector[i]); #endif } static void processBlock(uint32_t *state, uint32_t *buffer) { uint32_t new[4]; uint_fast8_t i = 0; new[0] = state[0]; new[1] = state[1]; new[2] = state[2]; new[3] = state[3]; byteSwapVectorIfBE(buffer, 16); #define LOOP_BODY(f) \ { \ uint32_t tmp = new[3]; \ tmp = new[3]; \ new[0] += f(new[1], new[2], new[3]) + \ buffer[wordOrder[i]] + table[i]; \ new[3] = new[2]; \ new[2] = new[1]; \ new[1] += OFRotateLeft(new[0], \ rotateBits[(i % 4) + (i / 16) * 4]); \ new[0] = tmp; \ } for (; i < 16; i++) LOOP_BODY(F) for (; i < 32; i++) LOOP_BODY(G) for (; i < 48; i++) LOOP_BODY(H) for (; i < 64; i++) LOOP_BODY(I) #undef LOOP_BODY state[0] += new[0]; state[1] += new[1]; state[2] += new[2]; state[3] += new[3]; } @implementation OFMD5Hash @synthesize calculated = _calculated; @synthesize allowsSwappableMemory = _allowsSwappableMemory; + (size_t)digestSize { return digestSize; } + (size_t)blockSize { return blockSize; } + (instancetype)hashWithAllowsSwappableMemory: (bool)allowsSwappableMemory { return [[[self alloc] initWithAllowsSwappableMemory: allowsSwappableMemory] autorelease]; } - (instancetype)initWithAllowsSwappableMemory: (bool)allowsSwappableMemory { self = [super init]; @try { _iVarsData = [[OFSecureData alloc] initWithCount: sizeof(*_iVars) allowsSwappableMemory: allowsSwappableMemory]; _iVars = _iVarsData.mutableItems; _allowsSwappableMemory = allowsSwappableMemory; [self of_resetState]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)of_init { return [super init]; } - (void)dealloc { [_iVarsData release]; [super dealloc]; } - (size_t)digestSize { return digestSize; } - (size_t)blockSize { return blockSize; } - (id)copy { OFMD5Hash *copy = [[OFMD5Hash alloc] of_init]; copy->_iVarsData = [_iVarsData copy]; copy->_iVars = copy->_iVarsData.mutableItems; copy->_allowsSwappableMemory = _allowsSwappableMemory; copy->_calculated = _calculated; return copy; } - (void)of_resetState { _iVars->state[0] = 0x67452301; _iVars->state[1] = 0xEFCDAB89; _iVars->state[2] = 0x98BADCFE; _iVars->state[3] = 0x10325476; } - (void)updateWithBuffer: (const void *)buffer_ length: (size_t)length { const unsigned char *buffer = buffer_; if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; if (length > SIZE_MAX / 8) @throw [OFOutOfRangeException exception]; _iVars->bits += (length * 8); while (length > 0) { size_t min = 64 - _iVars->bufferLength; if (min > length) min = length; memcpy(_iVars->buffer.bytes + _iVars->bufferLength, buffer, min); _iVars->bufferLength += min; buffer += min; length -= min; if (_iVars->bufferLength == 64) { processBlock(_iVars->state, _iVars->buffer.words); _iVars->bufferLength = 0; } } } - (const unsigned char *)digest { if (!_calculated) @throw [OFHashNotCalculatedException exceptionWithObject: self]; return (const unsigned char *)_iVars->state; } - (void)calculate { if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; _iVars->buffer.bytes[_iVars->bufferLength] = 0x80; OFZeroMemory(_iVars->buffer.bytes + _iVars->bufferLength + 1, 64 - _iVars->bufferLength - 1); if (_iVars->bufferLength >= 56) { processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(_iVars->buffer.bytes, 64); } _iVars->buffer.words[14] = OFToLittleEndian32((uint32_t)(_iVars->bits & 0xFFFFFFFF)); _iVars->buffer.words[15] = OFToLittleEndian32((uint32_t)(_iVars->bits >> 32)); processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); byteSwapVectorIfBE(_iVars->state, 4); _calculated = true; } - (void)reset { [self of_resetState]; _iVars->bits = 0; OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); _iVars->bufferLength = 0; _calculated = false; } @end objfw-1.1.6/src/OFMXDNSResourceRecord.h000066400000000000000000000042411465614216400175650ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFDNSResourceRecord.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFMXDNSResourceRecord \ * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h * * @brief A class representing an MX DNS resource record. */ OF_SUBCLASSING_RESTRICTED @interface OFMXDNSResourceRecord: OFDNSResourceRecord { uint16_t _preference; OFString *_mailExchange; } /** * @brief The preference of the resource record. */ @property (readonly, nonatomic) uint16_t preference; /** * @brief The mail exchange of the resource record. */ @property (readonly, nonatomic) OFString *mailExchange; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFMXDNSResourceRecord with the * specified name, class, preference, mail exchange and time to live. * * @param name The name for the resource record * @param DNSClass The class code for the resource record * @param preference The preference for the resource record * @param mailExchange The mail exchange for the resource record * @param TTL The time to live for the resource record * @return An initialized OFMXDNSResourceRecord */ - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass preference: (uint16_t)preference mailExchange: (OFString *)mailExchange TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFMXDNSResourceRecord.m000066400000000000000000000055471465614216400176040ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFMXDNSResourceRecord.h" @implementation OFMXDNSResourceRecord @synthesize preference = _preference, mailExchange = _mailExchange; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass preference: (uint16_t)preference mailExchange: (OFString *)mailExchange TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: DNSClass recordType: OFDNSRecordTypeMX TTL: TTL]; @try { _preference = preference; _mailExchange = [mailExchange copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_mailExchange release]; [super dealloc]; } - (bool)isEqual: (id)object { OFMXDNSResourceRecord *record; if (object == self) return true; if (![object isKindOfClass: [OFMXDNSResourceRecord class]]) return false; record = object; if (record->_name != _name && ![record->_name isEqual: _name]) return false; if (record->_DNSClass != _DNSClass) return false; if (record->_recordType != _recordType) return false; if (record->_preference != _preference) return false; if (record->_mailExchange != _mailExchange && ![record->_mailExchange isEqual: _mailExchange]) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddByte(&hash, _DNSClass >> 8); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType >> 8); OFHashAddByte(&hash, _recordType); OFHashAddByte(&hash, _preference >> 8); OFHashAddByte(&hash, _preference); OFHashAddHash(&hash, _mailExchange.hash); OFHashFinalize(&hash); return hash; } - (OFString *)description { return [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tClass = %@\n" @"\tPreference = %" PRIu16 "\n" @"\tMail Exchange = %@\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFDNSClassName(_DNSClass), _preference, _mailExchange, _TTL]; } @end objfw-1.1.6/src/OFMapTable+Private.h000066400000000000000000000020101465614216400171100ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFMapTable.h" OF_ASSUME_NONNULL_BEGIN OF_DIRECT_MEMBERS @interface OFMapTableEnumeratorWrapper: OFEnumerator { OFMapTableEnumerator *_enumerator; id _object; } - (instancetype)initWithEnumerator: (OFMapTableEnumerator *)enumerator object: (id)object; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFMapTable.h000066400000000000000000000174101465614216400155140ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFEnumerator.h" OF_ASSUME_NONNULL_BEGIN /** @file */ /** * @struct OFMapTableFunctions OFMapTable.h ObjFW/OFMapTable.h * * @brief A struct describing the functions to be used by the map table. */ typedef struct { /** The function to retain keys / objects */ void *_Nullable (*_Nullable retain)(void *_Nullable object); /** The function to release keys / objects */ void (*_Nullable release)(void *_Nullable object); /** The function to hash keys */ unsigned long (*_Nullable hash)(void *_Nullable object); /** The function to compare keys / objects */ bool (*_Nullable equal)(void *_Nullable object1, void *_Nullable object2); } OFMapTableFunctions; #ifdef OF_HAVE_BLOCKS /** * @brief A block for enumerating an OFMapTable. * * @param key The current key * @param object The current object * @param stop A pointer to a variable that can be set to true to stop the * enumeration */ typedef void (^OFMapTableEnumerationBlock)(void *_Nullable key, void *_Nullable object, bool *stop); /** * @brief A block for replacing objects in an OFMapTable. * * @param key The key of the object to replace * @param object The object to replace * @return The object to replace the object with */ typedef void *_Nullable (^OFMapTableReplaceBlock)(void *_Nullable key, void *_Nullable object); #endif @class OFMapTableEnumerator; /** * @class OFMapTable OFMapTable.h ObjFW/OFMapTable.h * * @brief A class similar to OFDictionary, but providing more options how keys * and objects should be retained, released, compared and hashed. */ OF_SUBCLASSING_RESTRICTED @interface OFMapTable: OFObject { OFMapTableFunctions _keyFunctions, _objectFunctions; struct OFMapTableBucket *_Nonnull *_Nullable _buckets; uint32_t _count, _capacity; unsigned char _rotation; unsigned long _mutations; } /** * @brief The key functions used by the map table. */ @property (readonly, nonatomic) OFMapTableFunctions keyFunctions; /** * @brief The object functions used by the map table. */ @property (readonly, nonatomic) OFMapTableFunctions objectFunctions; /** * @brief The number of objects in the map table. */ @property (readonly, nonatomic) size_t count; /** * @brief Creates a new OFMapTable with the specified key and object functions. * * @param keyFunctions A structure of functions for handling keys * @param objectFunctions A structure of functions for handling objects * @return A new autoreleased OFMapTable */ + (instancetype)mapTableWithKeyFunctions: (OFMapTableFunctions)keyFunctions objectFunctions: (OFMapTableFunctions)objectFunctions; /** * @brief Creates a new OFMapTable with the specified key functions, object * functions and capacity. * * @param keyFunctions A structure of functions for handling keys * @param objectFunctions A structure of functions for handling objects * @param capacity A hint about the count of elements expected to be in the map * table * @return A new autoreleased OFMapTable */ + (instancetype)mapTableWithKeyFunctions: (OFMapTableFunctions)keyFunctions objectFunctions: (OFMapTableFunctions)objectFunctions capacity: (size_t)capacity; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFMapTable with the specified key * and object functions. * * @param keyFunctions A structure of functions for handling keys * @param objectFunctions A structure of functions for handling objects * @return An initialized OFMapTable */ - (instancetype)initWithKeyFunctions: (OFMapTableFunctions)keyFunctions objectFunctions: (OFMapTableFunctions)objectFunctions; /** * @brief Initializes an already allocated OFMapTable with the specified key * functions, object functions and capacity. * * @param keyFunctions A structure of functions for handling keys * @param objectFunctions A structure of functions for handling objects * @param capacity A hint about the count of elements expected to be in the map * table * @return An initialized OFMapTable */ - (instancetype)initWithKeyFunctions: (OFMapTableFunctions)keyFunctions objectFunctions: (OFMapTableFunctions)objectFunctions capacity: (size_t)capacity OF_DESIGNATED_INITIALIZER; /** * @brief Returns the object for the given key or NULL if the key was not found. * * @param key The key whose object should be returned * @return The object for the given key or NULL if the key was not found */ - (nullable void *)objectForKey: (void *)key; /** * @brief Sets an object for a key. * * @param key The key to set * @param object The object to set the key to */ - (void)setObject: (nullable void *)object forKey: (nullable void *)key; /** * @brief Removes the object for the specified key from the map table. * * @param key The key whose object should be removed */ - (void)removeObjectForKey: (nullable void *)key; /** * @brief Removes all objects. */ - (void)removeAllObjects; /** * @brief Checks whether the map table contains an object equal to the * specified object. * * @param object The object which is checked for being in the map table * @return A boolean whether the map table contains the specified object */ - (bool)containsObject: (nullable void *)object; /** * @brief Checks whether the map table contains an object with the specified * address. * * @param object The object which is checked for being in the map table * @return A boolean whether the map table contains an object with the * specified address. */ - (bool)containsObjectIdenticalTo: (nullable void *)object; /** * @brief Returns an OFMapTableEnumerator to enumerate through the map table's * keys. * * @return An OFMapTableEnumerator to enumerate through the map table's keys */ - (OFMapTableEnumerator *)keyEnumerator; /** * @brief Returns an OFMapTableEnumerator to enumerate through the map table's * objects. * * @return An OFMapTableEnumerator to enumerate through the map table's objects */ - (OFMapTableEnumerator *)objectEnumerator; #ifdef OF_HAVE_BLOCKS /** * @brief Executes a block for each key / object pair. * * @param block The block to execute for each key / object pair. */ - (void)enumerateKeysAndObjectsUsingBlock: (OFMapTableEnumerationBlock)block; /** * @brief Replaces each object with the object returned by the block. * * @param block The block which returns a new object for each object */ - (void)replaceObjectsUsingBlock: (OFMapTableReplaceBlock)block; #endif @end /** * @class OFMapTableEnumerator OFMapTable.h ObjFW/OFMapTable.h * * @brief A class which provides methods to enumerate through an OFMapTable's * keys or objects. */ #ifndef OF_MAP_TABLE_M OF_SUBCLASSING_RESTRICTED #endif @interface OFMapTableEnumerator: OFObject { OFMapTable *_mapTable; struct OFMapTableBucket *_Nonnull *_Nullable _buckets; uint32_t _capacity; unsigned long _mutations, *_Nullable _mutationsPtr, _position; } - (instancetype)init OF_UNAVAILABLE; /** * @brief Returns a pointer to the next object, or NULL if the enumeration * finished. * * @return The next object */ - (void *_Nullable *_Nullable)nextObject; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFMapTable.m000066400000000000000000000414221465614216400155210ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #define OF_MAP_TABLE_M #include "config.h" #include #include #import "OFMapTable.h" #import "OFMapTable+Private.h" #import "OFEnumerator.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" extern unsigned long OFHashSeed; static const uint32_t minCapacity = 16; struct OFMapTableBucket { void *key, *object; uint32_t hash; }; static struct OFMapTableBucket deletedBucket = { 0 }; static void * defaultRetain(void *object) { return object; } static void defaultRelease(void *object) { } static unsigned long defaultHash(void *object) { return (unsigned long)(uintptr_t)object; } static bool defaultEqual(void *object1, void *object2) { return (object1 == object2); } OF_DIRECT_MEMBERS @interface OFMapTableEnumerator () - (instancetype)of_initWithMapTable: (OFMapTable *)mapTable buckets: (struct OFMapTableBucket **)buckets capacity: (uint32_t)capacity mutationsPointer: (unsigned long *)mutationsPtr OF_METHOD_FAMILY(init); @end @interface OFMapTableKeyEnumerator: OFMapTableEnumerator @end @interface OFMapTableObjectEnumerator: OFMapTableEnumerator @end @implementation OFMapTable @synthesize keyFunctions = _keyFunctions, objectFunctions = _objectFunctions; + (instancetype)mapTableWithKeyFunctions: (OFMapTableFunctions)keyFunctions objectFunctions: (OFMapTableFunctions)objectFunctions { return [[[self alloc] initWithKeyFunctions: keyFunctions objectFunctions: objectFunctions] autorelease]; } + (instancetype)mapTableWithKeyFunctions: (OFMapTableFunctions)keyFunctions objectFunctions: (OFMapTableFunctions)objectFunctions capacity: (size_t)capacity { return [[[self alloc] initWithKeyFunctions: keyFunctions objectFunctions: objectFunctions capacity: capacity] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithKeyFunctions: (OFMapTableFunctions)keyFunctions objectFunctions: (OFMapTableFunctions)objectFunctions { return [self initWithKeyFunctions: keyFunctions objectFunctions: objectFunctions capacity: 0]; } - (instancetype)initWithKeyFunctions: (OFMapTableFunctions)keyFunctions objectFunctions: (OFMapTableFunctions)objectFunctions capacity: (size_t)capacity { self = [super init]; @try { _keyFunctions = keyFunctions; _objectFunctions = objectFunctions; #define SET_DEFAULT(var, value) \ if (var == NULL) \ var = value; SET_DEFAULT(_keyFunctions.retain, defaultRetain); SET_DEFAULT(_keyFunctions.release, defaultRelease); SET_DEFAULT(_keyFunctions.hash, defaultHash); SET_DEFAULT(_keyFunctions.equal, defaultEqual); SET_DEFAULT(_objectFunctions.retain, defaultRetain); SET_DEFAULT(_objectFunctions.release, defaultRelease); SET_DEFAULT(_objectFunctions.hash, defaultHash); SET_DEFAULT(_objectFunctions.equal, defaultEqual); #undef SET_DEFAULT if (capacity > UINT32_MAX / sizeof(*_buckets) || capacity > UINT32_MAX / 8) @throw [OFOutOfRangeException exception]; for (_capacity = 1; _capacity < capacity;) { if (_capacity > UINT32_MAX / 2) @throw [OFOutOfRangeException exception]; _capacity *= 2; } if (capacity * 8 / _capacity >= 6) if (_capacity <= UINT32_MAX / 2) _capacity *= 2; if (_capacity < minCapacity) _capacity = minCapacity; _buckets = OFAllocZeroedMemory(_capacity, sizeof(*_buckets)); if (OFHashSeed != 0) _rotation = OFRandom16() & 31; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { for (uint32_t i = 0; i < _capacity; i++) { if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) { _keyFunctions.release(_buckets[i]->key); _objectFunctions.release(_buckets[i]->object); OFFreeMemory(_buckets[i]); } } OFFreeMemory(_buckets); [super dealloc]; } static void resizeForCount(OFMapTable *self, uint32_t count) { uint32_t fullness, capacity; struct OFMapTableBucket **buckets; unsigned char newRotation; if (count > UINT32_MAX / sizeof(*self->_buckets) || count > UINT32_MAX / 8) @throw [OFOutOfRangeException exception]; fullness = count * 8 / self->_capacity; if (fullness >= 6) { if (self->_capacity > UINT32_MAX / 2) return; capacity = self->_capacity * 2; } else if (fullness <= 1) capacity = self->_capacity / 2; else return; /* * Don't downsize if we have an initial capacity or if we would fall * below the minimum capacity. */ if ((capacity < self->_capacity && count > self->_count) || capacity < minCapacity) return; buckets = OFAllocZeroedMemory(capacity, sizeof(*buckets)); newRotation = (OFHashSeed != 0 ? OFRandom16() & 31 : 0); for (uint32_t i = 0; i < self->_capacity; i++) { if (self->_buckets[i] != NULL && self->_buckets[i] != &deletedBucket) { uint32_t rotatedHash, j, last; rotatedHash = OFRotateLeft(self->_buckets[i]->hash, newRotation); last = capacity; for (j = rotatedHash & (capacity - 1); j < last && buckets[j] != NULL; j++); /* In case the last bucket is already used */ if (j >= last) { last = rotatedHash & (capacity - 1); for (j = 0; j < last && buckets[j] != NULL; j++); } if (j >= last) @throw [OFOutOfRangeException exception]; buckets[j] = self->_buckets[i]; } } OFFreeMemory(self->_buckets); self->_buckets = buckets; self->_capacity = capacity; self->_rotation = newRotation; } static void setObject(OFMapTable *restrict self, void *key, void *object, uint32_t hash) { uint32_t rotatedHash, i, last; void *old; if (key == NULL || object == NULL) @throw [OFInvalidArgumentException exception]; rotatedHash = OFRotateLeft(hash, self->_rotation); last = self->_capacity; for (i = rotatedHash & (self->_capacity - 1); i < last && self->_buckets[i] != NULL; i++) { if (self->_buckets[i] == &deletedBucket) continue; if (self->_keyFunctions.equal(self->_buckets[i]->key, key)) break; } /* In case the last bucket is already used */ if (i >= last) { last = rotatedHash & (self->_capacity - 1); for (i = 0; i < last && self->_buckets[i] != NULL; i++) { if (self->_buckets[i] == &deletedBucket) continue; if (self->_keyFunctions.equal( self->_buckets[i]->key, key)) break; } } /* Key not in map table */ if (i >= last || self->_buckets[i] == NULL || self->_buckets[i] == &deletedBucket || !self->_keyFunctions.equal(self->_buckets[i]->key, key)) { struct OFMapTableBucket *bucket; resizeForCount(self, self->_count + 1); /* Resizing can change the rotation */ rotatedHash = OFRotateLeft(hash, self->_rotation); self->_mutations++; last = self->_capacity; for (i = rotatedHash & (self->_capacity - 1); i < last && self->_buckets[i] != NULL && self->_buckets[i] != &deletedBucket; i++); /* In case the last bucket is already used */ if (i >= last) { last = rotatedHash & (self->_capacity - 1); for (i = 0; i < last && self->_buckets[i] != NULL && self->_buckets[i] != &deletedBucket; i++); } if (i >= last) @throw [OFOutOfRangeException exception]; bucket = OFAllocMemory(1, sizeof(*bucket)); @try { bucket->key = self->_keyFunctions.retain(key); } @catch (id e) { OFFreeMemory(bucket); @throw e; } @try { bucket->object = self->_objectFunctions.retain(object); } @catch (id e) { self->_keyFunctions.release(bucket->key); OFFreeMemory(bucket); @throw e; } bucket->hash = hash; self->_buckets[i] = bucket; self->_count++; return; } old = self->_buckets[i]->object; self->_buckets[i]->object = self->_objectFunctions.retain(object); self->_objectFunctions.release(old); } - (bool)isEqual: (id)object { OFMapTable *mapTable; if (object == self) return true; if (![object isKindOfClass: [OFMapTable class]]) return false; mapTable = object; if (mapTable->_count != _count || mapTable->_keyFunctions.equal != _keyFunctions.equal || mapTable->_objectFunctions.equal != _objectFunctions.equal) return false; for (uint32_t i = 0; i < _capacity; i++) { if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) { void *objectIter = [mapTable objectForKey: _buckets[i]->key]; if (!_objectFunctions.equal(objectIter, _buckets[i]->object)) return false; } } return true; } - (unsigned long)hash { unsigned long hash = 0; for (unsigned long i = 0; i < _capacity; i++) { if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) { hash ^= _buckets[i]->hash; hash ^= _objectFunctions.hash(_buckets[i]->object); } } return hash; } - (id)copy { OFMapTable *copy = [[OFMapTable alloc] initWithKeyFunctions: _keyFunctions objectFunctions: _objectFunctions capacity: _capacity]; @try { for (uint32_t i = 0; i < _capacity; i++) if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) setObject(copy, _buckets[i]->key, _buckets[i]->object, _buckets[i]->hash); } @catch (id e) { [copy release]; @throw e; } return copy; } - (size_t)count { return _count; } - (void *)objectForKey: (void *)key { uint32_t i, rotatedHash, last; if (key == NULL) @throw [OFInvalidArgumentException exception]; rotatedHash = OFRotateLeft((uint32_t)_keyFunctions.hash(key), _rotation); last = _capacity; for (i = rotatedHash & (_capacity - 1); i < last && _buckets[i] != NULL; i++) { if (_buckets[i] == &deletedBucket) continue; if (_keyFunctions.equal(_buckets[i]->key, key)) return _buckets[i]->object; } if (i < last) return nil; /* In case the last bucket is already used */ last = rotatedHash & (_capacity - 1); for (i = 0; i < last && _buckets[i] != NULL; i++) { if (_buckets[i] == &deletedBucket) continue; if (_keyFunctions.equal(_buckets[i]->key, key)) return _buckets[i]->object; } return NULL; } - (void)setObject: (void *)object forKey: (void *)key { setObject(self, key, object, (uint32_t)_keyFunctions.hash(key)); } - (void)removeObjectForKey: (void *)key { uint32_t i, rotatedHash, last; if (key == NULL) @throw [OFInvalidArgumentException exception]; rotatedHash = OFRotateLeft((uint32_t)_keyFunctions.hash(key), _rotation); last = _capacity; for (i = rotatedHash & (_capacity - 1); i < last && _buckets[i] != NULL; i++) { if (_buckets[i] == &deletedBucket) continue; if (_keyFunctions.equal(_buckets[i]->key, key)) { _keyFunctions.release(_buckets[i]->key); _objectFunctions.release(_buckets[i]->object); OFFreeMemory(_buckets[i]); _buckets[i] = &deletedBucket; _count--; _mutations++; resizeForCount(self, _count); return; } } if (i < last) return; /* In case the last bucket is already used */ last = rotatedHash & (_capacity - 1); for (i = 0; i < last && _buckets[i] != NULL; i++) { if (_buckets[i] == &deletedBucket) continue; if (_keyFunctions.equal(_buckets[i]->key, key)) { _keyFunctions.release(_buckets[i]->key); _objectFunctions.release(_buckets[i]->object); OFFreeMemory(_buckets[i]); _buckets[i] = &deletedBucket; _count--; _mutations++; resizeForCount(self, _count); return; } } } - (void)removeAllObjects { for (uint32_t i = 0; i < _capacity; i++) { if (_buckets[i] != NULL) { if (_buckets[i] == &deletedBucket) { _buckets[i] = NULL; continue; } _keyFunctions.release(_buckets[i]->key); _objectFunctions.release(_buckets[i]->object); OFFreeMemory(_buckets[i]); _buckets[i] = NULL; } } _count = 0; _capacity = minCapacity; _buckets = OFResizeMemory(_buckets, _capacity, sizeof(*_buckets)); /* * Get a new random value for _rotation, so that it is not less secure * than creating a new hash map. */ if (OFHashSeed != 0) _rotation = OFRandom16() & 31; } - (bool)containsObject: (void *)object { if (object == NULL || _count == 0) return false; for (uint32_t i = 0; i < _capacity; i++) if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) if (_objectFunctions.equal(_buckets[i]->object, object)) return true; return false; } - (bool)containsObjectIdenticalTo: (void *)object { if (object == NULL || _count == 0) return false; for (uint32_t i = 0; i < _capacity; i++) if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) if (_buckets[i]->object == object) return true; return false; } - (OFMapTableEnumerator *)keyEnumerator { return [[[OFMapTableKeyEnumerator alloc] of_initWithMapTable: self buckets: _buckets capacity: _capacity mutationsPointer: &_mutations] autorelease]; } - (OFMapTableEnumerator *)objectEnumerator { return [[[OFMapTableObjectEnumerator alloc] of_initWithMapTable: self buckets: _buckets capacity: _capacity mutationsPointer: &_mutations] autorelease]; } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count { unsigned long j = state->state; int i; for (i = 0; i < count; i++) { for (; j < _capacity && (_buckets[j] == NULL || _buckets[j] == &deletedBucket); j++); if (j < _capacity) { objects[i] = _buckets[j]->key; j++; } else break; } state->state = j; state->itemsPtr = objects; state->mutationsPtr = &_mutations; return i; } #ifdef OF_HAVE_BLOCKS - (void)enumerateKeysAndObjectsUsingBlock: (OFMapTableEnumerationBlock)block { bool stop = false; unsigned long mutations = _mutations; for (size_t i = 0; i < _capacity && !stop; i++) { if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) block(_buckets[i]->key, _buckets[i]->object, &stop); if (_mutations != mutations) @throw [OFEnumerationMutationException exceptionWithObject: self]; } } - (void)replaceObjectsUsingBlock: (OFMapTableReplaceBlock)block { unsigned long mutations = _mutations; for (size_t i = 0; i < _capacity; i++) { if (_mutations != mutations) @throw [OFEnumerationMutationException exceptionWithObject: self]; if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) { void *new; new = block(_buckets[i]->key, _buckets[i]->object); if (new == NULL) @throw [OFInvalidArgumentException exception]; if (new != _buckets[i]->object) { _objectFunctions.release(_buckets[i]->object); _buckets[i]->object = _objectFunctions.retain(new); } } } } #endif @end @implementation OFMapTableEnumerator - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)of_initWithMapTable: (OFMapTable *)mapTable buckets: (struct OFMapTableBucket **)buckets capacity: (uint32_t)capacity mutationsPointer: (unsigned long *)mutationsPtr { self = [super init]; _mapTable = [mapTable retain]; _buckets = buckets; _capacity = capacity; _mutations = *mutationsPtr; _mutationsPtr = mutationsPtr; return self; } - (void)dealloc { [_mapTable release]; [super dealloc]; } - (void **)nextObject { OF_UNRECOGNIZED_SELECTOR } @end @implementation OFMapTableKeyEnumerator - (void **)nextObject { if (*_mutationsPtr != _mutations) @throw [OFEnumerationMutationException exceptionWithObject: _mapTable]; for (; _position < _capacity && (_buckets[_position] == NULL || _buckets[_position] == &deletedBucket); _position++); if (_position < _capacity) return &_buckets[_position++]->key; else return NULL; } @end @implementation OFMapTableObjectEnumerator - (void **)nextObject { if (*_mutationsPtr != _mutations) @throw [OFEnumerationMutationException exceptionWithObject: _mapTable]; for (; _position < _capacity && (_buckets[_position] == NULL || _buckets[_position] == &deletedBucket); _position++); if (_position < _capacity) return &_buckets[_position++]->object; else return NULL; } @end @implementation OFMapTableEnumeratorWrapper - (instancetype)initWithEnumerator: (OFMapTableEnumerator *)enumerator object: (id)object { self = [super init]; _enumerator = [enumerator retain]; _object = [object retain]; return self; } - (void)dealloc { [_enumerator release]; [_object release]; [super dealloc]; } - (id)nextObject { void **objectPtr; @try { objectPtr = [_enumerator nextObject]; if (objectPtr == NULL) return nil; } @catch (OFEnumerationMutationException *e) { @throw [OFEnumerationMutationException exceptionWithObject: _object]; } return (id)*objectPtr; } @end objfw-1.1.6/src/OFMatrix4x4.h000066400000000000000000000061471465614216400156400ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN /** * @brief A 4x4 matrix of floats. */ OF_SUBCLASSING_RESTRICTED @interface OFMatrix4x4: OFObject { OF_ALIGN(16) float _values[4][4]; } #ifdef OF_HAVE_CLASS_PROPERTIES @property (readonly, class) OFMatrix4x4 *identityMatrix; #endif /** * @brief A 2D array of the 4x4 floats of the matrix in row-major format. * * These may be modified directly. */ @property (readonly, nonatomic) float (*values)[4]; /** * @brief Returns the 4x4 identity matrix. */ + (OFMatrix4x4 *)identityMatrix; /** * @brief Creates a new 4x4 matrix with the specified values. * * @param values A 2D array of 4x4 floats in row-major format * @return A new, autoreleased OFMatrix4x4 */ + (instancetype)matrixWithValues: (const float [_Nonnull 4][4])values; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated 4x4 matrix with the specified values. * * @param values A 2D array of 4x4 floats in row-major format * @return An initialized OFMatrix4x4 */ - (instancetype)initWithValues: (const float [_Nonnull 4][4])values OF_DESIGNATED_INITIALIZER; /** * @brief Multiplies the receiver with the specified matrix on the left side * and the receiver on the right side. * * @param matrix The matrix to multiply the receiver with */ - (void)multiplyWithMatrix: (OFMatrix4x4 *)matrix; /** * @brief Translates the matrix with the specified vector. * * @param vector The vector to translate the matrix with */ - (void)translateWithVector: (OFVector3D)vector; /** * @brief Scales the matrix with the specified vector. * * @param vector The vector to scale the matrix with */ - (void)scaleWithVector: (OFVector3D)vector; /** * @brief Transforms the specified vector according to the matrix. * * @param vector The vector to transform * @return The transformed vector */ - (OFVector4D)transformedVector: (OFVector4D)vector; /** * @brief Transforms the specified vectors in-place according to the matrix. * * @warning Please note that the vectors must be 16 byte aligned! This is * required to allow SIMD optimizations. Passing a pointer to vectors * that are not 16 byte aligned will crash if SIMD optimizations are * enabled. * * @param vectors The vectors to transform * @param count The count of the specified vectors */ - (void)transformVectors: (OFVector4D *)vectors count: (size_t)count; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFMatrix4x4.m000066400000000000000000000245071465614216400156450ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFMatrix4x4.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFOnce.h" static const float identityValues[4][4] = { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 } }; @implementation OFMatrix4x4 #if (defined(OF_AMD64) || defined(OF_X86)) && defined(__GNUC__) # ifndef __clang__ # pragma GCC push_options # pragma GCC target("sse") # endif static void transformVectors_SSE(OFMatrix4x4 *self, SEL _cmd, OFVector4D *vectors, size_t count) { OF_ALIGN(16) float tmp[4]; __asm__ __volatile__ ( "test %[count], %[count]\n\t" "jz 0f\n" "\n\t" "movaps (%[matrix]), %%xmm0\n\t" "movaps 16(%[matrix]), %%xmm1\n\t" "movaps 32(%[matrix]), %%xmm2\n\t" # ifdef OF_AMD64 "movaps 48(%[matrix]), %%xmm8\n" # endif "\n\t" "0:\n\t" "movaps (%[vectors]), %%xmm3\n" "\n\t" "movaps %%xmm0, %%xmm4\n\t" "mulps %%xmm3, %%xmm4\n\t" "movaps %%xmm4, (%[tmp])\n\t" "addss 4(%[tmp]), %%xmm4\n\t" "addss 8(%[tmp]), %%xmm4\n\t" "addss 12(%[tmp]), %%xmm4\n" "\n\t" "movaps %%xmm1, %%xmm5\n\t" "mulps %%xmm3, %%xmm5\n\t" "movaps %%xmm5, (%[tmp])\n\t" "addss 4(%[tmp]), %%xmm5\n\t" "addss 8(%[tmp]), %%xmm5\n\t" "addss 12(%[tmp]), %%xmm5\n" "\n\t" "movaps %%xmm2, %%xmm6\n\t" "mulps %%xmm3, %%xmm6\n\t" "movaps %%xmm6, (%[tmp])\n\t" "addss 4(%[tmp]), %%xmm6\n\t" "addss 8(%[tmp]), %%xmm6\n\t" "addss 12(%[tmp]), %%xmm6\n" "\n\t" # ifdef OF_AMD64 "movaps %%xmm8, %%xmm7\n\t" # else "movaps 48(%[matrix]), %%xmm7\n\t" # endif "mulps %%xmm3, %%xmm7\n\t" "movaps %%xmm7, (%[tmp])\n\t" "addss 4(%[tmp]), %%xmm7\n\t" "addss 8(%[tmp]), %%xmm7\n\t" "addss 12(%[tmp]), %%xmm7\n" "\n\t" "movss %%xmm4, (%[vectors])\n\t" "movss %%xmm5, 4(%[vectors])\n\t" "movss %%xmm6, 8(%[vectors])\n\t" "movss %%xmm7, 12(%[vectors])\n" "\n\t" "add $16, %[vectors]\n\t" "dec %[count]\n\t" "jnz 0b\n" : [count] "+r" (count), [vectors] "+r" (vectors) : [matrix] "r" (self->_values), [tmp] "r" (&tmp) : "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7", # ifdef OF_AMD64 "xmm8", # endif "memory" ); } # ifndef __clang__ # pragma GCC pop_options # endif # ifndef __clang__ # pragma GCC push_options # pragma GCC target("3dnow") # endif static void multiplyWithMatrix_3DNow(OFMatrix4x4 *self, SEL _cmd, OFMatrix4x4 *matrix) { float (*left)[4] = matrix->_values, (*right)[4] = self->_values; float result[4][4], (*resultPtr)[4] = result; __asm__ __volatile__ ( "movl $4, %%ecx\n\t" "\n\t" "0:\n\t" "movd (%[right]), %%mm0\n\t" "punpckldq 16(%[right]), %%mm0\n\t" "pfmul (%[left]), %%mm0\n\t" "movd 32(%[right]), %%mm1\n\t" "punpckldq 48(%[right]), %%mm1\n\t" "pfmul 8(%[left]), %%mm1\n\t" "pfacc %%mm1, %%mm0\n\t" "pfacc %%mm0, %%mm0\n\t" "movd %%mm0, (%[result])\n\t" "movd 4(%[right]), %%mm0\n\t" "punpckldq 20(%[right]), %%mm0\n\t" "pfmul (%[left]), %%mm0\n\t" "movd 36(%[right]), %%mm1\n\t" "punpckldq 52(%[right]), %%mm1\n\t" "pfmul 8(%[left]), %%mm1\n\t" "pfacc %%mm1, %%mm0\n\t" "pfacc %%mm0, %%mm0\n\t" "movd %%mm0, 4(%[result])\n\t" "movd 8(%[right]), %%mm0\n\t" "punpckldq 24(%[right]), %%mm0\n\t" "pfmul (%[left]), %%mm0\n\t" "movd 40(%[right]), %%mm1\n\t" "punpckldq 56(%[right]), %%mm1\n\t" "pfmul 8(%[left]), %%mm1\n\t" "pfacc %%mm1, %%mm0\n\t" "pfacc %%mm0, %%mm0\n\t" "movd %%mm0, 8(%[result])\n\t" "movd 12(%[right]), %%mm0\n\t" "punpckldq 28(%[right]), %%mm0\n\t" "pfmul (%[left]), %%mm0\n\t" "movd 44(%[right]), %%mm1\n\t" "punpckldq 60(%[right]), %%mm1\n\t" "pfmul 8(%[left]), %%mm1\n\t" "pfacc %%mm1, %%mm0\n\t" "pfacc %%mm0, %%mm0\n\t" "movd %%mm0, 12(%[result])\n" "\n\t" "add $16, %[result]\n\t" "add $16, %[left]\n\t" "decl %%ecx\n\t" "jnz 0b\n" "\n\t" "femms" : [result] "+r" (resultPtr), [left] "+r" (left), [right] "+r" (right) : : "ecx", "mm0", "mm1", "memory" ); memcpy(self->_values, result, 16 * sizeof(float)); } static void transformVectors_3DNow(OFMatrix4x4 *self, SEL _cmd, OFVector4D *vectors, size_t count) { __asm__ __volatile__ ( "test %[count], %[count]\n\t" "jz 0f\n" "\n\t" "0:\n\t" "movq (%[vectors]), %%mm0\n\t" "movq 8(%[vectors]), %%mm1\n" "\n\t" "movq %%mm0, %%mm2\n\t" "movq %%mm1, %%mm3\n\t" "pfmul (%[matrix]), %%mm2\n\t" "pfmul 8(%[matrix]), %%mm3\n\t" "pfacc %%mm3, %%mm2\n\t" "pfacc %%mm2, %%mm2\n\t" "\n\t" "movq %%mm0, %%mm3\n\t" "movq %%mm1, %%mm4\n\t" "pfmul 16(%[matrix]), %%mm3\n\t" "pfmul 24(%[matrix]), %%mm4\n\t" "pfacc %%mm4, %%mm3\n\t" "pfacc %%mm3, %%mm3\n\t" "\n\t" "punpckldq %%mm3, %%mm2\n\t" "movq %%mm2, (%[vectors])\n" "\n\t" "movq %%mm0, %%mm2\n\t" "movq %%mm1, %%mm3\n\t" "pfmul 32(%[matrix]), %%mm2\n\t" "pfmul 40(%[matrix]), %%mm3\n\t" "pfacc %%mm3, %%mm2\n\t" "pfacc %%mm2, %%mm2\n\t" "\n\t" "pfmul 48(%[matrix]), %%mm0\n\t" "pfmul 56(%[matrix]), %%mm1\n\t" "pfacc %%mm1, %%mm0\n\t" "pfacc %%mm0, %%mm0\n\t" "\n\t" "punpckldq %%mm0, %%mm2\n\t" "movq %%mm2, 8(%[vectors])\n" "\n\t" "add $16, %[vectors]\n\t" "dec %[count]\n\t" "jnz 0b\n" "\n\t" "0:\n\t" "femms" : [count] "+r" (count), [vectors] "+r" (vectors) : [matrix] "r" (self->_values) : "mm0", "mm1", "mm2", "mm3", "mm4", "memory" ); } # ifndef __clang__ # pragma GCC pop_options # endif + (void)initialize { const char *typeEncoding; if (self != [OFMatrix4x4 class]) return; # define REPLACE(selector, func) \ typeEncoding = method_getTypeEncoding( \ class_getInstanceMethod(self, selector)); \ class_replaceMethod(self, selector, (IMP)func, typeEncoding); if ([OFSystemInfo supportsSSE]) { REPLACE(@selector(transformVectors:count:), transformVectors_SSE) } else if ([OFSystemInfo supports3DNow]) { REPLACE(@selector(multiplyWithMatrix:), multiplyWithMatrix_3DNow) REPLACE(@selector(transformVectors:count:), transformVectors_3DNow) } # undef REPLACE } #endif + (OFMatrix4x4 *)identityMatrix { return [[[OFMatrix4x4 alloc] initWithValues: identityValues] autorelease]; } + (instancetype)matrixWithValues: (const float [4][4])values { return [[[self alloc] initWithValues: values] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithValues: (const float [4][4])values { self = [super init]; memcpy(_values, values, 16 * sizeof(float)); return self; } - (float (*)[4])values { return _values; } - (instancetype)copy { return [[OFMatrix4x4 alloc] initWithValues: (const float (*)[4])_values]; } - (bool)isEqual: (OFMatrix4x4 *)matrix { if (![matrix isKindOfClass: [OFMatrix4x4 class]]) return false; return (memcmp(_values, matrix->_values, 16 * sizeof(float)) == 0); } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); for (uint_fast8_t i = 0; i < 4; i++) for (uint_fast8_t j = 0; j < 4; j++) OFHashAddHash(&hash, OFBitConvertFloatToUInt32(_values[i][j])); OFHashFinalize(&hash); return hash; } - (void)multiplyWithMatrix: (OFMatrix4x4 *)matrix { float result[4][4]; for (uint_fast8_t i = 0; i < 4; i++) for (uint_fast8_t j = 0; j < 4; j++) result[i][j] = matrix->_values[i][0] * _values[0][j] + matrix->_values[i][1] * _values[1][j] + matrix->_values[i][2] * _values[2][j] + matrix->_values[i][3] * _values[3][j]; memcpy(_values, result, 16 * sizeof(float)); } - (void)translateWithVector: (OFVector3D)vector { OFMatrix4x4 *translation = [[OFMatrix4x4 alloc] initWithValues: (const float [4][4]){ { 1, 0, 0, vector.x }, { 0, 1, 0, vector.y }, { 0, 0, 1, vector.z }, { 0, 0, 0, 1 } }]; [self multiplyWithMatrix: translation]; [translation release]; } - (void)scaleWithVector: (OFVector3D)vector { OFMatrix4x4 *scale = [[OFMatrix4x4 alloc] initWithValues: (const float [4][4]){ { vector.x, 0, 0, 0 }, { 0, vector.y, 0, 0 }, { 0, 0, vector.z, 0 }, { 0, 0, 0, 1 } }]; [self multiplyWithMatrix: scale]; [scale release]; } - (OFVector4D)transformedVector: (OFVector4D)vector { OF_ALIGN(16) OFVector4D copy = vector; [self transformVectors: © count: 1]; return copy; } - (void)transformVectors: (OFVector4D *)vectors count: (size_t)count { for (size_t i = 0; i < count; i++) { OFVector4D vector = vectors[i]; vectors[i].x = _values[0][0] * vector.x + _values[0][1] * vector.y + _values[0][2] * vector.z + _values[0][3] * vector.w; vectors[i].y = _values[1][0] * vector.x + _values[1][1] * vector.y + _values[1][2] * vector.z + _values[1][3] * vector.w; vectors[i].z = _values[2][0] * vector.x + _values[2][1] * vector.y + _values[2][2] * vector.z + _values[2][3] * vector.w; vectors[i].w = _values[3][0] * vector.x + _values[3][1] * vector.y + _values[3][2] * vector.z + _values[3][3] * vector.w; } } - (OFString *)description { return [OFString stringWithFormat: @"", _values[0][0], _values[0][1], _values[0][2], _values[0][3], _values[1][0], _values[1][1], _values[1][2], _values[1][3], _values[2][0], _values[2][1], _values[2][2], _values[2][3], _values[3][0], _values[3][1], _values[3][2], _values[3][3]]; } @end objfw-1.1.6/src/OFMemoryStream.h000066400000000000000000000043651465614216400164600ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFSeekableStream.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFMemoryStream OFMemoryStream.h ObjFW/OFMemoryStream.h * * @brief A seekable stream for reading from and writing to memory. */ OF_SUBCLASSING_RESTRICTED @interface OFMemoryStream: OFSeekableStream { char *_address; size_t _size, _position; bool _writable; } /** * @brief Creates a new OFMemoryStream with the specified memory. * * @warning The memory is not copied, so it is your responsibility that the * specified memory stays alive for as long as the OFMemoryStream does! * * @param address The memory address for the stream * @param size The size of the memory at the specified address * @param writable Whether writes to memory should be allowed * @return A new autoreleased OFMemoryStream */ + (instancetype)streamWithMemoryAddress: (void *)address size: (size_t)size writable: (bool)writable; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFMemoryStream with the specified * memory. * * @warning The memory is not copied, so it is your responsibility that the * specified memory stays alive for as long as the OFMemoryStream does! * * @param address The memory address for the stream * @param size The size of the memory at the specified address * @param writable Whether writes to memory should be allowed * @return An initialized OFMemoryStream */ - (instancetype)initWithMemoryAddress: (void *)address size: (size_t)size writable: (bool)writable; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFMemoryStream.m000066400000000000000000000062751465614216400164670ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFMemoryStream.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" #import "OFWriteFailedException.h" #import "OFSeekFailedException.h" @implementation OFMemoryStream + (instancetype)streamWithMemoryAddress: (void *)address size: (size_t)size writable: (bool)writable { return [[[self alloc] initWithMemoryAddress: address size: size writable: writable] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithMemoryAddress: (void *)address size: (size_t)size writable: (bool)writable { self = [super init]; @try { if (size > SSIZE_MAX || (ssize_t)size != (OFStreamOffset)size) @throw [OFOutOfRangeException exception]; _address = address; _size = size; _writable = writable; } @catch (id e) { [self release]; @throw e; } return self; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { if (SIZE_MAX - _position < length || _position + length > _size) length = _size - _position; memcpy(buffer, _address + _position, length); _position += length; return length; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { size_t bytesWritten = length; if (!_writable) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: EBADF]; if (SIZE_MAX - _position < length || _position + length > _size) bytesWritten = _size - _position; memcpy(_address + _position, buffer, bytesWritten); _position += bytesWritten; if (bytesWritten != length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: bytesWritten errNo: EFBIG]; return bytesWritten; } - (bool)lowlevelIsAtEndOfStream { return (_position == _size); } - (OFStreamOffset)lowlevelSeekToOffset: (OFStreamOffset)offset whence: (OFSeekWhence)whence { OFStreamOffset new; switch (whence) { case OFSeekSet: new = offset; break; case OFSeekCurrent: new = (OFStreamOffset)_position + offset; break; case OFSeekEnd: new = (OFStreamOffset)_size + offset; break; default: @throw [OFInvalidArgumentException exception]; } if (new < 0 || new > (OFStreamOffset)_size) @throw [OFSeekFailedException exceptionWithStream: self offset: offset whence: whence errNo: EINVAL]; return (_position = (size_t)new); } @end objfw-1.1.6/src/OFMessagePackExtension.h000066400000000000000000000040531465614216400201060ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFMessagePackRepresentation.h" OF_ASSUME_NONNULL_BEGIN @class OFData; /** * @class OFMessagePackExtension \ * OFMessagePackExtension.h ObjFW/OFMessagePackExtension.h * * @brief A class for representing the MessagePack extension type. */ OF_SUBCLASSING_RESTRICTED @interface OFMessagePackExtension: OFObject { int8_t _type; OFData *_data; } /** * @brief The MessagePack extension type. */ @property (readonly, nonatomic) int8_t type; /** * @brief The data of the extension. */ @property (readonly, nonatomic) OFData *data; /** * @brief Creates a new OFMessagePackRepresentation with the specified type and * data. * * @param type The MessagePack extension type * @param data The data for the extension * @return A new, autoreleased OFMessagePackRepresentation */ + (instancetype)extensionWithType: (int8_t)type data: (OFData *)data; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFMessagePackRepresentation with the * specified type and data. * * @param type The MessagePack extension type * @param data The data for the extension * @return An initialized OFMessagePackRepresentation */ - (instancetype)initWithType: (int8_t)type data: (OFData *)data OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFMessagePackExtension.m000066400000000000000000000074661465614216400201260ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFMessagePackExtension.h" #import "OFData.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" @implementation OFMessagePackExtension @synthesize type = _type, data = _data; + (instancetype)extensionWithType: (int8_t)type data: (OFData *)data { return [[[self alloc] initWithType: type data: data] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithType: (int8_t)type data: (OFData *)data { self = [super init]; @try { if (data == nil || data.itemSize != 1) @throw [OFInvalidArgumentException exception]; _type = type; _data = [data copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_data release]; [super dealloc]; } - (OFData *)messagePackRepresentation { OFMutableData *ret; uint8_t prefix; size_t count = _data.count; if (count == 1) { ret = [OFMutableData dataWithCapacity: 3]; prefix = 0xD4; [ret addItem: &prefix]; [ret addItem: &_type]; } else if (count == 2) { ret = [OFMutableData dataWithCapacity: 4]; prefix = 0xD5; [ret addItem: &prefix]; [ret addItem: &_type]; } else if (count == 4) { ret = [OFMutableData dataWithCapacity: 6]; prefix = 0xD6; [ret addItem: &prefix]; [ret addItem: &_type]; } else if (count == 8) { ret = [OFMutableData dataWithCapacity: 10]; prefix = 0xD7; [ret addItem: &prefix]; [ret addItem: &_type]; } else if (count == 16) { ret = [OFMutableData dataWithCapacity: 18]; prefix = 0xD8; [ret addItem: &prefix]; [ret addItem: &_type]; } else if (count <= UINT8_MAX) { uint8_t length; ret = [OFMutableData dataWithCapacity: count + 3]; prefix = 0xC7; [ret addItem: &prefix]; length = (uint8_t)count; [ret addItem: &length]; [ret addItem: &_type]; } else if (count <= UINT16_MAX) { uint16_t length; ret = [OFMutableData dataWithCapacity: count + 4]; prefix = 0xC8; [ret addItem: &prefix]; length = OFToBigEndian16((uint16_t)count); [ret addItems: &length count: 2]; [ret addItem: &_type]; } else if (count <= UINT32_MAX) { uint32_t length; ret = [OFMutableData dataWithCapacity: count + 6]; prefix = 0xC9; [ret addItem: &prefix]; length = OFToBigEndian32((uint32_t)count); [ret addItems: &length count: 4]; [ret addItem: &_type]; } else @throw [OFOutOfRangeException exception]; [ret addItems: _data.items count: _data.count]; [ret makeImmutable]; return ret; } - (OFString *)description { return [OFString stringWithFormat: @"", _type, _data]; } - (bool)isEqual: (id)object { OFMessagePackExtension *extension; if (object == self) return true; if (![object isKindOfClass: [OFMessagePackExtension class]]) return false; extension = object; if (extension->_type != _type || ![extension->_data isEqual: _data]) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddByte(&hash, (uint8_t)_type); OFHashAddHash(&hash, _data.hash); OFHashFinalize(&hash); return hash; } - (id)copy { return [self retain]; } @end objfw-1.1.6/src/OFMessagePackRepresentation.h000066400000000000000000000023221465614216400211310ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN @class OFData; /** * @protocol OFMessagePackRepresentation \ * OFMessagePackRepresentation.h ObjFW/OFMessagePackRepresentation.h * * @brief A protocol implemented by classes that support encoding to a * MessagePack representation. */ @protocol OFMessagePackRepresentation /** * @brief The MessagePack representation of the object as OFData. */ @property (readonly, nonatomic) OFData *messagePackRepresentation; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFMethodSignature.h000066400000000000000000000066411465614216400171350ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN @class OFMutableData; /** * @class OFMethodSignature OFMethodSignature.h ObjFW/OFMethodSignature.h * * @brief A class for parsing type encodings and accessing them. */ OF_SUBCLASSING_RESTRICTED @interface OFMethodSignature: OFObject { char *_types; OFMutableData *_typesPointers, *_offsets; } /** * @brief The number of arguments of the method. */ @property (readonly, nonatomic) size_t numberOfArguments; /** * @brief The return type of the method. */ @property (readonly, nonatomic) const char *methodReturnType; /** * @brief The size of the arguments on the stack frame. * * @note This is platform-dependent! */ @property (readonly, nonatomic) size_t frameLength; /** * @brief Creates a new OFMethodSignature with the specified ObjC types. * * @param types The ObjC types of the method * @return A new, autoreleased OFMethodSignature * @throw OFInvalidFormatException The type encoding is invalid */ + (instancetype)signatureWithObjCTypes: (const char *)types; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFMethodSignature with the specified * ObjC types. * * @param types The ObjC types of the method * @return An Initialized OFMethodSignature * @throw OFInvalidFormatException The type encoding is invalid */ - (instancetype)initWithObjCTypes: (const char *)types OF_DESIGNATED_INITIALIZER; /** * @brief Returns the ObjC type for the argument at the specified index. * * @param index The index of the argument for which to return the ObjC type * @return The ObjC type for the argument at the specified index */ - (const char *)argumentTypeAtIndex: (size_t)index; /** * @brief Returns the offset on the stack frame of the argument at the * specified index. * * @note This is platform-dependent! * * @param index The index of the argument for which to return the offset * @return The offset on the stack frame of the argument at the specified index */ - (size_t)argumentOffsetAtIndex: (size_t)index; @end #ifdef __cplusplus extern "C" { #endif /** * @brief Returns the size for the specified type encoding. * * @param type The type encoding to return the size for * @return The size for the specified type encoding * @throw OFInvalidFormatException The type encoding is invalid */ extern size_t OFSizeOfTypeEncoding(const char *type); /** * @brief Returns the alignment for the specified type encoding. * * @param type The type encoding to return the alignment for * @return The alignment for the specified type encoding * @throw OFInvalidFormatException The type encoding is invalid */ extern size_t OFAlignmentOfTypeEncoding(const char *type); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFMethodSignature.m000066400000000000000000000321201465614216400171310ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFMethodSignature.h" #import "OFData.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "macros.h" static size_t alignmentOfEncoding(const char **type, size_t *length, bool inStruct); static size_t sizeOfEncoding(const char **type, size_t *length); static size_t alignmentOfArray(const char **type, size_t *length) { size_t alignment; OFAssert(*length > 0); (*type)++; (*length)--; while (*length > 0 && OFASCIIIsDigit(**type)) { (*type)++; (*length)--; } alignment = alignmentOfEncoding(type, length, true); if (*length == 0 || **type != ']') @throw [OFInvalidFormatException exception]; (*type)++; (*length)--; return alignment; } static size_t alignmentOfStruct(const char **type, size_t *length) { size_t alignment = 0; #if defined(OF_POWERPC) && defined(OF_MACOS) bool first = true; #endif OFAssert(*length > 0); (*type)++; (*length)--; /* Skip name */ while (*length > 0 && **type != '=') { (*type)++; (*length)--; } if (*length == 0) @throw [OFInvalidFormatException exception]; /* Skip '=' */ (*type)++; (*length)--; while (*length > 0 && **type != '}') { size_t fieldAlignment = alignmentOfEncoding(type, length, true); #if defined(OF_POWERPC) && defined(OF_MACOS) if (!first && fieldAlignment > 4) fieldAlignment = 4; first = false; #endif if (fieldAlignment > alignment) alignment = fieldAlignment; } if (*length == 0 || **type != '}') @throw [OFInvalidFormatException exception]; (*type)++; (*length)--; return alignment; } static size_t alignmentOfUnion(const char **type, size_t *length) { size_t alignment = 0; OFAssert(*length > 0); (*type)++; (*length)--; /* Skip name */ while (*length > 0 && **type != '=') { (*type)++; (*length)--; } if (*length == 0) @throw [OFInvalidFormatException exception]; /* Skip '=' */ (*type)++; (*length)--; while (*length > 0 && **type != ')') { size_t fieldAlignment = alignmentOfEncoding(type, length, true); if (fieldAlignment > alignment) alignment = fieldAlignment; } if (*length == 0 || **type != ')') @throw [OFInvalidFormatException exception]; (*type)++; (*length)--; return alignment; } static size_t #if defined(__clang__) && __has_attribute(__optnone__) && \ __clang_major__ == 3 && __clang_minor__ <= 7 /* Work around an ICE in Clang 3.7.0 on Windows/x86 */ __attribute__((__optnone__)) #endif alignmentOfEncoding(const char **type, size_t *length, bool inStruct) { size_t alignment; if (*length == 0) @throw [OFInvalidFormatException exception]; if (**type == 'r') { (*type)++; (*length)--; if (*length == 0) @throw [OFInvalidFormatException exception]; } switch (**type) { case 'c': case 'C': alignment = OF_ALIGNOF(char); break; case 'i': case 'I': alignment = OF_ALIGNOF(int); break; case 's': case 'S': alignment = OF_ALIGNOF(short); break; case 'l': case 'L': alignment = OF_ALIGNOF(long); break; case 'q': case 'Q': #if defined(OF_X86) && !defined(OF_WINDOWS) if (inStruct) alignment = 4; else #endif alignment = OF_ALIGNOF(long long); break; #ifdef __SIZEOF_INT128__ case 't': case 'T': alignment = __extension__ OF_ALIGNOF(__int128); break; #endif case 'f': alignment = OF_ALIGNOF(float); break; case 'd': #if defined(OF_X86) && !defined(OF_WINDOWS) if (inStruct) alignment = 4; else #endif alignment = OF_ALIGNOF(double); break; case 'D': #if defined(OF_X86) && !defined(OF_WINDOWS) if (inStruct) alignment = 4; else #endif alignment = OF_ALIGNOF(long double); break; case 'B': alignment = OF_ALIGNOF(_Bool); break; case 'v': alignment = 0; break; case '*': alignment = OF_ALIGNOF(char *); break; case '@': alignment = OF_ALIGNOF(id); break; case '#': alignment = OF_ALIGNOF(Class); break; case ':': alignment = OF_ALIGNOF(SEL); break; case '[': return alignmentOfArray(type, length); case '{': return alignmentOfStruct(type, length); case '(': return alignmentOfUnion(type, length); case '^': /* Just to skip over the rest */ (*type)++; (*length)--; alignmentOfEncoding(type, length, false); return OF_ALIGNOF(void *); #ifndef __STDC_NO_COMPLEX__ case 'j': (*type)++; (*length)--; if (*length == 0) @throw [OFInvalidFormatException exception]; switch (**type) { case 'f': alignment = OF_ALIGNOF(float _Complex); break; case 'd': # if defined(OF_X86) && !defined(OF_WINDOWS) if (inStruct) alignment = 4; else # endif alignment = OF_ALIGNOF(double _Complex); break; case 'D': alignment = OF_ALIGNOF(long double _Complex); break; default: @throw [OFInvalidFormatException exception]; } break; #endif default: @throw [OFInvalidFormatException exception]; } (*type)++; (*length)--; return alignment; } static size_t sizeOfArray(const char **type, size_t *length) { size_t count = 0; size_t size; OFAssert(*length > 0); (*type)++; (*length)--; while (*length > 0 && OFASCIIIsDigit(**type)) { count = count * 10 + **type - '0'; (*type)++; (*length)--; } if (count == 0) @throw [OFInvalidFormatException exception]; size = sizeOfEncoding(type, length); if (*length == 0 || **type != ']') @throw [OFInvalidFormatException exception]; (*type)++; (*length)--; if (SIZE_MAX / count < size) @throw [OFOutOfRangeException exception]; return count * size; } static size_t sizeOfStruct(const char **type, size_t *length) { size_t size = 0; const char *typeCopy = *type; size_t lengthCopy = *length; size_t alignment = alignmentOfStruct(&typeCopy, &lengthCopy); #if defined(OF_POWERPC) && defined(OF_MACOS) bool first = true; #endif OFAssert(*length > 0); (*type)++; (*length)--; /* Skip name */ while (*length > 0 && **type != '=') { (*type)++; (*length)--; } if (*length == 0) @throw [OFInvalidFormatException exception]; /* Skip '=' */ (*type)++; (*length)--; while (*length > 0 && **type != '}') { size_t fieldSize, fieldAlignment; typeCopy = *type; lengthCopy = *length; fieldSize = sizeOfEncoding(type, length); fieldAlignment = alignmentOfEncoding(&typeCopy, &lengthCopy, true); #if defined(OF_POWERPC) && defined(OF_MACOS) if (!first && fieldAlignment > 4) fieldAlignment = 4; first = false; #endif if (size % fieldAlignment != 0) { size_t padding = fieldAlignment - (size % fieldAlignment); if (SIZE_MAX - size < padding) @throw [OFOutOfRangeException exception]; size += padding; } if (SIZE_MAX - size < fieldSize) @throw [OFOutOfRangeException exception]; size += fieldSize; } if (*length == 0 || **type != '}') @throw [OFInvalidFormatException exception]; (*type)++; (*length)--; if (size % alignment != 0) { size_t padding = alignment - (size % alignment); if (SIZE_MAX - size < padding) @throw [OFOutOfRangeException exception]; size += padding; } return size; } static size_t sizeOfUnion(const char **type, size_t *length) { size_t size = 0; OFAssert(*length > 0); (*type)++; (*length)--; /* Skip name */ while (*length > 0 && **type != '=') { (*type)++; (*length)--; } if (*length == 0) @throw [OFInvalidFormatException exception]; /* Skip '=' */ (*type)++; (*length)--; while (*length > 0 && **type != ')') { size_t fieldSize = sizeOfEncoding(type, length); if (fieldSize > size) size = fieldSize; } if (*length == 0 || **type != ')') @throw [OFInvalidFormatException exception]; (*type)++; (*length)--; return size; } static size_t #if defined(__clang__) && __has_attribute(__optnone__) && \ __clang_major__ == 3 && __clang_minor__ <= 7 /* Work around an ICE in Clang 3.7.0 on Windows/x86 */ __attribute__((__optnone__)) #endif sizeOfEncoding(const char **type, size_t *length) { size_t size; if (*length == 0) @throw [OFInvalidFormatException exception]; if (**type == 'r') { (*type)++; (*length)--; if (*length == 0) @throw [OFInvalidFormatException exception]; } switch (**type) { case 'c': case 'C': size = sizeof(char); break; case 'i': case 'I': size = sizeof(int); break; case 's': case 'S': size = sizeof(short); break; case 'l': case 'L': size = sizeof(long); break; case 'q': case 'Q': size = sizeof(long long); break; #ifdef __SIZEOF_INT128__ case 't': case 'T': size = __extension__ sizeof(__int128); break; #endif case 'f': size = sizeof(float); break; case 'd': size = sizeof(double); break; case 'D': size = sizeof(long double); break; case 'B': size = sizeof(_Bool); break; case 'v': size = 0; break; case '*': size = sizeof(char *); break; case '@': size = sizeof(id); break; case '#': size = sizeof(Class); break; case ':': size = sizeof(SEL); break; case '[': return sizeOfArray(type, length); case '{': return sizeOfStruct(type, length); case '(': return sizeOfUnion(type, length); case '^': /* Just to skip over the rest */ (*type)++; (*length)--; sizeOfEncoding(type, length); return sizeof(void *); #ifndef __STDC_NO_COMPLEX__ case 'j': (*type)++; (*length)--; if (*length == 0) @throw [OFInvalidFormatException exception]; switch (**type) { case 'f': size = sizeof(float _Complex); break; case 'd': size = sizeof(double _Complex); break; case 'D': size = sizeof(long double _Complex); break; default: @throw [OFInvalidFormatException exception]; } break; #endif default: @throw [OFInvalidFormatException exception]; } (*type)++; (*length)--; return size; } size_t OFSizeOfTypeEncoding(const char *type) { size_t length = strlen(type); size_t ret = sizeOfEncoding(&type, &length); if (length > 0) @throw [OFInvalidFormatException exception]; return ret; } size_t OFAlignmentOfTypeEncoding(const char *type) { size_t length = strlen(type); size_t ret = alignmentOfEncoding(&type, &length, false); if (length > 0) @throw [OFInvalidFormatException exception]; return ret; } @implementation OFMethodSignature + (instancetype)signatureWithObjCTypes: (const char*)types { return [[[self alloc] initWithObjCTypes: types] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithObjCTypes: (const char *)types { self = [super init]; @try { size_t length; const char *last; if (types == NULL) @throw [OFInvalidArgumentException exception]; length = strlen(types); if (length == 0) @throw [OFInvalidFormatException exception]; _types = OFAllocMemory(length + 1, 1); memcpy(_types, types, length); _typesPointers = [[OFMutableData alloc] initWithItemSize: sizeof(char *)]; _offsets = [[OFMutableData alloc] initWithItemSize: sizeof(size_t)]; last = _types; for (size_t i = 0; i < length; i++) { if (OFASCIIIsDigit(_types[i])) { size_t offset = _types[i] - '0'; if (last == _types + i) @throw [OFInvalidFormatException exception]; _types[i] = '\0'; [_typesPointers addItem: &last]; i++; for (; i < length && OFASCIIIsDigit(_types[i]); i++) offset = offset * 10 + _types[i] - '0'; [_offsets addItem: &offset]; last = _types + i; i--; } else if (_types[i] == '{') { size_t depth = 0; for (; i < length; i++) { if (_types[i] == '{') depth++; else if (_types[i] == '}') { if (--depth == 0) break; } } if (depth != 0) @throw [OFInvalidFormatException exception]; } else if (_types[i] == '(') { size_t depth = 0; for (; i < length; i++) { if (_types[i] == '(') depth++; else if (_types[i] == ')') { if (--depth == 0) break; } } if (depth != 0) @throw [OFInvalidFormatException exception]; } } if (last < _types + length) @throw [OFInvalidFormatException exception]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { OFFreeMemory(_types); [_typesPointers release]; [_offsets release]; [super dealloc]; } - (size_t)numberOfArguments { return _typesPointers.count - 1; } - (const char *)methodReturnType { return *(const char **)_typesPointers.firstItem; } - (size_t)frameLength { return *(size_t *)_offsets.firstItem; } - (const char *)argumentTypeAtIndex: (size_t)idx { return *(const char **)[_typesPointers itemAtIndex: idx + 1]; } - (size_t)argumentOffsetAtIndex: (size_t)idx { return *(size_t *)[_offsets itemAtIndex: idx + 1]; } @end objfw-1.1.6/src/OFMutableArchiveEntry.h000066400000000000000000000045671465614216400177550ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFArchiveEntry.h" OF_ASSUME_NONNULL_BEGIN /** * @protocol OFMutableArchiveEntry OFArchiveEntry.h ObjFW/OFArchiveEntry.h * * @brief A class which represents a mutable entry in an archive. */ @protocol OFMutableArchiveEntry /** * @brief The file name of the entry. */ @property (readwrite, copy, nonatomic) OFString *fileName; /** * @brief The compressed size of the entry's file. */ @property (readwrite, nonatomic) unsigned long long compressedSize; /** * @brief The uncompressed size of the entry's file. */ @property (readwrite, nonatomic) unsigned long long uncompressedSize; @optional /** * @brief The modification date of the file. */ @property (readwrite, retain, nonatomic) OFDate *modificationDate; /** * @brief The comment of the entry's file. */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *fileComment; /** * @brief The POSIX permissions of the file. */ @property OF_NULLABLE_PROPERTY (readwrite, retain, nonatomic) OFNumber *POSIXPermissions; /** * @brief The file owner's account ID. */ @property OF_NULLABLE_PROPERTY (readwrite, retain, nonatomic) OFNumber *ownerAccountID; /** * @brief The file owner's group account ID. */ @property OF_NULLABLE_PROPERTY (readwrite, retain, nonatomic) OFNumber *groupOwnerAccountID; /** * @brief The file owner's account name. */ @property OF_NULLABLE_PROPERTY (readwrite, retain, nonatomic) OFString *ownerAccountName; /** * @brief The file owner's group account name. */ @property OF_NULLABLE_PROPERTY (readwrite, retain, nonatomic) OFString *groupOwnerAccountName; @end OF_ASSUME_NONNULL_END #import "OFMutableArchiveEntry.h" objfw-1.1.6/src/OFMutableArray.h000066400000000000000000000160641465614216400164230ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFArray.h" OF_ASSUME_NONNULL_BEGIN /** @file */ #ifdef OF_HAVE_BLOCKS /** * @brief A block for replacing values in an OFMutableArray. * * @param object The object to replace * @param index The index of the object to replace * @return The object to replace the object with */ typedef id _Nonnull (^OFArrayReplaceBlock)(id object, size_t index); #endif /** * @class OFMutableArray OFArray.h ObjFW/OFArray.h * * @brief An abstract class for storing, adding and removing objects in an * array. * * @note Subclasses must implement @ref insertObject:atIndex:, * @ref replaceObjectAtIndex:withObject:, @ref removeObjectAtIndex: as * well as all methods of @ref OFArray that need to be implemented. */ @interface OFMutableArray OF_GENERIC(ObjectType): OFArray OF_GENERIC(ObjectType) #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # define ObjectType id #endif /** * @brief Creates a new OFMutableArray with enough memory to hold the specified * number of objects. * * @param capacity The initial capacity for the OFMutableArray * @return A new autoreleased OFMutableArray */ + (instancetype)arrayWithCapacity: (size_t)capacity; /** * @brief Initializes an OFMutableArray with no objects. * * @return An initialized OFMutableArray */ - (instancetype)init OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated OFMutableArray with enough memory to * hold the specified number of objects. * * @param capacity The initial capacity for the OFMutableArray * @return An initialized OFMutableArray */ - (instancetype)initWithCapacity: (size_t)capacity OF_DESIGNATED_INITIALIZER; /** * @brief Adds an object to the end of the array. * * @param object An object to add */ - (void)addObject: (ObjectType)object; /** * @brief Adds the objects from the specified OFArray to the end of the array. * * @param array An array of objects to add */ - (void)addObjectsFromArray: (OFArray OF_GENERIC(ObjectType) *)array; /** * @brief Inserts an object to the OFArray at the specified index. * * @param object An object to add * @param index The index where the object should be inserted */ - (void)insertObject: (ObjectType)object atIndex: (size_t)index; /** * @brief Inserts the objects from the specified OFArray at the specified index. * * @param array An array of objects * @param index The index where the objects should be inserted */ - (void)insertObjectsFromArray: (OFArray OF_GENERIC(ObjectType) *)array atIndex: (size_t)index; /** * @brief Replaces all objects equivalent to the specified object with the * other specified object. * * @param oldObject The object to replace * @param newObject The replacement object */ - (void)replaceObject: (ObjectType)oldObject withObject: (ObjectType)newObject; /** * @brief Replaces the object at the specified index with the specified object. * * @param index The index of the object to replace * @param object The replacement object */ - (void)replaceObjectAtIndex: (size_t)index withObject: (ObjectType)object; /** * @brief Replaces the object at the specified index with the specified object. * * This method is the same as @ref replaceObjectAtIndex:withObject:. * * This method is also used by the subscripting syntax. * * @param index The index of the object to replace * @param object The replacement object */ - (void)setObject: (ObjectType)object atIndexedSubscript: (size_t)index; /** * @brief Replaces all objects that have the same address as the specified * object with the other specified object. * * @param oldObject The object to replace * @param newObject The replacement object */ - (void)replaceObjectIdenticalTo: (ObjectType)oldObject withObject: (ObjectType)newObject; /** * @brief Removes all objects equivalent to the specified object. * * @param object The object to remove */ - (void)removeObject: (ObjectType)object; /** * @brief Removes all objects that have the same address as the specified * object. * * @param object The object to remove */ - (void)removeObjectIdenticalTo: (ObjectType)object; /** * @brief Removes the object at the specified index. * * @param index The index of the object to remove */ - (void)removeObjectAtIndex: (size_t)index; /** * @brief Removes the objects in the specified range. * * @param range The range of the objects to remove */ - (void)removeObjectsInRange: (OFRange)range; /** * @brief Removes the last object. */ - (void)removeLastObject; /** * @brief Removes all objects. */ - (void)removeAllObjects; #ifdef OF_HAVE_BLOCKS /** * @brief Replaces each object with the object returned by the block. * * @param block The block which returns a new object for each object */ - (void)replaceObjectsUsingBlock: (OFArrayReplaceBlock)block; #endif /** * @brief Exchange the objects at the specified indices. * * @param index1 The index of the first object to exchange * @param index2 The index of the second object to exchange */ - (void)exchangeObjectAtIndex: (size_t)index1 withObjectAtIndex: (size_t)index2; /** * @brief Sorts the array in ascending order. */ - (void)sort; /** * @brief Sorts the array using the specified selector and options. * * @param selector The selector to use to sort the array. It's signature * should be the same as that of -[compare:]. * @param options The options to use when sorting the array */ - (void)sortUsingSelector: (SEL)selector options: (OFArraySortOptions)options; /** * @brief Sorts the array using the specified function and options. * * @param compare The function to use to sort the array * @param context Context passed to the function to compare * @param options The options to use when sorting the array */ - (void)sortUsingFunction: (OFCompareFunction)compare context: (nullable void *)context options: (OFArraySortOptions)options; #ifdef OF_HAVE_BLOCKS /** * @brief Sorts the array using the specified comparator and options. * * @param comparator The comparator to use to sort the array * @param options The options to use when sorting the array */ - (void)sortUsingComparator: (OFComparator)comparator options: (OFArraySortOptions)options; #endif /** * @brief Reverts the order of the objects in the array. */ - (void)reverse; /** * @brief Converts the mutable array to an immutable array. */ - (void)makeImmutable; #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # undef ObjectType #endif @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFMutableArray.m000066400000000000000000000216401465614216400164240ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "OFMutableArray.h" #import "OFConcreteMutableArray.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" static struct { Class isa; } placeholder; @interface OFPlaceholderMutableArray: OFMutableArray @end static void quicksort(OFMutableArray *array, size_t left, size_t right, OFCompareFunction compare, void *context, OFArraySortOptions options) { OFComparisonResult ascending, descending; if (options & OFArraySortDescending) { ascending = OFOrderedDescending; descending = OFOrderedAscending; } else { ascending = OFOrderedAscending; descending = OFOrderedDescending; } while (left < right) { size_t i = left; size_t j = right - 1; id pivot = [array objectAtIndex: right]; do { while (compare([array objectAtIndex: i], pivot, context) != descending && i < right) i++; while (compare([array objectAtIndex: j], pivot, context) != ascending && j > left) j--; if (i < j) [array exchangeObjectAtIndex: i withObjectAtIndex: j]; } while (i < j); if (compare([array objectAtIndex: i], pivot, context) == descending) [array exchangeObjectAtIndex: i withObjectAtIndex: right]; if (i > 0) quicksort(array, left, i - 1, compare, context, options); left = i + 1; } } @implementation OFPlaceholderMutableArray #ifdef __clang__ /* We intentionally don't call into super, so silence the warning. */ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunknown-pragmas" # pragma clang diagnostic ignored "-Wobjc-designated-initializers" #endif - (instancetype)init { return (id)[[OFConcreteMutableArray alloc] init]; } - (instancetype)initWithCapacity: (size_t)capacity { return (id)[[OFConcreteMutableArray alloc] initWithCapacity: capacity]; } - (instancetype)initWithObject: (id)object { return (id)[[OFConcreteMutableArray alloc] initWithObject: object]; } - (instancetype)initWithObjects: (id)firstObject, ... { id ret; va_list arguments; va_start(arguments, firstObject); ret = [[OFConcreteMutableArray alloc] initWithObject: firstObject arguments: arguments]; va_end(arguments); return ret; } - (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments { return (id)[[OFConcreteMutableArray alloc] initWithObject: firstObject arguments: arguments]; } - (instancetype)initWithArray: (OFArray *)array { return (id)[[OFConcreteMutableArray alloc] initWithArray: array]; } - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { return (id)[[OFConcreteMutableArray alloc] initWithObjects: objects count: count]; } #ifdef __clang__ # pragma clang diagnostic pop #endif OF_SINGLETON_METHODS @end @implementation OFMutableArray + (void)initialize { if (self == [OFMutableArray class]) object_setClass((id)&placeholder, [OFPlaceholderMutableArray class]); } + (instancetype)alloc { if (self == [OFMutableArray class]) return (id)&placeholder; return [super alloc]; } + (instancetype)arrayWithCapacity: (size_t)capacity { return [[[self alloc] initWithCapacity: capacity] autorelease]; } - (instancetype)init { return [super init]; } #ifdef __clang__ /* We intentionally don't call into super, so silence the warning. */ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunknown-pragmas" # pragma clang diagnostic ignored "-Wobjc-designated-initializers" #endif - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { OF_INVALID_INIT_METHOD } - (instancetype)initWithCapacity: (size_t)capacity { OF_INVALID_INIT_METHOD } #ifdef __clang__ # pragma clang diagnostic pop #endif - (id)copy { return [[OFArray alloc] initWithArray: self]; } - (void)addObject: (id)object { [self insertObject: object atIndex: self.count]; } - (void)addObjectsFromArray: (OFArray *)array { [self insertObjectsFromArray: array atIndex: self.count]; } - (void)insertObject: (id)object atIndex: (size_t)idx { OF_UNRECOGNIZED_SELECTOR } - (void)insertObjectsFromArray: (OFArray *)array atIndex: (size_t)idx { size_t i = 0; for (id object in array) [self insertObject: object atIndex: idx + i++]; } - (void)replaceObjectAtIndex: (size_t)idx withObject: (id)object { OF_UNRECOGNIZED_SELECTOR } - (void)setObject: (id)object atIndexedSubscript: (size_t)idx { [self replaceObjectAtIndex: idx withObject: object]; } - (void)replaceObject: (id)oldObject withObject: (id)newObject { size_t count; if (oldObject == nil || newObject == nil) @throw [OFInvalidArgumentException exception]; count = self.count; for (size_t i = 0; i < count; i++) if ([[self objectAtIndex: i] isEqual: oldObject]) [self replaceObjectAtIndex: i withObject: newObject]; } - (void)replaceObjectIdenticalTo: (id)oldObject withObject: (id)newObject { size_t count; if (oldObject == nil || newObject == nil) @throw [OFInvalidArgumentException exception]; count = self.count; for (size_t i = 0; i < count; i++) if ([self objectAtIndex: i] == oldObject) [self replaceObjectAtIndex: i withObject: newObject]; } - (void)removeObjectAtIndex: (size_t)idx { OF_UNRECOGNIZED_SELECTOR } - (void)removeObject: (id)object { size_t count; if (object == nil) @throw [OFInvalidArgumentException exception]; count = self.count; for (size_t i = 0; i < count; i++) { if ([[self objectAtIndex: i] isEqual: object]) { [self removeObjectAtIndex: i]; i--; count--; continue; } } } - (void)removeObjectIdenticalTo: (id)object { size_t count; if (object == nil) @throw [OFInvalidArgumentException exception]; count = self.count; for (size_t i = 0; i < count; i++) { if ([self objectAtIndex: i] == object) { [self removeObjectAtIndex: i]; i--; count--; continue; } } } - (void)removeObjectsInRange: (OFRange)range { for (size_t i = 0; i < range.length; i++) [self removeObjectAtIndex: range.location]; } - (void)removeLastObject { size_t count = self.count; if (count == 0) return; [self removeObjectAtIndex: count - 1]; } - (void)removeAllObjects { [self removeObjectsInRange: OFMakeRange(0, self.count)]; } #ifdef OF_HAVE_BLOCKS - (void)replaceObjectsUsingBlock: (OFArrayReplaceBlock)block { [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { id new = block(object, idx); if (new != object) [self replaceObjectAtIndex: idx withObject: new]; }]; } #endif - (void)exchangeObjectAtIndex: (size_t)idx1 withObjectAtIndex: (size_t)idx2 { id object1 = [self objectAtIndex: idx1]; id object2 = [self objectAtIndex: idx2]; [object1 retain]; @try { [self replaceObjectAtIndex: idx1 withObject: object2]; [self replaceObjectAtIndex: idx2 withObject: object1]; } @finally { [object1 release]; } } - (void)sort { [self sortUsingSelector: @selector(compare:) options: 0]; } static OFComparisonResult selectorCompare(id left, id right, void *context) { SEL selector = context; OFComparisonResult (*comparator)(id, SEL, id) = (OFComparisonResult (*)(id, SEL, id)) [left methodForSelector: selector]; return comparator(left, selector, right); } - (void)sortUsingSelector: (SEL)selector options: (OFArraySortOptions)options { size_t count = self.count; if (count == 0 || count == 1) return; quicksort(self, 0, count - 1, selectorCompare, (void *)selector, options); } - (void)sortUsingFunction: (OFCompareFunction)compare context: (void *)context options: (OFArraySortOptions)options { size_t count = self.count; if (count == 0 || count == 1) return; quicksort(self, 0, count - 1, compare, context, options); } #ifdef OF_HAVE_BLOCKS static OFComparisonResult blockCompare(id left, id right, void *context) { OFComparator block = (OFComparator)context; return block(left, right); } - (void)sortUsingComparator: (OFComparator)comparator options: (OFArraySortOptions)options { size_t count = self.count; if (count == 0 || count == 1) return; quicksort(self, 0, count - 1, blockCompare, comparator, options); } #endif - (void)reverse { size_t i, j, count = self.count; if (count == 0 || count == 1) return; for (i = 0, j = count - 1; i < j; i++, j--) [self exchangeObjectAtIndex: i withObjectAtIndex: j]; } - (void)makeImmutable { } @end objfw-1.1.6/src/OFMutableData.h000066400000000000000000000120731465614216400162120ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFData.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFMutableData OFData.h ObjFW/OFData.h * * @brief A class for storing and manipulating arbitrary data in an array. */ @interface OFMutableData: OFData /** * @brief All items of the OFMutableData as a C array. * * @warning The pointer is only valid until the OFMutableData is changed! * * Modifying the returned array directly is allowed and will change the contents * of the data. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) void *mutableItems OF_RETURNS_INNER_POINTER; /** * @brief The first item of the OFMutableData or `NULL`. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) void *mutableFirstItem OF_RETURNS_INNER_POINTER; /** * @brief The last item of the OFMutableData or `NULL`. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) void *mutableLastItem OF_RETURNS_INNER_POINTER; /** * @brief Creates a new OFMutableData with enough memory to hold the specified * number of items which all have an item size of 1. * * @param capacity The initial capacity for the OFMutableData * @return A new autoreleased OFMutableData */ + (instancetype)dataWithCapacity: (size_t)capacity; /** * @brief Creates a new OFMutableData with enough memory to hold the specified * number of items which all have the same specified size. * * @param itemSize The size of a single element in the OFMutableData * @param capacity The initial capacity for the OFMutableData * @return A new autoreleased OFMutableData */ + (instancetype)dataWithItemSize: (size_t)itemSize capacity: (size_t)capacity; /** * @brief Initializes an already allocated OFMutableData with enough memory to * hold the the specified number of items which all have an item size of * 1. * * @param capacity The initial capacity for the OFMutableData * @return An initialized OFMutableData */ - (instancetype)initWithCapacity: (size_t)capacity; /** * @brief Initializes an already allocated OFMutableData with enough memory to * hold the the specified number of items which all have the same * specified size. * * @param itemSize The size of a single element in the OFMutableData * @param capacity The initial capacity for the OFMutableData * @return An initialized OFMutableData */ - (instancetype)initWithItemSize: (size_t)itemSize capacity: (size_t)capacity; /** * @brief Returns a specific item of the OFMutableData. * * Modifying the returned item directly is allowed and will change the contents * of the data. * * @param index The number of the item to return * @return The specified item of the OFMutableData */ - (void *)mutableItemAtIndex: (size_t)index OF_RETURNS_INNER_POINTER; /** * @brief Adds an item to the OFMutableData. * * @param item A pointer to an arbitrary item */ - (void)addItem: (const void *)item; /** * @brief Adds an item to the OFMutableData at the specified index. * * @param item A pointer to an arbitrary item * @param index The index where the item should be added */ - (void)insertItem: (const void *)item atIndex: (size_t)index; /** * @brief Adds items from a C array to the OFMutableData. * * @param items A C array containing the items to add * @param count The number of items to add */ - (void)addItems: (const void *)items count: (size_t)count; /** * @brief Adds items from a C array to the OFMutableData at the specified index. * * @param items A C array containing the items to add * @param index The index where the items should be added * @param count The number of items to add */ - (void)insertItems: (const void *)items atIndex: (size_t)index count: (size_t)count; /** * @brief Increases the count by the specified number. The new items are all * filled with null bytes. * * @param count The count by which to increase the count */ - (void)increaseCountBy: (size_t)count; /** * @brief Removes the item at the specified index. * * @param index The index of the item to remove */ - (void)removeItemAtIndex: (size_t)index; /** * @brief Removes the specified amount of items at the specified index. * * @param range The range of items to remove */ - (void)removeItemsInRange: (OFRange)range; /** * @brief Removes the last item. */ - (void)removeLastItem; /** * @brief Removes all items. */ - (void)removeAllItems; /** * @brief Converts the mutable data to an immutable data. */ - (void)makeImmutable; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFMutableData.m000066400000000000000000000146711465614216400162250ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #include #import "OFMutableData.h" #import "OFConcreteMutableData.h" #import "OFOutOfRangeException.h" static struct { Class isa; } placeholder; @interface OFPlaceholderMutableData: OFMutableData @end @implementation OFPlaceholderMutableData - (instancetype)init { return (id)[[OFConcreteMutableData alloc] init]; } - (instancetype)initWithItemSize: (size_t)itemSize { return (id)[[OFConcreteMutableData alloc] initWithItemSize: itemSize]; } - (instancetype)initWithItems: (const void *)items count: (size_t)count { return (id)[[OFConcreteMutableData alloc] initWithItems: items count: count]; } - (instancetype)initWithItems: (const void *)items count: (size_t)count itemSize: (size_t)itemSize { return (id)[[OFConcreteMutableData alloc] initWithItems: items count: count itemSize: itemSize]; } - (instancetype)initWithItemsNoCopy: (void *)items count: (size_t)count freeWhenDone: (bool)freeWhenDone { return (id)[[OFConcreteMutableData alloc] initWithItemsNoCopy: items count: count freeWhenDone: freeWhenDone]; } - (instancetype)initWithItemsNoCopy: (void *)items count: (size_t)count itemSize: (size_t)itemSize freeWhenDone: (bool)freeWhenDone { return (id)[[OFConcreteMutableData alloc] initWithItemsNoCopy: items count: count itemSize: itemSize freeWhenDone: freeWhenDone]; } #ifdef OF_HAVE_FILES - (instancetype)initWithContentsOfFile: (OFString *)path { return (id)[[OFConcreteMutableData alloc] initWithContentsOfFile: path]; } #endif - (instancetype)initWithContentsOfIRI: (OFIRI *)IRI { return (id)[[OFConcreteMutableData alloc] initWithContentsOfIRI: IRI]; } - (instancetype)initWithStringRepresentation: (OFString *)string { return (id)[[OFConcreteMutableData alloc] initWithStringRepresentation: string]; } - (instancetype)initWithBase64EncodedString: (OFString *)string { return (id)[[OFConcreteMutableData alloc] initWithBase64EncodedString: string]; } - (instancetype)initWithCapacity: (size_t)capacity { return (id)[[OFConcreteMutableData alloc] initWithCapacity: capacity]; } - (instancetype)initWithItemSize: (size_t)itemSize capacity: (size_t)capacity { return (id)[[OFConcreteMutableData alloc] initWithItemSize: itemSize capacity: capacity]; } OF_SINGLETON_METHODS @end @implementation OFMutableData + (void)initialize { if (self == [OFMutableData class]) object_setClass((id)&placeholder, [OFPlaceholderMutableData class]); } + (instancetype)alloc { if (self == [OFMutableData class]) return (id)&placeholder; return [super alloc]; } + (instancetype)dataWithItemSize: (size_t)itemSize { return [[[self alloc] initWithItemSize: itemSize] autorelease]; } + (instancetype)dataWithCapacity: (size_t)capacity { return [[[self alloc] initWithCapacity: capacity] autorelease]; } + (instancetype)dataWithItemSize: (size_t)itemSize capacity: (size_t)capacity { return [[[self alloc] initWithItemSize: itemSize capacity: capacity] autorelease]; } - (instancetype)initWithItemSize: (size_t)itemSize { return [self initWithItemSize: 1 capacity: 0]; } - (instancetype)initWithCapacity: (size_t)capacity { return [self initWithItemSize: 1 capacity: capacity]; } - (instancetype)initWithItemSize: (size_t)itemSize capacity: (size_t)capacity { OF_INVALID_INIT_METHOD } - (instancetype)initWithItemsNoCopy: (void *)items count: (size_t)count itemSize: (size_t)itemSize freeWhenDone: (bool)freeWhenDone { self = [self initWithItems: items count: count itemSize: itemSize]; if (freeWhenDone) OFFreeMemory(items); return self; } - (void *)mutableItems { OF_UNRECOGNIZED_SELECTOR } - (void *)mutableItemAtIndex: (size_t)idx { if (idx >= self.count) @throw [OFOutOfRangeException exception]; return (unsigned char *)self.mutableItems + idx * self.itemSize; } - (void *)mutableFirstItem { void *mutableItems = self.mutableItems; if (mutableItems == NULL || self.count == 0) return NULL; return mutableItems; } - (void *)mutableLastItem { unsigned char *mutableItems = self.mutableItems; size_t count = self.count; if (mutableItems == NULL || count == 0) return NULL; return mutableItems + (count - 1) * self.itemSize; } - (OFData *)subdataWithRange: (OFRange)range { size_t itemSize; if (range.length > SIZE_MAX - range.location || range.location + range.length > self.count) @throw [OFOutOfRangeException exception]; itemSize = self.itemSize; return [OFData dataWithItems: (unsigned char *)self.mutableItems + (range.location * itemSize) count: range.length itemSize: itemSize]; } - (void)addItem: (const void *)item { [self insertItems: item atIndex: self.count count: 1]; } - (void)insertItem: (const void *)item atIndex: (size_t)idx { [self insertItems: item atIndex: idx count: 1]; } - (void)addItems: (const void *)items count: (size_t)count { [self insertItems: items atIndex: self.count count: count]; } - (void)insertItems: (const void *)items atIndex: (size_t)idx count: (size_t)count { OF_UNRECOGNIZED_SELECTOR } - (void)increaseCountBy: (size_t)count { OF_UNRECOGNIZED_SELECTOR } - (void)removeItemAtIndex: (size_t)idx { [self removeItemsInRange: OFMakeRange(idx, 1)]; } - (void)removeItemsInRange: (OFRange)range { OF_UNRECOGNIZED_SELECTOR } - (void)removeLastItem { size_t count = self.count; if (count == 0) return; [self removeItemsInRange: OFMakeRange(count - 1, 1)]; } - (void)removeAllItems { [self removeItemsInRange: OFMakeRange(0, self.count)]; } - (id)copy { return [[OFData alloc] initWithItems: self.mutableItems count: self.count itemSize: self.itemSize]; } - (void)makeImmutable { } @end objfw-1.1.6/src/OFMutableDictionary.h000066400000000000000000000077401465614216400174530ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFDictionary.h" OF_ASSUME_NONNULL_BEGIN /** @file */ #ifdef OF_HAVE_BLOCKS /** * @brief A block for replacing objects in an OFMutableDictionary. * * @param key The key of the object to replace * @param object The object to replace * @return The object to replace the object with */ typedef id _Nonnull (^OFDictionaryReplaceBlock)(id key, id object); #endif /** * @class OFMutableDictionary OFDictionary.h ObjFW/OFDictionary.h * * @brief An abstract class for storing and changing objects in a dictionary. * * @note Subclasses must implement @ref setObject:forKey:, * @ref removeObjectForKey: as well as all methods of @ref OFDictionary * that need to be implemented. */ @interface OFMutableDictionary OF_GENERIC(KeyType, ObjectType): OFDictionary OF_GENERIC(KeyType, ObjectType) #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # define KeyType id # define ObjectType id #endif /** * @brief Creates a new OFMutableDictionary with enough memory to hold the * specified number of objects. * * @param capacity The initial capacity for the OFMutableDictionary * @return A new autoreleased OFMutableDictionary */ + (instancetype)dictionaryWithCapacity: (size_t)capacity; /** * @brief Initializes an already allocated OFMutableDictionary to be empty. * * @return An initialized OFMutableDictionary */ - (instancetype)init OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated OFMutableDictionary with enough * memory to hold the specified number of objects. * * @param capacity The initial capacity for the OFMutableDictionary * @return An initialized OFMutableDictionary */ - (instancetype)initWithCapacity: (size_t)capacity OF_DESIGNATED_INITIALIZER; /** * @brief Sets an object for a key. * * A key can be any object that conforms to the OFCopying protocol. * * @param key The key to set * @param object The object to set the key to */ - (void)setObject: (ObjectType)object forKey: (KeyType)key; /** * @brief Sets an object for a key. * * A key can be any object that conforms to the OFCopying protocol. * * This method is also used by the subscripting syntax. * * @param key The key to set * @param object The object to set the key to. If it is nil, this is equal to * calling @ref removeObjectForKey:. */ - (void)setObject: (nullable ObjectType)object forKeyedSubscript: (KeyType)key; /** * @brief Removes the object for the specified key from the dictionary. * * @param key The key whose object should be removed */ - (void)removeObjectForKey: (KeyType)key; /** * @brief Removes all objects. */ - (void)removeAllObjects; /** * @brief Adds the entries from the specified dictionary. * * @param dictionary The dictionary whose entries should be added */ - (void)addEntriesFromDictionary: (OFDictionary OF_GENERIC(KeyType, ObjectType) *)dictionary; #ifdef OF_HAVE_BLOCKS /** * @brief Replaces each object with the object returned by the block. * * @param block The block which returns a new object for each object */ - (void)replaceObjectsUsingBlock: (OFDictionaryReplaceBlock)block; #endif /** * @brief Converts the mutable dictionary to an immutable dictionary. */ - (void)makeImmutable; #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # undef KeyType # undef ObjectType #endif @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFMutableDictionary.m000066400000000000000000000111731465614216400174530ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFConcreteMutableDictionary.h" #import "OFArray.h" #import "OFString.h" static struct { Class isa; } placeholder; @interface OFPlaceholderMutableDictionary: OFDictionary @end @implementation OFPlaceholderMutableDictionary - (instancetype)init { return (id)[[OFConcreteMutableDictionary alloc] init]; } - (instancetype)initWithDictionary: (OFDictionary *)dictionary { return (id)[[OFConcreteMutableDictionary alloc] initWithDictionary: dictionary]; } - (instancetype)initWithObject: (id)object forKey: (id)key { return (id)[[OFConcreteMutableDictionary alloc] initWithObject: object forKey: key]; } - (instancetype)initWithObjects: (OFArray *)objects forKeys: (OFArray *)keys { return (id)[[OFConcreteMutableDictionary alloc] initWithObjects: objects forKeys: keys]; } - (instancetype)initWithObjects: (id const *)objects forKeys: (id const *)keys count: (size_t)count { return (id)[[OFConcreteMutableDictionary alloc] initWithObjects: objects forKeys: keys count: count]; } - (instancetype)initWithKeysAndObjects: (id)firstKey, ... { id ret; va_list arguments; va_start(arguments, firstKey); ret = (id)[[OFConcreteMutableDictionary alloc] initWithKey: firstKey arguments: arguments]; va_end(arguments); return ret; } - (instancetype)initWithKey: (id)firstKey arguments: (va_list)arguments { return (id)[[OFConcreteMutableDictionary alloc] initWithKey: firstKey arguments: arguments]; } - (instancetype)initWithCapacity: (size_t)capacity { return (id)[[OFConcreteMutableDictionary alloc] initWithCapacity: capacity]; } OF_SINGLETON_METHODS @end @implementation OFMutableDictionary + (void)initialize { if (self == [OFMutableDictionary class]) object_setClass((id)&placeholder, [OFPlaceholderMutableDictionary class]); } + (instancetype)alloc { if (self == [OFMutableDictionary class]) return (id)&placeholder; return [super alloc]; } + (instancetype)dictionaryWithCapacity: (size_t)capacity { return [[[self alloc] initWithCapacity: capacity] autorelease]; } - (instancetype)init { return [super init]; } #ifdef __clang__ /* We intentionally don't call into super, so silence the warning. */ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunknown-pragmas" # pragma clang diagnostic ignored "-Wobjc-designated-initializers" #endif - (instancetype)initWithObjects: (id const *)objects forKeys: (id const *)keys count: (size_t)count { OF_INVALID_INIT_METHOD } - (instancetype)initWithCapacity: (size_t)capacity { OF_INVALID_INIT_METHOD } #ifdef __clang__ # pragma clang diagnostic pop #endif - (void)setObject: (id)object forKey: (id)key { OF_UNRECOGNIZED_SELECTOR } - (void)setObject: (id)object forKeyedSubscript: (id)key { if (object != nil) [self setObject: object forKey: key]; else [self removeObjectForKey: key]; } - (void)removeObjectForKey: (id)key { OF_UNRECOGNIZED_SELECTOR } - (void)removeAllObjects { void *pool = objc_autoreleasePoolPush(); for (id key in self.allKeys) [self removeObjectForKey: key]; objc_autoreleasePoolPop(pool); } - (id)copy { return [[OFDictionary alloc] initWithDictionary: self]; } - (void)addEntriesFromDictionary: (OFDictionary *)dictionary { void *pool = objc_autoreleasePoolPush(); OFEnumerator *keyEnumerator = [dictionary keyEnumerator]; OFEnumerator *objectEnumerator = [dictionary objectEnumerator]; id key, object; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) [self setObject: object forKey: key]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS - (void)replaceObjectsUsingBlock: (OFDictionaryReplaceBlock)block { [self enumerateKeysAndObjectsUsingBlock: ^ (id key, id object, bool *stop) { id new = block(key, object); if (new != object) { [self setObject: block(key, object) forKey: key]; } }]; } #endif - (void)makeImmutable { } @end objfw-1.1.6/src/OFMutableIRI.h000066400000000000000000000154311465614216400157650ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFIRI.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFMutableIRI OFIRI.h ObjFW/OFIRI.h * * @brief A class for representing IRIs, URIs, URLs and URNs, for parsing them, * accessing parts of them as well as modifying them. * * This class follows RFC 3976 and RFC 3987. */ @interface OFMutableIRI: OFIRI { OF_RESERVE_IVARS(OFMutableIRI, 4) } /** * @brief The scheme part of the IRI. * * @throw OFInvalidFormatException The scheme being set is not in the correct * format */ @property (readwrite, copy, nonatomic) OFString *scheme; /** * @brief The host part of the IRI. */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *host; /** * @brief The host part of the IRI in percent-encoded form. * * Setting this retains the original percent-encoding used - if more characters * than necessary are percent-encoded, it is kept this way. * * @throw OFInvalidFormatException The host being set is not in the correct * format */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *percentEncodedHost; /** * @brief The port part of the IRI. * * @throw OFInvalidArgumentException The port is not valid (e.g. negative or * too big) */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFNumber *port; /** * @brief The user part of the IRI. */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *user; /** * @brief The user part of the IRI in percent-encoded form. * * Setting this retains the original percent-encoding used - if more characters * than necessary are percent-encoded, it is kept this way. * * @throw OFInvalidFormatException The user being set is not in the correct * format */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *percentEncodedUser; /** * @brief The password part of the IRI. */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *password; /** * @brief The password part of the IRI in percent-encoded form. * * Setting this retains the original percent-encoding used - if more characters * than necessary are percent-encoded, it is kept this way. * * @throw OFInvalidFormatException The password being set is not in the correct * format */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *percentEncodedPassword; /** * @brief The path part of the IRI. */ @property (readwrite, copy, nonatomic) OFString *path; /** * @brief The path part of the IRI in percent-encoded form. * * Setting this retains the original percent-encoding used - if more characters * than necessary are percent-encoded, it is kept this way. * * @throw OFInvalidFormatException The path being set is not in the correct * format */ @property (readwrite, copy, nonatomic) OFString *percentEncodedPath; /** * @brief The path of the IRI split into components. * * The first component must always be empty to designate the root. * * @throw OFInvalidFormatException The path components being set are not in the * correct format */ @property (readwrite, copy, nonatomic) OFArray OF_GENERIC(OFString *) *pathComponents; /** * @brief The query part of the IRI. */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *query; /** * @brief The query part of the IRI in percent-encoded form. * * Setting this retains the original percent-encoding used - if more characters * than necessary are percent-encoded, it is kept this way. * * @throw OFInvalidFormatException The query being set is not in the correct * format */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *percentEncodedQuery; /** * @brief The query part of the IRI as an array. * * For example, a query like `key1=value1&key2=value2` would correspond to the * following array: * * @[ * [OFPair pairWithFirstObject: @"key1" secondObject: @"value1"], * [OFPair pairWithFirstObject: @"key2" secondObject: @"value2"], * ] * * @throw OFInvalidFormatException The query is not in the correct format */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, OFString *) *) *queryItems; /** * @brief The fragment part of the IRI. */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *fragment; /** * @brief The fragment part of the IRI in percent-encoded form. * * Setting this retains the original percent-encoding used - if more characters * than necessary are percent-encoded, it is kept this way. * * @throw OFInvalidFormatException The fragment being set is not in the correct * format */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *percentEncodedFragment; /** * @brief Creates a new mutable IRI with the specified schemed. * * @param scheme The scheme for the IRI * @return A new, autoreleased OFMutableIRI */ + (instancetype)IRIWithScheme: (OFString *)scheme; /** * @brief Initializes an already allocated mutable IRI with the specified * schemed. * * @param scheme The scheme for the IRI * @return An initialized OFMutableIRI */ - (instancetype)initWithScheme: (OFString *)scheme; /** * @brief Appends the specified path component. * * @param component The component to append */ - (void)appendPathComponent: (OFString *)component; /** * @brief Appends the specified path component. * * @param component The component to append * @param isDirectory Whether the path is a directory, in which case a slash is * appended if there is no slash yet */ - (void)appendPathComponent: (OFString *)component isDirectory: (bool)isDirectory; /** * @brief Appends the specified path extension * * @param extension The path extension to append */ - (void)appendPathExtension: (OFString *)extension; /** * @brief Deletes the last path component. */ - (void)deleteLastPathComponent; /** * @brief Deletes the path extension. */ - (void)deletePathExtension; /** * @brief Resolves relative subpaths. */ - (void)standardizePath; /** * @brief Converts the mutable IRI to an immutable IRI. */ - (void)makeImmutable; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFMutableIRI.m000066400000000000000000000311471465614216400157740ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFMutableIRI.h" #import "OFIRI+Private.h" #import "OFArray.h" #import "OFDictionary.h" #ifdef OF_HAVE_FILES # import "OFFileManager.h" #endif #import "OFNumber.h" #import "OFPair.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" @implementation OFMutableIRI @dynamic scheme, host, percentEncodedHost, port, user, percentEncodedUser; @dynamic password, percentEncodedPassword, path, percentEncodedPath; @dynamic pathComponents, query, percentEncodedQuery, queryItems, fragment; @dynamic percentEncodedFragment; + (instancetype)IRIWithScheme: (OFString *)scheme { return [[[self alloc] initWithScheme: scheme] autorelease]; } - (instancetype)initWithScheme: (OFString *)scheme { self = [super of_init]; @try { self.scheme = scheme; _percentEncodedPath = @""; } @catch (id e) { [self release]; @throw e; } return self; } - (void)setScheme: (OFString *)scheme { void *pool = objc_autoreleasePoolPush(); OFString *old = _scheme; if (scheme.length < 1 || !OFASCIIIsAlpha(*scheme.UTF8String)) @throw [OFInvalidFormatException exception]; _OFIRIVerifyIsEscaped(scheme, [OFCharacterSet IRISchemeAllowedCharacterSet], false); _scheme = [scheme.lowercaseString copy]; [old release]; objc_autoreleasePoolPop(pool); } - (void)setHost: (OFString *)host { void *pool = objc_autoreleasePoolPush(); OFString *old = _percentEncodedHost; if (_OFIRIIsIPv6Host(host)) _percentEncodedHost = [[OFString alloc] initWithFormat: @"[%@]", host]; else _percentEncodedHost = [[host stringByAddingPercentEncodingWithAllowedCharacters: [OFCharacterSet IRIHostAllowedCharacterSet]] copy]; [old release]; objc_autoreleasePoolPop(pool); } - (void)setPercentEncodedHost: (OFString *)percentEncodedHost { OFString *old; if ([percentEncodedHost hasPrefix: @"["] && [percentEncodedHost hasSuffix: @"]"]) { if (!_OFIRIIsIPv6Host([percentEncodedHost substringWithRange: OFMakeRange(1, percentEncodedHost.length - 2)])) @throw [OFInvalidFormatException exception]; } else if (percentEncodedHost != nil) _OFIRIVerifyIsEscaped(percentEncodedHost, [OFCharacterSet IRIHostAllowedCharacterSet], true); old = _percentEncodedHost; _percentEncodedHost = [percentEncodedHost copy]; [old release]; } - (void)setPort: (OFNumber *)port { OFNumber *old = _port; if (port.longLongValue < 0 || port.longLongValue > 65535) @throw [OFInvalidArgumentException exception]; _port = [port copy]; [old release]; } - (void)setUser: (OFString *)user { void *pool = objc_autoreleasePoolPush(); OFString *old = _percentEncodedUser; _percentEncodedUser = [[user stringByAddingPercentEncodingWithAllowedCharacters: [OFCharacterSet IRIUserAllowedCharacterSet]] copy]; [old release]; objc_autoreleasePoolPop(pool); } - (void)setPercentEncodedUser: (OFString *)percentEncodedUser { OFString *old; if (percentEncodedUser != nil) _OFIRIVerifyIsEscaped(percentEncodedUser, [OFCharacterSet IRIUserAllowedCharacterSet], true); old = _percentEncodedUser; _percentEncodedUser = [percentEncodedUser copy]; [old release]; } - (void)setPassword: (OFString *)password { void *pool = objc_autoreleasePoolPush(); OFString *old = _percentEncodedPassword; _percentEncodedPassword = [[password stringByAddingPercentEncodingWithAllowedCharacters: [OFCharacterSet IRIPasswordAllowedCharacterSet]] copy]; [old release]; objc_autoreleasePoolPop(pool); } - (void)setPercentEncodedPassword: (OFString *)percentEncodedPassword { OFString *old; if (percentEncodedPassword != nil) _OFIRIVerifyIsEscaped(percentEncodedPassword, [OFCharacterSet IRIPasswordAllowedCharacterSet], true); old = _percentEncodedPassword; _percentEncodedPassword = [percentEncodedPassword copy]; [old release]; } - (void)setPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFString *old = _percentEncodedPath; _percentEncodedPath = [[path stringByAddingPercentEncodingWithAllowedCharacters: [OFCharacterSet IRIPathAllowedCharacterSet]] copy]; [old release]; objc_autoreleasePoolPop(pool); } - (void)setPercentEncodedPath: (OFString *)percentEncodedPath { OFString *old; _OFIRIVerifyIsEscaped(percentEncodedPath, [OFCharacterSet IRIPathAllowedCharacterSet], true); old = _percentEncodedPath; _percentEncodedPath = [percentEncodedPath copy]; [old release]; } - (void)setPathComponents: (OFArray *)components { void *pool = objc_autoreleasePoolPush(); if (components.count == 0) @throw [OFInvalidFormatException exception]; if ([components.firstObject isEqual: @"/"]) { OFMutableArray *mutComponents = [[components mutableCopy] autorelease]; [mutComponents replaceObjectAtIndex: 0 withObject: @""]; components = mutComponents; } self.path = [components componentsJoinedByString: @"/"]; objc_autoreleasePoolPop(pool); } - (void)setQuery: (OFString *)query { void *pool = objc_autoreleasePoolPush(); OFString *old = _percentEncodedQuery; _percentEncodedQuery = [[query stringByAddingPercentEncodingWithAllowedCharacters: [OFCharacterSet IRIQueryAllowedCharacterSet]] copy]; [old release]; objc_autoreleasePoolPop(pool); } - (void)setPercentEncodedQuery: (OFString *)percentEncodedQuery { OFString *old; if (percentEncodedQuery != nil) _OFIRIVerifyIsEscaped(percentEncodedQuery, [OFCharacterSet IRIQueryAllowedCharacterSet], true); old = _percentEncodedQuery; _percentEncodedQuery = [percentEncodedQuery copy]; [old release]; } - (void)setQueryItems: (OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, OFString *) *) *) queryItems { void *pool; OFMutableString *percentEncodedQuery; OFCharacterSet *characterSet; OFString *old; if (queryItems == nil) { [_percentEncodedQuery release]; _percentEncodedQuery = nil; return; } pool = objc_autoreleasePoolPush(); percentEncodedQuery = [OFMutableString string]; characterSet = [OFCharacterSet IRIQueryKeyValueAllowedCharacterSet]; for (OFPair OF_GENERIC(OFString *, OFString *) *item in queryItems) { OFString *key = [item.firstObject stringByAddingPercentEncodingWithAllowedCharacters: characterSet]; OFString *value = [item.secondObject stringByAddingPercentEncodingWithAllowedCharacters: characterSet]; if (percentEncodedQuery.length > 0) [percentEncodedQuery appendString: @"&"]; [percentEncodedQuery appendFormat: @"%@=%@", key, value]; } old = _percentEncodedQuery; _percentEncodedQuery = [percentEncodedQuery copy]; [old release]; objc_autoreleasePoolPop(pool); } - (void)setFragment: (OFString *)fragment { void *pool = objc_autoreleasePoolPush(); OFString *old = _percentEncodedFragment; _percentEncodedFragment = [[fragment stringByAddingPercentEncodingWithAllowedCharacters: [OFCharacterSet IRIFragmentAllowedCharacterSet]] copy]; [old release]; objc_autoreleasePoolPop(pool); } - (void)setPercentEncodedFragment: (OFString *)percentEncodedFragment { OFString *old; if (percentEncodedFragment != nil) _OFIRIVerifyIsEscaped(percentEncodedFragment, [OFCharacterSet IRIFragmentAllowedCharacterSet], true); old = _percentEncodedFragment; _percentEncodedFragment = [percentEncodedFragment copy]; [old release]; } - (id)copy { OFMutableIRI *copy = [self mutableCopy]; [copy makeImmutable]; return copy; } - (void)appendPathComponent: (OFString *)component { [self appendPathComponent: component isDirectory: false]; #ifdef OF_HAVE_FILES if ([_scheme isEqual: @"file"] && ![_percentEncodedPath hasSuffix: @"/"] && [[OFFileManager defaultManager] directoryExistsAtIRI: self]) { OFString *path = [[_percentEncodedPath stringByAppendingString: @"/"] retain]; [_percentEncodedPath release]; _percentEncodedPath = path; } #endif } - (void)appendPathComponent: (OFString *)component isDirectory: (bool)isDirectory { void *pool; OFString *path; if ([component isEqual: @"/"] && [_percentEncodedPath hasSuffix: @"/"]) return; pool = objc_autoreleasePoolPush(); component = [component stringByAddingPercentEncodingWithAllowedCharacters: [OFCharacterSet IRIPathAllowedCharacterSet]]; #if defined(OF_WINDOWS) || defined(OF_MSDOS) if ([_percentEncodedPath hasSuffix: @"/"] || ([_scheme isEqual: @"file"] && [_percentEncodedPath hasSuffix: @":"])) #else if ([_percentEncodedPath hasSuffix: @"/"]) #endif path = [_percentEncodedPath stringByAppendingString: component]; else path = [_percentEncodedPath stringByAppendingFormat: @"/%@", component]; if (isDirectory && ![path hasSuffix: @"/"]) path = [path stringByAppendingString: @"/"]; [_percentEncodedPath release]; _percentEncodedPath = [path retain]; objc_autoreleasePoolPop(pool); } - (void)appendPathExtension: (OFString *)extension { void *pool; OFMutableString *path; bool isDirectory = false; if (_percentEncodedPath.length == 0) return; pool = objc_autoreleasePoolPush(); path = [[_percentEncodedPath mutableCopy] autorelease]; extension = [extension stringByAddingPercentEncodingWithAllowedCharacters: [OFCharacterSet IRIPathAllowedCharacterSet]]; if ([path hasSuffix: @"/"]) { [path deleteCharactersInRange: OFMakeRange(path.length - 1, 1)]; isDirectory = true; } [path appendFormat: @".%@", extension]; if (isDirectory) [path appendString: @"/"]; [path makeImmutable]; [_percentEncodedPath release]; _percentEncodedPath = [path retain]; objc_autoreleasePoolPop(pool); } - (void)deleteLastPathComponent { void *pool = objc_autoreleasePoolPush(); OFString *path = _percentEncodedPath; size_t pos; if (path.length == 0 || [path isEqual: @"/"]) { objc_autoreleasePoolPop(pool); return; } if ([path hasSuffix: @"/"]) path = [path substringToIndex: path.length - 1]; pos = [path rangeOfString: @"/" options: OFStringSearchBackwards].location; if (pos == OFNotFound) { objc_autoreleasePoolPop(pool); return; } path = [path substringToIndex: pos + 1]; [_percentEncodedPath release]; _percentEncodedPath = [path retain]; objc_autoreleasePoolPop(pool); } - (void)deletePathExtension { void *pool = objc_autoreleasePoolPush(); OFMutableString *path = [[_percentEncodedPath mutableCopy] autorelease]; bool isDirectory = false; size_t pos; if ([path hasSuffix: @"/"]) { [path deleteCharactersInRange: OFMakeRange(path.length - 1, 1)]; isDirectory = true; } pos = [path rangeOfString: @"." options: OFStringSearchBackwards].location; if (pos == OFNotFound) { objc_autoreleasePoolPop(pool); return; } [path deleteCharactersInRange: OFMakeRange(pos, path.length - pos)]; if (isDirectory) [path appendString: @"/"]; [path makeImmutable]; [_percentEncodedPath release]; _percentEncodedPath = [path retain]; objc_autoreleasePoolPop(pool); } - (void)standardizePath { void *pool = objc_autoreleasePoolPush(); OFMutableArray OF_GENERIC(OFString *) *array; bool done = false, startsWithEmpty, endsWithEmpty; OFString *path; array = [[[_percentEncodedPath componentsSeparatedByString: @"/"] mutableCopy] autorelease]; endsWithEmpty = ([array.lastObject length] == 0); startsWithEmpty = ([array.firstObject length] == 0); while (!done) { size_t length = array.count; done = true; for (size_t i = 0; i < length; i++) { OFString *current = [array objectAtIndex: i]; OFString *parent = (i > 0 ? [array objectAtIndex: i - 1] : nil); if ([current isEqual: @"."] || current.length == 0) { [array removeObjectAtIndex: i]; done = false; break; } if ([current isEqual: @".."] && parent != nil && ![parent isEqual: @".."]) { [array removeObjectsInRange: OFMakeRange(i - 1, 2)]; done = false; break; } } } if (startsWithEmpty) [array insertObject: @"" atIndex: 0]; if (endsWithEmpty) [array addObject: @""]; path = [array componentsJoinedByString: @"/"]; if (startsWithEmpty && path.length == 0) path = @"/"; self.percentEncodedPath = path; objc_autoreleasePoolPop(pool); } - (void)makeImmutable { object_setClass(self, [OFIRI class]); } @end objfw-1.1.6/src/OFMutableLHAArchiveEntry.h000066400000000000000000000044401465614216400202700ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFLHAArchiveEntry.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFMutableLHAArchiveEntry OFLHAArchiveEntry.h ObjFW/OFHAArchiveEntry.h * * @brief A class which represents a mutable entry in an LHA archive. */ @interface OFMutableLHAArchiveEntry: OFLHAArchiveEntry { OF_RESERVE_IVARS(OFMutableLHAArchiveEntry, 4) } /** * @brief The compression method of the entry. */ @property (readwrite, copy, nonatomic) OFString *compressionMethod; /** * @brief The LHA level of the file. */ @property (readwrite, nonatomic) uint8_t headerLevel; /** * @brief The CRC16 of the file. */ @property (readwrite, nonatomic) uint16_t CRC16; /** * @brief The operating system identifier of the file. */ @property (readwrite, nonatomic) uint8_t operatingSystemIdentifier; /** * @brief The LHA extensions of the file. */ @property (readwrite, copy, nonatomic) OFArray OF_GENERIC(OFData *) *extensions; /** * @brief Creates a new OFMutableLHAArchiveEntry with the specified file name. * * @param fileName The file name for the OFLHAArchiveEntry * @return A new, autoreleased OFLHAArchiveEntry */ + (instancetype)entryWithFileName: (OFString *)fileName; /** * @brief Initializes an already allocated OFMutableLHAArchiveEntry with the * specified file name. * * @param fileName The file name for the OFLHAArchiveEntry * @return An initialized OFLHAArchiveEntry */ - (instancetype)initWithFileName: (OFString *)fileName; /** * @brief Converts the OFMutableLHAArchiveEntry to an immutable * OFLHAArchiveEntry. */ - (void)makeImmutable; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFMutableLHAArchiveEntry.m000066400000000000000000000074641465614216400203060ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFMutableLHAArchiveEntry.h" #import "OFLHAArchiveEntry+Private.h" #import "OFArray.h" #import "OFData.h" #import "OFDate.h" #import "OFNumber.h" #import "OFString.h" @implementation OFMutableLHAArchiveEntry @dynamic fileName, compressionMethod, compressedSize, uncompressedSize; @dynamic modificationDate, headerLevel, CRC16, operatingSystemIdentifier; @dynamic fileComment, POSIXPermissions, ownerAccountID, groupOwnerAccountID; @dynamic ownerAccountName, groupOwnerAccountName, extensions; + (instancetype)entryWithFileName: (OFString *)fileName { return [[[self alloc] initWithFileName: fileName] autorelease]; } - (instancetype)initWithFileName: (OFString *)fileName { self = [super of_init]; @try { _fileName = [fileName copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (id)copy { OFMutableLHAArchiveEntry *copy = [self mutableCopy]; [copy makeImmutable]; return copy; } - (void)setFileName: (OFString *)fileName { OFString *old = _fileName; _fileName = [fileName copy]; [old release]; [_directoryName release]; _directoryName = nil; } - (void)setCompressionMethod: (OFString *)compressionMethod { OFString *old = _compressionMethod; _compressionMethod = [compressionMethod copy]; [old release]; } - (void)setCompressedSize: (unsigned long long)compressedSize { _compressedSize = compressedSize; } - (void)setUncompressedSize: (unsigned long long)uncompressedSize { _uncompressedSize = uncompressedSize; } - (void)setModificationDate: (OFDate *)modificationDate { OFDate *old = _modificationDate; _modificationDate = [modificationDate retain]; [old release]; } - (void)setHeaderLevel: (uint8_t)headerLevel { _headerLevel = headerLevel; } - (void)setCRC16: (uint16_t)CRC16 { _CRC16 = CRC16; } - (void)setOperatingSystemIdentifier: (uint8_t)operatingSystemIdentifier { _operatingSystemIdentifier = operatingSystemIdentifier; } - (void)setFileComment: (OFString *)fileComment { OFString *old = _fileComment; _fileComment = [fileComment copy]; [old release]; } - (void)setPOSIXPermissions: (OFNumber *)POSIXPermissions { OFNumber *old = _POSIXPermissions; _POSIXPermissions = [POSIXPermissions retain]; [old release]; } - (void)setOwnerAccountID: (OFNumber *)ownerAccountID { OFNumber *old = _ownerAccountID; _ownerAccountID = [ownerAccountID retain]; [old release]; } - (void)setGroupOwnerAccountID: (OFNumber *)groupOwnerAccountID { OFNumber *old = _groupOwnerAccountID; _groupOwnerAccountID = [groupOwnerAccountID retain]; [old release]; } - (void)setOwnerAccountName: (OFString *)ownerAccountName { OFString *old = _ownerAccountName; _ownerAccountName = [ownerAccountName copy]; [old release]; } - (void)setGroupOwnerAccountName: (OFString *)groupOwnerAccountName { OFString *old = _groupOwnerAccountName; _groupOwnerAccountName = [groupOwnerAccountName copy]; [old release]; } - (void)setExtensions: (OFArray OF_GENERIC(OFData *) *)extensions { OFArray OF_GENERIC(OFData *) *old = _extensions; _extensions = [extensions copy]; [old release]; } - (void)makeImmutable { object_setClass(self, [OFLHAArchiveEntry class]); } @end objfw-1.1.6/src/OFMutablePair.h000066400000000000000000000030551465614216400162340ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFPair.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFMutablePair OFPair.h ObjFW/OFPair.h * * @brief A class for storing a pair of two objects. */ @interface OFMutablePair OF_GENERIC(FirstType, SecondType): OFPair OF_GENERIC(FirstType, SecondType) #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # define FirstType id # define SecondType id #endif { OF_RESERVE_IVARS(OFMutablePair, 4) } /** * @brief The first object of the pair. */ @property (readwrite, nonatomic, retain) FirstType firstObject; /** * @brief The second object of the pair. */ @property (readwrite, nonatomic, retain) SecondType secondObject; /** * @brief Converts the mutable pair to an immutable pair. */ - (void)makeImmutable; #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # undef FirstType # undef SecondType #endif @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFMutablePair.m000066400000000000000000000023611465614216400162400ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFMutablePair.h" @implementation OFMutablePair @dynamic firstObject, secondObject; - (void)setFirstObject: (id)firstObject { id old = _firstObject; _firstObject = [firstObject retain]; [old release]; } - (void)setSecondObject: (id)secondObject { id old = _secondObject; _secondObject = [secondObject retain]; [old release]; } - (id)copy { OFMutablePair *copy = [self mutableCopy]; [copy makeImmutable]; return copy; } - (void)makeImmutable { object_setClass(self, [OFPair class]); } @end objfw-1.1.6/src/OFMutableSet.h000066400000000000000000000060711465614216400160750ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFSet.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFMutableSet OFSet.h ObjFW/OFSet.h * * @brief An abstract class for a mutable unordered set of unique objects. * * @note Subclasses must implement @ref addObject:, @ref removeObject: as well * as all methods of @ref OFSet that need to be implemented. */ @interface OFMutableSet OF_GENERIC(ObjectType): OFSet OF_GENERIC(ObjectType) #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # define ObjectType id #endif /** * @brief Creates a new OFMutableSet with enough memory to hold the specified * number of objects. * * @param capacity The initial capacity for the OFMutableSet * @return A new autoreleased OFMutableSet */ + (instancetype)setWithCapacity: (size_t)capacity; /** * @brief Initializes an already allocated OFMutableSet to be empty. * * @return An initialized OFMutableSet */ - (instancetype)init OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated OFMutableSet with enough memory to * hold the specified number of objects. * * @param capacity The initial capacity for the OFMutableSet * @return An initialized OFMutableSet */ - (instancetype)initWithCapacity: (size_t)capacity OF_DESIGNATED_INITIALIZER; /** * @brief Adds the specified object to the set. * * @param object The object to add to the set */ - (void)addObject: (ObjectType)object; /** * @brief Removes the specified object from the set. * * @param object The object to remove from the set */ - (void)removeObject: (ObjectType)object; /** * @brief Removes all objects from the receiver which are in the specified set. * * @param set The set whose objects will be removed from the receiver */ - (void)minusSet: (OFSet OF_GENERIC(ObjectType) *)set; /** * @brief Removes all objects from the receiver which are not in the specified * set. * * @param set The set to intersect with */ - (void)intersectSet: (OFSet OF_GENERIC(ObjectType) *)set; /** * @brief Creates a union of the receiver and the specified set. * * @param set The set to create the union with */ - (void)unionSet: (OFSet OF_GENERIC(ObjectType) *)set; /** * @brief Removes all objects from the set. */ - (void)removeAllObjects; /** * @brief Converts the mutable set to an immutable set. */ - (void)makeImmutable; #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # undef ObjectType #endif @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFMutableSet.m000066400000000000000000000103731465614216400161020ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFMutableSet.h" #import "OFConcreteMutableSet.h" #import "OFString.h" static struct { Class isa; } placeholder; @interface OFPlaceholderMutableSet: OFMutableSet @end @implementation OFPlaceholderMutableSet #ifdef __clang__ /* We intentionally don't call into super, so silence the warning. */ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunknown-pragmas" # pragma clang diagnostic ignored "-Wobjc-designated-initializers" #endif - (instancetype)init { return (id)[[OFConcreteMutableSet alloc] init]; } - (instancetype)initWithSet: (OFSet *)set { return (id)[[OFConcreteMutableSet alloc] initWithSet: set]; } - (instancetype)initWithArray: (OFArray *)array { return (id)[[OFConcreteMutableSet alloc] initWithArray: array]; } - (instancetype)initWithObjects: (id)firstObject, ... { id ret; va_list arguments; va_start(arguments, firstObject); ret = [[OFConcreteMutableSet alloc] initWithObject: firstObject arguments: arguments]; va_end(arguments); return ret; } - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { return (id)[[OFConcreteMutableSet alloc] initWithObjects: objects count: count]; } - (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments { return (id)[[OFConcreteMutableSet alloc] initWithObject: firstObject arguments: arguments]; } - (instancetype)initWithCapacity: (size_t)capacity { return (id)[[OFConcreteMutableSet alloc] initWithCapacity: capacity]; } #ifdef __clang__ # pragma clang diagnostic pop #endif OF_SINGLETON_METHODS @end @implementation OFMutableSet + (void)initialize { if (self == [OFMutableSet class]) object_setClass((id)&placeholder, [OFPlaceholderMutableSet class]); } + (instancetype)alloc { if (self == [OFMutableSet class]) return (id)&placeholder; return [super alloc]; } + (instancetype)setWithCapacity: (size_t)capacity { return [[[self alloc] initWithCapacity: capacity] autorelease]; } - (instancetype)init { return [super init]; } #ifdef __clang__ /* We intentionally don't call into super, so silence the warning. */ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunknown-pragmas" # pragma clang diagnostic ignored "-Wobjc-designated-initializers" #endif - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { OF_INVALID_INIT_METHOD } - (instancetype)initWithCapacity: (size_t)capacity { OF_INVALID_INIT_METHOD } #ifdef __clang__ # pragma clang diagnostic pop #endif - (id)copy { return [[OFSet alloc] initWithSet: self]; } - (void)addObject: (id)object { OF_UNRECOGNIZED_SELECTOR } - (void)removeObject: (id)object { OF_UNRECOGNIZED_SELECTOR } - (void)minusSet: (OFSet *)set { for (id object in set) [self removeObject: object]; } - (void)intersectSet: (OFSet *)set { void *pool = objc_autoreleasePoolPush(); size_t count = self.count; id *cArray; cArray = OFAllocMemory(count, sizeof(id)); @try { size_t i; i = 0; for (id object in self) { OFAssert(i < count); cArray[i++] = object; } for (i = 0; i < count; i++) if (![set containsObject: cArray[i]]) [self removeObject: cArray[i]]; } @finally { OFFreeMemory(cArray); } objc_autoreleasePoolPop(pool); } - (void)unionSet: (OFSet *)set { for (id object in set) [self addObject: object]; } - (void)removeAllObjects { void *pool = objc_autoreleasePoolPush(); OFSet *copy = [[self copy] autorelease]; for (id object in copy) [self removeObject: object]; objc_autoreleasePoolPop(pool); } - (void)makeImmutable { } @end objfw-1.1.6/src/OFMutableString.h000066400000000000000000000145641465614216400166160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFString.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFMutableString OFString.h ObjFW/OFString.h * * @brief A class for storing and modifying strings. */ @interface OFMutableString: OFString /** * @brief Sets the character at the specified index. * * @param character The character to set * @param index The index where to set the character */ - (void)setCharacter: (OFUnichar)character atIndex: (size_t)index; /** * @brief Appends another OFString to the OFMutableString. * * @param string An OFString to append */ - (void)appendString: (OFString *)string; /** * @brief Appends the specified characters to the OFMutableString. * * @param characters An array of characters to append * @param length The length of the array of characters */ - (void)appendCharacters: (const OFUnichar *)characters length: (size_t)length; /** * @brief Appends a UTF-8 encoded C string to the OFMutableString. * * @param UTF8String A UTF-8 encoded C string to append * @throw OFInvalidEncodingException The C string is not in not in the correct * encoding */ - (void)appendUTF8String: (const char *)UTF8String; /** * @brief Appends a UTF-8 encoded C string with the specified length to the * OFMutableString. * * @param UTF8String A UTF-8 encoded C string to append * @param UTF8StringLength The length of the UTF-8 encoded C string * @throw OFInvalidEncodingException The C string is not in not in the correct * encoding */ - (void)appendUTF8String: (const char *)UTF8String length: (size_t)UTF8StringLength; /** * @brief Appends a C string with the specified encoding to the OFMutableString. * * @param cString A C string to append * @param encoding The encoding of the C string * @throw OFInvalidEncodingException The C string is not in not in the correct * encoding */ - (void)appendCString: (const char *)cString encoding: (OFStringEncoding)encoding; /** * @brief Appends a C string with the specified encoding and length to the * OFMutableString. * * @param cString A C string to append * @param encoding The encoding of the C string * @param cStringLength The length of the UTF-8 encoded C string * @throw OFInvalidEncodingException The C string is not in not in the correct * encoding */ - (void)appendCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength; /** * @brief Appends a formatted string to the OFMutableString. * * See `printf` for the format syntax. As an addition, `%@` is available as * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * @param format A format string which generates the string to append * @throw OFInvalidFormatException The specified format is invalid * @throw OFInvalidEncodingException The resulting string is not in not in UTF-8 * encoding */ - (void)appendFormat: (OFConstantString *)format, ...; /** * @brief Appends a formatted string to the OFMutableString. * * See printf for the format syntax. As an addition, `%@` is available as * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * @param format A format string which generates the string to append * @param arguments The arguments used in the format string * @throw OFInvalidFormatException The specified format is invalid */ - (void)appendFormat: (OFConstantString *)format arguments: (va_list)arguments; /** * @brief Converts the string to uppercase. */ - (void)uppercase; /** * @brief Converts the string to lowercase. */ - (void)lowercase; /** * @brief Capitalizes the string. * * @note This only considers spaces, tabs and newlines to be word delimiters! * Also note that this might change in the future to all word delimiters * specified by Unicode! */ - (void)capitalize; /** * @brief Inserts a string at the specified index. * * @param string The string to insert * @param index The index */ - (void)insertString: (OFString *)string atIndex: (size_t)index; /** * @brief Deletes the characters at the specified range. * * @param range The range of the characters which should be removed */ - (void)deleteCharactersInRange: (OFRange)range; /** * @brief Replaces the characters at the specified range. * * @param range The range of the characters which should be replaced * @param replacement The string to the replace the characters with */ - (void)replaceCharactersInRange: (OFRange)range withString: (OFString *)replacement; /** * @brief Replaces all occurrences of a string with another string. * * @param string The string to replace * @param replacement The string with which it should be replaced */ - (void)replaceOccurrencesOfString: (OFString *)string withString: (OFString *)replacement; /** * @brief Replaces all occurrences of a string in the specified range with * another string. * * @param string The string to replace * @param replacement The string with which it should be replaced * @param options Options modifying search behavior * Possible values: None yet * @param range The range in which the string should be replaced */ - (void)replaceOccurrencesOfString: (OFString *)string withString: (OFString *)replacement options: (int)options range: (OFRange)range; /** * @brief Deletes all whitespaces at the beginning of the string. */ - (void)deleteLeadingWhitespaces; /** * @brief Deletes all whitespaces at the end of the string. */ - (void)deleteTrailingWhitespaces; /** * @brief Deletes all whitespaces at the beginning and the end of the string. */ - (void)deleteEnclosingWhitespaces; /** * @brief Converts the mutable string to an immutable string. */ - (void)makeImmutable; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFMutableString.m000066400000000000000000000321341465614216400166140ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #include #import "OFString.h" #import "OFASPrintF.h" #import "OFMutableUTF8String.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "unicode.h" static struct { Class isa; } placeholder; @interface OFPlaceholderMutableString: OFMutableString @end @implementation OFPlaceholderMutableString #ifdef __clang__ /* We intentionally don't call into super, so silence the warning. */ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunknown-pragmas" # pragma clang diagnostic ignored "-Wobjc-designated-initializers" #endif - (instancetype)init { return (id)[[OFMutableUTF8String alloc] init]; } - (instancetype)initWithUTF8String: (const char *)UTF8String { return (id)[[OFMutableUTF8String alloc] initWithUTF8String: UTF8String]; } - (instancetype)initWithUTF8String: (const char *)UTF8String length: (size_t)UTF8StringLength { return (id)[[OFMutableUTF8String alloc] initWithUTF8String: UTF8String length: UTF8StringLength]; } - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding { return (id)[[OFMutableUTF8String alloc] initWithCString: cString encoding: encoding]; } - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength { return (id)[[OFMutableUTF8String alloc] initWithCString: cString encoding: encoding length: cStringLength]; } - (instancetype)initWithString: (OFString *)string { return (id)[[OFMutableUTF8String alloc] initWithString: string]; } - (instancetype)initWithCharacters: (const OFUnichar *)characters length: (size_t)length { return (id)[[OFMutableUTF8String alloc] initWithCharacters: characters length: length]; } - (instancetype)initWithUTF16String: (const OFChar16 *)string { return (id)[[OFMutableUTF8String alloc] initWithUTF16String: string]; } - (instancetype)initWithUTF16String: (const OFChar16 *)string length: (size_t)length { return (id)[[OFMutableUTF8String alloc] initWithUTF16String: string length: length]; } - (instancetype)initWithUTF16String: (const OFChar16 *)string byteOrder: (OFByteOrder)byteOrder { return (id)[[OFMutableUTF8String alloc] initWithUTF16String: string byteOrder: byteOrder]; } - (instancetype)initWithUTF16String: (const OFChar16 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder { return (id)[[OFMutableUTF8String alloc] initWithUTF16String: string length: length byteOrder: byteOrder]; } - (instancetype)initWithUTF32String: (const OFChar32 *)string { return (id)[[OFMutableUTF8String alloc] initWithUTF32String: string]; } - (instancetype)initWithUTF32String: (const OFChar32 *)string length: (size_t)length { return (id)[[OFMutableUTF8String alloc] initWithUTF32String: string length: length]; } - (instancetype)initWithUTF32String: (const OFChar32 *)string byteOrder: (OFByteOrder)byteOrder { return (id)[[OFMutableUTF8String alloc] initWithUTF32String: string byteOrder: byteOrder]; } - (instancetype)initWithUTF32String: (const OFChar32 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder { return (id)[[OFMutableUTF8String alloc] initWithUTF32String: string length: length byteOrder: byteOrder]; } - (instancetype)initWithFormat: (OFConstantString *)format, ... { id ret; va_list arguments; va_start(arguments, format); ret = [[OFMutableUTF8String alloc] initWithFormat: format arguments: arguments]; va_end(arguments); return ret; } - (instancetype)initWithFormat: (OFConstantString *)format arguments: (va_list)arguments { return (id)[[OFMutableUTF8String alloc] initWithFormat: format arguments: arguments]; } #ifdef OF_HAVE_FILES - (instancetype)initWithContentsOfFile: (OFString *)path { return (id)[[OFMutableUTF8String alloc] initWithContentsOfFile: path]; } - (instancetype)initWithContentsOfFile: (OFString *)path encoding: (OFStringEncoding)encoding { return (id)[[OFMutableUTF8String alloc] initWithContentsOfFile: path encoding: encoding]; } #endif - (instancetype)initWithContentsOfIRI: (OFIRI *)IRI { return (id)[[OFMutableUTF8String alloc] initWithContentsOfIRI: IRI]; } - (instancetype)initWithContentsOfIRI: (OFIRI *)IRI encoding: (OFStringEncoding)encoding { return (id)[[OFMutableUTF8String alloc] initWithContentsOfIRI: IRI encoding: encoding]; } #ifdef __clang__ # pragma clang diagnostic pop #endif OF_SINGLETON_METHODS @end @implementation OFMutableString + (void)initialize { if (self == [OFMutableString class]) object_setClass((id)&placeholder, [OFPlaceholderMutableString class]); } + (instancetype)alloc { if (self == [OFMutableString class]) return (id)&placeholder; return [super alloc]; } #ifdef OF_HAVE_UNICODE_TABLES - (void)of_convertWithWordStartTable: (const OFUnichar *const [])startTable wordMiddleTable: (const OFUnichar *const [])middleTable wordStartTableSize: (size_t)startTableSize wordMiddleTableSize: (size_t)middleTableSize { void *pool = objc_autoreleasePoolPush(); const OFUnichar *characters = self.characters; size_t length = self.length; bool isStart = true; for (size_t i = 0; i < length; i++) { const OFUnichar *const *table; size_t tableSize; OFUnichar c = characters[i]; if (isStart) { table = startTable; tableSize = middleTableSize; } else { table = middleTable; tableSize = middleTableSize; } if (c >> 8 < tableSize && table[c >> 8][c & 0xFF]) [self setCharacter: table[c >> 8][c & 0xFF] atIndex: i]; isStart = OFASCIIIsSpace(c); } objc_autoreleasePoolPop(pool); } #else static void convert(OFMutableString *self, char (*startFunction)(char), char (*middleFunction)(char)) { void *pool = objc_autoreleasePoolPush(); const OFUnichar *characters = self.characters; size_t length = self.length; bool isStart = true; for (size_t i = 0; i < length; i++) { char (*function)(char) = (isStart ? startFunction : middleFunction); OFUnichar c = characters[i]; if (c <= 0x7F) [self setCharacter: (int)function(c) atIndex: i]; isStart = OFASCIIIsSpace(c); } objc_autoreleasePoolPop(pool); } #endif - (void)setCharacter: (OFUnichar)character atIndex: (size_t)idx { void *pool = objc_autoreleasePoolPush(); OFString *string = [OFString stringWithCharacters: &character length: 1]; [self replaceCharactersInRange: OFMakeRange(idx, 1) withString: string]; objc_autoreleasePoolPop(pool); } - (void)appendString: (OFString *)string { [self insertString: string atIndex: self.length]; } - (void)appendCharacters: (const OFUnichar *)characters length: (size_t)length { void *pool = objc_autoreleasePoolPush(); [self appendString: [OFString stringWithCharacters: characters length: length]]; objc_autoreleasePoolPop(pool); } - (void)appendUTF8String: (const char *)UTF8String { void *pool = objc_autoreleasePoolPush(); [self appendString: [OFString stringWithUTF8String: UTF8String]]; objc_autoreleasePoolPop(pool); } - (void)appendUTF8String: (const char *)UTF8String length: (size_t)UTF8StringLength { void *pool = objc_autoreleasePoolPush(); [self appendString: [OFString stringWithUTF8String: UTF8String length: UTF8StringLength]]; objc_autoreleasePoolPop(pool); } - (void)appendCString: (const char *)cString encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); [self appendString: [OFString stringWithCString: cString encoding: encoding]]; objc_autoreleasePoolPop(pool); } - (void)appendCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength { void *pool = objc_autoreleasePoolPush(); [self appendString: [OFString stringWithCString: cString encoding: encoding length: cStringLength]]; objc_autoreleasePoolPop(pool); } - (void)appendFormat: (OFConstantString *)format, ... { va_list arguments; va_start(arguments, format); [self appendFormat: format arguments: arguments]; va_end(arguments); } - (void)appendFormat: (OFConstantString *)format arguments: (va_list)arguments { char *UTF8String; int UTF8StringLength; if (format == nil) @throw [OFInvalidArgumentException exception]; if ((UTF8StringLength = _OFVASPrintF(&UTF8String, format.UTF8String, arguments)) == -1) @throw [OFInvalidFormatException exception]; @try { [self appendUTF8String: UTF8String length: UTF8StringLength]; } @finally { free(UTF8String); } } #ifdef OF_HAVE_UNICODE_TABLES - (void)uppercase { [self of_convertWithWordStartTable: _OFUnicodeUppercaseTable wordMiddleTable: _OFUnicodeUppercaseTable wordStartTableSize: _OFUnicodeUppercaseTableSize wordMiddleTableSize: _OFUnicodeUppercaseTableSize]; } - (void)lowercase { [self of_convertWithWordStartTable: _OFUnicodeLowercaseTable wordMiddleTable: _OFUnicodeLowercaseTable wordStartTableSize: _OFUnicodeLowercaseTableSize wordMiddleTableSize: _OFUnicodeLowercaseTableSize]; } - (void)capitalize { [self of_convertWithWordStartTable: _OFUnicodeTitlecaseTable wordMiddleTable: _OFUnicodeLowercaseTable wordStartTableSize: _OFUnicodeTitlecaseTableSize wordMiddleTableSize: _OFUnicodeLowercaseTableSize]; } #else - (void)uppercase { convert(self, OFASCIIToUpper, OFASCIIToUpper); } - (void)lowercase { convert(self, OFASCIIToLower, OFASCIIToLower); } - (void)capitalize { convert(self, OFASCIIToUpper, OFASCIIToLower); } #endif - (void)insertString: (OFString *)string atIndex: (size_t)idx { [self replaceCharactersInRange: OFMakeRange(idx, 0) withString: string]; } - (void)deleteCharactersInRange: (OFRange)range { [self replaceCharactersInRange: range withString: @""]; } - (void)replaceCharactersInRange: (OFRange)range withString: (OFString *)replacement { OF_UNRECOGNIZED_SELECTOR } - (void)replaceOccurrencesOfString: (OFString *)string withString: (OFString *)replacement { [self replaceOccurrencesOfString: string withString: replacement options: 0 range: OFMakeRange(0, self.length)]; } - (void)replaceOccurrencesOfString: (OFString *)string withString: (OFString *)replacement options: (int)options range: (OFRange)range { void *pool = objc_autoreleasePoolPush(), *pool2; const OFUnichar *characters; const OFUnichar *searchCharacters = string.characters; size_t searchLength = string.length; size_t replacementLength = replacement.length; if (string == nil || replacement == nil) @throw [OFInvalidArgumentException exception]; if (range.length > SIZE_MAX - range.location || range.location + range.length > self.length) @throw [OFOutOfRangeException exception]; if (searchLength > range.length) { objc_autoreleasePoolPop(pool); return; } pool2 = objc_autoreleasePoolPush(); characters = self.characters; for (size_t i = range.location; i <= range.length - searchLength; i++) { if (memcmp(characters + i, searchCharacters, searchLength * sizeof(OFUnichar)) != 0) continue; [self replaceCharactersInRange: OFMakeRange(i, searchLength) withString: replacement]; range.length -= searchLength; range.length += replacementLength; i += replacementLength - 1; objc_autoreleasePoolPop(pool2); pool2 = objc_autoreleasePoolPush(); characters = self.characters; } objc_autoreleasePoolPop(pool); } - (void)deleteLeadingWhitespaces { void *pool = objc_autoreleasePoolPush(); const OFUnichar *characters = self.characters; size_t i, length = self.length; for (i = 0; i < length; i++) { OFUnichar c = characters[i]; if (!OFASCIIIsSpace(c)) break; } objc_autoreleasePoolPop(pool); [self deleteCharactersInRange: OFMakeRange(0, i)]; } - (void)deleteTrailingWhitespaces { void *pool; const OFUnichar *characters, *p; size_t length, d; length = self.length; if (length == 0) return; pool = objc_autoreleasePoolPush(); characters = self.characters; d = 0; for (p = characters + length - 1; p >= characters; p--) { if (!OFASCIIIsSpace(*p)) break; d++; } objc_autoreleasePoolPop(pool); [self deleteCharactersInRange: OFMakeRange(length - d, d)]; } - (void)deleteEnclosingWhitespaces { [self deleteLeadingWhitespaces]; [self deleteTrailingWhitespaces]; } - (id)copy { return [[OFString alloc] initWithString: self]; } - (void)makeImmutable { } @end objfw-1.1.6/src/OFMutableTarArchiveEntry.h000066400000000000000000000044251465614216400204150ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFTarArchiveEntry.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFMutableTarArchiveEntry OFTarArchiveEntry.h ObjFW/OFTarArchiveEntry.h * * @brief A class which represents a mutable entry of a tar archive. */ @interface OFMutableTarArchiveEntry: OFTarArchiveEntry { OF_RESERVE_IVARS(OFMutableTarArchiveEntry, 4) } /** * @brief The type of the archive entry. * * See @ref OFTarArchiveEntryType. */ @property (readwrite, nonatomic) OFTarArchiveEntryType type; /** * @brief The file name of the target (for a hard link or symbolic link). */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *targetFileName; /** * @brief The device major (if the file is a device). */ @property (readwrite, nonatomic) unsigned long deviceMajor; /** * @brief The device major (if the file is a device). */ @property (readwrite, nonatomic) unsigned long deviceMinor; /** * @brief Creates a new OFMutableTarArchiveEntry with the specified file name. * * @param fileName The file name for the OFTarArchiveEntry * @return A new, autoreleased OFTarArchiveEntry */ + (instancetype)entryWithFileName: (OFString *)fileName; /** * @brief Initializes an already allocated OFMutableTarArchiveEntry with the * specified file name. * * @param fileName The file name for the OFTarArchiveEntry * @return An initialized OFTarArchiveEntry */ - (instancetype)initWithFileName: (OFString *)fileName; /** * @brief Converts the OFMutableTarArchiveEntry to an immutable * OFTarArchiveEntry. */ - (void)makeImmutable; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFMutableTarArchiveEntry.m000066400000000000000000000067421465614216400204260ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFMutableTarArchiveEntry.h" #import "OFTarArchiveEntry+Private.h" #import "OFDate.h" #import "OFNumber.h" #import "OFString.h" @implementation OFMutableTarArchiveEntry @dynamic fileName, POSIXPermissions, ownerAccountID, groupOwnerAccountID; @dynamic compressedSize, uncompressedSize, modificationDate, type; @dynamic targetFileName, ownerAccountName, groupOwnerAccountName, deviceMajor; @dynamic deviceMinor; /* * The following is optional in OFMutableArchiveEntry, but Apple GCC 4.0.1 is * buggy and needs this to stop complaining. */ @dynamic fileComment; + (instancetype)entryWithFileName: (OFString *)fileName { return [[[self alloc] initWithFileName: fileName] autorelease]; } - (instancetype)initWithFileName: (OFString *)fileName { self = [super of_init]; @try { _fileName = [fileName copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (id)copy { OFMutableTarArchiveEntry *copy = [self mutableCopy]; [copy makeImmutable]; return copy; } - (void)setFileName: (OFString *)fileName { OFString *old = _fileName; _fileName = [fileName copy]; [old release]; } - (void)setPOSIXPermissions: (OFNumber *)POSIXPermissions { OFNumber *old = _POSIXPermissions; _POSIXPermissions = [POSIXPermissions retain]; [old release]; } - (void)setOwnerAccountID: (OFNumber *)ownerAccountID { OFNumber *old = _ownerAccountID; _ownerAccountID = [ownerAccountID retain]; [old release]; } - (void)setGroupOwnerAccountID: (OFNumber *)groupOwnerAccountID { OFNumber *old = _groupOwnerAccountID; _groupOwnerAccountID = [groupOwnerAccountID retain]; [old release]; } - (void)setCompressedSize: (unsigned long long)compressedSize { _compressedSize = compressedSize; } - (void)setUncompressedSize: (unsigned long long)uncompressedSize { _uncompressedSize = uncompressedSize; } - (void)setModificationDate: (OFDate *)modificationDate { OFDate *old = _modificationDate; _modificationDate = [modificationDate retain]; [old release]; } - (void)setType: (OFTarArchiveEntryType)type { _type = type; } - (void)setTargetFileName: (OFString *)targetFileName { OFString *old = _targetFileName; _targetFileName = [targetFileName copy]; [old release]; } - (void)setOwnerAccountName: (OFString *)ownerAccountName { OFString *old = _ownerAccountName; _ownerAccountName = [ownerAccountName copy]; [old release]; } - (void)setGroupOwnerAccountName: (OFString *)groupOwnerAccountName { OFString *old = _groupOwnerAccountName; _groupOwnerAccountName = [groupOwnerAccountName copy]; [old release]; } - (void)setDeviceMajor: (unsigned long)deviceMajor { _deviceMajor = deviceMajor; } - (void)setDeviceMinor: (unsigned long)deviceMinor { _deviceMinor = deviceMinor; } - (void)makeImmutable { object_setClass(self, [OFTarArchiveEntry class]); } @end objfw-1.1.6/src/OFMutableTriple.h000066400000000000000000000033701465614216400166000ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFTriple.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFMutableTriple OFTriple.h ObjFW/OFTriple.h * * @brief A class for storing a triple of three objects. */ @interface OFMutableTriple OF_GENERIC(FirstType, SecondType, ThirdType): OFTriple OF_GENERIC(FirstType, SecondType, ThirdType) #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # define FirstType id # define SecondType id # define ThirdType id #endif { OF_RESERVE_IVARS(OFMutableTriple, 4) } /** * @brief The first object of the triple. */ @property (readwrite, nonatomic, retain) FirstType firstObject; /** * @brief The second object of the triple. */ @property (readwrite, nonatomic, retain) SecondType secondObject; /** * @brief The third object of the triple. */ @property (readwrite, nonatomic, retain) ThirdType thirdObject; /** * @brief Converts the mutable triple to an immutable triple. */ - (void)makeImmutable; #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # undef FirstType # undef SecondType # undef ThirdType #endif @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFMutableTriple.m000066400000000000000000000026031465614216400166030ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFMutableTriple.h" @implementation OFMutableTriple @dynamic firstObject, secondObject, thirdObject; - (void)setFirstObject: (id)firstObject { id old = _firstObject; _firstObject = [firstObject retain]; [old release]; } - (void)setSecondObject: (id)secondObject { id old = _secondObject; _secondObject = [secondObject retain]; [old release]; } - (void)setThirdObject: (id)thirdObject { id old = _thirdObject; _thirdObject = [thirdObject retain]; [old release]; } - (id)copy { OFMutableTriple *copy = [self mutableCopy]; [copy makeImmutable]; return copy; } - (void)makeImmutable { object_setClass(self, [OFTriple class]); } @end objfw-1.1.6/src/OFMutableUTF8String.h000066400000000000000000000017071465614216400172600ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFMutableString.h" #import "OFUTF8String.h" OF_ASSUME_NONNULL_BEGIN @interface OFMutableUTF8String: OFMutableString { struct OFUTF8StringIvars *restrict _s; struct OFUTF8StringIvars _storage; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFMutableUTF8String.m000066400000000000000000000427671465614216400173000ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #include #import "OFMutableUTF8String.h" #import "OFASPrintF.h" #import "OFString.h" #import "OFUTF8String.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "unicode.h" @implementation OFMutableUTF8String + (void)initialize { if (self == [OFMutableUTF8String class]) [self inheritMethodsFromClass: [OFUTF8String class]]; } - (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String freeWhenDone: (bool)freeWhenDone { self = [self initWithUTF8String: UTF8String]; if (freeWhenDone) OFFreeMemory(UTF8String); return self; } - (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String length: (size_t)UTF8StringLength freeWhenDone: (bool)freeWhenDone { self = [self initWithUTF8String: UTF8String length: UTF8StringLength]; if (freeWhenDone) OFFreeMemory(UTF8String); return self; } #ifdef OF_HAVE_UNICODE_TABLES - (void)of_convertWithWordStartTable: (const OFUnichar *const [])startTable wordMiddleTable: (const OFUnichar *const [])middleTable wordStartTableSize: (size_t)startTableSize wordMiddleTableSize: (size_t)middleTableSize { OFUnichar *unicodeString; size_t unicodeLen, newCStringLength; size_t i, j; char *newCString; bool isStart = true; if (!_s->isUTF8) { uint8_t t; const OFUnichar *const *table; OFAssert(startTableSize >= 1 && middleTableSize >= 1); _s->hasHash = false; for (i = 0; i < _s->cStringLength; i++) { if (isStart) table = startTable; else table = middleTable; isStart = OFASCIIIsSpace(_s->cString[i]); if ((t = table[0][(uint8_t)_s->cString[i]]) != 0) _s->cString[i] = t; } return; } unicodeLen = self.length; unicodeString = OFAllocMemory(unicodeLen, sizeof(OFUnichar)); i = j = 0; newCStringLength = 0; while (i < _s->cStringLength) { const OFUnichar *const *table; size_t tableSize; OFUnichar c; ssize_t cLen; if (isStart) { table = startTable; tableSize = middleTableSize; } else { table = middleTable; tableSize = middleTableSize; } cLen = _OFUTF8StringDecode(_s->cString + i, _s->cStringLength - i, &c); if (cLen <= 0 || c > 0x10FFFF) { OFFreeMemory(unicodeString); @throw [OFInvalidEncodingException exception]; } isStart = OFASCIIIsSpace(c); if (c >> 8 < tableSize) { OFUnichar tc = table[c >> 8][c & 0xFF]; if (tc) c = tc; } unicodeString[j++] = c; if (c < 0x80) newCStringLength++; else if (c < 0x800) newCStringLength += 2; else if (c < 0x10000) newCStringLength += 3; else if (c < 0x110000) newCStringLength += 4; else { OFFreeMemory(unicodeString); @throw [OFInvalidEncodingException exception]; } i += cLen; } @try { newCString = OFAllocMemory(newCStringLength + 1, 1); } @catch (id e) { OFFreeMemory(unicodeString); @throw e; } j = 0; for (i = 0; i < unicodeLen; i++) { size_t d; if ((d = _OFUTF8StringEncode(unicodeString[i], newCString + j)) == 0) { OFFreeMemory(unicodeString); OFFreeMemory(newCString); @throw [OFInvalidEncodingException exception]; } j += d; } OFAssert(j == newCStringLength); newCString[j] = 0; OFFreeMemory(unicodeString); OFFreeMemory(_s->cString); _s->hasHash = false; _s->cString = newCString; _s->cStringLength = newCStringLength; /* * Even though cStringLength can change, length cannot, therefore no * need to change it. */ } #endif - (void)setCharacter: (OFUnichar)character atIndex: (size_t)idx { char buffer[4]; OFUnichar c; size_t lenNew; ssize_t lenOld; if (_s->isUTF8) idx = _OFUTF8StringIndexToPosition(_s->cString, idx, _s->cStringLength); if (idx >= _s->cStringLength) @throw [OFOutOfRangeException exception]; /* Shortcut if old and new character both are ASCII */ if (character < 0x80 && !(_s->cString[idx] & 0x80)) { _s->hasHash = false; _s->cString[idx] = character; return; } if ((lenNew = _OFUTF8StringEncode(character, buffer)) == 0) @throw [OFInvalidEncodingException exception]; if ((lenOld = _OFUTF8StringDecode(_s->cString + idx, _s->cStringLength - idx, &c)) <= 0) @throw [OFInvalidEncodingException exception]; _s->hasHash = false; if (lenNew == (size_t)lenOld) memcpy(_s->cString + idx, buffer, lenNew); else if (lenNew > (size_t)lenOld) { _s->cString = OFResizeMemory(_s->cString, _s->cStringLength - lenOld + lenNew + 1, 1); memmove(_s->cString + idx + lenNew, _s->cString + idx + lenOld, _s->cStringLength - idx - lenOld); memcpy(_s->cString + idx, buffer, lenNew); _s->cStringLength -= lenOld; _s->cStringLength += lenNew; _s->cString[_s->cStringLength] = '\0'; if (character >= 0x80) _s->isUTF8 = true; } else if (lenNew < (size_t)lenOld) { memmove(_s->cString + idx + lenNew, _s->cString + idx + lenOld, _s->cStringLength - idx - lenOld); memcpy(_s->cString + idx, buffer, lenNew); _s->cStringLength -= lenOld; _s->cStringLength += lenNew; _s->cString[_s->cStringLength] = '\0'; if (character >= 0x80) _s->isUTF8 = true; @try { _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } } - (void)appendUTF8String: (const char *)UTF8String { size_t UTF8StringLength = strlen(UTF8String); size_t length; if (UTF8StringLength >= 3 && memcmp(UTF8String, "\xEF\xBB\xBF", 3) == 0) { UTF8String += 3; UTF8StringLength -= 3; } switch (_OFUTF8StringCheck(UTF8String, UTF8StringLength, &length)) { case 1: _s->isUTF8 = true; break; case -1: @throw [OFInvalidEncodingException exception]; } _s->hasHash = false; _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + UTF8StringLength + 1, 1); memcpy(_s->cString + _s->cStringLength, UTF8String, UTF8StringLength + 1); _s->cStringLength += UTF8StringLength; _s->length += length; } - (void)appendUTF8String: (const char *)UTF8String length: (size_t)UTF8StringLength { size_t length; if (UTF8StringLength >= 3 && memcmp(UTF8String, "\xEF\xBB\xBF", 3) == 0) { UTF8String += 3; UTF8StringLength -= 3; } switch (_OFUTF8StringCheck(UTF8String, UTF8StringLength, &length)) { case 1: _s->isUTF8 = true; break; case -1: @throw [OFInvalidEncodingException exception]; } _s->hasHash = false; _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + UTF8StringLength + 1, 1); memcpy(_s->cString + _s->cStringLength, UTF8String, UTF8StringLength); _s->cStringLength += UTF8StringLength; _s->length += length; _s->cString[_s->cStringLength] = 0; } - (void)appendCString: (const char *)cString encoding: (OFStringEncoding)encoding { [self appendCString: cString encoding: encoding length: strlen(cString)]; } - (void)appendCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength { if (encoding == OFStringEncodingUTF8) [self appendUTF8String: cString length: cStringLength]; else { void *pool = objc_autoreleasePoolPush(); [self appendString: [OFString stringWithCString: cString encoding: encoding length: cStringLength]]; objc_autoreleasePoolPop(pool); } } - (void)appendString: (OFString *)string { size_t UTF8StringLength; if (string == nil) @throw [OFInvalidArgumentException exception]; UTF8StringLength = string.UTF8StringLength; _s->hasHash = false; _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + UTF8StringLength + 1, 1); memcpy(_s->cString + _s->cStringLength, string.UTF8String, UTF8StringLength); _s->cStringLength += UTF8StringLength; _s->length += string.length; _s->cString[_s->cStringLength] = 0; if ([string isKindOfClass: [OFUTF8String class]] || [string isKindOfClass: [OFMutableUTF8String class]]) { if (((OFMutableUTF8String *)string)->_s->isUTF8) _s->isUTF8 = true; } else _s->isUTF8 = true; } - (void)appendCharacters: (const OFUnichar *)characters length: (size_t)length { char *tmp = OFAllocMemory((length * 4) + 1, 1); @try { size_t j = 0; bool isUTF8 = false; for (size_t i = 0; i < length; i++) { size_t len = _OFUTF8StringEncode(characters[i], tmp + j); if (len == 0) @throw [OFInvalidEncodingException exception]; if (len > 1) isUTF8 = true; j += len; } tmp[j] = '\0'; _s->hasHash = false; _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + j + 1, 1); memcpy(_s->cString + _s->cStringLength, tmp, j + 1); _s->cStringLength += j; _s->length += length; if (isUTF8) _s->isUTF8 = true; } @finally { OFFreeMemory(tmp); } } - (void)appendFormat: (OFConstantString *)format arguments: (va_list)arguments { char *UTF8String; int UTF8StringLength; if (format == nil) @throw [OFInvalidArgumentException exception]; if ((UTF8StringLength = _OFVASPrintF(&UTF8String, format.UTF8String, arguments)) == -1) @throw [OFInvalidFormatException exception]; @try { [self appendUTF8String: UTF8String length: UTF8StringLength]; } @finally { free(UTF8String); } } - (void)insertString: (OFString *)string atIndex: (size_t)idx { size_t newCStringLength; if (idx > _s->length) @throw [OFOutOfRangeException exception]; if (_s->isUTF8) idx = _OFUTF8StringIndexToPosition(_s->cString, idx, _s->cStringLength); newCStringLength = _s->cStringLength + string.UTF8StringLength; _s->hasHash = false; _s->cString = OFResizeMemory(_s->cString, newCStringLength + 1, 1); memmove(_s->cString + idx + string.UTF8StringLength, _s->cString + idx, _s->cStringLength - idx); memcpy(_s->cString + idx, string.UTF8String, string.UTF8StringLength); _s->cString[newCStringLength] = '\0'; _s->cStringLength = newCStringLength; _s->length += string.length; if ([string isKindOfClass: [OFUTF8String class]] || [string isKindOfClass: [OFMutableUTF8String class]]) { if (((OFMutableUTF8String *)string)->_s->isUTF8) _s->isUTF8 = true; } else _s->isUTF8 = true; } - (void)deleteCharactersInRange: (OFRange)range { size_t start = range.location; size_t end = range.location + range.length; if (range.length > SIZE_MAX - range.location || end > _s->length) @throw [OFOutOfRangeException exception]; if (_s->isUTF8) { start = _OFUTF8StringIndexToPosition(_s->cString, start, _s->cStringLength); end = _OFUTF8StringIndexToPosition(_s->cString, end, _s->cStringLength); } memmove(_s->cString + start, _s->cString + end, _s->cStringLength - end); _s->hasHash = false; _s->length -= range.length; _s->cStringLength -= end - start; _s->cString[_s->cStringLength] = 0; @try { _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } - (void)replaceCharactersInRange: (OFRange)range withString: (OFString *)replacement { size_t start = range.location; size_t end = range.location + range.length; size_t newCStringLength, newLength; if (replacement == nil) @throw [OFInvalidArgumentException exception]; if (range.length > SIZE_MAX - range.location || end > _s->length) @throw [OFOutOfRangeException exception]; newLength = _s->length - range.length + replacement.length; if (_s->isUTF8) { start = _OFUTF8StringIndexToPosition(_s->cString, start, _s->cStringLength); end = _OFUTF8StringIndexToPosition(_s->cString, end, _s->cStringLength); } newCStringLength = _s->cStringLength - (end - start) + replacement.UTF8StringLength; _s->hasHash = false; /* * If the new string is bigger, we need to resize it first so we can * memmove() the rest of the string to the end. * * We must not resize the string if the new string is smaller, because * then we can't memmove() the rest of the string forward as the rest is * lost due to the resize! */ if (newCStringLength > _s->cStringLength) _s->cString = OFResizeMemory(_s->cString, newCStringLength + 1, 1); memmove(_s->cString + start + replacement.UTF8StringLength, _s->cString + end, _s->cStringLength - end); memcpy(_s->cString + start, replacement.UTF8String, replacement.UTF8StringLength); _s->cString[newCStringLength] = '\0'; /* * If the new string is smaller, we can safely resize it now as we're * done with memmove(). */ if (newCStringLength < _s->cStringLength) _s->cString = OFResizeMemory(_s->cString, newCStringLength + 1, 1); _s->cStringLength = newCStringLength; _s->length = newLength; if ([replacement isKindOfClass: [OFUTF8String class]] || [replacement isKindOfClass: [OFMutableUTF8String class]]) { if (((OFMutableUTF8String *)replacement)->_s->isUTF8) _s->isUTF8 = true; } else _s->isUTF8 = true; } - (void)replaceOccurrencesOfString: (OFString *)string withString: (OFString *)replacement options: (int)options range: (OFRange)range { const char *searchString = string.UTF8String; const char *replacementString = replacement.UTF8String; size_t searchLength = string.UTF8StringLength; size_t replacementLength = replacement.UTF8StringLength; size_t last, newCStringLength, newLength; char *newCString; if (string == nil || replacement == nil) @throw [OFInvalidArgumentException exception]; if (range.length > SIZE_MAX - range.location || range.location + range.length > self.length) @throw [OFOutOfRangeException exception]; if (_s->isUTF8) { range.location = _OFUTF8StringIndexToPosition(_s->cString, range.location, _s->cStringLength); range.length = _OFUTF8StringIndexToPosition( _s->cString + range.location, range.length, _s->cStringLength - range.location); } if (string.UTF8StringLength > range.length) return; newCString = NULL; newCStringLength = 0; newLength = _s->length; last = 0; for (size_t i = range.location; i <= range.length - searchLength; i++) { if (memcmp(_s->cString + i, searchString, searchLength) != 0) continue; @try { newCString = OFResizeMemory(newCString, newCStringLength + i - last + replacementLength + 1, 1); } @catch (id e) { OFFreeMemory(newCString); @throw e; } memcpy(newCString + newCStringLength, _s->cString + last, i - last); memcpy(newCString + newCStringLength + i - last, replacementString, replacementLength); newCStringLength += i - last + replacementLength; newLength = newLength - string.length + replacement.length; i += searchLength - 1; last = i + 1; } @try { newCString = OFResizeMemory(newCString, newCStringLength + _s->cStringLength - last + 1, 1); } @catch (id e) { OFFreeMemory(newCString); @throw e; } memcpy(newCString + newCStringLength, _s->cString + last, _s->cStringLength - last); newCStringLength += _s->cStringLength - last; newCString[newCStringLength] = 0; OFFreeMemory(_s->cString); _s->hasHash = false; _s->cString = newCString; _s->cStringLength = newCStringLength; _s->length = newLength; if ([replacement isKindOfClass: [OFUTF8String class]] || [replacement isKindOfClass: [OFMutableUTF8String class]]) { if (((OFMutableUTF8String *)replacement)->_s->isUTF8) _s->isUTF8 = true; } else _s->isUTF8 = true; } - (void)deleteLeadingWhitespaces { size_t i; for (i = 0; i < _s->cStringLength; i++) if (!OFASCIIIsSpace(_s->cString[i])) break; _s->hasHash = false; _s->cStringLength -= i; _s->length -= i; memmove(_s->cString, _s->cString + i, _s->cStringLength); _s->cString[_s->cStringLength] = '\0'; @try { _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } - (void)deleteTrailingWhitespaces { size_t d; char *p; _s->hasHash = false; d = 0; for (p = _s->cString + _s->cStringLength - 1; p >= _s->cString; p--) { if (!OFASCIIIsSpace(*p)) break; *p = '\0'; d++; } _s->cStringLength -= d; _s->length -= d; @try { _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } - (void)deleteEnclosingWhitespaces { size_t d, i; char *p; _s->hasHash = false; d = 0; for (p = _s->cString + _s->cStringLength - 1; p >= _s->cString; p--) { if (!OFASCIIIsSpace(*p)) break; *p = '\0'; d++; } _s->cStringLength -= d; _s->length -= d; for (i = 0; i < _s->cStringLength; i++) if (!OFASCIIIsSpace(_s->cString[i])) break; _s->cStringLength -= i; _s->length -= i; memmove(_s->cString, _s->cString + i, _s->cStringLength); _s->cString[_s->cStringLength] = '\0'; @try { _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } - (void)makeImmutable { object_setClass(self, [OFUTF8String class]); } @end objfw-1.1.6/src/OFMutableZIPArchiveEntry.h000066400000000000000000000071421465614216400203300ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFZIPArchiveEntry.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFMutableZIPArchiveEntry OFZIPArchiveEntry.h ObjFW/OFZIPArchiveEntry.h * * @brief A class which represents a mutable entry in the central directory of * a ZIP archive. */ @interface OFMutableZIPArchiveEntry: OFZIPArchiveEntry { OF_RESERVE_IVARS(OFMutableZIPArchiveEntry, 4) } /** * @brief The extra field of the entry. * * The item size *must* be 1! */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFData *extraField; /** * @brief The version which made the entry. * * The lower 8 bits are the ZIP specification version.@n * The upper 8 bits are the attribute compatibility. * See @ref OFZIPArchiveEntryAttributeCompatibility. */ @property (readwrite, nonatomic) OFZIPArchiveEntryAttributeCompatibility versionMadeBy; /** * @brief The minimum version required to extract the file. * * The lower 8 bits are the ZIP specification version.@n * The upper 8 bits are the attribute compatibility. * See @ref OFZIPArchiveEntryAttributeCompatibility. */ @property (readwrite, nonatomic) OFZIPArchiveEntryAttributeCompatibility minVersionNeeded; /** * @brief The compression method of the entry. * * Supported values are: * Value | Description * --------------------------------------------|--------------- * OFZIPArchiveEntryCompressionMethodNone | No compression * OFZIPArchiveEntryCompressionMethodDeflate | Deflate * OFZIPArchiveEntryCompressionMethodDeflate64 | Deflate64 * * Other values may be returned, but the file cannot be extracted then. */ @property (readwrite, nonatomic) OFZIPArchiveEntryCompressionMethod compressionMethod; /** * @brief The CRC32 checksum of the entry's file. */ @property (readwrite, nonatomic) uint32_t CRC32; /** * @brief The version specific attributes. * * The meaning of the version specific attributes depends on the attribute * compatibility part of the version that made the entry. */ @property (readwrite, nonatomic) uint32_t versionSpecificAttributes; /** * @brief The general purpose bit flag of the entry. * * See the ZIP specification for details. */ @property (readwrite, nonatomic) uint16_t generalPurposeBitFlag; /** * @brief Creates a new OFMutableZIPArchiveEntry with the specified file name. * * @param fileName The file name for the OFZIPArchiveEntry * @return A new, autoreleased OFZIPArchiveEntry */ + (instancetype)entryWithFileName: (OFString *)fileName; /** * @brief Initializes an already allocated OFMutableZIPArchiveEntry with the * specified file name. * * @param fileName The file name for the OFZIPArchiveEntry * @return An initialized OFZIPArchiveEntry */ - (instancetype)initWithFileName: (OFString *)fileName; /** * @brief Converts the OFMutableZIPArchiveEntry to an immutable * OFZIPArchiveEntry. */ - (void)makeImmutable; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFMutableZIPArchiveEntry.m000066400000000000000000000112771465614216400203410ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFMutableZIPArchiveEntry.h" #import "OFZIPArchiveEntry+Private.h" #import "OFData.h" #import "OFDate.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" @implementation OFMutableZIPArchiveEntry @dynamic fileName, fileComment, extraField, versionMadeBy, minVersionNeeded; @dynamic modificationDate, compressionMethod, compressedSize, uncompressedSize; @dynamic CRC32, versionSpecificAttributes, generalPurposeBitFlag; @dynamic of_startDiskNumber, of_localFileHeaderOffset; /* * The following are optional in OFMutableArchiveEntry, but Apple GCC 4.0.1 is * buggy and needs this to stop complaining. */ @dynamic POSIXPermissions, ownerAccountID, groupOwnerAccountID; @dynamic ownerAccountName, groupOwnerAccountName; + (instancetype)entryWithFileName: (OFString *)fileName { return [[[self alloc] initWithFileName: fileName] autorelease]; } - (instancetype)initWithFileName: (OFString *)fileName { self = [super of_init]; @try { void *pool = objc_autoreleasePoolPush(); if (fileName.UTF8StringLength > UINT16_MAX) @throw [OFOutOfRangeException exception]; _fileName = [fileName copy]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (id)copy { OFMutableZIPArchiveEntry *copy = [self mutableCopy]; [copy makeImmutable]; return copy; } - (void)setFileName: (OFString *)fileName { void *pool = objc_autoreleasePoolPush(); OFString *old; if (fileName.UTF8StringLength > UINT16_MAX) @throw [OFOutOfRangeException exception]; old = _fileName; _fileName = [fileName copy]; [old release]; objc_autoreleasePoolPop(pool); } - (void)setFileComment: (OFString *)fileComment { void *pool = objc_autoreleasePoolPush(); OFString *old; if (fileComment.UTF8StringLength > UINT16_MAX) @throw [OFOutOfRangeException exception]; old = _fileComment; _fileComment = [fileComment copy]; [old release]; objc_autoreleasePoolPop(pool); } - (void)setExtraField: (OFData *)extraField { void *pool = objc_autoreleasePoolPush(); OFData *old; if (extraField.itemSize != 1) @throw [OFInvalidArgumentException exception]; if (extraField.count > UINT16_MAX) @throw [OFOutOfRangeException exception]; old = _extraField; _extraField = [extraField copy]; [old release]; objc_autoreleasePoolPop(pool); } - (void)setVersionMadeBy: (OFZIPArchiveEntryAttributeCompatibility)versionMadeBy { _versionMadeBy = versionMadeBy; } - (void)setMinVersionNeeded: (OFZIPArchiveEntryAttributeCompatibility)minVersionNeeded { _minVersionNeeded = minVersionNeeded; } - (void)setModificationDate: (OFDate *)date { void *pool = objc_autoreleasePoolPush(); _lastModifiedFileDate = (((date.localYear - 1980) & 0xFF) << 9) | ((date.localMonthOfYear & 0x0F) << 5) | (date.localDayOfMonth & 0x1F); _lastModifiedFileTime = ((date.localHour & 0x1F) << 11) | ((date.localMinute & 0x3F) << 5) | ((date.second >> 1) & 0x0F); objc_autoreleasePoolPop(pool); } - (void)setCompressionMethod: (OFZIPArchiveEntryCompressionMethod)compressionMethod { _compressionMethod = compressionMethod; } - (void)setCompressedSize: (unsigned long long)compressedSize { _compressedSize = compressedSize; } - (void)setUncompressedSize: (unsigned long long)uncompressedSize { _uncompressedSize = uncompressedSize; } - (void)setCRC32: (uint32_t)CRC32 { _CRC32 = CRC32; } - (void)setVersionSpecificAttributes: (uint32_t)versionSpecificAttributes { _versionSpecificAttributes = versionSpecificAttributes; } - (void)setGeneralPurposeBitFlag: (uint16_t)generalPurposeBitFlag { _generalPurposeBitFlag = generalPurposeBitFlag; } - (void)of_setStartDiskNumber: (uint32_t)startDiskNumber { _startDiskNumber = startDiskNumber; } - (void)of_setLocalFileHeaderOffset: (int64_t)localFileHeaderOffset { if (localFileHeaderOffset < 0) @throw [OFInvalidArgumentException exception]; _localFileHeaderOffset = localFileHeaderOffset; } - (void)makeImmutable { object_setClass(self, [OFZIPArchiveEntry class]); } @end objfw-1.1.6/src/OFMutableZooArchiveEntry.h000066400000000000000000000054061465614216400204360ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFZooArchiveEntry.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFMutableZooArchiveEntry OFZooArchiveEntry.h ObjFW/OFZooArchiveEntry.h * * @brief A class which represents a mutable entry in a Zoo archive. */ @interface OFMutableZooArchiveEntry: OFZooArchiveEntry { OF_RESERVE_IVARS(OFMutableZooArchiveEntry, 4) } /** * @brief The header type of the entry. */ @property (readwrite, nonatomic) uint8_t headerType; /** * @brief The compression method of the entry. */ @property (readwrite, nonatomic) uint8_t compressionMethod; /** * @brief The CRC16 of the file. */ @property (readwrite, nonatomic) uint16_t CRC16; /** * @brief The minimum version required to extract the file. * * The upper 8 bits are the major version and the lower 8 bits the minor * version. */ @property (readwrite, nonatomic) uint16_t minVersionNeeded; /** * @brief Whether the file was deleted. */ @property (readwrite, nonatomic, getter=isDeleted) bool deleted; /** * @brief The operating system identifier of the file. */ @property (readwrite, nonatomic) uint16_t operatingSystemIdentifier; /** * @brief The time zone in which the file was stored, as an offset in hours * from UTC (as a float). * * @note Make sure to set the correct time zone before setting the modification * date! */ @property OF_NULLABLE_PROPERTY (readwrite, retain, nonatomic) OFNumber *timeZone; /** * @brief Creates a new OFMutableZooArchiveEntry with the specified file name. * * @param fileName The file name for the OFZooArchiveEntry * @return A new, autoreleased OFZooArchiveEntry */ + (instancetype)entryWithFileName: (OFString *)fileName; /** * @brief Initializes an already allocated OFMutableZooArchiveEntry with the * specified file name. * * @param fileName The file name for the OFZooArchiveEntry * @return An initialized OFZooArchiveEntry */ - (instancetype)initWithFileName: (OFString *)fileName; /** * @brief Converts the OFMutableZooArchiveEntry to an immutable * OFZooArchiveEntry. */ - (void)makeImmutable; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFMutableZooArchiveEntry.m000066400000000000000000000111321465614216400204340ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFMutableZooArchiveEntry.h" #import "OFZooArchiveEntry+Private.h" #import "OFDate.h" #import "OFNumber.h" #import "OFString.h" @implementation OFMutableZooArchiveEntry @dynamic headerType, compressionMethod, modificationDate, CRC16; @dynamic uncompressedSize, compressedSize, minVersionNeeded, deleted; @dynamic fileComment, fileName, operatingSystemIdentifier, POSIXPermissions; @dynamic timeZone; /* * The following properties are not implemented, but old Apple GCC requries * @dynamic for @optional properties. */ @dynamic ownerAccountID, groupOwnerAccountID, ownerAccountName; @dynamic groupOwnerAccountName; + (instancetype)entryWithFileName: (OFString *)fileName { return [[[self alloc] initWithFileName: fileName] autorelease]; } - (instancetype)initWithFileName: (OFString *)fileName { self = [super of_init]; @try { void *pool = objc_autoreleasePoolPush(); self.fileName = fileName; self.modificationDate = [OFDate date]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (id)copy { OFMutableZooArchiveEntry *copy = [self mutableCopy]; [copy makeImmutable]; return copy; } - (void)setHeaderType: (uint8_t)headerType { _headerType = headerType; } - (void)setCompressionMethod: (uint8_t)compressionMethod { _compressionMethod = compressionMethod; } - (void)setModificationDate: (OFDate *)date { void *pool = objc_autoreleasePoolPush(); if (_timeZone == 0x7F) { _lastModifiedFileDate = (((date.localYear - 1980) & 0xFF) << 9) | ((date.localMonthOfYear & 0x0F) << 5) | (date.localDayOfMonth & 0x1F); _lastModifiedFileTime = ((date.localHour & 0x1F) << 11) | ((date.localMinute & 0x3F) << 5) | ((date.second >> 1) & 0x0F); } else { date = [date dateByAddingTimeInterval: -(OFTimeInterval)_timeZone * 900]; _lastModifiedFileDate = (((date.year - 1980) & 0xFF) << 9) | ((date.monthOfYear & 0x0F) << 5) | (date.dayOfMonth & 0x1F); _lastModifiedFileTime = ((date.hour & 0x1F) << 11) | ((date.minute & 0x3F) << 5) | ((date.second >> 1) & 0x0F); } objc_autoreleasePoolPop(pool); } - (void)setCRC16: (uint16_t)CRC16 { _CRC16 = CRC16; } - (void)setUncompressedSize: (unsigned long long)uncompressedSize { _uncompressedSize = uncompressedSize; } - (void)setCompressedSize: (unsigned long long)compressedSize { _compressedSize = compressedSize; } - (void)setMinVersionNeeded: (uint16_t)minVersionNeeded { _minVersionNeeded = minVersionNeeded; } - (void)setDeleted: (bool)deleted { _deleted = deleted; } - (void)setFileComment: (OFString *)fileComment { OFString *old = _fileComment; _fileComment = [fileComment copy]; [old release]; } - (void)setFileName: (OFString *)fileName { void *pool = objc_autoreleasePoolPush(); OFString *oldFileName = _fileName, *oldDirectoryName = _directoryName; size_t lastSlash; lastSlash = [fileName rangeOfString: @"/" options: OFStringSearchBackwards].location; if (lastSlash != OFNotFound) { _fileName = [[fileName substringWithRange: OFMakeRange( lastSlash + 1, fileName.length - lastSlash - 1)] copy]; [oldFileName release]; _directoryName = [[fileName substringWithRange: OFMakeRange(0, lastSlash)] copy]; [oldDirectoryName release]; } else { _fileName = [fileName copy]; [oldFileName release]; [_directoryName release]; _directoryName = nil; } objc_autoreleasePoolPop(pool); } - (void)setOperatingSystemIdentifier: (uint16_t)operatingSystemIdentifier { _operatingSystemIdentifier = operatingSystemIdentifier; } - (void)setPOSIXPermissions: (OFNumber *)POSIXPermissions { OFNumber *old = _POSIXPermissions; _POSIXPermissions = [POSIXPermissions copy]; [old release]; } - (void)setTimeZone: (OFNumber *)timeZone { if (timeZone == nil) _timeZone = 0x7F; else _timeZone = -timeZone.floatValue * 4; } - (void)makeImmutable { object_setClass(self, [OFZooArchiveEntry class]); } @end objfw-1.1.6/src/OFMutex.h000066400000000000000000000026761465614216400151410ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFLocking.h" #import "OFPlainMutex.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFMutex OFMutex.h ObjFW/OFMutex.h * * @brief A class for creating mutual exclusions. * * If the mutex is deallocated while being held, it throws an * @ref OFStillLockedException. While this might break ARC's assumption that no * object ever throws in dealloc, it is considered a fatal programmer error * that should terminate the application. */ @interface OFMutex: OFObject { OFPlainMutex _mutex; bool _initialized; OFString *_Nullable _name; OF_RESERVE_IVARS(OFMutex, 4) } /** * @brief Creates a new mutex. * * @return A new autoreleased mutex. */ + (instancetype)mutex; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFMutex.m000066400000000000000000000043331465614216400151360ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFMutex.h" #import "OFString.h" #import "OFInitializationFailedException.h" #import "OFLockFailedException.h" #import "OFStillLockedException.h" #import "OFUnlockFailedException.h" @implementation OFMutex @synthesize name = _name; + (instancetype)mutex { return [[[self alloc] init] autorelease]; } - (instancetype)init { self = [super init]; if (OFPlainMutexNew(&_mutex) != 0) { Class c = self.class; [self release]; @throw [OFInitializationFailedException exceptionWithClass: c]; } _initialized = true; return self; } - (void)dealloc { if (_initialized) { int error = OFPlainMutexFree(&_mutex); if (error != 0) { OFEnsure(error == EBUSY); @throw [OFStillLockedException exceptionWithLock: self]; } } [_name release]; [super dealloc]; } - (void)lock { int error = OFPlainMutexLock(&_mutex); if (error != 0) @throw [OFLockFailedException exceptionWithLock: self errNo: error]; } - (bool)tryLock { int error = OFPlainMutexTryLock(&_mutex); if (error != 0) { if (error == EBUSY) return false; else @throw [OFLockFailedException exceptionWithLock: self errNo: error]; } return true; } - (void)unlock { int error = OFPlainMutexUnlock(&_mutex); if (error != 0) @throw [OFUnlockFailedException exceptionWithLock: self errNo: error]; } - (OFString *)description { if (_name == nil) return super.description; return [OFString stringWithFormat: @"<%@: %@>", self.className, _name]; } @end objfw-1.1.6/src/OFNSDNSResourceRecord.h000066400000000000000000000037301465614216400175630ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFDNSResourceRecord.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFNSDNSResourceRecord \ * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h * * @brief A class representing an NS DNS resource record. */ OF_SUBCLASSING_RESTRICTED @interface OFNSDNSResourceRecord: OFDNSResourceRecord { OFString *_authoritativeHost; } /** * @brief The authoritative host of the resource record. */ @property (readonly, nonatomic) OFString *authoritativeHost; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFNSDNSResourceRecord with the * specified name, class, authoritative host and time to live. * * @param name The name for the resource record * @param DNSClass The class code for the resource record * @param authoritativeHost The authoritative host for the resource record * @param TTL The time to live for the resource record * @return An initialized OFNSDNSResourceRecord */ - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass authoritativeHost: (OFString *)authoritativeHost TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFNSDNSResourceRecord.m000066400000000000000000000052331465614216400175700ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFMXDNSResourceRecord.h" @implementation OFNSDNSResourceRecord @synthesize authoritativeHost = _authoritativeHost; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass authoritativeHost: (OFString *)authoritativeHost TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: DNSClass recordType: OFDNSRecordTypeNS TTL: TTL]; @try { _authoritativeHost = [authoritativeHost copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_authoritativeHost release]; [super dealloc]; } - (bool)isEqual: (id)object { OFNSDNSResourceRecord *record; if (object == self) return true; if (![object isKindOfClass: [OFNSDNSResourceRecord class]]) return false; record = object; if (record->_name != _name && ![record->_name isEqual: _name]) return false; if (record->_DNSClass != _DNSClass) return false; if (record->_recordType != _recordType) return false; if (record->_authoritativeHost != _authoritativeHost && ![record->_authoritativeHost isEqual: _authoritativeHost]) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddByte(&hash, _DNSClass >> 8); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType >> 8); OFHashAddByte(&hash, _recordType); OFHashAddHash(&hash, _authoritativeHost.hash); OFHashFinalize(&hash); return hash; } - (OFString *)description { return [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tClass = %@\n" @"\tAuthoritative Host = %@\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFDNSClassName(_DNSClass), _authoritativeHost, _TTL]; } @end objfw-1.1.6/src/OFNotification.h000066400000000000000000000070731465614216400164610ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFConstantString; @class OFDictionary OF_GENERIC(KeyType, ObjectType); /** * @brief A name for a notification. */ typedef OFConstantString *OFNotificationName; /** * @class OFNotification OFNotification.h ObjFW/OFNotification.h * * @brief A class to represent a notification for or from * @ref OFNotificationCenter. */ @interface OFNotification: OFObject { OFNotificationName _name; id _Nullable _object; OFDictionary *_Nullable _userInfo; OF_RESERVE_IVARS(OFNotification, 4) } /** * @brief The name of the notification. */ @property (readonly, nonatomic) OFNotificationName name; /** * @brief The object of the notification. This is commonly the sender of the * notification. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) id object; /** * @brief Additional information about the notification. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFDictionary *userInfo; /** * @brief Creates a new notification with the specified name and object. * * @param name The name for the notification * @param object The object for the notification. This is commonly the sender * of the notification. * @return A new, autoreleased OFNotification */ + (instancetype)notificationWithName: (OFNotificationName)name object: (nullable id)object; /** * @brief Creates a new notification with the specified name, object and * additional information. * * @param name The name for the notification * @param object The object for the notification. This is commonly the sender * of the notification. * @param userInfo Additional information for the notification * @return A new, autoreleased OFNotification */ + (instancetype)notificationWithName: (OFNotificationName)name object: (nullable id)object userInfo: (nullable OFDictionary *)userInfo; /** * @brief Initializes an already allocated notification with the specified * name and object. * * @param name The name for the notification * @param object The object for the notification. This is commonly the sender * of the notification. * @return An initialized OFNotification */ - (instancetype)initWithName: (OFNotificationName)name object: (nullable id)object; /** * @brief Initializes an already allocated notification with the specified * name, object and additional information. * * @param name The name for the notification * @param object The object for the notification. This is commonly the sender * of the notification. * @param userInfo Additional information for the notification * @return An initialized OFNotification */ - (instancetype)initWithName: (OFNotificationName)name object: (nullable id)object userInfo: (nullable OFDictionary *)userInfo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFNotification.m000066400000000000000000000036751465614216400164720ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFNotification.h" #import "OFDictionary.h" #import "OFString.h" @implementation OFNotification @synthesize name = _name, object = _object, userInfo = _userInfo; + (instancetype)notificationWithName: (OFNotificationName)name object: (id)object { return [[[self alloc] initWithName: name object: object] autorelease]; } + (instancetype)notificationWithName: (OFNotificationName)name object: (id)object userInfo: (OFDictionary *)userInfo { return [[[self alloc] initWithName: name object: object userInfo: userInfo] autorelease]; } - (instancetype)initWithName: (OFNotificationName)name object: (id)object { return [self initWithName: name object: object userInfo: nil]; } - (instancetype)initWithName: (OFNotificationName)name object: (id)object userInfo: (OFDictionary *)userInfo { self = [super init]; @try { _name = [name copy]; _object = [object retain]; _userInfo = [userInfo copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_name release]; [_object release]; [_userInfo release]; [super dealloc]; } - (id)copy { return [self retain]; } @end objfw-1.1.6/src/OFNotificationCenter.h000066400000000000000000000111121465614216400176070ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFNotification.h" OF_ASSUME_NONNULL_BEGIN @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); #ifdef OF_HAVE_THREADS @class OFMutex; #endif #ifdef OF_HAVE_BLOCKS /** * @brief A block which is called when a notification has been posted. * * @param notification The notification that has been posted */ typedef void (^OFNotificationCenterBlock)(OFNotification *notification); #endif /** * @class OFNotificationCenter OFNotificationCenter.h \ * ObjFW/OFNotificationCenter.h * * @brief A class to send and register for notifications. */ #ifndef OF_NOTIFICATION_CENTER_M OF_SUBCLASSING_RESTRICTED #endif @interface OFNotificationCenter: OFObject { #ifdef OF_HAVE_THREADS OFMutex *_mutex; #endif OFMutableDictionary *_handles; } #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nonatomic) OFNotificationCenter *defaultCenter; #endif /** * @brief Returns the default notification center. */ + (OFNotificationCenter *)defaultCenter; /** * @brief Adds an observer for the specified notification and object. * * @param observer The object that should receive notifications * @param selector The selector to call on the observer on notifications. The * method must take exactly one object of type * @ref OFNotification. * @param name The name of the notification to observe * @param object The object that should be sending the notification, or `nil` * if the object should be ignored to determine what * notifications to deliver */ - (void)addObserver: (id)observer selector: (SEL)selector name: (OFNotificationName)name object: (nullable id)object; /** * @brief Removes an observer. All parameters must match those used with * @ref addObserver:selector:name:object:. * * @param observer The observer that was specified when adding the observer * @param selector The selector that was specified when adding the observer * @param name The name that was specified when adding the observer * @param object The object that was specified when adding the observer */ - (void)removeObserver: (id)observer selector: (SEL)selector name: (OFNotificationName)name object: (nullable id)object; #ifdef OF_HAVE_BLOCKS /** * @brief Adds an observer for the specified notification and object. * * To remove the observer again, use @ref removeObserver:. * * @param name The name of the notification to observe * @param object The object that should be sending the notification, or `nil` * if the object should be ignored to determine what * notifications to deliver * @param block The block to handle notifications * @return An opaque object to remove the observer again */ - (id)addObserverForName: (OFNotificationName)name object: (nullable id)object usingBlock: (OFNotificationCenterBlock)block; /** * @brief Removes an observer. The specified observer must be one returned by * @ref addObserver:selector:name:object:. * * @param observer The object that was returned when adding the observer */ - (void)removeObserver: (id)observer; #endif /** * @brief Posts the specified notification. * * @param notification The notification to post */ - (void)postNotification: (OFNotification *)notification; /** * @brief Posts a notification with the specified name and object. * * @param name The name for the notification * @param object The object for the notification */ - (void)postNotificationName: (OFNotificationName)name object: (nullable id)object; /** * @brief Posts a notification with the specified name, object and additional * information. * * @param name The name for the notification * @param object The object for the notification * @param userInfo Additional information for the notification */ - (void)postNotificationName: (OFNotificationName)name object: (nullable id)object userInfo: (nullable OFDictionary *)userInfo; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFNotificationCenter.m000066400000000000000000000202401465614216400176160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #define OF_NOTIFICATION_CENTER_M #include "config.h" #import "OFNotificationCenter.h" #import "OFArray.h" #import "OFDictionary.h" #ifdef OF_HAVE_THREADS # import "OFMutex.h" #endif #import "OFSet.h" #import "OFString.h" #import "OFInvalidArgumentException.h" @interface OFDefaultNotificationCenter: OFNotificationCenter @end @interface OFNotificationCenterHandle: OFObject { @public OFNotificationName _name; id _observer; SEL _selector; unsigned long _selectorHash; #ifdef OF_HAVE_BLOCKS OFNotificationCenterBlock _block; #endif id _object; } - (instancetype)initWithName: (OFNotificationName)name observer: (id)observer selector: (SEL)selector object: (id)object; #ifdef OF_HAVE_BLOCKS - (instancetype)initWithName: (OFNotificationName)name object: (id)object block: (OFNotificationCenterBlock)block; #endif @end static OFNotificationCenter *defaultCenter; @implementation OFNotificationCenterHandle - (instancetype)initWithName: (OFNotificationName)name observer: (id)observer selector: (SEL)selector object: (id)object { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); _name = [name copy]; _observer = observer; _selector = selector; _object = [object retain]; _selectorHash = [[OFString stringWithUTF8String: sel_getName(_selector)] hash]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } #ifdef OF_HAVE_BLOCKS - (instancetype)initWithName: (OFNotificationName)name object: (id)object block: (OFNotificationCenterBlock)block { self = [super init]; @try { _name = [name copy]; _object = [object retain]; _block = [block copy]; } @catch (id e) { [self release]; @throw e; } return self; } #endif - (void)dealloc { [_name release]; [_object release]; #ifdef OF_HAVE_BLOCKS [_block release]; #endif [super dealloc]; } - (bool)isEqual: (OFNotificationCenterHandle *)handle { if (![handle isKindOfClass: [OFNotificationCenterHandle class]]) return false; if (![handle->_name isEqual: _name]) return false; if (handle->_observer != _observer && ![handle->_observer isEqual: _observer]) return false; if (handle->_selector != _selector && !sel_isEqual(handle->_selector, _selector)) return false; #ifdef OF_HAVE_BLOCKS if (handle->_block != _block) return false; #endif if (handle->_object != _object && ![handle->_object isEqual: _object]) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddHash(&hash, [_observer hash]); OFHashAddHash(&hash, _selectorHash); #ifdef OF_HAVE_BLOCKS if (_block != NULL) OFHashAddHash(&hash, (unsigned long)(uintptr_t)_block); #endif OFHashAddHash(&hash, [_object hash]); OFHashFinalize(&hash); return hash; } @end @implementation OFNotificationCenter + (void)initialize { if (self != [OFNotificationCenter class]) return; defaultCenter = [[OFDefaultNotificationCenter alloc] init]; } + (OFNotificationCenter *)defaultCenter { return defaultCenter; } - (instancetype)init { self = [super init]; @try { #ifdef OF_HAVE_THREADS _mutex = [[OFMutex alloc] init]; #endif _handles = [[OFMutableDictionary alloc] init]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { #ifdef OF_HAVE_THREADS [_mutex release]; #endif [_handles release]; [super dealloc]; } - (void)of_addObserver: (OFNotificationCenterHandle *)handle { #ifdef OF_HAVE_THREADS [_mutex lock]; @try { #endif OFMutableSet *handlesForName = [_handles objectForKey: handle->_name]; if (handlesForName == nil) { handlesForName = [OFMutableSet set]; [_handles setObject: handlesForName forKey: handle->_name]; } [handlesForName addObject: handle]; #ifdef OF_HAVE_THREADS } @finally { [_mutex unlock]; } #endif } - (void)addObserver: (id)observer selector: (SEL)selector name: (OFNotificationName)name object: (id)object { void *pool = objc_autoreleasePoolPush(); [self of_addObserver: [[[OFNotificationCenterHandle alloc] initWithName: name observer: observer selector: selector object: object] autorelease]]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS - (id)addObserverForName: (OFNotificationName)name object: (id)object usingBlock: (OFNotificationCenterBlock)block { void *pool = objc_autoreleasePoolPush(); OFNotificationCenterHandle *handle = [[[OFNotificationCenterHandle alloc] initWithName: name object: object block: block] autorelease]; [self of_addObserver: handle]; [handle retain]; objc_autoreleasePoolPop(pool); return [handle autorelease]; } #endif - (void)removeObserver: (id)handle_ { OFNotificationCenterHandle *handle; void *pool; if (![handle_ isKindOfClass: [OFNotificationCenterHandle class]]) @throw [OFInvalidArgumentException exception]; handle = handle_; pool = objc_autoreleasePoolPush(); /* {} required to avoid -Wmisleading-indentation false positive. */ if (![handle isKindOfClass: [OFNotificationCenterHandle class]]) { @throw [OFInvalidArgumentException exception]; } #ifdef OF_HAVE_THREADS [_mutex lock]; @try { #endif OFNotificationName name = [[handle->_name copy] autorelease]; OFMutableSet *handlesForName = [_handles objectForKey: name]; [handlesForName removeObject: handle]; if (handlesForName.count == 0) [_handles removeObjectForKey: name]; #ifdef OF_HAVE_THREADS } @finally { [_mutex unlock]; } #endif objc_autoreleasePoolPop(pool); } - (void)removeObserver: (id)observer selector: (SEL)selector name: (OFNotificationName)name object: (id)object { void *pool = objc_autoreleasePoolPush(); [self removeObserver: [[[OFNotificationCenterHandle alloc] initWithName: name observer: observer selector: selector object: object] autorelease]]; objc_autoreleasePoolPop(pool); } - (void)postNotification: (OFNotification *)notification { void *pool = objc_autoreleasePoolPush(); OFMutableArray *matchedHandles = [OFMutableArray array]; #ifdef OF_HAVE_THREADS [_mutex lock]; @try { #endif for (OFNotificationCenterHandle *handle in [_handles objectForKey: notification.name]) if (handle->_object == nil || handle->_object == notification.object) [matchedHandles addObject: handle]; #ifdef OF_HAVE_THREADS } @finally { [_mutex unlock]; } #endif for (OFNotificationCenterHandle *handle in matchedHandles) { #ifdef OF_HAVE_BLOCKS if (handle->_block != NULL) handle->_block(notification); else { #endif void (*callback)(id, SEL, OFNotification *) = (void (*)(id, SEL, OFNotification *)) [handle->_observer methodForSelector: handle->_selector]; callback(handle->_observer, handle->_selector, notification); #ifdef OF_HAVE_BLOCKS } #endif } objc_autoreleasePoolPop(pool); } - (void)postNotificationName: (OFNotificationName)name object: (nullable id)object { [self postNotificationName: name object: object userInfo: nil]; } - (void)postNotificationName: (OFNotificationName)name object: (nullable id)object userInfo: (nullable OFDictionary *)userInfo { void *pool = objc_autoreleasePoolPush(); [self postNotification: [OFNotification notificationWithName: name object: object userInfo: userInfo]]; objc_autoreleasePoolPop(pool); } @end @implementation OFDefaultNotificationCenter OF_SINGLETON_METHODS @end objfw-1.1.6/src/OFNull.h000066400000000000000000000022771465614216400147460ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFJSONRepresentation.h" #import "OFMessagePackRepresentation.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFNull OFNull.h ObjFW/OFNull.h * * @brief A class for representing null values in collections. */ OF_SUBCLASSING_RESTRICTED @interface OFNull: OFObject /** * @brief Returns an OFNull singleton. * * @return An OFNull singleton */ + (OFNull *)null; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFNull.m000066400000000000000000000033351465614216400147470ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFNull.h" #import "OFData.h" #import "OFString.h" #import "OFInvalidArgumentException.h" @interface OFNull () - (OFString *) of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options depth: (size_t)depth; @end static OFNull *null = nil; @implementation OFNull + (void)initialize { null = [[self alloc] init]; } + (OFNull *)null { return null; } - (OFString *)description { return @""; } - (id)copy { return self; } - (OFString *)JSONRepresentation { return [self of_JSONRepresentationWithOptions: 0 depth: 0]; } - (OFString *)JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options { return [self of_JSONRepresentationWithOptions: options depth: 0]; } - (OFString *) of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options depth: (size_t)depth { return @"null"; } - (OFData *)messagePackRepresentation { uint8_t type = 0xC0; return [OFData dataWithItems: &type count: 1]; } OF_SINGLETON_METHODS @end objfw-1.1.6/src/OFNumber.h000066400000000000000000000235131465614216400152600ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif #include "objfw-defs.h" #ifdef OF_HAVE_SYS_TYPES_H # include #endif #import "OFJSONRepresentation.h" #import "OFMessagePackRepresentation.h" #import "OFValue.h" OF_ASSUME_NONNULL_BEGIN /** @file */ /** * @class OFNumber OFNumber.h ObjFW/OFNumber.h * * @brief Provides a way to store a number in an object. */ @interface OFNumber: OFValue /** * @brief The OFNumber as a `bool`. */ @property (readonly, nonatomic) bool boolValue; /** * @brief The OFNumber as a `signed char`. */ @property (readonly, nonatomic) signed char charValue; /** * @brief The OFNumber as a `short`. */ @property (readonly, nonatomic) short shortValue; /** * @brief The OFNumber as an `int`. */ @property (readonly, nonatomic) int intValue; /** * @brief The OFNumber as a `long`. */ @property (readonly, nonatomic) long longValue; /** * @brief The OFNumber as a `long long`. */ @property (readonly, nonatomic) long long longLongValue; /** * @brief The OFNumber as an `unsigned char`. */ @property (readonly, nonatomic) unsigned char unsignedCharValue; /** * @brief The OFNumber as an `unsigned short`. */ @property (readonly, nonatomic) unsigned short unsignedShortValue; /** * @brief The OFNumber as an `unsigned int`. */ @property (readonly, nonatomic) unsigned int unsignedIntValue; /** * @brief The OFNumber as an `unsigned long`. */ @property (readonly, nonatomic) unsigned long unsignedLongValue; /** * @brief The OFNumber as an `unsigned long long`. */ @property (readonly, nonatomic) unsigned long long unsignedLongLongValue; /** * @brief The OFNumber as a `float`. */ @property (readonly, nonatomic) float floatValue; /** * @brief The OFNumber as a `double`. */ @property (readonly, nonatomic) double doubleValue; /** * @brief The OFNumber as a string. */ @property (readonly, nonatomic) OFString *stringValue; + (instancetype)valueWithPointer: (const void *)pointer OF_UNAVAILABLE; + (instancetype)valueWithNonretainedObject: (id)object OF_UNAVAILABLE; + (instancetype)valueWithRange: (OFRange)range OF_UNAVAILABLE; + (instancetype)valueWithPoint: (OFPoint)point OF_UNAVAILABLE; + (instancetype)valueWithSize: (OFSize)size OF_UNAVAILABLE; + (instancetype)valueWithRect: (OFRect)rect OF_UNAVAILABLE; /** * @brief Creates a new OFNumber with the specified `bool`. * * @param value The `bool` value which the OFNumber should contain * @return A new autoreleased OFNumber */ + (instancetype)numberWithBool: (bool)value; /** * @brief Creates a new OFNumber with the specified `signed char`. * * @param value The `signed char` value which the OFNumber should contain * @return A new autoreleased OFNumber */ + (instancetype)numberWithChar: (signed char)value; /** * @brief Creates a new OFNumber with the specified `short`. * * @param value The `short` value which the OFNumber should contain * @return A new autoreleased OFNumber */ + (instancetype)numberWithShort: (short)value; /** * @brief Creates a new OFNumber with the specified `int`. * * @param value The `int` value which the OFNumber should contain * @return A new autoreleased OFNumber */ + (instancetype)numberWithInt: (int)value; /** * @brief Creates a new OFNumber with the specified `long`. * * @param value The `long` value which the OFNumber should contain * @return A new autoreleased OFNumber */ + (instancetype)numberWithLong: (long)value; /** * @brief Creates a new OFNumber with the specified `long long`. * * @param value The `long long` value which the OFNumber should contain * @return A new autoreleased OFNumber */ + (instancetype)numberWithLongLong: (long long)value; /** * @brief Creates a new OFNumber with the specified `unsigned char`. * * @param value The `unsigned char` value which the OFNumber should contain * @return A new autoreleased OFNumber */ + (instancetype)numberWithUnsignedChar: (unsigned char)value; /** * @brief Creates a new OFNumber with the specified `unsigned short`. * * @param value The `unsigned short` value which the OFNumber should contain * @return A new autoreleased OFNumber */ + (instancetype)numberWithUnsignedShort: (unsigned short)value; /** * @brief Creates a new OFNumber with the specified `unsigned int`. * * @param value The `unsigned int` value which the OFNumber should contain * @return A new autoreleased OFNumber */ + (instancetype)numberWithUnsignedInt: (unsigned int)value; /** * @brief Creates a new OFNumber with the specified `unsigned long`. * * @param value The `unsigned long` value which the OFNumber should contain * @return A new autoreleased OFNumber */ + (instancetype)numberWithUnsignedLong: (unsigned long)value; /** * @brief Creates a new OFNumber with the specified `unsigned long long`. * * @param value The `unsigned long long` value which the OFNumber should contain * @return A new autoreleased OFNumber */ + (instancetype)numberWithUnsignedLongLong: (unsigned long long)value; /** * @brief Creates a new OFNumber with the specified `float`. * * @param value The `float` value which the OFNumber should contain * @return A new autoreleased OFNumber */ + (instancetype)numberWithFloat: (float)value; /** * @brief Creates a new OFNumber with the specified `double`. * * @param value The `double` value which the OFNumber should contain * @return A new autoreleased OFNumber */ + (instancetype)numberWithDouble: (double)value; /** * @brief Initializes an already allocated OFNumber with the specified `bool`. * * @param value The `bool` value which the OFNumber should contain * @return An initialized OFNumber */ - (instancetype)initWithBool: (bool)value; /** * @brief Initializes an already allocated OFNumber with the specified * `signed char`. * * @param value The `signed char` value which the OFNumber should contain * @return An initialized OFNumber */ - (instancetype)initWithChar: (signed char)value; /** * @brief Initializes an already allocated OFNumber with the specified `short`. * * @param value The `short` value which the OFNumber should contain * @return An initialized OFNumber */ - (instancetype)initWithShort: (short)value; /** * @brief Initializes an already allocated OFNumber with the specified `int`. * * @param value The `int` value which the OFNumber should contain * @return An initialized OFNumber */ - (instancetype)initWithInt: (int)value; /** * @brief Initializes an already allocated OFNumber with the specified `long`. * * @param value The `long` value which the OFNumber should contain * @return An initialized OFNumber */ - (instancetype)initWithLong: (long)value; /** * @brief Initializes an already allocated OFNumber with the specified * `long long`. * * @param value The `long long` value which the OFNumber should contain * @return An initialized OFNumber */ - (instancetype)initWithLongLong: (long long)value; /** * @brief Initializes an already allocated OFNumber with the specified * `unsigned char`. * * @param value The `unsigned char` value which the OFNumber should contain * @return An initialized OFNumber */ - (instancetype)initWithUnsignedChar: (unsigned char)value; /** * @brief Initializes an already allocated OFNumber with the specified * `unsigned short`. * * @param value The `unsigned short` value which the OFNumber should contain * @return An initialized OFNumber */ - (instancetype)initWithUnsignedShort: (unsigned short)value; /** * @brief Initializes an already allocated OFNumber with the specified * `unsigned int`. * * @param value The `unsigned int` value which the OFNumber should contain * @return An initialized OFNumber */ - (instancetype)initWithUnsignedInt: (unsigned int)value; /** * @brief Initializes an already allocated OFNumber with the specified * `unsigned long`. * * @param value The `unsigned long` value which the OFNumber should contain * @return An initialized OFNumber */ - (instancetype)initWithUnsignedLong: (unsigned long)value; /** * @brief Initializes an already allocated OFNumber with the specified * `unsigned long long`. * * @param value The `unsigned long long` value which the OFNumber should contain * @return An initialized OFNumber */ - (instancetype)initWithUnsignedLongLong: (unsigned long long)value; /** * @brief Initializes an already allocated OFNumber with the specified `float`. * * @param value The `float` value which the OFNumber should contain * @return An initialized OFNumber */ - (instancetype)initWithFloat: (float)value; /** * @brief Initializes an already allocated OFNumber with the specified `double`. * * @param value The `double` value which the OFNumber should contain * @return An initialized OFNumber */ - (instancetype)initWithDouble: (double)value; /** * @brief Compares the number to another number. * * @param number The number to compare the number to * @return The result of the comparison */ - (OFComparisonResult)compare: (OFNumber *)number; @end OF_ASSUME_NONNULL_END #if !defined(NSINTEGER_DEFINED) && !__has_feature(modules) /* Required for number literals to work */ @compatibility_alias NSNumber OFNumber; #endif objfw-1.1.6/src/OFNumber.m000066400000000000000000000477671465614216400153060ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFNumber.h" #import "OFConcreteNumber.h" #import "OFData.h" #import "OFString.h" #import "OFTaggedPointerNumber.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" @interface OFNumber () - (OFString *) of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options depth: (size_t)depth; @end @interface OFPlaceholderNumber: OFNumber @end @interface OFConcreteNumberSingleton: OFConcreteNumber @end static struct { Class isa; } placeholder; #define SINGLETON(var, sel, val) \ static OFConcreteNumberSingleton *var; \ \ static void \ var##Init(void) \ { \ var = [[OFConcreteNumberSingleton alloc] sel val]; \ } SINGLETON(falseNumber, initWithBool:, false) SINGLETON(trueNumber, initWithBool:, true) SINGLETON(charZeroNumber, initWithChar:, 0) SINGLETON(shortZeroNumber, initWithShort:, 0) SINGLETON(intZeroNumber, initWithInt:, 0) SINGLETON(longZeroNumber, initWithLong:, 0) SINGLETON(longLongZeroNumber, initWithLongLong:, 0) SINGLETON(unsignedCharZeroNumber, initWithUnsignedChar:, 0) SINGLETON(unsignedShortZeroNumber, initWithUnsignedShort:, 0) SINGLETON(unsignedIntZeroNumber, initWithUnsignedInt:, 0) SINGLETON(unsignedLongZeroNumber, initWithUnsignedLong:, 0) SINGLETON(unsignedLongLongZeroNumber, initWithUnsignedLongLong:, 0) SINGLETON(floatZeroNumber, initWithFloat:, 0) SINGLETON(doubleZeroNumber, initWithDouble:, 0) #undef SINGLETON static bool isUnsigned(OFNumber *number) { switch (*number.objCType) { case 'B': case 'C': case 'S': case 'I': case 'L': case 'Q': return true; default: return false; } } static bool isSigned(OFNumber *number) { switch (*number.objCType) { case 'c': case 's': case 'i': case 'l': case 'q': return true; default: return false; } } static bool isFloat(OFNumber *number) { switch (*number.objCType) { case 'f': case 'd': return true; default: return false; } } @implementation OFPlaceholderNumber - (instancetype)initWithBool: (bool)value { if (value) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, trueNumberInit); return (id)trueNumber; } else { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, falseNumberInit); return (id)falseNumber; } } #ifdef __clang__ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif - (instancetype)initWithChar: (signed char)value { if (value == 0) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, charZeroNumberInit); return (id)charZeroNumber; #ifdef OF_OBJFW_RUNTIME } else if ((unsigned char)value <= (UINTPTR_MAX >> OFTaggedPointerNumberTagBits)) { id ret = [OFTaggedPointerNumber numberWithChar: value]; if (ret != nil) return ret; #endif } return (id)[[OFConcreteNumber alloc] initWithChar: value]; } - (instancetype)initWithShort: (short)value { if (value == 0) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, shortZeroNumberInit); return (id)shortZeroNumber; #ifdef OF_OBJFW_RUNTIME } else if ((unsigned short)value <= (UINTPTR_MAX >> OFTaggedPointerNumberTagBits)) { id ret = [OFTaggedPointerNumber numberWithShort: value]; if (ret != nil) return ret; #endif } return (id)[[OFConcreteNumber alloc] initWithShort: value]; } - (instancetype)initWithInt: (int)value { if (value == 0) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, intZeroNumberInit); return (id)intZeroNumber; #ifdef OF_OBJFW_RUNTIME } else if ((unsigned int)value <= (UINTPTR_MAX >> OFTaggedPointerNumberTagBits)) { id ret = [OFTaggedPointerNumber numberWithInt: value]; if (ret != nil) return ret; #endif } return (id)[[OFConcreteNumber alloc] initWithInt: value]; } - (instancetype)initWithLong: (long)value { if (value == 0) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, longZeroNumberInit); return (id)longZeroNumber; #ifdef OF_OBJFW_RUNTIME } else if ((unsigned long)value <= (UINTPTR_MAX >> OFTaggedPointerNumberTagBits)) { id ret = [OFTaggedPointerNumber numberWithLong: value]; if (ret != nil) return ret; #endif } return (id)[[OFConcreteNumber alloc] initWithLong: value]; } - (instancetype)initWithLongLong: (long long)value { if (value == 0) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, longLongZeroNumberInit); return (id)longLongZeroNumber; #ifdef OF_OBJFW_RUNTIME } else if ((unsigned long long)value <= (UINTPTR_MAX >> OFTaggedPointerNumberTagBits)) { id ret = [OFTaggedPointerNumber numberWithLongLong: value]; if (ret != nil) return ret; #endif } return (id)[[OFConcreteNumber alloc] initWithLongLong: value]; } - (instancetype)initWithUnsignedChar: (unsigned char)value { if (value == 0) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, unsignedCharZeroNumberInit); return (id)unsignedCharZeroNumber; #ifdef OF_OBJFW_RUNTIME } else if (value <= (UINTPTR_MAX >> OFTaggedPointerNumberTagBits)) { id ret = [OFTaggedPointerNumber numberWithUnsignedChar: value]; if (ret != nil) return ret; #endif } return (id)[[OFConcreteNumber alloc] initWithUnsignedChar: value]; } - (instancetype)initWithUnsignedShort: (unsigned short)value { if (value == 0) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, unsignedShortZeroNumberInit); return (id)unsignedShortZeroNumber; #ifdef OF_OBJFW_RUNTIME } else if (value <= (UINTPTR_MAX >> OFTaggedPointerNumberTagBits)) { id ret = [OFTaggedPointerNumber numberWithUnsignedShort: value]; if (ret != nil) return ret; #endif } return (id)[[OFConcreteNumber alloc] initWithUnsignedShort: value]; } - (instancetype)initWithUnsignedInt: (unsigned int)value { if (value == 0) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, unsignedIntZeroNumberInit); return (id)unsignedIntZeroNumber; #ifdef OF_OBJFW_RUNTIME } else if (value <= (UINTPTR_MAX >> OFTaggedPointerNumberTagBits)) { id ret = [OFTaggedPointerNumber numberWithUnsignedInt: value]; if (ret != nil) return ret; #endif } return (id)[[OFConcreteNumber alloc] initWithUnsignedInt: value]; } - (instancetype)initWithUnsignedLong: (unsigned long)value { if (value == 0) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, unsignedLongZeroNumberInit); return (id)unsignedLongZeroNumber; #ifdef OF_OBJFW_RUNTIME } else if (value <= (UINTPTR_MAX >> OFTaggedPointerNumberTagBits)) { id ret = [OFTaggedPointerNumber numberWithUnsignedLong: value]; if (ret != nil) return ret; #endif } return (id)[[OFConcreteNumber alloc] initWithUnsignedLong: value]; } - (instancetype)initWithUnsignedLongLong: (unsigned long long)value { if (value == 0) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, unsignedLongLongZeroNumberInit); return (id)unsignedLongLongZeroNumber; #ifdef OF_OBJFW_RUNTIME } else if (value <= (UINTPTR_MAX >> OFTaggedPointerNumberTagBits)) { id ret = [OFTaggedPointerNumber numberWithUnsignedLongLong: value]; if (ret != nil) return ret; #endif } return (id)[[OFConcreteNumber alloc] initWithUnsignedLongLong: value]; } - (instancetype)initWithFloat: (float)value { if (value == 0) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, floatZeroNumberInit); return (id)floatZeroNumber; } return (id)[[OFConcreteNumber alloc] initWithFloat: value]; } - (instancetype)initWithDouble: (double)value { if (value == 0) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, doubleZeroNumberInit); return (id)doubleZeroNumber; } return (id)[[OFConcreteNumber alloc] initWithDouble: value]; } #ifdef __clang__ # pragma clang diagnostic pop #endif OF_SINGLETON_METHODS @end @implementation OFConcreteNumberSingleton OF_SINGLETON_METHODS @end @implementation OFNumber + (void)initialize { if (self == [OFNumber class]) object_setClass((id)&placeholder, [OFPlaceholderNumber class]); } + (instancetype)alloc { if (self == [OFNumber class]) return (id)&placeholder; return [super alloc]; } + (instancetype)valueWithPointer: (const void *)pointer { OF_UNRECOGNIZED_SELECTOR } + (instancetype)valueWithNonretainedObject: (id)object { OF_UNRECOGNIZED_SELECTOR } + (instancetype)valueWithRange: (OFRange)range { OF_UNRECOGNIZED_SELECTOR } + (instancetype)valueWithPoint: (OFPoint)point { OF_UNRECOGNIZED_SELECTOR } + (instancetype)valueWithSize: (OFSize)size { OF_UNRECOGNIZED_SELECTOR } + (instancetype)valueWithRect: (OFRect)rect { OF_UNRECOGNIZED_SELECTOR } + (instancetype)numberWithBool: (bool)value { return [[[self alloc] initWithBool: value] autorelease]; } + (instancetype)numberWithChar: (signed char)value { return [[[self alloc] initWithChar: value] autorelease]; } + (instancetype)numberWithShort: (short)value { return [[[self alloc] initWithShort: value] autorelease]; } + (instancetype)numberWithInt: (int)value { return [[[self alloc] initWithInt: value] autorelease]; } + (instancetype)numberWithLong: (long)value { return [[[self alloc] initWithLong: value] autorelease]; } + (instancetype)numberWithLongLong: (long long)value { return [[[self alloc] initWithLongLong: value] autorelease]; } + (instancetype)numberWithUnsignedChar: (unsigned char)value { return [[[self alloc] initWithUnsignedChar: value] autorelease]; } + (instancetype)numberWithUnsignedShort: (unsigned short)value { return [[[self alloc] initWithUnsignedShort: value] autorelease]; } + (instancetype)numberWithUnsignedInt: (unsigned int)value { return [[[self alloc] initWithUnsignedInt: value] autorelease]; } + (instancetype)numberWithUnsignedLong: (unsigned long)value { return [[[self alloc] initWithUnsignedLong: value] autorelease]; } + (instancetype)numberWithUnsignedLongLong: (unsigned long long)value { return [[[self alloc] initWithUnsignedLongLong: value] autorelease]; } + (instancetype)numberWithFloat: (float)value { return [[[self alloc] initWithFloat: value] autorelease]; } + (instancetype)numberWithDouble: (double)value { return [[[self alloc] initWithDouble: value] autorelease]; } - (instancetype)initWithBool: (bool)value { return [self initWithBytes: &value objCType: @encode(bool)]; } - (instancetype)initWithChar: (signed char)value { return [self initWithBytes: &value objCType: @encode(signed char)]; } - (instancetype)initWithShort: (short)value { return [self initWithBytes: &value objCType: @encode(short)]; } - (instancetype)initWithInt: (int)value { return [self initWithBytes: &value objCType: @encode(int)]; } - (instancetype)initWithLong: (long)value { return [self initWithBytes: &value objCType: @encode(long)]; } - (instancetype)initWithLongLong: (long long)value { return [self initWithBytes: &value objCType: @encode(long long)]; } - (instancetype)initWithUnsignedChar: (unsigned char)value { return [self initWithBytes: &value objCType: @encode(unsigned char)]; } - (instancetype)initWithUnsignedShort: (unsigned short)value { return [self initWithBytes: &value objCType: @encode(unsigned short)]; } - (instancetype)initWithUnsignedInt: (unsigned int)value { return [self initWithBytes: &value objCType: @encode(unsigned int)]; } - (instancetype)initWithUnsignedLong: (unsigned long)value { return [self initWithBytes: &value objCType: @encode(unsigned long)]; } - (instancetype)initWithUnsignedLongLong: (unsigned long long)value { return [self initWithBytes: &value objCType: @encode(unsigned long long)]; } - (instancetype)initWithFloat: (float)value { return [self initWithBytes: &value objCType: @encode(float)]; } - (instancetype)initWithDouble: (double)value { return [self initWithBytes: &value objCType: @encode(double)]; } - (long long)longLongValue { OF_UNRECOGNIZED_SELECTOR } - (unsigned long long)unsignedLongLongValue { OF_UNRECOGNIZED_SELECTOR } - (double)doubleValue { OF_UNRECOGNIZED_SELECTOR } - (bool)boolValue { return (bool)self.unsignedLongLongValue; } - (signed char)charValue { return (signed char)self.longLongValue; } - (short)shortValue { return (short)self.longLongValue; } - (int)intValue { return (int)self.longLongValue; } - (long)longValue { return (long)self.longLongValue; } - (unsigned char)unsignedCharValue { return (unsigned char)self.unsignedLongLongValue; } - (unsigned short)unsignedShortValue { return (unsigned short)self.unsignedLongLongValue; } - (unsigned int)unsignedIntValue { return (unsigned int)self.unsignedLongLongValue; } - (unsigned long)unsignedLongValue { return (unsigned long)self.unsignedLongLongValue; } - (float)floatValue { return (float)self.doubleValue; } - (bool)isEqual: (id)object { OFNumber *number; if (object == self) return true; if (![object isKindOfClass: [OFNumber class]]) return false; number = object; if (isFloat(self) || isFloat(number)) { double value1 = number.doubleValue; double value2 = self.doubleValue; if (isnan(value1) && isnan(value2)) return true; if (isnan(value1) || isnan(value2)) return false; return (value1 == value2); } if (isSigned(self) || isSigned(number)) return (number.longLongValue == self.longLongValue); return (number.unsignedLongLongValue == self.unsignedLongLongValue); } - (OFComparisonResult)compare: (OFNumber *)number { if (![number isKindOfClass: [OFNumber class]]) @throw [OFInvalidArgumentException exception]; if (isFloat(self) || isFloat(number)) { double double1 = self.doubleValue; double double2 = number.doubleValue; if (double1 > double2) return OFOrderedDescending; if (double1 < double2) return OFOrderedAscending; return OFOrderedSame; } else if (isSigned(self) || isSigned(number)) { long long int1 = self.longLongValue; long long int2 = number.longLongValue; if (int1 > int2) return OFOrderedDescending; if (int1 < int2) return OFOrderedAscending; return OFOrderedSame; } else { unsigned long long uint1 = self.unsignedLongLongValue; unsigned long long uint2 = number.unsignedLongLongValue; if (uint1 > uint2) return OFOrderedDescending; if (uint1 < uint2) return OFOrderedAscending; return OFOrderedSame; } } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); if (isFloat(self)) { double d; if (isnan(self.doubleValue)) return 0; d = OFToLittleEndianDouble(self.doubleValue); for (uint_fast8_t i = 0; i < sizeof(double); i++) OFHashAddByte(&hash, ((char *)&d)[i]); } else if (isSigned(self) || isUnsigned(self)) { unsigned long long value = self.unsignedLongLongValue; while (value != 0) { OFHashAddByte(&hash, value & 0xFF); value >>= 8; } } else @throw [OFInvalidFormatException exception]; OFHashFinalize(&hash); return hash; } - (id)copy { return [self retain]; } - (OFString *)description { return [self stringValue]; } - (OFString *)stringValue { if (self.objCType[0] == 'B' && self.objCType[1] == '\0') return (self.boolValue ? @"true" : @"false"); if (isFloat(self)) return [OFString stringWithFormat: @"%g", self.doubleValue]; if (isSigned(self)) return [OFString stringWithFormat: @"%lld", self.longLongValue]; if (isUnsigned(self)) return [OFString stringWithFormat: @"%llu", self.unsignedLongLongValue]; @throw [OFInvalidFormatException exception]; } - (OFString *)JSONRepresentation { return [self of_JSONRepresentationWithOptions: 0 depth: 0]; } - (OFString *)JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options { return [self of_JSONRepresentationWithOptions: options depth: 0]; } - (OFString *) of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options depth: (size_t)depth { double doubleValue; if (self.objCType[0] == 'B' && self.objCType[1] == '\0') return (self.boolValue ? @"true" : @"false"); doubleValue = self.doubleValue; if (isinf(doubleValue)) { if (options & OFJSONRepresentationOptionJSON5) { if (doubleValue > 0) return @"Infinity"; else return @"-Infinity"; } else @throw [OFInvalidArgumentException exception]; } return self.description; } - (OFData *)messagePackRepresentation { OFMutableData *data; const char *typeEncoding = self.objCType; if (typeEncoding[0] == '\0' || typeEncoding[1] != '\0') @throw [OFInvalidFormatException exception]; if (*typeEncoding == 'B') { uint8_t type = (self.boolValue ? 0xC3 : 0xC2); data = [OFMutableData dataWithItems: &type count: 1]; } else if (*typeEncoding == 'f') { uint8_t type = 0xCA; float tmp = OFToBigEndianFloat(self.floatValue); data = [OFMutableData dataWithCapacity: 5]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (*typeEncoding == 'd') { uint8_t type = 0xCB; double tmp = OFToBigEndianDouble(self.doubleValue); data = [OFMutableData dataWithCapacity: 9]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (isSigned(self)) { long long value = self.longLongValue; if (value >= -32 && value < 0) { uint8_t tmp = 0xE0 | ((uint8_t)(value - 32) & 0x1F); data = [OFMutableData dataWithItems: &tmp count: 1]; } else if (value >= INT8_MIN && value <= INT8_MAX) { uint8_t type = 0xD0; int8_t tmp = (int8_t)value; data = [OFMutableData dataWithCapacity: 2]; [data addItem: &type]; [data addItem: &tmp]; } else if (value >= INT16_MIN && value <= INT16_MAX) { uint8_t type = 0xD1; int16_t tmp = OFToBigEndian16((int16_t)value); data = [OFMutableData dataWithCapacity: 3]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (value >= INT32_MIN && value <= INT32_MAX) { uint8_t type = 0xD2; int32_t tmp = OFToBigEndian32((int32_t)value); data = [OFMutableData dataWithCapacity: 5]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (value >= INT64_MIN && value <= INT64_MAX) { uint8_t type = 0xD3; int64_t tmp = OFToBigEndian64((int64_t)value); data = [OFMutableData dataWithCapacity: 9]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exception]; } else if (isUnsigned(self)) { unsigned long long value = self.unsignedLongLongValue; if (value <= 127) { uint8_t tmp = ((uint8_t)value & 0x7F); data = [OFMutableData dataWithItems: &tmp count: 1]; } else if (value <= UINT8_MAX) { uint8_t type = 0xCC; uint8_t tmp = (uint8_t)value; data = [OFMutableData dataWithCapacity: 2]; [data addItem: &type]; [data addItem: &tmp]; } else if (value <= UINT16_MAX) { uint8_t type = 0xCD; uint16_t tmp = OFToBigEndian16((uint16_t)value); data = [OFMutableData dataWithCapacity: 3]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (value <= UINT32_MAX) { uint8_t type = 0xCE; uint32_t tmp = OFToBigEndian32((uint32_t)value); data = [OFMutableData dataWithCapacity: 5]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (value <= UINT64_MAX) { uint8_t type = 0xCF; uint64_t tmp = OFToBigEndian64((uint64_t)value); data = [OFMutableData dataWithCapacity: 9]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exception]; } else @throw [OFInvalidFormatException exception]; [data makeImmutable]; return data; } @end objfw-1.1.6/src/OFObject+KeyValueCoding.h000066400000000000000000000020041465614216400200730ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFKeyValueCoding.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif extern int _OFObject_KeyValueCoding_reference OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif @interface OFObject (KeyValueCoding) @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFObject+KeyValueCoding.m000066400000000000000000000153621465614216400201130ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFObject.h" #import "OFObject+KeyValueCoding.h" #import "OFArray.h" #import "OFMethodSignature.h" #import "OFNumber.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFOutOfMemoryException.h" #import "OFUndefinedKeyException.h" int _OFObject_KeyValueCoding_reference; @implementation OFObject (KeyValueCoding) - (id)valueForKey: (OFString *)key { void *pool = objc_autoreleasePoolPush(); SEL selector = sel_registerName(key.UTF8String); OFMethodSignature *methodSignature = [self methodSignatureForSelector: selector]; id ret; if (methodSignature == nil) { size_t keyLength; char *name; if ((keyLength = key.UTF8StringLength) < 1) { objc_autoreleasePoolPop(pool); return [self valueForUndefinedKey: key]; } name = OFAllocMemory(keyLength + 3, 1); @try { memcpy(name, "is", 2); memcpy(name + 2, key.UTF8String, keyLength); name[keyLength + 2] = '\0'; name[2] = OFASCIIToUpper(name[2]); selector = sel_registerName(name); } @finally { OFFreeMemory(name); } methodSignature = [self methodSignatureForSelector: selector]; if (methodSignature == NULL) { objc_autoreleasePoolPop(pool); return [self valueForUndefinedKey: key]; } switch (*methodSignature.methodReturnType) { case '@': case '#': objc_autoreleasePoolPop(pool); return [self valueForUndefinedKey: key]; } } if (methodSignature.numberOfArguments != 2 || *[methodSignature argumentTypeAtIndex: 0] != '@' || *[methodSignature argumentTypeAtIndex: 1] != ':') { objc_autoreleasePoolPop(pool); return [self valueForUndefinedKey: key]; } switch (*methodSignature.methodReturnType) { case '@': case '#': ret = [self performSelector: selector]; break; #define CASE(encoding, type, method) \ case encoding: \ { \ type (*getter)(id, SEL) = (type (*)(id, SEL)) \ [self methodForSelector: selector]; \ ret = [OFNumber method getter(self, selector)]; \ } \ break; CASE('B', bool, numberWithBool:) CASE('c', char, numberWithChar:) CASE('s', short, numberWithShort:) CASE('i', int, numberWithInt:) CASE('l', long, numberWithLong:) CASE('q', long long, numberWithLongLong:) CASE('C', unsigned char, numberWithUnsignedChar:) CASE('S', unsigned short, numberWithUnsignedShort:) CASE('I', unsigned int, numberWithUnsignedInt:) CASE('L', unsigned long, numberWithUnsignedLong:) CASE('Q', unsigned long long, numberWithUnsignedLongLong:) CASE('f', float, numberWithFloat:) CASE('d', double, numberWithDouble:) #undef CASE default: objc_autoreleasePoolPop(pool); return [self valueForUndefinedKey: key]; } [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (id)valueForKeyPath: (OFString *)keyPath { void *pool = objc_autoreleasePoolPush(); id ret = self; for (OFString *key in [keyPath componentsSeparatedByString: @"."]) ret = [ret valueForKey: key]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (id)valueForUndefinedKey: (OFString *)key { @throw [OFUndefinedKeyException exceptionWithObject: self key: key]; } - (void)setValue: (id)value forKey: (OFString *)key { void *pool = objc_autoreleasePoolPush(); size_t keyLength; char *name; SEL selector; OFMethodSignature *methodSignature; const char *valueType; if ((keyLength = key.UTF8StringLength) < 1) { objc_autoreleasePoolPop(pool); [self setValue: value forUndefinedKey: key]; return; } name = OFAllocMemory(keyLength + 5, 1); @try { memcpy(name, "set", 3); memcpy(name + 3, key.UTF8String, keyLength); memcpy(name + keyLength + 3, ":", 2); name[3] = OFASCIIToUpper(name[3]); selector = sel_registerName(name); } @finally { OFFreeMemory(name); } methodSignature = [self methodSignatureForSelector: selector]; if (methodSignature == nil || methodSignature.numberOfArguments != 3 || *methodSignature.methodReturnType != 'v' || *[methodSignature argumentTypeAtIndex: 0] != '@' || *[methodSignature argumentTypeAtIndex: 1] != ':') { objc_autoreleasePoolPop(pool); [self setValue: value forUndefinedKey: key]; return; } valueType = [methodSignature argumentTypeAtIndex: 2]; if (*valueType != '@' && *valueType != '#' && value == nil) { objc_autoreleasePoolPop(pool); [self setNilValueForKey: key]; return; } switch (*valueType) { case '@': case '#': { void (*setter)(id, SEL, id) = (void (*)(id, SEL, id)) [self methodForSelector: selector]; setter(self, selector, value); } break; #define CASE(encoding, type, method) \ case encoding: \ { \ void (*setter)(id, SEL, type) = \ (void (*)(id, SEL, type)) \ [self methodForSelector: selector]; \ setter(self, selector, [value method]); \ } \ break; CASE('B', bool, boolValue) CASE('c', char, charValue) CASE('s', short, shortValue) CASE('i', int, intValue) CASE('l', long, longValue) CASE('q', long long, longLongValue) CASE('C', unsigned char, unsignedCharValue) CASE('S', unsigned short, unsignedShortValue) CASE('I', unsigned int, unsignedIntValue) CASE('L', unsigned long, unsignedLongValue) CASE('Q', unsigned long long, unsignedLongLongValue) CASE('f', float, floatValue) CASE('d', double, doubleValue) #undef CASE default: objc_autoreleasePoolPop(pool); [self setValue: value forUndefinedKey: key]; return; } objc_autoreleasePoolPop(pool); } - (void)setValue: (id)value forKeyPath: (OFString *)keyPath { void *pool = objc_autoreleasePoolPush(); OFArray *keys = [keyPath componentsSeparatedByString: @"."]; size_t keysCount = keys.count; id object = self; size_t i = 0; for (OFString *key in keys) { if (++i == keysCount) [object setValue: value forKey: key]; else object = [object valueForKey: key]; } objc_autoreleasePoolPop(pool); } - (void)setValue: (id)value forUndefinedKey: (OFString *)key { @throw [OFUndefinedKeyException exceptionWithObject: self key: key value: value]; } - (void)setNilValueForKey: (OFString *)key { @throw [OFInvalidArgumentException exception]; } @end objfw-1.1.6/src/OFObject.h000066400000000000000000001277671465614216400152560ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "objfw-defs.h" #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif #include #include #include #include #include "macros.h" #import "OFOnce.h" /* * Some versions of MinGW require to be included before * . Do this here to make sure this is always done in the correct * order, even if another header includes just . */ #ifdef __MINGW32__ # include <_mingw.h> # ifdef __MINGW64_VERSION_MAJOR # include # include # endif #endif OF_ASSUME_NONNULL_BEGIN /** @file */ /** * @brief A result of a comparison. */ typedef enum { /** The left object is smaller than the right */ OFOrderedAscending = -1, /** Both objects are equal */ OFOrderedSame = 0, /** The left object is bigger than the right */ OFOrderedDescending = 1 } OFComparisonResult; /** * @brief A function to compare two objects. * * @param left The left object * @param right The right object * @param context Context passed along for comparing * @return The order of the objects */ typedef OFComparisonResult (*OFCompareFunction)(id _Nonnull left, id _Nonnull right, void *_Nullable context); #ifdef OF_HAVE_BLOCKS /** * @brief A comparator to compare two objects. * * @param left The left object * @param right The right object * @return The order of the objects */ typedef OFComparisonResult (^OFComparator)(id _Nonnull left, id _Nonnull right); #endif /** * @brief An enum for representing endianness. */ typedef enum { /** Most significant byte first (big endian) */ OFByteOrderBigEndian, /** Least significant byte first (little endian) */ OFByteOrderLittleEndian, /** Native byte order of the system */ #ifdef OF_BIG_ENDIAN OFByteOrderNative = OFByteOrderBigEndian #else OFByteOrderNative = OFByteOrderLittleEndian #endif } OFByteOrder; /** * @struct OFRange OFObject.h ObjFW/OFObject.h * * @brief A range. */ typedef struct OF_BOXABLE OFRange { /** The start of the range */ size_t location; /** The length of the range */ size_t length; } OFRange; /** * @brief Creates a new OFRange. * * @param start The starting index of the range * @param length The length of the range * @return An OFRange with the specified start and length */ static OF_INLINE OFRange OF_CONST_FUNC OFMakeRange(size_t start, size_t length) { OFRange range = { start, length }; return range; } /** * @brief Returns whether the two ranges are equal. * * @param range1 The first range for the comparison * @param range2 The second range for the comparison * @return Whether the two ranges are equal */ static OF_INLINE bool OFEqualRanges(OFRange range1, OFRange range2) { if (range1.location != range2.location) return false; if (range1.length != range2.length) return false; return true; } /** * @brief A time interval in seconds. */ typedef double OFTimeInterval; /** * @struct OFPoint OFObject.h ObjFW/OFObject.h * * @brief A point in 2D space. */ typedef struct OF_BOXABLE OFPoint { /** The x coordinate of the point */ float x; /** The y coordinate of the point */ float y; } OFPoint; /** * @brief Creates a new OFPoint. * * @param x The x coordinate of the point * @param y The x coordinate of the point * @return An OFPoint with the specified coordinates */ static OF_INLINE OFPoint OF_CONST_FUNC OFMakePoint(float x, float y) { OFPoint point = { x, y }; return point; } /** * @brief Returns whether the two points are equal. * * @param point1 The first point for the comparison * @param point2 The second point for the comparison * @return Whether the two points are equal */ static OF_INLINE bool OFEqualPoints(OFPoint point1, OFPoint point2) { if (point1.x != point2.x) return false; if (point1.y != point2.y) return false; return true; } /** * @struct OFSize OFObject.h ObjFW/OFObject.h * * @brief A size. */ typedef struct OF_BOXABLE OFSize { /** The width of the size */ float width; /** The height of the size */ float height; } OFSize; /** * @brief Creates a new OFSize. * * @param width The width of the size * @param height The height of the size * @return An OFSize with the specified width and height */ static OF_INLINE OFSize OF_CONST_FUNC OFMakeSize(float width, float height) { OFSize size = { width, height }; return size; } /** * @brief Returns whether the two sizes are equal. * * @param size1 The first size for the comparison * @param size2 The second size for the comparison * @return Whether the two sizes are equal */ static OF_INLINE bool OFEqualSizes(OFSize size1, OFSize size2) { if (size1.width != size2.width) return false; if (size1.height != size2.height) return false; return true; } /** * @struct OFRect OFObject.h ObjFW/OFObject.h * * @brief A rectangle. */ typedef struct OF_BOXABLE OFRect { /** The point from where the rectangle originates */ OFPoint origin; /** The size of the rectangle */ OFSize size; } OFRect; /** * @brief Creates a new OFRect. * * @param x The x coordinate of the top left corner of the rectangle * @param y The y coordinate of the top left corner of the rectangle * @param width The width of the rectangle * @param height The height of the rectangle * @return An OFRect with the specified origin and size */ static OF_INLINE OFRect OF_CONST_FUNC OFMakeRect(float x, float y, float width, float height) { OFRect rect = { OFMakePoint(x, y), OFMakeSize(width, height) }; return rect; } /** * @brief Returns whether the two rectangles are equal. * * @param rect1 The first rectangle for the comparison * @param rect2 The second rectangle for the comparison * @return Whether the two rectangles are equal */ static OF_INLINE bool OFEqualRects(OFRect rect1, OFRect rect2) { if (!OFEqualPoints(rect1.origin, rect2.origin)) return false; if (!OFEqualSizes(rect1.size, rect2.size)) return false; return true; } /** * @struct OFVector3D OFObject.h ObjFW/OFObject.h * * @brief A vector in 3D space. */ typedef struct OF_BOXABLE OFVector3D { /** The x coordinate of the vector */ float x; /** The y coordinate of the vector */ float y; /** The z coordinate of the vector */ float z; } OFVector3D; /** * @brief Creates a new OFVector3D. * * @param x The x coordinate of the vector * @param y The x coordinate of the vector * @param z The z coordinate of the vector * @return An OFVector3D with the specified coordinates */ static OF_INLINE OFVector3D OF_CONST_FUNC OFMakeVector3D(float x, float y, float z) { OFVector3D vector = { x, y, z }; return vector; } /** * @brief Returns whether the two vectors are equal. * * @param vector1 The first vector for the comparison * @param vector2 The second vectors for the comparison * @return Whether the two vectors are equal */ static OF_INLINE bool OFEqualVectors3D(OFVector3D vector1, OFVector3D vector2) { if (vector1.x != vector2.x) return false; if (vector1.y != vector2.y) return false; if (vector1.z != vector2.z) return false; return true; } /** * @struct OFVector4D OFObject.h ObjFW/OFObject.h * * @brief A vector in 4D space. */ typedef struct OF_BOXABLE OFVector4D { /** The x coordinate of the vector */ float x; /** The y coordinate of the vector */ float y; /** The z coordinate of the vector */ float z; /** The w coordinate of the vector */ float w; } OFVector4D; /** * @brief Creates a new OFVector4D. * * @param x The x coordinate of the vector * @param y The x coordinate of the vector * @param z The z coordinate of the vector * @param w The w coordinate of the vector * @return An OFVector4D with the specified coordinates */ static OF_INLINE OFVector4D OF_CONST_FUNC OFMakeVector4D(float x, float y, float z, float w) { OFVector4D vector = { x, y, z, w }; return vector; } /** * @brief Returns whether the two vectors are equal. * * @param vector1 The first vector for the comparison * @param vector2 The second vectors for the comparison * @return Whether the two vectors are equal */ static OF_INLINE bool OFEqualVectors4D(OFVector4D vector1, OFVector4D vector2) { if (vector1.x != vector2.x) return false; if (vector1.y != vector2.y) return false; if (vector1.z != vector2.z) return false; if (vector1.w != vector2.w) return false; return true; } /** * @brief Adds the specified byte to the hash. * * @param hash A pointer to a hash to add the byte to * @param byte The byte to add to the hash */ static OF_INLINE void OFHashAddByte(unsigned long *_Nonnull hash, unsigned char byte) { uint32_t tmp = (uint32_t)*hash; tmp += byte; tmp += tmp << 10; tmp ^= tmp >> 6; *hash = tmp; } /** * @brief Adds the specified hash to the hash. * * @param hash A pointer to a hash to add the hash to * @param otherHash The hash to add to the hash */ static OF_INLINE void OFHashAddHash(unsigned long *_Nonnull hash, unsigned long otherHash) { OFHashAddByte(hash, (otherHash >> 24) & 0xFF); OFHashAddByte(hash, (otherHash >> 16) & 0xFF); OFHashAddByte(hash, (otherHash >> 8) & 0xFF); OFHashAddByte(hash, otherHash & 0xFF); } /** * @brief Finalizes the specified hash. * * @param hash A pointer to the hash to finalize */ static OF_INLINE void OFHashFinalize(unsigned long *_Nonnull hash) { uint32_t tmp = (uint32_t)*hash; tmp += tmp << 3; tmp ^= tmp >> 11; tmp += tmp << 15; *hash = tmp; } static const size_t OFNotFound = SIZE_MAX; @class OFMethodSignature; @class OFString; @class OFThread; /** * @protocol OFObject OFObject.h ObjFW/OFObject.h * * @brief The protocol which all root classes implement. */ @protocol OFObject /** * @brief Returns the class of the object. * * @return The class of the object */ - (Class)class; /** * @brief Returns the superclass of the object. * * @return The superclass of the object */ - (nullable Class)superclass; /** * @brief Returns a hash for the object. * * Classes containing data (like strings, arrays, lists etc.) should reimplement * this! * * @warning If you reimplement this, you also need to reimplement @ref isEqual: * to behave in a way compatible to your reimplementation of this * method! * * @return A hash for the object */ - (unsigned long)hash; /** * @brief Returns the retain count. * * @return The retain count */ - (unsigned int)retainCount; /** * @brief Returns whether the object is a proxy object. * * @return Whether the object is a proxy object */ - (bool)isProxy; /** * @brief Returns a boolean whether the object is of the specified kind. * * @param class_ The class for which the receiver is checked * @return A boolean whether the object is of the specified kind */ - (bool)isKindOfClass: (Class)class_; /** * @brief Returns a boolean whether the object is a member of the specified * class. * * @param class_ The class for which the receiver is checked * @return A boolean whether the object is a member of the specified class */ - (bool)isMemberOfClass: (Class)class_; /** * @brief Returns a boolean whether the object responds to the specified * selector. * * @param selector The selector which should be checked for respondence * @return A boolean whether the objects responds to the specified selector */ - (bool)respondsToSelector: (SEL)selector; /** * @brief Checks whether the object conforms to the specified protocol. * * @param protocol The protocol which should be checked for conformance * @return A boolean whether the object conforms to the specified protocol */ - (bool)conformsToProtocol: (Protocol *)protocol; /** * @brief Returns the implementation for the specified selector. * * @param selector The selector for which the method should be returned * @return The implementation for the specified selector */ - (nullable IMP)methodForSelector: (SEL)selector; /** * @brief Performs the specified selector. * * @param selector The selector to perform * @return The object returned by the method specified by the selector */ - (nullable id)performSelector: (SEL)selector; /** * @brief Performs the specified selector with the specified object. * * @param selector The selector to perform * @param object The object that is passed to the method specified by the * selector * @return The object returned by the method specified by the selector */ - (nullable id)performSelector: (SEL)selector withObject: (nullable id)object; /** * @brief Performs the specified selector with the specified objects. * * @param selector The selector to perform * @param object1 The first object that is passed to the method specified by the * selector * @param object2 The second object that is passed to the method specified by * the selector * @return The object returned by the method specified by the selector */ - (nullable id)performSelector: (SEL)selector withObject: (nullable id)object1 withObject: (nullable id)object2; /** * @brief Performs the specified selector with the specified objects. * * @param selector The selector to perform * @param object1 The first object that is passed to the method specified by the * selector * @param object2 The second object that is passed to the method specified by * the selector * @param object3 The third object that is passed to the method specified by the * selector * @return The object returned by the method specified by the selector */ - (nullable id)performSelector: (SEL)selector withObject: (nullable id)object1 withObject: (nullable id)object2 withObject: (nullable id)object3; /** * @brief Performs the specified selector with the specified objects. * * @param selector The selector to perform * @param object1 The first object that is passed to the method specified by the * selector * @param object2 The second object that is passed to the method specified by * the selector * @param object3 The third object that is passed to the method specified by the * selector * @param object4 The fourth object that is passed to the method specified by * the selector * @return The object returned by the method specified by the selector */ - (nullable id)performSelector: (SEL)selector withObject: (nullable id)object1 withObject: (nullable id)object2 withObject: (nullable id)object3 withObject: (nullable id)object4; /** * @brief Checks two objects for equality. * * Classes containing data (like strings, arrays, lists etc.) should reimplement * this! * * @warning If you reimplement this, you also need to reimplement @ref hash to * return the same hash for objects which are equal! * * @param object The object which should be tested for equality * @return A boolean whether the object is equal to the specified object */ - (bool)isEqual: (nullable id)object; /** * @brief Increases the retain count. * * Each time an object is released, the retain count gets decreased and the * object deallocated if it reaches 0. */ - (instancetype)retain; /** * @brief Decreases the retain count. * * Each time an object is released, the retain count gets decreased and the * object deallocated if it reaches 0. */ - (void)release; /** * @brief Adds the object to the topmost autorelease pool of the thread's * autorelease pool stack. * * @return The object */ - (instancetype)autorelease; /** * @brief Returns the receiver. * * @return The receiver */ - (instancetype)self; /** * @brief Returns whether the object allows a weak reference. * * @return Whether the object allows a weak references */ - (bool)allowsWeakReference; /** * @brief Retain a weak reference to this object. * * @return Whether a weak reference to this object has been retained */ - (bool)retainWeakReference; @end /** * @class OFObject OFObject.h ObjFW/OFObject.h * * @brief The root class for all other classes inside ObjFW. */ OF_ROOT_CLASS @interface OFObject { @private #ifndef __clang_analyzer__ Class _isa; #else Class _isa __attribute__((__unused__)); #endif } #ifdef OF_HAVE_CLASS_PROPERTIES # ifndef __cplusplus @property (class, readonly, nonatomic) Class class; # else @property (class, readonly, nonatomic, getter=class) Class class_; # endif @property (class, readonly, nonatomic) OFString *className; @property (class, readonly, nullable, nonatomic) Class superclass; @property (class, readonly, nonatomic) OFString *description; #endif #ifndef __cplusplus @property (readonly, nonatomic) Class class; #else @property (readonly, nonatomic, getter=class) Class class_; #endif @property OF_NULLABLE_PROPERTY (readonly, nonatomic) Class superclass; @property (readonly, nonatomic) unsigned long hash; @property (readonly, nonatomic) unsigned int retainCount; @property (readonly, nonatomic) bool isProxy; @property (readonly, nonatomic) bool allowsWeakReference; /** * @brief The name of the object's class. */ @property (readonly, nonatomic) OFString *className; /** * @brief A description for the object. * * This is used when the object is used in a format string and for debugging * purposes. */ @property (readonly, nonatomic) OFString *description; /** * @brief A method which is called once when the class is loaded into the * runtime. * * Derived classes can override this to execute their own code when the class * is loaded. */ + (void)load; /** * @brief A method which is called when the class is unloaded from the runtime. * * Derived classes can override this to execute their own code when the class * is unloaded. * * @warning This is not supported by the Apple runtime and currently only * called by the ObjFW runtime when @ref objc_deinit has been called! * In the future, this might also be called by the ObjFW runtime when * the class is part of a plugin that is being unloaded. */ + (void)unload; /** * @brief A method which is called the moment before the first call to the class * is being made. * * Derived classes can override this to execute their own code on * initialization. They should make sure to not execute any code if self is not * the class itself, as it might happen that the method was called for a * subclass which did not override this method. */ + (void)initialize; /** * @brief Allocates memory for an instance of the class and sets up the memory * pool for the object. * * This method will never return `nil`. * * @return The allocated object * @throw OFAllocFailedException There was not enough memory to allocate the * object * @throw OFInitializationFailedException The instance could not be constructed */ + (instancetype)alloc; /** * @brief Returns the class. * * @return The class */ + (Class)class; /** * @brief Returns the name of the class as a string. * * @return The name of the class as a string */ + (OFString *)className; /** * @brief Returns a boolean whether the class is a subclass of the specified * class. * * @param class_ The class which is checked for being a superclass * @return A boolean whether the class is a subclass of the specified class */ + (bool)isSubclassOfClass: (Class)class_; /** * @brief Returns the superclass of the class. * * @return The superclass of the class */ + (nullable Class)superclass; /** * @brief Checks whether instances of the class respond to a given selector. * * @param selector The selector which should be checked for respondence * @return A boolean whether instances of the class respond to the specified * selector */ + (bool)instancesRespondToSelector: (SEL)selector; /** * @brief Checks whether the class conforms to a given protocol. * * @param protocol The protocol which should be checked for conformance * @return A boolean whether the class conforms to the specified protocol */ + (bool)conformsToProtocol: (Protocol *)protocol; /** * @brief Returns the implementation of the instance method for the specified * selector. * * @param selector The selector for which the method should be returned * @return The implementation of the instance method for the specified selector * or `nil` if it isn't implemented */ + (nullable IMP)instanceMethodForSelector: (SEL)selector; /** * @brief Returns the method signature of the instance method for the specified * selector. * * @param selector The selector for which the method signature should be * returned * @return The method signature of the instance method for the specified * selector */ + (nullable OFMethodSignature *) instanceMethodSignatureForSelector: (SEL)selector; /** * @brief Returns a description for the class, which is usually the class name. * * This is mostly for debugging purposes. * * @return A description for the class, which is usually the class name */ + (OFString *)description; /** * @brief Replaces a class method with a class method from another class. * * @param selector The selector of the class method to replace * @param class_ The class from which the new class method should be taken * @return The old implementation */ + (nullable IMP)replaceClassMethod: (SEL)selector withMethodFromClass: (Class)class_; /** * @brief Replaces an instance method with an instance method from another * class. * * @param selector The selector of the instance method to replace * @param class_ The class from which the new instance method should be taken * @return The old implementation */ + (nullable IMP)replaceInstanceMethod: (SEL)selector withMethodFromClass: (Class)class_; /** * @brief Adds all methods from the specified class to the class that is the * receiver. * * Methods implemented by the receiving class itself will not be overridden, * however methods implemented by its superclass will. Therefore it behaves * similar as if the specified class is the superclass of the receiver. * * All methods from the superclasses of the specified class will also be added. * * If the specified class is a superclass of the receiving class, nothing is * done. * * The methods which will be added from the specified class are not allowed to * use super or access instance variables, instead they have to use accessors. * * @param class_ The class from which the instance methods should be inherited */ + (void)inheritMethodsFromClass: (Class)class_; /** * @brief Try to resolve the specified class method. * * This method is called if a class method was not found, so that an * implementation can be provided at runtime. * * @return Whether the method has been added to the class */ + (bool)resolveClassMethod: (SEL)selector; /** * @brief Try to resolve the specified instance method. * * This method is called if an instance method was not found, so that an * implementation can be provided at runtime. * * @return Whether the method has been added to the class */ + (bool)resolveInstanceMethod: (SEL)selector; /** * @brief Returns the class. * * This method exists so that classes can be used in collections requiring * conformance to the OFCopying protocol. * * @return The class of the object */ + (id)copy; /** * @brief Initializes an already allocated object. * * Derived classes may override this, but need to use the following pattern: * @code * self = [super init]; * * @try { * // Custom initialization code goes here. * } @catch (id e) { * [self release]; * @throw e; * } * * return self; * @endcode * * With ARC enabled, the following pattern needs to be used instead: * @code * self = [super init]; * * // Custom initialization code goes here. * * return self; * @endcode * * @ref init may never return `nil`, instead an exception (for example * @ref OFInitializationFailedException) should be thrown. * * @return An initialized object */ - (instancetype)init; /** * @brief Returns the method signature for the specified selector. * * @param selector The selector for which the method signature should be * returned * @return The method signature for the specified selector */ - (nullable OFMethodSignature *)methodSignatureForSelector: (SEL)selector; /** * @brief Deallocates the object. * * It is automatically called when the retain count reaches zero. * * This also frees all memory in its memory pool. */ - (void)dealloc; /** * @brief Performs the specified selector after the specified delay. * * @param selector The selector to perform * @param delay The delay after which the selector will be performed */ - (void)performSelector: (SEL)selector afterDelay: (OFTimeInterval)delay; /** * @brief Performs the specified selector with the specified object after the * specified delay. * * @param selector The selector to perform * @param object The object that is passed to the method specified by the * selector * @param delay The delay after which the selector will be performed */ - (void)performSelector: (SEL)selector withObject: (nullable id)object afterDelay: (OFTimeInterval)delay; /** * @brief Performs the specified selector with the specified objects after the * specified delay. * * @param selector The selector to perform * @param object1 The first object that is passed to the method specified by the * selector * @param object2 The second object that is passed to the method specified by * the selector * @param delay The delay after which the selector will be performed */ - (void)performSelector: (SEL)selector withObject: (nullable id)object1 withObject: (nullable id)object2 afterDelay: (OFTimeInterval)delay; /** * @brief Performs the specified selector with the specified objects after the * specified delay. * * @param selector The selector to perform * @param object1 The first object that is passed to the method specified by the * selector * @param object2 The second object that is passed to the method specified by * the selector * @param object3 The third object that is passed to the method specified by the * selector * @param delay The delay after which the selector will be performed */ - (void)performSelector: (SEL)selector withObject: (nullable id)object1 withObject: (nullable id)object2 withObject: (nullable id)object3 afterDelay: (OFTimeInterval)delay; /** * @brief Performs the specified selector with the specified objects after the * specified delay. * * @param selector The selector to perform * @param object1 The first object that is passed to the method specified by the * selector * @param object2 The second object that is passed to the method specified by * the selector * @param object3 The third object that is passed to the method specified by the * selector * @param object4 The fourth object that is passed to the method specified by * the selector * @param delay The delay after which the selector will be performed */ - (void)performSelector: (SEL)selector withObject: (nullable id)object1 withObject: (nullable id)object2 withObject: (nullable id)object3 withObject: (nullable id)object4 afterDelay: (OFTimeInterval)delay; #ifdef OF_HAVE_THREADS /** * @brief Performs the specified selector on the specified thread. * * @param selector The selector to perform * @param thread The thread on which to perform the selector * @param waitUntilDone Whether to wait until the perform finished */ - (void)performSelector: (SEL)selector onThread: (OFThread *)thread waitUntilDone: (bool)waitUntilDone; /** * @brief Performs the specified selector on the specified thread with the * specified object. * * @param selector The selector to perform * @param thread The thread on which to perform the selector * @param object The object that is passed to the method specified by the * selector * @param waitUntilDone Whether to wait until the perform finished */ - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (nullable id)object waitUntilDone: (bool)waitUntilDone; /** * @brief Performs the specified selector on the specified thread with the * specified objects. * * @param selector The selector to perform * @param thread The thread on which to perform the selector * @param object1 The first object that is passed to the method specified by the * selector * @param object2 The second object that is passed to the method specified by * the selector * @param waitUntilDone Whether to wait until the perform finished */ - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (nullable id)object1 withObject: (nullable id)object2 waitUntilDone: (bool)waitUntilDone; /** * @brief Performs the specified selector on the specified thread with the * specified objects. * * @param selector The selector to perform * @param thread The thread on which to perform the selector * @param object1 The first object that is passed to the method specified by the * selector * @param object2 The second object that is passed to the method specified by * the selector * @param object3 The third object that is passed to the method specified by the * selector * @param waitUntilDone Whether to wait until the perform finished */ - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (nullable id)object1 withObject: (nullable id)object2 withObject: (nullable id)object3 waitUntilDone: (bool)waitUntilDone; /** * @brief Performs the specified selector on the specified thread with the * specified objects. * * @param selector The selector to perform * @param thread The thread on which to perform the selector * @param object1 The first object that is passed to the method specified by the * selector * @param object2 The second object that is passed to the method specified by * the selector * @param object3 The third object that is passed to the method specified by the * selector * @param object4 The fourth object that is passed to the method specified by * the selector * @param waitUntilDone Whether to wait until the perform finished */ - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (nullable id)object1 withObject: (nullable id)object2 withObject: (nullable id)object3 withObject: (nullable id)object4 waitUntilDone: (bool)waitUntilDone; /** * @brief Performs the specified selector on the main thread. * * @param selector The selector to perform * @param waitUntilDone Whether to wait until the perform finished */ - (void)performSelectorOnMainThread: (SEL)selector waitUntilDone: (bool)waitUntilDone; /** * @brief Performs the specified selector on the main thread with the specified * object. * * @param selector The selector to perform * @param object The object that is passed to the method specified by the * selector * @param waitUntilDone Whether to wait until the perform finished */ - (void)performSelectorOnMainThread: (SEL)selector withObject: (nullable id)object waitUntilDone: (bool)waitUntilDone; /** * @brief Performs the specified selector on the main thread with the specified * objects. * * @param selector The selector to perform * @param object1 The first object that is passed to the method specified by the * selector * @param object2 The second object that is passed to the method specified by * the selector * @param waitUntilDone Whether to wait until the perform finished */ - (void)performSelectorOnMainThread: (SEL)selector withObject: (nullable id)object1 withObject: (nullable id)object2 waitUntilDone: (bool)waitUntilDone; /** * @brief Performs the specified selector on the main thread with the specified * objects. * * @param selector The selector to perform * @param object1 The first object that is passed to the method specified by the * selector * @param object2 The second object that is passed to the method specified by * the selector * @param object3 The third object that is passed to the method specified by the * selector * @param waitUntilDone Whether to wait until the perform finished */ - (void)performSelectorOnMainThread: (SEL)selector withObject: (nullable id)object1 withObject: (nullable id)object2 withObject: (nullable id)object3 waitUntilDone: (bool)waitUntilDone; /** * @brief Performs the specified selector on the main thread with the specified * objects. * * @param selector The selector to perform * @param object1 The first object that is passed to the method specified by the * selector * @param object2 The second object that is passed to the method specified by * the selector * @param object3 The third object that is passed to the method specified by the * selector * @param object4 The fourth object that is passed to the method specified by * the selector * @param waitUntilDone Whether to wait until the perform finished */ - (void)performSelectorOnMainThread: (SEL)selector withObject: (nullable id)object1 withObject: (nullable id)object2 withObject: (nullable id)object3 withObject: (nullable id)object4 waitUntilDone: (bool)waitUntilDone; /** * @brief Performs the specified selector on the specified thread after the * specified delay. * * @param selector The selector to perform * @param thread The thread on which to perform the selector * @param delay The delay after which the selector will be performed */ - (void)performSelector: (SEL)selector onThread: (OFThread *)thread afterDelay: (OFTimeInterval)delay; /** * @brief Performs the specified selector on the specified thread with the * specified object after the specified delay. * * @param selector The selector to perform * @param thread The thread on which to perform the selector * @param object The object that is passed to the method specified by the * selector * @param delay The delay after which the selector will be performed */ - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (nullable id)object afterDelay: (OFTimeInterval)delay; /** * @brief Performs the specified selector on the specified thread with the * specified objects after the specified delay. * * @param selector The selector to perform * @param thread The thread on which to perform the selector * @param object1 The first object that is passed to the method specified by the * selector * @param object2 The second object that is passed to the method specified by * the selector * @param delay The delay after which the selector will be performed */ - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (nullable id)object1 withObject: (nullable id)object2 afterDelay: (OFTimeInterval)delay; /** * @brief Performs the specified selector on the specified thread with the * specified objects after the specified delay. * * @param selector The selector to perform * @param thread The thread on which to perform the selector * @param object1 The first object that is passed to the method specified by the * selector * @param object2 The second object that is passed to the method specified by * the selector * @param object3 The third object that is passed to the method specified by the * selector * @param delay The delay after which the selector will be performed */ - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (nullable id)object1 withObject: (nullable id)object2 withObject: (nullable id)object3 afterDelay: (OFTimeInterval)delay; /** * @brief Performs the specified selector on the specified thread with the * specified objects after the specified delay. * * @param selector The selector to perform * @param thread The thread on which to perform the selector * @param object1 The first object that is passed to the method specified by the * selector * @param object2 The second object that is passed to the method specified by * the selector * @param object3 The third object that is passed to the method specified by the * selector * @param object4 The fourth object that is passed to the method specified by * the selector * @param delay The delay after which the selector will be performed */ - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (nullable id)object1 withObject: (nullable id)object2 withObject: (nullable id)object3 withObject: (nullable id)object4 afterDelay: (OFTimeInterval)delay; #endif /** * @brief This method is called when @ref resolveClassMethod: or * @ref resolveInstanceMethod: returned false. It should return a target * to which the message should be forwarded. * * @note When the message should not be forwarded, you should not return `nil`, * but instead return the result of `[super * forwardingTargetForSelector: selector]`. * * @return The target to forward the message to */ - (nullable id)forwardingTargetForSelector: (SEL)selector; /** * @brief Handles messages which are not understood by the receiver. * * @warning If you override this method, you must make sure that it never * returns! * * @param selector The selector not understood by the receiver * @throw OFNotImplementedException */ - (void)doesNotRecognizeSelector: (SEL)selector OF_NO_RETURN; @end /** * @protocol OFCopying OFObject.h ObjFW/OFObject.h * * @brief A protocol for the creation of copies. */ @protocol OFCopying /** * @brief Copies the object. * * For classes which can be immutable or mutable, this returns an immutable * copy. If only a mutable version of the class exists, it creates a mutable * copy. * * @return A copy of the object */ - (id)copy; @end /** * @protocol OFMutableCopying OFObject.h ObjFW/OFObject.h * * @brief A protocol for the creation of mutable copies. * * This protocol is implemented by objects that can be mutable and immutable * and allows returning a mutable copy. */ @protocol OFMutableCopying /** * @brief Creates a mutable copy of the object. * * @return A mutable copy of the object */ - (id)mutableCopy; @end /** * @protocol OFComparing OFObject.h ObjFW/OFObject.h * * @brief A protocol for comparing objects. * * This protocol is implemented by objects that can be compared. Its only * method, @ref compare:, should be overridden with a stronger type. */ @protocol OFComparing /** * @brief Compares the object to another object. * * @param object An object to compare the object to * @return The result of the comparison */ - (OFComparisonResult)compare: (id )object; @end #ifdef __cplusplus extern "C" { #endif /** * @brief Allocates memory for the specified number of items of the specified * size. * * To free the allocated memory, use @ref OFFreeMemory. * * @param count The number of items to allocate * @param size The size of each item to allocate * @return A pointer to the allocated memory. May return NULL if the specified * size or count is 0. * @throw OFOutOfMemoryException The allocation failed due to not enough memory * @throw OFOutOfRangeException The requested `count * size` exceeds the * address space */ extern void *_Nullable OFAllocMemory(size_t count, size_t size) OF_WARN_UNUSED_RESULT; /** * @brief Allocates memory for the specified number of items of the specified * size and initializes it with zeros. * * To free the allocated memory, use @ref OFFreeMemory. * * @param size The size of each item to allocate * @param count The number of items to allocate * @return A pointer to the allocated memory. May return NULL if the specified * size or count is 0. * @throw OFOutOfMemoryException The allocation failed due to not enough memory * @throw OFOutOfRangeException The requested `count * size` exceeds the * address space */ extern void *_Nullable OFAllocZeroedMemory(size_t count, size_t size) OF_WARN_UNUSED_RESULT; /** * @brief Resizes memory to the specified number of items of the specified size. * * To free the allocated memory, use @ref OFFreeMemory. * * If the pointer is NULL, this is equivalent to allocating memory. * If the size or number of items is 0, this is equivalent to freeing memory. * * @param pointer A pointer to the already allocated memory * @param size The size of each item to resize to * @param count The number of items to resize to * @return A pointer to the resized memory chunk * @throw OFOutOfMemoryException The reallocation failed due to not enough * memory * @throw OFOutOfRangeException The requested `count * size` exceeds the * address space */ extern void *_Nullable OFResizeMemory(void *_Nullable pointer, size_t count, size_t size) OF_WARN_UNUSED_RESULT; /** * @brief Frees memory allocated by @ref OFAllocMemory, @ref OFAllocZeroedMemory * or @ref OFResizeMemory. * * @param pointer A pointer to the memory to free or nil (passing nil does * nothing) */ extern void OFFreeMemory(void *_Nullable pointer); #ifdef OF_APPLE_RUNTIME extern void *_Null_unspecified objc_autoreleasePoolPush(void); extern void objc_autoreleasePoolPop(void *_Null_unspecified pool); # ifndef __OBJC2__ extern id _Nullable objc_constructInstance(Class _Nullable class_, void *_Nullable bytes); extern void *_Nullable objc_destructInstance(id _Nullable object); typedef enum objc_associationPolicy { OBJC_ASSOCIATION_ASSIGN = 0, OBJC_ASSOCIATION_RETAIN_NONATOMIC = 1, OBJC_ASSOCIATION_RETAIN = OBJC_ASSOCIATION_RETAIN_NONATOMIC | 0x300, OBJC_ASSOCIATION_COPY_NONATOMIC = 3, OBJC_ASSOCIATION_COPY = OBJC_ASSOCIATION_COPY_NONATOMIC | 0x300 } objc_associationPolicy; extern void objc_setAssociatedObject(id _Nonnull object, const void *_Nonnull key, id _Nullable value, objc_associationPolicy policy); extern id _Nullable objc_getAssociatedObject(id _Nonnull object, const void *_Nonnull key); extern void objc_removeAssociatedObjects(id _Nonnull object); # endif #endif /** * @brief Allocates a new object. * * This is useful to override @ref OFObject#alloc in a subclass that can then * allocate extra memory in the same memory allocation. * * @param class_ The class of which to allocate an object * @param extraSize Extra space after the ivars to allocate * @param extraAlignment Alignment of the extra space after the ivars * @param extra A pointer to set to a pointer to the extra space * @return The allocated object */ extern id OFAllocObject(Class class_, size_t extraSize, size_t extraAlignment, void *_Nullable *_Nullable extra); /** * @brief This function is called when a method is not found. * * It can also be called intentionally to indicate that a method is not * implemetned, for example in an abstract method. However, instead of calling * OFMethodNotFound directly, it is preferred to do the following: * * - (void)abstractMethod * { * OF_UNRECOGNIZED_SELECTOR * } * * However, do not use this for init methods. Instead, use the following: * * - (instancetype)init * { * OF_INVALID_INIT_METHOD * } * * @param self The object which does not have the method * @param _cmd The selector of the method that does not exist */ extern void OF_NO_RETURN_FUNC OFMethodNotFound(id self, SEL _cmd); /** * @brief Initializes the specified hash. * * @param hash A pointer to the hash to initialize */ extern void OFHashInit(unsigned long *_Nonnull hash); /** * @brief Returns 16 bit or non-cryptographical randomness. * * @return 16 bit or non-cryptographical randomness */ extern uint16_t OFRandom16(void); /** * @brief Returns 32 bit or non-cryptographical randomness. * * @return 32 bit or non-cryptographical randomness */ extern uint32_t OFRandom32(void); /** * @brief Returns 64 bit or non-cryptographical randomness. * * @return 64 bit or non-cryptographical randomness */ extern uint64_t OFRandom64(void); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END #import "OFBlock.h" #import "OFObject+KeyValueCoding.h" objfw-1.1.6/src/OFObject.m000066400000000000000000000754541465614216400152560ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #include #include "unistd_wrapper.h" #ifdef OF_APPLE_RUNTIME # include #endif #ifdef HAVE_GETRANDOM # include #endif #import "OFObject.h" #import "OFArray.h" #ifdef OF_HAVE_ATOMIC_OPS # import "OFAtomic.h" #endif #import "OFLocale.h" #import "OFMethodSignature.h" #import "OFRunLoop.h" #if !defined(OF_HAVE_ATOMIC_OPS) && defined(OF_HAVE_THREADS) # import "OFPlainMutex.h" /* For OFSpinlock */ #endif #import "OFStdIOStream.h" #import "OFString.h" #import "OFThread.h" #import "OFTimer.h" #import "OFValue.h" #import "OFAllocFailedException.h" #import "OFEnumerationMutationException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFNotImplementedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #if defined(OF_APPLE_RUNTIME) && __OBJC2__ # import #elif defined(OF_OBJFW_RUNTIME) # import "ObjFWRT.h" #endif #ifdef OF_WINDOWS # include #endif #ifdef OF_AMIGAOS # define Class IntuitionClass # include # undef Class #endif #ifdef OF_APPLE_RUNTIME extern id _Nullable _objc_rootAutorelease(id _Nullable object); #endif #if defined(OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR) extern id OFForward(id, SEL, ...); extern struct Stret OFForward_stret(id, SEL, ...); #else # define OFForward OFMethodNotFound # define OFForward_stret OFMethodNotFound_stret #endif #ifdef OF_WINDOWS static BOOLEAN NTAPI (*RtlGenRandomFuncPtr)(PVOID, ULONG); #endif struct PreIvars { #ifdef OF_MSDOS ptrdiff_t offset; #endif int retainCount; #if !defined(OF_HAVE_ATOMIC_OPS) && !defined(OF_AMIGAOS) OFSpinlock retainCountSpinlock; #endif }; #define PRE_IVARS_ALIGN \ OFRoundUpToPowerOf2(sizeof(struct PreIvars), OF_BIGGEST_ALIGNMENT) #define PRE_IVARS ((struct PreIvars *)(void *)((char *)self - PRE_IVARS_ALIGN)) static struct { Class isa; } allocFailedException; unsigned long OFHashSeed; void * OFAllocMemory(size_t count, size_t size) { void *pointer; if OF_UNLIKELY (count == 0 || size == 0) return NULL; if OF_UNLIKELY (count > SIZE_MAX / size) @throw [OFOutOfRangeException exception]; if OF_UNLIKELY ((pointer = malloc(count * size)) == NULL) @throw [OFOutOfMemoryException exceptionWithRequestedSize: size]; return pointer; } void * OFAllocZeroedMemory(size_t count, size_t size) { void *pointer; if OF_UNLIKELY (count == 0 || size == 0) return NULL; /* Not all calloc implementations check for overflow. */ if OF_UNLIKELY (count > SIZE_MAX / size) @throw [OFOutOfRangeException exception]; if OF_UNLIKELY ((pointer = calloc(count, size)) == NULL) @throw [OFOutOfMemoryException exceptionWithRequestedSize: size]; return pointer; } void * OFResizeMemory(void *pointer, size_t count, size_t size) { if OF_UNLIKELY (count == 0 || size == 0) { free(pointer); return NULL; } if OF_UNLIKELY (count > SIZE_MAX / size) @throw [OFOutOfRangeException exception]; if OF_UNLIKELY ((pointer = realloc(pointer, count * size)) == NULL) @throw [OFOutOfMemoryException exceptionWithRequestedSize: size]; return pointer; } void OFFreeMemory(void *pointer) { free(pointer); } #ifdef OF_MSDOS /* Unfortunately, DJGPP's memalign() is broken. */ static void * alignedAlloc(size_t size, size_t alignment, ptrdiff_t *offset) { char *ptr, *aligned; if ((ptr = malloc(size + alignment)) == NULL) return NULL; aligned = (char *)OFRoundUpToPowerOf2(alignment, (uintptr_t)ptr); *offset = aligned - ptr; return aligned; } static void alignedFree(void *ptr, ptrdiff_t offset) { if (ptr == NULL) return; free((void *)((uintptr_t)ptr - offset)); } #endif #if (!defined(HAVE_ARC4RANDOM) && !defined(HAVE_GETRANDOM)) || \ defined(OF_WINDOWS) static OFOnceControl randomOnceControl = OFOnceControlInitValue; static void initRandom(void) { struct timeval tv; # ifdef OF_WINDOWS HANDLE handle; if ((handle = GetModuleHandleA("advapi32.dll")) != NULL && (RtlGenRandomFuncPtr = (BOOLEAN NTAPI (*)(PVOID, ULONG)) GetProcAddress(handle, "SystemFunction036")) != NULL) return; # endif # ifdef HAVE_RANDOM gettimeofday(&tv, NULL); srandom((unsigned)(tv.tv_sec ^ tv.tv_usec)); # else gettimeofday(&tv, NULL); srand((unsigned)(tv.tv_sec ^ tv.tv_usec)); # endif } #endif uint16_t OFRandom16(void) { #if defined(HAVE_ARC4RANDOM) return arc4random(); #elif defined(HAVE_GETRANDOM) uint16_t buffer; OFEnsure(getrandom(&buffer, sizeof(buffer), 0) == sizeof(buffer)); return buffer; #else OFOnce(&randomOnceControl, initRandom); # ifdef OF_WINDOWS if (RtlGenRandomFuncPtr != NULL) { uint16_t buffer; OFEnsure(RtlGenRandomFuncPtr(&buffer, sizeof(buffer))); return buffer; } # endif # ifdef HAVE_RANDOM return random() & 0xFFFF; # else return rand() & 0xFFFF; # endif #endif } uint32_t OFRandom32(void) { #if defined(HAVE_ARC4RANDOM) return arc4random(); #elif defined(HAVE_GETRANDOM) uint32_t buffer; OFEnsure(getrandom(&buffer, sizeof(buffer), 0) == sizeof(buffer)); return buffer; #else # ifdef OF_WINDOWS OFOnce(&randomOnceControl, initRandom); if (RtlGenRandomFuncPtr != NULL) { uint32_t buffer; OFEnsure(RtlGenRandomFuncPtr(&buffer, sizeof(buffer))); return buffer; } # endif return ((uint32_t)OFRandom16() << 16) | OFRandom16(); #endif } uint64_t OFRandom64(void) { #if defined(HAVE_ARC4RANDOM_BUF) uint64_t buffer; arc4random_buf(&buffer, sizeof(buffer)); return buffer; #elif defined(HAVE_GETRANDOM) uint64_t buffer; OFEnsure(getrandom(&buffer, sizeof(buffer), 0) == sizeof(buffer)); return buffer; #else # ifdef OF_WINDOWS OFOnce(&randomOnceControl, initRandom); if (RtlGenRandomFuncPtr != NULL) { uint64_t buffer; OFEnsure(RtlGenRandomFuncPtr(&buffer, sizeof(buffer))); return buffer; } # endif return ((uint64_t)OFRandom32() << 32) | OFRandom32(); #endif } void OFHashInit(unsigned long *hash) { *hash = OFHashSeed; } static const char * typeEncodingForSelector(Class class, SEL selector) { Method method; if ((method = class_getInstanceMethod(class, selector)) == NULL) return NULL; return method_getTypeEncoding(method); } #if !defined(OF_APPLE_RUNTIME) || defined(__OBJC2__) static void uncaughtExceptionHandler(id exception) { OFArray OF_GENERIC(OFValue *) *stackTraceAddresses = nil; OFArray OF_GENERIC(OFString *) *stackTraceSymbols = nil; OFStringEncoding encoding = [OFLocale encoding]; OFLog(@"Runtime error: Unhandled exception:"); OFLog(@"%@", exception); if ([exception respondsToSelector: @selector(stackTraceAddresses)]) stackTraceAddresses = [exception stackTraceAddresses]; if (stackTraceAddresses != nil) { size_t count = stackTraceAddresses.count; if ([exception respondsToSelector: @selector(stackTraceSymbols)]) stackTraceSymbols = [exception stackTraceSymbols]; if (stackTraceSymbols.count != count) stackTraceSymbols = nil; OFLog(@""); OFLog(@"Stack trace:"); if (stackTraceSymbols != nil) { for (size_t i = 0; i < count; i++) { void *address = [[stackTraceAddresses objectAtIndex: i] pointerValue]; const char *symbol = [[stackTraceSymbols objectAtIndex: i] cStringWithEncoding: encoding]; OFLog(@" %p %s", address, symbol); } } else { for (size_t i = 0; i < count; i++) { void *address = [[stackTraceAddresses objectAtIndex: i] pointerValue]; OFLog(@" %p", address); } } } abort(); } #endif static void enumerationMutationHandler(id object) { @throw [OFEnumerationMutationException exceptionWithObject: object]; } void OF_NO_RETURN_FUNC OFMethodNotFound(id object, SEL selector) { [object doesNotRecognizeSelector: selector]; /* * Just in case doesNotRecognizeSelector: returned, even though it must * never return. */ abort(); OF_UNREACHABLE } void OF_NO_RETURN_FUNC OFMethodNotFound_stret(void *stret, id object, SEL selector) { OFMethodNotFound(object, selector); } id OFAllocObject(Class class, size_t extraSize, size_t extraAlignment, void **extra) { OFObject *instance; size_t instanceSize; #ifdef OF_MSDOS ptrdiff_t offset; #endif instanceSize = class_getInstanceSize(class); if OF_UNLIKELY (extraAlignment > 1) extraAlignment = OFRoundUpToPowerOf2(extraAlignment, PRE_IVARS_ALIGN + instanceSize) - PRE_IVARS_ALIGN - instanceSize; #if defined(OF_WINDOWS) instance = __mingw_aligned_malloc(PRE_IVARS_ALIGN + instanceSize + extraAlignment + extraSize, OF_BIGGEST_ALIGNMENT); #elif defined(OF_MSDOS) instance = alignedAlloc(PRE_IVARS_ALIGN + instanceSize + extraAlignment + extraSize, OF_BIGGEST_ALIGNMENT, &offset); #elif defined(OF_SOLARIS) if (posix_memalign((void **)&instance, OF_BIGGEST_ALIGNMENT, PRE_IVARS_ALIGN + instanceSize + extraAlignment + extraSize) != 0) instance = NULL; #else instance = malloc(PRE_IVARS_ALIGN + instanceSize + extraAlignment + extraSize); #endif if OF_UNLIKELY (instance == nil) { object_setClass((id)&allocFailedException, [OFAllocFailedException class]); @throw (id)&allocFailedException; } #ifdef OF_MSDOS ((struct PreIvars *)instance)->offset = offset; #endif ((struct PreIvars *)instance)->retainCount = 1; #if !defined(OF_HAVE_ATOMIC_OPS) && !defined(OF_AMIGAOS) if OF_UNLIKELY (OFSpinlockNew( &((struct PreIvars *)instance)->retainCountSpinlock) != 0) { # if defined(OF_WINDOWS) __mingw_aligned_free(instance); # elif defined(OF_MSDOS) alignedFree(instance, offset); # else free(instance); # endif @throw [OFInitializationFailedException exceptionWithClass: class]; } #endif instance = (OFObject *)(void *)((char *)instance + PRE_IVARS_ALIGN); memset(instance, 0, instanceSize + extraAlignment + extraSize); if (!objc_constructInstance(class, instance)) { #if !defined(OF_HAVE_ATOMIC_OPS) && !defined(OF_AMIGAOS) OFSpinlockFree(&((struct PreIvars *)(void *) ((char *)instance - PRE_IVARS_ALIGN))->retainCountSpinlock); #endif #if defined(OF_WINDOWS) __mingw_aligned_free((char *)instance - PRE_IVARS_ALIGN); #elif defined(OF_MSDOS) alignedFree((char *)instance - PRE_IVARS_ALIGN, offset); #else free((char *)instance - PRE_IVARS_ALIGN); #endif @throw [OFInitializationFailedException exceptionWithClass: class]; } if OF_UNLIKELY (extra != NULL) *extra = (char *)instance + instanceSize + extraAlignment; return instance; } const char * _NSPrintForDebugger(id object) { return [[object description] cStringWithEncoding: [OFLocale encoding]]; } /* References for static linking */ void OF_VISIBILITY_HIDDEN _references_to_categories_of_OFObject(void) { _OFObject_KeyValueCoding_reference = 1; } @implementation OFObject + (void)load { #if !defined(OF_APPLE_RUNTIME) || defined(__OBJC2__) objc_setUncaughtExceptionHandler(uncaughtExceptionHandler); #endif #if defined(OF_APPLE_RUNTIME) /* * If the NSFoundationVersionNumber symbol is defined, we are linked * against Foundation. Since CoreFoundation sets its own forward * handler on load, we should not set ours, as this will break * Foundation. * * Unfortunately, there is no way to check if a forward handler has * already been set, so this is the best we can do. */ if (dlsym(RTLD_DEFAULT, "NSFoundationVersionNumber") == NULL) objc_setForwardHandler((void *)&OFForward, (void *)&OFForward_stret); #else objc_setForwardHandler((IMP)&OFForward, (IMP)&OFForward_stret); #endif objc_setEnumerationMutationHandler(enumerationMutationHandler); do { OFHashSeed = OFRandom32(); } while (OFHashSeed == 0); #ifdef OF_OBJFW_RUNTIME objc_setTaggedPointerSecret(sizeof(uintptr_t) == 4 ? (uintptr_t)OFRandom32() : (uintptr_t)OFRandom64()); #endif } + (void)unload { } + (void)initialize { } + (instancetype)alloc { return OFAllocObject(self, 0, 0, NULL); } + (Class)class { return self; } + (OFString *)className { return [OFString stringWithCString: class_getName(self) encoding: OFStringEncodingASCII]; } + (bool)isSubclassOfClass: (Class)class { for (Class iter = self; iter != Nil; iter = class_getSuperclass(iter)) if (iter == class) return true; return false; } + (Class)superclass { return class_getSuperclass(self); } + (bool)instancesRespondToSelector: (SEL)selector { return class_respondsToSelector(self, selector); } + (bool)conformsToProtocol: (Protocol *)protocol { for (Class iter = self; iter != Nil; iter = class_getSuperclass(iter)) if (class_conformsToProtocol(iter, protocol)) return true; return false; } + (IMP)instanceMethodForSelector: (SEL)selector { return class_getMethodImplementation(self, selector); } + (OFMethodSignature *)instanceMethodSignatureForSelector: (SEL)selector { const char *typeEncoding = typeEncodingForSelector(self, selector); if (typeEncoding == NULL) return nil; return [OFMethodSignature signatureWithObjCTypes: typeEncoding]; } + (OFString *)description { return [self className]; } + (IMP)replaceClassMethod: (SEL)selector withMethodFromClass: (Class)class { IMP method = [class methodForSelector: selector]; if (method == NULL) @throw [OFInvalidArgumentException exception]; return class_replaceMethod(object_getClass(self), selector, method, typeEncodingForSelector(object_getClass(class), selector)); } + (IMP)replaceInstanceMethod: (SEL)selector withMethodFromClass: (Class)class { IMP method = [class instanceMethodForSelector: selector]; if (method == NULL) @throw [OFInvalidArgumentException exception]; return class_replaceMethod(self, selector, method, typeEncodingForSelector(class, selector)); } + (void)inheritMethodsFromClass: (Class)class { Class superclass = [self superclass]; Method *methodList; unsigned int count; if ([self isSubclassOfClass: class]) return; methodList = class_copyMethodList(object_getClass(class), &count); @try { for (unsigned int i = 0; i < count; i++) { SEL selector = method_getName(methodList[i]); /* * Don't replace methods implemented in the receiving * class. */ if ([self methodForSelector: selector] != [superclass methodForSelector: selector]) continue; [self replaceClassMethod: selector withMethodFromClass: class]; } } @finally { free(methodList); } methodList = class_copyMethodList(class, &count); @try { for (unsigned int i = 0; i < count; i++) { SEL selector = method_getName(methodList[i]); /* * Don't replace methods implemented in the receiving * class. */ if ([self instanceMethodForSelector: selector] != [superclass instanceMethodForSelector: selector]) continue; [self replaceInstanceMethod: selector withMethodFromClass: class]; } } @finally { free(methodList); } [self inheritMethodsFromClass: superclass]; } + (bool)resolveClassMethod: (SEL)selector { return false; } + (bool)resolveInstanceMethod: (SEL)selector { return false; } - (instancetype)init { return self; } - (Class)class { return object_getClass(self); } - (Class)superclass { return class_getSuperclass(object_getClass(self)); } - (OFString *)className { return [OFString stringWithCString: object_getClassName(self) encoding: OFStringEncodingASCII]; } - (bool)isKindOfClass: (Class)class { for (Class iter = object_getClass(self); iter != Nil; iter = class_getSuperclass(iter)) if (iter == class) return true; return false; } - (bool)isMemberOfClass: (Class)class { return (object_getClass(self) == class); } - (bool)respondsToSelector: (SEL)selector { return class_respondsToSelector(object_getClass(self), selector); } - (bool)conformsToProtocol: (Protocol *)protocol { return [object_getClass(self) conformsToProtocol: protocol]; } - (IMP)methodForSelector: (SEL)selector { return class_getMethodImplementation(object_getClass(self), selector); } - (id)performSelector: (SEL)selector { #if defined(OF_OBJFW_RUNTIME) id (*imp)(id, SEL) = (id (*)(id, SEL))objc_msg_lookup(self, selector); #elif defined(OF_APPLE_RUNTIME) id (*imp)(id, SEL) = (id (*)(id, SEL))objc_msgSend; #endif return imp(self, selector); } - (id)performSelector: (SEL)selector withObject: (id)object { #if defined(OF_OBJFW_RUNTIME) id (*imp)(id, SEL, id) = (id (*)(id, SEL, id))objc_msg_lookup(self, selector); #elif defined(OF_APPLE_RUNTIME) id (*imp)(id, SEL, id) = (id (*)(id, SEL, id))objc_msgSend; #endif return imp(self, selector, object); } - (id)performSelector: (SEL)selector withObject: (id)object1 withObject: (id)object2 { #if defined(OF_OBJFW_RUNTIME) id (*imp)(id, SEL, id, id) = (id (*)(id, SEL, id, id))objc_msg_lookup(self, selector); #elif defined(OF_APPLE_RUNTIME) id (*imp)(id, SEL, id, id) = (id (*)(id, SEL, id, id))objc_msgSend; #endif return imp(self, selector, object1, object2); } - (id)performSelector: (SEL)selector withObject: (id)object1 withObject: (id)object2 withObject: (id)object3 { #if defined(OF_OBJFW_RUNTIME) id (*imp)(id, SEL, id, id, id) = (id (*)(id, SEL, id, id, id))objc_msg_lookup(self, selector); #elif defined(OF_APPLE_RUNTIME) id (*imp)(id, SEL, id, id, id) = (id (*)(id, SEL, id, id, id))objc_msgSend; #endif return imp(self, selector, object1, object2, object3); } - (id)performSelector: (SEL)selector withObject: (id)object1 withObject: (id)object2 withObject: (id)object3 withObject: (id)object4 { #if defined(OF_OBJFW_RUNTIME) id (*imp)(id, SEL, id, id, id, id) = (id (*)(id, SEL, id, id, id, id))objc_msg_lookup(self, selector); #elif defined(OF_APPLE_RUNTIME) id (*imp)(id, SEL, id, id, id, id) = (id (*)(id, SEL, id, id, id, id))objc_msgSend; #endif return imp(self, selector, object1, object2, object3, object4); } - (void)performSelector: (SEL)selector afterDelay: (OFTimeInterval)delay { void *pool = objc_autoreleasePoolPush(); [OFTimer scheduledTimerWithTimeInterval: delay target: self selector: selector repeats: false]; objc_autoreleasePoolPop(pool); } - (void)performSelector: (SEL)selector withObject: (id)object afterDelay: (OFTimeInterval)delay { void *pool = objc_autoreleasePoolPush(); [OFTimer scheduledTimerWithTimeInterval: delay target: self selector: selector object: object repeats: false]; objc_autoreleasePoolPop(pool); } - (void)performSelector: (SEL)selector withObject: (id)object1 withObject: (id)object2 afterDelay: (OFTimeInterval)delay { void *pool = objc_autoreleasePoolPush(); [OFTimer scheduledTimerWithTimeInterval: delay target: self selector: selector object: object1 object: object2 repeats: false]; objc_autoreleasePoolPop(pool); } - (void)performSelector: (SEL)selector withObject: (id)object1 withObject: (id)object2 withObject: (id)object3 afterDelay: (OFTimeInterval)delay { void *pool = objc_autoreleasePoolPush(); [OFTimer scheduledTimerWithTimeInterval: delay target: self selector: selector object: object1 object: object2 object: object3 repeats: false]; objc_autoreleasePoolPop(pool); } - (void)performSelector: (SEL)selector withObject: (id)object1 withObject: (id)object2 withObject: (id)object3 withObject: (id)object4 afterDelay: (OFTimeInterval)delay { void *pool = objc_autoreleasePoolPush(); [OFTimer scheduledTimerWithTimeInterval: delay target: self selector: selector object: object1 object: object2 object: object3 object: object4 repeats: false]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_THREADS - (void)performSelector: (SEL)selector onThread: (OFThread *)thread waitUntilDone: (bool)waitUntilDone { void *pool = objc_autoreleasePoolPush(); OFTimer *timer = [OFTimer timerWithTimeInterval: 0 target: self selector: selector repeats: false]; [thread.runLoop addTimer: timer]; if (waitUntilDone) [timer waitUntilDone]; objc_autoreleasePoolPop(pool); } - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (id)object waitUntilDone: (bool)waitUntilDone { void *pool = objc_autoreleasePoolPush(); OFTimer *timer = [OFTimer timerWithTimeInterval: 0 target: self selector: selector object: object repeats: false]; [thread.runLoop addTimer: timer]; if (waitUntilDone) [timer waitUntilDone]; objc_autoreleasePoolPop(pool); } - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (id)object1 withObject: (id)object2 waitUntilDone: (bool)waitUntilDone { void *pool = objc_autoreleasePoolPush(); OFTimer *timer = [OFTimer timerWithTimeInterval: 0 target: self selector: selector object: object1 object: object2 repeats: false]; [thread.runLoop addTimer: timer]; if (waitUntilDone) [timer waitUntilDone]; objc_autoreleasePoolPop(pool); } - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (id)object1 withObject: (id)object2 withObject: (id)object3 waitUntilDone: (bool)waitUntilDone { void *pool = objc_autoreleasePoolPush(); OFTimer *timer = [OFTimer timerWithTimeInterval: 0 target: self selector: selector object: object1 object: object2 object: object3 repeats: false]; [thread.runLoop addTimer: timer]; if (waitUntilDone) [timer waitUntilDone]; objc_autoreleasePoolPop(pool); } - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (id)object1 withObject: (id)object2 withObject: (id)object3 withObject: (id)object4 waitUntilDone: (bool)waitUntilDone { void *pool = objc_autoreleasePoolPush(); OFTimer *timer = [OFTimer timerWithTimeInterval: 0 target: self selector: selector object: object1 object: object2 object: object3 object: object4 repeats: false]; [thread.runLoop addTimer: timer]; if (waitUntilDone) [timer waitUntilDone]; objc_autoreleasePoolPop(pool); } - (void)performSelectorOnMainThread: (SEL)selector waitUntilDone: (bool)waitUntilDone { void *pool = objc_autoreleasePoolPush(); OFTimer *timer = [OFTimer timerWithTimeInterval: 0 target: self selector: selector repeats: false]; [[OFRunLoop mainRunLoop] addTimer: timer]; if (waitUntilDone) [timer waitUntilDone]; objc_autoreleasePoolPop(pool); } - (void)performSelectorOnMainThread: (SEL)selector withObject: (id)object waitUntilDone: (bool)waitUntilDone { void *pool = objc_autoreleasePoolPush(); OFTimer *timer = [OFTimer timerWithTimeInterval: 0 target: self selector: selector object: object repeats: false]; [[OFRunLoop mainRunLoop] addTimer: timer]; if (waitUntilDone) [timer waitUntilDone]; objc_autoreleasePoolPop(pool); } - (void)performSelectorOnMainThread: (SEL)selector withObject: (id)object1 withObject: (id)object2 waitUntilDone: (bool)waitUntilDone { void *pool = objc_autoreleasePoolPush(); OFTimer *timer = [OFTimer timerWithTimeInterval: 0 target: self selector: selector object: object1 object: object2 repeats: false]; [[OFRunLoop mainRunLoop] addTimer: timer]; if (waitUntilDone) [timer waitUntilDone]; objc_autoreleasePoolPop(pool); } - (void)performSelectorOnMainThread: (SEL)selector withObject: (id)object1 withObject: (id)object2 withObject: (id)object3 waitUntilDone: (bool)waitUntilDone { void *pool = objc_autoreleasePoolPush(); OFTimer *timer = [OFTimer timerWithTimeInterval: 0 target: self selector: selector object: object1 object: object2 object: object3 repeats: false]; [[OFRunLoop mainRunLoop] addTimer: timer]; if (waitUntilDone) [timer waitUntilDone]; objc_autoreleasePoolPop(pool); } - (void)performSelectorOnMainThread: (SEL)selector withObject: (id)object1 withObject: (id)object2 withObject: (id)object3 withObject: (id)object4 waitUntilDone: (bool)waitUntilDone { void *pool = objc_autoreleasePoolPush(); OFTimer *timer = [OFTimer timerWithTimeInterval: 0 target: self selector: selector object: object1 object: object2 object: object3 object: object4 repeats: false]; [[OFRunLoop mainRunLoop] addTimer: timer]; if (waitUntilDone) [timer waitUntilDone]; objc_autoreleasePoolPop(pool); } - (void)performSelector: (SEL)selector onThread: (OFThread *)thread afterDelay: (OFTimeInterval)delay { void *pool = objc_autoreleasePoolPush(); [thread.runLoop addTimer: [OFTimer timerWithTimeInterval: delay target: self selector: selector repeats: false]]; objc_autoreleasePoolPop(pool); } - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (id)object afterDelay: (OFTimeInterval)delay { void *pool = objc_autoreleasePoolPush(); [thread.runLoop addTimer: [OFTimer timerWithTimeInterval: delay target: self selector: selector object: object repeats: false]]; objc_autoreleasePoolPop(pool); } - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (id)object1 withObject: (id)object2 afterDelay: (OFTimeInterval)delay { void *pool = objc_autoreleasePoolPush(); [thread.runLoop addTimer: [OFTimer timerWithTimeInterval: delay target: self selector: selector object: object1 object: object2 repeats: false]]; objc_autoreleasePoolPop(pool); } - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (id)object1 withObject: (id)object2 withObject: (id)object3 afterDelay: (OFTimeInterval)delay { void *pool = objc_autoreleasePoolPush(); [thread.runLoop addTimer: [OFTimer timerWithTimeInterval: delay target: self selector: selector object: object1 object: object2 object: object3 repeats: false]]; objc_autoreleasePoolPop(pool); } - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (id)object1 withObject: (id)object2 withObject: (id)object3 withObject: (id)object4 afterDelay: (OFTimeInterval)delay { void *pool = objc_autoreleasePoolPush(); [thread.runLoop addTimer: [OFTimer timerWithTimeInterval: delay target: self selector: selector object: object1 object: object2 object: object3 object: object4 repeats: false]]; objc_autoreleasePoolPop(pool); } #endif - (OFMethodSignature *)methodSignatureForSelector: (SEL)selector { const char *typeEncoding = typeEncodingForSelector(object_getClass(self), selector); if (typeEncoding == NULL) return nil; return [OFMethodSignature signatureWithObjCTypes: typeEncoding]; } - (bool)isEqual: (id)object { return (object == self); } - (unsigned long)hash { uintptr_t ptr = (uintptr_t)self; unsigned long hash; OFHashInit(&hash); for (size_t i = 0; i < sizeof(ptr); i++) { OFHashAddByte(&hash, ptr & 0xFF); ptr >>= 8; } OFHashFinalize(&hash); return hash; } - (OFString *)description { /* Classes containing data should reimplement this! */ return [OFString stringWithFormat: @"<%@>", self.className]; } - (id)forwardingTargetForSelector: (SEL)selector { return nil; } - (void)doesNotRecognizeSelector: (SEL)selector { @throw [OFNotImplementedException exceptionWithSelector: selector object: self]; } - (instancetype)retain { #if defined(OF_HAVE_ATOMIC_OPS) OFAtomicIntIncrease(&PRE_IVARS->retainCount); #elif defined(OF_AMIGAOS) /* * On AmigaOS, we can only have one CPU. As increasing a variable is a * single instruction on M68K, we don't need Forbid() / Permit() on * M68K. */ # ifndef OF_AMIGAOS_M68K Forbid(); # endif PRE_IVARS->retainCount++; # ifndef OF_AMIGAOS_M68K Permit(); # endif #else OFEnsure(OFSpinlockLock(&PRE_IVARS->retainCountSpinlock) == 0); PRE_IVARS->retainCount++; OFEnsure(OFSpinlockUnlock(&PRE_IVARS->retainCountSpinlock) == 0); #endif return self; } - (unsigned int)retainCount { OFAssert(PRE_IVARS->retainCount >= 0); return PRE_IVARS->retainCount; } - (void)release { #if defined(OF_HAVE_ATOMIC_OPS) OFReleaseMemoryBarrier(); if (OFAtomicIntDecrease(&PRE_IVARS->retainCount) <= 0) { OFAcquireMemoryBarrier(); [self dealloc]; } #elif defined(OF_AMIGAOS) int retainCount; Forbid(); retainCount = --PRE_IVARS->retainCount; Permit(); if (retainCount == 0) [self dealloc]; #else int retainCount; OFEnsure(OFSpinlockLock(&PRE_IVARS->retainCountSpinlock) == 0); retainCount = --PRE_IVARS->retainCount; OFEnsure(OFSpinlockUnlock(&PRE_IVARS->retainCountSpinlock) == 0); if (retainCount == 0) [self dealloc]; #endif } - (instancetype)autorelease { return _objc_rootAutorelease(self); } - (instancetype)self { return self; } - (bool)isProxy { return false; } - (bool)allowsWeakReference { return true; } - (bool)retainWeakReference { [self retain]; return true; } - (void)dealloc { objc_destructInstance(self); #if !defined(OF_HAVE_ATOMIC_OPS) && !defined(OF_AMIGAOS) OFSpinlockFree(&PRE_IVARS->retainCountSpinlock); #endif #if defined(OF_WINDOWS) __mingw_aligned_free((char *)self - PRE_IVARS_ALIGN); #elif defined(OF_MSDOS) alignedFree((char *)self - PRE_IVARS_ALIGN, PRE_IVARS->offset); #else free((char *)self - PRE_IVARS_ALIGN); #endif } /* Required to use properties with the Apple runtime */ - (id)copyWithZone: (void *)zone { if OF_UNLIKELY (zone != NULL) { [self doesNotRecognizeSelector: _cmd]; abort(); } return [(id)self copy]; } - (id)mutableCopyWithZone: (void *)zone { if OF_UNLIKELY (zone != NULL) { [self doesNotRecognizeSelector: _cmd]; abort(); } return [(id)self mutableCopy]; } /* * The following are needed as the root class is the superclass of the root * class's metaclass and thus instance methods can be sent to class objects as * well. */ + (id)retain { return self; } + (id)autorelease { return self; } + (unsigned int)retainCount { return OFMaxRetainCount; } + (void)release { } + (void)dealloc { OF_UNRECOGNIZED_SELECTOR } + (id)copy { return self; } + (id)mutableCopyWithZone: (void *)zone { OF_UNRECOGNIZED_SELECTOR } /* Required to use ObjFW from Swift */ + (instancetype)allocWithZone: (void *)zone { if OF_UNLIKELY (zone != NULL) { [self doesNotRecognizeSelector: _cmd]; abort(); } return [self alloc]; } @end objfw-1.1.6/src/OFOnce.h000066400000000000000000000032311465614216400147070ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "objfw-defs.h" #import "macros.h" #if defined(OF_HAVE_PTHREADS) # include typedef pthread_once_t OFOnceControl; # define OFOnceControlInitValue PTHREAD_ONCE_INIT #elif defined(OF_HAVE_ATOMIC_OPS) typedef volatile int OFOnceControl; # define OFOnceControlInitValue 0 #elif defined(OF_AMIGAOS) || !defined(OF_HAVE_THREADS) typedef int OFOnceControl; # define OFOnceControlInitValue 0 #endif OF_ASSUME_NONNULL_BEGIN /** @file */ typedef void (*OFOnceFunction)(void); #ifdef __cplusplus extern "C" { #endif /** * @brief Executes the specified function exactly once in the application's * lifetime, even in a multi-threaded environment. * * @param control An OFOnceControl. This should be a static variable * preinitialized to `OFOnceControlInitValue`. * @param function The function to execute once */ extern void OFOnce(OFOnceControl *control, OFOnceFunction function); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFOnce.m000066400000000000000000000035371465614216400147250ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFOnce.h" #if defined(OF_HAVE_THREADS) && defined(OF_HAVE_ATOMIC_OPS) # import "OFAtomic.h" # import "OFPlainMutex.h" #endif #ifdef OF_AMIGAOS # define Class IntuitionClass # include # undef Class #endif void OFOnce(OFOnceControl *control, void (*function)(void)) { #if !defined(OF_HAVE_THREADS) if (*control == 0) { function(); *control = 1; } #elif defined(OF_HAVE_PTHREADS) pthread_once(control, function); #elif defined(OF_HAVE_ATOMIC_OPS) /* Avoid atomic operations in case it's already done. */ if (*control == 2) return; if (OFAtomicIntCompareAndSwap(control, 0, 1)) { function(); OFMemoryBarrier(); OFAtomicIntIncrease(control); } else while (*control == 1) OFYieldThread(); #elif defined(OF_AMIGAOS) bool run = false; /* Avoid Forbid() in case it's already done. */ if (*control == 2) return; Forbid(); switch (*control) { case 0: *control = 1; run = true; break; case 1: while (*control == 1) { Permit(); Forbid(); } } Permit(); if (run) { function(); *control = 2; } #else # error No OFOnce available #endif } objfw-1.1.6/src/OFOptionsParser.h000066400000000000000000000124731465614216400166430ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFString.h" @class OFMapTable; OF_ASSUME_NONNULL_BEGIN /** * @struct OFOptionsParserOption OFOptionsParser.h ObjFW/OFOptionsParser.h * * @brief An option which can be parsed by an @ref OFOptionsParser. */ typedef struct { /** The short version (e.g. `-v`) of the option or `\0` for none. */ OFUnichar shortOption; /** * The long version (e.g. `--verbose`) of the option or `nil` for none. */ OFString *__unsafe_unretained _Nullable longOption; /** * Whether the option takes an argument. * * 0 means it takes no argument.@n * 1 means it takes a required argument.@n * -1 means it takes an optional argument.@n * * All other values are invalid and will throw an * @ref OFInvalidArgumentException. */ signed char hasArgument; /** * An optional pointer to a bool that is set to whether the option has * been specified. */ bool *_Nullable isSpecifiedPtr; /** * An optional pointer to an `OFString *` that is set to the * argument specified for the option or `nil` for no argument. */ OFString *__autoreleasing _Nullable *_Nullable argumentPtr; } OFOptionsParserOption; /** * @class OFOptionsParser OFOptionsParser.h ObjFW/OFOptionsParser.h * * @brief A class for parsing the program options specified on the command line. */ OF_SUBCLASSING_RESTRICTED @interface OFOptionsParser: OFObject { OFOptionsParserOption *_options; OFMapTable *_longOptions; OFArray OF_GENERIC(OFString *) *_arguments; size_t _index, _subIndex; OFUnichar _lastOption; OFString *_Nullable _lastLongOption, *_Nullable _argument; bool _done; } /** * @brief The last parsed option. * * If @ref nextOption returned `?` or `:`, this returns the option which was * unknown or for which the argument was missing.@n * If this returns `-`, the last option is only available as a long option (see * lastLongOption). */ @property (readonly, nonatomic) OFUnichar lastOption; /** * @brief The long option for the last parsed option, or `nil` if the last * parsed option was not passed as a long option by the user. * * In case @ref nextOption returned `?`, this contains the unknown long * option.@n * In case it returned `:`, this contains the long option which is missing an * argument.@n * In case it returned `=`, this contains the long option for which an * argument was specified even though the option takes no argument. * * @warning Unlike @ref lastOption, which returns the short option even if the * user specified a long option, this only returns the long option if * it was actually specified as a long option by the user. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *lastLongOption; /** * @brief The argument for the last parsed option, or `nil` if the last parsed * option takes no argument. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *argument; /** * @brief The arguments following the last option. */ @property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *remainingArguments; /** * @brief Creates a new OFOptionsParser which accepts the specified options. * * @param options An array of @ref OFOptionsParserOption specifying all * accepted options, terminated with an option whose short * option is `\0` and long option is `nil`. * * @return A new, autoreleased OFOptionsParser */ + (instancetype)parserWithOptions: (const OFOptionsParserOption *)options; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFOptionsParser so that it accepts * the specified options. * * @param options An array of @ref OFOptionsParserOption specifying all * accepted options, terminated with an option whose short * option is `\0` and long option is `nil`. * * @return An initialized OFOptionsParser */ - (instancetype)initWithOptions: (const OFOptionsParserOption *)options OF_DESIGNATED_INITIALIZER; /** * @brief Returns the next option. * * If the option is only available as a long option, `-` is returned. * Otherwise, the short option is returned, even if it was specified as a long * option.@n * If an unknown option is specified, `?` is returned.@n * If the argument for the option is missing, `:` is returned.@n * If there is an argument for the option even though it takes none, `=` is * returned.@n * If all options have been parsed, `\0` is returned. * * @note You need to call @ref nextOption repeatedly until it returns `\0` to * make sure all options have been parsed, even if you only rely on the * optional pointers specified and don't do any parsing yourself. * * @return The next option */ - (OFUnichar)nextOption; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFOptionsParser.m000066400000000000000000000145111465614216400166430ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFOptionsParser.h" #import "OFApplication.h" #import "OFArray.h" #import "OFMapTable.h" #import "OFInvalidArgumentException.h" static unsigned long stringHash(void *object) { return ((OFString *)object).hash; } static bool stringEqual(void *object1, void *object2) { return [(OFString *)object1 isEqual: (OFString *)object2]; } @implementation OFOptionsParser @synthesize lastOption = _lastOption, lastLongOption = _lastLongOption; @synthesize argument = _argument; + (instancetype)parserWithOptions: (const OFOptionsParserOption *)options { return [[[self alloc] initWithOptions: options] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithOptions: (const OFOptionsParserOption *)options { self = [super init]; @try { size_t count = 0; const OFOptionsParserOption *iter; OFOptionsParserOption *iter2; const OFMapTableFunctions keyFunctions = { .hash = stringHash, .equal = stringEqual }; const OFMapTableFunctions objectFunctions = { NULL }; /* Count, sanity check, initialize pointers */ for (iter = options; iter->shortOption != '\0' || iter->longOption != nil; iter++) { if (iter->hasArgument < -1 || iter->hasArgument > 1) @throw [OFInvalidArgumentException exception]; if (iter->shortOption != '\0' && iter->hasArgument == -1) @throw [OFInvalidArgumentException exception]; if (iter->hasArgument == 0 && iter->argumentPtr != NULL) @throw [OFInvalidArgumentException exception]; if (iter->isSpecifiedPtr) *iter->isSpecifiedPtr = false; if (iter->argumentPtr) *iter->argumentPtr = nil; count++; } _options = OFAllocMemory(count + 1, sizeof(*_options)); _longOptions = [[OFMapTable alloc] initWithKeyFunctions: keyFunctions objectFunctions: objectFunctions]; for (iter = options, iter2 = _options; iter->shortOption != '\0' || iter->longOption != nil; iter++, iter2++) { iter2->shortOption = iter->shortOption; iter2->longOption = nil; iter2->hasArgument = iter->hasArgument; iter2->isSpecifiedPtr = iter->isSpecifiedPtr; iter2->argumentPtr = iter->argumentPtr; if (iter->longOption != nil) { @try { iter2->longOption = [iter->longOption copy]; if ([_longOptions objectForKey: iter2->longOption] != NULL) @throw [OFInvalidArgumentException exception]; [_longOptions setObject: iter2 forKey: iter2->longOption]; } @catch (id e) { /* * Make sure we are in a consistent * state where dealloc works. */ [iter2->longOption release]; iter2->shortOption = '\0'; iter2->longOption = nil; @throw e; } } } iter2->shortOption = '\0'; iter2->longOption = nil; _arguments = [[OFApplication arguments] retain]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_options != NULL) for (OFOptionsParserOption *iter = _options; iter->shortOption != '\0' || iter->longOption != nil; iter++) [iter->longOption release]; OFFreeMemory(_options); [_longOptions release]; [_arguments release]; [_argument release]; [super dealloc]; } - (OFUnichar)nextOption { OFOptionsParserOption *iter; OFString *argument; if (_done || _index >= _arguments.count) return '\0'; [_lastLongOption release]; [_argument release]; _lastLongOption = nil; _argument = nil; argument = [_arguments objectAtIndex: _index]; if (_subIndex == 0) { if (argument.length < 2 || [argument characterAtIndex: 0] != '-') { _done = true; return '\0'; } if ([argument isEqual: @"--"]) { _done = true; _index++; return '\0'; } if ([argument hasPrefix: @"--"]) { void *pool = objc_autoreleasePoolPush(); size_t pos; OFOptionsParserOption *option; _lastOption = '-'; _index++; if ((pos = [argument rangeOfString: @"="].location) != OFNotFound) _argument = [[argument substringFromIndex: pos + 1] copy]; else pos = argument.length; _lastLongOption = [[argument substringWithRange: OFMakeRange(2, pos - 2)] copy]; objc_autoreleasePoolPop(pool); option = [_longOptions objectForKey: _lastLongOption]; if (option == NULL) return '?'; if (option->hasArgument == 1 && _argument == nil) return ':'; if (option->hasArgument == 0 && _argument != nil) return '='; if (option->isSpecifiedPtr != NULL) *option->isSpecifiedPtr = true; if (option->argumentPtr != NULL) *option->argumentPtr = [[_argument copy] autorelease]; if (option->shortOption != '\0') _lastOption = option->shortOption; return _lastOption; } _subIndex = 1; } _lastOption = [argument characterAtIndex: _subIndex++]; if (_subIndex >= argument.length) { _index++; _subIndex = 0; } for (iter = _options; iter->shortOption != '\0' || iter->longOption != nil; iter++) { if (iter->shortOption == _lastOption) { if (iter->hasArgument == 0) { if (iter->isSpecifiedPtr != NULL) *iter->isSpecifiedPtr = true; return _lastOption; } if (_index >= _arguments.count) return ':'; argument = [_arguments objectAtIndex: _index]; argument = [argument substringFromIndex: _subIndex]; _argument = [argument copy]; if (iter->isSpecifiedPtr != NULL) *iter->isSpecifiedPtr = true; if (iter->argumentPtr != NULL) *iter->argumentPtr = [[_argument copy] autorelease]; _index++; _subIndex = 0; return _lastOption; } } return '?'; } - (OFArray *)remainingArguments { return [_arguments objectsInRange: OFMakeRange(_index, _arguments.count - _index)]; } @end objfw-1.1.6/src/OFPBKDF2.h000066400000000000000000000042611465614216400147370ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif #import "macros.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFHMAC; /** * @brief The parameters for @ref OFPBKDF2. */ typedef struct { /** @brief The HMAC to use to derive a key. */ __unsafe_unretained OFHMAC *HMAC; /** @brief The number of iterations to perform. */ size_t iterations; /** @brief The salt to derive a key with. */ const unsigned char *salt; /** @brief The length of the salt. */ size_t saltLength; /** @brief The password to derive a key from. */ const char *password; /** @brief The length of the password. */ size_t passwordLength; /** @brief The buffer to write the key to. */ unsigned char *key; /** * @brief The desired length for the derived key. * * @ref key needs to have enough storage. */ size_t keyLength; /** @brief Whether data may be stored in swappable memory. */ bool allowsSwappableMemory; } OFPBKDF2Parameters; #ifdef __cplusplus extern "C" { #endif /** * @brief Derives a key from a password and a salt using PBKDF2. * * @note This will call @ref OFHMAC#reset on the `HMAC` first, making it * possible to reuse the `HMAC`, but also meaning all previous results * from the `HMAC` get invalidated if they have not been copied. * * @param parameters The parameters to use */ extern void OFPBKDF2(OFPBKDF2Parameters parameters); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFPBKDF2.m000066400000000000000000000064431465614216400147500ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFPBKDF2.h" #import "OFHMAC.h" #import "OFSecureData.h" #import "OFInvalidArgumentException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" void OFPBKDF2(OFPBKDF2Parameters param) { void *pool = objc_autoreleasePoolPush(); size_t blocks, digestSize = param.HMAC.digestSize; OFSecureData *buffer = [OFSecureData dataWithCount: digestSize allowsSwappableMemory: param.allowsSwappableMemory]; OFSecureData *digest = [OFSecureData dataWithCount: digestSize allowsSwappableMemory: param.allowsSwappableMemory]; unsigned char *bufferItems = buffer.mutableItems; unsigned char *digestItems = digest.mutableItems; OFSecureData *extendedSalt; unsigned char *extendedSaltItems; if (param.HMAC == nil || param.iterations == 0 || param.salt == NULL || param.password == NULL || param.key == NULL || param.keyLength == 0) @throw [OFInvalidArgumentException exception]; blocks = param.keyLength / digestSize; if (param.keyLength % digestSize != 0) blocks++; if (param.saltLength > SIZE_MAX - 4 || blocks > UINT32_MAX) @throw [OFOutOfRangeException exception]; extendedSalt = [OFSecureData dataWithCount: param.saltLength + 4 allowsSwappableMemory: param.allowsSwappableMemory]; extendedSaltItems = extendedSalt.mutableItems; @try { uint32_t i = OFToBigEndian32(1); [param.HMAC setKey: param.password length: param.passwordLength]; memcpy(extendedSaltItems, param.salt, param.saltLength); while (param.keyLength > 0) { size_t length; memcpy(extendedSaltItems + param.saltLength, &i, 4); [param.HMAC reset]; [param.HMAC updateWithBuffer: extendedSaltItems length: param.saltLength + 4]; [param.HMAC calculate]; memcpy(bufferItems, param.HMAC.digest, digestSize); memcpy(digestItems, param.HMAC.digest, digestSize); for (size_t j = 1; j < param.iterations; j++) { [param.HMAC reset]; [param.HMAC updateWithBuffer: digestItems length: digestSize]; [param.HMAC calculate]; memcpy(digestItems, param.HMAC.digest, digestSize); for (size_t k = 0; k < digestSize; k++) bufferItems[k] ^= digestItems[k]; } length = digestSize; if (length > param.keyLength) length = param.keyLength; memcpy(param.key, bufferItems, length); param.key += length; param.keyLength -= length; i = OFToBigEndian32(OFFromBigEndian32(i) + 1); } } @catch (id e) { [extendedSalt zero]; [buffer zero]; [digest zero]; @throw e; } @finally { [param.HMAC zero]; } objc_autoreleasePoolPop(pool); } objfw-1.1.6/src/OFPTRDNSResourceRecord.h000066400000000000000000000036441465614216400177140ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFDNSResourceRecord.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFPTRDNSResourceRecord \ * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h * * @brief A class representing a PTR DNS resource record. */ OF_SUBCLASSING_RESTRICTED @interface OFPTRDNSResourceRecord: OFDNSResourceRecord { OFString *_domainName; } /** * @brief The domain name of the resource record. */ @property (readonly, nonatomic) OFString *domainName; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFPTRDNSResourceRecord with the * specified name, class, domain name and time to live. * * @param name The name for the resource record * @param DNSClass The class code for the resource record * @param domainName The domain name for the resource record * @param TTL The time to live for the resource record * @return An initialized OFPTRDNSResourceRecord */ - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass domainName: (OFString *)domainName TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFPTRDNSResourceRecord.m000066400000000000000000000050761465614216400177220ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFPTRDNSResourceRecord.h" @implementation OFPTRDNSResourceRecord @synthesize domainName = _domainName; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass domainName: (OFString *)domainName TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: DNSClass recordType: OFDNSRecordTypePTR TTL: TTL]; @try { _domainName = [domainName copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_domainName release]; [super dealloc]; } - (bool)isEqual: (id)object { OFPTRDNSResourceRecord *record; if (object == self) return true; if (![object isKindOfClass: [OFPTRDNSResourceRecord class]]) return false; record = object; if (record->_name != _name && ![record->_name isEqual: _name]) return false; if (record->_DNSClass != _DNSClass) return false; if (record->_recordType != _recordType) return false; if (record->_domainName != _domainName && ![record->_domainName isEqual: _domainName]) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddByte(&hash, _DNSClass >> 8); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType >> 8); OFHashAddByte(&hash, _recordType); OFHashAddHash(&hash, _domainName.hash); OFHashFinalize(&hash); return hash; } - (OFString *)description { return [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tClass = %@\n" @"\tDomain Name = %@\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFDNSClassName(_DNSClass), _domainName, _TTL]; } @end objfw-1.1.6/src/OFPair.h000066400000000000000000000044511465614216400147230ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFPair OFPair.h ObjFW/OFPair.h * * @brief A class for storing a pair of two objects. */ @interface OFPair OF_GENERIC(FirstType, SecondType): OFObject #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # define FirstType id # define SecondType id #endif { FirstType _Nullable _firstObject; SecondType _Nullable _secondObject; OF_RESERVE_IVARS(OFPair, 4) } /** * @brief The first object of the pair. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic, retain) FirstType firstObject; /** * @brief The second object of the pair. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic, retain) SecondType secondObject; /** * @brief Creates a new OFPair with the specified objects. * * @param firstObject The first object for the pair * @param secondObject The second object for the pair * @return A new, autoreleased OFPair */ + (instancetype)pairWithFirstObject: (nullable FirstType)firstObject secondObject: (nullable SecondType)secondObject; /** * @brief Initializes an already allocated OFPair with the specified objects. * * @param firstObject The first object for the pair * @param secondObject The second object for the pair * @return An initialized OFPair */ - (instancetype)initWithFirstObject: (nullable FirstType)firstObject secondObject: (nullable SecondType)secondObject OF_DESIGNATED_INITIALIZER; #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # undef FirstType # undef SecondType #endif @end OF_ASSUME_NONNULL_END #import "OFMutablePair.h" objfw-1.1.6/src/OFPair.m000066400000000000000000000045071465614216400147320ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFPair.h" #import "OFString.h" @implementation OFPair + (instancetype)pairWithFirstObject: (id)firstObject secondObject: (id)secondObject { return [[[self alloc] initWithFirstObject: firstObject secondObject: secondObject] autorelease]; } - (instancetype)initWithFirstObject: (id)firstObject secondObject: (id)secondObject { self = [super init]; @try { _firstObject = [firstObject retain]; _secondObject = [secondObject retain]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_firstObject release]; [_secondObject release]; [super dealloc]; } - (id)firstObject { return _firstObject; } - (id)secondObject { return _secondObject; } - (bool)isEqual: (id)object { OFPair *pair; if (object == self) return true; if (![object isKindOfClass: [OFPair class]]) return false; pair = object; if (pair->_firstObject != _firstObject && ![pair->_firstObject isEqual: _firstObject]) return false; if (pair->_secondObject != _secondObject && ![pair->_secondObject isEqual: _secondObject]) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, [_firstObject hash]); OFHashAddHash(&hash, [_secondObject hash]); OFHashFinalize(&hash); return hash; } - (id)copy { return [self retain]; } - (id)mutableCopy { return [[OFMutablePair alloc] initWithFirstObject: _firstObject secondObject: _secondObject]; } - (OFString *)description { return [OFString stringWithFormat: @"<<%@, %@>>", _firstObject, _secondObject]; } @end objfw-1.1.6/src/OFPlainCondition.h000066400000000000000000000107241465614216400167420ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "objfw-defs.h" #include "platform.h" #if !defined(OF_HAVE_THREADS) || \ (!defined(OF_HAVE_PTHREADS) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS)) # error No conditions available! #endif /* For OFTimeInterval */ #import "OFObject.h" #import "OFPlainMutex.h" /** @file */ #if defined(OF_HAVE_PTHREADS) # include typedef pthread_cond_t OFPlainCondition; #elif defined(OF_WINDOWS) # include typedef struct { HANDLE event; volatile int count; } OFPlainCondition; #elif defined(OF_AMIGAOS) # include typedef struct { struct _OFPlainConditionWaitingTask { struct Task *task; unsigned char sigBit; struct _OFPlainConditionWaitingTask *next; } *waitingTasks; } OFPlainCondition; #endif #ifdef __cplusplus extern "C" { #endif /** * @brief Creates a new plain condition. * * A plain condition is similar to an @ref OFCondition, but does not use * exceptions and can be used from pure C code. * * @param condition A pointer to the condition to create * @return 0 on success, or an error number from `` on error */ extern int OFPlainConditionNew(OFPlainCondition *condition); /** * @brief Signals the specified condition. * * @param condition A pointer to the condition to signal * @return 0 on success, or an error number from `` on error */ extern int OFPlainConditionSignal(OFPlainCondition *condition); /** * @brief Broadcasts the specified condition, meaning it will be signaled to * everyone waiting. * * @param condition A pointer to the condition to broadcast * @return 0 on success, or an error number from `` on error */ extern int OFPlainConditionBroadcast(OFPlainCondition *condition); /** * @brief Waits on the specified condition with the specified mutex. * * @param condition A pointer to the condition to wait on * @param mutex The mutex to wait with * @return 0 on success, or an error number from `` on error */ extern int OFPlainConditionWait(OFPlainCondition *condition, OFPlainMutex *mutex); /** * @brief Waits on the specified condition with the specified mutex with a * timeout. * * @param condition A pointer to the condition to wait on * @param mutex The mutex to wait with * @param timeout The timeout after which to give up * @return 0 on success, or an error number from `` on error */ extern int OFPlainConditionTimedWait(OFPlainCondition *condition, OFPlainMutex *mutex, OFTimeInterval timeout); #if defined(OF_AMIGAOS) || defined(DOXYGEN) /** * @brief Waits on the specified condition with the specified mutex or the * specified Exec signal. * * @param condition A pointer to the condition to wait on * @param mutex The mutex to wait with * @param signalMask The Exec signal mask to wait for * @return 0 on success, or an error number from `` on error */ extern int OFPlainConditionWaitOrExecSignal(OFPlainCondition *condition, OFPlainMutex *mutex, ULONG *signalMask); /** * @brief Waits on the specified condition with the specified mutex or the * specified Exec signal, up until the timeout is reached. * * @param condition A pointer to the condition to wait on * @param mutex The mutex to wait with * @param signalMask The Exec signal mask to wait for * @param timeout The timeout after which to give up * @return 0 on success, or an error number from `` on error */ extern int OFPlainConditionTimedWaitOrExecSignal(OFPlainCondition *condition, OFPlainMutex *mutex, OFTimeInterval timeout, ULONG *signalMask); #endif /** * @brief Destroys the specified plain condition. * * @param condition A pointer to the condition to destroy * @return 0 on success, or an error number from `` on error */ extern int OFPlainConditionFree(OFPlainCondition *condition); #ifdef __cplusplus } #endif objfw-1.1.6/src/OFPlainCondition.m000066400000000000000000000017571465614216400167550ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" #if defined(OF_HAVE_PTHREADS) # include "platform/POSIX/OFPlainCondition.m" #elif defined(OF_WINDOWS) # include "platform/Windows/OFPlainCondition.m" #elif defined(OF_AMIGAOS) # include "platform/AmigaOS/OFPlainCondition.m" #endif objfw-1.1.6/src/OFPlainMutex.h000066400000000000000000000164651465614216400161260ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "objfw-defs.h" #include #include "platform.h" #if !defined(OF_HAVE_THREADS) || \ (!defined(OF_HAVE_PTHREADS) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS)) # error No mutexes available! #endif #import "macros.h" /** @file */ #if defined(OF_HAVE_PTHREADS) # include typedef pthread_mutex_t OFPlainMutex; #elif defined(OF_WINDOWS) # include typedef CRITICAL_SECTION OFPlainMutex; #elif defined(OF_AMIGAOS) # include typedef struct SignalSemaphore OFPlainMutex; #endif #if defined(OF_HAVE_ATOMIC_OPS) # import "OFAtomic.h" typedef volatile int OFSpinlock; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) typedef pthread_spinlock_t OFSpinlock; #else typedef OFPlainMutex OFSpinlock; #endif #ifdef OF_HAVE_SCHED_YIELD # include #endif #if defined(OF_HAVE_RECURSIVE_PTHREAD_MUTEXES) || defined(OF_WINDOWS) || \ defined(OF_AMIGAOS) # define OFPlainRecursiveMutex OFPlainMutex #else # import "OFTLSKey.h" typedef struct { OFPlainMutex mutex; OFTLSKey count; } OFPlainRecursiveMutex; #endif #ifdef __cplusplus extern "C" { #endif /** * @brief Creates a new plain mutex. * * A plain mutex is similar to an @ref OFMutex, but does not use exceptions and * is just a lightweight wrapper around the system's mutex implementation. * * @param mutex A pointer to the mutex to create * @return 0 on success, or an error number from `` on error */ extern int OFPlainMutexNew(OFPlainMutex *mutex); /** * @brief Locks the specified mutex. * * @param mutex A pointer to the mutex to lock * @return 0 on success, or an error number from `` on error */ extern int OFPlainMutexLock(OFPlainMutex *mutex); /** * @brief Tries to lock the specified mutex without blocking. * * @param mutex A pointer to the mutex to try to lock * @return 0 on success, or an error number from `` on error */ extern int OFPlainMutexTryLock(OFPlainMutex *mutex); /** * @brief Unlocks the specified mutex. * * @param mutex A pointer to the mutex to unlock * @return 0 on success, or an error number from `` on error */ extern int OFPlainMutexUnlock(OFPlainMutex *mutex); /** * @brief Destroys the specified mutex * * @param mutex A pointer to the mutex to destruct * @return 0 on success, or an error number from `` on error */ extern int OFPlainMutexFree(OFPlainMutex *mutex); /** * @brief Creates a new plain recursive mutex. * * A plain recursive mutex is similar to an @ref OFRecursiveMutex, but does not * use exceptions and is just a lightweight wrapper around the system's * recursive mutex implementation (or lacking that, a simple implementation of * recursive mutexes via regular mutexes). * * @param rmutex A pointer to the recursive mutex to create * @return 0 on success, or an error number from `` on error */ extern int OFPlainRecursiveMutexNew(OFPlainRecursiveMutex *rmutex); /** * @brief Locks the specified recursive mutex. * * @param rmutex A pointer to the recursive mutex to lock * @return 0 on success, or an error number from `` on error */ extern int OFPlainRecursiveMutexLock(OFPlainRecursiveMutex *rmutex); /** * @brief Tries to lock the specified recursive mutex without blocking. * * @param rmutex A pointer to the recursive mutex to try to lock * @return 0 on success, or an error number from `` on error */ extern int OFPlainRecursiveMutexTryLock(OFPlainRecursiveMutex *rmutex); /** * @brief Unlocks the specified recursive mutex. * * @param rmutex A pointer to the recursive mutex to unlock * @return 0 on success, or an error number from `` on error */ extern int OFPlainRecursiveMutexUnlock(OFPlainRecursiveMutex *rmutex); /** * @brief Destroys the specified recursive mutex * * @param rmutex A pointer to the recursive mutex to destruct * @return 0 on success, or an error number from `` on error */ extern int OFPlainRecursiveMutexFree(OFPlainRecursiveMutex *rmutex); #ifdef __cplusplus } #endif /* Spinlocks are inlined for performance. */ /** * @brief Yield the current thread, indicating to the OS that another thread * should execute instead. */ static OF_INLINE void OFYieldThread(void) { #if defined(OF_HAVE_SCHED_YIELD) sched_yield(); #elif defined(OF_WINDOWS) Sleep(0); #endif } /** * @brief Creates a new spinlock. * * @param spinlock A pointer to the spinlock to create * @return 0 on success, or an error number from `` on error */ static OF_INLINE int OFSpinlockNew(OFSpinlock *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) *spinlock = 0; return 0; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) return pthread_spin_init(spinlock, 0); #else return OFPlainMutexNew(spinlock); #endif } /** * @brief Tries to lock a spinlock. * * @param spinlock A pointer to the spinlock to try to lock * @return 0 on success, or an error number from `` on error */ static OF_INLINE int OFSpinlockTryLock(OFSpinlock *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) if (OFAtomicIntCompareAndSwap(spinlock, 0, 1)) { OFAcquireMemoryBarrier(); return 0; } return EBUSY; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) return pthread_spin_trylock(spinlock); #else return OFPlainMutexTryLock(spinlock); #endif } /** * @brief Locks a spinlock. * * @param spinlock A pointer to the spinlock to lock * @return 0 on success, or an error number from `` on error */ static OF_INLINE int OFSpinlockLock(OFSpinlock *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) size_t i; for (i = 0; i < 10; i++) if (OFSpinlockTryLock(spinlock) == 0) return 0; while (OFSpinlockTryLock(spinlock) == EBUSY) OFYieldThread(); return 0; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) return pthread_spin_lock(spinlock); #else return OFPlainMutexLock(spinlock); #endif } /** * @brief Unlocks a spinlock. * * @param spinlock A pointer to the spinlock to unlock * @return 0 on success, or an error number from `` on error */ static OF_INLINE int OFSpinlockUnlock(OFSpinlock *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) bool ret = OFAtomicIntCompareAndSwap(spinlock, 1, 0); OFReleaseMemoryBarrier(); return (ret ? 0 : EINVAL); #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) return pthread_spin_unlock(spinlock); #else return OFPlainMutexUnlock(spinlock); #endif } /** * @brief Destroys a spinlock. * * @param spinlock A pointer to the spinlock to destroy * @return 0 on success, or an error number from `` on error */ static OF_INLINE int OFSpinlockFree(OFSpinlock *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) (void)spinlock; return 0; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) return pthread_spin_destroy(spinlock); #else return OFPlainMutexFree(spinlock); #endif } objfw-1.1.6/src/OFPlainMutex.m000066400000000000000000000017431465614216400161240ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" #if defined(OF_HAVE_PTHREADS) # include "platform/POSIX/OFPlainMutex.m" #elif defined(OF_WINDOWS) # include "platform/Windows/OFPlainMutex.m" #elif defined(OF_AMIGAOS) # include "platform/AmigaOS/OFPlainMutex.m" #endif objfw-1.1.6/src/OFPlainThread.h000066400000000000000000000076151465614216400162300ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "objfw-defs.h" #include "platform.h" #if !defined(OF_HAVE_THREADS) || \ (!defined(OF_HAVE_PTHREADS) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS)) # error No threads available! #endif #import "OFObject.h" /** @file */ #if defined(OF_HAVE_PTHREADS) # include typedef pthread_t OFPlainThread; #elif defined(OF_WINDOWS) # include typedef HANDLE OFPlainThread; #elif defined(OF_AMIGAOS) # include # include typedef struct { struct Task *task; void (*function)(id); id object; struct SignalSemaphore semaphore; struct Task *joinTask; unsigned char joinSigBit; bool detached, done; } *OFPlainThread; #endif typedef struct { float priority; size_t stackSize; } OFPlainThreadAttributes; #if defined(OF_HAVE_PTHREADS) || defined(DOXYGEN) /** * @brief Returns the current plain thread. * * @return The current plain thread */ static OF_INLINE OFPlainThread OFCurrentPlainThread(void) { return pthread_self(); } /** * @brief Returns whether the specified plain thread is the current thread. * * @param thread The thread to check * @return Whether the specified plain thread is the current thread */ static OF_INLINE bool OFPlainThreadIsCurrent(OFPlainThread thread) { return pthread_equal(thread, pthread_self()); } #elif defined(OF_WINDOWS) static OF_INLINE OFPlainThread OFCurrentPlainThread(void) { return GetCurrentThread(); } static OF_INLINE bool OFPlainThreadIsCurrent(OFPlainThread thread) { return (thread == GetCurrentThread()); } #elif defined(OF_AMIGAOS) extern OFPlainThread OFCurrentPlainThread(void); extern bool OFPlainThreadIsCurrent(OFPlainThread); #endif #ifdef __cplusplus extern "C" { #endif /** * @brief Initializes the specified thread attributes. * * @param attr A pointer to the thread attributes to initialize * @return 0 on success, or an error number from `` on error */ extern int OFPlainThreadAttributesInit(OFPlainThreadAttributes *attr); /** * @brief Creates a new plain thread. * * A plain thread is similar to @ref OFThread, but does not use exceptions and * is just a lightweight wrapper around the system's thread implementation. * * @param thread A pointer to the thread to create * @param name A name for the thread * @param function The function the thread should execute * @param object The object to pass to the thread as an argument * @param attr Thread attributes * @return 0 on success, or an error number from `` on error */ extern int OFPlainThreadNew(OFPlainThread *thread, const char *name, void (*function)(id), id object, const OFPlainThreadAttributes *attr); /** * @brief Sets the name of the current thread. * * @param name The name for the current thread */ extern void OFSetThreadName(const char *name); /** * @brief Joins the specified thread. * * @param thread The thread to join * @return 0 on success, or an error number from `` on error */ extern int OFPlainThreadJoin(OFPlainThread thread); /** * @brief Detaches the specified thread. * * @param thread The thread to detach * @return 0 on success, or an error number from `` on error */ extern int OFPlainThreadDetach(OFPlainThread thread); #ifdef __cplusplus } #endif objfw-1.1.6/src/OFPlainThread.m000066400000000000000000000017461465614216400162340ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" #if defined(OF_HAVE_PTHREADS) # include "platform/POSIX/OFPlainThread.m" #elif defined(OF_WINDOWS) # include "platform/Windows/OFPlainThread.m" #elif defined(OF_AMIGAOS) # include "platform/AmigaOS/OFPlainThread.m" #endif objfw-1.1.6/src/OFPlugin.h000066400000000000000000000047201465614216400152650ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" @class OFString; #ifndef OF_WINDOWS # include typedef void *OFPluginHandle; #else # include typedef HMODULE OFPluginHandle; #endif OF_ASSUME_NONNULL_BEGIN /** * @class OFPlugin OFPlugin.h ObjFW/OFPlugin.h * * @brief A class representing a loaded plugin (shared library). * */ OF_SUBCLASSING_RESTRICTED @interface OFPlugin: OFObject { OFPluginHandle _handle; } /** * @brief Returns the plugin path for a plugin with the specified name. * * E.g. on ELF systems, it appends .so, while on macOS and iOS, it creates the * appropriate plugin path. This can also be prefixed by a directory. * * @param name The name to return the plugin path for * @return The plugin path */ + (OFString *)pathForName: (OFString *)name; /** * @brief Creates a new OFPlugin by loading the plugin with the specified path. * * @param path The path to the plugin file. The suffix is appended * automatically. * @return An new, autoreleased OFPlugin * @throw OFLoadPluginFailedException The plugin could not be loaded */ + (instancetype)pluginWithPath: (OFString *)path; /** * @brief Initializes an already allocated OFPlugin by loading the plugin with * the specified path. * * @param path The path to the plugin file. The suffix is appended * automatically. * @return An initialized OFPlugin * @throw OFLoadPluginFailedException The plugin could not be loaded */ - (instancetype)initWithPath: (OFString *)path; /** * @brief Returns the address for the specified symbol, or `nil` if not found. * * @param symbol The symbol to return the address for * @return The address for the specified symbol, or `nil` if not found */ - (nullable void *)addressForSymbol: (OFString *)symbol; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFPlugin.m000066400000000000000000000052751465614216400153000ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #ifdef HAVE_DLFCN_H # include #endif #import "OFPlugin.h" #import "OFLocale.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFInitializationFailedException.h" #import "OFLoadPluginFailedException.h" #ifndef RTLD_LAZY # define RTLD_LAZY 0 #endif @implementation OFPlugin + (instancetype)pluginWithPath: (OFString *)path { return [[[self alloc] initWithPath: path] autorelease]; } + (OFString *)pathForName: (OFString *)name { #if defined(OF_MACOS) return [name stringByAppendingFormat: @".bundle/Contents/MacOS/%@", name.lastPathComponent]; #elif defined(OF_IOS) return [name stringByAppendingFormat: @".bundle/%@", name.lastPathComponent]; #else return [name stringByAppendingString: @PLUGIN_SUFFIX]; #endif } - (instancetype)initWithPath: (OFString *)path { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); #ifndef OF_WINDOWS _handle = dlopen( [path cStringWithEncoding: [OFLocale encoding]], RTLD_LAZY); #else if ([OFSystemInfo isWindowsNT]) _handle = LoadLibraryW(path.UTF16String); else _handle = LoadLibraryA( [path cStringWithEncoding: [OFLocale encoding]]); #endif if (_handle == NULL) { #ifndef OF_WINDOWS OFString *error = [OFString stringWithCString: dlerror() encoding: [OFLocale encoding]]; #else OFString *error = nil; #endif @throw [OFLoadPluginFailedException exceptionWithPath: path error: error]; } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void *)addressForSymbol: (OFString *)symbol { #ifndef OF_WINDOWS return dlsym(_handle, [symbol cStringWithEncoding: [OFLocale encoding]]); #else return (void *)(uintptr_t)GetProcAddress(_handle, [symbol cStringWithEncoding: [OFLocale encoding]]); #endif } - (void)dealloc { #ifndef OF_WINDOWS dlclose(_handle); #else FreeLibrary(_handle); #endif [super dealloc]; } @end objfw-1.1.6/src/OFPollKernelEventObserver.h000066400000000000000000000017241465614216400206110ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFKernelEventObserver.h" OF_ASSUME_NONNULL_BEGIN @class OFMutableData; @interface OFPollKernelEventObserver: OFKernelEventObserver { OFMutableData *_FDs; int _maxFD; id __unsafe_unretained *_FDToObject; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFPollKernelEventObserver.m000066400000000000000000000120621465614216400206130ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #ifdef HAVE_POLL_H # include #endif #import "OFPollKernelEventObserver.h" #import "OFData.h" #import "OFSocket+Private.h" #import "OFObserveKernelEventsFailedException.h" #import "OFOutOfRangeException.h" #ifdef OF_WII # define pollfd pollsd # define fd socket #endif @implementation OFPollKernelEventObserver - (instancetype)init { self = [super init]; @try { struct pollfd p = { _cancelFD[0], POLLIN, 0 }; _FDs = [[OFMutableData alloc] initWithItemSize: sizeof(struct pollfd)]; [_FDs addItem: &p]; _maxFD = _cancelFD[0]; _FDToObject = OFAllocMemory((size_t)_maxFD + 1, sizeof(id)); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_FDs release]; OFFreeMemory(_FDToObject); [super dealloc]; } static void addObject(OFPollKernelEventObserver *self, id object, int fd, short events) { struct pollfd *FDs; size_t count; bool found; if (fd < 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: EBADF]; FDs = self->_FDs.mutableItems; count = self->_FDs.count; found = false; for (size_t i = 0; i < count; i++) { if (FDs[i].fd == fd) { FDs[i].events |= events; found = true; break; } } if (!found) { struct pollfd p = { fd, events, 0 }; if (fd > self->_maxFD) { self->_maxFD = fd; self->_FDToObject = OFResizeMemory(self->_FDToObject, (size_t)self->_maxFD + 1, sizeof(id)); } self->_FDToObject[fd] = object; [self->_FDs addItem: &p]; } } static void removeObject(OFPollKernelEventObserver *self, id object, int fd, short events) { struct pollfd *FDs; size_t nFDs; if (fd < 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: EBADF]; FDs = self->_FDs.mutableItems; nFDs = self->_FDs.count; for (size_t i = 0; i < nFDs; i++) { if (FDs[i].fd == fd) { FDs[i].events &= ~events; if (FDs[i].events == 0) { /* * TODO: Remove from and resize _FDToObject, * adjust _maxFD. */ [self->_FDs removeItemAtIndex: i]; } break; } } } - (void)addObjectForReading: (id )object { addObject(self, object, object.fileDescriptorForReading, POLLIN); [super addObjectForReading: object]; } - (void)addObjectForWriting: (id )object { addObject(self, object, object.fileDescriptorForWriting, POLLOUT); [super addObjectForWriting: object]; } - (void)removeObjectForReading: (id )object { removeObject(self, object, object.fileDescriptorForReading, POLLIN); [super removeObjectForReading: object]; } - (void)removeObjectForWriting: (id )object { removeObject(self, object, object.fileDescriptorForWriting, POLLOUT); [super removeObjectForWriting: object]; } - (void)observeForTimeInterval: (OFTimeInterval)timeInterval { void *pool; struct pollfd *FDs; int events; size_t nFDs; if ([self of_processReadBuffers]) return; pool = objc_autoreleasePoolPush(); FDs = [[[_FDs mutableCopy] autorelease] mutableItems]; nFDs = _FDs.count; #ifdef OPEN_MAX if (nFDs > OPEN_MAX) @throw [OFOutOfRangeException exception]; #endif events = poll(FDs, (nfds_t)nFDs, (int)(timeInterval != -1 ? timeInterval * 1000 : -1)); if (events < 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: errno]; for (size_t i = 0; i < nFDs; i++) { OFAssert(FDs[i].fd <= _maxFD); if (FDs[i].revents & POLLIN) { void *pool2; if (FDs[i].fd == _cancelFD[0]) { char buffer; #ifdef OF_HAVE_PIPE OFEnsure(read(_cancelFD[0], &buffer, 1) == 1); #else OFEnsure(recvfrom(_cancelFD[0], &buffer, 1, 0, NULL, NULL) == 1); #endif FDs[i].revents = 0; continue; } pool2 = objc_autoreleasePoolPush(); if ([_delegate respondsToSelector: @selector(objectIsReadyForReading:)]) [_delegate objectIsReadyForReading: _FDToObject[FDs[i].fd]]; objc_autoreleasePoolPop(pool2); } if (FDs[i].revents & (POLLOUT | POLLHUP)) { void *pool2 = objc_autoreleasePoolPush(); if ([_delegate respondsToSelector: @selector(objectIsReadyForWriting:)]) [_delegate objectIsReadyForWriting: _FDToObject[FDs[i].fd]]; objc_autoreleasePoolPop(pool2); } FDs[i].revents = 0; } objc_autoreleasePoolPop(pool); } @end objfw-1.1.6/src/OFRIPEMD160Hash.h000066400000000000000000000024361465614216400160440ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFCryptographicHash.h" OF_ASSUME_NONNULL_BEGIN @class OFSecureData; /** * @class OFRIPEMD160Hash OFRIPEMD160Hash.h ObjFW/OFRIPEMD160Hash.h * * @brief A class which provides methods to create a RIPEMD-160 hash. */ OF_SUBCLASSING_RESTRICTED @interface OFRIPEMD160Hash: OFObject { OFSecureData *_iVarsData; struct { uint32_t state[5]; uint64_t bits; union { unsigned char bytes[64]; uint32_t words[16]; } buffer; size_t bufferLength; } *_iVars; bool _allowsSwappableMemory; bool _calculated; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFRIPEMD160Hash.m000066400000000000000000000167221465614216400160540ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFRIPEMD160Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFHashNotCalculatedException.h" #import "OFOutOfRangeException.h" static const size_t digestSize = 20; static const size_t blockSize = 64; OF_DIRECT_MEMBERS @interface OFRIPEMD160Hash () - (void)of_resetState; @end #define F(a, b, c) ((a) ^ (b) ^ (c)) #define G(a, b, c) (((a) & (b)) | (~(a) & (c))) #define H(a, b, c) (((a) | ~(b)) ^ (c)) #define I(a, b, c) (((a) & (c)) | ((b) & ~(c))) #define J(a, b, c) ((a) ^ ((b) | ~(c))) static const uint8_t wordOrder[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13 }; static const uint8_t wordOrder2[] = { 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11 }; static const uint8_t rotateBits[] = { 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 }; static const uint8_t rotateBits2[] = { 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 }; static OF_INLINE void byteSwapVectorIfBE(uint32_t *vector, uint_fast8_t length) { #ifdef OF_BIG_ENDIAN for (uint_fast8_t i = 0; i < length; i++) vector[i] = OFByteSwap32(vector[i]); #endif } static void processBlock(uint32_t *state, uint32_t *buffer) { uint32_t new[5], new2[5]; uint_fast8_t i = 0; new[0] = new2[0] = state[0]; new[1] = new2[1] = state[1]; new[2] = new2[2] = state[2]; new[3] = new2[3] = state[3]; new[4] = new2[4] = state[4]; byteSwapVectorIfBE(buffer, 16); #define LOOP_BODY(f, g, k, k2) \ { \ uint32_t tmp; \ \ tmp = new[0] + f(new[1], new[2], new[3]) + \ buffer[wordOrder[i]] + k; \ tmp = OFRotateLeft(tmp, rotateBits[i]) + new[4]; \ \ new[0] = new[4]; \ new[4] = new[3]; \ new[3] = OFRotateLeft(new[2], 10); \ new[2] = new[1]; \ new[1] = tmp; \ \ tmp = new2[0] + g(new2[1], new2[2], new2[3]) + \ buffer[wordOrder2[i]] + k2; \ tmp = OFRotateLeft(tmp, rotateBits2[i]) + new2[4]; \ \ new2[0] = new2[4]; \ new2[4] = new2[3]; \ new2[3] = OFRotateLeft(new2[2], 10); \ new2[2] = new2[1]; \ new2[1] = tmp; \ } for (; i < 16; i++) LOOP_BODY(F, J, 0x00000000, 0x50A28BE6) for (; i < 32; i++) LOOP_BODY(G, I, 0x5A827999, 0x5C4DD124) for (; i < 48; i++) LOOP_BODY(H, H, 0x6ED9EBA1, 0x6D703EF3) for (; i < 64; i++) LOOP_BODY(I, G, 0x8F1BBCDC, 0x7A6D76E9) for (; i < 80; i++) LOOP_BODY(J, F, 0xA953FD4E, 0x00000000) #undef LOOP_BODY new2[3] += state[1] + new[2]; state[1] = state[2] + new[3] + new2[4]; state[2] = state[3] + new[4] + new2[0]; state[3] = state[4] + new[0] + new2[1]; state[4] = state[0] + new[1] + new2[2]; state[0] = new2[3]; } @implementation OFRIPEMD160Hash @synthesize calculated = _calculated; @synthesize allowsSwappableMemory = _allowsSwappableMemory; + (size_t)digestSize { return digestSize; } + (size_t)blockSize { return blockSize; } + (instancetype)hashWithAllowsSwappableMemory: (bool)allowsSwappableMemory { return [[[self alloc] initWithAllowsSwappableMemory: allowsSwappableMemory] autorelease]; } - (instancetype)initWithAllowsSwappableMemory: (bool)allowsSwappableMemory { self = [super init]; @try { _iVarsData = [[OFSecureData alloc] initWithCount: sizeof(*_iVars) allowsSwappableMemory: allowsSwappableMemory]; _iVars = _iVarsData.mutableItems; _allowsSwappableMemory = allowsSwappableMemory; [self of_resetState]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)of_init { return [super init]; } - (void)dealloc { [_iVarsData release]; [super dealloc]; } - (size_t)digestSize { return digestSize; } - (size_t)blockSize { return blockSize; } - (id)copy { OFRIPEMD160Hash *copy = [[OFRIPEMD160Hash alloc] of_init]; copy->_iVarsData = [_iVarsData copy]; copy->_iVars = copy->_iVarsData.mutableItems; copy->_allowsSwappableMemory = _allowsSwappableMemory; copy->_calculated = _calculated; return copy; } - (void)of_resetState { _iVars->state[0] = 0x67452301; _iVars->state[1] = 0xEFCDAB89; _iVars->state[2] = 0x98BADCFE; _iVars->state[3] = 0x10325476; _iVars->state[4] = 0xC3D2E1F0; } - (void)updateWithBuffer: (const void *)buffer_ length: (size_t)length { const unsigned char *buffer = buffer_; if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; if (length > SIZE_MAX / 8) @throw [OFOutOfRangeException exception]; _iVars->bits += (length * 8); while (length > 0) { size_t min = 64 - _iVars->bufferLength; if (min > length) min = length; memcpy(_iVars->buffer.bytes + _iVars->bufferLength, buffer, min); _iVars->bufferLength += min; buffer += min; length -= min; if (_iVars->bufferLength == 64) { processBlock(_iVars->state, _iVars->buffer.words); _iVars->bufferLength = 0; } } } - (const unsigned char *)digest { if (!_calculated) @throw [OFHashNotCalculatedException exceptionWithObject: self]; return (const unsigned char *)_iVars->state; } - (void)calculate { if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; _iVars->buffer.bytes[_iVars->bufferLength] = 0x80; OFZeroMemory(_iVars->buffer.bytes + _iVars->bufferLength + 1, 64 - _iVars->bufferLength - 1); if (_iVars->bufferLength >= 56) { processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(_iVars->buffer.bytes, 64); } _iVars->buffer.words[14] = OFToLittleEndian32((uint32_t)(_iVars->bits & 0xFFFFFFFF)); _iVars->buffer.words[15] = OFToLittleEndian32((uint32_t)(_iVars->bits >> 32)); processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); byteSwapVectorIfBE(_iVars->state, 5); _calculated = true; } - (void)reset { [self of_resetState]; _iVars->bits = 0; OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); _iVars->bufferLength = 0; _calculated = false; } @end objfw-1.1.6/src/OFRPDNSResourceRecord.h000066400000000000000000000044621465614216400175670ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFDNSResourceRecord.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFRPDNSResourceRecord \ * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h * * @brief A class representing an RP DNS resource record. */ OF_SUBCLASSING_RESTRICTED @interface OFRPDNSResourceRecord: OFDNSResourceRecord { OFString *_mailbox, *_TXTDomainName; } /** * @brief The mailbox of the responsible person of the resource record. */ @property (readonly, nonatomic) OFString *mailbox; /** * @brief A domain name that contains a TXT resource record for the responsible * person of the resource record. */ @property (readonly, nonatomic) OFString *TXTDomainName; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFRPDNSResourceRecord with the * specified name, class, alias and time to live. * * @param name The name for the resource record * @param DNSClass The class code for the resource record * @param mailbox The mailbox of the responsible person of the resource record * @param TXTDomainName A domain name that contains a TXT resource record for * the responsible person of the resource record * @param TTL The time to live for the resource record * @return An initialized OFRPDNSResourceRecord */ - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass mailbox: (OFString *)mailbox TXTDomainName: (OFString *)TXTDomainName TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFRPDNSResourceRecord.m000066400000000000000000000055751465614216400176020ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFRPDNSResourceRecord.h" @implementation OFRPDNSResourceRecord @synthesize mailbox = _mailbox, TXTDomainName = _TXTDomainName; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass mailbox: (OFString *)mailbox TXTDomainName: (OFString *)TXTDomainName TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: DNSClass recordType: OFDNSRecordTypeRP TTL: TTL]; @try { _mailbox = [mailbox copy]; _TXTDomainName = [TXTDomainName copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_mailbox release]; [_TXTDomainName release]; [super dealloc]; } - (bool)isEqual: (id)object { OFRPDNSResourceRecord *record; if (object == self) return true; if (![object isKindOfClass: [OFRPDNSResourceRecord class]]) return false; record = object; if (record->_name != _name && ![record->_name isEqual: _name]) return false; if (record->_DNSClass != _DNSClass) return false; if (record->_recordType != _recordType) return false; if (record->_mailbox != _mailbox && ![record->_mailbox isEqual: _mailbox]) return false; if (record->_TXTDomainName != _TXTDomainName && ![record->_TXTDomainName isEqual: _TXTDomainName]) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddByte(&hash, _DNSClass >> 8); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType >> 8); OFHashAddByte(&hash, _recordType); OFHashAddHash(&hash, _mailbox.hash); OFHashAddHash(&hash, _TXTDomainName.hash); OFHashFinalize(&hash); return hash; } - (OFString *)description { return [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tClass = %@\n" @"\tMailbox = %@\n" @"\tTXT Domain Name = %@\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFDNSClassName(_DNSClass), _mailbox, _TXTDomainName, _TTL]; } @end objfw-1.1.6/src/OFRangeCharacterSet.h000066400000000000000000000015611465614216400173540ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFCharacterSet.h" OF_ASSUME_NONNULL_BEGIN @interface OFRangeCharacterSet: OFCharacterSet { OFRange _range; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFRangeCharacterSet.m000066400000000000000000000024721465614216400173630ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFRangeCharacterSet.h" #import "OFString.h" #import "OFOutOfRangeException.h" @implementation OFRangeCharacterSet - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithRange: (OFRange)range { self = [super init]; @try { if (SIZE_MAX - range.location < range.length) @throw [OFOutOfRangeException exception]; _range = range; } @catch (id e) { [self release]; @throw e; } return self; } - (bool)characterIsMember: (OFUnichar)character { return (character >= _range.location && character < _range.location + _range.length); } @end objfw-1.1.6/src/OFRecursiveMutex.h000066400000000000000000000031111465614216400170120ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFLocking.h" #import "OFPlainMutex.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFRecursiveMutex OFRecursiveMutex.h ObjFW/OFRecursiveMutex.h * * @brief A class for creating mutual exclusions which can be entered * recursively. * * If the mutex is deallocated while being held, it throws an * @ref OFStillLockedException. While this might break ARC's assumption that no * object ever throws in dealloc, it is considered a fatal programmer error * that should terminate the application. */ OF_SUBCLASSING_RESTRICTED @interface OFRecursiveMutex: OFObject { OFPlainRecursiveMutex _rmutex; bool _initialized; OFString *_Nullable _name; OF_RESERVE_IVARS(OFRecursiveMutex, 4) } /** * @brief Creates a new recursive mutex. * * @return A new autoreleased recursive mutex. */ + (instancetype)mutex; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFRecursiveMutex.m000066400000000000000000000044371465614216400170330ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFRecursiveMutex.h" #import "OFString.h" #import "OFInitializationFailedException.h" #import "OFLockFailedException.h" #import "OFStillLockedException.h" #import "OFUnlockFailedException.h" @implementation OFRecursiveMutex @synthesize name = _name; + (instancetype)mutex { return [[[self alloc] init] autorelease]; } - (instancetype)init { self = [super init]; if (OFPlainRecursiveMutexNew(&_rmutex) != 0) { Class c = self.class; [self release]; @throw [OFInitializationFailedException exceptionWithClass: c]; } _initialized = true; return self; } - (void)dealloc { if (_initialized) { int error = OFPlainRecursiveMutexFree(&_rmutex); if (error != 0) { OFEnsure(error == EBUSY); @throw [OFStillLockedException exceptionWithLock: self]; } } [_name release]; [super dealloc]; } - (void)lock { int error = OFPlainRecursiveMutexLock(&_rmutex); if (error != 0) @throw [OFLockFailedException exceptionWithLock: self errNo: error]; } - (bool)tryLock { int error = OFPlainRecursiveMutexTryLock(&_rmutex); if (error != 0) { if (error == EBUSY) return false; else @throw [OFLockFailedException exceptionWithLock: self errNo: error]; } return true; } - (void)unlock { int error = OFPlainRecursiveMutexUnlock(&_rmutex); if (error != 0) @throw [OFUnlockFailedException exceptionWithLock: self errNo: error]; } - (OFString *)description { if (_name == nil) return super.description; return [OFString stringWithFormat: @"<%@: %@>", self.className, _name]; } @end objfw-1.1.6/src/OFRunLoop+Private.h000066400000000000000000000112001465614216400170220ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFRunLoop.h" #import "OFStream.h" #ifdef OF_HAVE_SOCKETS # import "OFDatagramSocket.h" # import "OFSequencedPacketSocket.h" # import "OFStreamSocket.h" #endif OF_ASSUME_NONNULL_BEGIN #ifdef OF_HAVE_SOCKETS @protocol OFRunLoopConnectDelegate - (void)of_socketDidConnect: (id)socket exception: (nullable id)exception; - (id)of_connectionFailedExceptionForErrNo: (int)errNo; @end #endif OF_DIRECT_MEMBERS @interface OFRunLoop () + (void)of_setMainRunLoop: (OFRunLoop *)runLoop; #ifdef OF_HAVE_SOCKETS + (void)of_addAsyncReadForStream: (OFStream *) stream buffer: (void *)buffer length: (size_t)length mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (nullable OFStreamAsyncReadBlock)block # endif delegate: (nullable id )delegate; + (void)of_addAsyncReadForStream: (OFStream *) stream buffer: (void *)buffer exactLength: (size_t)length mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (nullable OFStreamAsyncReadBlock)block # endif delegate: (nullable id )delegate; + (void)of_addAsyncReadLineForStream: (OFStream *) stream encoding: (OFStringEncoding)encoding mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (nullable OFStreamAsyncReadLineBlock)block # endif delegate: (nullable id )delegate; + (void)of_addAsyncWriteForStream: (OFStream *) stream data: (OFData *)data mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (nullable OFStreamAsyncWriteDataBlock)block # endif delegate: (nullable id )delegate; + (void)of_addAsyncWriteForStream: (OFStream *) stream string: (OFString *)string encoding: (OFStringEncoding)encoding mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (nullable OFStreamAsyncWriteStringBlock)block # endif delegate: (nullable id )delegate; # if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) + (void)of_addAsyncConnectForSocket: (id)socket mode: (OFRunLoopMode)mode delegate: (id )delegate; # endif + (void)of_addAsyncAcceptForSocket: (id)socket mode: (OFRunLoopMode)mode block: (nullable id)block delegate: (nullable id)delegate; + (void)of_addAsyncReceiveForDatagramSocket: (OFDatagramSocket *)socket buffer: (void *)buffer length: (size_t)length mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (nullable OFDatagramSocketAsyncReceiveBlock)block # endif delegate: (nullable id ) delegate; + (void)of_addAsyncSendForDatagramSocket: (OFDatagramSocket *)socket data: (OFData *)data receiver: (const OFSocketAddress *)receiver mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (nullable OFDatagramSocketAsyncSendDataBlock)block # endif delegate: (nullable id )delegate; + (void)of_addAsyncReceiveForSequencedPacketSocket: (OFSequencedPacketSocket *)socket buffer: (void *)buffer length: (size_t)length mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (nullable OFSequencedPacketSocketAsyncReceiveBlock)block # endif delegate: (nullable id ) delegate; + (void)of_addAsyncSendForSequencedPacketSocket: (OFSequencedPacketSocket *)socket data: (OFData *)data mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (nullable OFSequencedPacketSocketAsyncSendDataBlock)block # endif delegate: (nullable id )delegate; + (void)of_cancelAsyncRequestsForObject: (id)object mode: (OFRunLoopMode)mode; #endif - (void)of_removeTimer: (OFTimer *)timer forMode: (OFRunLoopMode)mode; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFRunLoop.h000066400000000000000000000127341465614216400154310ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFString.h" #ifdef OF_AMIGAOS # include #endif OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFSortedList OF_GENERIC(ObjectType); #ifdef OF_HAVE_THREADS @class OFMutex; @class OFCondition; #endif #ifdef OF_HAVE_SOCKETS @class OFKernelEventObserver; #endif @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); @class OFTimer; @class OFDate; /** * @brief A mode for an OFRunLoop. */ typedef OFConstantString *OFRunLoopMode; #ifdef __cplusplus extern "C" { #endif /** * @brief The default mode for an OFRunLoop. */ extern const OFRunLoopMode OFDefaultRunLoopMode; #ifdef __cplusplus } #endif /** * @class OFRunLoop OFRunLoop.h ObjFW/OFRunLoop.h * * @brief A class providing a run loop for the application and its processes. */ OF_SUBCLASSING_RESTRICTED @interface OFRunLoop: OFObject { OFMutableDictionary *_states; #ifdef OF_HAVE_THREADS OFMutex *_statesMutex; #endif OFRunLoopMode _Nullable _currentMode; volatile bool _stop; } #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nullable, nonatomic) OFRunLoop *mainRunLoop; @property (class, readonly, nullable, nonatomic) OFRunLoop *currentRunLoop; #endif @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFRunLoopMode currentMode; /** * @brief Returns the run loop for the main thread. * * @return The run loop for the main thread */ + (nullable OFRunLoop *)mainRunLoop; /** * @brief Returns the run loop for the current thread. * * @return The run loop for the current thread */ + (nullable OFRunLoop *)currentRunLoop; /** * @brief Adds an OFTimer to the run loop. * * @param timer The timer to add */ - (void)addTimer: (OFTimer *)timer; /** * @brief Adds an OFTimer to the run loop for the specified mode. * * @param timer The timer to add * @param mode The run loop mode in which to run the timer */ - (void)addTimer: (OFTimer *)timer forMode: (OFRunLoopMode)mode; #if defined(OF_AMIGAOS) || defined(DOXYGEN) /** * @brief Adds an Exec Signal to the run loop. * * If a signal is added multiple times, the specified methods will be performed * in the order added. * * @note This is only available on AmigaOS! * * @param signal The signal to add * @param target The target to call when the signal was received * @param selector The selector to call on the target when the signal was * received. The selector must have one parameter for the ULONG * of the signal that was received. */ - (void)addExecSignal: (ULONG)signal target: (id)target selector: (SEL)selector; /** * @brief Adds an Exec Signal to the run loop for the specified mode. * * If a signal is added multiple times, the specified methods will be performed * in the order added. * * @note This is only available on AmigaOS! * * @param signal The signal to add * @param mode The run loop mode in which to handle the signal * @param target The target to call when the signal was received * @param selector The selector to call on the target when the signal was * received. The selector must have one parameter for the ULONG * of the signal that was received. */ - (void)addExecSignal: (ULONG)signal forMode: (OFRunLoopMode)mode target: (id)target selector: (SEL)selector; /** * @brief Removes the specified Exec Signal with the specified target and * selector. * * @param signal The signal to remove * @param target The target which was specified when adding the signal * @param selector The selector which was specified when adding the signal */ - (void)removeExecSignal: (ULONG)signal target: (id)target selector: (SEL)selector; /** * @brief Removes the specified Exec Signal from the specified mode with the * specified target and selector. * * @param signal The signal to remove * @param mode The run loop mode to which the signal was added * @param target The target which was specified when adding the signal * @param selector The selector which was specified when adding the signal */ - (void)removeExecSignal: (ULONG)signal forMode: (OFRunLoopMode)mode target: (id)target selector: (SEL)selector; #endif /** * @brief Starts the run loop. */ - (void)run; /** * @brief Run the run loop until the specified deadline. * * @param deadline The date until which the run loop should run */ - (void)runUntilDate: (nullable OFDate *)deadline; /** * @brief Run the run loop until an event or timer occurs or the specified * deadline is reached. * * @param mode The mode in which to run the run loop * @param deadline The date until which the run loop should run at the longest */ - (void)runMode: (OFRunLoopMode)mode beforeDate: (nullable OFDate *)deadline; /** * @brief Stops the run loop. If there is still an operation being executed, it * is finished before the run loop stops. */ - (void)stop; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFRunLoop.m000066400000000000000000001105331465614216400154320ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #import "OFArray.h" #import "OFData.h" #import "OFDictionary.h" #ifdef OF_HAVE_SOCKETS # import "OFKernelEventObserver.h" # import "OFDatagramSocket.h" # import "OFSequencedPacketSocket.h" # import "OFSequencedPacketSocket+Private.h" # import "OFStreamSocket.h" # import "OFStreamSocket+Private.h" #endif #import "OFThread.h" #ifdef OF_HAVE_THREADS # import "OFMutex.h" # import "OFCondition.h" #endif #import "OFSortedList.h" #import "OFTimer.h" #import "OFTimer+Private.h" #import "OFDate.h" #import "OFObserveKernelEventsFailedException.h" #import "OFWriteFailedException.h" #include "OFRunLoopConstants.inc" static OFRunLoop *mainRunLoop = nil; @interface OFRunLoopState: OFObject #ifdef OF_HAVE_SOCKETS #endif { @public OFSortedList OF_GENERIC(OFTimer *) *_timersQueue; #ifdef OF_HAVE_THREADS OFMutex *_timersQueueMutex; #endif #if defined(OF_HAVE_SOCKETS) OFKernelEventObserver *_kernelEventObserver; OFMutableDictionary *_readQueues, *_writeQueues; #elif defined(OF_HAVE_THREADS) OFCondition *_condition; # ifdef OF_AMIGAOS ULONG _execSignalMask; # endif #endif #ifdef OF_AMIGAOS OFMutableData *_execSignals; OFMutableArray *_execSignalsTargets; OFMutableData *_execSignalsSelectors; # ifdef OF_HAVE_THREADS OFMutex *_execSignalsMutex; # endif #endif } @end #ifdef OF_HAVE_SOCKETS @interface OFRunLoopQueueItem: OFObject { @public id _delegate; } - (bool)handleObject: (id)object; @end @interface OFRunLoopReadQueueItem: OFRunLoopQueueItem { @public # ifdef OF_HAVE_BLOCKS OFStreamAsyncReadBlock _block; # endif void *_buffer; size_t _length; } @end @interface OFRunLoopExactReadQueueItem: OFRunLoopQueueItem { @public # ifdef OF_HAVE_BLOCKS OFStreamAsyncReadBlock _block; # endif void *_buffer; size_t _exactLength, _readLength; } @end @interface OFRunLoopReadLineQueueItem: OFRunLoopQueueItem { @public # ifdef OF_HAVE_BLOCKS OFStreamAsyncReadLineBlock _block; # endif OFStringEncoding _encoding; } @end @interface OFRunLoopWriteDataQueueItem: OFRunLoopQueueItem { @public # ifdef OF_HAVE_BLOCKS OFStreamAsyncWriteDataBlock _block; # endif OFData *_data; size_t _writtenLength; } @end @interface OFRunLoopWriteStringQueueItem: OFRunLoopQueueItem { @public # ifdef OF_HAVE_BLOCKS OFStreamAsyncWriteStringBlock _block; # endif OFString *_string; OFStringEncoding _encoding; size_t _writtenLength; } @end # if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) @interface OFRunLoopConnectQueueItem: OFRunLoopQueueItem @end # endif @interface OFRunLoopAcceptQueueItem: OFRunLoopQueueItem { @public # ifdef OF_HAVE_BLOCKS id _block; # endif } @end @interface OFRunLoopDatagramReceiveQueueItem: OFRunLoopQueueItem { @public # ifdef OF_HAVE_BLOCKS OFDatagramSocketAsyncReceiveBlock _block; # endif void *_buffer; size_t _length; } @end @interface OFRunLoopDatagramSendQueueItem: OFRunLoopQueueItem { @public # ifdef OF_HAVE_BLOCKS OFDatagramSocketAsyncSendDataBlock _block; # endif OFData *_data; OFSocketAddress _receiver; } @end @interface OFRunLoopPacketReceiveQueueItem: OFRunLoopQueueItem { @public # ifdef OF_HAVE_BLOCKS OFSequencedPacketSocketAsyncReceiveBlock _block; # endif void *_buffer; size_t _length; } @end @interface OFRunLoopPacketSendQueueItem: OFRunLoopQueueItem { @public # ifdef OF_HAVE_BLOCKS OFSequencedPacketSocketAsyncSendDataBlock _block; # endif OFData *_data; } @end #endif @implementation OFRunLoopState - (instancetype)init { self = [super init]; @try { _timersQueue = [[OFSortedList alloc] init]; #ifdef OF_HAVE_THREADS _timersQueueMutex = [[OFMutex alloc] init]; #endif #if defined(OF_HAVE_SOCKETS) _kernelEventObserver = [[OFKernelEventObserver alloc] init]; _kernelEventObserver.delegate = self; _readQueues = [[OFMutableDictionary alloc] init]; _writeQueues = [[OFMutableDictionary alloc] init]; #elif defined(OF_HAVE_THREADS) _condition = [[OFCondition alloc] init]; #endif #ifdef OF_AMIGAOS _execSignals = [[OFMutableData alloc] initWithItemSize: sizeof(ULONG)]; _execSignalsTargets = [[OFMutableArray alloc] init]; _execSignalsSelectors = [[OFMutableData alloc] initWithItemSize: sizeof(SEL)]; # ifdef OF_HAVE_THREADS _execSignalsMutex = [[OFMutex alloc] init]; # endif #endif } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_timersQueue release]; #ifdef OF_HAVE_THREADS [_timersQueueMutex release]; #endif #if defined(OF_HAVE_SOCKETS) [_kernelEventObserver release]; [_readQueues release]; [_writeQueues release]; #elif defined(OF_HAVE_THREADS) [_condition release]; #endif #ifdef OF_AMIGAOS [_execSignals release]; [_execSignalsTargets release]; [_execSignalsSelectors release]; # ifdef OF_HAVE_THREADS [_execSignalsMutex release]; # endif #endif [super dealloc]; } #ifdef OF_HAVE_SOCKETS - (void)objectIsReadyForReading: (id)object { /* * Retain the queue so that it doesn't disappear from us because the * handler called -[cancelAsyncRequests]. */ OFList OF_GENERIC(OF_KINDOF(OFRunLoopReadQueueItem *)) *queue = [[_readQueues objectForKey: object] retain]; OFAssert(queue != nil); @try { if (![queue.firstObject handleObject: object]) { OFListItem listItem = queue.firstListItem; /* * The handler might have called -[cancelAsyncRequests] * so that our queue is now empty, in which case we * should do nothing. */ if (listItem != NULL) { /* * Make sure we keep the target until after we * are done removing the object. The reason for * this is that the target might call * -[cancelAsyncRequests] in its dealloc. */ [[OFListItemObject(listItem) retain] autorelease]; [queue removeListItem: listItem]; if (queue.count == 0) { [_kernelEventObserver removeObjectForReading: object]; [_readQueues removeObjectForKey: object]; } } } } @finally { [queue release]; } } - (void)objectIsReadyForWriting: (id)object { /* * Retain the queue so that it doesn't disappear from us because the * handler called -[cancelAsyncRequests]. */ OFList *queue = [[_writeQueues objectForKey: object] retain]; OFAssert(queue != nil); @try { if (![queue.firstObject handleObject: object]) { OFListItem listItem = queue.firstListItem; /* * The handler might have called -[cancelAsyncRequests] * so that our queue is now empty, in which case we * should do nothing. */ if (listItem != NULL) { /* * Make sure we keep the target until after we * are done removing the object. The reason for * this is that the target might call * -[cancelAsyncRequests] in its dealloc. */ [[OFListItemObject(listItem) retain] autorelease]; [queue removeListItem: listItem]; if (queue.count == 0) { [_kernelEventObserver removeObjectForWriting: object]; [_writeQueues removeObjectForKey: object]; } } } } @finally { [queue release]; } } #endif #ifdef OF_AMIGAOS - (void)execSignalWasReceived: (ULONG)signalMask { void *pool = objc_autoreleasePoolPush(); OFData *signals; OFArray *targets; OFData *selectors; const ULONG *signalsItems; const id *targetsObjects; const SEL *selectorsItems; size_t count; # ifdef OF_HAVE_THREADS [_execSignalsMutex lock]; @try { # endif /* * Create copies, so that signal handlers are allowed to modify * signals. */ signals = [[_execSignals copy] autorelease]; targets = [[_execSignalsTargets copy] autorelease]; selectors = [[_execSignalsSelectors copy] autorelease]; # ifdef OF_HAVE_THREADS } @finally { [_execSignalsMutex unlock]; } # endif signalsItems = signals.items; targetsObjects = targets.objects; selectorsItems = selectors.items; count = signals.count; for (size_t i = 0; i < count; i++) { if (signalMask & (1ul << signalsItems[i])) { void (*callback)(id, SEL, ULONG) = (void (*)(id, SEL, ULONG))[targetsObjects[i] methodForSelector: selectorsItems[i]]; callback(targetsObjects[i], selectorsItems[i], signalsItems[i]); } } objc_autoreleasePoolPop(pool); } #endif @end #ifdef OF_HAVE_SOCKETS @implementation OFRunLoopQueueItem - (bool)handleObject: (id)object { OF_UNRECOGNIZED_SELECTOR } - (void)dealloc { [_delegate release]; [super dealloc]; } @end @implementation OFRunLoopReadQueueItem - (bool)handleObject: (id)object { size_t length; id exception = nil; @try { length = [object readIntoBuffer: _buffer length: _length]; } @catch (id e) { length = 0; exception = e; } # ifdef OF_HAVE_BLOCKS if (_block != NULL) return _block(length, exception); else { # endif if (![_delegate respondsToSelector: @selector(stream:didReadIntoBuffer:length:exception:)]) return false; return [_delegate stream: object didReadIntoBuffer: _buffer length: length exception: exception]; # ifdef OF_HAVE_BLOCKS } # endif } # ifdef OF_HAVE_BLOCKS - (void)dealloc { [_block release]; [super dealloc]; } # endif @end @implementation OFRunLoopExactReadQueueItem - (bool)handleObject: (id)object { size_t length; id exception = nil; @try { length = [object readIntoBuffer: (char *)_buffer + _readLength length: _exactLength - _readLength]; } @catch (id e) { length = 0; exception = e; } _readLength += length; if (_readLength != _exactLength && ![object isAtEndOfStream] && exception == nil) return true; # ifdef OF_HAVE_BLOCKS if (_block != NULL) { if (!_block(_readLength, exception)) return false; _readLength = 0; return true; } else { # endif if (![_delegate respondsToSelector: @selector(stream:didReadIntoBuffer:length:exception:)]) return false; if (![_delegate stream: object didReadIntoBuffer: _buffer length: _readLength exception: exception]) return false; _readLength = 0; return true; # ifdef OF_HAVE_BLOCKS } # endif } # ifdef OF_HAVE_BLOCKS - (void)dealloc { [_block release]; [super dealloc]; } # endif @end @implementation OFRunLoopReadLineQueueItem - (bool)handleObject: (id)object { OFString *line; id exception = nil; @try { line = [object tryReadLineWithEncoding: _encoding]; } @catch (id e) { line = nil; exception = e; } if (line == nil && ![object isAtEndOfStream] && exception == nil) return true; # ifdef OF_HAVE_BLOCKS if (_block != NULL) return _block(line, exception); else { # endif if (![_delegate respondsToSelector: @selector(stream:didReadLine:exception:)]) return false; return [_delegate stream: object didReadLine: line exception: exception]; # ifdef OF_HAVE_BLOCKS } # endif } # ifdef OF_HAVE_BLOCKS - (void)dealloc { [_block release]; [super dealloc]; } # endif @end @implementation OFRunLoopWriteDataQueueItem - (bool)handleObject: (id)object { size_t length; id exception = nil; size_t dataLength = _data.count * _data.itemSize; OFData *newData, *oldData; @try { const char *dataItems = _data.items; length = dataLength - _writtenLength; [object writeBuffer: dataItems + _writtenLength length: length]; } @catch (OFWriteFailedException *e) { length = e.bytesWritten; if (e.errNo != EWOULDBLOCK && e.errNo != EAGAIN) exception = e; } @catch (id e) { length = 0; exception = e; } _writtenLength += length; OFEnsure(_writtenLength <= dataLength); if (_writtenLength != dataLength && exception == nil) return true; # ifdef OF_HAVE_BLOCKS if (_block != NULL) { newData = _block(_writtenLength, exception); if (newData == nil) return false; oldData = _data; _data = [newData copy]; [oldData release]; _writtenLength = 0; return true; } else { # endif if (![_delegate respondsToSelector: @selector(stream:didWriteData:bytesWritten:exception:)]) return false; newData = [_delegate stream: object didWriteData: _data bytesWritten: _writtenLength exception: exception]; if (newData == nil) return false; oldData = _data; _data = [newData copy]; [oldData release]; _writtenLength = 0; return true; # ifdef OF_HAVE_BLOCKS } # endif } - (void)dealloc { [_data release]; # ifdef OF_HAVE_BLOCKS [_block release]; # endif [super dealloc]; } @end @implementation OFRunLoopWriteStringQueueItem - (bool)handleObject: (id)object { size_t length; id exception = nil; size_t cStringLength = [_string cStringLengthWithEncoding: _encoding]; OFString *newString, *oldString; @try { const char *cString = [_string cStringWithEncoding: _encoding]; length = cStringLength - _writtenLength; [object writeBuffer: cString + _writtenLength length: length]; } @catch (OFWriteFailedException *e) { length = e.bytesWritten; if (e.errNo != EWOULDBLOCK && e.errNo != EAGAIN) exception = e; } @catch (id e) { length = 0; exception = e; } _writtenLength += length; OFEnsure(_writtenLength <= cStringLength); if (_writtenLength != cStringLength && exception == nil) return true; # ifdef OF_HAVE_BLOCKS if (_block != NULL) { newString = _block(_writtenLength, exception); if (newString == nil) return false; oldString = _string; _string = [newString copy]; [oldString release]; _writtenLength = 0; return true; } else { # endif if (![_delegate respondsToSelector: @selector(stream: didWriteString:encoding:bytesWritten:exception:)]) return false; newString = [_delegate stream: object didWriteString: _string encoding: _encoding bytesWritten: _writtenLength exception: exception]; if (newString == nil) return false; oldString = _string; _string = [newString copy]; [oldString release]; _writtenLength = 0; return true; # ifdef OF_HAVE_BLOCKS } # endif } - (void)dealloc { [_string release]; # ifdef OF_HAVE_BLOCKS [_block release]; # endif [super dealloc]; } @end # if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) @implementation OFRunLoopConnectQueueItem - (bool)handleObject: (id)object { id exception = nil; int errNo; if ((errNo = [object of_socketError]) != 0) exception = [_delegate of_connectionFailedExceptionForErrNo: errNo]; if ([_delegate respondsToSelector: @selector(of_socketDidConnect:exception:)]) { /* * Make sure we only call the delegate once we removed the * socket from the kernel event observer. This is necessary as * otherwise we could try to connect to the next address and it * would not be re-registered with the kernel event observer, * which is necessary for some kernel event observers (e.g. * epoll) even if the fd of the new socket is the same. */ OFRunLoop *runLoop = [OFRunLoop currentRunLoop]; OFTimer *timer = [OFTimer timerWithTimeInterval: 0 target: _delegate selector: @selector(of_socketDidConnect: exception:) object: object object: exception repeats: false]; [runLoop addTimer: timer forMode: runLoop.currentMode]; } return false; } @end # endif @implementation OFRunLoopAcceptQueueItem - (bool)handleObject: (id)object { id acceptedSocket, exception = nil; @try { acceptedSocket = [object accept]; } @catch (id e) { acceptedSocket = nil; exception = e; } # ifdef OF_HAVE_BLOCKS if (_block != NULL) { if ([object isKindOfClass: [OFStreamSocket class]]) return ((OFStreamSocketAsyncAcceptBlock)_block)( acceptedSocket, exception); else if ([object isKindOfClass: [OFSequencedPacketSocket class]]) return ((OFSequencedPacketSocketAsyncAcceptBlock) _block)(acceptedSocket, exception); else OFEnsure(0); } else { # endif if (![_delegate respondsToSelector: @selector(socket:didAcceptSocket:exception:)]) return false; return [_delegate socket: object didAcceptSocket: acceptedSocket exception: exception]; # ifdef OF_HAVE_BLOCKS } # endif } # ifdef OF_HAVE_BLOCKS - (void)dealloc { [_block release]; [super dealloc]; } # endif @end @implementation OFRunLoopDatagramReceiveQueueItem - (bool)handleObject: (id)object { size_t length; OFSocketAddress address; id exception = nil; @try { length = [object receiveIntoBuffer: _buffer length: _length sender: &address]; } @catch (id e) { length = 0; exception = e; } # ifdef OF_HAVE_BLOCKS if (_block != NULL) return _block(length, &address, exception); else { # endif if (![_delegate respondsToSelector: @selector( socket:didReceiveIntoBuffer:length:sender:exception:)]) return false; return [_delegate socket: object didReceiveIntoBuffer: _buffer length: length sender: &address exception: exception]; # ifdef OF_HAVE_BLOCKS } # endif } # ifdef OF_HAVE_BLOCKS - (void)dealloc { [_block release]; [super dealloc]; } # endif @end @implementation OFRunLoopDatagramSendQueueItem - (bool)handleObject: (id)object { id exception = nil; OFData *newData, *oldData; @try { [object sendBuffer: _data.items length: _data.count * _data.itemSize receiver: &_receiver]; } @catch (id e) { exception = e; } # ifdef OF_HAVE_BLOCKS if (_block != NULL) { newData = _block(exception); if (newData == nil) return false; oldData = _data; _data = [newData copy]; [oldData release]; return true; } else { # endif if (![_delegate respondsToSelector: @selector(socket:didSendData:receiver:exception:)]) return false; newData = [_delegate socket: object didSendData: _data receiver: &_receiver exception: exception]; if (newData == nil) return false; oldData = _data; _data = [newData copy]; [oldData release]; return true; # ifdef OF_HAVE_BLOCKS } # endif } - (void)dealloc { [_data release]; # ifdef OF_HAVE_BLOCKS [_block release]; # endif [super dealloc]; } @end @implementation OFRunLoopPacketReceiveQueueItem - (bool)handleObject: (id)object { size_t length; id exception = nil; @try { length = [object receiveIntoBuffer: _buffer length: _length]; } @catch (id e) { length = 0; exception = e; } # ifdef OF_HAVE_BLOCKS if (_block != NULL) return _block(length, exception); else { # endif if (![_delegate respondsToSelector: @selector( socket:didReceiveIntoBuffer:length:exception:)]) return false; return [_delegate socket: object didReceiveIntoBuffer: _buffer length: length exception: exception]; # ifdef OF_HAVE_BLOCKS } # endif } # ifdef OF_HAVE_BLOCKS - (void)dealloc { [_block release]; [super dealloc]; } # endif @end @implementation OFRunLoopPacketSendQueueItem - (bool)handleObject: (id)object { id exception = nil; OFData *newData, *oldData; @try { [object sendBuffer: _data.items length: _data.count * _data.itemSize]; } @catch (id e) { exception = e; } # ifdef OF_HAVE_BLOCKS if (_block != NULL) { newData = _block(exception); if (newData == nil) return false; oldData = _data; _data = [newData copy]; [oldData release]; return true; } else { # endif if (![_delegate respondsToSelector: @selector(socket:didSendData:exception:)]) return false; newData = [_delegate socket: object didSendData: _data exception: exception]; if (newData == nil) return false; oldData = _data; _data = [newData copy]; [oldData release]; return true; # ifdef OF_HAVE_BLOCKS } # endif } - (void)dealloc { [_data release]; # ifdef OF_HAVE_BLOCKS [_block release]; # endif [super dealloc]; } @end #endif @implementation OFRunLoop @synthesize currentMode = _currentMode; + (OFRunLoop *)mainRunLoop { return mainRunLoop; } + (OFRunLoop *)currentRunLoop { #ifdef OF_HAVE_THREADS return [OFThread currentThread].runLoop; #else return [self mainRunLoop]; #endif } + (void)of_setMainRunLoop: (OFRunLoop *)runLoop { mainRunLoop = [runLoop retain]; } static OFRunLoopState * stateForMode(OFRunLoop *self, OFRunLoopMode mode, bool create) { OFRunLoopState *state; #ifdef OF_HAVE_THREADS [self->_statesMutex lock]; @try { #endif state = [self->_states objectForKey: mode]; if (create && state == nil) { state = [[OFRunLoopState alloc] init]; @try { [self->_states setObject: state forKey: mode]; } @finally { [state release]; } } #ifdef OF_HAVE_THREADS } @finally { [self->_statesMutex unlock]; } #endif return state; } #ifdef OF_HAVE_SOCKETS # define NEW_READ(type, object, mode) \ void *pool = objc_autoreleasePoolPush(); \ OFRunLoop *runLoop = [self currentRunLoop]; \ OFRunLoopState *state = stateForMode(runLoop, mode, true); \ OFList *queue = [state->_readQueues objectForKey: object]; \ type *queueItem; \ \ if (queue == nil) { \ queue = [OFList list]; \ [state->_readQueues setObject: queue forKey: object]; \ } \ \ if (queue.count == 0) \ [state->_kernelEventObserver \ addObjectForReading: object]; \ \ queueItem = [[[type alloc] init] autorelease]; # define NEW_WRITE(type, object, mode) \ void *pool = objc_autoreleasePoolPush(); \ OFRunLoop *runLoop = [self currentRunLoop]; \ OFRunLoopState *state = stateForMode(runLoop, mode, true); \ OFList *queue = [state->_writeQueues objectForKey: object]; \ type *queueItem; \ \ if (queue == nil) { \ queue = [OFList list]; \ [state->_writeQueues setObject: queue forKey: object]; \ } \ \ if (queue.count == 0) \ [state->_kernelEventObserver \ addObjectForWriting: object]; \ \ queueItem = [[[type alloc] init] autorelease]; #define QUEUE_ITEM \ [queue appendObject: queueItem]; \ \ objc_autoreleasePoolPop(pool); + (void)of_addAsyncReadForStream: (OFStream *) stream buffer: (void *)buffer length: (size_t)length mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (OFStreamAsyncReadBlock)block # endif delegate: (id )delegate { NEW_READ(OFRunLoopReadQueueItem, stream, mode) queueItem->_delegate = [delegate retain]; # ifdef OF_HAVE_BLOCKS queueItem->_block = [block copy]; # endif queueItem->_buffer = buffer; queueItem->_length = length; QUEUE_ITEM } + (void)of_addAsyncReadForStream: (OFStream *) stream buffer: (void *)buffer exactLength: (size_t)exactLength mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (OFStreamAsyncReadBlock)block # endif delegate: (id )delegate { NEW_READ(OFRunLoopExactReadQueueItem, stream, mode) queueItem->_delegate = [delegate retain]; # ifdef OF_HAVE_BLOCKS queueItem->_block = [block copy]; # endif queueItem->_buffer = buffer; queueItem->_exactLength = exactLength; QUEUE_ITEM } + (void)of_addAsyncReadLineForStream: (OFStream *) stream encoding: (OFStringEncoding)encoding mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (OFStreamAsyncReadLineBlock)block # endif delegate: (id )delegate { NEW_READ(OFRunLoopReadLineQueueItem, stream, mode) queueItem->_delegate = [delegate retain]; # ifdef OF_HAVE_BLOCKS queueItem->_block = [block copy]; # endif queueItem->_encoding = encoding; QUEUE_ITEM } + (void)of_addAsyncWriteForStream: (OFStream *) stream data: (OFData *)data mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (OFStreamAsyncWriteDataBlock)block # endif delegate: (id )delegate { NEW_WRITE(OFRunLoopWriteDataQueueItem, stream, mode) queueItem->_delegate = [delegate retain]; # ifdef OF_HAVE_BLOCKS queueItem->_block = [block copy]; # endif queueItem->_data = [data copy]; QUEUE_ITEM } + (void)of_addAsyncWriteForStream: (OFStream *) stream string: (OFString *)string encoding: (OFStringEncoding)encoding mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (OFStreamAsyncWriteStringBlock)block # endif delegate: (id )delegate { NEW_WRITE(OFRunLoopWriteStringQueueItem, stream, mode) queueItem->_delegate = [delegate retain]; # ifdef OF_HAVE_BLOCKS queueItem->_block = [block copy]; # endif queueItem->_string = [string copy]; queueItem->_encoding = encoding; QUEUE_ITEM } # if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) + (void)of_addAsyncConnectForSocket: (id)sock mode: (OFRunLoopMode)mode delegate: (id )delegate { NEW_WRITE(OFRunLoopConnectQueueItem, sock, mode) queueItem->_delegate = [delegate retain]; QUEUE_ITEM } # endif + (void)of_addAsyncAcceptForSocket: (id)sock mode: (OFRunLoopMode)mode block: (id)block delegate: (id)delegate { NEW_READ(OFRunLoopAcceptQueueItem, sock, mode) queueItem->_delegate = [delegate retain]; # ifdef OF_HAVE_BLOCKS queueItem->_block = [block copy]; # endif QUEUE_ITEM } + (void)of_addAsyncReceiveForDatagramSocket: (OFDatagramSocket *)sock buffer: (void *)buffer length: (size_t)length mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (OFDatagramSocketAsyncReceiveBlock)block # endif delegate: (id )delegate { NEW_READ(OFRunLoopDatagramReceiveQueueItem, sock, mode) queueItem->_delegate = [delegate retain]; # ifdef OF_HAVE_BLOCKS queueItem->_block = [block copy]; # endif queueItem->_buffer = buffer; queueItem->_length = length; QUEUE_ITEM } + (void)of_addAsyncSendForDatagramSocket: (OFDatagramSocket *)sock data: (OFData *)data receiver: (const OFSocketAddress *)receiver mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (OFDatagramSocketAsyncSendDataBlock)block # endif delegate: (id )delegate { NEW_WRITE(OFRunLoopDatagramSendQueueItem, sock, mode) queueItem->_delegate = [delegate retain]; # ifdef OF_HAVE_BLOCKS queueItem->_block = [block copy]; # endif queueItem->_data = [data copy]; queueItem->_receiver = *receiver; QUEUE_ITEM } + (void)of_addAsyncReceiveForSequencedPacketSocket: (OFSequencedPacketSocket *) sock buffer: (void *)buffer length: (size_t)length mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (OFSequencedPacketSocketAsyncReceiveBlock)block # endif delegate: (id )delegate { NEW_READ(OFRunLoopPacketReceiveQueueItem, sock, mode) queueItem->_delegate = [delegate retain]; # ifdef OF_HAVE_BLOCKS queueItem->_block = [block copy]; # endif queueItem->_buffer = buffer; queueItem->_length = length; QUEUE_ITEM } + (void)of_addAsyncSendForSequencedPacketSocket: (OFSequencedPacketSocket *)sock data: (OFData *)data mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (OFSequencedPacketSocketAsyncSendDataBlock)block # endif delegate: (id )delegate { NEW_WRITE(OFRunLoopPacketSendQueueItem, sock, mode) queueItem->_delegate = [delegate retain]; # ifdef OF_HAVE_BLOCKS queueItem->_block = [block copy]; # endif queueItem->_data = [data copy]; QUEUE_ITEM } # undef NEW_READ # undef NEW_WRITE # undef QUEUE_ITEM + (void)of_cancelAsyncRequestsForObject: (id)object mode: (OFRunLoopMode)mode { void *pool = objc_autoreleasePoolPush(); OFRunLoop *runLoop = [self currentRunLoop]; OFRunLoopState *state = stateForMode(runLoop, mode, false); OFList *queue; if (state == nil) return; if ((queue = [state->_writeQueues objectForKey: object]) != nil) { OFAssert(queue.count > 0); /* * Clear the queue now, in case this has been called from a * handler, as otherwise, we'd do the cleanups below twice. */ [queue removeAllObjects]; [state->_kernelEventObserver removeObjectForWriting: object]; [state->_writeQueues removeObjectForKey: object]; } if ((queue = [state->_readQueues objectForKey: object]) != nil) { OFAssert(queue.count > 0); /* * Clear the queue now, in case this has been called from a * handler, as otherwise, we'd do the cleanups below twice. */ [queue removeAllObjects]; [state->_kernelEventObserver removeObjectForReading: object]; [state->_readQueues removeObjectForKey: object]; } objc_autoreleasePoolPop(pool); } #endif - (instancetype)init { self = [super init]; @try { OFRunLoopState *state; _states = [[OFMutableDictionary alloc] init]; state = [[OFRunLoopState alloc] init]; @try { [_states setObject: state forKey: OFDefaultRunLoopMode]; } @finally { [state release]; } #ifdef OF_HAVE_THREADS _statesMutex = [[OFMutex alloc] init]; #endif } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_states release]; #ifdef OF_HAVE_THREADS [_statesMutex release]; #endif [super dealloc]; } - (void)addTimer: (OFTimer *)timer { [self addTimer: timer forMode: OFDefaultRunLoopMode]; } - (void)addTimer: (OFTimer *)timer forMode: (OFRunLoopMode)mode { OFRunLoopState *state = stateForMode(self, mode, true); #ifdef OF_HAVE_THREADS [state->_timersQueueMutex lock]; @try { #endif [state->_timersQueue insertObject: timer]; #ifdef OF_HAVE_THREADS } @finally { [state->_timersQueueMutex unlock]; } #endif [timer of_setInRunLoop: self mode: mode]; #if defined(OF_HAVE_SOCKETS) [state->_kernelEventObserver cancel]; #elif defined(OF_HAVE_THREADS) [state->_condition signal]; #endif } - (void)of_removeTimer: (OFTimer *)timer forMode: (OFRunLoopMode)mode { OFRunLoopState *state = stateForMode(self, mode, false); /* {} required to avoid -Wmisleading-indentation false positive. */ if (state == nil) { return; } #ifdef OF_HAVE_THREADS [state->_timersQueueMutex lock]; @try { #endif for (OFListItem iter = state->_timersQueue.firstListItem; iter != NULL; iter = OFListItemNext(iter)) { if ([OFListItemObject(iter) isEqual: timer]) { [state->_timersQueue removeListItem: iter]; break; } } #ifdef OF_HAVE_THREADS } @finally { [state->_timersQueueMutex unlock]; } #endif } #ifdef OF_AMIGAOS - (void)addExecSignal: (ULONG)signal target: (id)target selector: (SEL)selector { [self addExecSignal: signal forMode: OFDefaultRunLoopMode target: target selector: selector]; } - (void)addExecSignal: (ULONG)signal forMode: (OFRunLoopMode)mode target: (id)target selector: (SEL)selector { OFRunLoopState *state = stateForMode(self, mode, true); # ifdef OF_HAVE_THREADS [state->_execSignalsMutex lock]; @try { # endif [state->_execSignals addItem: &signal]; [state->_execSignalsTargets addObject: target]; [state->_execSignalsSelectors addItem: &selector]; # ifdef OF_HAVE_SOCKETS state->_kernelEventObserver.execSignalMask |= (1ul << signal); # elif defined(OF_HAVE_THREADS) state->_execSignalMask |= (1ul << signal); # endif # ifdef OF_HAVE_THREADS } @finally { [state->_execSignalsMutex unlock]; } # endif # if defined(OF_HAVE_SOCKETS) [state->_kernelEventObserver cancel]; # elif defined(OF_HAVE_THREADS) [state->_condition signal]; # endif } - (void)removeExecSignal: (ULONG)signal target: (id)target selector: (SEL)selector { [self removeExecSignal: signal forMode: OFDefaultRunLoopMode target: target selector: selector]; } - (void)removeExecSignal: (ULONG)signal forMode: (OFRunLoopMode)mode target: (id)target selector: (SEL)selector { OFRunLoopState *state = stateForMode(self, mode, false); if (state == nil) return; # ifdef OF_HAVE_THREADS [state->_execSignalsMutex lock]; @try { # endif const ULONG *signals = state->_execSignals.items; const id *targets = state->_execSignalsTargets.objects; const SEL *selectors = state->_execSignalsSelectors.items; size_t count = state->_execSignals.count; bool found = false; ULONG newMask = 0; for (size_t i = 0; i < count; i++) { if (!found && signals[i] == signal && targets[i] == target && selectors[i] == selector) { [state->_execSignals removeItemAtIndex: i]; [state->_execSignalsTargets removeObjectAtIndex: i]; [state->_execSignalsSelectors removeItemAtIndex: i]; found = true; } else newMask |= (1ul << signals[i]); } # ifdef OF_HAVE_SOCKETS state->_kernelEventObserver.execSignalMask = newMask; # elif defined(OF_HAVE_THREADS) state->_execSignalMask = newMask; # endif # ifdef OF_HAVE_THREADS } @finally { [state->_execSignalsMutex unlock]; } # endif # if defined(OF_HAVE_SOCKETS) [state->_kernelEventObserver cancel]; # elif defined(OF_HAVE_THREADS) [state->_condition signal]; # endif } #endif - (void)run { [self runUntilDate: nil]; } - (void)runUntilDate: (OFDate *)deadline { _stop = false; while (!_stop && (deadline == nil || deadline.timeIntervalSinceNow >= 0)) [self runMode: OFDefaultRunLoopMode beforeDate: deadline]; } - (void)runMode: (OFRunLoopMode)mode beforeDate: (OFDate *)deadline { void *pool = objc_autoreleasePoolPush(); OFRunLoopMode previousMode = _currentMode; OFRunLoopState *state = stateForMode(self, mode, false); if (state == nil) return; _currentMode = mode; @try { OFDate *nextTimer; #if defined(OF_AMIGAOS) && !defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS) ULONG signalMask; #endif for (;;) { OFTimer *timer; #ifdef OF_HAVE_THREADS [state->_timersQueueMutex lock]; @try { #endif OFListItem listItem = state->_timersQueue.firstListItem; if (listItem != NULL && [OFListItemObject(listItem) fireDate] .timeIntervalSinceNow <= 0) { timer = [[OFListItemObject(listItem) retain] autorelease]; [state->_timersQueue removeListItem: listItem]; [timer of_setInRunLoop: nil mode: nil]; } else break; #ifdef OF_HAVE_THREADS } @finally { [state->_timersQueueMutex unlock]; } #endif if (timer.valid) { [timer of_reschedule]; [timer fire]; return; } } #ifdef OF_HAVE_THREADS [state->_timersQueueMutex lock]; @try { #endif nextTimer = [[state->_timersQueue firstObject] fireDate]; #ifdef OF_HAVE_THREADS } @finally { [state->_timersQueueMutex unlock]; } #endif /* Watch for I/O events until the next timer is due */ if (nextTimer != nil || deadline != nil) { OFTimeInterval timeout; if (nextTimer != nil && deadline == nil) timeout = nextTimer.timeIntervalSinceNow; else if (nextTimer == nil && deadline != nil) timeout = deadline.timeIntervalSinceNow; else timeout = [nextTimer earlierDate: deadline] .timeIntervalSinceNow; if (timeout < 0) timeout = 0; #if defined(OF_HAVE_SOCKETS) @try { [state->_kernelEventObserver observeForTimeInterval: timeout]; } @catch (OFObserveKernelEventsFailedException *e) { if (e.errNo != EINTR) @throw e; } #elif defined(OF_HAVE_THREADS) [state->_condition lock]; # ifdef OF_AMIGAOS signalMask = state->_execSignalMask; [state->_condition waitForTimeInterval: timeout orExecSignal: &signalMask]; if (signalMask != 0) [state execSignalWasReceived: signalMask]; # else [state->_condition waitForTimeInterval: timeout]; # endif [state->_condition unlock]; #else [OFThread sleepForTimeInterval: timeout]; #endif } else { /* * No more timers and no deadline: Just watch for I/O * until we get an event. If a timer is added by * another thread, it cancels the observe. */ #if defined(OF_HAVE_SOCKETS) @try { [state->_kernelEventObserver observe]; } @catch (OFObserveKernelEventsFailedException *e) { if (e.errNo != EINTR) @throw e; } #elif defined(OF_HAVE_THREADS) [state->_condition lock]; # ifdef OF_AMIGAOS signalMask = state->_execSignalMask; [state->_condition waitForConditionOrExecSignal: &signalMask]; if (signalMask != 0) [state execSignalWasReceived: signalMask]; # else [state->_condition wait]; # endif [state->_condition unlock]; #else [OFThread sleepForTimeInterval: 86400]; #endif } objc_autoreleasePoolPop(pool); } @finally { _currentMode = previousMode; } } - (void)stop { OFRunLoopState *state = stateForMode(self, OFDefaultRunLoopMode, false); _stop = true; if (state == nil) return; #if defined(OF_HAVE_SOCKETS) [state->_kernelEventObserver cancel]; #elif defined(OF_HAVE_THREADS) [state->_condition signal]; #endif } @end objfw-1.1.6/src/OFRunLoopConstants.inc000066400000000000000000000014401465614216400176400ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ const OFRunLoopMode OFDefaultRunLoopMode = @"OFDefaultRunLoopMode"; objfw-1.1.6/src/OFSHA1Hash.h000066400000000000000000000024061465614216400153260ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFCryptographicHash.h" OF_ASSUME_NONNULL_BEGIN @class OFSecureData; /** * @class OFSHA1Hash OFSHA1Hash.h ObjFW/OFSHA1Hash.h * * @brief A class which provides methods to create an SHA-1 hash. */ OF_SUBCLASSING_RESTRICTED @interface OFSHA1Hash: OFObject { OFSecureData *_iVarsData; struct { uint32_t state[5]; uint64_t bits; union { unsigned char bytes[64]; uint32_t words[80]; } buffer; size_t bufferLength; } *_iVars; bool _allowsSwappableMemory; bool _calculated; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFSHA1Hash.m000066400000000000000000000132311465614216400153310ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFSHA1Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFHashNotCalculatedException.h" #import "OFOutOfRangeException.h" static const size_t digestSize = 20; static const size_t blockSize = 64; OF_DIRECT_MEMBERS @interface OFSHA1Hash () - (void)of_resetState; @end #define F(a, b, c, d) ((d) ^ ((b) & ((c) ^ (d)))) #define G(a, b, c, d) ((b) ^ (c) ^ (d)) #define H(a, b, c, d) (((b) & (c)) | ((d) & ((b) | (c)))) #define I(a, b, c, d) ((b) ^ (c) ^ (d)) static OF_INLINE void byteSwapVectorIfLE(uint32_t *vector, uint_fast8_t length) { #ifndef OF_BIG_ENDIAN for (uint_fast8_t i = 0; i < length; i++) vector[i] = OFByteSwap32(vector[i]); #endif } static void processBlock(uint32_t *state, uint32_t *buffer) { uint32_t new[5]; uint_fast8_t i; new[0] = state[0]; new[1] = state[1]; new[2] = state[2]; new[3] = state[3]; new[4] = state[4]; byteSwapVectorIfLE(buffer, 16); for (i = 16; i < 80; i++) { uint32_t tmp = buffer[i - 3] ^ buffer[i - 8] ^ buffer[i - 14] ^ buffer[i - 16]; buffer[i] = OFRotateLeft(tmp, 1); } #define LOOP_BODY(f, k) \ { \ uint32_t tmp = OFRotateLeft(new[0], 5) + \ f(new[0], new[1], new[2], new[3]) + \ new[4] + k + buffer[i]; \ new[4] = new[3]; \ new[3] = new[2]; \ new[2] = OFRotateLeft(new[1], 30); \ new[1] = new[0]; \ new[0] = tmp; \ } for (i = 0; i < 20; i++) LOOP_BODY(F, 0x5A827999) for (; i < 40; i++) LOOP_BODY(G, 0x6ED9EBA1) for (; i < 60; i++) LOOP_BODY(H, 0x8F1BBCDC) for (; i < 80; i++) LOOP_BODY(I, 0xCA62C1D6) #undef LOOP_BODY state[0] += new[0]; state[1] += new[1]; state[2] += new[2]; state[3] += new[3]; state[4] += new[4]; } @implementation OFSHA1Hash @synthesize calculated = _calculated; @synthesize allowsSwappableMemory = _allowsSwappableMemory; + (size_t)digestSize { return digestSize; } + (size_t)blockSize { return blockSize; } + (instancetype)hashWithAllowsSwappableMemory: (bool)allowsSwappableMemory { return [[[self alloc] initWithAllowsSwappableMemory: allowsSwappableMemory] autorelease]; } - (instancetype)initWithAllowsSwappableMemory: (bool)allowsSwappableMemory { self = [super init]; @try { _iVarsData = [[OFSecureData alloc] initWithCount: sizeof(*_iVars) allowsSwappableMemory: allowsSwappableMemory]; _iVars = _iVarsData.mutableItems; _allowsSwappableMemory = allowsSwappableMemory; [self of_resetState]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)of_init { return [super init]; } - (void)dealloc { [_iVarsData release]; [super dealloc]; } - (size_t)digestSize { return digestSize; } - (size_t)blockSize { return blockSize; } - (id)copy { OFSHA1Hash *copy = [[OFSHA1Hash alloc] of_init]; copy->_iVarsData = [_iVarsData copy]; copy->_iVars = copy->_iVarsData.mutableItems; copy->_allowsSwappableMemory = _allowsSwappableMemory; copy->_calculated = _calculated; return copy; } - (void)of_resetState { _iVars->state[0] = 0x67452301; _iVars->state[1] = 0xEFCDAB89; _iVars->state[2] = 0x98BADCFE; _iVars->state[3] = 0x10325476; _iVars->state[4] = 0xC3D2E1F0; } - (void)updateWithBuffer: (const void *)buffer_ length: (size_t)length { const unsigned char *buffer = buffer_; if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; if (length > SIZE_MAX / 8) @throw [OFOutOfRangeException exception]; _iVars->bits += (length * 8); while (length > 0) { size_t min = 64 - _iVars->bufferLength; if (min > length) min = length; memcpy(_iVars->buffer.bytes + _iVars->bufferLength, buffer, min); _iVars->bufferLength += min; buffer += min; length -= min; if (_iVars->bufferLength == 64) { processBlock(_iVars->state, _iVars->buffer.words); _iVars->bufferLength = 0; } } } - (const unsigned char *)digest { if (!_calculated) @throw [OFHashNotCalculatedException exceptionWithObject: self]; return (const unsigned char *)_iVars->state; } - (void)calculate { if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; _iVars->buffer.bytes[_iVars->bufferLength] = 0x80; OFZeroMemory(_iVars->buffer.bytes + _iVars->bufferLength + 1, 64 - _iVars->bufferLength - 1); if (_iVars->bufferLength >= 56) { processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(_iVars->buffer.bytes, 64); } _iVars->buffer.words[14] = OFToBigEndian32((uint32_t)(_iVars->bits >> 32)); _iVars->buffer.words[15] = OFToBigEndian32((uint32_t)(_iVars->bits & 0xFFFFFFFF)); processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); byteSwapVectorIfLE(_iVars->state, 5); _calculated = true; } - (void)reset { [self of_resetState]; _iVars->bits = 0; OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); _iVars->bufferLength = 0; _calculated = false; } @end objfw-1.1.6/src/OFSHA224Hash.h000066400000000000000000000017771465614216400155070ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFSHA224Or256Hash.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFSHA224Hash OFSHA224Hash.h ObjFW/OFSHA224Hash.h * * @brief A class which provides methods to create an SHA-224 hash. */ OF_SUBCLASSING_RESTRICTED @interface OFSHA224Hash: OFSHA224Or256Hash @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFSHA224Hash.m000066400000000000000000000023111465614216400154750ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFSHA224Hash.h" static const size_t digestSize = 28; @implementation OFSHA224Hash + (size_t)digestSize { return digestSize; } - (size_t)digestSize { return digestSize; } - (void)of_resetState { _iVars->state[0] = 0xC1059ED8; _iVars->state[1] = 0x367CD507; _iVars->state[2] = 0x3070DD17; _iVars->state[3] = 0xF70E5939; _iVars->state[4] = 0xFFC00B31; _iVars->state[5] = 0x68581511; _iVars->state[6] = 0x64F98FA7; _iVars->state[7] = 0xBEFA4FA4; } @end objfw-1.1.6/src/OFSHA224Or256Hash.h000066400000000000000000000024731465614216400162370ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFCryptographicHash.h" OF_ASSUME_NONNULL_BEGIN @class OFSecureData; /** * @class OFSHA224Or256Hash OFSHA224Or256Hash.h ObjFW/OFSHA224Or256Hash.h * * @brief A base class for SHA-224 and SHA-256. */ @interface OFSHA224Or256Hash: OFObject { @private OFSecureData *_iVarsData; @protected struct { uint32_t state[8]; uint64_t bits; union { unsigned char bytes[64]; uint32_t words[64]; } buffer; size_t bufferLength; } *_iVars; @private bool _allowsSwappableMemory; bool _calculated; OF_RESERVE_IVARS(OFSHA224Or256Hash, 4) } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFSHA224Or256Hash.m000066400000000000000000000150431465614216400162410ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "OFSHA224Or256Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFHashNotCalculatedException.h" #import "OFOutOfRangeException.h" static const size_t blockSize = 64; @interface OFSHA224Or256Hash () - (void)of_resetState; @end static const uint32_t table[] = { 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967, 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2 }; static OF_INLINE void byteSwapVectorIfLE(uint32_t *vector, uint_fast8_t length) { #ifndef OF_BIG_ENDIAN for (uint_fast8_t i = 0; i < length; i++) vector[i] = OFByteSwap32(vector[i]); #endif } static void processBlock(uint32_t *state, uint32_t *buffer) { uint32_t new[8]; uint_fast8_t i; new[0] = state[0]; new[1] = state[1]; new[2] = state[2]; new[3] = state[3]; new[4] = state[4]; new[5] = state[5]; new[6] = state[6]; new[7] = state[7]; byteSwapVectorIfLE(buffer, 16); for (i = 16; i < 64; i++) { uint32_t tmp; tmp = buffer[i - 2]; buffer[i] = (OFRotateRight(tmp, 17) ^ OFRotateRight(tmp, 19) ^ (tmp >> 10)) + buffer[i - 7]; tmp = buffer[i - 15]; buffer[i] += (OFRotateRight(tmp, 7) ^ OFRotateRight(tmp, 18) ^ (tmp >> 3)) + buffer[i - 16]; } for (i = 0; i < 64; i++) { uint32_t tmp1 = new[7] + (OFRotateRight(new[4], 6) ^ OFRotateRight(new[4], 11) ^ OFRotateRight(new[4], 25)) + ((new[4] & (new[5] ^ new[6])) ^ new[6]) + table[i] + buffer[i]; uint32_t tmp2 = (OFRotateRight(new[0], 2) ^ OFRotateRight(new[0], 13) ^ OFRotateRight(new[0], 22)) + ((new[0] & (new[1] | new[2])) | (new[1] & new[2])); new[7] = new[6]; new[6] = new[5]; new[5] = new[4]; new[4] = new[3] + tmp1; new[3] = new[2]; new[2] = new[1]; new[1] = new[0]; new[0] = tmp1 + tmp2; } state[0] += new[0]; state[1] += new[1]; state[2] += new[2]; state[3] += new[3]; state[4] += new[4]; state[5] += new[5]; state[6] += new[6]; state[7] += new[7]; } @implementation OFSHA224Or256Hash @synthesize calculated = _calculated; @synthesize allowsSwappableMemory = _allowsSwappableMemory; + (size_t)digestSize { OF_UNRECOGNIZED_SELECTOR } + (size_t)blockSize { return blockSize; } + (instancetype)hashWithAllowsSwappableMemory: (bool)allowsSwappableMemory { return [[[self alloc] initWithAllowsSwappableMemory: allowsSwappableMemory] autorelease]; } - (instancetype)initWithAllowsSwappableMemory: (bool)allowsSwappableMemory { self = [super init]; @try { _iVarsData = [[OFSecureData alloc] initWithCount: sizeof(*_iVars) allowsSwappableMemory: allowsSwappableMemory]; _iVars = _iVarsData.mutableItems; _allowsSwappableMemory = allowsSwappableMemory; if (self.class == [OFSHA224Or256Hash class]) { [self doesNotRecognizeSelector: _cmd]; abort(); } [self of_resetState]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)of_init { return [super init]; } - (void)dealloc { [_iVarsData release]; [super dealloc]; } - (size_t)digestSize { OF_UNRECOGNIZED_SELECTOR } - (size_t)blockSize { return blockSize; } - (id)copy { OFSHA224Or256Hash *copy = [[[self class] alloc] of_init]; copy->_iVarsData = [_iVarsData copy]; copy->_iVars = copy->_iVarsData.mutableItems; copy->_allowsSwappableMemory = _allowsSwappableMemory; copy->_calculated = _calculated; return copy; } - (void)updateWithBuffer: (const void *)buffer_ length: (size_t)length { const unsigned char *buffer = buffer_; if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; if (length > SIZE_MAX / 8) @throw [OFOutOfRangeException exception]; _iVars->bits += (length * 8); while (length > 0) { size_t min = 64 - _iVars->bufferLength; if (min > length) min = length; memcpy(_iVars->buffer.bytes + _iVars->bufferLength, buffer, min); _iVars->bufferLength += min; buffer += min; length -= min; if (_iVars->bufferLength == 64) { processBlock(_iVars->state, _iVars->buffer.words); _iVars->bufferLength = 0; } } } - (const unsigned char *)digest { if (!_calculated) @throw [OFHashNotCalculatedException exceptionWithObject: self]; return (const unsigned char *)_iVars->state; } - (void)calculate { if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; _iVars->buffer.bytes[_iVars->bufferLength] = 0x80; OFZeroMemory(_iVars->buffer.bytes + _iVars->bufferLength + 1, 64 - _iVars->bufferLength - 1); if (_iVars->bufferLength >= 56) { processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(_iVars->buffer.bytes, 64); } _iVars->buffer.words[14] = OFToBigEndian32((uint32_t)(_iVars->bits >> 32)); _iVars->buffer.words[15] = OFToBigEndian32((uint32_t)(_iVars->bits & 0xFFFFFFFF)); processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); byteSwapVectorIfLE(_iVars->state, 8); _calculated = true; } - (void)reset { [self of_resetState]; _iVars->bits = 0; OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); _iVars->bufferLength = 0; _calculated = false; } - (void)of_resetState { OF_UNRECOGNIZED_SELECTOR } @end objfw-1.1.6/src/OFSHA256Hash.h000066400000000000000000000017771465614216400155140ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFSHA224Or256Hash.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFSHA256Hash OFSHA256Hash.h ObjFW/OFSHA256Hash.h * * @brief A class which provides methods to create an SHA-256 hash. */ OF_SUBCLASSING_RESTRICTED @interface OFSHA256Hash: OFSHA224Or256Hash @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFSHA256Hash.m000066400000000000000000000023111465614216400155020ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFSHA256Hash.h" static const size_t digestSize = 32; @implementation OFSHA256Hash + (size_t)digestSize { return digestSize; } - (size_t)digestSize { return digestSize; } - (void)of_resetState { _iVars->state[0] = 0x6A09E667; _iVars->state[1] = 0xBB67AE85; _iVars->state[2] = 0x3C6EF372; _iVars->state[3] = 0xA54FF53A; _iVars->state[4] = 0x510E527F; _iVars->state[5] = 0x9B05688C; _iVars->state[6] = 0x1F83D9AB; _iVars->state[7] = 0x5BE0CD19; } @end objfw-1.1.6/src/OFSHA384Hash.h000066400000000000000000000017771465614216400155160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFSHA384Or512Hash.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFSHA384Hash OFSHA384Hash.h ObjFW/OFSHA384Hash.h * * @brief A class which provides methods to create an SHA-384 hash. */ OF_SUBCLASSING_RESTRICTED @interface OFSHA384Hash: OFSHA384Or512Hash @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFSHA384Hash.m000066400000000000000000000024111465614216400155050ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFSHA384Hash.h" static const size_t digestSize = 48; @implementation OFSHA384Hash + (size_t)digestSize { return digestSize; } - (size_t)digestSize { return digestSize; } - (void)of_resetState { _iVars->state[0] = 0xCBBB9D5DC1059ED8; _iVars->state[1] = 0x629A292A367CD507; _iVars->state[2] = 0x9159015A3070DD17; _iVars->state[3] = 0x152FECD8F70E5939; _iVars->state[4] = 0x67332667FFC00B31; _iVars->state[5] = 0x8EB44A8768581511; _iVars->state[6] = 0xDB0C2E0D64F98FA7; _iVars->state[7] = 0x47B5481DBEFA4FA4; } @end objfw-1.1.6/src/OFSHA384Or512Hash.h000066400000000000000000000024771465614216400162450ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFCryptographicHash.h" OF_ASSUME_NONNULL_BEGIN @class OFSecureData; /** * @class OFSHA384Or512Hash OFSHA384Or512Hash.h ObjFW/OFSHA384Or512Hash.h * * @brief A base class for SHA-384 and SHA-512. */ @interface OFSHA384Or512Hash: OFObject { @private OFSecureData *_iVarsData; @protected struct { uint64_t state[8]; uint64_t bits[2]; union { unsigned char bytes[128]; uint64_t words[80]; } buffer; size_t bufferLength; } *_iVars; @private bool _allowsSwappableMemory; bool _calculated; OF_RESERVE_IVARS(OFSHA384Or512Hash, 4) } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFSHA384Or512Hash.m000066400000000000000000000166571465614216400162570ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "OFSHA384Or512Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFHashNotCalculatedException.h" #import "OFOutOfRangeException.h" static const size_t blockSize = 128; @interface OFSHA384Or512Hash () - (void)of_resetState; @end static const uint64_t table[] = { 0x428A2F98D728AE22, 0x7137449123EF65CD, 0xB5C0FBCFEC4D3B2F, 0xE9B5DBA58189DBBC, 0x3956C25BF348B538, 0x59F111F1B605D019, 0x923F82A4AF194F9B, 0xAB1C5ED5DA6D8118, 0xD807AA98A3030242, 0x12835B0145706FBE, 0x243185BE4EE4B28C, 0x550C7DC3D5FFB4E2, 0x72BE5D74F27B896F, 0x80DEB1FE3B1696B1, 0x9BDC06A725C71235, 0xC19BF174CF692694, 0xE49B69C19EF14AD2, 0xEFBE4786384F25E3, 0x0FC19DC68B8CD5B5, 0x240CA1CC77AC9C65, 0x2DE92C6F592B0275, 0x4A7484AA6EA6E483, 0x5CB0A9DCBD41FBD4, 0x76F988DA831153B5, 0x983E5152EE66DFAB, 0xA831C66D2DB43210, 0xB00327C898FB213F, 0xBF597FC7BEEF0EE4, 0xC6E00BF33DA88FC2, 0xD5A79147930AA725, 0x06CA6351E003826F, 0x142929670A0E6E70, 0x27B70A8546D22FFC, 0x2E1B21385C26C926, 0x4D2C6DFC5AC42AED, 0x53380D139D95B3DF, 0x650A73548BAF63DE, 0x766A0ABB3C77B2A8, 0x81C2C92E47EDAEE6, 0x92722C851482353B, 0xA2BFE8A14CF10364, 0xA81A664BBC423001, 0xC24B8B70D0F89791, 0xC76C51A30654BE30, 0xD192E819D6EF5218, 0xD69906245565A910, 0xF40E35855771202A, 0x106AA07032BBD1B8, 0x19A4C116B8D2D0C8, 0x1E376C085141AB53, 0x2748774CDF8EEB99, 0x34B0BCB5E19B48A8, 0x391C0CB3C5C95A63, 0x4ED8AA4AE3418ACB, 0x5B9CCA4F7763E373, 0x682E6FF3D6B2B8A3, 0x748F82EE5DEFB2FC, 0x78A5636F43172F60, 0x84C87814A1F0AB72, 0x8CC702081A6439EC, 0x90BEFFFA23631E28, 0xA4506CEBDE82BDE9, 0xBEF9A3F7B2C67915, 0xC67178F2E372532B, 0xCA273ECEEA26619C, 0xD186B8C721C0C207, 0xEADA7DD6CDE0EB1E, 0xF57D4F7FEE6ED178, 0x06F067AA72176FBA, 0x0A637DC5A2C898A6, 0x113F9804BEF90DAE, 0x1B710B35131C471B, 0x28DB77F523047D84, 0x32CAAB7B40C72493, 0x3C9EBE0A15C9BEBC, 0x431D67C49C100D4C, 0x4CC5D4BECB3E42B6, 0x597F299CFC657E2A, 0x5FCB6FAB3AD6FAEC, 0x6C44198C4A475817 }; static OF_INLINE void byteSwapVectorIfLE(uint64_t *vector, uint_fast8_t length) { #ifndef OF_BIG_ENDIAN for (uint_fast8_t i = 0; i < length; i++) vector[i] = OFByteSwap64(vector[i]); #endif } static void processBlock(uint64_t *state, uint64_t *buffer) { uint64_t new[8]; uint_fast8_t i; new[0] = state[0]; new[1] = state[1]; new[2] = state[2]; new[3] = state[3]; new[4] = state[4]; new[5] = state[5]; new[6] = state[6]; new[7] = state[7]; byteSwapVectorIfLE(buffer, 16); for (i = 16; i < 80; i++) { uint64_t tmp; tmp = buffer[i - 2]; buffer[i] = (OFRotateRight(tmp, 19) ^ OFRotateRight(tmp, 61) ^ (tmp >> 6)) + buffer[i - 7]; tmp = buffer[i - 15]; buffer[i] += (OFRotateRight(tmp, 1) ^ OFRotateRight(tmp, 8) ^ (tmp >> 7)) + buffer[i - 16]; } for (i = 0; i < 80; i++) { uint64_t tmp1 = new[7] + (OFRotateRight(new[4], 14) ^ OFRotateRight(new[4], 18) ^ OFRotateRight(new[4], 41)) + ((new[4] & (new[5] ^ new[6])) ^ new[6]) + table[i] + buffer[i]; uint64_t tmp2 = (OFRotateRight(new[0], 28) ^ OFRotateRight(new[0], 34) ^ OFRotateRight(new[0], 39)) + ((new[0] & (new[1] | new[2])) | (new[1] & new[2])); new[7] = new[6]; new[6] = new[5]; new[5] = new[4]; new[4] = new[3] + tmp1; new[3] = new[2]; new[2] = new[1]; new[1] = new[0]; new[0] = tmp1 + tmp2; } state[0] += new[0]; state[1] += new[1]; state[2] += new[2]; state[3] += new[3]; state[4] += new[4]; state[5] += new[5]; state[6] += new[6]; state[7] += new[7]; } @implementation OFSHA384Or512Hash @synthesize calculated = _calculated; @synthesize allowsSwappableMemory = _allowsSwappableMemory; + (size_t)digestSize { OF_UNRECOGNIZED_SELECTOR } + (size_t)blockSize { return blockSize; } + (instancetype)hashWithAllowsSwappableMemory: (bool)allowsSwappableMemory { return [[[self alloc] initWithAllowsSwappableMemory: allowsSwappableMemory] autorelease]; } - (instancetype)initWithAllowsSwappableMemory: (bool)allowsSwappableMemory { self = [super init]; @try { _iVarsData = [[OFSecureData alloc] initWithCount: sizeof(*_iVars) allowsSwappableMemory: allowsSwappableMemory]; _iVars = _iVarsData.mutableItems; _allowsSwappableMemory = allowsSwappableMemory; if (self.class == [OFSHA384Or512Hash class]) { [self doesNotRecognizeSelector: _cmd]; abort(); } [self of_resetState]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)of_init { return [super init]; } - (void)dealloc { [_iVarsData release]; [super dealloc]; } - (size_t)digestSize { OF_UNRECOGNIZED_SELECTOR } - (size_t)blockSize { return blockSize; } - (id)copy { OFSHA384Or512Hash *copy = [[[self class] alloc] of_init]; copy->_iVarsData = [_iVarsData copy]; copy->_iVars = copy->_iVarsData.mutableItems; copy->_allowsSwappableMemory = _allowsSwappableMemory; copy->_calculated = _calculated; return copy; } - (void)updateWithBuffer: (const void *)buffer_ length: (size_t)length { const unsigned char *buffer = buffer_; if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; if (length > SIZE_MAX / 8) @throw [OFOutOfRangeException exception]; if (UINT64_MAX - _iVars->bits[0] < (length * 8)) _iVars->bits[1]++; _iVars->bits[0] += (length * 8); while (length > 0) { size_t min = 128 - _iVars->bufferLength; if (min > length) min = length; memcpy(_iVars->buffer.bytes + _iVars->bufferLength, buffer, min); _iVars->bufferLength += min; buffer += min; length -= min; if (_iVars->bufferLength == 128) { processBlock(_iVars->state, _iVars->buffer.words); _iVars->bufferLength = 0; } } } - (const unsigned char *)digest { if (!_calculated) @throw [OFHashNotCalculatedException exceptionWithObject: self]; return (const unsigned char *)_iVars->state; } - (void)calculate { if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; _iVars->buffer.bytes[_iVars->bufferLength] = 0x80; OFZeroMemory(_iVars->buffer.bytes + _iVars->bufferLength + 1, 128 - _iVars->bufferLength - 1); if (_iVars->bufferLength >= 112) { processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(_iVars->buffer.bytes, 128); } _iVars->buffer.words[14] = OFToBigEndian64(_iVars->bits[1]); _iVars->buffer.words[15] = OFToBigEndian64(_iVars->bits[0]); processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); byteSwapVectorIfLE(_iVars->state, 8); _calculated = true; } - (void)reset { [self of_resetState]; OFZeroMemory(_iVars->bits, sizeof(_iVars->bits)); OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); _iVars->bufferLength = 0; _calculated = false; } - (void)of_resetState { OF_UNRECOGNIZED_SELECTOR } @end objfw-1.1.6/src/OFSHA512Hash.h000066400000000000000000000017771465614216400155070ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFSHA384Or512Hash.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFSHA512Hash OFSHA512Hash.h ObjFW/OFSHA512Hash.h * * @brief A class which provides methods to create an SHA-512 hash. */ OF_SUBCLASSING_RESTRICTED @interface OFSHA512Hash: OFSHA384Or512Hash @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFSHA512Hash.m000066400000000000000000000024111465614216400154760ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFSHA512Hash.h" static const size_t digestSize = 64; @implementation OFSHA512Hash + (size_t)digestSize { return digestSize; } - (size_t)digestSize { return digestSize; } - (void)of_resetState { _iVars->state[0] = 0x6A09E667F3BCC908; _iVars->state[1] = 0xBB67AE8584CAA73B; _iVars->state[2] = 0x3C6EF372FE94F82B; _iVars->state[3] = 0xA54FF53A5F1D36F1; _iVars->state[4] = 0x510E527FADE682D1; _iVars->state[5] = 0x9B05688C2B3E6C1F; _iVars->state[6] = 0x1F83D9ABFB41BD6B; _iVars->state[7] = 0x5BE0CD19137E2179; } @end objfw-1.1.6/src/OFSOADNSResourceRecord.h000066400000000000000000000065751465614216400176770ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFDNSResourceRecord.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFSOADNSResourceRecord \ * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h * * @brief A class representing an SOA DNS resource record. */ OF_SUBCLASSING_RESTRICTED @interface OFSOADNSResourceRecord: OFDNSResourceRecord { OFString *_primaryNameServer, *_responsiblePerson; uint32_t _serialNumber, _refreshInterval, _retryInterval; uint32_t _expirationInterval, _minTTL; } /** * @brief The the primary name server for the zone. */ @property (readonly, nonatomic) OFString *primaryNameServer; /** * @brief The mailbox of the person responsible for the zone. */ @property (readonly, nonatomic) OFString *responsiblePerson; /** * @brief The serial number of the original copy of the zone. */ @property (readonly, nonatomic) uint32_t serialNumber; /** * @brief The refresh interval of the zone. */ @property (readonly, nonatomic) uint32_t refreshInterval; /** * @brief The retry interval of the zone. */ @property (readonly, nonatomic) uint32_t retryInterval; /** * @brief The expiration interval of the zone. */ @property (readonly, nonatomic) uint32_t expirationInterval; /** * @brief The minimum TTL of the zone. */ @property (readonly, nonatomic) uint32_t minTTL; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFSOADNSResourceRecord with the * specified name, class, text data and time to live. * * @param name The name for the resource record * @param DNSClass The class code for the resource record * @param primaryNameServer The the primary name server for the zone * @param responsiblePerson The mailbox of the person responsible for the zone * @param serialNumber The serial number of the original copy of the zone * @param refreshInterval The refresh interval of the zone * @param retryInterval The retry interval of the zone * @param expirationInterval The expiration interval of the zone * @param minTTL The minimum TTL of the zone * @param TTL The time to live for the resource record * @return An initialized OFSOADNSResourceRecord */ - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass primaryNameServer: (OFString *)primaryNameServer responsiblePerson: (OFString *)responsiblePerson serialNumber: (uint32_t)serialNumber refreshInterval: (uint32_t)refreshInterval retryInterval: (uint32_t)retryInterval expirationInterval: (uint32_t)expirationInterval minTTL: (uint32_t)minTTL TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFSOADNSResourceRecord.m000066400000000000000000000121261465614216400176710ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFSOADNSResourceRecord.h" @implementation OFSOADNSResourceRecord @synthesize primaryNameServer = _primaryNameServer; @synthesize responsiblePerson = _responsiblePerson; @synthesize serialNumber = _serialNumber, refreshInterval = _refreshInterval; @synthesize retryInterval = _retryInterval; @synthesize expirationInterval = _expirationInterval, minTTL = _minTTL; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass primaryNameServer: (OFString *)primaryNameServer responsiblePerson: (OFString *)responsiblePerson serialNumber: (uint32_t)serialNumber refreshInterval: (uint32_t)refreshInterval retryInterval: (uint32_t)retryInterval expirationInterval: (uint32_t)expirationInterval minTTL: (uint32_t)minTTL TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: DNSClass recordType: OFDNSRecordTypeSOA TTL: TTL]; @try { _primaryNameServer = [primaryNameServer copy]; _responsiblePerson = [responsiblePerson copy]; _serialNumber = serialNumber; _refreshInterval = refreshInterval; _retryInterval = retryInterval; _expirationInterval = expirationInterval; _minTTL = minTTL; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_primaryNameServer release]; [_responsiblePerson release]; [super dealloc]; } - (bool)isEqual: (id)object { OFSOADNSResourceRecord *record; if (object == self) return true; if (![object isKindOfClass: [OFSOADNSResourceRecord class]]) return false; record = object; if (record->_name != _name && ![record->_name isEqual: _name]) return false; if (record->_DNSClass != _DNSClass) return false; if (record->_recordType != _recordType) return false; if (record->_primaryNameServer != _primaryNameServer && ![record->_primaryNameServer isEqual: _primaryNameServer]) return false; if (record->_responsiblePerson != _responsiblePerson && ![record->_responsiblePerson isEqual: _responsiblePerson]) return false; if (record->_serialNumber != _serialNumber) return false; if (record->_refreshInterval != _refreshInterval) return false; if (record->_retryInterval != _retryInterval) return false; if (record->_expirationInterval != _expirationInterval) return false; if (record->_minTTL != _minTTL) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddByte(&hash, _DNSClass >> 8); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType >> 8); OFHashAddByte(&hash, _recordType); OFHashAddHash(&hash, _primaryNameServer.hash); OFHashAddHash(&hash, _responsiblePerson.hash); OFHashAddByte(&hash, _serialNumber >> 24); OFHashAddByte(&hash, _serialNumber >> 16); OFHashAddByte(&hash, _serialNumber >> 8); OFHashAddByte(&hash, _serialNumber); OFHashAddByte(&hash, _refreshInterval >> 24); OFHashAddByte(&hash, _refreshInterval >> 16); OFHashAddByte(&hash, _refreshInterval >> 8); OFHashAddByte(&hash, _refreshInterval); OFHashAddByte(&hash, _retryInterval >> 24); OFHashAddByte(&hash, _retryInterval >> 16); OFHashAddByte(&hash, _retryInterval >> 8); OFHashAddByte(&hash, _retryInterval); OFHashAddByte(&hash, _expirationInterval >> 24); OFHashAddByte(&hash, _expirationInterval >> 16); OFHashAddByte(&hash, _expirationInterval >> 8); OFHashAddByte(&hash, _expirationInterval); OFHashAddByte(&hash, _minTTL >> 24); OFHashAddByte(&hash, _minTTL >> 16); OFHashAddByte(&hash, _minTTL >> 8); OFHashAddByte(&hash, _minTTL); OFHashFinalize(&hash); return hash; } - (OFString *)description { return [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tClass = %@\n" @"\tPrimary Name Server = %@\n" @"\tResponsible Person = %@\n" @"\tSerial Number = %" PRIu32 "\n" @"\tRefresh Interval = %" PRIu32 "\n" @"\tRetry Interval = %" PRIu32 "\n" @"\tExpiration Interval = %" PRIu32 "\n" @"\tMinimum TTL = %" PRIu32 "\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFDNSClassName(_DNSClass), _primaryNameServer, _responsiblePerson, _serialNumber, _refreshInterval, _retryInterval, _expirationInterval, _minTTL, _TTL]; } @end objfw-1.1.6/src/OFSPXSocket.h000066400000000000000000000141241465614216400156510ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFSequencedPacketSocket.h" #import "OFRunLoop.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFSPXSocket; @class OFString; #ifdef OF_HAVE_BLOCKS /** * @brief A block which is called when the socket connected. * * @param exception An exception which occurred while connecting the socket or * `nil` on success */ typedef void (^OFSPXSocketAsyncConnectBlock)(id _Nullable exception); #endif /** * @protocol OFSPXSocketDelegate OFSPXSocket.h ObjFW/OFSPXSocket.h * * A delegate for OFSPXSocket. */ @protocol OFSPXSocketDelegate @optional /** * @brief A method which is called when a socket connected. * * @param socket The socket which connected * @param network The network of the node the socket connected to * @param node The node the socket connected to * @param port The port of the node to which the socket connected * @param exception An exception that occurred while connecting, or nil on * success */ - (void)socket: (OFSPXSocket *)socket didConnectToNetwork: (uint32_t)network node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port exception: (nullable id)exception; @end /** * @class OFSPXSocket OFSPXSocket.h ObjFW/OFSPXSocket.h * * @brief A class which provides methods to create and use SPX sockets. * * @note If you want to use SPX in streaming mode instead of in message mode, * use @ref OFSPXStreamSocket instead. * * To connect to a server, create a socket and connect it. * To create a server, create a socket, bind it and listen on it. */ @interface OFSPXSocket: OFSequencedPacketSocket { OF_RESERVE_IVARS(OFSPXSocket, 4) } /** * @brief The delegate for asynchronous operations on the socket. * * @note The delegate is retained for as long as asynchronous operations are * still ongoing. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id delegate; /** * @brief Connect the OFSPXSocket to the specified destination. * * @param network The network on which the node to connect to is * @param node The node to connect to * @param port The port (sometimes also called socket number) on the node to * connect to * @throw OFConnectSPXSocketFailedException Connecting failed * @throw OFAlreadyOpenException The socket is already connected or bound */ - (void)connectToNetwork: (uint32_t)network node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port; /** * @brief Asynchronously connect the OFSPXSocket to the specified destination. * * @param network The network on which the node to connect to is * @param node The node to connect to * @param port The port (sometimes also called socket number) on the node to * connect to */ - (void)asyncConnectToNetwork: (uint32_t)network node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port; /** * @brief Asynchronously connect the OFSPXSocket to the specified destination. * * @param network The network on which the node to connect to is * @param node The node to connect to * @param port The port (sometimes also called socket number) on the node to * connect to * @param runLoopMode The run loop mode in which to perform the asynchronous * connect */ - (void)asyncConnectToNetwork: (uint32_t)network node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously connect the OFSPXSocket to the specified destination. * * @param node The node to connect to * @param network The network on which the node to connect to is * @param port The port (sometimes also called socket number) on the node to * connect to * @param block The block to execute once the connection has been established */ - (void)asyncConnectToNetwork: (uint32_t)network node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port block: (OFSPXSocketAsyncConnectBlock)block; /** * @brief Asynchronously connect the OFSPXSocket to the specified destination. * * @param node The node to connect to * @param network The network on which the node to connect to is * @param port The port (sometimes also called socket number) on the node to * connect to * @param runLoopMode The run loop mode in which to perform the asynchronous * connect * @param block The block to execute once the connection has been established */ - (void)asyncConnectToNetwork: (uint32_t)network node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode block: (OFSPXSocketAsyncConnectBlock)block; #endif /** * @brief Bind the socket to the specified network, node and port. * * @param network The IPX network to bind to. 0 means the current network. * @param node The IPX network to bind to. An all zero node means the * computer's node. * @param port The port (sometimes called socket number) to bind to. 0 means to * pick one and return via the returned socket address. * @return The address on which this socket can be reached * @throw OFBindIPXSocketFailedException Binding failed * @throw OFAlreadyOpenException The socket is already connected or bound */ - (OFSocketAddress) bindToNetwork: (uint32_t)network node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFSPXSocket.m000066400000000000000000000233301465614216400156550ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFSPXSocket.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFAlreadyOpenException.h" #import "OFBindIPXSocketFailedException.h" #import "OFConnectSPXSocketFailedException.h" #import "OFNotOpenException.h" #ifndef NSPROTO_SPX # define NSPROTO_SPX 0 #endif static const uint8_t SPXPacketType = 5; @interface OFSPXSocket () - (int)of_createSocketForAddress: (const OFSocketAddress *)address errNo: (int *)errNo; - (bool)of_connectSocketToAddress: (const OFSocketAddress *)address errNo: (int *)errNo; - (void)of_closeSocket; @end OF_DIRECT_MEMBERS @interface OFSPXSocketAsyncConnectDelegate: OFObject { OFSPXSocket *_socket; uint32_t _network; unsigned char _node[IPX_NODE_LEN]; uint16_t _port; #ifdef OF_HAVE_BLOCKS OFSPXSocketAsyncConnectBlock _block; #endif } - (instancetype)initWithSocket: (OFSPXSocket *)socket network: (uint32_t)network node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port #ifdef OF_HAVE_BLOCKS block: (OFSPXSocketAsyncConnectBlock)block #endif ; - (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode; @end @implementation OFSPXSocketAsyncConnectDelegate - (instancetype)initWithSocket: (OFSPXSocket *)sock network: (uint32_t)network node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port #ifdef OF_HAVE_BLOCKS block: (OFSPXSocketAsyncConnectBlock)block #endif { self = [super init]; @try { _socket = [sock retain]; _network = network; memcpy(_node, node, IPX_NODE_LEN); _port = port; #ifdef OF_HAVE_BLOCKS _block = [block copy]; #endif } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_socket release]; #ifdef OF_HAVE_BLOCKS [_block release]; #endif [super dealloc]; } - (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode { OFSocketAddress address = OFSocketAddressMakeIPX(_network, _node, _port); id exception = nil; int errNo; if (![_socket of_createSocketForAddress: &address errNo: &errNo]) { exception = [self of_connectionFailedExceptionForErrNo: errNo]; goto inform_delegate; } _socket.canBlock = false; if (![_socket of_connectSocketToAddress: &address errNo: &errNo]) { #ifdef OF_WINDOWS if (errNo == EINPROGRESS || errNo == EWOULDBLOCK) { #else if (errNo == EINPROGRESS) { #endif [OFRunLoop of_addAsyncConnectForSocket: _socket mode: runLoopMode delegate: self]; return; } [_socket of_closeSocket]; exception = [self of_connectionFailedExceptionForErrNo: errNo]; } inform_delegate: [self performSelector: @selector(of_socketDidConnect:exception:) withObject: _socket withObject: exception afterDelay: 0]; } - (void)of_socketDidConnect: (id)sock exception: (id)exception { id delegate = ((OFSPXSocket *)sock).delegate; if (exception == nil) ((OFSPXSocket *)sock).canBlock = true; #ifdef OF_HAVE_BLOCKS if (_block != NULL) _block(exception); else { #endif if ([delegate respondsToSelector: @selector(socket:didConnectToNetwork:node:port:exception:)]) [delegate socket: _socket didConnectToNetwork: _network node: _node port: _port exception: exception]; #ifdef OF_HAVE_BLOCKS } #endif } - (id)of_connectionFailedExceptionForErrNo: (int)errNo { return [OFConnectSPXSocketFailedException exceptionWithNetwork: _network node: _node port: _port socket: _socket errNo: errNo]; } @end @implementation OFSPXSocket @dynamic delegate; - (int)of_createSocketForAddress: (const OFSocketAddress *)address errNo: (int *)errNo { #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyOpenException exceptionWithObject: self]; if ((_socket = socket(address->sockaddr.ipx.sipx_family, SOCK_SEQPACKET | SOCK_CLOEXEC, NSPROTO_SPX)) == OFInvalidSocketHandle) { *errNo = _OFSocketErrNo(); return false; } #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); #endif return true; } - (bool)of_connectSocketToAddress: (const OFSocketAddress *)address errNo: (int *)errNo { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; if (connect(_socket, (struct sockaddr *)&address->sockaddr, address->length) != 0) { *errNo = _OFSocketErrNo(); return false; } return true; } - (void)of_closeSocket { closesocket(_socket); _socket = OFInvalidSocketHandle; } - (void)connectToNetwork: (uint32_t)network node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port { OFSocketAddress address = OFSocketAddressMakeIPX(network, node, port); int errNo; if (![self of_createSocketForAddress: &address errNo: &errNo]) @throw [OFConnectSPXSocketFailedException exceptionWithNetwork: network node: node port: port socket: self errNo: errNo]; if (![self of_connectSocketToAddress: &address errNo: &errNo]) { [self of_closeSocket]; @throw [OFConnectSPXSocketFailedException exceptionWithNetwork: network node: node port: port socket: self errNo: errNo]; } } - (void)asyncConnectToNetwork: (uint32_t)network node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port { [self asyncConnectToNetwork: network node: node port: port runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncConnectToNetwork: (uint32_t)network node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode { void *pool = objc_autoreleasePoolPush(); [[[[OFSPXSocketAsyncConnectDelegate alloc] initWithSocket: self network: network node: node port: port #ifdef OF_HAVE_BLOCKS block: NULL #endif ] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS - (void)asyncConnectToNetwork: (uint32_t)network node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port block: (OFSPXSocketAsyncConnectBlock)block { [self asyncConnectToNetwork: network node: node port: port runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncConnectToNetwork: (uint32_t)network node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode block: (OFSPXSocketAsyncConnectBlock)block { void *pool = objc_autoreleasePoolPush(); [[[[OFSPXSocketAsyncConnectDelegate alloc] initWithSocket: self network: network node: node port: port block: block ] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } #endif - (OFSocketAddress)bindToNetwork: (uint32_t)network node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port { OFSocketAddress address; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) int flags; #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyOpenException exceptionWithObject: self]; address = OFSocketAddressMakeIPX(network, node, port); if ((_socket = socket(address.sockaddr.ipx.sipx_family, SOCK_SEQPACKET | SOCK_CLOEXEC, NSPROTO_SPX)) == OFInvalidSocketHandle) @throw [OFBindIPXSocketFailedException exceptionWithNetwork: network node: node port: port packetType: SPXPacketType socket: self errNo: _OFSocketErrNo()]; _canBlock = true; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); #endif if (bind(_socket, (struct sockaddr *)&address.sockaddr, address.length) != 0) { int errNo = _OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindIPXSocketFailedException exceptionWithNetwork: network node: node port: port packetType: SPXPacketType socket: self errNo: errNo]; } memset(&address, 0, sizeof(address)); address.family = OFSocketAddressFamilyIPX; address.length = (socklen_t)sizeof(address.sockaddr); if (_OFGetSockName(_socket, (struct sockaddr *)&address.sockaddr, &address.length) != 0) { int errNo = _OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindIPXSocketFailedException exceptionWithNetwork: network node: node port: port packetType: SPXPacketType socket: self errNo: errNo]; } if (address.sockaddr.ipx.sipx_family != AF_IPX) { closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindIPXSocketFailedException exceptionWithNetwork: network node: node port: port packetType: SPXPacketType socket: self errNo: EAFNOSUPPORT]; } return address; } @end objfw-1.1.6/src/OFSPXStreamSocket.h000066400000000000000000000143261465614216400170310ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFStreamSocket.h" #import "OFRunLoop.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFSPXStreamSocket; @class OFString; #ifdef OF_HAVE_BLOCKS /** * @brief A block which is called when the socket connected. * * @param exception An exception which occurred while connecting the socket or * `nil` on success */ typedef void (^OFSPXStreamSocketAsyncConnectBlock)(id _Nullable exception); #endif /** * @protocol OFSPXStreamSocketDelegate OFSPXStreamSocket.h \ * ObjFW/OFSPXStreamSocket.h * * A delegate for OFSPXStreamSocket. */ @protocol OFSPXStreamSocketDelegate @optional /** * @brief A method which is called when a socket connected. * * @param socket The socket which connected * @param network The network of the node the socket connected to * @param node The node the socket connected to * @param port The port of the node to which the socket connected * @param exception An exception that occurred while connecting, or nil on * success */ - (void)socket: (OFSPXStreamSocket *)socket didConnectToNetwork: (uint32_t)network node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port exception: (nullable id)exception; @end /** * @class OFSPXStreamSocket OFSPXStreamSocket.h ObjFW/OFSPXStreamSocket.h * * @brief A class which provides methods to create and use SPX stream sockets. * * @note If you want to use SPX in message mode instead of in streaming mode, * use @ref OFSPXSocket instead. * * To connect to a server, create a socket and connect it. * To create a server, create a socket, bind it and listen on it. */ @interface OFSPXStreamSocket: OFStreamSocket { OF_RESERVE_IVARS(OFSPXStreamSocket, 4) } /** * @brief The delegate for asynchronous operations on the socket. * * @note The delegate is retained for as long as asynchronous operations are * still ongoing. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id delegate; /** * @brief Connect the OFSPXStreamSocket to the specified destination. * * @param network The network on which the node to connect to is * @param node The node to connect to * @param port The port (sometimes also called socket number) on the node to * connect to * @throw OFConnectSPXSocketFailedException Connecting failed * @throw OFAlreadyOpenException The socket is already connected or bound */ - (void)connectToNetwork: (uint32_t)network node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port; /** * @brief Asynchronously connect the OFSPXStreamSocket to the specified * destination. * * @param network The network on which the node to connect to is * @param node The node to connect to * @param port The port (sometimes also called socket number) on the node to * connect to */ - (void)asyncConnectToNetwork: (uint32_t)network node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port; /** * @brief Asynchronously connect the OFSPXStreamSocket to the specified * destination. * * @param network The network on which the node to connect to is * @param node The node to connect to * @param port The port (sometimes also called socket number) on the node to * connect to * @param runLoopMode The run loop mode in which to perform the asynchronous * connect */ - (void)asyncConnectToNetwork: (uint32_t)network node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously connect the OFSPXStreamSocket to the specified * destination. * * @param network The network on which the node to connect to is * @param node The node to connect to * @param port The port (sometimes also called socket number) on the node to * connect to * @param block The block to execute once the connection has been established */ - (void)asyncConnectToNetwork: (uint32_t)network node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port block: (OFSPXStreamSocketAsyncConnectBlock)block; /** * @brief Asynchronously connect the OFSPXStreamSocket to the specified * destination. * * @param network The network on which the node to connect to is * @param node The node to connect to * @param port The port (sometimes also called socket number) on the node to * connect to * @param runLoopMode The run loop mode in which to perform the asynchronous * connect * @param block The block to execute once the connection has been established */ - (void)asyncConnectToNetwork: (uint32_t)network node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode block: (OFSPXStreamSocketAsyncConnectBlock)block; #endif /** * @brief Bind the socket to the specified network, node and port. * * @param network The IPX network to bind to. 0 means the current network. * @param node The IPX network to bind to. An all zero node means the * computer's node. * @param port The port (sometimes called socket number) to bind to. 0 means to * pick one and return via the returned socket address. * @return The address on which this socket can be reached * @throw OFBindIPXSocketFailedException Binding failed * @throw OFAlreadyOpenException The socket is already connected or bound */ - (OFSocketAddress) bindToNetwork: (uint32_t)network node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFSPXStreamSocket.m000066400000000000000000000235021465614216400170320ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFSPXStreamSocket.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFAlreadyOpenException.h" #import "OFBindIPXSocketFailedException.h" #import "OFConnectSPXSocketFailedException.h" #import "OFNotOpenException.h" #ifndef NSPROTO_SPX # define NSPROTO_SPX 0 #endif static const uint8_t SPXPacketType = 5; @interface OFSPXStreamSocket () - (int)of_createSocketForAddress: (const OFSocketAddress *)address errNo: (int *)errNo; - (bool)of_connectSocketToAddress: (const OFSocketAddress *)address errNo: (int *)errNo; - (void)of_closeSocket; @end OF_DIRECT_MEMBERS @interface OFSPXStreamSocketAsyncConnectDelegate: OFObject { OFSPXStreamSocket *_socket; uint32_t _network; unsigned char _node[IPX_NODE_LEN]; uint16_t _port; #ifdef OF_HAVE_BLOCKS OFSPXStreamSocketAsyncConnectBlock _block; #endif } - (instancetype)initWithSocket: (OFSPXStreamSocket *)socket network: (uint32_t)network node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port #ifdef OF_HAVE_BLOCKS block: (OFSPXStreamSocketAsyncConnectBlock)block #endif ; - (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode; @end @implementation OFSPXStreamSocketAsyncConnectDelegate - (instancetype)initWithSocket: (OFSPXStreamSocket *)sock network: (uint32_t)network node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port #ifdef OF_HAVE_BLOCKS block: (OFSPXStreamSocketAsyncConnectBlock)block #endif { self = [super init]; @try { _socket = [sock retain]; _network = network; memcpy(_node, node, IPX_NODE_LEN); _port = port; #ifdef OF_HAVE_BLOCKS _block = [block copy]; #endif } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_socket release]; #ifdef OF_HAVE_BLOCKS [_block release]; #endif [super dealloc]; } - (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode { OFSocketAddress address = OFSocketAddressMakeIPX(_network, _node, _port); id exception = nil; int errNo; if (![_socket of_createSocketForAddress: &address errNo: &errNo]) { exception = [self of_connectionFailedExceptionForErrNo: errNo]; goto inform_delegate; } _socket.canBlock = false; if (![_socket of_connectSocketToAddress: &address errNo: &errNo]) { #ifdef OF_WINDOWS if (errNo == EINPROGRESS || errNo == EWOULDBLOCK) { #else if (errNo == EINPROGRESS) { #endif [OFRunLoop of_addAsyncConnectForSocket: _socket mode: runLoopMode delegate: self]; return; } [_socket of_closeSocket]; exception = [self of_connectionFailedExceptionForErrNo: errNo]; } inform_delegate: [self performSelector: @selector(of_socketDidConnect:exception:) withObject: _socket withObject: exception afterDelay: 0]; } - (void)of_socketDidConnect: (id)sock exception: (id)exception { id delegate = ((OFSPXStreamSocket *)sock).delegate; if (exception == nil) ((OFSPXStreamSocket *)sock).canBlock = true; #ifdef OF_HAVE_BLOCKS if (_block != NULL) _block(exception); else { #endif if ([delegate respondsToSelector: @selector(socket:didConnectToNetwork:node:port:exception:)]) [delegate socket: _socket didConnectToNetwork: _network node: _node port: _port exception: exception]; #ifdef OF_HAVE_BLOCKS } #endif } - (id)of_connectionFailedExceptionForErrNo: (int)errNo { return [OFConnectSPXSocketFailedException exceptionWithNetwork: _network node: _node port: _port socket: _socket errNo: errNo]; } @end @implementation OFSPXStreamSocket @dynamic delegate; - (int)of_createSocketForAddress: (const OFSocketAddress *)address errNo: (int *)errNo { #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyOpenException exceptionWithObject: self]; if ((_socket = socket(address->sockaddr.ipx.sipx_family, SOCK_STREAM | SOCK_CLOEXEC, NSPROTO_SPX)) == OFInvalidSocketHandle) { *errNo = _OFSocketErrNo(); return false; } #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); #endif return true; } - (bool)of_connectSocketToAddress: (const OFSocketAddress *)address errNo: (int *)errNo { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; if (connect(_socket, (struct sockaddr *)&address->sockaddr, address->length) != 0) { *errNo = _OFSocketErrNo(); return false; } return true; } - (void)of_closeSocket { closesocket(_socket); _socket = OFInvalidSocketHandle; } - (void)connectToNetwork: (uint32_t)network node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port { OFSocketAddress address = OFSocketAddressMakeIPX(network, node, port); int errNo; if (![self of_createSocketForAddress: &address errNo: &errNo]) @throw [OFConnectSPXSocketFailedException exceptionWithNetwork: network node: node port: port socket: self errNo: errNo]; if (![self of_connectSocketToAddress: &address errNo: &errNo]) { [self of_closeSocket]; @throw [OFConnectSPXSocketFailedException exceptionWithNetwork: network node: node port: port socket: self errNo: errNo]; } } - (void)asyncConnectToNetwork: (uint32_t)network node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port { [self asyncConnectToNetwork: network node: node port: port runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncConnectToNetwork: (uint32_t)network node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode { void *pool = objc_autoreleasePoolPush(); [[[[OFSPXStreamSocketAsyncConnectDelegate alloc] initWithSocket: self network: network node: node port: port #ifdef OF_HAVE_BLOCKS block: NULL #endif ] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS - (void)asyncConnectToNetwork: (uint32_t)network node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port block: (OFSPXStreamSocketAsyncConnectBlock)block { [self asyncConnectToNetwork: network node: node port: port runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncConnectToNetwork: (uint32_t)network node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode block: (OFSPXStreamSocketAsyncConnectBlock)block { void *pool = objc_autoreleasePoolPush(); [[[[OFSPXStreamSocketAsyncConnectDelegate alloc] initWithSocket: self network: network node: node port: port block: block ] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } #endif - (OFSocketAddress)bindToNetwork: (uint32_t)network node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port { OFSocketAddress address; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) int flags; #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyOpenException exceptionWithObject: self]; address = OFSocketAddressMakeIPX(network, node, port); if ((_socket = socket(address.sockaddr.ipx.sipx_family, SOCK_STREAM | SOCK_CLOEXEC, NSPROTO_SPX)) == OFInvalidSocketHandle) @throw [OFBindIPXSocketFailedException exceptionWithNetwork: network node: node port: port packetType: SPXPacketType socket: self errNo: _OFSocketErrNo()]; _canBlock = true; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); #endif if (bind(_socket, (struct sockaddr *)&address.sockaddr, address.length) != 0) { int errNo = _OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindIPXSocketFailedException exceptionWithNetwork: network node: node port: port packetType: SPXPacketType socket: self errNo: errNo]; } memset(&address, 0, sizeof(address)); address.family = OFSocketAddressFamilyIPX; address.length = (socklen_t)sizeof(address.sockaddr); if (_OFGetSockName(_socket, (struct sockaddr *)&address.sockaddr, &address.length) != 0) { int errNo = _OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindIPXSocketFailedException exceptionWithNetwork: network node: node port: port packetType: SPXPacketType socket: self errNo: errNo]; } if (address.sockaddr.ipx.sipx_family != AF_IPX) { closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindIPXSocketFailedException exceptionWithNetwork: network node: node port: port packetType: SPXPacketType socket: self errNo: EAFNOSUPPORT]; } return address; } @end objfw-1.1.6/src/OFSRVDNSResourceRecord.h000066400000000000000000000046601465614216400177200ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFDNSResourceRecord.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFSRVDNSResourceRecord \ * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h * * @brief A class representing an SRV DNS resource record. */ OF_SUBCLASSING_RESTRICTED @interface OFSRVDNSResourceRecord: OFDNSResourceRecord { uint16_t _priority, _weight; OFString *_target; uint16_t _port; } /** * @brief The priority of the resource record. */ @property (readonly, nonatomic) uint16_t priority; /** * @brief The weight of the resource record. */ @property (readonly, nonatomic) uint16_t weight; /** * @brief The target of the resource record. */ @property (readonly, nonatomic) OFString *target; /** * @brief The port on the target of the resource record. */ @property (readonly, nonatomic) uint16_t port; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFSRVDNSResourceRecord with the * specified name, priority, weight, target, port and time to live. * * @param name The name for the resource record * @param priority The priority for the resource record * @param weight The weight for the resource record * @param target The target for the resource record * @param port The port on the target for the resource record * @param TTL The time to live for the resource record * @return An initialized OFSRVDNSResourceRecord */ - (instancetype)initWithName: (OFString *)name priority: (uint16_t)priority weight: (uint16_t)weight target: (OFString *)target port: (uint16_t)port TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFSRVDNSResourceRecord.m000066400000000000000000000061511465614216400177220ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFSRVDNSResourceRecord.h" @implementation OFSRVDNSResourceRecord @synthesize priority = _priority, weight = _weight, target = _target; @synthesize port = _port; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name priority: (uint16_t)priority weight: (uint16_t)weight target: (OFString *)target port: (uint16_t)port TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: OFDNSClassIN recordType: OFDNSRecordTypeSRV TTL: TTL]; @try { _priority = priority; _weight = weight; _target = [target copy]; _port = port; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_target release]; [super dealloc]; } - (bool)isEqual: (id)object { OFSRVDNSResourceRecord *record; if (object == self) return true; if (![object isKindOfClass: [OFSRVDNSResourceRecord class]]) return false; record = object; if (record->_name != _name && ![record->_name isEqual: _name]) return false; if (record->_DNSClass != _DNSClass) return false; if (record->_recordType != _recordType) return false; if (record->_priority != _priority) return false; if (record->_weight != _weight) return false; if (record->_target != _target && ![record->_target isEqual: _target]) return false; if (record->_port != _port) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddByte(&hash, _DNSClass >> 8); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType >> 8); OFHashAddByte(&hash, _recordType); OFHashAddByte(&hash, _priority >> 8); OFHashAddByte(&hash, _priority); OFHashAddByte(&hash, _weight >> 8); OFHashAddByte(&hash, _weight); OFHashAddHash(&hash, _target.hash); OFHashAddByte(&hash, _port >> 8); OFHashAddByte(&hash, _port); OFHashFinalize(&hash); return hash; } - (OFString *)description { return [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tPriority = %" PRIu16 "\n" @"\tWeight = %" PRIu16 "\n" @"\tTarget = %@\n" @"\tPort = %" PRIu16 "\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, _priority, _weight, _target, _port, _TTL]; } @end objfw-1.1.6/src/OFSandbox.h000066400000000000000000000075431465614216400154330ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFMutableArray OF_GENERIC(ObjectType); @class OFPair OF_GENERIC(FirstType, SecondType); typedef OFPair OF_GENERIC(OFString *, OFString *) *OFSandboxUnveilPath; OF_SUBCLASSING_RESTRICTED @interface OFSandbox: OFObject { unsigned int _allowsStdIO: 1; unsigned int _allowsReadingFiles: 1; unsigned int _allowsWritingFiles: 1; unsigned int _allowsCreatingFiles: 1; unsigned int _allowsCreatingSpecialFiles: 1; unsigned int _allowsTemporaryFiles: 1; unsigned int _allowsIPSockets: 1; unsigned int _allowsMulticastSockets: 1; unsigned int _allowsChangingFileAttributes: 1; unsigned int _allowsFileOwnerChanges: 1; unsigned int _allowsFileLocks: 1; unsigned int _allowsUNIXSockets: 1; unsigned int _allowsDNS: 1; unsigned int _allowsUserDatabaseReading: 1; unsigned int _allowsFileDescriptorSending: 1; unsigned int _allowsFileDescriptorReceiving: 1; unsigned int _allowsTape: 1; unsigned int _allowsTTY: 1; unsigned int _allowsProcessOperations: 1; unsigned int _allowsExec: 1; unsigned int _allowsProtExec: 1; unsigned int _allowsSetTime: 1; unsigned int _allowsPS: 1; unsigned int _allowsVMInfo: 1; unsigned int _allowsChangingProcessRights: 1; unsigned int _allowsPF: 1; unsigned int _allowsAudio: 1; unsigned int _allowsBPF: 1; unsigned int _allowsUnveil: 1; unsigned int _returnsErrors: 1; OFMutableArray OF_GENERIC(OFSandboxUnveilPath) *_unveiledPaths; @public size_t _unveiledPathsIndex; } @property (nonatomic) bool allowsStdIO; @property (nonatomic) bool allowsReadingFiles; @property (nonatomic) bool allowsWritingFiles; @property (nonatomic) bool allowsCreatingFiles; @property (nonatomic) bool allowsCreatingSpecialFiles; @property (nonatomic) bool allowsTemporaryFiles; @property (nonatomic) bool allowsIPSockets; @property (nonatomic) bool allowsMulticastSockets; @property (nonatomic) bool allowsChangingFileAttributes; @property (nonatomic) bool allowsFileOwnerChanges; @property (nonatomic) bool allowsFileLocks; @property (nonatomic) bool allowsUNIXSockets; @property (nonatomic) bool allowsDNS; @property (nonatomic) bool allowsUserDatabaseReading; @property (nonatomic) bool allowsFileDescriptorSending; @property (nonatomic) bool allowsFileDescriptorReceiving; @property (nonatomic) bool allowsTape; @property (nonatomic) bool allowsTTY; @property (nonatomic) bool allowsProcessOperations; @property (nonatomic) bool allowsExec; @property (nonatomic) bool allowsProtExec; @property (nonatomic) bool allowsSetTime; @property (nonatomic) bool allowsPS; @property (nonatomic) bool allowsVMInfo; @property (nonatomic) bool allowsChangingProcessRights; @property (nonatomic) bool allowsPF; @property (nonatomic) bool allowsAudio; @property (nonatomic) bool allowsBPF; @property (nonatomic) bool allowsUnveil; @property (nonatomic) bool returnsErrors; #ifdef OF_HAVE_PLEDGE @property (readonly, nonatomic) OFString *pledgeString; #endif @property (readonly, nonatomic) OFArray OF_GENERIC(OFSandboxUnveilPath) *unveiledPaths; + (instancetype)sandbox; - (void)unveilPath: (OFString *)path permissions: (OFString *)permissions; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFSandbox.m000066400000000000000000000323651465614216400154400ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFSandbox.h" #import "OFArray.h" #import "OFPair.h" #import "OFString.h" @implementation OFSandbox @synthesize unveiledPaths = _unveiledPaths; + (instancetype)sandbox { return [[[self alloc] init] autorelease]; } - (instancetype)init { self = [super init]; @try { _unveiledPaths = [[OFMutableArray alloc] init]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_unveiledPaths release]; [super dealloc]; } - (void)setAllowsStdIO: (bool)allowsStdIO { _allowsStdIO = allowsStdIO; } - (bool)allowsStdIO { return _allowsStdIO; } - (void)setAllowsReadingFiles: (bool)allowsReadingFiles { _allowsReadingFiles = allowsReadingFiles; } - (bool)allowsReadingFiles { return _allowsReadingFiles; } - (void)setAllowsWritingFiles: (bool)allowsWritingFiles { _allowsWritingFiles = allowsWritingFiles; } - (bool)allowsWritingFiles { return _allowsWritingFiles; } - (void)setAllowsCreatingFiles: (bool)allowsCreatingFiles { _allowsCreatingFiles = allowsCreatingFiles; } - (bool)allowsCreatingFiles { return _allowsCreatingFiles; } - (void)setAllowsCreatingSpecialFiles: (bool)allowsCreatingSpecialFiles { _allowsCreatingSpecialFiles = allowsCreatingSpecialFiles; } - (bool)allowsCreatingSpecialFiles { return _allowsCreatingSpecialFiles; } - (void)setAllowsTemporaryFiles: (bool)allowsTemporaryFiles { _allowsTemporaryFiles = allowsTemporaryFiles; } - (bool)allowsTemporaryFiles { return _allowsTemporaryFiles; } - (void)setAllowsIPSockets: (bool)allowsIPSockets { _allowsIPSockets = allowsIPSockets; } - (bool)allowsIPSockets { return _allowsIPSockets; } - (void)setAllowsMulticastSockets: (bool)allowsMulticastSockets { _allowsMulticastSockets = allowsMulticastSockets; } - (bool)allowsMulticastSockets { return _allowsMulticastSockets; } - (void)setAllowsChangingFileAttributes: (bool)allowsChangingFileAttributes { _allowsChangingFileAttributes = allowsChangingFileAttributes; } - (bool)allowsChangingFileAttributes { return _allowsChangingFileAttributes; } - (void)setAllowsFileOwnerChanges: (bool)allowsFileOwnerChanges { _allowsFileOwnerChanges = allowsFileOwnerChanges; } - (bool)allowsFileOwnerChanges { return _allowsFileOwnerChanges; } - (void)setAllowsFileLocks: (bool)allowsFileLocks { _allowsFileLocks = allowsFileLocks; } - (bool)allowsFileLocks { return _allowsFileLocks; } - (void)setAllowsUNIXSockets: (bool)allowsUNIXSockets { _allowsUNIXSockets = allowsUNIXSockets; } - (bool)allowsUNIXSockets { return _allowsUNIXSockets; } - (void)setAllowsDNS: (bool)allowsDNS { _allowsDNS = allowsDNS; } - (bool)allowsDNS { return _allowsDNS; } - (void)setAllowsUserDatabaseReading: (bool)allowsUserDatabaseReading { _allowsUserDatabaseReading = allowsUserDatabaseReading; } - (bool)allowsUserDatabaseReading { return _allowsUserDatabaseReading; } - (void)setAllowsFileDescriptorSending: (bool)allowsFileDescriptorSending { _allowsFileDescriptorSending = allowsFileDescriptorSending; } - (bool)allowsFileDescriptorSending { return _allowsFileDescriptorSending; } - (void)setAllowsFileDescriptorReceiving: (bool)allowsFileDescriptorReceiving { _allowsFileDescriptorReceiving = allowsFileDescriptorReceiving; } - (bool)allowsFileDescriptorReceiving { return _allowsFileDescriptorReceiving; } - (void)setAllowsTape: (bool)allowsTape { _allowsTape = allowsTape; } - (bool)allowsTape { return _allowsTape; } - (void)setAllowsTTY: (bool)allowsTTY { _allowsTTY = allowsTTY; } - (bool)allowsTTY { return _allowsTTY; } - (void)setAllowsProcessOperations: (bool)allowsProcessOperations { _allowsProcessOperations = allowsProcessOperations; } - (bool)allowsProcessOperations { return _allowsProcessOperations; } - (void)setAllowsExec: (bool)allowsExec { _allowsExec = allowsExec; } - (bool)allowsExec { return _allowsExec; } - (void)setAllowsProtExec: (bool)allowsProtExec { _allowsProtExec = allowsProtExec; } - (bool)allowsProtExec { return _allowsProtExec; } - (void)setAllowsSetTime: (bool)allowsSetTime { _allowsSetTime = allowsSetTime; } - (bool)allowsSetTime { return _allowsSetTime; } - (void)setAllowsPS: (bool)allowsPS { _allowsPS = allowsPS; } - (bool)allowsPS { return _allowsPS; } - (void)setAllowsVMInfo: (bool)allowsVMInfo { _allowsVMInfo = allowsVMInfo; } - (bool)allowsVMInfo { return _allowsVMInfo; } - (void)setAllowsChangingProcessRights: (bool)allowsChangingProcessRights { _allowsChangingProcessRights = allowsChangingProcessRights; } - (bool)allowsChangingProcessRights { return _allowsChangingProcessRights; } - (void)setAllowsPF: (bool)allowsPF { _allowsPF = allowsPF; } - (bool)allowsPF { return _allowsPF; } - (void)setAllowsAudio: (bool)allowsAudio { _allowsAudio = allowsAudio; } - (bool)allowsAudio { return _allowsAudio; } - (void)setAllowsBPF: (bool)allowsBPF { _allowsBPF = allowsBPF; } - (bool)allowsBPF { return _allowsBPF; } - (void)setAllowsUnveil: (bool)allowsUnveil { _allowsUnveil = allowsUnveil; } - (bool)allowsUnveil { return _allowsUnveil; } - (void)setReturnsErrors: (bool)returnsErrors { _returnsErrors = returnsErrors; } - (bool)returnsErrors { return _returnsErrors; } - (id)copy { OFSandbox *copy = [[OFSandbox alloc] init]; copy->_allowsStdIO = _allowsStdIO; copy->_allowsReadingFiles = _allowsReadingFiles; copy->_allowsWritingFiles = _allowsWritingFiles; copy->_allowsCreatingFiles = _allowsCreatingFiles; copy->_allowsCreatingSpecialFiles = _allowsCreatingSpecialFiles; copy->_allowsTemporaryFiles = _allowsTemporaryFiles; copy->_allowsIPSockets = _allowsIPSockets; copy->_allowsMulticastSockets = _allowsMulticastSockets; copy->_allowsChangingFileAttributes = _allowsChangingFileAttributes; copy->_allowsFileOwnerChanges = _allowsFileOwnerChanges; copy->_allowsFileLocks = _allowsFileLocks; copy->_allowsUNIXSockets = _allowsUNIXSockets; copy->_allowsDNS = _allowsDNS; copy->_allowsUserDatabaseReading = _allowsUserDatabaseReading; copy->_allowsFileDescriptorSending = _allowsFileDescriptorSending; copy->_allowsFileDescriptorReceiving = _allowsFileDescriptorReceiving; copy->_allowsTape = _allowsTape; copy->_allowsTTY = _allowsTTY; copy->_allowsProcessOperations = _allowsProcessOperations; copy->_allowsExec = _allowsExec; copy->_allowsProtExec = _allowsProtExec; copy->_allowsSetTime = _allowsSetTime; copy->_allowsPS = _allowsPS; copy->_allowsVMInfo = _allowsVMInfo; copy->_allowsChangingProcessRights = _allowsChangingProcessRights; copy->_allowsPF = _allowsPF; copy->_allowsAudio = _allowsAudio; copy->_allowsBPF = _allowsBPF; copy->_allowsUnveil = _allowsUnveil; copy->_returnsErrors = _returnsErrors; return copy; } - (bool)isEqual: (id)object { OFSandbox *sandbox; if (object == self) return true; if (![object isKindOfClass: [OFSandbox class]]) return false; sandbox = object; if (sandbox->_allowsStdIO != _allowsStdIO) return false; if (sandbox->_allowsReadingFiles != _allowsReadingFiles) return false; if (sandbox->_allowsWritingFiles != _allowsWritingFiles) return false; if (sandbox->_allowsCreatingFiles != _allowsCreatingFiles) return false; if (sandbox->_allowsCreatingSpecialFiles != _allowsCreatingSpecialFiles) return false; if (sandbox->_allowsTemporaryFiles != _allowsTemporaryFiles) return false; if (sandbox->_allowsIPSockets != _allowsIPSockets) return false; if (sandbox->_allowsMulticastSockets != _allowsMulticastSockets) return false; if (sandbox->_allowsChangingFileAttributes != _allowsChangingFileAttributes) return false; if (sandbox->_allowsFileOwnerChanges != _allowsFileOwnerChanges) return false; if (sandbox->_allowsFileLocks != _allowsFileLocks) return false; if (sandbox->_allowsUNIXSockets != _allowsUNIXSockets) return false; if (sandbox->_allowsDNS != _allowsDNS) return false; if (sandbox->_allowsUserDatabaseReading != _allowsUserDatabaseReading) return false; if (sandbox->_allowsFileDescriptorSending != _allowsFileDescriptorSending) return false; if (sandbox->_allowsFileDescriptorReceiving != _allowsFileDescriptorReceiving) return false; if (sandbox->_allowsTape != _allowsTape) return false; if (sandbox->_allowsTTY != _allowsTTY) return false; if (sandbox->_allowsProcessOperations != _allowsProcessOperations) return false; if (sandbox->_allowsExec != _allowsExec) return false; if (sandbox->_allowsProtExec != _allowsProtExec) return false; if (sandbox->_allowsSetTime != _allowsSetTime) return false; if (sandbox->_allowsPS != _allowsPS) return false; if (sandbox->_allowsVMInfo != _allowsVMInfo) return false; if (sandbox->_allowsChangingProcessRights != _allowsChangingProcessRights) return false; if (sandbox->_allowsPF != _allowsPF) return false; if (sandbox->_allowsAudio != _allowsAudio) return false; if (sandbox->_allowsBPF != _allowsBPF) return false; if (sandbox->_allowsUnveil != _allowsUnveil) return false; if (sandbox->_returnsErrors != _returnsErrors) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddByte(&hash, _allowsStdIO); OFHashAddByte(&hash, _allowsReadingFiles); OFHashAddByte(&hash, _allowsWritingFiles); OFHashAddByte(&hash, _allowsCreatingFiles); OFHashAddByte(&hash, _allowsCreatingSpecialFiles); OFHashAddByte(&hash, _allowsTemporaryFiles); OFHashAddByte(&hash, _allowsIPSockets); OFHashAddByte(&hash, _allowsMulticastSockets); OFHashAddByte(&hash, _allowsChangingFileAttributes); OFHashAddByte(&hash, _allowsFileOwnerChanges); OFHashAddByte(&hash, _allowsFileLocks); OFHashAddByte(&hash, _allowsUNIXSockets); OFHashAddByte(&hash, _allowsDNS); OFHashAddByte(&hash, _allowsUserDatabaseReading); OFHashAddByte(&hash, _allowsFileDescriptorSending); OFHashAddByte(&hash, _allowsFileDescriptorReceiving); OFHashAddByte(&hash, _allowsTape); OFHashAddByte(&hash, _allowsTTY); OFHashAddByte(&hash, _allowsProcessOperations); OFHashAddByte(&hash, _allowsExec); OFHashAddByte(&hash, _allowsProtExec); OFHashAddByte(&hash, _allowsSetTime); OFHashAddByte(&hash, _allowsPS); OFHashAddByte(&hash, _allowsVMInfo); OFHashAddByte(&hash, _allowsChangingProcessRights); OFHashAddByte(&hash, _allowsPF); OFHashAddByte(&hash, _allowsAudio); OFHashAddByte(&hash, _allowsBPF); OFHashAddByte(&hash, _allowsUnveil); OFHashAddByte(&hash, _returnsErrors); OFHashFinalize(&hash); return hash; } #ifdef OF_HAVE_PLEDGE - (OFString *)pledgeString { void *pool = objc_autoreleasePoolPush(); OFMutableArray *pledges = [OFMutableArray array]; OFString *ret; if (_allowsStdIO) [pledges addObject: @"stdio"]; if (_allowsReadingFiles) [pledges addObject: @"rpath"]; if (_allowsWritingFiles) [pledges addObject: @"wpath"]; if (_allowsCreatingFiles) [pledges addObject: @"cpath"]; if (_allowsCreatingSpecialFiles) [pledges addObject: @"dpath"]; if (_allowsTemporaryFiles) [pledges addObject: @"tmppath"]; if (_allowsIPSockets) [pledges addObject: @"inet"]; if (_allowsMulticastSockets) [pledges addObject: @"mcast"]; if (_allowsChangingFileAttributes) [pledges addObject: @"fattr"]; if (_allowsFileOwnerChanges) [pledges addObject: @"chown"]; if (_allowsFileLocks) [pledges addObject: @"flock"]; if (_allowsUNIXSockets) [pledges addObject: @"unix"]; if (_allowsDNS) [pledges addObject: @"dns"]; if (_allowsUserDatabaseReading) [pledges addObject: @"getpw"]; if (_allowsFileDescriptorSending) [pledges addObject: @"sendfd"]; if (_allowsFileDescriptorReceiving) [pledges addObject: @"recvfd"]; if (_allowsTape) [pledges addObject: @"tape"]; if (_allowsTTY) [pledges addObject: @"tty"]; if (_allowsProcessOperations) [pledges addObject: @"proc"]; if (_allowsExec) [pledges addObject: @"exec"]; if (_allowsProtExec) [pledges addObject: @"prot_exec"]; if (_allowsSetTime) [pledges addObject: @"settime"]; if (_allowsPS) [pledges addObject: @"ps"]; if (_allowsVMInfo) [pledges addObject: @"vminfo"]; if (_allowsChangingProcessRights) [pledges addObject: @"id"]; if (_allowsPF) [pledges addObject: @"pf"]; if (_allowsAudio) [pledges addObject: @"audio"]; if (_allowsBPF) [pledges addObject: @"bpf"]; if (_allowsUnveil) [pledges addObject: @"unveil"]; if (_returnsErrors) [pledges addObject: @"error"]; ret = [pledges componentsJoinedByString: @" "]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } #endif - (void)unveilPath: (OFString *)path permissions: (OFString *)permissions { void *pool = objc_autoreleasePoolPush(); [_unveiledPaths addObject: [OFPair pairWithFirstObject: path secondObject: permissions]]; objc_autoreleasePoolPop(pool); } - (OFArray OF_GENERIC(OFSandboxUnveilPath) *)unveiledPaths { return [[_unveiledPaths copy] autorelease]; } @end objfw-1.1.6/src/OFScrypt.h000066400000000000000000000044701465614216400153150ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif #import "macros.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFHMAC; /** * @brief The parameters for @ref OFScrypt. */ typedef struct { /** @brief The block size to use. */ size_t blockSize; /** @brief The CPU/memory cost factor to use. */ size_t costFactor; /** @brief The parallelization to use. */ size_t parallelization; /** @brief The salt to derive a key with. */ const unsigned char *salt; /** @brief The length of the salt. */ size_t saltLength; /** @brief The password to derive a key from. */ const char *password; /** @brief The length of the password. */ size_t passwordLength; /** @brief The buffer to write the key to. */ unsigned char *key; /** * @brief The desired length for the derived key. * * @ref key needs to have enough storage. */ size_t keyLength; /** @brief Whether data may be stored in swappable memory. */ bool allowsSwappableMemory; } OFScryptParameters; #ifdef __cplusplus extern "C" { #endif /* No OF_VISIBILITY_HIDDEN so tests can call it. */ extern void _OFSalsa20_8Core(uint32_t buffer[_Nonnull 16]); extern void _OFScryptBlockMix(uint32_t *output, const uint32_t *input, size_t blockSize); extern void _OFScryptROMix(uint32_t *buffer, size_t blockSize, size_t costFactor, uint32_t *tmp); /** * @brief Derives a key from a password and a salt using scrypt. * * @param parameters The parameters to use */ extern void OFScrypt(OFScryptParameters parameters); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFScrypt.m000066400000000000000000000156751465614216400153330ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFHMAC.h" #import "OFSHA256Hash.h" #import "OFSecureData.h" #import "OFInvalidArgumentException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFScrypt.h" #import "OFPBKDF2.h" void _OFSalsa20_8Core(uint32_t buffer[16]) { uint32_t tmp[16]; for (uint_fast8_t i = 0; i < 16; i++) tmp[i] = OFToLittleEndian32(buffer[i]); for (uint_fast8_t i = 0; i < 8; i += 2) { tmp[ 4] ^= OFRotateLeft(tmp[ 0] + tmp[12], 7); tmp[ 8] ^= OFRotateLeft(tmp[ 4] + tmp[ 0], 9); tmp[12] ^= OFRotateLeft(tmp[ 8] + tmp[ 4], 13); tmp[ 0] ^= OFRotateLeft(tmp[12] + tmp[ 8], 18); tmp[ 9] ^= OFRotateLeft(tmp[ 5] + tmp[ 1], 7); tmp[13] ^= OFRotateLeft(tmp[ 9] + tmp[ 5], 9); tmp[ 1] ^= OFRotateLeft(tmp[13] + tmp[ 9], 13); tmp[ 5] ^= OFRotateLeft(tmp[ 1] + tmp[13], 18); tmp[14] ^= OFRotateLeft(tmp[10] + tmp[ 6], 7); tmp[ 2] ^= OFRotateLeft(tmp[14] + tmp[10], 9); tmp[ 6] ^= OFRotateLeft(tmp[ 2] + tmp[14], 13); tmp[10] ^= OFRotateLeft(tmp[ 6] + tmp[ 2], 18); tmp[ 3] ^= OFRotateLeft(tmp[15] + tmp[11], 7); tmp[ 7] ^= OFRotateLeft(tmp[ 3] + tmp[15], 9); tmp[11] ^= OFRotateLeft(tmp[ 7] + tmp[ 3], 13); tmp[15] ^= OFRotateLeft(tmp[11] + tmp[ 7], 18); tmp[ 1] ^= OFRotateLeft(tmp[ 0] + tmp[ 3], 7); tmp[ 2] ^= OFRotateLeft(tmp[ 1] + tmp[ 0], 9); tmp[ 3] ^= OFRotateLeft(tmp[ 2] + tmp[ 1], 13); tmp[ 0] ^= OFRotateLeft(tmp[ 3] + tmp[ 2], 18); tmp[ 6] ^= OFRotateLeft(tmp[ 5] + tmp[ 4], 7); tmp[ 7] ^= OFRotateLeft(tmp[ 6] + tmp[ 5], 9); tmp[ 4] ^= OFRotateLeft(tmp[ 7] + tmp[ 6], 13); tmp[ 5] ^= OFRotateLeft(tmp[ 4] + tmp[ 7], 18); tmp[11] ^= OFRotateLeft(tmp[10] + tmp[ 9], 7); tmp[ 8] ^= OFRotateLeft(tmp[11] + tmp[10], 9); tmp[ 9] ^= OFRotateLeft(tmp[ 8] + tmp[11], 13); tmp[10] ^= OFRotateLeft(tmp[ 9] + tmp[ 8], 18); tmp[12] ^= OFRotateLeft(tmp[15] + tmp[14], 7); tmp[13] ^= OFRotateLeft(tmp[12] + tmp[15], 9); tmp[14] ^= OFRotateLeft(tmp[13] + tmp[12], 13); tmp[15] ^= OFRotateLeft(tmp[14] + tmp[13], 18); } for (uint_fast8_t i = 0; i < 16; i++) buffer[i] = OFToLittleEndian32(OFFromLittleEndian32(buffer[i]) + tmp[i]); OFZeroMemory(tmp, sizeof(tmp)); } void _OFScryptBlockMix(uint32_t *output, const uint32_t *input, size_t blockSize) { uint32_t tmp[16]; /* Check defined here and executed in OFScrypt() */ #define OVERFLOW_CHECK_1 \ if (param.blockSize > SIZE_MAX / 2 || \ 2 * param.blockSize - 1 > SIZE_MAX / 16) \ @throw [OFOutOfRangeException exception]; memcpy(tmp, input + (2 * blockSize - 1) * 16, 64); for (size_t i = 0; i < 2 * blockSize; i++) { for (size_t j = 0; j < 16; j++) tmp[j] ^= input[i * 16 + j]; _OFSalsa20_8Core(tmp); /* * Even indices are stored in the first half and odd ones in * the second. */ memcpy(output + ((i / 2) + (i & 1) * blockSize) * 16, tmp, 64); } OFZeroMemory(tmp, sizeof(tmp)); } void _OFScryptROMix(uint32_t *buffer, size_t blockSize, size_t costFactor, uint32_t *tmp) { /* Check defined here and executed in OFScrypt() */ #define OVERFLOW_CHECK_2 \ if (param.blockSize > SIZE_MAX / 128 / param.costFactor) \ @throw [OFOutOfRangeException exception]; uint32_t *tmp2 = tmp + 32 * blockSize; memcpy(tmp, buffer, 128 * blockSize); for (size_t i = 0; i < costFactor; i++) { memcpy(tmp2 + i * 32 * blockSize, tmp, 128 * blockSize); _OFScryptBlockMix(tmp, tmp2 + i * 32 * blockSize, blockSize); } for (size_t i = 0; i < costFactor; i++) { uint32_t j = OFFromLittleEndian32( tmp[(2 * blockSize - 1) * 16]) & (costFactor - 1); for (size_t k = 0; k < 32 * blockSize; k++) tmp[k] ^= tmp2[j * 32 * blockSize + k]; _OFScryptBlockMix(buffer, tmp, blockSize); if (i < costFactor - 1) memcpy(tmp, buffer, 128 * blockSize); } } void OFScrypt(OFScryptParameters param) { OFSecureData *tmp = nil, *buffer = nil; OFHMAC *HMAC = nil; if (param.blockSize == 0 || param.costFactor <= 1 || (param.costFactor & (param.costFactor - 1)) != 0 || param.parallelization == 0) @throw [OFInvalidArgumentException exception]; /* * These are defined by the functions above. They are defined there so * that the check is next to the code and easy to verify, but actually * checked here for performance. */ OVERFLOW_CHECK_1 OVERFLOW_CHECK_2 @try { uint32_t *tmpItems, *bufferItems; if (param.costFactor > SIZE_MAX - 1 || (param.costFactor + 1) > SIZE_MAX / 128) @throw [OFOutOfRangeException exception]; tmp = [[OFSecureData alloc] initWithCount: (param.costFactor + 1) * 128 itemSize: param.blockSize allowsSwappableMemory: param.allowsSwappableMemory]; tmpItems = tmp.mutableItems; if (param.parallelization > SIZE_MAX / 128) @throw [OFOutOfRangeException exception]; buffer = [[OFSecureData alloc] initWithCount: param.parallelization * 128 itemSize: param.blockSize allowsSwappableMemory: param.allowsSwappableMemory]; bufferItems = buffer.mutableItems; HMAC = [[OFHMAC alloc] initWithHashClass: [OFSHA256Hash class] allowsSwappableMemory: param.allowsSwappableMemory]; OFPBKDF2((OFPBKDF2Parameters){ .HMAC = HMAC, .iterations = 1, .salt = param.salt, .saltLength = param.saltLength, .password = param.password, .passwordLength = param.passwordLength, .key = (unsigned char *)bufferItems, .keyLength = param.parallelization * 128 * param.blockSize, .allowsSwappableMemory = param.allowsSwappableMemory }); for (size_t i = 0; i < param.parallelization; i++) _OFScryptROMix(bufferItems + i * 32 * param.blockSize, param.blockSize, param.costFactor, tmpItems); OFPBKDF2((OFPBKDF2Parameters){ .HMAC = HMAC, .iterations = 1, .salt = (unsigned char *)bufferItems, .saltLength = param.parallelization * 128 * param.blockSize, .password = param.password, .passwordLength = param.passwordLength, .key = param.key, .keyLength = param.keyLength, .allowsSwappableMemory = param.allowsSwappableMemory }); } @finally { [tmp release]; [buffer release]; [HMAC release]; } } objfw-1.1.6/src/OFSecureData.h000066400000000000000000000160501465614216400160460ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFData.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFSecureData OFSecureData.h ObjFW/OFSecureData.h * * @brief A class for storing arbitrary data in secure (non-swappable) memory, * securely wiping it when it gets deallocated. * * @warning Non-swappable memory might be unavailable, in which case this falls * back to swappable memory, but still wipes the data when it gets * deallocated. Check the @ref allowsSwappableMemory property to see * whether a particular OFSecureData might be allocated in swappable * memory. */ OF_SUBCLASSING_RESTRICTED @interface OFSecureData: OFData { unsigned char *_Nullable _items; size_t _count, _itemSize; bool _freeWhenDone, _allowsSwappableMemory; void *_page; } /** * @brief Whether the data may be stored in swappable memory. */ @property (readonly, nonatomic) bool allowsSwappableMemory; /** * @brief All items of the OFSecureData as a C array. * * Modifying the returned array directly is allowed and will change the contents * of the data. */ @property (readonly, nonatomic) void *mutableItems OF_RETURNS_INNER_POINTER; /** * @brief Preallocates the specified number of bytes for unswappable memory. * * This is useful to allocate unswappable memory before enabling a sandbox that * does not allow it anymore. * * @note This may only be called once per thread! * @note Preallocated unswappable memory is only available for data that is * smaller than a single page! * * @param size The number of bytes of unswappable memory to preallocate */ + (void)preallocateUnswappableMemoryWithSize: (size_t)size; /** * @brief Creates a new, autoreleased OFSecureData with `count` items of item * size 1, all set to zero. * * @param count The number of zero items the OFSecureData should contain * @param allowsSwappableMemory Whether the data may be stored in swappable * memory * @return A new, autoreleased OFSecureData */ + (instancetype)dataWithCount: (size_t)count allowsSwappableMemory: (bool)allowsSwappableMemory; /** * @brief Creates a new, autoreleased OFSecureData with `count` items of the * specified item size, all set to zero. * * @param count The number of zero items the OFSecureData should contain * @param itemSize The size of a single item in the OFSecureData in bytes * @param allowsSwappableMemory Whether the data may be stored in swappable * memory * @return A new, autoreleased OFSecureData */ + (instancetype)dataWithCount: (size_t)count itemSize: (size_t)itemSize allowsSwappableMemory: (bool)allowsSwappableMemory; + (instancetype)dataWithItems: (const void *)items count: (size_t)count OF_UNAVAILABLE; + (instancetype)dataWithItems: (const void *)items count: (size_t)count itemSize: (size_t)itemSize OF_UNAVAILABLE; + (instancetype)dataWithItemsNoCopy: (void *)items count: (size_t)count freeWhenDone: (bool)freeWhenDone OF_UNAVAILABLE; + (instancetype)dataWithItemsNoCopy: (void *)items count: (size_t)count itemSize: (size_t)itemSize freeWhenDone: (bool)freeWhenDone OF_UNAVAILABLE; #ifdef OF_HAVE_FILES + (instancetype)dataWithContentsOfFile: (OFString *)path OF_UNAVAILABLE; #endif + (instancetype)dataWithContentsOfIRI: (OFIRI *)IRI OF_UNAVAILABLE; + (instancetype)dataWithStringRepresentation: (OFString *)string OF_UNAVAILABLE; + (instancetype)dataWithBase64EncodedString: (OFString *)string OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFSecureData with `count` items of * item size 1, all set to zero. * * @param count The number of zero items the OFSecureData should contain * @param allowsSwappableMemory Whether the data may be stored in swappable * memory * @return An initialized OFSecureData */ - (instancetype)initWithCount: (size_t)count allowsSwappableMemory: (bool)allowsSwappableMemory; /** * @brief Initializes an already allocated OFSecureData with `count` items of * the specified item size, all set to zero. * * @param itemSize The size of a single item in the OFSecureData in bytes * @param count The number of zero items the OFSecureData should contain * @param allowsSwappableMemory Whether the data may be stored in swappable * memory * @return An initialized OFSecureData */ - (instancetype)initWithCount: (size_t)count itemSize: (size_t)itemSize allowsSwappableMemory: (bool)allowsSwappableMemory OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; - (instancetype)initWithItemSize: (size_t)itemSize OF_UNAVAILABLE; - (instancetype)initWithItems: (const void *)items count: (size_t)count OF_UNAVAILABLE; - (instancetype)initWithItems: (const void *)items count: (size_t)count itemSize: (size_t)itemSize OF_UNAVAILABLE; - (instancetype)initWithItemsNoCopy: (void *)items count: (size_t)count freeWhenDone: (bool)freeWhenDone OF_UNAVAILABLE; - (instancetype)initWithItemsNoCopy: (void *)items count: (size_t)count itemSize: (size_t)itemSize freeWhenDone: (bool)freeWhenDone OF_UNAVAILABLE; #ifdef OF_HAVE_FILES - (instancetype)initWithContentsOfFile: (OFString *)path OF_UNAVAILABLE; #endif - (instancetype)initWithContentsOfIRI: (OFIRI *)IRI OF_UNAVAILABLE; - (instancetype)initWithStringRepresentation: (OFString *)string OF_UNAVAILABLE; - (instancetype)initWithBase64EncodedString: (OFString *)string OF_UNAVAILABLE; /** * @brief Returns a specific item of the OFSecureData. * * Modifying the returned item directly is allowed and will change the contents * of the data array. * * @param index The number of the item to return * @return The specified item of the OFSecureData */ - (void *)mutableItemAtIndex: (size_t)index OF_RETURNS_INNER_POINTER; /** * @brief Checks the OFSecureData for equality to another object. * * If the specified object is a subclass of @ref OFData, the comparison is * performed in constant time. * * @param object The object which should be tested for equality * @return A boolean whether the OFSecureData is equal to the specified object */ - (bool)isEqual: (nullable id)object; /** * @brief Zeroes the data. */ - (void)zero; - (OFString *)stringRepresentation OF_UNAVAILABLE; - (OFString *)stringByBase64Encoding OF_UNAVAILABLE; #ifdef OF_HAVE_FILES - (void)writeToFile: (OFString *)path OF_UNAVAILABLE; #endif - (void)writeToIRI: (OFIRI *)IRI OF_UNAVAILABLE; - (OFData *)messagePackRepresentation OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFSecureData.m000066400000000000000000000354611465614216400160620ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #ifdef HAVE_SYS_MMAN_H # include #endif #import "OFSecureData.h" #import "OFString.h" #import "OFSystemInfo.h" #ifdef OF_HAVE_THREADS # import "OFTLSKey.h" #endif #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFNotImplementedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON) static const size_t chunkSize = 16; struct Page { struct Page *next, *previous; void *map; unsigned char *page; }; # if defined(OF_HAVE_COMPILER_TLS) static thread_local struct Page *firstPage = NULL; static thread_local struct Page *lastPage = NULL; static thread_local struct Page **preallocatedPages = NULL; static thread_local size_t numPreallocatedPages = 0; # elif defined(OF_HAVE_THREADS) static OFTLSKey firstPageKey, lastPageKey; static OFTLSKey preallocatedPagesKey, numPreallocatedPagesKey; # else static struct Page *firstPage = NULL; static struct Page *lastPage = NULL; static struct Page **preallocatedPages = NULL; static size_t numPreallocatedPages = 0; # endif static void * mapPages(size_t numPages) { size_t pageSize = [OFSystemInfo pageSize]; void *pointer; if (numPages > SIZE_MAX / pageSize) @throw [OFOutOfRangeException exception]; if ((pointer = mmap(NULL, numPages * pageSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0)) == MAP_FAILED) @throw [OFOutOfMemoryException exceptionWithRequestedSize: numPages * pageSize]; if (mlock(pointer, numPages * pageSize) != 0) { munmap(pointer, numPages * pageSize); @throw [OFOutOfMemoryException exceptionWithRequestedSize: numPages * pageSize]; } return pointer; } static void unmapPages(void *pointer, size_t numPages) { size_t pageSize = [OFSystemInfo pageSize]; if (numPages > SIZE_MAX / pageSize) @throw [OFOutOfRangeException exception]; munlock(pointer, numPages * pageSize); munmap(pointer, numPages * pageSize); } static struct Page * addPage(bool allowPreallocated) { size_t pageSize = [OFSystemInfo pageSize]; size_t mapSize = OFRoundUpToPowerOf2(CHAR_BIT, pageSize / chunkSize) / CHAR_BIT; struct Page *page; # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) struct Page *lastPage; # endif if (allowPreallocated) { # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) uintptr_t numPreallocatedPages = (uintptr_t)OFTLSKeyGet(numPreallocatedPagesKey); # endif if (numPreallocatedPages > 0) { # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) struct Page **preallocatedPages = OFTLSKeyGet(preallocatedPagesKey); # endif numPreallocatedPages--; # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OFEnsure(OFTLSKeySet(numPreallocatedPagesKey, (void *)numPreallocatedPages) == 0); # endif page = preallocatedPages[numPreallocatedPages]; if (numPreallocatedPages == 0) { OFFreeMemory(preallocatedPages); preallocatedPages = NULL; # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OFEnsure(OFTLSKeySet(preallocatedPagesKey, preallocatedPages) == 0); # endif } return page; } } page = OFAllocMemory(1, sizeof(*page)); @try { page->map = OFAllocZeroedMemory(1, mapSize); } @catch (id e) { OFFreeMemory(page); @throw e; } @try { page->page = mapPages(1); } @catch (id e) { OFFreeMemory(page->map); OFFreeMemory(page); @throw e; } OFZeroMemory(page->page, pageSize); # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) lastPage = OFTLSKeyGet(lastPageKey); # endif page->previous = lastPage; page->next = NULL; if (lastPage != NULL) lastPage->next = page; # if defined(OF_HAVE_COMPILER_TLS) || !defined(OF_HAVE_THREADS) lastPage = page; if (firstPage == NULL) firstPage = page; # else OFEnsure(OFTLSKeySet(lastPageKey, page) == 0); if (OFTLSKeyGet(firstPageKey) == NULL) OFEnsure(OFTLSKeySet(firstPageKey, page) == 0); # endif return page; } static void removePageIfEmpty(struct Page *page) { unsigned char *map = page->map; size_t pageSize = [OFSystemInfo pageSize]; size_t mapSize = OFRoundUpToPowerOf2(CHAR_BIT, pageSize / chunkSize) / CHAR_BIT; for (size_t i = 0; i < mapSize; i++) if (map[i] != 0) return; unmapPages(page->page, 1); OFFreeMemory(page->map); if (page->previous != NULL) page->previous->next = page->next; if (page->next != NULL) page->next->previous = page->previous; # if defined(OF_HAVE_COMPILER_TLS) || !defined(OF_HAVE_THREADS) if (firstPage == page) firstPage = page->next; if (lastPage == page) lastPage = page->previous; # else if (OFTLSKeyGet(firstPageKey) == page) OFEnsure(OFTLSKeySet(firstPageKey, page->next) == 0); if (OFTLSKeyGet(lastPageKey) == page) OFEnsure(OFTLSKeySet(lastPageKey, page->previous) == 0); # endif OFFreeMemory(page); } static void * allocateMemory(struct Page *page, size_t bytes) { size_t chunks, chunksLeft, pageSize, i, firstChunk; bytes = OFRoundUpToPowerOf2(chunkSize, bytes); chunks = chunksLeft = bytes / chunkSize; firstChunk = 0; pageSize = [OFSystemInfo pageSize]; for (i = 0; i < pageSize / chunkSize; i++) { if (OFBitsetIsSet(page->map, i)) { chunksLeft = chunks; firstChunk = i + 1; continue; } if (--chunksLeft == 0) break; } if (chunksLeft == 0) { for (size_t j = firstChunk; j < firstChunk + chunks; j++) OFBitsetSet(page->map, j); return page->page + (chunkSize * firstChunk); } return NULL; } static void freeMemory(struct Page *page, void *pointer, size_t bytes) { size_t chunks, chunkIndex; bytes = OFRoundUpToPowerOf2(chunkSize, bytes); chunks = bytes / chunkSize; chunkIndex = ((uintptr_t)pointer - (uintptr_t)page->page) / chunkSize; OFZeroMemory(pointer, bytes); for (size_t i = 0; i < chunks; i++) OFBitsetClear(page->map, chunkIndex + i); } #endif @implementation OFSecureData @synthesize allowsSwappableMemory = _allowsSwappableMemory; #if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON) && \ !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) + (void)initialize { if (self != [OFSecureData class]) return; if (OFTLSKeyNew(&firstPageKey) != 0 || OFTLSKeyNew(&lastPageKey) != 0 || OFTLSKeyNew(&preallocatedPagesKey) != 0 || OFTLSKeyNew(&numPreallocatedPagesKey) != 0) @throw [OFInitializationFailedException exceptionWithClass: self]; } #endif + (void)preallocateUnswappableMemoryWithSize: (size_t)size { #if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON) size_t pageSize = [OFSystemInfo pageSize]; size_t numPages = OFRoundUpToPowerOf2(pageSize, size) / pageSize; # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) struct Page **preallocatedPages = OFTLSKeyGet(preallocatedPagesKey); size_t numPreallocatedPages; # endif size_t i; if (preallocatedPages != NULL) @throw [OFInvalidArgumentException exception]; preallocatedPages = OFAllocZeroedMemory(numPages, sizeof(struct Page)); # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OFEnsure(OFTLSKeySet(preallocatedPagesKey, preallocatedPages) == 0); # endif @try { for (i = 0; i < numPages; i++) preallocatedPages[i] = addPage(false); } @catch (id e) { for (size_t j = 0; j < i; j++) removePageIfEmpty(preallocatedPages[j]); OFFreeMemory(preallocatedPages); preallocatedPages = NULL; @throw e; } numPreallocatedPages = numPages; # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OFEnsure(OFTLSKeySet(numPreallocatedPagesKey, (void *)(uintptr_t)numPreallocatedPages) == 0); # endif #else @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; #endif } + (instancetype)dataWithCount: (size_t)count allowsSwappableMemory: (bool)allowsSwappableMemory { return [[[self alloc] initWithCount: count allowsSwappableMemory: allowsSwappableMemory] autorelease]; } + (instancetype)dataWithCount: (size_t)count itemSize: (size_t)itemSize allowsSwappableMemory: (bool)allowsSwappableMemory { return [[[self alloc] initWithCount: count itemSize: itemSize allowsSwappableMemory: allowsSwappableMemory] autorelease]; } + (instancetype)dataWithItems: (const void *)items count: (size_t)count { OF_UNRECOGNIZED_SELECTOR } + (instancetype)dataWithItems: (const void *)items count: (size_t)count itemSize: (size_t)itemSize { OF_UNRECOGNIZED_SELECTOR } + (instancetype)dataWithItemsNoCopy: (void *)items count: (size_t)count freeWhenDone: (bool)freeWhenDone { OF_UNRECOGNIZED_SELECTOR } + (instancetype)dataWithItemsNoCopy: (void *)items count: (size_t)count itemSize: (size_t)itemSize freeWhenDone: (bool)freeWhenDone { OF_UNRECOGNIZED_SELECTOR } #ifdef OF_HAVE_FILES + (instancetype)dataWithContentsOfFile: (OFString *)path { OF_UNRECOGNIZED_SELECTOR } #endif + (instancetype)dataWithContentsOfIRI: (OFIRI *)IRI { OF_UNRECOGNIZED_SELECTOR } + (instancetype)dataWithStringRepresentation: (OFString *)string { OF_UNRECOGNIZED_SELECTOR } + (instancetype)dataWithBase64EncodedString: (OFString *)string { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithCount: (size_t)count allowsSwappableMemory: (bool)allowsSwappableMemory { return [self initWithCount: count itemSize: 1 allowsSwappableMemory: allowsSwappableMemory]; } - (instancetype)initWithCount: (size_t)count itemSize: (size_t)itemSize allowsSwappableMemory: (bool)allowsSwappableMemory { self = [super init]; @try { #if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON) size_t pageSize = [OFSystemInfo pageSize]; #endif if (count > SIZE_MAX / itemSize) @throw [OFOutOfRangeException exception]; if (allowsSwappableMemory) { _items = OFAllocMemory(count, itemSize); _freeWhenDone = true; memset(_items, 0, count * itemSize); #if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON) } else if (count * itemSize >= pageSize) _items = mapPages(OFRoundUpToPowerOf2(pageSize, count * itemSize) / pageSize); else { # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) struct Page *lastPage = OFTLSKeyGet(lastPageKey); # endif for (struct Page *page = lastPage; page != NULL; page = page->previous) { _items = allocateMemory(page, count * itemSize); if (_items != NULL) { _page = page; break; } } if (_items == NULL) { _page = addPage(true); _items = allocateMemory(_page, count * itemSize); if (_items == NULL) @throw [OFOutOfMemoryException exceptionWithRequestedSize: count * itemSize]; } } #else } else @throw [OFNotImplementedException exceptionWithSelector: _cmd object: nil]; #endif _count = count; _itemSize = itemSize; _allowsSwappableMemory = allowsSwappableMemory; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithItemSize: (size_t)itemSize { OF_INVALID_INIT_METHOD } - (instancetype)initWithItems: (const void *)items count: (size_t)count { OF_INVALID_INIT_METHOD } - (instancetype)initWithItems: (const void *)items count: (size_t)count itemSize: (size_t)itemSize { OF_INVALID_INIT_METHOD } - (instancetype)initWithItemsNoCopy: (void *)items count: (size_t)count freeWhenDone: (bool)freeWhenDone { OF_INVALID_INIT_METHOD } - (instancetype)initWithItemsNoCopy: (void *)items count: (size_t)count itemSize: (size_t)itemSize freeWhenDone: (bool)freeWhenDone { OF_INVALID_INIT_METHOD } #ifdef OF_HAVE_FILES - (instancetype)initWithContentsOfFile: (OFString *)path { OF_INVALID_INIT_METHOD } #endif - (instancetype)initWithContentsOfIRI: (OFIRI *)IRI { OF_INVALID_INIT_METHOD } - (instancetype)initWithStringRepresentation: (OFString *)string { OF_INVALID_INIT_METHOD } - (instancetype)initWithBase64EncodedString: (OFString *)string { OF_INVALID_INIT_METHOD } - (void)dealloc { [self zero]; #if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON) if (!_allowsSwappableMemory) { size_t pageSize = [OFSystemInfo pageSize]; if (_count * _itemSize > pageSize) unmapPages(_items, OFRoundUpToPowerOf2(pageSize, _count * _itemSize) / pageSize); else if (_page != NULL) { if (_items != NULL) freeMemory(_page, _items, _count * _itemSize); removePageIfEmpty(_page); } } #endif if (_freeWhenDone) OFFreeMemory(_items); [super dealloc]; } - (size_t)count { return _count; } - (size_t)itemSize { return _itemSize; } - (const void *)items { return _items; } - (void *)mutableItems { return _items; } - (void *)mutableItemAtIndex: (size_t)idx { if (idx >= _count) @throw [OFOutOfRangeException exception]; return _items + idx * _itemSize; } - (void)zero { OFZeroMemory(_items, _count * _itemSize); } - (id)copy { OFSecureData *copy = [[OFSecureData alloc] initWithCount: _count itemSize: _itemSize allowsSwappableMemory: _allowsSwappableMemory]; memcpy(copy.mutableItems, _items, _count * _itemSize); return copy; } - (id)mutableCopy { OFSecureData *copy = [[OFSecureData alloc] initWithCount: _count itemSize: _itemSize allowsSwappableMemory: _allowsSwappableMemory]; memcpy(copy.mutableItems, _items, _count * _itemSize); return copy; } - (bool)isEqual: (id)object { OFData *otherData; const unsigned char *otherDataItems; unsigned char diff; if (object == self) return true; if (![object isKindOfClass: [OFData class]]) return false; otherData = object; otherDataItems = otherData.items; if (otherData.count != _count || otherData.itemSize != _itemSize) return false; diff = 0; for (size_t i = 0; i < _count * _itemSize; i++) diff |= otherDataItems[i] ^ _items[i]; return (diff == 0); } - (OFString *)description { return @""; } - (OFString *)stringRepresentation { OF_UNRECOGNIZED_SELECTOR } - (OFString *)stringByBase64Encoding { OF_UNRECOGNIZED_SELECTOR } #ifdef OF_HAVE_FILES - (void)writeToFile: (OFString *)path { OF_UNRECOGNIZED_SELECTOR } #endif - (void)writeToIRI: (OFIRI *)IRI { OF_UNRECOGNIZED_SELECTOR } - (OFData *)messagePackRepresentation { OF_UNRECOGNIZED_SELECTOR } @end objfw-1.1.6/src/OFSeekableStream.h000066400000000000000000000056431465614216400167230ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif #include "objfw-defs.h" #ifdef OF_HAVE_SYS_TYPES_H # include #endif #import "OFStream.h" OF_ASSUME_NONNULL_BEGIN /** @file */ #if defined(OF_WINDOWS) typedef __int64 OFStreamOffset; #elif defined(OF_ANDROID) typedef long long OFStreamOffset; #elif defined(OF_MORPHOS) typedef long long OFStreamOffset; #elif defined(OF_HAVE_OFF64_T) typedef off64_t OFStreamOffset; #else typedef off_t OFStreamOffset; #endif /** * @brief From where to seek. */ typedef enum { /** Seek to the end of the stream + offset. */ OFSeekSet, /** Seek to the current location + offset. */ OFSeekCurrent, /** Seek to the specified byte. */ OFSeekEnd } OFSeekWhence; /** * @class OFSeekableStream OFSeekableStream.h ObjFW/OFSeekableStream.h * * @brief A stream that supports seeking. * * @note If you want to subclass this, override * @ref lowlevelSeekToOffset:whence:. OFSeekableStream uses this method * and makes it work together with the caching of OFStream. If you * override this methods without the `lowlevel` prefix, you *will* break * caching, get broken results and seek to the wrong position! */ @interface OFSeekableStream: OFStream { OF_RESERVE_IVARS(OFSeekableStream, 4) } /** * @brief Seeks to the specified offset. * * @param offset The offset in bytes * @param whence From where to seek. * @return The new offset form the start of the file * @throw OFSeekFailedException Seeking failed * @throw OFNotOpenException The stream is not open */ - (OFStreamOffset)seekToOffset: (OFStreamOffset)offset whence: (OFSeekWhence)whence; /** * @brief Seek the stream on the lowlevel. * * @warning Do not call this directly! * * @note Override this method with your actual seek implementation when * subclassing! * * @param offset The offset to seek to * @param whence From where to seek. * @return The new offset from the start of the file * @throw OFSeekFailedException Seeking failed * @throw OFNotOpenException The stream is not open */ - (OFStreamOffset)lowlevelSeekToOffset: (OFStreamOffset)offset whence: (OFSeekWhence)whence; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFSeekableStream.m000066400000000000000000000030521465614216400167200ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #define OF_SEEKABLE_STREAM_M #include "config.h" #include #include #import "OFSeekableStream.h" @implementation OFSeekableStream - (instancetype)init { if ([self isMemberOfClass: [OFSeekableStream class]]) { @try { [self doesNotRecognizeSelector: _cmd]; abort(); } @catch (id e) { [self release]; @throw e; } } return [super init]; } - (OFStreamOffset)lowlevelSeekToOffset: (OFStreamOffset)offset whence: (OFSeekWhence)whence { OF_UNRECOGNIZED_SELECTOR } - (OFStreamOffset)seekToOffset: (OFStreamOffset)offset whence: (OFSeekWhence)whence { if (whence == OFSeekCurrent) offset -= _readBufferLength; offset = [self lowlevelSeekToOffset: offset whence: whence]; OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = NULL; _readBufferLength = 0; return offset; } @end objfw-1.1.6/src/OFSelectKernelEventObserver.h000066400000000000000000000021721465614216400211200ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "objfw-defs.h" #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif #ifdef HAVE_SYS_SELECT_H # include #endif #import "OFKernelEventObserver.h" OF_ASSUME_NONNULL_BEGIN @interface OFSelectKernelEventObserver: OFKernelEventObserver { fd_set _readFDs, _writeFDs; int _maxFD; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFSelectKernelEventObserver.m000066400000000000000000000152401465614216400211250ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" #ifdef OF_WINDOWS /* Win32 has a ridiculous default of 64, even though it supports much more. */ # define FD_SETSIZE 1024 #endif #include #include #include #import "OFSelectKernelEventObserver.h" #import "OFArray.h" #import "OFSocket+Private.h" #import "OFInitializationFailedException.h" #import "OFObserveKernelEventsFailedException.h" #import "OFOutOfRangeException.h" #ifdef OF_AMIGAOS # define Class IntuitionClass # include # undef Class #endif #ifdef OF_HPUX /* FD_SET causes warnings on HP-UX/IA64. */ # pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif @implementation OFSelectKernelEventObserver - (instancetype)init { self = [super init]; @try { FD_ZERO(&_readFDs); FD_ZERO(&_writeFDs); #ifdef OF_AMIGAOS _maxFD = -1; #else # ifndef OF_WINDOWS if (_cancelFD[0] >= (int)FD_SETSIZE) @throw [OFInitializationFailedException exceptionWithClass: self.class]; # endif FD_SET(_cancelFD[0], &_readFDs); if (_cancelFD[0] > INT_MAX) @throw [OFOutOfRangeException exception]; _maxFD = (int)_cancelFD[0]; #endif } @catch (id e) { [self release]; @throw e; } return self; } - (void)addObjectForReading: (id )object { int fd = object.fileDescriptorForReading; if (fd < 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: EBADF]; if (fd > INT_MAX - 1) @throw [OFOutOfRangeException exception]; #ifndef OF_WINDOWS if (fd >= (int)FD_SETSIZE) @throw [OFOutOfRangeException exception]; #endif if (fd > _maxFD) _maxFD = fd; FD_SET((OFSocketHandle)fd, &_readFDs); [super addObjectForReading: object]; } - (void)addObjectForWriting: (id )object { int fd = object.fileDescriptorForWriting; if (fd < 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: EBADF]; if (fd > INT_MAX - 1) @throw [OFOutOfRangeException exception]; #ifndef OF_WINDOWS if (fd >= (int)FD_SETSIZE) @throw [OFOutOfRangeException exception]; #endif if (fd > _maxFD) _maxFD = fd; FD_SET((OFSocketHandle)fd, &_writeFDs); [super addObjectForWriting: object]; } - (void)removeObjectForReading: (id )object { /* TODO: Adjust _maxFD */ int fd = object.fileDescriptorForReading; if (fd < 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: EBADF]; #ifndef OF_WINDOWS if (fd >= (int)FD_SETSIZE) @throw [OFOutOfRangeException exception]; #endif FD_CLR((OFSocketHandle)fd, &_readFDs); [super removeObjectForReading: object]; } - (void)removeObjectForWriting: (id )object { /* TODO: Adjust _maxFD */ int fd = object.fileDescriptorForWriting; if (fd < 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: EBADF]; #ifndef OF_WINDOWS if (fd >= (int)FD_SETSIZE) @throw [OFOutOfRangeException exception]; #endif FD_CLR((OFSocketHandle)fd, &_writeFDs); [super removeObjectForWriting: object]; } - (void)observeForTimeInterval: (OFTimeInterval)timeInterval { fd_set readFDs; fd_set writeFDs; struct timeval timeout; int events; #ifdef OF_AMIGAOS BYTE cancelSignal; ULONG execSignalMask; #endif void *pool; if ([self of_processReadBuffers]) return; #ifdef FD_COPY FD_COPY(&_readFDs, &readFDs); FD_COPY(&_writeFDs, &writeFDs); #else readFDs = _readFDs; writeFDs = _writeFDs; #endif /* * We cast to int before assigning to tv_usec in order to avoid a * warning with Apple GCC on PowerPC. POSIX defines this as suseconds_t, * however, this is not available on Win32. As an int should always * satisfy the required range, we just cast to int. */ #ifndef OF_WINDOWS timeout.tv_sec = (time_t)timeInterval; #else timeout.tv_sec = (long)timeInterval; #endif timeout.tv_usec = (int)((timeInterval - timeout.tv_sec) * 1000000); #ifdef OF_AMIGAOS if ((cancelSignal = AllocSignal(-1)) == (BYTE)-1) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: EAGAIN]; execSignalMask = _execSignalMask | (1ul << cancelSignal); Forbid(); _waitingTask = FindTask(NULL); _cancelSignal = cancelSignal; events = WaitSelect(_maxFD + 1, &readFDs, &writeFDs, NULL, (void *)(timeInterval != -1 ? &timeout : NULL), &execSignalMask); execSignalMask &= ~(1ul << cancelSignal); _waitingTask = NULL; FreeSignal(_cancelSignal); Permit(); #else events = select(_maxFD + 1, &readFDs, &writeFDs, NULL, (timeInterval != -1 ? &timeout : NULL)); #endif if (events < 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: _OFSocketErrNo()]; #ifdef OF_AMIGAOS if (execSignalMask != 0 && [_delegate respondsToSelector: @selector(execSignalWasReceived:)]) [_delegate execSignalWasReceived: execSignalMask]; #else if (FD_ISSET(_cancelFD[0], &readFDs)) { char buffer; # ifdef OF_HAVE_PIPE OFEnsure(read(_cancelFD[0], &buffer, 1) == 1); # else OFEnsure(recvfrom(_cancelFD[0], (void *)&buffer, 1, 0, NULL, NULL) == 1); # endif } #endif pool = objc_autoreleasePoolPush(); for (id object in [[_readObjects copy] autorelease]) { void *pool2 = objc_autoreleasePoolPush(); int fd = object.fileDescriptorForReading; if (FD_ISSET((OFSocketHandle)fd, &readFDs) && [_delegate respondsToSelector: @selector(objectIsReadyForReading:)]) [_delegate objectIsReadyForReading: object]; objc_autoreleasePoolPop(pool2); } for (id object in [[_writeObjects copy] autorelease]) { void *pool2 = objc_autoreleasePoolPush(); int fd = object.fileDescriptorForWriting; if (FD_ISSET((OFSocketHandle)fd, &writeFDs) && [_delegate respondsToSelector: @selector(objectIsReadyForWriting:)]) [_delegate objectIsReadyForWriting: object]; objc_autoreleasePoolPop(pool2); } objc_autoreleasePoolPop(pool); } @end objfw-1.1.6/src/OFSequencedPacketSocket+Private.h000066400000000000000000000016461465614216400216560ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFSequencedPacketSocket.h" OF_ASSUME_NONNULL_BEGIN @interface OFSequencedPacketSocket () #ifndef OF_WII @property (readonly, nonatomic) int of_socketError; #endif @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFSequencedPacketSocket.h000066400000000000000000000324521465614216400202470ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFKernelEventObserver.h" #import "OFRunLoop.h" #import "OFSocket.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFData; @class OFSequencedPacketSocket; #ifdef OF_HAVE_BLOCKS /** * @brief A block which is called when a packet has been received. * * @param length The length of the packet * @param exception An exception which occurred while receiving or `nil` on * success * @return A bool whether the same block should be used for the next receive */ typedef bool (^OFSequencedPacketSocketAsyncReceiveBlock)(size_t length, id _Nullable exception); /** * @brief A block which is called when a packet has been sent. * * @param exception An exception which occurred while reading or `nil` on * success * @return The data to repeat the send with or nil if it should not repeat */ typedef OFData *_Nullable (^OFSequencedPacketSocketAsyncSendDataBlock)( id _Nullable exception); /** * @brief A block which is called when the socket accepted a connection. * * @param acceptedSocket The socket which has been accepted * @param exception An exception which occurred while accepting the socket or * `nil` on success * @return A bool whether the same block should be used for the next incoming * connection */ typedef bool (^OFSequencedPacketSocketAsyncAcceptBlock)( OFSequencedPacketSocket *acceptedSocket, id _Nullable exception); #endif /** * @protocol OFSequencedPacketSocketDelegate OFSequencedPacketSocket.h \ * ObjFW/OFSequencedPacketSocket.h * * @brief A delegate for OFSequencedPacketSocket. */ @protocol OFSequencedPacketSocketDelegate @optional /** * @brief This method is called when a packet has been received. * * @param socket The sequenced packet socket which received a packet * @param buffer The buffer the packet has been written to * @param length The length of the packet * @param exception An exception that occurred while receiving, or nil on * success * @return A bool whether the same block should be used for the next receive */ - (bool)socket: (OFSequencedPacketSocket *)socket didReceiveIntoBuffer: (void *)buffer length: (size_t)length exception: (nullable id)exception; /** * @brief This method is called when a packet has been sent. * * @param socket The sequenced packet socket which sent a packet * @param data The data which was sent * @param exception An exception that occurred while sending, or nil on success * @return The data to repeat the send with or nil if it should not repeat */ - (nullable OFData *)socket: (OFSequencedPacketSocket *)socket didSendData: (OFData *)data exception: (nullable id)exception; /** * @brief A method which is called when a socket accepted a connection. * * @param socket The socket which accepted the connection * @param acceptedSocket The socket which has been accepted * @param exception An exception that occurred while accepting, or nil on * success * @return A bool whether to accept the next incoming connection */ - (bool)socket: (OFSequencedPacketSocket *)socket didAcceptSocket: (OFSequencedPacketSocket *)acceptedSocket exception: (nullable id)exception; @end /** * @class OFSequencedPacketSocket OFSequencedPacketSocket.h \ * ObjFW/OFSequencedPacketSocket.h * * @brief A base class for sequenced packet sockets. * * @warning Even though the OFCopying protocol is implemented, it does *not* * return an independent copy of the socket, but instead retains it. * This is so that the socket can be used as a key for a dictionary, * so context can be associated with a socket. Using a socket in more * than one thread at the same time is not thread-safe, even if copy * was called to create one "instance" for every thread! */ @interface OFSequencedPacketSocket: OFObject { OFSocketHandle _socket; #ifdef OF_AMIGAOS LONG _socketID; /* unused, reserved for ABI stability */ int _family; /* unused, reserved for ABI stability */ #endif bool _canBlock, _listening; OFSocketAddress _remoteAddress; id _Nullable _delegate; OF_RESERVE_IVARS(OFSequencedPacketSocket, 4) } /** * @brief Whether the socket can block. * * By default, a socket can block. * * @throw OFGetOptionFailedException The option could not be retrieved * @throw OFSetOptionFailedException The option could not be set */ @property (nonatomic) bool canBlock; /** * @brief Whether the socket is a listening socket. */ @property (readonly, nonatomic, getter=isListening) bool listening; /** * @brief The remote address. * * @note This only works for accepted sockets! * * @throw OFNotOpenException The socket is not open * @throw OFInvalidArgumentException The socket has no remote address */ @property (readonly, nonatomic) const OFSocketAddress *remoteAddress; /** * @brief The delegate for asynchronous operations on the socket. * * @note The delegate is retained for as long as asynchronous operations are * still ongoing. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id delegate; /** * @brief Returns a new, autoreleased OFSequencedPacketSocket. * * @return A new, autoreleased OFSequencedPacketSocket */ + (instancetype)socket; /** * @brief Receives a packet and stores it into the specified buffer. * * If the buffer is too small, the receive operation fails. * * @param buffer The buffer to write the packet to * @param length The length of the buffer * @return The length of the received packet * @throw OFReadFailedException Receiving failed * @throw OFNotOpenException The socket is not open */ - (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length; /** * @brief Asynchronously receives a packet and stores it into the specified * buffer. * * If the buffer is too small, the receive operation fails. * * @param buffer The buffer to write the packet to * @param length The length of the buffer */ - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length; /** * @brief Asynchronously receives a packet and stores it into the specified * buffer. * * If the buffer is too small, the receive operation fails. * * @param buffer The buffer to write the packet to * @param length The length of the buffer * @param runLoopMode The run loop mode in which to perform the asynchronous * receive */ - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously receives a packet and stores it into the specified * buffer. * * If the buffer is too small, the receive operation fails. * * @param buffer The buffer to write the packet to * @param length The length of the buffer * @param block The block to call when the packet has been received. If the * block returns true, it will be called again with the same * buffer and maximum length when more packets have been received. * If you want the next method in the queue to handle the packet * received next, you need to return false from the method. */ - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length block: (OFSequencedPacketSocketAsyncReceiveBlock)block; /** * @brief Asynchronously receives a packet and stores it into the specified * buffer. * * If the buffer is too small, the receive operation fails. * * @param buffer The buffer to write the packet to * @param length The length of the buffer * @param runLoopMode The run loop mode in which to perform the asynchronous * receive * @param block The block to call when the packet has been received. If the * block returns true, it will be called again with the same * buffer and maximum length when more packets have been received. * If you want the next method in the queue to handle the packet * received next, you need to return false from the method. */ - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode block: (OFSequencedPacketSocketAsyncReceiveBlock)block; #endif /** * @brief Sends the specified packet. * * @param buffer The buffer to send as a packet * @param length The length of the buffer * @throw OFWriteFailedException Sending failed * @throw OFNotOpenException The socket is not open */ - (void)sendBuffer: (const void *)buffer length: (size_t)length; /** * @brief Asynchronously sends the specified packet. * * @param data The data to send as a packet */ - (void)asyncSendData: (OFData *)data; /** * @brief Asynchronously sends the specified packet. * * @param data The data to send as a packet * @param runLoopMode The run loop mode in which to perform the asynchronous * send */ - (void)asyncSendData: (OFData *)data runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously sends the specified packet. * * @param data The data to send as a packet * @param block The block to call when the packet has been sent. It should * return the data for the next send with the same callback or nil * if it should not repeat. */ - (void)asyncSendData: (OFData *)data block: (OFSequencedPacketSocketAsyncSendDataBlock)block; /** * @brief Asynchronously sends the specified packet. * * @param data The data to send as a packet * @param runLoopMode The run loop mode in which to perform the asynchronous * send * @param block The block to call when the packet has been sent. It should * return the data for the next send with the same callback or nil * if it should not repeat. */ - (void)asyncSendData: (OFData *)data runLoopMode: (OFRunLoopMode)runLoopMode block: (OFSequencedPacketSocketAsyncSendDataBlock)block; #endif /** * @brief Listen on the socket. * * @param backlog Maximum length for the queue of pending connections. * @throw OFListenOnSocketFailedException Listening failed * @throw OFNotOpenException The socket is not open */ - (void)listenWithBacklog: (int)backlog; /** * @brief Listen on the socket. * * @throw OFListenOnSocketFailedException Listening failed * @throw OFNotOpenException The socket is not open */ - (void)listen; /** * @brief Accept an incoming connection. * * @return An autoreleased sequenced packet socket for the accepted connection. * @throw OFAcceptSocketFailedException Accepting failed * @throw OFNotOpenException The socket is not open */ - (instancetype)accept; /** * @brief Asynchronously accept an incoming connection. */ - (void)asyncAccept; /** * @brief Asynchronously accept an incoming connection. * * @param runLoopMode The run loop mode in which to perform the asynchronous * accept */ - (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously accept an incoming connection. * * @param block The block to execute when a new connection has been accepted. * Returns whether the next incoming connection should be accepted * by the specified block as well. */ - (void)asyncAcceptWithBlock: (OFSequencedPacketSocketAsyncAcceptBlock)block; /** * @brief Asynchronously accept an incoming connection. * * @param runLoopMode The run loop mode in which to perform the asynchronous * accept * @param block The block to execute when a new connection has been accepted. * Returns whether the next incoming connection should be accepted * by the specified block as well. */ - (void) asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode block: (OFSequencedPacketSocketAsyncAcceptBlock)block; #endif /** * @brief Cancels all pending asynchronous requests on the socket. */ - (void)cancelAsyncRequests; /** * @brief Releases the socket from the current thread. * * This is necessary on some platforms in order to allow a different thread to * use the socket, e.g. on AmigaOS, but you should call it on all operating * systems before using the socket from a different thread. * * After calling this method, you must no longer use the socket until * @ref obtainSocketForCurrentThread has been called. */ - (void)releaseSocketFromCurrentThread; /** * @brief Obtains the socket for the current thread. * * This is necessary on some platforms in order to allow a different thread to * use the socket, e.g. on AmigaOS, but you should call it on all operating * systems before using the socket from a different thread. * * You must only call this method after @ref releaseSocketFromCurrentThread has * been called from a different thread. */ - (void)obtainSocketForCurrentThread; /** * @brief Closes the socket so that it can neither receive nor send any more * datagrams. * * @throw OFNotOpenException The socket is not open */ - (void)close; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFSequencedPacketSocket.m000066400000000000000000000270161465614216400202540ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #ifndef _XOPEN_SOURCE_EXTENDED # define _XOPEN_SOURCE_EXTENDED #endif #define _HPUX_ALT_XOPEN_SOCKET_API #include #ifdef HAVE_FCNTL_H # include #endif #import "OFSequencedPacketSocket.h" #import "OFSequencedPacketSocket+Private.h" #import "OFData.h" #import "OFRunLoop+Private.h" #import "OFRunLoop.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFAcceptSocketFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFListenOnSocketFailedException.h" #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFSetOptionFailedException.h" #import "OFWriteFailedException.h" @implementation OFSequencedPacketSocket @synthesize listening = _listening, delegate = _delegate; + (void)initialize { if (self != [OFSequencedPacketSocket class]) return; if (!_OFSocketInit()) @throw [OFInitializationFailedException exceptionWithClass: self]; } + (instancetype)socket { return [[[self alloc] init] autorelease]; } - (instancetype)init { self = [super init]; @try { if (self.class == [OFSequencedPacketSocket class]) { [self doesNotRecognizeSelector: _cmd]; abort(); } _socket = OFInvalidSocketHandle; _canBlock = true; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_socket != OFInvalidSocketHandle) [self close]; [super dealloc]; } #ifndef OF_WII - (int)of_socketError { int errNo; socklen_t len = sizeof(errNo); if (getsockopt(_socket, SOL_SOCKET, SO_ERROR, (char *)&errNo, &len) != 0) return _OFSocketErrNo(); return errNo; } #endif - (id)copy { return [self retain]; } - (bool)canBlock { return _canBlock; } - (void)setCanBlock: (bool)canBlock { #if defined(HAVE_FCNTL) int flags = fcntl(_socket, F_GETFL, 0); if (flags == -1) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: errno]; if (canBlock) flags &= ~O_NONBLOCK; else flags |= O_NONBLOCK; if (fcntl(_socket, F_SETFL, flags) == -1) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: errno]; _canBlock = canBlock; #elif defined(OF_WINDOWS) u_long v = !canBlock; if (ioctlsocket(_socket, FIONBIO, &v) == SOCKET_ERROR) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: _OFSocketErrNo()]; _canBlock = canBlock; #else OF_UNRECOGNIZED_SELECTOR #endif } - (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length { ssize_t ret; if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; #ifndef OF_WINDOWS if ((ret = recv(_socket, buffer, length, 0)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: _OFSocketErrNo()]; #else if (length > INT_MAX) @throw [OFOutOfRangeException exception]; if ((ret = recv(_socket, buffer, (int)length, 0)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: _OFSocketErrNo()]; #endif return ret; } - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length { [self asyncReceiveIntoBuffer: buffer length: length runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode { [OFRunLoop of_addAsyncReceiveForSequencedPacketSocket: self buffer: buffer length: length mode: runLoopMode # ifdef OF_HAVE_BLOCKS block: NULL # endif delegate: _delegate]; } #ifdef OF_HAVE_BLOCKS - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length block: (OFSequencedPacketSocketAsyncReceiveBlock)block { [self asyncReceiveIntoBuffer: buffer length: length runLoopMode: OFDefaultRunLoopMode block: block]; } - (void) asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode block: (OFSequencedPacketSocketAsyncReceiveBlock)block { [OFRunLoop of_addAsyncReceiveForSequencedPacketSocket: self buffer: buffer length: length mode: runLoopMode block: block delegate: nil]; } #endif - (void)sendBuffer: (const void *)buffer length: (size_t)length { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; #ifndef OF_WINDOWS ssize_t bytesWritten; if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = send(_socket, (void *)buffer, length, 0)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: _OFSocketErrNo()]; #else int bytesWritten; if (length > INT_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = send(_socket, buffer, (int)length, 0)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: _OFSocketErrNo()]; #endif if ((size_t)bytesWritten != length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: bytesWritten errNo: 0]; } - (void)asyncSendData: (OFData *)data { [self asyncSendData: data runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncSendData: (OFData *)data runLoopMode: (OFRunLoopMode)runLoopMode { [OFRunLoop of_addAsyncSendForSequencedPacketSocket: self data: data mode: runLoopMode # ifdef OF_HAVE_BLOCKS block: NULL # endif delegate: _delegate]; } #ifdef OF_HAVE_BLOCKS - (void)asyncSendData: (OFData *)data block: (OFSequencedPacketSocketAsyncSendDataBlock)block { [self asyncSendData: data runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncSendData: (OFData *)data runLoopMode: (OFRunLoopMode)runLoopMode block: (OFSequencedPacketSocketAsyncSendDataBlock)block { [OFRunLoop of_addAsyncSendForSequencedPacketSocket: self data: data mode: runLoopMode block: block delegate: nil]; } #endif - (void)listen { [self listenWithBacklog: SOMAXCONN]; } - (void)listenWithBacklog: (int)backlog { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; if (listen(_socket, backlog) == -1) @throw [OFListenOnSocketFailedException exceptionWithSocket: self backlog: backlog errNo: _OFSocketErrNo()]; _listening = true; } - (instancetype)accept { OFSequencedPacketSocket *client; #if (!defined(HAVE_PACCEPT) && !defined(HAVE_ACCEPT4)) || !defined(SOCK_CLOEXEC) # if defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; # endif #endif if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; client = [[[[self class] alloc] init] autorelease]; client->_remoteAddress.length = (socklen_t)sizeof(client->_remoteAddress.sockaddr); #if defined(HAVE_PACCEPT) && defined(SOCK_CLOEXEC) if ((client->_socket = paccept(_socket, (struct sockaddr *)&client->_remoteAddress.sockaddr, &client->_remoteAddress.length, NULL, SOCK_CLOEXEC)) == OFInvalidSocketHandle) @throw [OFAcceptSocketFailedException exceptionWithSocket: self errNo: _OFSocketErrNo()]; #elif defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) if ((client->_socket = accept4(_socket, (struct sockaddr *)&client->_remoteAddress.sockaddr, &client->_remoteAddress.length, SOCK_CLOEXEC)) == OFInvalidSocketHandle) @throw [OFAcceptSocketFailedException exceptionWithSocket: self errNo: _OFSocketErrNo()]; #else if ((client->_socket = accept(_socket, (struct sockaddr *)&client->_remoteAddress.sockaddr, &client->_remoteAddress.length)) == OFInvalidSocketHandle) @throw [OFAcceptSocketFailedException exceptionWithSocket: self errNo: _OFSocketErrNo()]; # if defined(HAVE_FCNTL) && defined(FD_CLOEXEC) if ((flags = fcntl(client->_socket, F_GETFD, 0)) != -1) fcntl(client->_socket, F_SETFD, flags | FD_CLOEXEC); # endif #endif OFAssert(client->_remoteAddress.length <= (socklen_t)sizeof(client->_remoteAddress.sockaddr)); switch (((struct sockaddr *)&client->_remoteAddress.sockaddr) ->sa_family) { case AF_INET: client->_remoteAddress.family = OFSocketAddressFamilyIPv4; break; #ifdef OF_HAVE_IPV6 case AF_INET6: client->_remoteAddress.family = OFSocketAddressFamilyIPv6; break; #endif #ifdef OF_HAVE_IPX case AF_IPX: client->_remoteAddress.family = OFSocketAddressFamilyIPX; break; #endif default: client->_remoteAddress.family = OFSocketAddressFamilyUnknown; break; } return client; } - (void)asyncAccept { [self asyncAcceptWithRunLoopMode: OFDefaultRunLoopMode]; } - (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode { [OFRunLoop of_addAsyncAcceptForSocket: self mode: runLoopMode block: NULL delegate: _delegate]; } #ifdef OF_HAVE_BLOCKS - (void)asyncAcceptWithBlock: (OFSequencedPacketSocketAsyncAcceptBlock)block { [self asyncAcceptWithRunLoopMode: OFDefaultRunLoopMode block: block]; } - (void) asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode block: (OFSequencedPacketSocketAsyncAcceptBlock)block { [OFRunLoop of_addAsyncAcceptForSocket: self mode: runLoopMode block: block delegate: nil]; } #endif - (const OFSocketAddress *)remoteAddress { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; if (_remoteAddress.length == 0) @throw [OFInvalidArgumentException exception]; if (_remoteAddress.length > (socklen_t)sizeof(_remoteAddress.sockaddr)) @throw [OFOutOfRangeException exception]; return &_remoteAddress; } - (void)cancelAsyncRequests { [OFRunLoop of_cancelAsyncRequestsForObject: self mode: OFDefaultRunLoopMode]; } - (int)fileDescriptorForReading { #ifndef OF_WINDOWS return _socket; #else if (_socket == OFInvalidSocketHandle) return -1; if (_socket > INT_MAX) @throw [OFOutOfRangeException exception]; return (int)_socket; #endif } - (int)fileDescriptorForWriting { #ifndef OF_WINDOWS return _socket; #else if (_socket == OFInvalidSocketHandle) return -1; if (_socket > INT_MAX) @throw [OFOutOfRangeException exception]; return (int)_socket; #endif } - (void)releaseSocketFromCurrentThread { /* * Currently a nop, as all supported OSes that have SOCK_SEQPACKET do * not need anything to move sockets between threads. */ } - (void)obtainSocketForCurrentThread { /* * Currently a nop, as all supported OSes that have SOCK_SEQPACKET do * not need anything to move sockets between threads. */ } - (void)close { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; _listening = false; memset(&_remoteAddress, 0, sizeof(_remoteAddress)); closesocket(_socket); _socket = OFInvalidSocketHandle; } @end objfw-1.1.6/src/OFSet.h000066400000000000000000000171761465614216400145730ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif #include #import "OFObject.h" #import "OFCollection.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFArray OF_GENERIC(ObjectType); #ifdef OF_HAVE_BLOCKS /** * @brief A block for enumerating an OFSet. * * @param object The current object * @param stop A pointer to a variable that can be set to true to stop the * enumeration */ typedef void (^OFSetEnumerationBlock)(id object, bool *stop); /** * @brief A block for filtering an OFSet. * * @param object The object to inspect * @return Whether the object should be in the filtered set */ typedef bool (^OFSetFilterBlock)(id object); #endif /** * @class OFSet OFSet.h ObjFW/OFSet.h * * @brief An abstract class for an unordered set of unique objects. * * @warning Do not mutate objects that are in a set! Changing the hash of * objects in a set breaks the internal representation of the set! * * @note Subclasses must implement @ref count, @ref containsObject: and * @ref objectEnumerator. */ @interface OFSet OF_GENERIC(ObjectType): OFObject #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # define ObjectType id #endif /** * @brief An array of all objects in the set. */ @property (readonly, nonatomic) OFArray OF_GENERIC(ObjectType) *allObjects; /** * @brief An arbitrary object in the set. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) ObjectType anyObject; /** * @brief Creates a new set. * * @return A new, autoreleased set */ + (instancetype)set; /** * @brief Creates a new set with the specified set. * * @param set The set to initialize the set with * @return A new, autoreleased set with the specified set */ + (instancetype)setWithSet: (OFSet OF_GENERIC(ObjectType) *)set; /** * @brief Creates a new set with the specified array. * * @param array The array to initialize the set with * @return A new, autoreleased set with the specified array */ + (instancetype)setWithArray: (OFArray OF_GENERIC(ObjectType) *)array; /** * @brief Creates a new set with the specified objects. * * @param firstObject The first object for the set * @return A new, autoreleased set with the specified objects */ + (instancetype)setWithObjects: (ObjectType)firstObject, ...; /** * @brief Creates a new set with the specified objects. * * @param objects An array of objects for the set * @param count The number of objects in the specified array * @return A new, autoreleased set with the specified objects */ + (instancetype)setWithObjects: (ObjectType const _Nonnull *_Nonnull)objects count: (size_t)count; /** * @brief Initializes an already allocated set to be empty. * * @return An initialized set */ - (instancetype)init OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated set with the specified set. * * @param set The set to initialize the set with * @return An initialized set with the specified set */ - (instancetype)initWithSet: (OFSet OF_GENERIC(ObjectType) *)set; /** * @brief Initializes an already allocated set with the specified array. * * @param array The array to initialize the set with * @return An initialized set with the specified array */ - (instancetype)initWithArray: (OFArray OF_GENERIC(ObjectType) *)array; /** * @brief Initializes an already allocated set with the specified objects. * * @param firstObject The first object for the set * @return An initialized set with the specified objects */ - (instancetype)initWithObjects: (ObjectType)firstObject, ... OF_SENTINEL; /** * @brief Initializes an already allocated set with the specified object and * va_list. * * @param firstObject The first object for the set * @param arguments A va_list with the other objects * @return An initialized set with the specified object and va_list */ - (instancetype)initWithObject: (ObjectType)firstObject arguments: (va_list)arguments; /** * @brief Initializes an already allocated set with the specified objects. * * @param objects An array of objects for the set * @param count The number of objects in the specified array * @return An initialized set with the specified objects */ - (instancetype)initWithObjects: (ObjectType const _Nonnull *_Nonnull)objects count: (size_t)count OF_DESIGNATED_INITIALIZER; /** * @brief Returns an OFEnumerator to enumerate through all objects of the set. * * @return An OFEnumerator to enumerate through all objects of the set */ - (OFEnumerator OF_GENERIC(ObjectType) *)objectEnumerator; /** * @brief Returns whether the receiver is a subset of the specified set. * * @return Whether the receiver is a subset of the specified set */ - (bool)isSubsetOfSet: (OFSet OF_GENERIC(ObjectType) *)set; /** * @brief Returns whether the receiver and the specified set have at least one * object in common. * * @return Whether the receiver and the specified set have at least one object * in common */ - (bool)intersectsSet: (OFSet OF_GENERIC(ObjectType) *)set; /** * @brief Creates a new set by creating the union of the receiver and the * specified set. * * @param set The set to create the union with */ - (OFSet OF_GENERIC(ObjectType) *)setByAddingObjectsFromSet: (OFSet OF_GENERIC(ObjectType) *)set; /** * @brief Checks whether the set contains an object equal to the specified * object. * * @param object The object which is checked for being in the set * @return A boolean whether the set contains the specified object */ - (bool)containsObject: (ObjectType)object; /** * @brief Returns the value for the specified key * * A new set with the value for the specified key for each object is returned. * * The special key `@count` can be used to retrieve the count as an OFNumber. * * @note Unlike with @ref OFArray, any nil values are removed! * * @param key The key of the value to return * @return The value for the specified key */ - (nullable id)valueForKey: (OFString *)key; /** * @brief Set the value for the specified key * * @ref setValue:forKey: is called for each object. * * @note A @ref OFNull value is translated to nil! * * @param value The value for the specified key * @param key The key of the value to set */ - (void)setValue: (nullable id)value forKey: (OFString *)key; #ifdef OF_HAVE_BLOCKS /** * @brief Executes a block for each object in the set. * * @param block The block to execute for each object in the set */ - (void)enumerateObjectsUsingBlock: (OFSetEnumerationBlock)block; /** * @brief Creates a new set, only containing the objects for which the block * returns true. * * @param block A block which determines if the object should be in the new set * @return A new, autoreleased OFSet */ - (OFSet OF_GENERIC(ObjectType) *) filteredSetUsingBlock: (OFSetFilterBlock)block; #endif #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # undef ObjectType #endif @end OF_ASSUME_NONNULL_END #import "OFMutableSet.h" objfw-1.1.6/src/OFSet.m000066400000000000000000000220711465614216400145660ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFSet.h" #import "OFArray.h" #import "OFConcreteSet.h" #import "OFCountedSet.h" #import "OFNull.h" #import "OFString.h" static struct { Class isa; } placeholder; @interface OFPlaceholderSet: OFSet @end @implementation OFPlaceholderSet #ifdef __clang__ /* We intentionally don't call into super, so silence the warning. */ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunknown-pragmas" # pragma clang diagnostic ignored "-Wobjc-designated-initializers" #endif - (instancetype)init { return (id)[[OFConcreteSet alloc] init]; } - (instancetype)initWithSet: (OFSet *)set { return (id)[[OFConcreteSet alloc] initWithSet: set]; } - (instancetype)initWithArray: (OFArray *)array { return (id)[[OFConcreteSet alloc] initWithArray: array]; } - (instancetype)initWithObjects: (id)firstObject, ... { id ret; va_list arguments; va_start(arguments, firstObject); ret = [[OFConcreteSet alloc] initWithObject: firstObject arguments: arguments]; va_end(arguments); return ret; } - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { return (id)[[OFConcreteSet alloc] initWithObjects: objects count: count]; } - (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments { return (id)[[OFConcreteSet alloc] initWithObject: firstObject arguments: arguments]; } #ifdef __clang__ # pragma clang diagnostic pop #endif OF_SINGLETON_METHODS @end @implementation OFSet + (void)initialize { if (self == [OFSet class]) object_setClass((id)&placeholder, [OFPlaceholderSet class]); } + (instancetype)alloc { if (self == [OFSet class]) return (id)&placeholder; return [super alloc]; } + (instancetype)set { return [[[self alloc] init] autorelease]; } + (instancetype)setWithSet: (OFSet *)set { return [[[self alloc] initWithSet: set] autorelease]; } + (instancetype)setWithArray: (OFArray *)array { return [[[self alloc] initWithArray: array] autorelease]; } + (instancetype)setWithObjects: (id)firstObject, ... { id ret; va_list arguments; va_start(arguments, firstObject); ret = [[[self alloc] initWithObject: firstObject arguments: arguments] autorelease]; va_end(arguments); return ret; } + (instancetype)setWithObjects: (id const *)objects count: (size_t)count { return [[[self alloc] initWithObjects: objects count: count] autorelease]; } - (instancetype)init { if ([self isMemberOfClass: [OFSet class]] || [self isMemberOfClass: [OFMutableSet class]] || [self isMemberOfClass: [OFCountedSet class]]) { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @throw e; } abort(); } return [super init]; } - (instancetype)initWithSet: (OFSet *)set { id *objects = NULL; size_t count; @try { void *pool = objc_autoreleasePoolPush(); size_t i = 0; count = set.count; objects = OFAllocMemory(count, sizeof(id)); for (id object in set) { OFEnsure(i < count); objects[i++] = object; } objc_autoreleasePoolPop(pool); } @catch (id e) { OFFreeMemory(objects); [self release]; @throw e; } @try { self = [self initWithObjects: objects count: count]; } @finally { OFFreeMemory(objects); } return self; } - (instancetype)initWithArray: (OFArray *)array { void *pool = objc_autoreleasePoolPush(); size_t count; const id *objects; @try { count = array.count; objects = array.objects; } @catch (id e) { [self release]; @throw e; } self = [self initWithObjects: objects count: count]; objc_autoreleasePoolPop(pool); return self; } #ifdef __clang__ /* We intentionally don't call into super, so silence the warning. */ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunknown-pragmas" # pragma clang diagnostic ignored "-Wobjc-designated-initializers" #endif - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { OF_INVALID_INIT_METHOD } #ifdef __clang__ # pragma clang diagnostic pop #endif - (instancetype)initWithObjects: (id)firstObject, ... { id ret; va_list arguments; va_start(arguments, firstObject); ret = [self initWithObject: firstObject arguments: arguments]; va_end(arguments); return ret; } - (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments { size_t count = 1; va_list argumentsCopy; id *objects; if (firstObject == nil) return [self init]; va_copy(argumentsCopy, arguments); while (va_arg(argumentsCopy, id) != nil) count++; @try { objects = OFAllocMemory(count, sizeof(id)); } @catch (id e) { [self release]; @throw e; } @try { objects[0] = firstObject; for (size_t i = 1; i < count; i++) { objects[i] = va_arg(arguments, id); OFEnsure(objects[i] != nil); } self = [self initWithObjects: objects count: count]; } @finally { OFFreeMemory(objects); } return self; } - (size_t)count { OF_UNRECOGNIZED_SELECTOR } - (id)valueForKey: (OFString *)key { id ret; if ([key isEqual: @"@count"]) return [super valueForKey: @"count"]; ret = [OFMutableSet setWithCapacity: self.count]; for (id object in self) { id value = [object valueForKey: key]; if (value != nil) [ret addObject: value]; } [ret makeImmutable]; return ret; } - (void)setValue: (id)value forKey: (OFString *)key { for (id object in self) [object setValue: value forKey: key]; } - (bool)containsObject: (id)object { OF_UNRECOGNIZED_SELECTOR } - (OFEnumerator *)objectEnumerator { OF_UNRECOGNIZED_SELECTOR } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count { static unsigned long dummyMutations; OFEnumerator *enumerator; int i; memcpy(&enumerator, state->extra, sizeof(enumerator)); if (enumerator == nil) { enumerator = [self objectEnumerator]; memcpy(state->extra, &enumerator, sizeof(enumerator)); } state->itemsPtr = objects; state->mutationsPtr = &dummyMutations; for (i = 0; i < count; i++) { id object = [enumerator nextObject]; if (object == nil) return i; objects[i] = object; } return i; } - (bool)isEqual: (id)object { OFSet *set; if (object == self) return true; if (![object isKindOfClass: [OFSet class]]) return false; set = object; if (set.count != self.count) return false; return [set isSubsetOfSet: self]; } - (unsigned long)hash { void *pool = objc_autoreleasePoolPush(); unsigned long hash = 0; for (id object in self) hash ^= [object hash]; objc_autoreleasePoolPop(pool); return hash; } - (OFString *)description { void *pool; OFMutableString *ret; size_t i, count = self.count; if (count == 0) return @"{()}"; ret = [OFMutableString stringWithString: @"{(\n"]; pool = objc_autoreleasePoolPush(); i = 0; for (id object in self) { void *pool2 = objc_autoreleasePoolPush(); [ret appendString: [object description]]; if (++i < count) [ret appendString: @",\n"]; objc_autoreleasePoolPop(pool2); } [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @"\n)}"]; [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } - (id)copy { return [self retain]; } - (id)mutableCopy { return [[OFMutableSet alloc] initWithSet: self]; } - (bool)isSubsetOfSet: (OFSet *)set { for (id object in self) if (![set containsObject: object]) return false; return true; } - (bool)intersectsSet: (OFSet *)set { for (id object in self) if ([set containsObject: object]) return true; return false; } - (OFSet *)setByAddingObjectsFromSet: (OFSet *)set { OFMutableSet *new = [[self mutableCopy] autorelease]; [new unionSet: set]; [new makeImmutable]; return new; } - (OFArray *)allObjects { void *pool = objc_autoreleasePoolPush(); OFArray *ret = [[[self objectEnumerator] allObjects] retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (id)anyObject { void *pool = objc_autoreleasePoolPush(); id ret = [[[self objectEnumerator] nextObject] retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (OFSetEnumerationBlock)block { bool stop = false; for (id object in self) { block(object, &stop); if (stop) break; } } - (OFSet *)filteredSetUsingBlock: (OFSetFilterBlock)block { OFMutableSet *ret = [OFMutableSet set]; [self enumerateObjectsUsingBlock: ^ (id object, bool *stop) { if (block(object)) [ret addObject: object]; }]; [ret makeImmutable]; return ret; } #endif @end objfw-1.1.6/src/OFSettings.h000066400000000000000000000147751465614216400156420ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN @class OFString; @class OFArray OF_GENERIC(ObjectType); /** * @class OFSettings OFSettings.h ObjFW/OFSettings.h * * Paths are delimited by dots, for example `category.subcategory.key`. * * @note The behavior when accessing a path with a different type than it has * been accessed with before is undefined! If you want to change the type * for a path, remove it and then set it with the new type. * * @brief A class for storing and retrieving settings */ @interface OFSettings: OFObject { OFString *_applicationName; OF_RESERVE_IVARS(OFSettings, 4) } /** * @brief The name of the application whose settings are accessed by the * instance. */ @property (readonly, nonatomic) OFString *applicationName; /** * @brief Create a new OFSettings instance for the application with the * specified name. * * @param applicationName The name of the application whose settings should be * accessed * @return A new, autoreleased OFSettings instance */ + (instancetype)settingsWithApplicationName: (OFString *)applicationName; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFSettings instance with the * specified application name. * * @param applicationName The name of the application whose settings should be * accessed * @return An initialized OFSettings instance */ - (instancetype)initWithApplicationName: (OFString *)applicationName OF_DESIGNATED_INITIALIZER; /** * @brief Sets the specified path to the specified string. * * @param string The string to set * @param path The path to store the string at */ - (void)setString: (OFString *)string forPath: (OFString *)path; /** * @brief Sets the specified path to the specified long long. * * @param longLong The long long to set * @param path The path to store the long long at */ - (void)setLongLong: (long long)longLong forPath: (OFString *)path; /** * @brief Sets the specified path to the specified bool. * * @param bool_ The bool to set * @param path The path to store the bool at */ - (void)setBool: (bool)bool_ forPath: (OFString *)path; /** * @brief Sets the specified path to the specified float. * * @param float_ The float to set * @param path The path to store the float at */ - (void)setFloat: (float)float_ forPath: (OFString *)path; /** * @brief Sets the specified path to the specified double. * * @param double_ The double to set * @param path The path to store the double at */ - (void)setDouble: (double)double_ forPath: (OFString *)path; /** * @brief Sets the specified path to the specified array of strings. * * @param array The array of strings to set * @param path The path to store the array of string at */ - (void)setStringArray: (OFArray OF_GENERIC(OFString *) *)array forPath: (OFString *)path; /** * @brief Returns the string for the specified path, or `nil` if the path does * not exist. * * @param path The path for which the string should be returned * @return The string of the specified path */ - (nullable OFString *)stringForPath: (OFString *)path; /** * @brief Returns the string for the specified path, or the default value if * the path does not exist. * * @param path The path for which the string should be returned * @param defaultValue The default value to return if the path does not exist * @return The string of the specified path */ - (nullable OFString *)stringForPath: (OFString *)path defaultValue: (nullable OFString *)defaultValue; /** * @brief Returns the long long for the specified path, or the default value if * the path does not exist. * * @param path The path for which the long long should be returned * @param defaultValue The default value to return if the path does not exist * @return The long long of the specified path */ - (long long)longLongForPath: (OFString *)path defaultValue: (long long)defaultValue; /** * @brief Returns the bool for the specified path, or the default value if the * path does not exist. * * @param path The path for which the bool should be returned * @param defaultValue The default value to return if the path does not exist * @return The bool of the specified path */ - (bool)boolForPath: (OFString *)path defaultValue: (bool)defaultValue; /** * @brief Returns the float for the specified path, or the default value if the * path does not exist. * * @param path The path for which the float should be returned * @param defaultValue The default value to return if the path does not exist * @return The float of the specified path */ - (float)floatForPath: (OFString *)path defaultValue: (float)defaultValue; /** * @brief Returns the double for the specified path, or the default value if * the path does not exist. * * @param path The path for which the double should be returned * @param defaultValue The default value to return if the path does not exist * @return The double of the specified path */ - (double)doubleForPath: (OFString *)path defaultValue: (double)defaultValue; /** * @brief Returns the array of strings for the specified path, or an empty * array if the path does not exist. * * @param path The path for which the array of strings should be returned * @return The array of string values of the specified path */ - (OFArray OF_GENERIC(OFString *) *)stringArrayForPath: (OFString *)path; /** * @brief Removes the value for the specified path. * * @param path The path for which the value should be removed */ - (void)removeValueForPath: (OFString *)path; /** * @brief Saves the settings to disk. * * @warning Some backends might save the settings instantly, others might not * save them before calling this method for performance reasons. You * should always call this method after doing a bunch of changes, no * matter which backend is used! */ - (void)save; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFSettings.m000066400000000000000000000056711465614216400156420ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFSettings.h" #import "OFINIFileSettings.h" #import "OFString.h" @implementation OFSettings @synthesize applicationName = _applicationName; + (instancetype)alloc { if (self == [OFSettings class]) return [OFINIFileSettings alloc]; return [super alloc]; } + (instancetype)settingsWithApplicationName: (OFString *)applicationName { return [[[self alloc] initWithApplicationName: applicationName] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithApplicationName: (OFString *)applicationName { self = [super init]; @try { _applicationName = [applicationName copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_applicationName release]; [super dealloc]; } - (void)setString: (OFString *)string forPath: (OFString *)path { OF_UNRECOGNIZED_SELECTOR } - (void)setLongLong: (long long)longLong forPath: (OFString *)path { OF_UNRECOGNIZED_SELECTOR } - (void)setBool: (bool)bool_ forPath: (OFString *)path { OF_UNRECOGNIZED_SELECTOR } - (void)setFloat: (float)float_ forPath: (OFString *)path { OF_UNRECOGNIZED_SELECTOR } - (void)setDouble: (double)double_ forPath: (OFString *)path { OF_UNRECOGNIZED_SELECTOR } - (void)setStringArray: (OFArray OF_GENERIC(OFString *) *)array forPath: (OFString *)path { OF_UNRECOGNIZED_SELECTOR } - (OFString *)stringForPath: (OFString *)path { return [self stringForPath: path defaultValue: nil]; } - (OFString *)stringForPath: (OFString *)path defaultValue: (OFString *)defaultValue { OF_UNRECOGNIZED_SELECTOR } - (long long)longLongForPath: (OFString *)path defaultValue: (long long)defaultValue { OF_UNRECOGNIZED_SELECTOR } - (bool)boolForPath: (OFString *)path defaultValue: (bool)defaultValue { OF_UNRECOGNIZED_SELECTOR } - (float)floatForPath: (OFString *)path defaultValue: (float)defaultValue { OF_UNRECOGNIZED_SELECTOR } - (double)doubleForPath: (OFString *)path defaultValue: (double)defaultValue { OF_UNRECOGNIZED_SELECTOR } - (OFArray OF_GENERIC(OFString *) *)stringArrayForPath: (OFString *)path { OF_UNRECOGNIZED_SELECTOR } - (void)removeValueForPath: (OFString *)path { OF_UNRECOGNIZED_SELECTOR } - (void)save { OF_UNRECOGNIZED_SELECTOR } @end objfw-1.1.6/src/OFSocket+Private.h000066400000000000000000000061101465614216400166600ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "unistd_wrapper.h" #ifdef HAVE_ARPA_INET_H # include #endif #ifdef HAVE_NETDB_H # include #endif #import "OFSocket.h" #ifndef INADDR_NONE # define INADDR_NONE ((in_addr_t)-1) #endif #ifndef SOMAXCONN /* * Use 16 as everything > 17 fails on Nintendo 3DS and 16 is a less arbitrary * number than 17. */ # define SOMAXCONN 16 #endif #ifndef SOCK_CLOEXEC # define SOCK_CLOEXEC 0 #endif #if defined(OF_AMIGAOS) # ifdef OF_MORPHOS # include # else # include # endif # include # define closesocket(sock) CloseSocket(sock) # define ioctlsocket(fd, req, arg) IoctlSocket(fd, req, arg) # define hstrerror(err) "unknown (no hstrerror)" # define SOCKET_ERROR -1 # if defined(OF_HAVE_THREADS) && !defined(OF_MORPHOS) # define SocketBase ((struct Library *)OFTLSKeyGet(_OFSocketBaseKey)) # ifdef OF_AMIGAOS4 # define ISocket ((struct SocketIFace *)OFTLSKeyGet(_OFSocketInterfaceKey)) # endif # endif # ifdef OF_MORPHOS typedef uint32_t in_addr_t; # endif #elif !defined(OF_WINDOWS) && !defined(OF_WII) # define closesocket(sock) close(sock) #endif #ifdef OF_WII # define accept(sock, addr, addrlen) net_accept(sock, addr, addrlen) # define bind(sock, addr, addrlen) net_bind(sock, addr, addrlen) # define closesocket(sock) net_close(sock) # define connect(sock, addr, addrlen) \ net_connect(sock, (struct sockaddr *)addr, addrlen) # define fcntl(fd, cmd, flags) net_fcntl(fd, cmd, flags) # define h_errno 0 # define hstrerror(err) "unknown (no hstrerror)" # define listen(sock, backlog) net_listen(sock, backlog) # define poll(fds, nfds, timeout) net_poll(fds, nfds, timeout) # define recv(sock, buf, len, flags) net_recv(sock, buf, len, flags) # define recvfrom(sock, buf, len, flags, addr, addrlen) \ net_recvfrom(sock, buf, len, flags, addr, addrlen) # define select(nfds, readfds, writefds, errorfds, timeout) \ net_select(nfds, readfds, writefds, errorfds, timeout) # define send(sock, buf, len, flags) net_send(sock, buf, len, flags) # define sendto(sock, buf, len, flags, addr, addrlen) \ net_sendto(sock, buf, len, flags, (struct sockaddr *)(addr), addrlen) # define setsockopt(sock, level, name, value, len) \ net_setsockopt(sock, level, name, value, len) # define socket(domain, type, proto) net_socket(domain, type, proto) typedef u32 in_addr_t; typedef u32 nfds_t; #endif objfw-1.1.6/src/OFSocket.h000066400000000000000000000312671465614216400152650ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "objfw-defs.h" #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif #include #import "OFString.h" #if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) # import "OFTLSKey.h" #endif #ifdef OF_HAVE_SYS_SOCKET_H # include #endif #ifdef OF_HAVE_NETINET_IN_H # include #endif #ifdef OF_HAVE_NETINET_TCP_H # include #endif #ifdef OF_HAVE_SYS_UN_H # include #endif #ifdef OF_HAVE_AFUNIX_H # include #endif #ifdef OF_HAVE_NETIPX_IPX_H # include #endif #if defined(OF_HAVE_NETAT_APPLETALK_H) # include #elif defined(OF_HAVE_NETATALK_AT_H) # include #endif #ifdef OF_WINDOWS # include # include # ifdef OF_HAVE_IPX # include # endif # ifdef OF_HAVE_APPLETALK # include # endif #endif #ifdef OF_WII # include #endif #ifdef OF_PSP # include #endif #import "macros.h" OF_ASSUME_NONNULL_BEGIN /** @file */ #ifndef OF_WINDOWS typedef int OFSocketHandle; static const OFSocketHandle OFInvalidSocketHandle = -1; #else typedef SOCKET OFSocketHandle; static const OFSocketHandle OFInvalidSocketHandle = INVALID_SOCKET; #endif #ifdef OF_WINDOWS typedef short sa_family_t; #endif #ifdef OF_WII typedef u8 sa_family_t; #endif #ifdef OF_MORPHOS typedef long socklen_t; typedef u_char sa_family_t; typedef u_short in_port_t; #endif /** * @brief A socket address family. */ typedef enum { /** An unknown address family. */ OFSocketAddressFamilyUnknown, /** IPv4 */ OFSocketAddressFamilyIPv4, /** IPv6 */ OFSocketAddressFamilyIPv6, /** UNIX */ OFSocketAddressFamilyUNIX, /** IPX */ OFSocketAddressFamilyIPX, /** AppleTalk */ OFSocketAddressFamilyAppleTalk, /** Any address family */ OFSocketAddressFamilyAny = 255 } OFSocketAddressFamily; #ifndef OF_HAVE_IPV6 struct sockaddr_in6 { sa_family_t sin6_family; in_port_t sin6_port; uint32_t sin6_flowinfo; struct in6_addr { uint8_t s6_addr[16]; } sin6_addr; uint32_t sin6_scope_id; }; #endif #if !defined(OF_HAVE_UNIX_SOCKETS) && !defined(OF_MORPHOS) && !defined(OF_MINT) struct sockaddr_un { sa_family_t sun_family; char sun_path[108]; }; #endif #ifndef IPX_NODE_LEN # define IPX_NODE_LEN 6 #endif #if !defined(OF_HAVE_IPX) struct sockaddr_ipx { sa_family_t sipx_family; uint32_t sipx_network; unsigned char sipx_node[IPX_NODE_LEN]; uint16_t sipx_port; uint8_t sipx_type; }; #elif defined(OF_WINDOWS) # define IPX_NODE_LEN 6 # define sipx_family sa_family # define sipx_network sa_netnum # define sipx_node sa_nodenum # define sipx_port sa_socket #elif defined(OF_FREEBSD) # define sipx_network sipx_addr.x_net.c_net # define sipx_node sipx_addr.x_host.c_host #endif #ifndef OF_HAVE_APPLETALK struct sockaddr_at { sa_family_t sat_family; uint8_t sat_port; uint16_t sat_net; uint8_t sat_node; }; #else # ifdef OF_WINDOWS # define sat_port sat_socket # else # define sat_net sat_addr.s_net # define sat_node sat_addr.s_node # endif #endif /** * @struct OFSocketAddress OFSocket.h ObjFW/OFSocket.h * * @brief A struct which represents a host / port pair for a socket. */ typedef struct OF_BOXABLE OFSocketAddress { OFSocketAddressFamily family; /* * We can't use struct sockaddr as it can contain variable length * arrays. */ union { struct sockaddr_in in; struct sockaddr_in6 in6; struct sockaddr_un un; struct sockaddr_ipx ipx; struct sockaddr_at at; #ifdef OF_HAVE_SOCKADDR_STORAGE /* * Required to make the ABI stable in case we want to add more * address types later. */ struct sockaddr_storage storage; #endif } sockaddr; socklen_t length; } OFSocketAddress; #ifdef __cplusplus extern "C" { #endif /** * @brief Parses the specified IP (either v4 or v6) and port into an * @ref OFSocketAddress. * * @param IP The IP to parse * @param port The port to use * @return The parsed IP and port as an OFSocketAddress * @throw OFInvalidFormatException The specified string is not a valid IP */ extern OFSocketAddress OFSocketAddressParseIP(OFString *IP, uint16_t port); /** * @brief Parses the specified IPv4 and port into an @ref OFSocketAddress. * * @param IP The IPv4 to parse * @param port The port to use * @return The parsed IPv4 and port as an OFSocketAddress * @throw OFInvalidFormatException The specified string is not a valid IPv4 */ extern OFSocketAddress OFSocketAddressParseIPv4(OFString *IP, uint16_t port); /** * @brief Parses the specified IPv6 and port into an @ref OFSocketAddress. * * @param IP The IPv6 to parse * @param port The port to use * @return The parsed IPv6 and port as an OFSocketAddress * @throw OFInvalidFormatException The specified string is not a valid IPv6 */ extern OFSocketAddress OFSocketAddressParseIPv6(OFString *IP, uint16_t port); /** * @brief Creates a UNIX socket address from the specified path. * * @param path The path of the UNIX socket * @return A UNIX socket address with the specified path */ extern OFSocketAddress OFSocketAddressMakeUNIX(OFString *path); /** * @brief Creates an IPX address for the specified network, node and port. * * @param network The IPX network * @param node The node in the IPX network * @param port The IPX port (sometimes called socket number) on the node * @return An IPX socket address with the specified node, network and port. */ extern OFSocketAddress OFSocketAddressMakeIPX(uint32_t network, const unsigned char node[_Nonnull IPX_NODE_LEN], uint16_t port); /** * @brief Creates an AppleTalk address for the specified network, node and port. * * @param network The AppleTalk network * @param node The node in the AppleTalk network * @param port The AppleTalk (sometimes called socket number) on the node * @return An AppleTalk socket address with the specified node, network and * port. */ extern OFSocketAddress OFSocketAddressMakeAppleTalk(uint16_t network, uint8_t node, uint8_t port); /** * @brief Compares two OFSocketAddress for equality. * * @param address1 The address to compare with the second address * @param address2 The second address * @return Whether the two addresses are equal */ extern bool OFSocketAddressEqual(const OFSocketAddress *_Nonnull address1, const OFSocketAddress *_Nonnull address2); /** * @brief Returns the hash for the specified @ref OFSocketAddress. * * @param address The address to hash * @return The hash for the specified OFSocketAddress */ extern unsigned long OFSocketAddressHash( const OFSocketAddress *_Nonnull address); /** * @brief Converts the specified @ref OFSocketAddress to a string. * * @param address The address to convert to a string * @return The address as a string, without the port */ extern OFString *_Nonnull OFSocketAddressString( const OFSocketAddress *_Nonnull address); /** * @brief Returns a description for the specified @ref OFSocketAddress. * * This is similar to @ref OFSocketAddressString, but it also contains the port. * * @param address The address to return a description for * @return The address as an string, with the port */ extern OFString *_Nonnull OFSocketAddressDescription( const OFSocketAddress *_Nonnull address); /** * @brief Sets the IP port of the specified @ref OFSocketAddress. * * @param address The address on which to set the port * @param port The port to set on the address */ extern void OFSocketAddressSetIPPort(OFSocketAddress *_Nonnull address, uint16_t port); /** * @brief Returns the IP port of the specified @ref OFSocketAddress. * * @param address The address on which to get the port * @return The port of the address */ extern uint16_t OFSocketAddressIPPort(const OFSocketAddress *_Nonnull address); /** * @brief Gets the UNIX socket path of the specified @ref OFSocketAddress. * * @param address The address on which to get the UNIX socket path * @return The UNIX socket path */ extern OFString *OFSocketAddressUNIXPath( const OFSocketAddress *_Nonnull address); /** * @brief Sets the IPX network of the specified @ref OFSocketAddress. * * @param address The address on which to set the IPX network * @param network The IPX network to set on the address */ extern void OFSocketAddressSetIPXNetwork(OFSocketAddress *_Nonnull address, uint32_t network); /** * @brief Returns the IPX network of the specified @ref OFSocketAddress. * * @param address The address on which to get the IPX network * @return The IPX network of the address */ extern uint32_t OFSocketAddressIPXNetwork( const OFSocketAddress *_Nonnull address); /** * @brief Sets the IPX node of the specified @ref OFSocketAddress. * * @param address The address on which to set the IPX node * @param node The IPX node to set on the address */ extern void OFSocketAddressSetIPXNode(OFSocketAddress *_Nonnull address, const unsigned char node[_Nonnull IPX_NODE_LEN]); /** * @brief Gets the IPX node of the specified @ref OFSocketAddress. * * @param address The address on which to get the IPX node * @param node A byte array to store the IPX node of the address */ extern void OFSocketAddressGetIPXNode(const OFSocketAddress *_Nonnull address, unsigned char node[_Nonnull IPX_NODE_LEN]); /** * @brief Sets the IPX port of the specified @ref OFSocketAddress. * * @param address The address on which to set the port * @param port The port to set on the address */ extern void OFSocketAddressSetIPXPort(OFSocketAddress *_Nonnull address, uint16_t port); /** * @brief Returns the IPX port of the specified @ref OFSocketAddress. * * @param address The address on which to get the port * @return The port of the address */ extern uint16_t OFSocketAddressIPXPort(const OFSocketAddress *_Nonnull address); /** * @brief Sets the AppleTalk network of the specified @ref OFSocketAddress. * * @param address The address on which to set the AppleTalk network * @param network The AppleTalk network to set on the address */ extern void OFSocketAddressSetAppleTalkNetwork( OFSocketAddress *_Nonnull address, uint16_t network); /** * @brief Returns the AppleTalk network of the specified @ref OFSocketAddress. * * @param address The address on which to get the AppleTalk network * @return The AppleTalk network of the address */ extern uint16_t OFSocketAddressAppleTalkNetwork( const OFSocketAddress *_Nonnull address); /** * @brief Sets the AppleTalk node of the specified @ref OFSocketAddress. * * @param address The address on which to set the AppleTalk node * @param node The AppleTalk node to set on the address */ extern void OFSocketAddressSetAppleTalkNode(OFSocketAddress *_Nonnull address, uint8_t node); /** * @brief Gets the AppleTalk node of the specified @ref OFSocketAddress. * * @param address The address on which to get the AppleTalk node * @return The AppleTalk node of the address */ extern uint8_t OFSocketAddressAppleTalkNode( const OFSocketAddress *_Nonnull address); /** * @brief Sets the AppleTalk port of the specified @ref OFSocketAddress. * * @param address The address on which to set the port * @param port The port to set on the address */ extern void OFSocketAddressSetAppleTalkPort(OFSocketAddress *_Nonnull address, uint8_t port); /** * @brief Returns the AppleTalk port of the specified @ref OFSocketAddress. * * @param address The address on which to get the port * @return The port of the address */ extern uint8_t OFSocketAddressAppleTalkPort( const OFSocketAddress *_Nonnull address); extern bool _OFSocketInit(void) OF_VISIBILITY_HIDDEN; #if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS) extern void _OFSocketDeinit(void) OF_VISIBILITY_HIDDEN; #endif extern int _OFSocketErrNo(void) OF_VISIBILITY_HIDDEN; #if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) extern int _OFGetSockName(OFSocketHandle sock, struct sockaddr *restrict addr, socklen_t *restrict addrLen) OF_VISIBILITY_HIDDEN; #endif #if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS) extern OFTLSKey _OFSocketBaseKey OF_VISIBILITY_HIDDEN; # ifdef OF_AMIGAOS4 extern OFTLSKey _OFSocketInterfaceKey OF_VISIBILITY_HIDDEN; # endif #endif #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFSocket.m000066400000000000000000000724241465614216400152720ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #ifndef _XOPEN_SOURCE_EXTENDED # define _XOPEN_SOURCE_EXTENDED #endif #define _HPUX_ALT_XOPEN_SOCKET_API #ifdef OF_NINTENDO_3DS # include /* For memalign() */ #endif #include #import "OFArray.h" #import "OFCharacterSet.h" #import "OFLocale.h" #ifdef OF_HAVE_THREADS # import "OFMutex.h" #endif #import "OFOnce.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFString.h" #ifdef OF_HAVE_THREADS # import "OFTLSKey.h" #endif #import "OFException.h" /* For some E* -> WSAE* defines */ #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFLockFailedException.h" #import "OFOutOfRangeException.h" #import "OFUnlockFailedException.h" #ifdef HAVE_NET_IF_H # include #endif #ifdef OF_AMIGAOS # define Class IntuitionClass # include # undef Class #endif #ifdef OF_NINTENDO_3DS # include <3ds/types.h> # include <3ds/services/soc.h> #endif #ifdef OF_NINTENDO_SWITCH # define id nx_id # include # undef id #endif #if defined(OF_HAVE_THREADS) && (!defined(OF_AMIGAOS) || defined(OF_MORPHOS)) static OFMutex *mutex; static void releaseMutex(void) { [mutex release]; } #endif #if !defined(OF_AMIGAOS) || defined(OF_MORPHOS) || !defined(OF_HAVE_THREADS) static bool initSuccessful = false; #endif #ifdef OF_AMIGAOS # if defined(OF_HAVE_THREADS) && !defined(OF_MORPHOS) OFTLSKey _OFSocketBaseKey; # ifdef OF_AMIGAOS4 OFTLSKey _OFSocketInterfaceKey; # endif # else struct Library *SocketBase; # ifdef OF_AMIGAOS4 struct SocketIFace *ISocket = NULL; # endif # endif #endif #if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS) OF_CONSTRUCTOR() { if (OFTLSKeyNew(&_OFSocketBaseKey) != 0) @throw [OFInitializationFailedException exception]; # ifdef OF_AMIGAOS4 if (OFTLSKeyNew(&_OFSocketInterfaceKey) != 0) @throw [OFInitializationFailedException exception]; # endif } #endif #if !defined(OF_AMIGAOS) || defined(OF_MORPHOS) || !defined(OF_HAVE_THREADS) static void init(void) { # if defined(OF_WINDOWS) WSADATA wsa; if (WSAStartup(MAKEWORD(2, 0), &wsa)) return; # elif defined(OF_AMIGAOS) if ((SocketBase = OpenLibrary("bsdsocket.library", 4)) == NULL) return; # ifdef OF_AMIGAOS4 if ((ISocket = (struct SocketIFace *) GetInterface(SocketBase, "main", 1, NULL)) == NULL) { CloseLibrary(SocketBase); return; } # endif # elif defined(OF_WII) if (net_init() < 0) return; # elif defined(OF_NINTENDO_3DS) void *ctx; if ((ctx = memalign(0x1000, 0x100000)) == NULL) return; if (socInit(ctx, 0x100000) != 0) return; atexit((void (*)(void))socExit); # elif defined(OF_NINTENDO_SWITCH) if (R_FAILED(socketInitializeDefault())) return; atexit(socketExit); # endif # if defined(OF_HAVE_THREADS) && (!defined(OF_AMIGAOS) || defined(OF_MORPHOS)) mutex = [[OFMutex alloc] init]; atexit(releaseMutex); # endif initSuccessful = true; } OF_DESTRUCTOR() { # ifdef OF_AMIGAOS # ifdef OF_AMIGAOS4 if (ISocket != NULL) DropInterface((struct Interface *)ISocket); # endif if (SocketBase != NULL) CloseLibrary(SocketBase); # endif } #endif bool _OFSocketInit(void) { #if !defined(OF_AMIGAOS) || defined(OF_MORPHOS) || !defined(OF_HAVE_THREADS) static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, init); return initSuccessful; #else struct Library *socketBase; # ifdef OF_AMIGAOS4 struct SocketIFace *socketInterface; # endif # ifdef OF_AMIGAOS4 if ((socketInterface = OFTLSKeyGet(_OFSocketInterfaceKey)) != NULL) # else if ((socketBase = OFTLSKeyGet(_OFSocketBaseKey)) != NULL) # endif return true; if ((socketBase = OpenLibrary("bsdsocket.library", 4)) == NULL) return false; # ifdef OF_AMIGAOS4 if ((socketInterface = (struct SocketIFace *) GetInterface(socketBase, "main", 1, NULL)) == NULL) { CloseLibrary(socketBase); return false; } # endif if (OFTLSKeySet(_OFSocketBaseKey, socketBase) != 0) { CloseLibrary(socketBase); # ifdef OF_AMIGAOS4 DropInterface((struct Interface *)socketInterface); # endif return false; } # ifdef OF_AMIGAOS4 if (OFTLSKeySet(_OFSocketInterfaceKey, socketInterface) != 0) { CloseLibrary(socketBase); DropInterface((struct Interface *)socketInterface); return false; } # endif return true; #endif } #if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS) void _OFSocketDeinit(void) { struct Library *socketBase = OFTLSKeyGet(_OFSocketBaseKey); # ifdef OF_AMIGAOS4 struct SocketIFace *socketInterface = OFTLSKeyGet(_OFSocketInterfaceKey); if (socketInterface != NULL) DropInterface((struct Interface *)socketInterface); # endif if (socketBase != NULL) CloseLibrary(socketBase); } #endif int _OFSocketErrNo(void) { #if defined(OF_WINDOWS) switch (WSAGetLastError()) { case WSAEACCES: return EACCES; case WSAEADDRINUSE: return EADDRINUSE; case WSAEADDRNOTAVAIL: return EADDRNOTAVAIL; case WSAEAFNOSUPPORT: return EAFNOSUPPORT; case WSAEALREADY: return EALREADY; case WSAEBADF: return EBADF; case WSAECONNABORTED: return ECONNABORTED; case WSAECONNREFUSED: return ECONNREFUSED; case WSAECONNRESET: return ECONNRESET; case WSAEDESTADDRREQ: return EDESTADDRREQ; case WSAEDISCON: return EPIPE; case WSAEDQUOT: return EDQUOT; case WSAEFAULT: return EFAULT; case WSAEHOSTDOWN: return EHOSTDOWN; case WSAEHOSTUNREACH: return EHOSTUNREACH; case WSAEINPROGRESS: return EINPROGRESS; case WSAEINTR: return EINTR; case WSAEINVAL: return EINVAL; case WSAEISCONN: return EISCONN; case WSAELOOP: return ELOOP; case WSAEMSGSIZE: return EMSGSIZE; case WSAENAMETOOLONG: return ENAMETOOLONG; case WSAENETDOWN: return ENETDOWN; case WSAENETRESET: return ENETRESET; case WSAENETUNREACH: return ENETUNREACH; case WSAENOBUFS: return ENOBUFS; case WSAENOPROTOOPT: return ENOPROTOOPT; case WSAENOTCONN: return ENOTCONN; case WSAENOTEMPTY: return ENOTEMPTY; case WSAENOTSOCK: return ENOTSOCK; case WSAEOPNOTSUPP: return EOPNOTSUPP; case WSAEPFNOSUPPORT: return EPFNOSUPPORT; case WSAEPROCLIM: return EPROCLIM; case WSAEPROTONOSUPPORT: return EPROTONOSUPPORT; case WSAEPROTOTYPE: return EPROTOTYPE; case WSAEREMOTE: return EREMOTE; case WSAESHUTDOWN: return ESHUTDOWN; case WSAESOCKTNOSUPPORT: return ESOCKTNOSUPPORT; case WSAESTALE: return ESTALE; case WSAETIMEDOUT: return ETIMEDOUT; case WSAETOOMANYREFS: return ETOOMANYREFS; case WSAEUSERS: return EUSERS; case WSAEWOULDBLOCK: return EWOULDBLOCK; } return 0; #elif defined(OF_AMIGAOS) return Errno(); #else return errno; #endif } #ifndef OF_WII int _OFGetSockName(OFSocketHandle sock, struct sockaddr *restrict addr, socklen_t *restrict addrLen) { int ret; # if defined(OF_HAVE_THREADS) && (!defined(OF_AMIGAOS) || defined(OF_MORPHOS)) [mutex lock]; # endif ret = getsockname(sock, addr, addrLen); # if defined(OF_HAVE_THREADS) && (!defined(OF_AMIGAOS) || defined(OF_MORPHOS)) [mutex unlock]; # endif return ret; } #endif OFSocketAddress OFSocketAddressParseIPv4(OFString *IPv4, uint16_t port) { void *pool = objc_autoreleasePoolPush(); OFCharacterSet *whitespaceCharacterSet = [OFCharacterSet whitespaceCharacterSet]; OFSocketAddress ret; struct sockaddr_in *addrIn = &ret.sockaddr.in; OFArray OF_GENERIC(OFString *) *components; uint32_t addr; memset(&ret, '\0', sizeof(ret)); ret.family = OFSocketAddressFamilyIPv4; #if defined(OF_WII) || defined(OF_NINTENDO_3DS) ret.length = 8; #else ret.length = sizeof(ret.sockaddr.in); #endif addrIn->sin_family = AF_INET; addrIn->sin_port = OFToBigEndian16(port); #ifdef OF_WII addrIn->sin_len = ret.length; #endif components = [IPv4 componentsSeparatedByString: @"."]; if (components.count != 4) @throw [OFInvalidFormatException exception]; addr = 0; for (OFString *component in components) { unsigned long long number; if (component.length == 0) @throw [OFInvalidFormatException exception]; if ([component indexOfCharacterFromSet: whitespaceCharacterSet] != OFNotFound) @throw [OFInvalidFormatException exception]; number = component.unsignedLongLongValue; if (number > UINT8_MAX) @throw [OFInvalidFormatException exception]; addr = (addr << 8) | ((uint32_t)number & 0xFF); } addrIn->sin_addr.s_addr = OFToBigEndian32(addr); objc_autoreleasePoolPop(pool); return ret; } static uint16_t parseIPv6Component(OFString *component) { unsigned long long number; if ([component indexOfCharacterFromSet: [OFCharacterSet whitespaceCharacterSet]] != OFNotFound) @throw [OFInvalidFormatException exception]; number = [component unsignedLongLongValueWithBase: 16]; if (number > UINT16_MAX) @throw [OFInvalidFormatException exception]; return (uint16_t)number; } static OFString * transformEmbeddedIPv4(OFString *IPv6) { size_t lastColon = [IPv6 rangeOfString: @":" options: OFStringSearchBackwards].location; OFString *IPv4; OFSocketAddress address; const struct sockaddr_in *addrIn; uint32_t addr; if (lastColon == OFNotFound) @throw [OFInvalidFormatException exception]; IPv4 = [IPv6 substringWithRange: OFMakeRange(lastColon + 1, IPv6.length - lastColon - 1)]; IPv6 = [IPv6 substringWithRange: OFMakeRange(0, lastColon + 1)]; address = OFSocketAddressParseIPv4(IPv4, 0); addrIn = &address.sockaddr.in; addr = OFFromBigEndian32(addrIn->sin_addr.s_addr); return [IPv6 stringByAppendingString: [OFString stringWithFormat: @"%x%02x:%x%02x", (addr & 0xFF000000) >> 24, (addr & 0x00FF0000) >> 16, (addr & 0x0000FF00) >> 8, addr & 0x000000FF]]; } OFSocketAddress OFSocketAddressParseIPv6(OFString *IPv6, uint16_t port) { void *pool = objc_autoreleasePoolPush(); OFSocketAddress ret; struct sockaddr_in6 *addrIn6 = &ret.sockaddr.in6; size_t doubleColon, percent; memset(&ret, '\0', sizeof(ret)); ret.family = OFSocketAddressFamilyIPv6; ret.length = sizeof(ret.sockaddr.in6); #ifdef AF_INET6 addrIn6->sin6_family = AF_INET6; #else addrIn6->sin6_family = AF_UNSPEC; #endif addrIn6->sin6_port = OFToBigEndian16(port); if ((percent = [IPv6 rangeOfString: @"%"].location) != OFNotFound) { OFString *interface = [IPv6 substringFromIndex: percent + 1]; IPv6 = [IPv6 substringToIndex: percent]; @try { addrIn6->sin6_scope_id = (uint32_t)[interface unsignedLongLongValueWithBase: 10]; } @catch (OFInvalidFormatException *e) { #if defined(HAVE_IF_NAMETOINDEX) && !defined(OF_WINDOWS) addrIn6->sin6_scope_id = if_nametoindex([interface cStringWithEncoding: [OFLocale encoding]]); #endif } if (addrIn6->sin6_scope_id == 0) @throw [OFInvalidArgumentException exception]; } if ([IPv6 rangeOfString: @"."].location != OFNotFound) IPv6 = transformEmbeddedIPv4(IPv6); doubleColon = [IPv6 rangeOfString: @"::"].location; if (doubleColon != OFNotFound) { OFString *left = [IPv6 substringToIndex: doubleColon]; OFString *right = [IPv6 substringFromIndex: doubleColon + 2]; OFArray OF_GENERIC(OFString *) *leftComponents; OFArray OF_GENERIC(OFString *) *rightComponents; size_t i; if ([right hasPrefix: @":"] || [right containsString: @"::"]) @throw [OFInvalidFormatException exception]; leftComponents = [left componentsSeparatedByString: @":"]; rightComponents = [right componentsSeparatedByString: @":"]; if (leftComponents.count + rightComponents.count > 7) @throw [OFInvalidFormatException exception]; i = 0; for (OFString *component in leftComponents) { uint16_t number = parseIPv6Component(component); addrIn6->sin6_addr.s6_addr[i++] = number >> 8; addrIn6->sin6_addr.s6_addr[i++] = number; } i = 16; for (OFString *component in rightComponents.reversedArray) { uint16_t number = parseIPv6Component(component); addrIn6->sin6_addr.s6_addr[--i] = number; addrIn6->sin6_addr.s6_addr[--i] = number >> 8; } } else { OFArray OF_GENERIC(OFString *) *components = [IPv6 componentsSeparatedByString: @":"]; size_t i; if (components.count != 8) @throw [OFInvalidFormatException exception]; i = 0; for (OFString *component in components) { uint16_t number; if (component.length == 0) @throw [OFInvalidFormatException exception]; number = parseIPv6Component(component); addrIn6->sin6_addr.s6_addr[i++] = number >> 8; addrIn6->sin6_addr.s6_addr[i++] = number; } } objc_autoreleasePoolPop(pool); return ret; } OFSocketAddress OFSocketAddressParseIP(OFString *IP, uint16_t port) { OFSocketAddress ret; @try { ret = OFSocketAddressParseIPv6(IP, port); } @catch (OFInvalidFormatException *e) { ret = OFSocketAddressParseIPv4(IP, port); } return ret; } OFSocketAddress OFSocketAddressMakeUNIX(OFString *path) { void *pool = objc_autoreleasePoolPush(); OFStringEncoding encoding = [OFLocale encoding]; size_t length = [path cStringLengthWithEncoding: encoding]; OFSocketAddress ret; if (length > sizeof(ret.sockaddr.un.sun_path)) @throw [OFOutOfRangeException exception]; memset(&ret, '\0', sizeof(ret)); ret.family = OFSocketAddressFamilyUNIX; ret.length = (socklen_t) (offsetof(struct sockaddr_un, sun_path) + length); #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN ret.sockaddr.un.sun_len = (uint8_t)length; #endif #ifdef AF_UNIX ret.sockaddr.un.sun_family = AF_UNIX; #else ret.sockaddr.un.sun_family = AF_UNSPEC; #endif memcpy(ret.sockaddr.un.sun_path, [path cStringWithEncoding: encoding], length); objc_autoreleasePoolPop(pool); return ret; } OFSocketAddress OFSocketAddressMakeIPX(uint32_t network, const unsigned char node[IPX_NODE_LEN], uint16_t port) { OFSocketAddress ret; memset(&ret, '\0', sizeof(ret)); ret.family = OFSocketAddressFamilyIPX; ret.length = sizeof(ret.sockaddr.ipx); #ifdef AF_IPX ret.sockaddr.ipx.sipx_family = AF_IPX; #else ret.sockaddr.ipx.sipx_family = AF_UNSPEC; #endif network = OFToBigEndian32(network); memcpy(&ret.sockaddr.ipx.sipx_network, &network, sizeof(ret.sockaddr.ipx.sipx_network)); memcpy(ret.sockaddr.ipx.sipx_node, node, IPX_NODE_LEN); ret.sockaddr.ipx.sipx_port = OFToBigEndian16(port); return ret; } OFSocketAddress OFSocketAddressMakeAppleTalk(uint16_t network, uint8_t node, uint8_t port) { OFSocketAddress ret; memset(&ret, '\0', sizeof(ret)); ret.family = OFSocketAddressFamilyAppleTalk; ret.length = sizeof(ret.sockaddr.at); #ifdef AF_APPLETALK ret.sockaddr.at.sat_family = AF_APPLETALK; #else ret.sockaddr.at.sat_family = AF_UNSPEC; #endif #ifdef OF_WINDOWS ret.sockaddr.at.sat_net = network; #else ret.sockaddr.at.sat_net = OFToBigEndian16(network); #endif ret.sockaddr.at.sat_node = node; ret.sockaddr.at.sat_port = port; return ret; } bool OFSocketAddressEqual(const OFSocketAddress *address1, const OFSocketAddress *address2) { const struct sockaddr_in *addrIn1, *addrIn2; const struct sockaddr_in6 *addrIn6_1, *addrIn6_2; const struct sockaddr_ipx *addrIPX1, *addrIPX2; const struct sockaddr_at *addrAT1, *addrAT2; void *pool; OFString *path1, *path2; bool ret; if (address1->family != address2->family) return false; switch (address1->family) { case OFSocketAddressFamilyIPv4: #if defined(OF_WII) || defined(OF_NINTENDO_3DS) if (address1->length < 8 || address2->length < 8) @throw [OFInvalidArgumentException exception]; #else if (address1->length < (socklen_t)sizeof(struct sockaddr_in) || address2->length < (socklen_t)sizeof(struct sockaddr_in)) @throw [OFInvalidArgumentException exception]; #endif addrIn1 = &address1->sockaddr.in; addrIn2 = &address2->sockaddr.in; if (addrIn1->sin_port != addrIn2->sin_port) return false; if (addrIn1->sin_addr.s_addr != addrIn2->sin_addr.s_addr) return false; return true; case OFSocketAddressFamilyIPv6: if (address1->length < (socklen_t)sizeof(struct sockaddr_in6) || address2->length < (socklen_t)sizeof(struct sockaddr_in6)) @throw [OFInvalidArgumentException exception]; addrIn6_1 = &address1->sockaddr.in6; addrIn6_2 = &address2->sockaddr.in6; if (addrIn6_1->sin6_port != addrIn6_2->sin6_port) return false; if (memcmp(addrIn6_1->sin6_addr.s6_addr, addrIn6_2->sin6_addr.s6_addr, sizeof(addrIn6_1->sin6_addr.s6_addr)) != 0) return false; return true; case OFSocketAddressFamilyUNIX: pool = objc_autoreleasePoolPush(); path1 = OFSocketAddressUNIXPath(address1); path2 = OFSocketAddressUNIXPath(address2); if (path1 == nil || path2 == nil) { objc_autoreleasePoolPop(pool); return false; } ret = [path1 isEqual: path2]; objc_autoreleasePoolPop(pool); return ret; case OFSocketAddressFamilyIPX: if (address1->length < (socklen_t)sizeof(struct sockaddr_ipx) || address2->length < (socklen_t)sizeof(struct sockaddr_ipx)) @throw [OFInvalidArgumentException exception]; addrIPX1 = &address1->sockaddr.ipx; addrIPX2 = &address2->sockaddr.ipx; if (addrIPX1->sipx_port != addrIPX2->sipx_port) return false; if (memcmp(&addrIPX1->sipx_network, &addrIPX2->sipx_network, 4) != 0) return false; if (memcmp(addrIPX1->sipx_node, addrIPX2->sipx_node, IPX_NODE_LEN) != 0) return false; return true; case OFSocketAddressFamilyAppleTalk: if (address1->length < (socklen_t)sizeof(struct sockaddr_at) || address2->length < (socklen_t)sizeof(struct sockaddr_at)) @throw [OFInvalidArgumentException exception]; addrAT1 = &address1->sockaddr.at; addrAT2 = &address2->sockaddr.at; if (addrAT1->sat_net != addrAT2->sat_net) return false; if (addrAT1->sat_node != addrAT2->sat_node) return false; if (addrAT1->sat_port != addrAT2->sat_port) return false; return true; default: @throw [OFInvalidArgumentException exception]; } } unsigned long OFSocketAddressHash(const OFSocketAddress *address) { unsigned long hash; OFHashInit(&hash); OFHashAddByte(&hash, address->family); switch (address->family) { case OFSocketAddressFamilyIPv4: #if defined(OF_WII) || defined(OF_NINTENDO_3DS) if (address->length < 8) @throw [OFInvalidArgumentException exception]; #else if (address->length < (socklen_t)sizeof(struct sockaddr_in)) @throw [OFInvalidArgumentException exception]; #endif OFHashAddByte(&hash, address->sockaddr.in.sin_port >> 8); OFHashAddByte(&hash, address->sockaddr.in.sin_port); OFHashAddByte(&hash, address->sockaddr.in.sin_addr.s_addr >> 24); OFHashAddByte(&hash, address->sockaddr.in.sin_addr.s_addr >> 16); OFHashAddByte(&hash, address->sockaddr.in.sin_addr.s_addr >> 8); OFHashAddByte(&hash, address->sockaddr.in.sin_addr.s_addr); break; case OFSocketAddressFamilyIPv6: if (address->length < (socklen_t)sizeof(struct sockaddr_in6)) @throw [OFInvalidArgumentException exception]; OFHashAddByte(&hash, address->sockaddr.in6.sin6_port >> 8); OFHashAddByte(&hash, address->sockaddr.in6.sin6_port); for (size_t i = 0; i < sizeof(address->sockaddr.in6.sin6_addr.s6_addr); i++) OFHashAddByte(&hash, address->sockaddr.in6.sin6_addr.s6_addr[i]); break; case OFSocketAddressFamilyUNIX:; void *pool = objc_autoreleasePoolPush(); OFString *path = OFSocketAddressUNIXPath(address); hash = path.hash; objc_autoreleasePoolPop(pool); return hash; case OFSocketAddressFamilyIPX:; unsigned char network[ sizeof(address->sockaddr.ipx.sipx_network)]; if (address->length < (socklen_t)sizeof(struct sockaddr_ipx)) @throw [OFInvalidArgumentException exception]; OFHashAddByte(&hash, address->sockaddr.ipx.sipx_port >> 8); OFHashAddByte(&hash, address->sockaddr.ipx.sipx_port); memcpy(network, &address->sockaddr.ipx.sipx_network, sizeof(network)); for (size_t i = 0; i < sizeof(network); i++) OFHashAddByte(&hash, network[i]); for (size_t i = 0; i < IPX_NODE_LEN; i++) OFHashAddByte(&hash, address->sockaddr.ipx.sipx_node[i]); break; case OFSocketAddressFamilyAppleTalk: if (address->length < (socklen_t)sizeof(struct sockaddr_at)) @throw [OFInvalidArgumentException exception]; OFHashAddByte(&hash, address->sockaddr.at.sat_net >> 8); OFHashAddByte(&hash, address->sockaddr.at.sat_net); OFHashAddByte(&hash, address->sockaddr.at.sat_port); break; default: @throw [OFInvalidArgumentException exception]; } OFHashFinalize(&hash); return hash; } static OFString * IPv4String(const OFSocketAddress *address) { const struct sockaddr_in *addrIn = &address->sockaddr.in; uint32_t addr = OFFromBigEndian32(addrIn->sin_addr.s_addr); OFString *string; string = [OFString stringWithFormat: @"%u.%u.%u.%u", (addr & 0xFF000000) >> 24, (addr & 0x00FF0000) >> 16, (addr & 0x0000FF00) >> 8, addr & 0x000000FF]; return string; } static OFString * IPv6String(const OFSocketAddress *address) { OFMutableString *string = [OFMutableString string]; const struct sockaddr_in6 *addrIn6 = &address->sockaddr.in6; int_fast8_t zerosStart = -1, maxZerosStart = -1; uint_fast8_t zerosCount = 0, maxZerosCount = 0; bool first = true; for (uint_fast8_t i = 0; i < 16; i += 2) { if (addrIn6->sin6_addr.s6_addr[i] == 0 && addrIn6->sin6_addr.s6_addr[i + 1] == 0) { if (zerosStart >= 0) zerosCount++; else { zerosStart = i; zerosCount = 1; } } else { if (zerosCount > maxZerosCount) { maxZerosStart = zerosStart; maxZerosCount = zerosCount; } zerosStart = -1; } } if (zerosCount > maxZerosCount) { maxZerosStart = zerosStart; maxZerosCount = zerosCount; } if (maxZerosCount >= 2) { for (int_fast8_t i = 0; i < maxZerosStart; i += 2) { [string appendFormat: (first ? @"%x" : @":%x"), (addrIn6->sin6_addr.s6_addr[(uint_fast8_t)i] << 8) | addrIn6->sin6_addr.s6_addr[(uint_fast8_t)i + 1]]; first = false; } [string appendString: @"::"]; first = true; for (int_fast8_t i = maxZerosStart + (maxZerosCount * 2); i < 16; i += 2) { [string appendFormat: (first ? @"%x" : @":%x"), (addrIn6->sin6_addr.s6_addr[(uint_fast8_t)i] << 8) | addrIn6->sin6_addr.s6_addr[(uint_fast8_t)i + 1]]; first = false; } } else { for (uint_fast8_t i = 0; i < 16; i += 2) { [string appendFormat: (first ? @"%x" : @":%x"), (addrIn6->sin6_addr.s6_addr[i] << 8) | addrIn6->sin6_addr.s6_addr[i + 1]]; first = false; } } if (addrIn6->sin6_scope_id != 0) { #if defined(HAVE_IF_INDEXTONAME) && !defined(OF_WINDOWS) char interface[IF_NAMESIZE]; if (if_indextoname(addrIn6->sin6_scope_id, interface) != NULL) [string appendFormat: @"%%%s", interface]; else # endif [string appendFormat: @"%%%u", addrIn6->sin6_scope_id]; } [string makeImmutable]; return string; } static OFString * IPXString(const OFSocketAddress *address) { const struct sockaddr_ipx *addrIPX = &address->sockaddr.ipx; uint32_t network; uint64_t node; memcpy(&network, &addrIPX->sipx_network, sizeof(addrIPX->sipx_network)); node = ((uint64_t)addrIPX->sipx_node[0] << 40) | ((uint64_t)addrIPX->sipx_node[1] << 32) | ((uint64_t)addrIPX->sipx_node[2] << 24) | ((uint64_t)addrIPX->sipx_node[3] << 16) | ((uint64_t)addrIPX->sipx_node[4] << 8) | (uint64_t)addrIPX->sipx_node[5]; return [OFString stringWithFormat: @"%" PRIX32 ".%" PRIX64, OFFromBigEndian32(network), node]; } static OFString * appleTalkString(const OFSocketAddress *address) { const struct sockaddr_at *addrAT = &address->sockaddr.at; return [OFString stringWithFormat: @"%" PRIu8 ".%" PRIu8, OFFromBigEndian16(addrAT->sat_net), addrAT->sat_node]; } OFString * OFSocketAddressString(const OFSocketAddress *address) { switch (address->family) { case OFSocketAddressFamilyIPv4: return IPv4String(address); case OFSocketAddressFamilyIPv6: return IPv6String(address); case OFSocketAddressFamilyUNIX: return OFSocketAddressUNIXPath(address); case OFSocketAddressFamilyIPX: return IPXString(address); case OFSocketAddressFamilyAppleTalk: return appleTalkString(address); default: @throw [OFInvalidArgumentException exception]; } } OFString * OFSocketAddressDescription(const OFSocketAddress *address) { switch (address->family) { case OFSocketAddressFamilyIPv4: return [OFString stringWithFormat: @"%@:%" PRIu16, IPv4String(address), OFSocketAddressIPPort(address)]; case OFSocketAddressFamilyIPv6: return [OFString stringWithFormat: @"[%@]:%" PRIu16, IPv6String(address), OFSocketAddressIPPort(address)]; case OFSocketAddressFamilyIPX: return [OFString stringWithFormat: @"%@.%" PRIX16, IPXString(address), OFSocketAddressIPXPort(address)]; case OFSocketAddressFamilyAppleTalk: return [OFString stringWithFormat: @"%@." PRIu8, appleTalkString(address), OFSocketAddressAppleTalkPort(address)]; default: return OFSocketAddressString(address); } } void OFSocketAddressSetIPPort(OFSocketAddress *address, uint16_t port) { switch (address->family) { case OFSocketAddressFamilyIPv4: address->sockaddr.in.sin_port = OFToBigEndian16(port); break; case OFSocketAddressFamilyIPv6: address->sockaddr.in6.sin6_port = OFToBigEndian16(port); break; default: @throw [OFInvalidArgumentException exception]; } } uint16_t OFSocketAddressIPPort(const OFSocketAddress *address) { switch (address->family) { case OFSocketAddressFamilyIPv4: return OFFromBigEndian16(address->sockaddr.in.sin_port); case OFSocketAddressFamilyIPv6: return OFFromBigEndian16(address->sockaddr.in6.sin6_port); default: @throw [OFInvalidArgumentException exception]; } } OFString * OFSocketAddressUNIXPath(const OFSocketAddress *_Nonnull address) { socklen_t length; if (address->family != OFSocketAddressFamilyUNIX) @throw [OFInvalidArgumentException exception]; length = address->length - offsetof(struct sockaddr_un, sun_path); for (socklen_t i = 0; i < length; i++) if (address->sockaddr.un.sun_path[i] == 0) length = i; return [OFString stringWithCString: address->sockaddr.un.sun_path encoding: [OFLocale encoding] length: length]; } void OFSocketAddressSetIPXNetwork(OFSocketAddress *address, uint32_t network) { if (address->family != OFSocketAddressFamilyIPX) @throw [OFInvalidArgumentException exception]; network = OFToBigEndian32(network); memcpy(&address->sockaddr.ipx.sipx_network, &network, sizeof(address->sockaddr.ipx.sipx_network)); } uint32_t OFSocketAddressIPXNetwork(const OFSocketAddress *address) { uint32_t network; if (address->family != OFSocketAddressFamilyIPX) @throw [OFInvalidArgumentException exception]; memcpy(&network, &address->sockaddr.ipx.sipx_network, sizeof(network)); return OFFromBigEndian32(network); } void OFSocketAddressSetIPXNode(OFSocketAddress *address, const unsigned char node[IPX_NODE_LEN]) { if (address->family != OFSocketAddressFamilyIPX) @throw [OFInvalidArgumentException exception]; memcpy(address->sockaddr.ipx.sipx_node, node, IPX_NODE_LEN); } void OFSocketAddressGetIPXNode(const OFSocketAddress *address, unsigned char node[IPX_NODE_LEN]) { if (address->family != OFSocketAddressFamilyIPX) @throw [OFInvalidArgumentException exception]; memcpy(node, address->sockaddr.ipx.sipx_node, IPX_NODE_LEN); } void OFSocketAddressSetIPXPort(OFSocketAddress *address, uint16_t port) { if (address->family != OFSocketAddressFamilyIPX) @throw [OFInvalidArgumentException exception]; address->sockaddr.ipx.sipx_port = OFToBigEndian16(port); } uint16_t OFSocketAddressIPXPort(const OFSocketAddress *address) { if (address->family != OFSocketAddressFamilyIPX) @throw [OFInvalidArgumentException exception]; return OFFromBigEndian16(address->sockaddr.ipx.sipx_port); } void OFSocketAddressSetAppleTalkNetwork(OFSocketAddress *address, uint16_t network) { if (address->family != OFSocketAddressFamilyAppleTalk) @throw [OFInvalidArgumentException exception]; #ifdef OF_WINDOWS address->sockaddr.at.sat_net = network; #else address->sockaddr.at.sat_net = OFToBigEndian16(network); #endif } uint16_t OFSocketAddressAppleTalkNetwork(const OFSocketAddress *address) { if (address->family != OFSocketAddressFamilyAppleTalk) @throw [OFInvalidArgumentException exception]; #ifdef OF_WINDOWS return address->sockaddr.at.sat_net; #else return OFFromBigEndian16(address->sockaddr.at.sat_net); #endif } void OFSocketAddressSetAppleTalkNode(OFSocketAddress *address, uint8_t node) { if (address->family != OFSocketAddressFamilyAppleTalk) @throw [OFInvalidArgumentException exception]; address->sockaddr.at.sat_node = node; } uint8_t OFSocketAddressAppleTalkNode(const OFSocketAddress *address) { if (address->family != OFSocketAddressFamilyAppleTalk) @throw [OFInvalidArgumentException exception]; return address->sockaddr.at.sat_node; } void OFSocketAddressSetAppleTalkPort(OFSocketAddress *address, uint8_t port) { if (address->family != OFSocketAddressFamilyAppleTalk) @throw [OFInvalidArgumentException exception]; address->sockaddr.at.sat_port = port; } uint8_t OFSocketAddressAppleTalkPort(const OFSocketAddress *address) { if (address->family != OFSocketAddressFamilyAppleTalk) @throw [OFInvalidArgumentException exception]; return address->sockaddr.at.sat_port; } objfw-1.1.6/src/OFSortedList.h000066400000000000000000000036411465614216400161240ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFList.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFSortedList OFSortedList.h ObjFW/OFSortedList.h * * @brief A class which provides easy to use sorted double-linked lists. * * @warning Because the list is sorted, all methods inserting an object at a * specific place are unavailable, even though they exist in OFList! */ @interface OFSortedList OF_GENERIC(ObjectType): OFList OF_GENERIC(ObjectType) #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # define ObjectType id #endif { OF_RESERVE_IVARS(OFSortedList, 4) } - (OFListItem)appendObject: (ObjectType)object OF_UNAVAILABLE; - (OFListItem)prependObject: (ObjectType)object OF_UNAVAILABLE; - (OFListItem)insertObject: (ObjectType)object beforeListItem: (OFListItem)listItem OF_UNAVAILABLE; - (OFListItem)insertObject: (ObjectType)object afterListItem: (OFListItem)listItem OF_UNAVAILABLE; /** * @brief Inserts the object to the list while keeping the list sorted. * * @param object The object to insert * @return The list object for the object just added */ - (OFListItem)insertObject: (ObjectType )object; #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # undef ObjectType #endif @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFSortedList.m000066400000000000000000000027401465614216400161300ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFSortedList.h" @implementation OFSortedList - (OFListItem)appendObject: (id)object { OF_UNRECOGNIZED_SELECTOR } - (OFListItem)prependObject: (id)object { OF_UNRECOGNIZED_SELECTOR } - (OFListItem)insertObject: (id)object beforeListItem: (OFListItem)listItem { OF_UNRECOGNIZED_SELECTOR } - (OFListItem)insertObject: (id)object afterListItem: (OFListItem)listItem { OF_UNRECOGNIZED_SELECTOR } - (OFListItem)insertObject: (id )object { OFListItem iter; for (iter = _lastListItem; iter != NULL; iter = OFListItemPrevious(iter)) { if ([object compare: OFListItemObject(iter)] != OFOrderedAscending) return [super insertObject: object afterListItem: iter]; } return [super prependObject: object]; } @end objfw-1.1.6/src/OFStdIOStream+Private.h000066400000000000000000000021671465614216400175760ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFStdIOStream.h" OF_ASSUME_NONNULL_BEGIN OF_DIRECT_MEMBERS @interface OFStdIOStream () #if defined(OF_AMIGAOS) - (instancetype)of_initWithHandle: (BPTR)handle closable: (bool)closable OF_METHOD_FAMILY(init); #elif defined(OF_WII_U) - (instancetype)of_init OF_METHOD_FAMILY(init); #else - (instancetype)of_initWithFileDescriptor: (int)fd OF_METHOD_FAMILY(init); #endif @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFStdIOStream.h000066400000000000000000000111371465614216400161650ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFStream.h" #import "OFKernelEventObserver.h" #ifdef OF_AMIGAOS # include #endif OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFColor; /** * @class OFStdIOStream OFStdIOStream.h ObjFW/OFStdIOStream.h * * @brief A class for providing standard input, output and error as OFStream. * * The global variables @ref OFStdIn, @ref OFStdOut and @ref OFStdErr are * instances of this class and need no initialization. */ #ifdef OF_STDIO_STREAM_WIN32_CONSOLE_H OF_SUBCLASSING_RESTRICTED #endif @interface OFStdIOStream: OFStream #if !defined(OF_WINDOWS) && !defined(OF_AMIGAOS) && !defined(OF_WII_U) #endif { #if defined(OF_AMIGAOS) BPTR _handle; bool _closable; #elif !defined(OF_WII_U) int _fd; #endif bool _atEndOfStream; } /** * @brief Whether there is an underlying terminal. */ @property (readonly, nonatomic) bool hasTerminal; /** * @brief The number of columns, or -1 if there is no underlying terminal or * the number of columns could not be queried. */ @property (readonly, nonatomic) int columns; /** * @brief The number of rows, or -1 if there is no underlying terminal or the * number of rows could not be queried. */ @property (readonly, nonatomic) int rows; - (instancetype)init OF_UNAVAILABLE; /** * @brief Sets the foreground color on the underlying terminal. Does nothing if * there is no underlying terminal or colors are unsupported. * * @param color The foreground color to set */ - (void)setForegroundColor: (OFColor *)color; /** * @brief Sets the background color on the underlying terminal. Does nothing if * there is no underlying terminal or colors are unsupported. * * @param color The background color to set */ - (void)setBackgroundColor: (OFColor *)color; /** * @brief Resets all attributes (color, bold, etc.). Does nothing if there is * no underlying terminal. */ - (void)reset; /** * @brief Clears the entire underlying terminal. Does nothing if there is no * underlying terminal. */ - (void)clear; /** * @brief Erases the entire current line on the underlying terminal. Does * nothing if there is no underlying terminal. */ - (void)eraseLine; /** * @brief Moves the cursor to the specified column in the current row. Does * nothing if there is no underlying terminal. * * @param column The column in the current row to move the cursor to */ - (void)setCursorColumn: (unsigned int)column; /** * @brief Moves the cursor to the specified absolute position. Does nothing if * there is no underlying terminal. * * @param position The position to move the cursor to */ - (void)setCursorPosition: (OFPoint)position; /** * @brief Moves the cursor to the specified relative position. Does nothing if * there is no underlying terminal. * * @param position The position to move the cursor to */ - (void)setRelativeCursorPosition: (OFPoint)position; @end #ifdef __cplusplus extern "C" { #endif /** @file */ /** * @brief The standard input as an OFStream. */ extern OFStdIOStream *_Nullable OFStdIn; /** * @brief The standard output as an OFStream. */ extern OFStdIOStream *_Nullable OFStdOut; /** * @brief The standard error as an OFStream. */ extern OFStdIOStream *_Nullable OFStdErr; /** * @brief Logs the specified printf-style format to @ref OFStdErr. * * This prefixes the output with the date, timestamp, process name and PID. * * @param format The format for the line to log. See @ref OFStream#writeFormat:. */ extern void OFLog(OFConstantString *format, ...); /** * @brief Logs the specified printf-style format to @ref OFStdErr. * * This prefixes the output with the date, timestamp, process name and PID. * * @param format The format for the line to log. See @ref OFStream#writeFormat:. * @param arguments The arguments for the format */ extern void OFLogV(OFConstantString *format, va_list arguments); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFStdIOStream.m000066400000000000000000000324131465614216400161720ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include "unistd_wrapper.h" #ifdef HAVE_SYS_IOCTL_H # include #endif #ifdef HAVE_SYS_TTYCOM_H # include #endif #import "OFStdIOStream.h" #import "OFStdIOStream+Private.h" #import "OFColor.h" #import "OFDate.h" #import "OFApplication.h" #ifdef OF_WINDOWS # import "OFWin32ConsoleStdIOStream.h" #endif #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFWriteFailedException.h" #ifdef OF_IOS # undef HAVE_ISATTY #endif #ifdef OF_AMIGAOS # define Class IntuitionClass # include # include # undef Class # undef HAVE_ISATTY #endif #ifdef OF_MSDOS # include #endif #ifdef OF_WII_U # define BOOL WUT_BOOL # include # undef BOOL #endif /* References for static linking */ #ifdef OF_WINDOWS void _reference_to_OFWin32ConsoleStdIOStream(void) { [OFWin32ConsoleStdIOStream class]; } #endif OFStdIOStream *OFStdIn = nil; OFStdIOStream *OFStdOut = nil; OFStdIOStream *OFStdErr = nil; #ifdef OF_AMIGAOS OF_DESTRUCTOR() { [OFStdIn dealloc]; [OFStdOut dealloc]; [OFStdErr dealloc]; } #endif void OFLog(OFConstantString *format, ...) { va_list arguments; va_start(arguments, format); OFLogV(format, arguments); va_end(arguments); } void OFLogV(OFConstantString *format, va_list arguments) { void *pool = objc_autoreleasePoolPush(); OFDate *date; OFString *dateString, *me, *msg; date = [OFDate date]; dateString = [date localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; #ifdef OF_HAVE_FILES me = [OFApplication programName].lastPathComponent; #else me = [OFApplication programName]; #endif if (me == nil) me = @"?"; msg = [[[OFString alloc] initWithFormat: format arguments: arguments] autorelease]; [OFStdErr writeFormat: @"[%@.%03d %@(%d)] %@\n", dateString, date.microsecond / 1000, me, getpid(), msg]; objc_autoreleasePoolPop(pool); } #ifdef OF_MSDOS int colorToMSDOS(OFColor *color) { if ([color isEqual: [OFColor black]]) return BLACK; if ([color isEqual: [OFColor navy]]) return BLUE; if ([color isEqual: [OFColor green]]) return GREEN; if ([color isEqual: [OFColor teal]]) return CYAN; if ([color isEqual: [OFColor maroon]]) return RED; if ([color isEqual: [OFColor purple]]) return MAGENTA; if ([color isEqual: [OFColor olive]]) return BROWN; if ([color isEqual: [OFColor silver]]) return LIGHTGRAY; if ([color isEqual: [OFColor gray]]) return DARKGRAY; if ([color isEqual: [OFColor blue]]) return LIGHTBLUE; if ([color isEqual: [OFColor lime]]) return LIGHTGREEN; if ([color isEqual: [OFColor aqua]]) return LIGHTCYAN; if ([color isEqual: [OFColor red]]) return LIGHTRED; if ([color isEqual: [OFColor fuchsia]]) return LIGHTMAGENTA; if ([color isEqual: [OFColor yellow]]) return YELLOW; if ([color isEqual: [OFColor white]]) return WHITE; return -1; } #else static int colorToANSI(OFColor *color) { if ([color isEqual: [OFColor black]]) return 30; if ([color isEqual: [OFColor maroon]]) return 31; if ([color isEqual: [OFColor green]]) return 32; if ([color isEqual: [OFColor olive]]) return 33; if ([color isEqual: [OFColor navy]]) return 34; if ([color isEqual: [OFColor purple]]) return 35; if ([color isEqual: [OFColor teal]]) return 36; if ([color isEqual: [OFColor silver]]) return 37; if ([color isEqual: [OFColor gray]]) return 90; if ([color isEqual: [OFColor red]]) return 91; if ([color isEqual: [OFColor lime]]) return 92; if ([color isEqual: [OFColor yellow]]) return 93; if ([color isEqual: [OFColor blue]]) return 94; if ([color isEqual: [OFColor fuchsia]]) return 95; if ([color isEqual: [OFColor aqua]]) return 96; if ([color isEqual: [OFColor white]]) return 97; return -1; } #endif @implementation OFStdIOStream #ifndef OF_WINDOWS + (void)load { if (self != [OFStdIOStream class]) return; # if defined(OF_AMIGAOS) BPTR input, output, error; bool inputClosable = false, outputClosable = false, errorClosable = false; input = Input(); output = Output(); error = ((struct Process *)FindTask(NULL))->pr_CES; if (input == 0) { input = Open("*", MODE_OLDFILE); inputClosable = true; } if (output == 0) { output = Open("*", MODE_OLDFILE); outputClosable = true; } if (error == 0) { error = Open("*", MODE_OLDFILE); errorClosable = true; } OFStdIn = [[OFStdIOStream alloc] of_initWithHandle: input closable: inputClosable]; OFStdOut = [[OFStdIOStream alloc] of_initWithHandle: output closable: outputClosable]; OFStdErr = [[OFStdIOStream alloc] of_initWithHandle: error closable: errorClosable]; # elif defined(OF_WII_U) OFStdOut = [[OFStdIOStream alloc] of_init]; OFStdErr = [[OFStdIOStream alloc] of_init]; # else int fd; if ((fd = fileno(stdin)) >= 0) OFStdIn = [[OFStdIOStream alloc] of_initWithFileDescriptor: fd]; if ((fd = fileno(stdout)) >= 0) OFStdOut = [[OFStdIOStream alloc] of_initWithFileDescriptor: fd]; if ((fd = fileno(stderr)) >= 0) OFStdErr = [[OFStdIOStream alloc] of_initWithFileDescriptor: fd]; # endif } #endif - (instancetype)init { OF_INVALID_INIT_METHOD } #if defined(OF_AMIGAOS) - (instancetype)of_initWithHandle: (BPTR)handle closable: (bool)closable { self = [super init]; _handle = handle; _closable = closable; return self; } #elif defined(OF_WII_U) - (instancetype)of_init { return [super init]; } #else - (instancetype)of_initWithFileDescriptor: (int)fd { self = [super init]; _fd = fd; return self; } #endif - (void)dealloc { #if defined(OF_AMIGAOS) if (_handle != 0) [self close]; #elif !defined(OF_WII_U) if (_fd != -1) [self close]; #endif [super dealloc]; } - (bool)lowlevelIsAtEndOfStream { #if defined(OF_AMIGAOS) if (_handle == 0) @throw [OFNotOpenException exceptionWithObject: self]; #elif !defined(OF_WII_U) if (_fd == -1) @throw [OFNotOpenException exceptionWithObject: self]; #endif return _atEndOfStream; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { #if defined(OF_AMIGAOS) ssize_t ret; if (_handle == 0) @throw [OFNotOpenException exceptionWithObject: self]; if (length > LONG_MAX) @throw [OFOutOfRangeException exception]; if ((ret = Read(_handle, buffer, length)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: EIO]; if (ret == 0) _atEndOfStream = true; return ret; #elif defined(OF_WII_U) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: EOPNOTSUPP]; #else ssize_t ret; if (_fd == -1) @throw [OFNotOpenException exceptionWithObject: self]; # ifndef OF_WINDOWS if ((ret = read(_fd, buffer, length)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: errno]; # else if (length > UINT_MAX) @throw [OFOutOfRangeException exception]; if ((ret = read(_fd, buffer, (unsigned int)length)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: errno]; # endif if (ret == 0) _atEndOfStream = true; return ret; #endif } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { #if defined(OF_AMIGAOS) LONG bytesWritten; if (_handle == 0) @throw [OFNotOpenException exceptionWithObject: self]; if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = Write(_handle, (void *)buffer, length)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: EIO]; return (size_t)bytesWritten; #elif defined(OF_MSDOS) ssize_t bytesWritten; if (self.hasTerminal) { const char *buffer_ = buffer; for (size_t i = 0; i < length; i++) { if (buffer_[i] == '\n') putch('\r'); putch(buffer_[i]); } return length; } if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = write(_fd, buffer, length)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: errno]; return (size_t)bytesWritten; #elif defined(OF_WII_U) OSConsoleWrite(buffer, length); return length; #else if (_fd == -1) @throw [OFNotOpenException exceptionWithObject: self]; # ifndef OF_WINDOWS ssize_t bytesWritten; if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = write(_fd, buffer, length)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: errno]; # else int bytesWritten; if (length > INT_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = write(_fd, buffer, (int)length)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: errno]; # endif return (size_t)bytesWritten; #endif } #if !defined(OF_WINDOWS) && !defined(OF_AMIGAOS) && !defined(OF_WII_U) - (int)fileDescriptorForReading { return _fd; } - (int)fileDescriptorForWriting { return _fd; } #endif - (void)close { #if defined(OF_AMIGAOS) if (_handle == 0) @throw [OFNotOpenException exceptionWithObject: self]; if (_closable) Close(_handle); _handle = 0; #elif !defined(OF_WII_U) if (_fd == -1) @throw [OFNotOpenException exceptionWithObject: self]; close(_fd); _fd = -1; #endif [super close]; } - (instancetype)autorelease { return self; } - (instancetype)retain { return self; } - (void)release { } - (unsigned int)retainCount { return OFMaxRetainCount; } - (bool)hasTerminal { #if defined(OF_WII) || defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS) || \ defined(OF_NINTENDO_SWITCH) return true; #elif defined(HAVE_ISATTY) && !defined(OF_WII_U) return isatty(_fd); #else return false; #endif } - (int)columns { #if defined(OF_MSDOS) struct text_info ti; gettextinfo(&ti); return ti.screenwidth; #elif defined(HAVE_IOCTL) && defined(TIOCGWINSZ) && \ !defined(OF_AMIGAOS) && !defined(OF_WII_U) struct winsize ws; if (ioctl(_fd, TIOCGWINSZ, &ws) != 0) return -1; return ws.ws_col; #else return -1; #endif } - (int)rows { #if defined(OF_MSDOS) struct text_info ti; gettextinfo(&ti); return ti.screenwidth; #elif defined(HAVE_IOCTL) && defined(TIOCGWINSZ) && \ !defined(OF_AMIGAOS) && !defined(OF_WII_U) struct winsize ws; if (ioctl(_fd, TIOCGWINSZ, &ws) != 0) return -1; return ws.ws_row; #else return -1; #endif } - (void)setForegroundColor: (OFColor *)color { int code; if (!self.hasTerminal) return; #ifdef OF_MSDOS if ((code = colorToMSDOS(color)) == -1) return; textcolor(code); #else if ((code = colorToANSI(color)) == -1) return; [self writeFormat: @"\033[%um", code]; #endif } - (void)setBackgroundColor: (OFColor *)color { int code; if (!self.hasTerminal) return; #ifdef OF_MSDOS if ((code = colorToMSDOS(color)) == -1) return; textbackground(code); #else if ((code = colorToANSI(color)) == -1) return; [self writeFormat: @"\033[%um", code + 10]; #endif } - (void)reset { if (!self.hasTerminal) return; #ifdef OF_MSDOS normvideo(); #else [self writeString: @"\033[0m"]; #endif } - (void)clear { if (!self.hasTerminal) return; #ifdef OF_MSDOS clrscr(); #else [self writeString: @"\033[2J"]; #endif } - (void)eraseLine { if (!self.hasTerminal) return; #ifdef OF_MSDOS int column = wherex(); gotoxy(1, wherey()); clreol(); gotoxy(column, wherey()); #else [self writeString: @"\033[2K"]; #endif } - (void)setCursorColumn: (unsigned int)column { if (!self.hasTerminal) return; #ifdef OF_MSDOS gotoxy(column + 1, wherey()); #else [self writeFormat: @"\033[%uG", column + 1]; #endif } - (void)setCursorPosition: (OFPoint)position { if (position.x < 0 || position.y < 0) @throw [OFInvalidArgumentException exception]; if (!self.hasTerminal) return; #ifdef OF_MSDOS gotoxy(position.x + 1, position.y + 1); #else [self writeFormat: @"\033[%u;%uH", (unsigned)position.y + 1, (unsigned)position.x + 1]; #endif } - (void)setRelativeCursorPosition: (OFPoint)position { if (!self.hasTerminal) return; #ifdef OF_MSDOS gotoxy(wherex() + position.x, wherey() + position.y); #else if (position.x > 0) [self writeFormat: @"\033[%uC", (unsigned)position.x]; else if (position.x < 0) [self writeFormat: @"\033[%uD", (unsigned)-position.x]; if (position.y > 0) [self writeFormat: @"\033[%uB", (unsigned)position.y]; else if (position.y < 0) [self writeFormat: @"\033[%uA", (unsigned)-position.y]; #endif } @end objfw-1.1.6/src/OFStrFTime.h000066400000000000000000000021761465614216400155270ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif #include #import "macros.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif extern size_t _OFStrFTime(char *buffer, size_t bufferLen, const char *format, struct tm *tm, short tz) OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFStrFTime.m000066400000000000000000000066231465614216400155350ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "OFStrFTime.h" #import "macros.h" static const char weekDays[7][4] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; static const char monthNames[12][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; size_t _OFStrFTime(char *buffer, size_t bufferLen, const char *format, struct tm *tm, short tz) { enum { stateSearchConversionSpecifier, stateInConversionSpecifier } state = stateSearchConversionSpecifier; size_t j, formatLen; if (bufferLen == 0) return 0; formatLen = strlen(format); j = 0; for (size_t i = 0; i < formatLen; i++) { switch (state) { case stateSearchConversionSpecifier: if (format[i] == '%') state = stateInConversionSpecifier; else { if (j >= bufferLen) return 0; buffer[j++] = format[i]; } break; case stateInConversionSpecifier:; const char *appendFormat; unsigned int value = 0; char append[5]; int appendLen; switch (format[i]) { case '%': appendFormat = "%%"; break; case 'a': if (tm->tm_wday > 6) return 0; appendFormat = weekDays[tm->tm_wday]; break; case 'b': if (tm->tm_mon > 11) return 0; appendFormat = monthNames[tm->tm_mon]; break; case 'd': appendFormat = "%02u"; value = tm->tm_mday; break; case 'e': appendFormat = "%2u"; value = tm->tm_mday; break; case 'H': appendFormat = "%02u"; value = tm->tm_hour; break; case 'M': appendFormat = "%02u"; value = tm->tm_min; break; case 'm': appendFormat = "%02u"; value = tm->tm_mon + 1; break; case 'n': appendFormat = "\n"; break; case 'S': appendFormat = "%02u"; value = tm->tm_sec; break; case 't': appendFormat = "\t"; break; case 'Y': appendFormat = "%4u"; value = tm->tm_year + 1900; break; case 'y': appendFormat = "%02u"; value = tm->tm_year; while (value > 100) value -= 100; break; case 'z': if (tz == 0) appendFormat = "Z"; else if (tz >= 0) { appendFormat = "+%04u"; value = tz; } else { appendFormat = "-%04u"; value = -tz; } value = (value / 60) * 100 + (value % 60); break; default: return 0; } appendLen = snprintf(append, sizeof(append), appendFormat, value); if (appendLen < 0 || (size_t)appendLen >= sizeof(append)) return 0; if (bufferLen - j < (size_t)appendLen) return 0; memcpy(buffer + j, append, appendLen); j += appendLen; state = stateSearchConversionSpecifier; } } if (j >= bufferLen) return 0; buffer[j] = 0; return j; } objfw-1.1.6/src/OFStrPTime.h000066400000000000000000000022531465614216400155350ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif #include #import "macros.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif /* No OF_VISIBILITY_HIDDEN so tests can call it. */ extern const char *_Nullable _OFStrPTime(const char *buffer, const char *format, struct tm *tm, short *_Nullable tz); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFStrPTime.m000066400000000000000000000116601465614216400155440ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFStrPTime.h" #import "macros.h" const char * _OFStrPTime(const char *buffer, const char *format, struct tm *tm, short *tz) { enum { stateSearchConversionSpecifier, stateInConversionSpecifier } state = stateSearchConversionSpecifier; size_t j, bufferLen, formatLen; bufferLen = strlen(buffer); formatLen = strlen(format); j = 0; for (size_t i = 0; i < formatLen; i++) { if (j >= bufferLen) return NULL; switch (state) { case stateSearchConversionSpecifier: if (format[i] == '%') state = stateInConversionSpecifier; else if (format[i] != buffer[j++]) return NULL; break; case stateInConversionSpecifier:; int k, maxLen, number = 0; switch (format[i]) { case 'd': case 'e': case 'H': case 'm': case 'M': case 'S': case 'y': maxLen = 2; break; case 'Y': maxLen = 4; break; case '%': case 'a': case 'b': case 'n': case 't': case 'z': maxLen = 0; break; default: return NULL; } if (maxLen > 0 && (buffer[j] < '0' || buffer[j] > '9')) return NULL; for (k = 0; k < maxLen && j < bufferLen && buffer[j] >= '0' && buffer[j] <= '9'; k++, j++) { number *= 10; number += buffer[j] - '0'; } switch (format[i]) { case 'a': if (bufferLen < j + 3) return NULL; if (memcmp(buffer + j, "Sun", 3) == 0) tm->tm_wday = 0; else if (memcmp(buffer + j, "Mon", 3) == 0) tm->tm_wday = 1; else if (memcmp(buffer + j, "Tue", 3) == 0) tm->tm_wday = 2; else if (memcmp(buffer + j, "Wed", 3) == 0) tm->tm_wday = 3; else if (memcmp(buffer + j, "Thu", 3) == 0) tm->tm_wday = 4; else if (memcmp(buffer + j, "Fri", 3) == 0) tm->tm_wday = 5; else if (memcmp(buffer + j, "Sat", 3) == 0) tm->tm_wday = 6; else return NULL; j += 3; break; case 'b': if (bufferLen < j + 3) return NULL; if (memcmp(buffer + j, "Jan", 3) == 0) tm->tm_mon = 0; else if (memcmp(buffer + j, "Feb", 3) == 0) tm->tm_mon = 1; else if (memcmp(buffer + j, "Mar", 3) == 0) tm->tm_mon = 2; else if (memcmp(buffer + j, "Apr", 3) == 0) tm->tm_mon = 3; else if (memcmp(buffer + j, "May", 3) == 0) tm->tm_mon = 4; else if (memcmp(buffer + j, "Jun", 3) == 0) tm->tm_mon = 5; else if (memcmp(buffer + j, "Jul", 3) == 0) tm->tm_mon = 6; else if (memcmp(buffer + j, "Aug", 3) == 0) tm->tm_mon = 7; else if (memcmp(buffer + j, "Sep", 3) == 0) tm->tm_mon = 8; else if (memcmp(buffer + j, "Oct", 3) == 0) tm->tm_mon = 9; else if (memcmp(buffer + j, "Nov", 3) == 0) tm->tm_mon = 10; else if (memcmp(buffer + j, "Dec", 3) == 0) tm->tm_mon = 11; else return NULL; j += 3; break; case 'd': case 'e': tm->tm_mday = number; break; case 'H': tm->tm_hour = number; break; case 'm': tm->tm_mon = number - 1; break; case 'M': tm->tm_min = number; break; case 'S': tm->tm_sec = number; break; case 'y': if (number <= 68) number += 100; tm->tm_year = number; break; case 'Y': if (number < 1900) return NULL; tm->tm_year = number - 1900; break; case 'z': if (buffer[j] == '-' || buffer[j] == '+') { const char *b = buffer + j; if (bufferLen < j + 5) return NULL; if (tz == NULL) break; *tz = (((short)b[1] - '0') * 600 + ((short)b[2] - '0') * 60 + ((short)b[3] - '0') * 10 + ((short)b[4] - '0')) * (b[0] == '-' ? -1 : 1); j += 5; } else if (buffer[j] == 'Z') { if (tz != NULL) *tz = 0; j++; } else if (buffer[j] == 'G') { if (bufferLen < j + 3) return NULL; if (buffer[j + 1] != 'M' || buffer[j + 2] != 'T') return NULL; if (tz != NULL) *tz = 0; j += 3; } else return NULL; break; case '%': if (buffer[j++] != '%') return NULL; break; case 'n': if (buffer[j++] != '\n') return NULL; break; case 't': if (buffer[j++] != '\t') return NULL; break; } state = stateSearchConversionSpecifier; break; } } return buffer + j; } objfw-1.1.6/src/OFStream+Private.h000066400000000000000000000016401465614216400166660ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFStream.h" OF_ASSUME_NONNULL_BEGIN @interface OFStream () @property (readonly, nonatomic, getter=of_isWaitingForDelimiter) bool of_waitingForDelimiter; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFStream.h000066400000000000000000001452001465614216400152610ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif #include #import "OFObject.h" #import "OFString.h" #import "OFRunLoop.h" #ifdef OF_HAVE_SOCKETS # import "OFKernelEventObserver.h" #endif OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFStream; @class OFData; #if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_BLOCKS) /** * @brief A block which is called when data was read asynchronously from a * stream. * * @param length The length of the data that has been read * @param exception An exception which occurred while reading or `nil` on * success * @return A bool whether the same block should be used for the next read */ typedef bool (^OFStreamAsyncReadBlock)(size_t length, id _Nullable exception); /** * @brief A block which is called when a line was read asynchronously from a * stream. * * @param line The line which has been read or `nil` when the end of stream * occurred * @param exception An exception which occurred while reading or `nil` on * success * @return A bool whether the same block should be used for the next read */ typedef bool (^OFStreamAsyncReadLineBlock)(OFString *_Nullable line, id _Nullable exception); /** * @brief A block which is called when data was written asynchronously to a * stream. * * @param bytesWritten The number of bytes which have been written. This * matches the length of the specified data on the * asynchronous write if no exception was encountered. * @param exception An exception which occurred while writing or `nil` on * success * @return The data to repeat the write with or nil if it should not repeat */ typedef OFData *_Nullable (^OFStreamAsyncWriteDataBlock)(size_t bytesWritten, id _Nullable exception); /** * @brief A block which is called when a string was written asynchronously to a * stream. * * @param bytesWritten The number of bytes which have been written. This * matches the length of the specified data on the * asynchronous write if no exception was encountered. * @param exception An exception which occurred while writing or `nil` on * success * @return The string to repeat the write with or nil if it should not repeat */ typedef OFString *_Nullable (^OFStreamAsyncWriteStringBlock)( size_t bytesWritten, id _Nullable exception); #endif /** * @protocol OFStreamDelegate OFStream.h ObjFW/OFStream.h * * A delegate for OFStream. */ @protocol OFStreamDelegate @optional /** * @brief This method is called when data was read asynchronously from a * stream. * * @param stream The stream on which data was read * @param buffer A buffer with the data that has been read * @param length The length of the data that has been read * @param exception An exception that occurred while reading, or nil on success * @return A bool whether the read should be repeated */ - (bool)stream: (OFStream *)stream didReadIntoBuffer: (void *)buffer length: (size_t)length exception: (nullable id)exception; /** * @brief This method is called when a line was read asynchronously from a * stream. * * @param stream The stream on which a line was read * @param line The line which has been read or `nil` when the end of stream * occurred * @param exception An exception that occurred while reading, or nil on success * @return A bool whether the read should be repeated */ - (bool)stream: (OFStream *)stream didReadLine: (nullable OFString *)line exception: (nullable id)exception; /** * @brief This method is called when data was written asynchronously to a * stream. * * @param stream The stream to which data was written * @param data The data which was written to the stream * @param bytesWritten The number of bytes which have been written. This * matches the length of the specified data on the * asynchronous write if no exception was encountered. * @param exception An exception that occurred while writing, or nil on success * @return The data to repeat the write with or nil if it should not repeat */ - (nullable OFData *)stream: (OFStream *)stream didWriteData: (OFData *)data bytesWritten: (size_t)bytesWritten exception: (nullable id)exception; /** * @brief This method is called when a string was written asynchronously to a * stream. * * @param stream The stream to which a string was written * @param string The string which was written to the stream * @param encoding The encoding in which the string was written * @param bytesWritten The number of bytes which have been written. This * matches the length of the specified data on the * asynchronous write if no exception was encountered. * @param exception An exception that occurred while writing, or nil on success * @return The string to repeat the write with or nil if it should not repeat */ - (nullable OFString *)stream: (OFStream *)stream didWriteString: (OFString *)string encoding: (OFStringEncoding)encoding bytesWritten: (size_t)bytesWritten exception: (nullable id)exception; @end /** * @class OFStream OFStream.h ObjFW/OFStream.h * * @brief A base class for different types of streams. * * @warning Even though the OFCopying protocol is implemented, it does *not* * return an independent copy of the stream, but instead retains it. * This is so that the stream can be used as a key for a dictionary, * so context can be associated with a stream. Using a stream in more * than one thread at the same time is not thread-safe, even if copy * was called to create one "instance" for every thread! * * @note If you want to subclass this, override * @ref lowlevelReadIntoBuffer:length:, @ref lowlevelWriteBuffer:length: * and @ref lowlevelIsAtEndOfStream, but nothing else, as those are are * the methods that do the actual work. OFStream uses those for all other * methods and does all the caching and other stuff for you. If you * override these methods without the `lowlevel` prefix, you *will* break * caching and get broken results! */ @interface OFStream: OFObject { bool _canBlock; id _Nullable _delegate; #ifndef OF_SEEKABLE_STREAM_M @private #endif char *_Nullable _readBuffer, *_Nullable _readBufferMemory; char *_Nullable _writeBuffer; size_t _readBufferLength, _writeBufferLength; bool _buffersWrites, _waitingForDelimiter; OF_RESERVE_IVARS(OFStream, 4) } /** * @brief Whether the end of the stream has been reached. */ @property (readonly, nonatomic, getter=isAtEndOfStream) bool atEndOfStream; /** * @brief Whether writes are buffered. */ @property (nonatomic) bool buffersWrites; /** * @brief Whether data is present in the internal read buffer. */ @property (readonly, nonatomic) bool hasDataInReadBuffer; /** * @brief Whether the stream can block. * * By default, a stream can block. * On Win32, setting this currently only works for sockets! * * @throw OFGetOptionFailedException The option could not be retrieved * @throw OFSetOptionFailedException The option could not be set */ @property (nonatomic) bool canBlock; /** * @brief The delegate for asynchronous operations on the stream. * * @note The delegate is retained for as long as asynchronous operations are * still ongoing. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id delegate; /** * @brief Reads *at most* `length` bytes from the stream into a buffer. * * On network streams, this might read less than the specified number of bytes. * If you want to read exactly the specified number of bytes, use * @ref readIntoBuffer:exactLength:. Note that a read can even return 0 bytes - * this does not necessarily mean that the stream ended, so you still need to * check @ref atEndOfStream. Do not assume that the stream ended just because a * read returned 0 bytes - some streams do internal processing that has a * result of 0 bytes. * * @param buffer The buffer into which the data is read * @param length The length of the data that should be read at most. * The buffer *must* be *at least* this big! * @return The number of bytes read * @throw OFReadFailedException Reading failed * @throw OFNotOpenException The stream is not open */ - (size_t)readIntoBuffer: (void *)buffer length: (size_t)length; /** * @brief Reads exactly the specified `length` bytes from the stream into a * buffer. * * Unlike @ref readIntoBuffer:length:, this method does not return when less * than the specified length has been read - instead, it waits until it got * exactly the specified length. * * @warning Only call this when you know that specified amount of data is * available! Otherwise you will get an exception! * * @param buffer The buffer into which the data is read * @param length The length of the data that should be read. * The buffer *must* be *at least* this big! * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading the specified amount * @throw OFNotOpenException The stream is not open */ - (void)readIntoBuffer: (void *)buffer exactLength: (size_t)length; #ifdef OF_HAVE_SOCKETS /** * @brief Asynchronously reads *at most* `length` bytes from the stream into a * buffer. * * On network streams, this might read less than the specified number of bytes. * If you want to read exactly the specified number of bytes, use * @ref asyncReadIntoBuffer:exactLength:. Note that a read can even return 0 * bytes - this does not necessarily mean that the stream ended, so you still * need to check @ref atEndOfStream. Do not assume that the stream ended just * because a read returned 0 bytes - some streams do internal processing that * has a result of 0 bytes. * * @note The stream must conform to @ref OFReadyForReadingObserving in order * for this to work! * * @param buffer The buffer into which the data is read. * The buffer must not be freed before the async read completed! * @param length The length of the data that should be read at most. * The buffer *must* be *at least* this big! */ - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length; /** * @brief Asynchronously reads *at most* `length` bytes from the stream into a * buffer. * * On network streams, this might read less than the specified number of bytes. * If you want to read exactly the specified number of bytes, use * @ref asyncReadIntoBuffer:exactLength:. Note that a read can even return 0 * bytes - this does not necessarily mean that the stream ended, so you still * need to check @ref atEndOfStream. Do not assume that the stream ended just * because a read returned 0 bytes - some streams do internal processing that * has a result of 0 bytes. * * @note The stream must conform to @ref OFReadyForReadingObserving in order * for this to work! * * @param buffer The buffer into which the data is read. * The buffer must not be freed before the async read completed! * @param length The length of the data that should be read at most. * The buffer *must* be *at least* this big! * @param runLoopMode The run loop mode in which to perform the async read */ - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode; /** * @brief Asynchronously reads exactly the specified `length` bytes from the * stream into a buffer. * * Unlike @ref asyncReadIntoBuffer:length:, this method does not call the * method when less than the specified length has been read - instead, it waits * until it got exactly the specified length, the stream has ended or an * exception occurred. * * @note The stream must conform to @ref OFReadyForReadingObserving in order * for this to work! * * @param buffer The buffer into which the data is read * @param length The length of the data that should be read. * The buffer *must* be *at least* this big! */ - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length; /** * @brief Asynchronously reads exactly the specified `length` bytes from the * stream into a buffer. * * Unlike @ref asyncReadIntoBuffer:length:, this method does not call the * method when less than the specified length has been read - instead, it waits * until it got exactly the specified length, the stream has ended or an * exception occurred. * * @note The stream must conform to @ref OFReadyForReadingObserving in order * for this to work! * * @param buffer The buffer into which the data is read * @param length The length of the data that should be read. * The buffer *must* be *at least* this big! * @param runLoopMode The run loop mode in which to perform the async read */ - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode; # ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously reads *at most* ref `length` bytes from the stream * into a buffer. * * On network streams, this might read less than the specified number of bytes. * If you want to read exactly the specified number of bytes, use * @ref asyncReadIntoBuffer:exactLength:block:. Note that a read can even * return 0 bytes - this does not necessarily mean that the stream ended, so * you still need to check @ref atEndOfStream. Do not assume that the stream * ended just because a read returned 0 bytes - some streams do internal * processing that has a result of 0 bytes. * * @note The stream must conform to @ref OFReadyForReadingObserving in order * for this to work! * * @param buffer The buffer into which the data is read. * The buffer must not be freed before the async read completed! * @param length The length of the data that should be read at most. * The buffer *must* be *at least* this big! * @param block The block to call when the data has been received. * If the block returns true, it will be called again with the same * buffer and maximum length when more data has been received. If * you want the next block in the queue to handle the data * received next, you need to return false from the block. */ - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length block: (OFStreamAsyncReadBlock)block; /** * @brief Asynchronously reads *at most* `length` bytes from the stream into a * buffer. * * On network streams, this might read less than the specified number of bytes. * If you want to read exactly the specified number of bytes, use * @ref asyncReadIntoBuffer:exactLength:block:. Note that a read can even * return 0 bytes - this does not necessarily mean that the stream ended, so * you still need to check @ref atEndOfStream. Do not assume that the stream * ended just because a read returned 0 bytes - some streams do internal * processing that has a result of 0 bytes. * * @note The stream must conform to @ref OFReadyForReadingObserving in order * for this to work! * * @param buffer The buffer into which the data is read. * The buffer must not be freed before the async read completed! * @param length The length of the data that should be read at most. * The buffer *must* be *at least* this big! * @param runLoopMode The run loop mode in which to perform the async read * @param block The block to call when the data has been received. * If the block returns true, it will be called again with the same * buffer and maximum length when more data has been received. If * you want the next block in the queue to handle the data * received next, you need to return false from the block. */ - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamAsyncReadBlock)block; /** * @brief Asynchronously reads exactly the specified `length` bytes from the * stream into a buffer. * * Unlike @ref asyncReadIntoBuffer:length:block:, this method does not invoke * the block when less than the specified length has been read - instead, it * waits until it got exactly the specified length, the stream has ended or an * exception occurred. * * @note The stream must conform to @ref OFReadyForReadingObserving in order * for this to work! * * @param buffer The buffer into which the data is read * @param length The length of the data that should be read. * The buffer *must* be *at least* this big! * @param block The block to call when the data has been received. * If the block returns true, it will be called again with the same * buffer and exact length when more data has been received. If * you want the next block in the queue to handle the data * received next, you need to return false from the block. */ - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length block: (OFStreamAsyncReadBlock)block; /** * @brief Asynchronously reads exactly the specified `length` bytes from the * stream into a buffer. * * Unlike @ref asyncReadIntoBuffer:length:block:, this method does not invoke * the block when less than the specified length has been read - instead, it * waits until it got exactly the specified length, the stream has ended or an * exception occurred. * * @note The stream must conform to @ref OFReadyForReadingObserving in order * for this to work! * * @param buffer The buffer into which the data is read * @param length The length of the data that should be read. * The buffer *must* be *at least* this big! * @param runLoopMode The run loop mode in which to perform the async read * @param block The block to call when the data has been received. * If the block returns true, it will be called again with the same * buffer and exact length when more data has been received. If * you want the next block in the queue to handle the data * received next, you need to return false from the block. */ - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamAsyncReadBlock)block; # endif #endif /** * @brief Reads a uint8_t from the stream. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint8_t from the stream * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (uint8_t)readInt8; /** * @brief Reads a uint16_t from the stream which is encoded in big endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint16_t from the stream in big endian * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (uint16_t)readBigEndianInt16; /** * @brief Reads a uint32_t from the stream which is encoded in big endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint32_t from the stream in big endian * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (uint32_t)readBigEndianInt32; /** * @brief Reads a uint64_t from the stream which is encoded in big endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint64_t from the stream in big endian * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (uint64_t)readBigEndianInt64; /** * @brief Reads a float from the stream which is encoded in big endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A float from the stream in big endian * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (float)readBigEndianFloat; /** * @brief Reads a double from the stream which is encoded in big endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A double from the stream in big endian * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (double)readBigEndianDouble; /** * @brief Reads a uint16_t from the stream which is encoded in little endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint16_t from the stream in little endian * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (uint16_t)readLittleEndianInt16; /** * @brief Reads a uint32_t from the stream which is encoded in little endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint32_t from the stream in little endian * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (uint32_t)readLittleEndianInt32; /** * @brief Reads a uint64_t from the stream which is encoded in little endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint64_t from the stream in little endian * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (uint64_t)readLittleEndianInt64; /** * @brief Reads a float from the stream which is encoded in little endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A float from the stream in little endian * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (float)readLittleEndianFloat; /** * @brief Reads a double from the stream which is encoded in little endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A double from the stream in little endian * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (double)readLittleEndianDouble; /** * @brief Reads the specified number of items with an item size of 1 from the * stream and returns them as OFData. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @param count The number of items to read * @return OFData with count items. * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (OFData *)readDataWithCount: (size_t)count; /** * @brief Reads the specified number of items with the specified item size from * the stream and returns them as OFData. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @param itemSize The size of each item * @param count The number of items to read * @return OFData with count items. * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (OFData *)readDataWithItemSize: (size_t)itemSize count: (size_t)count; /** * @brief Returns OFData with all the remaining data of the stream. * * @return OFData with an item size of 1 with all the data of the stream until * the end of the stream is reached. * @throw OFReadFailedException Reading failed * @throw OFNotOpenException The stream is not open */ - (OFData *)readDataUntilEndOfStream; /** * @brief Reads a string with the specified length from the stream. * * If `\0` appears in the stream, the string will be truncated at the `\0` and * the rest of the bytes of the string will be lost. This way, reading from the * stream will not break because of a `\0` because the specified number of * bytes is still being read and only the string gets truncated. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @param length The length (in bytes) of the string to read from the stream * @return A string with the specified length * @throw OFReadFailedException Reading failed * @throw OFInvalidEncodingException The string read from the stream has * invalid encoding * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (OFString *)readStringWithLength: (size_t)length; /** * @brief Reads a string with the specified encoding and length from the stream. * * If a `\0` appears in the stream, the string will be truncated at the `\0` * and the rest of the bytes of the string will be lost. This way, reading from * the stream will not break because of a `\0` because the specified number of * bytes is still being read and only the string gets truncated. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @param encoding The encoding of the string to read from the stream * @param length The length (in bytes) of the string to read from the stream * @return A string with the specified length * @throw OFReadFailedException Reading failed * @throw OFInvalidEncodingException The string read from the stream has * invalid encoding * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (OFString *)readStringWithLength: (size_t)length encoding: (OFStringEncoding)encoding; /** * @brief Reads until a newline, `\0` or end of stream occurs. * * @return The line that was read, autoreleased, or `nil` if the end of the * stream has been reached. * @throw OFReadFailedException Reading failed * @throw OFInvalidEncodingException The string read from the stream has * invalid encoding * @throw OFNotOpenException The stream is not open */ - (nullable OFString *)readLine; /** * @brief Reads with the specified encoding until a newline, `\0` or end of * stream occurs. * * @param encoding The encoding used by the stream * @return The line that was read, autoreleased, or `nil` if the end of the * stream has been reached. * @throw OFReadFailedException Reading failed * @throw OFInvalidEncodingException The string read from the stream has * invalid encoding * @throw OFNotOpenException The stream is not open */ - (nullable OFString *)readLineWithEncoding: (OFStringEncoding)encoding; #ifdef OF_HAVE_SOCKETS /** * @brief Asynchronously reads until a newline, `\0`, end of stream or an * exception occurs. * * @note The stream must conform to @ref OFReadyForReadingObserving in order * for this to work! */ - (void)asyncReadLine; /** * @brief Asynchronously reads with the specified encoding until a newline, * `\0`, end of stream or an exception occurs. * * @note The stream must conform to @ref OFReadyForReadingObserving in order * for this to work! * * @param encoding The encoding used by the stream */ - (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding; /** * @brief Asynchronously reads with the specified encoding until a newline, * `\0`, end of stream or an exception occurs. * * @note The stream must conform to @ref OFReadyForReadingObserving in order * for this to work! * * @param encoding The encoding used by the stream * @param runLoopMode The run loop mode in which to perform the async read */ - (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding runLoopMode: (OFRunLoopMode)runLoopMode; # ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously reads until a newline, `\0`, end of stream or an * exception occurs. * * @note The stream must conform to @ref OFReadyForReadingObserving in order * for this to work! * * @param block The block to call when the data has been received. * If the block returns true, it will be called again when the next * line has been received. If you want the next block in the queue * to handle the next line, you need to return false from the * block. */ - (void)asyncReadLineWithBlock: (OFStreamAsyncReadLineBlock)block; /** * @brief Asynchronously reads with the specified encoding until a newline, * `\0`, end of stream or an exception occurs. * * @note The stream must conform to @ref OFReadyForReadingObserving in order * for this to work! * * @param encoding The encoding used by the stream * @param block The block to call when the data has been received. * If the block returns true, it will be called again when the next * line has been received. If you want the next block in the queue * to handle the next line, you need to return false from the * block. */ - (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding block: (OFStreamAsyncReadLineBlock)block; /** * @brief Asynchronously reads with the specified encoding until a newline, * `\0`, end of stream or an exception occurs. * * @note The stream must conform to @ref OFReadyForReadingObserving in order * for this to work! * * @param encoding The encoding used by the stream * @param runLoopMode The run loop mode in which to perform the async read * @param block The block to call when the data has been received. * If the block returns true, it will be called again when the next * line has been received. If you want the next block in the queue * to handle the next line, you need to return false from the * block. */ - (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding runLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamAsyncReadLineBlock)block; # endif #endif /** * @brief Tries to read a line from the stream (see @ref readLine) and returns * `nil` if no complete line has been received yet. * * @return The line that was read, autoreleased, or `nil` if the line is not * complete yet * @throw OFReadFailedException Reading failed * @throw OFInvalidEncodingException The string read from the stream has * invalid encoding * @throw OFNotOpenException The stream is not open */ - (nullable OFString *)tryReadLine; /** * @brief Tries to read a line from the stream with the specified encoding (see * @ref readLineWithEncoding:) and returns `nil` if no complete line has * been received yet. * * @param encoding The encoding used by the stream * @return The line that was read, autoreleased, or `nil` if the line is not * complete yet * @throw OFReadFailedException Reading failed * @throw OFInvalidEncodingException The string read from the stream has * invalid encoding * @throw OFNotOpenException The stream is not open */ - (nullable OFString *)tryReadLineWithEncoding: (OFStringEncoding)encoding; /** * @brief Reads until the specified string or `\0` is found or the end of * stream occurs. * * @param delimiter The delimiter * @return The string that was read, autoreleased, or `nil` if the end of the * stream has been reached. * @throw OFReadFailedException Reading failed * @throw OFInvalidEncodingException The string read from the stream has * invalid encoding * @throw OFNotOpenException The stream is not open */ - (nullable OFString *)readUntilDelimiter: (OFString *)delimiter; /** * @brief Reads until the specified string or `\0` is found or the end of * stream occurs. * * @param delimiter The delimiter * @param encoding The encoding used by the stream * @return The string that was read, autoreleased, or `nil` if the end of the * stream has been reached. * @throw OFReadFailedException Reading failed * @throw OFInvalidEncodingException The string read from the stream has * invalid encoding * @throw OFNotOpenException The stream is not open */ - (nullable OFString *)readUntilDelimiter: (OFString *)delimiter encoding: (OFStringEncoding)encoding; /** * @brief Tries to reads until the specified string or `\0` is found or the end * of stream (see @ref readUntilDelimiter:) and returns `nil` if not * enough data has been received yet. * * @param delimiter The delimiter * @return The string that was read, autoreleased, or `nil` if the end of the * stream has been reached. * @throw OFReadFailedException Reading failed * @throw OFInvalidEncodingException The string read from the stream has * invalid encoding * @throw OFNotOpenException The stream is not open */ - (nullable OFString *)tryReadUntilDelimiter: (OFString *)delimiter; /** * @brief Tries to read until the specified string or `\0` is found or the end * of stream occurs (see @ref readUntilDelimiter:encoding:) and returns * `nil` if not enough data has been received yet. * * @param delimiter The delimiter * @param encoding The encoding used by the stream * @return The string that was read, autoreleased, or `nil` if the end of the * stream has been reached. * @throw OFReadFailedException Reading failed * @throw OFInvalidEncodingException The string read from the stream has * invalid encoding * @throw OFNotOpenException The stream is not open */ - (nullable OFString *)tryReadUntilDelimiter: (OFString *)delimiter encoding: (OFStringEncoding)encoding; /** * @brief Writes everything in the write buffer to the stream. * * @return Whether the write buffer was flushed entirely. On non-blocking * sockets, this can return `false` if flushing the write buffer in its * entirety would block. */ - (bool)flushWriteBuffer; /** * @brief Writes from a buffer into the stream. * * In non-blocking mode, if less than the specified length could be written, an * @ref OFWriteFailedException is thrown with @ref OFWriteFailedException#errNo * being set to `EWOULDBLOCK` or `EAGAIN` (you need to check for both, as they * are not the same on some systems) and * @ref OFWriteFailedException#bytesWritten being set to the number of bytes * that were written, if any. * * @param buffer The buffer from which the data is written into the stream * @param length The length of the data that should be written * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeBuffer: (const void *)buffer length: (size_t)length; #ifdef OF_HAVE_SOCKETS /** * @brief Asynchronously writes data into the stream. * * @note The stream must conform to @ref OFReadyForWritingObserving in order * for this to work! * * @param data The data which is written into the stream */ - (void)asyncWriteData: (OFData *)data; /** * @brief Asynchronously writes data into the stream. * * @note The stream must conform to @ref OFReadyForWritingObserving in order * for this to work! * * @param data The data which is written into the stream * @param runLoopMode The run loop mode in which to perform the async write */ - (void)asyncWriteData: (OFData *)data runLoopMode: (OFRunLoopMode)runLoopMode; /** * @brief Asynchronously writes a string in UTF-8 encoding into the stream. * * @note The stream must conform to @ref OFReadyForWritingObserving in order * for this to work! * * @param string The string which is written into the stream */ - (void)asyncWriteString: (OFString *)string; /** * @brief Asynchronously writes a string in the specified encoding into the * stream. * * @note The stream must conform to @ref OFReadyForWritingObserving in order * for this to work! * * @param string The string which is written into the stream * @param encoding The encoding in which the string should be written to the * stream */ - (void)asyncWriteString: (OFString *)string encoding: (OFStringEncoding)encoding; /** * @brief Asynchronously writes a string in the specified encoding into the * stream. * * @note The stream must conform to @ref OFReadyForWritingObserving in order * for this to work! * * @param string The string which is written into the stream * @param encoding The encoding in which the string should be written to the * stream * @param runLoopMode The run loop mode in which to perform the async write */ - (void)asyncWriteString: (OFString *)string encoding: (OFStringEncoding)encoding runLoopMode: (OFRunLoopMode)runLoopMode; # ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously writes data into the stream. * * @note The stream must conform to @ref OFReadyForWritingObserving in order * for this to work! * * @param data The data which is written into the stream * @param block The block to call when the data has been written. It should * return the data for the next write with the same callback or * nil if it should not repeat. */ - (void)asyncWriteData: (OFData *)data block: (OFStreamAsyncWriteDataBlock)block; /** * @brief Asynchronously writes data into the stream. * * @note The stream must conform to @ref OFReadyForWritingObserving in order * for this to work! * * @param data The data which is written into the stream * @param runLoopMode The run loop mode in which to perform the async write * @param block The block to call when the data has been written. It should * return the data for the next write with the same callback or * nil if it should not repeat. */ - (void)asyncWriteData: (OFData *)data runLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamAsyncWriteDataBlock)block; /** * @brief Asynchronously writes a string into the stream. * * @note The stream must conform to @ref OFReadyForWritingObserving in order * for this to work! * * @param string The string which is written into the stream * @param block The block to call when the string has been written. It should * return the string for the next write with the same callback or * nil if it should not repeat. */ - (void)asyncWriteString: (OFString *)string block: (OFStreamAsyncWriteStringBlock)block; /** * @brief Asynchronously writes a string in the specified encoding into the * stream. * * @note The stream must conform to @ref OFReadyForWritingObserving in order * for this to work! * * @param string The string which is written into the stream * @param encoding The encoding in which the string should be written to the * stream * @param block The block to call when the string has been written. It should * return the string for the next write with the same callback or * nil if it should not repeat. */ - (void)asyncWriteString: (OFString *)string encoding: (OFStringEncoding)encoding block: (OFStreamAsyncWriteStringBlock)block; /** * @brief Asynchronously writes a string in the specified encoding into the * stream. * * @note The stream must conform to @ref OFReadyForWritingObserving in order * for this to work! * * @param string The string which is written into the stream * @param encoding The encoding in which the string should be written to the * stream * @param runLoopMode The run loop mode in which to perform the async write * @param block The block to call when the string has been written. It should * return the string for the next write with the same callback or * nil if it should not repeat. */ - (void)asyncWriteString: (OFString *)string encoding: (OFStringEncoding)encoding runLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamAsyncWriteStringBlock)block; # endif #endif /** * @brief Writes a uint8_t into the stream. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param int8 A uint8_t * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeInt8: (uint8_t)int8; /** * @brief Writes a uint16_t into the stream, encoded in big endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param int16 A uint16_t * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeBigEndianInt16: (uint16_t)int16; /** * @brief Writes a uint32_t into the stream, encoded in big endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param int32 A uint32_t * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeBigEndianInt32: (uint32_t)int32; /** * @brief Writes a uint64_t into the stream, encoded in big endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param int64 A uint64_t * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeBigEndianInt64: (uint64_t)int64; /** * @brief Writes a float into the stream, encoded in big endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param float_ A float * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeBigEndianFloat: (float)float_; /** * @brief Writes a double into the stream, encoded in big endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param double_ A double * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeBigEndianDouble: (double)double_; /** * @brief Writes a uint16_t into the stream, encoded in little endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param int16 A uint16_t * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeLittleEndianInt16: (uint16_t)int16; /** * @brief Writes a uint32_t into the stream, encoded in little endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param int32 A uint32_t * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeLittleEndianInt32: (uint32_t)int32; /** * @brief Writes a uint64_t into the stream, encoded in little endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param int64 A uint64_t * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeLittleEndianInt64: (uint64_t)int64; /** * @brief Writes a float into the stream, encoded in little endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param float_ A float * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeLittleEndianFloat: (float)float_; /** * @brief Writes a double into the stream, encoded in little endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param double_ A double * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeLittleEndianDouble: (double)double_; /** * @brief Writes OFData into the stream. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param data The OFData to write into the stream * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeData: (OFData *)data; /** * @brief Writes a string into the stream, without the trailing zero. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param string The string from which the data is written to the stream * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeString: (OFString *)string; /** * @brief Writes a string into the stream in the specified encoding, without * the trailing zero. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param string The string from which the data is written to the stream * @param encoding The encoding in which to write the string to the stream * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeString: (OFString *)string encoding: (OFStringEncoding)encoding; /** * @brief Writes a string into the stream with a trailing newline. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param string The string from which the data is written to the stream * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeLine: (OFString *)string; /** * @brief Writes a string into the stream in the specified encoding with a * trailing newline. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param string The string from which the data is written to the stream * @param encoding The encoding in which to write the string to the stream * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeLine: (OFString *)string encoding: (OFStringEncoding)encoding; /** * @brief Writes a formatted string into the stream. * * See printf for the format syntax. As an addition, `%@` is available as * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param format A string used as format * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open * @throw OFInvalidFormatException The specified format is invalid */ - (void)writeFormat: (OFConstantString *)format, ...; /** * @brief Writes a formatted string into the stream. * * See printf for the format syntax. As an addition, `%@` is available as * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param format A string used as format * @param arguments The arguments used in the format string * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open * @throw OFInvalidFormatException The specified format is invalid */ - (void)writeFormat: (OFConstantString *)format arguments: (va_list)arguments; #ifdef OF_HAVE_SOCKETS /** * @brief Cancels all pending asynchronous requests on the stream. */ - (void)cancelAsyncRequests; #endif /** * @brief "Reverses" a read operation, meaning the bytes from the specified * buffer will be returned on the next read operation. * * This is useful for reading into a buffer, parsing the data and then giving * back the data which does not need to be processed. This can be used to * optimize situations in which the length of the data that needs to be * processed is not known before all data has been processed - for example in * decompression - in which it would otherwise be necessary to read byte by * byte to avoid consuming bytes that need to be parsed by something else - * for example the data descriptor in a ZIP archive which immediately follows * the compressed data. * * If the stream is a file, this method does not change any data in the file. * * If the stream is seekable, a seek operation will discard any data which was * unread. * * @param buffer The buffer to unread * @param length The length of the buffer to unread */ - (void)unreadFromBuffer: (const void *)buffer length: (size_t)length; /** * @brief Closes the stream. * * @note If you override this, make sure to call `[super close]`! * * @throw OFNotOpenException The stream is not open */ - (void)close; /** * @brief Performs a lowlevel read. * * @warning Do not call this directly! * * @note Override this method with your actual read implementation when * subclassing! * * @param buffer The buffer for the data to read * @param length The length of the buffer * @return The number of bytes read * @throw OFReadFailedException Reading failed * @throw OFNotOpenException The stream is not open */ - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length; /** * @brief Performs a lowlevel write. * * @warning Do not call this directly! * * @note Override this method with your actual write implementation when * subclassing! * * @param buffer The buffer with the data to write * @param length The length of the data to write * @return The number of bytes written * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length; /** * @brief Returns whether the lowlevel is at the end of the stream. * * @warning Do not call this directly! * * @note Override this method with your actual end of stream checking * implementation when subclassing! * * @return Whether the lowlevel is at the end of the stream */ - (bool)lowlevelIsAtEndOfStream; /** * @brief Returns whether the lowlevel has data in the read buffer. * * @warning Do not call this directly! * * @note Override this method in case your stream can buffer data itself, such * as when implementing @ref OFTLSStream. If not overridden, it always * returns false. * * @return Whether the lowlevel has data in the read buffer */ - (bool)lowlevelHasDataInReadBuffer; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFStream.m000066400000000000000000000730741465614216400152770ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #include #include #include #ifdef HAVE_FCNTL_H # include #endif #include "platform.h" #if !defined(OF_WINDOWS) && !defined(OF_MORPHOS) # include #endif #import "OFStream.h" #import "OFStream+Private.h" #import "OFASPrintF.h" #import "OFData.h" #import "OFKernelEventObserver.h" #import "OFRunLoop+Private.h" #import "OFRunLoop.h" #ifdef OF_HAVE_SOCKETS # import "OFSocket+Private.h" #endif #import "OFString.h" #import "OFSystemInfo.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFSetOptionFailedException.h" #import "OFTruncatedDataException.h" #import "OFWriteFailedException.h" #define minReadSize 512 @implementation OFStream @synthesize buffersWrites = _buffersWrites; @synthesize of_waitingForDelimiter = _waitingForDelimiter, delegate = _delegate; #if defined(SIGPIPE) && defined(SIG_IGN) + (void)initialize { if (self == [OFStream class]) signal(SIGPIPE, SIG_IGN); } #endif - (instancetype)init { self = [super init]; @try { if (self.class == [OFStream class]) { [self doesNotRecognizeSelector: _cmd]; abort(); } _canBlock = true; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { OFFreeMemory(_readBufferMemory); OFFreeMemory(_writeBuffer); [super dealloc]; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { OF_UNRECOGNIZED_SELECTOR } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { OF_UNRECOGNIZED_SELECTOR } - (bool)lowlevelIsAtEndOfStream { OF_UNRECOGNIZED_SELECTOR } - (bool)lowlevelHasDataInReadBuffer { return false; } - (id)copy { return [self retain]; } - (bool)isAtEndOfStream { if (_readBufferLength > 0) return false; return [self lowlevelIsAtEndOfStream]; } - (size_t)readIntoBuffer: (void *)buffer length: (size_t)length { if (_readBufferLength == 0) { /* * For small sizes, it is cheaper to read more and cache the * remainder - even if that means more copying of data - than * to do a syscall for every read. */ if (length < minReadSize) { char tmp[minReadSize], *readBuffer; size_t bytesRead; bytesRead = [self lowlevelReadIntoBuffer: tmp length: minReadSize]; if (bytesRead > length) { memcpy(buffer, tmp, length); readBuffer = OFAllocMemory(bytesRead - length, 1); memcpy(readBuffer, tmp + length, bytesRead - length); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength = bytesRead - length; return length; } else { memcpy(buffer, tmp, bytesRead); return bytesRead; } } return [self lowlevelReadIntoBuffer: buffer length: length]; } if (length >= _readBufferLength) { size_t ret = _readBufferLength; memcpy(buffer, _readBuffer, _readBufferLength); OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = NULL; _readBufferLength = 0; return ret; } else { memcpy(buffer, _readBuffer, length); _readBuffer += length; _readBufferLength -= length; return length; } } - (void)readIntoBuffer: (void *)buffer exactLength: (size_t)length { size_t readLength = 0; while (readLength < length) { if (self.atEndOfStream) @throw [OFTruncatedDataException exception]; readLength += [self readIntoBuffer: (char *)buffer + readLength length: length - readLength]; } } #ifdef OF_HAVE_SOCKETS - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length { [self asyncReadIntoBuffer: buffer length: length runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode { OFStream *stream = (OFStream *)self; [OFRunLoop of_addAsyncReadForStream: stream buffer: buffer length: length mode: runLoopMode # ifdef OF_HAVE_BLOCKS block: NULL # endif delegate: _delegate]; } - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length { [self asyncReadIntoBuffer: buffer exactLength: length runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode { OFStream *stream = (OFStream *)self; [OFRunLoop of_addAsyncReadForStream: stream buffer: buffer exactLength: length mode: runLoopMode # ifdef OF_HAVE_BLOCKS block: NULL # endif delegate: _delegate]; } # ifdef OF_HAVE_BLOCKS - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length block: (OFStreamAsyncReadBlock)block { [self asyncReadIntoBuffer: buffer length: length runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamAsyncReadBlock)block { OFStream *stream = (OFStream *)self; [OFRunLoop of_addAsyncReadForStream: stream buffer: buffer length: length mode: runLoopMode block: block delegate: nil]; } - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length block: (OFStreamAsyncReadBlock)block { [self asyncReadIntoBuffer: buffer exactLength: length runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamAsyncReadBlock)block { OFStream *stream = (OFStream *)self; [OFRunLoop of_addAsyncReadForStream: stream buffer: buffer exactLength: length mode: runLoopMode block: block delegate: nil]; } # endif #endif - (uint8_t)readInt8 { uint8_t ret; [self readIntoBuffer: (char *)&ret exactLength: 1]; return ret; } - (uint16_t)readBigEndianInt16 { uint16_t ret; [self readIntoBuffer: (char *)&ret exactLength: 2]; return OFFromBigEndian16(ret); } - (uint32_t)readBigEndianInt32 { uint32_t ret; [self readIntoBuffer: (char *)&ret exactLength: 4]; return OFFromBigEndian32(ret); } - (uint64_t)readBigEndianInt64 { uint64_t ret; [self readIntoBuffer: (char *)&ret exactLength: 8]; return OFFromBigEndian64(ret); } - (float)readBigEndianFloat { float ret; [self readIntoBuffer: (char *)&ret exactLength: 4]; return OFFromBigEndianFloat(ret); } - (double)readBigEndianDouble { double ret; [self readIntoBuffer: (char *)&ret exactLength: 8]; return OFFromBigEndianDouble(ret); } - (uint16_t)readLittleEndianInt16 { uint16_t ret; [self readIntoBuffer: (char *)&ret exactLength: 2]; return OFFromLittleEndian16(ret); } - (uint32_t)readLittleEndianInt32 { uint32_t ret; [self readIntoBuffer: (char *)&ret exactLength: 4]; return OFFromLittleEndian32(ret); } - (uint64_t)readLittleEndianInt64 { uint64_t ret; [self readIntoBuffer: (char *)&ret exactLength: 8]; return OFFromLittleEndian64(ret); } - (float)readLittleEndianFloat { float ret; [self readIntoBuffer: (char *)&ret exactLength: 4]; return OFFromLittleEndianFloat(ret); } - (double)readLittleEndianDouble { double ret; [self readIntoBuffer: (char *)&ret exactLength: 8]; return OFFromLittleEndianDouble(ret); } - (OFData *)readDataWithCount: (size_t)count { return [self readDataWithItemSize: 1 count: count]; } - (OFData *)readDataWithItemSize: (size_t)itemSize count: (size_t)count { OFData *ret; char *buffer; if OF_UNLIKELY (count > SIZE_MAX / itemSize) @throw [OFOutOfRangeException exception]; buffer = OFAllocMemory(count, itemSize); @try { [self readIntoBuffer: buffer exactLength: count * itemSize]; ret = [OFData dataWithItemsNoCopy: buffer count: count itemSize: itemSize freeWhenDone: true]; } @catch (id e) { OFFreeMemory(buffer); @throw e; } return ret; } - (OFData *)readDataUntilEndOfStream { OFMutableData *data = [OFMutableData data]; size_t pageSize = [OFSystemInfo pageSize]; char *buffer = OFAllocMemory(1, pageSize); @try { while (!self.atEndOfStream) { size_t length = [self readIntoBuffer: buffer length: pageSize]; [data addItems: buffer count: length]; } } @finally { OFFreeMemory(buffer); } [data makeImmutable]; return data; } - (OFString *)readStringWithLength: (size_t)length { return [self readStringWithLength: length encoding: OFStringEncodingUTF8]; } - (OFString *)readStringWithLength: (size_t)length encoding: (OFStringEncoding)encoding { OFString *ret; char *buffer = OFAllocMemory(length + 1, 1); buffer[length] = 0; @try { [self readIntoBuffer: buffer exactLength: length]; ret = [OFString stringWithCString: buffer encoding: encoding]; } @finally { OFFreeMemory(buffer); } return ret; } - (OFString *)tryReadLineWithEncoding: (OFStringEncoding)encoding { size_t pageSize, bufferLength; char *buffer, *readBuffer; OFString *ret; /* Look if there's a line or \0 in our buffer */ if (!_waitingForDelimiter && _readBuffer != NULL) { for (size_t i = 0; i < _readBufferLength; i++) { if OF_UNLIKELY (_readBuffer[i] == '\n' || _readBuffer[i] == '\0') { size_t retLength = i; if (i > 0 && _readBuffer[i - 1] == '\r') retLength--; ret = [OFString stringWithCString: _readBuffer encoding: encoding length: retLength]; _readBuffer += i + 1; _readBufferLength -= i + 1; _waitingForDelimiter = false; return ret; } } } /* Read and see if we got a newline or \0 */ pageSize = [OFSystemInfo pageSize]; buffer = OFAllocMemory(1, pageSize); @try { if ([self lowlevelIsAtEndOfStream]) { size_t retLength; if (_readBuffer == NULL) { _waitingForDelimiter = false; return nil; } retLength = _readBufferLength; if (retLength > 0 && _readBuffer[retLength - 1] == '\r') retLength--; ret = [OFString stringWithCString: _readBuffer encoding: encoding length: retLength]; OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = NULL; _readBufferLength = 0; _waitingForDelimiter = false; return ret; } bufferLength = [self lowlevelReadIntoBuffer: buffer length: pageSize]; /* Look if there's a newline or \0 */ for (size_t i = 0; i < bufferLength; i++) { if OF_UNLIKELY (buffer[i] == '\n' || buffer[i] == '\0') { size_t retLength = _readBufferLength + i; char *retCString = OFAllocMemory(retLength, 1); if (_readBuffer != NULL) memcpy(retCString, _readBuffer, _readBufferLength); memcpy(retCString + _readBufferLength, buffer, i); if (retLength > 0 && retCString[retLength - 1] == '\r') retLength--; @try { ret = [OFString stringWithCString: retCString encoding: encoding length: retLength]; } @catch (id e) { if (bufferLength > 0) { /* * Append data to _readBuffer * to prevent loss of data. */ readBuffer = OFAllocMemory( _readBufferLength + bufferLength, 1); memcpy(readBuffer, _readBuffer, _readBufferLength); memcpy(readBuffer + _readBufferLength, buffer, bufferLength); OFFreeMemory(_readBufferMemory); _readBuffer = readBuffer; _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } @throw e; } @finally { OFFreeMemory(retCString); } readBuffer = OFAllocMemory(bufferLength - i - 1, 1); if (readBuffer != NULL) memcpy(readBuffer, buffer + i + 1, bufferLength - i - 1); OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength = bufferLength - i - 1; _waitingForDelimiter = false; return ret; } } /* There was no newline or \0 */ if (bufferLength > 0) { readBuffer = OFAllocMemory( _readBufferLength + bufferLength, 1); memcpy(readBuffer, _readBuffer, _readBufferLength); memcpy(readBuffer + _readBufferLength, buffer, bufferLength); OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } } @finally { OFFreeMemory(buffer); } _waitingForDelimiter = true; return nil; } - (OFString *)readLine { return [self readLineWithEncoding: OFStringEncodingUTF8]; } - (OFString *)readLineWithEncoding: (OFStringEncoding)encoding { OFString *line = nil; while ((line = [self tryReadLineWithEncoding: encoding]) == nil) if (self.atEndOfStream) return nil; return line; } #ifdef OF_HAVE_SOCKETS - (void)asyncReadLine { [self asyncReadLineWithEncoding: OFStringEncodingUTF8 runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding { [self asyncReadLineWithEncoding: encoding runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding runLoopMode: (OFRunLoopMode)runLoopMode { OFStream *stream = (OFStream *)self; [OFRunLoop of_addAsyncReadLineForStream: stream encoding: encoding mode: runLoopMode # ifdef OF_HAVE_BLOCKS block: NULL # endif delegate: _delegate]; } # ifdef OF_HAVE_BLOCKS - (void)asyncReadLineWithBlock: (OFStreamAsyncReadLineBlock)block { [self asyncReadLineWithEncoding: OFStringEncodingUTF8 runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding block: (OFStreamAsyncReadLineBlock)block { [self asyncReadLineWithEncoding: encoding runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding runLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamAsyncReadLineBlock)block { OFStream *stream = (OFStream *)self; [OFRunLoop of_addAsyncReadLineForStream: stream encoding: encoding mode: runLoopMode block: block delegate: nil]; } # endif #endif - (OFString *)tryReadLine { return [self tryReadLineWithEncoding: OFStringEncodingUTF8]; } - (OFString *)tryReadUntilDelimiter: (OFString *)delimiter encoding: (OFStringEncoding)encoding { const char *delimiterCString; size_t j, delimiterLength, pageSize, bufferLength; char *buffer, *readBuffer; OFString *ret; delimiterCString = [delimiter cStringWithEncoding: encoding]; delimiterLength = [delimiter cStringLengthWithEncoding: encoding]; j = 0; if (delimiterLength == 0) @throw [OFInvalidArgumentException exception]; /* Look if there's something in our buffer */ if (!_waitingForDelimiter && _readBuffer != NULL) { for (size_t i = 0; i < _readBufferLength; i++) { if (_readBuffer[i] != delimiterCString[j++]) j = 0; if (j == delimiterLength || _readBuffer[i] == '\0') { if (_readBuffer[i] == '\0') delimiterLength = 1; ret = [OFString stringWithCString: _readBuffer encoding: encoding length: i + 1 - delimiterLength]; _readBuffer += i + 1; _readBufferLength -= i + 1; _waitingForDelimiter = false; return ret; } } } /* Read and see if we got a delimiter or \0 */ pageSize = [OFSystemInfo pageSize]; buffer = OFAllocMemory(1, pageSize); @try { if ([self lowlevelIsAtEndOfStream]) { if (_readBuffer == NULL) { _waitingForDelimiter = false; return nil; } ret = [OFString stringWithCString: _readBuffer encoding: encoding length: _readBufferLength]; OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = NULL; _readBufferLength = 0; _waitingForDelimiter = false; return ret; } bufferLength = [self lowlevelReadIntoBuffer: buffer length: pageSize]; /* Look if there's a delimiter or \0 */ for (size_t i = 0; i < bufferLength; i++) { if (buffer[i] != delimiterCString[j++]) j = 0; if (j == delimiterLength || buffer[i] == '\0') { size_t retLength; char *retCString; if (buffer[i] == '\0') delimiterLength = 1; retLength = _readBufferLength + i + 1 - delimiterLength; retCString = OFAllocMemory(retLength, 1); if (_readBuffer != NULL && _readBufferLength <= retLength) memcpy(retCString, _readBuffer, _readBufferLength); else if (_readBuffer != NULL) memcpy(retCString, _readBuffer, retLength); if (i >= delimiterLength) memcpy(retCString + _readBufferLength, buffer, i + 1 - delimiterLength); @try { ret = [OFString stringWithCString: retCString encoding: encoding length: retLength]; } @catch (id e) { if (bufferLength > 0) { /* * Append data to _readBuffer * to prevent loss of data. */ readBuffer = OFAllocMemory( _readBufferLength + bufferLength, 1); memcpy(readBuffer, _readBuffer, _readBufferLength); memcpy(readBuffer + _readBufferLength, buffer, bufferLength); OFFreeMemory(_readBufferMemory); _readBuffer = readBuffer; _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } @throw e; } @finally { OFFreeMemory(retCString); } readBuffer = OFAllocMemory(bufferLength - i - 1, 1); if (readBuffer != NULL) memcpy(readBuffer, buffer + i + 1, bufferLength - i - 1); OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength = bufferLength - i - 1; _waitingForDelimiter = false; return ret; } } /* Neither the delimiter nor \0 was found */ if (bufferLength > 0) { readBuffer = OFAllocMemory( _readBufferLength + bufferLength, 1); memcpy(readBuffer, _readBuffer, _readBufferLength); memcpy(readBuffer + _readBufferLength, buffer, bufferLength); OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } } @finally { OFFreeMemory(buffer); } _waitingForDelimiter = true; return nil; } - (OFString *)readUntilDelimiter: (OFString *)delimiter { return [self readUntilDelimiter: delimiter encoding: OFStringEncodingUTF8]; } - (OFString *)readUntilDelimiter: (OFString *)delimiter encoding: (OFStringEncoding)encoding { OFString *ret = nil; while ((ret = [self tryReadUntilDelimiter: delimiter encoding: encoding]) == nil) if (self.atEndOfStream) return nil; return ret; } - (OFString *)tryReadUntilDelimiter: (OFString *)delimiter { return [self tryReadUntilDelimiter: delimiter encoding: OFStringEncodingUTF8]; } - (bool)flushWriteBuffer { size_t bytesWritten; if (_writeBuffer == NULL) return true; bytesWritten = [self lowlevelWriteBuffer: _writeBuffer length: _writeBufferLength]; if (bytesWritten == 0) return false; if (bytesWritten == _writeBufferLength) { OFFreeMemory(_writeBuffer); _writeBuffer = NULL; _writeBufferLength = 0; return true; } OFEnsure(bytesWritten <= _writeBufferLength); memmove(_writeBuffer, _writeBuffer + bytesWritten, _writeBufferLength - bytesWritten); _writeBufferLength -= bytesWritten; @try { _writeBuffer = OFResizeMemory(_writeBuffer, _writeBufferLength, 1); } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only made it smaller. */ } return false; } - (void)writeBuffer: (const void *)buffer length: (size_t)length { if (!_buffersWrites) { size_t bytesWritten = [self lowlevelWriteBuffer: buffer length: length]; if (bytesWritten < length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: bytesWritten errNo: 0]; } else { if (SIZE_MAX - _writeBufferLength < length) @throw [OFOutOfRangeException exception]; _writeBuffer = OFResizeMemory(_writeBuffer, _writeBufferLength + length, 1); memcpy(_writeBuffer + _writeBufferLength, buffer, length); _writeBufferLength += length; } } #ifdef OF_HAVE_SOCKETS - (void)asyncWriteData: (OFData *)data { [self asyncWriteData: data runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncWriteData: (OFData *)data runLoopMode: (OFRunLoopMode)runLoopMode { OFStream *stream = (OFStream *)self; [OFRunLoop of_addAsyncWriteForStream: stream data: data mode: runLoopMode # ifdef OF_HAVE_BLOCKS block: NULL # endif delegate: _delegate]; } - (void)asyncWriteString: (OFString *)string { [self asyncWriteString: string encoding: OFStringEncodingUTF8 runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncWriteString: (OFString *)string encoding: (OFStringEncoding)encoding { [self asyncWriteString: string encoding: encoding runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncWriteString: (OFString *)string encoding: (OFStringEncoding)encoding runLoopMode: (OFRunLoopMode)runLoopMode { OFStream *stream = (OFStream *)self; [OFRunLoop of_addAsyncWriteForStream: stream string: string encoding: encoding mode: runLoopMode # ifdef OF_HAVE_BLOCKS block: NULL # endif delegate: _delegate]; } # ifdef OF_HAVE_BLOCKS - (void)asyncWriteData: (OFData *)data block: (OFStreamAsyncWriteDataBlock)block { [self asyncWriteData: data runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncWriteData: (OFData *)data runLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamAsyncWriteDataBlock)block { OFStream *stream = (OFStream *)self; [OFRunLoop of_addAsyncWriteForStream: stream data: data mode: runLoopMode block: block delegate: nil]; } - (void)asyncWriteString: (OFString *)string block: (OFStreamAsyncWriteStringBlock)block { [self asyncWriteString: string encoding: OFStringEncodingUTF8 runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncWriteString: (OFString *)string encoding: (OFStringEncoding)encoding block: (OFStreamAsyncWriteStringBlock)block { [self asyncWriteString: string encoding: encoding runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncWriteString: (OFString *)string encoding: (OFStringEncoding)encoding runLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamAsyncWriteStringBlock)block { OFStream *stream = (OFStream *)self; [OFRunLoop of_addAsyncWriteForStream: stream string: string encoding: encoding mode: runLoopMode block: block delegate: nil]; } # endif #endif - (void)writeInt8: (uint8_t)int8 { [self writeBuffer: (char *)&int8 length: 1]; } - (void)writeBigEndianInt16: (uint16_t)int16 { int16 = OFToBigEndian16(int16); [self writeBuffer: (char *)&int16 length: 2]; } - (void)writeBigEndianInt32: (uint32_t)int32 { int32 = OFToBigEndian32(int32); [self writeBuffer: (char *)&int32 length: 4]; } - (void)writeBigEndianInt64: (uint64_t)int64 { int64 = OFToBigEndian64(int64); [self writeBuffer: (char *)&int64 length: 8]; } - (void)writeBigEndianFloat: (float)float_ { float_ = OFToBigEndianFloat(float_); [self writeBuffer: (char *)&float_ length: 4]; } - (void)writeBigEndianDouble: (double)double_ { double_ = OFToBigEndianDouble(double_); [self writeBuffer: (char *)&double_ length: 8]; } - (void)writeLittleEndianInt16: (uint16_t)int16 { int16 = OFToLittleEndian16(int16); [self writeBuffer: (char *)&int16 length: 2]; } - (void)writeLittleEndianInt32: (uint32_t)int32 { int32 = OFToLittleEndian32(int32); [self writeBuffer: (char *)&int32 length: 4]; } - (void)writeLittleEndianInt64: (uint64_t)int64 { int64 = OFToLittleEndian64(int64); [self writeBuffer: (char *)&int64 length: 8]; } - (void)writeLittleEndianFloat: (float)float_ { float_ = OFToLittleEndianFloat(float_); [self writeBuffer: (char *)&float_ length: 4]; } - (void)writeLittleEndianDouble: (double)double_ { double_ = OFToLittleEndianDouble(double_); [self writeBuffer: (char *)&double_ length: 8]; } - (void)writeData: (OFData *)data { void *pool; size_t length; if (data == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); length = data.count * data.itemSize; [self writeBuffer: data.items length: length]; objc_autoreleasePoolPop(pool); } - (void)writeString: (OFString *)string { [self writeString: string encoding: OFStringEncodingUTF8]; } - (void)writeString: (OFString *)string encoding: (OFStringEncoding)encoding { void *pool; size_t length; if (string == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); length = [string cStringLengthWithEncoding: encoding]; [self writeBuffer: [string cStringWithEncoding: encoding] length: length]; objc_autoreleasePoolPop(pool); } - (void)writeLine: (OFString *)string { [self writeLine: string encoding: OFStringEncodingUTF8]; } - (void)writeLine: (OFString *)string encoding: (OFStringEncoding)encoding { size_t stringLength = [string cStringLengthWithEncoding: encoding]; char *buffer; buffer = OFAllocMemory(stringLength + 1, 1); @try { memcpy(buffer, [string cStringWithEncoding: encoding], stringLength); buffer[stringLength] = '\n'; [self writeBuffer: buffer length: stringLength + 1]; } @finally { OFFreeMemory(buffer); } } - (void)writeFormat: (OFConstantString *)format, ... { va_list arguments; va_start(arguments, format); [self writeFormat: format arguments: arguments]; va_end(arguments); } - (void)writeFormat: (OFConstantString *)format arguments: (va_list)arguments { char *UTF8String; int length; if (format == nil) @throw [OFInvalidArgumentException exception]; if ((length = _OFVASPrintF(&UTF8String, format.UTF8String, arguments)) == -1) @throw [OFInvalidFormatException exception]; @try { [self writeBuffer: UTF8String length: length]; } @finally { free(UTF8String); } } - (bool)hasDataInReadBuffer { return (_readBufferLength > 0 || [self lowlevelHasDataInReadBuffer]); } - (bool)canBlock { return _canBlock; } - (void)setCanBlock: (bool)canBlock { #if defined(HAVE_FCNTL) && !defined(OF_AMIGAOS) bool readImplemented = false, writeImplemented = false; @try { int readFlags; readFlags = fcntl(((id )self) .fileDescriptorForReading, F_GETFL, 0); readImplemented = true; if (readFlags == -1) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: errno]; if (canBlock) readFlags &= ~O_NONBLOCK; else readFlags |= O_NONBLOCK; if (fcntl(((id )self) .fileDescriptorForReading, F_SETFL, readFlags) == -1) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: errno]; } @catch (OFNotImplementedException *e) { } @try { int writeFlags; writeFlags = fcntl(((id )self) .fileDescriptorForWriting, F_GETFL, 0); writeImplemented = true; if (writeFlags == -1) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: errno]; if (canBlock) writeFlags &= ~O_NONBLOCK; else writeFlags |= O_NONBLOCK; if (fcntl(((id )self) .fileDescriptorForWriting, F_SETFL, writeFlags) == -1) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: errno]; } @catch (OFNotImplementedException *e) { } if (!readImplemented && !writeImplemented) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; _canBlock = canBlock; #else OF_UNRECOGNIZED_SELECTOR #endif } - (int)fileDescriptorForReading { OF_UNRECOGNIZED_SELECTOR } - (int)fileDescriptorForWriting { OF_UNRECOGNIZED_SELECTOR } #ifdef OF_HAVE_SOCKETS - (void)cancelAsyncRequests { [OFRunLoop of_cancelAsyncRequestsForObject: self mode: OFDefaultRunLoopMode]; } #endif - (void)unreadFromBuffer: (const void *)buffer length: (size_t)length { char *readBuffer; if (length > SIZE_MAX - _readBufferLength) @throw [OFOutOfRangeException exception]; readBuffer = OFAllocMemory(_readBufferLength + length, 1); memcpy(readBuffer, buffer, length); memcpy(readBuffer + length, _readBuffer, _readBufferLength); OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength += length; } - (void)close { OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = NULL; _readBufferLength = 0; OFFreeMemory(_writeBuffer); _writeBuffer = NULL; _writeBufferLength = 0; _buffersWrites = false; _waitingForDelimiter = false; } @end objfw-1.1.6/src/OFStreamSocket+Private.h000066400000000000000000000016241465614216400200410ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFStreamSocket.h" OF_ASSUME_NONNULL_BEGIN @interface OFStreamSocket () #ifndef OF_WII @property (readonly, nonatomic) int of_socketError; #endif @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFStreamSocket.h000066400000000000000000000135451465614216400164400ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFStream.h" #import "OFSocket.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFStreamSocket; #ifdef OF_HAVE_BLOCKS /** * @brief A block which is called when the socket accepted a connection. * * @param acceptedSocket The socket which has been accepted * @param exception An exception which occurred while accepting the socket or * `nil` on success * @return A bool whether the same block should be used for the next incoming * connection */ typedef bool (^OFStreamSocketAsyncAcceptBlock)(OFStreamSocket *acceptedSocket, id _Nullable exception); #endif /** * @protocol OFStreamSocketDelegate OFStreamSocket.h ObjFW/OFStreamSocket.h * * A delegate for OFStreamSocket. */ @protocol OFStreamSocketDelegate @optional /** * @brief A method which is called when a socket accepted a connection. * * @param socket The socket which accepted the connection * @param acceptedSocket The socket which has been accepted * @param exception An exception that occurred while accepting, or nil on * success * @return A bool whether to accept the next incoming connection */ - (bool)socket: (OFStreamSocket *)socket didAcceptSocket: (OFStreamSocket *)acceptedSocket exception: (nullable id)exception; @end /** * @class OFStreamSocket OFStreamSocket.h ObjFW/OFStreamSocket.h * * @brief A class which provides methods to create and use stream sockets. */ @interface OFStreamSocket: OFStream { OFSocketHandle _socket; #ifdef OF_AMIGAOS LONG _socketID; int _family; /* unused, reserved for ABI stability */ #endif bool _atEndOfStream, _listening; OFSocketAddress _remoteAddress; OF_RESERVE_IVARS(OFStreamSocket, 4) } /** * @brief Whether the socket is a listening socket. */ @property (readonly, nonatomic, getter=isListening) bool listening; /** * @brief The remote address. * * @note This only works for accepted sockets! * * @throw OFNotOpenException The socket is not open * @throw OFInvalidArgumentException The socket has no remote address */ @property (readonly, nonatomic) const OFSocketAddress *remoteAddress; /** * @brief The delegate for asynchronous operations on the socket. * * @note The delegate is retained for as long as asynchronous operations are * still ongoing. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id delegate; /** * @brief Returns a new, autoreleased OFStreamSocket. * * @return A new, autoreleased OFStreamSocket */ + (instancetype)socket; /** * @brief Listen on the socket. * * @param backlog Maximum length for the queue of pending connections. * @throw OFListenOnSocketFailedException Listening failed * @throw OFNotOpenException The socket is not open */ - (void)listenWithBacklog: (int)backlog; /** * @brief Listen on the socket. * * @throw OFListenOnSocketFailedException Listening failed * @throw OFNotOpenException The socket is not open */ - (void)listen; /** * @brief Accept an incoming connection. * * @return An autoreleased OFStreamSocket for the accepted connection. * @throw OFAcceptSocketFailedException Accepting failed * @throw OFNotOpenException The socket is not open */ - (instancetype)accept; /** * @brief Asynchronously accept an incoming connection. */ - (void)asyncAccept; /** * @brief Asynchronously accept an incoming connection. * * @param runLoopMode The run loop mode in which to perform the async accept */ - (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously accept an incoming connection. * * @param block The block to execute when a new connection has been accepted. * Returns whether the next incoming connection should be accepted * by the specified block as well. */ - (void)asyncAcceptWithBlock: (OFStreamSocketAsyncAcceptBlock)block; /** * @brief Asynchronously accept an incoming connection. * * @param runLoopMode The run loop mode in which to perform the async accept * @param block The block to execute when a new connection has been accepted. * Returns whether the next incoming connection should be accepted * by the specified block as well. */ - (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamSocketAsyncAcceptBlock)block; #endif /** * @brief Releases the socket from the current thread. * * This is necessary on some platforms in order to allow a different thread to * use the socket, e.g. on AmigaOS, but you should call it on all operating * systems before using the socket from a different thread. * * After calling this method, you must no longer use the socket until * @ref obtainSocketForCurrentThread has been called. */ - (void)releaseSocketFromCurrentThread; /** * @brief Obtains the socket for the current thread. * * This is necessary on some platforms in order to allow a different thread to * use the socket, e.g. on AmigaOS, but you should call it on all operating * systems before using the socket from a different thread. * * You must only call this method after @ref releaseSocketFromCurrentThread has * been called from a different thread. */ - (void)obtainSocketForCurrentThread; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFStreamSocket.m000066400000000000000000000236341465614216400164450ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #ifndef _XOPEN_SOURCE_EXTENDED # define _XOPEN_SOURCE_EXTENDED #endif #define _HPUX_ALT_XOPEN_SOCKET_API #include #include #import "OFStreamSocket.h" #import "OFStreamSocket+Private.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #import "OFSocket+Private.h" #import "OFAcceptSocketFailedException.h" #import "OFAlreadyOpenException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFListenOnSocketFailedException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFSetOptionFailedException.h" #import "OFWriteFailedException.h" #if defined(OF_AMIGAOS) && !defined(UNIQUE_ID) # define UNIQUE_ID -1 #endif @implementation OFStreamSocket @dynamic delegate; @synthesize listening = _listening; + (void)initialize { if (self != [OFStreamSocket class]) return; if (!_OFSocketInit()) @throw [OFInitializationFailedException exceptionWithClass: self]; } + (instancetype)socket { return [[[self alloc] init] autorelease]; } - (instancetype)init { self = [super init]; @try { if (self.class == [OFStreamSocket class]) { [self doesNotRecognizeSelector: _cmd]; abort(); } _socket = OFInvalidSocketHandle; #ifdef OF_AMIGAOS _socketID = -1; #endif } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_socket != OFInvalidSocketHandle) [self close]; [super dealloc]; } - (bool)lowlevelIsAtEndOfStream { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; return _atEndOfStream; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { ssize_t ret; if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; #ifndef OF_WINDOWS if ((ret = recv(_socket, buffer, length, 0)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: _OFSocketErrNo()]; #else if (length > INT_MAX) @throw [OFOutOfRangeException exception]; if ((ret = recv(_socket, buffer, (int)length, 0)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: _OFSocketErrNo()]; #endif if (ret == 0) _atEndOfStream = true; return ret; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; #ifndef OF_WINDOWS ssize_t bytesWritten; if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = send(_socket, (void *)buffer, length, 0)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: _OFSocketErrNo()]; #else int bytesWritten; if (length > INT_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = send(_socket, buffer, (int)length, 0)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: _OFSocketErrNo()]; #endif return (size_t)bytesWritten; } #if defined(OF_WINDOWS) || defined(OF_AMIGAOS) - (void)setCanBlock: (bool)canBlock { # ifdef OF_WINDOWS u_long v = !canBlock; # else char v = !canBlock; # endif if (ioctlsocket(_socket, FIONBIO, &v) == SOCKET_ERROR) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: _OFSocketErrNo()]; _canBlock = canBlock; } #endif - (int)fileDescriptorForReading { #ifndef OF_WINDOWS return _socket; #else if (_socket == OFInvalidSocketHandle) return -1; if (_socket > INT_MAX) @throw [OFOutOfRangeException exception]; return (int)_socket; #endif } - (int)fileDescriptorForWriting { #ifndef OF_WINDOWS return _socket; #else if (_socket == OFInvalidSocketHandle) return -1; if (_socket > INT_MAX) @throw [OFOutOfRangeException exception]; return (int)_socket; #endif } #ifndef OF_WII - (int)of_socketError { int errNo; socklen_t len = sizeof(errNo); if (getsockopt(_socket, SOL_SOCKET, SO_ERROR, (char *)&errNo, &len) != 0) return _OFSocketErrNo(); return errNo; } #endif - (void)listen { [self listenWithBacklog: SOMAXCONN]; } - (void)listenWithBacklog: (int)backlog { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; if (listen(_socket, backlog) == -1) @throw [OFListenOnSocketFailedException exceptionWithSocket: self backlog: backlog errNo: _OFSocketErrNo()]; _listening = true; } - (instancetype)accept { OFStreamSocket *client; #if (!defined(HAVE_PACCEPT) && !defined(HAVE_ACCEPT4)) || !defined(SOCK_CLOEXEC) # if defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; # endif #endif if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; client = [[[[self class] alloc] init] autorelease]; client->_remoteAddress.length = (socklen_t)sizeof(client->_remoteAddress.sockaddr); #if defined(HAVE_PACCEPT) && defined(SOCK_CLOEXEC) if ((client->_socket = paccept(_socket, (struct sockaddr *)&client->_remoteAddress.sockaddr, &client->_remoteAddress.length, NULL, SOCK_CLOEXEC)) == OFInvalidSocketHandle) @throw [OFAcceptSocketFailedException exceptionWithSocket: self errNo: _OFSocketErrNo()]; #elif defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) if ((client->_socket = accept4(_socket, (struct sockaddr * )&client->_remoteAddress.sockaddr, &client->_remoteAddress.length, SOCK_CLOEXEC)) == OFInvalidSocketHandle) @throw [OFAcceptSocketFailedException exceptionWithSocket: self errNo: _OFSocketErrNo()]; #else if ((client->_socket = accept(_socket, (struct sockaddr *)&client->_remoteAddress.sockaddr, &client->_remoteAddress.length)) == OFInvalidSocketHandle) @throw [OFAcceptSocketFailedException exceptionWithSocket: self errNo: _OFSocketErrNo()]; # if defined(HAVE_FCNTL) && defined(FD_CLOEXEC) if ((flags = fcntl(client->_socket, F_GETFD, 0)) != -1) fcntl(client->_socket, F_SETFD, flags | FD_CLOEXEC); # endif #endif OFAssert(client->_remoteAddress.length <= (socklen_t)sizeof(client->_remoteAddress.sockaddr)); switch (((struct sockaddr *)&client->_remoteAddress.sockaddr) ->sa_family) { case AF_INET: client->_remoteAddress.family = OFSocketAddressFamilyIPv4; break; #ifdef OF_HAVE_IPV6 case AF_INET6: client->_remoteAddress.family = OFSocketAddressFamilyIPv6; break; #endif #ifdef OF_HAVE_UNIX_SOCKETS case AF_UNIX: client->_remoteAddress.family = OFSocketAddressFamilyUNIX; break; #endif #ifdef OF_HAVE_IPX case AF_IPX: client->_remoteAddress.family = OFSocketAddressFamilyIPX; break; #endif default: client->_remoteAddress.family = OFSocketAddressFamilyUnknown; break; } return client; } - (void)asyncAccept { [self asyncAcceptWithRunLoopMode: OFDefaultRunLoopMode]; } - (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode { [OFRunLoop of_addAsyncAcceptForSocket: self mode: runLoopMode block: NULL delegate: _delegate]; } #ifdef OF_HAVE_BLOCKS - (void)asyncAcceptWithBlock: (OFStreamSocketAsyncAcceptBlock)block { [self asyncAcceptWithRunLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamSocketAsyncAcceptBlock)block { [OFRunLoop of_addAsyncAcceptForSocket: self mode: runLoopMode block: block delegate: nil]; } #endif - (const OFSocketAddress *)remoteAddress { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; if (_remoteAddress.length == 0) @throw [OFInvalidArgumentException exception]; if (_remoteAddress.length > (socklen_t)sizeof(_remoteAddress.sockaddr)) @throw [OFOutOfRangeException exception]; return &_remoteAddress; } - (void)releaseSocketFromCurrentThread { #ifdef OF_AMIGAOS if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; if ((_socketID = ReleaseSocket(_socket, UNIQUE_ID)) == -1) { switch (Errno()) { case ENOMEM: @throw [OFOutOfMemoryException exceptionWithRequestedSize: 0]; case EBADF: @throw [OFNotOpenException exceptionWithObject: self]; default: OFEnsure(0); } } _socket = OFInvalidSocketHandle; #endif } - (void)obtainSocketForCurrentThread { #ifdef OF_AMIGAOS if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyOpenException exceptionWithObject: self]; if (_socketID == -1) @throw [OFNotOpenException exceptionWithObject: self]; /* * FIXME: We should store these, but that requires changing all * subclasses. This only becomes a problem if IPv6 support ever * gets added. */ _socket = ObtainSocket(_socketID, AF_INET, SOCK_STREAM, 0); if (_socket == OFInvalidSocketHandle) @throw [OFInitializationFailedException exceptionWithClass: self.class]; _socketID = -1; #endif } - (void)close { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; _listening = false; memset(&_remoteAddress, 0, sizeof(_remoteAddress)); closesocket(_socket); _socket = OFInvalidSocketHandle; _atEndOfStream = false; [super close]; } @end objfw-1.1.6/src/OFString+CryptographicHashing.h000066400000000000000000000035321465614216400214110ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFString.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif extern int _OFString_CryptographicHashing_reference OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif @interface OFString (CryptographicHashing) /** * @brief The MD5 hash of the string as a string. */ @property (readonly, nonatomic) OFString *stringByMD5Hashing; /** * @brief The RIPEMD-160 hash of the string as a string. */ @property (readonly, nonatomic) OFString *stringByRIPEMD160Hashing; /** * @brief The SHA-1 hash of the string as a string. */ @property (readonly, nonatomic) OFString *stringBySHA1Hashing; /** * @brief The SHA-224 hash of the string as a string. */ @property (readonly, nonatomic) OFString *stringBySHA224Hashing; /** * @brief The SHA-256 hash of the string as a string. */ @property (readonly, nonatomic) OFString *stringBySHA256Hashing; /** * @brief The SHA-384 hash of the string as a string. */ @property (readonly, nonatomic) OFString *stringBySHA384Hashing; /** * @brief The SHA-512 hash of the string as a string. */ @property (readonly, nonatomic) OFString *stringBySHA512Hashing; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFString+CryptographicHashing.m000066400000000000000000000050031465614216400214110ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFString.h" #import "OFCryptographicHash.h" #import "OFMD5Hash.h" #import "OFRIPEMD160Hash.h" #import "OFSHA1Hash.h" #import "OFSHA224Hash.h" #import "OFSHA256Hash.h" #import "OFSHA384Hash.h" #import "OFSHA512Hash.h" int _OFString_CryptographicHashing_reference; @implementation OFString (CryptographicHashing) static OFString * stringByHashing(Class class, OFString *self) { void *pool = objc_autoreleasePoolPush(); id hash = [class hashWithAllowsSwappableMemory: true]; size_t digestSize = [class digestSize]; const unsigned char *digest; char cString[digestSize * 2]; [hash updateWithBuffer: self.UTF8String length: self.UTF8StringLength]; [hash calculate]; digest = hash.digest; for (size_t i = 0; i < digestSize; i++) { uint8_t high, low; high = digest[i] >> 4; low = digest[i] & 0x0F; cString[i * 2] = (high > 9 ? high - 10 + 'a' : high + '0'); cString[i * 2 + 1] = (low > 9 ? low - 10 + 'a' : low + '0'); } objc_autoreleasePoolPop(pool); return [OFString stringWithCString: cString encoding: OFStringEncodingASCII length: digestSize * 2]; } - (OFString *)stringByMD5Hashing { return stringByHashing([OFMD5Hash class], self); } - (OFString *)stringByRIPEMD160Hashing { return stringByHashing([OFRIPEMD160Hash class], self); } - (OFString *)stringBySHA1Hashing { return stringByHashing([OFSHA1Hash class], self); } - (OFString *)stringBySHA224Hashing { return stringByHashing([OFSHA224Hash class], self); } - (OFString *)stringBySHA256Hashing { return stringByHashing([OFSHA256Hash class], self); } - (OFString *)stringBySHA384Hashing { return stringByHashing([OFSHA384Hash class], self); } - (OFString *)stringBySHA512Hashing { return stringByHashing([OFSHA512Hash class], self); } @end objfw-1.1.6/src/OFString+JSONParsing.h000066400000000000000000000056771465614216400174020ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFString.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif extern int _OFString_JSONParsing_reference OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif @interface OFString (JSONParsing) /** * @brief The string interpreted as JSON and parsed as an object. * * @note This also allows parsing JSON5, an extension of JSON. See * http://json5.org/ for more details. * * @warning Although not specified by the JSON specification, this can also * return primitives like strings and numbers. The rationale behind * this is that most JSON parsers allow JSON data just consisting of a * single primitive, leading to real world JSON files sometimes only * consisting of a single primitive. Therefore, you should not make any * assumptions about the object returned by this method if you don't * want your program to terminate due to a message not understood, but * instead check the returned object using @ref isKindOfClass:. * * @throw OFInvalidJSONException The string contained invalid JSON */ @property (readonly, nonatomic) id objectByParsingJSON; /** * @brief Creates an object from the JSON value of the string. * * @note This also allows parsing JSON5, an extension of JSON. See * http://json5.org/ for more details. * * @warning Although not specified by the JSON specification, this can also * return primitives like strings and numbers. The rationale behind * this is that most JSON parsers allow JSON data just consisting of a * single primitive, leading to real world JSON files sometimes only * consisting of a single primitive. Therefore, you should not make any * assumptions about the object returned by this method if you don't * want your program to terminate due to a message not understood, but * instead check the returned object using @ref isKindOfClass:. * * @param depthLimit The maximum depth the parser should accept (defaults to 32 * if not specified, 0 means no limit (insecure!)) * @return An object * @throw OFInvalidJSONException The string contained invalid JSON */ - (id)objectByParsingJSONWithDepthLimit: (size_t)depthLimit; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFString+JSONParsing.m000066400000000000000000000317531465614216400174010ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #include #import "OFString+JSONParsing.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFNumber.h" #import "OFNull.h" #import "OFInvalidJSONException.h" #ifndef INFINITY # define INFINITY __builtin_inf() #endif int _OFString_JSONParsing_reference; static id nextObject(const char **pointer, const char *stop, size_t *line, size_t depthLimit); static void skipWhitespaces(const char **pointer, const char *stop, size_t *line) { while (*pointer < stop && (**pointer == ' ' || **pointer == '\t' || **pointer == '\r' || **pointer == '\n')) { if (**pointer == '\n') (*line)++; (*pointer)++; } } static void skipComment(const char **pointer, const char *stop, size_t *line) { if (**pointer != '/') return; if (*pointer + 1 >= stop) return; (*pointer)++; if (**pointer == '*') { bool lastIsAsterisk = false; (*pointer)++; while (*pointer < stop) { if (lastIsAsterisk && **pointer == '/') { (*pointer)++; return; } lastIsAsterisk = (**pointer == '*'); if (**pointer == '\n') (*line)++; (*pointer)++; } } else if (**pointer == '/') { (*pointer)++; while (*pointer < stop) { if (**pointer == '\r' || **pointer == '\n') { (*pointer)++; (*line)++; return; } (*pointer)++; } } else (*pointer)--; } static void skipWhitespacesAndComments(const char **pointer, const char *stop, size_t *line) { const char *old = NULL; while (old != *pointer) { old = *pointer; skipWhitespaces(pointer, stop, line); skipComment(pointer, stop, line); } } static inline OFChar16 parseUnicodeEscape(const char *pointer, const char *stop) { OFChar16 ret = 0; if (pointer + 5 >= stop) return 0xFFFF; if (pointer[0] != '\\' || pointer[1] != 'u') return 0xFFFF; for (uint8_t i = 0; i < 4; i++) { char c = pointer[i + 2]; ret <<= 4; if (c >= '0' && c <= '9') ret |= c - '0'; else if (c >= 'a' && c <= 'f') ret |= c + 10 - 'a'; else if (c >= 'A' && c <= 'F') ret |= c + 10 - 'A'; else return 0xFFFF; } if (ret == 0) return 0xFFFF; return ret; } static inline OFString * parseString(const char **pointer, const char *stop, size_t *line) { char *buffer; size_t i = 0; char delimiter = **pointer; if (++(*pointer) + 1 >= stop) return nil; buffer = OFAllocMemory(stop - *pointer, 1); while (*pointer < stop) { /* Parse escape codes */ if (**pointer == '\\') { if (++(*pointer) >= stop) { OFFreeMemory(buffer); return nil; } switch (**pointer) { case '"': case '\\': case '/': buffer[i++] = **pointer; (*pointer)++; break; case 'b': buffer[i++] = '\b'; (*pointer)++; break; case 'f': buffer[i++] = '\f'; (*pointer)++; break; case 'n': buffer[i++] = '\n'; (*pointer)++; break; case 'r': buffer[i++] = '\r'; (*pointer)++; break; case 't': buffer[i++] = '\t'; (*pointer)++; break; /* Parse Unicode escape sequence */ case 'u':; OFChar16 c1, c2; OFUnichar c; size_t l; c1 = parseUnicodeEscape(*pointer - 1, stop); if (c1 == 0xFFFF) { OFFreeMemory(buffer); return nil; } /* Low surrogate */ if ((c1 & 0xFC00) == 0xDC00) { OFFreeMemory(buffer); return nil; } /* Normal character */ if ((c1 & 0xFC00) != 0xD800) { l = _OFUTF8StringEncode(c1, buffer + i); if (l == 0) { OFFreeMemory(buffer); return nil; } i += l; *pointer += 5; break; } /* * If we are still here, we only got one UTF-16 * surrogate and now need to get the other one * in order to produce UTF-8 and not CESU-8. */ c2 = parseUnicodeEscape(*pointer + 5, stop); if (c2 == 0xFFFF) { OFFreeMemory(buffer); return nil; } c = (((c1 & 0x3FF) << 10) | (c2 & 0x3FF)) + 0x10000; l = _OFUTF8StringEncode(c, buffer + i); if (l == 0) { OFFreeMemory(buffer); return nil; } i += l; *pointer += 11; break; case '\r': (*pointer)++; if (*pointer < stop && **pointer == '\n') { (*pointer)++; (*line)++; } break; case '\n': (*pointer)++; (*line)++; break; default: OFFreeMemory(buffer); return nil; } /* End of string found */ } else if (**pointer == delimiter) { OFString *ret; @try { ret = [OFString stringWithUTF8String: buffer length: i]; } @finally { OFFreeMemory(buffer); } (*pointer)++; return ret; /* Newlines in strings are disallowed */ } else if (**pointer == '\n' || **pointer == '\r') { (*line)++; OFFreeMemory(buffer); return nil; } else { buffer[i++] = **pointer; (*pointer)++; } } OFFreeMemory(buffer); return nil; } static inline OFString * parseIdentifier(const char **pointer, const char *stop) { char *buffer; size_t i = 0; buffer = OFAllocMemory(stop - *pointer, 1); while (*pointer < stop) { if ((**pointer >= 'a' && **pointer <= 'z') || (**pointer >= 'A' && **pointer <= 'Z') || (**pointer >= '0' && **pointer <= '9') || **pointer == '_' || **pointer == '$' || (**pointer & 0x80)) { buffer[i++] = **pointer; (*pointer)++; } else if (**pointer == '\\') { OFChar16 c1, c2; OFUnichar c; size_t l; if (++(*pointer) >= stop || **pointer != 'u') { OFFreeMemory(buffer); return nil; } c1 = parseUnicodeEscape(*pointer - 1, stop); if (c1 == 0xFFFF) { OFFreeMemory(buffer); return nil; } /* Low surrogate */ if ((c1 & 0xFC00) == 0xDC00) { OFFreeMemory(buffer); return nil; } /* Normal character */ if ((c1 & 0xFC00) != 0xD800) { l = _OFUTF8StringEncode(c1, buffer + i); if (l == 0) { OFFreeMemory(buffer); return nil; } i += l; *pointer += 5; continue; } /* * If we are still here, we only got one UTF-16 * surrogate and now need to get the other one in order * to produce UTF-8 and not CESU-8. */ c2 = parseUnicodeEscape(*pointer + 5, stop); if (c2 == 0xFFFF) { OFFreeMemory(buffer); return nil; } c = (((c1 & 0x3FF) << 10) | (c2 & 0x3FF)) + 0x10000; l = _OFUTF8StringEncode(c, buffer + i); if (l == 0) { OFFreeMemory(buffer); return nil; } i += l; *pointer += 11; } else { OFString *ret; if (i == 0 || (buffer[0] >= '0' && buffer[0] <= '9')) { OFFreeMemory(buffer); return nil; } @try { ret = [OFString stringWithUTF8String: buffer length: i]; } @finally { OFFreeMemory(buffer); } return ret; } } /* * It is never possible to end with an identifier, thus we should never * reach stop. */ OFFreeMemory(buffer); return nil; } static inline OFMutableArray * parseArray(const char **pointer, const char *stop, size_t *line, size_t depthLimit) { OFMutableArray *array = [OFMutableArray array]; if (++(*pointer) >= stop) return nil; if (--depthLimit == 0) return nil; while (**pointer != ']') { id object; skipWhitespacesAndComments(pointer, stop, line); if (*pointer >= stop) return nil; if (**pointer == ']') break; if (**pointer == ',') { (*pointer)++; skipWhitespacesAndComments(pointer, stop, line); if (*pointer >= stop || **pointer != ']') return nil; break; } object = nextObject(pointer, stop, line, depthLimit); if (object == nil) return nil; [array addObject: object]; skipWhitespacesAndComments(pointer, stop, line); if (*pointer >= stop) return nil; if (**pointer == ',') { (*pointer)++; skipWhitespacesAndComments(pointer, stop, line); if (*pointer >= stop) return nil; } else if (**pointer != ']') return nil; } (*pointer)++; return array; } static inline OFMutableDictionary * parseDictionary(const char **pointer, const char *stop, size_t *line, size_t depthLimit) { OFMutableDictionary *dictionary = [OFMutableDictionary dictionary]; if (++(*pointer) >= stop) return nil; if (--depthLimit == 0) return nil; while (**pointer != '}') { OFString *key; id object; skipWhitespacesAndComments(pointer, stop, line); if (*pointer >= stop) return nil; if (**pointer == '}') break; if (**pointer == ',') { (*pointer)++; skipWhitespacesAndComments(pointer, stop, line); if (*pointer >= stop || **pointer != '}') return nil; break; } skipWhitespacesAndComments(pointer, stop, line); if (*pointer + 1 >= stop) return nil; if ((**pointer >= 'a' && **pointer <= 'z') || (**pointer >= 'A' && **pointer <= 'Z') || **pointer == '_' || **pointer == '$' || **pointer == '\\') key = parseIdentifier(pointer, stop); else key = nextObject(pointer, stop, line, depthLimit); if (![key isKindOfClass: [OFString class]]) return nil; skipWhitespacesAndComments(pointer, stop, line); if (*pointer + 1 >= stop || **pointer != ':') return nil; (*pointer)++; object = nextObject(pointer, stop, line, depthLimit); if (object == nil) return nil; [dictionary setObject: object forKey: key]; skipWhitespacesAndComments(pointer, stop, line); if (*pointer >= stop) return nil; if (**pointer == ',') { (*pointer)++; skipWhitespacesAndComments(pointer, stop, line); if (*pointer >= stop) return nil; } else if (**pointer != '}') return nil; } (*pointer)++; return dictionary; } static inline OFNumber * parseNumber(const char **pointer, const char *stop, size_t *line) { bool isNegative = (*pointer < stop && (*pointer)[0] == '-'); bool hasDecimal = false; size_t i; OFString *string; OFNumber *number; for (i = 0; *pointer + i < stop; i++) { if ((*pointer)[i] == '.') hasDecimal = true; if ((*pointer)[i] == ' ' || (*pointer)[i] == '\t' || (*pointer)[i] == '\r' || (*pointer)[i] == '\n' || (*pointer)[i] == ',' || (*pointer)[i] == ']' || (*pointer)[i] == '}') { if ((*pointer)[i] == '\n') (*line)++; break; } } string = [[OFString alloc] initWithUTF8String: *pointer length: i]; *pointer += i; @try { if (hasDecimal) number = [OFNumber numberWithDouble: string.doubleValue]; else if ([string isEqual: @"Infinity"]) number = [OFNumber numberWithDouble: INFINITY]; else if ([string isEqual: @"-Infinity"]) number = [OFNumber numberWithDouble: -INFINITY]; else if (isNegative) number = [OFNumber numberWithLongLong: [string longLongValueWithBase: 0]]; else number = [OFNumber numberWithUnsignedLongLong: [string unsignedLongLongValueWithBase: 0]]; } @finally { [string release]; } return number; } static id nextObject(const char **pointer, const char *stop, size_t *line, size_t depthLimit) { skipWhitespacesAndComments(pointer, stop, line); if (*pointer >= stop) return nil; switch (**pointer) { case '"': case '\'': return parseString(pointer, stop, line); case '[': return parseArray(pointer, stop, line, depthLimit); case '{': return parseDictionary(pointer, stop, line, depthLimit); case 't': if (*pointer + 3 >= stop) return nil; if (memcmp(*pointer, "true", 4) != 0) return nil; (*pointer) += 4; return [OFNumber numberWithBool: true]; case 'f': if (*pointer + 4 >= stop) return nil; if (memcmp(*pointer, "false", 5) != 0) return nil; (*pointer) += 5; return [OFNumber numberWithBool: false]; case 'n': if (*pointer + 3 >= stop) return nil; if (memcmp(*pointer, "null", 4) != 0) return nil; (*pointer) += 4; return [OFNull null]; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '+': case '-': case '.': case 'I': return parseNumber(pointer, stop, line); default: return nil; } } @implementation OFString (JSONParsing) - (id)objectByParsingJSON { return [self objectByParsingJSONWithDepthLimit: 32]; } - (id)objectByParsingJSONWithDepthLimit: (size_t)depthLimit { void *pool = objc_autoreleasePoolPush(); const char *pointer = self.UTF8String; const char *stop = pointer + self.UTF8StringLength; id object; size_t line = 1; object = nextObject(&pointer, stop, &line, depthLimit); skipWhitespacesAndComments(&pointer, stop, &line); if (pointer < stop || object == nil) @throw [OFInvalidJSONException exceptionWithString: self line: line]; [object retain]; objc_autoreleasePoolPop(pool); return [object autorelease]; } @end objfw-1.1.6/src/OFString+PathAdditions.h000066400000000000000000000060101465614216400200160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFString.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif extern int _OFString_PathAdditions_reference OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif @interface OFString (PathAdditions) /** * @brief Whether the path is an absolute path. */ @property (readonly, nonatomic, getter=isAbsolutePath) bool absolutePath; /** * @brief The components of the string when interpreted as a path. */ @property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *pathComponents; /** * @brief The last path component of the string when interpreted as a path. */ @property (readonly, nonatomic) OFString *lastPathComponent; /** * @brief The file extension of string when interpreted as a path. */ @property (readonly, nonatomic) OFString *pathExtension; /** * @brief The directory name of the string when interpreted as a path. */ @property (readonly, nonatomic) OFString *stringByDeletingLastPathComponent; /** * @brief The string with the file extension of the path removed. */ @property (readonly, nonatomic) OFString *stringByDeletingPathExtension; /** * @brief The string interpreted as a path with relative sub paths resolved. */ @property (readonly, nonatomic) OFString *stringByStandardizingPath; /** * @brief Creates a path from the specified path components. * * @param components An array of components for the path * @return A new autoreleased OFString */ + (OFString *)pathWithComponents: (OFArray OF_GENERIC(OFString *) *)components; /** * @brief Creates a new string by appending a path component. * * @param component The path component to append * @return A new, autoreleased OFString with the path component appended */ - (OFString *)stringByAppendingPathComponent: (OFString *)component; /** * @brief Creates a new string by appending a path extension. * * @param extension The extension to append * @return A new, autoreleased OFString with the path extension appended */ - (OFString *)stringByAppendingPathExtension: (OFString *)extension; - (bool)of_isDirectoryPath; - (OFString *)of_pathToIRIPathWithPercentEncodedHost: (OFString *__autoreleasing _Nullable *_Nonnull)percentEncodedHost; - (OFString *)of_IRIPathToPathWithPercentEncodedHost: (nullable OFString *)percentEncodedHost; - (OFString *)of_pathComponentToIRIPathComponent; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFString+PathAdditions.m000066400000000000000000000022631465614216400200310ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" #if defined(OF_WINDOWS) || defined(OF_MSDOS) || defined(OF_MINT) # import "platform/Windows/OFString+PathAdditions.m" #elif defined(OF_AMIGAOS) # import "platform/AmigaOS/OFString+PathAdditions.m" #elif defined(OF_WII) || defined(OF_NINTENDO_DS) || \ defined(OF_NINTENDO_3DS) || defined(OF_NINTENDO_SWITCH) # import "platform/libfat/OFString+PathAdditions.m" #else # import "platform/POSIX/OFString+PathAdditions.m" #endif objfw-1.1.6/src/OFString+PercentEncoding.h000066400000000000000000000030661465614216400203420ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @class OFCharacterSet; #ifdef __cplusplus extern "C" { #endif extern int _OFString_PercentEncoding_reference OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif @interface OFString (PercentEncoding) /** * @brief The string with percent encoding removed. * * @throw OFInvalidFormatException The string is not in proper percent encoding */ @property (readonly, nonatomic) OFString *stringByRemovingPercentEncoding; /** * @brief Percent-encodes a string for use in an IRI, but does not escape the * specified allowed characters. * * @param allowedCharacters A character set of characters that should not be * escaped * * @return A new autoreleased string */ - (OFString *)stringByAddingPercentEncodingWithAllowedCharacters: (OFCharacterSet *)allowedCharacters; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFString+PercentEncoding.m000066400000000000000000000072571465614216400203550ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "OFString+PercentEncoding.h" #import "OFCharacterSet.h" #import "OFInvalidFormatException.h" #import "OFInvalidEncodingException.h" #import "OFOutOfMemoryException.h" /* Reference for static linking */ int _OFString_PercentEncoding_reference; @implementation OFString (PercentEncoding) - (OFString *)stringByAddingPercentEncodingWithAllowedCharacters: (OFCharacterSet *)allowedCharacters { OFMutableString *ret = [OFMutableString string]; void *pool = objc_autoreleasePoolPush(); const OFUnichar *characters = self.characters; size_t length = self.length; bool (*characterIsMember)(id, SEL, OFUnichar) = (bool (*)(id, SEL, OFUnichar))[allowedCharacters methodForSelector: @selector(characterIsMember:)]; for (size_t i = 0; i < length; i++) { OFUnichar c = characters[i]; if (characterIsMember(allowedCharacters, @selector(characterIsMember:), c)) [ret appendCharacters: &c length: 1]; else { char buffer[4]; size_t bufferLen; if ((bufferLen = _OFUTF8StringEncode(c, buffer)) == 0) @throw [OFInvalidEncodingException exception]; for (size_t j = 0; j < bufferLen; j++) { unsigned char byte = buffer[j]; unsigned char high = byte >> 4; unsigned char low = byte & 0x0F; char escaped[3]; escaped[0] = '%'; escaped[1] = (high > 9 ? high - 10 + 'A' : high + '0'); escaped[2] = (low > 9 ? low - 10 + 'A' : low + '0'); [ret appendUTF8String: escaped length: 3]; } } } objc_autoreleasePoolPop(pool); return ret; } - (OFString *)stringByRemovingPercentEncoding { void *pool = objc_autoreleasePoolPush(); const char *string = self.UTF8String; size_t length = self.UTF8StringLength; char *retCString; char byte = 0; int state = 0; size_t i = 0; OFString *ret; retCString = OFAllocMemory(length + 1, 1); while (length--) { char c = *string++; switch (state) { case 0: if (c == '%') state = 1; else retCString[i++] = c; break; case 1: case 2:; uint8_t shift = (state == 1 ? 4 : 0); if (c >= '0' && c <= '9') byte += (c - '0') << shift; else if (c >= 'A' && c <= 'F') byte += (c - 'A' + 10) << shift; else if (c >= 'a' && c <= 'f') byte += (c - 'a' + 10) << shift; else { OFFreeMemory(retCString); @throw [OFInvalidFormatException exception]; } if (++state == 3) { retCString[i++] = byte; state = 0; byte = 0; } break; } } retCString[i] = '\0'; objc_autoreleasePoolPop(pool); if (state != 0) { OFFreeMemory(retCString); @throw [OFInvalidFormatException exception]; } @try { retCString = OFResizeMemory(retCString, 1, i + 1); } @catch (OFOutOfMemoryException *e) { /* We don't care if it fails, as we only made it smaller. */ } @try { ret = [OFString stringWithUTF8StringNoCopy: retCString length: i freeWhenDone: true]; } @catch (id e) { OFFreeMemory(retCString); @throw e; } return ret; } @end objfw-1.1.6/src/OFString+PropertyListParsing.h000066400000000000000000000025651465614216400213020ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFString.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif extern int _OFString_PropertyListParsing_reference OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif @interface OFString (PropertyListParsing) /** * @brief The string interpreted as a property list and parsed as an object. * * @note This only supports XML property lists! * * @throw OFInvalidFormatException The string is not in correct XML property * list format * @throw OFUnsupportedVersionException The property list is using a version * that is not supported */ @property (readonly, nonatomic) id objectByParsingPropertyList; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFString+PropertyListParsing.m000066400000000000000000000126521465614216400213050ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFString+PropertyListParsing.h" #import "OFArray.h" #import "OFData.h" #import "OFDate.h" #import "OFDictionary.h" #import "OFNumber.h" #import "OFXMLAttribute.h" #import "OFXMLElement.h" #import "OFInvalidFormatException.h" #import "OFUnsupportedVersionException.h" int _OFString_PropertyListParsing_reference; static id parseElement(OFXMLElement *element); static OFArray * parseArrayElement(OFXMLElement *element) { OFMutableArray *ret = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); for (OFXMLElement *child in element.elements) [ret addObject: parseElement(child)]; [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } static OFDictionary * parseDictElement(OFXMLElement *element) { OFMutableDictionary *ret = [OFMutableDictionary dictionary]; void *pool = objc_autoreleasePoolPush(); OFArray OF_GENERIC(OFXMLElement *) *children = element.elements; OFEnumerator OF_GENERIC(OFXMLElement *) *enumerator; OFXMLElement *key, *object; if (children.count % 2 != 0) @throw [OFInvalidFormatException exception]; enumerator = [children objectEnumerator]; while ((key = [enumerator nextObject]) && (object = [enumerator nextObject])) { if (key.namespace != nil || key.attributes.count != 0 || ![key.name isEqual: @"key"]) @throw [OFInvalidFormatException exception]; [ret setObject: parseElement(object) forKey: key.stringValue]; } [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } static OFString * parseStringElement(OFXMLElement *element) { return element.stringValue; } static OFData * parseDataElement(OFXMLElement *element) { return [OFData dataWithBase64EncodedString: element.stringValue]; } static OFDate * parseDateElement(OFXMLElement *element) { return [OFDate dateWithDateString: element.stringValue format: @"%Y-%m-%dT%H:%M:%SZ"]; } static OFNumber * parseTrueElement(OFXMLElement *element) { if (element.children.count != 0) @throw [OFInvalidFormatException exception]; return [OFNumber numberWithBool: true]; } static OFNumber * parseFalseElement(OFXMLElement *element) { if (element.children.count != 0) @throw [OFInvalidFormatException exception]; return [OFNumber numberWithBool: false]; } static OFNumber * parseRealElement(OFXMLElement *element) { return [OFNumber numberWithDouble: element.doubleValue]; } static OFNumber * parseIntegerElement(OFXMLElement *element) { void *pool = objc_autoreleasePoolPush(); OFString *stringValue; OFNumber *ret; stringValue = element.stringValue.stringByDeletingEnclosingWhitespaces; if ([stringValue hasPrefix: @"-"]) ret = [OFNumber numberWithLongLong: stringValue.longLongValue]; else ret = [OFNumber numberWithUnsignedLongLong: stringValue.unsignedLongLongValue]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } static id parseElement(OFXMLElement *element) { OFString *elementName; if (element.namespace != nil || element.attributes.count != 0) @throw [OFInvalidFormatException exception]; elementName = element.name; if ([elementName isEqual: @"array"]) return parseArrayElement(element); else if ([elementName isEqual: @"dict"]) return parseDictElement(element); else if ([elementName isEqual: @"string"]) return parseStringElement(element); else if ([elementName isEqual: @"data"]) return parseDataElement(element); else if ([elementName isEqual: @"date"]) return parseDateElement(element); else if ([elementName isEqual: @"true"]) return parseTrueElement(element); else if ([elementName isEqual: @"false"]) return parseFalseElement(element); else if ([elementName isEqual: @"real"]) return parseRealElement(element); else if ([elementName isEqual: @"integer"]) return parseIntegerElement(element); else @throw [OFInvalidFormatException exception]; } @implementation OFString (PropertyListParsing) - (id)objectByParsingPropertyList { void *pool = objc_autoreleasePoolPush(); OFXMLElement *rootElement = [OFXMLElement elementWithXMLString: self]; OFXMLAttribute *versionAttribute; OFArray OF_GENERIC(OFXMLElement *) *elements; id ret; if (![rootElement.name isEqual: @"plist"] || rootElement.namespace != nil) @throw [OFInvalidFormatException exception]; versionAttribute = [rootElement attributeForName: @"version"]; if (versionAttribute == nil) @throw [OFInvalidFormatException exception]; if (![versionAttribute.stringValue isEqual: @"1.0"]) @throw [OFUnsupportedVersionException exceptionWithVersion: [versionAttribute stringValue]]; elements = rootElement.elements; if (elements.count != 1) @throw [OFInvalidFormatException exception]; ret = parseElement(elements.firstObject); [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @end objfw-1.1.6/src/OFString+XMLEscaping.h000066400000000000000000000021301465614216400173740ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFString.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif extern int _OFString_XMLEscaping_reference OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif @interface OFString (XMLEscaping) /** * @brief The string in a form escaped for use in an XML document. */ @property (readonly, nonatomic) OFString *stringByXMLEscaping; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFString+XMLEscaping.m000066400000000000000000000043461465614216400174140ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "OFString.h" #import "OFOutOfMemoryException.h" int _OFString_XMLEscaping_reference; @implementation OFString (XMLEscaping) - (OFString *)stringByXMLEscaping { void *pool = objc_autoreleasePoolPush(); char *retCString; const char *string, *append; size_t length, retLength, appendLen; size_t j; OFString *ret; string = self.UTF8String; length = self.UTF8StringLength; j = 0; retLength = length; retCString = OFAllocMemory(retLength, 1); for (size_t i = 0; i < length; i++) { switch (string[i]) { case '<': append = "<"; appendLen = 4; break; case '>': append = ">"; appendLen = 4; break; case '"': append = """; appendLen = 6; break; case '\'': append = "'"; appendLen = 6; break; case '&': append = "&"; appendLen = 5; break; case '\r': append = " "; appendLen = 5; break; default: append = NULL; appendLen = 0; } if (append != NULL) { @try { retCString = OFResizeMemory(retCString, 1, retLength + appendLen); } @catch (id e) { OFFreeMemory(retCString); @throw e; } retLength += appendLen - 1; memcpy(retCString + j, append, appendLen); j += appendLen; } else retCString[j++] = string[i]; } OFAssert(j == retLength); objc_autoreleasePoolPop(pool); @try { ret = [OFString stringWithUTF8String: retCString length: retLength]; } @finally { OFFreeMemory(retCString); } return ret; } @end objfw-1.1.6/src/OFString+XMLUnescaping.h000066400000000000000000000061571465614216400177540ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFString.h" OF_ASSUME_NONNULL_BEGIN /** @file */ #ifdef __cplusplus extern "C" { #endif extern int _OFString_XMLUnescaping_reference OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif #ifdef OF_HAVE_BLOCKS /** * @brief A block which is called to replace unknown XML entities in an XML * string. * * @param string The XML string which contains an unknown entity * @param entity The XML entity which is unknown * @return A replacement string for the unknown entity */ typedef OFString *_Nullable (^OFStringXMLUnescapingBlock)(OFString *string, OFString *entity); #endif /** * @protocol OFStringXMLUnescapingDelegate OFString.h ObjFW/OFString.h * * @brief A protocol that needs to be implemented by delegates for * stringByXMLUnescapingWithHandler:. */ @protocol OFStringXMLUnescapingDelegate /** * @brief This callback is called when an unknown entity was found while trying * to unescape XML. * * The callback is supposed to return a substitution for the entity or `nil` if * it is unknown to the callback as well, in which case an exception will be * thrown. * * @param string The string which contains the unknown entity * @param entity The name of the entity that is unknown * @return A substitution for the entity or `nil` */ - (nullable OFString *)string: (OFString *)string containsUnknownEntityNamed: (OFString *)entity; @end @interface OFString (XMLUnescaping) /** * @brief The string with XML entities unescapted. */ @property (readonly, nonatomic) OFString *stringByXMLUnescaping; /** * @brief Unescapes XML in the string and uses the specified delegate for * unknown entities. * * @param delegate An OFXMLUnescapingDelegate as a handler for unknown entities * @throw OFInvalidFormatException The string is not a valid XML string * @throw OFUnknownXMLEntityException The string contains unknown XML entities */ - (OFString *)stringByXMLUnescapingWithDelegate: (nullable id )delegate; #ifdef OF_HAVE_BLOCKS /** * @brief Unescapes XML in the string and uses the specified block for unknown * entities. * * @param block A block which handles unknown entities * @throw OFInvalidFormatException The string is not a valid XML string * @throw OFUnknownXMLEntityException The string contains unknown XML entities */ - (OFString *)stringByXMLUnescapingWithBlock: (OFStringXMLUnescapingBlock)block; #endif @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFString+XMLUnescaping.m000066400000000000000000000120721465614216400177520ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFString.h" #import "OFInvalidFormatException.h" #import "OFUnknownXMLEntityException.h" int _OFString_XMLUnescaping_reference; static OF_INLINE OFString * parseNumericEntity(const char *entity, size_t length) { OFUnichar c; size_t i; char buffer[5]; if (length == 1 || *entity != '#') return nil; c = 0; entity++; length--; if (entity[0] == 'x') { if (length == 1) return nil; entity++; length--; for (i = 0; i < length; i++) { if (entity[i] >= '0' && entity[i] <= '9') c = (c << 4) | (entity[i] - '0'); else if (entity[i] >= 'A' && entity[i] <= 'F') c = (c << 4) | (entity[i] - 'A' + 10); else if (entity[i] >= 'a' && entity[i] <= 'f') c = (c << 4) | (entity[i] - 'a' + 10); else return nil; } } else { for (i = 0; i < length; i++) { if (entity[i] >= '0' && entity[i] <= '9') c = (c * 10) + (entity[i] - '0'); else return nil; } } if ((i = _OFUTF8StringEncode(c, buffer)) == 0) return nil; buffer[i] = 0; return [OFString stringWithUTF8String: buffer length: i]; } static OFString * parseEntities(OFString *self, id (*lookup)(void *, OFString *, OFString *), void *context) { OFMutableString *ret; void *pool; const char *string; size_t i, last, length; bool inEntity; ret = [OFMutableString string]; pool = objc_autoreleasePoolPush(); string = self.UTF8String; length = self.UTF8StringLength; last = 0; inEntity = false; for (i = 0; i < length; i++) { if (!inEntity && string[i] == '&') { [ret appendUTF8String: string + last length: i - last]; last = i + 1; inEntity = true; } else if (inEntity && string[i] == ';') { const char *entity = string + last; size_t entityLength = i - last; if (entityLength == 2 && memcmp(entity, "lt", 2) == 0) [ret appendCString: "<" encoding: OFStringEncodingASCII length: 1]; else if (entityLength == 2 && memcmp(entity, "gt", 2) == 0) [ret appendCString: ">" encoding: OFStringEncodingASCII length: 1]; else if (entityLength == 4 && memcmp(entity, "quot", 4) == 0) [ret appendCString: "\"" encoding: OFStringEncodingASCII length: 1]; else if (entityLength == 4 && memcmp(entity, "apos", 4) == 0) [ret appendCString: "'" encoding: OFStringEncodingASCII length: 1]; else if (entityLength == 3 && memcmp(entity, "amp", 3) == 0) [ret appendCString: "&" encoding: OFStringEncodingASCII length: 1]; else if (entity[0] == '#') { void *pool2; OFString *tmp; pool2 = objc_autoreleasePoolPush(); tmp = parseNumericEntity(entity, entityLength); if (tmp == nil) @throw [OFInvalidFormatException exception]; [ret appendString: tmp]; objc_autoreleasePoolPop(pool2); } else { void *pool2; OFString *name, *tmp; pool2 = objc_autoreleasePoolPush(); name = [OFString stringWithUTF8String: entity length: entityLength]; tmp = lookup(context, self, name); if (tmp == nil) @throw [OFUnknownXMLEntityException exceptionWithEntityName: name]; [ret appendString: tmp]; objc_autoreleasePoolPop(pool2); } last = i + 1; inEntity = false; } } if (inEntity) @throw [OFInvalidFormatException exception]; [ret appendUTF8String: string + last length: i - last]; [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } static id lookupUsingDelegate(void *context, OFString *self, OFString *entity) { id delegate = context; if (delegate == nil) return nil; return [delegate string: self containsUnknownEntityNamed: entity]; } #ifdef OF_HAVE_BLOCKS static id lookupUsingBlock(void *context, OFString *self, OFString *entity) { OFStringXMLUnescapingBlock block = context; if (block == NULL) return nil; return block(self, entity); } #endif @implementation OFString (XMLUnescaping) - (OFString *)stringByXMLUnescaping { return [self stringByXMLUnescapingWithDelegate: nil]; } - (OFString *)stringByXMLUnescapingWithDelegate: (id )delegate { return parseEntities(self, lookupUsingDelegate, delegate); } #ifdef OF_HAVE_BLOCKS - (OFString *)stringByXMLUnescapingWithBlock: (OFStringXMLUnescapingBlock)block { return parseEntities(self, lookupUsingBlock, block); } #endif @end objfw-1.1.6/src/OFString.h000066400000000000000000001340121465614216400152730ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif #include "objfw-defs.h" #ifdef OF_HAVE_SYS_TYPES_H # include #endif #include #include #ifdef OF_HAVE_INTTYPES_H # include #endif #import "OFObject.h" #import "OFJSONRepresentation.h" #import "OFMessagePackRepresentation.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFArray OF_GENERIC(ObjectType); @class OFCharacterSet; @class OFConstantString; @class OFIRI; @class OFString; #if defined(__cplusplus) && __cplusplus >= 201103L typedef char16_t OFChar16; typedef char32_t OFChar32; #else typedef uint_least16_t OFChar16; typedef uint_least32_t OFChar32; #endif typedef OFChar32 OFUnichar; /** * @brief The encoding of a string. */ typedef enum { /* * UTF-8 *has* to be 0, so that if the current @ref OFLocale is * `nil`, `[OFLocale encoding]` returns UTF-8. */ /** UTF-8 */ OFStringEncodingUTF8, /** ASCII */ OFStringEncodingASCII, /** ISO 8859-1 */ OFStringEncodingISO8859_1, /** ISO 8859-2 */ OFStringEncodingISO8859_2, /** ISO 8859-3 */ OFStringEncodingISO8859_3, /** ISO 8859-15 */ OFStringEncodingISO8859_15, /** Windows-1251 */ OFStringEncodingWindows1251, /** Windows-1252 */ OFStringEncodingWindows1252, /** Code page 437 */ OFStringEncodingCodepage437, /** Code page 850 */ OFStringEncodingCodepage850, /** Code page 858 */ OFStringEncodingCodepage858, /** Mac OS Roman */ OFStringEncodingMacRoman, /** KOI8-R */ OFStringEncodingKOI8R, /** KOI8-U */ OFStringEncodingKOI8U, /** Try to automatically detect the encoding */ OFStringEncodingAutodetect = -1 } OFStringEncoding; /** * @brief Options for searching in strings. * * This is a bit mask. */ typedef enum { /** Search backwards in the string */ OFStringSearchBackwards = 1 } OFStringSearchOptions; /** * @brief Options for separating strings. * * This is a bit mask. */ typedef enum { /** Skip empty components */ OFStringSkipEmptyComponents = 1 } OFStringSeparationOptions; #ifdef OF_HAVE_BLOCKS /** * @brief A block for enumerating the lines of a string. * * @param line The current line * @param stop A pointer to a variable that can be set to true to stop the * enumeration */ typedef void (^OFStringLineEnumerationBlock)(OFString *line, bool *stop); #endif /** * @class OFString OFString.h ObjFW/OFString.h * * @brief A class for handling strings. */ @interface OFString: OFObject /** * @brief The length of the string in Unicode code points. */ @property (readonly, nonatomic) size_t length; /** * @brief The OFString as a UTF-8 encoded C string. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. */ @property (readonly, nonatomic) const char *UTF8String; /** * @brief The number of bytes the string needs in UTF-8 encoding. */ @property (readonly, nonatomic) size_t UTF8StringLength; /** * @brief The string in uppercase. */ @property (readonly, nonatomic) OFString *uppercaseString; /** * @brief The string in lowercase. */ @property (readonly, nonatomic) OFString *lowercaseString; /** * @brief The string in capitalized form. * * @note This only considers spaces, tabs and newlines to be word delimiters! * Also note that this might change in the future to all word delimiters * specified by Unicode! */ @property (readonly, nonatomic) OFString *capitalizedString; /** * @brief The decimal value of the string as a `long long`. * * Leading and trailing whitespaces are ignored. * * If the string contains any non-number characters, an * @ref OFInvalidFormatException is thrown. * * If the number is too big to fit into a `long long`, an * @ref OFOutOfRangeException is thrown. */ @property (readonly, nonatomic) long long longLongValue; /** * @brief The decimal value of the string as an `unsigned long long`. * * Leading and trailing whitespaces are ignored. * * If the string contains any non-number characters, an * @ref OFInvalidFormatException is thrown. * * If the number is too big to fit into an `unsigned long long`, an * @ref OFOutOfRangeException is thrown. */ @property (readonly, nonatomic) unsigned long long unsignedLongLongValue; /** * @brief The float value of the string as a float. * * @throw OFInvalidFormatException The string cannot be parsed as a `float` * @throw OFOutOfRangeException The value cannot be represented as a `float` */ @property (readonly, nonatomic) float floatValue; /** * @brief The double value of the string as a double. * * @throw OFInvalidFormatException The string cannot be parsed as a `double` * @throw OFOutOfRangeException The value cannot be represented as a `double` */ @property (readonly, nonatomic) double doubleValue; /** * @brief The string as an array of Unicode characters. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. * * The returned string is *not* null-terminated. */ @property (readonly, nonatomic) const OFUnichar *characters; /** * @brief The string in UTF-16 encoding with native byte order. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. * * The returned string is null-terminated. */ @property (readonly, nonatomic) const OFChar16 *UTF16String; /** * @brief The length of the string in UTF-16 characters. */ @property (readonly, nonatomic) size_t UTF16StringLength; /** * @brief The string in UTF-32 encoding with native byte order. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. * * The returned string is null-terminated. */ @property (readonly, nonatomic) const OFChar32 *UTF32String; /** * @brief The string with leading whitespaces deleted. */ @property (readonly, nonatomic) OFString *stringByDeletingLeadingWhitespaces; /** * @brief The string with trailing whitespaces deleted. */ @property (readonly, nonatomic) OFString *stringByDeletingTrailingWhitespaces; /** * @brief The string with leading and trailing whitespaces deleted. */ @property (readonly, nonatomic) OFString *stringByDeletingEnclosingWhitespaces; #if defined(OF_WINDOWS) || defined(DOXYGEN) /** * @brief The string with the Windows Environment Strings expanded. */ @property (readonly, nonatomic) OFString *stringByExpandingWindowsEnvironmentStrings; #endif /** * @brief Creates a new OFString. * * @return A new, autoreleased OFString */ + (instancetype)string; /** * @brief Creates a new OFString from a UTF-8 encoded C string. * * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @return A new autoreleased OFString * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ + (instancetype)stringWithUTF8String: (const char *)UTF8String; /** * @brief Creates a new OFString from a UTF-8 encoded C string with the * specified length. * * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @param UTF8StringLength The length of the UTF-8 encoded C string * @return A new autoreleased OFString * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ + (instancetype)stringWithUTF8String: (const char *)UTF8String length: (size_t)UTF8StringLength; /** * @brief Creates a new OFString from a UTF-8 encoded C string without copying * the string, if possible. * * If initialization fails for whatever reason, the passed C string is *not* * freed if `freeWhenDone` is true. * * @note OFMutableString always creates a copy! * * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @param freeWhenDone Whether to free the C string when the OFString gets * deallocated * @return A new autoreleased OFString * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ + (instancetype)stringWithUTF8StringNoCopy: (char *)UTF8String freeWhenDone: (bool)freeWhenDone; /** * @brief Creates a new OFString from a UTF-8 encoded C string with the * specified length without copying the string, if possible. * * If initialization fails for whatever reason, the passed C string is *not* * freed if `freeWhenDone` is true. * * @note OFMutableString always creates a copy! * * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @param UTF8StringLength The length of the UTF-8 encoded C string * @param freeWhenDone Whether to free the C string when the OFString gets * deallocated * @return A new autoreleased OFString * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ + (instancetype)stringWithUTF8StringNoCopy: (char *)UTF8String length: (size_t)UTF8StringLength freeWhenDone: (bool)freeWhenDone; /** * @brief Creates a new OFString from a C string with the specified encoding. * * @param cString A C string to initialize the OFString with * @param encoding The encoding of the C string * @return A new autoreleased OFString * @throw OFInvalidEncodingException The string is not in the specified encoding */ + (instancetype)stringWithCString: (const char *)cString encoding: (OFStringEncoding)encoding; /** * @brief Creates a new OFString from a C string with the specified encoding * and length. * * @param cString A C string to initialize the OFString with * @param encoding The encoding of the C string * @param cStringLength The length of the C string * @return A new autoreleased OFString * @throw OFInvalidEncodingException The string is not in the specified encoding */ + (instancetype)stringWithCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength; /** * @brief Creates a new OFString from OFData with the specified encoding. * * @param data OFData with the contents of the string * @param encoding The encoding in which the string is stored in the OFData * @return An new autoreleased OFString * @throw OFInvalidEncodingException The string is not in the specified encoding */ + (instancetype)stringWithData: (OFData *)data encoding: (OFStringEncoding)encoding; /** * @brief Creates a new OFString from another string. * * @param string A string to initialize the OFString with * @return A new autoreleased OFString */ + (instancetype)stringWithString: (OFString *)string; /** * @brief Creates a new OFString from a Unicode string with the specified * length. * * @param characters An array of Unicode characters * @param length The length of the Unicode character array * @return A new autoreleased OFString */ + (instancetype)stringWithCharacters: (const OFUnichar *)characters length: (size_t)length; /** * @brief Creates a new OFString from a UTF-16 encoded string. * * @param string A zero-terminated UTF-16 string * @return A new autoreleased OFString * @throw OFInvalidEncodingException The string is not properly UTF-16-encoded */ + (instancetype)stringWithUTF16String: (const OFChar16 *)string; /** * @brief Creates a new OFString from a UTF-16 encoded string with the * specified length. * * @param string A zero-terminated UTF-16 string * @param length The length of the UTF-16 string * @return A new autoreleased OFString * @throw OFInvalidEncodingException The string is not properly UTF-16-encoded */ + (instancetype)stringWithUTF16String: (const OFChar16 *)string length: (size_t)length; /** * @brief Creates a new OFString from a UTF-16 encoded string, assuming the * specified byte order if no byte order mark is found. * * @param string A zero-terminated UTF-16 string * @param byteOrder The byte order to assume if there is no byte order mark * @return A new autoreleased OFString * @throw OFInvalidEncodingException The string is not properly UTF-16-encoded */ + (instancetype)stringWithUTF16String: (const OFChar16 *)string byteOrder: (OFByteOrder)byteOrder; /** * @brief Creates a new OFString from a UTF-16 encoded string with the * specified length, assuming the specified byte order if no byte order * mark is found. * * @param string A zero-terminated UTF-16 string * @param length The length of the UTF-16 string * @param byteOrder The byte order to assume if there is no byte order mark * @return A new autoreleased OFString * @throw OFInvalidEncodingException The string is not properly UTF-16-encoded */ + (instancetype)stringWithUTF16String: (const OFChar16 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder; /** * @brief Creates a new OFString from a UTF-32 encoded string. * * @param string A zero-terminated UTF-32 string * @return A new autoreleased OFString */ + (instancetype)stringWithUTF32String: (const OFChar32 *)string; /** * @brief Creates a new OFString from a UTF-32 encoded string with the * specified length. * * @param string A zero-terminated UTF-32 string * @param length The length of the UTF-32 string * @return A new autoreleased OFString */ + (instancetype)stringWithUTF32String: (const OFChar32 *)string length: (size_t)length; /** * @brief Creates a new OFString from a UTF-32 encoded string, assuming the * specified byte order if no byte order mark is found. * * @param string A zero-terminated UTF-32 string * @param byteOrder The byte order to assume if there is no byte order mark * @return A new autoreleased OFString */ + (instancetype)stringWithUTF32String: (const OFChar32 *)string byteOrder: (OFByteOrder)byteOrder; /** * @brief Creates a new OFString from a UTF-32 encoded string with the * specified length, assuming the specified byte order if no byte order * mark is found. * * @param string A zero-terminated UTF-32 string * @param length The length of the UTF-32 string * @param byteOrder The byte order to assume if there is no byte order mark * @return A new autoreleased OFString */ + (instancetype)stringWithUTF32String: (const OFChar32 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder; /** * @brief Creates a new OFString from a format string. * * See printf for the format syntax. As an addition, `%@` is available as * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * @param format A string used as format to initialize the OFString * @return A new autoreleased OFString * @throw OFInvalidFormatException The specified format is invalid * @throw OFInvalidEncodingException The resulting string is not in not in UTF-8 * encoding */ + (instancetype)stringWithFormat: (OFConstantString *)format, ...; #ifdef OF_HAVE_FILES /** * @brief Creates a new OFString with the contents of the specified UTF-8 * encoded file. * * @param path The path to the file * @return A new autoreleased OFString * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ + (instancetype)stringWithContentsOfFile: (OFString *)path; /** * @brief Creates a new OFString with the contents of the specified file in the * specified encoding. * * @param path The path to the file * @param encoding The encoding of the file * @return A new autoreleased OFString * @throw OFInvalidEncodingException The string is not in the specified encoding */ + (instancetype)stringWithContentsOfFile: (OFString *)path encoding: (OFStringEncoding)encoding; #endif /** * @brief Creates a new OFString with the contents of the specified IRI. * * If the IRI's scheme is file, it tries UTF-8 encoding. * * If the IRI's scheme is `http` or `https`, it tries to detect the encoding * from the HTTP headers. If it could not detect the encoding using the HTTP * headers, it tries UTF-8. * * @param IRI The IRI to the contents for the string * @return A new autoreleased OFString * @throw OFInvalidEncodingException The string is not in the expected encoding */ + (instancetype)stringWithContentsOfIRI: (OFIRI *)IRI; /** * @brief Creates a new OFString with the contents of the specified IRI in the * specified encoding. * * @param IRI The IRI to the contents for the string * @param encoding The encoding to assume * @return A new autoreleased OFString * @throw OFInvalidEncodingException The string is not in the specified encoding */ + (instancetype)stringWithContentsOfIRI: (OFIRI *)IRI encoding: (OFStringEncoding)encoding; /** * @brief Initializes an already allocated OFString to be empty. * * @return An initialized OFString */ - (instancetype)init OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated OFString from a UTF-8 encoded C * string. * * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @return An initialized OFString * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ - (instancetype)initWithUTF8String: (const char *)UTF8String; /** * @brief Initializes an already allocated OFString from a UTF-8 encoded C * string with the specified length. * * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @param UTF8StringLength The length of the UTF-8 encoded C string * @return An initialized OFString * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ - (instancetype)initWithUTF8String: (const char *)UTF8String length: (size_t)UTF8StringLength; /** * @brief Initializes an already allocated OFString from an UTF-8 encoded C * string without copying the string, if possible. * * If initialization fails for whatever reason, the passed C string is *not* * freed if `freeWhenDone` is true. * * @note OFMutableString always creates a copy! * * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @param freeWhenDone Whether to free the C string when it is not needed * anymore * @return An initialized OFString * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ - (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String freeWhenDone: (bool)freeWhenDone; /** * @brief Initializes an already allocated OFString from an UTF-8 encoded C * string with the specified length without copying the string, if * possible. * * If initialization fails for whatever reason, the passed C string is *not* * freed if `freeWhenDone` is true. * * @note OFMutableString always creates a copy! * * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @param UTF8StringLength The length of the UTF-8 encoded C string * @param freeWhenDone Whether to free the C string when it is not needed * anymore * @return An initialized OFString * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ - (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String length: (size_t)UTF8StringLength freeWhenDone: (bool)freeWhenDone; /** * @brief Initializes an already allocated OFString from a C string with the * specified encoding. * * @param cString A C string to initialize the OFString with * @param encoding The encoding of the C string * @return An initialized OFString * @throw OFInvalidEncodingException The string is not in the specified encoding */ - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding; /** * @brief Initializes an already allocated OFString from a C string with the * specified encoding and length. * * @param cString A C string to initialize the OFString with * @param encoding The encoding of the C string * @param cStringLength The length of the C string * @return An initialized OFString * @throw OFInvalidEncodingException The string is not in the specified encoding */ - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength; /** * @brief Initializes an already allocated OFString from OFData with the * specified encoding. * * @param data OFData with the contents of the string * @param encoding The encoding in which the string is stored in the OFData * @return An initialized OFString * @throw OFInvalidEncodingException The string is not in the specified encoding */ - (instancetype)initWithData: (OFData *)data encoding: (OFStringEncoding)encoding; /** * @brief Initializes an already allocated OFString with another string. * * @param string A string to initialize the OFString with * @return An initialized OFString */ - (instancetype)initWithString: (OFString *)string; /** * @brief Initializes an already allocated OFString with a Unicode string with * the specified length. * * @param characters An array of Unicode characters * @param length The length of the Unicode character array * @return An initialized OFString */ - (instancetype)initWithCharacters: (const OFUnichar *)characters length: (size_t)length; /** * @brief Initializes an already allocated OFString with a UTF-16 string. * * @param string A zero-terminated UTF-16 string * @return An initialized OFString * @throw OFInvalidEncodingException The string is not properly UTF-16-encoded */ - (instancetype)initWithUTF16String: (const OFChar16 *)string; /** * @brief Initializes an already allocated OFString with a UTF-16 string with * the specified length. * * @param string A zero-terminated UTF-16 string * @param length The length of the UTF-16 string * @return An initialized OFString * @throw OFInvalidEncodingException The string is not properly UTF-16-encoded */ - (instancetype)initWithUTF16String: (const OFChar16 *)string length: (size_t)length; /** * @brief Initializes an already allocated OFString with a UTF-16 string, * assuming the specified byte order if no byte order mark is found. * * @param string A zero-terminated UTF-16 string * @param byteOrder The byte order to assume if there is no byte order mark * @return An initialized OFString * @throw OFInvalidEncodingException The string is not properly UTF-16-encoded */ - (instancetype)initWithUTF16String: (const OFChar16 *)string byteOrder: (OFByteOrder)byteOrder; /** * @brief Initializes an already allocated OFString with a UTF-16 string with * the specified length, assuming the specified byte order if no byte * order mark is found. * * @param string A zero-terminated UTF-16 string * @param length The length of the UTF-16 string * @param byteOrder The byte order to assume if there is no byte order mark * @return An initialized OFString * @throw OFInvalidEncodingException The string is not properly UTF-16-encoded */ - (instancetype)initWithUTF16String: (const OFChar16 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder; /** * @brief Initializes an already allocated OFString with a UTF-32 string. * * @param string A zero-terminated UTF-32 string * @return An initialized OFString */ - (instancetype)initWithUTF32String: (const OFChar32 *)string; /** * @brief Initializes an already allocated OFString with a UTF-32 string with * the specified length * * @param string A zero-terminated UTF-32 string * @param length The length of the UTF-32 string * @return An initialized OFString */ - (instancetype)initWithUTF32String: (const OFChar32 *)string length: (size_t)length; /** * @brief Initializes an already allocated OFString with a UTF-32 string, * assuming the specified byte order if no byte order mark is found. * * @param string A zero-terminated UTF-32 string * @param byteOrder The byte order to assume if there is no byte order mark * @return An initialized OFString */ - (instancetype)initWithUTF32String: (const OFChar32 *)string byteOrder: (OFByteOrder)byteOrder; /** * @brief Initializes an already allocated OFString with a UTF-32 string with * the specified length, assuming the specified byte order if no byte * order mark is found. * * @param string A zero-terminated UTF-32 string * @param length The length of the UTF-32 string * @param byteOrder The byte order to assume if there is no byte order mark * @return An initialized OFString */ - (instancetype)initWithUTF32String: (const OFChar32 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder; /** * @brief Initializes an already allocated OFString with a format string. * * See printf for the format syntax. As an addition, `%@` is available as * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * @param format A string used as format to initialize the OFString * @return An initialized OFString * @throw OFInvalidFormatException The specified format is invalid * @throw OFInvalidEncodingException The resulting string is not in not in UTF-8 * encoding */ - (instancetype)initWithFormat: (OFConstantString *)format, ...; /** * @brief Initializes an already allocated OFString with a format string. * * See printf for the format syntax. As an addition, `%@` is available as * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * @param format A string used as format to initialize the OFString * @param arguments The arguments used in the format string * @return An initialized OFString * @throw OFInvalidFormatException The specified format is invalid * @throw OFInvalidEncodingException The resulting string is not in not in UTF-8 * encoding */ - (instancetype)initWithFormat: (OFConstantString *)format arguments: (va_list)arguments; #ifdef OF_HAVE_FILES /** * @brief Initializes an already allocated OFString with the contents of the * specified file in the specified encoding. * * @param path The path to the file * @return An initialized OFString * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ - (instancetype)initWithContentsOfFile: (OFString *)path; /** * @brief Initializes an already allocated OFString with the contents of the * specified file in the specified encoding. * * @param path The path to the file * @param encoding The encoding of the file * @return An initialized OFString * @throw OFInvalidEncodingException The string is not in the specified encoding */ - (instancetype)initWithContentsOfFile: (OFString *)path encoding: (OFStringEncoding)encoding; #endif /** * @brief Initializes an already allocated OFString with the contents of the * specified IRI. * * If the IRI's scheme is file, it tries UTF-8 encoding. * * If the IRI's scheme is `http` or `https`, it tries to detect the encoding * from the HTTP headers. If it could not detect the encoding using the HTTP * headers, it tries UTF-8. * * @param IRI The IRI to the contents for the string * @return An initialized OFString * @throw OFInvalidEncodingException The string is not in the expected encoding */ - (instancetype)initWithContentsOfIRI: (OFIRI *)IRI; /** * @brief Initializes an already allocated OFString with the contents of the * specified IRI in the specified encoding. * * @param IRI The IRI to the contents for the string * @param encoding The encoding to assume * @return An initialized OFString * @throw OFInvalidEncodingException The string is not in the specified encoding */ - (instancetype)initWithContentsOfIRI: (OFIRI *)IRI encoding: (OFStringEncoding)encoding; /** * @brief Writes the OFString into the specified C string with the specified * encoding. * * @param cString The C string to write into * @param maxLength The maximum number of bytes to write into the C string, * including the terminating zero * @param encoding The encoding to use for writing into the C string * @return The number of bytes written into the C string, without the * terminating zero * @throw OFInvalidEncodingException The string cannot be represented in the * specified encoding */ - (size_t)getCString: (char *)cString maxLength: (size_t)maxLength encoding: (OFStringEncoding)encoding; /** * @brief Writes the OFString into the specified C string with the specified * encoding, replacing characters that cannot be represented in the * specified encoding with a question mark. * * @param cString The C string to write into * @param maxLength The maximum number of bytes to write into the C string, * including the terminating zero * @param encoding The encoding to use for writing into the C string * @return The number of bytes written into the C string, without the * terminating zero */ - (size_t)getLossyCString: (char *)cString maxLength: (size_t)maxLength encoding: (OFStringEncoding)encoding; /** * @brief Returns the OFString as a C string in the specified encoding. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. * * @param encoding The encoding for the C string * @return The OFString as a C string in the specified encoding * @throw OFInvalidEncodingException The string cannot be represented in the * specified encoding */ - (const char *)cStringWithEncoding: (OFStringEncoding)encoding; /** * @brief Returns the OFString as a C string in the specified encoding, * replacing characters that cannot be represented in the specified * encoding with a question mark. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. * * @param encoding The encoding for the C string * @return The OFString as a C string in the specified encoding */ - (const char *)lossyCStringWithEncoding: (OFStringEncoding)encoding; /** * @brief Returns the number of bytes the string needs in the specified * encoding. * * @param encoding The encoding for the string * @return The number of bytes the string needs in the specified encoding. * @throw OFInvalidEncodingException The string cannot be represented in the * specified encoding */ - (size_t)cStringLengthWithEncoding: (OFStringEncoding)encoding; /** * @brief Compares the string to another string. * * @param string The string to compare the string to * @return The result of the comparison */ - (OFComparisonResult)compare: (OFString *)string; /** * @brief Compares the string to another string without caring about the case. * * @param string The string to compare the string to * @return The result of the comparison */ - (OFComparisonResult)caseInsensitiveCompare: (OFString *)string; /** * @brief Returns the Unicode character at the specified index. * * @param index The index of the Unicode character to return * @return The Unicode character at the specified index */ - (OFUnichar)characterAtIndex: (size_t)index; /** * @brief Copies the Unicode characters in the specified range to the specified * buffer. * * @param buffer The buffer to store the Unicode characters * @param range The range of the Unicode characters to copy */ - (void)getCharacters: (OFUnichar *)buffer inRange: (OFRange)range; /** * @brief Returns the range of the first occurrence of the string. * * @param string The string to search * @return The range of the first occurrence of the string or a range with * `OFNotFound` as start position if it was not found */ - (OFRange)rangeOfString: (OFString *)string; /** * @brief Returns the range of the string. * * @param string The string to search * @param options Options modifying search behavior * @return The range of the first occurrence of the string or a range with * `OFNotFound` as start position if it was not found */ - (OFRange)rangeOfString: (OFString *)string options: (OFStringSearchOptions)options; /** * @brief Returns the range of the string in the specified range. * * @param string The string to search * @param options Options modifying search behaviour * @param range The range in which to search * @return The range of the first occurrence of the string or a range with * `OFNotFound` as start position if it was not found */ - (OFRange)rangeOfString: (OFString *)string options: (OFStringSearchOptions)options range: (OFRange)range; /** * @brief Returns the index of the first character from the set. * * @param characterSet The set of characters to search for * @return The index of the first occurrence of a character from the set or * `OFNotFound` if it was not found */ - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet; /** * @brief Returns the index of the first character from the set. * * @param characterSet The set of characters to search for * @param options Options modifying search behavior * @return The index of the first occurrence of a character from the set or * `OFNotFound` if it was not found */ - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet options: (OFStringSearchOptions)options; /** * @brief Returns the index of the first character from the set. * * @param characterSet The set of characters to search for * @param options Options modifying search behavior * @param range The range in which to search * @return The index of the first occurrence of a character from the set or * `OFNotFound` if it was not found */ - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet options: (OFStringSearchOptions)options range: (OFRange)range; /** * @brief Returns whether the string contains the specified string. * * @param string The string to search * @return Whether the string contains the specified string */ - (bool)containsString: (OFString *)string; /** * @brief Creates a substring from the specified index to the end. * * @param idx The index from where the substring should start, inclusive * @return The substring from the specified index to the end */ - (OFString *)substringFromIndex: (size_t)idx; /** * @brief Creates a substring from the beginning to the specified index. * * @param idx The index at which the substring should end, exclusive * @return The substring from the beginning to the specified index */ - (OFString *)substringToIndex: (size_t)idx; /** * @brief Creates a substring with the specified range. * * @param range The range of the substring * @return The substring as a new autoreleased OFString */ - (OFString *)substringWithRange: (OFRange)range; /** * @brief The value of the string in the specified base as a `long long`. * * Leading and trailing whitespaces are ignored. * * If the string contains any non-number characters, an * @ref OFInvalidFormatException is thrown. * * If the number is too big to fit into a `long long`, an * @ref OFOutOfRangeException is thrown. * * @param base The base to use. If the base is 0, base 16 is assumed if the * string starts with 0x (after stripping white spaces). If the * string starts with 0, base 8 is assumed. Otherwise, base 10 is * assumed. * @return The value of the string in the specified base * @throw OFInvalidFormatException The string cannot be parsed as a `long long` * @throw OFOutOfRangeException The value cannot be represented as a `long long` */ - (long long)longLongValueWithBase: (unsigned char)base; /** * @brief The value of the string in the specified base as an * `unsigned long long`. * * Leading and trailing whitespaces are ignored. * * If the string contains any non-number characters, an * @ref OFInvalidFormatException is thrown. * * If the number is too big to fit into an `unsigned long long`, an * @ref OFOutOfRangeException is thrown. * * @param base The base to use. If the base is 0, base 16 is assumed if the * string starts with 0x (after stripping white spaces). If the * string starts with 0, base 8 is assumed. Otherwise, base 10 is * assumed. * @return The value of the string in the specified base * @throw OFInvalidFormatException The string cannot be parsed as an * `unsigned long long` * @throw OFOutOfRangeException The value cannot be represented as an * `unsigned long long` */ - (unsigned long long)unsignedLongLongValueWithBase: (unsigned char)base; /** * @brief Creates a new string by appending another string. * * @param string The string to append * @return A new, autoreleased OFString with the specified string appended */ - (OFString *)stringByAppendingString: (OFString *)string; /** * @brief Creates a new string by appending the specified format. * * @param format A format string which generates the string to append * @return A new, autoreleased OFString with the specified format appended * @throw OFInvalidEncodingException The string was not properly UTF-8-encoded * after formatting it * @throw OFInvalidFormatException The specified format is invalid */ - (OFString *)stringByAppendingFormat: (OFConstantString *)format, ...; /** * @brief Creates a new string by appending the specified format. * * @param format A format string which generates the string to append * @param arguments The arguments used in the format string * @return A new, autoreleased OFString with the specified format appended * @throw OFInvalidEncodingException The string was not properly UTF-8-encoded * after formatting it * @throw OFInvalidFormatException The specified format is invalid */ - (OFString *)stringByAppendingFormat: (OFConstantString *)format arguments: (va_list)arguments; /** * @brief Creates a new string by replacing the occurrences of the specified * string with the specified replacement. * * @param string The string to replace * @param replacement The string with which it should be replaced * @return A new string with the occurrences of the specified string replaced */ - (OFString *)stringByReplacingOccurrencesOfString: (OFString *)string withString: (OFString *)replacement; /** * @brief Creates a new string by replacing the occurrences of the specified * string in the specified range with the specified replacement. * * @param string The string to replace * @param replacement The string with which it should be replaced * @param options Options modifying search behavior. * Possible values are: * * None yet, pass 0 * @param range The range in which to replace the string * @return A new string with the occurrences of the specified string replaced */ - (OFString *)stringByReplacingOccurrencesOfString: (OFString *)string withString: (OFString *)replacement options: (int)options range: (OFRange)range; /** * @brief Checks whether the string has the specified prefix. * * @param prefix The prefix to check for * @return A boolean whether the string has the specified prefix */ - (bool)hasPrefix: (OFString *)prefix; /** * @brief Checks whether the string has the specified suffix. * * @param suffix The suffix to check for * @return A boolean whether the string has the specified suffix */ - (bool)hasSuffix: (OFString *)suffix; /** * @brief Separates the string into an array of strings, split by the specified * delimiter. * * @param delimiter The delimiter for separating * @return An autoreleased OFArray with the separated string */ - (OFArray OF_GENERIC(OFString *) *) componentsSeparatedByString: (OFString *)delimiter; /** * @brief Separates the string into an array of strings, split by the specified * delimiter. * * @param delimiter The delimiter for separating * @param options Options according to which the string should be separated * @return An autoreleased OFArray with the separated string */ - (OFArray OF_GENERIC(OFString *) *) componentsSeparatedByString: (OFString *)delimiter options: (OFStringSeparationOptions)options; /** * @brief Separates the string into an array of strings, split by characters in * the specified set. * * @param characterSet The character set for separating * @return An autoreleased OFArray with the separated string */ - (OFArray OF_GENERIC(OFString *) *) componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet; /** * @brief Separates the string into an array of strings, split by characters in * the specified set. * * @param characterSet The character set for separating * @param options Options according to which the string should be separated * @return An autoreleased OFArray with the separated string */ - (OFArray OF_GENERIC(OFString *) *) componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet options: (OFStringSeparationOptions)options; /** * @brief Returns the string in UTF-16 encoding with the specified byte order. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. * * The returned string is null-terminated. * * @param byteOrder The byte order for the UTF-16 encoding * @return The string in UTF-16 encoding with the specified byte order * @throw OFInvalidEncodingException The string cannot be represented in UTF-16 */ - (const OFChar16 *)UTF16StringWithByteOrder: (OFByteOrder)byteOrder; /** * @brief Returns the string in UTF-32 encoding with the specified byte order. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. * * The returned string is null-terminated. * * @param byteOrder The byte order for the UTF-32 encoding * @return The string in UTF-32 encoding with the specified byte order */ - (const OFChar32 *)UTF32StringWithByteOrder: (OFByteOrder)byteOrder; /** * @brief Returns the string as OFData with the specified encoding. * * @param encoding The encoding to use for the returned OFData * @return The string as OFData with the specified encoding * @throw OFInvalidEncodingException The string cannot be represented in the * specified encoding */ - (OFData *)dataWithEncoding: (OFStringEncoding)encoding; #ifdef OF_HAVE_FILES /** * @brief Writes the string into the specified file using UTF-8 encoding. * * @param path The path of the file to write to */ - (void)writeToFile: (OFString *)path; /** * @brief Writes the string into the specified file using the specified * encoding. * * @param path The path of the file to write to * @param encoding The encoding to use to write the string into the file * @throw OFInvalidEncodingException The string cannot be represented in the * specified encoding */ - (void)writeToFile: (OFString *)path encoding: (OFStringEncoding)encoding; #endif /** * @brief Writes the string to the specified IRI using UTF-8 encoding. * * @param IRI The IRI to write to */ - (void)writeToIRI: (OFIRI *)IRI; /** * @brief Writes the string to the specified IRI using the specified encoding. * * @param IRI The IRI to write to * @param encoding The encoding to use to write the string to the IRI * @throw OFInvalidEncodingException The string cannot be represented in the * specified encoding */ - (void)writeToIRI: (OFIRI *)IRI encoding: (OFStringEncoding)encoding; #ifdef OF_HAVE_BLOCKS /** * Enumerates all lines in the receiver using the specified block. * * @brief block The block to call for each line */ - (void)enumerateLinesUsingBlock: (OFStringLineEnumerationBlock)block; #endif @end #ifdef __cplusplus extern "C" { #endif /** * @brief Parses the specified string encoding name and returns the * OFStringEncoding for it. * * Throws @ref OFInvalidArgumentException if the specified name is not a valid * encoding name. * * @param name The name to parse as a string encoding * @return The OFStringEncoding for the specified name */ extern OFStringEncoding OFStringEncodingParseName(OFString *name); /** * @brief Returns the name of the specified OFStringEncoding. * * @param encoding The encoding for which to return the name * @return The name of the specified OFStringEncoding */ extern OFString *_Nullable OFStringEncodingName(OFStringEncoding encoding); /** * @brief Returns the length of the specified UTF-16 string. * * @param string The UTF-16 string * @return The length of the specified UTF-16 string */ extern size_t OFUTF16StringLength(const OFChar16 *string); /** * @brief Returns the length of the specified UTF-32 string. * * @param string The UTF-32 string * @return The length of the specified UTF-32 string */ extern size_t OFUTF32StringLength(const OFChar32 *string); extern char *_Nullable _OFStrDup(const char *_Nonnull) OF_VISIBILITY_HIDDEN; extern size_t _OFUTF8StringEncode(OFUnichar, char *) OF_VISIBILITY_HIDDEN; extern ssize_t _OFUTF8StringDecode(const char *, size_t, OFUnichar *) OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END #import "OFConstantString.h" #import "OFMutableString.h" #import "OFString+CryptographicHashing.h" #import "OFString+JSONParsing.h" #ifdef OF_HAVE_FILES # import "OFString+PathAdditions.h" #endif #import "OFString+PercentEncoding.h" #import "OFString+PropertyListParsing.h" #import "OFString+XMLEscaping.h" #import "OFString+XMLUnescaping.h" #if !defined(NSINTEGER_DEFINED) && !__has_feature(modules) /* * Very *ugly* hack required for string boxing literals to work. * * This hack is needed in order to work with `@class NSString` from Apple's * objc/NSString.h - which is included when using modules - as * @compatibility_alias does not work if @class has been used before. * For some reason, this makes Clang refer to OFString for string box literals * and not to NSString (which would result in a linker error, but would be the * correct behavior). * * TODO: Submit a patch for Clang that makes the boxing classes configurable! */ @interface NSString: OFString @end #endif objfw-1.1.6/src/OFString.m000066400000000000000000002001611465614216400152770ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #include #include #include #include #if defined(HAVE_STRTOF_L) || defined(HAVE_STRTOD_L) || defined(HAVE_USELOCALE) # include #endif #ifdef HAVE_XLOCALE_H # include #endif #import "OFString.h" #import "OFASPrintF.h" #import "OFArray.h" #import "OFCharacterSet.h" #import "OFData.h" #import "OFDictionary.h" #ifdef OF_HAVE_FILES # import "OFFile.h" # import "OFFileManager.h" #endif #import "OFIRI.h" #import "OFIRIHandler.h" #import "OFLocale.h" #import "OFStream.h" #import "OFSystemInfo.h" #import "OFUTF8String.h" #import "OFUTF8String+Private.h" #import "OFGetItemAttributesFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" #import "unicode.h" /* * It seems strtod is buggy on Win32. * However, the MinGW version __strtod seems to be ok. */ #ifdef __MINGW32__ # define strtod __strtod #endif #ifndef HAVE_STRTOF # define strtof strtod #endif #ifndef INFINITY # define INFINITY __builtin_inf() #endif static struct { Class isa; } placeholder; #if defined(HAVE_STRTOF_L) || defined(HAVE_STRTOD_L) || defined(HAVE_USELOCALE) static locale_t cLocale; #endif @interface OFString () - (size_t)of_getCString: (char *)cString maxLength: (size_t)maxLength encoding: (OFStringEncoding)encoding lossy: (bool)lossy OF_DIRECT; - (const char *)of_cStringWithEncoding: (OFStringEncoding)encoding lossy: (bool)lossy OF_DIRECT; - (OFString *) of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options depth: (size_t)depth; @end @interface OFPlaceholderString: OFString @end extern bool _OFUnicodeToISO8859_2(const OFUnichar *, unsigned char *, size_t, bool); extern bool _OFUnicodeToISO8859_3(const OFUnichar *, unsigned char *, size_t, bool); extern bool _OFUnicodeToISO8859_15(const OFUnichar *, unsigned char *, size_t, bool); extern bool _OFUnicodeToWindows1251(const OFUnichar *, unsigned char *, size_t, bool); extern bool _OFUnicodeToWindows1252(const OFUnichar *, unsigned char *, size_t, bool); extern bool _OFUnicodeToCodepage437(const OFUnichar *, unsigned char *, size_t, bool); extern bool _OFUnicodeToCodepage850(const OFUnichar *, unsigned char *, size_t, bool); extern bool _OFUnicodeToCodepage858(const OFUnichar *, unsigned char *, size_t, bool); extern bool _OFUnicodeToMacRoman(const OFUnichar *, unsigned char *, size_t, bool); extern bool _OFUnicodeToKOI8R(const OFUnichar *, unsigned char *, size_t, bool); extern bool _OFUnicodeToKOI8U(const OFUnichar *, unsigned char *, size_t, bool); /* References for static linking */ void OF_VISIBILITY_HIDDEN _references_to_categories_of_OFString(void) { _OFString_CryptographicHashing_reference = 1; _OFString_JSONParsing_reference = 1; #ifdef OF_HAVE_FILES _OFString_PathAdditions_reference = 1; #endif _OFString_PercentEncoding_reference = 1; _OFString_PropertyListParsing_reference = 1; _OFString_XMLEscaping_reference = 1; _OFString_XMLUnescaping_reference = 1; } void OF_VISIBILITY_HIDDEN _reference_to_OFConstantString(void) { [OFConstantString class]; } OFStringEncoding OFStringEncodingParseName(OFString *string) { void *pool = objc_autoreleasePoolPush(); OFStringEncoding encoding; string = string.lowercaseString; if ([string isEqual: @"utf8"] || [string isEqual: @"utf-8"]) encoding = OFStringEncodingUTF8; else if ([string isEqual: @"ascii"] || [string isEqual: @"us-ascii"]) encoding = OFStringEncodingASCII; else if ([string isEqual: @"iso-8859-1"] || [string isEqual: @"iso_8859-1"]) encoding = OFStringEncodingISO8859_1; else if ([string isEqual: @"iso-8859-2"] || [string isEqual: @"iso_8859-2"]) encoding = OFStringEncodingISO8859_2; else if ([string isEqual: @"iso-8859-3"] || [string isEqual: @"iso_8859-3"]) encoding = OFStringEncodingISO8859_3; else if ([string isEqual: @"iso-8859-15"] || [string isEqual: @"iso_8859-15"]) encoding = OFStringEncodingISO8859_15; else if ([string isEqual: @"windows-1251"] || [string isEqual: @"cp1251"] || [string isEqual: @"cp-1251"] || [string isEqual: @"1251"]) encoding = OFStringEncodingWindows1251; else if ([string isEqual: @"windows-1252"] || [string isEqual: @"cp1252"] || [string isEqual: @"cp-1252"] || [string isEqual: @"1252"]) encoding = OFStringEncodingWindows1252; else if ([string isEqual: @"cp437"] || [string isEqual: @"cp-437"] || [string isEqual: @"ibm437"] || [string isEqual: @"437"]) encoding = OFStringEncodingCodepage437; else if ([string isEqual: @"cp850"] || [string isEqual: @"cp-850"] || [string isEqual: @"ibm850"] || [string isEqual: @"850"]) encoding = OFStringEncodingCodepage850; else if ([string isEqual: @"cp858"] || [string isEqual: @"cp-858"] || [string isEqual: @"ibm858"] || [string isEqual: @"858"]) encoding = OFStringEncodingCodepage858; else if ([string isEqual: @"macintosh"] || [string isEqual: @"mac"]) encoding = OFStringEncodingMacRoman; else if ([string isEqual: @"koi8-r"]) encoding = OFStringEncodingKOI8R; else if ([string isEqual: @"koi8-u"]) encoding = OFStringEncodingKOI8U; else @throw [OFInvalidArgumentException exception]; objc_autoreleasePoolPop(pool); return encoding; } OFString * OFStringEncodingName(OFStringEncoding encoding) { switch (encoding) { case OFStringEncodingUTF8: return @"UTF-8"; case OFStringEncodingASCII: return @"ASCII"; case OFStringEncodingISO8859_1: return @"ISO 8859-1"; case OFStringEncodingISO8859_2: return @"ISO 8859-2"; case OFStringEncodingISO8859_3: return @"ISO 8859-3"; case OFStringEncodingISO8859_15: return @"ISO 8859-15"; case OFStringEncodingWindows1251: return @"Windows-1251"; case OFStringEncodingWindows1252: return @"Windows-1252"; case OFStringEncodingCodepage437: return @"Codepage 437"; case OFStringEncodingCodepage850: return @"Codepage 850"; case OFStringEncodingCodepage858: return @"Codepage 858"; case OFStringEncodingMacRoman: return @"Mac Roman"; case OFStringEncodingKOI8R: return @"KOI8-R"; case OFStringEncodingKOI8U: return @"KOI8-U"; case OFStringEncodingAutodetect: return @"autodetect"; } return nil; } size_t _OFUTF8StringEncode(OFUnichar character, char *buffer) { if (character < 0x80) { buffer[0] = character; return 1; } else if (character < 0x800) { buffer[0] = 0xC0 | (character >> 6); buffer[1] = 0x80 | (character & 0x3F); return 2; } else if (character < 0x10000) { buffer[0] = 0xE0 | (character >> 12); buffer[1] = 0x80 | (character >> 6 & 0x3F); buffer[2] = 0x80 | (character & 0x3F); return 3; } else if (character < 0x110000) { buffer[0] = 0xF0 | (character >> 18); buffer[1] = 0x80 | (character >> 12 & 0x3F); buffer[2] = 0x80 | (character >> 6 & 0x3F); buffer[3] = 0x80 | (character & 0x3F); return 4; } return 0; } ssize_t _OFUTF8StringDecode(const char *buffer_, size_t length, OFUnichar *ret) { const unsigned char *buffer = (const unsigned char *)buffer_; if (!(*buffer & 0x80)) { *ret = buffer[0]; return 1; } if ((*buffer & 0xE0) == 0xC0) { if OF_UNLIKELY (length < 2) return -2; if OF_UNLIKELY ((buffer[1] & 0xC0) != 0x80) return 0; *ret = ((buffer[0] & 0x1F) << 6) | (buffer[1] & 0x3F); return 2; } if ((*buffer & 0xF0) == 0xE0) { if OF_UNLIKELY (length < 3) return -3; if OF_UNLIKELY ((buffer[1] & 0xC0) != 0x80 || (buffer[2] & 0xC0) != 0x80) return 0; *ret = ((buffer[0] & 0x0F) << 12) | ((buffer[1] & 0x3F) << 6) | (buffer[2] & 0x3F); return 3; } if ((*buffer & 0xF8) == 0xF0) { if OF_UNLIKELY (length < 4) return -4; if OF_UNLIKELY ((buffer[1] & 0xC0) != 0x80 || (buffer[2] & 0xC0) != 0x80 || (buffer[3] & 0xC0) != 0x80) return 0; *ret = ((buffer[0] & 0x07) << 18) | ((buffer[1] & 0x3F) << 12) | ((buffer[2] & 0x3F) << 6) | (buffer[3] & 0x3F); return 4; } return 0; } size_t OFUTF16StringLength(const OFChar16 *string) { size_t length = 0; while (*string++ != 0) length++; return length; } size_t OFUTF32StringLength(const OFChar32 *string) { size_t length = 0; while (*string++ != 0) length++; return length; } char * _OFStrDup(const char *string) { size_t length = strlen(string); char *copy = (char *)OFAllocMemory(1, length + 1); memcpy(copy, string, length + 1); return copy; } @implementation OFPlaceholderString #ifdef __clang__ /* We intentionally don't call into super, so silence the warning. */ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunknown-pragmas" # pragma clang diagnostic ignored "-Wobjc-designated-initializers" #endif - (instancetype)init { return (id)[[OFUTF8String alloc] init]; } - (instancetype)initWithUTF8String: (const char *)UTF8String { OFUTF8String *string; size_t length; void *storage; length = strlen(UTF8String); string = OFAllocObject([OFUTF8String class], length + 1, 1, &storage); return (id)[string of_initWithUTF8String: UTF8String length: length storage: storage]; } - (instancetype)initWithUTF8String: (const char *)UTF8String length: (size_t)UTF8StringLength { OFUTF8String *string; void *storage; string = OFAllocObject([OFUTF8String class], UTF8StringLength + 1, 1, &storage); return (id)[string of_initWithUTF8String: UTF8String length: UTF8StringLength storage: storage]; } - (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String freeWhenDone: (bool)freeWhenDone { return (id)[[OFUTF8String alloc] initWithUTF8StringNoCopy: UTF8String freeWhenDone: freeWhenDone]; } - (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String length: (size_t)UTF8StringLength freeWhenDone: (bool)freeWhenDone { return (id)[[OFUTF8String alloc] initWithUTF8StringNoCopy: UTF8String length: UTF8StringLength freeWhenDone: freeWhenDone]; } - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding { if (encoding == OFStringEncodingUTF8) { OFUTF8String *string; size_t length; void *storage; length = strlen(cString); string = OFAllocObject([OFUTF8String class], length + 1, 1, &storage); return (id)[string of_initWithUTF8String: cString length: length storage: storage]; } return (id)[[OFUTF8String alloc] initWithCString: cString encoding: encoding]; } - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength { if (encoding == OFStringEncodingUTF8) { OFUTF8String *string; void *storage; string = OFAllocObject([OFUTF8String class], cStringLength + 1, 1, &storage); return (id)[string of_initWithUTF8String: cString length: cStringLength storage: storage]; } return (id)[[OFUTF8String alloc] initWithCString: cString encoding: encoding length: cStringLength]; } - (instancetype)initWithData: (OFData *)data encoding: (OFStringEncoding)encoding { return (id)[[OFUTF8String alloc] initWithData: data encoding: encoding]; } - (instancetype)initWithString: (OFString *)string { return (id)[[OFUTF8String alloc] initWithString: string]; } - (instancetype)initWithCharacters: (const OFUnichar *)string length: (size_t)length { return (id)[[OFUTF8String alloc] initWithCharacters: string length: length]; } - (instancetype)initWithUTF16String: (const OFChar16 *)string { return (id)[[OFUTF8String alloc] initWithUTF16String: string]; } - (instancetype)initWithUTF16String: (const OFChar16 *)string length: (size_t)length { return (id)[[OFUTF8String alloc] initWithUTF16String: string length: length]; } - (instancetype)initWithUTF16String: (const OFChar16 *)string byteOrder: (OFByteOrder)byteOrder { return (id)[[OFUTF8String alloc] initWithUTF16String: string byteOrder: byteOrder]; } - (instancetype)initWithUTF16String: (const OFChar16 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder { return (id)[[OFUTF8String alloc] initWithUTF16String: string length: length byteOrder: byteOrder]; } - (instancetype)initWithUTF32String: (const OFChar32 *)string { return (id)[[OFUTF8String alloc] initWithUTF32String: string]; } - (instancetype)initWithUTF32String: (const OFChar32 *)string length: (size_t)length { return (id)[[OFUTF8String alloc] initWithUTF32String: string length: length]; } - (instancetype)initWithUTF32String: (const OFChar32 *)string byteOrder: (OFByteOrder)byteOrder { return (id)[[OFUTF8String alloc] initWithUTF32String: string byteOrder: byteOrder]; } - (instancetype)initWithUTF32String: (const OFChar32 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder { return (id)[[OFUTF8String alloc] initWithUTF32String: string length: length byteOrder: byteOrder]; } - (instancetype)initWithFormat: (OFConstantString *)format, ... { id ret; va_list arguments; va_start(arguments, format); ret = [[OFUTF8String alloc] initWithFormat: format arguments: arguments]; va_end(arguments); return ret; } - (instancetype)initWithFormat: (OFConstantString *)format arguments: (va_list)arguments { return (id)[[OFUTF8String alloc] initWithFormat: format arguments: arguments]; } #ifdef OF_HAVE_FILES - (instancetype)initWithContentsOfFile: (OFString *)path { return (id)[[OFUTF8String alloc] initWithContentsOfFile: path]; } - (instancetype)initWithContentsOfFile: (OFString *)path encoding: (OFStringEncoding)encoding { return (id)[[OFUTF8String alloc] initWithContentsOfFile: path encoding: encoding]; } #endif - (instancetype)initWithContentsOfIRI: (OFIRI *)IRI { return (id)[[OFUTF8String alloc] initWithContentsOfIRI: IRI]; } - (instancetype)initWithContentsOfIRI: (OFIRI *)IRI encoding: (OFStringEncoding)encoding { return (id)[[OFUTF8String alloc] initWithContentsOfIRI: IRI encoding: encoding]; } #ifdef __clang__ # pragma clang diagnostic pop #endif OF_SINGLETON_METHODS @end @implementation OFString + (void)initialize { if (self != [OFString class]) return; object_setClass((id)&placeholder, [OFPlaceholderString class]); #if defined(HAVE_STRTOF_L) || defined(HAVE_STRTOD_L) || defined(HAVE_USELOCALE) if ((cLocale = newlocale(LC_ALL_MASK, "C", NULL)) == NULL) @throw [OFInitializationFailedException exceptionWithClass: self]; #endif } + (instancetype)alloc { if (self == [OFString class]) return (id)&placeholder; return [super alloc]; } + (instancetype)string { return [[[self alloc] init] autorelease]; } + (instancetype)stringWithUTF8String: (const char *)UTF8String { return [[[self alloc] initWithUTF8String: UTF8String] autorelease]; } + (instancetype)stringWithUTF8String: (const char *)UTF8String length: (size_t)UTF8StringLength { return [[[self alloc] initWithUTF8String: UTF8String length: UTF8StringLength] autorelease]; } + (instancetype)stringWithUTF8StringNoCopy: (char *)UTF8String freeWhenDone: (bool)freeWhenDone { return [[[self alloc] initWithUTF8StringNoCopy: UTF8String freeWhenDone: freeWhenDone] autorelease]; } + (instancetype)stringWithUTF8StringNoCopy: (char *)UTF8String length: (size_t)UTF8StringLength freeWhenDone: (bool)freeWhenDone { return [[[self alloc] initWithUTF8StringNoCopy: UTF8String length: UTF8StringLength freeWhenDone: freeWhenDone] autorelease]; } + (instancetype)stringWithCString: (const char *)cString encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithCString: cString encoding: encoding] autorelease]; } + (instancetype)stringWithCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength { return [[[self alloc] initWithCString: cString encoding: encoding length: cStringLength] autorelease]; } + (instancetype)stringWithData: (OFData *)data encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithData: data encoding: encoding] autorelease]; } + (instancetype)stringWithString: (OFString *)string { return [[[self alloc] initWithString: string] autorelease]; } + (instancetype)stringWithCharacters: (const OFUnichar *)string length: (size_t)length { return [[[self alloc] initWithCharacters: string length: length] autorelease]; } + (instancetype)stringWithUTF16String: (const OFChar16 *)string { return [[[self alloc] initWithUTF16String: string] autorelease]; } + (instancetype)stringWithUTF16String: (const OFChar16 *)string length: (size_t)length { return [[[self alloc] initWithUTF16String: string length: length] autorelease]; } + (instancetype)stringWithUTF16String: (const OFChar16 *)string byteOrder: (OFByteOrder)byteOrder { return [[[self alloc] initWithUTF16String: string byteOrder: byteOrder] autorelease]; } + (instancetype)stringWithUTF16String: (const OFChar16 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder { return [[[self alloc] initWithUTF16String: string length: length byteOrder: byteOrder] autorelease]; } + (instancetype)stringWithUTF32String: (const OFChar32 *)string { return [[[self alloc] initWithUTF32String: string] autorelease]; } + (instancetype)stringWithUTF32String: (const OFChar32 *)string length: (size_t)length { return [[[self alloc] initWithUTF32String: string length: length] autorelease]; } + (instancetype)stringWithUTF32String: (const OFChar32 *)string byteOrder: (OFByteOrder)byteOrder { return [[[self alloc] initWithUTF32String: string byteOrder: byteOrder] autorelease]; } + (instancetype)stringWithUTF32String: (const OFChar32 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder { return [[[self alloc] initWithUTF32String: string length: length byteOrder: byteOrder] autorelease]; } + (instancetype)stringWithFormat: (OFConstantString *)format, ... { id ret; va_list arguments; va_start(arguments, format); ret = [[[self alloc] initWithFormat: format arguments: arguments] autorelease]; va_end(arguments); return ret; } #ifdef OF_HAVE_FILES + (instancetype)stringWithContentsOfFile: (OFString *)path { return [[[self alloc] initWithContentsOfFile: path] autorelease]; } + (instancetype)stringWithContentsOfFile: (OFString *)path encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithContentsOfFile: path encoding: encoding] autorelease]; } #endif + (instancetype)stringWithContentsOfIRI: (OFIRI *)IRI { return [[[self alloc] initWithContentsOfIRI: IRI] autorelease]; } + (instancetype)stringWithContentsOfIRI: (OFIRI *)IRI encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithContentsOfIRI: IRI encoding: encoding] autorelease]; } - (instancetype)init { if ([self isMemberOfClass: [OFString class]] || [self isMemberOfClass: [OFMutableString class]]) { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @throw e; } abort(); } return [super init]; } - (instancetype)initWithUTF8String: (const char *)UTF8String { return [self initWithCString: UTF8String encoding: OFStringEncodingUTF8 length: strlen(UTF8String)]; } - (instancetype)initWithUTF8String: (const char *)UTF8String length: (size_t)UTF8StringLength { return [self initWithCString: UTF8String encoding: OFStringEncodingUTF8 length: UTF8StringLength]; } - (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String freeWhenDone: (bool)freeWhenDone { id ret = [self initWithUTF8String: UTF8String]; if (freeWhenDone) OFFreeMemory(UTF8String); return ret; } - (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String length: (size_t)UTF8StringLength freeWhenDone: (bool)freeWhenDone { id ret = [self initWithUTF8String: UTF8String length: UTF8StringLength]; if (freeWhenDone) OFFreeMemory(UTF8String); return ret; } - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding { return [self initWithCString: cString encoding: encoding length: strlen(cString)]; } #ifdef __clang__ /* We intentionally don't call into super, so silence the warning. */ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunknown-pragmas" # pragma clang diagnostic ignored "-Wobjc-designated-initializers" #endif - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength { OF_INVALID_INIT_METHOD } #ifdef __clang__ # pragma clang diagnostic pop #endif - (instancetype)initWithData: (OFData *)data encoding: (OFStringEncoding)encoding { @try { if (data.itemSize != 1) @throw [OFInvalidArgumentException exception]; } @catch (id e) { [self release]; @throw e; } self = [self initWithCString: data.items encoding: encoding length: data.count]; return self; } #ifdef __clang__ /* We intentionally don't call into super, so silence the warning. */ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunknown-pragmas" # pragma clang diagnostic ignored "-Wobjc-designated-initializers" #endif - (instancetype)initWithString: (OFString *)string { OF_INVALID_INIT_METHOD } - (instancetype)initWithCharacters: (const OFUnichar *)string length: (size_t)length { OF_INVALID_INIT_METHOD } #ifdef __clang__ # pragma clang diagnostic pop #endif - (instancetype)initWithUTF16String: (const OFChar16 *)string { return [self initWithUTF16String: string length: OFUTF16StringLength(string) byteOrder: OFByteOrderNative]; } - (instancetype)initWithUTF16String: (const OFChar16 *)string length: (size_t)length { return [self initWithUTF16String: string length: length byteOrder: OFByteOrderNative]; } - (instancetype)initWithUTF16String: (const OFChar16 *)string byteOrder: (OFByteOrder)byteOrder { return [self initWithUTF16String: string length: OFUTF16StringLength(string) byteOrder: byteOrder]; } #ifdef __clang__ /* We intentionally don't call into super, so silence the warning. */ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunknown-pragmas" # pragma clang diagnostic ignored "-Wobjc-designated-initializers" #endif - (instancetype)initWithUTF16String: (const OFChar16 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder { OF_INVALID_INIT_METHOD } #ifdef __clang__ # pragma clang diagnostic pop #endif - (instancetype)initWithUTF32String: (const OFChar32 *)string { return [self initWithUTF32String: string length: OFUTF32StringLength(string) byteOrder: OFByteOrderNative]; } - (instancetype)initWithUTF32String: (const OFChar32 *)string length: (size_t)length { return [self initWithUTF32String: string length: length byteOrder: OFByteOrderNative]; } - (instancetype)initWithUTF32String: (const OFChar32 *)string byteOrder: (OFByteOrder)byteOrder { return [self initWithUTF32String: string length: OFUTF32StringLength(string) byteOrder: byteOrder]; } #ifdef __clang__ /* We intentionally don't call into super, so silence the warning. */ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunknown-pragmas" # pragma clang diagnostic ignored "-Wobjc-designated-initializers" #endif - (instancetype)initWithUTF32String: (const OFChar32 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder { OF_INVALID_INIT_METHOD } #ifdef __clang__ # pragma clang diagnostic pop #endif - (instancetype)initWithFormat: (OFConstantString *)format, ... { id ret; va_list arguments; va_start(arguments, format); ret = [self initWithFormat: format arguments: arguments]; va_end(arguments); return ret; } #ifdef __clang__ /* We intentionally don't call into super, so silence the warning. */ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunknown-pragmas" # pragma clang diagnostic ignored "-Wobjc-designated-initializers" #endif - (instancetype)initWithFormat: (OFConstantString *)format arguments: (va_list)arguments { OF_INVALID_INIT_METHOD } #ifdef __clang__ # pragma clang diagnostic pop #endif #ifdef OF_HAVE_FILES - (instancetype)initWithContentsOfFile: (OFString *)path { return [self initWithContentsOfFile: path encoding: OFStringEncodingUTF8]; } - (instancetype)initWithContentsOfFile: (OFString *)path encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFIRI *IRI; @try { IRI = [OFIRI fileIRIWithPath: path isDirectory: false]; } @catch (id e) { [self release]; @throw e; } self = [self initWithContentsOfIRI: IRI encoding: encoding]; objc_autoreleasePoolPop(pool); return self; } #endif - (instancetype)initWithContentsOfIRI: (OFIRI *)IRI { return [self initWithContentsOfIRI: IRI encoding: OFStringEncodingAutodetect]; } - (instancetype)initWithContentsOfIRI: (OFIRI *)IRI encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFData *data; @try { data = [OFData dataWithContentsOfIRI: IRI]; } @catch (id e) { [self release]; @throw e; } /* FIXME: Detect encoding where we can. */ if (encoding == OFStringEncodingAutodetect) encoding = OFStringEncodingUTF8; self = [self initWithCString: data.items encoding: encoding length: data.count * data.itemSize]; objc_autoreleasePoolPop(pool); return self; } - (size_t)of_getCString: (char *)cString maxLength: (size_t)maxLength encoding: (OFStringEncoding)encoding lossy: (bool)lossy { const OFUnichar *characters = self.characters; size_t i, length = self.length; switch (encoding) { case OFStringEncodingUTF8:; size_t j = 0; for (i = 0; i < length; i++) { char buffer[4]; size_t len = _OFUTF8StringEncode(characters[i], buffer); /* * Check for one more than the current index, as we * need one for the terminating zero. */ if (j + len >= maxLength) @throw [OFOutOfRangeException exception]; switch (len) { case 1: cString[j++] = buffer[0]; break; case 2: case 3: case 4: memcpy(cString + j, buffer, len); j += len; break; default: @throw [OFInvalidEncodingException exception]; break; } } cString[j] = '\0'; return j; case OFStringEncodingASCII: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; for (i = 0; i < length; i++) { if OF_UNLIKELY (characters[i] > 0x80) { if (lossy) cString[i] = '?'; else @throw [OFInvalidEncodingException exception]; } else cString[i] = (unsigned char)characters[i]; } cString[i] = '\0'; return length; case OFStringEncodingISO8859_1: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; for (i = 0; i < length; i++) { if OF_UNLIKELY (characters[i] > 0xFF) { if (lossy) cString[i] = '?'; else @throw [OFInvalidEncodingException exception]; } else cString[i] = (unsigned char)characters[i]; } cString[i] = '\0'; return length; #ifdef HAVE_ISO_8859_2 case OFStringEncodingISO8859_2: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!_OFUnicodeToISO8859_2(characters, (unsigned char *)cString, length, lossy)) @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; #endif #ifdef HAVE_ISO_8859_3 case OFStringEncodingISO8859_3: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!_OFUnicodeToISO8859_3(characters, (unsigned char *)cString, length, lossy)) @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; #endif #ifdef HAVE_ISO_8859_15 case OFStringEncodingISO8859_15: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!_OFUnicodeToISO8859_15(characters, (unsigned char *)cString, length, lossy)) @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; #endif #ifdef HAVE_WINDOWS_1251 case OFStringEncodingWindows1251: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!_OFUnicodeToWindows1251(characters, (unsigned char *)cString, length, lossy)) @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; #endif #ifdef HAVE_WINDOWS_1252 case OFStringEncodingWindows1252: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!_OFUnicodeToWindows1252(characters, (unsigned char *)cString, length, lossy)) @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; #endif #ifdef HAVE_CODEPAGE_437 case OFStringEncodingCodepage437: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!_OFUnicodeToCodepage437(characters, (unsigned char *)cString, length, lossy)) @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; #endif #ifdef HAVE_CODEPAGE_850 case OFStringEncodingCodepage850: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!_OFUnicodeToCodepage850(characters, (unsigned char *)cString, length, lossy)) @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; #endif #ifdef HAVE_CODEPAGE_858 case OFStringEncodingCodepage858: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!_OFUnicodeToCodepage858(characters, (unsigned char *)cString, length, lossy)) @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; #endif #ifdef HAVE_MAC_ROMAN case OFStringEncodingMacRoman: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!_OFUnicodeToMacRoman(characters, (unsigned char *)cString, length, lossy)) @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; #endif #ifdef HAVE_KOI8_R case OFStringEncodingKOI8R: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!_OFUnicodeToKOI8R(characters, (unsigned char *)cString, length, lossy)) @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; #endif #ifdef HAVE_KOI8_U case OFStringEncodingKOI8U: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!_OFUnicodeToKOI8U(characters, (unsigned char *)cString, length, lossy)) @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; #endif default: @throw [OFInvalidArgumentException exception]; } } - (size_t)getCString: (char *)cString maxLength: (size_t)maxLength encoding: (OFStringEncoding)encoding { return [self of_getCString: cString maxLength: maxLength encoding: encoding lossy: false]; } - (size_t)getLossyCString: (char *)cString maxLength: (size_t)maxLength encoding: (OFStringEncoding)encoding { return [self of_getCString: cString maxLength: maxLength encoding: encoding lossy: true]; } - (const char *)of_cStringWithEncoding: (OFStringEncoding)encoding lossy: (bool)lossy { size_t length = self.length; char *cString; size_t cStringLength; const char *ret; switch (encoding) { case OFStringEncodingUTF8: cString = OFAllocMemory((length * 4) + 1, 1); @try { cStringLength = [self of_getCString: cString maxLength: (length * 4) + 1 encoding: OFStringEncodingUTF8 lossy: lossy]; } @catch (id e) { OFFreeMemory(cString); @throw e; } @try { cString = OFResizeMemory(cString, cStringLength + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } break; case OFStringEncodingASCII: case OFStringEncodingISO8859_1: case OFStringEncodingISO8859_2: case OFStringEncodingISO8859_3: case OFStringEncodingISO8859_15: case OFStringEncodingWindows1251: case OFStringEncodingWindows1252: case OFStringEncodingCodepage437: case OFStringEncodingCodepage850: case OFStringEncodingCodepage858: case OFStringEncodingMacRoman: case OFStringEncodingKOI8R: case OFStringEncodingKOI8U: cString = OFAllocMemory(length + 1, 1); @try { cStringLength = [self of_getCString: cString maxLength: length + 1 encoding: encoding lossy: lossy]; } @catch (id e) { OFFreeMemory(cString); @throw e; } break; default: @throw [OFInvalidArgumentException exception]; } @try { ret = [[OFData dataWithItemsNoCopy: cString count: cStringLength + 1 freeWhenDone: true] items]; } @catch (id e) { OFFreeMemory(cString); @throw e; } return ret; } - (const char *)cStringWithEncoding: (OFStringEncoding)encoding { return [self of_cStringWithEncoding: encoding lossy: false]; } - (const char *)lossyCStringWithEncoding: (OFStringEncoding)encoding { return [self of_cStringWithEncoding: encoding lossy: true]; } - (const char *)UTF8String { return [self cStringWithEncoding: OFStringEncodingUTF8]; } - (size_t)length { OF_UNRECOGNIZED_SELECTOR } - (size_t)cStringLengthWithEncoding: (OFStringEncoding)encoding { switch (encoding) { case OFStringEncodingUTF8:; const OFUnichar *characters; size_t length, UTF8StringLength = 0; characters = self.characters; length = self.length; for (size_t i = 0; i < length; i++) { char buffer[4]; size_t len = _OFUTF8StringEncode(characters[i], buffer); if (len == 0) @throw [OFInvalidEncodingException exception]; UTF8StringLength += len; } return UTF8StringLength; case OFStringEncodingASCII: case OFStringEncodingISO8859_1: case OFStringEncodingISO8859_2: case OFStringEncodingISO8859_3: case OFStringEncodingISO8859_15: case OFStringEncodingWindows1251: case OFStringEncodingWindows1252: case OFStringEncodingCodepage437: case OFStringEncodingCodepage850: case OFStringEncodingCodepage858: case OFStringEncodingMacRoman: case OFStringEncodingKOI8R: case OFStringEncodingKOI8U: return self.length; default: @throw [OFInvalidArgumentException exception]; } } - (size_t)UTF8StringLength { return [self cStringLengthWithEncoding: OFStringEncodingUTF8]; } - (OFUnichar)characterAtIndex: (size_t)idx { OF_UNRECOGNIZED_SELECTOR } - (void)getCharacters: (OFUnichar *)buffer inRange: (OFRange)range { for (size_t i = 0; i < range.length; i++) buffer[i] = [self characterAtIndex: range.location + i]; } - (bool)isEqual: (id)object { void *pool; OFString *string; const OFUnichar *characters, *otherCharacters; size_t length; if (object == self) return true; if (![object isKindOfClass: [OFString class]]) return false; string = object; length = self.length; if (string.length != length) return false; pool = objc_autoreleasePoolPush(); characters = self.characters; otherCharacters = string.characters; if (memcmp(characters, otherCharacters, length * sizeof(OFUnichar)) != 0) { objc_autoreleasePoolPop(pool); return false; } objc_autoreleasePoolPop(pool); return true; } - (id)copy { return [self retain]; } - (id)mutableCopy { return [[OFMutableString alloc] initWithString: self]; } - (OFComparisonResult)compare: (OFString *)string { void *pool; const OFUnichar *characters, *otherCharacters; size_t minimumLength; if (string == self) return OFOrderedSame; if (![string isKindOfClass: [OFString class]]) @throw [OFInvalidArgumentException exception]; minimumLength = (self.length > string.length ? string.length : self.length); pool = objc_autoreleasePoolPush(); characters = self.characters; otherCharacters = string.characters; for (size_t i = 0; i < minimumLength; i++) { if (characters[i] > otherCharacters[i]) { objc_autoreleasePoolPop(pool); return OFOrderedDescending; } if (characters[i] < otherCharacters[i]) { objc_autoreleasePoolPop(pool); return OFOrderedAscending; } } objc_autoreleasePoolPop(pool); if (self.length > string.length) return OFOrderedDescending; if (self.length < string.length) return OFOrderedAscending; return OFOrderedSame; } - (OFComparisonResult)caseInsensitiveCompare: (OFString *)string { void *pool = objc_autoreleasePoolPush(); const OFUnichar *characters, *otherCharacters; size_t length, otherLength, minimumLength; if (string == self) return OFOrderedSame; characters = self.characters; otherCharacters = string.characters; length = self.length; otherLength = string.length; minimumLength = (length > otherLength ? otherLength : length); for (size_t i = 0; i < minimumLength; i++) { OFUnichar c = characters[i]; OFUnichar oc = otherCharacters[i]; #ifdef OF_HAVE_UNICODE_TABLES if (c >> 8 < _OFUnicodeCaseFoldingTableSize) { OFUnichar tc = _OFUnicodeCaseFoldingTable[c >> 8][c & 0xFF]; if (tc) c = tc; } if (oc >> 8 < _OFUnicodeCaseFoldingTableSize) { OFUnichar tc = _OFUnicodeCaseFoldingTable[oc >> 8][oc & 0xFF]; if (tc) oc = tc; } #else c = OFASCIIToUpper(c); oc = OFASCIIToUpper(oc); #endif if (c > oc) { objc_autoreleasePoolPop(pool); return OFOrderedDescending; } if (c < oc) { objc_autoreleasePoolPop(pool); return OFOrderedAscending; } } objc_autoreleasePoolPop(pool); if (length > otherLength) return OFOrderedDescending; if (length < otherLength) return OFOrderedAscending; return OFOrderedSame; } - (unsigned long)hash { const OFUnichar *characters = self.characters; size_t length = self.length; unsigned long hash; OFHashInit(&hash); for (size_t i = 0; i < length; i++) { const OFUnichar c = characters[i]; OFHashAddByte(&hash, (c & 0xFF0000) >> 16); OFHashAddByte(&hash, (c & 0x00FF00) >> 8); OFHashAddByte(&hash, c & 0x0000FF); } OFHashFinalize(&hash); return hash; } - (OFString *)description { return [[self copy] autorelease]; } - (OFString *)JSONRepresentation { return [self of_JSONRepresentationWithOptions: 0 depth: 0]; } - (OFString *)JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options { return [self of_JSONRepresentationWithOptions: options depth: 0]; } - (OFString *) of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options depth: (size_t)depth { OFMutableString *JSON = [[self mutableCopy] autorelease]; /* FIXME: This is slow! Write it in pure C! */ [JSON replaceOccurrencesOfString: @"\\" withString: @"\\\\"]; [JSON replaceOccurrencesOfString: @"\"" withString: @"\\\""]; [JSON replaceOccurrencesOfString: @"\b" withString: @"\\b"]; [JSON replaceOccurrencesOfString: @"\f" withString: @"\\f"]; [JSON replaceOccurrencesOfString: @"\r" withString: @"\\r"]; [JSON replaceOccurrencesOfString: @"\t" withString: @"\\t"]; if (options & OFJSONRepresentationOptionJSON5) { [JSON replaceOccurrencesOfString: @"\n" withString: @"\\\n"]; if (options & OFJSONRepresentationOptionIsIdentifier) { const char *cString = self.UTF8String; if ((!OFASCIIIsAlpha(cString[0]) && cString[0] != '_' && cString[0] != '$') || strpbrk(cString, " \n\r\t\b\f\\\"'") != NULL) { [JSON insertString: @"\"" atIndex: 0]; [JSON appendString: @"\""]; } } else { [JSON insertString: @"\"" atIndex: 0]; [JSON appendString: @"\""]; } } else { [JSON replaceOccurrencesOfString: @"\n" withString: @"\\n"]; [JSON insertString: @"\"" atIndex: 0]; [JSON appendString: @"\""]; } [JSON makeImmutable]; return JSON; } - (OFData *)messagePackRepresentation { OFMutableData *data; size_t length; length = self.UTF8StringLength; if (length <= 31) { uint8_t tmp = 0xA0 | ((uint8_t)length & 0x1F); data = [OFMutableData dataWithCapacity: length + 1]; [data addItem: &tmp]; } else if (length <= UINT8_MAX) { uint8_t type = 0xD9; uint8_t tmp = (uint8_t)length; data = [OFMutableData dataWithCapacity: length + 2]; [data addItem: &type]; [data addItem: &tmp]; } else if (length <= UINT16_MAX) { uint8_t type = 0xDA; uint16_t tmp = OFToBigEndian16((uint16_t)length); data = [OFMutableData dataWithCapacity: length + 3]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (length <= UINT32_MAX) { uint8_t type = 0xDB; uint32_t tmp = OFToBigEndian32((uint32_t)length); data = [OFMutableData dataWithCapacity: length + 5]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exception]; [data addItems: self.UTF8String count: length]; return data; } - (OFRange)rangeOfString: (OFString *)string { return [self rangeOfString: string options: 0 range: OFMakeRange(0, self.length)]; } - (OFRange)rangeOfString: (OFString *)string options: (OFStringSearchOptions)options { return [self rangeOfString: string options: options range: OFMakeRange(0, self.length)]; } - (OFRange)rangeOfString: (OFString *)string options: (OFStringSearchOptions)options range: (OFRange)range { void *pool; const OFUnichar *searchCharacters; OFUnichar *characters; size_t searchLength; if ((searchLength = string.length) == 0) return OFMakeRange(0, 0); if (searchLength > range.length) return OFMakeRange(OFNotFound, 0); if (range.length > SIZE_MAX / sizeof(OFUnichar)) @throw [OFOutOfRangeException exception]; pool = objc_autoreleasePoolPush(); searchCharacters = string.characters; characters = OFAllocMemory(range.length, sizeof(OFUnichar)); @try { [self getCharacters: characters inRange: range]; if (options & OFStringSearchBackwards) { for (size_t i = range.length - searchLength;; i--) { if (memcmp(characters + i, searchCharacters, searchLength * sizeof(OFUnichar)) == 0) { objc_autoreleasePoolPop(pool); return OFMakeRange(range.location + i, searchLength); } /* No match and we're at the last character */ if (i == 0) break; } } else { for (size_t i = 0; i <= range.length - searchLength; i++) { if (memcmp(characters + i, searchCharacters, searchLength * sizeof(OFUnichar)) == 0) { objc_autoreleasePoolPop(pool); return OFMakeRange(range.location + i, searchLength); } } } } @finally { OFFreeMemory(characters); } objc_autoreleasePoolPop(pool); return OFMakeRange(OFNotFound, 0); } - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet { return [self indexOfCharacterFromSet: characterSet options: 0 range: OFMakeRange(0, self.length)]; } - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet options: (OFStringSearchOptions)options { return [self indexOfCharacterFromSet: characterSet options: options range: OFMakeRange(0, self.length)]; } - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet options: (OFStringSearchOptions)options range: (OFRange)range { bool (*characterIsMember)(id, SEL, OFUnichar) = (bool (*)(id, SEL, OFUnichar))[characterSet methodForSelector: @selector(characterIsMember:)]; OFUnichar *characters; if (range.length == 0) return OFNotFound; if (range.length > SIZE_MAX / sizeof(OFUnichar)) @throw [OFOutOfRangeException exception]; characters = OFAllocMemory(range.length, sizeof(OFUnichar)); @try { [self getCharacters: characters inRange: range]; if (options & OFStringSearchBackwards) { for (size_t i = range.length - 1;; i--) { if (characterIsMember(characterSet, @selector(characterIsMember:), characters[i])) return range.location + i; /* No match and we're at the last character */ if (i == 0) break; } } else { for (size_t i = 0; i < range.length; i++) if (characterIsMember(characterSet, @selector(characterIsMember:), characters[i])) return range.location + i; } } @finally { OFFreeMemory(characters); } return OFNotFound; } - (bool)containsString: (OFString *)string { void *pool; const OFUnichar *characters, *searchCharacters; size_t length, searchLength; if ((searchLength = string.length) == 0) return true; if (searchLength > (length = self.length)) return false; pool = objc_autoreleasePoolPush(); characters = self.characters; searchCharacters = string.characters; for (size_t i = 0; i <= length - searchLength; i++) { if (memcmp(characters + i, searchCharacters, searchLength * sizeof(OFUnichar)) == 0) { objc_autoreleasePoolPop(pool); return true; } } objc_autoreleasePoolPop(pool); return false; } - (OFString *)substringFromIndex: (size_t)idx { return [self substringWithRange: OFMakeRange(idx, self.length - idx)]; } - (OFString *)substringToIndex: (size_t)idx { return [self substringWithRange: OFMakeRange(0, idx)]; } - (OFString *)substringWithRange: (OFRange)range { void *pool; OFString *ret; if (range.length > SIZE_MAX - range.location || range.location + range.length > self.length) @throw [OFOutOfRangeException exception]; pool = objc_autoreleasePoolPush(); ret = [[OFString alloc] initWithCharacters: self.characters + range.location length: range.length]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)stringByAppendingString: (OFString *)string { OFMutableString *new; new = [OFMutableString stringWithString: self]; [new appendString: string]; [new makeImmutable]; return new; } - (OFString *)stringByAppendingFormat: (OFConstantString *)format, ... { OFString *ret; va_list arguments; va_start(arguments, format); ret = [self stringByAppendingFormat: format arguments: arguments]; va_end(arguments); return ret; } - (OFString *)stringByAppendingFormat: (OFConstantString *)format arguments: (va_list)arguments { OFMutableString *new = [OFMutableString stringWithString: self]; [new appendFormat: format arguments: arguments]; [new makeImmutable]; return new; } - (OFString *)stringByReplacingOccurrencesOfString: (OFString *)string withString: (OFString *)replacement { OFMutableString *new = [[self mutableCopy] autorelease]; [new replaceOccurrencesOfString: string withString: replacement]; [new makeImmutable]; return new; } - (OFString *)stringByReplacingOccurrencesOfString: (OFString *)string withString: (OFString *)replacement options: (int)options range: (OFRange)range { OFMutableString *new = [[self mutableCopy] autorelease]; [new replaceOccurrencesOfString: string withString: replacement options: options range: range]; [new makeImmutable]; return new; } - (OFString *)uppercaseString { OFMutableString *new = [[self mutableCopy] autorelease]; [new uppercase]; [new makeImmutable]; return new; } - (OFString *)lowercaseString { OFMutableString *new = [[self mutableCopy] autorelease]; [new lowercase]; [new makeImmutable]; return new; } - (OFString *)capitalizedString { OFMutableString *new = [[self mutableCopy] autorelease]; [new capitalize]; [new makeImmutable]; return new; } - (OFString *)stringByDeletingLeadingWhitespaces { OFMutableString *new = [[self mutableCopy] autorelease]; [new deleteLeadingWhitespaces]; [new makeImmutable]; return new; } - (OFString *)stringByDeletingTrailingWhitespaces { OFMutableString *new = [[self mutableCopy] autorelease]; [new deleteTrailingWhitespaces]; [new makeImmutable]; return new; } - (OFString *)stringByDeletingEnclosingWhitespaces { OFMutableString *new = [[self mutableCopy] autorelease]; [new deleteEnclosingWhitespaces]; [new makeImmutable]; return new; } - (bool)hasPrefix: (OFString *)prefix { OFUnichar *tmp; size_t prefixLength; bool hasPrefix; if ((prefixLength = prefix.length) > self.length) return false; tmp = OFAllocMemory(prefixLength, sizeof(OFUnichar)); @try { void *pool = objc_autoreleasePoolPush(); [self getCharacters: tmp inRange: OFMakeRange(0, prefixLength)]; hasPrefix = (memcmp(tmp, prefix.characters, prefixLength * sizeof(OFUnichar)) == 0); objc_autoreleasePoolPop(pool); } @finally { OFFreeMemory(tmp); } return hasPrefix; } - (bool)hasSuffix: (OFString *)suffix { OFUnichar *tmp; const OFUnichar *suffixCharacters; size_t length, suffixLength; bool hasSuffix; if ((suffixLength = suffix.length) > self.length) return false; length = self.length; tmp = OFAllocMemory(suffixLength, sizeof(OFUnichar)); @try { void *pool = objc_autoreleasePoolPush(); [self getCharacters: tmp inRange: OFMakeRange(length - suffixLength, suffixLength)]; suffixCharacters = suffix.characters; hasSuffix = (memcmp(tmp, suffixCharacters, suffixLength * sizeof(OFUnichar)) == 0); objc_autoreleasePoolPop(pool); } @finally { OFFreeMemory(tmp); } return hasSuffix; } - (OFArray *)componentsSeparatedByString: (OFString *)delimiter { return [self componentsSeparatedByString: delimiter options: 0]; } - (OFArray *)componentsSeparatedByString: (OFString *)delimiter options: (OFStringSeparationOptions)options { void *pool; OFMutableArray *array; const OFUnichar *characters, *delimiterCharacters; bool skipEmpty = (options & OFStringSkipEmptyComponents); size_t length = self.length; size_t delimiterLength = delimiter.length; size_t last; OFString *component; if (delimiter == nil) @throw [OFInvalidArgumentException exception]; if (delimiter.length == 0) return [OFArray arrayWithObject: self]; array = [OFMutableArray array]; pool = objc_autoreleasePoolPush(); characters = self.characters; delimiterCharacters = delimiter.characters; if (delimiterLength > length) { [array addObject: [[self copy] autorelease]]; [array makeImmutable]; objc_autoreleasePoolPop(pool); return array; } last = 0; for (size_t i = 0; i <= length - delimiterLength; i++) { if (memcmp(characters + i, delimiterCharacters, delimiterLength * sizeof(OFUnichar)) != 0) continue; component = [self substringWithRange: OFMakeRange(last, i - last)]; if (!skipEmpty || component.length > 0) [array addObject: component]; i += delimiterLength - 1; last = i + 1; } component = [self substringWithRange: OFMakeRange(last, length - last)]; if (!skipEmpty || component.length > 0) [array addObject: component]; [array makeImmutable]; objc_autoreleasePoolPop(pool); return array; } - (OFArray *) componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet { return [self componentsSeparatedByCharactersInSet: characterSet options: 0]; } - (OFArray *) componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet options: (OFStringSeparationOptions)options { OFMutableArray *array = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); bool skipEmpty = (options & OFStringSkipEmptyComponents); const OFUnichar *characters = self.characters; size_t length = self.length; bool (*characterIsMember)(id, SEL, OFUnichar) = (bool (*)(id, SEL, OFUnichar))[characterSet methodForSelector: @selector(characterIsMember:)]; size_t last; last = 0; for (size_t i = 0; i < length; i++) { if (characterIsMember(characterSet, @selector(characterIsMember:), characters[i])) { if (!skipEmpty || i != last) { OFString *component = [self substringWithRange: OFMakeRange(last, i - last)]; [array addObject: component]; } last = i + 1; } } if (!skipEmpty || length != last) { OFString *component = [self substringWithRange: OFMakeRange(last, length - last)]; [array addObject: component]; } [array makeImmutable]; objc_autoreleasePoolPop(pool); return array; } - (long long)longLongValue { return [self longLongValueWithBase: 10]; } - (long long)longLongValueWithBase: (unsigned char)base { void *pool = objc_autoreleasePoolPush(); const char *UTF8String = self.UTF8String; bool negative = false; long long value = 0; while (OFASCIIIsSpace(*UTF8String)) UTF8String++; switch (*UTF8String) { case '-': negative = true; case '+': UTF8String++; } if (UTF8String[0] == '0') { if (UTF8String[1] == 'x') { if (base == 0) base = 16; if (base != 16 || UTF8String[2] == '\0') @throw [OFInvalidFormatException exception]; UTF8String += 2; } else { if (base == 0) base = 8; UTF8String++; } } if (base == 0) base = 10; while (*UTF8String != '\0') { unsigned char c = OFASCIIToUpper(*UTF8String++); if (c >= '0' && c <= '9') c -= '0'; else if (c >= 'A' && c <= 'Z') c -= ('A' - 10); else if (OFASCIIIsSpace(c)) { while (*UTF8String != '\0') if (!OFASCIIIsSpace(*UTF8String++)) @throw [OFInvalidFormatException exception]; break; } else @throw [OFInvalidFormatException exception]; if (c >= base) @throw [OFInvalidFormatException exception]; if (LLONG_MAX / base < value || LLONG_MAX - (value * base) < c) @throw [OFOutOfRangeException exception]; value = (value * base) + c; } if (negative) value *= -1; objc_autoreleasePoolPop(pool); return value; } - (unsigned long long)unsignedLongLongValue { return [self unsignedLongLongValueWithBase: 10]; } - (unsigned long long)unsignedLongLongValueWithBase: (unsigned char)base { void *pool = objc_autoreleasePoolPush(); const char *UTF8String = self.UTF8String; unsigned long long value = 0; while (OFASCIIIsSpace(*UTF8String)) UTF8String++; switch (*UTF8String) { case '-': @throw [OFInvalidFormatException exception]; case '+': UTF8String++; } if (UTF8String[0] == '0') { if (UTF8String[1] == 'x') { if (base == 0) base = 16; if (base != 16 || UTF8String[2] == '\0') @throw [OFInvalidFormatException exception]; UTF8String += 2; } else { if (base == 0) base = 8; UTF8String++; } } if (base == 0) base = 10; while (*UTF8String != '\0') { unsigned char c = OFASCIIToUpper(*UTF8String++); if (c >= '0' && c <= '9') c -= '0'; else if (c >= 'A' && c <= 'Z') c -= ('A' - 10); else if (OFASCIIIsSpace(c)) { while (*UTF8String != '\0') if (!OFASCIIIsSpace(*UTF8String++)) @throw [OFInvalidFormatException exception]; break; } else @throw [OFInvalidFormatException exception]; if (c >= base) @throw [OFInvalidFormatException exception]; if (ULLONG_MAX / base < value || ULLONG_MAX - (value * base) < c) @throw [OFOutOfRangeException exception]; value = (value * base) + c; } objc_autoreleasePoolPop(pool); return value; } - (float)floatValue { void *pool = objc_autoreleasePoolPush(); OFString *stripped = self.stringByDeletingEnclosingWhitespaces; if ([stripped caseInsensitiveCompare: @"INF"] == OFOrderedSame || [stripped caseInsensitiveCompare: @"INFINITY"] == OFOrderedSame) return INFINITY; if ([stripped caseInsensitiveCompare: @"-INF"] == OFOrderedSame || [stripped caseInsensitiveCompare: @"-INFINITY"] == OFOrderedSame) return -INFINITY; if ([stripped caseInsensitiveCompare: @"NAN"] == OFOrderedSame) return NAN; if ([stripped caseInsensitiveCompare: @"-NAN"] == OFOrderedSame) return -NAN; #if defined(HAVE_STRTOF_L) || defined(HAVE_USELOCALE) const char *UTF8String = self.UTF8String; #else OFString *decimalSeparator = [OFLocale decimalSeparator]; const char *UTF8String; if ([decimalSeparator isEqual: @"."]) UTF8String = self.UTF8String; else /* * If we have no strtof_l, we have no other choice than to * replace the locale's decimal point with something that will * be rejected and replacing "." with the locale's decimal * point. */ UTF8String = [[self stringByReplacingOccurrencesOfString: decimalSeparator withString: @"!"] stringByReplacingOccurrencesOfString: @"." withString: decimalSeparator] .UTF8String; #endif char *endPtr = NULL; float value; errno = 0; #if defined(HAVE_STRTOF_L) value = strtof_l(UTF8String, &endPtr, cLocale); #elif defined(HAVE_USELOCALE) locale_t previousLocale = uselocale(cLocale); value = strtof(UTF8String, &endPtr); uselocale(previousLocale); #else value = strtof(UTF8String, &endPtr); #endif if (value == HUGE_VALF && errno == ERANGE) @throw [OFOutOfRangeException exception]; /* Check if there are any invalid chars left */ if (endPtr != NULL) for (; *endPtr != '\0'; endPtr++) /* Use isspace since strtof uses the same. */ if (!isspace((unsigned char)*endPtr)) @throw [OFInvalidFormatException exception]; objc_autoreleasePoolPop(pool); return value; } - (double)doubleValue { void *pool = objc_autoreleasePoolPush(); OFString *stripped = self.stringByDeletingEnclosingWhitespaces; if ([stripped caseInsensitiveCompare: @"INF"] == OFOrderedSame || [stripped caseInsensitiveCompare: @"INFINITY"] == OFOrderedSame) return INFINITY; if ([stripped caseInsensitiveCompare: @"-INF"] == OFOrderedSame || [stripped caseInsensitiveCompare: @"-INFINITY"] == OFOrderedSame) return -INFINITY; if ([stripped caseInsensitiveCompare: @"NAN"] == OFOrderedSame) return NAN; if ([stripped caseInsensitiveCompare: @"-NAN"] == OFOrderedSame) return -NAN; #if defined(HAVE_STRTOD_L) || defined(HAVE_USELOCALE) const char *UTF8String = self.UTF8String; #else OFString *decimalSeparator = [OFLocale decimalSeparator]; const char *UTF8String; if ([decimalSeparator isEqual: @"."]) UTF8String = self.UTF8String; else /* * If we have no strtod_l, we have no other choice than to * replace the locale's decimal point with something that will * be rejected and replacing "." with the locale's decimal * point. */ UTF8String = [[self stringByReplacingOccurrencesOfString: decimalSeparator withString: @"!"] stringByReplacingOccurrencesOfString: @"." withString: decimalSeparator] .UTF8String; #endif char *endPtr = NULL; double value; errno = 0; #if defined(HAVE_STRTOD_L) value = strtod_l(UTF8String, &endPtr, cLocale); #elif defined(HAVE_USELOCALE) locale_t previousLocale = uselocale(cLocale); value = strtod(UTF8String, &endPtr); uselocale(previousLocale); #else value = strtod(UTF8String, &endPtr); #endif if (value == HUGE_VAL && errno == ERANGE) @throw [OFOutOfRangeException exception]; /* Check if there are any invalid chars left */ if (endPtr != NULL) for (; *endPtr != '\0'; endPtr++) /* Use isspace since strtod uses the same. */ if (!isspace((unsigned char)*endPtr)) @throw [OFInvalidFormatException exception]; objc_autoreleasePoolPop(pool); return value; } - (const OFUnichar *)characters { size_t length = self.length; OFUnichar *buffer; const OFUnichar *ret; buffer = OFAllocMemory(length, sizeof(OFUnichar)); @try { [self getCharacters: buffer inRange: OFMakeRange(0, length)]; ret = [[OFData dataWithItemsNoCopy: buffer count: length itemSize: sizeof(OFUnichar) freeWhenDone: true] items]; } @catch (id e) { OFFreeMemory(buffer); @throw e; } return ret; } - (const OFChar16 *)UTF16String { return [self UTF16StringWithByteOrder: OFByteOrderNative]; } - (const OFChar16 *)UTF16StringWithByteOrder: (OFByteOrder)byteOrder { void *pool = objc_autoreleasePoolPush(); const OFUnichar *characters = self.characters; size_t length = self.length; OFChar16 *buffer; size_t j; bool swap = (byteOrder != OFByteOrderNative); const OFChar16 *ret; /* Allocate memory for the worst case */ buffer = OFAllocMemory((length + 1) * 2, sizeof(OFChar16)); j = 0; for (size_t i = 0; i < length; i++) { OFUnichar c = characters[i]; if (c > 0x10FFFF) { OFFreeMemory(buffer); @throw [OFInvalidEncodingException exception]; } if (swap) { if (c > 0xFFFF) { c -= 0x10000; buffer[j++] = OFByteSwap16(0xD800 | (c >> 10)); buffer[j++] = OFByteSwap16(0xDC00 | (c & 0x3FF)); } else buffer[j++] = OFByteSwap16(c); } else { if (c > 0xFFFF) { c -= 0x10000; buffer[j++] = 0xD800 | (c >> 10); buffer[j++] = 0xDC00 | (c & 0x3FF); } else buffer[j++] = c; } } buffer[j] = 0; @try { buffer = OFResizeMemory(buffer, j + 1, sizeof(OFChar16)); } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } objc_autoreleasePoolPop(pool); @try { ret = [[OFData dataWithItemsNoCopy: buffer count: j + 1 itemSize: sizeof(OFChar16) freeWhenDone: true] items]; } @catch (id e) { OFFreeMemory(buffer); @throw e; } return ret; } - (size_t)UTF16StringLength { const OFUnichar *characters = self.characters; size_t length, UTF16StringLength; length = UTF16StringLength = self.length; for (size_t i = 0; i < length; i++) if (characters[i] > 0xFFFF) UTF16StringLength++; return UTF16StringLength; } - (const OFChar32 *)UTF32String { return [self UTF32StringWithByteOrder: OFByteOrderNative]; } - (const OFChar32 *)UTF32StringWithByteOrder: (OFByteOrder)byteOrder { size_t length = self.length; OFChar32 *buffer; const OFChar32 *ret; buffer = OFAllocMemory(length + 1, sizeof(OFChar32)); @try { [self getCharacters: buffer inRange: OFMakeRange(0, length)]; buffer[length] = 0; if (byteOrder != OFByteOrderNative) for (size_t i = 0; i < length; i++) buffer[i] = OFByteSwap32(buffer[i]); ret = [[OFData dataWithItemsNoCopy: buffer count: length + 1 itemSize: sizeof(OFChar32) freeWhenDone: true] items]; } @catch (id e) { OFFreeMemory(buffer); @throw e; } return ret; } - (OFData *)dataWithEncoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFData *data = [OFData dataWithItems: [self cStringWithEncoding: encoding] count: [self cStringLengthWithEncoding: encoding]]; [data retain]; objc_autoreleasePoolPop(pool); return [data autorelease]; } #ifdef OF_WINDOWS - (OFString *)stringByExpandingWindowsEnvironmentStrings { if ([OFSystemInfo isWindowsNT]) { wchar_t buffer[512]; size_t length; if ((length = ExpandEnvironmentStringsW(self.UTF16String, buffer, sizeof(buffer))) == 0) return self; return [OFString stringWithUTF16String: buffer length: length - 1]; } else { OFStringEncoding encoding = [OFLocale encoding]; char buffer[512]; size_t length; if ((length = ExpandEnvironmentStringsA( [self cStringWithEncoding: encoding], buffer, sizeof(buffer))) == 0) return self; return [OFString stringWithCString: buffer encoding: encoding length: length - 1]; } } #endif #ifdef OF_HAVE_FILES - (void)writeToFile: (OFString *)path { [self writeToFile: path encoding: OFStringEncodingUTF8]; } - (void)writeToFile: (OFString *)path encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFFile *file = [OFFile fileWithPath: path mode: @"w"]; [file writeString: self encoding: encoding]; objc_autoreleasePoolPop(pool); } #endif - (void)writeToIRI: (OFIRI *)IRI { [self writeToIRI: IRI encoding: OFStringEncodingUTF8]; } - (void)writeToIRI: (OFIRI *)IRI encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFStream *stream; stream = [OFIRIHandler openItemAtIRI: IRI mode: @"w"]; [stream writeString: self encoding: encoding]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS - (void)enumerateLinesUsingBlock: (OFStringLineEnumerationBlock)block { void *pool = objc_autoreleasePoolPush(); const OFUnichar *characters = self.characters; size_t i, last = 0, length = self.length; bool stop = false, lastCarriageReturn = false; for (i = 0; i < length && !stop; i++) { if (lastCarriageReturn && characters[i] == '\n') { lastCarriageReturn = false; last++; continue; } if (characters[i] == '\n' || characters[i] == '\r') { void *pool2 = objc_autoreleasePoolPush(); block([self substringWithRange: OFMakeRange(last, i - last)], &stop); last = i + 1; objc_autoreleasePoolPop(pool2); } lastCarriageReturn = (characters[i] == '\r'); } if (!stop) block([self substringWithRange: OFMakeRange(last, i - last)], &stop); objc_autoreleasePoolPop(pool); } #endif @end objfw-1.1.6/src/OFSubarray.h000066400000000000000000000016641465614216400156230ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFArray.h" OF_ASSUME_NONNULL_BEGIN @interface OFSubarray: OFArray { OFArray *_array; OFRange _range; } - (instancetype)initWithArray: (OFArray *)array range: (OFRange)range; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFSubarray.m000066400000000000000000000050151465614216400156220ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFSubarray.h" #import "OFOutOfRangeException.h" @implementation OFSubarray + (instancetype)arrayWithArray: (OFArray *)array range: (OFRange)range { return [[[self alloc] initWithArray: array range: range] autorelease]; } - (instancetype)initWithArray: (OFArray *)array range: (OFRange)range { self = [super init]; @try { /* Should usually be retain, as it's useless with a copy */ _array = [array copy]; _range = range; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_array release]; [super dealloc]; } - (size_t)count { return _range.length; } - (id)objectAtIndex: (size_t)idx { if (idx >= _range.length) @throw [OFOutOfRangeException exception]; return [_array objectAtIndex: idx + _range.location]; } - (void)getObjects: (id *)buffer inRange: (OFRange)range { if (range.length > SIZE_MAX - range.location || range.location + range.length > _range.length) @throw [OFOutOfRangeException exception]; range.location += _range.location; [_array getObjects: buffer inRange: range]; } - (size_t)indexOfObject: (id)object { size_t idx = [_array indexOfObject: object]; if (idx < _range.location) return OFNotFound; idx -= _range.location; if (idx >= _range.length) return OFNotFound; return idx; } - (size_t)indexOfObjectIdenticalTo: (id)object { size_t idx = [_array indexOfObjectIdenticalTo: object]; if (idx < _range.location) return OFNotFound; idx -= _range.location; if (idx >= _range.length) return OFNotFound; return idx; } - (OFArray *)objectsInRange: (OFRange)range { if (range.length > SIZE_MAX - range.location || range.location + range.length > _range.length) @throw [OFOutOfRangeException exception]; range.location += _range.location; return [_array objectsInRange: range]; } @end objfw-1.1.6/src/OFSubdata.h000066400000000000000000000016541465614216400154150ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFData.h" OF_ASSUME_NONNULL_BEGIN @interface OFSubdata: OFData { OFData *_data; OFRange _range; } - (instancetype)initWithData: (OFData *)data range: (OFRange)range; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFSubdata.m000066400000000000000000000024761465614216400154250ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFSubdata.h" @implementation OFSubdata - (instancetype)initWithData: (OFData *)data range: (OFRange)range { self = [super init]; @try { /* Should usually be retain, as it's useless with a copy */ _data = [data copy]; _range = range; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_data release]; [super dealloc]; } - (size_t)count { return _range.length; } - (size_t)itemSize { return _data.itemSize; } - (const void *)items { return (const unsigned char *)_data.items + (_range.location * _data.itemSize); } @end objfw-1.1.6/src/OFSubprocess.h000066400000000000000000000167011465614216400161610ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif #include "objfw-defs.h" #ifdef OF_HAVE_SYS_TYPES_H # include #endif #import "OFStream.h" #import "OFKernelEventObserver.h" #import "OFString.h" #ifdef OF_WINDOWS # include #endif OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFDictionary OF_GENERIC(KeyType, ObjectType); /** * @class OFSubprocess OFSubprocess.h ObjFW/OFSubprocess.h * * @brief A class for stream-like communication with a newly created subprocess. */ OF_SUBCLASSING_RESTRICTED @interface OFSubprocess: OFStream #ifndef OF_WINDOWS #endif { #ifndef OF_WINDOWS pid_t _pid; int _readPipe[2], _writePipe[2]; #else HANDLE _handle, _readPipe[2], _writePipe[2]; #endif int _status; bool _atEndOfStream; } /** * @brief Creates a new OFSubprocess with the specified program and invokes the * program. * * @param program The program to execute. If it does not start with a slash, the * search path specified in PATH is used. * @return A new, autoreleased OFSubprocess. */ + (instancetype)subprocessWithProgram: (OFString *)program; /** * @brief Creates a new OFSubprocess with the specified program and arguments * and invokes the program. * * @param program The program to execute. If it does not start with a slash, the * search path specified in PATH is used. * @param arguments The arguments to pass to the program, or `nil` * @return A new, autoreleased OFSubprocess. */ + (instancetype) subprocessWithProgram: (OFString *)program arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments; /** * @brief Creates a new OFSubprocess with the specified program, program name * and arguments and invokes the program. * * @param program The program to execute. If it does not start with a slash, the * search path specified in PATH is used. * @param programName The program name for the program to invoke (argv[0]). * Usually, this is equal to program. * @param arguments The arguments to pass to the program, or `nil` * @return A new, autoreleased OFSubprocess. */ + (instancetype) subprocessWithProgram: (OFString *)program programName: (OFString *)programName arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments; /** * @brief Creates a new OFSubprocess with the specified program, program name, * arguments and environment and invokes the program. * * @param program The program to execute. If it does not start with a slash, the * search path specified in PATH is used. * @param programName The program name for the program to invoke (argv[0]). * Usually, this is equal to program. * @param arguments The arguments to pass to the program, or `nil` * @param environment The environment to pass to the program, or `nil`. If it * is not `nil`, the passed dictionary will be used to * override the environment. If you want to add to the * existing environment, you need to get the existing * environment first, copy it, modify it and then pass it. * @return A new, autoreleased OFSubprocess. */ + (instancetype) subprocessWithProgram: (OFString *)program programName: (OFString *)programName arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments environment: (nullable OFDictionary OF_GENERIC(OFString *, OFString *) *)environment; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFSubprocess with the specified * program and invokes the program. * * @param program The program to execute. If it does not start with a slash, the * search path specified in PATH is used. * @return An initialized OFSubprocess. */ - (instancetype)initWithProgram: (OFString *)program; /** * @brief Initializes an already allocated OFSubprocess with the specified * program and arguments and invokes the program. * * @param program The program to execute. If it does not start with a slash, the * search path specified in PATH is used. * @param arguments The arguments to pass to the program, or `nil` * @return An initialized OFSubprocess. */ - (instancetype) initWithProgram: (OFString *)program arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments; /** * @brief Initializes an already allocated OFSubprocess with the specified * program, program name and arguments and invokes the program. * * @param program The program to execute. If it does not start with a slash, the * search path specified in PATH is used. * @param programName The program name for the program to invoke (argv[0]). * Usually, this is equal to program. * @param arguments The arguments to pass to the program, or `nil` * @return An initialized OFSubprocess. */ - (instancetype) initWithProgram: (OFString *)program programName: (OFString *)programName arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments; /** * @brief Initializes an already allocated OFSubprocess with the specified * program, program name, arguments and environment and invokes the * program. * * @param program The program to execute. If it does not start with a slash, the * search path specified in PATH is used. * @param programName The program name for the program to invoke (argv[0]). * Usually, this is equal to program. * @param arguments The arguments to pass to the program, or `nil` * @param environment The environment to pass to the program, or `nil`. If it * is not `nil`, the passed dictionary will be used to * override the environment. If you want to add to the * existing environment, you need to get the existing * environment first, copy it, modify it and then pass it. * @return An initialized OFSubprocess. */ - (instancetype) initWithProgram: (OFString *)program programName: (OFString *)programName arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments environment: (nullable OFDictionary OF_GENERIC(OFString *, OFString *) *)environment OF_DESIGNATED_INITIALIZER; /** * @brief Closes the write direction of the subprocess. * * This method needs to be called for some programs before data can be read, * since some programs don't start processing before the write direction is * closed. * * @throw OFNotOpenException The subprocess was already closed */ - (void)closeForWriting; /** * @brief Waits for the subprocess to terminate and returns the exit status. * * If the subprocess has already exited, this returns the exit status * immediately. * * @return The status code of the subprocess * @throw OFNotOpenException The subprocess was already closed */ - (int)waitForTermination; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFSubprocess.m000066400000000000000000000015751465614216400161710ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" #ifdef OF_WINDOWS # include "platform/Windows/OFSubprocess.m" #else # include "platform/POSIX/OFSubprocess.m" #endif objfw-1.1.6/src/OFSystemInfo+NetworkInterfaces.h000066400000000000000000000053561465614216400215660ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFSystemInfo.h" OF_ASSUME_NONNULL_BEGIN /** * @brief A dictionary describing a network interface, as returned by * @ref networkInterfaces. * * Keys are of type @ref OFNetworkInterfaceKey. */ typedef OFDictionary OF_GENERIC(OFString *, id) *OFNetworkInterface; /** * @brief A key of an @ref OFNetworkInterface. * * Possible values are: * * * @ref OFNetworkInterfaceIndex */ typedef OFConstantString *OFNetworkInterfaceKey; /** * @brief The index of a network interface. * * This maps to an @ref OFNumber. */ extern OFNetworkInterfaceKey OFNetworkInterfaceIndex; /** * @brief The hardware address of a network interface. * * This maps to an @ref OFData. */ extern OFNetworkInterfaceKey OFNetworkInterfaceHardwareAddress; /** * @brief The IPv4 addresses of a network interface. * * This maps to an @ref OFData of @ref OFSocketAddress. */ extern OFNetworkInterfaceKey OFNetworkInterfaceIPv4Addresses; #ifdef OF_HAVE_IPV6 /** * @brief The IPv6 addresses of a network interface. * * This maps to an @ref OFData of @ref OFSocketAddress. */ extern OFNetworkInterfaceKey OFNetworkInterfaceIPv6Addresses; #endif #ifdef OF_HAVE_IPX /** * @brief The IPX addresses of a network interface. * * This maps to an @ref OFData of @ref OFSocketAddress. */ extern OFNetworkInterfaceKey OFNetworkInterfaceIPXAddresses; #endif #ifdef OF_HAVE_APPLETALK /** * @brief The AppleTalk addresses of a network interface. * * This maps to an @ref OFData of @ref OFSocketAddress. */ extern OFNetworkInterfaceKey OFNetworkInterfaceAppleTalkAddresses; #endif @interface OFSystemInfo (NetworkInterfaces) #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nullable, nonatomic) OFDictionary OF_GENERIC(OFString *, OFNetworkInterface) *networkInterfaces; #endif /** * @brief Returns the available (though not necessarily configured) network * interfaces. * * @return The available network interfaces */ + (nullable OFDictionary OF_GENERIC(OFString *, OFNetworkInterface) *) networkInterfaces; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFSystemInfo+NetworkInterfaces.m000066400000000000000000000030621465614216400215630ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFSystemInfo.h" OFNetworkInterfaceKey OFNetworkInterfaceIndex = @"OFNetworkInterfaceIndex"; OFNetworkInterfaceKey OFNetworkInterfaceHardwareAddress = @"OFNetworkInterfaceHardwareAddress"; OFNetworkInterfaceKey OFNetworkInterfaceIPv4Addresses = @"OFNetworkInterfaceIPv4Addresses"; #ifdef OF_HAVE_IPV6 OFNetworkInterfaceKey OFNetworkInterfaceIPv6Addresses = @"OFNetworkInterfaceIPv6Addresses"; #endif #ifdef OF_HAVE_IPX OFNetworkInterfaceKey OFNetworkInterfaceIPXAddresses = @"OFNetworkInterfaceIPXAddresses"; #endif #ifdef OF_HAVE_APPLETALK OFNetworkInterfaceKey OFNetworkInterfaceAppleTalkAddresses = @"OFNetworkInterfaceAppleTalkAddresses"; #endif #ifdef OF_WINDOWS # include "platform/Windows/OFSystemInfo+NetworkInterfaces.m" #else # include "platform/POSIX/OFSystemInfo+NetworkInterfaces.m" #endif objfw-1.1.6/src/OFSystemInfo.h000066400000000000000000000401251465614216400161260ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @class OFDictionary OF_GENERIC(KeyType, ObjectType); @class OFIRI; /** * @class OFSystemInfo OFSystemInfo.h ObjFW/OFSystemInfo.h * * @brief A class for querying information about the system. */ OF_SUBCLASSING_RESTRICTED @interface OFSystemInfo: OFObject #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nonatomic) size_t pageSize; @property (class, readonly, nonatomic) size_t numberOfCPUs; @property (class, readonly, nonatomic) OFString *ObjFWVersion; @property (class, readonly, nonatomic) unsigned short ObjFWVersionMajor; @property (class, readonly, nonatomic) unsigned short ObjFWVersionMinor; @property (class, readonly, nullable, nonatomic) OFString *operatingSystemName; @property (class, readonly, nullable, nonatomic) OFString *operatingSystemVersion; #if defined(OF_WINDOWS) || defined(DOXYGEN) @property (class, readonly, nullable, nonatomic) OFString *wineVersion; #endif @property (class, readonly, nullable, nonatomic) OFIRI *userDataIRI; @property (class, readonly, nullable, nonatomic) OFIRI *userConfigIRI; @property (class, readonly, nullable, nonatomic) OFIRI *temporaryDirectoryIRI; @property (class, readonly, nullable, nonatomic) OFString *CPUVendor; @property (class, readonly, nullable, nonatomic) OFString *CPUModel; # if defined(OF_AMD64) || defined(OF_X86) || defined(DOXYGEN) @property (class, readonly, nonatomic) bool supportsMMX; @property (class, readonly, nonatomic) bool supports3DNow; @property (class, readonly, nonatomic) bool supportsEnhanced3DNow; @property (class, readonly, nonatomic) bool supportsSSE; @property (class, readonly, nonatomic) bool supportsSSE2; @property (class, readonly, nonatomic) bool supportsSSE3; @property (class, readonly, nonatomic) bool supportsSSSE3; @property (class, readonly, nonatomic) bool supportsSSE41; @property (class, readonly, nonatomic) bool supportsSSE42; @property (class, readonly, nonatomic) bool supportsAVX; @property (class, readonly, nonatomic) bool supportsAVX2; @property (class, readonly, nonatomic) bool supportsAESNI; @property (class, readonly, nonatomic) bool supportsSHAExtensions; @property (class, readonly, nonatomic) bool supportsFusedMultiplyAdd; @property (class, readonly, nonatomic) bool supportsF16C; @property (class, readonly, nonatomic) bool supportsAVX512Foundation; @property (class, readonly, nonatomic) bool supportsAVX512ConflictDetectionInstructions; @property (class, readonly, nonatomic) bool supportsAVX512ExponentialAndReciprocalInstructions; @property (class, readonly, nonatomic) bool supportsAVX512PrefetchInstructions; @property (class, readonly, nonatomic) bool supportsAVX512VectorLengthExtensions; @property (class, readonly, nonatomic) bool supportsAVX512DoublewordAndQuadwordInstructions; @property (class, readonly, nonatomic) bool supportsAVX512ByteAndWordInstructions; @property (class, readonly, nonatomic) bool supportsAVX512IntegerFusedMultiplyAdd; @property (class, readonly, nonatomic) bool supportsAVX512VectorByteManipulationInstructions; @property (class, readonly, nonatomic) bool supportsAVX512VectorPopulationCountInstruction; @property (class, readonly, nonatomic) bool supportsAVX512VectorNeuralNetworkInstructions; @property (class, readonly, nonatomic) bool supportsAVX512VectorByteManipulationInstructions2; @property (class, readonly, nonatomic) bool supportsAVX512BitAlgorithms; @property (class, readonly, nonatomic) bool supportsAVX512Float16Instructions; @property (class, readonly, nonatomic) bool supportsAVX512BFloat16Instructions; # endif # if defined(OF_POWERPC) || defined(OF_POWERPC64) || defined(DOXYGEN) @property (class, readonly, nonatomic) bool supportsAltiVec; # endif # if defined(OF_WINDOWS) || defined(DOXYGEN) @property (class, readonly, nonatomic, getter=isWindowsNT) bool windowsNT; # endif #endif /** * @brief Returns the size of a page. * * @return The size of a page */ + (size_t)pageSize; /** * @brief Returns the number of CPUs installed in the system. * * A CPU with multiple cores counts as multiple CPUs. * * If the system has no CPU, the return value is undefined. * * @return The number of CPUs installed in the system */ + (size_t)numberOfCPUs; /** * @brief The version of ObjFW. * * @return The version of ObjFW */ + (OFString *)ObjFWVersion; /** * @brief The major version of ObjFW. * * @return The major version of ObjFW */ + (unsigned short)ObjFWVersionMajor; /** * @brief The minor version of ObjFW. * * @return The minor version of ObjFW */ + (unsigned short)ObjFWVersionMinor; /** * @brief Returns the name of the operating system the application is running * on. * * @return The name of the operating system the application is running on */ + (nullable OFString *)operatingSystemName; /** * @brief Returns the version of the operating system the application is * running on. * * @return The version of the operating system the application is running on */ + (nullable OFString *)operatingSystemVersion; #if defined(OF_WINDOWS) || defined(DOXYGEN) /** * @brief Returns the version of Wine the application is running on, or `nil` * if not running on Wine (e.g. on Windows natively). * * @note This is only available on Windows. * * @return The version of Wine the application is running on, or `nil` if not * running on Wine (e.g. on Windows natively) */ + (nullable OFString *)wineVersion; #endif /** * @brief Returns the path where user data for the application can be stored. * * On UNIX systems, this adheres to the XDG Base Directory specification.@n * On macOS and iOS, it uses the `NSApplicationSupportDirectory` directory.@n * On Windows, it uses the `APPDATA` environment variable.@n * On Haiku, it uses the `B_USER_SETTINGS_DIRECTORY` directory.@n * On AmigaOS and MorphOS, it returns `PROGDIR:`. * * @return The path where user data for the application can be stored */ + (nullable OFIRI *)userDataIRI; /** * @brief Returns the path where user configuration for the application can be * stored. * * On UNIX systems, this adheres to the XDG Base Directory specification.@n * On macOS and iOS, it uses the `Preferences` directory inside of * `NSLibraryDirectory` directory.@n * On Windows, it uses the `APPDATA` environment variable.@n * On Haiku, it uses the `B_USER_SETTINGS_DIRECTORY` directory. * On AmigaOS and MorphOS, it returns `PROGDIR:`. * * @return The path where user configuration for the application can be stored */ + (nullable OFIRI *)userConfigIRI; /** * @brief Returns a path where temporary files for can be stored. * * If possible, returns a temporary directory for the user, otherwise returns a * global temporary directory. * * On UNIX systems, this adheres to the XDG Base Directory specification and * returns `/tmp` if `XDG_RUNTIME_DIR` is not set.@n * On macOS and iOS, this uses `_CS_DARWIN_USER_TEMP_DIR`, falling back to * `/tmp` if this fails.@n * On Windows, it uses `GetTempPath`.@n * On Haiku, it uses the `B_SYSTEM_TEMP_DIRECTORY` directory. * On AmigaOS and MorphOS, it returns `T:`. * * @return A path where temporary files can be stored */ + (nullable OFIRI *)temporaryDirectoryIRI; /** * @brief Returns the vendor of the CPU. * * If the vendor could not be determined, `nil` is returned instead. * * @return The vendor of the CPU */ + (nullable OFString *)CPUVendor; /** * @brief Returns the model of the CPU. * * If the model could not be determined, `nil` is returned instead. * * @return The model of the CPU */ + (nullable OFString *)CPUModel; #if defined(OF_AMD64) || defined(OF_X86) || defined(DOXYGEN) /** * @brief Returns whether the CPU supports MMX. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU supports MMX */ + (bool)supportsMMX; /** * @brief Returns whether the CPU supports 3DNow!. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU supports 3DNow! */ + (bool)supports3DNow; /** * @brief Returns whether the CPU supports enhanced 3DNow!. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU supports enhanced 3DNow! */ + (bool)supportsEnhanced3DNow; /** * @brief Returns whether the CPU supports SSE. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU supports SSE */ + (bool)supportsSSE; /** * @brief Returns whether the CPU supports SSE2. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU supports SSE2 */ + (bool)supportsSSE2; /** * @brief Returns whether the CPU supports SSE3. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU supports SSE3 */ + (bool)supportsSSE3; /** * @brief Returns whether the CPU supports SSSE3. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU supports SSSE3 */ + (bool)supportsSSSE3; /** * @brief Returns whether the CPU supports SSE4.1. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU supports SSE4.1 */ + (bool)supportsSSE41; /** * @brief Returns whether the CPU supports SSE4.2. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU supports SSE4.2 */ + (bool)supportsSSE42; /** * @brief Returns whether the CPU and OS support AVX. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU and OS support AVX */ + (bool)supportsAVX; /** * @brief Returns whether the CPU and OS support AVX2. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU and OS support AVX2 */ + (bool)supportsAVX2; /** * @brief Returns whether the CPU supports AES-NI. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU supports AES-NI */ + (bool)supportsAESNI; /** * @brief Returns whether the CPU supports Intel SHA Extensions. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU supports Intel SHA Extensions */ + (bool)supportsSHAExtensions; /** * @brief Returns whether the CPU supports fused multiply-add. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU supports fused multiply-add */ + (bool)supportsFusedMultiplyAdd; /** * @brief Returns whether the CPU supports F16C. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU supports F16C */ + (bool)supportsF16C; /** * @brief Returns whether the CPU and OS support AVX-512 Foundation. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU and OS support AVX-512 Foundation */ + (bool)supportsAVX512Foundation; /** * @brief Returns whether the CPU and OS support AVX-512 Conflict Detection * Instructions. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU and OS support AVX-512 Conflict Detection * Instructions */ + (bool)supportsAVX512ConflictDetectionInstructions; /** * @brief Returns whether the CPU and OS support AVX-512 Exponential and * Reciprocal Instructions. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU and OS support AVX-512 Exponential and Reciprocal * Instructions */ + (bool)supportsAVX512ExponentialAndReciprocalInstructions; /** * @brief Returns whether the CPU and OS support AVX-512 Prefetch Instructions. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU and OS support AVX-512 Prefetch Instructions */ + (bool)supportsAVX512PrefetchInstructions; /** * @brief Returns whether the CPU and OS support AVX-512 Vector Length * Extensions. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU and OS support AVX-512 Vector Length Extensions */ + (bool)supportsAVX512VectorLengthExtensions; /** * @brief Returns whether the CPU and OS support AVX-512 Doubleword and Quadword * Instructions. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU and OS support AVX-512 Doubleword and Quadword * Instructions */ + (bool)supportsAVX512DoublewordAndQuadwordInstructions; /** * @brief Returns whether the CPU and OS support AVX-512 Byte and Word * Instructions. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU and OS support AVX-512 Byte and Word Instructions */ + (bool)supportsAVX512ByteAndWordInstructions; /** * @brief Returns whether the CPU and OS support AVX-512 Integer Fused * Multiply-Add. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU and OS support AVX-512 Integer Fused Multiply-Add */ + (bool)supportsAVX512IntegerFusedMultiplyAdd; /** * @brief Returns whether the CPU and OS support AVX-512 Vector Byte * Manipulation Instructions. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU and OS support AVX-512 Vector Byte Manipulation * Instructions */ + (bool)supportsAVX512VectorByteManipulationInstructions; /** * @brief Returns whether the CPU and OS support the AVX-512 Vector Population * Count Instruction. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU and OS support AVX-512 the Vector Population Count * Instruction */ + (bool)supportsAVX512VectorPopulationCountInstruction; /** * @brief Returns whether the CPU and OS support AVX-512 Vector Neural Network * Instructions. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU and OS support AVX-512 Vector Neural Network * Instructions */ + (bool)supportsAVX512VectorNeuralNetworkInstructions; /** * @brief Returns whether the CPU and OS support AVX-512 Vector Byte * Manipulation Instructions 2. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU and OS support AVX-512 Vector Byte Manipulation * Instructions 2 */ + (bool)supportsAVX512VectorByteManipulationInstructions2; /** * @brief Returns whether the CPU and OS support AVX-512 Bit Algorithms. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU and OS support AVX-512 Bit Algorithms */ + (bool)supportsAVX512BitAlgorithms; /** * @brief Returns whether the CPU and OS support AVX-512 Float16 Instructions. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU and OS support AVX-512 Float16 Instructions */ + (bool)supportsAVX512Float16Instructions; /** * @brief Returns whether the CPU and OS support AVX-512 BFloat16 Instructions. * * @note This method is only available on AMD64 and x86. * * @return Whether the CPU and OS support AVX-512 BFloat16 Instructions */ + (bool)supportsAVX512BFloat16Instructions; #endif #if defined(OF_POWERPC) || defined(OF_POWERPC64) || defined(DOXYGEN) /** * @brief Returns whether the CPU and OS support AltiVec. * * @note This method is only available on PowerPC and PowerPC 64. * * @return Whether the CPU and OS support AltiVec */ + (bool)supportsAltiVec; #endif #if defined(OF_WINDOWS) || defined(DOXYGEN) /** * @brief Returns whether the application is running on Windows NT. * * @note This method is only available on Windows. * * @return Whether the application is running on Windows NT */ + (bool)isWindowsNT; #endif + (instancetype)alloc OF_UNAVAILABLE; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END #ifdef OF_HAVE_SOCKETS # import "OFSystemInfo+NetworkInterfaces.h" #endif objfw-1.1.6/src/OFSystemInfo.m000066400000000000000000000604551465614216400161430ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include /* include any libc header to get the libc defines */ #include #include #include "unistd_wrapper.h" #include "platform.h" #ifdef HAVE_SYS_UTSNAME_H # include #endif #if defined(OF_MACOS) || defined(OF_IOS) || defined(OF_NETBSD) # include #endif #ifdef OF_AMIGAOS # define Class IntuitionClass # include # include # undef Class #endif #if defined(OF_AMIGAOS4) # include #elif defined(OF_MORPHOS) # include #endif #ifdef OF_NINTENDO_SWITCH # define id nx_id # import # undef nx_id #endif #ifdef OF_DJGPP # include #endif #import "OFSystemInfo.h" #import "OFApplication.h" #import "OFArray.h" #import "OFData.h" #import "OFDictionary.h" #ifdef OF_HAVE_FILES # import "OFFile.h" # import "OFFileManager.h" #endif #import "OFIRI.h" #import "OFLocale.h" #import "OFNumber.h" #import "OFOnce.h" #import "OFString.h" #import "OFInvalidFormatException.h" #import "OFOpenItemFailedException.h" #if defined(OF_MACOS) || defined(OF_IOS) # ifdef HAVE_SYSDIR_H # include # endif #endif #ifdef OF_HAIKU # include #endif #ifdef OF_QNX # include #endif #if !defined(PATH_MAX) && defined(MAX_PATH) # define PATH_MAX MAX_PATH #endif #if defined(OF_MACOS) || defined(OF_IOS) /* * These have been dropped from newer iOS SDKs, however, their replacements are * not available on iOS < 10. This means it's impossible to search for the * paths when using a new SDK while targeting iOS 9 or earlier. To work around * this, we define those manually, only to be used when the replacements are * not available at runtime. */ typedef enum { NSLibraryDirectory = 5, NSApplicationSupportDirectory = 14 } NSSearchPathDirectory; typedef enum { NSUserDomainMask = 1 } NSSearchPathDomainMask; typedef unsigned int NSSearchPathEnumerationState; extern NSSearchPathEnumerationState NSStartSearchPathEnumeration( NSSearchPathDirectory, NSSearchPathDomainMask); extern NSSearchPathEnumerationState NSGetNextSearchPathEnumeration( NSSearchPathEnumerationState, char *); #endif #if defined(OF_AMD64) || defined(OF_X86) struct X86Regs { uint32_t eax, ebx, ecx, edx; }; static bool SSESupport; static jmp_buf SSETestEnv; static void SSETestSIGILLHandler(int signum) { longjmp(SSETestEnv, 1); } # ifndef __clang__ # pragma GCC push_options # pragma GCC target("sse") # endif static void SSETest(void) { void (*oldHandler)(int) = signal(SIGILL, SSETestSIGILLHandler); if (setjmp(SSETestEnv) == 0) { __asm__ __volatile__ ( "movaps %%xmm0, %%xmm0" ::: "xmm0" /* clang is unhappy if we don't clobber it */ ); SSESupport = true; } else SSESupport = false; signal(SIGILL, oldHandler); } # ifndef __clang__ # pragma GCC pop_options # endif #endif static size_t pageSize = 4096; static size_t numberOfCPUs = 1; static OFString *operatingSystemName = nil; static OFString *operatingSystemVersion = nil; #ifdef OF_WINDOWS static const char *(*wine_get_version)(void); #endif static void initOperatingSystemName(void) { #if defined(OF_IOS) operatingSystemName = @"iOS"; #elif defined(OF_MACOS) operatingSystemName = @"macOS"; #elif defined(OF_WINDOWS) operatingSystemName = @"Windows"; #elif defined(OF_ANDROID) operatingSystemName = @"Android"; #elif defined(OF_AMIGAOS_M68K) operatingSystemName = @"AmigaOS"; #elif defined(OF_MORPHOS) operatingSystemName = @"MorphOS"; #elif defined(OF_AMIGAOS4) operatingSystemName = @"AmigaOS 4"; #elif defined(OF_WII) operatingSystemName = @"Nintendo Wii"; #elif defined(OF_WII_U) operatingSystemName = @"Nintendo Wii U"; #elif defined(NINTENDO_3DS) operatingSystemName = @"Nintendo 3DS"; #elif defined(OF_NINTENDO_DS) operatingSystemName = @"Nintendo DS"; #elif defined(OF_NINTENDO_SWITCH) operatingSystemName = @"Nintendo Switch"; #elif defined(OF_PSP) operatingSystemName = @"PlayStation Portable"; #elif defined(OF_DJGPP) operatingSystemName = [[OFString alloc] initWithCString: _os_flavor encoding: OFStringEncodingASCII]; #elif defined(HAVE_SYS_UTSNAME_H) && defined(HAVE_UNAME) struct utsname name; if (uname(&name) == -1) return; operatingSystemName = [[OFString alloc] initWithCString: name.sysname encoding: [OFLocale encoding]]; #endif } static void initOperatingSystemVersion(void) { #if defined(OF_IOS) || defined(OF_MACOS) # ifdef OF_HAVE_FILES void *pool = objc_autoreleasePoolPush(); @try { OFDictionary *propertyList = [[OFString stringWithContentsOfFile: @"/System/Library/CoreServices/" @"SystemVersion.plist"] objectByParsingPropertyList]; operatingSystemVersion = [[propertyList objectForKey: @"ProductVersion"] copy]; } @finally { objc_autoreleasePoolPop(pool); } # endif #elif defined(OF_WINDOWS) # ifdef OF_HAVE_FILES void *pool = objc_autoreleasePoolPush(); @try { OFStringEncoding encoding = [OFLocale encoding]; char systemDir[PATH_MAX]; UINT systemDirLen; OFString *systemDirString; const char *path; void *buffer; DWORD bufferLen; systemDirLen = GetSystemDirectoryA(systemDir, PATH_MAX); if (systemDirLen == 0) return; systemDirString = [OFString stringWithCString: systemDir encoding: encoding length: systemDirLen]; path = [[systemDirString stringByAppendingPathComponent: @"kernel32.dll"] cStringWithEncoding: encoding]; if ((bufferLen = GetFileVersionInfoSizeA(path, NULL)) == 0) return; if ((buffer = malloc(bufferLen)) == 0) return; @try { void *data; UINT dataLen; VS_FIXEDFILEINFO *info; if (!GetFileVersionInfoA(path, 0, bufferLen, buffer)) return; if (!VerQueryValueA(buffer, "\\", &data, &dataLen) || dataLen < sizeof(info)) return; info = (VS_FIXEDFILEINFO *)data; operatingSystemVersion = [[OFString alloc] initWithFormat: @"%u.%u.%u", HIWORD(info->dwProductVersionMS), LOWORD(info->dwProductVersionMS), HIWORD(info->dwProductVersionLS)]; } @finally { free(buffer); } } @finally { objc_autoreleasePoolPop(pool); } # endif #elif defined(OF_ANDROID) /* TODO */ #elif defined(OF_AMIGAOS) operatingSystemVersion = [[OFString alloc] initWithFormat: @"Kickstart %u.%u", SysBase->LibNode.lib_Version, SysBase->SoftVer]; #elif defined(OF_DJGPP) operatingSystemVersion = [[OFString alloc] initWithFormat: @"%u.%u", _osmajor, _osminor]; #elif defined(OF_WII) || defined(NINTENDO_3DS) || defined(OF_NINTENDO_DS) || \ defined(OF_PSP) /* Intentionally nothing */ #elif defined(HAVE_SYS_UTSNAME_H) && defined(HAVE_UNAME) struct utsname name; if (uname(&name) == -1) return; operatingSystemVersion = [[OFString alloc] initWithCString: name.release encoding: [OFLocale encoding]]; #endif } #ifdef OF_NINTENDO_SWITCH static OFIRI *tmpFSIRI = nil; static void mountTmpFS(void) { if (R_SUCCEEDED(fsdevMountTemporaryStorage("tmpfs"))) tmpFSIRI = [[OFIRI alloc] initFileIRIWithPath: @"tmpfs:/" isDirectory: true]; } #endif #if defined(OF_AMD64) || defined(OF_X86) static OF_INLINE struct X86Regs OF_CONST_FUNC x86CPUID(uint32_t eax, uint32_t ecx) { struct X86Regs regs; # if defined(OF_AMD64) && defined(__GNUC__) __asm__ ( "cpuid" : "=a" (regs.eax), "=b" (regs.ebx), "=c" (regs.ecx), "=d" (regs.edx) : "a" (eax), "c" (ecx) ); # elif defined(OF_X86) && defined(__GNUC__) /* * This workaround is required by older GCC versions when using -fPIC, * as ebx is a special register in PIC code. Yes, GCC is indeed not * able to just push a register onto the stack before the __asm__ block * and to pop it afterwards. */ __asm__ ( "xchgl %%ebx, %%edi\n\t" "cpuid\n\t" "xchgl %%edi, %%ebx" : "=a" (regs.eax), "=D" (regs.ebx), "=c" (regs.ecx), "=d" (regs.edx) : "a" (eax), "c" (ecx) ); # else memset(®s, 0, sizeof(regs)); # endif return regs; } static OF_INLINE struct X86Regs x86XCR(uint32_t ecx) { struct X86Regs regs = { 0 }; if (!(x86CPUID(1, 0).ecx & (1u << 27))) return regs; __asm__ ( "xgetbv" : "=a" (regs.eax), "=d" (regs.edx) : "c" (ecx) ); return regs; } #endif @implementation OFSystemInfo + (void)initialize { long tmp; if (self != [OFSystemInfo class]) return; #if defined(OF_AMD64) || defined(OF_X86) /* * Do this as early as possible, as it involves signals. * Required as cpuid can return SSE support while the OS has not * enabled it. */ SSETest(); #endif #if defined(OF_WINDOWS) HANDLE module; SYSTEM_INFO si; GetSystemInfo(&si); pageSize = si.dwPageSize; numberOfCPUs = si.dwNumberOfProcessors; if ((module = GetModuleHandle("ntdll.dll")) != NULL) wine_get_version = (const char *(*)(void)) GetProcAddress(module, "wine_get_version"); #elif defined(OF_QNX) if ((tmp = sysconf(_SC_PAGESIZE)) > 0) pageSize = tmp; numberOfCPUs = _syspage_ptr->num_cpu; #else # if defined(HAVE_SYSCONF) && defined(_SC_PAGESIZE) if ((tmp = sysconf(_SC_PAGESIZE)) > 0) pageSize = tmp; # endif # if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_CONF) if ((tmp = sysconf(_SC_NPROCESSORS_CONF)) > 0) numberOfCPUs = tmp; # endif #endif (void)tmp; } + (instancetype)alloc { OF_UNRECOGNIZED_SELECTOR } + (size_t)pageSize { return pageSize; } + (size_t)numberOfCPUs { return numberOfCPUs; } + (OFString *)ObjFWVersion { return @PACKAGE_VERSION; } + (unsigned short)ObjFWVersionMajor { return OBJFW_VERSION_MAJOR; } + (unsigned short)ObjFWVersionMinor { return OBJFW_VERSION_MINOR; } + (OFString *)operatingSystemName { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, initOperatingSystemName); return operatingSystemName; } + (OFString *)operatingSystemVersion { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, initOperatingSystemVersion); return operatingSystemVersion; } #ifdef OF_WINDOWS + (OFString *)wineVersion { if (wine_get_version != NULL) return [OFString stringWithCString: wine_get_version() encoding: [OFLocale encoding]]; return nil; } #endif + (OFIRI *)userDataIRI { #ifdef OF_HAVE_FILES # if defined(OF_MACOS) || defined(OF_IOS) char pathC[PATH_MAX]; OFMutableString *path; # ifdef HAVE_SYSDIR_START_SEARCH_PATH_ENUMERATION if (@available(macOS 10.12, iOS 10, *)) { sysdir_search_path_enumeration_state state; state = sysdir_start_search_path_enumeration( SYSDIR_DIRECTORY_APPLICATION_SUPPORT, SYSDIR_DOMAIN_MASK_USER); if (sysdir_get_next_search_path_enumeration(state, pathC) == 0) return nil; } else { # endif NSSearchPathEnumerationState state; state = NSStartSearchPathEnumeration( NSApplicationSupportDirectory, NSUserDomainMask); if (NSGetNextSearchPathEnumeration(state, pathC) == 0) return nil; # ifdef HAVE_SYSDIR_START_SEARCH_PATH_ENUMERATION } # endif path = [OFMutableString stringWithUTF8String: pathC]; if ([path hasPrefix: @"~"]) { OFDictionary *env = [OFApplication environment]; OFString *home; if ((home = [env objectForKey: @"HOME"]) == nil) return nil; [path deleteCharactersInRange: OFMakeRange(0, 1)]; [path insertString: home atIndex: 0]; } [path makeImmutable]; return [OFIRI fileIRIWithPath: path isDirectory: true]; # elif defined(OF_WINDOWS) OFDictionary *env = [OFApplication environment]; OFString *appData; if ((appData = [env objectForKey: @"APPDATA"]) == nil) return nil; return [OFIRI fileIRIWithPath: appData isDirectory: true]; # elif defined(OF_HAIKU) char pathC[PATH_MAX]; if (find_directory(B_USER_SETTINGS_DIRECTORY, 0, false, pathC, PATH_MAX) != B_OK) return nil; return [OFIRI fileIRIWithPath: [OFString stringWithUTF8String: pathC] isDirectory: true]; # elif defined(OF_AMIGAOS) return [OFIRI fileIRIWithPath: @"PROGDIR:" isDirectory: true]; # elif defined(OF_WII) || defined(OF_NINTENDO_3DS) return [[OFFileManager defaultManager] currentDirectoryIRI]; # else OFDictionary *env = [OFApplication environment]; OFString *var; OFIRI *IRI; void *pool; if ((var = [env objectForKey: @"XDG_DATA_HOME"]) != nil && var.length > 0) return [OFIRI fileIRIWithPath: var isDirectory: true]; if ((var = [env objectForKey: @"HOME"]) == nil) return nil; pool = objc_autoreleasePoolPush(); var = [OFString pathWithComponents: [OFArray arrayWithObjects: var, @".local", @"share", nil]]; IRI = [[OFIRI alloc] initFileIRIWithPath: var isDirectory: true]; objc_autoreleasePoolPop(pool); return [IRI autorelease]; # endif #else return nil; #endif } + (OFIRI *)userConfigIRI { #ifdef OF_HAVE_FILES # if defined(OF_MACOS) || defined(OF_IOS) char pathC[PATH_MAX]; OFMutableString *path; # ifdef HAVE_SYSDIR_START_SEARCH_PATH_ENUMERATION if (@available(macOS 10.12, iOS 10, *)) { sysdir_search_path_enumeration_state state; state = sysdir_start_search_path_enumeration( SYSDIR_DIRECTORY_LIBRARY, SYSDIR_DOMAIN_MASK_USER); if (sysdir_get_next_search_path_enumeration(state, pathC) == 0) return nil; } else { # endif NSSearchPathEnumerationState state; state = NSStartSearchPathEnumeration(NSLibraryDirectory, NSUserDomainMask); if (NSGetNextSearchPathEnumeration(state, pathC) == 0) return nil; # ifdef HAVE_SYSDIR_START_SEARCH_PATH_ENUMERATION } # endif path = [OFMutableString stringWithUTF8String: pathC]; if ([path hasPrefix: @"~"]) { OFDictionary *env = [OFApplication environment]; OFString *home; if ((home = [env objectForKey: @"HOME"]) == nil) return nil; [path deleteCharactersInRange: OFMakeRange(0, 1)]; [path insertString: home atIndex: 0]; } [path appendString: @"/Preferences"]; [path makeImmutable]; return [OFIRI fileIRIWithPath: path isDirectory: true]; # elif defined(OF_WINDOWS) OFDictionary *env = [OFApplication environment]; OFString *appData; if ((appData = [env objectForKey: @"APPDATA"]) == nil) return nil; return [OFIRI fileIRIWithPath: appData isDirectory: true]; # elif defined(OF_HAIKU) char pathC[PATH_MAX]; if (find_directory(B_USER_SETTINGS_DIRECTORY, 0, false, pathC, PATH_MAX) != B_OK) return nil; return [OFIRI fileIRIWithPath: [OFString stringWithUTF8String: pathC] isDirectory: true]; # elif defined(OF_AMIGAOS) return [OFIRI fileIRIWithPath: @"PROGDIR:" isDirectory: true]; # elif defined(OF_WII) || defined(OF_NINTENDO_3DS) return [[OFFileManager defaultManager] currentDirectoryIRI]; # else OFDictionary *env = [OFApplication environment]; OFString *var; if ((var = [env objectForKey: @"XDG_CONFIG_HOME"]) != nil && var.length > 0) return [OFIRI fileIRIWithPath: var isDirectory: true]; if ((var = [env objectForKey: @"HOME"]) == nil) return nil; var = [var stringByAppendingPathComponent: @".config"]; return [OFIRI fileIRIWithPath: var isDirectory: true]; # endif #else return nil; #endif } + (OFIRI *)temporaryDirectoryIRI { #ifdef OF_HAVE_FILES # if defined(OF_MACOS) || defined(OF_IOS) char buffer[PATH_MAX]; size_t length; OFString *path; if ((length = confstr(_CS_DARWIN_USER_TEMP_DIR, buffer, PATH_MAX)) == 0) return [OFIRI fileIRIWithPath: @"/tmp" isDirectory: true]; path = [OFString stringWithCString: buffer encoding: [OFLocale encoding] length: length - 1]; return [OFIRI fileIRIWithPath: path isDirectory: true]; # elif defined(OF_WINDOWS) OFString *path; if ([self isWindowsNT]) { wchar_t buffer[PATH_MAX]; if (!GetTempPathW(PATH_MAX, buffer)) return nil; path = [OFString stringWithUTF16String: buffer]; } else { char buffer[PATH_MAX]; if (!GetTempPathA(PATH_MAX, buffer)) return nil; path = [OFString stringWithCString: buffer encoding: [OFLocale encoding]]; } return [OFIRI fileIRIWithPath: path isDirectory: true]; # elif defined(OF_HAIKU) char pathC[PATH_MAX]; if (find_directory(B_SYSTEM_TEMP_DIRECTORY, 0, false, pathC, PATH_MAX) != B_OK) return nil; return [OFIRI fileIRIWithPath: [OFString stringWithUTF8String: pathC] isDirectory: true]; # elif defined(OF_AMIGAOS) return [OFIRI fileIRIWithPath: @"T:" isDirectory: true]; # elif defined(OF_MSDOS) OFString *path = [[OFApplication environment] objectForKey: @"TEMP"]; if (path == nil) return nil; return [OFIRI fileIRIWithPath: path isDirectory: true]; # elif defined(OF_MINT) return [OFIRI fileIRIWithPath: @"u:\\tmp" isDirectory: true]; # elif defined(OF_WII) || defined(OF_NINTENDO_3DS) return [[OFFileManager defaultManager] currentDirectoryIRI]; # elif defined(OF_NINTENDO_SWITCH) static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, mountTmpFS); return tmpFSIRI; # else OFString *path; path = [[OFApplication environment] objectForKey: @"XDG_RUNTIME_DIR"]; if (path != nil) return [OFIRI fileIRIWithPath: path isDirectory: true]; path = [[OFApplication environment] objectForKey: @"TMPDIR"]; if (path != nil) return [OFIRI fileIRIWithPath: path isDirectory: true]; return [OFIRI fileIRIWithPath: @"/tmp" isDirectory: true]; # endif #else return nil; #endif } + (OFString *)CPUVendor { #if (defined(OF_AMD64) || defined(OF_X86)) && defined(__GNUC__) struct X86Regs regs = x86CPUID(0, 0); uint32_t buffer[3]; if (regs.eax == 0) return nil; buffer[0] = regs.ebx; buffer[1] = regs.edx; buffer[2] = regs.ecx; return [OFString stringWithCString: (char *)buffer encoding: OFStringEncodingASCII length: 12]; #elif defined(OF_M68K) return @"Motorola"; #else return nil; #endif } + (OFString *)CPUModel { #if (defined(OF_AMD64) || defined(OF_X86)) && defined(__GNUC__) struct X86Regs regs = x86CPUID(0x80000000, 0); uint32_t buffer[12]; size_t i; if (regs.eax < 0x80000004) return nil; i = 0; for (uint32_t eax = 0x80000002; eax <= 0x80000004; eax++) { regs = x86CPUID(eax, 0); buffer[i++] = regs.eax; buffer[i++] = regs.ebx; buffer[i++] = regs.ecx; buffer[i++] = regs.edx; } return [OFString stringWithCString: (char *)buffer encoding: OFStringEncodingASCII]; #elif defined(OF_MACOS) || defined(OF_IOS) char buffer[128]; size_t length = sizeof(buffer); if (sysctlbyname("machdep.cpu.brand_string", &buffer, &length, NULL, 0) != 0) return nil; return [OFString stringWithCString: buffer encoding: [OFLocale encoding] length: length]; #elif defined(OF_AMIGAOS4) CONST_STRPTR model, version; GetCPUInfoTags(GCIT_ModelString, &model, GCIT_VersionString, &version, TAG_END); if (version != NULL) return [OFString stringWithFormat: @"%s V%s", model, version]; else return [OFString stringWithCString: model encoding: OFStringEncodingASCII]; #elif defined(OF_AMIGAOS_M68K) if (SysBase->AttnFlags & AFF_68060) return @"68060"; if (SysBase->AttnFlags & AFF_68040) return @"68040"; if (SysBase->AttnFlags & AFF_68030) return @"68030"; if (SysBase->AttnFlags & AFF_68020) return @"68020"; if (SysBase->AttnFlags & AFF_68010) return @"68010"; else return @"68000"; #else return nil; #endif } #if defined(OF_AMD64) || defined(OF_X86) + (bool)supportsMMX { return (x86CPUID(0, 0).eax >= 1 && x86CPUID(1, 0).edx & (1u << 23)); } + (bool)supports3DNow { return (x86CPUID(0x80000000, 0).eax >= 0x80000001 && x86CPUID(0x80000001, 0).edx & (1u << 31)); } + (bool)supportsEnhanced3DNow { return (x86CPUID(0x80000000, 0).eax >= 0x80000001 && x86CPUID(0x80000001, 0).edx & (1u << 30)); } + (bool)supportsSSE { return SSESupport && (x86CPUID(0, 0).eax >= 1 && x86CPUID(1, 0).edx & (1u << 25)); } + (bool)supportsSSE2 { return SSESupport && (x86CPUID(0, 0).eax >= 1 && x86CPUID(1, 0).edx & (1u << 26)); } + (bool)supportsSSE3 { return SSESupport && (x86CPUID(0, 0).eax >= 1 && x86CPUID(1, 0).ecx & (1u << 0)); } + (bool)supportsSSSE3 { return SSESupport && (x86CPUID(0, 0).eax >= 1 && x86CPUID(1, 0).ecx & (1u << 9)); } + (bool)supportsSSE41 { return SSESupport && (x86CPUID(0, 0).eax >= 1 && x86CPUID(1, 0).ecx & (1u << 19)); } + (bool)supportsSSE42 { return SSESupport && (x86CPUID(0, 0).eax >= 1 && x86CPUID(1, 0).ecx & (1u << 20)); } + (bool)supportsAVX { return ((x86CPUID(0, 0).eax >= 1 && x86CPUID(1, 0).ecx & (1u << 28)) && (x86XCR(0).eax & 0x6) == 0x6); } + (bool)supportsAVX2 { return ((x86CPUID(0, 0).eax >= 7 && (x86CPUID(7, 0).ebx & (1u << 5))) && (x86XCR(0).eax & 0x6) == 0x6); } + (bool)supportsAESNI { return (x86CPUID(0, 0).eax >= 1 && x86CPUID(1, 0).ecx & (1u << 25)); } + (bool)supportsSHAExtensions { return (x86CPUID(0, 0).eax >= 7 && x86CPUID(7, 0).ebx & (1u << 29)); } + (bool)supportsFusedMultiplyAdd { return (x86CPUID(0, 0).eax >= 1 && x86CPUID(1, 0).ecx & (1u << 12)); } + (bool)supportsF16C { return (x86CPUID(0, 0).eax >= 1 && x86CPUID(1, 0).ecx & (1u << 29)); } + (bool)supportsAVX512Foundation { return ((x86CPUID(0, 0).eax >= 7 && x86CPUID(7, 0).ebx & (1u << 16)) && (x86XCR(0).eax & 0xE6) == 0xE6); } + (bool)supportsAVX512ConflictDetectionInstructions { return ((x86CPUID(0, 0).eax >= 7 && x86CPUID(7, 0).ebx & (1u << 28)) && (x86XCR(0).eax & 0xE6) == 0xE6); } + (bool)supportsAVX512ExponentialAndReciprocalInstructions { return ((x86CPUID(0, 0).eax >= 7 && x86CPUID(7, 0).ebx & (1u << 27)) && (x86XCR(0).eax & 0xE6) == 0xE6); } + (bool)supportsAVX512PrefetchInstructions { return ((x86CPUID(0, 0).eax >= 7 && x86CPUID(7, 0).ebx & (1u << 26)) && (x86XCR(0).eax & 0xE6) == 0xE6); } + (bool)supportsAVX512VectorLengthExtensions { return ((x86CPUID(0, 0).eax >= 7 && x86CPUID(7, 0).ebx & (1u << 31)) && (x86XCR(0).eax & 0xE6) == 0xE6); } + (bool)supportsAVX512DoublewordAndQuadwordInstructions { return ((x86CPUID(0, 0).eax >= 7 && x86CPUID(7, 0).ebx & (1u << 17)) && (x86XCR(0).eax & 0xE6) == 0xE6); } + (bool)supportsAVX512ByteAndWordInstructions { return ((x86CPUID(0, 0).eax >= 7 && x86CPUID(7, 0).ebx & (1u << 30)) && (x86XCR(0).eax & 0xE6) == 0xE6); } + (bool)supportsAVX512IntegerFusedMultiplyAdd { return ((x86CPUID(0, 0).eax >= 7 && x86CPUID(7, 0).ebx & (1u << 21)) && (x86XCR(0).eax & 0xE6) == 0xE6); } + (bool)supportsAVX512VectorByteManipulationInstructions { return ((x86CPUID(0, 0).eax >= 7 && x86CPUID(7, 0).ecx & (1u << 1)) && (x86XCR(0).eax & 0xE6) == 0xE6); } + (bool)supportsAVX512VectorPopulationCountInstruction { return ((x86CPUID(0, 0).eax >= 7 && x86CPUID(7, 0).ecx & (1u << 14)) && (x86XCR(0).eax & 0xE6) == 0xE6); } + (bool)supportsAVX512VectorNeuralNetworkInstructions { return ((x86CPUID(0, 0).eax >= 7 && x86CPUID(7, 0).ecx & (1u << 11)) && (x86XCR(0).eax & 0xE6) == 0xE6); } + (bool)supportsAVX512VectorByteManipulationInstructions2 { return ((x86CPUID(0, 0).eax >= 7 && x86CPUID(7, 0).ecx & (1u << 6)) && (x86XCR(0).eax & 0xE6) == 0xE6); } + (bool)supportsAVX512BitAlgorithms { return ((x86CPUID(0, 0).eax >= 7 && x86CPUID(7, 0).ecx & (1u << 12)) && (x86XCR(0).eax & 0xE6) == 0xE6); } + (bool)supportsAVX512Float16Instructions { return ((x86CPUID(0, 0).eax >= 7 && x86CPUID(7, 0).edx & (1u << 23)) && (x86XCR(0).eax & 0xE6) == 0xE6); } + (bool)supportsAVX512BFloat16Instructions { return ((x86CPUID(0, 0).eax >= 7 && x86CPUID(7, 1).eax & (1u << 5)) && (x86XCR(0).eax & 0xE6) == 0xE6); } #endif #if defined(OF_POWERPC) || defined(OF_POWERPC64) + (bool)supportsAltiVec { # if defined(OF_MACOS) int name[2] = { CTL_HW, HW_VECTORUNIT }, value = 0; size_t length = sizeof(value); if (sysctl(name, 2, &value, &length, NULL, 0) == 0) return value; # elif defined(OF_AMIGAOS4) uint32_t vectorUnit; GetCPUInfoTags(GCIT_VectorUnit, &vectorUnit, TAG_END); return (vectorUnit == VECTORTYPE_ALTIVEC); # elif defined(OF_MORPHOS) uint32_t supportsAltiVec; if (NewGetSystemAttrs(&supportsAltiVec, sizeof(supportsAltiVec), SYSTEMINFOTYPE_PPC_ALTIVEC, TAG_DONE) > 0) return supportsAltiVec; # endif return false; } #endif #ifdef OF_WINDOWS + (bool)isWindowsNT { return !(GetVersion() & 0x80000000); } #endif - (instancetype)init { OF_INVALID_INIT_METHOD } @end objfw-1.1.6/src/OFTCPSocket.h000066400000000000000000000155061465614216400156320ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFStreamSocket.h" #import "OFRunLoop.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFTCPSocket; @class OFString; #ifdef OF_HAVE_BLOCKS /** * @brief A block which is called when the socket connected. * * @param exception An exception which occurred while connecting the socket or * `nil` on success */ typedef void (^OFTCPSocketAsyncConnectBlock)(id _Nullable exception); #endif /** * @protocol OFTCPSocketDelegate OFTCPSocket.h ObjFW/OFTCPSocket.h * * A delegate for OFTCPSocket. */ @protocol OFTCPSocketDelegate @optional /** * @brief A method which is called when a socket connected. * * @param socket The socket which connected * @param host The host connected to * @param port The port on the host connected to * @param exception An exception that occurred while connecting, or nil on * success */ - (void)socket: (OFTCPSocket *)socket didConnectToHost: (OFString *)host port: (uint16_t)port exception: (nullable id)exception; @end /** * @class OFTCPSocket OFTCPSocket.h ObjFW/OFTCPSocket.h * * @brief A class which provides methods to create and use TCP sockets. * * To connect to a server, create a socket and connect it. * To create a server, create a socket, bind it and listen on it. */ @interface OFTCPSocket: OFStreamSocket { OFString *_Nullable _SOCKS5Host; uint16_t _SOCKS5Port; #ifdef OF_WII uint16_t _port; #endif OF_RESERVE_IVARS(OFTCPSocket, 4) } #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, nullable, copy, nonatomic) OFString *SOCKS5Host; @property (class, nonatomic) uint16_t SOCKS5Port; #endif #if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) /** * @brief Whether the socket sends keep-alives for the connection. * * @warning This is not available on the Wii or Nintendo 3DS! * * @throw OFGetOptionFailedException The option could not be retrieved * @throw OFSetOptionFailedException The option could not be set */ @property (nonatomic) bool sendsKeepAlives; #endif #ifndef OF_WII /** * @brief Whether sending segments can be delayed. Setting this to `false` sets * TCP_NODELAY on the socket. * * @warning This is not available on the Wii! * * @throw OFGetOptionFailedException The option could not be retrieved * @throw OFSetOptionFailedException The option could not be set */ @property (nonatomic) bool canDelaySendingSegments; #endif /** * @brief The host to use as a SOCKS5 proxy. */ @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *SOCKS5Host; /** * @brief The port to use on the SOCKS5 proxy. */ @property (nonatomic) uint16_t SOCKS5Port; /** * @brief The delegate for asynchronous operations on the socket. * * @note The delegate is retained for as long as asynchronous operations are * still ongoing. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id delegate; /** * @brief Sets the global SOCKS5 proxy host to use when creating a new socket * * @param SOCKS5Host The host to use as a SOCKS5 proxy when creating a new * socket */ + (void)setSOCKS5Host: (nullable OFString *)SOCKS5Host; /** * @brief Returns the host to use as a SOCKS5 proxy when creating a new socket * * @return The host to use as a SOCKS5 proxy when creating a new socket */ + (nullable OFString *)SOCKS5Host; /** * @brief Sets the global SOCKS5 proxy port to use when creating a new socket * * @param SOCKS5Port The port to use as a SOCKS5 proxy when creating a new socket */ + (void)setSOCKS5Port: (uint16_t)SOCKS5Port; /** * @brief Returns the port to use as a SOCKS5 proxy when creating a new socket * * @return The port to use as a SOCKS5 proxy when creating a new socket */ + (uint16_t)SOCKS5Port; /** * @brief Connects the OFTCPSocket to the specified destination. * * @param host The host to connect to * @param port The port on the host to connect to * @throw OFConnectIPSocketFailedException Connecting failed * @throw OFAlreadyOpenException The socket is already connected or bound */ - (void)connectToHost: (OFString *)host port: (uint16_t)port; /** * @brief Asynchronously connects the OFTCPSocket to the specified destination. * * @param host The host to connect to * @param port The port on the host to connect to */ - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port; /** * @brief Asynchronously connects the OFTCPSocket to the specified destination. * * @param host The host to connect to * @param port The port on the host to connect to * @param runLoopMode The run loop mode in which to perform the asynchronous * connect */ - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously connects the OFTCPSocket to the specified destination. * * @param host The host to connect to * @param port The port on the host to connect to * @param block The block to execute once the connection has been established */ - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port block: (OFTCPSocketAsyncConnectBlock)block; /** * @brief Asynchronously connects the OFTCPSocket to the specified destination. * * @param host The host to connect to * @param port The port on the host to connect to * @param runLoopMode The run loop mode in which to perform the asynchronous * connect * @param block The block to execute once the connection has been established */ - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode block: (OFTCPSocketAsyncConnectBlock)block; #endif /** * @brief Binds the socket to the specified host and port. * * @param host The host to bind to. Use `@"0.0.0.0"` for IPv4 or `@"::"` for * IPv6 to bind to all. * @param port The port to bind to. If the port is 0, an unused port will be * chosen, which can be obtained using the return value. * @return The address the socket was bound to * @throw OFBindIPSocketFailedException Binding failed * @throw OFAlreadyOpenException The socket is already connected or bound */ - (OFSocketAddress)bindToHost: (OFString *)host port: (uint16_t)port; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFTCPSocket.m000066400000000000000000000261371465614216400156410ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #ifndef _XOPEN_SOURCE_EXTENDED # define _XOPEN_SOURCE_EXTENDED #endif #define _HPUX_ALT_XOPEN_SOCKET_API #include #include #include #include #ifdef HAVE_FCNTL_H # include #endif #import "OFTCPSocket.h" #import "OFAsyncIPSocketConnector.h" #import "OFDNSResolver.h" #import "OFData.h" #import "OFDate.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFString.h" #import "OFTCPSocketSOCKS5Connector.h" #import "OFThread.h" #import "OFAlreadyOpenException.h" #import "OFBindIPSocketFailedException.h" #import "OFGetOptionFailedException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFSetOptionFailedException.h" static const OFRunLoopMode connectRunLoopMode = @"OFTCPSocketConnectRunLoopMode"; static OFString *defaultSOCKS5Host = nil; static uint16_t defaultSOCKS5Port = 1080; @interface OFTCPSocket () @end @interface OFTCPSocketConnectDelegate: OFObject { @public bool _done; id _exception; } @end @implementation OFTCPSocketConnectDelegate - (void)dealloc { [_exception release]; [super dealloc]; } - (void)socket: (OFTCPSocket *)sock didConnectToHost: (OFString *)host port: (uint16_t)port exception: (id)exception { _done = true; _exception = [exception retain]; } @end @implementation OFTCPSocket @synthesize SOCKS5Host = _SOCKS5Host, SOCKS5Port = _SOCKS5Port; @dynamic delegate; + (void)setSOCKS5Host: (OFString *)host { id old = defaultSOCKS5Host; defaultSOCKS5Host = [host copy]; [old release]; } + (OFString *)SOCKS5Host { return defaultSOCKS5Host; } + (void)setSOCKS5Port: (uint16_t)port { defaultSOCKS5Port = port; } + (uint16_t)SOCKS5Port { return defaultSOCKS5Port; } - (instancetype)init { self = [super init]; @try { _SOCKS5Host = [defaultSOCKS5Host copy]; _SOCKS5Port = defaultSOCKS5Port; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_SOCKS5Host release]; [super dealloc]; } - (bool)of_createSocketForAddress: (const OFSocketAddress *)address errNo: (int *)errNo { #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyOpenException exceptionWithObject: self]; if ((_socket = socket( ((struct sockaddr *)&address->sockaddr)->sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle) { *errNo = _OFSocketErrNo(); return false; } #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); #endif return true; } - (bool)of_connectSocketToAddress: (const OFSocketAddress *)address errNo: (int *)errNo { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; /* Cast needed for AmigaOS, where the argument is declared non-const */ if (connect(_socket, (struct sockaddr *)&address->sockaddr, address->length) != 0) { *errNo = _OFSocketErrNo(); return false; } return true; } - (void)of_closeSocket { closesocket(_socket); _socket = OFInvalidSocketHandle; } - (void)connectToHost: (OFString *)host port: (uint16_t)port { void *pool = objc_autoreleasePoolPush(); id delegate = _delegate; OFTCPSocketConnectDelegate *connectDelegate = [[[OFTCPSocketConnectDelegate alloc] init] autorelease]; OFRunLoop *runLoop = [OFRunLoop currentRunLoop]; _delegate = connectDelegate; [self asyncConnectToHost: host port: port runLoopMode: connectRunLoopMode]; while (!connectDelegate->_done) [runLoop runMode: connectRunLoopMode beforeDate: nil]; /* Cleanup */ [runLoop runMode: connectRunLoopMode beforeDate: [OFDate date]]; _delegate = delegate; if (connectDelegate->_exception != nil) @throw connectDelegate->_exception; objc_autoreleasePoolPop(pool); } - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port { [self asyncConnectToHost: host port: port runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode { void *pool = objc_autoreleasePoolPush(); id delegate; if (_SOCKS5Host != nil) { delegate = [[[OFTCPSocketSOCKS5Connector alloc] initWithSocket: self host: host port: port delegate: _delegate #ifdef OF_HAVE_BLOCKS block: NULL #endif ] autorelease]; host = _SOCKS5Host; port = _SOCKS5Port; } else delegate = _delegate; [[[[OFAsyncIPSocketConnector alloc] initWithSocket: self host: host port: port delegate: delegate block: NULL ] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port block: (OFTCPSocketAsyncConnectBlock)block { [self asyncConnectToHost: host port: port runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode block: (OFTCPSocketAsyncConnectBlock)block { void *pool = objc_autoreleasePoolPush(); id delegate = nil; if (_SOCKS5Host != nil) { delegate = [[[OFTCPSocketSOCKS5Connector alloc] initWithSocket: self host: host port: port delegate: nil block: block] autorelease]; host = _SOCKS5Host; port = _SOCKS5Port; } [[[[OFAsyncIPSocketConnector alloc] initWithSocket: self host: host port: port delegate: delegate block: (delegate == nil ? block : NULL)] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } #endif - (OFSocketAddress)bindToHost: (OFString *)host port: (uint16_t)port { const int one = 1; void *pool = objc_autoreleasePoolPush(); OFData *socketAddresses; OFSocketAddress address; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyOpenException exceptionWithObject: self]; if (_SOCKS5Host != nil) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; socketAddresses = [[OFThread DNSResolver] resolveAddressesForHost: host addressFamily: OFSocketAddressFamilyAny]; address = *(OFSocketAddress *)[socketAddresses itemAtIndex: 0]; OFSocketAddressSetIPPort(&address, port); if ((_socket = socket( ((struct sockaddr *)&address.sockaddr)->sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle) @throw [OFBindIPSocketFailedException exceptionWithHost: host port: port socket: self errNo: _OFSocketErrNo()]; _canBlock = true; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); #endif setsockopt(_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&one, (socklen_t)sizeof(one)); #if defined(OF_HPUX) || defined(OF_WII) || defined(OF_NINTENDO_3DS) if (port != 0) { #endif if (bind(_socket, (struct sockaddr *)&address.sockaddr, address.length) != 0) { int errNo = _OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindIPSocketFailedException exceptionWithHost: host port: port socket: self errNo: errNo]; } #if defined(OF_HPUX) || defined(OF_WII) || defined(OF_NINTENDO_3DS) } else { for (;;) { uint16_t rnd = 0; int ret; while (rnd < 1024) rnd = (uint16_t)rand(); OFSocketAddressSetIPPort(&address, rnd); if ((ret = bind(_socket, (struct sockaddr *)&address.sockaddr, address.length)) == 0) break; if (_OFSocketErrNo() != EADDRINUSE) { int errNo = _OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindIPSocketFailedException exceptionWithHost: host port: port socket: self errNo: errNo]; } } } #endif #if !defined(OF_HPUX) && !defined(OF_WII) && !defined(OF_NINTENDO_3DS) memset(&address, 0, sizeof(address)); address.length = (socklen_t)sizeof(address.sockaddr); if (_OFGetSockName(_socket, (struct sockaddr *)&address.sockaddr, &address.length) != 0) { int errNo = _OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindIPSocketFailedException exceptionWithHost: host port: port socket: self errNo: errNo]; } switch (((struct sockaddr *)&address.sockaddr)->sa_family) { case AF_INET: address.family = OFSocketAddressFamilyIPv4; break; # ifdef OF_HAVE_IPV6 case AF_INET6: address.family = OFSocketAddressFamilyIPv6; break; # endif default: closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindIPSocketFailedException exceptionWithHost: host port: port socket: self errNo: EAFNOSUPPORT]; } #endif objc_autoreleasePoolPop(pool); return address; } #if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) - (void)setSendsKeepAlives: (bool)sendsKeepAlives { int v = sendsKeepAlives; if (setsockopt(_socket, SOL_SOCKET, SO_KEEPALIVE, (char *)&v, (socklen_t)sizeof(v)) != 0) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: _OFSocketErrNo()]; } - (bool)sendsKeepAlives { int v; socklen_t len = sizeof(v); if (getsockopt(_socket, SOL_SOCKET, SO_KEEPALIVE, (char *)&v, &len) != 0 || len != sizeof(v)) @throw [OFGetOptionFailedException exceptionWithObject: self errNo: _OFSocketErrNo()]; return v; } #endif #ifndef OF_WII - (void)setCanDelaySendingSegments: (bool)canDelaySendingSegments { int v = !canDelaySendingSegments; if (setsockopt(_socket, IPPROTO_TCP, TCP_NODELAY, (char *)&v, (socklen_t)sizeof(v)) != 0) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: _OFSocketErrNo()]; } - (bool)canDelaySendingSegments { int v; socklen_t len = sizeof(v); if (getsockopt(_socket, IPPROTO_TCP, TCP_NODELAY, (char *)&v, &len) != 0 || len != sizeof(v)) @throw [OFGetOptionFailedException exceptionWithObject: self errNo: _OFSocketErrNo()]; return !v; } #endif - (void)close { #ifdef OF_WII _port = 0; #endif [super close]; } @end objfw-1.1.6/src/OFTCPSocketSOCKS5Connector.h000066400000000000000000000030021465614216400203610ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFTCPSocket.h" OF_ASSUME_NONNULL_BEGIN @class OFString; @interface OFTCPSocketSOCKS5Connector: OFObject { OFTCPSocket *_socket; OFString *_host; uint16_t _port; id _Nullable _delegate; #ifdef OF_HAVE_BLOCKS OFTCPSocketAsyncConnectBlock _Nullable _block; #endif id _Nullable _exception; uint_least8_t _SOCKS5State; /* Longest read is domain name (max 255 bytes) + port */ unsigned char _buffer[257]; OFMutableData *_Nullable _request; } - (instancetype)initWithSocket: (OFTCPSocket *)sock host: (OFString *)host port: (uint16_t)port delegate: (nullable id )delegate #ifdef OF_HAVE_BLOCKS block: (nullable OFTCPSocketAsyncConnectBlock)block #endif ; - (void)didConnect; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFTCPSocketSOCKS5Connector.m000066400000000000000000000152641465614216400204030ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFTCPSocketSOCKS5Connector.h" #import "OFData.h" #import "OFRunLoop.h" #import "OFString.h" #import "OFConnectIPSocketFailedException.h" enum { stateSendAuthentication = 1, stateReadVersion, stateSendRequest, stateReadResponse, stateReadAddress, stateReadAddressLength, }; @implementation OFTCPSocketSOCKS5Connector - (instancetype)initWithSocket: (OFTCPSocket *)sock host: (OFString *)host port: (uint16_t)port delegate: (id )delegate #ifdef OF_HAVE_BLOCKS block: (OFTCPSocketAsyncConnectBlock)block #endif { self = [super init]; @try { _socket = [sock retain]; _host = [host copy]; _port = port; _delegate = [delegate retain]; #ifdef OF_HAVE_BLOCKS _block = [block copy]; #endif _socket.delegate = self; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_socket.delegate == self) _socket.delegate = _delegate; [_socket release]; [_host release]; [_delegate release]; #ifdef OF_HAVE_BLOCKS [_block release]; #endif [_exception release]; [_request release]; [super dealloc]; } - (void)didConnect { _socket.delegate = _delegate; #ifdef OF_HAVE_BLOCKS if (_block != NULL) _block(_exception); else { #endif if ([_delegate respondsToSelector: @selector(socket:didConnectToHost:port:exception:)]) [_delegate socket: _socket didConnectToHost: _host port: _port exception: _exception]; #ifdef OF_HAVE_BLOCKS } #endif } - (void)socket: (OFTCPSocket *)sock didConnectToHost: (OFString *)host port: (uint16_t)port exception: (id)exception { OFData *data; if (exception != nil) { _exception = [exception retain]; [self didConnect]; return; } data = [OFData dataWithItems: "\x05\x01\x00" count: 3]; _SOCKS5State = stateSendAuthentication; [_socket asyncWriteData: data runLoopMode: [OFRunLoop currentRunLoop].currentMode]; } - (bool)stream: (OFStream *)sock didReadIntoBuffer: (void *)buffer length: (size_t)length exception: (id)exception { OFRunLoopMode runLoopMode; unsigned char *SOCKSVersion; uint8_t hostLength; unsigned char port[2]; unsigned char *response, *addressLength; if (exception != nil) { _exception = [exception retain]; [self didConnect]; return false; } runLoopMode = [OFRunLoop currentRunLoop].currentMode; switch (_SOCKS5State) { case stateReadVersion: SOCKSVersion = buffer; if (SOCKSVersion[0] != 5 || SOCKSVersion[1] != 0) { _exception = [[OFConnectIPSocketFailedException alloc] initWithHost: _host port: _port socket: self errNo: EPROTONOSUPPORT]; [self didConnect]; return false; } [_request release]; _request = [[OFMutableData alloc] init]; [_request addItems: "\x05\x01\x00\x03" count: 4]; hostLength = (uint8_t)_host.UTF8StringLength; [_request addItem: &hostLength]; [_request addItems: _host.UTF8String count: hostLength]; port[0] = _port >> 8; port[1] = _port & 0xFF; [_request addItems: port count: 2]; _SOCKS5State = stateSendRequest; [_socket asyncWriteData: _request runLoopMode: runLoopMode]; return false; case stateReadResponse: response = buffer; if (response[0] != 5 || response[2] != 0) { _exception = [[OFConnectIPSocketFailedException alloc] initWithHost: _host port: _port socket: self errNo: EPROTONOSUPPORT]; [self didConnect]; return false; } if (response[1] != 0) { int errNo; switch (response[1]) { case 0x02: errNo = EPERM; break; case 0x03: errNo = ENETUNREACH; break; case 0x04: errNo = EHOSTUNREACH; break; case 0x05: errNo = ECONNREFUSED; break; case 0x06: errNo = ETIMEDOUT; break; case 0x07: errNo = EOPNOTSUPP; break; case 0x08: errNo = EAFNOSUPPORT; break; default: #ifdef EPROTO errNo = EPROTO; #else errNo = 0; #endif break; } _exception = [[OFConnectIPSocketFailedException alloc] initWithHost: _host port: _port socket: _socket errNo: errNo]; [self didConnect]; return false; } /* Skip the rest of the response */ switch (response[3]) { case 1: /* IPv4 */ _SOCKS5State = stateReadAddress; [_socket asyncReadIntoBuffer: _buffer exactLength: 4 + 2 runLoopMode: runLoopMode]; return false; case 3: /* Domain name */ _SOCKS5State = stateReadAddressLength; [_socket asyncReadIntoBuffer: _buffer exactLength: 1 runLoopMode: runLoopMode]; return false; case 4: /* IPv6 */ _SOCKS5State = stateReadAddress; [_socket asyncReadIntoBuffer: _buffer exactLength: 16 + 2 runLoopMode: runLoopMode]; return false; default: _exception = [[OFConnectIPSocketFailedException alloc] initWithHost: _host port: _port socket: self errNo: EPROTONOSUPPORT]; [self didConnect]; return false; } return false; case stateReadAddress: [self didConnect]; return false; case stateReadAddressLength: addressLength = buffer; _SOCKS5State = stateReadAddress; [_socket asyncReadIntoBuffer: _buffer exactLength: addressLength[0] + 2 runLoopMode: runLoopMode]; return false; default: OFAssert(0); return false; } } - (OFData *)stream: (OFStream *)sock didWriteData: (OFData *)data bytesWritten: (size_t)bytesWritten exception: (id)exception { OFRunLoopMode runLoopMode; if (exception != nil) { _exception = [exception retain]; [self didConnect]; return nil; } runLoopMode = [OFRunLoop currentRunLoop].currentMode; switch (_SOCKS5State) { case stateSendAuthentication: _SOCKS5State = stateReadVersion; [_socket asyncReadIntoBuffer: _buffer exactLength: 2 runLoopMode: runLoopMode]; return nil; case stateSendRequest: [_request release]; _request = nil; _SOCKS5State = stateReadResponse; [_socket asyncReadIntoBuffer: _buffer exactLength: 4 runLoopMode: runLoopMode]; return nil; default: OFAssert(0); return nil; } } @end objfw-1.1.6/src/OFTLSKey.h000066400000000000000000000062721465614216400151460ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "objfw-defs.h" #include #include "platform.h" #if !defined(OF_HAVE_THREADS) || \ (!defined(OF_HAVE_PTHREADS) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS)) # error No thread-local storage available! #endif #import "macros.h" /** @file */ #if defined(OF_HAVE_PTHREADS) # include typedef pthread_key_t OFTLSKey; #elif defined(OF_WINDOWS) # include typedef DWORD OFTLSKey; #elif defined(OF_MORPHOS) # include typedef ULONG OFTLSKey; #elif defined(OF_AMIGAOS) typedef struct _OFTLSKey { struct objc_hashtable *table; struct _OFTLSKey *next, *previous; } *OFTLSKey; #endif #ifdef __cplusplus extern "C" { #endif /** * @brief Creates a new Thread Local Storage key. * * @param key A pointer to the key to create * @return 0 on success, or an error number from `` on error */ extern int OFTLSKeyNew(OFTLSKey *key); /** * @brief Destroys the specified Thread Local Storage key. * * @param key A pointer to the key to destroy * @return 0 on success, or an error number from `` on error */ extern int OFTLSKeyFree(OFTLSKey key); #ifdef __cplusplus } #endif /* TLS keys are inlined for performance. */ #if defined(OF_HAVE_PTHREADS) || defined(DOXYGEN) /** * @brief Returns the current value for the specified Thread Local Storage key. * * @param key A pointer to the key whose value to return * @return The current value for the specified Thread Local Storage key */ static OF_INLINE void * OFTLSKeyGet(OFTLSKey key) { return pthread_getspecific(key); } /** * @brief Sets the current value for the specified Thread Local Storage key. * * @param key A pointer to the key whose value to set * @param value The new value for the key */ static OF_INLINE int OFTLSKeySet(OFTLSKey key, void *value) { return pthread_setspecific(key, value); } #elif defined(OF_WINDOWS) static OF_INLINE void * OFTLSKeyGet(OFTLSKey key) { return TlsGetValue(key); } static OF_INLINE int OFTLSKeySet(OFTLSKey key, void *value) { return (TlsSetValue(key, value) ? 0 : EINVAL); } #elif defined(OF_MORPHOS) static OF_INLINE void * OFTLSKeyGet(OFTLSKey key) { return (void *)TLSGetValue(key); } static OF_INLINE int OFTLSKeySet(OFTLSKey key, void *value) { return (TLSSetValue(key, (APTR)value) ? 0 : EINVAL); } #elif defined(OF_AMIGAOS) /* Those are too big too inline. */ # ifdef __cplusplus extern "C" { # endif extern void *OFTLSKeyGet(OFTLSKey key); extern int OFTLSKeySet(OFTLSKey key, void *value); # ifdef __cplusplus } # endif #endif objfw-1.1.6/src/OFTLSKey.m000066400000000000000000000020311465614216400151400ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" #if defined(OF_HAVE_PTHREADS) # include "platform/POSIX/OFTLSKey.m" #elif defined(OF_WINDOWS) # include "platform/Windows/OFTLSKey.m" #elif defined(OF_MORPHOS) # include "platform/MorphOS/OFTLSKey.m" #elif defined(OF_AMIGAOS) # include "platform/AmigaOS/OFTLSKey.m" #endif objfw-1.1.6/src/OFTLSStream.h000066400000000000000000000134541465614216400156510ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFStream.h" #import "OFRunLoop.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFTLSStream; /** * @brief An enum representing an error of an OFTLSStream. */ typedef enum { /** @brief An unknown error. */ OFTLSStreamErrorCodeUnknown, /** @brief Initialization of the TLS context failed. */ OFTLSStreamErrorCodeInitializationFailed } OFTLSStreamErrorCode; /** * @protocol OFTLSStreamDelegate OFTLSStream.h ObjFW/OFTLSStream.h * * A delegate for OFTLSStream. */ @protocol OFTLSStreamDelegate /** * @brief A method which is called when a TLS stream performed the client * handshake. * * @param stream The TLS stream which performed the handshake * @param host The host for which the handshake was performed * @param exception An exception that occurred during the handshake, or nil on * success */ - (void)stream: (OFTLSStream *)stream didPerformClientHandshakeWithHost: (OFString *)host exception: (nullable id)exception; @end /** * @class OFTLSStream OFTLSStream.h ObjFW/OFTLSStream.h * * @brief A class that provides Transport Layer Security on top of a stream. * * This class is a class cluster and returns a suitable OFTLSStream subclass, * if available. * * Subclasses need to override @ref lowlevelReadIntoBuffer:length:, * @ref lowlevelWriteBuffer:length:, * @ref lowlevelHasDataInReadBuffer and * @ref asyncPerformClientHandshakeWithHost:runLoopMode:. * * In order to get access to the underlying stream, @ref underlyingStream can * be used. */ @interface OFTLSStream: OFStream { OFStream *_underlyingStream; bool _verifiesCertificates; OF_RESERVE_IVARS(OFTLSStream, 4) } /** * @brief The underlying stream. */ @property (readonly, nonatomic) OFStream *underlyingStream; /** * @brief The delegate for asynchronous operations on the stream. * * @note The delegate is retained for as long as asynchronous operations are * still ongoing. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id delegate; /** * @brief Whether certificates are verified. Default is true. */ @property (nonatomic) bool verifiesCertificates; - (instancetype)init OF_UNAVAILABLE; /** * @brief Creates a new TLS stream with the specified stream as its underlying * stream. * * @param stream The stream to use as underlying stream. Must not be closed * before the TLS stream is closed. * @return A new, autoreleased TLS stream */ + (instancetype)streamWithStream: (OFStream *)stream; /** * @brief Initializes the TLS stream with the specified stream as its * underlying stream. * * @note The delegate of the specified stream will be changed to the TLS * stream. You must not change this before the TLS session is completed. * * @param stream The stream to use as underlying stream. Must not be closed * before the TLS stream is closed. * @return An initialized TLS stream */ - (instancetype)initWithStream: (OFStream *)stream OF_DESIGNATED_INITIALIZER; /** * @brief Asynchronously performs the TLS client handshake for the specified * host and calls the delegate afterwards. * * @param host The host to perform the handshake with * @throw OFTLSHandshakeFailedException The TLS handshake failed * @throw OFAlreadyOpenException The handshake was already performed */ - (void)asyncPerformClientHandshakeWithHost: (OFString *)host; /** * @brief Asynchronously performs the TLS client handshake for the specified * host and calls the delegate afterwards. * * @param host The host to perform the handshake with * @param runLoopMode The run loop mode in which to perform the async handshake * @throw OFTLSHandshakeFailedException The TLS handshake failed * @throw OFAlreadyOpenException The handshake was already performed */ - (void)asyncPerformClientHandshakeWithHost: (OFString *)host runLoopMode: (OFRunLoopMode)runLoopMode; /** * @brief Performs the TLS client handshake for the specified host. * * @param host The host to perform the handshake with * @throw OFTLSHandshakeFailedException The TLS handshake failed * @throw OFAlreadyOpenException The handshake was already performed */ - (void)performClientHandshakeWithHost: (OFString *)host; @end #ifdef __cplusplus extern "C" { #endif /** * @brief The implementation for OFTLSStream to use. * * This can be set to a class that is always used for OFTLSStream. This is * useful to either force a specific implementation or use one that ObjFW does * not know about. */ extern Class OFTLSStreamImplementation; /** * @brief Returns a string description for the TLS stream error code. * * @param errorCode The error code to return the description for * @return A string description for the TLS stream error code */ extern OFString *OFTLSStreamErrorCodeDescription( OFTLSStreamErrorCode errorCode); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFTLSStream.m000066400000000000000000000107201465614216400156470ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFTLSStream.h" #import "OFDate.h" #import "OFNotImplementedException.h" #import "OFTLSHandshakeFailedException.h" @interface OFTLSStreamHandshakeDelegate: OFObject { @public bool _done; id _exception; } @end Class OFTLSStreamImplementation = Nil; static const OFRunLoopMode handshakeRunLoopMode = @"OFTLSStreamHandshakeRunLoopMode"; /* * References to exceptions. This is needed because they are only used by * subclasses that are in a different library. */ void OF_VISIBILITY_HIDDEN _references_to_exceptions_of_OFTLSStream(void) { _OFTLSHandshakeFailedException_reference = 1; } OFString * OFTLSStreamErrorCodeDescription(OFTLSStreamErrorCode errorCode) { switch (errorCode) { case OFTLSStreamErrorCodeInitializationFailed: return @"Initialization of TLS context failed"; default: return @"Unknown error"; } } @implementation OFTLSStreamHandshakeDelegate - (void)dealloc { [_exception release]; [super dealloc]; } - (void)stream: (OFTLSStream *)stream didPerformClientHandshakeWithHost: (OFString *)host exception: (id)exception { _done = true; _exception = [exception retain]; } @end @implementation OFTLSStream @synthesize underlyingStream = _underlyingStream; @dynamic delegate; @synthesize verifiesCertificates = _verifiesCertificates; + (instancetype)alloc { if (self == [OFTLSStream class]) { if (OFTLSStreamImplementation != Nil) return [OFTLSStreamImplementation alloc]; @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; } return [super alloc]; } + (instancetype)streamWithStream: (OFStream *)stream { return [[[self alloc] initWithStream: stream] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithStream: (OFStream *)stream { self = [super init]; @try { _underlyingStream = [stream retain]; _verifiesCertificates = true; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_underlyingStream release]; [super dealloc]; } - (void)close { [_underlyingStream release]; _underlyingStream = nil; [super close]; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { OF_UNRECOGNIZED_SELECTOR } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { OF_UNRECOGNIZED_SELECTOR } - (bool)lowlevelIsAtEndOfStream { return _underlyingStream.atEndOfStream; } - (int)fileDescriptorForReading { return _underlyingStream.fileDescriptorForReading; } - (int)fileDescriptorForWriting { return _underlyingStream.fileDescriptorForWriting; } - (void)asyncPerformClientHandshakeWithHost: (OFString *)host { [self asyncPerformClientHandshakeWithHost: host runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncPerformClientHandshakeWithHost: (OFString *)host runLoopMode: (OFRunLoopMode)runLoopMode { OF_UNRECOGNIZED_SELECTOR } - (void)performClientHandshakeWithHost: (OFString *)host { void *pool = objc_autoreleasePoolPush(); id delegate = _delegate; OFTLSStreamHandshakeDelegate *handshakeDelegate = [[[OFTLSStreamHandshakeDelegate alloc] init] autorelease]; OFRunLoop *runLoop = [OFRunLoop currentRunLoop]; _delegate = handshakeDelegate; [self asyncPerformClientHandshakeWithHost: host runLoopMode: handshakeRunLoopMode]; while (!handshakeDelegate->_done) [runLoop runMode: handshakeRunLoopMode beforeDate: nil]; /* Cleanup */ [runLoop runMode: handshakeRunLoopMode beforeDate: [OFDate date]]; _delegate = delegate; if (handshakeDelegate->_exception != nil) @throw handshakeDelegate->_exception; objc_autoreleasePoolPop(pool); } @end objfw-1.1.6/src/OFTXTDNSResourceRecord.h000066400000000000000000000037441465614216400177270ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFDNSResourceRecord.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFTXTDNSResourceRecord \ * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h * * @brief A class representing a TXT DNS resource record. */ OF_SUBCLASSING_RESTRICTED @interface OFTXTDNSResourceRecord: OFDNSResourceRecord { OFArray OF_GENERIC(OFData *) *_textStrings; } /** * @brief The text of the resource record. */ @property (readonly, nonatomic) OFArray OF_GENERIC(OFData *) *textStrings; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFTXTDNSResourceRecord with the * specified name, class, text data and time to live. * * @param name The name for the resource record * @param DNSClass The class code for the resource record * @param textStrings An array of text strings for the resource record * @param TTL The time to live for the resource record * @return An initialized OFTXTDNSResourceRecord */ - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass textStrings: (OFArray OF_GENERIC(OFData *) *)textStrings TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFTXTDNSResourceRecord.m000066400000000000000000000067641465614216400177410ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFTXTDNSResourceRecord.h" #import "OFArray.h" #import "OFData.h" @implementation OFTXTDNSResourceRecord @synthesize textStrings = _textStrings; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass textStrings: (OFArray OF_GENERIC(OFData *) *)textStrings TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: DNSClass recordType: OFDNSRecordTypeTXT TTL: TTL]; @try { _textStrings = [textStrings copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_textStrings release]; [super dealloc]; } - (bool)isEqual: (id)object { OFTXTDNSResourceRecord *record; if (object == self) return true; if (![object isKindOfClass: [OFTXTDNSResourceRecord class]]) return false; record = object; if (record->_name != _name && ![record->_name isEqual: _name]) return false; if (record->_DNSClass != _DNSClass) return false; if (record->_recordType != _recordType) return false; if (record->_textStrings != _textStrings && ![record->_textStrings isEqual: _textStrings]) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddByte(&hash, _DNSClass >> 8); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType >> 8); OFHashAddByte(&hash, _recordType); OFHashAddHash(&hash, _textStrings.hash); OFHashFinalize(&hash); return hash; } - (OFString *)description { void *pool = objc_autoreleasePoolPush(); OFMutableString *text = [OFMutableString string]; bool first = true; OFString *ret; for (OFData *string in _textStrings) { const unsigned char *stringItems = string.items; size_t stringCount = string.count; if (first) { first = false; [text appendString: @"\""]; } else [text appendString: @" \""]; for (size_t i = 0; i < stringCount; i++) { if (stringItems[i] == '\\') [text appendString: @"\\\\"]; else if (stringItems[i] == '"') [text appendString: @"\\\""]; else if (stringItems[i] < 0x20) [text appendFormat: @"\\x%02X", stringItems[i]]; else if (stringItems[i] < 0x7F) [text appendFormat: @"%c", stringItems[i]]; else [text appendFormat: @"\\x%02X", stringItems[i]]; } [text appendString: @"\""]; } ret = [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tClass = %@\n" @"\tText strings = %@\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFDNSClassName(_DNSClass), text, _TTL]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @end objfw-1.1.6/src/OFTaggedPointerColor.h000066400000000000000000000016721465614216400175650ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFColor.h" OF_ASSUME_NONNULL_BEGIN @interface OFTaggedPointerColor: OFColor + (OFTaggedPointerColor *)colorWithRed: (uint8_t)red green: (uint8_t)green blue: (uint8_t)blue; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFTaggedPointerColor.m000066400000000000000000000027731465614216400175750ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFTaggedPointerColor.h" static int colorTag; @implementation OFTaggedPointerColor + (void)initialize { if (self == [OFTaggedPointerColor class]) colorTag = objc_registerTaggedPointerClass(self); } + (OFTaggedPointerColor *)colorWithRed: (uint8_t)red green: (uint8_t)green blue: (uint8_t)blue { return objc_createTaggedPointer(colorTag, (uintptr_t)red << 16 | (uintptr_t)green << 8 | (uintptr_t)blue); } - (void)getRed: (float *)red green: (float *)green blue: (float *)blue alpha: (float *)alpha { uintptr_t value = object_getTaggedPointerValue(self); *red = (float)(value >> 16) / 255; *green = (float)((value >> 8) & 0xFF) / 255; *blue = (float)(value & 0xFF) / 255; if (alpha != NULL) *alpha = 1; } OF_SINGLETON_METHODS @end objfw-1.1.6/src/OFTaggedPointerDate.h000066400000000000000000000017001465614216400173540ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFDate.h" OF_ASSUME_NONNULL_BEGIN #if UINTPTR_MAX == UINT64_MAX @interface OFTaggedPointerDate: OFDate + (OFTaggedPointerDate *)dateWithUInt64TimeIntervalSince1970: (uint64_t)value; @end #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFTaggedPointerDate.m000066400000000000000000000025531465614216400173700ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFTaggedPointerDate.h" #if UINTPTR_MAX == UINT64_MAX static int dateTag; @implementation OFTaggedPointerDate + (void)initialize { if (self == [OFTaggedPointerDate class]) dateTag = objc_registerTaggedPointerClass(self); } + (OFTaggedPointerDate *)dateWithUInt64TimeIntervalSince1970: (uint64_t)value { return objc_createTaggedPointer(dateTag, value & ~(UINT64_C(4) << 60)); } - (OFTimeInterval)timeIntervalSince1970 { uint64_t value = (uint64_t)object_getTaggedPointerValue(self); value |= UINT64_C(4) << 60; return OFFromBigEndianDouble(OFBitConvertUInt64ToDouble(OFToBigEndian64( value))); } OF_SINGLETON_METHODS @end #endif objfw-1.1.6/src/OFTaggedPointerNumber.h000066400000000000000000000015721465614216400177360ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFNumber.h" OF_ASSUME_NONNULL_BEGIN #define OFTaggedPointerNumberTagBits 4 @interface OFTaggedPointerNumber: OFNumber @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFTaggedPointerNumber.m000066400000000000000000000124461465614216400177450ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFTaggedPointerNumber.h" #import "OFInvalidFormatException.h" enum Tag { tagChar, tagShort, tagInt, tagLong, tagLongLong, tagUnsignedChar, tagUnsignedShort, tagUnsignedInt, tagUnsignedLong, tagUnsignedLongLong, }; static const uintptr_t tagMask = (1 << OFTaggedPointerNumberTagBits) - 1; static int numberTag; @implementation OFTaggedPointerNumber + (void)initialize { if (self == [OFTaggedPointerNumber class]) numberTag = objc_registerTaggedPointerClass(self); } + (OFTaggedPointerNumber *)numberWithChar: (signed char)value { return objc_createTaggedPointer(numberTag, ((uintptr_t)(unsigned char)value << OFTaggedPointerNumberTagBits) | tagChar); } + (OFTaggedPointerNumber *)numberWithShort: (short)value { return objc_createTaggedPointer(numberTag, ((uintptr_t)(unsigned short)value << OFTaggedPointerNumberTagBits) | tagShort); } + (OFTaggedPointerNumber *)numberWithInt: (int)value { return objc_createTaggedPointer(numberTag, ((uintptr_t)(unsigned int)value << OFTaggedPointerNumberTagBits) | tagInt); } + (OFTaggedPointerNumber *)numberWithLong: (long)value { return objc_createTaggedPointer(numberTag, ((uintptr_t)(unsigned long)value << OFTaggedPointerNumberTagBits) | tagLong); } + (OFTaggedPointerNumber *)numberWithLongLong: (long long)value { return objc_createTaggedPointer(numberTag, ((uintptr_t)(unsigned long long)value << OFTaggedPointerNumberTagBits) | tagLongLong); } + (OFTaggedPointerNumber *)numberWithUnsignedChar: (unsigned char)value { return objc_createTaggedPointer(numberTag, ((uintptr_t)value << OFTaggedPointerNumberTagBits) | tagUnsignedChar); } + (OFTaggedPointerNumber *)numberWithUnsignedShort: (unsigned short)value { return objc_createTaggedPointer(numberTag, ((uintptr_t)value << OFTaggedPointerNumberTagBits) | tagUnsignedShort); } + (OFTaggedPointerNumber *)numberWithUnsignedInt: (unsigned int)value { return objc_createTaggedPointer(numberTag, ((uintptr_t)value << OFTaggedPointerNumberTagBits) | tagUnsignedInt); } + (OFTaggedPointerNumber *)numberWithUnsignedLong: (unsigned long)value { return objc_createTaggedPointer(numberTag, ((uintptr_t)value << OFTaggedPointerNumberTagBits) | tagUnsignedLong); } + (OFTaggedPointerNumber *)numberWithUnsignedLongLong: (unsigned long long)value { return objc_createTaggedPointer(numberTag, ((uintptr_t)value << OFTaggedPointerNumberTagBits) | tagUnsignedLongLong); } - (const char *)objCType { uintptr_t value = object_getTaggedPointerValue(self); switch (value & tagMask) { case tagChar: return @encode(signed char); case tagShort: return @encode(short); case tagInt: return @encode(int); case tagLong: return @encode(long); case tagLongLong: return @encode(long long); case tagUnsignedChar: return @encode(unsigned char); case tagUnsignedShort: return @encode(unsigned short); case tagUnsignedInt: return @encode(unsigned int); case tagUnsignedLong: return @encode(unsigned long); case tagUnsignedLongLong: return @encode(unsigned long long); default: @throw [OFInvalidFormatException exception]; } } #define RETURN_VALUE \ uintptr_t value = object_getTaggedPointerValue(self); \ \ switch (value & tagMask) { \ case tagChar: \ return (signed char)(unsigned char) \ (value >> OFTaggedPointerNumberTagBits); \ case tagShort: \ return (short)(unsigned short) \ (value >> OFTaggedPointerNumberTagBits); \ case tagInt: \ return (int)(unsigned int) \ (value >> OFTaggedPointerNumberTagBits); \ case tagLong: \ return (long)(unsigned long) \ (value >> OFTaggedPointerNumberTagBits); \ case tagLongLong: \ return (long long)(unsigned long long) \ (value >> OFTaggedPointerNumberTagBits); \ case tagUnsignedChar: \ return (unsigned char) \ (value >> OFTaggedPointerNumberTagBits); \ case tagUnsignedShort: \ return (unsigned short) \ (value >> OFTaggedPointerNumberTagBits); \ case tagUnsignedInt: \ return (unsigned int) \ (value >> OFTaggedPointerNumberTagBits); \ case tagUnsignedLong: \ return (unsigned long) \ (value >> OFTaggedPointerNumberTagBits); \ case tagUnsignedLongLong: \ return (unsigned long long) \ (value >> OFTaggedPointerNumberTagBits); \ default: \ @throw [OFInvalidFormatException exception]; \ } - (long long)longLongValue { RETURN_VALUE } - (unsigned long long)unsignedLongLongValue { RETURN_VALUE } - (double)doubleValue { RETURN_VALUE } #undef RETURN_VALUE OF_SINGLETON_METHODS @end objfw-1.1.6/src/OFTarArchive.h000066400000000000000000000140571465614216400160630ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFString.h" #import "OFTarArchiveEntry.h" OF_ASSUME_NONNULL_BEGIN @class OFIRI; @class OFStream; /** * @class OFTarArchive OFTarArchive.h ObjFW/OFTarArchive.h * * @brief A class for accessing and manipulating tar archives. */ OF_SUBCLASSING_RESTRICTED @interface OFTarArchive: OFObject { OFStream *_stream; uint_least8_t _mode; OFStringEncoding _encoding; OFTarArchiveEntry *_Nullable _currentEntry; #ifdef OF_TAR_ARCHIVE_M @public #endif OFStream *_Nullable _lastReturnedStream; } /** * @brief The encoding to use for the archive. Defaults to UTF-8. */ @property (nonatomic) OFStringEncoding encoding; /** * @brief Creates a new OFTarArchive object with the specified stream. * * @param stream A stream from which the tar archive will be read. * For append mode, this needs to be an OFSeekableStream. * @param mode The mode for the tar file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return A new, autoreleased OFTarArchive * @throw OFInvalidFormatException The archive has an invalid format * @throw OFSeekFailedException The archive was open in append mode and seeking * failed */ + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode; /** * @brief Creates a new OFTarArchive object with the specified file. * * @param IRI The IRI to the tar archive * @param mode The mode for the tar file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return A new, autoreleased OFTarArchive * @throw OFInvalidFormatException The archive has an invalid format * @throw OFSeekFailedException The archive was open in append mode and seeking * failed */ + (instancetype)archiveWithIRI: (OFIRI *)IRI mode: (OFString *)mode; /** * @brief Creates an IRI for accessing the specified file within the specified * tar archive. * * @param path The path of the file within the archive * @param IRI The IRI of the archive * @return An IRI for accessing the specified file within the specified tar * archive */ + (OFIRI *)IRIForFilePath: (OFString *)path inArchiveWithIRI: (OFIRI *)IRI; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFTarArchive object with the * specified stream. * * @param stream A stream from which the tar archive will be read. * For append mode, this needs to be an OFSeekableStream. * @param mode The mode for the tar file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return An initialized OFTarArchive * @throw OFInvalidFormatException The archive has an invalid format * @throw OFSeekFailedException The archive was open in append mode and seeking * failed */ - (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated OFTarArchive object with the * specified file. * * @param IRI The IRI to the tar archive * @param mode The mode for the tar file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return An initialized OFTarArchive * @throw OFInvalidFormatException The archive has an invalid format * @throw OFSeekFailedException The archive was open in append mode and seeking * failed */ - (instancetype)initWithIRI: (OFIRI *)IRI mode: (OFString *)mode; /** * @brief Returns the next entry from the tar archive or `nil` if all entries * have been read. * * @note This is only available in read mode. * * @warning Calling @ref nextEntry will invalidate all streams returned by * @ref streamForReadingCurrentEntry or * @ref streamForWritingEntry:! Reading from or writing to an * invalidated stream will throw an @ref OFReadFailedException or * @ref OFWriteFailedException! * * @return The next entry from the tar archive or `nil` if all entries have * been read * @throw OFInvalidFormatException The archive has an invalid format */ - (nullable OFTarArchiveEntry *)nextEntry; /** * @brief Returns a stream for reading the current entry. * * @note This is only available in read mode. * * @note The returned stream conforms to @ref OFReadyForReadingObserving if the * underlying stream does so, too. * * @return A stream for reading the current entry */ - (OFStream *)streamForReadingCurrentEntry; /** * @brief Returns a stream for writing the specified entry. * * @note This is only available in write and append mode. * * @note The returned stream conforms to @ref OFReadyForWritingObserving if the * underlying stream does so, too. * * @warning Calling @ref streamForWritingEntry: will invalidate all streams * returned by @ref streamForReadingCurrentEntry or * @ref streamForWritingEntry:! Reading from or writing to an * invalidated stream will throw an @ref OFReadFailedException or * @ref OFWriteFailedException! * * @param entry The entry for which a stream for writing should be returned * @return A stream for writing the specified entry */ - (OFStream *)streamForWritingEntry: (OFTarArchiveEntry *)entry; /** * @brief Closes the OFTarArchive. * * @throw OFNotOpenException The archive is not open */ - (void)close; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFTarArchive.m000066400000000000000000000263301465614216400160650ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #define OF_TAR_ARCHIVE_M #include "config.h" #include #import "OFTarArchive.h" #import "OFTarArchiveEntry.h" #import "OFTarArchiveEntry+Private.h" #import "OFArchiveIRIHandler.h" #import "OFDate.h" #import "OFIRI.h" #import "OFIRIHandler.h" #import "OFKernelEventObserver.h" #import "OFSeekableStream.h" #import "OFStream.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFWriteFailedException.h" enum { modeRead, modeWrite, modeAppend }; OF_DIRECT_MEMBERS @interface OFTarArchiveFileReadStream: OFStream { OFTarArchive *_archive; OFTarArchiveEntry *_entry; OFStream *_stream; unsigned long long _toRead; bool _atEndOfStream, _skipped; } - (instancetype)of_initWithArchive: (OFTarArchive *)archive stream: (OFStream *)stream entry: (OFTarArchiveEntry *)entry; - (void)of_skip; @end OF_DIRECT_MEMBERS @interface OFTarArchiveFileWriteStream: OFStream { OFTarArchive *_archive; OFTarArchiveEntry *_entry; OFStream *_stream; unsigned long long _toWrite; } - (instancetype)of_initWithArchive: (OFTarArchive *)archive stream: (OFStream *)stream entry: (OFTarArchiveEntry *)entry; @end @implementation OFTarArchive: OFObject @synthesize encoding = _encoding; + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode { return [[[self alloc] initWithStream: stream mode: mode] autorelease]; } + (instancetype)archiveWithIRI: (OFIRI *)IRI mode: (OFString *)mode { return [[[self alloc] initWithIRI: IRI mode: mode] autorelease]; } + (OFIRI *)IRIForFilePath: (OFString *)path inArchiveWithIRI: (OFIRI *)IRI { return _OFArchiveIRIHandlerIRIForFileInArchive(@"tar", path, IRI); } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode { self = [super init]; @try { _stream = [stream retain]; if ([mode isEqual: @"r"]) _mode = modeRead; else if ([mode isEqual: @"w"]) _mode = modeWrite; else if ([mode isEqual: @"a"]) _mode = modeAppend; else @throw [OFInvalidArgumentException exception]; if (_mode == modeAppend) { uint32_t buffer[1024 / sizeof(uint32_t)]; bool empty = true; if (![_stream isKindOfClass: [OFSeekableStream class]]) @throw [OFInvalidArgumentException exception]; [(OFSeekableStream *)_stream seekToOffset: -1024 whence: OFSeekEnd]; [_stream readIntoBuffer: buffer exactLength: 1024]; for (size_t i = 0; i < 1024 / sizeof(uint32_t); i++) if (buffer[i] != 0) empty = false; if (!empty) @throw [OFInvalidFormatException exception]; [(OFSeekableStream *)stream seekToOffset: -1024 whence: OFSeekEnd]; } _encoding = OFStringEncodingUTF8; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithIRI: (OFIRI *)IRI mode: (OFString *)mode { void *pool = objc_autoreleasePoolPush(); OFStream *stream; @try { if ([mode isEqual: @"a"]) stream = [OFIRIHandler openItemAtIRI: IRI mode: @"r+"]; else stream = [OFIRIHandler openItemAtIRI: IRI mode: mode]; } @catch (id e) { [self release]; @throw e; } self = [self initWithStream: stream mode: mode]; objc_autoreleasePoolPop(pool); return self; } - (void)dealloc { [self close]; [_currentEntry release]; [super dealloc]; } - (OFTarArchiveEntry *)nextEntry { uint32_t buffer[512 / sizeof(uint32_t)]; bool empty = true; if (_mode != modeRead) @throw [OFInvalidArgumentException exception]; if (_currentEntry != nil && _lastReturnedStream == nil) { /* * No read stream was created since the last call to * -[nextEntry]. Create it so that we can properly skip the * data. */ void *pool = objc_autoreleasePoolPush(); [self streamForReadingCurrentEntry]; objc_autoreleasePoolPop(pool); } [_currentEntry release]; _currentEntry = nil; [(OFTarArchiveFileReadStream *)_lastReturnedStream of_skip]; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } _lastReturnedStream = nil; if (_stream.atEndOfStream) return nil; [_stream readIntoBuffer: buffer exactLength: 512]; for (size_t i = 0; i < 512 / sizeof(uint32_t); i++) if (buffer[i] != 0) empty = false; if (empty) { [_stream readIntoBuffer: buffer exactLength: 512]; for (size_t i = 0; i < 512 / sizeof(uint32_t); i++) if (buffer[i] != 0) @throw [OFInvalidFormatException exception]; return nil; } _currentEntry = [[OFTarArchiveEntry alloc] of_initWithHeader: (unsigned char *)buffer encoding: _encoding]; return _currentEntry; } - (OFStream *)streamForReadingCurrentEntry { if (_mode != modeRead) @throw [OFInvalidArgumentException exception]; if (_currentEntry == nil) @throw [OFInvalidArgumentException exception]; _lastReturnedStream = [[[OFTarArchiveFileReadStream alloc] of_initWithArchive: self stream: _stream entry: _currentEntry] autorelease]; [_currentEntry release]; _currentEntry = nil; return _lastReturnedStream; } - (OFStream *)streamForWritingEntry: (OFTarArchiveEntry *)entry { if (_mode != modeWrite && _mode != modeAppend) @throw [OFInvalidArgumentException exception]; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } _lastReturnedStream = nil; [entry of_writeToStream: _stream encoding: _encoding]; _lastReturnedStream = [[[OFTarArchiveFileWriteStream alloc] of_initWithArchive: self stream: _stream entry: entry] autorelease]; return _lastReturnedStream; } - (void)close { if (_stream == nil) return; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } _lastReturnedStream = nil; if (_mode == modeWrite || _mode == modeAppend) { char buffer[1024]; memset(buffer, '\0', 1024); [_stream writeBuffer: buffer length: 1024]; } [_stream release]; _stream = nil; } @end @implementation OFTarArchiveFileReadStream - (instancetype)of_initWithArchive: (OFTarArchive *)archive stream: (OFStream *)stream entry: (OFTarArchiveEntry *)entry { self = [super init]; @try { _archive = [archive retain]; _entry = [entry copy]; _stream = [stream retain]; _toRead = entry.uncompressedSize; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_stream != nil) [self close]; [_entry release]; if (_archive->_lastReturnedStream == self) _archive->_lastReturnedStream = nil; [_archive release]; [super dealloc]; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { size_t ret; if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (_atEndOfStream) return 0; #if SIZE_MAX >= ULLONG_MAX if (length > ULLONG_MAX) @throw [OFOutOfRangeException exception]; #endif if ((unsigned long long)length > _toRead) length = (size_t)_toRead; ret = [_stream readIntoBuffer: buffer length: length]; if (ret == 0) _atEndOfStream = true; _toRead -= ret; return ret; } - (bool)lowlevelIsAtEndOfStream { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; return _atEndOfStream; } - (bool)lowlevelHasDataInReadBuffer { return _stream.hasDataInReadBuffer; } - (int)fileDescriptorForReading { return ((id )_stream) .fileDescriptorForReading; } - (void)close { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; [self of_skip]; [_stream release]; _stream = nil; [super close]; } - (void)of_skip { if (_stream == nil || _skipped) return; if ([_stream isKindOfClass: [OFSeekableStream class]] && _toRead <= LLONG_MAX && (OFStreamOffset)_toRead == (long long)_toRead) { unsigned long long size; [(OFSeekableStream *)_stream seekToOffset: (OFStreamOffset)_toRead whence: OFSeekCurrent]; _toRead = 0; size = _entry.uncompressedSize; if (size % 512 != 0) [(OFSeekableStream *)_stream seekToOffset: 512 - (size % 512) whence: OFSeekCurrent]; } else { char buffer[512]; unsigned long long size; while (_toRead >= 512) { [_stream readIntoBuffer: buffer exactLength: 512]; _toRead -= 512; } if (_toRead > 0) { [_stream readIntoBuffer: buffer exactLength: (size_t)_toRead]; _toRead = 0; } size = _entry.uncompressedSize; if (size % 512 != 0) [_stream readIntoBuffer: buffer exactLength: (size_t)(512 - (size % 512))]; } _skipped = true; } @end @implementation OFTarArchiveFileWriteStream - (instancetype)of_initWithArchive: (OFTarArchive *)archive stream: (OFStream *)stream entry: (OFTarArchiveEntry *)entry { self = [super init]; @try { _archive = [archive retain]; _entry = [entry copy]; _stream = [stream retain]; _toWrite = entry.uncompressedSize; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_stream != nil) [self close]; [_entry release]; if (_archive->_lastReturnedStream == self) _archive->_lastReturnedStream = nil; [_archive release]; [super dealloc]; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (length > _toWrite) @throw [OFOutOfRangeException exception]; @try { [_stream writeBuffer: buffer length: length]; } @catch (OFWriteFailedException *e) { OFEnsure(e.bytesWritten <= length); _toWrite -= e.bytesWritten; if (e.errNo == EWOULDBLOCK || e.errNo == EAGAIN) return e.bytesWritten; @throw e; } _toWrite -= length; return length; } - (bool)lowlevelIsAtEndOfStream { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; return (_toWrite == 0); } - (int)fileDescriptorForWriting { return ((id )_stream) .fileDescriptorForWriting; } - (void)close { unsigned long long remainder; if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (_toWrite > 0) @throw [OFTruncatedDataException exception]; remainder = 512 - _entry.uncompressedSize % 512; if (remainder != 512) { bool didBufferWrites = _stream.buffersWrites; _stream.buffersWrites = true; while (remainder--) [_stream writeInt8: 0]; [_stream flushWriteBuffer]; _stream.buffersWrites = didBufferWrites; } [_stream release]; _stream = nil; [super close]; } @end objfw-1.1.6/src/OFTarArchiveEntry+Private.h000066400000000000000000000022351465614216400205060ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFTarArchiveEntry.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @class OFStream; @interface OFTarArchiveEntry () - (instancetype)of_init OF_METHOD_FAMILY(init); - (instancetype)of_initWithHeader: (unsigned char [_Nonnull 512])header encoding: (OFStringEncoding)encoding OF_METHOD_FAMILY(init) OF_DIRECT; - (void)of_writeToStream: (OFStream *)stream encoding: (OFStringEncoding)encoding OF_DIRECT; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFTarArchiveEntry.h000066400000000000000000000053131465614216400171000ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFArchiveEntry.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFDate; @class OFNumber; /** * @brief The type of the archive entry. */ typedef enum { /** Normal file */ OFTarArchiveEntryTypeFile = '0', /** Hard link */ OFTarArchiveEntryTypeLink = '1', /** Symbolic link */ OFTarArchiveEntryTypeSymlink = '2', /** Character device */ OFTarArchiveEntryTypeCharacterDevice = '3', /** Block device */ OFTarArchiveEntryTypeBlockDevice = '4', /** Directory */ OFTarArchiveEntryTypeDirectory = '5', /** FIFO */ OFTarArchiveEntryTypeFIFO = '6', /** Contiguous file */ OFTarArchiveEntryTypeContiguousFile = '7', } OFTarArchiveEntryType; /** * @class OFTarArchiveEntry OFTarArchiveEntry.h ObjFW/OFTarArchiveEntry.h * * @brief A class which represents an entry of a tar archive. */ @interface OFTarArchiveEntry: OFObject { OFString *_fileName; OFNumber *_POSIXPermissions, *_ownerAccountID, *_groupOwnerAccountID; unsigned long long _compressedSize, _uncompressedSize; OFDate *_modificationDate; OFTarArchiveEntryType _type; OFString *_Nullable _targetFileName; OFString *_Nullable _ownerAccountName; OFString *_Nullable _groupOwnerAccountName; unsigned long _deviceMajor, _deviceMinor; OF_RESERVE_IVARS(OFTarArchiveEntry, 4) } /** * @brief The type of the archive entry. * * See @ref OFTarArchiveEntryType. */ @property (readonly, nonatomic) OFTarArchiveEntryType type; /** * @brief The file name of the target (for a hard link or symbolic link). */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *targetFileName; /** * @brief The device major (if the file is a device). */ @property (readonly, nonatomic) unsigned long deviceMajor; /** * @brief The device major (if the file is a device). */ @property (readonly, nonatomic) unsigned long deviceMinor; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END #import "OFMutableTarArchiveEntry.h" objfw-1.1.6/src/OFTarArchiveEntry.m000066400000000000000000000226741465614216400171160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFTarArchiveEntry.h" #import "OFTarArchiveEntry+Private.h" #import "OFDate.h" #import "OFNumber.h" #import "OFStream.h" #import "OFString.h" #import "OFOutOfRangeException.h" static OFString * stringFromBuffer(const unsigned char *buffer, size_t length, OFStringEncoding encoding) { for (size_t i = 0; i < length; i++) if (buffer[i] == '\0') length = i; return [OFString stringWithCString: (const char *)buffer encoding: encoding length: length]; } static void stringToBuffer(unsigned char *buffer, OFString *string, size_t length, OFStringEncoding encoding) { size_t cStringLength = [string cStringLengthWithEncoding: encoding]; if (cStringLength > length) @throw [OFOutOfRangeException exception]; memcpy(buffer, [string cStringWithEncoding: encoding], cStringLength); for (size_t i = cStringLength; i < length; i++) buffer[i] = '\0'; } static unsigned long long octalValueFromBuffer(const unsigned char *buffer, size_t length, unsigned long long max) { unsigned long long value = 0; if (length == 0) return 0; if (buffer[0] == 0x80) { for (size_t i = 1; i < length; i++) value = (value << 8) | buffer[i]; } else value = [stringFromBuffer(buffer, length, OFStringEncodingASCII) unsignedLongLongValueWithBase: 8]; if (value > max) @throw [OFOutOfRangeException exception]; return value; } @implementation OFTarArchiveEntry /* * The following is optional in OFArchiveEntry, but Apple GCC 4.0.1 is buggy * and needs this to stop complaining. */ @dynamic fileComment; - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)of_init { self = [super init]; @try { _type = OFTarArchiveEntryTypeFile; _POSIXPermissions = [[OFNumber alloc] initWithUnsignedShort: 0644]; _modificationDate = [[OFDate alloc] init]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)of_initWithHeader: (unsigned char [512])header encoding: (OFStringEncoding)encoding { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFString *targetFileName; _fileName = [stringFromBuffer(header, 100, encoding) copy]; _POSIXPermissions = [[OFNumber alloc] initWithUnsignedLongLong: octalValueFromBuffer(header + 100, 8, ULONG_MAX)]; _ownerAccountID = [[OFNumber alloc] initWithUnsignedLongLong: octalValueFromBuffer(header + 108, 8, ULONG_MAX)]; _groupOwnerAccountID = [[OFNumber alloc] initWithUnsignedLongLong: octalValueFromBuffer(header + 116, 8, ULONG_MAX)]; _uncompressedSize = (unsigned long long)octalValueFromBuffer( header + 124, 12, ULLONG_MAX); _compressedSize = _uncompressedSize + (512 - _uncompressedSize % 512); _modificationDate = [[OFDate alloc] initWithTimeIntervalSince1970: (OFTimeInterval)octalValueFromBuffer( header + 136, 12, ULLONG_MAX)]; _type = header[156]; targetFileName = stringFromBuffer(header + 157, 100, encoding); if (targetFileName.length > 0) _targetFileName = [targetFileName copy]; if (_type == '\0') _type = OFTarArchiveEntryTypeFile; if (memcmp(header + 257, "ustar\0" "00", 8) == 0) { OFString *prefix; _ownerAccountName = [stringFromBuffer(header + 265, 32, encoding) copy]; _groupOwnerAccountName = [stringFromBuffer(header + 297, 32, encoding) copy]; _deviceMajor = (unsigned long)octalValueFromBuffer( header + 329, 8, ULONG_MAX); _deviceMinor = (unsigned long)octalValueFromBuffer( header + 337, 8, ULONG_MAX); prefix = stringFromBuffer(header + 345, 155, encoding); if (prefix.length > 0) { OFString *fileName = [OFString stringWithFormat: @"%@/%@", prefix, _fileName]; [_fileName release]; _fileName = [fileName copy]; } } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_fileName release]; [_POSIXPermissions release]; [_ownerAccountID release]; [_groupOwnerAccountID release]; [_modificationDate release]; [_targetFileName release]; [_ownerAccountName release]; [_groupOwnerAccountName release]; [super dealloc]; } - (id)copy { return [self retain]; } - (id)mutableCopy { OFTarArchiveEntry *copy = [[OFMutableTarArchiveEntry alloc] initWithFileName: _fileName]; @try { copy->_POSIXPermissions = [_POSIXPermissions retain]; copy->_ownerAccountID = [_ownerAccountID retain]; copy->_groupOwnerAccountID = [_groupOwnerAccountID retain]; copy->_compressedSize = _compressedSize; copy->_uncompressedSize = _uncompressedSize; copy->_modificationDate = [_modificationDate copy]; copy->_type = _type; copy->_targetFileName = [_targetFileName copy]; copy->_ownerAccountName = [_ownerAccountName copy]; copy->_groupOwnerAccountName = [_groupOwnerAccountName copy]; copy->_deviceMajor = _deviceMajor; copy->_deviceMinor = _deviceMinor; } @catch (id e) { [copy release]; @throw e; } return copy; } - (OFString *)fileName { return _fileName; } - (OFNumber *)POSIXPermissions { return _POSIXPermissions; } - (OFNumber *)ownerAccountID { return _ownerAccountID; } - (OFNumber *)groupOwnerAccountID { return _groupOwnerAccountID; } - (unsigned long long)compressedSize { return _compressedSize; } - (unsigned long long)uncompressedSize { return _uncompressedSize; } - (OFDate *)modificationDate { return _modificationDate; } - (OFTarArchiveEntryType)type { return _type; } - (OFString *)targetFileName { return _targetFileName; } - (OFString *)ownerAccountName { return _ownerAccountName; } - (OFString *)groupOwnerAccountName { return _groupOwnerAccountName; } - (unsigned long)deviceMajor { return _deviceMajor; } - (unsigned long)deviceMinor { return _deviceMinor; } - (OFString *)description { void *pool = objc_autoreleasePoolPush(); OFString *POSIXPermissions = nil, *ret; if (_POSIXPermissions != nil) POSIXPermissions = [OFString stringWithFormat: @"%ho", _POSIXPermissions.unsignedShortValue]; ret = [OFString stringWithFormat: @"<%@:\n" @"\tFile name = %@\n" @"\tPOSIX permissions = %@\n" @"\tOwner account ID = %@\n" @"\tGroup owner account ID = %@\n" @"\tCompressed size = %llu\n" @"\tUncompressed size = %llu\n" @"\tModification date = %@\n" @"\tType = %u\n" @"\tTarget file name = %@\n" @"\tOwner account name = %@\n" @"\tGroup owner account name = %@\n" @"\tDevice major = %" PRIu32 @"\n" @"\tDevice minor = %" PRIu32 @"\n" @">", self.class, _fileName, POSIXPermissions, _ownerAccountID, _groupOwnerAccountID, _compressedSize, _uncompressedSize, _modificationDate, _type, _targetFileName, _ownerAccountName, _groupOwnerAccountName, _deviceMajor, _deviceMinor]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (void)of_writeToStream: (OFStream *)stream encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); unsigned char buffer[512]; unsigned long long modificationDate; uint16_t checksum = 0; stringToBuffer(buffer, _fileName, 100, encoding); stringToBuffer(buffer + 100, [OFString stringWithFormat: @"%06o ", _POSIXPermissions.unsignedShortValue], 8, OFStringEncodingASCII); stringToBuffer(buffer + 108, [OFString stringWithFormat: @"%06o ", _ownerAccountID.unsignedShortValue], 8, OFStringEncodingASCII); stringToBuffer(buffer + 116, [OFString stringWithFormat: @"%06o ", _groupOwnerAccountID.unsignedShortValue], 8, OFStringEncodingASCII); stringToBuffer(buffer + 124, [OFString stringWithFormat: @"%011llo ", _uncompressedSize], 12, OFStringEncodingASCII); modificationDate = _modificationDate.timeIntervalSince1970; stringToBuffer(buffer + 136, [OFString stringWithFormat: @"%011llo", modificationDate], 12, OFStringEncodingASCII); /* * During checksumming, the checksum field is expected to be set to 8 * spaces. */ memset(buffer + 148, ' ', 8); buffer[156] = _type; stringToBuffer(buffer + 157, _targetFileName, 100, encoding); /* ustar */ memcpy(buffer + 257, "ustar\0" "00", 8); stringToBuffer(buffer + 265, _ownerAccountName, 32, encoding); stringToBuffer(buffer + 297, _groupOwnerAccountName, 32, encoding); stringToBuffer(buffer + 329, [OFString stringWithFormat: @"%06" PRIo32 " ", _deviceMajor], 8, OFStringEncodingASCII); stringToBuffer(buffer + 337, [OFString stringWithFormat: @"%06" PRIo32 " ", _deviceMinor], 8, OFStringEncodingASCII); memset(buffer + 345, '\0', 155 + 12); /* Fill in the checksum */ for (size_t i = 0; i < 500; i++) checksum += buffer[i]; stringToBuffer(buffer + 148, [OFString stringWithFormat: @"%06" PRIo16, checksum], 7, OFStringEncodingASCII); [stream writeBuffer: buffer length: sizeof(buffer)]; objc_autoreleasePoolPop(pool); } @end objfw-1.1.6/src/OFThread+Private.h000066400000000000000000000016131465614216400166420ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFThread.h" OF_ASSUME_NONNULL_BEGIN #ifdef OF_HAVE_THREADS OF_DIRECT_MEMBERS @interface OFThread () + (void)of_createMainThread; @end #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFThread.h000066400000000000000000000211201465614216400152270ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include #import "OFObject.h" #ifdef OF_HAVE_THREADS # import "OFPlainThread.h" #endif OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFDate; #ifdef OF_HAVE_SOCKETS @class OFDNSResolver; #endif @class OFRunLoop; @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); #if defined(OF_HAVE_THREADS) && defined(OF_HAVE_BLOCKS) /** * @brief A block to be executed in a new thread. * * @return The object which should be returned when the thread is joined */ typedef id _Nullable (^OFThreadBlock)(void); #endif /** * @class OFThread OFThread.h ObjFW/OFThread.h * * @brief A class which provides portable threads. * * To use it, you should create a new class derived from it and reimplement * main. * * @warning Some operating systems such as AmigaOS need special per-thread * initialization of sockets. If you intend to use sockets in the * thread, set the @ref supportsSockets property to true before * starting it. * * @warning Even though the OFCopying protocol is implemented, it does *not* * return an independent copy of the thread, but instead retains it. * This is so that the thread can be used as a key for a dictionary, * so context can be associated with a thread. */ @interface OFThread: OFObject #ifdef OF_HAVE_THREADS { @private OFPlainThread _thread; OFPlainThreadAttributes _attr; enum OFThreadState { OFThreadStateNotRunning, OFThreadStateRunning, OFThreadStateWaitingForJoin } _running; # ifndef OF_OBJFW_RUNTIME void *_pool; # endif # ifdef OF_HAVE_BLOCKS OFThreadBlock _Nullable _block; # endif jmp_buf _exitEnv; id _returnValue; bool _supportsSockets; OFRunLoop *_Nullable _runLoop; OFMutableDictionary *_threadDictionary; OFString *_Nullable _name; # ifdef OF_HAVE_SOCKETS OFDNSResolver *_DNSResolver; # endif OF_RESERVE_IVARS(OFThread, 4) } #endif #ifdef OF_HAVE_CLASS_PROPERTIES # ifdef OF_HAVE_THREADS @property (class, readonly, nullable, nonatomic) OFThread *currentThread; @property (class, readonly, nullable, nonatomic) OFThread *mainThread; @property (class, readonly, nonatomic) bool isMainThread; @property (class, readonly, nullable, nonatomic) OFMutableDictionary *threadDictionary; @property (class, nullable, copy, nonatomic) OFString *name; # endif # ifdef OF_HAVE_SOCKETS @property (class, readonly, nonatomic) OFDNSResolver *DNSResolver; # endif #endif #ifdef OF_HAVE_THREADS /** * @brief The name for the thread to use when starting it. * * @note While this can be changed after the thread has been started, it will * have no effect once the thread started. If you want to change the name * of the current thread after it has been started, look at the class * method @ref setName:. */ @property OF_NULLABLE_PROPERTY (copy) OFString *name; # ifdef OF_HAVE_BLOCKS /** * @brief The block to execute in the thread. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFThreadBlock block; # endif /** * @brief The run loop for the thread. */ @property (readonly, nonatomic) OFRunLoop *runLoop; /** * @brief The priority of the thread. * * @note This has to be set before the thread is started! * * This is a value between -1.0 (meaning lowest priority that still schedules) * and +1.0 (meaning highest priority that still allows getting preempted) * with normal priority being 0.0 (meaning being the same as the main thread). * * @throw OFThreadStillRunningException The thread is already/still running and * thus the priority cannot be changed */ @property (nonatomic) float priority; /** * @brief The stack size of the thread. * * @note This has to be set before the thread is started! * * @throw OFThreadStillRunningException The thread is already/still running and * thus the stack size cannot be changed */ @property (nonatomic) size_t stackSize; /** * @brief Whether the thread supports sockets. * * Some operating systems such as AmigaOS need special per-thread * initialization of sockets. If you intend to use sockets in the thread, set * this property to true before starting the thread. * * @throw OFThreadStillRunningException The thread is already/still running and * thus the sockets support cannot be * enabled/disabled */ @property (nonatomic) bool supportsSockets; /** * @brief Creates a new thread. * * @return A new, autoreleased thread */ + (instancetype)thread; # ifdef OF_HAVE_BLOCKS /** * @brief Creates a new thread with the specified block. * * @param block A block which is executed by the thread * @return A new, autoreleased thread */ + (instancetype)threadWithBlock: (OFThreadBlock)block; # endif /** * @brief Returns the current thread. * * @return The current thread */ + (nullable OFThread *)currentThread; /** * @brief Returns the main thread. * * @return The main thread */ + (nullable OFThread *)mainThread; /** * @brief Returns whether the current thread is the main thread. * * @return Whether the current thread is the main thread. */ + (bool)isMainThread; /** * @brief Returns a dictionary to store thread-specific data, meaning it * returns a different dictionary for every thread. * * @return A dictionary to store thread-specific data */ + (nullable OFMutableDictionary *)threadDictionary; #endif #ifdef OF_HAVE_SOCKETS /** * @brief Returns the DNS resolver for the current thread. * * Constructs the DNS resolver is there is none yet, unless @ref currentThread * is `nil`, in which case it returns `nil`. * * @return The DNS resolver for the current thread */ + (nullable OFDNSResolver *)DNSResolver; #endif /** * @brief Suspends execution of the current thread for the specified time * interval. * * @param timeInterval The number of seconds to sleep */ + (void)sleepForTimeInterval: (OFTimeInterval)timeInterval; /** * @brief Suspends execution of the current thread until the specified date. * * @param date The date to wait for */ + (void)sleepUntilDate: (OFDate *)date; /** * @brief Yields a processor voluntarily and moves the thread to the end of the * queue for its priority. */ + (void)yield; #ifdef OF_HAVE_THREADS /** * @brief Terminates the current thread, letting it return `nil`. */ + (void)terminate OF_NO_RETURN; /** * @brief Terminates the current thread, letting it return the specified object. * * @param object The object which the terminated thread will return * @throw OFInvalidArgumentException The method was called from the main thread */ + (void)terminateWithObject: (nullable id)object OF_NO_RETURN; /** * @brief Sets the name of the current thread. * * Unlike the instance method, this can be used after the thread has been * started. * * @param name The new name for the current thread. */ + (void)setName: (nullable OFString *)name; /** * @brief Returns the name of the current thread. * * @return The name of the current thread. */ + (nullable OFString *)name; # ifdef OF_HAVE_BLOCKS /** * @brief Initializes an already allocated thread with the specified block. * * @param block A block which is executed by the thread * @return An initialized OFThread. */ - (instancetype)initWithBlock: (OFThreadBlock)block; # endif /** * @brief The main routine of the thread. You need to reimplement this! * * @return The object the join method should return when called for this thread */ - (nullable id)main; /** * @brief This routine is executed when the thread's main method has finished * executing or terminate has been called. * * @note Be sure to call `[super handleTermination]`! */ - (void)handleTermination OF_REQUIRES_SUPER; /** * @brief Starts the thread. * * @throw OFStartThreadFailedException Starting the thread failed * @throw OFThreadStillRunningException The thread is still running */ - (void)start; /** * @brief Joins a thread. * * @return The object returned by the main method of the thread. * @throw OFJoinThreadFailedException Joining the thread failed */ - (id)join; #else - (instancetype)init OF_UNAVAILABLE; #endif @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFThread.m000066400000000000000000000261001465614216400152370ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #define _POSIX_TIMERS #include #include #include #include #ifdef OF_HAVE_SCHED_YIELD # include #endif #include "unistd_wrapper.h" #include "platform.h" #ifdef OF_AMIGAOS # define Class IntuitionClass # include # include # undef Class #endif #ifdef OF_WII # define nanosleep ogc_nanosleep # include # undef nanosleep #endif #ifdef OF_NINTENDO_3DS # include <3ds/svc.h> #endif #import "OFThread.h" #import "OFThread+Private.h" #ifdef OF_HAVE_ATOMIC_OPS # import "OFAtomic.h" #endif #import "OFDate.h" #import "OFDictionary.h" #ifdef OF_HAVE_SOCKETS # import "OFDNSResolver.h" #endif #import "OFLocale.h" #import "OFRunLoop.h" #import "OFString.h" #ifdef OF_WINDOWS # include #endif #ifdef OF_NINTENDO_DS # define asm __asm__ # include # undef asm #endif #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFNotImplementedException.h" #import "OFOutOfRangeException.h" #ifdef OF_HAVE_THREADS # import "OFJoinThreadFailedException.h" # import "OFStartThreadFailedException.h" # import "OFThreadStillRunningException.h" #endif #ifdef OF_MINT /* freemint-gcc does not have trunc() */ # define trunc(x) ((int64_t)(x)) #endif #if defined(OF_HAVE_THREADS) # import "OFTLSKey.h" # if defined(OF_AMIGAOS) && defined(OF_HAVE_SOCKETS) # import "OFSocket.h" # endif static OFTLSKey threadSelfKey; static OFThread *mainThread; #elif defined(OF_HAVE_SOCKETS) static OFDNSResolver *DNSResolver; #endif @implementation OFThread #ifdef OF_HAVE_THREADS static void callMain(id object) { OFThread *thread = (OFThread *)object; OFString *name; if (OFTLSKeySet(threadSelfKey, thread) != 0) @throw [OFInitializationFailedException exceptionWithClass: thread.class]; #ifndef OF_OBJFW_RUNTIME thread->_pool = objc_autoreleasePoolPush(); #endif name = thread.name; if (name != nil) OFSetThreadName( [name cStringWithEncoding: [OFLocale encoding]]); else OFSetThreadName(object_getClassName(thread)); #if defined(OF_AMIGAOS) && defined(OF_HAVE_SOCKETS) if (thread.supportsSockets) if (!_OFSocketInit()) @throw [OFInitializationFailedException exceptionWithClass: thread.class]; #endif /* * Nasty workaround for thread implementations which can't return a * pointer on join, or don't have a way to exit a thread. */ if (setjmp(thread->_exitEnv) == 0) { # ifdef OF_HAVE_BLOCKS if (thread->_block != NULL) thread->_returnValue = [thread->_block() retain]; else # endif thread->_returnValue = [[thread main] retain]; } [thread handleTermination]; #ifdef OF_OBJFW_RUNTIME objc_autoreleasePoolPop((void *)(uintptr_t)-1); #else objc_autoreleasePoolPop(thread->_pool); #endif #if defined(OF_AMIGAOS) && !defined(OF_MORPHOS) && defined(OF_HAVE_SOCKETS) if (thread.supportsSockets) _OFSocketDeinit(); #endif thread->_running = OFThreadStateWaitingForJoin; [thread release]; } @synthesize name = _name; # ifdef OF_HAVE_BLOCKS @synthesize block = _block; # endif + (void)initialize { if (self != [OFThread class]) return; if (OFTLSKeyNew(&threadSelfKey) != 0) @throw [OFInitializationFailedException exceptionWithClass: self]; } + (instancetype)thread { return [[[self alloc] init] autorelease]; } # ifdef OF_HAVE_BLOCKS + (instancetype)threadWithBlock: (OFThreadBlock)block { return [[[self alloc] initWithBlock: block] autorelease]; } # endif + (OFThread *)currentThread { return OFTLSKeyGet(threadSelfKey); } + (OFThread *)mainThread { return mainThread; } + (bool)isMainThread { if (mainThread == nil) return false; return (OFTLSKeyGet(threadSelfKey) == mainThread); } + (OFMutableDictionary *)threadDictionary { OFThread *thread = OFTLSKeyGet(threadSelfKey); if (thread == nil) return nil; if (thread->_threadDictionary == nil) thread->_threadDictionary = [[OFMutableDictionary alloc] init]; return thread->_threadDictionary; } #endif #ifdef OF_HAVE_SOCKETS + (OFDNSResolver *)DNSResolver { # ifdef OF_HAVE_THREADS OFThread *thread = OFTLSKeyGet(threadSelfKey); if (thread == nil) return nil; if (thread->_DNSResolver == nil) thread->_DNSResolver = [[OFDNSResolver alloc] init]; return thread->_DNSResolver; # else if (DNSResolver == nil) DNSResolver = [[OFDNSResolver alloc] init]; return DNSResolver; # endif } #endif + (void)sleepForTimeInterval: (OFTimeInterval)timeInterval { if (timeInterval < 0) return; #if defined(OF_WINDOWS) if (timeInterval * 1000 > UINT_MAX) @throw [OFOutOfRangeException exception]; Sleep((unsigned int)(timeInterval * 1000)); #elif defined(OF_NINTENDO_3DS) if (timeInterval * 1000000000 > INT64_MAX) @throw [OFOutOfRangeException exception]; svcSleepThread((int64_t)(timeInterval * 1000000000)); #elif defined(OF_AMIGAOS) struct timerequest request = *DOSBase->dl_TimeReq; request.tr_node.io_Message.mn_ReplyPort = &((struct Process *)FindTask(NULL))->pr_MsgPort; request.tr_node.io_Command = TR_ADDREQUEST; request.tr_time.tv_secs = (ULONG)timeInterval; request.tr_time.tv_micro = (ULONG) ((timeInterval - (unsigned int)timeInterval) * 1000000); DoIO((struct IORequest *)&request); #elif defined(HAVE_NANOSLEEP) struct timespec rqtp; rqtp.tv_sec = (time_t)timeInterval; rqtp.tv_nsec = (long)((timeInterval - rqtp.tv_sec) * 1000000000); if (rqtp.tv_sec != trunc(timeInterval)) @throw [OFOutOfRangeException exception]; nanosleep(&rqtp, NULL); #elif defined(OF_NINTENDO_DS) uint64_t counter; if (timeInterval > UINT64_MAX / 60) @throw [OFOutOfRangeException exception]; counter = timeInterval * 60; while (counter--) swiWaitForVBlank(); #else if (timeInterval > UINT_MAX) @throw [OFOutOfRangeException exception]; sleep((unsigned int)timeInterval); usleep((unsigned int) ((timeInterval - (unsigned int)timeInterval) * 1000000)); #endif } + (void)sleepUntilDate: (OFDate *)date { [self sleepForTimeInterval: date.timeIntervalSinceNow]; } + (void)yield { #ifdef OF_HAVE_SCHED_YIELD sched_yield(); #else [self sleepForTimeInterval: 0]; #endif } #ifdef OF_HAVE_THREADS + (void)terminate { [self terminateWithObject: nil]; /* * For some reason, Clang thinks terminateWithObject: can return - even * though it is declared OF_NO_RETURN - and warns that terminate * returns while being declared OF_NO_RETURN. */ OF_UNREACHABLE } + (void)terminateWithObject: (id)object { OFThread *thread = OFTLSKeyGet(threadSelfKey); if (thread == mainThread) @throw [OFInvalidArgumentException exception]; OFEnsure(thread != nil); thread->_returnValue = [object retain]; longjmp(thread->_exitEnv, 1); OF_UNREACHABLE } + (void)setName: (OFString *)name { [OFThread currentThread].name = name; if (name != nil) OFSetThreadName( [name cStringWithEncoding: [OFLocale encoding]]); else OFSetThreadName(class_getName([self class])); } + (OFString *)name { return [OFThread currentThread].name; } + (void)of_createMainThread { mainThread = [[OFThread alloc] init]; mainThread->_thread = OFCurrentPlainThread(); mainThread->_running = OFThreadStateRunning; if (OFTLSKeySet(threadSelfKey, mainThread) != 0) @throw [OFInitializationFailedException exceptionWithClass: self]; } - (instancetype)init { self = [super init]; @try { if (OFPlainThreadAttributesInit(&_attr) != 0) @throw [OFInitializationFailedException exceptionWithClass: self.class]; } @catch (id e) { [self release]; @throw e; } return self; } # ifdef OF_HAVE_BLOCKS - (instancetype)initWithBlock: (OFThreadBlock)block { self = [self init]; @try { _block = [block copy]; } @catch (id e) { [self release]; @throw e; } return self; } # endif - (id)main { [[OFRunLoop currentRunLoop] run]; return nil; } - (void)handleTermination { OFRunLoop *oldRunLoop = _runLoop; _runLoop = nil; [oldRunLoop release]; [_threadDictionary release]; _threadDictionary = nil; # ifdef OF_HAVE_SOCKETS [_DNSResolver release]; _DNSResolver = nil; # endif } - (void)start { int error; if (_running == OFThreadStateRunning) @throw [OFThreadStillRunningException exceptionWithThread: self]; if (_running == OFThreadStateWaitingForJoin) { OFPlainThreadDetach(_thread); [_returnValue release]; } [self retain]; _running = OFThreadStateRunning; if ((error = OFPlainThreadNew(&_thread, [_name cStringWithEncoding: [OFLocale encoding]], callMain, self, &_attr)) != 0) { [self release]; @throw [OFStartThreadFailedException exceptionWithThread: self errNo: error]; } } - (id)join { int error; if (_running == OFThreadStateNotRunning) @throw [OFJoinThreadFailedException exceptionWithThread: self errNo: EINVAL]; if ((error = OFPlainThreadJoin(_thread)) != 0) @throw [OFJoinThreadFailedException exceptionWithThread: self errNo: error]; _running = OFThreadStateNotRunning; return _returnValue; } - (id)copy { return [self retain]; } - (OFRunLoop *)runLoop { # if defined(OF_HAVE_ATOMIC_OPS) && !defined(__clang_analyzer__) if (_runLoop == nil) { OFRunLoop *tmp = [[OFRunLoop alloc] init]; if (!OFAtomicPointerCompareAndSwap( (void **)&_runLoop, nil, tmp)) [tmp release]; } # else @synchronized (self) { if (_runLoop == nil) _runLoop = [[OFRunLoop alloc] init]; } # endif return _runLoop; } - (float)priority { return _attr.priority; } - (void)setPriority: (float)priority { if (_running == OFThreadStateRunning) @throw [OFThreadStillRunningException exceptionWithThread: self]; _attr.priority = priority; } - (size_t)stackSize { return _attr.stackSize; } - (void)setStackSize: (size_t)stackSize { if (_running == OFThreadStateRunning) @throw [OFThreadStillRunningException exceptionWithThread: self]; _attr.stackSize = stackSize; } - (bool)supportsSockets { return _supportsSockets; } - (void)setSupportsSockets: (bool)supportsSockets { if (_running == OFThreadStateRunning) @throw [OFThreadStillRunningException exceptionWithThread: self]; _supportsSockets = supportsSockets; } - (void)dealloc { if (_running == OFThreadStateRunning) @throw [OFThreadStillRunningException exceptionWithThread: self]; /* * We should not be running anymore, but call detach in order to free * the resources. */ if (_running == OFThreadStateWaitingForJoin) OFPlainThreadDetach(_thread); [_returnValue release]; # ifdef OF_HAVE_BLOCKS [_block release]; # endif [super dealloc]; } #else - (instancetype)init { OF_INVALID_INIT_METHOD } #endif @end objfw-1.1.6/src/OFTimer+Private.h000066400000000000000000000017051465614216400165150ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFTimer.h" OF_ASSUME_NONNULL_BEGIN OF_DIRECT_MEMBERS @interface OFTimer () - (void)of_setInRunLoop: (nullable OFRunLoop *)runLoop mode: (nullable OFRunLoopMode)mode; - (void)of_reschedule; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFTimer.h000066400000000000000000000411151465614216400151060ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFRunLoop.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFTimer; @class OFDate; #ifdef OF_HAVE_THREADS @class OFCondition; #endif #ifdef OF_HAVE_BLOCKS /** * @brief A block to execute when a timer fires. * * @param timer The timer which fired */ typedef void (^OFTimerBlock)(OFTimer *timer); #endif /** * @class OFTimer OFTimer.h ObjFW/OFTimer.h * * @brief A class for creating and firing timers. */ OF_SUBCLASSING_RESTRICTED @interface OFTimer: OFObject { OFDate *_fireDate; OFTimeInterval _interval; id _target; id _Nullable _object1, _object2, _object3, _object4; SEL _selector; unsigned char _arguments; bool _repeats; #ifdef OF_HAVE_BLOCKS OFTimerBlock _block; #endif bool _valid; #ifdef OF_HAVE_THREADS OFCondition *_condition; bool _done; #endif OFRunLoop *_Nullable _inRunLoop; OFRunLoopMode _Nullable _inRunLoopMode; } /** * @brief The time interval in which the timer will repeat, if it is a * repeating timer. */ @property (readonly, nonatomic) OFTimeInterval timeInterval; /** * @brief Whether the timer repeats. */ @property (readonly, nonatomic) bool repeats; /** * @brief Whether the timer is valid. */ @property (readonly, nonatomic, getter=isValid) bool valid; /** * @brief The next date at which the timer will fire. * * If the timer is already scheduled in a run loop, it will be rescheduled. * Note that rescheduling is an expensive operation, though it still might be * preferable to reschedule instead of invalidating the timer and creating a * new one. */ @property (copy, nonatomic) OFDate *fireDate; /** * @brief Creates and schedules a new timer with the specified time interval. * * @param timeInterval The time interval after which the timer should be fired * @param target The target on which to call the selector * @param selector The selector to call on the target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector repeats: (bool)repeats; /** * @brief Creates and schedules a new timer with the specified time interval. * * @param timeInterval The time interval after which the timer should be fired * @param target The target on which to call the selector * @param selector The selector to call on the target * @param object An object to pass when calling the selector on the target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (nullable id)object repeats: (bool)repeats; /** * @brief Creates and schedules a new timer with the specified time interval. * * @param timeInterval The time interval after which the timer should be fired * @param target The target on which to call the selector * @param selector The selector to call on the target * @param object1 The first object to pass when calling the selector on the * target * @param object2 The second object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (nullable id)object1 object: (nullable id)object2 repeats: (bool)repeats; /** * @brief Creates and schedules a new timer with the specified time interval. * * @param timeInterval The time interval after which the timer should be fired * @param target The target on which to call the selector * @param selector The selector to call on the target * @param object1 The first object to pass when calling the selector on the * target * @param object2 The second object to pass when calling the selector on the * target * @param object3 The third object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (nullable id)object1 object: (nullable id)object2 object: (nullable id)object3 repeats: (bool)repeats; /** * @brief Creates and schedules a new timer with the specified time interval. * * @param timeInterval The time interval after which the timer should be fired * @param target The target on which to call the selector * @param selector The selector to call on the target * @param object1 The first object to pass when calling the selector on the * target * @param object2 The second object to pass when calling the selector on the * target * @param object3 The third object to pass when calling the selector on the * target * @param object4 The fourth object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (nullable id)object1 object: (nullable id)object2 object: (nullable id)object3 object: (nullable id)object4 repeats: (bool)repeats; #ifdef OF_HAVE_BLOCKS /** * @brief Creates and schedules a new timer with the specified time interval. * * @param timeInterval The time interval after which the timer should be fired * @param repeats Whether the timer repeats after it has been executed * @param block The block to invoke when the timer fires * @return A new, autoreleased timer */ + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval repeats: (bool)repeats block: (OFTimerBlock)block; #endif /** * @brief Creates a new timer with the specified time interval. * * @param timeInterval The time interval after which the timer should be fired * @param target The target on which to call the selector * @param selector The selector to call on the target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector repeats: (bool)repeats; /** * @brief Creates a new timer with the specified time interval. * * @param timeInterval The time interval after which the timer should be fired * @param target The target on which to call the selector * @param selector The selector to call on the target * @param object An object to pass when calling the selector on the target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (nullable id)object repeats: (bool)repeats; /** * @brief Creates a new timer with the specified time interval. * * @param timeInterval The time interval after which the timer should be fired * @param target The target on which to call the selector * @param selector The selector to call on the target * @param object1 The first object to pass when calling the selector on the * target * @param object2 The second object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (nullable id)object1 object: (nullable id)object2 repeats: (bool)repeats; /** * @brief Creates a new timer with the specified time interval. * * @param timeInterval The time interval after which the timer should be fired * @param target The target on which to call the selector * @param selector The selector to call on the target * @param object1 The first object to pass when calling the selector on the * target * @param object2 The second object to pass when calling the selector on the * target * @param object3 The third object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (nullable id)object1 object: (nullable id)object2 object: (nullable id)object3 repeats: (bool)repeats; /** * @brief Creates a new timer with the specified time interval. * * @param timeInterval The time interval after which the timer should be fired * @param target The target on which to call the selector * @param selector The selector to call on the target * @param object1 The first object to pass when calling the selector on the * target * @param object2 The second object to pass when calling the selector on the * target * @param object3 The third object to pass when calling the selector on the * target * @param object4 The fourth object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (nullable id)object1 object: (nullable id)object2 object: (nullable id)object3 object: (nullable id)object4 repeats: (bool)repeats; #ifdef OF_HAVE_BLOCKS /** * @brief Creates a new timer with the specified time interval. * * @param timeInterval The time interval after which the timer should be fired * @param repeats Whether the timer repeats after it has been executed * @param block The block to invoke when the timer fires * @return A new, autoreleased timer */ + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval repeats: (bool)repeats block: (OFTimerBlock)block; #endif - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated timer with the specified time * interval. * * @param fireDate The date at which the timer should fire * @param interval The time interval after which to repeat the timer, if it is * a repeating timer * @param target The target on which to call the selector * @param selector The selector to call on the target * @param repeats Whether the timer repeats after it has been executed * @return An initialized timer */ - (instancetype)initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval target: (id)target selector: (SEL)selector repeats: (bool)repeats; /** * @brief Initializes an already allocated timer with the specified time * interval. * * @param fireDate The date at which the timer should fire * @param interval The time interval after which to repeat the timer, if it is * a repeating timer * @param target The target on which to call the selector * @param selector The selector to call on the target * @param object An object to pass when calling the selector on the target * @param repeats Whether the timer repeats after it has been executed * @return An initialized timer */ - (instancetype)initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval target: (id)target selector: (SEL)selector object: (nullable id)object repeats: (bool)repeats; /** * @brief Initializes an already allocated timer with the specified time * interval. * * @param fireDate The date at which the timer should fire * @param interval The time interval after which to repeat the timer, if it is * a repeating timer * @param target The target on which to call the selector * @param selector The selector to call on the target * @param object1 The first object to pass when calling the selector on the * target * @param object2 The second object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return An initialized timer */ - (instancetype)initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval target: (id)target selector: (SEL)selector object: (nullable id)object1 object: (nullable id)object2 repeats: (bool)repeats; /** * @brief Initializes an already allocated timer with the specified time * interval. * * @param fireDate The date at which the timer should fire * @param interval The time interval after which to repeat the timer, if it is * a repeating timer * @param target The target on which to call the selector * @param selector The selector to call on the target * @param object1 The first object to pass when calling the selector on the * target * @param object2 The second object to pass when calling the selector on the * target * @param object3 The third object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return An initialized timer */ - (instancetype)initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval target: (id)target selector: (SEL)selector object: (nullable id)object1 object: (nullable id)object2 object: (nullable id)object3 repeats: (bool)repeats; /** * @brief Initializes an already allocated timer with the specified time * interval. * * @param fireDate The date at which the timer should fire * @param interval The time interval after which to repeat the timer, if it is * a repeating timer * @param target The target on which to call the selector * @param selector The selector to call on the target * @param object1 The first object to pass when calling the selector on the * target * @param object2 The second object to pass when calling the selector on the * target * @param object3 The third object to pass when calling the selector on the * target * @param object4 The fourth object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return An initialized timer */ - (instancetype)initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval target: (id)target selector: (SEL)selector object: (nullable id)object1 object: (nullable id)object2 object: (nullable id)object3 object: (nullable id)object4 repeats: (bool)repeats; #ifdef OF_HAVE_BLOCKS /** * @brief Initializes an already allocated timer with the specified time * interval. * * @param fireDate The date at which the timer should fire * @param interval The time interval after which to repeat the timer, if it is * a repeating timer * @param repeats Whether the timer repeats after it has been executed * @param block The block to invoke when the timer fires * @return An initialized timer */ - (instancetype)initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval repeats: (bool)repeats block: (OFTimerBlock)block; #endif /** * @brief Compares the timer to another timer. * * @param timer The timer to compare the string to * @return The result of the comparison */ - (OFComparisonResult)compare: (OFTimer *)timer; /** * @brief Fires the timer without changing its regular schedule. * * A non-repeating timer will be invalidated after firing. */ - (void)fire; /** * @brief Invalidates the timer, preventing it from firing. */ - (void)invalidate; #ifdef OF_HAVE_THREADS /** * @brief Waits until the timer fired. */ - (void)waitUntilDone; #endif @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFTimer.m000066400000000000000000000416261465614216400151220ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFTimer.h" #import "OFTimer+Private.h" #import "OFDate.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #ifdef OF_HAVE_THREADS # import "OFCondition.h" #endif #import "OFInvalidArgumentException.h" @implementation OFTimer @synthesize timeInterval = _interval, repeats = _repeats, valid = _valid; + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector repeats: (bool)repeats { void *pool = objc_autoreleasePoolPush(); OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: timeInterval]; id timer = [[[self alloc] initWithFireDate: fireDate interval: timeInterval target: target selector: selector repeats: repeats] autorelease]; [[OFRunLoop currentRunLoop] addTimer: timer]; [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (id)object repeats: (bool)repeats { void *pool = objc_autoreleasePoolPush(); OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: timeInterval]; id timer = [[[self alloc] initWithFireDate: fireDate interval: timeInterval target: target selector: selector object: object repeats: repeats] autorelease]; [[OFRunLoop currentRunLoop] addTimer: timer]; [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (id)object1 object: (id)object2 repeats: (bool)repeats { void *pool = objc_autoreleasePoolPush(); OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: timeInterval]; id timer = [[[self alloc] initWithFireDate: fireDate interval: timeInterval target: target selector: selector object: object1 object: object2 repeats: repeats] autorelease]; [[OFRunLoop currentRunLoop] addTimer: timer]; [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (id)object1 object: (id)object2 object: (id)object3 repeats: (bool)repeats { void *pool = objc_autoreleasePoolPush(); OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: timeInterval]; id timer = [[[self alloc] initWithFireDate: fireDate interval: timeInterval target: target selector: selector object: object1 object: object2 object: object3 repeats: repeats] autorelease]; [[OFRunLoop currentRunLoop] addTimer: timer]; [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (id)object1 object: (id)object2 object: (id)object3 object: (id)object4 repeats: (bool)repeats { void *pool = objc_autoreleasePoolPush(); OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: timeInterval]; id timer = [[[self alloc] initWithFireDate: fireDate interval: timeInterval target: target selector: selector object: object1 object: object2 object: object3 object: object4 repeats: repeats] autorelease]; [[OFRunLoop currentRunLoop] addTimer: timer]; [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } #ifdef OF_HAVE_BLOCKS + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval repeats: (bool)repeats block: (OFTimerBlock)block { void *pool = objc_autoreleasePoolPush(); OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: timeInterval]; id timer = [[[self alloc] initWithFireDate: fireDate interval: timeInterval repeats: repeats block: block] autorelease]; [[OFRunLoop currentRunLoop] addTimer: timer]; [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } #endif + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector repeats: (bool)repeats { void *pool = objc_autoreleasePoolPush(); OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: timeInterval]; id timer = [[[self alloc] initWithFireDate: fireDate interval: timeInterval target: target selector: selector repeats: repeats] autorelease]; [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (id)object repeats: (bool)repeats { void *pool = objc_autoreleasePoolPush(); OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: timeInterval]; id timer = [[[self alloc] initWithFireDate: fireDate interval: timeInterval target: target selector: selector object: object repeats: repeats] autorelease]; [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (id)object1 object: (id)object2 repeats: (bool)repeats { void *pool = objc_autoreleasePoolPush(); OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: timeInterval]; id timer = [[[self alloc] initWithFireDate: fireDate interval: timeInterval target: target selector: selector object: object1 object: object2 repeats: repeats] autorelease]; [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (id)object1 object: (id)object2 object: (id)object3 repeats: (bool)repeats { void *pool = objc_autoreleasePoolPush(); OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: timeInterval]; id timer = [[[self alloc] initWithFireDate: fireDate interval: timeInterval target: target selector: selector object: object1 object: object2 object: object3 repeats: repeats] autorelease]; [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (id)object1 object: (id)object2 object: (id)object3 object: (id)object4 repeats: (bool)repeats { void *pool = objc_autoreleasePoolPush(); OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: timeInterval]; id timer = [[[self alloc] initWithFireDate: fireDate interval: timeInterval target: target selector: selector object: object1 object: object2 object: object3 object: object4 repeats: repeats] autorelease]; [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } #ifdef OF_HAVE_BLOCKS + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval repeats: (bool)repeats block: (OFTimerBlock)block { void *pool = objc_autoreleasePoolPush(); OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: timeInterval]; id timer = [[[self alloc] initWithFireDate: fireDate interval: timeInterval repeats: repeats block: block] autorelease]; [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } #endif - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)of_initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval target: (id)target selector: (SEL)selector object: (id)object1 object: (id)object2 object: (id)object3 object: (id)object4 arguments: (unsigned char)arguments repeats: (bool)repeats OF_METHOD_FAMILY(init) OF_DIRECT { self = [super init]; @try { _fireDate = [fireDate retain]; _interval = interval; _target = [target retain]; _selector = selector; _object1 = [object1 retain]; _object2 = [object2 retain]; _object3 = [object3 retain]; _object4 = [object4 retain]; _arguments = arguments; _repeats = repeats; _valid = true; #ifdef OF_HAVE_THREADS _condition = [[OFCondition alloc] init]; #endif } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval target: (id)target selector: (SEL)selector repeats: (bool)repeats { return [self of_initWithFireDate: fireDate interval: interval target: target selector: selector object: nil object: nil object: nil object: nil arguments: 0 repeats: repeats]; } - (instancetype)initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval target: (id)target selector: (SEL)selector object: (id)object repeats: (bool)repeats { return [self of_initWithFireDate: fireDate interval: interval target: target selector: selector object: object object: nil object: nil object: nil arguments: 1 repeats: repeats]; } - (instancetype)initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval target: (id)target selector: (SEL)selector object: (id)object1 object: (id)object2 repeats: (bool)repeats { return [self of_initWithFireDate: fireDate interval: interval target: target selector: selector object: object1 object: object2 object: nil object: nil arguments: 2 repeats: repeats]; } - (instancetype)initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval target: (id)target selector: (SEL)selector object: (id)object1 object: (id)object2 object: (id)object3 repeats: (bool)repeats { return [self of_initWithFireDate: fireDate interval: interval target: target selector: selector object: object1 object: object2 object: object3 object: nil arguments: 3 repeats: repeats]; } - (instancetype)initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval target: (id)target selector: (SEL)selector object: (id)object1 object: (id)object2 object: (id)object3 object: (id)object4 repeats: (bool)repeats { return [self of_initWithFireDate: fireDate interval: interval target: target selector: selector object: object1 object: object2 object: object3 object: object4 arguments: 4 repeats: repeats]; } #ifdef OF_HAVE_BLOCKS - (instancetype)initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval repeats: (bool)repeats block: (OFTimerBlock)block { self = [super init]; @try { _fireDate = [fireDate retain]; _interval = interval; _repeats = repeats; _block = [block copy]; _valid = true; # ifdef OF_HAVE_THREADS _condition = [[OFCondition alloc] init]; # endif } @catch (id e) { [self release]; @throw e; } return self; } #endif - (void)dealloc { /* * The run loop references the timer, so it should never be deallocated * if it is still in a run loop. */ OFAssert(_inRunLoop == nil); OFAssert(_inRunLoopMode == nil); [_fireDate release]; [_target release]; [_object1 release]; [_object2 release]; [_object3 release]; [_object4 release]; #ifdef OF_HAVE_BLOCKS [_block release]; #endif #ifdef OF_HAVE_THREADS [_condition release]; #endif [super dealloc]; } - (OFComparisonResult)compare: (OFTimer *)timer { if (![timer isKindOfClass: [OFTimer class]]) @throw [OFInvalidArgumentException exception]; return [_fireDate compare: timer->_fireDate]; } - (void)of_setInRunLoop: (OFRunLoop *)runLoop mode: (OFRunLoopMode)mode { OFRunLoop *oldInRunLoop = _inRunLoop; OFRunLoopMode oldInRunLoopMode = _inRunLoopMode; _inRunLoop = [runLoop retain]; [oldInRunLoop release]; _inRunLoopMode = [mode copy]; [oldInRunLoopMode release]; } - (void)of_reschedule { long long missedIntervals; OFTimeInterval newFireDate; OFRunLoop *runLoop; if (!_repeats || !_valid) return; missedIntervals = -_fireDate.timeIntervalSinceNow / _interval; /* In case the clock was changed backwards */ if (missedIntervals < 0) missedIntervals = 0; newFireDate = _fireDate.timeIntervalSince1970 + (missedIntervals + 1) * _interval; [_fireDate release]; _fireDate = nil; _fireDate = [[OFDate alloc] initWithTimeIntervalSince1970: newFireDate]; runLoop = [OFRunLoop currentRunLoop]; [runLoop addTimer: self forMode: runLoop.currentMode]; } - (void)fire { OFEnsure(_arguments <= 4); if (!_valid) return; #ifdef OF_HAVE_BLOCKS if (_block != NULL) _block(self); else { #endif switch (_arguments) { case 0: [_target performSelector: _selector]; break; case 1: [_target performSelector: _selector withObject: _object1]; break; case 2: [_target performSelector: _selector withObject: _object1 withObject: _object2]; break; case 3: [_target performSelector: _selector withObject: _object1 withObject: _object2 withObject: _object3]; break; case 4: [_target performSelector: _selector withObject: _object1 withObject: _object2 withObject: _object3 withObject: _object4]; break; } #ifdef OF_HAVE_BLOCKS } #endif if (!_repeats) [self invalidate]; #ifdef OF_HAVE_THREADS [_condition lock]; @try { _done = true; [_condition signal]; } @finally { [_condition unlock]; } #endif } - (OFDate *)fireDate { return _fireDate; } - (void)setFireDate: (OFDate *)fireDate { [self retain]; @try { @synchronized (self) { OFDate *old; [_inRunLoop of_removeTimer: self forMode: _inRunLoopMode]; old = _fireDate; _fireDate = [fireDate copy]; [old release]; [_inRunLoop addTimer: self forMode: _inRunLoopMode]; } } @finally { [self release]; } } - (void)invalidate { _valid = false; #ifdef OF_HAVE_BLOCKS [_block release]; #endif [_target release]; [_object1 release]; [_object2 release]; [_object3 release]; [_object4 release]; _target = nil; _object1 = nil; _object2 = nil; _object3 = nil; _object4 = nil; } #ifdef OF_HAVE_THREADS - (void)waitUntilDone { [_condition lock]; @try { if (_done) { _done = false; return; } [_condition wait]; } @finally { [_condition unlock]; } } #endif - (OFString *)description { #ifdef OF_HAVE_BLOCKS if (_block != NULL) return [OFString stringWithFormat: @"<%@:\n" @"\tFire date: %@\n" @"\tInterval: %lf\n" @"\tRepeats: %s\n" @"\tBlock: %@\n" @"\tValid: %s\n" @">", self.class, _fireDate, _interval, (_repeats ? "yes" : "no"), _block, (_valid ? "yes" : "no")]; else { #endif void *pool = objc_autoreleasePoolPush(); OFString *objects = @"", *ret; if (_arguments >= 1) objects = [objects stringByAppendingFormat: @"\tObject: %@\n", _object1]; if (_arguments >= 2) objects = [objects stringByAppendingFormat: @"\tObject: %@\n", _object2]; if (_arguments >= 3) objects = [objects stringByAppendingFormat: @"\tObject: %@\n", _object3]; if (_arguments >= 4) objects = [objects stringByAppendingFormat: @"\tObject: %@\n", _object4]; ret = [[OFString alloc] initWithFormat: @"<%@:\n" @"\tFire date: %@\n" @"\tInterval: %lf\n" @"\tRepeats: %s\n" @"\tTarget: %@\n" @"\tSelector: %s\n" @"%@" @"\tValid: %s\n" @">", self.class, _fireDate, _interval, (_repeats ? "yes" : "no"), _target, sel_getName(_selector), objects, (_valid ? "yes" : "no")]; objc_autoreleasePoolPop(pool); return [ret autorelease]; #ifdef OF_HAVE_BLOCKS } #endif } @end objfw-1.1.6/src/OFTriple.h000066400000000000000000000053731465614216400152730ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFTriple OFTriple.h ObjFW/OFTriple.h * * @brief A class for storing a triple of three objects. */ @interface OFTriple OF_GENERIC(FirstType, SecondType, ThirdType): OFObject #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # define FirstType id # define SecondType id # define ThirdType id #endif { FirstType _Nullable _firstObject; SecondType _Nullable _secondObject; ThirdType _Nullable _thirdObject; OF_RESERVE_IVARS(OFTriple, 4) } /** * @brief The first object of the triple. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic, retain) FirstType firstObject; /** * @brief The second object of the triple. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic, retain) SecondType secondObject; /** * @brief The third object of the triple. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic, retain) ThirdType thirdObject; /** * @brief Creates a new OFTriple with the specified objects. * * @param firstObject The first object for the triple * @param secondObject The second object for the triple * @param thirdObject The second object for the triple * @return A new, autoreleased OFTriple */ + (instancetype)tripleWithFirstObject: (nullable FirstType)firstObject secondObject: (nullable SecondType)secondObject thirdObject: (nullable ThirdType)thirdObject; /** * @brief Initializes an already allocated OFTriple with the specified objects. * * @param firstObject The first object for the triple * @param secondObject The second object for the triple * @param thirdObject The second object for the triple * @return An initialized OFTriple */ - (instancetype)initWithFirstObject: (nullable FirstType)firstObject secondObject: (nullable SecondType)secondObject thirdObject: (nullable ThirdType)thirdObject OF_DESIGNATED_INITIALIZER; #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # undef FirstType # undef SecondType # undef ThirdType #endif @end OF_ASSUME_NONNULL_END #import "OFMutableTriple.h" objfw-1.1.6/src/OFTriple.m000066400000000000000000000054061465614216400152750ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFTriple.h" #import "OFString.h" @implementation OFTriple + (instancetype)tripleWithFirstObject: (id)firstObject secondObject: (id)secondObject thirdObject: (id)thirdObject { return [[[self alloc] initWithFirstObject: firstObject secondObject: secondObject thirdObject: thirdObject] autorelease]; } - (instancetype)initWithFirstObject: (id)firstObject secondObject: (id)secondObject thirdObject: (id)thirdObject { self = [super init]; @try { _firstObject = [firstObject retain]; _secondObject = [secondObject retain]; _thirdObject = [thirdObject retain]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_firstObject release]; [_secondObject release]; [_thirdObject release]; [super dealloc]; } - (id)firstObject { return _firstObject; } - (id)secondObject { return _secondObject; } - (id)thirdObject { return _thirdObject; } - (bool)isEqual: (id)object { OFTriple *triple; if (object == self) return true; if (![object isKindOfClass: [OFTriple class]]) return false; triple = object; if (triple->_firstObject != _firstObject && ![triple->_firstObject isEqual: _firstObject]) return false; if (triple->_secondObject != _secondObject && ![triple->_secondObject isEqual: _secondObject]) return false; if (triple->_thirdObject != _thirdObject && ![triple->_thirdObject isEqual: _thirdObject]) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, [_firstObject hash]); OFHashAddHash(&hash, [_secondObject hash]); OFHashAddHash(&hash, [_thirdObject hash]); OFHashFinalize(&hash); return hash; } - (id)copy { return [self retain]; } - (id)mutableCopy { return [[OFMutableTriple alloc] initWithFirstObject: _firstObject secondObject: _secondObject thirdObject: _thirdObject]; } - (OFString *)description { return [OFString stringWithFormat: @"<<%@, %@, %@>>", _firstObject, _secondObject, _thirdObject]; } @end objfw-1.1.6/src/OFUDPSocket+Private.h000066400000000000000000000016461465614216400172420ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFUDPSocket.h" OF_ASSUME_NONNULL_BEGIN OF_DIRECT_MEMBERS @interface OFUDPSocket () - (void)of_bindToAddress: (OFSocketAddress *)address extraType: (int)extraType; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFUDPSocket.h000066400000000000000000000056451465614216400156370ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFDatagramSocket.h" OF_ASSUME_NONNULL_BEGIN @class OFString; /** * @protocol OFUDPSocketDelegate OFUDPSocket.h ObjFW/OFUDPSocket.h * * @brief A delegate for OFUDPSocket. */ @protocol OFUDPSocketDelegate @end /** * @class OFUDPSocket OFUDPSocket.h ObjFW/OFUDPSocket.h * * @brief A class which provides methods to create and use UDP sockets. * * Addresses are of type @ref OFSocketAddress. You can use the current thread's * @ref OFDNSResolver to create an address for a host / port pair, * @ref OFSocketAddressString to get the IP address string for an address and * @ref OFSocketAddressIPPort to get the port for an address. If you want to * compare two addresses, you can use * @ref OFSocketAddressEqual and you can use @ref OFSocketAddressHash to get a * hash to use in e.g. @ref OFMapTable. * * @warning Even though the OFCopying protocol is implemented, it does *not* * return an independent copy of the socket, but instead retains it. * This is so that the socket can be used as a key for a dictionary, * so context can be associated with a socket. Using a socket in more * than one thread at the same time is not thread-safe, even if copy * was called to create one "instance" for every thread! */ @interface OFUDPSocket: OFDatagramSocket { #ifdef OF_WII uint16_t _port; #endif OF_RESERVE_IVARS(OFUDPSocket, 4) } /** * @brief The delegate for asynchronous operations on the socket. * * @note The delegate is retained for as long as asynchronous operations are * still ongoing. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id delegate; /** * @brief Binds the socket to the specified host and port. * * @param host The host to bind to. Use `@"0.0.0.0"` for IPv4 or `@"::"` for * IPv6 to bind to all. * @param port The port to bind to. If the port is 0, an unused port will be * chosen, which can be obtained using the return value. * @return The address the socket was bound to * @throw OFBindIPSocketFailedException Binding failed * @throw OFAlreadyOpenException The socket is already bound */ - (OFSocketAddress)bindToHost: (OFString *)host port: (uint16_t)port; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFUDPSocket.m000066400000000000000000000116271465614216400156410ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #ifndef _XOPEN_SOURCE_EXTENDED # define _XOPEN_SOURCE_EXTENDED #endif #define _HPUX_ALT_XOPEN_SOCKET_API #include #ifdef HAVE_FCNTL_H # include #endif #import "OFUDPSocket.h" #import "OFUDPSocket+Private.h" #import "OFDNSResolver.h" #import "OFData.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFThread.h" #import "OFAlreadyOpenException.h" #import "OFBindIPSocketFailedException.h" @implementation OFUDPSocket @dynamic delegate; - (void)of_bindToAddress: (OFSocketAddress *)address extraType: (int)extraType OF_DIRECT { #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; #endif #if !defined(OF_HPUX) && !defined(OF_WII) && !defined(OF_NINTENDO_3DS) OFString *host; uint16_t port; #endif if ((_socket = socket( ((struct sockaddr *)&address->sockaddr)->sa_family, SOCK_DGRAM | SOCK_CLOEXEC | extraType, 0)) == OFInvalidSocketHandle) @throw [OFBindIPSocketFailedException exceptionWithHost: OFSocketAddressString(address) port: OFSocketAddressIPPort(address) socket: self errNo: _OFSocketErrNo()]; _canBlock = true; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) /* {} needed to avoid warning with Clang 10 if next #if is false. */ if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) { fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); } #endif #if defined(OF_HPUX) || defined(OF_WII) || defined(OF_NINTENDO_3DS) if (OFSocketAddressIPPort(address) != 0) { #endif if (bind(_socket, (struct sockaddr *)&address->sockaddr, address->length) != 0) { int errNo = _OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindIPSocketFailedException exceptionWithHost: OFSocketAddressString(address) port: OFSocketAddressIPPort(address) socket: self errNo: errNo]; } #if defined(OF_HPUX) || defined(OF_WII) || defined(OF_NINTENDO_3DS) } else { for (;;) { uint16_t rnd = 0; int ret; while (rnd < 1024) rnd = (uint16_t)rand(); OFSocketAddressSetIPPort(address, rnd); if ((ret = bind(_socket, (struct sockaddr *)&address->sockaddr, address->length)) == 0) break; if (_OFSocketErrNo() != EADDRINUSE) { int errNo = _OFSocketErrNo(); OFString *host = OFSocketAddressString(address); uint16_t port = OFSocketAddressIPPort(address); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindIPSocketFailedException exceptionWithHost: host port: port socket: self errNo: errNo]; } } } #endif #if !defined(OF_HPUX) && !defined(OF_WII) && !defined(OF_NINTENDO_3DS) host = OFSocketAddressString(address); port = OFSocketAddressIPPort(address); memset(address, 0, sizeof(*address)); address->length = (socklen_t)sizeof(address->sockaddr); if (_OFGetSockName(_socket, (struct sockaddr *)&address->sockaddr, &address->length) != 0) { int errNo = _OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindIPSocketFailedException exceptionWithHost: host port: port socket: self errNo: errNo]; } switch (((struct sockaddr *)&address->sockaddr)->sa_family) { case AF_INET: address->family = OFSocketAddressFamilyIPv4; break; # ifdef OF_HAVE_IPV6 case AF_INET6: address->family = OFSocketAddressFamilyIPv6; break; # endif default: closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindIPSocketFailedException exceptionWithHost: host port: port socket: self errNo: EAFNOSUPPORT]; } #endif } - (OFSocketAddress)bindToHost: (OFString *)host port: (uint16_t)port { void *pool = objc_autoreleasePoolPush(); OFData *socketAddresses; OFSocketAddress address; if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyOpenException exceptionWithObject: self]; socketAddresses = [[OFThread DNSResolver] resolveAddressesForHost: host addressFamily: OFSocketAddressFamilyAny]; address = *(OFSocketAddress *)[socketAddresses itemAtIndex: 0]; OFSocketAddressSetIPPort(&address, port); [self of_bindToAddress: &address extraType: 0]; objc_autoreleasePoolPop(pool); return address; } @end objfw-1.1.6/src/OFUNIXDatagramSocket.h000066400000000000000000000051041465614216400174210ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFDatagramSocket.h" OF_ASSUME_NONNULL_BEGIN @class OFString; /** * @protocol OFUNIXDatagramSocketDelegate OFUNIXDatagramSocket.h \ * ObjFW/OFUNIXDatagramSocket.h * * @brief A delegate for OFUNIXDatagramSocket. */ @protocol OFUNIXDatagramSocketDelegate @end /** * @class OFUNIXDatagramSocket OFUNIXDatagramSocket.h \ * ObjFW/OFUNIXDatagramSocket.h * * @brief A class which provides methods to create and use UNIX datagram * sockets. * * Addresses are of type @ref OFSocketAddress. You can use * @ref OFSocketAddressMakeUNIX to create an address or * @ref OFSocketAddressUNIXPath to get the socket path. * * @warning Even though the OFCopying protocol is implemented, it does *not* * return an independent copy of the socket, but instead retains it. * This is so that the socket can be used as a key for a dictionary, * so context can be associated with a socket. Using a socket in more * than one thread at the same time is not thread-safe, even if copy * was called to create one "instance" for every thread! */ @interface OFUNIXDatagramSocket: OFDatagramSocket { OF_RESERVE_IVARS(OFUNIXDatagramSocket, 4) } /** * @brief The delegate for asynchronous operations on the socket. * * @note The delegate is retained for as long as asynchronous operations are * still ongoing. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id delegate; /** * @brief Bind the socket to the specified path. * * @param path The path to bind to or `nil` for an anonymous socket * @return The address on which this socket can be reached, if a path was * specified * @throw OFBindUNIXSocketFailedException Binding failed * @throw OFAlreadyOpenException The socket is already bound */ - (OFSocketAddress)bindToPath: (nullable OFString *)path; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFUNIXDatagramSocket.m000066400000000000000000000042561465614216400174350ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #ifdef HAVE_FCNTL_H # include #endif #import "OFUNIXDatagramSocket.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFString.h" #import "OFAlreadyOpenException.h" #import "OFBindUNIXSocketFailedException.h" @implementation OFUNIXDatagramSocket @dynamic delegate; - (OFSocketAddress)bindToPath: (OFString *)path { OFSocketAddress address; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) int flags; #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyOpenException exceptionWithObject: self]; if (path != nil) address = OFSocketAddressMakeUNIX(path); else { address.family = OFSocketAddressFamilyUnknown; address.length = 0; } if ((_socket = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle) @throw [OFBindUNIXSocketFailedException exceptionWithPath: path socket: self errNo: _OFSocketErrNo()]; _canBlock = true; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); #endif if (path != nil) { if (bind(_socket, (struct sockaddr *)&address.sockaddr, address.length) != 0) { int errNo = _OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindUNIXSocketFailedException exceptionWithPath: path socket: self errNo: errNo]; } } return address; } @end objfw-1.1.6/src/OFUNIXStreamSocket.h000066400000000000000000000043471465614216400171440ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFStreamSocket.h" OF_ASSUME_NONNULL_BEGIN @class OFString; /** * @protocol OFUNIXStreamSocketDelegate OFUNIXStreamSocket.h \ * ObjFW/OFUNIXStreamSocket.h * * A delegate for OFUNIXStreamSocket. */ @protocol OFUNIXStreamSocketDelegate @end /** * @class OFUNIXStreamSocket OFUNIXStreamSocket.h ObjFW/OFUNIXStreamSocket.h * * @brief A class which provides methods to create and use UNIX stream sockets. * * To connect to a server, create a socket and connect it. * To create a server, create a socket, bind it and listen on it. */ @interface OFUNIXStreamSocket: OFStreamSocket { OF_RESERVE_IVARS(OFUNIXStreamSocket, 4) } /** * @brief The delegate for asynchronous operations on the socket. * * @note The delegate is retained for as long as asynchronous operations are * still ongoing. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id delegate; /** * @brief Connects the OFUNIXStreamSocket to the specified destination. * * @param path The path to connect to * @throw OFConnectUNIXSocketFailedException Connecting failed * @throw OFAlreadyOpenException The socket is already connected or bound */ - (void)connectToPath: (OFString *)path; /** * @brief Binds the socket to the specified host and port. * * @param path The path to bind to * @throw OFBindUNIXSocketFailedException Binding failed * @throw OFAlreadyOpenException The socket is already connected or bound */ - (void)bindToPath: (OFString *)path; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFUNIXStreamSocket.m000066400000000000000000000061361465614216400171470ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #ifdef HAVE_FCNTL_H # include #endif #import "OFUNIXStreamSocket.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFString.h" #import "OFAlreadyOpenException.h" #import "OFBindUNIXSocketFailedException.h" #import "OFConnectUNIXSocketFailedException.h" @implementation OFUNIXStreamSocket @dynamic delegate; - (void)connectToPath: (OFString *)path { OFSocketAddress address; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyOpenException exceptionWithObject: self]; address = OFSocketAddressMakeUNIX(path); if ((_socket = socket(address.sockaddr.un.sun_family, SOCK_STREAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle) @throw [OFConnectUNIXSocketFailedException exceptionWithPath: path socket: self errNo: _OFSocketErrNo()]; _canBlock = true; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); #endif if (connect(_socket, (struct sockaddr *)&address.sockaddr, address.length) != 0) { int errNo = _OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFConnectUNIXSocketFailedException exceptionWithPath: path socket: self errNo: errNo]; } } - (void)bindToPath: (OFString *)path { OFSocketAddress address; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyOpenException exceptionWithObject: self]; address = OFSocketAddressMakeUNIX(path); if ((_socket = socket(address.sockaddr.un.sun_family, SOCK_STREAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle) @throw [OFBindUNIXSocketFailedException exceptionWithPath: path socket: self errNo: _OFSocketErrNo()]; _canBlock = true; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); #endif if (bind(_socket, (struct sockaddr *)&address.sockaddr, address.length) != 0) { int errNo = _OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindUNIXSocketFailedException exceptionWithPath: path socket: self errNo: errNo]; } } @end objfw-1.1.6/src/OFURIDNSResourceRecord.h000066400000000000000000000044701465614216400177040ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFDNSResourceRecord.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFURIDNSResourceRecord \ * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h * * @brief A class representing an URI DNS resource record. */ OF_SUBCLASSING_RESTRICTED @interface OFURIDNSResourceRecord: OFDNSResourceRecord { uint16_t _priority, _weight; OFString *_target; } /** * @brief The priority of the resource record. */ @property (readonly, nonatomic) uint16_t priority; /** * @brief The weight of the resource record. */ @property (readonly, nonatomic) uint16_t weight; /** * @brief The target of the resource record. */ @property (readonly, nonatomic) OFString *target; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFURIDNSResourceRecord with the * specified name, class, priority, weight, target and time to live. * * @param name The name for the resource record * @param DNSClass The class code for the resource record * @param priority The priority for the resource record * @param weight The weight for the resource record * @param target The target for the resource record * @param TTL The time to live for the resource record * @return An initialized OFURIDNSResourceRecord */ - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass priority: (uint16_t)priority weight: (uint16_t)weight target: (OFString *)target TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFURIDNSResourceRecord.m000066400000000000000000000057521465614216400177150ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFURIDNSResourceRecord.h" @implementation OFURIDNSResourceRecord @synthesize priority = _priority, weight = _weight, target = _target; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass priority: (uint16_t)priority weight: (uint16_t)weight target: (OFString *)target TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: DNSClass recordType: OFDNSRecordTypeURI TTL: TTL]; @try { _priority = priority; _weight = weight; _target = [target copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_target release]; [super dealloc]; } - (bool)isEqual: (id)object { OFURIDNSResourceRecord *record; if (object == self) return true; if (![object isKindOfClass: [OFURIDNSResourceRecord class]]) return false; record = object; if (record->_name != _name && ![record->_name isEqual: _name]) return false; if (record->_DNSClass != _DNSClass) return false; if (record->_recordType != _recordType) return false; if (record->_priority != _priority) return false; if (record->_weight != _weight) return false; if (record->_target != _target && ![record->_target isEqual: _target]) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddByte(&hash, _DNSClass >> 8); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType >> 8); OFHashAddByte(&hash, _recordType); OFHashAddByte(&hash, _priority >> 8); OFHashAddByte(&hash, _priority); OFHashAddByte(&hash, _weight >> 8); OFHashAddByte(&hash, _weight); OFHashAddHash(&hash, _target.hash); OFHashFinalize(&hash); return hash; } - (OFString *)description { return [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tClass = %@\n" @"\tPriority = %" PRIu16 "\n" @"\tWeight = %" PRIu16 "\n" @"\tTarget = %@\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFDNSClassName(_DNSClass), _priority, _weight, _target, _TTL]; } @end objfw-1.1.6/src/OFUTF8String+Private.h000066400000000000000000000017751465614216400173610ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFUTF8String.h" OF_ASSUME_NONNULL_BEGIN OF_DIRECT_MEMBERS @interface OFUTF8String () - (instancetype)of_initWithUTF8String: (const char *)UTF8String length: (size_t)UTF8StringLength storage: (char *)storage OF_METHOD_FAMILY(init); @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFUTF8String.h000066400000000000000000000030521465614216400157410ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @interface OFUTF8String: OFString { /* * A pointer to the actual data. * * Since constant strings don't have `_storage`, they have to allocate * it on the first access. Strings created at runtime just set the * pointer to `&_storage`. */ struct OFUTF8StringIvars { char *cString; size_t cStringLength; bool isUTF8; size_t length; bool hasHash; unsigned long hash; bool freeWhenDone; } *restrict _s; struct OFUTF8StringIvars _storage; } @end #ifdef __cplusplus extern "C" { #endif extern int _OFUTF8StringCheck(const char *, size_t, size_t *) OF_VISIBILITY_HIDDEN; extern size_t _OFUTF8StringIndexToPosition(const char *, size_t, size_t) OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFUTF8String.m000066400000000000000000000673531465614216400157640ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #include #ifdef OF_HAVE_SYS_TYPES_H # include #endif #import "OFUTF8String.h" #import "OFUTF8String+Private.h" #import "OFASPrintF.h" #import "OFArray.h" #import "OFData.h" #import "OFMutableUTF8String.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "unicode.h" extern const OFChar16 _OFISO8859_2Table[]; extern const size_t _OFISO8859_2TableOffset; extern const OFChar16 _OFISO8859_3Table[]; extern const size_t _OFISO8859_3TableOffset; extern const OFChar16 _OFISO8859_15Table[]; extern const size_t _OFISO8859_15TableOffset; extern const OFChar16 _OFWindows1251Table[]; extern const size_t _OFWindows1251TableOffset; extern const OFChar16 _OFWindows1252Table[]; extern const size_t _OFWindows1252TableOffset; extern const OFChar16 _OFCodepage437Table[]; extern const size_t _OFCodepage437TableOffset; extern const OFChar16 _OFCodepage850Table[]; extern const size_t _OFCodepage850TableOffset; extern const OFChar16 _OFCodepage858Table[]; extern const size_t _OFCodepage858TableOffset; extern const OFChar16 _OFMacRomanTable[]; extern const size_t _OFMacRomanTableOffset; extern const OFChar16 _OFKOI8RTable[]; extern const size_t _OFKOI8RTableOffset; extern const OFChar16 _OFKOI8UTable[]; extern const size_t _OFKOI8UTableOffset; static inline int memcasecmp(const char *first, const char *second, size_t length) { for (size_t i = 0; i < length; i++) { unsigned char f = first[i]; unsigned char s = second[i]; f = OFASCIIToUpper(f); s = OFASCIIToUpper(s); if (f > s) return OFOrderedDescending; if (f < s) return OFOrderedAscending; } return OFOrderedSame; } int _OFUTF8StringCheck(const char *UTF8String, size_t UTF8Length, size_t *length) { size_t tmpLength = UTF8Length; int isUTF8 = 0; for (size_t i = 0; i < UTF8Length; i++) { /* No sign of UTF-8 here */ if OF_LIKELY (!(UTF8String[i] & 0x80)) continue; isUTF8 = 1; /* We're missing a start byte here */ if OF_UNLIKELY (!(UTF8String[i] & 0x40)) return -1; /* 2 byte sequences for code points 0 - 127 are forbidden */ if OF_UNLIKELY ((UTF8String[i] & 0x7E) == 0x40) return -1; /* We have at minimum a 2 byte character -> check next byte */ if OF_UNLIKELY (UTF8Length <= i + 1 || (UTF8String[i + 1] & 0xC0) != 0x80) return -1; /* Check if we have at minimum a 3 byte character */ if OF_LIKELY (!(UTF8String[i] & 0x20)) { i++; tmpLength--; continue; } /* We have at minimum a 3 byte char -> check second next byte */ if OF_UNLIKELY (UTF8Length <= i + 2 || (UTF8String[i + 2] & 0xC0) != 0x80) return -1; /* Check if we have a 4 byte character */ if OF_LIKELY (!(UTF8String[i] & 0x10)) { i += 2; tmpLength -= 2; continue; } /* We have a 4 byte character -> check third next byte */ if OF_UNLIKELY (UTF8Length <= i + 3 || (UTF8String[i + 3] & 0xC0) != 0x80) return -1; /* * Just in case, check if there's a 5th character, which is * forbidden by UTF-8 */ if OF_UNLIKELY (UTF8String[i] & 0x08) return -1; i += 3; tmpLength -= 3; } if (length != NULL) *length = tmpLength; return isUTF8; } static size_t positionToIndex(const char *string, size_t position) { size_t idx = position; for (size_t i = 0; i < position; i++) if OF_UNLIKELY ((string[i] & 0xC0) == 0x80) idx--; return idx; } size_t _OFUTF8StringIndexToPosition(const char *string, size_t idx, size_t length) { for (size_t i = 0; i <= idx; i++) if OF_UNLIKELY ((string[i] & 0xC0) == 0x80) if (++idx > length) @throw [OFInvalidFormatException exception]; return idx; } @implementation OFUTF8String - (instancetype)init { self = [super init]; @try { _s = &_storage; _s->cString = OFAllocZeroedMemory(1, 1); _s->freeWhenDone = true; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)of_initWithUTF8String: (const char *)UTF8String length: (size_t)UTF8StringLength storage: (char *)storage { self = [super init]; @try { if (UTF8StringLength >= 3 && memcmp(UTF8String, "\xEF\xBB\xBF", 3) == 0) { UTF8String += 3; UTF8StringLength -= 3; } _s = &_storage; _s->cString = storage; _s->cStringLength = UTF8StringLength; switch (_OFUTF8StringCheck(UTF8String, UTF8StringLength, &_s->length)) { case 1: _s->isUTF8 = true; break; case -1: @throw [OFInvalidEncodingException exception]; } memcpy(_s->cString, UTF8String, UTF8StringLength); _s->cString[UTF8StringLength] = 0; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength { self = [super init]; @try { const OFChar16 *table; size_t tableOffset, j; if (encoding == OFStringEncodingUTF8 && cStringLength >= 3 && memcmp(cString, "\xEF\xBB\xBF", 3) == 0) { cString += 3; cStringLength -= 3; } _s = &_storage; _s->cString = OFAllocMemory(cStringLength + 1, 1); _s->cStringLength = cStringLength; _s->freeWhenDone = true; if (encoding == OFStringEncodingUTF8 || encoding == OFStringEncodingASCII) { switch (_OFUTF8StringCheck(cString, cStringLength, &_s->length)) { case 1: if (encoding == OFStringEncodingASCII) @throw [OFInvalidEncodingException exception]; _s->isUTF8 = true; break; case -1: @throw [OFInvalidEncodingException exception]; } memcpy(_s->cString, cString, cStringLength); _s->cString[cStringLength] = 0; return self; } /* All other encodings we support are single byte encodings */ _s->length = cStringLength; if (encoding == OFStringEncodingISO8859_1) { j = 0; for (size_t i = 0; i < cStringLength; i++) { char buffer[4]; size_t bytes; if (!(cString[i] & 0x80)) { _s->cString[j++] = cString[i]; continue; } _s->isUTF8 = true; bytes = _OFUTF8StringEncode( (uint8_t)cString[i], buffer); if (bytes == 0) @throw [OFInvalidEncodingException exception]; _s->cStringLength += bytes - 1; _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, 1); memcpy(_s->cString + j, buffer, bytes); j += bytes; } _s->cString[_s->cStringLength] = 0; return self; } switch (encoding) { #define CASE(encoding, var) \ case encoding: \ table = var; \ tableOffset = var##Offset; \ break; #ifdef HAVE_ISO_8859_2 CASE(OFStringEncodingISO8859_2, _OFISO8859_2Table) #endif #ifdef HAVE_ISO_8859_3 CASE(OFStringEncodingISO8859_3, _OFISO8859_3Table) #endif #ifdef HAVE_ISO_8859_15 CASE(OFStringEncodingISO8859_15, _OFISO8859_15Table) #endif #ifdef HAVE_WINDOWS_1251 CASE(OFStringEncodingWindows1251, _OFWindows1251Table) #endif #ifdef HAVE_WINDOWS_1252 CASE(OFStringEncodingWindows1252, _OFWindows1252Table) #endif #ifdef HAVE_CODEPAGE_437 CASE(OFStringEncodingCodepage437, _OFCodepage437Table) #endif #ifdef HAVE_CODEPAGE_850 CASE(OFStringEncodingCodepage850, _OFCodepage850Table) #endif #ifdef HAVE_CODEPAGE_858 CASE(OFStringEncodingCodepage858, _OFCodepage858Table) #endif #ifdef HAVE_MAC_ROMAN CASE(OFStringEncodingMacRoman, _OFMacRomanTable) #endif #ifdef HAVE_KOI8_R CASE(OFStringEncodingKOI8R, _OFKOI8RTable) #endif #ifdef HAVE_KOI8_U CASE(OFStringEncodingKOI8U, _OFKOI8UTable) #endif #undef CASE default: @throw [OFInvalidArgumentException exception]; } j = 0; for (size_t i = 0; i < cStringLength; i++) { unsigned char character = (unsigned char)cString[i]; OFUnichar unichar; char buffer[4]; size_t byteLength; if (character < tableOffset) { _s->cString[j++] = cString[i]; continue; } unichar = table[character - tableOffset]; if (unichar == 0xFFFF) @throw [OFInvalidEncodingException exception]; _s->isUTF8 = true; byteLength = _OFUTF8StringEncode(unichar, buffer); if (byteLength == 0) @throw [OFInvalidEncodingException exception]; _s->cStringLength += byteLength - 1; _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, 1); memcpy(_s->cString + j, buffer, byteLength); j += byteLength; } _s->cString[_s->cStringLength] = 0; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String freeWhenDone: (bool)freeWhenDone { return [self initWithUTF8StringNoCopy: UTF8String length: strlen(UTF8String) freeWhenDone: freeWhenDone]; } - (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String length: (size_t)UTF8StringLength freeWhenDone: (bool)freeWhenDone { self = [super init]; @try { _s = &_storage; if (UTF8StringLength >= 3 && memcmp(UTF8String, "\xEF\xBB\xBF", 3) == 0) { UTF8String += 3; UTF8StringLength -= 3; } switch (_OFUTF8StringCheck(UTF8String, UTF8StringLength, &_s->length)) { case 1: _s->isUTF8 = true; break; case -1: @throw [OFInvalidEncodingException exception]; } _s->cString = (char *)UTF8String; _s->cStringLength = UTF8StringLength; _s->freeWhenDone = freeWhenDone; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithString: (OFString *)string { self = [super init]; @try { _s = &_storage; _s->cStringLength = string.UTF8StringLength; if ([string isKindOfClass: [OFUTF8String class]] || [string isKindOfClass: [OFMutableUTF8String class]]) _s->isUTF8 = ((OFUTF8String *)string)->_s->isUTF8; else _s->isUTF8 = true; _s->length = string.length; _s->cString = OFAllocMemory(_s->cStringLength + 1, 1); memcpy(_s->cString, string.UTF8String, _s->cStringLength + 1); _s->freeWhenDone = true; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithCharacters: (const OFUnichar *)characters length: (size_t)length { self = [super init]; @try { size_t j; _s = &_storage; _s->cString = OFAllocMemory((length * 4) + 1, 1); _s->length = length; _s->freeWhenDone = true; j = 0; for (size_t i = 0; i < length; i++) { size_t len = _OFUTF8StringEncode(characters[i], _s->cString + j); if (len == 0) @throw [OFInvalidEncodingException exception]; if (len > 1) _s->isUTF8 = true; j += len; } _s->cString[j] = '\0'; _s->cStringLength = j; @try { _s->cString = OFResizeMemory(_s->cString, j + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithUTF16String: (const OFChar16 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder { self = [super init]; @try { size_t j; bool swap = false; if (length > 0 && *string == 0xFEFF) { string++; length--; } else if (length > 0 && *string == 0xFFFE) { swap = true; string++; length--; } else if (byteOrder != OFByteOrderNative) swap = true; _s = &_storage; _s->cString = OFAllocMemory((length * 4) + 1, 1); _s->length = length; _s->freeWhenDone = true; j = 0; for (size_t i = 0; i < length; i++) { OFUnichar character = (swap ? OFByteSwap16(string[i]) : string[i]); size_t len; /* Missing high surrogate */ if ((character & 0xFC00) == 0xDC00) @throw [OFInvalidEncodingException exception]; if ((character & 0xFC00) == 0xD800) { OFChar16 nextCharacter; if (length <= i + 1) @throw [OFInvalidEncodingException exception]; nextCharacter = (swap ? OFByteSwap16(string[i + 1]) : string[i + 1]); if ((nextCharacter & 0xFC00) != 0xDC00) @throw [OFInvalidEncodingException exception]; character = (((character & 0x3FF) << 10) | (nextCharacter & 0x3FF)) + 0x10000; i++; _s->length--; } len = _OFUTF8StringEncode(character, _s->cString + j); if (len == 0) @throw [OFInvalidEncodingException exception]; if (len > 1) _s->isUTF8 = true; j += len; } _s->cString[j] = '\0'; _s->cStringLength = j; @try { _s->cString = OFResizeMemory(_s->cString, j + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithUTF32String: (const OFChar32 *)characters length: (size_t)length byteOrder: (OFByteOrder)byteOrder { self = [super init]; @try { size_t j; bool swap = false; if (length > 0 && *characters == 0xFEFF) { characters++; length--; } else if (length > 0 && *characters == 0xFFFE0000) { swap = true; characters++; length--; } else if (byteOrder != OFByteOrderNative) swap = true; _s = &_storage; _s->cString = OFAllocMemory((length * 4) + 1, 1); _s->length = length; _s->freeWhenDone = true; j = 0; for (size_t i = 0; i < length; i++) { char buffer[4]; size_t len = _OFUTF8StringEncode((swap ? OFByteSwap32(characters[i]) : characters[i]), buffer); switch (len) { case 1: _s->cString[j++] = buffer[0]; break; case 2: case 3: case 4: _s->isUTF8 = true; memcpy(_s->cString + j, buffer, len); j += len; break; default: @throw [OFInvalidEncodingException exception]; } } _s->cString[j] = '\0'; _s->cStringLength = j; @try { _s->cString = OFResizeMemory(_s->cString, j + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithFormat: (OFConstantString *)format arguments: (va_list)arguments { self = [super init]; @try { char *tmp; int cStringLength; if (format == nil) @throw [OFInvalidArgumentException exception]; _s = &_storage; if ((cStringLength = _OFVASPrintF(&tmp, format.UTF8String, arguments)) == -1) @throw [OFInvalidFormatException exception]; _s->cStringLength = cStringLength; @try { switch (_OFUTF8StringCheck(tmp, cStringLength, &_s->length)) { case 1: _s->isUTF8 = true; break; case -1: @throw [OFInvalidEncodingException exception]; } _s->cString = OFAllocMemory(cStringLength + 1, 1); memcpy(_s->cString, tmp, cStringLength + 1); _s->freeWhenDone = true; } @finally { OFFreeMemory(tmp); } } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_s != NULL && _s->freeWhenDone) OFFreeMemory(_s->cString); [super dealloc]; } - (size_t)getCString: (char *)cString maxLength: (size_t)maxLength encoding: (OFStringEncoding)encoding { switch (encoding) { case OFStringEncodingASCII: if (_s->isUTF8) @throw [OFInvalidEncodingException exception]; /* intentional fall-through */ case OFStringEncodingUTF8: if (_s->cStringLength + 1 > maxLength) @throw [OFOutOfRangeException exception]; memcpy(cString, _s->cString, _s->cStringLength + 1); return _s->cStringLength; default: return [super getCString: cString maxLength: maxLength encoding: encoding]; } } - (const char *)cStringWithEncoding: (OFStringEncoding)encoding { switch (encoding) { case OFStringEncodingASCII: if (_s->isUTF8) @throw [OFInvalidEncodingException exception]; /* intentional fall-through */ case OFStringEncodingUTF8: return _s->cString; default: return [super cStringWithEncoding: encoding]; } } - (const char *)UTF8String { return _s->cString; } - (size_t)length { return _s->length; } - (size_t)cStringLengthWithEncoding: (OFStringEncoding)encoding { switch (encoding) { case OFStringEncodingUTF8: case OFStringEncodingASCII: return _s->cStringLength; default: return [super cStringLengthWithEncoding: encoding]; } } - (size_t)UTF8StringLength { return _s->cStringLength; } - (bool)isEqual: (id)object { OFUTF8String *string; if (object == self) return true; if (![object isKindOfClass: [OFString class]]) return false; string = object; if (string.UTF8StringLength != _s->cStringLength || string.length != _s->length) return false; if (([string isKindOfClass: [OFUTF8String class]] || [string isKindOfClass: [OFMutableUTF8String class]]) && _s->hasHash && string->_s->hasHash && _s->hash != string->_s->hash) return false; if (strcmp(_s->cString, string.UTF8String) != 0) return false; return true; } - (OFComparisonResult)compare: (OFString *)string { size_t otherCStringLength, minimumCStringLength; int compare; if (string == self) return OFOrderedSame; if (![string isKindOfClass: [OFString class]]) @throw [OFInvalidArgumentException exception]; otherCStringLength = string.UTF8StringLength; minimumCStringLength = (_s->cStringLength > otherCStringLength ? otherCStringLength : _s->cStringLength); if ((compare = memcmp(_s->cString, string.UTF8String, minimumCStringLength)) == 0) { if (_s->cStringLength > otherCStringLength) return OFOrderedDescending; if (_s->cStringLength < otherCStringLength) return OFOrderedAscending; return OFOrderedSame; } if (compare > 0) return OFOrderedDescending; else return OFOrderedAscending; } - (OFComparisonResult)caseInsensitiveCompare: (OFString *)string { const char *otherCString; size_t otherCStringLength, minimumCStringLength; #ifdef OF_HAVE_UNICODE_TABLES size_t i, j; #endif int compare; if (string == self) return OFOrderedSame; otherCString = string.UTF8String; otherCStringLength = string.UTF8StringLength; #ifdef OF_HAVE_UNICODE_TABLES if (!_s->isUTF8) { #endif minimumCStringLength = (_s->cStringLength > otherCStringLength ? otherCStringLength : _s->cStringLength); if ((compare = memcasecmp(_s->cString, otherCString, minimumCStringLength)) == 0) { if (_s->cStringLength > otherCStringLength) return OFOrderedDescending; if (_s->cStringLength < otherCStringLength) return OFOrderedAscending; return OFOrderedSame; } if (compare > 0) return OFOrderedDescending; else return OFOrderedAscending; #ifdef OF_HAVE_UNICODE_TABLES } i = j = 0; while (i < _s->cStringLength && j < otherCStringLength) { OFUnichar c1, c2; ssize_t l1, l2; l1 = _OFUTF8StringDecode(_s->cString + i, _s->cStringLength - i, &c1); l2 = _OFUTF8StringDecode(otherCString + j, otherCStringLength - j, &c2); if (l1 <= 0 || l2 <= 0 || c1 > 0x10FFFF || c2 > 0x10FFFF) @throw [OFInvalidEncodingException exception]; if (c1 >> 8 < _OFUnicodeCaseFoldingTableSize) { OFUnichar tc = _OFUnicodeCaseFoldingTable[c1 >> 8][c1 & 0xFF]; if (tc) c1 = tc; } if (c2 >> 8 < _OFUnicodeCaseFoldingTableSize) { OFUnichar tc = _OFUnicodeCaseFoldingTable[c2 >> 8][c2 & 0xFF]; if (tc) c2 = tc; } if (c1 > c2) return OFOrderedDescending; if (c1 < c2) return OFOrderedAscending; i += l1; j += l2; } if (_s->cStringLength - i > otherCStringLength - j) return OFOrderedDescending; else if (_s->cStringLength - i < otherCStringLength - j) return OFOrderedAscending; #endif return OFOrderedSame; } - (unsigned long)hash { unsigned long hash; if (_s->hasHash) return _s->hash; OFHashInit(&hash); for (size_t i = 0; i < _s->cStringLength; i++) { OFUnichar c; ssize_t length; if ((length = _OFUTF8StringDecode(_s->cString + i, _s->cStringLength - i, &c)) <= 0) @throw [OFInvalidEncodingException exception]; OFHashAddByte(&hash, (c & 0xFF0000) >> 16); OFHashAddByte(&hash, (c & 0x00FF00) >> 8); OFHashAddByte(&hash, c & 0x0000FF); i += length - 1; } OFHashFinalize(&hash); _s->hash = hash; _s->hasHash = true; return hash; } - (OFUnichar)characterAtIndex: (size_t)idx { OFUnichar character; if (idx >= _s->length) @throw [OFOutOfRangeException exception]; if (!_s->isUTF8) return _s->cString[idx]; idx = _OFUTF8StringIndexToPosition(_s->cString, idx, _s->cStringLength); if (_OFUTF8StringDecode(_s->cString + idx, _s->cStringLength - idx, &character) <= 0) @throw [OFInvalidEncodingException exception]; return character; } - (void)getCharacters: (OFUnichar *)buffer inRange: (OFRange)range { /* TODO: Could be slightly optimized */ void *pool = objc_autoreleasePoolPush(); const OFUnichar *characters = self.characters; if (range.length > SIZE_MAX - range.location || range.location + range.length > _s->length) @throw [OFOutOfRangeException exception]; memcpy(buffer, characters + range.location, range.length * sizeof(OFUnichar)); objc_autoreleasePoolPop(pool); } - (OFRange)rangeOfString: (OFString *)string options: (OFStringSearchOptions)options range: (OFRange)range { const char *cString = string.UTF8String; size_t cStringLength = string.UTF8StringLength; size_t rangeLocation, rangeLength; if (range.length > SIZE_MAX - range.location || range.location + range.length > _s->length) @throw [OFOutOfRangeException exception]; if (_s->isUTF8) { rangeLocation = _OFUTF8StringIndexToPosition( _s->cString, range.location, _s->cStringLength); rangeLength = _OFUTF8StringIndexToPosition( _s->cString + rangeLocation, range.length, _s->cStringLength - rangeLocation); } else { rangeLocation = range.location; rangeLength = range.length; } if (cStringLength == 0) return OFMakeRange(0, 0); if (cStringLength > rangeLength) return OFMakeRange(OFNotFound, 0); if (options & OFStringSearchBackwards) { for (size_t i = rangeLength - cStringLength;; i--) { if (memcmp(_s->cString + rangeLocation + i, cString, cStringLength) == 0) { range.location += positionToIndex( _s->cString + rangeLocation, i); range.length = string.length; return range; } /* Did not match and we're at the last char */ if (i == 0) return OFMakeRange(OFNotFound, 0); } } else { for (size_t i = 0; i <= rangeLength - cStringLength; i++) { if (memcmp(_s->cString + rangeLocation + i, cString, cStringLength) == 0) { range.location += positionToIndex( _s->cString + rangeLocation, i); range.length = string.length; return range; } } } return OFMakeRange(OFNotFound, 0); } - (bool)containsString: (OFString *)string { const char *cString = string.UTF8String; size_t cStringLength = string.UTF8StringLength; if (cStringLength == 0) return true; if (cStringLength > _s->cStringLength) return false; for (size_t i = 0; i <= _s->cStringLength - cStringLength; i++) if (memcmp(_s->cString + i, cString, cStringLength) == 0) return true; return false; } - (OFString *)substringWithRange: (OFRange)range { size_t start = range.location; size_t end = range.location + range.length; if (range.length > SIZE_MAX - range.location || end > _s->length) @throw [OFOutOfRangeException exception]; if (_s->isUTF8) { start = _OFUTF8StringIndexToPosition(_s->cString, start, _s->cStringLength); end = _OFUTF8StringIndexToPosition(_s->cString, end, _s->cStringLength); } return [OFString stringWithUTF8String: _s->cString + start length: end - start]; } - (bool)hasPrefix: (OFString *)prefix { size_t cStringLength = prefix.UTF8StringLength; if (cStringLength > _s->cStringLength) return false; return (memcmp(_s->cString, prefix.UTF8String, cStringLength) == 0); } - (bool)hasSuffix: (OFString *)suffix { size_t cStringLength = suffix.UTF8StringLength; if (cStringLength > _s->cStringLength) return false; return (memcmp(_s->cString + (_s->cStringLength - cStringLength), suffix.UTF8String, cStringLength) == 0); } - (OFArray *)componentsSeparatedByString: (OFString *)delimiter options: (OFStringSeparationOptions)options { void *pool; OFMutableArray *array; const char *cString; size_t cStringLength; bool skipEmpty = (options & OFStringSkipEmptyComponents); size_t last; OFString *component; if (delimiter == nil) @throw [OFInvalidArgumentException exception]; if (delimiter.length == 0) return [OFArray arrayWithObject: self]; array = [OFMutableArray array]; pool = objc_autoreleasePoolPush(); cString = delimiter.UTF8String; cStringLength = delimiter.UTF8StringLength; if (cStringLength > _s->cStringLength) { [array addObject: [[self copy] autorelease]]; objc_autoreleasePoolPop(pool); return array; } last = 0; for (size_t i = 0; i <= _s->cStringLength - cStringLength; i++) { if (memcmp(_s->cString + i, cString, cStringLength) != 0) continue; component = [OFString stringWithUTF8String: _s->cString + last length: i - last]; if (!skipEmpty || component.length > 0) [array addObject: component]; i += cStringLength - 1; last = i + 1; } component = [OFString stringWithUTF8String: _s->cString + last]; if (!skipEmpty || component.length > 0) [array addObject: component]; [array makeImmutable]; objc_autoreleasePoolPop(pool); return array; } - (const OFUnichar *)characters { OFUnichar *buffer = OFAllocMemory(_s->length, sizeof(OFUnichar)); size_t i = 0, j = 0; const OFUnichar *ret; while (i < _s->cStringLength) { OFUnichar c; ssize_t cLen; cLen = _OFUTF8StringDecode(_s->cString + i, _s->cStringLength - i, &c); if (cLen <= 0 || c > 0x10FFFF) { OFFreeMemory(buffer); @throw [OFInvalidEncodingException exception]; } buffer[j++] = c; i += cLen; } @try { ret = [[OFData dataWithItemsNoCopy: buffer count: _s->length itemSize: sizeof(OFUnichar) freeWhenDone: true] items]; } @catch (id e) { OFFreeMemory(buffer); @throw e; } return ret; } - (const OFChar32 *)UTF32StringWithByteOrder: (OFByteOrder)byteOrder { OFChar32 *buffer = OFAllocMemory(_s->length + 1, sizeof(OFChar32)); size_t i = 0, j = 0; const OFChar32 *ret; while (i < _s->cStringLength) { OFChar32 c; ssize_t cLen; cLen = _OFUTF8StringDecode(_s->cString + i, _s->cStringLength - i, &c); if (cLen <= 0 || c > 0x10FFFF) { OFFreeMemory(buffer); @throw [OFInvalidEncodingException exception]; } if (byteOrder != OFByteOrderNative) buffer[j++] = OFByteSwap32(c); else buffer[j++] = c; i += cLen; } buffer[j] = 0; @try { ret = [[OFData dataWithItemsNoCopy: buffer count: _s->length + 1 itemSize: sizeof(OFChar32) freeWhenDone: true] items]; } @catch (id e) { OFFreeMemory(buffer); @throw e; } return ret; } #ifdef OF_HAVE_BLOCKS - (void)enumerateLinesUsingBlock: (OFStringLineEnumerationBlock)block { void *pool; const char *cString = _s->cString; const char *last = cString; bool stop = false, lastCarriageReturn = false; while (!stop && *cString != 0) { if (lastCarriageReturn && *cString == '\n') { lastCarriageReturn = false; cString++; last++; continue; } if (*cString == '\n' || *cString == '\r') { pool = objc_autoreleasePoolPush(); block([OFString stringWithUTF8String: last length: cString - last], &stop); last = cString + 1; objc_autoreleasePoolPop(pool); } lastCarriageReturn = (*cString == '\r'); cString++; } pool = objc_autoreleasePoolPush(); if (!stop) block([OFString stringWithUTF8String: last length: cString - last], &stop); objc_autoreleasePoolPop(pool); } #endif @end objfw-1.1.6/src/OFUUID.h000066400000000000000000000055331465614216400146000ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN @class OFString; /** * @class OFUUID OFUUID.h ObjFW/OFUUID.h * * @brief A UUID conforming to RFC 4122. */ OF_SUBCLASSING_RESTRICTED @interface OFUUID: OFObject { unsigned char _bytes[16]; } /** * @brief The UUID as a string. */ @property (readonly, nonatomic) OFString *UUIDString; /** * @brief Creates a new random UUID as per RFC 4122 version 4. * * @return A new, autoreleased OFUUID */ + (instancetype)UUID; /** * @brief Creates a new UUID with the specified bytes. * * @param bytes The bytes for the UUID * @return A new, autoreleased OFUUID */ + (instancetype)UUIDWithUUIDBytes: (const unsigned char [_Nonnull 16])bytes; /** * @brief Creates a new UUID with the specified UUID string. * * @param string The UUID string for the UUID * @return A new, autoreleased OFUUID * @throw OFInvalidFormatException The specified string is not a valid UUID * string */ + (instancetype)UUIDWithUUIDString: (OFString *)string; /** * @brief Initializes an already allocated OFUUID as a new random UUID as per * RFC 4122 version 4. * * @return An initialized OFUUID */ - (instancetype)init; /** * @brief Initializes an already allocated OFUUID with the specified bytes. * * @param bytes The bytes to initialize the OFUUID with * @return An initialized OFUUID */ - (instancetype)initWithUUIDBytes: (const unsigned char [_Nonnull 16])bytes; /** * @brief Initializes an already allocated OFUUID with the specified UUID * string. * * @param string The UUID string to initialize the OFUUID with * @return An initialized OFUUID * @throw OFInvalidFormatException The specified string is not a valid UUID * string */ - (instancetype)initWithUUIDString: (OFString *)string; /** * @brief Compares the UUID to another UUID. * * @param UUID The UUID to compare to * @return The result of the comparison */ - (OFComparisonResult)compare: (OFUUID *)UUID; /** * @brief Gets the bytes of the UUID. * * @param bytes An array of 16 bytes into which to write the UUID */ - (void)getUUIDBytes: (unsigned char [_Nonnull 16])bytes; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFUUID.m000066400000000000000000000115341465614216400146030ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFUUID.h" #import "OFArray.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #define bytesSize 16 @implementation OFUUID + (instancetype)UUID { return [[[self alloc] init] autorelease]; } + (instancetype)UUIDWithUUIDBytes: (const unsigned char [16])bytes { return [[[self alloc] initWithUUIDBytes: bytes] autorelease]; } + (instancetype)UUIDWithUUIDString: (OFString *)string { return [[[self alloc] initWithUUIDString: string] autorelease]; } - (instancetype)init { uint64_t r; self = [super init]; r = OFRandom64(); memcpy(_bytes, &r, 8); r = OFRandom64(); memcpy(_bytes + 8, &r, 8); _bytes[6] &= ~((1 << 7) | (1 << 5) | (1 << 4)); _bytes[6] |= (1 << 6); _bytes[8] &= ~(1 << 6); _bytes[8] |= (1 << 7); return self; } - (instancetype)initWithUUIDBytes: (const unsigned char [16])bytes { self = [super init]; memcpy(_bytes, bytes, sizeof(_bytes)); return self; } static void decode(OFArray OF_GENERIC(OFString *) *components, size_t componentIndex, size_t componentLength, unsigned char *bytes, size_t *i) { void *pool = objc_autoreleasePoolPush(); OFString *component = [components objectAtIndex: componentIndex]; const char *cString; if (component.UTF8StringLength != componentLength) @throw [OFInvalidFormatException exception]; if (*i + componentLength / 2 > bytesSize) @throw [OFOutOfRangeException exception]; cString = component.UTF8String; for (size_t j = 0; j < componentLength; j += 2) { uint8_t value; if (cString[j] >= '0' && cString[j] <= '9') value = cString[j] - '0'; else if (cString[j] >= 'a' && cString[j] <= 'f') value = cString[j] - 'a' + 10; else if (cString[j] >= 'A' && cString[j] <= 'F') value = cString[j] - 'A' + 10; else @throw [OFInvalidFormatException exception]; value <<= 4; if (cString[j + 1] >= '0' && cString[j + 1] <= '9') value |= cString[j + 1] - '0'; else if (cString[j + 1] >= 'a' && cString[j + 1] <= 'f') value |= cString[j + 1] - 'a' + 10; else if (cString[j + 1] >= 'A' && cString[j + 1] <= 'F') value |= cString[j + 1] - 'A' + 10; else @throw [OFInvalidFormatException exception]; bytes[(*i)++] = value; } objc_autoreleasePoolPop(pool); } - (instancetype)initWithUUIDString: (OFString *)string { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); size_t i = 0; OFArray OF_GENERIC(OFString *) *components = [string componentsSeparatedByString: @"-"]; if (components.count != 5) @throw [OFInvalidFormatException exception]; decode(components, 0, 8, _bytes, &i); decode(components, 1, 4, _bytes, &i); decode(components, 2, 4, _bytes, &i); decode(components, 3, 4, _bytes, &i); decode(components, 4, 12, _bytes, &i); OFEnsure(i == 16); objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (bool)isEqual: (id)object { OFUUID *UUID; if (![object isKindOfClass: [OFUUID class]]) return false; UUID = object; return (memcmp(_bytes, UUID->_bytes, sizeof(_bytes)) == 0); } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); for (size_t i = 0; i < sizeof(_bytes); i++) OFHashAddByte(&hash, _bytes[i]); OFHashFinalize(&hash); return hash; } - (id)copy { return [self retain]; } - (OFComparisonResult)compare: (OFUUID *)UUID { int comparison; if (![UUID isKindOfClass: [OFUUID class]]) @throw [OFInvalidArgumentException exception]; if ((comparison = memcmp(_bytes, UUID->_bytes, sizeof(_bytes))) == 0) return OFOrderedSame; if (comparison > 0) return OFOrderedDescending; else return OFOrderedAscending; } - (void)getUUIDBytes: (unsigned char [16])bytes { memcpy(bytes, _bytes, sizeof(_bytes)); } - (OFString *)UUIDString { return [OFString stringWithFormat: @"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" @"%02x%02x%02x%02x%02x%02x", _bytes[0], _bytes[1], _bytes[2], _bytes[3], _bytes[4], _bytes[5], _bytes[6], _bytes[7], _bytes[8], _bytes[9], _bytes[10], _bytes[11], _bytes[12], _bytes[13], _bytes[14], _bytes[15]]; } - (OFString *)description { return self.UUIDString; } @end objfw-1.1.6/src/OFValue.h000066400000000000000000000131311465614216400150770ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFValue OFValue.h ObjFW/OFValue.h * * @brief A class for storing arbitrary values in an object. */ @interface OFValue: OFObject /** * @brief The ObjC type encoding of the value. */ @property (readonly, nonatomic) const char *objCType; /** * @brief The value as a pointer to void. * * @throw OFOutOfRangeException The value is not pointer-sized */ @property (readonly, nonatomic) void *pointerValue; /** * @brief The value as a non-retained object. * * @throw OFOutOfRangeException The value is not pointer-sized */ @property (readonly, nonatomic) id nonretainedObjectValue; /** * @brief The value as an OFRange. * * @throw OFOutOfRangeException The value is not OFRange-sized */ @property (readonly, nonatomic) OFRange rangeValue; /** * @brief The value as an OFPoint. * * @throw OFOutOfRangeException The value is not OFPoint-sized */ @property (readonly, nonatomic) OFPoint pointValue; /** * @brief The value as an OFSize. * * @throw OFOutOfRangeException The value is not OFSize-sized */ @property (readonly, nonatomic) OFSize sizeValue; /** * @brief The value as an OFRect. * * @throw OFOutOfRangeException The value is not OFRect-sized */ @property (readonly, nonatomic) OFRect rectValue; /** * @brief The value as an OFVector3D. * * @throw OFOutOfRangeException The value is not OFVector3D-sized */ @property (readonly, nonatomic) OFVector3D vector3DValue; /** * @brief The value as an OFVector4D. * * @throw OFOutOfRangeException The value is not OFVector4D-sized */ @property (readonly, nonatomic) OFVector4D vector4DValue; /** * @brief Creates a new, autorelease OFValue with the specified bytes of the * specified type. * * @param bytes The bytes containing the value * @param objCType The ObjC type encoding for the value * @return A new, autoreleased OFValue */ + (instancetype)valueWithBytes: (const void *)bytes objCType: (const char *)objCType; /** * @brief Creates a new, autoreleased OFValue containing the specified pointer. * * Only the raw value of the pointer is stored and no data will be copied. * * @param pointer The pointer the OFValue should contain * @return A new, autoreleased OFValue */ + (instancetype)valueWithPointer: (const void *)pointer; /** * @brief Creates a new, autoreleased OFValue containing the specified * non-retained object. * * The object is not retained, which makes this useful for storing objects in * collections without retaining them. * * @param object The object the OFValue should contain without retaining it * @return A new, autoreleased OFValue */ + (instancetype)valueWithNonretainedObject: (id)object; /** * @brief Creates a new, autoreleased OFValue containing the specified range. * * @param range The range the OFValue should contain * @return A new, autoreleased OFValue */ + (instancetype)valueWithRange: (OFRange)range; /** * @brief Creates a new, autoreleased OFValue containing the specified point. * * @param point The point the OFValue should contain * @return A new, autoreleased OFValue */ + (instancetype)valueWithPoint: (OFPoint)point; /** * @brief Creates a new, autoreleased OFValue containing the specified size. * * @param size The size the OFValue should contain * @return A new, autoreleased OFValue */ + (instancetype)valueWithSize: (OFSize)size; /** * @brief Creates a new, autoreleased OFValue containing the specified * rectangle. * * @param rect The rectangle the OFValue should contain * @return A new, autoreleased OFValue */ + (instancetype)valueWithRect: (OFRect)rect; /** * @brief Creates a new, autoreleased OFValue containing the specified * 3D vector. * * @param vector3D The 3D vector the OFValue should contain * @return A new, autoreleased OFValue */ + (instancetype)valueWithVector3D: (OFVector3D)vector3D; /** * @brief Creates a new, autoreleased OFValue containing the specified * 4D vector. * * @param vector4D The 4D vector the OFValue should contain * @return A new, autoreleased OFValue */ + (instancetype)valueWithVector4D: (OFVector4D)vector4D; /** * @brief Initializes an already allocated OFValue with the specified bytes of * the specified type. * * @param bytes The bytes containing the value * @param objCType The ObjC type encoding for the value * @return An initialized OFValue */ - (instancetype)initWithBytes: (const void *)bytes objCType: (const char *)objCType OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; /** * @brief Gets the value. * * @param value The buffer to copy the value into * @param size The size of the value * @throw OFOutOfRangeException The specified size does not match the value */ - (void)getValue: (void *)value size: (size_t)size; @end OF_ASSUME_NONNULL_END #if !defined(NSINTEGER_DEFINED) && !__has_feature(modules) /* Required for array literals to work */ @compatibility_alias NSValue OFValue; #endif objfw-1.1.6/src/OFValue.m000066400000000000000000000177011465614216400151130ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFValue.h" #import "OFConcreteValue.h" #import "OFMethodSignature.h" #import "OFString.h" #import "OFOutOfMemoryException.h" static struct { Class isa; } placeholder; @interface OFPlaceholderValue: OFValue @end @implementation OFPlaceholderValue #ifdef __clang__ /* We intentionally don't call into super, so silence the warning. */ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunknown-pragmas" # pragma clang diagnostic ignored "-Wobjc-designated-initializers" #endif - (instancetype)initWithBytes: (const void *)bytes objCType: (const char *)objCType { return (id)[[OFConcreteValue alloc] initWithBytes: bytes objCType: objCType]; } #ifdef __clang__ # pragma clang diagnostic pop #endif OF_SINGLETON_METHODS @end @implementation OFValue + (void)initialize { if (self == [OFValue class]) object_setClass((id)&placeholder, [OFPlaceholderValue class]); } + (instancetype)alloc { if (self == [OFValue class]) return (id)&placeholder; return [super alloc]; } + (instancetype)valueWithBytes: (const void *)bytes objCType: (const char *)objCType { return [[[OFValue alloc] initWithBytes: bytes objCType: objCType] autorelease]; } + (instancetype)valueWithPointer: (const void *)pointer { return [[[OFValue alloc] initWithBytes: &pointer objCType: @encode(const void *)] autorelease]; } + (instancetype)valueWithNonretainedObject: (id)object { return [[[OFValue alloc] initWithBytes: &object objCType: @encode(id)] autorelease]; } + (instancetype)valueWithRange: (OFRange)range { return [[[OFValue alloc] initWithBytes: &range objCType: @encode(OFRange)] autorelease]; } + (instancetype)valueWithPoint: (OFPoint)point { return [[[OFValue alloc] initWithBytes: &point objCType: @encode(OFPoint)] autorelease]; } + (instancetype)valueWithSize: (OFSize)size { return [[[OFValue alloc] initWithBytes: &size objCType: @encode(OFSize)] autorelease]; } + (instancetype)valueWithRect: (OFRect)rect { return [[[OFValue alloc] initWithBytes: &rect objCType: @encode(OFRect)] autorelease]; } + (instancetype)valueWithVector3D: (OFVector3D)vector3D { return [[[OFValue alloc] initWithBytes: &vector3D objCType: @encode(OFVector3D)] autorelease]; } + (instancetype)valueWithVector4D: (OFVector4D)vector4D { return [[[OFValue alloc] initWithBytes: &vector4D objCType: @encode(OFVector4D)] autorelease]; } - (instancetype)initWithBytes: (const void *)bytes objCType: (const char *)objCType { if ([self isMemberOfClass: [OFValue class]]) { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @throw e; } abort(); } return [super init]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (bool)isEqual: (id)object { const char *objCType; size_t size; void *value, *otherValue; bool ret; if (object == self) return true; if (![object isKindOfClass: [OFValue class]]) return false; objCType = self.objCType; if (strcmp([object objCType], objCType) != 0) return false; size = OFSizeOfTypeEncoding(objCType); value = OFAllocMemory(1, size); @try { otherValue = OFAllocMemory(1, size); } @catch (id e) { OFFreeMemory(value); @throw e; } @try { [self getValue: value size: size]; [object getValue: otherValue size: size]; ret = (memcmp(value, otherValue, size) == 0); } @finally { OFFreeMemory(value); OFFreeMemory(otherValue); } return ret; } - (unsigned long)hash { size_t size = OFSizeOfTypeEncoding(self.objCType); unsigned char *value; unsigned long hash; value = OFAllocMemory(1, size); @try { [self getValue: value size: size]; OFHashInit(&hash); for (size_t i = 0; i < size; i++) OFHashAddByte(&hash, value[i]); OFHashFinalize(&hash); } @finally { OFFreeMemory(value); } return hash; } - (id)copy { return [self retain]; } - (const char *)objCType { OF_UNRECOGNIZED_SELECTOR } - (void)getValue: (void *)value size: (size_t)size { OF_UNRECOGNIZED_SELECTOR } - (void *)pointerValue { void *ret; [self getValue: &ret size: sizeof(ret)]; return ret; } - (id)nonretainedObjectValue { id ret; [self getValue: &ret size: sizeof(ret)]; return ret; } - (OFRange)rangeValue { OFRange ret; [self getValue: &ret size: sizeof(ret)]; return ret; } - (OFPoint)pointValue { OFPoint ret; [self getValue: &ret size: sizeof(ret)]; return ret; } - (OFSize)sizeValue { OFSize ret; [self getValue: &ret size: sizeof(ret)]; return ret; } - (OFRect)rectValue { OFRect ret; [self getValue: &ret size: sizeof(ret)]; return ret; } - (OFVector3D)vector3DValue { OFVector3D ret; [self getValue: &ret size: sizeof(ret)]; return ret; } - (OFVector4D)vector4DValue { OFVector4D ret; [self getValue: &ret size: sizeof(ret)]; return ret; } - (OFString *)description { const char *objCType = self.objCType; OFMutableString *ret; size_t size; unsigned char *value; if (strcmp(objCType, @encode(OFRange)) == 0 || strcmp(objCType, @encode(const OFRange)) == 0) { OFRange rangeValue; [self getValue: &rangeValue size: sizeof(rangeValue)]; return [OFString stringWithFormat: @"", rangeValue.location, rangeValue.length]; } else if (strcmp(objCType, @encode(OFPoint)) == 0 || strcmp(objCType, @encode(const OFPoint)) == 0) { OFPoint pointValue; [self getValue: &pointValue size: sizeof(pointValue)]; return [OFString stringWithFormat: @"", pointValue.x, pointValue.y]; } else if (strcmp(objCType, @encode(OFSize)) == 0 || strcmp(objCType, @encode(const OFSize)) == 0) { OFSize sizeValue; [self getValue: &sizeValue size: sizeof(sizeValue)]; return [OFString stringWithFormat: @"", sizeValue.width, sizeValue.height]; } else if (strcmp(objCType, @encode(OFRect)) == 0 || strcmp(objCType, @encode(const OFRect)) == 0) { OFRect rectValue; [self getValue: &rectValue size: sizeof(rectValue)]; return [OFString stringWithFormat: @"", rectValue.origin.x, rectValue.origin.y, rectValue.size.width, rectValue.size.height]; } else if (strcmp(objCType, @encode(OFVector3D)) == 0 || strcmp(objCType, @encode(const OFVector3D)) == 0) { OFVector3D vector3DValue; [self getValue: &vector3DValue size: sizeof(vector3DValue)]; return [OFString stringWithFormat: @"", vector3DValue.x, vector3DValue.y, vector3DValue.z]; } else if (strcmp(objCType, @encode(OFVector4D)) == 0 || strcmp(objCType, @encode(const OFVector4D)) == 0) { OFVector4D vector4DValue; [self getValue: &vector4DValue size: sizeof(vector4DValue)]; return [OFString stringWithFormat: @"", vector4DValue.x, vector4DValue.y, vector4DValue.z, vector4DValue.w]; } ret = [OFMutableString stringWithString: @" 0) [ret appendString: @" "]; [ret appendFormat: @"%02x", value[i]]; } } @finally { OFFreeMemory(value); } [ret appendString: @">"]; [ret makeImmutable]; return ret; } @end objfw-1.1.6/src/OFWin32ConsoleStdIOStream.h000066400000000000000000000017651465614216400203410ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFStdIOStream.h" OF_ASSUME_NONNULL_BEGIN @interface OFWin32ConsoleStdIOStream: OFStdIOStream { HANDLE _handle; WORD _attributes; OFChar16 _incompleteUTF16Surrogate; char _incompleteUTF8Surrogate[4]; size_t _incompleteUTF8SurrogateLen; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFWindowsRegistryKey.h000066400000000000000000000174041465614216400176660ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFString.h" #include OF_ASSUME_NONNULL_BEGIN @class OFData; /** * @class OFWindowsRegistryKey \ * OFWindowsRegistryKey.h ObjFW/OFWindowsRegistryKey.h */ OF_SUBCLASSING_RESTRICTED @interface OFWindowsRegistryKey: OFObject { HKEY _hKey; bool _close; } /** * @brief Returns the OFWindowsRegistryKey for the HKEY_CLASSES_ROOT key. * * @return The OFWindowsRegistryKey for the HKEY_CLASSES_ROOT key */ + (instancetype)classesRootKey; /** * @brief Returns the OFWindowsRegistryKey for the HKEY_CURRENT_CONFIG key. * * @return The OFWindowsRegistryKey for the HKEY_CURRENT_CONFIG key */ + (instancetype)currentConfigKey; /** * @brief Returns the OFWindowsRegistryKey for the HKEY_CURRENT_USER key. * * @return The OFWindowsRegistryKey for the HKEY_CURRENT_USER key */ + (instancetype)currentUserKey; /** * @brief Returns the OFWindowsRegistryKey for the HKEY_LOCAL_MACHINE key. * * @return The OFWindowsRegistryKey for the HKEY_LOCAL_MACHINE key */ + (instancetype)localMachineKey; /** * @brief Returns the OFWindowsRegistryKey for the HKEY_USERS key. * * @return The OFWindowsRegistryKey for the HKEY_USERS key */ + (instancetype)usersKey; - (instancetype)init OF_UNAVAILABLE; /** * @brief Opens the subkey at the specified path. * * @param path The path of the subkey to open * @param accessRights Please refer to the `RegOpenKeyEx()` documentation for * `samDesired` * @param options Please refer to the `RegOpenKeyEx()` documentation for * `ulOptions`. Usually 0. * @return The subkey with the specified path * @throw OFOpenWindowsRegistryKeyFailedException Opening the key failed */ - (OFWindowsRegistryKey *)openSubkeyAtPath: (OFString *)path accessRights: (REGSAM)accessRights options: (DWORD)options; /** * @brief Creates a subkey at the specified path or opens it if it already * exists. * * @param path The path of the subkey to create * @param accessRights Please refer to the `RegCreateKeyEx()` documentation for * `samDesired` * @param securityAttributes Please refer to the `RegCreateKeyEx()` * documentation for `lpSecurityAttributes`. Usually * NULL. * @param options Please refer to the `RegCreateKeyEx()` documentation for * `dwOptions`. Usually 0. * @param disposition A pointer to a variable that will be set to whether the * key was created or already existed, or `NULL`. Please * refer to the `RegCreateKeyEx()` documentation for * `lpdwDisposition`. * @return The subkey with the specified path * @throw OFCreateWindowsRegistryKeyFailedException Creating the key failed */ - (OFWindowsRegistryKey *) createSubkeyAtPath: (OFString *)path accessRights: (REGSAM)accessRights securityAttributes: (nullable SECURITY_ATTRIBUTES *)securityAttributes options: (DWORD)options disposition: (nullable DWORD *)disposition; /** * @brief Returns the data for the specified value at the specified path. * * @param name The name of the value to return * @param type A pointer to store the type of the value, or NULL * @return The data for the specified value * @throw OFGetWindowsRegistryValueFailedException Getting the value failed */ - (nullable OFData *)dataForValueNamed: (nullable OFString *)name type: (nullable DWORD *)type; /** * @brief Sets the data for the specified value. * * @param data The data to set the value to * @param name The name of the value to set * @param type The type for the value * @throw OFSetWindowsRegistryValueFailedException Setting the value failed */ - (void)setData: (nullable OFData *)data forValueNamed: (nullable OFString *)name type: (DWORD)type; /** * @brief Returns the string for the specified value at the specified path. * * @param name The name of the value to return * @return The string for the specified value * @throw OFGetWindowsRegistryValueFailedException Getting the value failed * @throw OFInvalidEncodingException The encoding of the value is invalid */ - (nullable OFString *)stringForValueNamed: (nullable OFString *)name; /** * @brief Returns the string for the specified value at the specified path. * * @param name The name of the value to return * @param type A pointer to store the type of the value, or NULL * @return The string for the specified value * @throw OFGetWindowsRegistryValueFailedException Getting the value failed * @throw OFInvalidEncodingException The encoding of the value is invalid */ - (nullable OFString *)stringForValueNamed: (nullable OFString *)name type: (nullable DWORD *)type; /** * @brief Sets the string for the specified value. * * @param string The string to set the value to * @param name The name of the value to set * @throw OFSetWindowsRegistryValueFailedException Setting the value failed */ - (void)setString: (nullable OFString *)string forValueNamed: (nullable OFString *)name; /** * @brief Sets the string for the specified value. * * @param string The string to set the value to * @param name The name of the value to set * @param type The type for the value * @throw OFSetWindowsRegistryValueFailedException Setting the value failed */ - (void)setString: (nullable OFString *)string forValueNamed: (nullable OFString *)name type: (DWORD)type; /** * @brief Returns the DWORD for the specified value at the specified path. * * @param name The name of the value to return * @return The DWORD for the specified value * @throw OFGetWindowsRegistryValueFailedException Getting the value failed * @throw OFUndefinedKeyException There is no value with the specified key */ - (uint32_t)DWORDForValueNamed: (nullable OFString *)name; /** * @brief Sets the DWORD for the specified value. * * @param dword The DWORD to set the value to * @param name The name of the value to set * @throw OFSetWindowsRegistryValueFailedException Setting the value failed */ - (void)setDWORD: (uint32_t)dword forValueNamed: (nullable OFString *)name; /** * @brief Returns the QWORD for the specified value at the specified path. * * @param name The name of the value to return * @return The QWORD for the specified value * @throw OFGetWindowsRegistryValueFailedException Getting the value failed * @throw OFUndefinedKeyException There is no value with the specified key */ - (uint64_t)QWORDForValueNamed: (nullable OFString *)name; /** * @brief Sets the QWORD for the specified value. * * @param qword The QWORD to set the value to * @param name The name of the value to set * @throw OFSetWindowsRegistryValueFailedException Setting the value failed */ - (void)setQWORD: (uint64_t)qword forValueNamed: (nullable OFString *)name; /** * @brief Deletes the specified value. * * @param name The value to delete * @throw OFDeleteWindowsRegistryValueFailedException Deleting the value failed */ - (void)deleteValueNamed: (nullable OFString *)name; /** * @brief Deletes the specified subkey. * * @param subkeyPath The path of the subkey to delete * @throw OFDeleteWindowsRegistryKeyFailedException Deleting the key failed */ - (void)deleteSubkeyAtPath: (OFString *)subkeyPath; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFWindowsRegistryKey.m000066400000000000000000000261111465614216400176660ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFWindowsRegistryKey.h" #import "OFData.h" #import "OFLocale.h" #import "OFSystemInfo.h" #include #import "OFCreateWindowsRegistryKeyFailedException.h" #import "OFDeleteWindowsRegistryKeyFailedException.h" #import "OFDeleteWindowsRegistryValueFailedException.h" #import "OFGetWindowsRegistryValueFailedException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFOpenWindowsRegistryKeyFailedException.h" #import "OFOutOfRangeException.h" #import "OFSetWindowsRegistryValueFailedException.h" #import "OFUndefinedKeyException.h" OF_DIRECT_MEMBERS @interface OFWindowsRegistryKey () - (instancetype)of_initWithHKey: (HKEY)hKey close: (bool)close; @end @implementation OFWindowsRegistryKey + (instancetype)classesRootKey { return [[[self alloc] of_initWithHKey: HKEY_CLASSES_ROOT close: false] autorelease]; } + (instancetype)currentConfigKey { return [[[self alloc] of_initWithHKey: HKEY_CURRENT_CONFIG close: false] autorelease]; } + (instancetype)currentUserKey { return [[[self alloc] of_initWithHKey: HKEY_CURRENT_USER close: false] autorelease]; } + (instancetype)localMachineKey { return [[[self alloc] of_initWithHKey: HKEY_LOCAL_MACHINE close: false] autorelease]; } + (instancetype)usersKey { return [[[self alloc] of_initWithHKey: HKEY_USERS close: false] autorelease]; } - (instancetype)of_initWithHKey: (HKEY)hKey close: (bool)close { self = [super init]; _hKey = hKey; _close = close; return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { if (_close) RegCloseKey(_hKey); [super dealloc]; } - (OFWindowsRegistryKey *)openSubkeyAtPath: (OFString *)path accessRights: (REGSAM)accessRights options: (DWORD)options { void *pool = objc_autoreleasePoolPush(); LSTATUS status; HKEY subKey; if ([OFSystemInfo isWindowsNT]) status = RegOpenKeyExW(_hKey, path.UTF16String, options, accessRights, &subKey); else status = RegOpenKeyExA(_hKey, [path cStringWithEncoding: [OFLocale encoding]], options, accessRights, &subKey); if (status != ERROR_SUCCESS) @throw [OFOpenWindowsRegistryKeyFailedException exceptionWithRegistryKey: self path: path accessRights: accessRights options: options status: status]; objc_autoreleasePoolPop(pool); return [[[OFWindowsRegistryKey alloc] of_initWithHKey: subKey close: true] autorelease]; } - (OFWindowsRegistryKey *) createSubkeyAtPath: (OFString *)path accessRights: (REGSAM)accessRights securityAttributes: (LPSECURITY_ATTRIBUTES)securityAttributes options: (DWORD)options disposition: (DWORD *)disposition { void *pool = objc_autoreleasePoolPush(); LSTATUS status; HKEY subKey; if ([OFSystemInfo isWindowsNT]) status = RegCreateKeyExW(_hKey, path.UTF16String, 0, NULL, options, accessRights, securityAttributes, &subKey, NULL); else status = RegCreateKeyExA(_hKey, [path cStringWithEncoding: [OFLocale encoding]], 0, NULL, options, accessRights, securityAttributes, &subKey, NULL); if (status != ERROR_SUCCESS) @throw [OFCreateWindowsRegistryKeyFailedException exceptionWithRegistryKey: self path: path accessRights: accessRights securityAttributes: securityAttributes options: options status: status]; objc_autoreleasePoolPop(pool); return [[[OFWindowsRegistryKey alloc] of_initWithHKey: subKey close: true] autorelease]; } - (OFData *)dataForValueNamed: (OFString *)name type: (DWORD *)type { void *pool = objc_autoreleasePoolPush(); BYTE stackBuffer[256], *buffer = stackBuffer; DWORD length = sizeof(stackBuffer); OFMutableData *ret = nil; bool winNT = [OFSystemInfo isWindowsNT]; LSTATUS status; for (;;) { if (winNT) status = RegQueryValueExW(_hKey, name.UTF16String, NULL, type, buffer, &length); else status = RegQueryValueExA(_hKey, [name cStringWithEncoding: [OFLocale encoding]], NULL, type, buffer, &length); switch (status) { case ERROR_SUCCESS: if (buffer == stackBuffer) { objc_autoreleasePoolPop(pool); return [OFData dataWithItems: buffer count: length]; } else { [ret makeImmutable]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } case ERROR_FILE_NOT_FOUND: objc_autoreleasePoolPop(pool); return nil; case ERROR_MORE_DATA: objc_autoreleasePoolPop(pool); pool = objc_autoreleasePoolPush(); ret = [OFMutableData dataWithCapacity: length]; [ret increaseCountBy: length]; buffer = ret.mutableItems; continue; default: @throw [OFGetWindowsRegistryValueFailedException exceptionWithRegistryKey: self valueName: name status: status]; } } } - (void)setData: (OFData *)data forValueNamed: (OFString *)name type: (DWORD)type { size_t length = data.count * data.itemSize; LSTATUS status; if (length > UINT32_MAX) @throw [OFOutOfRangeException exception]; if ([OFSystemInfo isWindowsNT]) status = RegSetValueExW(_hKey, name.UTF16String, 0, type, data.items, (DWORD)length); else status = RegSetValueExA(_hKey, [name cStringWithEncoding: [OFLocale encoding]], 0, type, data.items, (DWORD)length); if (status != ERROR_SUCCESS) @throw [OFSetWindowsRegistryValueFailedException exceptionWithRegistryKey: self valueName: name data: data type: type status: status]; } - (OFString *)stringForValueNamed: (OFString *)name { return [self stringForValueNamed: name type: NULL]; } - (OFString *)stringForValueNamed: (OFString *)name type: (DWORD *)typeOut { void *pool = objc_autoreleasePoolPush(); DWORD type; OFData *data = [self dataForValueNamed: name type: &type]; OFString *ret; if (data == nil) return nil; if (type != REG_SZ && type != REG_EXPAND_SZ && type != REG_LINK) @throw [OFInvalidEncodingException exception]; if (data.itemSize != 1) @throw [OFInvalidFormatException exception]; if ([OFSystemInfo isWindowsNT]) { const OFChar16 *UTF16String = data.items; size_t length = data.count; if (length % 2 == 1) @throw [OFInvalidFormatException exception]; length /= 2; /* * REG_SZ and REG_EXPAND_SZ contain a \0, but can contain data * after it that should be ignored. */ for (size_t i = 0; i < length; i++) { if (UTF16String[i] == 0) { length = i; break; } } ret = [[OFString alloc] initWithUTF16String: UTF16String length: length]; } else { const char *cString = data.items; size_t length = data.count; /* * REG_SZ and REG_EXPAND_SZ contain a \0, but can contain data * after it that should be ignored. */ for (size_t i = 0; i < length; i++) { if (cString[i] == 0) { length = i; break; } } ret = [[OFString alloc] initWithCString: cString encoding: [OFLocale encoding] length: length]; } if (typeOut != NULL) *typeOut = type; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (void)setString: (OFString *)string forValueNamed: (OFString *)name { [self setString: string forValueNamed: name type: REG_SZ]; } - (void)setString: (OFString *)string forValueNamed: (OFString *)name type: (DWORD)type { void *pool = objc_autoreleasePoolPush(); OFData *data; if ([OFSystemInfo isWindowsNT]) data = [OFData dataWithItems: string.UTF16String count: string.UTF16StringLength + 1 itemSize: sizeof(OFChar16)]; else { OFStringEncoding encoding = [OFLocale encoding]; const char *cString = [string cStringWithEncoding: encoding]; size_t length = [string cStringLengthWithEncoding: encoding]; data = [OFData dataWithItems: cString count: length + 1]; } [self setData: data forValueNamed: name type: type]; objc_autoreleasePoolPop(pool); } - (uint32_t)DWORDForValueNamed: (OFString *)name { void *pool = objc_autoreleasePoolPush(); DWORD type, ret; OFData *data = [self dataForValueNamed: name type: &type]; if (data == nil) @throw [OFUndefinedKeyException exceptionWithObject: self key: name value: nil]; if (type != REG_DWORD) @throw [OFInvalidEncodingException exception]; if (data.count != sizeof(ret) || data.itemSize != 1) @throw [OFInvalidFormatException exception]; memcpy(&ret, data.items, sizeof(ret)); objc_autoreleasePoolPop(pool); return ret; } - (void)setDWORD: (uint32_t)dword forValueNamed: (OFString *)name { void *pool = objc_autoreleasePoolPush(); OFData *data = [OFData dataWithItems: &dword count: sizeof(dword)]; [self setData: data forValueNamed: name type: REG_DWORD]; objc_autoreleasePoolPop(pool); } - (uint64_t)QWORDForValueNamed: (OFString *)name { void *pool = objc_autoreleasePoolPush(); DWORD type; uint64_t ret; OFData *data = [self dataForValueNamed: name type: &type]; if (data == nil) @throw [OFUndefinedKeyException exceptionWithObject: self key: name value: nil]; if (type != REG_QWORD) @throw [OFInvalidEncodingException exception]; if (data.count != sizeof(ret) || data.itemSize != 1) @throw [OFInvalidFormatException exception]; memcpy(&ret, data.items, sizeof(ret)); objc_autoreleasePoolPop(pool); return ret; } - (void)setQWORD: (uint64_t)qword forValueNamed: (OFString *)name { void *pool = objc_autoreleasePoolPush(); OFData *data = [OFData dataWithItems: &qword count: sizeof(qword)]; [self setData: data forValueNamed: name type: REG_QWORD]; objc_autoreleasePoolPop(pool); } - (void)deleteValueNamed: (OFString *)name { void *pool = objc_autoreleasePoolPush(); LSTATUS status; if ([OFSystemInfo isWindowsNT]) status = RegDeleteValueW(_hKey, name.UTF16String); else status = RegDeleteValueA(_hKey, [name cStringWithEncoding: [OFLocale encoding]]); if (status != ERROR_SUCCESS) @throw [OFDeleteWindowsRegistryValueFailedException exceptionWithRegistryKey: self valueName: name status: status]; objc_autoreleasePoolPop(pool); } - (void)deleteSubkeyAtPath: (OFString *)subkeyPath { void *pool = objc_autoreleasePoolPush(); LSTATUS status; if ([OFSystemInfo isWindowsNT]) status = RegDeleteKeyW(_hKey, subkeyPath.UTF16String); else status = RegDeleteKeyA(_hKey, [subkeyPath cStringWithEncoding: [OFLocale encoding]]); if (status != ERROR_SUCCESS) @throw [OFDeleteWindowsRegistryKeyFailedException exceptionWithRegistryKey: self subkeyPath: subkeyPath status: status]; objc_autoreleasePoolPop(pool); } @end objfw-1.1.6/src/OFXMLAttribute.h000066400000000000000000000057651465614216400163650ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFXMLNode.h" OF_ASSUME_NONNULL_BEGIN @class OFString; /** * @class OFXMLAttribute OFXMLAttribute.h ObjFW/OFXMLAttribute.h * * @brief A representation of an attribute of an XML element as an object. */ OF_SUBCLASSING_RESTRICTED @interface OFXMLAttribute: OFXMLNode { #if defined(OF_XML_ELEMENT_M) || defined(OF_XML_PARSER_M) @public #endif OFString *_name, *_Nullable _namespace, *_stringValue; bool _useDoubleQuotes; } /** * @brief The name of the attribute. */ @property (readonly, nonatomic) OFString *name; /** * @brief The namespace of the attribute. */ #ifndef __cplusplus @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *namespace; #else @property OF_NULLABLE_PROPERTY (readonly, nonatomic, getter=namespace) OFString *nameSpace; #endif /** * @brief Creates a new XML attribute. * * @param name The name of the attribute * @param stringValue The string value of the attribute * @return A new autoreleased OFXMLAttribute with the specified parameters */ + (instancetype)attributeWithName: (OFString *)name stringValue: (OFString *)stringValue; /** * @brief Creates a new XML attribute. * * @param name The name of the attribute * @param nameSpace The namespace of the attribute * @param stringValue The string value of the attribute * @return A new autoreleased OFXMLAttribute with the specified parameters */ + (instancetype)attributeWithName: (OFString *)name namespace: (nullable OFString *)nameSpace stringValue: (OFString *)stringValue; /** * @brief Initializes an already allocated OFXMLAttribute. * * @param name The name of the attribute * @param stringValue The string value of the attribute * @return An initialized OFXMLAttribute with the specified parameters */ - (instancetype)initWithName: (OFString *)name stringValue: (OFString *)stringValue; /** * @brief Initializes an already allocated OFXMLAttribute. * * @param name The name of the attribute * @param nameSpace The namespace of the attribute * @param stringValue The string value of the attribute * @return An initialized OFXMLAttribute with the specified parameters */ - (instancetype)initWithName: (OFString *)name namespace: (nullable OFString *)nameSpace stringValue: (OFString *)stringValue OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFXMLAttribute.m000066400000000000000000000060511465614216400163570ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFXMLAttribute.h" #import "OFXMLNode+Private.h" #import "OFString.h" #import "OFDictionary.h" #import "OFInvalidArgumentException.h" @implementation OFXMLAttribute @synthesize name = _name, namespace = _namespace; + (instancetype)attributeWithName: (OFString *)name namespace: (OFString *)namespace stringValue: (OFString *)stringValue { return [[[self alloc] initWithName: name namespace: namespace stringValue: stringValue] autorelease]; } + (instancetype)attributeWithName: (OFString *)name stringValue: (OFString *)stringValue { return [[[self alloc] initWithName: name stringValue: stringValue] autorelease]; } - (instancetype)initWithName: (OFString *)name stringValue: (OFString *)stringValue { return [self initWithName: name namespace: nil stringValue: stringValue]; } - (instancetype)initWithName: (OFString *)name namespace: (OFString *)namespace stringValue: (OFString *)stringValue { self = [super of_init]; @try { _name = [name copy]; _namespace = [namespace copy]; _stringValue = [stringValue copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_name release]; [_namespace release]; [_stringValue release]; [super dealloc]; } - (OFString *)stringValue { return [[_stringValue copy] autorelease]; } - (void)setStringValue: (OFString *)stringValue { OFString *old = _stringValue; _stringValue = [stringValue copy]; [old release]; } - (bool)isEqual: (id)object { OFXMLAttribute *attribute; if (object == self) return true; if (![object isKindOfClass: [OFXMLAttribute class]]) return false; attribute = object; if (![attribute->_name isEqual: _name]) return false; if (attribute->_namespace != _namespace && ![attribute->_namespace isEqual: _namespace]) return false; if (![attribute->_stringValue isEqual: _stringValue]) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddHash(&hash, _namespace.hash); OFHashAddHash(&hash, _stringValue.hash); OFHashFinalize(&hash); return hash; } - (OFString *)description { return [OFString stringWithFormat: @"<%@: name=%@, namespace=%@, " @"stringValue=%@>", self.class, _name, _namespace, _stringValue]; } @end objfw-1.1.6/src/OFXMLCDATA.h000066400000000000000000000026251465614216400152260ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFXMLNode.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFXMLCDATA OFXMLCDATA.h ObjFW/OFXMLCDATA.h * * @brief A class representing XML CDATA. */ OF_SUBCLASSING_RESTRICTED @interface OFXMLCDATA: OFXMLNode { OFString *_CDATA; } /** * @brief Creates a new OFXMLCDATA with the specified string. * * @param string The string value for the CDATA * @return A new OFXMLCDATA */ + (instancetype)CDATAWithString: (OFString *)string; /** * @brief Initializes an already allocated OFXMLCDATA with the specified string. * * @param string The string value for the CDATA * @return An initialized OFXMLCDATA */ - (instancetype)initWithString: (OFString *)string; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFXMLCDATA.m000066400000000000000000000040761465614216400152350ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFXMLCDATA.h" #import "OFXMLNode+Private.h" #import "OFString.h" #import "OFInvalidArgumentException.h" @implementation OFXMLCDATA + (instancetype)CDATAWithString: (OFString *)string { return [[[self alloc] initWithString: string] autorelease]; } - (instancetype)initWithString: (OFString *)string { self = [super of_init]; @try { _CDATA = [string copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_CDATA release]; [super dealloc]; } - (bool)isEqual: (id)object { OFXMLCDATA *CDATA; if (object == self) return true; if (![object isKindOfClass: [OFXMLCDATA class]]) return false; CDATA = object; return ([CDATA->_CDATA isEqual: _CDATA]); } - (unsigned long)hash { return _CDATA.hash; } - (OFString *)stringValue { return [[_CDATA copy] autorelease]; } - (void)setStringValue: (OFString *)stringValue { OFString *old = _CDATA; _CDATA = [stringValue copy]; [old release]; } - (OFString *)XMLString { void *pool = objc_autoreleasePoolPush(); OFString *tmp = [_CDATA stringByReplacingOccurrencesOfString: @"]]>" withString: @"]]>]]>", tmp]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)description { return self.XMLString; } @end objfw-1.1.6/src/OFXMLCharacters.h000066400000000000000000000027331465614216400164710ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFXMLNode.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFXMLCharacters OFXMLCharacters.h ObjFW/OFXMLCharacters.h * * @brief A class representing XML characters. */ OF_SUBCLASSING_RESTRICTED @interface OFXMLCharacters: OFXMLNode { OFString *_characters; } /** * @brief Creates a new OFXMLCharacters with the specified string. * * @param string The string value for the characters * @return A new OFXMLCharacters */ + (instancetype)charactersWithString: (OFString *)string; /** * @brief Initializes an already allocated OFXMLCharacters with the specified * string. * * @param string The string value for the characters * @return An initialized OFXMLCharacters */ - (instancetype)initWithString: (OFString *)string; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFXMLCharacters.m000066400000000000000000000036031465614216400164730ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFXMLCharacters.h" #import "OFXMLNode+Private.h" #import "OFString.h" #import "OFInvalidArgumentException.h" @implementation OFXMLCharacters + (instancetype)charactersWithString: (OFString *)string { return [[[self alloc] initWithString: string] autorelease]; } - (instancetype)initWithString: (OFString *)string { self = [super of_init]; @try { _characters = [string copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_characters release]; [super dealloc]; } - (bool)isEqual: (id)object { OFXMLCharacters *characters; if (object == self) return true; if (![object isKindOfClass: [OFXMLCharacters class]]) return false; characters = object; return ([characters->_characters isEqual: _characters]); } - (unsigned long)hash { return _characters.hash; } - (OFString *)stringValue { return [[_characters copy] autorelease]; } - (void)setStringValue: (OFString *)stringValue { OFString *old = _characters; _characters = [stringValue copy]; [old release]; } - (OFString *)XMLString { return _characters.stringByXMLEscaping; } - (OFString *)description { return self.XMLString; } @end objfw-1.1.6/src/OFXMLComment.h000066400000000000000000000027531465614216400160160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFXMLNode.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFXMLComment OFXMLComment.h ObjFW/OFXMLComment.h * * @brief A class for representing XML comments. */ OF_SUBCLASSING_RESTRICTED @interface OFXMLComment: OFXMLNode { OFString *_text; } /** * @brief The comment text. */ @property (readonly, nonatomic) OFString *text; /** * @brief Creates a new OFXMLComment with the specified text. * * @param text The text for the comment * @return A new OFXMLComment */ + (instancetype)commentWithText: (OFString *)text; /** * @brief Initializes an already allocated OFXMLComment with the specified * text. * * @param text The text for the comment * @return An initialized OFXMLComment */ - (instancetype)initWithText: (OFString *)text; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFXMLComment.m000066400000000000000000000033351465614216400160200ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFXMLComment.h" #import "OFXMLNode+Private.h" #import "OFString.h" #import "OFInvalidArgumentException.h" @implementation OFXMLComment @synthesize text = _text; + (instancetype)commentWithText: (OFString *)text { return [[[self alloc] initWithText: text] autorelease]; } - (instancetype)initWithText: (OFString *)text { self = [super of_init]; @try { _text = [text copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_text release]; [super dealloc]; } - (bool)isEqual: (id)object { OFXMLComment *comment; if (object == self) return true; if (![object isKindOfClass: [OFXMLComment class]]) return false; comment = object; return ([comment->_text isEqual: _text]); } - (unsigned long)hash { return _text.hash; } - (OFString *)stringValue { return @""; } - (OFString *)XMLString { return [OFString stringWithFormat: @"", _text]; } - (OFString *)description { return self.XMLString; } @end objfw-1.1.6/src/OFXMLElement.h000066400000000000000000000335631465614216400160100ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFXMLNode.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFMutableArray OF_GENERIC(ObjectType); @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); @class OFMutableString; @class OFStream; @class OFString; @class OFXMLAttribute; /** * @class OFXMLElement OFXMLElement.h ObjFW/OFXMLElement.h * * @brief A class which stores an XML element. */ @interface OFXMLElement: OFXMLNode { OFString *_name, *_Nullable _namespace; OFMutableArray OF_GENERIC(OFXMLAttribute *) *_Nullable _attributes; OFMutableDictionary OF_GENERIC(OFString *, OFString *) *_Nullable _namespaces; OFMutableArray OF_GENERIC(OFXMLNode *) *_Nullable _children; OF_RESERVE_IVARS(OFXMLElement, 4) } /** * @brief The name of the element. */ @property (copy, nonatomic) OFString *name; /** * @brief The namespace of the element. */ #ifndef __cplusplus @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *namespace; #else @property OF_NULLABLE_PROPERTY (copy, nonatomic, getter=namespace, setter=setNamespace:) OFString *nameSpace; #endif /** * @brief An array with the attributes of the element. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFArray OF_GENERIC(OFXMLAttribute *) *attributes; /** * @brief An array of @ref OFXMLNode with all children of the element. */ @property OF_NULLABLE_PROPERTY (nonatomic, copy) OFArray OF_GENERIC(OFXMLNode *) *children; /** * @brief All children that are elements. */ @property (readonly, nonatomic) OFArray OF_GENERIC(OFXMLElement *) *elements; /** * @brief Creates a new XML element with the specified name. * * @param name The name for the element * @return A new autoreleased OFXMLElement with the specified element name */ + (instancetype)elementWithName: (OFString *)name; /** * @brief Creates a new XML element with the specified name and string value. * * @param name The name for the element * @param stringValue The value for the element * @return A new autoreleased OFXMLElement with the specified element name and * value */ + (instancetype)elementWithName: (OFString *)name stringValue: (nullable OFString *)stringValue; /** * @brief Creates a new XML element with the specified name and namespace. * * @param name The name for the element * @param nameSpace The namespace for the element * @return A new autoreleased OFXMLElement with the specified element name and * namespace */ + (instancetype)elementWithName: (OFString *)name namespace: (nullable OFString *)nameSpace; /** * @brief Creates a new XML element with the specified name, namespace and * string value. * * @param name The name for the element * @param nameSpace The namespace for the element * @param stringValue The value for the element * @return A new autoreleased OFXMLElement with the specified element name, * namespace and value */ + (instancetype)elementWithName: (OFString *)name namespace: (nullable OFString *)nameSpace stringValue: (nullable OFString *)stringValue; /** * @brief Parses the string and returns an OFXMLElement for it. * * @param string The string to parse * @return A new autoreleased OFXMLElement with the contents of the string * @throw OFMalformedXMLException The XML was malformed * @throw OFUnboundPrefixException A prefix was used that was not bound to any * namespace * @throw OFInvalidEncodingException The XML is not in the encoding it specified */ + (instancetype)elementWithXMLString: (OFString *)string; /** * @brief Parses the specified stream and returns an OFXMLElement for it. * * @param stream The stream to parse * @return A new autoreleased OFXMLElement with the contents of the specified * stream * @throw OFMalformedXMLException The XML was malformed * @throw OFUnboundPrefixException A prefix was used that was not bound to any * namespace * @throw OFInvalidEncodingException The XML is not in the encoding it specified */ + (instancetype)elementWithStream: (OFStream *)stream; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFXMLElement with the specified name. * * @param name The name for the element * @return An initialized OFXMLElement with the specified element name */ - (instancetype)initWithName: (OFString *)name; /** * @brief Initializes an already allocated OFXMLElement with the specified name * and string value. * * @param name The name for the element * @param stringValue The value for the element * @return An initialized OFXMLElement with the specified element name and * value */ - (instancetype)initWithName: (OFString *)name stringValue: (nullable OFString *)stringValue; /** * @brief Initializes an already allocated OFXMLElement with the specified name * and namespace. * * @param name The name for the element * @param nameSpace The namespace for the element * @return An initialized OFXMLElement with the specified element name and * namespace */ - (instancetype)initWithName: (OFString *)name namespace: (nullable OFString *)nameSpace OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated OFXMLElement with the specified name, * namespace and value. * * @param name The name for the element * @param nameSpace The namespace for the element * @param stringValue The value for the element * @return An initialized OFXMLElement with the specified element name, * namespace and value */ - (instancetype)initWithName: (OFString *)name namespace: (nullable OFString *)nameSpace stringValue: (nullable OFString *)stringValue; /** * @brief Parses the string and initializes an already allocated OFXMLElement * with it. * * @param string The string to parse * @return An initialized OFXMLElement with the contents of the string * @throw OFMalformedXMLException The XML was malformed * @throw OFUnboundPrefixException A prefix was used that was not bound to any * namespace * @throw OFInvalidEncodingException The XML is not in the encoding it specified */ - (instancetype)initWithXMLString: (OFString *)string; /** * @brief Parses the specified stream and initializes an already allocated * OFXMLElement with it. * * @param stream The stream to parse * @return An initialized OFXMLElement with the contents of the specified stream * @throw OFMalformedXMLException The XML was malformed * @throw OFUnboundPrefixException A prefix was used that was not bound to any * namespace * @throw OFInvalidEncodingException The XML is not in the encoding it specified */ - (instancetype)initWithStream: (OFStream *)stream; /** * @brief Sets a prefix for a namespace. * * @param prefix The prefix for the namespace * @param nameSpace The namespace for which the prefix is set */ - (void)setPrefix: (OFString *)prefix forNamespace: (OFString *)nameSpace; /** * @brief Binds a prefix for a namespace. * * @param prefix The prefix for the namespace * @param nameSpace The namespace for which the prefix is bound */ - (void)bindPrefix: (OFString *)prefix forNamespace: (OFString *)nameSpace; /** * @brief Adds the specified attribute. * * If an attribute with the same name and namespace already exists, it is not * added. * * @param attribute The attribute to add */ - (void)addAttribute: (OFXMLAttribute *)attribute; /** * @brief Adds the specified attribute with the specified string value. * * If an attribute with the same name and namespace already exists, it is not * added. * * @param name The name of the attribute * @param stringValue The value of the attribute */ - (void)addAttributeWithName: (OFString *)name stringValue: (OFString *)stringValue; /** * @brief Adds the specified attribute with the specified namespace and string * value. * * If an attribute with the same name and namespace already exists, it is not * added. * * @param name The name of the attribute * @param nameSpace The namespace of the attribute * @param stringValue The value of the attribute */ - (void)addAttributeWithName: (OFString *)name namespace: (nullable OFString *)nameSpace stringValue: (OFString *)stringValue; /** * @brief Returns the attribute with the specified name. * * @param attributeName The name of the attribute * @return The attribute with the specified name */ - (nullable OFXMLAttribute *)attributeForName: (OFString *)attributeName; /** * @brief Returns the attribute with the specified name and namespace. * * @param attributeName The name of the attribute * @param attributeNS The namespace of the attribute * @return The attribute with the specified name and namespace */ - (nullable OFXMLAttribute *)attributeForName: (OFString *)attributeName namespace: (nullable OFString *)attributeNS; /** * @brief Removes the attribute with the specified name. * * @param attributeName The name of the attribute */ - (void)removeAttributeForName: (OFString *)attributeName; /** * @brief Removes the attribute with the specified name and namespace. * * @param attributeName The name of the attribute * @param attributeNS The namespace of the attribute */ - (void)removeAttributeForName: (OFString *)attributeName namespace: (nullable OFString *)attributeNS; /** * @brief Adds a child to the OFXMLElement. * * @param child An OFXMLNode which is added as a child */ - (void)addChild: (OFXMLNode *)child; /** * @brief Inserts a child at the specified index. * * @param child An OFXMLNode which is added as a child * @param index The index where the child is added */ - (void)insertChild: (OFXMLNode *)child atIndex: (size_t)index; /** * @brief Inserts the specified children at the specified index. * * @param children An array of @ref OFXMLNode which are added as children * @param index The index where the child is added */ - (void)insertChildren: (OFArray OF_GENERIC(OFXMLNode *) *)children atIndex: (size_t)index; /** * @brief Removes the first child that is equal to the specified OFXMLNode. * * @param child The child to remove from the OFXMLElement */ - (void)removeChild: (OFXMLNode *)child; /** * @brief Removes the child at the specified index. * * @param index The index of the child to remove */ - (void)removeChildAtIndex: (size_t)index; /** * @brief Replaces the first child that is equal to the specified OFXMLNode * with the specified node. * * @param child The child to replace * @param node The node to replace the child with */ - (void)replaceChild: (OFXMLNode *)child withNode: (OFXMLNode *)node; /** * @brief Replaces the child at the specified index with the specified node. * * @param index The index of the child to replace * @param node The node to replace the child with */ - (void)replaceChildAtIndex: (size_t)index withNode: (OFXMLNode *)node; /** * @brief Returns all children that have the specified namespace. * * @return All children that have the specified namespace */ - (OFArray OF_GENERIC(OFXMLElement *) *) elementsForNamespace: (nullable OFString *)elementNS; /** * @brief Returns the first child element with the specified name. * * @param elementName The name of the element * @return The first child element with the specified name */ - (nullable OFXMLElement *)elementForName: (OFString *)elementName; /** * @brief Returns the child elements with the specified name. * * @param elementName The name of the elements * @return The child elements with the specified name */ - (OFArray OF_GENERIC(OFXMLElement *) *) elementsForName: (OFString *)elementName; /** * @brief Returns the first child element with the specified name and namespace. * * @param elementName The name of the element * @param elementNS The namespace of the element * @return The first child element with the specified name and namespace */ - (nullable OFXMLElement *)elementForName: (OFString *)elementName namespace: (nullable OFString *)elementNS; /** * @brief Returns the child elements with the specified name and namespace. * * @param elementName The name of the elements * @param elementNS The namespace of the elements * @return The child elements with the specified name and namespace */ - (OFArray OF_GENERIC(OFXMLElement *) *) elementsForName: (OFString *)elementName namespace: (nullable OFString *)elementNS; /** * @brief Returns an OFString representing the OFXMLElement as an XML string * with the specified indentation per level. * * @param indentation The indentation per level * @return An OFString representing the OFXMLNode as an XML string with * indentation * @throw OFUnboundNamespaceException The node uses a namespace that was not * bound to a prefix in a context where it * needs a prefix */ - (OFString *)XMLStringWithIndentation: (unsigned int)indentation; /** * @brief Returns an OFString representing the OFXMLElement as an XML string * with the specified default namespace and indentation per level. * * @param defaultNS The default namespace * @param indentation The indentation per level * @return An OFString representing the OFXMLNode as an XML string with * indentation * @throw OFUnboundNamespaceException The node uses a namespace that was not * bound to a prefix in a context where it * needs a prefix */ - (OFString *)XMLStringWithDefaultNamespace: (OFString *)defaultNS indentation: (unsigned int)indentation; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFXMLElement.m000066400000000000000000000506641465614216400160160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #define OF_XML_ELEMENT_M #include #include #import "OFXMLElement.h" #import "OFArray.h" #import "OFData.h" #import "OFDictionary.h" #import "OFStream.h" #import "OFString.h" #import "OFXMLAttribute.h" #import "OFXMLCDATA.h" #import "OFXMLCharacters.h" #import "OFXMLElementBuilder.h" #import "OFXMLNode+Private.h" #import "OFXMLParser.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFMalformedXMLException.h" #import "OFUnboundNamespaceException.h" @interface OFXMLElementElementBuilderDelegate: OFObject { @public OFXMLElement *_element; } @end @implementation OFXMLElementElementBuilderDelegate - (void)elementBuilder: (OFXMLElementBuilder *)builder didBuildElement: (OFXMLElement *)element { if (_element == nil) _element = [element retain]; } - (void)dealloc { [_element release]; [super dealloc]; } @end @implementation OFXMLElement @synthesize name = _name, namespace = _namespace; + (instancetype)elementWithName: (OFString *)name { return [[[self alloc] initWithName: name] autorelease]; } + (instancetype)elementWithName: (OFString *)name stringValue: (OFString *)stringValue { return [[[self alloc] initWithName: name stringValue: stringValue] autorelease]; } + (instancetype)elementWithName: (OFString *)name namespace: (OFString *)namespace { return [[[self alloc] initWithName: name namespace: namespace] autorelease]; } + (instancetype)elementWithName: (OFString *)name namespace: (OFString *)namespace stringValue: (OFString *)stringValue { return [[[self alloc] initWithName: name namespace: namespace stringValue: stringValue] autorelease]; } + (instancetype)elementWithXMLString: (OFString *)string { return [[[self alloc] initWithXMLString: string] autorelease]; } + (instancetype)elementWithStream: (OFStream *)stream { return [[[self alloc] initWithStream: stream] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name { return [self initWithName: name namespace: nil stringValue: nil]; } - (instancetype)initWithName: (OFString *)name stringValue: (OFString *)stringValue { return [self initWithName: name namespace: nil stringValue: stringValue]; } - (instancetype)initWithName: (OFString *)name namespace: (OFString *)namespace { self = [super of_init]; @try { if (name == nil) @throw [OFInvalidArgumentException exception]; _name = [name copy]; _namespace = [namespace copy]; _namespaces = [[OFMutableDictionary alloc] initWithKeysAndObjects: @"http://www.w3.org/XML/1998/namespace", @"xml", @"http://www.w3.org/2000/xmlns/", @"xmlns", nil]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithName: (OFString *)name namespace: (OFString *)namespace stringValue: (OFString *)stringValue { self = [self initWithName: name namespace: namespace]; @try { if (stringValue != nil) self.stringValue = stringValue; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithXMLString: (OFString *)string { void *pool; OFXMLElement *element; @try { OFXMLParser *parser; OFXMLElementBuilder *builder; OFXMLElementElementBuilderDelegate *delegate; if (string == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); parser = [OFXMLParser parser]; builder = [OFXMLElementBuilder builder]; delegate = [[[OFXMLElementElementBuilderDelegate alloc] init] autorelease]; parser.delegate = builder; builder.delegate = delegate; [parser parseString: string]; if (!parser.hasFinishedParsing) @throw [OFMalformedXMLException exceptionWithParser: parser]; element = delegate->_element; } @catch (id e) { [self release]; @throw e; } self = [self initWithName: element->_name namespace: element->_namespace]; @try { [_attributes release]; _attributes = [element->_attributes retain]; [_namespaces release]; _namespaces = [element->_namespaces retain]; [_children release]; _children = [element->_children retain]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithStream: (OFStream *)stream { void *pool; OFXMLElement *element; @try { OFXMLParser *parser; OFXMLElementBuilder *builder; OFXMLElementElementBuilderDelegate *delegate; pool = objc_autoreleasePoolPush(); parser = [OFXMLParser parser]; builder = [OFXMLElementBuilder builder]; delegate = [[[OFXMLElementElementBuilderDelegate alloc] init] autorelease]; parser.delegate = builder; builder.delegate = delegate; [parser parseStream: stream]; if (!parser.hasFinishedParsing) @throw [OFMalformedXMLException exceptionWithParser: parser]; element = delegate->_element; } @catch (id e) { [self release]; @throw e; } self = [self initWithName: element->_name namespace: element->_namespace]; @try { [_attributes release]; _attributes = [element->_attributes retain]; [_namespaces release]; _namespaces = [element->_namespaces retain]; [_children release]; _children = [element->_children retain]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_name release]; [_namespace release]; [_attributes release]; [_namespaces release]; [_children release]; [super dealloc]; } - (OFArray *)attributes { return [[_attributes copy] autorelease]; } - (void)setChildren: (OFArray *)children { OFArray *old = _children; _children = [children mutableCopy]; [old release]; } - (OFArray *)children { return [[_children copy] autorelease]; } - (void)setStringValue: (OFString *)stringValue { void *pool = objc_autoreleasePoolPush(); self.children = [OFArray arrayWithObject: [OFXMLCharacters charactersWithString: stringValue]]; objc_autoreleasePoolPop(pool); } - (OFString *)stringValue { OFMutableString *ret; if (_children.count == 0) return @""; ret = [OFMutableString string]; for (OFXMLNode *child in _children) { void *pool = objc_autoreleasePoolPush(); [ret appendString: child.stringValue]; objc_autoreleasePoolPop(pool); } [ret makeImmutable]; return ret; } - (OFString *)of_XMLStringWithDefaultNS: (OFString *)defaultNS namespaces: (OFDictionary *)allNS indentation: (unsigned int)indentation level: (unsigned int)level OF_DIRECT { void *pool; char *cString; size_t length, i; OFString *prefix, *ret; pool = objc_autoreleasePoolPush(); /* Add the namespaces of the current element */ if (allNS != nil) { OFEnumerator *keyEnumerator = [_namespaces keyEnumerator]; OFEnumerator *objectEnumerator = [_namespaces objectEnumerator]; OFMutableDictionary *tmp; OFString *key, *object; tmp = [[allNS mutableCopy] autorelease]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) [tmp setObject: object forKey: key]; allNS = tmp; } else allNS = _namespaces; prefix = [allNS objectForKey: (_namespace != nil ? _namespace : (OFString *)@"")]; i = 0; length = _name.UTF8StringLength + 3 + (level * indentation); cString = OFAllocMemory(length, 1); @try { memset(cString + i, ' ', level * indentation); i += level * indentation; /* Start of tag */ cString[i++] = '<'; if (prefix.length > 0) { length += prefix.UTF8StringLength + 1; cString = OFResizeMemory(cString, length, 1); memcpy(cString + i, prefix.UTF8String, prefix.UTF8StringLength); i += prefix.UTF8StringLength; cString[i++] = ':'; } memcpy(cString + i, _name.UTF8String, _name.UTF8StringLength); i += _name.UTF8StringLength; /* xmlns if necessary */ if (prefix.length == 0 && defaultNS != _namespace && ![defaultNS isEqual: _namespace]) { length += _namespace.UTF8StringLength + 9; cString = OFResizeMemory(cString, length, 1); memcpy(cString + i, " xmlns='", 8); i += 8; memcpy(cString + i, _namespace.UTF8String, _namespace.UTF8StringLength); i += _namespace.UTF8StringLength; cString[i++] = '\''; defaultNS = _namespace; } /* Attributes */ for (OFXMLAttribute *attribute in _attributes) { void *pool2 = objc_autoreleasePoolPush(); const char *attributeNameCString = attribute->_name.UTF8String; size_t attributeNameLength = attribute->_name.UTF8StringLength; OFString *attributePrefix = nil; OFString *tmp = attribute.stringValue.stringByXMLEscaping; char delimiter = (attribute->_useDoubleQuotes ? '"' : '\''); if (attribute->_namespace != nil && [(attributePrefix = [allNS objectForKey: attribute->_namespace]) length] == 0) @throw [OFUnboundNamespaceException exceptionWithNamespace: attribute.namespace element: self]; length += attributeNameLength + (attributePrefix != nil ? attributePrefix.UTF8StringLength + 1 : 0) + tmp.UTF8StringLength + 4; cString = OFResizeMemory(cString, length, 1); cString[i++] = ' '; if (attributePrefix != nil) { memcpy(cString + i, attributePrefix.UTF8String, attributePrefix.UTF8StringLength); i += attributePrefix.UTF8StringLength; cString[i++] = ':'; } memcpy(cString + i, attributeNameCString, attributeNameLength); i += attributeNameLength; cString[i++] = '='; cString[i++] = delimiter; memcpy(cString + i, tmp.UTF8String, tmp.UTF8StringLength); i += tmp.UTF8StringLength; cString[i++] = delimiter; objc_autoreleasePoolPop(pool2); } /* Children */ if (_children != nil) { OFMutableData *tmp = [OFMutableData data]; bool indent; if (indentation > 0) { indent = true; for (OFXMLNode *child in _children) { if ([child isKindOfClass: [OFXMLCharacters class]] || [child isKindOfClass: [OFXMLCDATA class]]) { indent = false; break; } } } else indent = false; for (OFXMLNode *child in _children) { OFString *childString; unsigned int ind = (indent ? indentation : 0); if (ind) [tmp addItem: "\n"]; if ([child isKindOfClass: [OFXMLElement class]]) childString = [(OFXMLElement *)child of_XMLStringWithDefaultNS: defaultNS namespaces: allNS indentation: ind level: level + 1]; else { childString = child.XMLString; for (unsigned int j = 0; j < ind * (level + 1); j++) [tmp addItem: " "]; } [tmp addItems: childString.UTF8String count: childString.UTF8StringLength]; } if (indent) [tmp addItem: "\n"]; length += tmp.count + _name.UTF8StringLength + 2 + (indent ? level * indentation : 0); cString = OFResizeMemory(cString, length, 1); cString[i++] = '>'; memcpy(cString + i, tmp.items, tmp.count); i += tmp.count; if (indent) { memset(cString + i, ' ', level * indentation); i += level * indentation; } cString[i++] = '<'; cString[i++] = '/'; if (prefix.length > 0) { length += prefix.UTF8StringLength + 1; cString = OFResizeMemory(cString, length, 1); memcpy(cString + i, prefix.UTF8String, prefix.UTF8StringLength); i += prefix.UTF8StringLength; cString[i++] = ':'; } memcpy(cString + i, _name.UTF8String, _name.UTF8StringLength); i += _name.UTF8StringLength; } else cString[i++] = '/'; cString[i++] = '>'; OFAssert(i == length); objc_autoreleasePoolPop(pool); ret = [OFString stringWithUTF8String: cString length: length]; } @finally { OFFreeMemory(cString); } return ret; } - (OFString *)XMLString { return [self of_XMLStringWithDefaultNS: nil namespaces: nil indentation: 0 level: 0]; } - (OFString *)XMLStringWithIndentation: (unsigned int)indentation { return [self of_XMLStringWithDefaultNS: nil namespaces: nil indentation: indentation level: 0]; } - (OFString *)XMLStringWithDefaultNamespace: (OFString *)defaultNS indentation: (unsigned int)indentation { return [self of_XMLStringWithDefaultNS: defaultNS namespaces: nil indentation: indentation level: 0]; } - (void)addAttribute: (OFXMLAttribute *)attribute { if (![attribute isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exception]; if (_attributes == nil) _attributes = [[OFMutableArray alloc] init]; if ([self attributeForName: attribute->_name namespace: attribute->_namespace] == nil) [_attributes addObject: attribute]; } - (void)addAttributeWithName: (OFString *)name stringValue: (OFString *)stringValue { [self addAttributeWithName: name namespace: nil stringValue: stringValue]; } - (void)addAttributeWithName: (OFString *)name namespace: (OFString *)namespace stringValue: (OFString *)stringValue { void *pool = objc_autoreleasePoolPush(); [self addAttribute: [OFXMLAttribute attributeWithName: name namespace: namespace stringValue: stringValue]]; objc_autoreleasePoolPop(pool); } - (OFXMLAttribute *)attributeForName: (OFString *)attributeName { for (OFXMLAttribute *attribute in _attributes) if (attribute->_namespace == nil && [attribute->_name isEqual: attributeName]) return attribute; return nil; } - (OFXMLAttribute *)attributeForName: (OFString *)attributeName namespace: (OFString *)attributeNS { if (attributeNS == nil) return [self attributeForName: attributeName]; for (OFXMLAttribute *attribute in _attributes) if ([attribute->_namespace isEqual: attributeNS] && [attribute->_name isEqual: attributeName]) return attribute; return nil; } - (void)removeAttributeForName: (OFString *)attributeName { OFXMLAttribute *const *objects = _attributes.objects; size_t count = _attributes.count; for (size_t i = 0; i < count; i++) { if (objects[i]->_namespace == nil && [objects[i]->_name isEqual: attributeName]) { [_attributes removeObjectAtIndex: i]; return; } } } - (void)removeAttributeForName: (OFString *)attributeName namespace: (OFString *)attributeNS { OFXMLAttribute *const *objects; size_t count; if (attributeNS == nil) { [self removeAttributeForName: attributeName]; return; } objects = _attributes.objects; count = _attributes.count; for (size_t i = 0; i < count; i++) { if ([objects[i]->_namespace isEqual: attributeNS] && [objects[i]->_name isEqual: attributeName]) { [_attributes removeObjectAtIndex: i]; return; } } } - (void)setPrefix: (OFString *)prefix forNamespace: (OFString *)namespace { if (prefix.length == 0) @throw [OFInvalidArgumentException exception]; [_namespaces setObject: prefix forKey: namespace]; } - (void)bindPrefix: (OFString *)prefix forNamespace: (OFString *)namespace { [self setPrefix: prefix forNamespace: namespace]; [self addAttributeWithName: prefix namespace: @"http://www.w3.org/2000/xmlns/" stringValue: namespace]; } - (void)addChild: (OFXMLNode *)child { if ([child isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exception]; if (_children == nil) _children = [[OFMutableArray alloc] init]; [_children addObject: child]; } - (void)insertChild: (OFXMLNode *)child atIndex: (size_t)idx { if ([child isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exception]; if (_children == nil) _children = [[OFMutableArray alloc] init]; [_children insertObject: child atIndex: idx]; } - (void)insertChildren: (OFArray *)children atIndex: (size_t)idx { for (OFXMLNode *node in children) if ([node isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exception]; [_children insertObjectsFromArray: children atIndex: idx]; } - (void)removeChild: (OFXMLNode *)child { if ([child isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exception]; [_children removeObject: child]; } - (void)removeChildAtIndex: (size_t)idx { [_children removeObjectAtIndex: idx]; } - (void)replaceChild: (OFXMLNode *)child withNode: (OFXMLNode *)node { if ([node isKindOfClass: [OFXMLAttribute class]] || [child isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exception]; [_children replaceObject: child withObject: node]; } - (void)replaceChildAtIndex: (size_t)idx withNode: (OFXMLNode *)node { if ([node isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exception]; [_children replaceObjectAtIndex: idx withObject: node]; } - (OFXMLElement *)elementForName: (OFString *)elementName { return [self elementsForName: elementName].firstObject; } - (OFXMLElement *)elementForName: (OFString *)elementName namespace: (OFString *)elementNS { return [self elementsForName: elementName namespace: elementNS].firstObject; } - (OFArray *)elements { OFMutableArray OF_GENERIC(OFXMLElement *) *ret = [OFMutableArray array]; for (OFXMLNode *child in _children) if ([child isKindOfClass: [OFXMLElement class]]) [ret addObject: (OFXMLElement *)child]; [ret makeImmutable]; return ret; } - (OFArray *)elementsForName: (OFString *)elementName { OFMutableArray OF_GENERIC(OFXMLElement *) *ret = [OFMutableArray array]; for (OFXMLNode *child in _children) { if ([child isKindOfClass: [OFXMLElement class]]) { OFXMLElement *element = (OFXMLElement *)child; if (element->_namespace == nil && [element->_name isEqual: elementName]) [ret addObject: element]; } } [ret makeImmutable]; return ret; } - (OFArray *)elementsForNamespace: (OFString *)elementNS { OFMutableArray OF_GENERIC(OFXMLElement *) *ret = [OFMutableArray array]; for (OFXMLNode *child in _children) { if ([child isKindOfClass: [OFXMLElement class]]) { OFXMLElement *element = (OFXMLElement *)child; if (element->_name != nil && [element->_namespace isEqual: elementNS]) [ret addObject: element]; } } [ret makeImmutable]; return ret; } - (OFArray *)elementsForName: (OFString *)elementName namespace: (OFString *)elementNS { OFMutableArray OF_GENERIC(OFXMLElement *) *ret; if (elementNS == nil) return [self elementsForName: elementName]; ret = [OFMutableArray array]; for (OFXMLNode *child in _children) { if ([child isKindOfClass: [OFXMLElement class]]) { OFXMLElement *element = (OFXMLElement *)child; if ([element->_namespace isEqual: elementNS] && [element->_name isEqual: elementName]) [ret addObject: element]; } } [ret makeImmutable]; return ret; } - (bool)isEqual: (id)object { OFXMLElement *element; if (object == self) return true; if (![object isKindOfClass: [OFXMLElement class]]) return false; element = object; if (element->_name != _name && ![element->_name isEqual: _name]) return false; if (element->_namespace != _namespace && ![element->_namespace isEqual: _namespace]) return false; if (element->_attributes != _attributes && ![element->_attributes isEqual: _attributes]) return false; if (element->_namespaces != _namespaces && ![element->_namespaces isEqual: _namespaces]) return false; if (element->_children != _children && ![element->_children isEqual: _children]) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddHash(&hash, _namespace.hash); OFHashAddHash(&hash, _attributes.hash); OFHashAddHash(&hash, _namespaces.hash); OFHashAddHash(&hash, _children.hash); OFHashFinalize(&hash); return hash; } - (id)copy { OFXMLElement *copy = [[OFXMLElement alloc] of_init]; @try { copy->_name = [_name copy]; copy->_namespace = [_namespace copy]; copy->_attributes = [_attributes mutableCopy]; copy->_namespaces = [_namespaces mutableCopy]; copy->_children = [_children mutableCopy]; } @catch (id e) { [copy release]; @throw e; } return copy; } @end objfw-1.1.6/src/OFXMLElementBuilder.h000066400000000000000000000105021465614216400173030ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFXMLParser.h" OF_ASSUME_NONNULL_BEGIN @class OFMutableArray OF_GENERIC(ObjectType); @class OFXMLElement; @class OFXMLElementBuilder; /** * @protocol OFXMLElementBuilderDelegate * OFXMLElementBuilder.h ObjFW/OFXMLElementBuilder.h * * @brief A protocol that needs to be implemented by delegates for * OFXMLElementBuilder. */ @protocol OFXMLElementBuilderDelegate /** * @brief This callback is called when the OFXMLElementBuilder built an element. * * If the OFXMLElementBuilder was used as a delegate for the OFXMLParser since * parsing started, this will return the complete document as an OFXMLElement * with all children. * * @param builder The builder which built an OFXMLElement * @param element The OFXMLElement the OFXMLElementBuilder built */ - (void)elementBuilder: (OFXMLElementBuilder *)builder didBuildElement: (OFXMLElement *)element; @optional /** * @brief This callback is called when the OFXMLElementBuilder built an * OFXMLNode which is not inside an element. * * This is usually called for comments or whitespace character data before the * root element. * * @param builder The builder which built the OFXMLNode without parent * @param node The OFXMLNode the OFXMLElementBuilder built */ - (void)elementBuilder: (OFXMLElementBuilder *)builder didBuildOrphanNode: (OFXMLNode *)node; /** * @brief This callback is called when the OFXMLElementBuilder gets a close tag * which does not belong there. * * Most likely, the OFXMLElementBuilder was used to build XML only of a child * of the root element and the root element was closed. Often the delegate is * set to the OFXMLElementBuilder when a certain element is found, this can be * used then to set the delegate back after that certain element has been * closed. * * If this method is not implemented in the delegate, the default is to throw * an OFMalformedXMLException. * * @param builder The builder which did not expect the close tag * @param name The name of the close tag * @param prefix The prefix of the close tag * @param nameSpace The namespace of the close tag */ - (void)elementBuilder: (OFXMLElementBuilder *)builder didNotExpectCloseTag: (OFString *)name prefix: (nullable OFString *)prefix namespace: (nullable OFString *)nameSpace; /** * @brief This callback is called when the XML parser for the element builder * found an unknown entity. * * @param builder The element builder which found an unknown entity * @param entity The name of the entity * @return The substitution for the entity */ - (OFString *)elementBuilder: (OFXMLElementBuilder *)builder foundUnknownEntityNamed: (OFString *)entity; @end /** * @class OFXMLElementBuilder OFXMLElementBuilder.h ObjFW/OFXMLElementBuilder.h * * @brief A class implementing the OFXMLParserDelegate protocol that can build * OFXMLElements from the document parsed by the OFXMLParser. * * It can also be used to build OFXMLElements from parts of the document by * first parsing stuff using the OFXMLParser with another delegate and then * setting the OFXMLElementBuilder as delegate for the parser. */ OF_SUBCLASSING_RESTRICTED @interface OFXMLElementBuilder: OFObject { OFMutableArray OF_GENERIC(OFXMLElement *) *_stack; id _Nullable _delegate; } /** * @brief The delegate for the OFXMLElementBuilder. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id delegate; /** * @brief Creates a new element builder. * * @return A new, autoreleased OFXMLElementBuilder */ + (instancetype)builder; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFXMLElementBuilder.m000066400000000000000000000111411465614216400173100ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFXMLElementBuilder.h" #import "OFArray.h" #import "OFXMLAttribute.h" #import "OFXMLCDATA.h" #import "OFXMLCharacters.h" #import "OFXMLComment.h" #import "OFXMLElement.h" #import "OFXMLParser.h" #import "OFXMLProcessingInstruction.h" #import "OFMalformedXMLException.h" @implementation OFXMLElementBuilder @synthesize delegate = _delegate; + (instancetype)builder { return [[[self alloc] init] autorelease]; } - (instancetype)init { self = [super init]; @try { _stack = [[OFMutableArray alloc] init]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_stack release]; [super dealloc]; } - (void)parser: (OFXMLParser *)parser foundProcessingInstructionWithTarget: (OFString *)target text: (OFString *)text { OFXMLProcessingInstruction *node = [OFXMLProcessingInstruction processingInstructionWithTarget: target text: text]; OFXMLElement *parent = _stack.lastObject; if (parent != nil) [parent addChild: node]; else if ([_delegate respondsToSelector: @selector(elementBuilder:didBuildOrphanNode:)]) [_delegate elementBuilder: self didBuildOrphanNode: node]; } - (void)parser: (OFXMLParser *)parser didStartElement: (OFString *)name prefix: (OFString *)prefix namespace: (OFString *)namespace attributes: (OFArray *)attributes { OFXMLElement *element = [OFXMLElement elementWithName: name namespace: namespace]; for (OFXMLAttribute *attribute in attributes) { if (attribute.namespace == nil && [attribute.name isEqual: @"xmlns"]) continue; if ([attribute.namespace isEqual: @"http://www.w3.org/2000/xmlns/"]) [element setPrefix: attribute.name forNamespace: attribute.stringValue]; [element addAttribute: attribute]; } [_stack.lastObject addChild: element]; [_stack addObject: element]; } - (void)parser: (OFXMLParser *)parser didEndElement: (OFString *)name prefix: (OFString *)prefix namespace: (OFString *)namespace { switch (_stack.count) { case 0: if ([_delegate respondsToSelector: @selector(elementBuilder: didNotExpectCloseTag:prefix:namespace:)]) [_delegate elementBuilder: self didNotExpectCloseTag: name prefix: prefix namespace: namespace]; else @throw [OFMalformedXMLException exception]; return; case 1: [_delegate elementBuilder: self didBuildElement: _stack.firstObject]; break; } [_stack removeLastObject]; } - (void)parser: (OFXMLParser *)parser foundCharacters: (OFString *)characters { OFXMLCharacters *node; OFXMLElement *parent; node = [OFXMLCharacters charactersWithString: characters]; parent = _stack.lastObject; if (parent != nil) [parent addChild: node]; else if ([_delegate respondsToSelector: @selector(elementBuilder:didBuildOrphanNode:)]) [_delegate elementBuilder: self didBuildOrphanNode: node]; } - (void)parser: (OFXMLParser *)parser foundCDATA: (OFString *)CDATA { OFXMLCDATA *node = [OFXMLCDATA CDATAWithString: CDATA]; OFXMLElement *parent = _stack.lastObject; if (parent != nil) [parent addChild: node]; else if ([_delegate respondsToSelector: @selector(elementBuilder:didBuildOrphanNode:)]) [_delegate elementBuilder: self didBuildOrphanNode: node]; } - (void)parser: (OFXMLParser *)parser foundComment: (OFString *)comment { OFXMLComment *node = [OFXMLComment commentWithText: comment]; OFXMLElement *parent = _stack.lastObject; if (parent != nil) [parent addChild: node]; else if ([_delegate respondsToSelector: @selector(elementBuilder:didBuildOrphanNode:)]) [_delegate elementBuilder: self didBuildOrphanNode: node]; } - (OFString *)parser: (OFXMLParser *)parser foundUnknownEntityNamed: (OFString *)entity { if ([_delegate respondsToSelector: @selector(elementBuilder:foundUnknownEntityNamed:)]) return [_delegate elementBuilder: self foundUnknownEntityNamed: entity]; return nil; } @end objfw-1.1.6/src/OFXMLNode+Private.h000066400000000000000000000015601465614216400167020ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFXMLNode.h" OF_ASSUME_NONNULL_BEGIN @interface OFXMLNode () - (instancetype)of_init OF_METHOD_FAMILY(init); @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFXMLNode.h000066400000000000000000000065471465614216400153060ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFXMLNode OFXMLNode.h ObjFW/OFXMLNode.h * * @brief A class which stores an XML element. */ @interface OFXMLNode: OFObject { OF_RESERVE_IVARS(OFXMLNode, 4) } /** * @brief The contents of the node as a string value. * * For an @ref OFXMLElement, setting it removes all children and creates a * single child with the specified string value. */ @property (nonatomic, copy) OFString *stringValue; /** * @brief The contents of the receiver as a `long long` value. * * @throw OFInvalidFormatException The node cannot be parsed as a `long long` */ @property (readonly, nonatomic) long long longLongValue; /** * @brief The contents of the receiver as an `unsigned long long` value. * * @throw OFInvalidFormatException The node cannot be parsed as an * `unsigned long long` */ @property (readonly, nonatomic) unsigned long long unsignedLongLongValue; /** * @brief The contents of the receiver as a float value. * * @throw OFInvalidFormatException The node cannot be parsed as a `float` */ @property (readonly, nonatomic) float floatValue; /** * @brief The contents of the receiver as a double value. * * @throw OFInvalidFormatException The node cannot be parsed as a `double` */ @property (readonly, nonatomic) double doubleValue; /** * @brief A string representing the node as an XML string. * * @throw OFUnboundNamespaceException The node uses a namespace that was not * bound to a prefix in a context where it * needs a prefix */ @property (readonly, nonatomic) OFString *XMLString; - (instancetype)init OF_UNAVAILABLE; /** * @brief The contents of the receiver as a `long long` value in the specified * base. * * @param base The base to use. If the base is 0, base 16 is assumed if the * string starts with 0x (after stripping white spaces). If the * string starts with 0, base 8 is assumed. Otherwise, base 10 is * assumed. * @return The contents of the receiver as a `long long` value in the specified * base */ - (long long)longLongValueWithBase: (unsigned char)base; /** * @brief The contents of the receiver as an `unsigned long long` value in the * specified base. * * @param base The base to use. If the base is 0, base 16 is assumed if the * string starts with 0x (after stripping white spaces). If the * string starts with 0, base 8 is assumed. Otherwise, base 10 is * assumed. * @return The contents of the receiver as an `unsigned long long` value in the * specified base */ - (unsigned long long)unsignedLongLongValueWithBase: (unsigned char)base; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFXMLNode.m000066400000000000000000000033501465614216400153000ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFXMLNode.h" #import "OFString.h" @implementation OFXMLNode - (instancetype)of_init { return [super init]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (OFString *)stringValue { OF_UNRECOGNIZED_SELECTOR } - (void)setStringValue: (OFString *)stringValue { OF_UNRECOGNIZED_SELECTOR } - (long long)longLongValue { return self.stringValue.longLongValue; } - (long long)longLongValueWithBase: (unsigned char)base { return [self.stringValue longLongValueWithBase: base]; } - (unsigned long long)unsignedLongLongValue { return self.stringValue.unsignedLongLongValue; } - (unsigned long long)unsignedLongLongValueWithBase: (unsigned char)base { return [self.stringValue unsignedLongLongValueWithBase: base]; } - (float)floatValue { return self.stringValue.floatValue; } - (double)doubleValue { return self.stringValue.doubleValue; } - (OFString *)XMLString { OF_UNRECOGNIZED_SELECTOR } - (OFString *)description { return self.XMLString; } - (id)copy { return [self retain]; } @end objfw-1.1.6/src/OFXMLParser.h000066400000000000000000000160331465614216400156440ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFString.h" #import "OFXMLAttribute.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFMutableData; @class OFMutableArray OF_GENERIC(ObjectType); @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); @class OFStream; @class OFXMLParser; /** * @protocol OFXMLParserDelegate OFXMLParser.h ObjFW/OFXMLParser.h * * @brief A protocol that needs to be implemented by delegates for OFXMLParser. */ @protocol OFXMLParserDelegate @optional /** * @brief This callback is called when the XML parser found a processing * instruction. * * @param parser The parser which found a processing instruction * @param target The target of the processing instruction * @param text The text of the processing instruction */ - (void)parser: (OFXMLParser *)parser foundProcessingInstructionWithTarget: (OFString *)target text: (nullable OFString *)text; /** * @brief This callback is called when the XML parser found the start of a new * tag. * * @param parser The parser which found a new tag * @param name The name of the tag which just started * @param prefix The prefix of the tag which just started or `nil` * @param nameSpace The namespace of the tag which just started or `nil` * @param attributes The attributes included in the tag which just started or * `nil` */ - (void)parser: (OFXMLParser *)parser didStartElement: (OFString *)name prefix: (nullable OFString *)prefix namespace: (nullable OFString *)nameSpace attributes: (nullable OFArray OF_GENERIC(OFXMLAttribute *) *)attributes; /** * @brief This callback is called when the XML parser found the end of a tag. * * @param parser The parser which found the end of a tag * @param name The name of the tag which just ended * @param prefix The prefix of the tag which just ended or `nil` * @param nameSpace The namespace of the tag which just ended or `nil` */ - (void)parser: (OFXMLParser *)parser didEndElement: (OFString *)name prefix: (nullable OFString *)prefix namespace: (nullable OFString *)nameSpace; /** * @brief This callback is called when the XML parser found characters. * * In case there are comments or CDATA, it is possible that this callback is * called multiple times in a row. * * @param parser The parser which found a string * @param characters The characters the XML parser found */ - (void)parser: (OFXMLParser *)parser foundCharacters: (OFString *)characters; /** * @brief This callback is called when the XML parser found CDATA. * * @param parser The parser which found a string * @param CDATA The CDATA the XML parser found */ - (void)parser: (OFXMLParser *)parser foundCDATA: (OFString *)CDATA; /** * @brief This callback is called when the XML parser found a comment. * * @param parser The parser which found a comment * @param comment The comment the XML parser found */ - (void)parser: (OFXMLParser *)parser foundComment: (OFString *)comment; /** * @brief This callback is called when the XML parser found an entity it * doesn't know. * * The callback is supposed to return a substitution for the entity or `nil` if * it is not known to the callback as well, in which case an exception will be * risen. * * @param parser The parser which found an unknown entity * @param entity The name of the entity the XML parser didn't know * @return A substitution for the entity or `nil` */ - (nullable OFString *)parser: (OFXMLParser *)parser foundUnknownEntityNamed: (OFString *)entity; @end /** * @class OFXMLParser OFXMLParser.h ObjFW/OFXMLParser.h * * @brief An event-based XML parser. * * OFXMLParser is an event-based XML parser which calls the delegate's callbacks * as soon as it finds something, thus suitable for streams as well. */ OF_SUBCLASSING_RESTRICTED @interface OFXMLParser: OFObject { id _Nullable _delegate; uint_least8_t _state; size_t _i, _last; const char *_Nullable _data; OFMutableData *_buffer; OFString *_Nullable _name, *_Nullable _prefix; OFMutableArray OF_GENERIC(OFMutableDictionary OF_GENERIC(OFString *, OFString *) *) *_namespaces; OFMutableArray OF_GENERIC(OFXMLAttribute *) *_attributes; OFString *_Nullable _attributeName, *_Nullable _attributePrefix; char _delimiter; OFMutableArray OF_GENERIC(OFString *) *_previous; size_t _level; bool _acceptProlog; size_t _lineNumber; bool _lastCarriageReturn, _finishedParsing; OFStringEncoding _encoding; size_t _depthLimit; } /** * @brief The delegate that is used by the XML parser. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id delegate; /** * @brief The current line number. */ @property (readonly, nonatomic) size_t lineNumber; /** * @brief Whether the XML parser has finished parsing. */ @property (readonly, nonatomic, getter=hasFinishedParsing) bool finishedParsing; /** * @brief The depth limit for the XML parser. * * If the depth limit is exceeded, an OFMalformedXMLException is thrown. * * The default is 32. 0 means unlimited (insecure!). */ @property (nonatomic) size_t depthLimit; /** * @brief Creates a new XML parser. * * @return A new, autoreleased OFXMLParser */ + (instancetype)parser; /** * @brief Parses the specified buffer with the specified size. * * @param buffer The buffer to parse * @param length The length of the buffer * @throw OFMalformedXMLException The XML was malformed * @throw OFUnboundPrefixException A prefix was used that was not bound to any * namespace * @throw OFInvalidEncodingException The XML is not in the encoding it specified */ - (void)parseBuffer: (const char *)buffer length: (size_t)length; /** * @brief Parses the specified string. * * @param string The string to parse * @throw OFMalformedXMLException The XML was malformed * @throw OFUnboundPrefixException A prefix was used that was not bound to any * namespace * @throw OFInvalidEncodingException The XML is not in the encoding it specified */ - (void)parseString: (OFString *)string; /** * @brief Parses the specified stream. * * @param stream The stream to parse * @throw OFMalformedXMLException The XML was malformed * @throw OFUnboundPrefixException A prefix was used that was not bound to any * namespace * @throw OFInvalidEncodingException The XML is not in the encoding it specified */ - (void)parseStream: (OFStream *)stream; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFXMLParser.m000066400000000000000000000667201465614216400156610ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #define OF_XML_PARSER_M #include #import "OFXMLParser.h" #import "OFArray.h" #import "OFCharacterSet.h" #import "OFData.h" #import "OFDictionary.h" #ifdef OF_HAVE_FILES # import "OFFile.h" #endif #import "OFStream.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFXMLAttribute.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFMalformedXMLException.h" #import "OFOutOfRangeException.h" #import "OFUnboundPrefixException.h" enum { stateInByteOrderMark, stateOutsideTag, stateTagOpened, stateInProcessingInstruction, stateInTagName, stateInCloseTagName, stateInTag, stateInAttributeName, stateExpectAttributeEqualSign, stateExpectAttributeDelimiter, stateInAttributeValue, stateExpectTagClose, stateExpectSpaceOrTagClose, stateInExclamationMark, stateInCDATAOpening, stateInCDATA, stateInCommentOpening, stateInComment1, stateInComment2, stateInDOCTYPE }; @interface OFXMLParser () @end static void inByteOrderMarkState(OFXMLParser *); static void outsideTagState(OFXMLParser *); static void tagOpenedState(OFXMLParser *); static void inProcessingInstructionState(OFXMLParser *); static void inTagNameState(OFXMLParser *); static void inCloseTagNameState(OFXMLParser *); static void inTagState(OFXMLParser *); static void inAttributeNameState(OFXMLParser *); static void expectAttributeEqualSignState(OFXMLParser *); static void expectAttributeDelimiterState(OFXMLParser *); static void inAttributeValueState(OFXMLParser *); static void expectTagCloseState(OFXMLParser *); static void expectSpaceOrTagCloseState(OFXMLParser *); static void inExclamationMarkState(OFXMLParser *); static void inCDATAOpeningState(OFXMLParser *); static void inCDATAState(OFXMLParser *); static void inCommentOpeningState(OFXMLParser *); static void inCommentState1(OFXMLParser *); static void inCommentState2(OFXMLParser *); static void inDOCTYPEState(OFXMLParser *); typedef void (*StateFunction)(OFXMLParser *); static StateFunction lookupTable[] = { [stateInByteOrderMark] = inByteOrderMarkState, [stateOutsideTag] = outsideTagState, [stateTagOpened] = tagOpenedState, [stateInProcessingInstruction] = inProcessingInstructionState, [stateInTagName] = inTagNameState, [stateInCloseTagName] = inCloseTagNameState, [stateInTag] = inTagState, [stateInAttributeName] = inAttributeNameState, [stateExpectAttributeEqualSign] = expectAttributeEqualSignState, [stateExpectAttributeDelimiter] = expectAttributeDelimiterState, [stateInAttributeValue] = inAttributeValueState, [stateExpectTagClose] = expectTagCloseState, [stateExpectSpaceOrTagClose] = expectSpaceOrTagCloseState, [stateInExclamationMark] = inExclamationMarkState, [stateInCDATAOpening] = inCDATAOpeningState, [stateInCDATA] = inCDATAState, [stateInCommentOpening] = inCommentOpeningState, [stateInComment1] = inCommentState1, [stateInComment2] = inCommentState2, [stateInDOCTYPE] = inDOCTYPEState }; static OF_INLINE void appendToBuffer(OFMutableData *buffer, const char *string, OFStringEncoding encoding, size_t length) { if OF_LIKELY (encoding == OFStringEncodingUTF8) [buffer addItems: string count: length]; else { void *pool = objc_autoreleasePoolPush(); OFString *tmp = [OFString stringWithCString: string encoding: encoding length: length]; [buffer addItems: tmp.UTF8String count: tmp.UTF8StringLength]; objc_autoreleasePoolPop(pool); } } static OFString * transformString(OFXMLParser *parser, OFMutableData *buffer, size_t cut, bool unescape) { char *items = buffer.mutableItems; size_t length = buffer.count - cut; bool hasEntities = false; OFString *ret; for (size_t i = 0; i < length; i++) { if (items[i] == '\r') { if (i + 1 < length && items[i + 1] == '\n') { [buffer removeItemAtIndex: i]; items = buffer.mutableItems; i--; length--; } else items[i] = '\n'; } else if (items[i] == '&') hasEntities = true; } ret = [OFString stringWithUTF8String: items length: length]; if (unescape && hasEntities) { @try { return [ret stringByXMLUnescapingWithDelegate: parser]; } @catch (OFInvalidFormatException *e) { @throw [OFMalformedXMLException exceptionWithParser: parser]; } } return ret; } static OFString * namespaceForPrefix(OFString *prefix, OFArray *namespaces) { OFDictionary *const *objects = namespaces.objects; size_t count = namespaces.count; if (prefix == nil) prefix = @""; while (count > 0) { OFString *tmp; if ((tmp = [objects[--count] objectForKey: prefix]) != nil) return tmp; } return nil; } static OF_INLINE void resolveAttributeNamespace(OFXMLAttribute *attribute, OFArray *namespaces, OFXMLParser *self) { OFString *attributeNS; OFString *attributePrefix = attribute->_namespace; if (attributePrefix == nil) return; attributeNS = namespaceForPrefix(attributePrefix, namespaces); if ((attributePrefix != nil && attributeNS == nil)) @throw [OFUnboundPrefixException exceptionWithPrefix: attributePrefix parser: self]; [attribute->_namespace release]; attribute->_namespace = [attributeNS retain]; } @implementation OFXMLParser @synthesize delegate = _delegate, depthLimit = _depthLimit; + (instancetype)parser { return [[[self alloc] init] autorelease]; } - (instancetype)init { self = [super init]; @try { void *pool; OFMutableDictionary *dict; _buffer = [[OFMutableData alloc] init]; _previous = [[OFMutableArray alloc] init]; _namespaces = [[OFMutableArray alloc] init]; _attributes = [[OFMutableArray alloc] init]; pool = objc_autoreleasePoolPush(); dict = [OFMutableDictionary dictionaryWithKeysAndObjects: @"xml", @"http://www.w3.org/XML/1998/namespace", @"xmlns", @"http://www.w3.org/2000/xmlns/", nil]; [_namespaces addObject: dict]; _acceptProlog = true; _lineNumber = 1; _encoding = OFStringEncodingUTF8; _depthLimit = 32; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_buffer release]; [_name release]; [_prefix release]; [_namespaces release]; [_attributes release]; [_attributeName release]; [_attributePrefix release]; [_previous release]; [super dealloc]; } - (void)parseBuffer: (const char *)buffer length: (size_t)length { _data = buffer; for (_i = _last = 0; _i < length; _i++) { size_t j = _i; lookupTable[_state](self); /* Ensure we don't count this character twice */ if (_i != j) continue; if (_data[_i] == '\r' || (_data[_i] == '\n' && !_lastCarriageReturn)) _lineNumber++; _lastCarriageReturn = (_data[_i] == '\r'); } /* In stateInTag, there can be only spaces */ if (length - _last > 0 && _state != stateInTag) appendToBuffer(_buffer, _data + _last, _encoding, length - _last); } - (void)parseString: (OFString *)string { [self parseBuffer: string.UTF8String length: string.UTF8StringLength]; } - (void)parseStream: (OFStream *)stream { size_t pageSize = [OFSystemInfo pageSize]; char *buffer = OFAllocMemory(1, pageSize); @try { while (!stream.atEndOfStream) { size_t length = [stream readIntoBuffer: buffer length: pageSize]; [self parseBuffer: buffer length: length]; } } @finally { OFFreeMemory(buffer); } } static void inByteOrderMarkState(OFXMLParser *self) { if (self->_data[self->_i] != "\xEF\xBB\xBF"[self->_level]) { if (self->_level == 0) { self->_state = stateOutsideTag; self->_i--; return; } @throw [OFMalformedXMLException exceptionWithParser: self]; } if (self->_level++ == 2) self->_state = stateOutsideTag; self->_last = self->_i + 1; } /* Not in a tag */ static void outsideTagState(OFXMLParser *self) { size_t length; if ((self->_finishedParsing || self->_previous.count < 1) && self->_data[self->_i] != ' ' && self->_data[self->_i] != '\t' && self->_data[self->_i] != '\n' && self->_data[self->_i] != '\r' && self->_data[self->_i] != '<') @throw [OFMalformedXMLException exceptionWithParser: self]; if (self->_data[self->_i] != '<') return; if ((length = self->_i - self->_last) > 0) appendToBuffer(self->_buffer, self->_data + self->_last, self->_encoding, length); if (self->_buffer.count > 0) { void *pool = objc_autoreleasePoolPush(); OFString *characters = transformString(self, self->_buffer, 0, true); if ([self->_delegate respondsToSelector: @selector(parser:foundCharacters:)]) [self->_delegate parser: self foundCharacters: characters]; objc_autoreleasePoolPop(pool); } [self->_buffer removeAllItems]; self->_last = self->_i + 1; self->_state = stateTagOpened; } /* Tag was just opened */ static void tagOpenedState(OFXMLParser *self) { if (self->_finishedParsing && self->_data[self->_i] != '!' && self->_data[self->_i] != '?') @throw [OFMalformedXMLException exceptionWithParser: self]; switch (self->_data[self->_i]) { case '?': self->_last = self->_i + 1; self->_state = stateInProcessingInstruction; self->_level = 0; break; case '/': self->_last = self->_i + 1; self->_state = stateInCloseTagName; self->_acceptProlog = false; break; case '!': self->_last = self->_i + 1; self->_state = stateInExclamationMark; self->_acceptProlog = false; break; default: if (self->_depthLimit > 0 && self->_previous.count >= self->_depthLimit) @throw [OFOutOfRangeException exception]; self->_state = stateInTagName; self->_acceptProlog = false; self->_i--; break; } } /* */ static bool parseXMLProcessingInstruction(OFXMLParser *self, OFString *data) { const char *cString; size_t length, last; int PIState = 0; OFString *attribute = nil; OFMutableString *value = nil; char piDelimiter = 0; bool hasVersion = false; if (!self->_acceptProlog) return false; self->_acceptProlog = false; cString = data.UTF8String; length = data.UTF8StringLength; last = 0; for (size_t i = 0; i < length; i++) { switch (PIState) { case 0: if (cString[i] == ' ' || cString[i] == '\t' || cString[i] == '\r' || cString[i] == '\n') continue; last = i; PIState = 1; i--; break; case 1: if (cString[i] != '=') continue; attribute = [OFString stringWithCString: cString + last encoding: self->_encoding length: i - last]; last = i + 1; PIState = 2; break; case 2: if (cString[i] != '\'' && cString[i] != '"') return false; piDelimiter = cString[i]; last = i + 1; PIState = 3; break; case 3: if (cString[i] != piDelimiter) continue; value = [OFMutableString stringWithCString: cString + last encoding: self->_encoding length: i - last]; if ([attribute isEqual: @"version"]) { if (![value hasPrefix: @"1."]) return false; hasVersion = true; } if ([attribute isEqual: @"encoding"]) { @try { self->_encoding = OFStringEncodingParseName(value); } @catch (OFInvalidArgumentException *e) { @throw [OFInvalidEncodingException exception]; } } last = i + 1; PIState = 0; break; } } if (PIState != 0 || !hasVersion) return false; return true; } /* Inside processing instruction */ static void inProcessingInstructionState(OFXMLParser *self) { if (self->_data[self->_i] == '?') self->_level = 1; else if (self->_level == 1 && self->_data[self->_i] == '>') { void *pool = objc_autoreleasePoolPush(); OFString *PI, *target, *text = nil; OFCharacterSet *whitespaceCS; size_t pos; appendToBuffer(self->_buffer, self->_data + self->_last, self->_encoding, self->_i - self->_last); PI = transformString(self, self->_buffer, 1, false); whitespaceCS = [OFCharacterSet characterSetWithCharactersInString: @" \r\n\r"]; pos = [PI indexOfCharacterFromSet: whitespaceCS]; if (pos != OFNotFound) { target = [PI substringToIndex: pos]; text = [[PI substringFromIndex: pos + 1] stringByDeletingEnclosingWhitespaces]; if (text.length == 0) text = nil; } else target = PI; if ([target caseInsensitiveCompare: @"xml"] == OFOrderedSame) if (!parseXMLProcessingInstruction(self, text)) @throw [OFMalformedXMLException exceptionWithParser: self]; if ([self->_delegate respondsToSelector: @selector( parser:foundProcessingInstructionWithTarget:text:)]) [self->_delegate parser: self foundProcessingInstructionWithTarget: target text: text]; objc_autoreleasePoolPop(pool); [self->_buffer removeAllItems]; self->_last = self->_i + 1; self->_state = stateOutsideTag; } else self->_level = 0; } /* Inside a tag, no name yet */ static void inTagNameState(OFXMLParser *self) { void *pool; const char *bufferCString, *tmp; size_t length, bufferLength; OFString *bufferString; if (self->_data[self->_i] != ' ' && self->_data[self->_i] != '\t' && self->_data[self->_i] != '\n' && self->_data[self->_i] != '\r' && self->_data[self->_i] != '>' && self->_data[self->_i] != '/') return; if ((length = self->_i - self->_last) > 0) appendToBuffer(self->_buffer, self->_data + self->_last, self->_encoding, length); pool = objc_autoreleasePoolPush(); bufferCString = self->_buffer.items; bufferLength = self->_buffer.count; bufferString = [OFString stringWithUTF8String: bufferCString length: bufferLength]; if ((tmp = memchr(bufferCString, ':', bufferLength)) != NULL) { self->_name = [[OFString alloc] initWithUTF8String: tmp + 1 length: bufferLength - (tmp - bufferCString) - 1]; self->_prefix = [[OFString alloc] initWithUTF8String: bufferCString length: tmp - bufferCString]; } else { self->_name = [bufferString copy]; self->_prefix = nil; } if (self->_data[self->_i] == '>' || self->_data[self->_i] == '/') { OFString *namespace = namespaceForPrefix(self->_prefix, self->_namespaces); if (self->_prefix != nil && namespace == nil) @throw [OFUnboundPrefixException exceptionWithPrefix: self->_prefix parser: self]; if ([self->_delegate respondsToSelector: @selector(parser: didStartElement:prefix:namespace:attributes:)]) [self->_delegate parser: self didStartElement: self->_name prefix: self->_prefix namespace: namespace attributes: nil]; if (self->_data[self->_i] == '/') { if ([self->_delegate respondsToSelector: @selector(parser:didEndElement:prefix:namespace:)]) [self->_delegate parser: self didEndElement: self->_name prefix: self->_prefix namespace: namespace]; if (self->_previous.count == 0) self->_finishedParsing = true; } else [self->_previous addObject: bufferString]; [self->_name release]; [self->_prefix release]; self->_name = self->_prefix = nil; self->_state = (self->_data[self->_i] == '/' ? stateExpectTagClose : stateOutsideTag); } else self->_state = stateInTag; if (self->_data[self->_i] != '/') [self->_namespaces addObject: [OFMutableDictionary dictionary]]; objc_autoreleasePoolPop(pool); [self->_buffer removeAllItems]; self->_last = self->_i + 1; } /* Inside a close tag, no name yet */ static void inCloseTagNameState(OFXMLParser *self) { void *pool; const char *bufferCString, *tmp; size_t length, bufferLength; OFString *bufferString, *namespace; if (self->_data[self->_i] != ' ' && self->_data[self->_i] != '\t' && self->_data[self->_i] != '\n' && self->_data[self->_i] != '\r' && self->_data[self->_i] != '>') return; if ((length = self->_i - self->_last) > 0) appendToBuffer(self->_buffer, self->_data + self->_last, self->_encoding, length); pool = objc_autoreleasePoolPush(); bufferCString = self->_buffer.items; bufferLength = self->_buffer.count; bufferString = [OFString stringWithUTF8String: bufferCString length: bufferLength]; if ((tmp = memchr(bufferCString, ':', bufferLength)) != NULL) { self->_name = [[OFString alloc] initWithUTF8String: tmp + 1 length: bufferLength - (tmp - bufferCString) - 1]; self->_prefix = [[OFString alloc] initWithUTF8String: bufferCString length: tmp - bufferCString]; } else { self->_name = [bufferString copy]; self->_prefix = nil; } if (![self->_previous.lastObject isEqual: bufferString]) @throw [OFMalformedXMLException exceptionWithParser: self]; [self->_previous removeLastObject]; [self->_buffer removeAllItems]; namespace = namespaceForPrefix(self->_prefix, self->_namespaces); if (self->_prefix != nil && namespace == nil) @throw [OFUnboundPrefixException exceptionWithPrefix: self->_prefix parser: self]; if ([self->_delegate respondsToSelector: @selector(parser:didEndElement:prefix:namespace:)]) [self->_delegate parser: self didEndElement: self->_name prefix: self->_prefix namespace: namespace]; objc_autoreleasePoolPop(pool); [self->_namespaces removeLastObject]; [self->_name release]; [self->_prefix release]; self->_name = self->_prefix = nil; self->_last = self->_i + 1; self->_state = (self->_data[self->_i] == '>' ? stateOutsideTag : stateExpectSpaceOrTagClose); if (self->_previous.count == 0) self->_finishedParsing = true; } /* Inside a tag, name found */ static void inTagState(OFXMLParser *self) { void *pool; OFString *namespace; OFXMLAttribute *const *attributesObjects; size_t attributesCount; if (self->_data[self->_i] != '>' && self->_data[self->_i] != '/') { if (self->_data[self->_i] != ' ' && self->_data[self->_i] != '\t' && self->_data[self->_i] != '\n' && self->_data[self->_i] != '\r') { self->_last = self->_i; self->_state = stateInAttributeName; self->_i--; } return; } attributesObjects = self->_attributes.objects; attributesCount = self->_attributes.count; namespace = namespaceForPrefix(self->_prefix, self->_namespaces); if (self->_prefix != nil && namespace == nil) @throw [OFUnboundPrefixException exceptionWithPrefix: self->_prefix parser: self]; for (size_t j = 0; j < attributesCount; j++) resolveAttributeNamespace(attributesObjects[j], self->_namespaces, self); pool = objc_autoreleasePoolPush(); if ([self->_delegate respondsToSelector: @selector(parser:didStartElement:prefix:namespace:attributes:)]) [self->_delegate parser: self didStartElement: self->_name prefix: self->_prefix namespace: namespace attributes: self->_attributes]; if (self->_data[self->_i] == '/') { if ([self->_delegate respondsToSelector: @selector(parser:didEndElement:prefix:namespace:)]) [self->_delegate parser: self didEndElement: self->_name prefix: self->_prefix namespace: namespace]; if (self->_previous.count == 0) self->_finishedParsing = true; [self->_namespaces removeLastObject]; } else if (self->_prefix != nil) { OFString *str = [OFString stringWithFormat: @"%@:%@", self->_prefix, self->_name]; [self->_previous addObject: str]; } else [self->_previous addObject: self->_name]; objc_autoreleasePoolPop(pool); [self->_name release]; [self->_prefix release]; [self->_attributes removeAllObjects]; self->_name = self->_prefix = nil; self->_last = self->_i + 1; self->_state = (self->_data[self->_i] == '/' ? stateExpectTagClose : stateOutsideTag); } /* Looking for attribute name */ static void inAttributeNameState(OFXMLParser *self) { void *pool; OFString *bufferString; const char *bufferCString, *tmp; size_t length, bufferLength; if (self->_data[self->_i] != '=' && self->_data[self->_i] != ' ' && self->_data[self->_i] != '\t' && self->_data[self->_i] != '\n' && self->_data[self->_i] != '\r') return; if ((length = self->_i - self->_last) > 0) appendToBuffer(self->_buffer, self->_data + self->_last, self->_encoding, length); pool = objc_autoreleasePoolPush(); bufferString = [OFString stringWithUTF8String: self->_buffer.items length: self->_buffer.count]; bufferCString = bufferString.UTF8String; bufferLength = bufferString.UTF8StringLength; if ((tmp = memchr(bufferCString, ':', bufferLength)) != NULL) { self->_attributeName = [[OFString alloc] initWithUTF8String: tmp + 1 length: bufferLength - (tmp - bufferCString) - 1]; self->_attributePrefix = [[OFString alloc] initWithUTF8String: bufferCString length: tmp - bufferCString]; } else { self->_attributeName = [bufferString copy]; self->_attributePrefix = nil; } objc_autoreleasePoolPop(pool); [self->_buffer removeAllItems]; self->_last = self->_i + 1; self->_state = (self->_data[self->_i] == '=' ? stateExpectAttributeDelimiter : stateExpectAttributeEqualSign); } /* Expecting equal sign of an attribute */ static void expectAttributeEqualSignState(OFXMLParser *self) { if (self->_data[self->_i] == '=') { self->_last = self->_i + 1; self->_state = stateExpectAttributeDelimiter; return; } if (self->_data[self->_i] != ' ' && self->_data[self->_i] != '\t' && self->_data[self->_i] != '\n' && self->_data[self->_i] != '\r') @throw [OFMalformedXMLException exceptionWithParser: self]; } /* Expecting name/value delimiter of an attribute */ static void expectAttributeDelimiterState(OFXMLParser *self) { self->_last = self->_i + 1; if (self->_data[self->_i] == ' ' || self->_data[self->_i] == '\t' || self->_data[self->_i] == '\n' || self->_data[self->_i] == '\r') return; if (self->_data[self->_i] != '\'' && self->_data[self->_i] != '"') @throw [OFMalformedXMLException exceptionWithParser: self]; self->_delimiter = self->_data[self->_i]; self->_state = stateInAttributeValue; } /* Looking for attribute value */ static void inAttributeValueState(OFXMLParser *self) { void *pool; OFString *attributeValue; size_t length; OFXMLAttribute *attribute; if (self->_data[self->_i] != self->_delimiter) return; if ((length = self->_i - self->_last) > 0) appendToBuffer(self->_buffer, self->_data + self->_last, self->_encoding, length); pool = objc_autoreleasePoolPush(); attributeValue = transformString(self, self->_buffer, 0, true); if (self->_attributePrefix == nil && [self->_attributeName isEqual: @"xmlns"]) [self->_namespaces.lastObject setObject: attributeValue forKey: @""]; if ([self->_attributePrefix isEqual: @"xmlns"]) [self->_namespaces.lastObject setObject: attributeValue forKey: self->_attributeName]; attribute = [OFXMLAttribute attributeWithName: self->_attributeName namespace: self->_attributePrefix stringValue: attributeValue]; attribute->_useDoubleQuotes = (self->_delimiter == '"'); [self->_attributes addObject: attribute]; objc_autoreleasePoolPop(pool); [self->_buffer removeAllItems]; [self->_attributeName release]; [self->_attributePrefix release]; self->_attributeName = self->_attributePrefix = nil; self->_last = self->_i + 1; self->_state = stateInTag; } /* Expecting closing '>' */ static void expectTagCloseState(OFXMLParser *self) { if (self->_data[self->_i] == '>') { self->_last = self->_i + 1; self->_state = stateOutsideTag; } else @throw [OFMalformedXMLException exceptionWithParser: self]; } /* Expecting closing '>' or space */ static void expectSpaceOrTagCloseState(OFXMLParser *self) { if (self->_data[self->_i] == '>') { self->_last = self->_i + 1; self->_state = stateOutsideTag; } else if (self->_data[self->_i] != ' ' && self->_data[self->_i] != '\t' && self->_data[self->_i] != '\n' && self->_data[self->_i] != '\r') @throw [OFMalformedXMLException exceptionWithParser: self]; } /* In _finishedParsing && self->_data[self->_i] != '-') @throw [OFMalformedXMLException exceptionWithParser: self]; if (self->_data[self->_i] == '-') self->_state = stateInCommentOpening; else if (self->_data[self->_i] == '[') { self->_state = stateInCDATAOpening; self->_level = 0; } else if (self->_data[self->_i] == 'D') { self->_state = stateInDOCTYPE; self->_level = 0; } else @throw [OFMalformedXMLException exceptionWithParser: self]; self->_last = self->_i + 1; } /* CDATA */ static void inCDATAOpeningState(OFXMLParser *self) { if (self->_data[self->_i] != "CDATA["[self->_level]) @throw [OFMalformedXMLException exceptionWithParser: self]; if (++self->_level == 6) { self->_state = stateInCDATA; self->_level = 0; } self->_last = self->_i + 1; } static void inCDATAState(OFXMLParser *self) { if (self->_data[self->_i] == ']') self->_level++; else if (self->_data[self->_i] == '>' && self->_level >= 2) { void *pool = objc_autoreleasePoolPush(); OFString *CDATA; appendToBuffer(self->_buffer, self->_data + self->_last, self->_encoding, self->_i - self->_last); CDATA = transformString(self, self->_buffer, 2, false); if ([self->_delegate respondsToSelector: @selector(parser:foundCDATA:)]) [self->_delegate parser: self foundCDATA: CDATA]; objc_autoreleasePoolPop(pool); [self->_buffer removeAllItems]; self->_last = self->_i + 1; self->_state = stateOutsideTag; } else self->_level = 0; } /* Comment */ static void inCommentOpeningState(OFXMLParser *self) { if (self->_data[self->_i] != '-') @throw [OFMalformedXMLException exceptionWithParser: self]; self->_last = self->_i + 1; self->_state = stateInComment1; self->_level = 0; } static void inCommentState1(OFXMLParser *self) { if (self->_data[self->_i] == '-') self->_level++; else self->_level = 0; if (self->_level == 2) self->_state = stateInComment2; } static void inCommentState2(OFXMLParser *self) { void *pool; OFString *comment; if (self->_data[self->_i] != '>') @throw [OFMalformedXMLException exceptionWithParser: self]; pool = objc_autoreleasePoolPush(); appendToBuffer(self->_buffer, self->_data + self->_last, self->_encoding, self->_i - self->_last); comment = transformString(self, self->_buffer, 2, false); if ([self->_delegate respondsToSelector: @selector(parser:foundComment:)]) [self->_delegate parser: self foundComment: comment]; objc_autoreleasePoolPop(pool); [self->_buffer removeAllItems]; self->_last = self->_i + 1; self->_state = stateOutsideTag; } /* In */ static void inDOCTYPEState(OFXMLParser *self) { if ((self->_level < 6 && self->_data[self->_i] != "OCTYPE"[self->_level]) || (self->_level == 6 && self->_data[self->_i] != ' ' && self->_data[self->_i] != '\t' && self->_data[self->_i] != '\n' && self->_data[self->_i] != '\r')) @throw [OFMalformedXMLException exceptionWithParser: self]; self->_level++; if (self->_level > 6 && self->_data[self->_i] == '>') self->_state = stateOutsideTag; self->_last = self->_i + 1; } - (size_t)lineNumber { return _lineNumber; } - (bool)hasFinishedParsing { return _finishedParsing; } - (OFString *)string: (OFString *)string containsUnknownEntityNamed: (OFString *)entity { if ([_delegate respondsToSelector: @selector(parser:foundUnknownEntityNamed:)]) return [_delegate parser: self foundUnknownEntityNamed: entity]; return nil; } @end objfw-1.1.6/src/OFXMLProcessingInstruction.h000066400000000000000000000040731465614216400207670ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFXMLNode.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFXMLProcessingInstruction \ * OFXMLProcessingInstruction.h ObjFW/OFXMLProcessingInstruction.h * * @brief A class for representing an XML processing instruction. */ OF_SUBCLASSING_RESTRICTED @interface OFXMLProcessingInstruction: OFXMLNode { OFString *_target, *_Nullable _text; } /** * @brief The target of the processing instruction. */ @property (readonly, nonatomic) OFString *target; /** * @brief The text of the processing instruction. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *text; /** * @brief Creates a new OFXMLProcessingInstruction with the specified target * and text. * * @param target The target for the processing instruction * @param text The text for the processing instruction * @return A new OFXMLProcessingInstruction */ + (instancetype)processingInstructionWithTarget: (OFString *)target text: (OFString *)text; /** * @brief Initializes an already allocated OFXMLProcessingInstruction with the * specified target and text. * * @param target The target for the processing instruction * @param text The text for the processing instruction * @return An initialized OFXMLProcessingInstruction */ - (instancetype)initWithTarget: (OFString *)target text: (OFString *)text OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFXMLProcessingInstruction.m000066400000000000000000000046021465614216400207720ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFXMLProcessingInstruction.h" #import "OFString.h" #import "OFXMLAttribute.h" #import "OFXMLNode+Private.h" #import "OFInvalidArgumentException.h" @implementation OFXMLProcessingInstruction @synthesize target = _target, text = _text; + (instancetype)processingInstructionWithTarget: (OFString *)target text: (OFString *)text { return [[[self alloc] initWithTarget: target text: text] autorelease]; } - (instancetype)initWithTarget: (OFString *)target text: (OFString *)text { self = [super of_init]; @try { _target = [target copy]; _text = [text copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_target release]; [_text release]; [super dealloc]; } - (bool)isEqual: (id)object { OFXMLProcessingInstruction *processingInstruction; if (object == self) return true; if (![object isKindOfClass: [OFXMLProcessingInstruction class]]) return false; processingInstruction = object; if (![processingInstruction->_target isEqual: _target]) return false; if (processingInstruction->_text != _text && ![processingInstruction->_text isEqual: _text]) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _target.hash); OFHashAddHash(&hash, _text.hash); OFHashFinalize(&hash); return hash; } - (OFString *)stringValue { return @""; } - (OFString *)XMLString { if (_text.length > 0) return [OFString stringWithFormat: @"", _target, _text]; else return [OFString stringWithFormat: @"", _target]; } - (OFString *)description { return self.XMLString; } @end objfw-1.1.6/src/OFZIPArchive.h000066400000000000000000000216201465614216400157710ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFString.h" #import "OFZIPArchiveEntry.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFMutableArray OF_GENERIC(ObjectType); @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); @class OFSeekableStream; @class OFStream; @class OFZIPArchive; /** * @protocol OFZIPArchiveDelegate OFZIPArchive.h ObjFW/OFZIPArchive.h * * @brief A delegate for OFZIPArchive. */ @protocol OFZIPArchiveDelegate @optional /** * @brief A callback that is called when an @ref OFZIPArchive wants to read a * different archive part. * * @param archive The archive that wants to read another part * @param partNumber The number of the part the archive wants to read * @param lastPartNumber The number of the last archive part * @return The stream to read the needed part, or `nil` if no such part exists */ - (nullable OFSeekableStream *)archive: (OFZIPArchive *)archive wantsPartNumbered: (unsigned int)partNumber lastPartNumber: (unsigned int)lastPartNumber; @end /** * @class OFZIPArchive OFZIPArchive.h ObjFW/OFZIPArchive.h * * @brief A class for accessing and manipulating ZIP files. */ OF_SUBCLASSING_RESTRICTED @interface OFZIPArchive: OFObject { #ifdef OF_ZIP_ARCHIVE_M @public #endif OFObject *_Nullable _delegate; OF_KINDOF(OFStream *) _stream; int64_t _offset; uint_least8_t _mode; uint32_t _diskNumber, _lastDiskNumber; @protected uint32_t _centralDirectoryDisk; uint64_t _centralDirectoryEntriesInDisk, _centralDirectoryEntries; uint64_t _centralDirectorySize; int64_t _centralDirectoryOffset; OFString *_Nullable _archiveComment; #ifdef OF_ZIP_ARCHIVE_M @public #endif OFMutableArray OF_GENERIC(OFZIPArchiveEntry *) *_entries; OFMutableDictionary OF_GENERIC(OFString *, OFZIPArchiveEntry *) *_pathToEntryMap; OFStream *_Nullable _lastReturnedStream; } /** * @brief The delegate of the ZIP archive. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) OFObject *delegate; /** * @brief The archive comment. */ @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *archiveComment; /** * @brief The entries in the central directory of the archive as an array of * objects of class @ref OFZIPArchiveEntry. * * The objects of the array have the same order as the entries in the central * directory, which does not need to be the order in which the actual files are * stored. */ @property (readonly, nonatomic) OFArray OF_GENERIC(OFZIPArchiveEntry *) *entries; /** * @brief Creates a new OFZIPArchive object with the specified stream. * * @param stream A stream from which the ZIP archive will be read. * For read and append mode, this needs to be an OFSeekableStream. * @param mode The mode for the ZIP file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return A new, autoreleased OFZIPArchive * @throw OFInvalidFormatException The format is not that of a valid ZIP archive */ + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode; /** * @brief Creates a new OFZIPArchive object with the specified file. * * @param IRI The IRI to the ZIP file * @param mode The mode for the ZIP file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return A new, autoreleased OFZIPArchive * @throw OFInvalidFormatException The format is not that of a valid ZIP archive */ + (instancetype)archiveWithIRI: (OFIRI *)IRI mode: (OFString *)mode; /** * @brief Creates an IRI for accessing the specified file within the specified * ZIP archive. * * @param path The path of the file within the archive * @param IRI The IRI of the archive * @return An IRI for accessing the specified file within the specified ZIP * archive */ + (OFIRI *)IRIForFilePath: (OFString *)path inArchiveWithIRI: (OFIRI *)IRI; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFZIPArchive object with the * specified stream. * * @param stream A stream from which the ZIP archive will be read. * For read and append mode, this needs to be an OFSeekableStream. * @param mode The mode for the ZIP file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return An initialized OFZIPArchive * @throw OFInvalidFormatException The format is not that of a valid ZIP archive */ - (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated OFZIPArchive object with the * specified file. * * @param IRI The IRI to the ZIP file * @param mode The mode for the ZIP file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return An initialized OFZIPArchive * @throw OFInvalidFormatException The format is not that of a valid ZIP archive */ - (instancetype)initWithIRI: (OFIRI *)IRI mode: (OFString *)mode; /** * @brief Returns a stream for reading the specified file from the archive. * * @note This method is only available in read mode. * * @note The returned stream conforms to @ref OFReadyForReadingObserving if the * underlying stream does so, too. * * @warning Calling @ref streamForReadingFile: will invalidate all streams * previously returned by @ref streamForReadingFile: or * @ref streamForWritingEntry:! Reading from or writing to an * invalidated stream will throw an @ref OFReadFailedException or * @ref OFWriteFailedException! * * @param path The path to the file inside the archive * @return A stream for reading the specified file form the archive * @throw OFNotOpenException The archive is not open * @throw OFInvalidArgumentException The archive is not in read mode * @throw OFOpenItemFailedException Opening the specified file within the * archive failed * @throw OFInvalidFormatException The local header and the header in the * central directory do not match enough * @throw OFUnsupportedVersionException The file uses a version of the ZIP * format that is not supported */ - (OFStream *)streamForReadingFile: (OFString *)path; /** * @brief Returns a stream for writing the specified entry to the archive. * * @note This method is only available in write and append mode. * * @note The returned stream conforms to @ref OFReadyForWritingObserving if the * underlying stream does so, too. * * @warning Calling @ref streamForWritingEntry: will invalidate all streams * previously returned by @ref streamForReadingFile: or * @ref streamForWritingEntry:! Reading from or writing to an * invalidated stream will throw an @ref OFReadFailedException or * @ref OFWriteFailedException! * * @param entry The entry to write to the archive.@n * The following parts of the specified entry will be ignored: * * The lower 8 bits of the version made by. * * The lower 8 bits of the minimum version needed. * * The compressed size. * * The uncompressed size. * * The CRC32. * * Bit 3 and 11 of the general purpose bit flag. * @return A stream for writing the specified entry to the archive * @throw OFNotOpenException The archive is not open * @throw OFInvalidArgumentException The archive is not in write mode * @throw OFOpenItemFailedException Opening the specified file within the * archive failed. If * @ref OFOpenItemFailedException#errNo is * `EEXIST`, it failed because there is * already a file with the same name in the * archive. * @throw OFNotImplementedException The desired compression method is not * implemented */ - (OFStream *)streamForWritingEntry: (OFZIPArchiveEntry *)entry; /** * @brief Closes the OFZIPArchive. * * @throw OFNotOpenException The archive is not open */ - (void)close; @end #ifdef __cplusplus extern "C" { #endif extern uint32_t _OFZIPArchiveReadField32(const uint8_t *_Nonnull *_Nonnull, uint16_t *_Nonnull) OF_VISIBILITY_HIDDEN; extern uint64_t _OFZIPArchiveReadField64(const uint8_t *_Nonnull *_Nonnull, uint16_t *_Nonnull) OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFZIPArchive.m000066400000000000000000000704051465614216400160030ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #define OF_ZIP_ARCHIVE_M #include "config.h" #include #import "OFZIPArchive.h" #import "OFZIPArchiveEntry.h" #import "OFZIPArchiveEntry+Private.h" #import "OFArchiveIRIHandler.h" #import "OFArray.h" #import "OFCRC32.h" #import "OFData.h" #import "OFDictionary.h" #import "OFIRI.h" #import "OFIRIHandler.h" #import "OFInflate64Stream.h" #import "OFInflateStream.h" #import "OFSeekableStream.h" #import "OFStream.h" #import "OFChecksumMismatchException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfRangeException.h" #import "OFSeekFailedException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedVersionException.h" #import "OFWriteFailedException.h" /* * TODO: Current limitations: * - Encrypted files cannot be read. */ enum { modeRead, modeWrite, modeAppend }; OF_DIRECT_MEMBERS @interface OFZIPArchive () - (void)of_readZIPInfo; - (void)of_readEntries; - (void)of_writeCentralDirectory; @end OF_DIRECT_MEMBERS @interface OFZIPArchiveLocalFileHeader: OFObject { @public uint16_t _minVersionNeeded, _generalPurposeBitFlag, _compressionMethod; uint16_t _lastModifiedFileTime, _lastModifiedFileDate; uint32_t _CRC32; uint64_t _compressedSize, _uncompressedSize; OFString *_fileName; OFData *_extraField; } - (instancetype)initWithStream: (OFStream *)stream; - (bool)matchesEntry: (OFZIPArchiveEntry *)entry; @end OF_DIRECT_MEMBERS @interface OFZIPArchiveFileReadStream: OFStream { OFZIPArchive *_archive; OFZIPArchiveEntryCompressionMethod _compressionMethod; OF_KINDOF(OFStream *) _decompressedStream; OFZIPArchiveEntry *_entry; unsigned long long _toRead; uint32_t _CRC32; bool _atEndOfStream; } - (instancetype)of_initWithArchive: (OFZIPArchive *)archive stream: (OFStream *)stream entry: (OFZIPArchiveEntry *)entry; @end OF_DIRECT_MEMBERS @interface OFZIPArchiveFileWriteStream: OFStream { OFZIPArchive *_archive; OF_KINDOF(OFStream *) _stream; uint32_t _CRC32; OFStreamOffset _CRC32Offset, _size64Offset; @public unsigned long long _bytesWritten; OFMutableZIPArchiveEntry *_entry; } - (instancetype)of_initWithArchive: (OFZIPArchive *)archive stream: (OFStream *)stream entry: (OFMutableZIPArchiveEntry *)entry CRC32Offset: (OFStreamOffset)CRC32Offset size64Offset: (OFStreamOffset)size64Offset; @end uint32_t _OFZIPArchiveReadField32(const uint8_t **data, uint16_t *size) { uint32_t field = 0; if (*size < 4) @throw [OFInvalidFormatException exception]; for (uint8_t i = 0; i < 4; i++) field |= (uint32_t)(*data)[i] << (i * 8); *data += 4; *size -= 4; return field; } uint64_t _OFZIPArchiveReadField64(const uint8_t **data, uint16_t *size) { uint64_t field = 0; if (*size < 8) @throw [OFInvalidFormatException exception]; for (uint8_t i = 0; i < 8; i++) field |= (uint64_t)(*data)[i] << (i * 8); *data += 8; *size -= 8; return field; } @implementation OFZIPArchive @synthesize delegate = _delegate, archiveComment = _archiveComment; static void seekOrThrowInvalidFormat(OFZIPArchive *archive, const uint32_t *diskNumber, OFStreamOffset offset, OFSeekWhence whence) { if (diskNumber != NULL && *diskNumber != archive->_diskNumber) { OFStream *oldStream = archive->_stream; OFSeekableStream *stream; if (archive->_mode != modeRead || *diskNumber > archive->_lastDiskNumber) @throw [OFInvalidFormatException exception]; stream = [archive->_delegate archive: archive wantsPartNumbered: *diskNumber lastPartNumber: archive->_lastDiskNumber]; if (stream == nil) @throw [OFInvalidFormatException exception]; archive->_diskNumber = *diskNumber; archive->_stream = [stream retain]; [oldStream release]; } @try { [archive->_stream seekToOffset: offset whence: whence]; } @catch (OFSeekFailedException *e) { if (e.errNo == EINVAL) @throw [OFInvalidFormatException exception]; @throw e; } } + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode { return [[[self alloc] initWithStream: stream mode: mode] autorelease]; } + (instancetype)archiveWithIRI: (OFIRI *)IRI mode: (OFString *)mode { return [[[self alloc] initWithIRI: IRI mode: mode] autorelease]; } + (OFIRI *)IRIForFilePath: (OFString *)path inArchiveWithIRI: (OFIRI *)IRI { return _OFArchiveIRIHandlerIRIForFileInArchive(@"zip", path, IRI); } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode { self = [super init]; @try { if ([mode isEqual: @"r"]) _mode = modeRead; else if ([mode isEqual: @"w"]) _mode = modeWrite; else if ([mode isEqual: @"a"]) _mode = modeAppend; else @throw [OFInvalidArgumentException exception]; _stream = [stream retain]; _entries = [[OFMutableArray alloc] init]; _pathToEntryMap = [[OFMutableDictionary alloc] init]; if (_mode == modeRead || _mode == modeAppend) { if (![stream isKindOfClass: [OFSeekableStream class]]) @throw [OFInvalidArgumentException exception]; [self of_readZIPInfo]; [self of_readEntries]; } if (_mode == modeAppend) { _offset = _centralDirectoryOffset; seekOrThrowInvalidFormat(self, NULL, (OFStreamOffset)_offset, OFSeekSet); } } @catch (id e) { /* * If we are in write or append mode, we do not want -[close] * to write anything to it on error - after all, it might not * be a ZIP file which we would destroy otherwise. */ [_stream release]; _stream = nil; [self release]; @throw e; } return self; } - (instancetype)initWithIRI: (OFIRI *)IRI mode: (OFString *)mode { void *pool = objc_autoreleasePoolPush(); OFStream *stream; @try { if ([mode isEqual: @"a"]) stream = [OFIRIHandler openItemAtIRI: IRI mode: @"r+"]; else stream = [OFIRIHandler openItemAtIRI: IRI mode: mode]; } @catch (id e) { [self release]; @throw e; } self = [self initWithStream: stream mode: mode]; objc_autoreleasePoolPop(pool); return self; } - (void)dealloc { if (_stream != nil) [self close]; [_stream release]; [_archiveComment release]; [_entries release]; [_pathToEntryMap release]; [super dealloc]; } - (void)of_readZIPInfo { void *pool = objc_autoreleasePoolPush(); uint16_t commentLength; OFStreamOffset offset = -22; bool valid = false; do { seekOrThrowInvalidFormat(self, NULL, offset, OFSeekEnd); if ([_stream readLittleEndianInt32] == 0x06054B50) { valid = true; break; } } while (--offset >= -65557); if (!valid) @throw [OFInvalidFormatException exception]; _diskNumber = _lastDiskNumber = [_stream readLittleEndianInt16]; _centralDirectoryDisk = [_stream readLittleEndianInt16]; _centralDirectoryEntriesInDisk = [_stream readLittleEndianInt16]; _centralDirectoryEntries = [_stream readLittleEndianInt16]; _centralDirectorySize = [_stream readLittleEndianInt32]; _centralDirectoryOffset = [_stream readLittleEndianInt32]; commentLength = [_stream readLittleEndianInt16]; _archiveComment = [[_stream readStringWithLength: commentLength encoding: OFStringEncodingCodepage437] copy]; if (_lastDiskNumber == 0xFFFF || _centralDirectoryDisk == 0xFFFF || _centralDirectoryEntriesInDisk == 0xFFFF || _centralDirectoryEntries == 0xFFFF || _centralDirectorySize == 0xFFFFFFFF || _centralDirectoryOffset == 0xFFFFFFFF) { uint32_t diskNumber; int64_t offset64; uint64_t size; seekOrThrowInvalidFormat(self, NULL, offset - 20, OFSeekEnd); if ([_stream readLittleEndianInt32] != 0x07064B50) { objc_autoreleasePoolPop(pool); return; } /* * FIXME: Handle number of the disk containing ZIP64 end of * central directory record. */ diskNumber = [_stream readLittleEndianInt32]; offset64 = [_stream readLittleEndianInt64]; _diskNumber = _lastDiskNumber = [_stream readLittleEndianInt32]; if (offset64 < 0 || (OFStreamOffset)offset64 != offset64) @throw [OFOutOfRangeException exception]; seekOrThrowInvalidFormat(self, &diskNumber, (OFStreamOffset)offset64, OFSeekSet); if ([_stream readLittleEndianInt32] != 0x06064B50) @throw [OFInvalidFormatException exception]; size = [_stream readLittleEndianInt64]; if (size < 44) @throw [OFInvalidFormatException exception]; /* version made by */ [_stream readLittleEndianInt16]; /* version needed to extract */ [_stream readLittleEndianInt16]; diskNumber = [_stream readLittleEndianInt32]; if (diskNumber != _diskNumber) @throw [OFInvalidFormatException exception]; _centralDirectoryDisk = [_stream readLittleEndianInt32]; _centralDirectoryEntriesInDisk = [_stream readLittleEndianInt64]; _centralDirectoryEntries = [_stream readLittleEndianInt64]; _centralDirectorySize = [_stream readLittleEndianInt64]; _centralDirectoryOffset = [_stream readLittleEndianInt64]; if (_centralDirectoryOffset < 0 || (OFStreamOffset)_centralDirectoryOffset != _centralDirectoryOffset) @throw [OFOutOfRangeException exception]; } objc_autoreleasePoolPop(pool); } - (void)of_readEntries { void *pool = objc_autoreleasePoolPush(); if (_centralDirectoryOffset < 0 || (OFStreamOffset)_centralDirectoryOffset != _centralDirectoryOffset) @throw [OFOutOfRangeException exception]; seekOrThrowInvalidFormat(self, &_centralDirectoryDisk, (OFStreamOffset)_centralDirectoryOffset, OFSeekSet); for (size_t i = 0; i < _centralDirectoryEntries; i++) { OFZIPArchiveEntry *entry; char buffer; /* * The stream might have 0 bytes left to read, but might not * realize that before a read is attempted, where it will then * return a length of 0. But OFZIPArchiveEntry expects to be * able to read the entire entry and will then throw an * OFTruncatedDataException. Therefore, try to peek one byte to * make sure the stream realizes that it's at the end. */ if ([_stream readIntoBuffer: &buffer length: 1] == 1) [_stream unreadFromBuffer: &buffer length: 1]; if ([_stream isAtEndOfStream]) { OFStream *oldStream = _stream; OFSeekableStream *stream; if (_diskNumber >= _lastDiskNumber) @throw [OFTruncatedDataException exception]; stream = [_delegate archive: self wantsPartNumbered: _diskNumber + 1 lastPartNumber: _lastDiskNumber]; if (stream == nil) @throw [OFInvalidFormatException exception]; _diskNumber++; _stream = [stream retain]; [oldStream release]; } entry = [[[OFZIPArchiveEntry alloc] of_initWithStream: _stream] autorelease]; if ([_pathToEntryMap objectForKey: entry.fileName] != nil) @throw [OFInvalidFormatException exception]; [_entries addObject: entry]; [_pathToEntryMap setObject: entry forKey: entry.fileName]; } objc_autoreleasePoolPop(pool); } - (OFArray *)entries { return [[_entries copy] autorelease]; } - (OFString *)archiveComment { return _archiveComment; } - (void)setArchiveComment: (OFString *)comment { void *pool = objc_autoreleasePoolPush(); OFString *old; if (comment.UTF8StringLength > UINT16_MAX) @throw [OFOutOfRangeException exception]; old = _archiveComment; _archiveComment = [comment copy]; [old release]; objc_autoreleasePoolPop(pool); } - (OFStream *)streamForReadingFile: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFZIPArchiveEntry *entry; OFZIPArchiveLocalFileHeader *localFileHeader; uint32_t startDiskNumber; int64_t offset64; if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (_mode != modeRead) @throw [OFInvalidArgumentException exception]; if ((entry = [_pathToEntryMap objectForKey: path]) == nil) @throw [OFOpenItemFailedException exceptionWithPath: path mode: @"r" errNo: ENOENT]; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } _lastReturnedStream = nil; startDiskNumber = entry.of_startDiskNumber; offset64 = entry.of_localFileHeaderOffset; if (offset64 < 0 || (OFStreamOffset)offset64 != offset64) @throw [OFOutOfRangeException exception]; seekOrThrowInvalidFormat(self, &startDiskNumber, (OFStreamOffset)offset64, OFSeekSet); localFileHeader = [[[OFZIPArchiveLocalFileHeader alloc] initWithStream: _stream] autorelease]; if (![localFileHeader matchesEntry: entry]) @throw [OFInvalidFormatException exception]; if ((localFileHeader->_minVersionNeeded & 0xFF) > 45) { OFString *version = [OFString stringWithFormat: @"%u.%u", (localFileHeader->_minVersionNeeded & 0xFF) / 10, (localFileHeader->_minVersionNeeded & 0xFF) % 10]; @throw [OFUnsupportedVersionException exceptionWithVersion: version]; } objc_autoreleasePoolPop(pool); _lastReturnedStream = [[[OFZIPArchiveFileReadStream alloc] of_initWithArchive: self stream: _stream entry: entry] autorelease]; return _lastReturnedStream; } - (OFStream *)streamForWritingEntry: (OFZIPArchiveEntry *)entry_ { int64_t offsetAdd = 0; void *pool; OFMutableZIPArchiveEntry *entry; OFString *fileName; bool seekable; OFStreamOffset CRC32Offset = 0, size64Offset = 0; OFData *extraField; uint16_t fileNameLength, extraFieldLength; if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (_mode != modeWrite && _mode != modeAppend) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); entry = [[entry_ mutableCopy] autorelease]; if ([_pathToEntryMap objectForKey: entry.fileName] != nil) @throw [OFOpenItemFailedException exceptionWithPath: entry.fileName mode: @"w" errNo: EEXIST]; if (entry.compressionMethod != OFZIPArchiveEntryCompressionMethodNone) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } _lastReturnedStream = nil; fileName = entry.fileName; fileNameLength = fileName.UTF8StringLength; extraField = entry.extraField; extraFieldLength = extraField.count; if (UINT16_MAX - extraFieldLength < 20) @throw [OFOutOfRangeException exception]; seekable = [_stream isKindOfClass: [OFSeekableStream class]]; entry.versionMadeBy = (entry.versionMadeBy & 0xFF00) | 45; entry.minVersionNeeded = (entry.minVersionNeeded & 0xFF00) | 45; entry.compressedSize = 0; entry.uncompressedSize = 0; entry.CRC32 = 0; entry.generalPurposeBitFlag |= (seekable ? 0 : (1u << 3)) | (1u << 11); entry.of_startDiskNumber = _diskNumber; entry.of_localFileHeaderOffset = _offset; [_stream writeLittleEndianInt32: 0x04034B50]; [_stream writeLittleEndianInt16: entry.minVersionNeeded]; [_stream writeLittleEndianInt16: entry.generalPurposeBitFlag]; [_stream writeLittleEndianInt16: entry.compressionMethod]; [_stream writeLittleEndianInt16: entry.of_lastModifiedFileTime]; [_stream writeLittleEndianInt16: entry.of_lastModifiedFileDate]; /* Written later or data descriptor used instead */ if (seekable) CRC32Offset = [_stream seekToOffset: 0 whence: OFSeekCurrent]; [_stream writeLittleEndianInt32: 0]; /* We use ZIP64 */ [_stream writeLittleEndianInt32: 0xFFFFFFFF]; [_stream writeLittleEndianInt32: 0xFFFFFFFF]; [_stream writeLittleEndianInt16: fileNameLength]; [_stream writeLittleEndianInt16: extraFieldLength + 20]; offsetAdd += 4 + (5 * 2) + (3 * 4) + (2 * 2); [_stream writeString: fileName]; offsetAdd += fileNameLength; [_stream writeLittleEndianInt16: OFZIPArchiveEntryExtraFieldTagZIP64]; [_stream writeLittleEndianInt16: 16]; /* Written later or data descriptor used instead */ if (seekable) size64Offset = [_stream seekToOffset: 0 whence: OFSeekCurrent]; [_stream writeLittleEndianInt64: 0]; [_stream writeLittleEndianInt64: 0]; offsetAdd += (2 * 2) + (2 * 8); if (extraField != nil) [_stream writeData: extraField]; offsetAdd += extraFieldLength; if (INT64_MAX - _offset < offsetAdd) @throw [OFOutOfRangeException exception]; _offset += offsetAdd; _lastReturnedStream = [[OFZIPArchiveFileWriteStream alloc] of_initWithArchive: self stream: _stream entry: entry CRC32Offset: CRC32Offset size64Offset: size64Offset]; objc_autoreleasePoolPop(pool); return [_lastReturnedStream autorelease]; } - (void)of_writeCentralDirectory { void *pool = objc_autoreleasePoolPush(); _centralDirectoryEntries = 0; _centralDirectoryEntriesInDisk = 0; _centralDirectorySize = 0; _centralDirectoryOffset = _offset; for (OFZIPArchiveEntry *entry in _entries) { _centralDirectorySize += [entry of_writeToStream: _stream]; _centralDirectoryEntries++; _centralDirectoryEntriesInDisk++; } /* ZIP64 end of central directory */ [_stream writeLittleEndianInt32: 0x06064B50]; [_stream writeLittleEndianInt64: 44]; /* Remaining size */ [_stream writeLittleEndianInt16: 45]; /* Version made by */ [_stream writeLittleEndianInt16: 45]; /* Version required */ [_stream writeLittleEndianInt32: _diskNumber]; [_stream writeLittleEndianInt32: _centralDirectoryDisk]; [_stream writeLittleEndianInt64: _centralDirectoryEntriesInDisk]; [_stream writeLittleEndianInt64: _centralDirectoryEntries]; [_stream writeLittleEndianInt64: _centralDirectorySize]; [_stream writeLittleEndianInt64: _centralDirectoryOffset]; /* ZIP64 end of central directory locator */ [_stream writeLittleEndianInt32: 0x07064B50]; [_stream writeLittleEndianInt32: _diskNumber]; [_stream writeLittleEndianInt64: _centralDirectoryOffset + _centralDirectorySize]; [_stream writeLittleEndianInt32: 0]; /* Total number of disks */ /* End of central directory */ [_stream writeLittleEndianInt32: 0x06054B50]; [_stream writeLittleEndianInt16: 0xFFFF]; /* Disk number */ [_stream writeLittleEndianInt16: 0xFFFF]; /* CD disk */ [_stream writeLittleEndianInt16: 0xFFFF]; /* CD entries in disk */ [_stream writeLittleEndianInt16: 0xFFFF]; /* CD entries */ [_stream writeLittleEndianInt32: 0xFFFFFFFF]; /* CD size */ [_stream writeLittleEndianInt32: 0xFFFFFFFF]; /* CD offset */ [_stream writeLittleEndianInt16: _archiveComment.UTF8StringLength]; if (_archiveComment != nil) [_stream writeString: _archiveComment]; objc_autoreleasePoolPop(pool); } - (void)close { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } _lastReturnedStream = nil; if (_mode == modeWrite || _mode == modeAppend) [self of_writeCentralDirectory]; [_stream release]; _stream = nil; } @end @implementation OFZIPArchiveLocalFileHeader - (instancetype)initWithStream: (OFStream *)stream { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFMutableData *extraField = nil; uint16_t fileNameLength, extraFieldLength; OFStringEncoding encoding; size_t ZIP64Index; uint16_t ZIP64Size; if ([stream readLittleEndianInt32] != 0x04034B50) @throw [OFInvalidFormatException exception]; _minVersionNeeded = [stream readLittleEndianInt16]; _generalPurposeBitFlag = [stream readLittleEndianInt16]; _compressionMethod = [stream readLittleEndianInt16]; _lastModifiedFileTime = [stream readLittleEndianInt16]; _lastModifiedFileDate = [stream readLittleEndianInt16]; _CRC32 = [stream readLittleEndianInt32]; _compressedSize = [stream readLittleEndianInt32]; _uncompressedSize = [stream readLittleEndianInt32]; fileNameLength = [stream readLittleEndianInt16]; extraFieldLength = [stream readLittleEndianInt16]; encoding = (_generalPurposeBitFlag & (1u << 11) ? OFStringEncodingUTF8 : OFStringEncodingCodepage437); _fileName = [[stream readStringWithLength: fileNameLength encoding: encoding] copy]; if (extraFieldLength > 0) extraField = [[[stream readDataWithCount: extraFieldLength] mutableCopy] autorelease]; ZIP64Index = OFZIPArchiveEntryExtraFieldFind(extraField, OFZIPArchiveEntryExtraFieldTagZIP64, &ZIP64Size); if (ZIP64Index != OFNotFound) { const uint8_t *ZIP64 = [extraField itemAtIndex: ZIP64Index]; OFRange range = OFMakeRange(ZIP64Index - 4, ZIP64Size + 4); if (_uncompressedSize == 0xFFFFFFFF) _uncompressedSize = _OFZIPArchiveReadField64( &ZIP64, &ZIP64Size); if (_compressedSize == 0xFFFFFFFF) _compressedSize = _OFZIPArchiveReadField64( &ZIP64, &ZIP64Size); if (ZIP64Size > 0) @throw [OFInvalidFormatException exception]; [extraField removeItemsInRange: range]; } if (extraField.count > 0) { [extraField makeImmutable]; _extraField = [extraField copy]; } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_fileName release]; [_extraField release]; [super dealloc]; } - (bool)matchesEntry: (OFZIPArchiveEntry *)entry { if (_compressionMethod != entry.compressionMethod || _lastModifiedFileTime != entry.of_lastModifiedFileTime || _lastModifiedFileDate != entry.of_lastModifiedFileDate) return false; if (!(_generalPurposeBitFlag & (1u << 3))) if (_CRC32 != entry.CRC32 || _compressedSize != entry.compressedSize || _uncompressedSize != entry.uncompressedSize) return false; if (![_fileName isEqual: entry.fileName]) return false; return true; } @end @implementation OFZIPArchiveFileReadStream - (instancetype)of_initWithArchive: (OFZIPArchive *)archive stream: (OFStream *)stream entry: (OFZIPArchiveEntry *)entry { self = [super init]; @try { _archive = [archive retain]; _compressionMethod = entry.compressionMethod; switch (_compressionMethod) { case OFZIPArchiveEntryCompressionMethodNone: _decompressedStream = [_archive->_stream retain]; break; case OFZIPArchiveEntryCompressionMethodDeflate: _decompressedStream = [[OFInflateStream alloc] initWithStream: _archive->_stream]; break; case OFZIPArchiveEntryCompressionMethodDeflate64: _decompressedStream = [[OFInflate64Stream alloc] initWithStream: _archive->_stream]; break; default: @throw [OFNotImplementedException exceptionWithSelector: _cmd object: nil]; } _entry = [entry copy]; _toRead = entry.uncompressedSize; _CRC32 = ~0; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_decompressedStream != nil) [self close]; [_entry release]; if (_archive->_lastReturnedStream == self) _archive->_lastReturnedStream = nil; [_archive release]; [super dealloc]; } - (bool)lowlevelIsAtEndOfStream { if (_decompressedStream == nil) @throw [OFNotOpenException exceptionWithObject: self]; return _atEndOfStream; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { size_t ret; if (_decompressedStream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (_atEndOfStream) return 0; if ([_archive->_stream isAtEndOfStream] && ![_decompressedStream hasDataInReadBuffer]) { OFStream *oldStream = _archive->_stream, *oldDecompressedStream; OFSeekableStream *stream; if (_archive->_diskNumber >= _archive->_lastDiskNumber) @throw [OFTruncatedDataException exception]; stream = [_archive->_delegate archive: _archive wantsPartNumbered: _archive->_diskNumber + 1 lastPartNumber: _archive->_lastDiskNumber]; if (stream == nil) @throw [OFInvalidFormatException exception]; _archive->_diskNumber++; _archive->_stream = [stream retain]; [oldStream release]; switch (_compressionMethod) { case OFZIPArchiveEntryCompressionMethodNone: oldDecompressedStream = _decompressedStream; _decompressedStream = [_archive->_stream retain]; [oldDecompressedStream release]; break; case OFZIPArchiveEntryCompressionMethodDeflate: case OFZIPArchiveEntryCompressionMethodDeflate64: [_decompressedStream setUnderlyingStream: _archive->_stream]; break; default: @throw [OFNotImplementedException exceptionWithSelector: _cmd object: nil]; } } #if SIZE_MAX >= UINT64_MAX if (length > UINT64_MAX) @throw [OFOutOfRangeException exception]; #endif if (length > _toRead) length = (size_t)_toRead; ret = [_decompressedStream readIntoBuffer: buffer length: length]; _toRead -= ret; _CRC32 = _OFCRC32(_CRC32, buffer, ret); if (_toRead == 0) { _atEndOfStream = true; if (~_CRC32 != _entry.CRC32) { OFString *actualChecksum = [OFString stringWithFormat: @"%08" PRIX32, ~_CRC32]; OFString *expectedChecksum = [OFString stringWithFormat: @"%08" PRIX32, _entry.CRC32]; @throw [OFChecksumMismatchException exceptionWithActualChecksum: actualChecksum expectedChecksum: expectedChecksum]; } } return ret; } - (bool)lowlevelHasDataInReadBuffer { return ((OFStream *)_decompressedStream).hasDataInReadBuffer; } - (int)fileDescriptorForReading { return ((id )_decompressedStream) .fileDescriptorForReading; } - (void)close { if (_decompressedStream == nil) @throw [OFNotOpenException exceptionWithObject: self]; [_decompressedStream release]; _decompressedStream = nil; [super close]; } @end @implementation OFZIPArchiveFileWriteStream - (instancetype)of_initWithArchive: (OFZIPArchive *)archive stream: (OFStream *)stream entry: (OFMutableZIPArchiveEntry *)entry CRC32Offset: (OFStreamOffset)CRC32Offset size64Offset: (OFStreamOffset)size64Offset { self = [super init]; _archive = [archive retain]; _stream = [stream retain]; _entry = [entry retain]; _CRC32 = ~0; _CRC32Offset = CRC32Offset; _size64Offset = size64Offset; return self; } - (void)dealloc { if (_stream != nil) [self close]; [_entry release]; if (_archive->_lastReturnedStream == self) _archive->_lastReturnedStream = nil; [_archive release]; [super dealloc]; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { #if SIZE_MAX >= INT64_MAX if (length > INT64_MAX) @throw [OFOutOfRangeException exception]; #endif if (ULLONG_MAX - _bytesWritten < length) @throw [OFOutOfRangeException exception]; @try { [_stream writeBuffer: buffer length: length]; } @catch (OFWriteFailedException *e) { OFEnsure(e.bytesWritten <= length); _bytesWritten += (unsigned long long)e.bytesWritten; _CRC32 = _OFCRC32(_CRC32, buffer, e.bytesWritten); if (e.errNo == EWOULDBLOCK || e.errNo == EAGAIN) return e.bytesWritten; @throw e; } _bytesWritten += (unsigned long long)length; _CRC32 = _OFCRC32(_CRC32, buffer, length); return length; } - (void)close { bool seekable; if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (_bytesWritten > UINT64_MAX) @throw [OFOutOfRangeException exception]; seekable = [_stream isKindOfClass: [OFSeekableStream class]]; if (seekable) { OFStreamOffset offset = [_stream seekToOffset: 0 whence: OFSeekCurrent]; [_stream seekToOffset: _CRC32Offset whence: OFSeekSet]; [_stream writeLittleEndianInt32: ~_CRC32]; [_stream seekToOffset: _size64Offset whence: OFSeekSet]; [_stream writeLittleEndianInt64: (uint64_t)_bytesWritten]; [_stream writeLittleEndianInt64: (uint64_t)_bytesWritten]; [_stream seekToOffset: offset whence: OFSeekSet]; } else { [_stream writeLittleEndianInt32: 0x08074B50]; [_stream writeLittleEndianInt32: ~_CRC32]; [_stream writeLittleEndianInt64: (uint64_t)_bytesWritten]; [_stream writeLittleEndianInt64: (uint64_t)_bytesWritten]; } [_stream release]; _stream = nil; _entry.CRC32 = ~_CRC32; _entry.compressedSize = _bytesWritten; _entry.uncompressedSize = _bytesWritten; [_entry makeImmutable]; if (!seekable) _bytesWritten += (2 * 4 + 2 * 8); [_archive->_entries addObject: _entry]; [_archive->_pathToEntryMap setObject: _entry forKey: _entry.fileName]; if (ULLONG_MAX - _archive->_offset < _bytesWritten) @throw [OFOutOfRangeException exception]; _archive->_offset += _bytesWritten; [super close]; } @end objfw-1.1.6/src/OFZIPArchiveEntry+Private.h000066400000000000000000000027541465614216400204300ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFZIPArchive.h" OF_ASSUME_NONNULL_BEGIN @interface OFZIPArchiveEntry () @property (readonly, nonatomic) uint16_t of_lastModifiedFileTime, of_lastModifiedFileDate; @property (readonly, nonatomic) uint32_t of_startDiskNumber; @property (readonly, nonatomic) int64_t of_localFileHeaderOffset; - (instancetype)of_init OF_METHOD_FAMILY(init); - (instancetype)of_initWithStream: (OFStream *)stream OF_METHOD_FAMILY(init) OF_DIRECT; - (uint64_t)of_writeToStream: (OFStream *)stream OF_DIRECT; @end @interface OFMutableZIPArchiveEntry () @property (readwrite, nonatomic, setter=of_setStartDiskNumber:) uint32_t of_startDiskNumber; @property (readwrite, nonatomic, setter=of_setLocalFileHeaderOffset:) int64_t of_localFileHeaderOffset; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFZIPArchiveEntry.h000066400000000000000000000163711465614216400170220ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFArchiveEntry.h" OF_ASSUME_NONNULL_BEGIN /** @file */ typedef enum { OFZIPArchiveEntryCompressionMethodNone = 0, OFZIPArchiveEntryCompressionMethodShrink = 1, OFZIPArchiveEntryCompressionMethodReduceFactor1 = 2, OFZIPArchiveEntryCompressionMethodReduceFactor2 = 3, OFZIPArchiveEntryCompressionMethodReduceFactor3 = 4, OFZIPArchiveEntryCompressionMethodReduceFactor4 = 5, OFZIPArchiveEntryCompressionMethodImplode = 6, OFZIPArchiveEntryCompressionMethodDeflate = 8, OFZIPArchiveEntryCompressionMethodDeflate64 = 9, OFZIPArchiveEntryCompressionMethodBZIP2 = 12, OFZIPArchiveEntryCompressionMethodLZMA = 14, OFZIPArchiveEntryCompressionMethodWavPack = 97, OFZIPArchiveEntryCompressionMethodPPMd = 98 } OFZIPArchiveEntryCompressionMethod; /** * @brief Attribute compatibility part of ZIP versions. */ typedef enum { /** MS-DOS and OS/2 */ OFZIPArchiveEntryAttributeCompatibilityMSDOS = 0, /** Amiga */ OFZIPArchiveEntryAttributeCompatibilityAmiga = 1, /** OpenVMS */ OFZIPArchiveEntryAttributeCompatibilityOpenVMS = 2, /** UNIX */ OFZIPArchiveEntryAttributeCompatibilityUNIX = 3, /** VM/CMS */ OFZIPArchiveEntryAttributeCompatibilityVM_CMS = 4, /** Atari ST */ OFZIPArchiveEntryAttributeCompatibilityAtariST = 5, /** OS/2 HPFS */ OFZIPArchiveEntryAttributeCompatibilityOS2HPFS = 6, /** Macintosh */ OFZIPArchiveEntryAttributeCompatibilityMacintosh = 7, /** Z-System */ OFZIPArchiveEntryAttributeCompatibilityZSystem = 8, /** CP/M */ OFZIPArchiveEntryAttributeCompatibilityCPM = 9, /** Windows NTFS */ OFZIPArchiveEntryAttributeCompatibilityWindowsNTFS = 10, /** MVS (OS/390 - Z/OS) */ OFZIPArchiveEntryAttributeCompatibilityMVS = 11, /** VSE */ OFZIPArchiveEntryAttributeCompatibilityVSE = 12, /** Acorn RISC OS */ OFZIPArchiveEntryAttributeCompatibilityAcornRISCOS = 13, /** VFAT */ OFZIPArchiveEntryAttributeCompatibilityVFAT = 14, /** Alternate MVS */ OFZIPArchiveEntryAttributeCompatibilityAlternateMVS = 15, /** BeOS */ OFZIPArchiveEntryAttributeCompatibilityBeOS = 16, /** Tandem */ OFZIPArchiveEntryAttributeCompatibilityTandem = 17, /** OS/400 */ OFZIPArchiveEntryAttributeCompatibilityOS400 = 18, /** OS X (Darwin) */ OFZIPArchiveEntryAttributeCompatibilityOSX = 19 } OFZIPArchiveEntryAttributeCompatibility; /** * @brief Tags for the extra field. */ typedef enum { /** ZIP64 extra field tag */ OFZIPArchiveEntryExtraFieldTagZIP64 = 0x0001 } OFZIPArchiveEntryExtraFieldTag; @class OFString; @class OFData; @class OFFile; @class OFDate; /** * @class OFZIPArchiveEntry OFZIPArchiveEntry.h ObjFW/OFZIPArchiveEntry.h * * @brief A class which represents an entry in the central directory of a ZIP * archive. */ @interface OFZIPArchiveEntry: OFObject { OFZIPArchiveEntryAttributeCompatibility _versionMadeBy; OFZIPArchiveEntryAttributeCompatibility _minVersionNeeded; uint16_t _generalPurposeBitFlag; OFZIPArchiveEntryCompressionMethod _compressionMethod; uint16_t _lastModifiedFileTime, _lastModifiedFileDate; uint32_t _CRC32; unsigned long long _compressedSize, _uncompressedSize; OFString *_fileName; OFData *_Nullable _extraField; OFString *_Nullable _fileComment; uint32_t _startDiskNumber; uint16_t _internalAttributes; uint32_t _versionSpecificAttributes; int64_t _localFileHeaderOffset; OF_RESERVE_IVARS(OFZIPArchiveEntry, 4) } /** * @brief The extra field of the entry. * * The item size *must* be 1! */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFData *extraField; /** * @brief The version which made the entry. * * The lower 8 bits are the ZIP specification version.@n * The upper 8 bits are the attribute compatibility. * See @ref OFZIPArchiveEntryAttributeCompatibility. */ @property (readonly, nonatomic) OFZIPArchiveEntryAttributeCompatibility versionMadeBy; /** * @brief The minimum version required to extract the file. * * The lower 8 bits are the ZIP specification version.@n * The upper 8 bits are the attribute compatibility. * See @ref OFZIPArchiveEntryAttributeCompatibility. */ @property (readonly, nonatomic) OFZIPArchiveEntryAttributeCompatibility minVersionNeeded; /** * @brief The compression method of the entry. * * Supported values are: * Value | Description * --------------------------------------------|--------------- * OFZIPArchiveEntryCompressionMethodNone | No compression * OFZIPArchiveEntryCompressionMethodDeflate | Deflate * OFZIPArchiveEntryCompressionMethodDeflate64 | Deflate64 * * Other values may be returned, but the file cannot be extracted then. */ @property (readonly, nonatomic) OFZIPArchiveEntryCompressionMethod compressionMethod; /** * @brief The CRC32 checksum of the entry's file. */ @property (readonly, nonatomic) uint32_t CRC32; /** * @brief The version specific attributes. * * The meaning of the version specific attributes depends on the attribute * compatibility part of the version that made the entry. */ @property (readonly, nonatomic) uint32_t versionSpecificAttributes; /** * @brief The general purpose bit flag of the entry. * * See the ZIP specification for details. */ @property (readonly, nonatomic) uint16_t generalPurposeBitFlag; - (instancetype)init OF_UNAVAILABLE; @end #ifdef __cplusplus extern "C" { #endif /** * @brief Converts the ZIP entry version to a string. * * @param version The ZIP entry version to convert to a string * @return The ZIP entry version as a string */ extern OFString *OFZIPArchiveEntryVersionToString(uint16_t version); /** * @brief Converts the ZIP entry compression method to a string. * * @param compressionMethod The ZIP entry compression method to convert to a * string * @return The ZIP entry compression method as a string */ extern OFString *OFZIPArchiveEntryCompressionMethodName( OFZIPArchiveEntryCompressionMethod compressionMethod); /** * @brief Gets a pointer to and the size of the extensible data field with the * specified tag. * * @param extraField The extra field to search for an extensible data field with * the specified tag * @param tag The tag to look for * @param size A pointer to an uint16_t that should be set to the size * @return The index at which the extra field content starts in the OFData, or * `OFNotFound` */ extern size_t OFZIPArchiveEntryExtraFieldFind(OFData *extraField, OFZIPArchiveEntryExtraFieldTag tag, uint16_t *size); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END #import "OFMutableZIPArchiveEntry.h" objfw-1.1.6/src/OFZIPArchiveEntry.m000066400000000000000000000327251465614216400170300ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFZIPArchiveEntry.h" #import "OFZIPArchiveEntry+Private.h" #import "OFData.h" #import "OFDate.h" #import "OFStream.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" OFString * OFZIPArchiveEntryVersionToString(uint16_t version) { const char *attrCompat = NULL; switch (version >> 8) { case OFZIPArchiveEntryAttributeCompatibilityMSDOS: attrCompat = "MS-DOS or OS/2"; break; case OFZIPArchiveEntryAttributeCompatibilityAmiga: attrCompat = "Amiga"; break; case OFZIPArchiveEntryAttributeCompatibilityOpenVMS: attrCompat = "OpenVMS"; break; case OFZIPArchiveEntryAttributeCompatibilityUNIX: attrCompat = "UNIX"; break; case OFZIPArchiveEntryAttributeCompatibilityVM_CMS: attrCompat = "VM/CMS"; break; case OFZIPArchiveEntryAttributeCompatibilityAtariST: attrCompat = "Atari ST"; break; case OFZIPArchiveEntryAttributeCompatibilityOS2HPFS: attrCompat = "OS/2 HPFS"; break; case OFZIPArchiveEntryAttributeCompatibilityMacintosh: attrCompat = "Macintosh"; break; case OFZIPArchiveEntryAttributeCompatibilityZSystem: attrCompat = "Z-System"; break; case OFZIPArchiveEntryAttributeCompatibilityCPM: attrCompat = "CP/M"; break; case OFZIPArchiveEntryAttributeCompatibilityWindowsNTFS: attrCompat = "Windows NTFS"; break; case OFZIPArchiveEntryAttributeCompatibilityMVS: attrCompat = "MVS (OS/390 - Z/OS)"; break; case OFZIPArchiveEntryAttributeCompatibilityVSE: attrCompat = "VSE"; break; case OFZIPArchiveEntryAttributeCompatibilityAcornRISCOS: attrCompat = "Acorn RISC OS"; break; case OFZIPArchiveEntryAttributeCompatibilityVFAT: attrCompat = "VFAT"; break; case OFZIPArchiveEntryAttributeCompatibilityAlternateMVS: attrCompat = "Alternate MVS"; break; case OFZIPArchiveEntryAttributeCompatibilityBeOS: attrCompat = "BeOS"; break; case OFZIPArchiveEntryAttributeCompatibilityTandem: attrCompat = "Tandem"; break; case OFZIPArchiveEntryAttributeCompatibilityOS400: attrCompat = "OS/400"; break; case OFZIPArchiveEntryAttributeCompatibilityOSX: attrCompat = "OS X (Darwin)"; break; } if (attrCompat != NULL) return [OFString stringWithFormat: @"%u.%u, %s", (version & 0xFF) / 10, (version & 0xFF) % 10, attrCompat]; else return [OFString stringWithFormat: @"%u.%u, unknown %02X", (version % 0xFF) / 10, (version & 0xFF) % 10, version >> 8]; } OFString * OFZIPArchiveEntryCompressionMethodName( OFZIPArchiveEntryCompressionMethod compressionMethod) { switch (compressionMethod) { case OFZIPArchiveEntryCompressionMethodNone: return @"none"; case OFZIPArchiveEntryCompressionMethodShrink: return @"Shrink"; case OFZIPArchiveEntryCompressionMethodReduceFactor1: return @"Reduce (factor 1)"; case OFZIPArchiveEntryCompressionMethodReduceFactor2: return @"Reduce (factor 2)"; case OFZIPArchiveEntryCompressionMethodReduceFactor3: return @"Reduce (factor 3)"; case OFZIPArchiveEntryCompressionMethodReduceFactor4: return @"Reduce (factor 4)"; case OFZIPArchiveEntryCompressionMethodImplode: return @"Implode"; case OFZIPArchiveEntryCompressionMethodDeflate: return @"Deflate"; case OFZIPArchiveEntryCompressionMethodDeflate64: return @"Deflate64"; case OFZIPArchiveEntryCompressionMethodBZIP2: return @"BZip2"; case OFZIPArchiveEntryCompressionMethodLZMA: return @"LZMA"; case OFZIPArchiveEntryCompressionMethodWavPack: return @"WavPack"; case OFZIPArchiveEntryCompressionMethodPPMd: return @"PPMd"; default: return @"unknown"; } } size_t OFZIPArchiveEntryExtraFieldFind(OFData *extraField, OFZIPArchiveEntryExtraFieldTag tag, uint16_t *size) { const uint8_t *bytes = extraField.items; size_t count = extraField.count; for (size_t i = 0; i < count;) { uint16_t currentTag, currentSize; if (i + 3 >= count) @throw [OFInvalidFormatException exception]; currentTag = (bytes[i + 1] << 8) | bytes[i]; currentSize = (bytes[i + 3] << 8) | bytes[i + 2]; if (i + 3 + currentSize >= count) @throw [OFInvalidFormatException exception]; if (currentTag == tag) { *size = currentSize; return i + 4; } i += 4 + currentSize; } *size = 0; return OFNotFound; } @implementation OFZIPArchiveEntry /* * The following are optional in OFArchiveEntry, but Apple GCC 4.0.1 is buggy * and needs this to stop complaining. */ @dynamic POSIXPermissions, ownerAccountID, groupOwnerAccountID; @dynamic ownerAccountName, groupOwnerAccountName; - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)of_init { return [super init]; } - (instancetype)of_initWithStream: (OFStream *)stream { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFMutableData *extraField = nil; uint16_t fileNameLength, extraFieldLength, fileCommentLength; OFStringEncoding encoding; size_t ZIP64Index; uint16_t ZIP64Size; if ([stream readLittleEndianInt32] != 0x02014B50) @throw [OFInvalidFormatException exception]; _versionMadeBy = [stream readLittleEndianInt16]; _minVersionNeeded = [stream readLittleEndianInt16]; _generalPurposeBitFlag = [stream readLittleEndianInt16]; _compressionMethod = [stream readLittleEndianInt16]; _lastModifiedFileTime = [stream readLittleEndianInt16]; _lastModifiedFileDate = [stream readLittleEndianInt16]; _CRC32 = [stream readLittleEndianInt32]; _compressedSize = [stream readLittleEndianInt32]; _uncompressedSize = [stream readLittleEndianInt32]; fileNameLength = [stream readLittleEndianInt16]; extraFieldLength = [stream readLittleEndianInt16]; fileCommentLength = [stream readLittleEndianInt16]; _startDiskNumber = [stream readLittleEndianInt16]; _internalAttributes = [stream readLittleEndianInt16]; _versionSpecificAttributes = [stream readLittleEndianInt32]; _localFileHeaderOffset = [stream readLittleEndianInt32]; encoding = (_generalPurposeBitFlag & (1u << 11) ? OFStringEncodingUTF8 : OFStringEncodingCodepage437); _fileName = [[stream readStringWithLength: fileNameLength encoding: encoding] copy]; if (extraFieldLength > 0) extraField = [[[stream readDataWithCount: extraFieldLength] mutableCopy] autorelease]; if (fileCommentLength > 0) _fileComment = [[stream readStringWithLength: fileCommentLength encoding: encoding] copy]; ZIP64Index = OFZIPArchiveEntryExtraFieldFind(extraField, OFZIPArchiveEntryExtraFieldTagZIP64, &ZIP64Size); if (ZIP64Index != OFNotFound) { const uint8_t *ZIP64 = [extraField itemAtIndex: ZIP64Index]; OFRange range = OFMakeRange(ZIP64Index - 4, ZIP64Size + 4); if (_uncompressedSize == 0xFFFFFFFF) _uncompressedSize = _OFZIPArchiveReadField64( &ZIP64, &ZIP64Size); if (_compressedSize == 0xFFFFFFFF) _compressedSize = _OFZIPArchiveReadField64( &ZIP64, &ZIP64Size); if (_localFileHeaderOffset == 0xFFFFFFFF) _localFileHeaderOffset = _OFZIPArchiveReadField64(&ZIP64, &ZIP64Size); if (_startDiskNumber == 0xFFFF) _startDiskNumber = _OFZIPArchiveReadField32( &ZIP64, &ZIP64Size); if (ZIP64Size > 0 || _localFileHeaderOffset < 0) @throw [OFInvalidFormatException exception]; [extraField removeItemsInRange: range]; } if (extraField.count > 0) { [extraField makeImmutable]; _extraField = [extraField copy]; } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_fileName release]; [_extraField release]; [_fileComment release]; [super dealloc]; } - (id)copy { return [self retain]; } - (id)mutableCopy { OFZIPArchiveEntry *copy = [[OFMutableZIPArchiveEntry alloc] initWithFileName: _fileName]; @try { copy->_versionMadeBy = _versionMadeBy; copy->_minVersionNeeded = _minVersionNeeded; copy->_generalPurposeBitFlag = _generalPurposeBitFlag; copy->_compressionMethod = _compressionMethod; copy->_lastModifiedFileTime = _lastModifiedFileTime; copy->_lastModifiedFileDate = _lastModifiedFileDate; copy->_CRC32 = _CRC32; copy->_compressedSize = _compressedSize; copy->_uncompressedSize = _uncompressedSize; copy->_extraField = [_extraField copy]; copy->_fileComment = [_extraField copy]; copy->_startDiskNumber = _startDiskNumber; copy->_internalAttributes = _internalAttributes; copy->_versionSpecificAttributes = _versionSpecificAttributes; copy->_localFileHeaderOffset = _localFileHeaderOffset; } @catch (id e) { [copy release]; @throw e; } return copy; } - (OFString *)fileName { return _fileName; } - (OFString *)fileComment { return _fileComment; } - (OFData *)extraField { return _extraField; } - (OFZIPArchiveEntryAttributeCompatibility)versionMadeBy { return _versionMadeBy; } - (OFZIPArchiveEntryAttributeCompatibility)minVersionNeeded { return _minVersionNeeded; } - (OFDate *)modificationDate { void *pool = objc_autoreleasePoolPush(); uint16_t year = ((_lastModifiedFileDate & 0xFE00) >> 9) + 1980; uint8_t month = (_lastModifiedFileDate & 0x1E0) >> 5; uint8_t day = (_lastModifiedFileDate & 0x1F); uint8_t hour = (_lastModifiedFileTime & 0xF800) >> 11; uint8_t minute = (_lastModifiedFileTime & 0x7E0) >> 5; uint8_t second = (_lastModifiedFileTime & 0x1F) << 1; OFDate *date; OFString *dateString; dateString = [OFString stringWithFormat: @"%04u-%02u-%02u %02u:%02u:%02u", year, month, day, hour, minute, second]; date = [[OFDate alloc] initWithLocalDateString: dateString format: @"%Y-%m-%d %H:%M:%S"]; objc_autoreleasePoolPop(pool); return [date autorelease]; } - (OFZIPArchiveEntryCompressionMethod)compressionMethod { return _compressionMethod; } - (unsigned long long)compressedSize { return _compressedSize; } - (unsigned long long)uncompressedSize { return _uncompressedSize; } - (uint32_t)CRC32 { return _CRC32; } - (uint32_t)versionSpecificAttributes { return _versionSpecificAttributes; } - (uint16_t)generalPurposeBitFlag { return _generalPurposeBitFlag; } - (uint16_t)of_lastModifiedFileTime { return _lastModifiedFileTime; } - (uint16_t)of_lastModifiedFileDate { return _lastModifiedFileDate; } - (uint32_t)of_startDiskNumber { return _startDiskNumber; } - (int64_t)of_localFileHeaderOffset { return _localFileHeaderOffset; } - (OFString *)description { void *pool = objc_autoreleasePoolPush(); OFString *compressionMethod = OFZIPArchiveEntryCompressionMethodName(_compressionMethod); OFString *ret = [OFString stringWithFormat: @"<%@:\n" @"\tFile name = %@\n" @"\tFile comment = %@\n" @"\tGeneral purpose bit flag = %u\n" @"\tCompressed size = %llu\n" @"\tUncompressed size = %llu\n" @"\tCompression method = %@\n" @"\tModification date = %@\n" @"\tCRC32 = %08" @PRIX32 @"\n" @"\tExtra field = %@\n" @">", self.class, _fileName, _fileComment, _generalPurposeBitFlag, _compressedSize, _uncompressedSize, compressionMethod, self.modificationDate, _CRC32, _extraField]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (uint64_t)of_writeToStream: (OFStream *)stream { void *pool = objc_autoreleasePoolPush(); uint64_t size = 0; if (UINT16_MAX - _extraField.count < 32) @throw [OFOutOfRangeException exception]; [stream writeLittleEndianInt32: 0x02014B50]; [stream writeLittleEndianInt16: _versionMadeBy]; [stream writeLittleEndianInt16: _minVersionNeeded]; [stream writeLittleEndianInt16: _generalPurposeBitFlag]; [stream writeLittleEndianInt16: _compressionMethod]; [stream writeLittleEndianInt16: _lastModifiedFileTime]; [stream writeLittleEndianInt16: _lastModifiedFileDate]; [stream writeLittleEndianInt32: _CRC32]; [stream writeLittleEndianInt32: 0xFFFFFFFF]; [stream writeLittleEndianInt32: 0xFFFFFFFF]; [stream writeLittleEndianInt16: (uint16_t)_fileName.UTF8StringLength]; [stream writeLittleEndianInt16: (uint16_t)_extraField.count + 32]; [stream writeLittleEndianInt16: (uint16_t)_fileComment.UTF8StringLength]; [stream writeLittleEndianInt16: 0xFFFF]; [stream writeLittleEndianInt16: _internalAttributes]; [stream writeLittleEndianInt32: _versionSpecificAttributes]; [stream writeLittleEndianInt32: 0xFFFFFFFF]; size += (4 + (6 * 2) + (3 * 4) + (5 * 2) + (2 * 4)); [stream writeString: _fileName]; size += (uint64_t)_fileName.UTF8StringLength; [stream writeLittleEndianInt16: OFZIPArchiveEntryExtraFieldTagZIP64]; [stream writeLittleEndianInt16: 28]; [stream writeLittleEndianInt64: _uncompressedSize]; [stream writeLittleEndianInt64: _compressedSize]; [stream writeLittleEndianInt64: _localFileHeaderOffset]; [stream writeLittleEndianInt32: _startDiskNumber]; size += (2 * 2) + (3 * 8) + 4; if (_extraField != nil) [stream writeData: _extraField]; size += (uint64_t)_extraField.count; if (_fileComment != nil) [stream writeString: _fileComment]; size += (uint64_t)_fileComment.UTF8StringLength; objc_autoreleasePoolPop(pool); return size; } @end objfw-1.1.6/src/OFZooArchive.h000066400000000000000000000141321465614216400160760ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFSeekableStream.h" #import "OFString.h" #import "OFZooArchiveEntry.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFZooArchive OFZooArchive.h ObjFW/OFZooArchive.h * * @brief A class for accessing and manipulating Zoo files. */ OF_SUBCLASSING_RESTRICTED @interface OFZooArchive: OFObject { OF_KINDOF(OFStream *) _stream; uint_least8_t _mode; OFStringEncoding _encoding; uint16_t _minVersionNeeded; uint8_t _headerType; OFString *_Nullable _archiveComment; OFZooArchiveEntry *_Nullable _currentEntry; #ifdef OF_ZOO_ARCHIVE_M @public #endif OFStream *_Nullable _lastReturnedStream; @protected OFStreamOffset _lastHeaderOffset; size_t _lastHeaderLength; } /** * @brief The encoding to use for the archive. Defaults to UTF-8. */ @property (nonatomic) OFStringEncoding encoding; /** * @brief The archive comment. */ @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *archiveComment; /** * @brief Creates a new OFZooArchive object with the specified stream. * * @param stream A stream from which the Zoo archive will be read. * This needs to be an OFSeekableStream. For writing, the stream * needs to support both reading and writing at the same time. * @param mode The mode for the Zoo file. Valid modes are "r" for reading and * "w" for creating a new file. * @return A new, autoreleased OFZooArchive */ + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode; /** * @brief Creates a new OFZooArchive object with the specified file. * * @param IRI The IRI to the Zoo file * @param mode The mode for the Zoo file. Valid modes are "r" for reading and * "w" for creating a new file. * @return A new, autoreleased OFZooArchive */ + (instancetype)archiveWithIRI: (OFIRI *)IRI mode: (OFString *)mode; /** * @brief Creates an IRI for accessing the specified file within the specified * Zoo archive. * * @param path The path of the file within the archive * @param IRI The IRI of the archive * @return An IRI for accessing the specified file within the specified Zoo * archive */ + (OFIRI *)IRIForFilePath: (OFString *)path inArchiveWithIRI: (OFIRI *)IRI; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFZooArchive object with the * specified stream. * * @param stream A stream from which the Zoo archive will be read. * This needs to be an OFSeekableStream. For writing, the stream * needs to support both reading and writing at the same time. * @param mode The mode for the Zoo file. Valid modes are "r" for reading and * "w" for creating a new file. * @return An initialized OFZooArchive */ - (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated OFZooArchive object with the * specified file. * * @param IRI The IRI to the Zoo file * @param mode The mode for the Zoo file. Valid modes is "r" for reading and * "w" for creating a new file. * @return An initialized OFZooArchive */ - (instancetype)initWithIRI: (OFIRI *)IRI mode: (OFString *)mode; /** * @brief Returns the next entry from the Zoo archive or `nil` if all entries * have been read. * * @note This is only available in read mode. * * @warning Calling @ref nextEntry will invalidate all streams returned by * @ref streamForReadingCurrentEntry or * @ref streamForWritingEntry:! Reading from or writing to an * invalidated stream will throw an @ref OFReadFailedException or * @ref OFWriteFailedException! * * @return The next entry from the Zoo archive or `nil` if all entries have * been read * @throw OFInvalidFormatException The archive's format is invalid * @throw OFUnsupportedVersionException The archive's format is of an * unsupported version * @throw OFTruncatedDataException The archive was truncated */ - (nullable OFZooArchiveEntry *)nextEntry; /** * @brief Returns a stream for reading the current entry. * * @note This is only available in read mode. * * @note The returned stream conforms to @ref OFReadyForReadingObserving if the * underlying stream does so, too. * * @return A stream for reading the current entry * @throw OFSeekFailedException Seeking to the data in the archive failed */ - (OFStream *)streamForReadingCurrentEntry; /** * @brief Returns a stream for writing the specified entry. * * @note This is only available in write and append mode. * * @note The returned stream conforms to @ref OFReadyForWritingObserving if the * underlying stream does so, too. * * @warning Calling @ref streamForWritingEntry: will invalidate all streams * returned by @ref streamForReadingCurrentEntry or * @ref streamForWritingEntry:! Reading from or writing to an * invalidated stream will throw an @ref OFReadFailedException or * @ref OFWriteFailedException! * * @param entry The entry for which a stream for writing should be returned.@n * The following parts of the specified entry will be ignored: * * The header type. * * The minimum version needed. * * The compressed size. * * The uncompressed size. * * The CRC16. * @return A stream for writing the specified entry */ - (OFStream *)streamForWritingEntry: (OFZooArchiveEntry *)entry; /** * @brief Closes the OFZooArchive. * * @throw OFNotOpenException The archive is not open */ - (void)close; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFZooArchive.m000066400000000000000000000370001465614216400161020ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #define OF_ZOO_ARCHIVE_M #include "config.h" #include #import "OFZooArchive.h" #import "OFZooArchiveEntry.h" #import "OFZooArchiveEntry+Private.h" #import "OFArchiveIRIHandler.h" #import "OFCRC16.h" #import "OFIRI.h" #import "OFIRIHandler.h" #import "OFKernelEventObserver.h" #import "OFLHADecompressingStream.h" #import "OFSeekableStream.h" #import "OFStream.h" #import "OFString.h" #import "OFChecksumMismatchException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedVersionException.h" #import "OFWriteFailedException.h" enum { modeRead, modeWrite }; OF_DIRECT_MEMBERS @interface OFZooArchive () - (void)of_readArchiveHeader; @end OF_DIRECT_MEMBERS @interface OFZooArchiveFileReadStream: OFStream { OFZooArchive *_archive; OF_KINDOF(OFStream *) _stream; OFStream *_decompressedStream; OFZooArchiveEntry *_entry; unsigned long long _toRead; uint16_t _CRC16; bool _atEndOfStream; } - (instancetype)of_initWithArchive: (OFZooArchive *)archive stream: (OFStream *)stream entry: (OFZooArchiveEntry *)entry; @end OF_DIRECT_MEMBERS @interface OFZooArchiveFileWriteStream: OFStream { OFZooArchive *_archive; OFMutableZooArchiveEntry *_entry; OFStringEncoding _encoding; OFSeekableStream *_stream; OFStreamOffset *_lastHeaderOffset; size_t *_lastHeaderLength; uint32_t _bytesWritten; uint16_t _CRC16; } - (instancetype)of_initWithArchive: (OFZooArchive *)archive stream: (OFSeekableStream *)stream entry: (OFZooArchiveEntry *)entry encoding: (OFStringEncoding)encoding lastHeaderOffset: (OFStreamOffset *)lastHeaderOffset lastHeaderLength: (size_t *)lastHeaderLength; @end @implementation OFZooArchive @synthesize encoding = _encoding; + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode { return [[[self alloc] initWithStream: stream mode: mode] autorelease]; } + (instancetype)archiveWithIRI: (OFIRI *)IRI mode: (OFString *)mode { return [[[self alloc] initWithIRI: IRI mode: mode] autorelease]; } + (OFIRI *)IRIForFilePath: (OFString *)path inArchiveWithIRI: (OFIRI *)IRI { return _OFArchiveIRIHandlerIRIForFileInArchive(@"zoo", path, IRI); } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode { self = [super init]; @try { if ([mode isEqual: @"r"]) _mode = modeRead; else if ([mode isEqual: @"w"]) _mode = modeWrite; else if ([mode isEqual: @"a"]) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: nil]; else @throw [OFInvalidArgumentException exception]; if (![stream isKindOfClass: [OFSeekableStream class]]) @throw [OFInvalidArgumentException exception]; _stream = [stream retain]; _encoding = OFStringEncodingUTF8; if (_mode == modeRead) [self of_readArchiveHeader]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithIRI: (OFIRI *)IRI mode: (OFString *)mode { void *pool = objc_autoreleasePoolPush(); OFStream *stream; @try { if ([mode isEqual: @"w"]) stream = [OFIRIHandler openItemAtIRI: IRI mode: @"w+"]; else stream = [OFIRIHandler openItemAtIRI: IRI mode: mode]; } @catch (id e) { [self release]; @throw e; } self = [self initWithStream: stream mode: mode]; objc_autoreleasePoolPop(pool); return self; } - (void)dealloc { if (_stream != nil) [self close]; [_archiveComment release]; [_currentEntry release]; [super dealloc]; } - (void)of_readArchiveHeader { char headerText[20]; uint32_t firstFileOffset, commentOffset; uint16_t commentLength; [_stream readIntoBuffer: headerText exactLength: 20]; if ([_stream readLittleEndianInt32] != 0xFDC4A7DC) @throw [OFInvalidFormatException exception]; firstFileOffset = [_stream readLittleEndianInt32]; if ([_stream readLittleEndianInt32] != ~(uint32_t)(firstFileOffset - 1)) @throw [OFInvalidFormatException exception]; if ((_minVersionNeeded = [_stream readBigEndianInt16]) > 0x201) @throw [OFUnsupportedVersionException exceptionWithVersion: [OFString stringWithFormat: @"%" PRIu8 @".%" PRIu8, _minVersionNeeded >> 8, _minVersionNeeded & 0xFF]]; if ((_headerType = [_stream readInt8]) > 1) @throw [OFUnsupportedVersionException exceptionWithVersion: [OFString stringWithFormat: @"%" PRIu8, _headerType]]; commentOffset = [_stream readLittleEndianInt32]; commentLength = [_stream readLittleEndianInt16]; if (commentOffset > 0) { [_stream seekToOffset: commentOffset whence: OFSeekSet]; _archiveComment = [_stream readStringWithLength: commentLength encoding: _encoding]; } [_stream seekToOffset: firstFileOffset whence: OFSeekSet]; } - (OFString *)archiveComment { return _archiveComment; } - (void)setArchiveComment: (OFString *)comment { void *pool = objc_autoreleasePoolPush(); OFString *old; if ([comment cStringLengthWithEncoding: _encoding] > UINT16_MAX) @throw [OFOutOfRangeException exception]; old = _archiveComment; _archiveComment = [comment copy]; [old release]; objc_autoreleasePoolPop(pool); } - (OFZooArchiveEntry *)nextEntry { if (_mode != modeRead) @throw [OFInvalidArgumentException exception]; if (_currentEntry != nil) [_stream seekToOffset: _currentEntry->_nextHeaderOffset whence: OFSeekSet]; [_currentEntry release]; _currentEntry = nil; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } _lastReturnedStream = nil; _currentEntry = [[OFZooArchiveEntry alloc] of_initWithStream: _stream encoding: _encoding]; return _currentEntry; } - (OFStream *)streamForReadingCurrentEntry { if (_mode != modeRead) @throw [OFInvalidArgumentException exception]; if (_currentEntry == nil) @throw [OFInvalidArgumentException exception]; _lastReturnedStream = [[[OFZooArchiveFileReadStream alloc] of_initWithArchive: self stream: _stream entry: _currentEntry] autorelease]; return _lastReturnedStream; } - (void)of_fixUpLastHeader { OFStreamOffset offset; unsigned char *buffer; if (_lastHeaderOffset == 0) return; offset = [_stream seekToOffset: 0 whence: OFSeekCurrent]; if (offset < 0 || (unsigned long long)offset > UINT32_MAX) @throw [OFOutOfRangeException exception]; OFEnsure(_lastHeaderLength >= 56); [_stream seekToOffset: _lastHeaderOffset whence: OFSeekSet]; buffer = OFAllocMemory(1, _lastHeaderLength); @try { uint16_t tmp16; uint32_t tmp32; [_stream readIntoBuffer: buffer exactLength: _lastHeaderLength]; tmp32 = OFToLittleEndian32((uint32_t)offset); memcpy(buffer + 6, &tmp32, 4); tmp16 = OFToLittleEndian16( _OFCRC16(0, buffer, _lastHeaderLength)); memcpy(buffer + 54, &tmp16, 2); [_stream seekToOffset: _lastHeaderOffset whence: OFSeekSet]; [_stream writeBuffer: buffer length: _lastHeaderLength]; [_stream seekToOffset: offset whence: OFSeekSet]; } @finally { OFFreeMemory(buffer); } } - (OFStream *)streamForWritingEntry: (OFZooArchiveEntry *)entry { if (_mode != modeWrite) @throw [OFInvalidArgumentException exception]; if (entry.compressionMethod != 0) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; if (_lastHeaderOffset == 0) { uint16_t commentLength = [_archiveComment cStringLengthWithEncoding: _encoding]; /* First file - write header. */ [_stream writeBuffer: "ObjFW Zoo Archive.\x1F" length: 20]; [_stream writeLittleEndianInt32: 0xFDC4A7DC]; [_stream writeLittleEndianInt32: 42 + commentLength]; [_stream writeLittleEndianInt32: -(42 + commentLength)]; /* TODO: Increase to 0x201 once we add compressed files. */ [_stream writeBigEndianInt16: 0x200]; /* Header type */ [_stream writeInt8: 1]; if (_archiveComment != nil) { [_stream writeLittleEndianInt32: 42]; [_stream writeLittleEndianInt16: commentLength]; } else { [_stream writeLittleEndianInt32: 0]; [_stream writeLittleEndianInt16: 0]; } /* Version flag */ [_stream writeInt8: 0]; if (_archiveComment != nil) [_stream writeString: _archiveComment encoding: _encoding]; } else [self of_fixUpLastHeader]; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } _lastReturnedStream = nil; _lastReturnedStream = [[[OFZooArchiveFileWriteStream alloc] of_initWithArchive: self stream: _stream entry: entry encoding: _encoding lastHeaderOffset: &_lastHeaderOffset lastHeaderLength: &_lastHeaderLength] autorelease]; return _lastReturnedStream; } - (void)close { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } _lastReturnedStream = nil; /* * Zoo archives should be terminated with an entry that has a next * header offset of 0. */ if (_mode == modeWrite) { static const unsigned char header[56] = { 0xDC, 0xA7, 0xC4, 0xFD, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFC, 0x83 }; [self of_fixUpLastHeader]; [_stream writeBuffer: header length: sizeof(header)]; } [_stream release]; _stream = nil; } @end @implementation OFZooArchiveFileReadStream - (instancetype)of_initWithArchive: (OFZooArchive *)archive stream: (OFStream *)stream entry: (OFZooArchiveEntry *)entry { self = [super init]; @try { _archive = [archive retain]; _stream = [stream retain]; switch (entry.compressionMethod) { case 0: _decompressedStream = [stream retain]; break; case 2: _decompressedStream = [[OFLHADecompressingStream alloc] of_initWithStream: stream distanceBits: 4 dictionaryBits: 14]; break; default: @throw [OFUnsupportedVersionException exceptionWithVersion: [OFString stringWithFormat: @"%u", entry.compressionMethod]]; } _entry = [entry copy]; _toRead = entry.uncompressedSize; [_stream seekToOffset: entry->_dataOffset whence: OFSeekSet]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_stream != nil && _decompressedStream != nil) [self close]; [_entry release]; if (_archive->_lastReturnedStream == self) _archive->_lastReturnedStream = nil; [_archive release]; [super dealloc]; } - (bool)lowlevelIsAtEndOfStream { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; return _atEndOfStream; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { size_t ret; if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (_atEndOfStream) return 0; if ([_stream isAtEndOfStream] && !_decompressedStream.hasDataInReadBuffer) @throw [OFTruncatedDataException exception]; if (length > _toRead) length = (size_t)_toRead; ret = [_decompressedStream readIntoBuffer: buffer length: length]; _toRead -= ret; _CRC16 = _OFCRC16(_CRC16, buffer, ret); if (_toRead == 0) { _atEndOfStream = true; if (_CRC16 != _entry.CRC16) { OFString *actualChecksum = [OFString stringWithFormat: @"%04" @PRIX16, _CRC16]; OFString *expectedChecksum = [OFString stringWithFormat: @"%04" @PRIX16, _entry.CRC16]; @throw [OFChecksumMismatchException exceptionWithActualChecksum: actualChecksum expectedChecksum: expectedChecksum]; } } return ret; } - (bool)hasDataInReadBuffer { return (super.hasDataInReadBuffer || _decompressedStream.hasDataInReadBuffer); } - (int)fileDescriptorForReading { return ((id )_decompressedStream) .fileDescriptorForReading; } - (void)close { if (_stream == nil || _decompressedStream == nil) @throw [OFNotOpenException exceptionWithObject: self]; [_stream release]; _stream = nil; [_decompressedStream release]; _decompressedStream = nil; [super close]; } @end @implementation OFZooArchiveFileWriteStream - (instancetype)of_initWithArchive: (OFZooArchive *)archive stream: (OFSeekableStream *)stream entry: (OFZooArchiveEntry *)entry encoding: (OFStringEncoding)encoding lastHeaderOffset: (OFStreamOffset *)lastHeaderOffset lastHeaderLength: (size_t *)lastHeaderLength { self = [super init]; @try { _archive = [archive retain]; _entry = [entry mutableCopy]; _encoding = encoding; _lastHeaderOffset = lastHeaderOffset; _lastHeaderLength = lastHeaderLength; *_lastHeaderOffset = [stream seekToOffset: 0 whence: OFSeekCurrent]; *_lastHeaderLength = [_entry of_writeToStream: stream encoding: _encoding]; /* * Retain stream last, so that -[close] called by -[dealloc] * doesn't write in case of error. */ _stream = [stream retain]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_stream != nil) [self close]; [_entry release]; if (_archive->_lastReturnedStream == self) _archive->_lastReturnedStream = nil; [_archive release]; [super dealloc]; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (UINT32_MAX - _bytesWritten < length) @throw [OFOutOfRangeException exception]; @try { [_stream writeBuffer: buffer length: length]; } @catch (OFWriteFailedException *e) { OFEnsure(e.bytesWritten <= length); _bytesWritten += (uint32_t)e.bytesWritten; _CRC16 = _OFCRC16(_CRC16, buffer, e.bytesWritten); if (e.errNo == EWOULDBLOCK || e.errNo == EAGAIN) return e.bytesWritten; @throw e; } _bytesWritten += (uint32_t)length; _CRC16 = _OFCRC16(_CRC16, buffer, length); return length; } - (bool)lowlevelIsAtEndOfStream { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; return _stream.atEndOfStream; } - (int)fileDescriptorForWriting { return ((id )_stream) .fileDescriptorForWriting; } - (void)close { OFStreamOffset offset; if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; _entry.uncompressedSize = _bytesWritten; _entry.compressedSize = _bytesWritten; _entry.CRC16 = _CRC16; offset = [_stream seekToOffset: 0 whence: OFSeekCurrent]; if ((unsigned long long)offset > UINT32_MAX) @throw [OFOutOfRangeException exception]; [_stream seekToOffset: *_lastHeaderOffset whence: OFSeekSet]; _entry->_dataOffset = (uint32_t)offset; OFEnsure([_entry of_writeToStream: _stream encoding: _encoding] == *_lastHeaderLength); [_stream seekToOffset: offset whence: OFSeekSet]; [_stream release]; _stream = nil; [super close]; } @end objfw-1.1.6/src/OFZooArchiveEntry+Private.h000066400000000000000000000022211465614216400205220ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFZooArchive.h" #import "OFSeekableStream.h" OF_ASSUME_NONNULL_BEGIN @interface OFZooArchiveEntry () - (instancetype)of_init OF_METHOD_FAMILY(init); - (nullable instancetype)of_initWithStream: (OFSeekableStream *)stream encoding: (OFStringEncoding)encoding OF_METHOD_FAMILY(init) OF_DIRECT; - (size_t)of_writeToStream: (OFSeekableStream *)stream encoding: (OFStringEncoding)encoding; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/OFZooArchiveEntry.h000066400000000000000000000052151465614216400171220ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFArchiveEntry.h" OF_ASSUME_NONNULL_BEGIN @class OFDate; @class OFNumber; @class OFString; /** * @class OFZooArchiveEntry OFZooArchiveEntry.h ObjFW/OFZooArchiveEntry.h * * @brief A class which represents an entry in a Zoo archive. */ @interface OFZooArchiveEntry: OFObject { uint8_t _headerType, _compressionMethod; #ifdef OF_ZOO_ARCHIVE_M @public #endif unsigned long long _nextHeaderOffset, _dataOffset; @protected uint16_t _lastModifiedFileDate, _lastModifiedFileTime; uint16_t _CRC16; unsigned long long _uncompressedSize, _compressedSize; uint16_t _minVersionNeeded; bool _deleted; OFString *_Nullable _fileComment; OFString *_fileName, *_Nullable _directoryName; uint16_t _operatingSystemIdentifier; OFNumber *_Nullable _POSIXPermissions; int8_t _timeZone; OF_RESERVE_IVARS(OFZooArchiveEntry, 4) } /** * @brief The header type of the entry. */ @property (readonly, nonatomic) uint8_t headerType; /** * @brief The compression method of the entry. */ @property (readonly, nonatomic) uint8_t compressionMethod; /** * @brief The CRC16 of the file. */ @property (readonly, nonatomic) uint16_t CRC16; /** * @brief The minimum version required to extract the file. * * The upper 8 bits are the major version and the lower 8 bits the minor * version. */ @property (readonly, nonatomic) uint16_t minVersionNeeded; /** * @brief Whether the file was deleted. */ @property (readonly, nonatomic, getter=isDeleted) bool deleted; /** * @brief The operating system identifier of the file. */ @property (readonly, nonatomic) uint16_t operatingSystemIdentifier; /** * @brief The time zone in which the file was stored, as an offset in hours * from UTC (as a float). */ @property OF_NULLABLE_PROPERTY (readonly, retain, nonatomic) OFNumber *timeZone; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END #import "OFMutableZooArchiveEntry.h" objfw-1.1.6/src/OFZooArchiveEntry.m000066400000000000000000000312761465614216400171350ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFZooArchiveEntry.h" #import "OFZooArchiveEntry+Private.h" #import "OFData.h" #import "OFDate.h" #import "OFNumber.h" #import "OFSeekableStream.h" #import "OFString.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "OFUnsupportedVersionException.h" @implementation OFZooArchiveEntry /* * The following properties are not implemented, but old Apple GCC requries * @dynamic for @optional properties. */ @dynamic ownerAccountID, groupOwnerAccountID, ownerAccountName; @dynamic groupOwnerAccountName; - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)of_init { self = [super init]; @try { _headerType = 2; _minVersionNeeded = 0x100; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)of_initWithStream: (OFSeekableStream *)stream encoding: (OFStringEncoding)encoding { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); char fileNameBuffer[13]; uint32_t commentOffset; uint16_t commentLength; if ([stream readLittleEndianInt32] != 0xFDC4A7DC) @throw [OFInvalidFormatException exception]; if ((_headerType = [stream readInt8]) > 2) @throw [OFUnsupportedVersionException exceptionWithVersion: [OFString stringWithFormat: @"%" PRIu8, _headerType]]; _compressionMethod = [stream readInt8]; _nextHeaderOffset = [stream readLittleEndianInt32]; if (_nextHeaderOffset == 0) { [self release]; return nil; } _dataOffset = [stream readLittleEndianInt32]; _lastModifiedFileDate = [stream readLittleEndianInt16]; _lastModifiedFileTime = [stream readLittleEndianInt16]; _CRC16 = [stream readLittleEndianInt16]; _uncompressedSize = [stream readLittleEndianInt32]; _compressedSize = [stream readLittleEndianInt32]; if ((_minVersionNeeded = [stream readBigEndianInt16]) > 0x201) @throw [OFUnsupportedVersionException exceptionWithVersion: [OFString stringWithFormat: @"%" PRIu8 @".%" PRIu8, _minVersionNeeded >> 8, _minVersionNeeded & 0xFF]]; _deleted = [stream readInt8]; /* * File structure, whatever that is meant to be. Seems to * always be 0. */ [stream readInt8]; commentOffset = [stream readLittleEndianInt32]; commentLength = [stream readLittleEndianInt16]; [stream readIntoBuffer: fileNameBuffer exactLength: 13]; if (fileNameBuffer[12] != '\0') fileNameBuffer[12] = '\0'; if (_headerType >= 2) { uint16_t extraLength = [stream readLittleEndianInt16]; uint8_t fileNameLength = 0, directoryNameLength = 0; _timeZone = [stream readInt8]; /* CRC16 of the header */ [stream readLittleEndianInt16]; if (extraLength >= 2) { fileNameLength = [stream readInt8]; directoryNameLength = [stream readInt8]; extraLength -= 2; } if (fileNameLength > 0) { if (extraLength < fileNameLength) @throw [OFInvalidFormatException exception]; _fileName = [[stream readStringWithLength: fileNameLength encoding: encoding] copy]; extraLength -= fileNameLength; } else _fileName = [[OFString alloc] initWithCString: fileNameBuffer encoding: encoding]; if (directoryNameLength > 0) { if (extraLength < directoryNameLength) @throw [OFInvalidFormatException exception]; _directoryName = [[stream readStringWithLength: directoryNameLength encoding: encoding] copy]; extraLength -= directoryNameLength; } if (extraLength >= 2) { _operatingSystemIdentifier = [stream readLittleEndianInt16]; extraLength -= 2; } if (extraLength >= 3) { uint8_t attributes[3]; [stream readIntoBuffer: attributes exactLength: 3]; if (attributes[2] & (1 << 6)) { uint16_t mode = (attributes[0] | (attributes[1] << 8)) & 0777; _POSIXPermissions = [[OFNumber alloc] initWithUnsignedShort: mode]; } extraLength -= 3; } } else { _fileName = [[OFString alloc] initWithCString: fileNameBuffer encoding: encoding]; _timeZone = 0x7F; } if (commentOffset != 0) { [stream seekToOffset: commentOffset whence: OFSeekSet]; _fileComment = [[stream readStringWithLength: commentLength encoding: encoding] retain]; } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_fileComment release]; [_fileName release]; [_directoryName release]; [_POSIXPermissions release]; [super dealloc]; } - (id)copy { return [self retain]; } - (id)mutableCopy { OFZooArchiveEntry *copy = [[OFMutableZooArchiveEntry alloc] initWithFileName: self.fileName]; @try { copy->_headerType = _headerType; copy->_compressionMethod = _compressionMethod; copy->_nextHeaderOffset = _nextHeaderOffset; copy->_dataOffset = _dataOffset; copy->_lastModifiedFileDate = _lastModifiedFileDate; copy->_lastModifiedFileTime = _lastModifiedFileTime; copy->_CRC16 = _CRC16; copy->_uncompressedSize = _uncompressedSize; copy->_compressedSize = _compressedSize; copy->_minVersionNeeded = _minVersionNeeded; copy->_deleted = _deleted; copy->_fileComment = [_fileComment copy]; copy->_operatingSystemIdentifier = _operatingSystemIdentifier; copy->_POSIXPermissions = [_POSIXPermissions retain]; copy->_timeZone = _timeZone; } @catch (id e) { [self release]; @throw e; } return copy; } - (uint8_t)headerType { return _headerType; } - (uint8_t)compressionMethod { return _compressionMethod; } - (OFDate *)modificationDate { void *pool = objc_autoreleasePoolPush(); uint16_t year = ((_lastModifiedFileDate & 0xFE00) >> 9) + 1980; uint8_t month = (_lastModifiedFileDate & 0x1E0) >> 5; uint8_t day = (_lastModifiedFileDate & 0x1F); uint8_t hour = (_lastModifiedFileTime & 0xF800) >> 11; uint8_t minute = (_lastModifiedFileTime & 0x7E0) >> 5; uint8_t second = (_lastModifiedFileTime & 0x1F) << 1; OFDate *date; OFString *dateString; dateString = [OFString stringWithFormat: @"%04u-%02u-%02u %02u:%02u:%02u", year, month, day, hour, minute, second]; if (_timeZone == 0x7F) date = [[OFDate alloc] initWithLocalDateString: dateString format: @"%Y-%m-%d %H:%M:%S"]; else { date = [OFDate dateWithDateString: dateString format: @"%Y-%m-%d %H:%M:%S"]; date = [[date dateByAddingTimeInterval: (OFTimeInterval)_timeZone * 900] retain]; } objc_autoreleasePoolPop(pool); return [date autorelease]; } - (uint16_t)CRC16 { return _CRC16; } - (unsigned long long)uncompressedSize { return _uncompressedSize; } - (unsigned long long)compressedSize { return _compressedSize; } - (uint16_t)minVersionNeeded { return _minVersionNeeded; } - (bool)isDeleted { return _deleted; } - (OFString *)fileComment { return _fileComment; } - (OFString *)fileName { if (_directoryName == nil) return _fileName; return [OFString stringWithFormat: @"%@/%@", _directoryName, _fileName]; } - (uint16_t)operatingSystemIdentifier { return _operatingSystemIdentifier; } - (OFNumber *)POSIXPermissions { return _POSIXPermissions; } - (OFNumber *)timeZone { if (_timeZone == 0x7F) return nil; return [OFNumber numberWithFloat: -(float)_timeZone / 4]; } - (size_t)of_writeToStream: (OFSeekableStream *)stream encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFMutableData *data = [OFMutableData dataWithCapacity: 56]; OFStreamOffset offset = [stream seekToOffset: 0 whence: OFSeekCurrent]; size_t dataOffsetIndex, commentOffsetIndex; char fileNameBuffer[13] = { 0 }; uint8_t tmp8; uint16_t tmp16; uint32_t tmp32; size_t commentLength, fileNameLength, directoryNameLength, length; if (_uncompressedSize > UINT32_MAX || _compressedSize > UINT32_MAX) @throw [OFOutOfRangeException exception]; commentLength = [_fileComment cStringLengthWithEncoding: encoding]; if (commentLength > UINT16_MAX) @throw [OFOutOfRangeException exception]; fileNameLength = [_fileName cStringLengthWithEncoding: encoding]; if (fileNameLength > UINT8_MAX - 1) @throw [OFOutOfRangeException exception]; directoryNameLength = [_directoryName cStringLengthWithEncoding: encoding]; if (directoryNameLength > UINT8_MAX - 1) @throw [OFOutOfRangeException exception]; [data addItems: "\xDC\xA7\xC4\xFD" count: 4]; /* Header type */ [data addItem: "\x02"]; [data addItem: &_compressionMethod]; /* Next header offset filled when writing the next header */ [data increaseCountBy: 4]; /* Data offset is filled after generating the header */ dataOffsetIndex = data.count; [data increaseCountBy: 4]; tmp16 = OFToLittleEndian16(_lastModifiedFileDate); [data addItems: &tmp16 count: 2]; tmp16 = OFToLittleEndian16(_lastModifiedFileTime); [data addItems: &tmp16 count: 2]; tmp16 = OFToLittleEndian16(_CRC16); [data addItems: &tmp16 count: 2]; tmp32 = OFToLittleEndian32((uint32_t)_uncompressedSize); [data addItems: &tmp32 count: 4]; tmp32 = OFToLittleEndian32((uint32_t)_compressedSize); [data addItems: &tmp32 count: 4]; /* Min version needed */ /* TODO: Increase to 2.1 once we add compression. */ [data addItems: "\x02\x00" count: 2]; [data addItem: (_deleted ? "\x01" : "")]; /* * File structure, whatever that is meant to be. * Seems to always be 0. */ [data addItem: ""]; /* Comment offset is filled after generating the header */ commentOffsetIndex = data.count; [data increaseCountBy: 4]; tmp16 = OFToLittleEndian16((uint16_t)commentLength); [data addItems: &tmp16 count: 2]; strncpy(fileNameBuffer, [_fileName cStringWithEncoding: encoding], 12); [data addItems: fileNameBuffer count: 13]; /* Variable length. */ tmp16 = OFToLittleEndian16(fileNameLength + directoryNameLength + 4 + (_POSIXPermissions != nil ? 3 : 0)); [data addItems: &tmp16 count: 2]; [data addItem: &_timeZone]; /* * CRC16 is filled when writing the next header, as the CRC needs to * include the next header offset. */ [data increaseCountBy: 2]; /* Include \0 */ if (fileNameLength > 0) fileNameLength++; if (directoryNameLength > 0) directoryNameLength++; tmp8 = (uint8_t)fileNameLength; [data addItem: &tmp8]; tmp8 = (uint8_t)directoryNameLength; [data addItem: &tmp8]; [data addItems: [_fileName cStringWithEncoding: encoding] count: fileNameLength]; [data addItems: [_directoryName cStringWithEncoding: encoding] count: directoryNameLength]; tmp16 = OFToLittleEndian16((uint16_t)_operatingSystemIdentifier); [data addItems: &tmp16 count: 2]; if (_POSIXPermissions != nil) { unsigned short mode = _POSIXPermissions.unsignedShortValue; uint8_t attributes[3]; attributes[0] = mode & 0xFF; attributes[1] = mode >> 8; attributes[2] = (1 << 6); [data addItems: attributes count: sizeof(attributes)]; } /* Now that we have the entire header, we know where the data starts. */ if (SIZE_MAX - data.count < commentLength) @throw [OFOutOfRangeException exception]; if (offset < 0 || UINT32_MAX - (unsigned long long)offset < data.count + commentLength) @throw [OFOutOfRangeException exception]; tmp32 = OFToLittleEndian32( (uint32_t)offset + (uint32_t)data.count + (uint32_t)commentLength); memcpy([data mutableItemAtIndex: dataOffsetIndex], &tmp32, 4); tmp32 = OFToLittleEndian32((uint32_t)offset + (uint32_t)data.count); memcpy([data mutableItemAtIndex: commentOffsetIndex], &tmp32, 4); [stream writeData: data]; length = data.count; if (commentLength > 0) [stream writeString: _fileComment encoding: encoding]; objc_autoreleasePoolPop(pool); return length; } - (OFString *)description { void *pool = objc_autoreleasePoolPush(); OFString *ret = [OFString stringWithFormat: @"<%@:\n" @"\tFile name = %@\n" @"\tFile comment = %@\n" @"\tCompressed size = %llu\n" @"\tUncompressed size = %llu\n" @"\tCompression method = %u\n" @"\tModification date = %@\n" @"\tCRC16 = %04" @PRIX16 @"\n" @"\tDeleted = %u\n" @">", self.class, _fileName, _fileComment, _compressedSize, _uncompressedSize, _compressionMethod, self.modificationDate, _CRC16, _deleted]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @end objfw-1.1.6/src/ObjFW.h000066400000000000000000000162161465614216400145540ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFBlock.h" #import "OFString.h" #import "OFCharacterSet.h" #import "OFData.h" #import "OFArray.h" #import "OFSecureData.h" #import "OFList.h" #import "OFSortedList.h" #import "OFDictionary.h" #import "OFMapTable.h" #import "OFSet.h" #import "OFCountedSet.h" #import "OFValue.h" #import "OFPair.h" #import "OFTriple.h" #import "OFEnumerator.h" #import "OFNull.h" #import "OFMethodSignature.h" #import "OFInvocation.h" #import "OFNumber.h" #import "OFDate.h" #import "OFIRI.h" #import "OFIRIHandler.h" #import "OFUUID.h" #import "OFColor.h" #import "OFNotification.h" #import "OFNotificationCenter.h" #import "OFStream.h" #import "OFSeekableStream.h" #import "OFMemoryStream.h" #import "OFStdIOStream.h" #import "OFInflateStream.h" #import "OFInflate64Stream.h" #import "OFGZIPStream.h" #import "OFLHAArchive.h" #import "OFLHAArchiveEntry.h" #import "OFTarArchive.h" #import "OFTarArchiveEntry.h" #import "OFZIPArchive.h" #import "OFZIPArchiveEntry.h" #import "OFZooArchive.h" #import "OFZooArchiveEntry.h" #import "OFFileManager.h" #ifdef OF_HAVE_FILES # import "OFFile.h" #endif #import "OFINIFile.h" #import "OFSettings.h" #ifdef OF_HAVE_SOCKETS # import "OFStreamSocket.h" # import "OFDatagramSocket.h" # import "OFSequencedPacketSocket.h" # import "OFTCPSocket.h" # import "OFUDPSocket.h" # import "OFTLSStream.h" # import "OFKernelEventObserver.h" # import "OFDNSQuery.h" # import "OFDNSResourceRecord.h" # import "OFDNSResponse.h" # import "OFDNSResolver.h" # ifdef OF_HAVE_UNIX_SOCKETS # import "OFUNIXDatagramSocket.h" # import "OFUNIXStreamSocket.h" # endif # ifdef OF_HAVE_IPX # import "OFIPXSocket.h" # import "OFSPXSocket.h" # import "OFSPXStreamSocket.h" # endif # ifdef OF_HAVE_APPLETALK # import "OFDDPSocket.h" # endif # import "OFHTTPClient.h" # import "OFHTTPCookie.h" # import "OFHTTPCookieManager.h" # import "OFHTTPRequest.h" # import "OFHTTPResponse.h" # import "OFHTTPServer.h" #endif #ifdef OF_HAVE_SUBPROCESSES # import "OFSubprocess.h" #endif #import "OFCryptographicHash.h" #import "OFMD5Hash.h" #import "OFRIPEMD160Hash.h" #import "OFSHA1Hash.h" #import "OFSHA224Hash.h" #import "OFSHA256Hash.h" #import "OFSHA384Hash.h" #import "OFSHA512Hash.h" #import "OFHMAC.h" #import "OFXMLAttribute.h" #import "OFXMLElement.h" #import "OFXMLAttribute.h" #import "OFXMLCharacters.h" #import "OFXMLCDATA.h" #import "OFXMLComment.h" #import "OFXMLProcessingInstruction.h" #import "OFXMLParser.h" #import "OFXMLElementBuilder.h" #import "OFMessagePackExtension.h" #import "OFApplication.h" #import "OFSystemInfo.h" #import "OFLocale.h" #import "OFOptionsParser.h" #import "OFTimer.h" #import "OFRunLoop.h" #import "OFMatrix4x4.h" #ifdef OF_WINDOWS # import "OFWindowsRegistryKey.h" #endif #import "OFAllocFailedException.h" #import "OFAlreadyOpenException.h" #import "OFException.h" #import "OFChangeCurrentDirectoryFailedException.h" #import "OFChecksumMismatchException.h" #import "OFCopyItemFailedException.h" #import "OFCreateDirectoryFailedException.h" #import "OFCreateSymbolicLinkFailedException.h" #import "OFEnumerationMutationException.h" #ifdef OF_HAVE_FILES # import "OFGetCurrentDirectoryFailedException.h" #endif #import "OFGetItemAttributesFailedException.h" #import "OFGetOptionFailedException.h" #import "OFHashAlreadyCalculatedException.h" #import "OFHashNotCalculatedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFInvalidJSONException.h" #import "OFInvalidServerResponseException.h" #import "OFLinkItemFailedException.h" #ifdef OF_HAVE_PLUGINS # import "OFLoadPluginFailedException.h" #endif #import "OFLockFailedException.h" #import "OFMalformedXMLException.h" #import "OFMoveItemFailedException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFReadOrWriteFailedException.h" #import "OFRemoveItemFailedException.h" #import "OFSeekFailedException.h" #import "OFSetItemAttributesFailedException.h" #import "OFSetOptionFailedException.h" #import "OFStillLockedException.h" #import "OFTruncatedDataException.h" #import "OFUnboundNamespaceException.h" #import "OFUnboundPrefixException.h" #import "OFUndefinedKeyException.h" #import "OFUnknownXMLEntityException.h" #import "OFUnlockFailedException.h" #import "OFUnsupportedProtocolException.h" #import "OFUnsupportedVersionException.h" #import "OFWriteFailedException.h" #ifdef OF_HAVE_SOCKETS # import "OFAcceptSocketFailedException.h" # import "OFBindIPSocketFailedException.h" # import "OFBindSocketFailedException.h" # import "OFConnectIPSocketFailedException.h" # import "OFConnectSocketFailedException.h" # import "OFDNSQueryFailedException.h" # import "OFHTTPRequestFailedException.h" # import "OFListenOnSocketFailedException.h" # import "OFObserveKernelEventsFailedException.h" # import "OFResolveHostFailedException.h" # import "OFTLSHandshakeFailedException.h" # ifdef OF_HAVE_UNIX_SOCKETS # import "OFBindUNIXSocketFailedException.h" # import "OFConnectUNIXSocketFailedException.h" # endif # ifdef OF_HAVE_IPX # import "OFBindIPXSocketFailedException.h" # import "OFConnectSPXSocketFailedException.h" # endif # ifdef OF_HAVE_APPLETALK # import "OFBindDDPSocketFailedException.h" # endif #endif #ifdef OF_HAVE_THREADS # import "OFBroadcastConditionFailedException.h" # import "OFConditionStillWaitingException.h" # import "OFJoinThreadFailedException.h" # import "OFSignalConditionFailedException.h" # import "OFStartThreadFailedException.h" # import "OFThreadStillRunningException.h" # import "OFWaitForConditionFailedException.h" #endif #ifdef OF_HAVE_PLUGINS # import "OFPlugin.h" #endif #ifdef OF_WINDOWS # import "OFCreateWindowsRegistryKeyFailedException.h" # import "OFDeleteWindowsRegistryKeyFailedException.h" # import "OFDeleteWindowsRegistryValueFailedException.h" # import "OFGetWindowsRegistryValueFailedException.h" # import "OFOpenWindowsRegistryKeyFailedException.h" # import "OFSetWindowsRegistryValueFailedException.h" #endif #ifdef OF_HAVE_ATOMIC_OPS # import "OFAtomic.h" #endif #import "OFLocking.h" #import "OFOnce.h" #import "OFThread.h" #ifdef OF_HAVE_THREADS # import "OFCondition.h" # import "OFMutex.h" # import "OFPlainCondition.h" # import "OFPlainMutex.h" # import "OFPlainThread.h" # import "OFRecursiveMutex.h" # import "OFTLSKey.h" #endif #import "OFPBKDF2.h" #import "OFScrypt.h" objfw-1.1.6/src/bridge/000077500000000000000000000000001465614216400146625ustar00rootroot00000000000000objfw-1.1.6/src/bridge/Info.plist.in000066400000000000000000000012561465614216400172430ustar00rootroot00000000000000 CFBundleExecutable ObjFWBridge CFBundleName ObjFWBridge CFBundleIdentifier im.nil.objfw.bridge CFBundleInfoDictionaryVersion 6.0 CFBundlePackageType FMWK CFBundleVersion @BUNDLE_VERSION@ CFBundleShortVersionString @BUNDLE_SHORT_VERSION@ MinimumOSVersion 9.0 objfw-1.1.6/src/bridge/Makefile000066400000000000000000000032121465614216400163200ustar00rootroot00000000000000include ../../extra.mk DISTCLEAN = Info.plist SHARED_LIB = ${OBJFWBRIDGE_SHARED_LIB} STATIC_LIB = ${OBJFWBRIDGE_STATIC_LIB} FRAMEWORK = ${OBJFWBRIDGE_FRAMEWORK} LIB_MAJOR = ${OBJFWBRIDGE_LIB_MAJOR} LIB_MINOR = ${OBJFWBRIDGE_LIB_MINOR} LIB_PATCH = ${OBJFWBRIDGE_LIB_PATCH} SRCS = OFArray+NSObject.m \ OFEnumerator+NSObject.m \ OFException+Swift.m \ OFDictionary+NSObject.m \ OFNumber+NSObject.m \ OFSet+NSObject.m \ OFString+NSObject.m \ NSArray+OFObject.m \ NSDictionary+OFObject.m \ NSEnumerator+OFObject.m \ NSNumber+OFObject.m \ NSSet+OFObject.m \ NSString+OFObject.m INCLUDES := ${SRCS:.m=.h} \ NSBridging.h \ OFBridging.h \ ObjFWBridge.h SRCS += NSOFArray.m \ NSOFDictionary.m \ NSOFEnumerator.m \ NSOFSet.m \ OFNSArray.m \ OFNSDictionary.m \ OFNSEnumerator.m \ OFNSSet.m includesubdir = ObjFWBridge include ../../buildsys.mk install-extra: i=ObjFWBridge.oc; \ ${INSTALL_STATUS}; \ if ${MKDIR_P} ${DESTDIR}${libdir}/objfw-config && \ ${INSTALL} -m 644 $$i ${DESTDIR}${libdir}/objfw-config/$$i; then \ ${INSTALL_OK}; \ else \ ${INSTALL_FAILED}; \ fi uninstall-extra: i=ObjFWBridge.oc; \ if test -f ${DESTDIR}${libdir}/objfw-config/$$i; then \ if rm -f ${DESTDIR}${libdir}/objfw-config/$$i; then \ ${DELETE_OK}; \ else \ ${DELETE_FAILED}; \ fi \ fi rmdir ${DESTDIR}${libdir}/objfw-config >/dev/null 2>&1 || true CPPFLAGS += -I. -I.. -I../.. -I../exceptions -DOBJFWBRIDGE_LOCAL_INCLUDES LD = ${OBJC} FRAMEWORK_LIBS := -framework Foundation -F.. -framework ObjFW ${LIBS} LIBS := -framework Foundation -L.. -lobjfw ${LIBS} objfw-1.1.6/src/bridge/NSArray+OFObject.h000066400000000000000000000023541465614216400200050ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import #import "NSBridging.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); #ifdef __cplusplus extern "C" { #endif extern int _NSArray_OFObject_reference OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif /** * @category NSArray (OFObject) \ * NSArray+OFObject.h ObjFWBridge/NSArray+OFObject.h * * @brief Support for bridging NSArrays to OFArrays. */ @interface NSArray (OFObject) @property (readonly, nonatomic) OFArray *OFObject; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/bridge/NSArray+OFObject.m000066400000000000000000000016651465614216400200160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "NSArray+OFObject.h" #import "OFNSArray.h" int _NSArray_OFObject_reference; @implementation NSArray (OFObject) - (OFArray *)OFObject { return [[[OFNSArray alloc] initWithNSArray: self] autorelease]; } @end objfw-1.1.6/src/bridge/NSBridging.h000066400000000000000000000025671465614216400170330ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifdef OBJFWBRIDGE_LOCAL_INCLUDES # import "macros.h" #else # if defined(__has_feature) && __has_feature(modules) @import ObjFW; # else # import # endif #endif OF_ASSUME_NONNULL_BEGIN /** * @protocol NSBridging NSBridging.h ObjFWBridge/NSBridging.h * * @brief A protocol implemented by classes supporting bridging Foundation * objects to ObjFW objects. */ @protocol NSBridging /** * @brief An instance of an ObjFW object corresponding to the object. * * If possible, the original object is wrapped. If this is not possible, an * autoreleased copy is created. */ @property (readonly, nonatomic) id OFObject; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/bridge/NSDictionary+OFObject.h000066400000000000000000000024511465614216400210320ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import #import "NSBridging.h" OF_ASSUME_NONNULL_BEGIN @class OFDictionary OF_GENERIC(KeyType, ObjectType); #ifdef __cplusplus extern "C" { #endif extern int _NSDictionary_OFObject_reference OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif /** * @category NSDictionary (OFObject) \ * NSDictionary+OFObject.h ObjFWBridge/NSDictionary+OFObject.h * * @brief Support for bridging NSDictionaries to OFDictionaries. */ @interface NSDictionary (OFObject) @property (readonly, nonatomic) OFDictionary *OFObject; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/bridge/NSDictionary+OFObject.m000066400000000000000000000017351465614216400210430ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "NSDictionary+OFObject.h" #import "OFNSDictionary.h" int _NSDictionary_OFObject_reference; @implementation NSDictionary (OFObject) - (OFDictionary *)OFObject { return [[[OFNSDictionary alloc] initWithNSDictionary: self] autorelease]; } @end objfw-1.1.6/src/bridge/NSEnumerator+OFObject.h000066400000000000000000000024361465614216400210510ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import #import "NSBridging.h" OF_ASSUME_NONNULL_BEGIN @class OFEnumerator OF_GENERIC(ObjectType); #ifdef __cplusplus extern "C" { #endif extern int _NSEnumerator_OFObject_reference OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif /** * @category NSEnumerator (OFObject) \ * NSEnumerator+OFObject.h ObjFWBridge/NSEnumerator+OFObject.h * * @brief Support for bridging NSEnumerators to OFEnumerators. */ @interface NSEnumerator (OFObject) @property (readonly, nonatomic) OFEnumerator *OFObject; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/bridge/NSEnumerator+OFObject.m000066400000000000000000000017351465614216400210570ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "NSEnumerator+OFObject.h" #import "OFNSEnumerator.h" int _NSEnumerator_OFObject_reference; @implementation NSEnumerator (OFObject) - (OFEnumerator *)OFObject { return [[[OFNSEnumerator alloc] initWithNSEnumerator: self] autorelease]; } @end objfw-1.1.6/src/bridge/NSNumber+OFObject.h000066400000000000000000000023341465614216400201550ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import #import "NSBridging.h" OF_ASSUME_NONNULL_BEGIN @class OFNumber; #ifdef __cplusplus extern "C" { #endif extern int _NSNumber_OFObject_reference OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif /** * @category NSNumber (OFObject) * NSNumber+OFObject.h ObjFWBridge/NSNumber+OFObject.h * * @brief Support for bridging NSNumbers to OFNumbers. */ @interface NSNumber (OFObject) @property (readonly, nonatomic) OFNumber *OFObject; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/bridge/NSNumber+OFObject.m000066400000000000000000000041651465614216400201660ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "NSNumber+OFObject.h" #import "OFNumber.h" #import "OFInvalidArgumentException.h" int _NSNumber_OFObject_reference; @implementation NSNumber (OFObject) - (OFNumber *)OFObject { const char *type = self.objCType; if (strcmp(type, "c") == 0) return [OFNumber numberWithChar: self.charValue]; else if (strcmp(type, "C") == 0) return [OFNumber numberWithUnsignedChar: self.unsignedCharValue]; else if (strcmp(type, "s") == 0) return [OFNumber numberWithShort: self.shortValue]; else if (strcmp(type, "S") == 0) return [OFNumber numberWithUnsignedShort: self.unsignedShortValue]; else if (strcmp(type, "i") == 0) return [OFNumber numberWithInt: self.intValue]; else if (strcmp(type, "I") == 0) return [OFNumber numberWithUnsignedInt: self.unsignedIntValue]; else if (strcmp(type, "l") == 0) return [OFNumber numberWithLong: self.longValue]; else if (strcmp(type, "L") == 0) return [OFNumber numberWithUnsignedLong: self.unsignedLongValue]; else if (strcmp(type, "q") == 0) return [OFNumber numberWithLongLong: self.longLongValue]; else if (strcmp(type, "Q") == 0) return [OFNumber numberWithUnsignedLongLong: self.unsignedLongLongValue]; else if (strcmp(type, "f") == 0) return [OFNumber numberWithFloat: self.floatValue]; else if (strcmp(type, "d") == 0) return [OFNumber numberWithDouble: self.doubleValue]; @throw [OFInvalidArgumentException exception]; } @end objfw-1.1.6/src/bridge/NSOFArray.h000066400000000000000000000016761465614216400166110ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import #import "macros.h" @class OFArray; OF_ASSUME_NONNULL_BEGIN @interface NSOFArray: NSArray { OFArray *_array; } - (instancetype)initWithOFArray: (OFArray *)array; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/bridge/NSOFArray.m000066400000000000000000000026011465614216400166030ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "NSOFArray.h" #import "OFArray.h" #import "OFBridging.h" #import "OFOutOfRangeException.h" @implementation NSOFArray - (instancetype)initWithOFArray: (OFArray *)array { if ((self = [super init]) != nil) _array = [array retain]; return self; } - (void)dealloc { [_array release]; [super dealloc]; } - (id)objectAtIndex: (NSUInteger)idx { id object = [_array objectAtIndex: idx]; if ([(OFObject *)object conformsToProtocol: @protocol(OFBridging)]) return [object NSObject]; return object; } - (NSUInteger)count { size_t count = _array.count; if (count > NSUIntegerMax) @throw [OFOutOfRangeException exception]; return (NSUInteger)count; } @end objfw-1.1.6/src/bridge/NSOFDictionary.h000066400000000000000000000017531465614216400176340ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import #import "macros.h" @class OFDictionary; OF_ASSUME_NONNULL_BEGIN @interface NSOFDictionary: NSDictionary { OFDictionary *_dictionary; } - (instancetype)initWithOFDictionary: (OFDictionary *)dictionary; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/bridge/NSOFDictionary.m000066400000000000000000000032401465614216400176320ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "NSOFDictionary.h" #import "OFDictionary.h" #import "OFEnumerator+NSObject.h" #import "NSBridging.h" #import "OFBridging.h" #import "OFOutOfRangeException.h" @implementation NSOFDictionary - (instancetype)initWithOFDictionary: (OFDictionary *)dictionary { if ((self = [super init]) != nil) _dictionary = [dictionary retain]; return self; } - (void)dealloc { [_dictionary release]; [super dealloc]; } - (id)objectForKey: (id)key { id object; if ([(NSObject *)key conformsToProtocol: @protocol(NSBridging)]) key = [key OFObject]; object = [_dictionary objectForKey: key]; if ([(OFObject *)object conformsToProtocol: @protocol(OFBridging)]) return [object NSObject]; return object; } - (NSUInteger)count { size_t count = _dictionary.count; if (count > NSUIntegerMax) @throw [OFOutOfRangeException exception]; return (NSUInteger)count; } - (NSEnumerator *)keyEnumerator { return [_dictionary keyEnumerator].NSObject; } @end objfw-1.1.6/src/bridge/NSOFEnumerator.h000066400000000000000000000017531465614216400176500ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import #import "macros.h" @class OFEnumerator; OF_ASSUME_NONNULL_BEGIN @interface NSOFEnumerator: NSEnumerator { OFEnumerator *_enumerator; } - (instancetype)initWithOFEnumerator: (OFEnumerator *)enumerator; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/bridge/NSOFEnumerator.m000066400000000000000000000023601465614216400176500ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "NSOFEnumerator.h" #import "OFEnumerator.h" #import "NSBridging.h" #import "OFBridging.h" @implementation NSOFEnumerator - (instancetype)initWithOFEnumerator: (OFEnumerator *)enumerator { if ((self = [super init]) != nil) _enumerator = [enumerator retain]; return self; } - (void)dealloc { [_enumerator release]; [super dealloc]; } - (id)nextObject { id object = [_enumerator nextObject]; if ([(OFObject *)object conformsToProtocol: @protocol(OFBridging)]) return [object NSObject]; return object; } @end objfw-1.1.6/src/bridge/NSOFSet.h000066400000000000000000000016541465614216400162620ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import #import "macros.h" @class OFSet; OF_ASSUME_NONNULL_BEGIN @interface NSOFSet: NSSet { OFSet *_set; } - (instancetype)initWithOFSet: (OFSet *)set; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/bridge/NSOFSet.m000066400000000000000000000030351465614216400162620ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "NSOFSet.h" #import "OFEnumerator+NSObject.h" #import "OFSet.h" #import "OFBridging.h" #import "NSBridging.h" #import "OFOutOfRangeException.h" @implementation NSOFSet - (instancetype)initWithOFSet: (OFSet *)set { if ((self = [super init]) != nil) _set = [set retain]; return self; } - (void)dealloc { [_set release]; [super dealloc]; } - (id)member: (id)object { id originalObject = object; if ([(NSObject *)object conformsToProtocol: @protocol(NSBridging)]) object = [object OFObject]; if ([_set containsObject: object]) return originalObject; return nil; } - (NSUInteger)count { size_t count = _set.count; if (count > NSUIntegerMax) @throw [OFOutOfRangeException exception]; return (NSUInteger)count; } - (NSEnumerator *)objectEnumerator { return [_set objectEnumerator].NSObject; } @end objfw-1.1.6/src/bridge/NSSet+OFObject.h000066400000000000000000000023261465614216400174610ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import #import "NSBridging.h" OF_ASSUME_NONNULL_BEGIN @class OFSet OF_GENERIC(ObjectType); #ifdef __cplusplus extern "C" { #endif extern int _NSSet_OFObject_reference OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif /** * @category NSSet (OFObject) * NSSet+OFObject.h ObjFWBridge/NSSet+OFObject.h * * @brief Support for bridging NSSets to OFSets. */ @interface NSSet (OFObject) @property (readonly, nonatomic) OFSet *OFObject; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/bridge/NSSet+OFObject.m000066400000000000000000000016471465614216400174730ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "NSSet+OFObject.h" #import "OFNSSet.h" int _NSSet_OFObject_reference; @implementation NSSet (OFObject) - (OFSet *)OFObject { return [[[OFNSSet alloc] initWithNSSet: self] autorelease]; } @end objfw-1.1.6/src/bridge/NSString+OFObject.h000066400000000000000000000026251465614216400201760ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import #import "NSBridging.h" OF_ASSUME_NONNULL_BEGIN @class OFString; #ifdef __cplusplus extern "C" { #endif extern int _NSString_OFObject_reference OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif /** * @category NSString (OFObject) * NSString+OFObject.h ObjFWBridge/NSString+OFObject.h * * @brief Support for bridging NSStrings to OFStrings. * * Unfortunately, they need to be copied, as NSString is not capable of * handling UCS-4 properly (a character of NSString is only 2 bytes, while a * character of OFString is 4). */ @interface NSString (OFObject) @property (readonly, nonatomic) OFString *OFObject; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/bridge/NSString+OFObject.m000066400000000000000000000016611465614216400202020ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "NSString+OFObject.h" #import "OFString.h" int _NSString_OFObject_reference; @implementation NSString (OFObject) - (OFString *)OFObject { return [OFString stringWithUTF8String: self.UTF8String]; } @end objfw-1.1.6/src/bridge/OFArray+NSObject.h000066400000000000000000000025261465614216400200060ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifdef OBJFWBRIDGE_LOCAL_INCLUDES # import "OFArray.h" #else # if defined(__has_feature) && __has_feature(modules) @import ObjFW; # else # import # endif #endif #import "OFBridging.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif extern int _OFArray_NSObject_reference OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif /** * @category OFArray (NSObject) \ * OFArray+NSObject.h ObjFWBridge/OFArray+NSObject.h * @brief Support for bridging OFArrays to NSArrays. */ @interface OFArray (NSObject) @property (readonly, nonatomic) NSArray *NSObject; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/bridge/OFArray+NSObject.m000066400000000000000000000016661465614216400200170ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "NSOFArray.h" #import "OFArray+NSObject.h" int _OFArray_NSObject_reference; @implementation OFArray (NSObject) - (NSArray *)NSObject { return [[[NSOFArray alloc] initWithOFArray: self] autorelease]; } @end objfw-1.1.6/src/bridge/OFBridging.h000066400000000000000000000025731465614216400170140ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifdef OBJFWBRIDGE_LOCAL_INCLUDES # import "macros.h" #else # if defined(__has_feature) && __has_feature(modules) @import ObjFW; # else # import # endif #endif OF_ASSUME_NONNULL_BEGIN /** * @protocol OFBridging OFBridging.h ObjFWBridge/OFBridging.h * * @brief A protocol implemented by classes supporting bridging ObjFW objects * to Foundation objects. */ @protocol OFBridging /** * @brief An instance of a Foundation object corresponding to the object. * * If possible, the original object is wrapped. If this is not possible, an * autoreleased copy is created. */ @property (readonly, nonatomic) id NSObject; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/bridge/OFDictionary+NSObject.h000066400000000000000000000026151465614216400210340ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifdef OBJFWBRIDGE_LOCAL_INCLUDES # import "OFDictionary.h" #else # if defined(__has_feature) && __has_feature(modules) @import ObjFW; # else # import # endif #endif #import "OFBridging.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif extern int _OFDictionary_NSObject_reference OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif /** * @category OFDictionary (NSObject) \ * OFDictionary+NSObject.h ObjFWBridge/OFDictionary+NSObject.h * * @brief Support for bridging OFDictionaries to NSDictionaries. */ @interface OFDictionary (NSObject) @property (readonly, nonatomic) NSDictionary *NSObject; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/bridge/OFDictionary+NSObject.m000066400000000000000000000017361465614216400210440ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "NSOFDictionary.h" #import "OFDictionary+NSObject.h" int _OFDictionary_NSObject_reference; @implementation OFDictionary (NSObject) - (NSDictionary *)NSObject { return [[[NSOFDictionary alloc] initWithOFDictionary: self] autorelease]; } @end objfw-1.1.6/src/bridge/OFEnumerator+NSObject.h000066400000000000000000000026101465614216400210430ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifdef OBJFWBRIDGE_LOCAL_INCLUDES # import "OFEnumerator.h" #else # if defined(__has_feature) && __has_feature(modules) @import ObjFW; # else # import # endif #endif #import "OFBridging.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif extern int _OFEnumerator_NSObject_reference OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif /** * @category OFEnumerator (NSObject) \ * OFEnumerator+NSObject.h ObjFWBridge/OFEnumerator+NSObject.h * @brief Support for bridging OFEnumerators to NSEnumerators. */ @interface OFEnumerator (NSObject) @property (readonly, nonatomic) NSEnumerator *NSObject; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/bridge/OFEnumerator+NSObject.m000066400000000000000000000017361465614216400210600ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "NSOFEnumerator.h" #import "OFEnumerator+NSObject.h" int _OFEnumerator_NSObject_reference; @implementation OFEnumerator (NSObject) - (NSEnumerator *)NSObject { return [[[NSOFEnumerator alloc] initWithOFEnumerator: self] autorelease]; } @end objfw-1.1.6/src/bridge/OFException+Swift.h000066400000000000000000000044371465614216400203160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifdef OBJFWBRIDGE_LOCAL_INCLUDES # import "OFException.h" #else # if defined(__has_feature) && __has_feature(modules) @import ObjFW; # else # import # endif #endif OF_ASSUME_NONNULL_BEGIN @interface OFException (Swift) #ifdef OF_HAVE_BLOCKS /** * @brief Execute the specified try block and call the catch block if an * OFException occurred. * * @note This is only useful to catch OFExceptions in Swift. * * @param try The try block to execute * @param catch The catch block to execute if an OFException occurred */ + (void)try: (void (^)(void))try catch: (void (^)(OF_KINDOF(OFException *)))catch; /** * @brief Execute the specified try block and finally call the finally block. * * @note This is only useful for Swift. * * @param try The try block to execute * @param finally The finally block to call at the end */ + (void)try: (void (^)(void))try finally: (void (^)(void))finally; /** * @brief Execute the specified try block and call the catch block if an * OFException occurred and finally call the finally block. * * @note This is only useful to catch OFExceptions in Swift. * * @param try The try block to execute * @param catch The catch block to execute if an OFException occurred * @param finally The finally block to call at the end */ + (void)try: (void (^)(void))try catch: (void (^)(OF_KINDOF(OFException *)))catch finally: (void (^)(void))finally; #endif /** * @brief Raises the exception. * * @note This is only useful to raise OFExceptions in Swift. */ - (void)throw OF_NO_RETURN; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/bridge/OFException+Swift.m000066400000000000000000000025231465614216400203150ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException+Swift.h" @implementation OFException (NSError) #ifdef OF_HAVE_BLOCKS + (void)try: (void (^)(void))try catch: (void (^)(OF_KINDOF(OFException *e)))catch { @try { try(); } @catch (OFException *e) { catch(e); } } + (void)try: (void (^)(void))try finally: (void (^)(void))finally { @try { try(); } @finally { finally(); } } + (void)try: (void (^)(void))try catch: (void (^)(OF_KINDOF(OFException *e)))catch finally: (void (^)(void))finally { @try { try(); } @catch (OFException *e) { catch(e); } @finally { finally(); } } #endif - (void)throw { @throw self; } @end objfw-1.1.6/src/bridge/OFNSArray.h000066400000000000000000000020771465614216400166050ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifdef OBJFWBRIDGE_LOCAL_INCLUDES # import "OFArray.h" #else # if defined(__has_feature) && __has_feature(modules) @import ObjFW; # else # import # endif #endif OF_ASSUME_NONNULL_BEGIN @class NSArray; @interface OFNSArray: OFArray { NSArray *_array; } - (instancetype)initWithNSArray: (NSArray *)array; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/bridge/OFNSArray.m000066400000000000000000000030071465614216400166040ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import #import "OFNSArray.h" #import "NSBridging.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" @implementation OFNSArray - (instancetype)initWithNSArray: (NSArray *)array { self = [super init]; @try { if (array == nil) @throw [OFInvalidArgumentException exception]; _array = [array retain]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_array release]; [super dealloc]; } - (id)objectAtIndex: (size_t)idx { id object; if (idx > NSUIntegerMax) @throw [OFOutOfRangeException exception]; object = [_array objectAtIndex: idx]; if ([(NSObject *)object conformsToProtocol: @protocol(NSBridging)]) return [object OFObject]; return object; } - (size_t)count { return _array.count; } @end objfw-1.1.6/src/bridge/OFNSDictionary.h000066400000000000000000000021611465614216400176260ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifdef OBJFWBRIDGE_LOCAL_INCLUDES # import "OFDictionary.h" #else # if defined(__has_feature) && __has_feature(modules) @import ObjFW; # else # import # endif #endif OF_ASSUME_NONNULL_BEGIN @class NSDictionary; @interface OFNSDictionary: OFDictionary { NSDictionary *_dictionary; } - (instancetype)initWithNSDictionary: (NSDictionary *)dictionary; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/bridge/OFNSDictionary.m000066400000000000000000000032741465614216400176410ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import #import "OFNSDictionary.h" #import "NSEnumerator+OFObject.h" #import "NSBridging.h" #import "OFBridging.h" #import "OFInvalidArgumentException.h" @implementation OFNSDictionary - (instancetype)initWithNSDictionary: (NSDictionary *)dictionary { self = [super init]; @try { if (dictionary == nil) @throw [OFInvalidArgumentException exception]; _dictionary = [dictionary retain]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_dictionary release]; [super dealloc]; } - (id)objectForKey: (id)key { id object; if ([(OFObject *)key conformsToProtocol: @protocol(OFBridging)]) key = [key NSObject]; object = [_dictionary objectForKey: key]; if ([(NSObject *)object conformsToProtocol: @protocol(NSBridging)]) return [object OFObject]; return object; } - (size_t)count { return _dictionary.count; } - (OFEnumerator *)keyEnumerator { return [_dictionary keyEnumerator].OFObject; } @end objfw-1.1.6/src/bridge/OFNSEnumerator.h000066400000000000000000000021611465614216400176420ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifdef OBJFWBRIDGE_LOCAL_INCLUDES # import "OFEnumerator.h" #else # if defined(__has_feature) && __has_feature(modules) @import ObjFW; # else # import # endif #endif OF_ASSUME_NONNULL_BEGIN @class NSEnumerator; @interface OFNSEnumerator: OFEnumerator { NSEnumerator *_enumerator; } - (instancetype)initWithNSEnumerator: (NSEnumerator *)enumerator; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/bridge/OFNSEnumerator.m000066400000000000000000000026401465614216400176510ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import #import "OFNSEnumerator.h" #import "NSBridging.h" #import "OFBridging.h" #import "OFInvalidArgumentException.h" @implementation OFNSEnumerator - (instancetype)initWithNSEnumerator: (NSEnumerator *)enumerator { self = [super init]; @try { if (enumerator == nil) @throw [OFInvalidArgumentException exception]; _enumerator = [enumerator retain]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_enumerator release]; [super dealloc]; } - (id)nextObject { id object = [_enumerator nextObject]; if ([(NSObject *)object conformsToProtocol: @protocol(NSBridging)]) return [object OFObject]; return object; } @end objfw-1.1.6/src/bridge/OFNSSet.h000066400000000000000000000020531465614216400162540ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifdef OBJFWBRIDGE_LOCAL_INCLUDES # import "OFSet.h" #else # if defined(__has_feature) && __has_feature(modules) @import ObjFW; # else # import # endif #endif OF_ASSUME_NONNULL_BEGIN @class NSSet; @interface OFNSSet: OFSet { NSSet *_set; } - (instancetype)initWithNSSet: (NSSet *)set; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/bridge/OFNSSet.m000066400000000000000000000031771465614216400162710ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import #import "OFNSSet.h" #import "NSEnumerator+OFObject.h" #import "OFBridging.h" #import "NSBridging.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" @implementation OFNSSet - (instancetype)initWithNSSet: (NSSet *)set { self = [super init]; @try { if (set == nil) @throw [OFInvalidArgumentException exception]; _set = [set retain]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_set release]; [super dealloc]; } - (bool)containsObject: (id)object { void *pool = objc_autoreleasePoolPush(); bool ret; if ([(OFObject *)object conformsToProtocol: @protocol(OFBridging)]) object = [object NSObject]; ret = [_set containsObject: object]; objc_autoreleasePoolPop(pool); return ret; } - (size_t)count { return _set.count; } - (OFEnumerator *)objectEnumerator { return [_set objectEnumerator].OFObject; } @end objfw-1.1.6/src/bridge/OFNumber+NSObject.h000066400000000000000000000025431465614216400201570ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifdef OBJFWBRIDGE_LOCAL_INCLUDES # import "OFNumber.h" #else # if defined(__has_feature) && __has_feature(modules) @import ObjFW; # else # import # endif #endif #import "OFBridging.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif extern int _OFNumber_NSObject_reference OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif /** * @category OFNumber (NSObject) \ * OFNumber+NSObject.h ObjFWBridge/OFNumber+NSObject.h * * @brief Support for bridging OFNumbers to NSNumbers. */ @interface OFNumber (NSObject) @property (readonly, nonatomic) NSNumber *NSObject; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/bridge/OFNumber+NSObject.m000066400000000000000000000043261465614216400201650ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import #import "OFNumber+NSObject.h" #import "OFInvalidArgumentException.h" int _OFNumber_NSObject_reference; @implementation OFNumber (NSObject) - (NSNumber *)NSObject { const char *type = self.objCType; if (strcmp(type, "B") == 0) return [NSNumber numberWithBool: self.boolValue]; else if (strcmp(type, "c") == 0) return [NSNumber numberWithChar: self.charValue]; else if (strcmp(type, "C") == 0) return [NSNumber numberWithUnsignedChar: self.unsignedCharValue]; else if (strcmp(type, "s") == 0) return [NSNumber numberWithShort: self.shortValue]; else if (strcmp(type, "S") == 0) return [NSNumber numberWithUnsignedShort: self.unsignedShortValue]; else if (strcmp(type, "i") == 0) return [NSNumber numberWithInt: self.intValue]; else if (strcmp(type, "I") == 0) return [NSNumber numberWithUnsignedInt: self.unsignedIntValue]; else if (strcmp(type, "l") == 0) return [NSNumber numberWithLong: self.longValue]; else if (strcmp(type, "L") == 0) return [NSNumber numberWithUnsignedLong: self.unsignedLongValue]; else if (strcmp(type, "q") == 0) return [NSNumber numberWithLongLong: self.longLongValue]; else if (strcmp(type, "Q") == 0) return [NSNumber numberWithUnsignedLongLong: self.unsignedLongLongValue]; else if (strcmp(type, "f") == 0) return [NSNumber numberWithFloat: self.floatValue]; else if (strcmp(type, "d") == 0) return [NSNumber numberWithDouble: self.doubleValue]; @throw [OFInvalidArgumentException exception]; } @end objfw-1.1.6/src/bridge/OFSet+NSObject.h000066400000000000000000000025021465614216400174550ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifdef OBJFWBRIDGE_LOCAL_INCLUDES # import "OFSet.h" #else # if defined(__has_feature) && __has_feature(modules) @import ObjFW; # else # import # endif #endif #import "OFBridging.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif extern int _OFSet_NSObject_reference OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif /** * @category OFSet (NSObject) \ * OFSet+NSObject.h ObjFWBridge/OFSet+NSObject.h * @brief Support for bridging OFSets to NSSets. */ @interface OFSet (NSObject) @property (readonly, nonatomic) NSSet *NSObject; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/bridge/OFSet+NSObject.m000066400000000000000000000016501465614216400174650ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "NSOFSet.h" #import "OFSet+NSObject.h" int _OFSet_NSObject_reference; @implementation OFSet (NSObject) - (NSSet *)NSObject { return [[[NSOFSet alloc] initWithOFSet: self] autorelease]; } @end objfw-1.1.6/src/bridge/OFString+NSObject.h000066400000000000000000000030331465614216400201700ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifdef OBJFWBRIDGE_LOCAL_INCLUDES # import "OFString.h" #else # if defined(__has_feature) && __has_feature(modules) @import ObjFW; # else # import # endif #endif #import "OFBridging.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif extern int _OFString_NSObject_reference OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif /** * @category OFString (NSObject) \ * OFString+NSObject.h ObjFWBridge/OFString+NSObject.h * * @brief Support for bridging OFStrings to NSStrings. * * Unfortunately, they need to be copied, as NSString is not capable of * handling UCS-4 properly (a character of NSString is only 2 bytes, while a * character of OFString is 4). */ @interface OFString (NSObject) @property (readonly, nonatomic) NSString *NSObject; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/bridge/OFString+NSObject.m000066400000000000000000000021631465614216400202000ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import #import "OFString+NSObject.h" #import "OFInitializationFailedException.h" int _OFString_NSObject_reference; @implementation OFString (NSObject) - (NSString *)NSObject { NSString *string = [NSString stringWithUTF8String: self.UTF8String]; if (string == nil) @throw [OFInitializationFailedException exceptionWithClass: [NSString class]]; return string; } @end objfw-1.1.6/src/bridge/ObjFWBridge.h000066400000000000000000000021531465614216400171200ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "NSArray+OFObject.h" #import "NSDictionary+OFObject.h" #import "NSEnumerator+OFObject.h" #import "NSNumber+OFObject.h" #import "NSSet+OFObject.h" #import "NSString+OFObject.h" #import "OFArray+NSObject.h" #import "OFException+Swift.h" #import "OFDictionary+NSObject.h" #import "OFEnumerator+NSObject.h" #import "OFNumber+NSObject.h" #import "OFSet+NSObject.h" #import "OFString+NSObject.h" objfw-1.1.6/src/bridge/ObjFWBridge.oc000066400000000000000000000002321465614216400172660ustar00rootroot00000000000000package_format 1 LIBS="-lobjfwbridge $LIBS" FRAMEWORK_LIBS="-framework ObjFWBridge $FRAMEWORK_LIBS" STATIC_LIBS="${libdir}/libobjfwbridge.a $STATIC_LIBS" objfw-1.1.6/src/bridge/module.modulemap000066400000000000000000000001151465614216400200510ustar00rootroot00000000000000framework module ObjFWBridge { umbrella header "ObjFWBridge.h" export * } objfw-1.1.6/src/encodings/000077500000000000000000000000001465614216400153775ustar00rootroot00000000000000objfw-1.1.6/src/encodings/Makefile000066400000000000000000000003261465614216400170400ustar00rootroot00000000000000include ../../extra.mk STATIC_PIC_LIB_NOINST = ${ENCODINGS_LIB_A} STATIC_LIB_NOINST = ${ENCODINGS_A} SRCS = ${ENCODINGS_SRCS} include ../../buildsys.mk CPPFLAGS += -I. -I.. -I../.. -I../runtime -I../exceptions objfw-1.1.6/src/encodings/codepage-437.m000066400000000000000000000137261465614216400176500ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFString.h" #import "common.h" const OFChar16 _OFCodepage437Table[] OF_VISIBILITY_HIDDEN = { 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5, 0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192, 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB, 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510, 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567, 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580, 0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229, 0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0 }; const size_t _OFCodepage437TableOffset OF_VISIBILITY_HIDDEN = 256 - (sizeof(_OFCodepage437Table) / sizeof(*_OFCodepage437Table)); static const unsigned char page0[] = { 0xFF, 0xAD, 0x9B, 0x9C, 0x00, 0x9D, 0x00, 0x00, 0x00, 0x00, 0xA6, 0xAE, 0xAA, 0x00, 0x00, 0x00, 0xF8, 0xF1, 0xFD, 0x00, 0x00, 0xE6, 0x00, 0xFA, 0x00, 0x00, 0xA7, 0xAF, 0xAC, 0xAB, 0x00, 0xA8, 0x00, 0x00, 0x00, 0x00, 0x8E, 0x8F, 0x92, 0x80, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA5, 0x00, 0x00, 0x00, 0x00, 0x99, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9A, 0x00, 0x00, 0xE1, 0x85, 0xA0, 0x83, 0x00, 0x84, 0x86, 0x91, 0x87, 0x8A, 0x82, 0x88, 0x89, 0x8D, 0xA1, 0x8C, 0x8B, 0x00, 0xA4, 0x95, 0xA2, 0x93, 0x00, 0x94, 0xF6, 0x00, 0x97, 0xA3, 0x96, 0x81, 0x00, 0x00, 0x98 }; static const uint8_t page0Start = 0xA0; static const unsigned char page1[] = { 0x9F }; static const uint8_t page1Start = 0x92; static const unsigned char page3[] = { 0xE2, 0x00, 0x00, 0x00, 0x00, 0xE9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE4, 0x00, 0x00, 0xE8, 0x00, 0x00, 0xEA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0xEB, 0xEE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE3, 0x00, 0x00, 0xE5, 0xE7, 0x00, 0xED }; static const uint8_t page3Start = 0x93; static const unsigned char page20[] = { 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9E }; static const uint8_t page20Start = 0x7F; static const unsigned char page22[] = { 0xF9, 0xFB, 0x00, 0x00, 0x00, 0xEC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0xF3, 0xF2 }; static const uint8_t page22Start = 0x19; static const unsigned char page23[] = { 0xA9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF4, 0xF5 }; static const uint8_t page23Start = 0x10; static const unsigned char page25[] = { 0xC4, 0x00, 0xB3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDA, 0x00, 0x00, 0x00, 0xBF, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0xD9, 0x00, 0x00, 0x00, 0xC3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCD, 0xBA, 0xD5, 0xD6, 0xC9, 0xB8, 0xB7, 0xBB, 0xD4, 0xD3, 0xC8, 0xBE, 0xBD, 0xBC, 0xC6, 0xC7, 0xCC, 0xB5, 0xB6, 0xB9, 0xD1, 0xD2, 0xCB, 0xCF, 0xD0, 0xCA, 0xD8, 0xD7, 0xCE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDF, 0x00, 0x00, 0x00, 0xDC, 0x00, 0x00, 0x00, 0xDB, 0x00, 0x00, 0x00, 0xDD, 0x00, 0x00, 0x00, 0xDE, 0xB0, 0xB1, 0xB2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE }; static const uint8_t page25Start = 0x00; bool OF_VISIBILITY_HIDDEN _OFUnicodeToCodepage437(const OFUnichar *input, unsigned char *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { OFUnichar c = input[i]; if OF_UNLIKELY (c > 0x7F) { uint8_t idx; if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; continue; } else return false; } switch (c >> 8) { CASE_MISSING_IS_ERROR(0) CASE_MISSING_IS_ERROR(1) CASE_MISSING_IS_ERROR(3) CASE_MISSING_IS_ERROR(20) CASE_MISSING_IS_ERROR(22) CASE_MISSING_IS_ERROR(23) CASE_MISSING_IS_ERROR(25) default: if (lossy) { output[i] = '?'; continue; } else return false; } } else output[i] = (unsigned char)c; } return true; } objfw-1.1.6/src/encodings/codepage-850.m000066400000000000000000000121351465614216400176400ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFString.h" #import "common.h" const OFChar16 _OFCodepage850Table[] OF_VISIBILITY_HIDDEN = { 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5, 0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x0192, 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB, 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0, 0x00A9, 0x2563, 0x2551, 0x2557, 0x255D, 0x00A2, 0x00A5, 0x2510, 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4, 0x00F0, 0x00D0, 0x00CA, 0x00CB, 0x00C8, 0x0131, 0x00CD, 0x00CE, 0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00A6, 0x00CC, 0x2580, 0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x00FE, 0x00DE, 0x00DA, 0x00DB, 0x00D9, 0x00FD, 0x00DD, 0x00AF, 0x00B4, 0x00AD, 0x00B1, 0x2017, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8, 0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0 }; const size_t _OFCodepage850TableOffset OF_VISIBILITY_HIDDEN = 256 - (sizeof(_OFCodepage850Table) / sizeof(*_OFCodepage850Table)); static const unsigned char page0[] = { 0xFF, 0xAD, 0xBD, 0x9C, 0xCF, 0xBE, 0xDD, 0xF5, 0xF9, 0xB8, 0xA6, 0xAE, 0xAA, 0xF0, 0xA9, 0xEE, 0xF8, 0xF1, 0xFD, 0xFC, 0xEF, 0xE6, 0xF4, 0xFA, 0xF7, 0xFB, 0xA7, 0xAF, 0xAC, 0xAB, 0xF3, 0xA8, 0xB7, 0xB5, 0xB6, 0xC7, 0x8E, 0x8F, 0x92, 0x80, 0xD4, 0x90, 0xD2, 0xD3, 0xDE, 0xD6, 0xD7, 0xD8, 0xD1, 0xA5, 0xE3, 0xE0, 0xE2, 0xE5, 0x99, 0x9E, 0x9D, 0xEB, 0xE9, 0xEA, 0x9A, 0xED, 0xE8, 0xE1, 0x85, 0xA0, 0x83, 0xC6, 0x84, 0x86, 0x91, 0x87, 0x8A, 0x82, 0x88, 0x89, 0x8D, 0xA1, 0x8C, 0x8B, 0xD0, 0xA4, 0x95, 0xA2, 0x93, 0xE4, 0x94, 0xF6, 0x9B, 0x97, 0xA3, 0x96, 0x81, 0xEC, 0xE7, 0x98 }; static const uint8_t page0Start = 0xA0; static const unsigned char page1[] = { 0xD5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9F }; static const uint8_t page1Start = 0x31; static const unsigned char page20[] = { 0xF2 }; static const uint8_t page20Start = 0x17; static const unsigned char page25[] = { 0xC4, 0x00, 0xB3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDA, 0x00, 0x00, 0x00, 0xBF, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0xD9, 0x00, 0x00, 0x00, 0xC3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCD, 0xBA, 0x00, 0x00, 0xC9, 0x00, 0x00, 0xBB, 0x00, 0x00, 0xC8, 0x00, 0x00, 0xBC, 0x00, 0x00, 0xCC, 0x00, 0x00, 0xB9, 0x00, 0x00, 0xCB, 0x00, 0x00, 0xCA, 0x00, 0x00, 0xCE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDF, 0x00, 0x00, 0x00, 0xDC, 0x00, 0x00, 0x00, 0xDB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0, 0xB1, 0xB2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE }; static const uint8_t page25Start = 0x00; bool OF_VISIBILITY_HIDDEN _OFUnicodeToCodepage850(const OFUnichar *input, unsigned char *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { OFUnichar c = input[i]; if OF_UNLIKELY (c > 0x7F) { uint8_t idx; if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; continue; } else return false; } switch (c >> 8) { CASE_MISSING_IS_ERROR(0) CASE_MISSING_IS_ERROR(1) CASE_MISSING_IS_ERROR(20) CASE_MISSING_IS_ERROR(25) default: if (lossy) { output[i] = '?'; continue; } else return false; } } else output[i] = (unsigned char)c; } return true; } objfw-1.1.6/src/encodings/codepage-858.m000066400000000000000000000126331465614216400176530ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFString.h" #import "common.h" const OFChar16 _OFCodepage858Table[] OF_VISIBILITY_HIDDEN = { 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5, 0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x0192, 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB, 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0, 0x00A9, 0x2563, 0x2551, 0x2557, 0x255D, 0x00A2, 0x00A5, 0x2510, 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4, 0x00F0, 0x00D0, 0x00CA, 0x00CB, 0x00C8, 0x20AC, 0x00CD, 0x00CE, 0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00A6, 0x00CC, 0x2580, 0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x00FE, 0x00DE, 0x00DA, 0x00DB, 0x00D9, 0x00FD, 0x00DD, 0x00AF, 0x00B4, 0x00AD, 0x00B1, 0x2017, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8, 0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0 }; const size_t _OFCodepage858TableOffset OF_VISIBILITY_HIDDEN = 256 - (sizeof(_OFCodepage858Table) / sizeof(*_OFCodepage858Table)); static const unsigned char page0[] = { 0xFF, 0xAD, 0xBD, 0x9C, 0xCF, 0xBE, 0xDD, 0xF5, 0xF9, 0xB8, 0xA6, 0xAE, 0xAA, 0xF0, 0xA9, 0xEE, 0xF8, 0xF1, 0xFD, 0xFC, 0xEF, 0xE6, 0xF4, 0xFA, 0xF7, 0xFB, 0xA7, 0xAF, 0xAC, 0xAB, 0xF3, 0xA8, 0xB7, 0xB5, 0xB6, 0xC7, 0x8E, 0x8F, 0x92, 0x80, 0xD4, 0x90, 0xD2, 0xD3, 0xDE, 0xD6, 0xD7, 0xD8, 0xD1, 0xA5, 0xE3, 0xE0, 0xE2, 0xE5, 0x99, 0x9E, 0x9D, 0xEB, 0xE9, 0xEA, 0x9A, 0xED, 0xE8, 0xE1, 0x85, 0xA0, 0x83, 0xC6, 0x84, 0x86, 0x91, 0x87, 0x8A, 0x82, 0x88, 0x89, 0x8D, 0xA1, 0x8C, 0x8B, 0xD0, 0xA4, 0x95, 0xA2, 0x93, 0xE4, 0x94, 0xF6, 0x9B, 0x97, 0xA3, 0x96, 0x81, 0xEC, 0xE7, 0x98 }; static const uint8_t page0Start = 0xA0; static const unsigned char page1[] = { 0x9F }; static const uint8_t page1Start = 0x92; static const unsigned char page20[] = { 0xF2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD5 }; static const uint8_t page20Start = 0x17; static const unsigned char page25[] = { 0xC4, 0x00, 0xB3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDA, 0x00, 0x00, 0x00, 0xBF, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0xD9, 0x00, 0x00, 0x00, 0xC3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCD, 0xBA, 0x00, 0x00, 0xC9, 0x00, 0x00, 0xBB, 0x00, 0x00, 0xC8, 0x00, 0x00, 0xBC, 0x00, 0x00, 0xCC, 0x00, 0x00, 0xB9, 0x00, 0x00, 0xCB, 0x00, 0x00, 0xCA, 0x00, 0x00, 0xCE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDF, 0x00, 0x00, 0x00, 0xDC, 0x00, 0x00, 0x00, 0xDB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0, 0xB1, 0xB2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE }; static const uint8_t page25Start = 0x00; bool OF_VISIBILITY_HIDDEN _OFUnicodeToCodepage858(const OFUnichar *input, unsigned char *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { OFUnichar c = input[i]; if OF_UNLIKELY (c > 0x7F) { uint8_t idx; if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; continue; } else return false; } switch (c >> 8) { CASE_MISSING_IS_ERROR(0) CASE_MISSING_IS_ERROR(1) CASE_MISSING_IS_ERROR(20) CASE_MISSING_IS_ERROR(25) default: if (lossy) { output[i] = '?'; continue; } else return false; } } else output[i] = (unsigned char)c; } return true; } objfw-1.1.6/src/encodings/common.h000066400000000000000000000034361465614216400170460ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #define CASE_MISSING_IS_KEEP(nr) \ case nr: \ if OF_UNLIKELY ((c & 0xFF) < page##nr##Start) { \ output[i] = (unsigned char)c; \ continue; \ } \ \ idx = (c & 0xFF) - page##nr##Start; \ \ if (idx >= sizeof(page##nr)) { \ output[i] = (unsigned char)c; \ continue; \ } \ \ if (page##nr[idx] == 0x00) { \ if (lossy) { \ output[i] = '?'; \ continue; \ } else \ return false; \ } \ \ output[i] = page##nr[idx]; \ break; #define CASE_MISSING_IS_ERROR(nr) \ case 0x##nr: \ if OF_UNLIKELY ((c & 0xFF) < page##nr##Start) { \ if (lossy) { \ output[i] = '?'; \ continue; \ } else \ return false; \ } \ \ idx = (c & 0xFF) - page##nr##Start; \ \ if (idx >= sizeof(page##nr) || page##nr[idx] == 0) { \ if (lossy) { \ output[i] = '?'; \ continue; \ } else \ return false; \ } \ \ output[i] = page##nr[idx]; \ break; objfw-1.1.6/src/encodings/iso-8859-15.m000066400000000000000000000060341465614216400172100ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFString.h" #import "common.h" const OFChar16 _OFISO8859_15Table[] OF_VISIBILITY_HIDDEN = { 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x20AC, 0x00A5, 0x0160, 0x00A7, 0x0161, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x017D, 0x00B5, 0x00B6, 0x00B7, 0x017E, 0x00B9, 0x00BA, 0x00BB, 0x0152, 0x0153, 0x0178, 0x00BF, 0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF, 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7, 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF, 0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7, 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, 0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF }; const size_t _OFISO8859_15TableOffset OF_VISIBILITY_HIDDEN = 256 - (sizeof(_OFISO8859_15Table) / sizeof(*_OFISO8859_15Table)); static const unsigned char page0[] = { 0x00, 0xA5, 0x00, 0xA7, 0x00, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, 0x00, 0xB5, 0xB6, 0xB7, 0x00, 0xB9, 0xBA, 0xBB, 0x00, 0x00, 0x00 }; static const uint8_t page0Start = 0xA4; static const unsigned char page1[] = { 0xBC, 0xBD, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA6, 0xA8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBE, 0x00, 0x00, 0x00, 0x00, 0xB4, 0xB8 }; static const uint8_t page1Start = 0x52; static const unsigned char page20[] = { 0xA4 }; static const uint8_t page20Start = 0xAC; bool OF_VISIBILITY_HIDDEN _OFUnicodeToISO8859_15(const OFUnichar *input, unsigned char *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { OFUnichar c = input[i]; if OF_UNLIKELY (c > 0x7F) { uint8_t idx; if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; continue; } else return false; } switch (c >> 8) { CASE_MISSING_IS_KEEP(0) CASE_MISSING_IS_ERROR(1) CASE_MISSING_IS_ERROR(20) default: if (lossy) { output[i] = '?'; continue; } else return false; } } else output[i] = (unsigned char)c; } return true; } objfw-1.1.6/src/encodings/iso-8859-2.m000066400000000000000000000100521465614216400171170ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFString.h" #import "common.h" const OFChar16 _OFISO8859_2Table[] OF_VISIBILITY_HIDDEN = { 0x00A0, 0x0104, 0x02D8, 0x0141, 0x00A4, 0x013D, 0x015A, 0x00A7, 0x00A8, 0x0160, 0x015E, 0x0164, 0x0179, 0x00AD, 0x017D, 0x017B, 0x00B0, 0x0105, 0x02DB, 0x0142, 0x00B4, 0x013E, 0x015B, 0x02C7, 0x00B8, 0x0161, 0x015F, 0x0165, 0x017A, 0x02DD, 0x017E, 0x017C, 0x0154, 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x0139, 0x0106, 0x00C7, 0x010C, 0x00C9, 0x0118, 0x00CB, 0x011A, 0x00CD, 0x00CE, 0x010E, 0x0110, 0x0143, 0x0147, 0x00D3, 0x00D4, 0x0150, 0x00D6, 0x00D7, 0x0158, 0x016E, 0x00DA, 0x0170, 0x00DC, 0x00DD, 0x0162, 0x00DF, 0x0155, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x013A, 0x0107, 0x00E7, 0x010D, 0x00E9, 0x0119, 0x00EB, 0x011B, 0x00ED, 0x00EE, 0x010F, 0x0111, 0x0144, 0x0148, 0x00F3, 0x00F4, 0x0151, 0x00F6, 0x00F7, 0x0159, 0x016F, 0x00FA, 0x0171, 0x00FC, 0x00FD, 0x0163, 0x02D9 }; const size_t _OFISO8859_2TableOffset OF_VISIBILITY_HIDDEN = 256 - (sizeof(_OFISO8859_2Table) / sizeof(*_OFISO8859_2Table)); static const unsigned char page0[] = { 0xA0, 0x00, 0x00, 0x00, 0xA4, 0x00, 0x00, 0xA7, 0xA8, 0x00, 0x00, 0x00, 0x00, 0xAD, 0x00, 0x00, 0xB0, 0x00, 0x00, 0x00, 0xB4, 0x00, 0x00, 0x00, 0xB8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC1, 0xC2, 0x00, 0xC4, 0x00, 0x00, 0xC7, 0x00, 0xC9, 0x00, 0xCB, 0x00, 0xCD, 0xCE, 0x00, 0x00, 0x00, 0x00, 0xD3, 0xD4, 0x00, 0xD6, 0xD7, 0x00, 0x00, 0xDA, 0x00, 0xDC, 0xDD, 0x00, 0xDF, 0x00, 0xE1, 0xE2, 0x00, 0xE4, 0x00, 0x00, 0xE7, 0x00, 0xE9, 0x00, 0xEB, 0x00, 0xED, 0xEE, 0x00, 0x00, 0x00, 0x00, 0xF3, 0xF4, 0x00, 0xF6, 0xF7, 0x00, 0x00, 0xFA, 0x00, 0xFC, 0xFD, 0x00, 0x00 }; static const uint8_t page0Start = 0xA0; static const unsigned char page1[] = { 0xC3, 0xE3, 0xA1, 0xB1, 0xC6, 0xE6, 0x00, 0x00, 0x00, 0x00, 0xC8, 0xE8, 0xCF, 0xEF, 0xD0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCA, 0xEA, 0xCC, 0xEC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC5, 0xE5, 0x00, 0x00, 0xA5, 0xB5, 0x00, 0x00, 0xA3, 0xB3, 0xD1, 0xF1, 0x00, 0x00, 0xD2, 0xF2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD5, 0xF5, 0x00, 0x00, 0xC0, 0xE0, 0x00, 0x00, 0xD8, 0xF8, 0xA6, 0xB6, 0x00, 0x00, 0xAA, 0xBA, 0xA9, 0xB9, 0xDE, 0xFE, 0xAB, 0xBB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD9, 0xF9, 0xDB, 0xFB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAC, 0xBC, 0xAF, 0xBF, 0xAE, 0xBE }; static const uint8_t page1Start = 0x02; static const unsigned char page2[] = { 0xB7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2, 0xFF, 0x00, 0xB2, 0x00, 0xBD }; static const uint8_t page2Start = 0xC7; bool OF_VISIBILITY_HIDDEN _OFUnicodeToISO8859_2(const OFUnichar *input, unsigned char *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { OFUnichar c = input[i]; if OF_UNLIKELY (c > 0x7F) { uint8_t idx; if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; continue; } else return false; } switch (c >> 8) { CASE_MISSING_IS_KEEP(0) CASE_MISSING_IS_ERROR(1) CASE_MISSING_IS_ERROR(2) default: if (lossy) { output[i] = '?'; continue; } else return false; } } else output[i] = (unsigned char)c; } return true; } objfw-1.1.6/src/encodings/iso-8859-3.m000066400000000000000000000075711465614216400171340ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFString.h" #import "common.h" const OFChar16 _OFISO8859_3Table[] OF_VISIBILITY_HIDDEN = { 0x00A0, 0x0126, 0x02D8, 0x00A3, 0x00A4, 0xFFFF, 0x0124, 0x00A7, 0x00A8, 0x0130, 0x015E, 0x011E, 0x0134, 0x00AD, 0xFFFF, 0x017B, 0x00B0, 0x0127, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x0125, 0x00B7, 0x00B8, 0x0131, 0x015F, 0x011F, 0x0135, 0x00BD, 0xFFFF, 0x017C, 0x00C0, 0x00C1, 0x00C2, 0xFFFF, 0x00C4, 0x010A, 0x0108, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF, 0xFFFF, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x0120, 0x00D6, 0x00D7, 0x011C, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x016C, 0x015C, 0x00DF, 0x00E0, 0x00E1, 0x00E2, 0xFFFF, 0x00E4, 0x010B, 0x0109, 0x00E7, 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, 0xFFFF, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x0121, 0x00F6, 0x00F7, 0x011D, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x016D, 0x015D, 0x02D9 }; const size_t _OFISO8859_3TableOffset OF_VISIBILITY_HIDDEN = 256 - (sizeof(_OFISO8859_3Table) / sizeof(*_OFISO8859_3Table)); static const unsigned char page0[] = { 0xA0, 0x00, 0x00, 0xA3, 0xA4, 0x00, 0x00, 0xA7, 0xA8, 0x00, 0x00, 0x00, 0x00, 0xAD, 0x00, 0x00, 0xB0, 0x00, 0xB2, 0xB3, 0xB4, 0xB5, 0x00, 0xB7, 0xB8, 0x00, 0x00, 0x00, 0x00, 0xBD, 0x00, 0x00, 0xC0, 0xC1, 0xC2, 0x00, 0xC4, 0x00, 0x00, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0x00, 0xD1, 0xD2, 0xD3, 0xD4, 0x00, 0xD6, 0xD7, 0x00, 0xD9, 0xDA, 0xDB, 0xDC, 0x00, 0x00, 0xDF, 0xE0, 0xE1, 0xE2, 0x00, 0xE4, 0x00, 0x00, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0x00, 0xF1, 0xF2, 0xF3, 0xF4, 0x00, 0xF6, 0xF7, 0x00, 0xF9, 0xFA, 0xFB, 0xFC, 0x00, 0x00, 0x00 }; static const uint8_t page0Start = 0xA0; static const unsigned char page1[] = { 0xC6, 0xE6, 0xC5, 0xE5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD8, 0xF8, 0xAB, 0xBB, 0xD5, 0xF5, 0x00, 0x00, 0xA6, 0xB6, 0xA1, 0xB1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA9, 0xB9, 0x00, 0x00, 0xAC, 0xBC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDE, 0xFE, 0xAA, 0xBA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDD, 0xFD, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAF, 0xBF }; static const uint8_t page1Start = 0x08; static const unsigned char page2[] = { 0xA2, 0xFF }; static const uint8_t page2Start = 0xD8; bool OF_VISIBILITY_HIDDEN _OFUnicodeToISO8859_3(const OFUnichar *input, unsigned char *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { OFUnichar c = input[i]; if OF_UNLIKELY (c > 0x7F) { uint8_t idx; if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; continue; } else return false; } switch (c >> 8) { CASE_MISSING_IS_KEEP(0) CASE_MISSING_IS_ERROR(1) CASE_MISSING_IS_ERROR(2) default: if (lossy) { output[i] = '?'; continue; } else return false; } } else output[i] = (unsigned char)c; } return true; } objfw-1.1.6/src/encodings/koi8-r.m000066400000000000000000000127651465614216400167010ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFString.h" #import "common.h" const OFChar16 _OFKOI8RTable[] OF_VISIBILITY_HIDDEN = { 0x2500, 0x2502, 0x250C, 0x2510, 0x2514, 0x2518, 0x251C, 0x2524, 0x252C, 0x2534, 0x253C, 0x2580, 0x2584, 0x2588, 0x258C, 0x2590, 0x2591, 0x2592, 0x2593, 0x2320, 0x25A0, 0x2219, 0x221A, 0x2248, 0x2264, 0x2265, 0x00A0, 0x2321, 0x00B0, 0x00B2, 0x00B7, 0x00F7, 0x2550, 0x2551, 0x2552, 0x0451, 0x2553, 0x2554, 0x2555, 0x2556, 0x2557, 0x2558, 0x2559, 0x255A, 0x255B, 0x255C, 0x255D, 0x255E, 0x255F, 0x2560, 0x2561, 0x0401, 0x2562, 0x2563, 0x2564, 0x2565, 0x2566, 0x2567, 0x2568, 0x2569, 0x256A, 0x256B, 0x256C, 0x00A9, 0x044E, 0x0430, 0x0431, 0x0446, 0x0434, 0x0435, 0x0444, 0x0433, 0x0445, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F, 0x044F, 0x0440, 0x0441, 0x0442, 0x0443, 0x0436, 0x0432, 0x044C, 0x044B, 0x0437, 0x0448, 0x044D, 0x0449, 0x0447, 0x044A, 0x042E, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413, 0x0425, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F, 0x042F, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412, 0x042C, 0x042B, 0x0417, 0x0428, 0x042D, 0x0429, 0x0427, 0x042A }; const size_t _OFKOI8RTableOffset OF_VISIBILITY_HIDDEN = 256 - (sizeof(_OFKOI8RTable) / sizeof(*_OFKOI8RTable)); static const unsigned char page0[] = { 0x9A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9C, 0x00, 0x9D, 0x00, 0x00, 0x00, 0x00, 0x9E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9F }; static const uint8_t page0Start = 0xA0; static const unsigned char page4[] = { 0xB3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE1, 0xE2, 0xF7, 0xE7, 0xE4, 0xE5, 0xF6, 0xFA, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF2, 0xF3, 0xF4, 0xF5, 0xE6, 0xE8, 0xE3, 0xFE, 0xFB, 0xFD, 0xFF, 0xF9, 0xF8, 0xFC, 0xE0, 0xF1, 0xC1, 0xC2, 0xD7, 0xC7, 0xC4, 0xC5, 0xD6, 0xDA, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD2, 0xD3, 0xD4, 0xD5, 0xC6, 0xC8, 0xC3, 0xDE, 0xDB, 0xDD, 0xDF, 0xD9, 0xD8, 0xDC, 0xC0, 0xD1, 0x00, 0xA3 }; static const uint8_t page4Start = 0x01; static const unsigned char page22[] = { 0x95, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x97, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x98, 0x99 }; static const uint8_t page22Start = 0x19; static const unsigned char page23[] = { 0x93, 0x9B }; static const uint8_t page23Start = 0x20; static const unsigned char page25[] = { 0x80, 0x00, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00, 0x00, 0x83, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x85, 0x00, 0x00, 0x00, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x89, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0xA1, 0xA2, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8B, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x00, 0x8D, 0x00, 0x00, 0x00, 0x8E, 0x00, 0x00, 0x00, 0x8F, 0x90, 0x91, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x94 }; static const uint8_t page25Start = 0x00; bool OF_VISIBILITY_HIDDEN _OFUnicodeToKOI8R(const OFUnichar *input, unsigned char *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { OFUnichar c = input[i]; if OF_UNLIKELY (c > 0x7F) { uint8_t idx; if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; continue; } else return false; } switch (c >> 8) { CASE_MISSING_IS_ERROR(0) CASE_MISSING_IS_ERROR(4) CASE_MISSING_IS_ERROR(22) CASE_MISSING_IS_ERROR(23) CASE_MISSING_IS_ERROR(25) default: if (lossy) { output[i] = '?'; continue; } else return false; } } else output[i] = (unsigned char)c; } return true; } objfw-1.1.6/src/encodings/koi8-u.m000066400000000000000000000135751465614216400167040ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFString.h" #import "common.h" const OFChar16 _OFKOI8UTable[] OF_VISIBILITY_HIDDEN = { 0x2500, 0x2502, 0x250C, 0x2510, 0x2514, 0x2518, 0x251C, 0x2524, 0x252C, 0x2534, 0x253C, 0x2580, 0x2584, 0x2588, 0x258C, 0x2590, 0x2591, 0x2592, 0x2593, 0x2320, 0x25A0, 0x2219, 0x221A, 0x2248, 0x2264, 0x2265, 0x00A0, 0x2321, 0x00B0, 0x00B2, 0x00B7, 0x00F7, 0x2550, 0x2551, 0x2552, 0x0451, 0x0454, 0x2554, 0x0456, 0x0457, 0x2557, 0x2558, 0x2559, 0x255A, 0x255B, 0x0491, 0x255D, 0x255E, 0x255F, 0x2560, 0x2561, 0x0401, 0x0404, 0x2563, 0x0406, 0x0407, 0x2566, 0x2567, 0x2568, 0x2569, 0x256A, 0x0490, 0x256C, 0x00A9, 0x044E, 0x0430, 0x0431, 0x0446, 0x0434, 0x0435, 0x0444, 0x0433, 0x0445, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F, 0x044F, 0x0440, 0x0441, 0x0442, 0x0443, 0x0436, 0x0432, 0x044C, 0x044B, 0x0437, 0x0448, 0x044D, 0x0449, 0x0447, 0x044A, 0x042E, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413, 0x0425, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F, 0x042F, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412, 0x042C, 0x042B, 0x0417, 0x0428, 0x042D, 0x0429, 0x0427, 0x042A }; const size_t _OFKOI8UTableOffset OF_VISIBILITY_HIDDEN = 256 - (sizeof(_OFKOI8UTable) / sizeof(*_OFKOI8UTable)); static const unsigned char page0[] = { 0x9A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9C, 0x00, 0x9D, 0x00, 0x00, 0x00, 0x00, 0x9E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9F }; static const uint8_t page0Start = 0xA0; static const unsigned char page4[] = { 0xB3, 0x00, 0x00, 0xB4, 0x00, 0xB6, 0xB7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE1, 0xE2, 0xF7, 0xE7, 0xE4, 0xE5, 0xF6, 0xFA, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF2, 0xF3, 0xF4, 0xF5, 0xE6, 0xE8, 0xE3, 0xFE, 0xFB, 0xFD, 0xFF, 0xF9, 0xF8, 0xFC, 0xE0, 0xF1, 0xC1, 0xC2, 0xD7, 0xC7, 0xC4, 0xC5, 0xD6, 0xDA, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD2, 0xD3, 0xD4, 0xD5, 0xC6, 0xC8, 0xC3, 0xDE, 0xDB, 0xDD, 0xDF, 0xD9, 0xD8, 0xDC, 0xC0, 0xD1, 0x00, 0xA3, 0x00, 0x00, 0xA4, 0x00, 0xA6, 0xA7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBD, 0xAD }; static const uint8_t page4Start = 0x01; static const unsigned char page22[] = { 0x95, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x97, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x98, 0x99 }; static const uint8_t page22Start = 0x19; static const unsigned char page23[] = { 0x93, 0x9B }; static const uint8_t page23Start = 0x20; static const unsigned char page25[] = { 0x80, 0x00, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00, 0x00, 0x83, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x85, 0x00, 0x00, 0x00, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x89, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0xA1, 0xA2, 0x00, 0xA5, 0x00, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0x00, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0x00, 0xB5, 0x00, 0x00, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0x00, 0xBE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8B, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x00, 0x8D, 0x00, 0x00, 0x00, 0x8E, 0x00, 0x00, 0x00, 0x8F, 0x90, 0x91, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x94 }; static const uint8_t page25Start = 0x00; bool OF_VISIBILITY_HIDDEN _OFUnicodeToKOI8U(const OFUnichar *input, unsigned char *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { OFUnichar c = input[i]; if OF_UNLIKELY (c > 0x7F) { uint8_t idx; if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; continue; } else return false; } switch (c >> 8) { CASE_MISSING_IS_ERROR(0) CASE_MISSING_IS_ERROR(4) CASE_MISSING_IS_ERROR(22) CASE_MISSING_IS_ERROR(23) CASE_MISSING_IS_ERROR(25) default: if (lossy) { output[i] = '?'; continue; } else return false; } } else output[i] = (unsigned char)c; } return true; } objfw-1.1.6/src/encodings/mac-roman.m000066400000000000000000000151511465614216400174320ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFString.h" #import "common.h" const OFChar16 _OFMacRomanTable[] OF_VISIBILITY_HIDDEN = { 0x00C4, 0x00C5, 0x00C7, 0x00C9, 0x00D1, 0x00D6, 0x00DC, 0x00E1, 0x00E0, 0x00E2, 0x00E4, 0x00E3, 0x00E5, 0x00E7, 0x00E9, 0x00E8, 0x00EA, 0x00EB, 0x00ED, 0x00EC, 0x00EE, 0x00EF, 0x00F1, 0x00F3, 0x00F2, 0x00F4, 0x00F6, 0x00F5, 0x00FA, 0x00F9, 0x00FB, 0x00FC, 0x2020, 0x00B0, 0x00A2, 0x00A3, 0x00A7, 0x2022, 0x00B6, 0x00DF, 0x00AE, 0x00A9, 0x2122, 0x00B4, 0x00A8, 0x2260, 0x00C6, 0x00D8, 0x221E, 0x00B1, 0x2264, 0x2265, 0x00A5, 0x00B5, 0x2202, 0x2211, 0x220F, 0x03C0, 0x222B, 0x00AA, 0x00BA, 0x03A9, 0x00E6, 0x00F8, 0x00BF, 0x00A1, 0x00AC, 0x221A, 0x0192, 0x2248, 0x2206, 0x00AB, 0x00BB, 0x2026, 0x00A0, 0x00C0, 0x00C3, 0x00D5, 0x0152, 0x0153, 0x2013, 0x2014, 0x201C, 0x201D, 0x2018, 0x2019, 0x00F7, 0x25CA, 0x00FF, 0x0178, 0x2044, 0x20AC, 0x2039, 0x203A, 0xFB01, 0xFB02, 0x2021, 0x00B7, 0x201A, 0x201E, 0x2030, 0x00C2, 0x00CA, 0x00C1, 0x00CB, 0x00C8, 0x00CD, 0x00CE, 0x00CF, 0x00CC, 0x00D3, 0x00D4, 0xF8FF, 0x00D2, 0x00DA, 0x00DB, 0x00D9, 0x0131, 0x02C6, 0x02DC, 0x00AF, 0x02D8, 0x02D9, 0x02DA, 0x00B8, 0x02DD, 0x02DB, 0x02C7 }; const size_t _OFMacRomanTableOffset OF_VISIBILITY_HIDDEN = 256 - (sizeof(_OFMacRomanTable) / sizeof(*_OFMacRomanTable)); static const unsigned char page0[] = { 0xCA, 0xC1, 0xA2, 0xA3, 0x00, 0xB4, 0x00, 0xA4, 0xAC, 0xA9, 0xBB, 0xC7, 0xC2, 0x00, 0xA8, 0xF8, 0xA1, 0xB1, 0x00, 0x00, 0xAB, 0xB5, 0xA6, 0xE1, 0xFC, 0x00, 0xBC, 0xC8, 0x00, 0x00, 0x00, 0xC0, 0xCB, 0xE7, 0xE5, 0xCC, 0x80, 0x81, 0xAE, 0x82, 0xE9, 0x83, 0xE6, 0xE8, 0xED, 0xEA, 0xEB, 0xEC, 0x00, 0x84, 0xF1, 0xEE, 0xEF, 0xCD, 0x85, 0x00, 0xAF, 0xF4, 0xF2, 0xF3, 0x86, 0x00, 0x00, 0xA7, 0x88, 0x87, 0x89, 0x8B, 0x8A, 0x8C, 0xBE, 0x8D, 0x8F, 0x8E, 0x90, 0x91, 0x93, 0x92, 0x94, 0x95, 0x00, 0x96, 0x98, 0x97, 0x99, 0x9B, 0x9A, 0xD6, 0xBF, 0x9D, 0x9C, 0x9E, 0x9F, 0x00, 0x00, 0xD8 }; static const uint8_t page0Start = 0xA0; static const unsigned char page1[] = { 0xF5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCE, 0xCF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC4 }; static const uint8_t page1Start = 0x31; static const unsigned char page2[] = { 0xF6, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF9, 0xFA, 0xFB, 0xFE, 0xF7, 0xFD }; static const uint8_t page2Start = 0xC6; static const unsigned char page3[] = { 0xBD, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB9 }; static const uint8_t page3Start = 0xA9; static const unsigned char page20[] = { 0xD0, 0xD1, 0x00, 0x00, 0x00, 0xD4, 0xD5, 0xE2, 0x00, 0xD2, 0xD3, 0xE3, 0x00, 0xA0, 0xE0, 0xA5, 0x00, 0x00, 0x00, 0xC9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDC, 0xDD, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDB }; static const uint8_t page20Start = 0x13; static const unsigned char page21[] = { 0xAA }; static const uint8_t page21Start = 0x22; static const unsigned char page22[] = { 0xB6, 0x00, 0x00, 0x00, 0xC6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB8, 0x00, 0xB7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC3, 0x00, 0x00, 0x00, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAD, 0x00, 0x00, 0x00, 0xB2, 0xB3 }; static const uint8_t page22Start = 0x02; static const unsigned char page25[] = { 0xD7 }; static const uint8_t page25Start = 0xCA; static const unsigned char pageF8[] = { 0xF0 }; static const uint8_t pageF8Start = 0xFF; static const unsigned char pageFB[] = { 0xDE, 0xDF }; static const uint8_t pageFBStart = 0x01; bool OF_VISIBILITY_HIDDEN _OFUnicodeToMacRoman(const OFUnichar *input, unsigned char *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { OFUnichar c = input[i]; if OF_UNLIKELY (c > 0x7F) { uint8_t idx; if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; continue; } else return false; } switch (c >> 8) { CASE_MISSING_IS_ERROR(0) CASE_MISSING_IS_ERROR(1) CASE_MISSING_IS_ERROR(2) CASE_MISSING_IS_ERROR(3) CASE_MISSING_IS_ERROR(20) CASE_MISSING_IS_ERROR(21) CASE_MISSING_IS_ERROR(22) CASE_MISSING_IS_ERROR(25) CASE_MISSING_IS_ERROR(F8) CASE_MISSING_IS_ERROR(FB) default: if (lossy) { output[i] = '?'; continue; } else return false; } } else output[i] = (unsigned char)c; } return true; } objfw-1.1.6/src/encodings/windows-1251.m000066400000000000000000000117731465614216400176460ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFString.h" #import "common.h" const OFChar16 _OFWindows1251Table[] OF_VISIBILITY_HIDDEN = { 0x0402, 0x0403, 0x201A, 0x0453, 0x201E, 0x2026, 0x2020, 0x2021, 0x20AC, 0x2030, 0x0409, 0x2039, 0x040A, 0x040C, 0x040B, 0x040F, 0x0452, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, 0xFFFF, 0x2122, 0x0459, 0x203A, 0x045A, 0x045C, 0x045B, 0x045F, 0x00A0, 0x040E, 0x045E, 0x0408, 0x00A4, 0x0490, 0x00A6, 0x00A7, 0x0401, 0x00A9, 0x0404, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x0407, 0x00B0, 0x00B1, 0x0406, 0x0456, 0x0491, 0x00B5, 0x00B6, 0x00B7, 0x0451, 0x2116, 0x0454, 0x00BB, 0x0458, 0x0405, 0x0455, 0x0457, 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F, 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F, 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F, 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F }; const size_t _OFWindows1251TableOffset OF_VISIBILITY_HIDDEN = 256 - (sizeof(_OFWindows1251Table) / sizeof(*_OFWindows1251Table)); static const unsigned char page0[] = { 0xA0, 0x00, 0x00, 0x00, 0xA4, 0x00, 0xA6, 0xA7, 0x00, 0xA9, 0x00, 0xAB, 0xAC, 0xAD, 0xAE, 0x00, 0xB0, 0xB1, 0x00, 0x00, 0x00, 0xB5, 0xB6, 0xB7, 0x00, 0x00, 0x00, 0xBB }; static const uint8_t page0Start = 0xA0; static const unsigned char page4[] = { 0xA8, 0x80, 0x81, 0xAA, 0xBD, 0xB2, 0xAF, 0xA3, 0x8A, 0x8C, 0x8E, 0x8D, 0x00, 0xA1, 0x8F, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 0x00, 0xB8, 0x90, 0x83, 0xBA, 0xBE, 0xB3, 0xBF, 0xBC, 0x9A, 0x9C, 0x9E, 0x9D, 0x00, 0xA2, 0x9F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA5, 0xB4 }; static const uint8_t page4Start = 0x01; static const unsigned char page20[] = { 0x96, 0x97, 0x00, 0x00, 0x00, 0x91, 0x92, 0x82, 0x00, 0x93, 0x94, 0x84, 0x00, 0x86, 0x87, 0x95, 0x00, 0x00, 0x00, 0x85, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x89, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8B, 0x9B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88 }; static const uint8_t page20Start = 0x13; static const unsigned char page21[] = { 0xB9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x99 }; static const uint8_t page21Start = 0x16; bool OF_VISIBILITY_HIDDEN _OFUnicodeToWindows1251(const OFUnichar *input, unsigned char *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { OFUnichar c = input[i]; if OF_UNLIKELY (c > 0x7F) { uint8_t idx; if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; continue; } else return false; } switch (c >> 8) { CASE_MISSING_IS_ERROR(0) CASE_MISSING_IS_ERROR(4) CASE_MISSING_IS_ERROR(20) CASE_MISSING_IS_ERROR(21) default: if (lossy) { output[i] = '?'; continue; } else return false; } } else output[i] = (unsigned char)c; } return true; } objfw-1.1.6/src/encodings/windows-1252.m000066400000000000000000000113321465614216400176360ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFString.h" #import "common.h" const OFChar16 _OFWindows1252Table[] OF_VISIBILITY_HIDDEN = { 0x20AC, 0xFFFF, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0xFFFF, 0x017D, 0xFFFF, 0xFFFF, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, 0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0xFFFF, 0x017E, 0x0178, 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7, 0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7, 0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF, 0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF, 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7, 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF, 0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7, 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, 0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF }; const size_t _OFWindows1252TableOffset OF_VISIBILITY_HIDDEN = 256 - (sizeof(_OFWindows1252Table) / sizeof(*_OFWindows1252Table)); static const unsigned char page0[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const uint8_t page0Start = 0x80; static const unsigned char page1[] = { 0x8C, 0x9C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8A, 0x9A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9F, 0x00, 0x00, 0x00, 0x00, 0x8E, 0x9E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83 }; static const uint8_t page1Start = 0x52; static const unsigned char page2[] = { 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x98 }; static const uint8_t page2Start = 0xC6; static const unsigned char page20[] = { 0x96, 0x97, 0x00, 0x00, 0x00, 0x91, 0x92, 0x82, 0x00, 0x93, 0x94, 0x84, 0x00, 0x86, 0x87, 0x95, 0x00, 0x00, 0x00, 0x85, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x89, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8B, 0x9B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }; static const uint8_t page20Start = 0x13; static const unsigned char page21[] = { 0x99 }; static const uint8_t page21Start = 0x22; bool OF_VISIBILITY_HIDDEN _OFUnicodeToWindows1252(const OFUnichar *input, unsigned char *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { OFUnichar c = input[i]; if OF_UNLIKELY (c > 0x7F) { uint8_t idx; if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; continue; } else return false; } switch (c >> 8) { CASE_MISSING_IS_KEEP(0) CASE_MISSING_IS_ERROR(1) CASE_MISSING_IS_ERROR(2) CASE_MISSING_IS_ERROR(20) CASE_MISSING_IS_ERROR(21) default: if (lossy) { output[i] = '?'; continue; } else return false; } } else output[i] = (unsigned char)c; } return true; } objfw-1.1.6/src/exceptions/000077500000000000000000000000001465614216400156075ustar00rootroot00000000000000objfw-1.1.6/src/exceptions/Makefile000066400000000000000000000071741465614216400172600ustar00rootroot00000000000000include ../../extra.mk STATIC_PIC_LIB_NOINST = ${EXCEPTIONS_LIB_A} STATIC_LIB_NOINST = ${EXCEPTIONS_A} SRCS = OFAllocFailedException.m \ OFAlreadyOpenException.m \ OFChecksumMismatchException.m \ OFCopyItemFailedException.m \ OFCreateDirectoryFailedException.m \ OFCreateSymbolicLinkFailedException.m \ OFEnumerationMutationException.m \ OFException.m \ OFGetItemAttributesFailedException.m \ OFGetOptionFailedException.m \ OFHashAlreadyCalculatedException.m \ OFHashNotCalculatedException.m \ OFInitializationFailedException.m \ OFInvalidArgumentException.m \ OFInvalidEncodingException.m \ OFInvalidFormatException.m \ OFInvalidJSONException.m \ OFInvalidServerResponseException.m \ OFLinkItemFailedException.m \ OFLockFailedException.m \ OFMalformedXMLException.m \ OFMoveItemFailedException.m \ OFNotImplementedException.m \ OFNotOpenException.m \ OFOpenItemFailedException.m \ OFOutOfMemoryException.m \ OFOutOfRangeException.m \ OFReadFailedException.m \ OFReadOrWriteFailedException.m \ OFRemoveItemFailedException.m \ OFSeekFailedException.m \ OFSetItemAttributesFailedException.m \ OFSetOptionFailedException.m \ OFStillLockedException.m \ OFTruncatedDataException.m \ OFUnboundNamespaceException.m \ OFUnboundPrefixException.m \ OFUndefinedKeyException.m \ OFUnknownXMLEntityException.m \ OFUnlockFailedException.m \ OFUnsupportedProtocolException.m \ OFUnsupportedVersionException.m \ OFWriteFailedException.m \ ${USE_SRCS_FILES} \ ${USE_SRCS_PLUGINS} \ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_THREADS} \ ${USE_SRCS_WINDOWS} SRCS_FILES = OFChangeCurrentDirectoryFailedException.m \ OFGetCurrentDirectoryFailedException.m SRCS_PLUGINS = OFLoadPluginFailedException.m SRCS_SOCKETS = OFAcceptSocketFailedException.m \ OFBindIPSocketFailedException.m \ OFBindSocketFailedException.m \ OFConnectIPSocketFailedException.m \ OFConnectSocketFailedException.m \ OFDNSQueryFailedException.m \ OFHTTPRequestFailedException.m \ OFListenOnSocketFailedException.m \ OFObserveKernelEventsFailedException.m \ OFResolveHostFailedException.m \ OFTLSHandshakeFailedException.m \ ${USE_SRCS_APPLETALK} \ ${USE_SRCS_IPX} \ ${USE_SRCS_UNIX_SOCKETS} SRCS_APPLETALK = OFBindDDPSocketFailedException.m SRCS_IPX = OFBindIPXSocketFailedException.m \ OFConnectSPXSocketFailedException.m SRCS_UNIX_SOCKETS = OFBindUNIXSocketFailedException.m \ OFConnectUNIXSocketFailedException.m SRCS_THREADS = OFBroadcastConditionFailedException.m \ OFConditionStillWaitingException.m \ OFJoinThreadFailedException.m \ OFSignalConditionFailedException.m \ OFStartThreadFailedException.m \ OFThreadStillRunningException.m \ OFWaitForConditionFailedException.m SRCS_WINDOWS = OFCreateWindowsRegistryKeyFailedException.m \ OFDeleteWindowsRegistryKeyFailedException.m \ OFDeleteWindowsRegistryValueFailedException.m \ OFGetWindowsRegistryValueFailedException.m \ OFOpenWindowsRegistryKeyFailedException.m \ OFSetWindowsRegistryValueFailedException.m INCLUDES := ${SRCS:.m=.h} SRCS += OFActivateSandboxFailedException.m include ../../buildsys.mk CPPFLAGS += -I. -I.. -I../.. -I../runtime objfw-1.1.6/src/exceptions/OFAcceptSocketFailedException.h000066400000000000000000000041251465614216400235430ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif OF_ASSUME_NONNULL_BEGIN /** * @class OFAcceptSocketFailedException \ * OFAcceptSocketFailedException.h ObjFW/OFAcceptSocketFailedException.h * * @brief An exception indicating that accepting a connection failed. */ @interface OFAcceptSocketFailedException: OFException { id _socket; int _errNo; OF_RESERVE_IVARS(OFAcceptSocketFailedException, 4) } /** * @brief The socket which could not accept a connection. */ @property (readonly, nonatomic) id socket; /** * @brief The errno from when the exception was created. */ @property (readonly, nonatomic) int errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Creates a new, autoreleased accept failed exception. * * @param socket The socket which could not accept a connection * @param errNo The errno for the error * @return A new, autoreleased accept failed exception */ + (instancetype)exceptionWithSocket: (id)socket errNo: (int)errNo; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated accept failed exception. * * @param socket The socket which could not accept a connection * @param errNo The errno for the error * @return An initialized accept failed exception */ - (instancetype)initWithSocket: (id)socket errNo: (int)errNo OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFAcceptSocketFailedException.m000066400000000000000000000030041465614216400235430ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFAcceptSocketFailedException.h" #import "OFString.h" @implementation OFAcceptSocketFailedException @synthesize socket = _socket, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo { return [[[self alloc] initWithSocket: sock errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithSocket: (id)sock errNo: (int)errNo { self = [super init]; _socket = [sock retain]; _errNo = errNo; return self; } - (void)dealloc { [_socket release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to accept connection in socket of class %@: %@", [_socket class], OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFActivateSandboxFailedException.h000066400000000000000000000024031465614216400242470ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFSandbox; @interface OFActivateSandboxFailedException: OFException { OFSandbox *_sandbox; int _errNo; } @property (readonly, nonatomic) OFSandbox *sandbox; @property (readonly, nonatomic) int errNo; + (instancetype)exception OF_UNAVAILABLE; + (instancetype)exceptionWithSandbox: (OFSandbox *)sandbox errNo: (int)errNo; - (instancetype)init OF_UNAVAILABLE; - (instancetype)initWithSandbox: (OFSandbox *)sandbox errNo: (int)errNo OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFActivateSandboxFailedException.m000066400000000000000000000030431465614216400242550ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFActivateSandboxFailedException.h" #import "OFString.h" #import "OFSandbox.h" @implementation OFActivateSandboxFailedException @synthesize sandbox = _sandbox, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithSandbox: (OFSandbox *)sandbox errNo: (int)errNo { return [[[self alloc] initWithSandbox: sandbox errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithSandbox: (OFSandbox *)sandbox errNo: (int)errNo { self = [super init]; _sandbox = [sandbox retain]; _errNo = errNo; return self; } - (void)dealloc { [_sandbox release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"The sandbox could not be applied: %@", OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFAllocFailedException.h000066400000000000000000000032551465614216400222300ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN @class OFString; /** * @class OFAllocFailedException \ * OFAllocFailedException.h ObjFW/OFAllocFailedException.h * * @brief An exception indicating an object could not be allocated. * * This exception is preallocated, as when there's no memory, no exception can * be allocated of course. That's why you shouldn't and even can't deallocate * it. * * This is the only exception which is not an OFException as it's special. It * does not know for which class allocation failed and it should not be handled * like other exceptions, as the exception handling code is not allowed to * allocate *any* memory. */ OF_SUBCLASSING_RESTRICTED @interface OFAllocFailedException: OFObject + (instancetype)exception OF_UNAVAILABLE; - (instancetype)init OF_UNAVAILABLE; /** * @brief Returns a description of the exception. * * @return A description of the exception */ - (OFString *)description; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFAllocFailedException.m000066400000000000000000000021231465614216400222260ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFAllocFailedException.h" #import "OFString.h" @implementation OFAllocFailedException + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)alloc { OF_UNRECOGNIZED_SELECTOR } - (instancetype)init { OF_INVALID_INIT_METHOD } OF_SINGLETON_METHODS - (OFString *)description { return @"Allocating an object failed!"; } @end objfw-1.1.6/src/exceptions/OFAlreadyOpenException.h000066400000000000000000000033651465614216400222760ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFAlreadyOpenException \ * OFAlreadyOpenException.h ObjFW/OFAlreadyOpenException.h * * @brief An exception indicating that an object is already open and thus * cannot be opened again. */ @interface OFAlreadyOpenException: OFException { id _object; OF_RESERVE_IVARS(OFAlreadyOpenException, 4) } /** * @brief The object which is already open. */ @property (readonly, nonatomic) id object; /** * @brief Creates a new, autoreleased already open exception. * * @param object The object which is already open * @return A new, autoreleased already open exception */ + (instancetype)exceptionWithObject: (id)object; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated already open exception. * * @param object The object which is already open * @return An initialized already open exception */ - (instancetype)initWithObject: (id)object OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFAlreadyOpenException.m000066400000000000000000000026611465614216400223010ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFAlreadyOpenException.h" #import "OFString.h" @implementation OFAlreadyOpenException @synthesize object = _object; + (instancetype)exceptionWithObject: (id)object { return [[[self alloc] initWithObject: object] autorelease]; } + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithObject: (id)object { self = [super init]; _object = [object retain]; return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_object release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"An object of type %@ is already open and thus cannot be opened " @"again!", [_object class]]; } @end objfw-1.1.6/src/exceptions/OFBindDDPSocketFailedException.h000066400000000000000000000061701465614216400235520ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFBindSocketFailedException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFBindDDPSocketFailedException \ * OFBindDDPSocketFailedException.h \ * ObjFW/OFBindDDPSocketFailedException.h * * @brief An exception indicating that binding a DDP socket failed. */ OF_SUBCLASSING_RESTRICTED @interface OFBindDDPSocketFailedException: OFBindSocketFailedException { uint16_t _network; uint8_t _node, _port, _protocolType; } /** * @brief The DDP network on which binding failed. */ @property (readonly, nonatomic) uint16_t network; /** * @brief The DDP node for which binding failed. */ @property (readonly, nonatomic) uint8_t node; /** * @brief The DDP port on which binding failed. */ @property (readonly, nonatomic) uint8_t port; /** * @brief The DDP protocol type for which binding failed. */ @property (readonly, nonatomic) uint8_t protocolType; /** * @brief Creates a new, autoreleased bind DDP socket failed exception. * * @param network The DDP network on which binding failed * @param node The DDP node for which binding failed * @param port The DDP port on which binding failed * @param protocolType The DDP protocol type for which binding failed. * @param socket The socket which could not be bound * @param errNo The errno of the error that occurred * @return A new, autoreleased bind DDP socket failed exception */ + (instancetype)exceptionWithNetwork: (uint16_t)network node: (uint8_t)node port: (uint8_t)port protocolType: (uint8_t)protocolType socket: (id)socket errNo: (int)errNo; + (instancetype)exceptionWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; /** * @brief Initializes an already allocated bind DDP socket failed exception. * * @param network The DDP network on which binding failed * @param node The DDP node for which binding failed * @param port The DDP port on which binding failed * @param protocolType The DDP protocol type for which binding failed. * @param socket The socket which could not be bound * @param errNo The errno of the error that occurred * @return An initialized bind DDP socket failed exception */ - (instancetype)initWithNetwork: (uint16_t)network node: (uint8_t)node port: (uint8_t)port protocolType: (uint8_t)protocolType socket: (id)socket errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)initWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFBindDDPSocketFailedException.m000066400000000000000000000043421465614216400235560ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFBindDDPSocketFailedException.h" #import "OFData.h" #import "OFString.h" @implementation OFBindDDPSocketFailedException @synthesize network = _network, node = _node, port = _port; @synthesize protocolType = _protocolType; + (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithNetwork: (uint16_t)network node: (uint8_t)node port: (uint8_t)port protocolType: (uint8_t)protocolType socket: (id)sock errNo: (int)errNo { return [[[self alloc] initWithNetwork: network node: node port: port protocolType: protocolType socket: sock errNo: errNo] autorelease]; } - (instancetype)initWithSocket: (id)sock errNo: (int)errNo { OF_INVALID_INIT_METHOD } - (instancetype)initWithNetwork: (uint16_t)network node: (uint8_t)node port: (uint8_t)port protocolType: (uint8_t)protocolType socket: (id)sock errNo: (int)errNo { self = [super initWithSocket: sock errNo: errNo]; @try { _network = network; _node = node; _port = port; _protocolType = protocolType; } @catch (id e) { [self release]; @throw e; } return self; } - (OFString *)description { return [OFString stringWithFormat: @"Binding to port %" @PRIx8 @" of node %" @PRIx8 @" on network " @"%" PRIx16 @" with protocol type 0x%" @PRIX8 @" failed in socket " @"of type %@: %@", _port, _node, _network, _protocolType, [_socket class], OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFBindIPSocketFailedException.h000066400000000000000000000050511465614216400234500ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFBindSocketFailedException.h" #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif OF_ASSUME_NONNULL_BEGIN /** * @class OFBindIPSocketFailedException \ * OFBindIPSocketFailedException.h ObjFW/OFBindIPSocketFailedException.h * * @brief An exception indicating that binding an IP socket failed. */ OF_SUBCLASSING_RESTRICTED @interface OFBindIPSocketFailedException: OFBindSocketFailedException { OFString *_Nullable _host; uint16_t _port; } /** * @brief The host on which binding failed. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *host; /** * @brief The port on which binding failed. */ @property (readonly, nonatomic) uint16_t port; /** * @brief Creates a new, autoreleased bind IP socket failed exception. * * @param host The host on which binding failed * @param port The port on which binding failed * @param socket The socket which could not be bound * @param errNo The errno of the error that occurred * @return A new, autoreleased bind IP socket failed exception */ + (instancetype)exceptionWithHost: (OFString *)host port: (uint16_t)port socket: (id)socket errNo: (int)errNo; + (instancetype)exceptionWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; /** * @brief Initializes an already allocated bind IP socket failed exception. * * @param host The host on which binding failed * @param port The port on which binding failed * @param socket The socket which could not be bound * @param errNo The errno of the error that occurred * @return An initialized bind IP socket failed exception */ - (instancetype)initWithHost: (OFString *)host port: (uint16_t)port socket: (id)socket errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)initWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFBindIPSocketFailedException.m000066400000000000000000000035711465614216400234620ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFBindIPSocketFailedException.h" #import "OFString.h" @implementation OFBindIPSocketFailedException @synthesize host = _host, port = _port; + (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithHost: (OFString *)host port: (uint16_t)port socket: (id)sock errNo: (int)errNo { return [[[self alloc] initWithHost: host port: port socket: sock errNo: errNo] autorelease]; } - (instancetype)initWithSocket: (id)sock errNo: (int)errNo { OF_INVALID_INIT_METHOD } - (instancetype)initWithHost: (OFString *)host port: (uint16_t)port socket: (id)sock errNo: (int)errNo { self = [super initWithSocket: sock errNo: errNo]; @try { _host = [host copy]; _port = port; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_host release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Binding to port %" @PRIu16 @" on host %@ failed in socket of " @"type %@: %@", _port, _host, [_socket class], OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFBindIPXSocketFailedException.h000066400000000000000000000064541465614216400236100ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFBindSocketFailedException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFBindIPXSocketFailedException \ * OFBindIPXSocketFailedException.h \ * ObjFW/OFBindIPXSocketFailedException.h * * @brief An exception indicating that binding an IPX socket failed. */ OF_SUBCLASSING_RESTRICTED @interface OFBindIPXSocketFailedException: OFBindSocketFailedException { uint32_t _network; unsigned char _node[IPX_NODE_LEN]; uint16_t _port; uint8_t _packetType; } /** * @brief The IPX network on which binding failed. */ @property (readonly, nonatomic) uint32_t network; /** * @brief The IPX port on which binding failed. */ @property (readonly, nonatomic) uint16_t port; /** * @brief The IPX packet type for which binding failed. */ @property (readonly, nonatomic) uint8_t packetType; /** * @brief Creates a new, autoreleased bind IPX socket failed exception. * * @param network The IPX network to which binding failed * @param node The IPX node to which binding failed * @param port The IPX port to which binding failed * @param packetType The IPX packet type for which binding failed * @param socket The socket which could not be bound * @param errNo The errno of the error that occurred * @return A new, autoreleased bind IPX socket failed exception */ + (instancetype) exceptionWithNetwork: (uint32_t)network node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port packetType: (uint8_t)packetType socket: (id)socket errNo: (int)errNo; + (instancetype)exceptionWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; /** * @brief Initializes an already allocated bind IPX socket failed exception. * * @param network The IPX network to which binding failed * @param node The IPX node to which binding failed * @param port The IPX port to which binding failed * @param packetType The IPX packet type for which binding failed * @param socket The socket which could not be bound * @param errNo The errno of the error that occurred * @return An initialized bind IPX socket failed exception */ - (instancetype) initWithNetwork: (uint32_t)network node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port packetType: (uint8_t)packetType socket: (id)socket errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)initWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; /** * @brief Get the IPX node for which binding failed. * * @param node A pointer to where to write the node to */ - (void)getNode: (unsigned char [_Nonnull IPX_NODE_LEN])node; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFBindIPXSocketFailedException.m000066400000000000000000000047271465614216400236160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFBindIPXSocketFailedException.h" #import "OFData.h" #import "OFString.h" @implementation OFBindIPXSocketFailedException @synthesize network = _network, port = _port, packetType = _packetType; + (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo { OF_UNRECOGNIZED_SELECTOR } + (instancetype) exceptionWithNetwork: (uint32_t)network node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port packetType: (uint8_t)packetType socket: (id)sock errNo: (int)errNo { return [[[self alloc] initWithNetwork: network node: node port: port packetType: packetType socket: sock errNo: errNo] autorelease]; } - (instancetype)initWithSocket: (id)sock errNo: (int)errNo { OF_INVALID_INIT_METHOD } - (instancetype) initWithNetwork: (uint32_t)network node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port packetType: (uint8_t)packetType socket: (id)sock errNo: (int)errNo { self = [super initWithSocket: sock errNo: errNo]; @try { _network = network; memcpy(_node, node, sizeof(_node)); _port = port; _packetType = packetType; } @catch (id e) { [self release]; @throw e; } return self; } - (void)getNode: (unsigned char [IPX_NODE_LEN])node { memcpy(node, _node, sizeof(_node)); } - (OFString *)description { return [OFString stringWithFormat: @"Binding to network %" @PRIx16 " on node " @"%02X:%02X:%02X:%02X:%02X:%02X with port %" @PRIx16 @" failed for " @"packet type %" @PRIx8 " in socket of type %@: %@", _network, _node[0], _node[1], _node[2], _node[3], _node[4], _node[5], _port, _packetType, [_socket class], OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFBindSocketFailedException.h000066400000000000000000000041371465614216400232230ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif #import "OFSocket.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFBindSocketFailedException \ * OFBindSocketFailedException.h ObjFW/OFBindSocketFailedException.h * * @brief An exception indicating that binding a socket failed. */ @interface OFBindSocketFailedException: OFException { id _socket; int _errNo; OF_RESERVE_IVARS(OFBindSocketFailedException, 4) } /** * @brief The socket which could not be bound. */ @property (readonly, nonatomic) id socket; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased bind socket failed exception. * * @param socket The socket which could not be bound * @param errNo The errno of the error that occurred * @return A new, autoreleased bind socket failed exception */ + (instancetype)exceptionWithSocket: (id)socket errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated bind socket failed exception. * * @param socket The socket which could not be bound * @param errNo The errno of the error that occurred * @return An initialized bind socket failed exception */ - (instancetype)initWithSocket: (id)socket errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFBindSocketFailedException.m000066400000000000000000000030571465614216400232300ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFBindSocketFailedException.h" #import "OFString.h" @implementation OFBindSocketFailedException @synthesize socket = _socket, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo { return [[[self alloc] initWithSocket: sock errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithSocket: (id)sock errNo: (int)errNo { self = [super init]; @try { _socket = [sock retain]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_socket release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Binding a socket of type %@ failed: %@", [_socket class], OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFBindUNIXSocketFailedException.h000066400000000000000000000044131465614216400237240ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFBindSocketFailedException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFBindUNIXSocketFailedException \ * OFBindUNIXSocketFailedException.h \ * ObjFW/OFBindUNIXSocketFailedException.h * * @brief An exception indicating that binding a UNIX socket failed. */ OF_SUBCLASSING_RESTRICTED @interface OFBindUNIXSocketFailedException: OFBindSocketFailedException { OFString *_Nullable _path; } /** * @brief The path on which binding failed. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *path; /** * @brief Creates a new, autoreleased bind UNIX socket failed exception. * * @param path The path on which binding failed * @param socket The socket which could not be bound * @param errNo The errno of the error that occurred * @return A new, autoreleased bind UNIX socket failed exception */ + (instancetype)exceptionWithPath: (nullable OFString *)path socket: (id)socket errNo: (int)errNo; + (instancetype)exceptionWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; /** * @brief Initializes an already allocated bind UNIX socket failed exception. * * @param path The path on which binding failed * @param socket The socket which could not be bound * @param errNo The errno of the error that occurred * @return An initialized bind UNIX socket failed exception */ - (instancetype)initWithPath: (nullable OFString *)path socket: (id)socket errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)initWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFBindUNIXSocketFailedException.m000066400000000000000000000033571465614216400237370ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFBindUNIXSocketFailedException.h" #import "OFString.h" @implementation OFBindUNIXSocketFailedException @synthesize path = _path; + (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithPath: (OFString *)path socket: (id)sock errNo: (int)errNo { return [[[self alloc] initWithPath: path socket: sock errNo: errNo] autorelease]; } - (instancetype)initWithSocket: (id)sock errNo: (int)errNo { OF_INVALID_INIT_METHOD } - (instancetype)initWithPath: (OFString *)path socket: (id)sock errNo: (int)errNo { self = [super initWithSocket: sock errNo: errNo]; @try { _path = [path copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_path release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Binding to path %@ failed in socket of type %@: %@", _path, [_socket class], OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFBroadcastConditionFailedException.h000066400000000000000000000044251465614216400247470ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #ifndef OF_HAVE_THREADS # error No threads available! #endif OF_ASSUME_NONNULL_BEGIN @class OFCondition; /** * @class OFBroadcastConditionFailedException \ * OFBroadcastConditionFailedException.h \ * ObjFW/OFBroadcastConditionFailedException.h * * @brief An exception indicating broadcasting a condition failed. */ @interface OFBroadcastConditionFailedException: OFException { OFCondition *_condition; int _errNo; OF_RESERVE_IVARS(OFBroadcastConditionFailedException, 4) } /** * @brief The condition which could not be broadcasted. */ @property (readonly, nonatomic) OFCondition *condition; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Returns a new, autoreleased condition broadcast failed exception. * * @param condition The condition which could not be broadcasted * @param errNo The errno of the error that occurred * @return A new, autoreleased condition broadcast failed exception */ + (instancetype)exceptionWithCondition: (OFCondition *)condition errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated condition broadcast failed exception. * * @param condition The condition which could not be broadcasted * @param errNo The errno of the error that occurred * @return An initialized condition broadcast failed exception */ - (instancetype)initWithCondition: (OFCondition *)condition errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFBroadcastConditionFailedException.m000066400000000000000000000032001465614216400247420ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFBroadcastConditionFailedException.h" #import "OFString.h" #import "OFCondition.h" @implementation OFBroadcastConditionFailedException @synthesize condition = _condition, errNo = _errNo; + (instancetype)exceptionWithCondition: (OFCondition *)condition errNo: (int)errNo { return [[[self alloc] initWithCondition: condition errNo: errNo] autorelease]; } + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithCondition: (OFCondition *)condition errNo: (int)errNo { self = [super init]; _condition = [condition retain]; _errNo = errNo; return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_condition release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Broadcasting a condition of type %@ failed: %s", _condition.class, strerror(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFChangeCurrentDirectoryFailedException.h000066400000000000000000000045011465614216400256060ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFChangeCurrentDirectoryFailedException \ * OFChangeCurrentDirectoryFailedException.h \ * ObjFW/OFChangeCurrentDirectoryFailedException.h * * @brief An exception indicating that changing the current directory path * failed. */ @interface OFChangeCurrentDirectoryFailedException: OFException { OFString *_path; int _errNo; OF_RESERVE_IVARS(OFChangeCurrentDirectoryFailedException, 4) } /** * @brief The path of the directory to which the current path could not be * changed. */ @property (readonly, nonatomic) OFString *path; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased change current directory path failed * exception. * * @param path The path of the directory to which the current path could not be * changed * @param errNo The errno of the error that occurred * @return A new, autoreleased change current directory path failed exception */ + (instancetype)exceptionWithPath: (OFString *)path errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated change directory failed exception. * * @param path The path of the directory to which the current path could not be * changed * @param errNo The errno of the error that occurred * @return An initialized change current directory path failed exception */ - (instancetype)initWithPath: (OFString *)path errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFChangeCurrentDirectoryFailedException.m000066400000000000000000000031071465614216400256140ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFChangeCurrentDirectoryFailedException.h" #import "OFString.h" @implementation OFChangeCurrentDirectoryFailedException @synthesize path = _path, errNo = _errNo; + (instancetype)exceptionWithPath: (OFString *)path errNo: (int)errNo { return [[[self alloc] initWithPath: path errNo: errNo] autorelease]; } + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithPath: (OFString *)path errNo: (int)errNo { self = [super init]; @try { _path = [path copy]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_path release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to change the current directory to %@: %@", _path, OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFChecksumMismatchException.h000066400000000000000000000042421465614216400233160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFChecksumMismatchException \ * OFChecksumMismatchException.h ObjFW/OFChecksumMismatchException.h * * @brief An exception indicating that a checksum did not match. */ @interface OFChecksumMismatchException: OFException { OFString *_actualChecksum, *_expectedChecksum; OF_RESERVE_IVARS(OFChecksumMismatchException, 4) } /** * @brief The actual checksum calculated. */ @property (readonly, nonatomic) OFString *actualChecksum; /** * @brief The expected checksum. */ @property (readonly, nonatomic) OFString *expectedChecksum; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Creates a new, autoreleased checksum mismatch exception. * * @param actualChecksum The actual checksum calculated * @param expectedChecksum The expected checksum * @return A new, autoreleased checksum mismatch exception. */ + (instancetype)exceptionWithActualChecksum: (OFString *)actualChecksum expectedChecksum: (OFString *)expectedChecksum; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated checksum mismatch exception. * * @param actualChecksum The actual checksum calculated * @param expectedChecksum The expected checksum * @return An initialized checksum mismatch exception. */ - (instancetype)initWithActualChecksum: (OFString *)actualChecksum expectedChecksum: (OFString *)expectedChecksum OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFChecksumMismatchException.m000066400000000000000000000035361465614216400233300ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFChecksumMismatchException.h" #import "OFString.h" @implementation OFChecksumMismatchException @synthesize actualChecksum = _actualChecksum; @synthesize expectedChecksum = _expectedChecksum; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithActualChecksum: (OFString *)actualChecksum expectedChecksum: (OFString *)expectedChecksum { return [[[self alloc] initWithActualChecksum: actualChecksum expectedChecksum: expectedChecksum] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithActualChecksum: (OFString *)actualChecksum expectedChecksum: (OFString *)expectedChecksum { self = [super init]; @try { _actualChecksum = [actualChecksum copy]; _expectedChecksum = [expectedChecksum copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_actualChecksum release]; [_expectedChecksum release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Checksum was %@ but %@ was expected!", _actualChecksum, _expectedChecksum]; } @end objfw-1.1.6/src/exceptions/OFConditionStillWaitingException.h000066400000000000000000000040121465614216400243420ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #ifndef OF_HAVE_THREADS # error No threads available! #endif OF_ASSUME_NONNULL_BEGIN @class OFCondition; /** * @class OFConditionStillWaitingException \ * OFConditionStillWaitingException.h \ * ObjFW/OFConditionStillWaitingException.h * * @brief An exception indicating that a thread is still waiting for a * condition. */ @interface OFConditionStillWaitingException: OFException { OFCondition *_condition; OF_RESERVE_IVARS(OFConditionStillWaitingException, 4) } /** * @brief The condition for which is still being waited. */ @property (readonly, nonatomic) OFCondition *condition; /** * @brief Creates a new, autoreleased condition still waiting exception. * * @param condition The condition for which is still being waited * @return A new, autoreleased condition still waiting exception */ + (instancetype)exceptionWithCondition: (OFCondition *)condition; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated condition still waiting exception. * * @param condition The condition for which is still being waited * @return An initialized condition still waiting exception */ - (instancetype)initWithCondition: (OFCondition *)condition OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFConditionStillWaitingException.m000066400000000000000000000030571465614216400243570ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFConditionStillWaitingException.h" #import "OFString.h" #import "OFCondition.h" @implementation OFConditionStillWaitingException @synthesize condition = _condition; + (instancetype)exceptionWithCondition: (OFCondition *)condition { return [[[self alloc] initWithCondition: condition] autorelease]; } + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithCondition: (OFCondition *)condition { self = [super init]; _condition = [condition retain]; return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_condition release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Deallocation of a condition of type %@ was tried, even though " "a thread was still waiting for it!", _condition.class]; } @end objfw-1.1.6/src/exceptions/OFConnectIPSocketFailedException.h000066400000000000000000000051571465614216400241740ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFConnectSocketFailedException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFConnectIPSocketFailedException \ * OFConnectIPSocketFailedException.h \ * ObjFW/OFConnectIPSocketFailedException.h * * @brief An exception indicating that an IP connection could not be * established. */ OF_SUBCLASSING_RESTRICTED @interface OFConnectIPSocketFailedException: OFConnectSocketFailedException { OFString *_Nullable _host; uint16_t _port; } /** * @brief The host to which the connection failed. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *host; /** * @brief The port on the host to which the connection failed. */ @property (readonly, nonatomic) uint16_t port; /** * @brief Creates a new, autoreleased connect IP socket failed exception. * * @param host The host to which the connection failed * @param port The port on the host to which the connection failed * @param socket The socket which could not connect * @param errNo The errno of the error that occurred * @return A new, autoreleased connect IP socket failed exception */ + (instancetype)exceptionWithHost: (OFString *)host port: (uint16_t)port socket: (id)socket errNo: (int)errNo; + (instancetype)exceptionWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; /** * @brief Initializes an already allocated connect IP socket failed exception. * * @param host The host to which the connection failed * @param port The port on the host to which the connection failed * @param socket The socket which could not connect * @param errNo The errno of the error that occurred * @return An initialized connect IP socket failed exception */ - (instancetype)initWithHost: (OFString *)host port: (uint16_t)port socket: (id)socket errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)initWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFConnectIPSocketFailedException.m000066400000000000000000000036211465614216400241730ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFConnectIPSocketFailedException.h" #import "OFString.h" @implementation OFConnectIPSocketFailedException @synthesize host = _host, port = _port; + (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithHost: (OFString *)host port: (uint16_t)port socket: (id)sock errNo: (int)errNo { return [[[self alloc] initWithHost: host port: port socket: sock errNo: errNo] autorelease]; } - (instancetype)initWithSocket: (id)sock errNo: (int)errNo { OF_INVALID_INIT_METHOD } - (instancetype)initWithHost: (OFString *)host port: (uint16_t)port socket: (id)sock errNo: (int)errNo { self = [super initWithSocket: sock errNo: errNo]; @try { _host = [host copy]; _port = port; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_host release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"A connection to %@ on port %" @PRIu16 @" could not be " @"established in socket of type %@: %@", _host, _port, [_socket class], OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFConnectSPXSocketFailedException.h000066400000000000000000000061711465614216400243330ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFConnectSocketFailedException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFConnectSPXSocketFailedException \ * OFConnectSPXSocketFailedException.h \ * ObjFW/OFConnectSocketFailedException.h * * @brief An exception indicating that an SPX connection could not be * established. */ OF_SUBCLASSING_RESTRICTED @interface OFConnectSPXSocketFailedException: OFConnectSocketFailedException { uint32_t _network; unsigned char _node[IPX_NODE_LEN]; uint16_t _port; } /** * @brief The IPX network of the node to which the connection failed. */ @property (readonly, nonatomic) uint32_t network; /** * @brief The IPX port on the host to which the connection failed. */ @property (readonly, nonatomic) uint16_t port; /** * @brief Creates a new, autoreleased connect SPX socket failed exception. * * @param network The IPX network of the node to which the connection failed * @param node The node to which the connection failed * @param port The port on the node to which the connection failed * @param socket The socket which could not connect * @param errNo The errno of the error that occurred * @return A new, autoreleased connect SPX socket failed exception */ + (instancetype) exceptionWithNetwork: (uint32_t)network node: (const unsigned char [_Nullable IPX_NODE_LEN])node port: (uint16_t)port socket: (id)socket errNo: (int)errNo; + (instancetype)exceptionWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; /** * @brief Initializes an already allocated connect SPX socket failed exception. * * @param network The IPX network of the node to which the connection failed * @param node The node to which the connection failed * @param port The port on the node to which the connection failed * @param socket The socket which could not connect * @param errNo The errno of the error that occurred * @return An initialized connect SPX socket failed exception */ - (instancetype) initWithNetwork: (uint32_t)network node: (const unsigned char [_Nullable IPX_NODE_LEN])node port: (uint16_t)port socket: (id)socket errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)initWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; /** * @brief Get the IPX node to which the connection failed. * * @param node A pointer to where to write the node to */ - (void)getNode: (unsigned char [_Nonnull IPX_NODE_LEN])node; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFConnectSPXSocketFailedException.m000066400000000000000000000044011465614216400243320ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFConnectSPXSocketFailedException.h" #import "OFData.h" #import "OFString.h" @implementation OFConnectSPXSocketFailedException @synthesize network = _network, port = _port; + (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithNetwork: (uint32_t)network node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port socket: (id)sock errNo: (int)errNo { return [[[self alloc] initWithNetwork: network node: node port: port socket: sock errNo: errNo] autorelease]; } - (instancetype)initWithSocket: (id)sock errNo: (int)errNo { OF_INVALID_INIT_METHOD } - (instancetype)initWithNetwork: (uint32_t)network node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port socket: (id)sock errNo: (int)errNo { self = [super initWithSocket: sock errNo: errNo]; @try { _network = network; memcpy(_node, node, IPX_NODE_LEN); _port = port; } @catch (id e) { [self release]; @throw e; } return self; } - (void)getNode: (unsigned char [IPX_NODE_LEN])node { memcpy(node, _node, sizeof(_node)); } - (OFString *)description { return [OFString stringWithFormat: @"A connection to %02X:%02X:%02X:%02X:%02X:%02X port %" @PRIu16 @" on network %" @PRIX32 " could not be established in socket of " @"type %@: %@", _node[0], _node[1], _node[2], _node[3], _node[4], _node[5], _port, _network, [_socket class], OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFConnectSocketFailedException.h000066400000000000000000000042211465614216400237320ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif #import "OFSocket.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFConnectSocketFailedException \ * OFConnectSocketFailedException.h \ * ObjFW/OFConnectSocketFailedException.h * * @brief An exception indicating that a connection could not be established. */ @interface OFConnectSocketFailedException: OFException { id _socket; int _errNo; OF_RESERVE_IVARS(OFConnectSocketFailedException, 4) } /** * @brief The socket which could not connect. */ @property (readonly, nonatomic) id socket; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased connect socket failed exception. * * @param socket The socket which could not connect * @param errNo The errno of the error that occurred * @return A new, autoreleased connect socket failed exception */ + (instancetype)exceptionWithSocket: (id)socket errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated connect socket failed exception. * * @param socket The socket which could not connect * @param errNo The errno of the error that occurred * @return An initialized connect socket failed exception */ - (instancetype)initWithSocket: (id)socket errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFConnectSocketFailedException.m000066400000000000000000000031311465614216400237360ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFConnectSocketFailedException.h" #import "OFString.h" @implementation OFConnectSocketFailedException @synthesize socket = _socket, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo { return [[[self alloc] initWithSocket: sock errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithSocket: (id)sock errNo: (int)errNo { self = [super init]; @try { _socket = [sock retain]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_socket release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"A connection to could not be established in socket of type " @"%@: %@", [_socket class], OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFConnectUNIXSocketFailedException.h000066400000000000000000000045041465614216400244420ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFConnectSocketFailedException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFConnectUNIXSocketFailedException \ * OFConnectUNIXSocketFailedException.h \ * ObjFW/OFConnectUNIXSocketFailedException.h * * @brief An exception indicating that a UNIX socket connection could not be * established. */ OF_SUBCLASSING_RESTRICTED @interface OFConnectUNIXSocketFailedException: OFConnectSocketFailedException { OFString *_Nullable _path; } /** * @brief The path to which the connection failed. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *path; /** * @brief Creates a new, autoreleased connect UNIX socket failed exception. * * @param path The path to which the connection failed * @param socket The socket which could not connect * @param errNo The errno of the error that occurred * @return A new, autoreleased connect UNIX socket failed exception */ + (instancetype)exceptionWithPath: (OFString *)path socket: (id)socket errNo: (int)errNo; + (instancetype)exceptionWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; /** * @brief Initializes an already allocated connect UNIX socket failed exception. * * @param path The path to which the connection failed * @param socket The socket which could not connect * @param errNo The errno of the error that occurred * @return An initialized connect UNIX socket failed exception */ - (instancetype)initWithPath: (OFString *)path socket: (id)socket errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)initWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFConnectUNIXSocketFailedException.m000066400000000000000000000034201465614216400244430ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFConnectUNIXSocketFailedException.h" #import "OFString.h" @implementation OFConnectUNIXSocketFailedException @synthesize path = _path; + (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithPath: (OFString *)path socket: (id)sock errNo: (int)errNo { return [[[self alloc] initWithPath: path socket: sock errNo: errNo] autorelease]; } - (instancetype)initWithSocket: (id)sock errNo: (int)errNo { OF_INVALID_INIT_METHOD } - (instancetype)initWithPath: (OFString *)path socket: (id)sock errNo: (int)errNo { self = [super initWithSocket: sock errNo: errNo]; @try { _path = [path copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_path release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"A connection to %@ could not be established in socket of type " @"%@: %@", _path, [_socket class], OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFCopyItemFailedException.h000066400000000000000000000045001465614216400227210ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFIRI; /** * @class OFCopyItemFailedException \ * OFCopyItemFailedException.h ObjFW/OFCopyItemFailedException.h * * @brief An exception indicating that copying a item failed. */ @interface OFCopyItemFailedException: OFException { OFIRI *_sourceIRI, *_destinationIRI; int _errNo; OF_RESERVE_IVARS(OFCopyItemFailedException, 4) } /** * @brief The IRI of the source item. */ @property (readonly, nonatomic) OFIRI *sourceIRI; /** * @brief The destination IRI. */ @property (readonly, nonatomic) OFIRI *destinationIRI; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased copy item failed exception. * * @param sourceIRI The IRI of the source item * @param destinationIRI The destination IRI * @param errNo The errno of the error that occurred * @return A new, autoreleased copy item failed exception */ + (instancetype)exceptionWithSourceIRI: (OFIRI *)sourceIRI destinationIRI: (OFIRI *)destinationIRI errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated copy item failed exception. * * @param sourceIRI The IRI of the source item * @param destinationIRI The destination IRI * @param errNo The errno of the error that occurred * @return An initialized copy item failed exception */ - (instancetype)initWithSourceIRI: (OFIRI *)sourceIRI destinationIRI: (OFIRI *)destinationIRI errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFCopyItemFailedException.m000066400000000000000000000035631465614216400227360ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFCopyItemFailedException.h" #import "OFIRI.h" #import "OFString.h" @implementation OFCopyItemFailedException @synthesize sourceIRI = _sourceIRI, destinationIRI = _destinationIRI; @synthesize errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithSourceIRI: (OFIRI *)sourceIRI destinationIRI: (OFIRI *)destinationIRI errNo: (int)errNo { return [[[self alloc] initWithSourceIRI: sourceIRI destinationIRI: destinationIRI errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithSourceIRI: (OFIRI *)sourceIRI destinationIRI: (OFIRI *)destinationIRI errNo: (int)errNo { self = [super init]; @try { _sourceIRI = [sourceIRI copy]; _destinationIRI = [destinationIRI copy]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_sourceIRI release]; [_destinationIRI release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to copy item %@ to %@: %@", _sourceIRI, _destinationIRI, OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFCreateDirectoryFailedException.h000066400000000000000000000041761465614216400242710ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFIRI; /** * @class OFCreateDirectoryFailedException \ * OFCreateDirectoryFailedException.h \ * ObjFW/OFCreateDirectoryFailedException.h * * @brief An exception indicating a directory couldn't be created. */ @interface OFCreateDirectoryFailedException: OFException { OFIRI *_IRI; int _errNo; OF_RESERVE_IVARS(OFCreateDirectoryFailedException, 4) } /** * @brief The IRI of the directory which couldn't be created. */ @property (readonly, nonatomic) OFIRI *IRI; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased create directory failed exception. * * @param IRI The IRI of the directory which could not be created * @param errNo The errno of the error that occurred * @return A new, autoreleased create directory failed exception */ + (instancetype)exceptionWithIRI: (OFIRI *)IRI errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated create directory failed exception. * * @param IRI The IRI of the directory which could not be created * @param errNo The errno of the error that occurred * @return An initialized create directory failed exception */ - (instancetype)initWithIRI: (OFIRI *)IRI errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFCreateDirectoryFailedException.m000066400000000000000000000030451465614216400242700ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFCreateDirectoryFailedException.h" #import "OFIRI.h" #import "OFString.h" @implementation OFCreateDirectoryFailedException @synthesize IRI = _IRI, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithIRI: (OFIRI *)IRI errNo: (int)errNo { return [[[self alloc] initWithIRI: IRI errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithIRI: (OFIRI *)IRI errNo: (int)errNo { self = [super init]; @try { _IRI = [IRI copy]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_IRI release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to create directory %@: %@", _IRI, OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFCreateSymbolicLinkFailedException.h000066400000000000000000000047411465614216400247220ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFIRI; /** * @class OFCreateSymbolicLinkFailedException \ * OFCreateSymbolicLinkFailedException.h \ * ObjFW/OFCreateSymbolicLinkFailedException.h * * @brief An exception indicating that creating a symbolic link failed. */ @interface OFCreateSymbolicLinkFailedException: OFException { OFIRI *_IRI; OFString *_target; int _errNo; OF_RESERVE_IVARS(OFCreateSymbolicLinkFailedException, 4) } /** * @brief The IRI at which the symbolic link should have been created. */ @property (readonly, nonatomic) OFIRI *IRI; /** * @brief The target for the symbolic link. */ @property (readonly, nonatomic) OFString *target; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased create symbolic link failed exception. * * @param IRI The IRI where the symbolic link should have been created * @param target The target for the symbolic link * @param errNo The errno of the error that occurred * @return A new, autoreleased create symbolic link failed exception */ + (instancetype)exceptionWithIRI: (OFIRI *)IRI target: (OFString *)target errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated create symbolic link failed * exception. * * @param IRI The IRI where the symbolic link should have been created * @param target The target for the symbolic link * @param errNo The errno of the error that occurred * @return An initialized create symbolic link failed exception */ - (instancetype)initWithIRI: (OFIRI *)IRI target: (OFString *)target errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFCreateSymbolicLinkFailedException.m000066400000000000000000000033731465614216400247270ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFCreateSymbolicLinkFailedException.h" #import "OFIRI.h" #import "OFString.h" @implementation OFCreateSymbolicLinkFailedException @synthesize IRI = _IRI, target = _target, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithIRI: (OFIRI *)IRI target: (OFString *)target errNo: (int)errNo { return [[[self alloc] initWithIRI: IRI target: target errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithIRI: (OFIRI *)IRI target: (OFString *)target errNo: (int)errNo { self = [super init]; @try { _IRI = [IRI copy]; _target = [target copy]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_IRI release]; [_target release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to create symbolic link %@ with target %@: %@", _IRI, _target, OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFCreateWindowsRegistryKeyFailedException.h000066400000000000000000000100411465614216400261450ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #import "OFWindowsRegistryKey.h" #include OF_ASSUME_NONNULL_BEGIN /** * @class OFCreateWindowsRegistryKeyFailedException \ * OFCreateWindowsRegistryKeyFailedException.h \ * ObjFW/OFCreateWindowsRegistryKeyFailedException.h * * @brief An exception indicating that creating a Windows registry key failed. */ @interface OFCreateWindowsRegistryKeyFailedException: OFException { OFWindowsRegistryKey *_registryKey; OFString *_path; DWORD _options; REGSAM _accessRights; LPSECURITY_ATTRIBUTES _Nullable _securityAttributes; LSTATUS _status; OF_RESERVE_IVARS(OFCreateWindowsRegistryKeyFailedException, 4) } /** * @brief The registry key on which creating the subkey failed. */ @property (readonly, nonatomic) OFWindowsRegistryKey *registryKey; /** * @brief The path for the subkey that could not be created. */ @property (readonly, nonatomic) OFString *path; /** * @brief The access rights for the subkey that could not be created. */ @property (readonly, nonatomic) REGSAM accessRights; /** * @brief The security options for the subkey that could not be created. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) LPSECURITY_ATTRIBUTES securityAttributes; /** * @brief The options for the subkey that could not be created. */ @property (readonly, nonatomic) DWORD options; /** * @brief The status returned by RegCreateKeyEx(). */ @property (readonly, nonatomic) LSTATUS status; /** * @brief Creates a new, autoreleased create Windows registry key failed * exception. * * @param registryKey The registry key on which creating the subkey failed * @param path The path for the subkey that could not be created * @param accessRights The access rights for the sub key that could not be * created * @param securityAttributes The security options for the subkey that could * not be created * @param options The options for the subkey that could not be created * @param status The status returned by RegCreateKeyEx() * @return A new, autoreleased creates Windows registry key failed exception */ + (instancetype) exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey path: (OFString *)path accessRights: (REGSAM)accessRights securityAttributes: (nullable LPSECURITY_ATTRIBUTES)securityAttributes options: (DWORD)options status: (LSTATUS)status; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated create Windows registry key failed * exception. * * @param registryKey The registry key on which creating the subkey failed * @param path The path for the subkey that could not be created * @param accessRights The access rights for the sub key that could not be * created * @param securityAttributes The security options for the subkey that could * not be created * @param options The options for the subkey that could not be created * @param status The status returned by RegCreateKeyEx() * @return An initialized create Windows registry key failed exception */ - (instancetype) initWithRegistryKey: (OFWindowsRegistryKey *)registryKey path: (OFString *)path accessRights: (REGSAM)accessRights securityAttributes: (nullable LPSECURITY_ATTRIBUTES)securityAttributes options: (DWORD)options status: (LSTATUS)status OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFCreateWindowsRegistryKeyFailedException.m000066400000000000000000000045771465614216400261730ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFCreateWindowsRegistryKeyFailedException.h" @implementation OFCreateWindowsRegistryKeyFailedException @synthesize registryKey = _registryKey, path = _path; @synthesize accessRights = _accessRights; @synthesize securityAttributes = _securityAttributes, options = _options; @synthesize status = _status; + (instancetype) exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey path: (OFString *)path accessRights: (REGSAM)accessRights securityAttributes: (LPSECURITY_ATTRIBUTES)securityAttributes options: (DWORD)options status: (LSTATUS)status { return [[[self alloc] initWithRegistryKey: registryKey path: path accessRights: accessRights securityAttributes: securityAttributes options: options status: status] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey path: (OFString *)path accessRights: (REGSAM)accessRights securityAttributes: (LPSECURITY_ATTRIBUTES)securityAttributes options: (DWORD)options status: (LSTATUS)status { self = [super init]; @try { _registryKey = [registryKey retain]; _path = [path copy]; _accessRights = accessRights; _securityAttributes = securityAttributes; _options = options; _status = status; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_registryKey release]; [_path release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to create subkey at path %@: %@", _path, _OFWindowsStatusToString(_status)]; } @end objfw-1.1.6/src/exceptions/OFDNSQueryFailedException.h000066400000000000000000000045671465614216400226570ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #import "OFDNSQuery.h" #import "OFDNSResolver.h" #import "OFDNSResourceRecord.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFDNSQueryFailedException \ * OFDNSQueryFailedException.h ObjFW/OFDNSQueryFailedException.h * * @brief An exception indicating that a DNS query failed. */ @interface OFDNSQueryFailedException: OFException { OFDNSQuery *_query; OFDNSResolverErrorCode _errorCode; OF_RESERVE_IVARS(OFDNSQueryFailedException, 4) } /** * @brief The query which could not be performed. */ @property (readonly, nonatomic) OFDNSQuery *query; /** * @brief The error code from the resolver. */ @property (readonly, nonatomic) OFDNSResolverErrorCode errorCode; /** * @brief Creates a new, autoreleased DNS query failed exception. * * @param query The query which could not be performed * @param errorCode The error from the resolver * @return A new, autoreleased address translation failed exception */ + (instancetype)exceptionWithQuery: (OFDNSQuery *)query errorCode: (OFDNSResolverErrorCode)errorCode; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated DNS query failed exception. * * @param query The query which could not be performed * @param errorCode The error from the resolver * @return An initialized address translation failed exception */ - (instancetype)initWithQuery: (OFDNSQuery *)query errorCode: (OFDNSResolverErrorCode)errorCode; - (instancetype)init OF_UNAVAILABLE; @end #ifdef __cplusplus extern "C" { #endif extern OFString *_OFDNSResolverErrorCodeDescription( OFDNSResolverErrorCode errorCode) OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFDNSQueryFailedException.m000066400000000000000000000053631465614216400226570ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFDNSQueryFailedException.h" #import "OFString.h" OFString * _OFDNSResolverErrorCodeDescription(OFDNSResolverErrorCode errorCode) { switch (errorCode) { case OFDNSResolverErrorCodeTimeout: return @"The query timed out."; case OFDNSResolverErrorCodeCanceled: return @"The query was canceled."; case OFDNSResolverErrorCodeNoResult: return @"No result for the specified host with the specified " @"type and class."; case OFDNSResolverErrorCodeServerInvalidFormat: return @"The server considered the query to be malformed."; case OFDNSResolverErrorCodeServerFailure: return @"The server was unable to process due to an internal " @"error."; case OFDNSResolverErrorCodeServerNameError: return @"The server returned an error that the domain does not " @"exist."; case OFDNSResolverErrorCodeServerNotImplemented: return @"The server does not have support for the requested " @"query."; case OFDNSResolverErrorCodeServerRefused: return @"The server refused the query."; case OFDNSResolverErrorCodeNoNameServer: return @"There was no name server to query."; default: return @"Unknown error."; } } @implementation OFDNSQueryFailedException @synthesize query = _query, errorCode = _errorCode; + (instancetype)exceptionWithQuery: (OFDNSQuery *)query errorCode: (OFDNSResolverErrorCode)errorCode { return [[[self alloc] initWithQuery: query errorCode: errorCode] autorelease]; } + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithQuery: (OFDNSQuery *)query errorCode: (OFDNSResolverErrorCode)errorCode { self = [super init]; @try { _query = [query copy]; _errorCode = errorCode; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_query release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"DNS query %@ could not be performed: %@", _query, _OFDNSResolverErrorCodeDescription(_errorCode)]; } @end objfw-1.1.6/src/exceptions/OFDeleteWindowsRegistryKeyFailedException.h000066400000000000000000000054061465614216400261550ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #import "OFWindowsRegistryKey.h" #include OF_ASSUME_NONNULL_BEGIN /** * @class OFDeleteWindowsRegistryKeyFailedException \ * OFDeleteWindowsRegistryKeyFailedException.h \ * ObjFW/OFDeleteWindowsRegistryKeyFailedException.h * * @brief An exception indicating that deleting a Windows registry key failed. */ @interface OFDeleteWindowsRegistryKeyFailedException: OFException { OFWindowsRegistryKey *_registryKey; OFString *_subkeyPath; LSTATUS _status; OF_RESERVE_IVARS(OFDeleteWindowsRegistryKeyFailedException, 4) } /** * @brief The registry key on which deleting the subkey failed. */ @property (readonly, nonatomic) OFWindowsRegistryKey *registryKey; /** * @brief The path of the subkey which could not be deleted. */ @property (readonly, nonatomic) OFString *subkeyPath; /** * @brief The status returned by RegDeleteKeyEx(). */ @property (readonly, nonatomic) LSTATUS status; /** * @brief Creates a new, autoreleased delete Windows registry key failed * exception. * * @param registryKey The registry key on which deleting the subkey failed * @param subkeyPath The path of the subkey which could not be deleted * @param status The status returned by RegDeleteKeyEx() * @return A new, autoreleased delete Windows registry key failed exception */ + (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey subkeyPath: (OFString *)subkeyPath status: (LSTATUS)status; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated delete Windows registry key failed * exception. * * @param registryKey The registry key on which deleting the subkey failed * @param subkeyPath The path of the subkey which could not be deleted * @param status The status returned by RegDeleteKeyEx() * @return An initialized delete Windows registry key failed exception */ - (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey subkeyPath: (OFString *)subkeyPath status: (LSTATUS)status OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFDeleteWindowsRegistryKeyFailedException.m000066400000000000000000000036011465614216400261550ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFDeleteWindowsRegistryKeyFailedException.h" #import "OFData.h" @implementation OFDeleteWindowsRegistryKeyFailedException @synthesize registryKey = _registryKey, subkeyPath = _subkeyPath; @synthesize status = _status; + (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey subkeyPath: (OFString *)subkeyPath status: (LSTATUS)status { return [[[self alloc] initWithRegistryKey: registryKey subkeyPath: subkeyPath status: status] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey subkeyPath: (OFString *)subkeyPath status: (LSTATUS)status { self = [super init]; @try { _registryKey = [registryKey retain]; _subkeyPath = [subkeyPath copy]; _status = status; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_registryKey release]; [_subkeyPath release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to delete subkey at path %@: %@", _subkeyPath, _OFWindowsStatusToString(_status)]; } @end objfw-1.1.6/src/exceptions/OFDeleteWindowsRegistryValueFailedException.h000066400000000000000000000055051465614216400265010ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #import "OFWindowsRegistryKey.h" #include OF_ASSUME_NONNULL_BEGIN /** * @class OFDeleteWindowsRegistryValueFailedException \ * OFDeleteWindowsRegistryValueFailedException.h \ * ObjFW/OFDeleteWindowsRegistryValueFailedException.h * * @brief An exception indicating that deleting a Windows registry value failed. */ @interface OFDeleteWindowsRegistryValueFailedException: OFException { OFWindowsRegistryKey *_registryKey; OFString *_Nullable _valueName; LSTATUS _status; OF_RESERVE_IVARS(OFDeleteWindowsRegistryValueFailedException, 4) } /** * @brief The registry key on which deleting the value failed. */ @property (readonly, nonatomic) OFWindowsRegistryKey *registryKey; /** * @brief The name of the value which could not be deleted. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *valueName; /** * @brief The status returned by RegDeleteValueEx(). */ @property (readonly, nonatomic) LSTATUS status; /** * @brief Creates a new, autoreleased delete Windows registry value failed * exception. * * @param registryKey The registry key on which deleting the value failed * @param valueName The name of the value which could not be deleted * @param status The status returned by RegDeleteValueEx() * @return A new, autoreleased delete Windows registry value failed exception */ + (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey valueName: (nullable OFString *)valueName status: (LSTATUS)status; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated delete Windows registry value failed * exception. * * @param registryKey The registry key on which deleting the value failed * @param valueName The name of the value which could not be deleted * @param status The status returned by RegDeleteValueEx() * @return An initialized delete Windows registry value failed exception */ - (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey valueName: (nullable OFString *)valueName status: (LSTATUS)status OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFDeleteWindowsRegistryValueFailedException.m000066400000000000000000000035621465614216400265070ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFDeleteWindowsRegistryValueFailedException.h" #import "OFData.h" @implementation OFDeleteWindowsRegistryValueFailedException @synthesize registryKey = _registryKey, valueName = _valueName; @synthesize status = _status; + (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey valueName: (OFString *)valueName status: (LSTATUS)status { return [[[self alloc] initWithRegistryKey: registryKey valueName: valueName status: status] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey valueName: (OFString *)valueName status: (LSTATUS)status { self = [super init]; @try { _registryKey = [registryKey retain]; _valueName = [valueName copy]; _status = status; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_registryKey release]; [_valueName release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to delete value named %@: %@", _valueName, _OFWindowsStatusToString(_status)]; } @end objfw-1.1.6/src/exceptions/OFEnumerationMutationException.h000066400000000000000000000035471465614216400241040ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFEnumerationMutationException \ * OFEnumerationMutationException.h \ * ObjFW/OFEnumerationMutationException.h * * @brief An exception indicating that a mutation was detected during * enumeration. */ @interface OFEnumerationMutationException: OFException { id _object; OF_RESERVE_IVARS(OFEnumerationMutationException, 4) } /** * @brief The object which was mutated during enumeration. */ @property (readonly, nonatomic) id object; /** * @brief Creates a new, autoreleased enumeration mutation exception. * * @param object The object which was mutated during enumeration * @return A new, autoreleased enumeration mutation exception */ + (instancetype)exceptionWithObject: (id)object; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated enumeration mutation exception. * * @param object The object which was mutated during enumeration * @return An initialized enumeration mutation exception */ - (instancetype)initWithObject: (id)object OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFEnumerationMutationException.m000066400000000000000000000026451465614216400241070ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFEnumerationMutationException.h" #import "OFString.h" @implementation OFEnumerationMutationException @synthesize object = _object; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithObject: (id)object { return [[[self alloc] initWithObject: object] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithObject: (id)object { self = [super init]; _object = [object retain]; return self; } - (void)dealloc { [_object release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Object of class %@ was mutated during enumeration!", [_object class]]; } @end objfw-1.1.6/src/exceptions/OFException.h000066400000000000000000000116261465614216400201510ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #ifdef OF_WINDOWS # include #endif OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFArray OF_GENERIC(ObjectType); @class OFString; @class OFValue; #define OFStackTraceSize 16 #if defined(OF_WINDOWS) && defined(OF_HAVE_SOCKETS) # ifndef EADDRINUSE # define EADDRINUSE WSAEADDRINUSE # endif # ifndef EADDRNOTAVAIL # define EADDRNOTAVAIL WSAEADDRNOTAVAIL # endif # ifndef EAFNOSUPPORT # define EAFNOSUPPORT WSAEAFNOSUPPORT # endif # ifndef EALREADY # define EALREADY WSAEALREADY # endif # ifndef ECONNABORTED # define ECONNABORTED WSAECONNABORTED # endif # ifndef ECONNREFUSED # define ECONNREFUSED WSAECONNREFUSED # endif # ifndef ECONNRESET # define ECONNRESET WSAECONNRESET # endif # ifndef EDESTADDRREQ # define EDESTADDRREQ WSAEDESTADDRREQ # endif # ifndef EDQUOT # define EDQUOT WSAEDQUOT # endif # ifndef EHOSTDOWN # define EHOSTDOWN WSAEHOSTDOWN # endif # ifndef EHOSTUNREACH # define EHOSTUNREACH WSAEHOSTUNREACH # endif # ifndef EINPROGRESS # define EINPROGRESS WSAEINPROGRESS # endif # ifndef EISCONN # define EISCONN WSAEISCONN # endif # ifndef ELOOP # define ELOOP WSAELOOP # endif # ifndef EMSGSIZE # define EMSGSIZE WSAEMSGSIZE # endif # ifndef ENETDOWN # define ENETDOWN WSAENETDOWN # endif # ifndef ENETRESET # define ENETRESET WSAENETRESET # endif # ifndef ENETUNREACH # define ENETUNREACH WSAENETUNREACH # endif # ifndef ENOBUFS # define ENOBUFS WSAENOBUFS # endif # ifndef ENOPROTOOPT # define ENOPROTOOPT WSAENOPROTOOPT # endif # ifndef ENOTCONN # define ENOTCONN WSAENOTCONN # endif # ifndef ENOTSOCK # define ENOTSOCK WSAENOTSOCK # endif # ifndef EOPNOTSUPP # define EOPNOTSUPP WSAEOPNOTSUPP # endif # ifndef EPFNOSUPPORT # define EPFNOSUPPORT WSAEPFNOSUPPORT # endif # ifndef EPROCLIM # define EPROCLIM WSAEPROCLIM # endif # ifndef EPROTONOSUPPORT # define EPROTONOSUPPORT WSAEPROTONOSUPPORT # endif # ifndef EPROTOTYPE # define EPROTOTYPE WSAEPROTOTYPE # endif # ifndef EREMOTE # define EREMOTE WSAEREMOTE # endif # ifndef ESHUTDOWN # define ESHUTDOWN WSAESHUTDOWN # endif # ifndef ESOCKTNOSUPPORT # define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT # endif # ifndef ESTALE # define ESTALE WSAESTALE # endif # ifndef ETIMEDOUT # define ETIMEDOUT WSAETIMEDOUT # endif # ifndef ETOOMANYREFS # define ETOOMANYREFS WSAETOOMANYREFS # endif # ifndef EUSERS # define EUSERS WSAEUSERS # endif # ifndef EWOULDBLOCK # define EWOULDBLOCK WSAEWOULDBLOCK # endif #endif #ifndef EWOULDBLOCK # define EWOULDBLOCK EAGAIN #endif /** * @class OFException OFException.h ObjFW/OFException.h * * @brief The base class for all exceptions in ObjFW * * The OFException class is the base class for all exceptions in ObjFW, except * the OFAllocFailedException. */ @interface OFException: OFObject { void *_stackTrace[OFStackTraceSize]; OF_RESERVE_IVARS(OFException, 4) } /** * @brief Creates a new, autoreleased exception. * * @return A new, autoreleased exception */ + (instancetype)exception; /** * @brief Returns a description of the exception. * * @return A description of the exception */ - (OFString *)description; /** * @brief Returns a stack trace of when the exception was created or `nil` if * no stack trace is available. The returned array contains OFValues * with @ref OFValue#pointerValue set to the address. * * @return The stack trace as array of addresses */ - (nullable OFArray OF_GENERIC(OFValue *) *)stackTraceAddresses; /** * @brief Returns a stack trace of when the exception was created or `nil` if * no stack trace symbols are available. * * @return The stack trace as array of symbols */ - (nullable OFArray OF_GENERIC(OFString *) *)stackTraceSymbols; @end #ifdef __cplusplus extern "C" { #endif /** * @brief Converts the specified error number (from ``) to a string. * * Unlike the system function `strerror`, this function is always thread-safe. * * As an addition, on Windows, it is also able to convert socket error numbers * to string. * * @param errNo The error number to convert to a string * @return A string describing the error */ extern OFString *OFStrError(int errNo); #ifdef OF_WINDOWS extern OFString *_OFWindowsStatusToString(LSTATUS status) OF_VISIBILITY_HIDDEN; #endif #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFException.m000066400000000000000000000203321465614216400201500ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #include #include #ifdef HAVE_DLFCN_H # include #endif #import "OFException.h" #import "OFArray.h" #import "OFLocale.h" #ifdef OF_HAVE_THREADS # import "OFPlainMutex.h" #endif #import "OFString.h" #import "OFSystemInfo.h" #import "OFValue.h" #import "OFInitializationFailedException.h" #import "OFLockFailedException.h" #import "OFUnlockFailedException.h" #if defined(OF_WINDOWS) && defined(OF_HAVE_SOCKETS) # include #endif #if defined(OF_ARM) && !defined(__ARM_DWARF_EH__) # define HAVE_ARM_EHABI_EXCEPTIONS #endif struct _Unwind_Context; typedef enum { _URC_OK = 0, _URC_END_OF_STACK = 5 } _Unwind_Reason_Code; struct BacktraceCtx { void **backtrace; uint8_t i; }; #ifdef HAVE__UNWIND_BACKTRACE extern _Unwind_Reason_Code _Unwind_Backtrace( _Unwind_Reason_Code (*)(struct _Unwind_Context *, void *), void *); #endif #ifndef HAVE_ARM_EHABI_EXCEPTIONS extern uintptr_t _Unwind_GetIP(struct _Unwind_Context *); #else extern int _Unwind_VRS_Get(struct _Unwind_Context *, int, uint32_t, int, void *); #endif #if !defined(HAVE_STRERROR_R) && defined(OF_HAVE_THREADS) static OFPlainMutex mutex; OF_CONSTRUCTOR() { OFEnsure(OFPlainMutexNew(&mutex) == 0); } OF_DESTRUCTOR() { OFPlainMutexFree(&mutex); } #endif OFString * OFStrError(int errNo) { OFString *ret; #ifdef HAVE_STRERROR_R char buffer[256]; #endif if (errNo == 0) return @"Unknown error"; #if defined(OF_WINDOWS) && defined(OF_HAVE_SOCKETS) /* * These were translated from WSAE* errors to errno and thus Win32's * strerror_r() does not know about them. * * FIXME: These could have better descriptions! */ switch (errNo) { case EADDRINUSE: return @"EADDRINUSE"; case EADDRNOTAVAIL: return @"EADDRNOTAVAIL"; case EAFNOSUPPORT: return @"EAFNOSUPPORT"; case EALREADY: return @"EALREADY"; case ECONNABORTED: return @"ECONNABORTED"; case ECONNREFUSED: return @"ECONNREFUSED"; case ECONNRESET: return @"ECONNRESET"; case EDESTADDRREQ: return @"EDESTADDRREQ"; case EDQUOT: return @"EDQUOT"; case EHOSTDOWN: return @"EHOSTDOWN"; case EHOSTUNREACH: return @"EHOSTUNREACH"; case EINPROGRESS: return @"EINPROGRESS"; case EISCONN: return @"EISCONN"; case ELOOP: return @"ELOOP"; case EMSGSIZE: return @"EMSGSIZE"; case ENETDOWN: return @"ENETDOWN"; case ENETRESET: return @"ENETRESET"; case ENETUNREACH: return @"ENETUNREACH"; case ENOBUFS: return @"ENOBUFS"; case ENOPROTOOPT: return @"ENOPROTOOPT"; case ENOTCONN: return @"ENOTCONN"; case ENOTSOCK: return @"ENOTSOCK"; case EOPNOTSUPP: return @"EOPNOTSUPP"; case EPFNOSUPPORT: return @"EPFNOSUPPORT"; case EPROCLIM: return @"EPROCLIM"; case EPROTONOSUPPORT: return @"EPROTONOSUPPORT"; case EPROTOTYPE: return @"EPROTOTYPE"; case EREMOTE: return @"EREMOTE"; case ESHUTDOWN: return @"ESHUTDOWN"; case ESOCKTNOSUPPORT: return @"ESOCKTNOSUPPORT"; case ESTALE: return @"ESTALE"; case ETIMEDOUT: return @"ETIMEDOUT"; case ETOOMANYREFS: return @"ETOOMANYREFS"; case EUSERS: return @"EUSERS"; case EWOULDBLOCK: return @"EWOULDBLOCK"; } #endif #if defined(STRERROR_R_RETURNS_CHARP) /* glibc uses a different strerror_r when _GNU_SOURCE is defined */ char *string; if ((string = strerror_r(errNo, buffer, 256)) == NULL) return @"Unknown error (strerror_r failed)"; ret = [OFString stringWithCString: string encoding: [OFLocale encoding]]; #elif defined(HAVE_STRERROR_R) if (strerror_r(errNo, buffer, 256) != 0) return @"Unknown error (strerror_r failed)"; ret = [OFString stringWithCString: buffer encoding: [OFLocale encoding]]; #else # ifdef OF_HAVE_THREADS if (OFPlainMutexLock(&mutex) != 0) @throw [OFLockFailedException exception]; @try { # endif ret = [OFString stringWithCString: strerror(errNo) encoding: [OFLocale encoding]]; # ifdef OF_HAVE_THREADS } @finally { if (OFPlainMutexUnlock(&mutex) != 0) @throw [OFUnlockFailedException exception]; } # endif #endif return ret; } #ifdef OF_WINDOWS OFString * _OFWindowsStatusToString(LSTATUS status) { OFString *string = nil; void *buffer; if ([OFSystemInfo isWindowsNT]) { if (FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK, NULL, status, 0, (LPWSTR)&buffer, 0, NULL) != 0) { @try { string = [OFString stringWithUTF16String: buffer]; } @finally { LocalFree(buffer); } } } else { if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK, NULL, status, 0, (LPSTR)&buffer, 0, NULL) != 0) { @try { string = [OFString stringWithCString: buffer encoding: [OFLocale encoding]]; } @finally { LocalFree(buffer); } } } if (string == nil) string = [OFString stringWithFormat: @"Status code %u", status]; return string; } #endif #ifdef HAVE__UNWIND_BACKTRACE static _Unwind_Reason_Code backtraceCallback(struct _Unwind_Context *ctx, void *data) { struct BacktraceCtx *bt = data; if (bt->i < OFStackTraceSize) { # ifndef HAVE_ARM_EHABI_EXCEPTIONS bt->backtrace[bt->i++] = (void *)_Unwind_GetIP(ctx); # else uintptr_t ip; _Unwind_VRS_Get(ctx, 0, 15, 0, &ip); bt->backtrace[bt->i++] = (void *)(ip & ~1); # endif return _URC_OK; } return _URC_END_OF_STACK; } #endif @implementation OFException + (instancetype)exception { return [[[self alloc] init] autorelease]; } #ifdef HAVE__UNWIND_BACKTRACE - (instancetype)init { struct BacktraceCtx ctx; self = [super init]; ctx.backtrace = _stackTrace; ctx.i = 0; _Unwind_Backtrace(backtraceCallback, &ctx); return self; } #endif - (OFString *)description { return [OFString stringWithFormat: @"An exception of type %@ occurred!", self.class]; } - (OFArray OF_GENERIC(OFValue *) *)stackTraceAddresses { #ifdef HAVE__UNWIND_BACKTRACE OFMutableArray OF_GENERIC(OFValue *) *stackTrace = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); for (uint_fast8_t i = 0; i < OFStackTraceSize && _stackTrace[i] != NULL; i++) [stackTrace addObject: [OFValue valueWithPointer: _stackTrace[i]]]; objc_autoreleasePoolPop(pool); [stackTrace makeImmutable]; return stackTrace; #else return nil; #endif } - (OFArray OF_GENERIC(OFString *) *)stackTraceSymbols { #if defined(HAVE__UNWIND_BACKTRACE) && defined(HAVE_DLADDR) OFMutableArray OF_GENERIC(OFString *) *stackTrace = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); for (uint_fast8_t i = 0; i < OFStackTraceSize && _stackTrace[i] != NULL; i++) { Dl_info info; if (dladdr(_stackTrace[i], &info)) { ptrdiff_t offset = (char *)_stackTrace[i] - (char *)info.dli_saddr; OFString *frame; if (info.dli_fname != NULL && info.dli_sname != NULL) frame = [OFString stringWithFormat: @"%s`%s+%td", info.dli_fname, info.dli_sname, offset]; else if (info.dli_sname != NULL) frame = [OFString stringWithFormat: @"%s+%td", info.dli_sname, offset]; else if (info.dli_fname != NULL) frame = [OFString stringWithFormat: @"%s`%p", info.dli_fname, _stackTrace[i]]; else frame = [OFString stringWithFormat: @"%p", _stackTrace[i]]; [stackTrace addObject: frame]; } else [stackTrace addObject: [OFString stringWithFormat: @"%p", _stackTrace[i]]]; } objc_autoreleasePoolPop(pool); [stackTrace makeImmutable]; return stackTrace; #else return nil; #endif } @end objfw-1.1.6/src/exceptions/OFGetCurrentDirectoryFailedException.h000066400000000000000000000036231465614216400251440ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFGetCurrentDirectoryFailedException \ * OFGetCurrentDirectoryFailedException.h \ * ObjFW/OFGetCurrentDirectoryFailedException.h * * @brief An exception indicating that getting the current directory path * failed. */ @interface OFGetCurrentDirectoryFailedException: OFException { int _errNo; OF_RESERVE_IVARS(OFGetCurrentDirectoryFailedException, 4) } /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased get current directory path failed * exception. * * @param errNo The errno of the error that occurred * @return A new, autoreleased get current directory failed exception */ + (instancetype)exceptionWithErrNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated get current directory path failed * exception. * * @param errNo The errno of the error that occurred * @return An initialized get current directory path failed exception */ - (instancetype)initWithErrNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFGetCurrentDirectoryFailedException.m000066400000000000000000000025421465614216400251500ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFGetCurrentDirectoryFailedException.h" #import "OFString.h" @implementation OFGetCurrentDirectoryFailedException @synthesize errNo = _errNo; + (instancetype)exceptionWithErrNo: (int)errNo { return [[[self alloc] initWithErrNo: errNo] autorelease]; } + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithErrNo: (int)errNo { self = [super init]; _errNo = errNo; return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (OFString *)description { return [OFString stringWithFormat: @"Getting the current directory path failed: %@", OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFGetItemAttributesFailedException.h000066400000000000000000000043221465614216400245770ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFIRI; /** * @class OFGetItemAttributesFailedException \ * OFGetItemAttributesFailedException.h \ * ObjFW/OFGetItemAttributesFailedException.h * * @brief An exception indicating an item's attributes could not be retrieved. */ @interface OFGetItemAttributesFailedException: OFException { OFIRI *_IRI; int _errNo; OF_RESERVE_IVARS(OFGetItemAttributesFailedException, 4) } /** * @brief The IRI of the item whose attributes could not be retrieved. */ @property (readonly, nonatomic) OFIRI *IRI; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased retrieve item attributes failed exception. * * @param IRI The IRI of the item whose attributes could not be retrieved * @param errNo The errno of the error that occurred * @return A new, autoreleased retrieve item attributes failed exception */ + (instancetype)exceptionWithIRI: (OFIRI *)IRI errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated retrieve item attributes failed * exception. * * @param IRI The IRI of the item whose attributes could not be retrieved * @param errNo The errno of the error that occurred * @return An initialized retrieve item attributes failed exception */ - (instancetype)initWithIRI: (OFIRI *)IRI errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFGetItemAttributesFailedException.m000066400000000000000000000030651465614216400246070ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFGetItemAttributesFailedException.h" #import "OFIRI.h" #import "OFString.h" @implementation OFGetItemAttributesFailedException @synthesize IRI = _IRI, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithIRI: (OFIRI *)IRI errNo: (int)errNo { return [[[self alloc] initWithIRI: IRI errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithIRI: (OFIRI *)IRI errNo: (int)errNo { self = [super init]; @try { _IRI = [IRI copy]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_IRI release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to get attributes for item %@: %@", _IRI, OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFGetOptionFailedException.h000066400000000000000000000041731465614216400231060ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFGetOptionFailedException \ * OFGetOptionFailedException.h ObjFW/OFGetOptionFailedException.h * * @brief An exception indicating that getting an option for an object failed. */ @interface OFGetOptionFailedException: OFException { id _Nullable _object; int _errNo; OF_RESERVE_IVARS(OFGetOptionFailedException, 4) } /** * @brief The object for which the option could not be retrieved. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) id object; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased get option failed exception. * * @param object The object for which the option could not be retrieved * @param errNo The errno of the error that occurred * @return A new, autoreleased get option failed exception */ + (instancetype)exceptionWithObject: (nullable id)object errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated get option failed exception. * * @param object The object for which the option could not be retrieved * @param errNo The errno of the error that occurred * @return An initialized get option failed exception */ - (instancetype)initWithObject: (nullable id)object errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFGetOptionFailedException.m000066400000000000000000000032041465614216400231050ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFGetOptionFailedException.h" #import "OFString.h" @implementation OFGetOptionFailedException @synthesize object = _object, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithObject: (id)object errNo: (int)errNo { return [[[self alloc] initWithObject: object errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithObject: (id)object errNo: (int)errNo { self = [super init]; _object = [object retain]; _errNo = errNo; return self; } - (void)dealloc { [_object release]; [super dealloc]; } - (OFString *)description { if (_object != nil) return [OFString stringWithFormat: @"Getting an option in an object of type %@ failed: %@", [_object class], OFStrError(_errNo)]; else return [OFString stringWithFormat: @"Getting an option failed: %@", OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFGetWindowsRegistryValueFailedException.h000066400000000000000000000056321465614216400260170ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #import "OFWindowsRegistryKey.h" #include OF_ASSUME_NONNULL_BEGIN /** * @class OFGetWindowsRegistryValueFailedException \ * OFGetWindowsRegistryValueFailedException.h \ * ObjFW/OFGetWindowsRegistryValueFailedException.h * * @brief An exception indicating that getting a Windows registry value failed. */ @interface OFGetWindowsRegistryValueFailedException: OFException { OFWindowsRegistryKey *_registryKey; OFString *_Nullable _valueName; LSTATUS _status; OF_RESERVE_IVARS(OFGetWindowsRegistryValueFailedException, 4) } /** * @brief The registry key on which getting the value at the key path failed. */ @property (readonly, nonatomic) OFWindowsRegistryKey *registryKey; /** * @brief The name of the value which could not be retrieved. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *valueName; /** * @brief The status returned by RegGetValueEx(). */ @property (readonly, nonatomic) LSTATUS status; /** * @brief Creates a new, autoreleased get Windows registry value failed * exception. * * @param registryKey The registry key on which getting the value at the sub * key path failed * @param valueName The name of the value which could not be retrieved * @param status The status returned by RegGetValueEx() * @return A new, autoreleased get Windows registry value failed exception */ + (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey valueName: (nullable OFString *)valueName status: (LSTATUS)status; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated get Windows registry value failed * exception. * * @param registryKey The registry key on which getting the value at the sub * key path failed * @param valueName The name of the value which could not be retrieved * @param status The status returned by RegGetValueEx() * @return An initialized get Windows registry value failed exception */ - (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey valueName: (nullable OFString *)valueName status: (LSTATUS)status OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFGetWindowsRegistryValueFailedException.m000066400000000000000000000036161465614216400260240ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFGetWindowsRegistryValueFailedException.h" @implementation OFGetWindowsRegistryValueFailedException @synthesize registryKey = _registryKey, valueName = _valueName; @synthesize status = _status; + (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey valueName: (OFString *)valueName status: (LSTATUS)status { return [[[self alloc] initWithRegistryKey: registryKey valueName: valueName status: status] autorelease]; } + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey valueName: (OFString *)valueName status: (LSTATUS)status { self = [super init]; @try { _registryKey = [registryKey retain]; _valueName = [valueName copy]; _status = status; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_registryKey release]; [_valueName release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to get value named %@: %@", _valueName, _OFWindowsStatusToString(_status)]; } @end objfw-1.1.6/src/exceptions/OFHTTPRequestFailedException.h000066400000000000000000000044131465614216400233230ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif OF_ASSUME_NONNULL_BEGIN @class OFHTTPRequest; @class OFHTTPResponse; /** * @class OFHTTPRequestFailedException \ * OFHTTPRequestFailedException.h \ * ObjFW/OFHTTPRequestFailedException.h * * @brief An exception indicating that an HTTP request failed. */ @interface OFHTTPRequestFailedException: OFException { OFHTTPRequest *_request; OFHTTPResponse *_response; OF_RESERVE_IVARS(OFHTTPRequestFailedException, 4) } /** * @brief The HTTP request which failed. */ @property (readonly, nonatomic) OFHTTPRequest *request; /** * @brief The response for the failed HTTP request. */ @property (readonly, nonatomic) OFHTTPResponse *response; /** * @brief Creates a new, autoreleased HTTP request failed exception. * * @param request The HTTP request which failed * @param response The response for the failed HTTP request * @return A new, autoreleased HTTP request failed exception */ + (instancetype)exceptionWithRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated HTTP request failed exception. * * @param request The HTTP request which failed * @param response The response for the failed HTTP request * @return A new HTTP request failed exception */ - (instancetype)initWithRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFHTTPRequestFailedException.m000066400000000000000000000034331465614216400233310ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFHTTPRequestFailedException.h" #import "OFString.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" @implementation OFHTTPRequestFailedException @synthesize request = _request, response = _response; + (instancetype)exceptionWithRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response { return [[[self alloc] initWithRequest: request response: response] autorelease]; } + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response { self = [super init]; _request = [request retain]; _response = [response retain]; return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_request release]; [_response release]; [super dealloc]; } - (OFString *)description { OFString *method = OFHTTPRequestMethodString(_request.method); return [OFString stringWithFormat: @"An HTTP %@ request with IRI %@ failed with code %hd!", method, _request.IRI, _response.statusCode]; } @end objfw-1.1.6/src/exceptions/OFHashAlreadyCalculatedException.h000066400000000000000000000035361465614216400242420ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFHashAlreadyCalculatedException \ * OFHashAlreadyCalculatedException.h \ * ObjFW/OFHashAlreadyCalculatedException.h * * @brief An exception indicating that the hash has already been calculated. */ @interface OFHashAlreadyCalculatedException: OFException { id _object; OF_RESERVE_IVARS(OFHashAlreadyCalculatedException, 4) } /** * @brief The hash which has already been calculated. */ @property (readonly, nonatomic) id object; /** * @brief Creates a new, autoreleased hash already calculated exception. * * @param object The hash which has already been calculated * @return A new, autoreleased hash already calculated exception */ + (instancetype)exceptionWithObject: (id)object; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated hash already calculated exception. * * @param object The hash which has already been calculated * @return An initialized hash already calculated exception */ - (instancetype)initWithObject: (id)object OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFHashAlreadyCalculatedException.m000066400000000000000000000027151465614216400242450ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFHashAlreadyCalculatedException.h" #import "OFString.h" @implementation OFHashAlreadyCalculatedException @synthesize object = _object; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithObject: (id)object { return [[[self alloc] initWithObject: object] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithObject: (id)object { self = [super init]; _object = [object retain]; return self; } - (void)dealloc { [_object release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"The hash of type %@ has already been calculated and thus no new " @"data can be added!", [_object class]]; } @end objfw-1.1.6/src/exceptions/OFHashNotCalculatedException.h000066400000000000000000000034631465614216400234200ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFHashNotCalculatedException OFHashNotCalculatedException.h \ * ObjFW/OFHashNotCalculatedException.h * * @brief An exception indicating that the hash has not been calculated yet. */ @interface OFHashNotCalculatedException: OFException { id _object; OF_RESERVE_IVARS(OFHashNotCalculatedException, 4) } /** * @brief The hash which has not been calculated yet. */ @property (readonly, nonatomic) id object; /** * @brief Creates a new, autoreleased hash not calculated exception. * * @param object The hash which has not been calculated yet * @return A new, autoreleased hash not calculated exception */ + (instancetype)exceptionWithObject: (id)object; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated hash not calculated exception. * * @param object The hash which has not been calculated yet * @return An initialized hash not calculated exception */ - (instancetype)initWithObject: (id)object OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFHashNotCalculatedException.m000066400000000000000000000026371465614216400234270ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFHashNotCalculatedException.h" #import "OFString.h" @implementation OFHashNotCalculatedException @synthesize object = _object; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithObject: (id)object { return [[[self alloc] initWithObject: object] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithObject: (id)object { self = [super init]; _object = [object retain]; return self; } - (void)dealloc { [_object release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"The hash of type %@ has not been calculated yet!", [_object class]]; } @end objfw-1.1.6/src/exceptions/OFInitializationFailedException.h000066400000000000000000000034511465614216400241630ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFInitializationFailedException \ * OFInitializationFailedException.h \ * ObjFW/OFInitializationFailedException.h * * @brief An exception indicating that initializing something failed. */ @interface OFInitializationFailedException: OFException { Class _inClass; OF_RESERVE_IVARS(OFInitializationFailedException, 4) } /** * @brief The class for which initialization failed. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) Class inClass; /** * @brief Creates a new, autoreleased initialization failed exception. * * @param class_ The class for which initialization failed * @return A new, autoreleased initialization failed exception */ + (instancetype)exceptionWithClass: (nullable Class)class_; /** * @brief Initializes an already allocated initialization failed exception. * * @param class_ The class for which initialization failed * @return An initialized initialization failed exception */ - (instancetype)initWithClass: (nullable Class)class_ OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFInitializationFailedException.m000066400000000000000000000025431465614216400241710ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFInitializationFailedException.h" #import "OFString.h" @implementation OFInitializationFailedException @synthesize inClass = _inClass; + (instancetype)exceptionWithClass: (Class)class { return [[[self alloc] initWithClass: class] autorelease]; } - (instancetype)init { return [self initWithClass: Nil]; } - (instancetype)initWithClass: (Class)class { self = [super init]; _inClass = class; return self; } - (OFString *)description { if (_inClass != Nil) return [OFString stringWithFormat: @"Initialization failed for or in class %@!", _inClass]; else return @"Initialization failed!"; } @end objfw-1.1.6/src/exceptions/OFInvalidArgumentException.h000066400000000000000000000021311465614216400231520ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFInvalidArgumentException \ * OFInvalidArgumentException.h ObjFW/OFInvalidArgumentException.h * * @brief An exception indicating that the argument is invalid for this method. */ @interface OFInvalidArgumentException: OFException { OF_RESERVE_IVARS(OFInvalidArgumentException, 4) } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFInvalidArgumentException.m000066400000000000000000000016741465614216400231720ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFInvalidArgumentException.h" #import "OFString.h" @implementation OFInvalidArgumentException - (OFString *)description { return @"An invalid argument or receiver has been specified!"; } @end objfw-1.1.6/src/exceptions/OFInvalidEncodingException.h000066400000000000000000000021311465614216400231160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFInvalidEncodingException \ * OFInvalidEncodingException.h ObjFW/OFInvalidEncodingException.h * * @brief An exception indicating that the encoding is invalid for this object. */ @interface OFInvalidEncodingException: OFException { OF_RESERVE_IVARS(OFInvalidEncodingException, 4) } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFInvalidEncodingException.m000066400000000000000000000016401465614216400231270ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFInvalidEncodingException.h" #import "OFString.h" @implementation OFInvalidEncodingException - (OFString *)description { return @"An encoding is invalid!"; } @end objfw-1.1.6/src/exceptions/OFInvalidFormatException.h000066400000000000000000000020751465614216400226270ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFInvalidFormatException \ * OFInvalidFormatException.h ObjFW/OFInvalidFormatException.h * * @brief An exception indicating that the format is invalid. */ @interface OFInvalidFormatException: OFException { OF_RESERVE_IVARS(OFInvalidFormatException, 4) } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFInvalidFormatException.m000066400000000000000000000016311465614216400226310ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFInvalidFormatException.h" #import "OFString.h" @implementation OFInvalidFormatException - (OFString *)description { return @"A format is invalid!"; } @end objfw-1.1.6/src/exceptions/OFInvalidJSONException.h000066400000000000000000000042321465614216400221450ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFInvalidJSONException \ * OFInvalidJSONException.h ObjFW/OFInvalidJSONException.h * * @brief An exception indicating a JSON representation is invalid. */ @interface OFInvalidJSONException: OFException { OFString *_string; size_t _line; OF_RESERVE_IVARS(OFInvalidJSONException, 4) } /** * @brief The string containing the invalid JSON representation. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *string; /** * @brief The line in which parsing the JSON representation failed. */ @property (readonly, nonatomic) size_t line; /** * @brief Creates a new, autoreleased invalid JSON exception. * * @param string The string containing the invalid JSON representation * @param line The line in which the parsing error was encountered * @return A new, autoreleased invalid JSON exception */ + (instancetype)exceptionWithString: (nullable OFString *)string line: (size_t)line; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated invalid JSON exception. * * @param string The string containing the invalid JSON representation * @param line The line in which the parsing error was encountered * @return An initialized invalid JSON exception */ - (instancetype)initWithString: (nullable OFString *)string line: (size_t)line OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFInvalidJSONException.m000066400000000000000000000030351465614216400221520ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFInvalidJSONException.h" #import "OFString.h" @implementation OFInvalidJSONException @synthesize string = _string, line = _line; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithString: (OFString *)string line: (size_t)line { return [[[self alloc] initWithString: string line: line] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithString: (OFString *)string line: (size_t)line { self = [super init]; @try { _string = [string copy]; _line = line; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_string release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"The JSON representation is invalid in line %zu!", _line]; } @end objfw-1.1.6/src/exceptions/OFInvalidServerResponseException.h000066400000000000000000000021721465614216400243620ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFInvalidServerResponseException \ * OFInvalidServerResponseException.h \ * ObjFW/OFInvalidServerResponseException.h * * @brief An exception indicating that the server sent an invalid response. */ @interface OFInvalidServerResponseException: OFException { OF_RESERVE_IVARS(OFInvalidServerResponseException, 4) } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFInvalidServerResponseException.m000066400000000000000000000016751465614216400243760ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFInvalidServerResponseException.h" #import "OFString.h" @implementation OFInvalidServerResponseException - (OFString *)description { return @"Got an invalid response from the server!"; } @end objfw-1.1.6/src/exceptions/OFJoinThreadFailedException.h000066400000000000000000000042661465614216400232300ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #ifndef OF_HAVE_THREADS # error No threads available! #endif OF_ASSUME_NONNULL_BEGIN @class OFThread; /** * @class OFJoinThreadFailedException \ * OFJoinThreadFailedException.h ObjFW/OFJoinThreadFailedException.h * * @brief An exception indicating that joining a thread failed. */ @interface OFJoinThreadFailedException: OFException { OFThread *_Nullable _thread; int _errNo; OF_RESERVE_IVARS(OFJoinThreadFailedException, 4) } /** * @brief The thread which could not be joined. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFThread *thread; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased thread join failed exception. * * @param thread The thread which could not be joined * @param errNo The errno of the error that occurred * @return A new, autoreleased thread join failed exception */ + (instancetype)exceptionWithThread: (nullable OFThread *)thread errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated thread join failed exception. * * @param thread The thread which could not be joined * @param errNo The errno of the error that occurred * @return An initialized thread join failed exception */ - (instancetype)initWithThread: (nullable OFThread *)thread errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFJoinThreadFailedException.m000066400000000000000000000030571465614216400232320ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFJoinThreadFailedException.h" #import "OFString.h" #import "OFThread.h" @implementation OFJoinThreadFailedException @synthesize thread = _thread, errNo = _errNo; + (instancetype)exceptionWithThread: (OFThread *)thread errNo: (int)errNo { return [[[self alloc] initWithThread: thread errNo: errNo] autorelease]; } + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithThread: (OFThread *)thread errNo: (int)errNo { self = [super init]; _thread = [thread retain]; _errNo = errNo; return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_thread release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Joining a thread of type %@ failed: %s", _thread.class, strerror(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFLinkItemFailedException.h000066400000000000000000000045261465614216400227140ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFIRI; /** * @class OFLinkItemFailedException \ * OFLinkItemFailedException.h ObjFW/OFLinkItemFailedException.h * * @brief An exception indicating that creating a link failed. */ @interface OFLinkItemFailedException: OFException { OFIRI *_sourceIRI, *_destinationIRI; int _errNo; OF_RESERVE_IVARS(OFLinkItemFailedException, 4) } /** * @brief An IRI with the source for the link. */ @property (readonly, nonatomic) OFIRI *sourceIRI; /** * @brief An IRI with the destination for the link. */ @property (readonly, nonatomic) OFIRI *destinationIRI; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased link failed exception. * * @param sourceIRI The source for the link * @param destinationIRI The destination for the link * @param errNo The errno of the error that occurred * @return A new, autoreleased link failed exception */ + (instancetype)exceptionWithSourceIRI: (OFIRI *)sourceIRI destinationIRI: (OFIRI *)destinationIRI errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated link failed exception. * * @param sourceIRI The source for the link * @param destinationIRI The destination for the link * @param errNo The errno of the error that occurred * @return An initialized link failed exception */ - (instancetype)initWithSourceIRI: (OFIRI*)sourceIRI destinationIRI: (OFIRI *)destinationIRI errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFLinkItemFailedException.m000066400000000000000000000035631465614216400227210ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFLinkItemFailedException.h" #import "OFIRI.h" #import "OFString.h" @implementation OFLinkItemFailedException @synthesize sourceIRI = _sourceIRI, destinationIRI = _destinationIRI; @synthesize errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithSourceIRI: (OFIRI *)sourceIRI destinationIRI: (OFIRI *)destinationIRI errNo: (int)errNo { return [[[self alloc] initWithSourceIRI: sourceIRI destinationIRI: destinationIRI errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithSourceIRI: (OFIRI *)sourceIRI destinationIRI: (OFIRI *)destinationIRI errNo: (int)errNo { self = [super init]; @try { _sourceIRI = [sourceIRI copy]; _destinationIRI = [destinationIRI copy]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_sourceIRI release]; [_destinationIRI release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to link file %@ to %@: %@", _sourceIRI, _destinationIRI, OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFListenOnSocketFailedException.h000066400000000000000000000045421465614216400241020ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif OF_ASSUME_NONNULL_BEGIN /** * @class OFListenOnSocketFailedException \ * OFListenOnSocketFailedException.h \ * ObjFW/OFListenOnSocketFailedException.h * * @brief An exception indicating that listening on the socket failed. */ @interface OFListenOnSocketFailedException: OFException { id _socket; int _backlog, _errNo; OF_RESERVE_IVARS(OFListenOnSocketFailedException, 4) } /** * @brief The socket which failed to listen. */ @property (readonly, nonatomic) id socket; /** * @brief The requested back log. */ @property (readonly, nonatomic) int backlog; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased listen failed exception. * * @param socket The socket which failed to listen * @param backlog The requested size of the back log * @param errNo The errno of the error that occurred * @return A new, autoreleased listen failed exception */ + (instancetype)exceptionWithSocket: (id)socket backlog: (int)backlog errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated listen failed exception. * * @param socket The socket which failed to listen * @param backlog The requested size of the back log * @param errNo The errno of the error that occurred * @return An initialized listen failed exception */ - (instancetype)initWithSocket: (id)socket backlog: (int)backlog errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFListenOnSocketFailedException.m000066400000000000000000000032461465614216400241070ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFListenOnSocketFailedException.h" #import "OFString.h" @implementation OFListenOnSocketFailedException @synthesize socket = _socket, backlog = _backlog, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithSocket: (id)sock backlog: (int)backlog errNo: (int)errNo { return [[[self alloc] initWithSocket: sock backlog: backlog errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithSocket: (id)sock backlog: (int)backlog errNo: (int)errNo { self = [super init]; _socket = [sock retain]; _backlog = backlog; _errNo = errNo; return self; } - (void)dealloc { [_socket release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to listen in socket of type %@ with a back log of %d: %@", [_socket class], _backlog, OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFLoadPluginFailedException.h000066400000000000000000000043161465614216400232330ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFLoadPluginFailedException \ * OFLoadPluginFailedException.h ObjFW/OFLoadPluginFailedException.h * * @brief An exception indicating a plugin could not be loaded. */ @interface OFLoadPluginFailedException: OFException { OFString *_path, *_Nullable _error; OF_RESERVE_IVARS(OFLoadPluginFailedException, 4) } /** * @brief The path of the plugin which could not be loaded */ @property (readonly, nonatomic) OFString *path; /** * @brief The error why the plugin could not be loaded, as a string */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *error; /** * @brief Creates a new, autoreleased load plugin failed exception. * * @param path The path of the plugin which could not be loaded * @param error The error why the plugin could not be loaded, as a string * @return A new, autoreleased load plugin failed exception */ + (instancetype)exceptionWithPath: (OFString *)path error: (nullable OFString *)error; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated load plugin failed exception. * * @param path The path of the plugin which could not be loaded * @param error The error why the plugin could not be loaded, as a string * @return An initialized load plugin failed exception */ - (instancetype)initWithPath: (OFString *)path error: (nullable OFString *)error OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFLoadPluginFailedException.m000066400000000000000000000032371465614216400232410ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFLoadPluginFailedException.h" #import "OFString.h" @implementation OFLoadPluginFailedException @synthesize path = _path, error = _error; + (instancetype)exceptionWithPath: (OFString *)path error: (OFString *)error { return [[[self alloc] initWithPath: path error: error] autorelease]; } + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithPath: (OFString *)path error: (OFString *)error { self = [super init]; @try { _path = [path copy]; _error = [error copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_path release]; [_error release]; [super dealloc]; } - (OFString *)description { if (_error != nil) return [OFString stringWithFormat: @"Failed to load plugin %@: %@", _path, _error]; else return [OFString stringWithFormat: @"Failed to load plugin: %@", _path]; } @end objfw-1.1.6/src/exceptions/OFLockFailedException.h000066400000000000000000000037561465614216400220740ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #import "OFLocking.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFLockFailedException \ * OFLockFailedException.h ObjFW/OFLockFailedException.h * * @brief An exception indicating that locking a lock failed. */ @interface OFLockFailedException: OFException { id _Nullable _lock; int _errNo; OF_RESERVE_IVARS(OFLockFailedException, 4) } /** * @brief The lock which could not be locked. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) id lock; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased lock failed exception. * * @param lock The lock which could not be locked * @param errNo The errno of the error that occurred * @return A new, autoreleased lock failed exception */ + (instancetype)exceptionWithLock: (nullable id )lock errNo: (int)errNo; /** * @brief Initializes an already allocated lock failed exception. * * @param lock The lock which could not be locked * @param errNo The errno of the error that occurred * @return An initialized lock failed exception */ - (instancetype)initWithLock: (nullable id )lock errNo: (int)errNo OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFLockFailedException.m000066400000000000000000000027351465614216400220750ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFLockFailedException.h" #import "OFString.h" @implementation OFLockFailedException @synthesize lock = _lock, errNo = _errNo; + (instancetype)exceptionWithLock: (id )lock errNo: (int)errNo { return [[[self alloc] initWithLock: lock errNo: errNo] autorelease]; } - (instancetype)initWithLock: (id )lock errNo: (int)errNo { self = [super init]; _lock = [lock retain]; _errNo = errNo; return self; } - (void)dealloc { [_lock release]; [super dealloc]; } - (OFString *)description { if (_lock != nil) return [OFString stringWithFormat: @"A lock of type %@ could not be locked: %s", [_lock class], strerror(_errNo)]; else return @"A lock could not be locked!"; } @end objfw-1.1.6/src/exceptions/OFMalformedXMLException.h000066400000000000000000000034311465614216400223540ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" @class OFXMLParser; OF_ASSUME_NONNULL_BEGIN /** * @class OFMalformedXMLException \ * OFMalformedXMLException.h ObjFW/OFMalformedXMLException.h * * @brief An exception indicating that a parser encountered malformed XML. */ @interface OFMalformedXMLException: OFException { OFXMLParser *_parser; OF_RESERVE_IVARS(OFMalformedXMLException, 4) } /** * @brief The parser which encountered malformed XML. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFXMLParser *parser; /** * @brief Creates a new, autoreleased malformed XML exception. * * @param parser The parser which encountered malformed XML * @return A new, autoreleased malformed XML exception */ + (instancetype)exceptionWithParser: (nullable OFXMLParser *)parser; /** * @brief Initializes an already allocated malformed XML exception. * * @param parser The parser which encountered malformed XML * @return An initialized malformed XML exception */ - (instancetype)initWithParser: (nullable OFXMLParser *)parser OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFMalformedXMLException.m000066400000000000000000000030171465614216400223610ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFMalformedXMLException.h" #import "OFString.h" #import "OFXMLParser.h" @implementation OFMalformedXMLException @synthesize parser = _parser; + (instancetype)exceptionWithParser: (OFXMLParser *)parser { return [[[self alloc] initWithParser: parser] autorelease]; } - (instancetype)init { return [self initWithParser: nil]; } - (instancetype)initWithParser: (OFXMLParser *)parser { self = [super init]; _parser = [parser retain]; return self; } - (void)dealloc { [_parser release]; [super dealloc]; } - (OFString *)description { if (_parser != nil) return [OFString stringWithFormat: @"An XML parser of type %@ encountered malformed XML in " @"line %zu!", _parser.class, _parser.lineNumber]; else return @"An XML parser encountered malformed XML!"; } @end objfw-1.1.6/src/exceptions/OFMoveItemFailedException.h000066400000000000000000000044121465614216400227170ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFIRI; /** * @class OFMoveItemFailedException \ * OFMoveItemFailedException.h ObjFW/OFMoveItemFailedException.h * * @brief An exception indicating that moving an item failed. */ @interface OFMoveItemFailedException: OFException { OFIRI *_sourceIRI, *_destinationIRI; int _errNo; OF_RESERVE_IVARS(OFMoveItemFailedException, 4) } /** * @brief The original IRI. */ @property (readonly, nonatomic) OFIRI *sourceIRI; /** * @brief The new IRI. */ @property (readonly, nonatomic) OFIRI *destinationIRI; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased move item failed exception. * * @param sourceIRI The original IRI * @param destinationIRI The new IRI * @param errNo The errno of the error that occurred * @return A new, autoreleased move item failed exception */ + (instancetype)exceptionWithSourceIRI: (OFIRI *)sourceIRI destinationIRI: (OFIRI *)destinationIRI errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated move item failed exception. * * @param sourceIRI The original IRI * @param destinationIRI The new IRI * @param errNo The errno of the error that occurred * @return An initialized move item failed exception */ - (instancetype)initWithSourceIRI: (OFIRI *)sourceIRI destinationIRI: (OFIRI *)destinationIRI errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFMoveItemFailedException.m000066400000000000000000000035731465614216400227330ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFMoveItemFailedException.h" #import "OFIRI.h" #import "OFString.h" @implementation OFMoveItemFailedException @synthesize sourceIRI = _sourceIRI, destinationIRI = _destinationIRI; @synthesize errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithSourceIRI: (OFIRI *)sourceIRI destinationIRI: (OFIRI *)destinationIRI errNo: (int)errNo { return [[[self alloc] initWithSourceIRI: sourceIRI destinationIRI: destinationIRI errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithSourceIRI: (OFIRI *)sourceIRI destinationIRI: (OFIRI *)destinationIRI errNo: (int)errNo { self = [super init]; @try { _sourceIRI = [sourceIRI copy]; _destinationIRI = [destinationIRI copy]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_sourceIRI release]; [_destinationIRI release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to move item at %@ to %@: %@", _sourceIRI, _destinationIRI, OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFNotImplementedException.h000066400000000000000000000043161465614216400230140ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFNotImplementedException \ * OFNotImplementedException.h ObjFW/OFNotImplementedException.h * * @brief An exception indicating that a method or part of it is not * implemented. */ @interface OFNotImplementedException: OFException { SEL _selector; id _Nullable _object; OF_RESERVE_IVARS(OFNotImplementedException, 4) } /** * @brief The selector which is not or not fully implemented. */ @property (readonly, nonatomic) SEL selector; /** * @brief The object which does not (fully) implement the selector. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) id object; /** * @brief Creates a new, autoreleased not implemented exception. * * @param selector The selector which is not or not fully implemented * @param object The object which does not (fully) implement the selector * @return A new, autoreleased not implemented exception */ + (instancetype)exceptionWithSelector: (SEL)selector object: (nullable id)object; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated not implemented exception. * * @param selector The selector which is not or not fully implemented * @param object The object which does not (fully) implement the selector * @return An initialized not implemented exception */ - (instancetype)initWithSelector: (SEL)selector object: (nullable id)object OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFNotImplementedException.m000066400000000000000000000034361465614216400230230ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFNotImplementedException.h" #import "OFString.h" @implementation OFNotImplementedException @synthesize selector = _selector, object = _object; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithSelector: (SEL)selector object: (id)object { return [[[self alloc] initWithSelector: selector object: object] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithSelector: (SEL)selector object: (id)object { self = [super init]; _selector = selector; _object = [object retain]; return self; } - (void)dealloc { [_object release]; [super dealloc]; } - (OFString *)description { if (_object != nil) return [OFString stringWithFormat: @"The selector %s is not understood by an object of type " @"%@ or not (fully) implemented!", sel_getName(_selector), [_object class]]; else return [OFString stringWithFormat: @"The selector %s is not understood by an unknown object " @"or not (fully) implemented!", sel_getName(_selector)]; } @end objfw-1.1.6/src/exceptions/OFNotOpenException.h000066400000000000000000000033401465614216400214460ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFNotOpenException OFNotOpenException.h ObjFW/OFNotOpenException.h * * @brief An exception indicating an object is not open, connected or bound. */ @interface OFNotOpenException: OFException { id _object; OF_RESERVE_IVARS(OFNotOpenException, 4) } /** * @brief The object which is not open, connected or bound. */ @property (readonly, nonatomic) id object; /** * @brief Creates a new, autoreleased not open exception. * * @param object The object which is not open, connected or bound * @return A new, autoreleased not open exception */ + (instancetype)exceptionWithObject: (id)object; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated not open exception. * * @param object The object which is not open, connected or bound * @return An initialized not open exception */ - (instancetype)initWithObject: (id)object OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFNotOpenException.m000066400000000000000000000026211465614216400214540ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFNotOpenException.h" #import "OFString.h" @implementation OFNotOpenException @synthesize object = _object; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithObject: (id)object { return [[[self alloc] initWithObject: object] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithObject: (id)object { self = [super init]; _object = [object retain]; return self; } - (void)dealloc { [_object release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"The object of type %@ is not open, connected or bound!", [_object class]]; } @end objfw-1.1.6/src/exceptions/OFObserveKernelEventsFailedException.h000066400000000000000000000042621465614216400251300ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFKernelEventObserver; /** * @class OFObserveKernelEventsFailedException \ * OFObserveKernelEventsFailedException.h \ * ObjFW/OFObserveKernelEventsFailedException.h * * @brief An exception indicating that observing failed. */ @interface OFObserveKernelEventsFailedException: OFException { OFKernelEventObserver *_observer; int _errNo; OF_RESERVE_IVARS(OFObserveKernelEventsFailedException, 4) } /** * @brief The observer which failed to observe. */ @property (readonly, nonatomic) OFKernelEventObserver *observer; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased observe failed exception. * * @param observer The observer which failed to observe * @param errNo The errno of the error that occurred * @return A new, autoreleased observe failed exception */ + (instancetype)exceptionWithObserver: (OFKernelEventObserver *)observer errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated observe failed exception. * * @param observer The observer which failed to observe * @param errNo The errno of the error that occurred * @return An initialized observe failed exception */ - (instancetype)initWithObserver: (OFKernelEventObserver *)observer errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFObserveKernelEventsFailedException.m000066400000000000000000000033021465614216400251270ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFObserveKernelEventsFailedException.h" #import "OFString.h" #import "OFKernelEventObserver.h" @implementation OFObserveKernelEventsFailedException @synthesize observer = _observer, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithObserver: (OFKernelEventObserver *)observer errNo: (int)errNo { return [[[self alloc] initWithObserver: observer errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithObserver: (OFKernelEventObserver *)observer errNo: (int)errNo { self = [super init]; @try { _observer = [observer retain]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_observer release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"An observer of class %@ failed to observe: %@", _observer.class, OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFOpenItemFailedException.h000066400000000000000000000067321465614216400227210ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFIRI; /** * @class OFOpenItemFailedException \ * OFOpenItemFailedException.h ObjFW/OFOpenItemFailedException.h * * @brief An exception indicating an item could not be opened. */ @interface OFOpenItemFailedException: OFException { OFIRI *_Nullable _IRI; OFString *_Nullable _path; OFString *_mode; int _errNo; OF_RESERVE_IVARS(OFOpenItemFailedException, 4) } /** * @brief The IRI of the item which could not be opened. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFIRI *IRI; /** * @brief The path of the item which could not be opened. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *path; /** * @brief The mode in which the item should have been opened. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *mode; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased open item failed exception. * * @param IRI The IRI of the item which could not be opened * @param mode A string with the mode in which the item should have been opened * @param errNo The errno of the error that occurred * @return A new, autoreleased open item failed exception */ + (instancetype)exceptionWithIRI: (OFIRI *)IRI mode: (nullable OFString *)mode errNo: (int)errNo; /** * @brief Creates a new, autoreleased open item failed exception. * * @param path The path of the item which could not be opened * @param mode A string with the mode in which the item should have been opened * @param errNo The errno of the error that occurred * @return A new, autoreleased open item failed exception */ + (instancetype)exceptionWithPath: (OFString *)path mode: (nullable OFString *)mode errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated open item failed exception. * * @param IRI The IRI of the item which could not be opened * @param mode A string with the mode in which the item should have been opened * @param errNo The errno of the error that occurred * @return An initialized open item failed exception */ - (instancetype)initWithIRI: (OFIRI *)IRI mode: (nullable OFString *)mode errNo: (int)errNo; /** * @brief Initializes an already allocated open item failed exception. * * @param path The path of the item which could not be opened * @param mode A string with the mode in which the item should have been opened * @param errNo The errno of the error that occurred * @return An initialized open item failed exception */ - (instancetype)initWithPath: (OFString *)path mode: (nullable OFString *)mode errNo: (int)errNo; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFOpenItemFailedException.m000066400000000000000000000046441465614216400227260ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFOpenItemFailedException.h" #import "OFIRI.h" #import "OFString.h" @implementation OFOpenItemFailedException @synthesize IRI = _IRI, path = _path, mode = _mode, errNo = _errNo; + (instancetype)exceptionWithIRI: (OFIRI *)IRI mode: (OFString *)mode errNo: (int)errNo { return [[[self alloc] initWithIRI: IRI mode: mode errNo: errNo] autorelease]; } + (instancetype)exceptionWithPath: (OFString *)path mode: (OFString *)mode errNo: (int)errNo { return [[[self alloc] initWithPath: path mode: mode errNo: errNo] autorelease]; } + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithIRI: (OFIRI *)IRI mode: (OFString *)mode errNo: (int)errNo { self = [super init]; @try { _IRI = [IRI copy]; _mode = [mode copy]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode errNo: (int)errNo { self = [super init]; @try { _path = [path copy]; _mode = [mode copy]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_IRI release]; [_path release]; [_mode release]; [super dealloc]; } - (OFString *)description { id item = nil; if (_IRI != nil) item = _IRI; else if (_path != nil) item = _path; if (_mode != nil) return [OFString stringWithFormat: @"Failed to open file %@ with mode %@: %@", item, _mode, OFStrError(_errNo)]; else return [OFString stringWithFormat: @"Failed to open item %@: %@", item, OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFOpenWindowsRegistryKeyFailedException.h000066400000000000000000000070271465614216400256550ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #import "OFWindowsRegistryKey.h" #include OF_ASSUME_NONNULL_BEGIN /** * @class OFOpenWindowsRegistryKeyFailedException \ * OFOpenWindowsRegistryKeyFailedException.h \ * ObjFW/OFOpenWindowsRegistryKeyFailedException.h * * @brief An exception indicating that opening a Windows registry key failed. */ @interface OFOpenWindowsRegistryKeyFailedException: OFException { OFWindowsRegistryKey *_registryKey; OFString *_path; REGSAM _accessRights; LPSECURITY_ATTRIBUTES _Nullable _securityAttributes; DWORD _options; LSTATUS _status; OF_RESERVE_IVARS(OFOpenWindowsRegistryKeyFailedException, 4) } /** * @brief The registry key on which opening the subkey failed. */ @property (readonly, nonatomic) OFWindowsRegistryKey *registryKey; /** * @brief The path for the subkey that could not be opened. */ @property (readonly, nonatomic) OFString *path; /** * @brief The access rights for the subkey that could not be opened. */ @property (readonly, nonatomic) REGSAM accessRights; /** * @brief The options for the subkey that could not be opened. */ @property (readonly, nonatomic) DWORD options; /** * @brief The status returned by RegOpenKeyEx(). */ @property (readonly, nonatomic) LSTATUS status; /** * @brief Creates a new, autoreleased open Windows registry key failed * exception. * * @param registryKey The registry key on which opening the subkey failed * @param path The path for the subkey that could not be opened * @param accessRights The access rights for the sub key that could not be * opened * @param options The options for the subkey that could not be opened * @param status The status returned by RegOpenKeyEx() * @return A new, autoreleased open Windows registry key failed exception */ + (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey path: (OFString *)path accessRights: (REGSAM)accessRights options: (DWORD)options status: (LSTATUS)status; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated open Windows registry key failed * exception. * * @param registryKey The registry key on which opening the subkey failed * @param path The path for the subkey that could not be opened * @param accessRights The access rights for the sub key that could not be * opened * @param options The options for the subkey that could not be opened * @param status The status returned by RegOpenKeyEx() * @return An initialized open Windows registry key failed exception */ - (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey path: (OFString *)path accessRights: (REGSAM)accessRights options: (DWORD)options status: (LSTATUS)status OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFOpenWindowsRegistryKeyFailedException.m000066400000000000000000000042221465614216400256540ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFOpenWindowsRegistryKeyFailedException.h" @implementation OFOpenWindowsRegistryKeyFailedException @synthesize registryKey = _registryKey, path = _path; @synthesize accessRights = _accessRights, options = _options, status = _status; + (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey path: (OFString *)path accessRights: (REGSAM)accessRights options: (DWORD)options status: (LSTATUS)status { return [[[self alloc] initWithRegistryKey: registryKey path: path accessRights: accessRights options: options status: status] autorelease]; } + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey path: (OFString *)path accessRights: (REGSAM)accessRights options: (DWORD)options status: (LSTATUS)status { self = [super init]; @try { _registryKey = [registryKey retain]; _path = [path copy]; _accessRights = accessRights; _options = options; _status = status; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_registryKey release]; [_path release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to open subkey at path %@: %@", _path, _OFWindowsStatusToString(_status)]; } @end objfw-1.1.6/src/exceptions/OFOutOfMemoryException.h000066400000000000000000000033731465614216400223170ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFOutOfMemoryException \ * OFOutOfMemoryException.h ObjFW/OFOutOfMemoryException.h * * @brief An exception indicating there is not enough memory available. */ @interface OFOutOfMemoryException: OFException { size_t _requestedSize; OF_RESERVE_IVARS(OFOutOfMemoryException, 4) } /** * @brief The size of the memory that could not be allocated. */ @property (readonly, nonatomic) size_t requestedSize; /** * @brief Creates a new, autoreleased no memory exception. * * @param requestedSize The size of the memory that could not be allocated * @return A new, autoreleased no memory exception */ + (instancetype)exceptionWithRequestedSize: (size_t)requestedSize; /** * @brief Initializes an already allocated no memory exception. * * @param requestedSize The size of the memory that could not be allocated * @return An initialized no memory exception */ - (instancetype)initWithRequestedSize: (size_t)requestedSize OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFOutOfMemoryException.m000066400000000000000000000026611465614216400223230ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFOutOfMemoryException.h" #import "OFString.h" @implementation OFOutOfMemoryException @synthesize requestedSize = _requestedSize; + (instancetype)exceptionWithRequestedSize: (size_t)requestedSize { return [[[self alloc] initWithRequestedSize: requestedSize] autorelease]; } - (instancetype)init { return [self initWithRequestedSize: 0]; } - (instancetype)initWithRequestedSize: (size_t)requestedSize { self = [super init]; _requestedSize = requestedSize; return self; } - (OFString *)description { if (_requestedSize != 0) return [OFString stringWithFormat: @"Could not allocate %zu bytes!", _requestedSize]; else return @"Could not allocate enough memory!"; } @end objfw-1.1.6/src/exceptions/OFOutOfRangeException.h000066400000000000000000000020631465614216400220760ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFOutOfRangeException \ * OFOutOfRangeException.h ObjFW/OFOutOfRangeException.h * * @brief An exception indicating the given value is out of range. */ @interface OFOutOfRangeException: OFException { OF_RESERVE_IVARS(OFOutOfRangeException, 4) } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFOutOfRangeException.m000066400000000000000000000016221465614216400221030ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFOutOfRangeException.h" #import "OFString.h" @implementation OFOutOfRangeException - (OFString *)description { return @"Value out of range!"; } @end objfw-1.1.6/src/exceptions/OFReadFailedException.h000066400000000000000000000021301465614216400220400ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFReadOrWriteFailedException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFReadFailedException \ * OFReadFailedException.h ObjFW/OFReadFailedException.h * * @brief An exception indicating that reading from an object failed. */ @interface OFReadFailedException: OFReadOrWriteFailedException { OF_RESERVE_IVARS(OFReadFailedException, 4) } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFReadFailedException.m000066400000000000000000000022721465614216400220540ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFReadFailedException.h" #import "OFString.h" @implementation OFReadFailedException - (OFString *)description { if (_errNo != 0) return [OFString stringWithFormat: @"Failed to read %zu bytes from an object of type %@: %@", _requestedLength, [_object class], OFStrError(_errNo)]; else return [OFString stringWithFormat: @"Failed to read %zu bytes from an object of type %@", _requestedLength, [_object class]]; } @end objfw-1.1.6/src/exceptions/OFReadOrWriteFailedException.h000066400000000000000000000050741465614216400233660ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFReadOrWriteFailedException \ * OFReadOrWriteFailedException.h ObjFW/OFReadOrWriteFailedException.h * * @brief An exception indicating that reading from or writing to an object * failed. */ @interface OFReadOrWriteFailedException: OFException { id _object; size_t _requestedLength; int _errNo; OF_RESERVE_IVARS(OFReadOrWriteFailedException, 4) } /** * @brief The stream which caused the read or write failed exception. */ @property (readonly, nonatomic) id object; /** * @brief The requested length of the data that could not be read / written. */ @property (readonly, nonatomic) size_t requestedLength; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Creates a new, autoreleased read or write failed exception. * * @param object The object from which reading or to which writing failed * @param requestedLength The requested length of the data that could not be * read / written * @param errNo The errno of the error that occurred * @return A new, autoreleased read or write failed exception */ + (instancetype)exceptionWithObject: (id)object requestedLength: (size_t)requestedLength errNo: (int)errNo; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated read or write failed exception. * * @param object The object from which reading or to which writing failed * @param requestedLength The requested length of the data that could not be * read / written * @param errNo The errno of the error that occurred * @return A new open file failed exception */ - (instancetype)initWithObject: (id)object requestedLength: (size_t)requestedLength errNo: (int)errNo OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFReadOrWriteFailedException.m000066400000000000000000000037521465614216400233740ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFReadOrWriteFailedException.h" #import "OFString.h" @implementation OFReadOrWriteFailedException @synthesize object = _object, requestedLength = _requestedLength; @synthesize errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithObject: (id)object requestedLength: (size_t)requestedLength errNo: (int)errNo { return [[[self alloc] initWithObject: object requestedLength: requestedLength errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithObject: (id)object requestedLength: (size_t)requestedLength errNo: (int)errNo { self = [super init]; _object = [object retain]; _requestedLength = requestedLength; _errNo = errNo; return self; } - (void)dealloc { [_object release]; [super dealloc]; } - (OFString *)description { if (_errNo != 0) return [OFString stringWithFormat: @"Failed to read or write %zu bytes from / to an object of " @"type %@: %@", _requestedLength, [_object class], OFStrError(_errNo)]; else return [OFString stringWithFormat: @"Failed to read or write %zu bytes from / to an object of " @"type %@", _requestedLength, [_object class]]; } @end objfw-1.1.6/src/exceptions/OFRemoveItemFailedException.h000066400000000000000000000040571465614216400232530ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFIRI; /** * @class OFRemoveItemFailedException \ * OFRemoveItemFailedException.h ObjFW/OFRemoveItemFailedException.h * * @brief An exception indicating that removing an item failed. */ @interface OFRemoveItemFailedException: OFException { OFIRI *_IRI; int _errNo; OF_RESERVE_IVARS(OFRemoveItemFailedException, 4) } /** * @brief The IRI of the item which could not be removed. */ @property (readonly, nonatomic) OFIRI *IRI; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased remove failed exception. * * @param IRI The IRI of the item which could not be removed * @param errNo The errno of the error that occurred * @return A new, autoreleased remove item failed exception */ + (instancetype)exceptionWithIRI: (OFIRI *)IRI errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated remove failed exception. * * @param IRI The IRI of the item which could not be removed * @param errNo The errno of the error that occurred * @return An initialized remove item failed exception */ - (instancetype)initWithIRI: (OFIRI *)IRI errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFRemoveItemFailedException.m000066400000000000000000000030351465614216400232530ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFRemoveItemFailedException.h" #import "OFIRI.h" #import "OFString.h" @implementation OFRemoveItemFailedException @synthesize IRI = _IRI, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithIRI: (OFIRI *)IRI errNo: (int)errNo { return [[[self alloc] initWithIRI: IRI errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithIRI: (OFIRI *)IRI errNo: (int)errNo { self = [super init]; @try { _IRI = [IRI copy]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_IRI release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to remove item at IRI %@: %@", _IRI, OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFResolveHostFailedException.h000066400000000000000000000051731465614216400234540ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #import "OFDNSResolver.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFResolveHostFailedException \ * OFResolveHostFailedException.h ObjFW/OFResolveHostFailedException.h * * @brief An exception indicating that resolving a host failed. */ @interface OFResolveHostFailedException: OFException { OFString *_host; OFSocketAddressFamily _addressFamily; OFDNSResolverErrorCode _errorCode; OF_RESERVE_IVARS(OFResolveHostFailedException, 4) } /** * @brief The host which could not be resolved. */ @property (readonly, nonatomic) OFString *host; /** * @brief The address family for which the host could not be resolved. */ @property (readonly, nonatomic) OFSocketAddressFamily addressFamily; /** * @brief The error code from the resolver. */ @property (readonly, nonatomic) OFDNSResolverErrorCode errorCode; /** * @brief Creates a new, autoreleased resolve host failed exception. * * @param host The host which could not be resolved * @param addressFamily The address family for which the host could not be * resolved * @param errorCode The error code from the resolver * @return A new, autoreleased address translation failed exception */ + (instancetype)exceptionWithHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily errorCode: (OFDNSResolverErrorCode)errorCode; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated resolve host failed exception. * * @param host The host which could not be resolved * @param addressFamily The address family for which the host could not be * resolved * @param errorCode The error code from the resolver * @return An initialized address translation failed exception */ - (instancetype)initWithHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily errorCode: (OFDNSResolverErrorCode)errorCode; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFResolveHostFailedException.m000066400000000000000000000036541465614216400234630ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFResolveHostFailedException.h" #import "OFDNSQueryFailedException.h" #import "OFString.h" @implementation OFResolveHostFailedException @synthesize host = _host, addressFamily = _addressFamily; @synthesize errorCode = _errorCode; + (instancetype)exceptionWithHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily errorCode: (OFDNSResolverErrorCode)errorCode { return [[[self alloc] initWithHost: host addressFamily: addressFamily errorCode: errorCode] autorelease]; } + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily errorCode: (OFDNSResolverErrorCode)errorCode { self = [super init]; @try { _host = [host copy]; _addressFamily = addressFamily; _errorCode = errorCode; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_host release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"The host %@ could not be resolved: %@", _host, _OFDNSResolverErrorCodeDescription(_errorCode)]; } @end objfw-1.1.6/src/exceptions/OFSeekFailedException.h000066400000000000000000000052241465614216400220630ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #import "OFSeekableStream.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFSeekFailedException \ * OFSeekFailedException.h ObjFW/OFSeekFailedException.h * * @brief An exception indicating that seeking in a stream failed. */ @interface OFSeekFailedException: OFException { OFSeekableStream *_stream; OFStreamOffset _offset; OFSeekWhence _whence; int _errNo; OF_RESERVE_IVARS(OFSeekFailedException, 4) } /** * @brief The stream for which seeking failed. */ @property (readonly, nonatomic) OFSeekableStream *stream; /** * @brief The offset to which seeking failed. */ @property (readonly, nonatomic) OFStreamOffset offset; /** * @brief To what the offset is relative. */ @property (readonly, nonatomic) OFSeekWhence whence; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased seek failed exception. * * @param stream The stream for which seeking failed * @param offset The offset to which seeking failed * @param whence To what the offset is relative * @param errNo The errno of the error that occurred * @return A new, autoreleased seek failed exception */ + (instancetype)exceptionWithStream: (OFSeekableStream *)stream offset: (OFStreamOffset)offset whence: (OFSeekWhence)whence errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated seek failed exception. * * @param stream The stream for which seeking failed * @param offset The offset to which seeking failed * @param whence To what the offset is relative * @param errNo The errno of the error that occurred * @return An initialized seek failed exception */ - (instancetype)initWithStream: (OFSeekableStream *)stream offset: (OFStreamOffset)offset whence: (OFSeekWhence)whence errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFSeekFailedException.m000066400000000000000000000035271465614216400220740ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFSeekFailedException.h" #import "OFString.h" #import "OFSeekableStream.h" @implementation OFSeekFailedException @synthesize stream = _stream, offset = _offset, whence = _whence; @synthesize errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithStream: (OFSeekableStream *)stream offset: (OFStreamOffset)offset whence: (OFSeekWhence)whence errNo: (int)errNo { return [[[self alloc] initWithStream: stream offset: offset whence: whence errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithStream: (OFSeekableStream *)stream offset: (OFStreamOffset)offset whence: (OFSeekWhence)whence errNo: (int)errNo { self = [super init]; _stream = [stream retain]; _offset = offset; _whence = whence; _errNo = errNo; return self; } - (void)dealloc { [_stream release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Seeking failed in stream of type %@: %@", _stream.class, OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFSetItemAttributesFailedException.h000066400000000000000000000060261465614216400246160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #import "OFIRIHandler.h" OF_ASSUME_NONNULL_BEGIN @class OFIRI; /** * @class OFSetItemAttributesFailedException \ * OFSetItemAttributesFailedException.h \ * ObjFW/OFSetItemAttributesFailedException.h * * @brief An exception indicating an item's attributes could not be set. */ @interface OFSetItemAttributesFailedException: OFException { OFIRI *_IRI; OFFileAttributes _attributes; OFFileAttributeKey _failedAttribute; int _errNo; OF_RESERVE_IVARS(OFSetItemAttributesFailedException, 4) } /** * @brief The IRI of the item whose attributes could not be set. */ @property (readonly, nonatomic) OFIRI *IRI; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief The attributes that should have been set. */ @property (readonly, nonatomic) OFFileAttributes attributes; /** * @brief The first attribute that could not be set. */ @property (readonly, nonatomic) OFFileAttributeKey failedAttribute; /** * @brief Creates a new, autoreleased set item attributes failed exception. * * @param IRI The IRI of the item whose attributes could not be set * @param attributes The attributes that should have been set for the specified * item. * @param failedAttribute The first attribute that could not be set * @param errNo The errno of the error that occurred * @return A new, autoreleased set item attributes failed exception */ + (instancetype)exceptionWithIRI: (OFIRI *)IRI attributes: (OFFileAttributes)attributes failedAttribute: (OFFileAttributeKey)failedAttribute errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated set item attributes failed exception. * * @param IRI The IRI of the item whose attributes could not be set * @param attributes The attributes that should have been set for the specified * item. * @param failedAttribute The first attribute that could not be set * @param errNo The errno of the error that occurred * @return An initialized set item attributes failed exception */ - (instancetype)initWithIRI: (OFIRI *)IRI attributes: (OFFileAttributes)attributes failedAttribute: (OFFileAttributeKey)failedAttribute errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFSetItemAttributesFailedException.m000066400000000000000000000041041465614216400246160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFSetItemAttributesFailedException.h" #import "OFIRI.h" #import "OFString.h" @implementation OFSetItemAttributesFailedException @synthesize IRI = _IRI, attributes = _attributes; @synthesize failedAttribute = _failedAttribute, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithIRI: (OFIRI *)IRI attributes: (OFFileAttributes)attributes failedAttribute: (OFFileAttributeKey)failedAttribute errNo: (int)errNo { return [[[self alloc] initWithIRI: IRI attributes: attributes failedAttribute: failedAttribute errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithIRI: (OFIRI *)IRI attributes: (OFFileAttributes)attributes failedAttribute: (OFFileAttributeKey)failedAttribute errNo: (int)errNo { self = [super init]; @try { _IRI = [IRI copy]; _attributes = [attributes copy]; _failedAttribute = [failedAttribute copy]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_IRI release]; [_attributes release]; [_failedAttribute release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to set attribute %@ for item %@: %@", _failedAttribute, _IRI, OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFSetOptionFailedException.h000066400000000000000000000041511465614216400231160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFSetOptionFailedException \ * OFSetOptionFailedException.h ObjFW/OFSetOptionFailedException.h * * @brief An exception indicating that setting an option for an object failed. */ @interface OFSetOptionFailedException: OFException { id _Nullable _object; int _errNo; OF_RESERVE_IVARS(OFSetOptionFailedException, 4) } /** * @brief The object for which the option could not be set. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) id object; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased set option failed exception. * * @param object The object for which the option could not be set * @param errNo The errno of the error that occurred * @return A new, autoreleased set option failed exception */ + (instancetype)exceptionWithObject: (nullable id)object errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated set option failed exception. * * @param object The object for which the option could not be set * @param errNo The errno of the error that occurred * @return An initialized set option failed exception */ - (instancetype)initWithObject: (nullable id)object errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFSetOptionFailedException.m000066400000000000000000000032041465614216400231210ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFSetOptionFailedException.h" #import "OFString.h" @implementation OFSetOptionFailedException @synthesize object = _object, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithObject: (id)object errNo: (int)errNo { return [[[self alloc] initWithObject: object errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithObject: (id)object errNo: (int)errNo { self = [super init]; _object = [object retain]; _errNo = errNo; return self; } - (void)dealloc { [_object release]; [super dealloc]; } - (OFString *)description { if (_object != nil) return [OFString stringWithFormat: @"Setting an option in an object of type %@ failed: %@", [_object class], OFStrError(_errNo)]; else return [OFString stringWithFormat: @"Setting an option failed: %@", OFStrError(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFSetWindowsRegistryValueFailedException.h000066400000000000000000000066361465614216400260400ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #import "OFWindowsRegistryKey.h" #include OF_ASSUME_NONNULL_BEGIN /** * @class OFSetWindowsRegistryValueFailedException \ * OFSetWindowsRegistryValueFailedException.h \ * ObjFW/OFSetWindowsRegistryValueFailedException.h * * @brief An exception indicating that setting a Windows registry value failed. */ @interface OFSetWindowsRegistryValueFailedException: OFException { OFWindowsRegistryKey *_registryKey; OFString *_Nullable _valueName; OFData *_Nullable _data; DWORD _type; LSTATUS _status; OF_RESERVE_IVARS(OFSetWindowsRegistryValueFailedException, 4) } /** * @brief The registry key on which setting the value failed. */ @property (readonly, nonatomic) OFWindowsRegistryKey *registryKey; /** * @brief The name of the value which could not be set. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *valueName; /** * @brief The data to which the value could not be set. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFData *data; /** * @brief The type for the value that could not be set. */ @property (readonly, nonatomic) DWORD type; /** * @brief The status returned by RegSetValueEx(). */ @property (readonly, nonatomic) LSTATUS status; /** * @brief Creates a new, autoreleased set Windows registry value failed * exception. * * @param registryKey The registry key on which setting the value failed * @param valueName The name of the value which could not be set * @param data The data to which the value could not be set * @param type The type for the value that could not be set * @param status The status returned by RegSetValueEx() * @return A new, autoreleased set Windows registry value failed exception */ + (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey valueName: (nullable OFString *)valueName data: (nullable OFData *)data type: (DWORD)type status: (LSTATUS)status; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated set Windows registry value failed * exception. * * @param registryKey The registry key on which setting the value failed * @param valueName The name of the value which could not be set * @param data The data to which the value could not be set * @param type The type for the value that could not be set * @param status The status returned by RegSetValueEx() * @return An initialized set Windows registry value failed exception */ - (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey valueName: (nullable OFString *)valueName data: (nullable OFData *)data type: (DWORD)type status: (LSTATUS)status OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFSetWindowsRegistryValueFailedException.m000066400000000000000000000041541465614216400260360ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFSetWindowsRegistryValueFailedException.h" #import "OFData.h" @implementation OFSetWindowsRegistryValueFailedException @synthesize registryKey = _registryKey, valueName = _valueName, data = _data; @synthesize type = _type, status = _status; + (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey valueName: (OFString *)valueName data: (OFData *)data type: (DWORD)type status: (LSTATUS)status { return [[[self alloc] initWithRegistryKey: registryKey valueName: valueName data: data type: type status: status] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey valueName: (OFString *)valueName data: (OFData *)data type: (DWORD)type status: (LSTATUS)status { self = [super init]; @try { _registryKey = [registryKey retain]; _valueName = [valueName copy]; _data = [data copy]; _type = type; _status = status; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_registryKey release]; [_valueName release]; [_data release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to set value named %@ of type %u: %@", _valueName, _type, _OFWindowsStatusToString(_status)]; } @end objfw-1.1.6/src/exceptions/OFSignalConditionFailedException.h000066400000000000000000000043561465614216400242650ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #ifndef OF_HAVE_THREADS # error No threads available! #endif OF_ASSUME_NONNULL_BEGIN @class OFCondition; /** * @class OFSignalConditionFailedException \ * OFSignalConditionFailedException.h \ * ObjFW/OFSignalConditionFailedException.h * * @brief An exception indicating signaling a condition failed. */ @interface OFSignalConditionFailedException: OFException { OFCondition *_condition; int _errNo; OF_RESERVE_IVARS(OFSignalConditionFailedException, 4) } /** * @brief The condition which could not be signaled. */ @property (readonly, nonatomic) OFCondition *condition; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased condition signal failed exception. * * @param condition The condition which could not be signaled * @param errNo The errno of the error that occurred * @return A new, autoreleased condition signal failed exception */ + (instancetype)exceptionWithCondition: (OFCondition *)condition errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated condition signal failed exception. * * @param condition The condition which could not be signaled * @param errNo The errno of the error that occurred * @return An initialized condition signal failed exception */ - (instancetype)initWithCondition: (OFCondition *)condition errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFSignalConditionFailedException.m000066400000000000000000000031671465614216400242710ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFSignalConditionFailedException.h" #import "OFString.h" #import "OFCondition.h" @implementation OFSignalConditionFailedException @synthesize condition = _condition, errNo = _errNo; + (instancetype)exceptionWithCondition: (OFCondition *)condition errNo: (int)errNo { return [[[self alloc] initWithCondition: condition errNo: errNo] autorelease]; } + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithCondition: (OFCondition *)condition errNo: (int)errNo { self = [super init]; _condition = [condition retain]; _errNo = errNo; return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_condition release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Signaling a condition of type %@ failed: %s", _condition.class, strerror(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFStartThreadFailedException.h000066400000000000000000000043031465614216400234160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #ifndef OF_HAVE_THREADS # error No threads available! #endif OF_ASSUME_NONNULL_BEGIN @class OFThread; /** * @class OFStartThreadFailedException \ * OFStartThreadFailedException.h ObjFW/OFStartThreadFailedException.h * * @brief An exception indicating that starting a thread failed. */ @interface OFStartThreadFailedException: OFException { OFThread *_Nullable _thread; int _errNo; OF_RESERVE_IVARS(OFStartThreadFailedException, 4) } /** * @brief The thread which could not be started. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFThread *thread; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased thread start failed exception. * * @param thread The thread which could not be started * @param errNo The errno of the error that occurred * @return A new, autoreleased thread start failed exception */ + (instancetype)exceptionWithThread: (nullable OFThread *)thread errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated thread start failed exception. * * @param thread The thread which could not be started * @param errNo The errno of the error that occurred * @return An initialized thread start failed exception */ - (instancetype)initWithThread: (nullable OFThread *)thread errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFStartThreadFailedException.m000066400000000000000000000030621465614216400234240ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFStartThreadFailedException.h" #import "OFString.h" #import "OFThread.h" @implementation OFStartThreadFailedException @synthesize thread = _thread, errNo = _errNo; + (instancetype)exceptionWithThread: (OFThread *)thread errNo: (int)errNo { return [[[self alloc] initWithThread: thread errNo: errNo] autorelease]; } + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithThread: (OFThread *)thread errNo: (int)errNo { self = [super init]; _thread = [thread retain]; _errNo = errNo; return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_thread release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Starting a thread of type %@ failed: %s", _thread.class, strerror(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFStillLockedException.h000066400000000000000000000033411465614216400222760ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #import "OFLocking.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFStillLockedException \ * OFStillLockedException.h ObjFW/OFStillLockedException.h * * @brief An exception indicating that a lock is still locked. */ @interface OFStillLockedException: OFException { id _Nullable _lock; OF_RESERVE_IVARS(OFStillLockedException, 4) } /** * @brief The lock which is still locked. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) id lock; /** * @brief Creates a new, autoreleased still locked exception. * * @param lock The lock which is still locked * @return A new, autoreleased still locked exception */ + (instancetype)exceptionWithLock: (nullable id )lock; /** * @brief Initializes an already allocated still locked exception. * * @param lock The lock which is still locked * @return An initialized still locked exception */ - (instancetype)initWithLock: (nullable id )lock OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFStillLockedException.m000066400000000000000000000027451465614216400223120ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFStillLockedException.h" #import "OFString.h" @implementation OFStillLockedException @synthesize lock = _lock; + (instancetype)exceptionWithLock: (id )lock { return [[[self alloc] initWithLock: lock] autorelease]; } - (instancetype)init { return [self initWithLock: nil]; } - (instancetype)initWithLock: (id )lock { self = [super init]; _lock = [lock retain]; return self; } - (void)dealloc { [_lock release]; [super dealloc]; } - (OFString *)description { if (_lock != nil) return [OFString stringWithFormat: @"Deallocation of a lock of type %@ even though it was " @"still locked!", [_lock class]]; else return @"Deallocation of a lock even though it was still " @"locked!"; } @end objfw-1.1.6/src/exceptions/OFTLSHandshakeFailedException.h000066400000000000000000000053231465614216400234450ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif #import "OFTLSStream.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif extern int _OFTLSHandshakeFailedException_reference OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif /** * @class OFTLSHandshakeFailedException \ * OFTLSHandshakeFailedException.h ObjFW/OFTLSHandshakeFailedException.h * * @brief An exception indicating that a TLS handshake. */ @interface OFTLSHandshakeFailedException: OFException { OFTLSStream *_stream; OFString *_Nullable _host; OFTLSStreamErrorCode _errorCode; OF_RESERVE_IVARS(OFTLSHandshakeFailedException, 4) } /** * @brief The TLS stream which failed the handshake. */ @property (readonly, nonatomic) OFTLSStream *stream; /** * @brief The host for the handshake. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *host; /** * @brief The error code from the TLS stream. */ @property (readonly, nonatomic) OFTLSStreamErrorCode errorCode; /** * @brief Creates a new, autoreleased TLS handshake failed exception. * * @param stream The TLS stream which failed the handshake * @param host The host for the handshake * @param errorCode The error code from the TLS stream * @return A new, autoreleased TLS handshake failed exception */ + (instancetype)exceptionWithStream: (OFTLSStream *)stream host: (nullable OFString *)host errorCode: (OFTLSStreamErrorCode)errorCode; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated TLS handshake failed exception. * * @param stream The TLS stream which failed the handshake * @param host The host for the handshake * @param errorCode The error code from the TLS stream * @return An initialized TLS handshake failed exception */ - (instancetype)initWithStream: (OFTLSStream *)stream host: (nullable OFString *)host errorCode: (OFTLSStreamErrorCode)errorCode OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFTLSHandshakeFailedException.m000066400000000000000000000041031465614216400234450ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFTLSHandshakeFailedException.h" #import "OFString.h" int _OFTLSHandshakeFailedException_reference; @implementation OFTLSHandshakeFailedException @synthesize stream = _stream, host = _host, errorCode = _errorCode; + (instancetype)exceptionWithStream: (OFTLSStream *)stream host: (OFString *)host errorCode: (OFTLSStreamErrorCode)errorCode { return [[[self alloc] initWithStream: stream host: host errorCode: errorCode] autorelease]; } + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithStream: (OFTLSStream *)stream host: (OFString *)host errorCode: (OFTLSStreamErrorCode)errorCode { self = [super init]; @try { _stream = [stream retain]; _host = [host copy]; _errorCode = errorCode; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_stream release]; [_host release]; [super dealloc]; } - (OFString *)description { if (_host != nil) return [OFString stringWithFormat: @"TLS handshake in class %@ with host %@ failed: %@", _stream.class, _host, OFTLSStreamErrorCodeDescription(_errorCode)]; else return [OFString stringWithFormat: @"TLS handshake in class %@ failed: %@", _stream.class, OFTLSStreamErrorCodeDescription(_errorCode)]; } @end objfw-1.1.6/src/exceptions/OFThreadStillRunningException.h000066400000000000000000000035501465614216400236470ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #ifndef OF_HAVE_THREADS # error No threads available! #endif OF_ASSUME_NONNULL_BEGIN @class OFThread; /** * @class OFThreadStillRunningException \ * OFThreadStillRunningException.h ObjFW/OFThreadStillRunningException.h * * @brief An exception indicating that a thread is still running. */ @interface OFThreadStillRunningException: OFException { OFThread *_Nullable _thread; OF_RESERVE_IVARS(OFThreadStillRunningException, 4) } /** * @brief The thread which is still running. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFThread *thread; /** * @brief Creates a new, autoreleased thread still running exception. * * @param thread The thread which is still running * @return A new, autoreleased thread still running exception */ + (instancetype)exceptionWithThread: (nullable OFThread *)thread; /** * @brief Initializes an already allocated thread still running exception. * * @param thread The thread which is still running * @return An initialized thread still running exception */ - (instancetype)initWithThread: (nullable OFThread *)thread OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFThreadStillRunningException.m000066400000000000000000000030651465614216400236550ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFThreadStillRunningException.h" #import "OFString.h" #import "OFThread.h" @implementation OFThreadStillRunningException @synthesize thread = _thread; + (instancetype)exceptionWithThread: (OFThread *)thread { return [[[self alloc] initWithThread: thread] autorelease]; } - (instancetype)init { return [self initWithThread: nil]; } - (instancetype)initWithThread: (OFThread *)thread { self = [super init]; _thread = [thread retain]; return self; } - (void)dealloc { [_thread release]; [super dealloc]; } - (OFString *)description { if (_thread) return [OFString stringWithFormat: @"Deallocation of a thread of type %@ was tried, even " @"though it was still running!", _thread.class]; else return @"Deallocation of a thread was tried, even though it " @"was still running!"; } @end objfw-1.1.6/src/exceptions/OFTruncatedDataException.h000066400000000000000000000021471465614216400226130ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFTruncatedDataException \ * OFTruncatedDataException.h ObjFW/OFTruncatedDataException.h * * @brief An exception indicating that data was truncated while it should not * have been truncated. */ @interface OFTruncatedDataException: OFException { OF_RESERVE_IVARS(OFTruncatedDataException, 4) } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFTruncatedDataException.m000066400000000000000000000017351465614216400226220ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFTruncatedDataException.h" #import "OFString.h" @implementation OFTruncatedDataException - (OFString *)description { return @"Truncated data was received or produced when it should not " @"have been truncated!"; } @end objfw-1.1.6/src/exceptions/OFUnboundNamespaceException.h000066400000000000000000000044321465614216400233160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFXMLElement; /** * @class OFUnboundNamespaceException \ * OFUnboundNamespaceException.h ObjFW/OFUnboundNamespaceException.h * * @brief An exception indicating an attempt to use an unbound namespace. */ @interface OFUnboundNamespaceException: OFException { OFString *_namespace; OFXMLElement *_element; OF_RESERVE_IVARS(OFUnboundNamespaceException, 4) } /** * @brief The unbound namespace. */ #ifndef __cplusplus @property (readonly, nonatomic) OFString *namespace; #else @property (readonly, nonatomic, getter=namespace) OFString *nameSpace; #endif /** * @brief The element in which the namespace was not bound. */ @property (readonly, nonatomic) OFXMLElement *element; /** * @brief Creates a new, autoreleased unbound namespace exception. * * @param nameSpace The namespace which is unbound * @param element The element in which the namespace was not bound * @return A new, autoreleased unbound namespace exception */ + (instancetype)exceptionWithNamespace: (OFString *)nameSpace element: (OFXMLElement *)element; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated unbound namespace exception. * * @param nameSpace The namespace which is unbound * @param element The element in which the namespace was not bound * @return An initialized unbound namespace exception */ - (instancetype)initWithNamespace: (OFString *)nameSpace element: (OFXMLElement *)element OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFUnboundNamespaceException.m000066400000000000000000000033431465614216400233230ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFUnboundNamespaceException.h" #import "OFString.h" #import "OFXMLElement.h" @implementation OFUnboundNamespaceException @synthesize namespace = _namespace, element = _element; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithNamespace: (OFString *)namespace element: (OFXMLElement *)element { return [[[self alloc] initWithNamespace: namespace element: element] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithNamespace: (OFString *)namespace element: (OFXMLElement *)element { self = [super init]; @try { _namespace = [namespace copy]; _element = [element retain]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_namespace release]; [_element release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"The namespace %@ is not bound in an element of type %@!", _namespace, _element.class]; } @end objfw-1.1.6/src/exceptions/OFUnboundPrefixException.h000066400000000000000000000041331465614216400226550ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFXMLParser; /** * @class OFUnboundPrefixException \ * OFUnboundPrefixException.h ObjFW/OFUnboundPrefixException.h * * @brief An exception indicating an attempt to use an unbound prefix. */ @interface OFUnboundPrefixException: OFException { OFString *_prefix; OFXMLParser *_parser; OF_RESERVE_IVARS(OFUnboundPrefixException, 4) } /** * @brief The unbound prefix. */ @property (readonly, nonatomic) OFString *prefix; /** * @brief The parser which encountered the unbound prefix. */ @property (readonly, nonatomic) OFXMLParser *parser; /** * @brief Creates a new, autoreleased unbound prefix exception. * * @param prefix The prefix which is unbound * @param parser The parser which encountered the unbound prefix * @return A new, autoreleased unbound prefix exception */ + (instancetype)exceptionWithPrefix: (OFString *)prefix parser: (OFXMLParser *)parser; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated unbound prefix exception. * * @param prefix The prefix which is unbound * @param parser The parser which encountered the unbound prefix * @return An initialized unbound prefix exception */ - (instancetype)initWithPrefix: (OFString *)prefix parser: (OFXMLParser *)parser OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFUnboundPrefixException.m000066400000000000000000000033201465614216400226570ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFUnboundPrefixException.h" #import "OFString.h" #import "OFXMLParser.h" @implementation OFUnboundPrefixException @synthesize prefix = _prefix, parser = _parser; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithPrefix: (OFString *)prefix parser: (OFXMLParser *)parser { return [[[self alloc] initWithPrefix: prefix parser: parser] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithPrefix: (OFString *)prefix parser: (OFXMLParser *)parser { self = [super init]; @try { _prefix = [prefix copy]; _parser = [parser retain]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_prefix release]; [_parser release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"An XML parser of type %@ encountered the unbound prefix %@ in " @"line %zu!", _parser.class, _prefix, _parser.lineNumber]; } @end objfw-1.1.6/src/exceptions/OFUndefinedKeyException.h000066400000000000000000000056671465614216400224540ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFUndefinedKeyException \ * OFUndefinedKeyException.h ObjFW/OFUndefinedKeyException.h * * @brief An exception indicating that a key is undefined (e.g. for Key Value * Coding). */ @interface OFUndefinedKeyException: OFException { id _object; OFString *_Nullable _key; id _Nullable _value; OF_RESERVE_IVARS(OFUndefinedKeyException, 4) } /** * @brief The object on which the key is undefined. */ @property (readonly, nonatomic) id object; /** * @brief The key which is undefined. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *key; /** * @brief The value for the undefined key */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) id value; /** * @brief Creates a new, autoreleased undefined key exception. * * @param object The object on which the key is undefined * @param key The key which is undefined * * @return A new, autoreleased undefined key exception */ + (instancetype)exceptionWithObject: (id)object key: (OFString *)key; /** * @brief Creates a new, autoreleased undefined key exception. * * @param object The object on which the key is undefined * @param key The key which is undefined * @param value The value for the undefined key * * @return A new, autoreleased undefined key exception */ + (instancetype)exceptionWithObject: (id)object key: (nullable OFString *)key value: (nullable id)value; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated undefined key exception. * * @param object The object on which the key is undefined * @param key The key which is undefined * * @return An initialized undefined key exception */ - (instancetype)initWithObject: (id)object key: (OFString *)key; /** * @brief Initializes an already allocated undefined key exception. * * @param object The object on which the key is undefined * @param key The key which is undefined * @param value The value for the undefined key * * @return An initialized undefined key exception */ - (instancetype)initWithObject: (id)object key: (nullable OFString *)key value: (nullable id)value OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFUndefinedKeyException.m000066400000000000000000000037411465614216400224500ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFUndefinedKeyException.h" #import "OFString.h" @implementation OFUndefinedKeyException @synthesize object = _object, key = _key, value = _value; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithObject: (id)object key: (OFString *)key { return [[[self alloc] initWithObject: object key: key] autorelease]; } + (instancetype)exceptionWithObject: (id)object key: (OFString *)key value: (id)value { return [[[self alloc] initWithObject: object key: key value: value] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithObject: (id)object key: (OFString *)key { return [self initWithObject: object key: key value: nil]; } - (instancetype)initWithObject: (id)object key: (OFString *)key value: (id)value { self = [super init]; @try { _object = [object retain]; _key = [key copy]; _value = [value retain]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_object release]; [_key release]; [_value release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"The key \"%@\" is undefined for an object of type %@!", _key, [_object className]]; } @end objfw-1.1.6/src/exceptions/OFUnknownXMLEntityException.h000066400000000000000000000035371465614216400233110ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFUnknownXMLEntityException \ * OFUnknownXMLEntityException.h ObjFW/OFUnknownXMLEntityException.h * * @brief An exception indicating that a parser encountered an unknown XML * entity. */ @interface OFUnknownXMLEntityException: OFException { OFString *_entityName; OF_RESERVE_IVARS(OFUnknownXMLEntityException, 4) } /** * @brief The name of the unknown XML entity. */ @property (readonly, nonatomic) OFString *entityName; /** * @brief Creates a new, autoreleased unknown XML entity exception. * * @param entityName The name of the unknown XML entity * @return A new, autoreleased unknown XML entity exception */ + (instancetype)exceptionWithEntityName: (OFString *)entityName; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated unknown XML entity exception. * * @param entityName The name of the unknown XML entity * @return An initialized unknown XML entity exception */ - (instancetype)initWithEntityName: (OFString *)entityName OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFUnknownXMLEntityException.m000066400000000000000000000030241465614216400233050ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFUnknownXMLEntityException.h" #import "OFString.h" @implementation OFUnknownXMLEntityException @synthesize entityName = _entityName; + (instancetype)exceptionWithEntityName: (OFString *)entityName { return [[[self alloc] initWithEntityName: entityName] autorelease]; } + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithEntityName: (OFString *)entityName { self = [super init]; @try { _entityName = [entityName copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_entityName release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"A parser encountered an unknown XML entity named %@!", _entityName]; } @end objfw-1.1.6/src/exceptions/OFUnlockFailedException.h000066400000000000000000000040101465614216400224170ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #import "OFLocking.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFUnlockFailedException \ * OFUnlockFailedException.h ObjFW/OFUnlockFailedException.h * * @brief An exception indicating that unlocking a lock failed. */ @interface OFUnlockFailedException: OFException { id _Nullable _lock; int _errNo; OF_RESERVE_IVARS(OFUnlockFailedException, 4) } /** * @brief The lock which could not be unlocked. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) id lock; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased unlock failed exception. * * @param lock The lock which could not be unlocked * @param errNo The errno of the error that occurred * @return A new, autoreleased unlock failed exception */ + (instancetype)exceptionWithLock: (nullable id )lock errNo: (int)errNo; /** * @brief Initializes an already allocated unlock failed exception. * * @param lock The lock which could not be unlocked * @param errNo The errno of the error that occurred * @return An initialized unlock failed exception */ - (instancetype)initWithLock: (nullable id )lock errNo: (int)errNo OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFUnlockFailedException.m000066400000000000000000000027451465614216400224410ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFUnlockFailedException.h" #import "OFString.h" @implementation OFUnlockFailedException @synthesize lock = _lock, errNo = _errNo; + (instancetype)exceptionWithLock: (id )lock errNo: (int)errNo { return [[[self alloc] initWithLock: lock errNo: errNo] autorelease]; } - (instancetype)initWithLock: (id )lock errNo: (int)errNo { self = [super init]; _lock = [lock retain]; _errNo = errNo; return self; } - (void)dealloc { [_lock release]; [super dealloc]; } - (OFString *)description { if (_lock != nil) return [OFString stringWithFormat: @"A lock of type %@ could not be unlocked: %s", [_lock class], strerror(_errNo)]; else return @"A lock could not be unlocked!"; } @end objfw-1.1.6/src/exceptions/OFUnsupportedProtocolException.h000066400000000000000000000034621465614216400241430ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFIRI; /** * @class OFUnsupportedProtocolException \ * OFUnsupportedProtocolException.h \ * ObjFW/OFUnsupportedProtocolException.h * * @brief An exception indicating that the protocol specified by the IRI is not * supported. */ @interface OFUnsupportedProtocolException: OFException { OFIRI *_Nullable _IRI; OF_RESERVE_IVARS(OFUnsupportedProtocolException, 4) } /** * @brief The IRI whose protocol is unsupported. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFIRI *IRI; /** * @brief Creates a new, autoreleased unsupported protocol exception. * * @param IRI The IRI whose protocol is unsupported * @return A new, autoreleased unsupported protocol exception */ + (instancetype)exceptionWithIRI: (nullable OFIRI*)IRI; /** * @brief Initializes an already allocated unsupported protocol exception * * @param IRI The IRI whose protocol is unsupported * @return An initialized unsupported protocol exception */ - (instancetype)initWithIRI: (nullable OFIRI*)IRI OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFUnsupportedProtocolException.m000066400000000000000000000025511465614216400241460ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFUnsupportedProtocolException.h" #import "OFIRI.h" #import "OFString.h" @implementation OFUnsupportedProtocolException @synthesize IRI = _IRI; + (instancetype)exceptionWithIRI: (OFIRI *)IRI { return [[[self alloc] initWithIRI: IRI] autorelease]; } - (instancetype)initWithIRI: (OFIRI *)IRI { self = [super init]; _IRI = [IRI retain]; return self; } - (void)dealloc { [_IRI release]; [super dealloc]; } - (OFString *)description { if (_IRI != nil) return [OFString stringWithFormat: @"The protocol of IRI %@ is not supported!", _IRI]; else return @"The requested protocol is unsupported!"; } @end objfw-1.1.6/src/exceptions/OFUnsupportedVersionException.h000066400000000000000000000035421465614216400237660ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFUnsupportedVersionException \ * OFUnsupportedVersionException.h ObjFW/OFUnsupportedVersionException.h * * @brief An exception indicating that the specified version of the format or * protocol is not supported. */ @interface OFUnsupportedVersionException: OFException { OFString *_version; OF_RESERVE_IVARS(OFUnsupportedVersionException, 4) } /** * @brief The version which is unsupported. */ @property (readonly, nonatomic) OFString *version; /** * @brief Creates a new, autoreleased unsupported version exception. * * @param version The version which is unsupported * @return A new, autoreleased unsupported version exception */ + (instancetype)exceptionWithVersion: (OFString *)version; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated unsupported protocol exception. * * @param version The version which is unsupported * @return An initialized unsupported version exception */ - (instancetype)initWithVersion: (OFString *)version OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFUnsupportedVersionException.m000066400000000000000000000027661465614216400240020ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFUnsupportedVersionException.h" #import "OFString.h" @implementation OFUnsupportedVersionException @synthesize version = _version; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithVersion: (OFString *)version { return [[[self alloc] initWithVersion: version] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithVersion: (OFString *)version { self = [super init]; @try { _version = [version copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_version release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Version %@ of the format or protocol is not supported!", _version]; } @end objfw-1.1.6/src/exceptions/OFWaitForConditionFailedException.h000066400000000000000000000043631465614216400244210ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #ifndef OF_HAVE_THREADS # error No threads available! #endif OF_ASSUME_NONNULL_BEGIN @class OFCondition; /** * @class OFWaitForConditionFailedException \ * OFWaitForConditionFailedException.h \ * ObjFW/OFWaitForConditionFailedException.h * * @brief An exception indicating waiting for a condition failed. */ @interface OFWaitForConditionFailedException: OFException { OFCondition *_condition; int _errNo; OF_RESERVE_IVARS(OFWaitForConditionFailedException, 4) } /** * @brief The condition for which could not be waited. */ @property (readonly, nonatomic) OFCondition *condition; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased condition wait failed exception. * * @param condition The condition for which could not be waited * @param errNo The errno of the error that occurred * @return A new, autoreleased condition wait failed exception */ + (instancetype)exceptionWithCondition: (OFCondition *)condition errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated condition wait failed exception. * * @param condition The condition for which could not be waited * @param errNo The errno of the error that occurred * @return An initialized condition wait failed exception */ - (instancetype)initWithCondition: (OFCondition *)condition errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFWaitForConditionFailedException.m000066400000000000000000000031731465614216400244240ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFWaitForConditionFailedException.h" #import "OFString.h" #import "OFCondition.h" @implementation OFWaitForConditionFailedException @synthesize condition = _condition, errNo = _errNo; + (instancetype)exceptionWithCondition: (OFCondition *)condition errNo: (int)errNo { return [[[self alloc] initWithCondition: condition errNo: errNo] autorelease]; } + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithCondition: (OFCondition *)condition errNo: (int)errNo { self = [super init]; _condition = [condition retain]; _errNo = errNo; return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_condition release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Waiting for a condition of type %@ failed: %s", _condition.class, strerror(_errNo)]; } @end objfw-1.1.6/src/exceptions/OFWriteFailedException.h000066400000000000000000000054731465614216400222740ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFReadOrWriteFailedException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFWriteFailedException \ * OFWriteFailedException.h ObjFW/OFWriteFailedException.h * * @brief An exception indicating that writing to an object failed. */ @interface OFWriteFailedException: OFReadOrWriteFailedException { size_t _bytesWritten; OF_RESERVE_IVARS(OFWriteFailedException, 4) } /** * @brief The number of bytes already written before the write failed. * * This can be used to make sure that a retry does not write data already * written before. */ @property (readonly, nonatomic) size_t bytesWritten; /** * @brief Creates a new, autoreleased write failed exception. * * @param object The object from which reading or to which writing failed * @param requestedLength The requested length of the data that could not be * read / written * @param bytesWritten The amount of bytes already written before the write * failed * @param errNo The errno of the error that occurred * @return A new, autoreleased write failed exception */ + (instancetype)exceptionWithObject: (id)object requestedLength: (size_t)requestedLength bytesWritten: (size_t)bytesWritten errNo: (int)errNo; + (instancetype)exceptionWithObject: (id)object requestedLength: (size_t)requestedLength errNo: (int)errNo OF_UNAVAILABLE; /** * @brief Initializes an already allocated write failed exception. * * @param object The object from which reading or to which writing failed * @param requestedLength The requested length of the data that could not be * read / written * @param bytesWritten The amount of bytes already written before the write * failed * @param errNo The errno of the error that occurred * @return A new open file failed exception */ - (instancetype)initWithObject: (id)object requestedLength: (size_t)requestedLength bytesWritten: (size_t)bytesWritten errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)initWithObject: (id)object requestedLength: (size_t)requestedLength errNo: (int)errNo OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/exceptions/OFWriteFailedException.m000066400000000000000000000045311465614216400222730ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFWriteFailedException.h" #import "OFString.h" @implementation OFWriteFailedException @synthesize bytesWritten = _bytesWritten; + (instancetype)exceptionWithObject: (id)object requestedLength: (size_t)requestedLength errNo: (int)errNo { return [[[self alloc] initWithObject: object requestedLength: requestedLength errNo: errNo] autorelease]; } + (instancetype)exceptionWithObject: (id)object requestedLength: (size_t)requestedLength bytesWritten: (size_t)bytesWritten errNo: (int)errNo { return [[[self alloc] initWithObject: object requestedLength: requestedLength bytesWritten: bytesWritten errNo: errNo] autorelease]; } - (instancetype)initWithObject: (id)object requestedLength: (size_t)requestedLength errNo: (int)errNo { OF_INVALID_INIT_METHOD } - (instancetype)initWithObject: (id)object requestedLength: (size_t)requestedLength bytesWritten: (size_t)bytesWritten errNo: (int)errNo { self = [super initWithObject: object requestedLength: requestedLength errNo: errNo]; _bytesWritten = bytesWritten; return self; } - (OFString *)description { if (_errNo != 0) return [OFString stringWithFormat: @"Failed to write %zu bytes (after %zu bytes written) to " @"an object of type %@: %@", _requestedLength, _bytesWritten, [_object class], OFStrError(_errNo)]; else return [OFString stringWithFormat: @"Failed to write %zu bytes (after %zu bytes written) to " @"an object of type %@", _requestedLength, _bytesWritten, [_object class]]; } @end objfw-1.1.6/src/forwarding/000077500000000000000000000000001465614216400155705ustar00rootroot00000000000000objfw-1.1.6/src/forwarding/Makefile000066400000000000000000000002611465614216400172270ustar00rootroot00000000000000include ../../extra.mk STATIC_PIC_LIB_NOINST = ${FORWARDING_LIB_A} STATIC_LIB_NOINST = ${FORWARDING_A} SRCS = forwarding.S include ../../buildsys.mk ASFLAGS += -I../.. -I.. objfw-1.1.6/src/forwarding/apple-forwarding-amd64.S000066400000000000000000000100561465614216400220700ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #ifdef HAVE_CET_H # include #else # define _CET_ENDBR #endif .globl _OFForward .globl _OFForward_stret .section __TEXT, __objc_methname, cstring_literals Lstr_forwardingTargetForSelector_: .asciz "forwardingTargetForSelector:" .section __DATA, __objc_selrefs, literal_pointers, no_dead_strip .p2align 3 Lsel_forwardingTargetForSelector_: .quad Lstr_forwardingTargetForSelector_ .section __DATA, __objc_imageinfo, regular, no_dead_strip .long 0, 0x40 .section __TEXT, __text, regular, pure_instructions _OFForward: _CET_ENDBR pushq %rbp movq %rsp, %rbp /* Save all arguments */ subq $0xC0, %rsp /* 16-byte alignment */ movq %rax, -0x8(%rbp) movq %rdi, -0x10(%rbp) movq %rsi, -0x18(%rbp) movq %rdx, -0x20(%rbp) movq %rcx, -0x28(%rbp) movq %r8, -0x30(%rbp) movq %r9, -0x38(%rbp) movaps %xmm0, -0x50(%rbp) movaps %xmm1, -0x60(%rbp) movaps %xmm2, -0x70(%rbp) movaps %xmm3, -0x80(%rbp) movaps %xmm4, -0x90(%rbp) movaps %xmm5, -0xA0(%rbp) movaps %xmm6, -0xB0(%rbp) movaps %xmm7, -0xC0(%rbp) call _object_getClass movq %rax, %rdi movq Lsel_forwardingTargetForSelector_(%rip), %rsi call _class_respondsToSelector testq %rax, %rax jz 0f movq -0x10(%rbp), %rdi movq Lsel_forwardingTargetForSelector_(%rip), %rsi movq -0x18(%rbp), %rdx call _objc_msgSend testq %rax, %rax jz 0f cmpq -0x10(%rbp), %rax je 0f movq %rax, %rdi /* Restore all arguments, except %rdi */ movaps -0xC0(%rbp), %xmm7 movaps -0xB0(%rbp), %xmm6 movaps -0xA0(%rbp), %xmm5 movaps -0x90(%rbp), %xmm4 movaps -0x80(%rbp), %xmm3 movaps -0x70(%rbp), %xmm2 movaps -0x60(%rbp), %xmm1 movaps -0x50(%rbp), %xmm0 movq -0x38(%rbp), %r9 movq -0x30(%rbp), %r8 movq -0x28(%rbp), %rcx movq -0x20(%rbp), %rdx movq -0x18(%rbp), %rsi movq -0x8(%rbp), %rax movq %rbp, %rsp popq %rbp jmp _objc_msgSend 0: movq -0x10(%rbp), %rdi movq -0x18(%rbp), %rsi movq %rbp, %rsp popq %rbp jmp _OFMethodNotFound _OFForward_stret: _CET_ENDBR pushq %rbp movq %rsp, %rbp /* Save all arguments */ subq $0xC0, %rsp /* 16-byte alignment */ movq %rax, -0x8(%rbp) movq %rdi, -0x10(%rbp) movq %rsi, -0x18(%rbp) movq %rdx, -0x20(%rbp) movq %rcx, -0x28(%rbp) movq %r8, -0x30(%rbp) movq %r9, -0x38(%rbp) movaps %xmm0, -0x50(%rbp) movaps %xmm1, -0x60(%rbp) movaps %xmm2, -0x70(%rbp) movaps %xmm3, -0x80(%rbp) movaps %xmm4, -0x90(%rbp) movaps %xmm5, -0xA0(%rbp) movaps %xmm6, -0xB0(%rbp) movaps %xmm7, -0xC0(%rbp) movq %rsi, %rdi call _object_getClass movq %rax, %rdi movq Lsel_forwardingTargetForSelector_(%rip), %rsi call _class_respondsToSelector testq %rax, %rax jz 0f movq -0x18(%rbp), %rdi movq Lsel_forwardingTargetForSelector_(%rip), %rsi movq -0x20(%rbp), %rdx call _objc_msgSend testq %rax, %rax jz 0f cmpq -0x18(%rbp), %rax je 0f movq %rax, %rsi /* Restore all arguments, except %rsi */ movaps -0xC0(%rbp), %xmm7 movaps -0xB0(%rbp), %xmm6 movaps -0xA0(%rbp), %xmm5 movaps -0x90(%rbp), %xmm4 movaps -0x80(%rbp), %xmm3 movaps -0x70(%rbp), %xmm2 movaps -0x60(%rbp), %xmm1 movaps -0x50(%rbp), %xmm0 movq -0x38(%rbp), %r9 movq -0x30(%rbp), %r8 movq -0x28(%rbp), %rcx movq -0x20(%rbp), %rdx movq -0x10(%rbp), %rdi movq -0x8(%rbp), %rax movq %rbp, %rsp popq %rbp jmp _objc_msgSend_stret 0: movq -0x10(%rbp), %rdi movq -0x18(%rbp), %rsi movq -0x20(%rbp), %rdx movq %rbp, %rsp popq %rbp jmp _OFMethodNotFound_stret objfw-1.1.6/src/forwarding/apple-forwarding-arm.S000066400000000000000000000050001465614216400217250ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" .globl _OFForward .globl _OFForward_stret .section __TEXT, __objc_methname, cstring_literals Lstr_forwardingTargetForSelector_: .asciz "forwardingTargetForSelector:" .section __DATA, __objc_selrefs, literal_pointers, no_dead_strip Lsel_forwardingTargetForSelector_: .long str_forwardingTargetForSelector_ .section __DATA, __objc_imageinfo, regular, no_dead_strip .long 0, 0 .section __TEXT, __text, regular, pure_instructions .arm .align 2 _OFForward: stmfd sp!, {r0-r4, lr} vstmdb sp!, {d0-d7} ldr r4, Lsel_forwardingTargetForSelector_$indirect_L0 L0: ldr r4, [pc, r4] blx _object_getClass mov r1, r4 blx _class_respondsToSelector cmp r0, #0 beq 0f ldr r0, [sp, #64] mov r1, r4 ldr r2, [sp, #68] blx _objc_msgSend cmp r0, #0 beq 0f ldr r1, [sp, #64] cmp r0, r1 beq 0f vldmia sp!, {d0-d7} add sp, sp, #4 @ throw away r0 ldmfd sp!, {r1-r4, lr} b _objc_msgSend 0: vldmia sp!, {d0-d7} ldmfd sp!, {r0-r4, lr} b _OFMethodNotFound .data_region Lsel_forwardingTargetForSelector_$indirect_L0: .long Lsel_forwardingTargetForSelector_-(L0+8) .end_data_region .align 2 _OFForward_stret: stmfd sp!, {r0-r4, lr} vstmdb sp!, {d0-d7} ldr r4, Lsel_forwardingTargetForSelector_$indirect_L1 L1: ldr r4, [pc, r4] mov r0, r1 blx _object_getClass mov r1, r4 blx _class_respondsToSelector cmp r0, #0 beq 0f ldr r0, [sp, #68] mov r1, r4 ldr r2, [sp, #72] blx _objc_msgSend cmp r0, #0 beq 0f ldr r1, [sp, #68] cmp r0, r1 beq 0f mov r1, r0 vldmia sp!, {d0-d7} ldmfd sp!, {r0} add sp, sp, #4 @ throw away r1 ldmfd sp!, {r2-r4, lr} b _objc_msgSend_stret 0: vldmia sp!, {d0-d7} ldmfd sp!, {r0-r4, lr} b _OFMethodNotFound_stret .data_region Lsel_forwardingTargetForSelector_$indirect_L1: .long Lsel_forwardingTargetForSelector_-(L1+8) .end_data_region objfw-1.1.6/src/forwarding/apple-forwarding-arm64.S000066400000000000000000000044571465614216400221160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" .globl _OFForward .globl _OFForward_stret .section __TEXT, __objc_methname, cstring_literals Lstr_forwardingTargetForSelector_: .asciz "forwardingTargetForSelector:" .section __DATA, __objc_selrefs, literal_pointers, no_dead_strip .p2align 3 Lsel_forwardingTargetForSelector_: .quad Lstr_forwardingTargetForSelector_ .section __DATA, __objc_imageinfo, regular, no_dead_strip .long 0, 0x40 .section __TEXT, __text, regular, pure_instructions .align 2 _OFForward: _OFForward_stret: #ifdef HAVE_BTI bti c #endif stp fp, lr, [sp, #-224]! mov fp, sp /* Save all arguments, x8 and x19 */ stp x0, x1, [sp, #16] stp x2, x3, [sp, #32] stp x4, x5, [sp, #48] stp x6, x7, [sp, #64] stp x8, x19, [sp, #80] /* Save all foating point arguments */ stp q0, q1, [sp, #96] stp q2, q3, [sp, #128] stp q4, q5, [sp, #160] stp q6, q7, [sp, #192] bl _object_getClass adrp x19, Lsel_forwardingTargetForSelector_@PAGE add x19, x19, Lsel_forwardingTargetForSelector_@PAGEOFF ldr x19, [x19] mov x1, x19 bl _class_respondsToSelector cbz x0, 0f ldp x0, x2, [sp, #16] mov x1, x19 bl _objc_msgSend cbz x0, 0f ldr x1, [sp, #16] cmp x0, x1 b.eq 0f /* Restore all arguments, x8 and x19, but not x0 */ ldr x1, [sp, #24] ldp x2, x3, [sp, #32] ldp x4, x5, [sp, #48] ldp x6, x7, [sp, #64] ldp x8, x19, [sp, #80] /* Restore all foating point arguments */ ldp q0, q1, [sp, #96] ldp q2, q3, [sp, #128] ldp q4, q5, [sp, #160] ldp q6, q7, [sp, #192] ldp fp, lr, [sp], #224 b _objc_msgSend 0: ldp x0, x1, [sp, #16] ldr x19, [sp, #88] ldp fp, lr, [sp], #224 b _OFMethodNotFound objfw-1.1.6/src/forwarding/apple-forwarding-powerpc.S000066400000000000000000000105051465614216400226330ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" .globl _OFForward .globl _OFForward_stret .section __TEXT, __cstring, cstring_literals Lstr_forwardingTargetForSelector_: .asciz "forwardingTargetForSelector:" .section __OBJC, __message_refs Lsel_forwardingTargetForSelector_: .long Lstr_forwardingTargetForSelector_ .section __OBJC, __image_info .long 0, 0 .section __TEXT, __text, regular, pure_instructions _OFForward: mflr r0 stw r0, 8(r1) stwu r1, -192(r1) /* * Save all arguments and r13. * * We can dump two parameters in the parameter area as we know that * space has been reserved for at least two parameters. */ stw r3, 216(r1) stw r4, 220(r1) stw r5, 56(r1) stw r6, 60(r1) stw r7, 64(r1) stw r8, 68(r1) stw r9, 72(r1) stw r10, 76(r1) stw r13, 80(r1) /* Save all floating point arguments */ stfd f1, 88(r1) stfd f2, 96(r1) stfd f3, 104(r1) stfd f4, 112(r1) stfd f5, 120(r1) stfd f6, 128(r1) stfd f7, 136(r1) stfd f8, 144(r1) stfd f9, 152(r1) stfd f10, 160(r1) stfd f11, 168(r1) stfd f12, 176(r1) stfd f13, 184(r1) bl _object_getClass bl 0f 0: mflr r13 addis r13, r13, ha16(Lsel_forwardingTargetForSelector_-0b) lwz r13, lo16(Lsel_forwardingTargetForSelector_-0b)(r13) mr r4, r13 bl _class_respondsToSelector cmpwi r3, 0 beq- 0f lwz r3, 216(r1) mr r4, r13 lwz r5, 220(r1) bl _objc_msgSend cmpwi r3, 0 beq- 0f lwz r4, 216(r1) cmpw r3, r4 beq- 0f /* Restore all arguments and r13, except r3 */ lwz r4, 220(r1) lwz r5, 56(r1) lwz r6, 60(r1) lwz r7, 64(r1) lwz r8, 68(r1) lwz r9, 72(r1) lwz r10, 76(r1) lwz r13, 80(r1) /* Restore all floating point arguments */ lfd f1, 88(r1) lfd f2, 96(r1) lfd f3, 104(r1) lfd f4, 112(r1) lfd f5, 120(r1) lfd f6, 128(r1) lfd f7, 136(r1) lfd f8, 144(r1) lfd f9, 152(r1) lfd f10, 160(r1) lfd f11, 168(r1) lfd f12, 176(r1) lfd f13, 184(r1) addi r1, r1, 192 lwz r0, 8(r1) mtlr r0 b _objc_msgSend 0: lwz r3, 216(r1) lwz r4, 220(r1) addi r1, r1, 192 lwz r0, 8(r1) mtlr r0 b _OFMethodNotFound _OFForward_stret: mflr r0 stw r0, 8(r1) stwu r1, -184(r1) /* * Save all arguments and r13. * * We can dump three parameters in the parameter area as we know that * space has been reserved for at least three parameters. */ stw r3, 208(r1) stw r4, 212(r1) stw r5, 216(r1) stw r6, 56(r1) stw r7, 60(r1) stw r8, 64(r1) stw r9, 68(r1) stw r10, 72(r1) stw r13, 76(r1) /* Save all floating point arguments */ stfd f1, 80(r1) stfd f2, 88(r1) stfd f3, 96(r1) stfd f4, 104(r1) stfd f5, 112(r1) stfd f6, 120(r1) stfd f7, 128(r1) stfd f8, 136(r1) stfd f9, 144(r1) stfd f10, 152(r1) stfd f11, 160(r1) stfd f12, 168(r1) stfd f13, 176(r1) mr r3, r4 bl _object_getClass bl 0f 0: mflr r13 addis r13, r13, ha16(Lsel_forwardingTargetForSelector_-0b) lwz r13, lo16(Lsel_forwardingTargetForSelector_-0b)(r13) mr r4, r13 bl _class_respondsToSelector cmpwi r3, 0 beq- 0f lwz r3, 212(r1) mr r4, r13 lwz r5, 216(r1) bl _objc_msgSend cmpwi r3, 0 beq- 0f lwz r4, 212(r1) cmpw r3, r4 beq- 0f mr r4, r3 /* Restore all arguments and r13, except r4 */ lwz r3, 208(r1) lwz r5, 216(r1) lwz r6, 56(r1) lwz r7, 60(r1) lwz r8, 64(r1) lwz r9, 68(r1) lwz r10, 72(r1) lwz r13, 76(r1) /* Restore all floating point arguments */ lfd f1, 80(r1) lfd f2, 88(r1) lfd f3, 96(r1) lfd f4, 104(r1) lfd f5, 112(r1) lfd f6, 120(r1) lfd f7, 128(r1) lfd f8, 136(r1) lfd f9, 144(r1) lfd f10, 152(r1) lfd f11, 160(r1) lfd f12, 168(r1) lfd f13, 176(r1) addi r1, r1, 184 lwz r0, 8(r1) mtlr r0 b _objc_msgSend_stret 0: lwz r3, 208(r1) lwz r4, 212(r1) lwz r5, 216(r1) addi r1, r1, 184 lwz r0, 8(r1) mtlr r0 b _OFMethodNotFound_stret objfw-1.1.6/src/forwarding/apple-forwarding-x86.S000066400000000000000000000051501465614216400216010ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #ifdef HAVE_CET_H # include #else # define _CET_ENDBR #endif .globl _OFForward .globl _OFForward_stret .section __TEXT, __cstring, cstring_literals Lstr_forwardingTargetForSelector_: .asciz "forwardingTargetForSelector:" .section __OBJC, __message_refs, literal_pointers, no_dead_strip Lsel_forwardingTargetForSelector_: .long Lstr_forwardingTargetForSelector_ .section __OBJC, __image_info .long 0, 0 .section __TEXT, __text, regular, pure_instructions _OFForward: _CET_ENDBR pushl %ebp movl %esp, %ebp pushl %ebx subl $20, %esp call LgetEIP 0: movl 8(%ebp), %eax movl %eax, (%esp) call _object_getClass movl %eax, (%esp) movl Lsel_forwardingTargetForSelector_-0b(%ebx), %eax movl %eax, 4(%esp) call _class_respondsToSelector testl %eax, %eax jz 0f movl 8(%ebp), %eax movl %eax, (%esp) movl Lsel_forwardingTargetForSelector_-0b(%ebx), %eax movl %eax, 4(%esp) movl 12(%ebp), %eax movl %eax, 8(%esp) call _objc_msgSend testl %eax, %eax jz 0f cmpl 8(%ebp), %eax je 0f movl %eax, 8(%ebp) addl $20, %esp popl %ebx popl %ebp jmp _objc_msgSend 0: addl $20, %esp popl %ebx popl %ebp jmp _OFMethodNotFound _OFForward_stret: _CET_ENDBR pushl %ebp movl %esp, %ebp pushl %ebx subl $20, %esp call LgetEIP 0: movl 12(%ebp), %eax movl %eax, (%esp) call _object_getClass movl %eax, (%esp) movl Lsel_forwardingTargetForSelector_-0b(%ebx), %eax movl %eax, 4(%esp) call _class_respondsToSelector testl %eax, %eax jz 0f movl 12(%ebp), %eax movl %eax, (%esp) movl Lsel_forwardingTargetForSelector_-0b(%ebx), %eax movl %eax, 4(%esp) movl 16(%ebp), %eax movl %eax, 8(%esp) call _objc_msgSend testl %eax, %eax jz 0f cmpl 12(%ebp), %eax je 0f movl %eax, 12(%ebp) addl $20, %esp popl %ebx popl %ebp jmp _objc_msgSend_stret 0: addl $20, %esp popl %ebx popl %ebp jmp _OFMethodNotFound_stret LgetEIP: movl (%esp), %ebx ret objfw-1.1.6/src/forwarding/forwarding-amd64-elf.S000066400000000000000000000114751465614216400215430ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" #ifdef HAVE_CET_H # include #else # define _CET_ENDBR #endif .globl OFForward .globl OFForward_stret .section .text OFForward: _CET_ENDBR pushq %rbp movq %rsp, %rbp /* Save all arguments */ subq $0xC0, %rsp /* 16-byte alignment */ movq %rax, -0x8(%rbp) movq %rdi, -0x10(%rbp) movq %rsi, -0x18(%rbp) movq %rdx, -0x20(%rbp) movq %rcx, -0x28(%rbp) movq %r8, -0x30(%rbp) movq %r9, -0x38(%rbp) movaps %xmm0, -0x50(%rbp) movaps %xmm1, -0x60(%rbp) movaps %xmm2, -0x70(%rbp) movaps %xmm3, -0x80(%rbp) movaps %xmm4, -0x90(%rbp) movaps %xmm5, -0xA0(%rbp) movaps %xmm6, -0xB0(%rbp) movaps %xmm7, -0xC0(%rbp) call object_getClass@PLT movq %rax, %rdi leaq .Lsel_forwardingTargetForSelector_(%rip), %rsi call class_respondsToSelector@PLT testq %rax, %rax jz 0f movq -0x10(%rbp), %rdi leaq .Lsel_forwardingTargetForSelector_(%rip), %rsi call objc_msg_lookup@PLT movq -0x10(%rbp), %rdi leaq .Lsel_forwardingTargetForSelector_(%rip), %rsi movq -0x18(%rbp), %rdx call *%rax testq %rax, %rax jz 0f cmpq -0x10(%rbp), %rax je 0f movq %rax, -0x10(%rbp) movq %rax, %rdi movq -0x18(%rbp), %rsi call objc_msg_lookup@PLT movq %rax, %r11 /* Restore all arguments */ movaps -0xC0(%rbp), %xmm7 movaps -0xB0(%rbp), %xmm6 movaps -0xA0(%rbp), %xmm5 movaps -0x90(%rbp), %xmm4 movaps -0x80(%rbp), %xmm3 movaps -0x70(%rbp), %xmm2 movaps -0x60(%rbp), %xmm1 movaps -0x50(%rbp), %xmm0 movq -0x38(%rbp), %r9 movq -0x30(%rbp), %r8 movq -0x28(%rbp), %rcx movq -0x20(%rbp), %rdx movq -0x18(%rbp), %rsi movq -0x10(%rbp), %rdi movq -0x8(%rbp), %rax movq %rbp, %rsp popq %rbp jmpq *%r11 0: movq -0x10(%rbp), %rdi movq -0x18(%rbp), %rsi movq %rbp, %rsp popq %rbp jmp OFMethodNotFound@PLT .type OFForward, %function .size OFForward, .-OFForward OFForward_stret: _CET_ENDBR pushq %rbp movq %rsp, %rbp /* Save all arguments */ subq $0xC0, %rsp /* 16-byte alignment */ movq %rax, -0x8(%rbp) movq %rdi, -0x10(%rbp) movq %rsi, -0x18(%rbp) movq %rdx, -0x20(%rbp) movq %rcx, -0x28(%rbp) movq %r8, -0x30(%rbp) movq %r9, -0x38(%rbp) movaps %xmm0, -0x50(%rbp) movaps %xmm1, -0x60(%rbp) movaps %xmm2, -0x70(%rbp) movaps %xmm3, -0x80(%rbp) movaps %xmm4, -0x90(%rbp) movaps %xmm5, -0xA0(%rbp) movaps %xmm6, -0xB0(%rbp) movaps %xmm7, -0xC0(%rbp) movq %rsi, %rdi call object_getClass@PLT movq %rax, %rdi leaq .Lsel_forwardingTargetForSelector_(%rip), %rsi call class_respondsToSelector@PLT testq %rax, %rax jz 0f movq -0x18(%rbp), %rdi leaq .Lsel_forwardingTargetForSelector_(%rip), %rsi call objc_msg_lookup@PLT movq -0x18(%rbp), %rdi leaq .Lsel_forwardingTargetForSelector_(%rip), %rsi movq -0x20(%rbp), %rdx call *%rax testq %rax, %rax jz 0f cmpq -0x18(%rbp), %rax je 0f movq %rax, -0x18(%rbp) movq %rax, %rdi movq -0x20(%rbp), %rsi call objc_msg_lookup_stret@PLT movq %rax, %r11 /* Restore all arguments */ movaps -0xC0(%rbp), %xmm7 movaps -0xB0(%rbp), %xmm6 movaps -0xA0(%rbp), %xmm5 movaps -0x90(%rbp), %xmm4 movaps -0x80(%rbp), %xmm3 movaps -0x70(%rbp), %xmm2 movaps -0x60(%rbp), %xmm1 movaps -0x50(%rbp), %xmm0 movq -0x38(%rbp), %r9 movq -0x30(%rbp), %r8 movq -0x28(%rbp), %rcx movq -0x20(%rbp), %rdx movq -0x18(%rbp), %rsi movq -0x10(%rbp), %rdi movq -0x8(%rbp), %rax movq %rbp, %rsp popq %rbp jmpq *%r11 0: movq -0x10(%rbp), %rdi movq -0x18(%rbp), %rsi movq -0x20(%rbp), %rdx movq %rbp, %rsp popq %rbp jmp OFMethodNotFound_stret@PLT .type OFForward_stret, %function .size OFForward_stret, .-OFForward_stret .Linit: _CET_ENDBR leaq .Lmodule(%rip), %rdi jmp __objc_exec_class@PLT #ifdef OF_SOLARIS .section .init_array, "aw" #else .section .ctors, "aw", %progbits #endif .quad .Linit .section .rodata .Lstr_forwardingTargetForSelector_: .asciz "forwardingTargetForSelector:" .section .data .Lsel_forwardingTargetForSelector_: .quad .Lstr_forwardingTargetForSelector_, 0 .quad 0, 0 .Lsymtab: .quad 0, .Lsel_forwardingTargetForSelector_ .short 0, 0 .long 0 .quad 0 .Lmodule: .quad 8, 32, 0, .Lsymtab #if defined(OF_LINUX) || defined(OF_HAIKU) || defined(OF_HURD) .section .note.GNU-stack, "", %progbits #endif objfw-1.1.6/src/forwarding/forwarding-amd64-macho.S000066400000000000000000000110771465614216400220620ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" #ifdef HAVE_CET_H # include #else # define _CET_ENDBR #endif .globl _OFForward .globl _OFForward_stret .section __TEXT, __text, regular, pure_instructions _OFForward: _CET_ENDBR pushq %rbp movq %rsp, %rbp /* Save all arguments */ subq $0xC0, %rsp /* 16-byte alignment */ movq %rax, -0x8(%rbp) movq %rdi, -0x10(%rbp) movq %rsi, -0x18(%rbp) movq %rdx, -0x20(%rbp) movq %rcx, -0x28(%rbp) movq %r8, -0x30(%rbp) movq %r9, -0x38(%rbp) movaps %xmm0, -0x50(%rbp) movaps %xmm1, -0x60(%rbp) movaps %xmm2, -0x70(%rbp) movaps %xmm3, -0x80(%rbp) movaps %xmm4, -0x90(%rbp) movaps %xmm5, -0xA0(%rbp) movaps %xmm6, -0xB0(%rbp) movaps %xmm7, -0xC0(%rbp) call _object_getClass movq %rax, %rdi leaq Lsel_forwardingTargetForSelector_(%rip), %rsi call _class_respondsToSelector testq %rax, %rax jz 0f movq -0x10(%rbp), %rdi leaq Lsel_forwardingTargetForSelector_(%rip), %rsi call _objc_msg_lookup movq -0x10(%rbp), %rdi leaq Lsel_forwardingTargetForSelector_(%rip), %rsi movq -0x18(%rbp), %rdx call *%rax testq %rax, %rax jz 0f cmpq -0x10(%rbp), %rax je 0f movq %rax, -0x10(%rbp) movq %rax, %rdi movq -0x18(%rbp), %rsi call _objc_msg_lookup movq %rax, %r11 /* Restore all arguments */ movaps -0xC0(%rbp), %xmm7 movaps -0xB0(%rbp), %xmm6 movaps -0xA0(%rbp), %xmm5 movaps -0x90(%rbp), %xmm4 movaps -0x80(%rbp), %xmm3 movaps -0x70(%rbp), %xmm2 movaps -0x60(%rbp), %xmm1 movaps -0x50(%rbp), %xmm0 movq -0x38(%rbp), %r9 movq -0x30(%rbp), %r8 movq -0x28(%rbp), %rcx movq -0x20(%rbp), %rdx movq -0x18(%rbp), %rsi movq -0x10(%rbp), %rdi movq -0x8(%rbp), %rax movq %rbp, %rsp popq %rbp jmpq *%r11 0: movq -0x10(%rbp), %rdi movq -0x18(%rbp), %rsi movq %rbp, %rsp popq %rbp jmp _OFMethodNotFound _OFForward_stret: _CET_ENDBR pushq %rbp movq %rsp, %rbp /* Save all arguments */ subq $0xC0, %rsp /* 16-byte alignment */ movq %rax, -0x8(%rbp) movq %rdi, -0x10(%rbp) movq %rsi, -0x18(%rbp) movq %rdx, -0x20(%rbp) movq %rcx, -0x28(%rbp) movq %r8, -0x30(%rbp) movq %r9, -0x38(%rbp) movaps %xmm0, -0x50(%rbp) movaps %xmm1, -0x60(%rbp) movaps %xmm2, -0x70(%rbp) movaps %xmm3, -0x80(%rbp) movaps %xmm4, -0x90(%rbp) movaps %xmm5, -0xA0(%rbp) movaps %xmm6, -0xB0(%rbp) movaps %xmm7, -0xC0(%rbp) movq %rsi, %rdi call _object_getClass movq %rax, %rdi leaq Lsel_forwardingTargetForSelector_(%rip), %rsi call _class_respondsToSelector testq %rax, %rax jz 0f movq -0x18(%rbp), %rdi leaq Lsel_forwardingTargetForSelector_(%rip), %rsi call _objc_msg_lookup movq -0x18(%rbp), %rdi leaq Lsel_forwardingTargetForSelector_(%rip), %rsi movq -0x20(%rbp), %rdx call *%rax testq %rax, %rax jz 0f cmpq -0x18(%rbp), %rax je 0f movq %rax, -0x18(%rbp) movq %rax, %rdi movq -0x20(%rbp), %rsi call _objc_msg_lookup_stret movq %rax, %r11 /* Restore all arguments */ movaps -0xC0(%rbp), %xmm7 movaps -0xB0(%rbp), %xmm6 movaps -0xA0(%rbp), %xmm5 movaps -0x90(%rbp), %xmm4 movaps -0x80(%rbp), %xmm3 movaps -0x70(%rbp), %xmm2 movaps -0x60(%rbp), %xmm1 movaps -0x50(%rbp), %xmm0 movq -0x38(%rbp), %r9 movq -0x30(%rbp), %r8 movq -0x28(%rbp), %rcx movq -0x20(%rbp), %rdx movq -0x18(%rbp), %rsi movq -0x10(%rbp), %rdi movq -0x8(%rbp), %rax movq %rbp, %rsp popq %rbp jmpq *%r11 0: movq -0x10(%rbp), %rdi movq -0x18(%rbp), %rsi movq -0x20(%rbp), %rdx movq %rbp, %rsp popq %rbp jmp _OFMethodNotFound_stret Linit: _CET_ENDBR leaq Lmodule(%rip), %rdi jmp ___objc_exec_class .section __DATA, __mod_init_func, mod_init_funcs .quad Linit .section __TEXT, __cstring, cstring_literals Lstr_forwardingTargetForSelector_: .asciz "forwardingTargetForSelector:" .section __DATA, __data Lsel_forwardingTargetForSelector_: .quad Lstr_forwardingTargetForSelector_, 0 .quad 0, 0 Lsymtab: .quad 0, Lsel_forwardingTargetForSelector_ .short 0, 0 .long 0 .quad 0 Lmodule: .quad 8, 32, 0, Lsymtab objfw-1.1.6/src/forwarding/forwarding-amd64-win64.S000066400000000000000000000076661465614216400217530ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #ifdef HAVE_CET_H # include #else # define _CET_ENDBR #endif .globl OFForward .globl OFForward_stret .section .text OFForward: _CET_ENDBR pushq %rbp movq %rsp, %rbp /* Save all arguments */ subq $0x90, %rsp /* 16-byte alignment */ movq %rax, -0x28(%rbp) movq %rcx, -0x30(%rbp) movq %rdx, -0x38(%rbp) movq %r8, -0x40(%rbp) movq %r9, -0x48(%rbp) movaps %xmm0, -0x60(%rbp) movaps %xmm1, -0x70(%rbp) movaps %xmm2, -0x80(%rbp) movaps %xmm3, -0x90(%rbp) call object_getClass movq %rax, %rcx leaq .Lsel_forwardingTargetForSelector_(%rip), %rdx call class_respondsToSelector testq %rax, %rax jz 0f movq -0x30(%rbp), %rcx leaq .Lsel_forwardingTargetForSelector_(%rip), %rdx call objc_msg_lookup movq -0x30(%rbp), %rcx leaq .Lsel_forwardingTargetForSelector_(%rip), %rdx movq -0x38(%rbp), %r8 call *%rax testq %rax, %rax jz 0f cmpq -0x30(%rbp), %rax je 0f movq %rax, -0x30(%rbp) movq %rax, %rcx movq -0x38(%rbp), %rdx call objc_msg_lookup movq %rax, %r11 /* Restore all arguments */ movaps -0x90(%rbp), %xmm3 movaps -0x80(%rbp), %xmm2 movaps -0x70(%rbp), %xmm1 movaps -0x60(%rbp), %xmm0 movq -0x48(%rbp), %r9 movq -0x40(%rbp), %r8 movq -0x38(%rbp), %rdx movq -0x30(%rbp), %rcx movq -0x28(%rbp), %rax movq %rbp, %rsp popq %rbp jmpq *%r11 0: movq -0x30(%rbp), %rcx movq -0x38(%rbp), %rdx movq %rbp, %rsp popq %rbp jmp OFMethodNotFound .def OFForward .scl 2 .type 32 .endef OFForward_stret: _CET_ENDBR pushq %rbp movq %rsp, %rbp /* Save all arguments */ subq $0x90, %rsp /* 16-byte alignment */ movq %rax, -0x28(%rbp) movq %rcx, -0x30(%rbp) movq %rdx, -0x38(%rbp) movq %r8, -0x40(%rbp) movq %r9, -0x48(%rbp) movaps %xmm0, -0x60(%rbp) movaps %xmm1, -0x70(%rbp) movaps %xmm2, -0x80(%rbp) movaps %xmm3, -0x90(%rbp) movq %rdx, %rcx call object_getClass movq %rax, %rcx leaq .Lsel_forwardingTargetForSelector_(%rip), %rdx call class_respondsToSelector testq %rax, %rax jz 0f movq -0x38(%rbp), %rcx leaq .Lsel_forwardingTargetForSelector_(%rip), %rdx call objc_msg_lookup movq -0x38(%rbp), %rcx leaq .Lsel_forwardingTargetForSelector_(%rip), %rdx movq -0x40(%rbp), %r8 call *%rax testq %rax, %rax jz 0f cmpq -0x38(%rbp), %rax je 0f movq %rax, -0x38(%rbp) movq %rax, %rcx movq -0x40(%rbp), %rdx call objc_msg_lookup_stret movq %rax, %r11 /* Restore all arguments */ movaps -0x90(%rbp), %xmm3 movaps -0x80(%rbp), %xmm2 movaps -0x70(%rbp), %xmm1 movaps -0x60(%rbp), %xmm0 movq -0x48(%rbp), %r9 movq -0x40(%rbp), %r8 movq -0x38(%rbp), %rdx movq -0x30(%rbp), %rcx movq -0x28(%rbp), %rax movq %rbp, %rsp popq %rbp jmpq *%r11 0: movq -0x30(%rbp), %rcx movq -0x38(%rbp), %rdx movq -0x40(%rbp), %r8 movq %rbp, %rsp popq %rbp jmp OFMethodNotFound_stret .def OFForward_stret .scl 2 .type 32 .endef .Linit: _CET_ENDBR leaq .Lmodule(%rip), %rcx jmp __objc_exec_class .section .ctors, "aw" .quad .Linit .section .rodata .Lstr_forwardingTargetForSelector_: .asciz "forwardingTargetForSelector:" .section .data .Lsel_forwardingTargetForSelector_: .quad .Lstr_forwardingTargetForSelector_, 0 .quad 0, 0 .Lsymtab: .long 0, 0 .quad .Lsel_forwardingTargetForSelector_ .short 0, 0 .long 0 .quad 0 .Lmodule: .long 8, 32 .quad 0, .Lsymtab objfw-1.1.6/src/forwarding/forwarding-arm-elf.S000066400000000000000000000063661465614216400214120ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" #ifdef HAVE_VFP2 .fpu vfp #endif .globl OFForward .globl OFForward_stret .section .text OFForward: #ifdef HAVE_VFP2 vstmdb sp!, {d0-d7} #endif stmfd sp!, {r0-r4, lr} ldr r4, .Lsel_forwardingTargetForSelector_$indirect_.L0 .L0: add r4, pc bl object_getClass(PLT) mov r1, r4 bl class_respondsToSelector(PLT) cmp r0, #0 beq 0f ldr r0, [sp, #0] mov r1, r4 bl objc_msg_lookup(PLT) mov r12, r0 ldr r0, [sp, #0] mov r1, r4 ldr r2, [sp, #4] #ifdef HAVE_BLX blx r12 #else mov lr, pc bx r12 #endif cmp r0, #0 beq 0f ldr r1, [sp, #0] cmp r0, r1 beq 0f str r0, [sp, #0] ldr r1, [sp, #4] bl objc_msg_lookup(PLT) mov r12, r0 ldmfd sp!, {r0-r4, lr} #ifdef HAVE_VFP2 vldmia sp!, {d0-d7} #endif bx r12 0: ldmfd sp!, {r0-r4, lr} #ifdef HAVE_VFP2 vldmia sp!, {d0-d7} #endif b OFMethodNotFound(PLT) .type OFForward, %function .size OFForward, .-OFForward OFForward_stret: #ifdef HAVE_VFP2 vstmdb sp!, {d0-d7} #endif stmfd sp!, {r0-r4, lr} ldr r4, .Lsel_forwardingTargetForSelector_$indirect_.L1 .L1: add r4, pc mov r0, r1 bl object_getClass(PLT) mov r1, r4 bl class_respondsToSelector(PLT) cmp r0, #0 beq 0f ldr r0, [sp, #4] mov r1, r4 bl objc_msg_lookup(PLT) mov r12, r0 ldr r0, [sp, #4] mov r1, r4 ldr r2, [sp, #8] #ifdef HAVE_BLX blx r12 #else mov lr, pc bx r12 #endif cmp r0, #0 beq 0f ldr r1, [sp, #4] cmp r0, r1 beq 0f str r0, [sp, #4] ldr r1, [sp, #8] bl objc_msg_lookup_stret(PLT) mov r12, r0 ldmfd sp!, {r0-r4, lr} #ifdef HAVE_VFP2 vldmia sp!, {d0-d7} #endif bx r12 0: ldmfd sp!, {r0-r4, lr} #ifdef HAVE_VFP2 vldmia sp!, {d0-d7} #endif b OFMethodNotFound_stret(PLT) .type OFForward_stret, %function .size OFForward_stret, .-OFForward_stret .Linit: ldr r0, .Lmodule$indirect_.L2 .L2: add r0, pc b __objc_exec_class(PLT) .Lsel_forwardingTargetForSelector_$indirect_.L0: .long .Lsel_forwardingTargetForSelector_-(.L0+8) .Lsel_forwardingTargetForSelector_$indirect_.L1: .long .Lsel_forwardingTargetForSelector_-(.L1+8) .Lmodule$indirect_.L2: .long .Lmodule-(.L2+8) .section .init_array, "aw", %init_array .long .Linit .section .rodata .Lstr_forwardingTargetForSelector_: .asciz "forwardingTargetForSelector:" .section .data .Lsel_forwardingTargetForSelector_: .long .Lstr_forwardingTargetForSelector_, 0 .long 0, 0 .Lsymtab: .long 0, .Lsel_forwardingTargetForSelector_ .short 0, 0 .long 0 .long 0 .Lmodule: .long 8, 16, 0, .Lsymtab #if defined(OF_LINUX) || defined(OF_HAIKU) || defined(OF_HURD) .section .note.GNU-stack, "", %progbits #endif objfw-1.1.6/src/forwarding/forwarding-arm64-elf.S000066400000000000000000000053711465614216400215570ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" .globl OFForward .globl OFForward_stret .section .text OFForward: OFForward_stret: #ifdef HAVE_BTI bti c #endif stp fp, lr, [sp, #-224]! mov fp, sp /* Save all arguments, x8 and x19 */ stp x0, x1, [sp, #16] stp x2, x3, [sp, #32] stp x4, x5, [sp, #48] stp x6, x7, [sp, #64] stp x8, x19, [sp, #80] /* Save all foating point arguments */ stp q0, q1, [sp, #96] stp q2, q3, [sp, #128] stp q4, q5, [sp, #160] stp q6, q7, [sp, #192] bl object_getClass adrp x19, .Lsel_forwardingTargetForSelector_ add x19, x19, :lo12:.Lsel_forwardingTargetForSelector_ mov x1, x19 bl class_respondsToSelector cbz x0, 0f ldr x0, [sp, #16] mov x1, x19 bl objc_msg_lookup mov x1, x19 mov x19, x0 ldp x0, x2, [sp, #16] blr x19 cbz x0, 0f ldr x1, [sp, #16] cmp x0, x1 b.eq 0f mov x19, x0 ldr x1, [sp, #24] bl objc_msg_lookup mov x16, x0 mov x0, x19 /* Restore all arguments, x8 and x19, but not x0 */ ldr x1, [sp, #24] ldp x2, x3, [sp, #32] ldp x4, x5, [sp, #48] ldp x6, x7, [sp, #64] ldp x8, x19, [sp, #80] /* Restore all foating point arguments */ ldp q0, q1, [sp, #96] ldp q2, q3, [sp, #128] ldp q4, q5, [sp, #160] ldp q6, q7, [sp, #192] ldp fp, lr, [sp], #224 br x16 0: ldp x0, x1, [sp, #16] ldr x19, [sp, #88] ldp fp, lr, [sp], #224 b OFMethodNotFound .type OFForward, %function .size OFForward, .-OFForward .type OFForward_stret, %function .size OFForward_stret, .-OFForward_stret .Linit: #ifdef HAVE_BTI bti c #endif adrp x0, .Lmodule add x0, x0, :lo12:.Lmodule b __objc_exec_class .section .init_array, "aw", %init_array .xword .Linit .section .rodata .Lstr_forwardingTargetForSelector_: .asciz "forwardingTargetForSelector:" .section .data .Lsel_forwardingTargetForSelector_: .xword .Lstr_forwardingTargetForSelector_, 0 .xword 0, 0 .Lsymtab: .xword 0, .Lsel_forwardingTargetForSelector_ .short 0, 0 .long 4 .xword 0 .Lmodule: .xword 8, 32, 0, .Lsymtab #if defined(OF_LINUX) || defined(OF_HAIKU) || defined(OF_HURD) .section .note.GNU-stack, "", %progbits #endif objfw-1.1.6/src/forwarding/forwarding-mips-elf.S000066400000000000000000000140131465614216400215670ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" .globl OFForward .globl OFForward_stret #ifdef OF_PIC .macro j_pic symbol lw $t9, %call16(\symbol)($gp) jr $t9 .endm .macro jal_pic symbol lw $t9, %call16(\symbol)($gp) jalr $t9 .endm #else .macro j_pic symbol j \symbol .endm .macro jal_pic symbol jal \symbol .endm #endif .section .text OFForward: #ifdef OF_PIC lui $gp, %hi(_gp_disp) addiu $gp, $gp, %lo(_gp_disp) addu $gp, $gp, $t9 #endif addiu $sp, $sp, -96 /* * O32: The registers for floating point arguments don't need to be * saved, as the ABI specifies that all remaining arguments are passed * in integer registers if the first argument is passed in an integer * register. This is always the case, as the first argument is always * self. */ sw $ra, 16($sp) sw $s0, 20($sp) sw $s1, 24($sp) sw $a0, 28($sp) sw $a1, 32($sp) sw $a2, 36($sp) sw $a3, 40($sp) #ifdef OF_MIPS_EABI /* For some reason, $a4-$a7 are not always defined */ sw $8, 44($sp) sw $9, 48($sp) sw $10, 52($sp) sw $11, 56($sp) swc1 $f12, 60($sp) swc1 $f13, 64($sp) swc1 $f14, 68($sp) swc1 $f15, 72($sp) swc1 $f16, 76($sp) swc1 $f17, 80($sp) swc1 $f18, 84($sp) swc1 $f19, 88($sp) #endif move $s0, $gp #ifdef OF_PIC lw $s1, %got(.Lsel_forwardingTargetForSelector_)($gp) #else lui $s1, %hi(.Lsel_forwardingTargetForSelector_) #endif addiu $s1, $s1, %lo(.Lsel_forwardingTargetForSelector_) jal_pic object_getClass move $gp, $s0 move $a0, $v0 move $a1, $s1 jal_pic class_respondsToSelector beqz $v0, 0f move $gp, $s0 lw $a0, 28($sp) move $a1, $s1 jal_pic objc_msg_lookup move $gp, $s0 lw $a0, 28($sp) move $a1, $s1 lw $a2, 32($sp) move $t9, $v0 jalr $t9 beqz $v0, 0f lw $t0, 28($sp) beq $v0, $t0, 0f sw $v0, 28($sp) move $gp, $s0 move $a0, $v0 lw $a1, 32($sp) jal_pic objc_msg_lookup #ifdef OF_MIPS_EABI lwc1 $f19, 88($sp) lwc1 $f18, 84($sp) lwc1 $f17, 80($sp) lwc1 $f16, 76($sp) lwc1 $f15, 72($sp) lwc1 $f14, 68($sp) lwc1 $f13, 64($sp) lwc1 $f12, 60($sp) lw $11, 56($sp) lw $10, 52($sp) lw $9, 48($sp) lw $8, 44($sp) #endif lw $a3, 40($sp) lw $a2, 36($sp) lw $a1, 32($sp) lw $a0, 28($sp) lw $s1, 24($sp) lw $s0, 20($sp) lw $ra, 16($sp) addiu $sp, $sp, 96 move $t9, $v0 jr $t9 0: move $gp, $s0 lw $a1, 32($sp) lw $a0, 28($sp) lw $s1, 24($sp) lw $s0, 20($sp) lw $ra, 16($sp) addiu $sp, $sp, 96 j_pic OFMethodNotFound .type OFForward, %function .size OFForward, .-OFForward OFForward_stret: #ifdef OF_PIC lui $gp, %hi(_gp_disp) addiu $gp, $gp, %lo(_gp_disp) addu $gp, $gp, $t9 #endif addiu $sp, $sp, -96 /* * O32: The registers for floating point arguments don't need to be * saved, as the ABI specifies that all remaining arguments are passed * in integer registers if the first argument is passed in an integer * register. This is always the case, as the first argument is always * self. */ sw $ra, 16($sp) sw $s0, 20($sp) sw $s1, 24($sp) sw $a0, 28($sp) sw $a1, 32($sp) sw $a2, 36($sp) sw $a3, 40($sp) #ifdef OF_MIPS_EABI /* For some reason, $a4-$a8 are not always defined */ sw $8, 44($sp) sw $9, 48($sp) sw $10, 52($sp) sw $11, 56($sp) swc1 $f12, 60($sp) swc1 $f13, 64($sp) swc1 $f14, 68($sp) swc1 $f15, 72($sp) swc1 $f16, 76($sp) swc1 $f17, 80($sp) swc1 $f18, 84($sp) swc1 $f19, 88($sp) #endif move $s0, $gp #ifdef OF_PIC lw $s1, %got(.Lsel_forwardingTargetForSelector_)($gp) #else lui $s1, %hi(.Lsel_forwardingTargetForSelector_) #endif addiu $s1, $s1, %lo(.Lsel_forwardingTargetForSelector_) move $a0, $a1 jal_pic object_getClass move $gp, $s0 move $a0, $v0 move $a1, $s1 jal_pic class_respondsToSelector beqz $v0, 0f move $gp, $s0 lw $a0, 32($sp) move $a1, $s1 jal_pic objc_msg_lookup move $gp, $s0 lw $a0, 32($sp) move $a1, $s1 lw $a2, 36($sp) move $t9, $v0 jalr $t9 beqz $v0, 0f lw $t0, 32($sp) beq $v0, $t0, 0f sw $v0, 32($sp) move $gp, $s0 move $a0, $v0 lw $a1, 36($sp) jal_pic objc_msg_lookup_stret #ifdef OF_MIPS_EABI lwc1 $f19, 88($sp) lwc1 $f18, 84($sp) lwc1 $f17, 80($sp) lwc1 $f16, 76($sp) lwc1 $f15, 72($sp) lwc1 $f14, 68($sp) lwc1 $f13, 64($sp) lwc1 $f12, 60($sp) lw $11, 56($sp) lw $10, 52($sp) lw $9, 48($sp) lw $8, 44($sp) #endif lw $a3, 40($sp) lw $a2, 36($sp) lw $a1, 32($sp) lw $a0, 28($sp) lw $s1, 24($sp) lw $s0, 20($sp) lw $ra, 16($sp) addiu $sp, $sp, 96 move $t9, $v0 jr $t9 0: move $gp, $s0 lw $a2, 36($sp) lw $a1, 32($sp) lw $a0, 28($sp) lw $s1, 24($sp) lw $s0, 20($sp) lw $ra, 16($sp) addiu $sp, $sp, 96 j_pic OFMethodNotFound_stret .type OFForward_stret, %function .size OFForward_stret, .-OFForward_stret .Linit: #ifdef OF_PIC lui $gp, %hi(_gp_disp) addiu $gp, $gp, %lo(_gp_disp) addu $gp, $gp, $t9 lw $a0, %got(.Lmodule)($gp) addiu $a0, $a0, %lo(.Lmodule) lw $t9, %call16(__objc_exec_class)($gp) jr $t9 #else lui $a0, %hi(.Lmodule) addiu $a0, $a0, %lo(.Lmodule) j __objc_exec_class #endif .section .ctors, "aw", %progbits .long .Linit .section .rodata .Lstr_forwardingTargetForSelector_: .asciz "forwardingTargetForSelector:" .section .data .Lsel_forwardingTargetForSelector_: .long .Lstr_forwardingTargetForSelector_, 0 .long 0, 0 .Lsymtab: .long 0, .Lsel_forwardingTargetForSelector_ .short 0, 0 .long 0 .long 0 .Lmodule: .long 8, 16, 0, .Lsymtab #if defined(OF_LINUX) || defined(OF_HAIKU) || defined(OF_HURD) .section .note.GNU-stack, "", %progbits #endif objfw-1.1.6/src/forwarding/forwarding-powerpc-elf.S000066400000000000000000000153111465614216400223000ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" .globl OFForward .globl OFForward_stret .section .text OFForward: stwu %r1, -112(%r1) mflr %r0 stw %r0, 116(%r1) #ifdef OF_PIC stw %r30, 104(%r1) bl 0f 0: mflr %r30 addis %r30, %r30, .Lbiased_got2-0b@ha addi %r30, %r30, .Lbiased_got2-0b@l #endif /* Save all arguments */ stw %r3, 8(%r1) stw %r4, 12(%r1) stw %r5, 16(%r1) stw %r6, 20(%r1) stw %r7, 24(%r1) stw %r8, 28(%r1) stw %r9, 32(%r1) stw %r10, 36(%r1) /* Save all floating point arguments */ stfd %f1, 40(%r1) stfd %f2, 48(%r1) stfd %f3, 56(%r1) stfd %f4, 64(%r1) stfd %f5, 72(%r1) stfd %f6, 80(%r1) stfd %f7, 88(%r1) stfd %f8, 96(%r1) #ifdef OF_PIC bl object_getClass+0x8000@plt lwz %r4, .Lgot_sel_forwardingTargetForSelector_-.Lbiased_got2(%r30) bl class_respondsToSelector+0x8000@plt #else bl object_getClass lis %r4, .Lsel_forwardingTargetForSelector_@ha la %r4, .Lsel_forwardingTargetForSelector_@l(%r4) bl class_respondsToSelector #endif cmpwi %r3, 0 beq- 0f lwz %r3, 8(%r1) #ifdef OF_PIC lwz %r4, .Lgot_sel_forwardingTargetForSelector_-.Lbiased_got2(%r30) bl objc_msg_lookup+0x8000@plt #else lis %r4, .Lsel_forwardingTargetForSelector_@ha la %r4, .Lsel_forwardingTargetForSelector_@l(%r4) bl objc_msg_lookup #endif mtctr %r3 lwz %r3, 8(%r1) #ifdef OF_PIC lwz %r4, .Lgot_sel_forwardingTargetForSelector_-.Lbiased_got2(%r30) #else lis %r4, .Lsel_forwardingTargetForSelector_@ha la %r4, .Lsel_forwardingTargetForSelector_@l(%r4) #endif lwz %r5, 12(%r1) bctrl cmpwi %r3, 0 beq- 0f lwz %r4, 8(%r1) cmpw %r3, %r4 beq- 0f stw %r3, 8(%r1) lwz %r4, 12(%r1) #ifdef OF_PIC bl objc_msg_lookup+0x8000@plt #else bl objc_msg_lookup #endif mtctr %r3 /* Restore all arguments */ lwz %r3, 8(%r1) lwz %r4, 12(%r1) lwz %r5, 16(%r1) lwz %r6, 20(%r1) lwz %r7, 24(%r1) lwz %r8, 28(%r1) lwz %r9, 32(%r1) lwz %r10, 36(%r1) /* Restore all floating point arguments */ lfd %f1, 40(%r1) lfd %f2, 48(%r1) lfd %f3, 56(%r1) lfd %f4, 64(%r1) lfd %f5, 72(%r1) lfd %f6, 80(%r1) lfd %f7, 88(%r1) lfd %f8, 96(%r1) #ifdef OF_PIC lwz %r30, 104(%r1) #endif lwz %r0, 116(%r1) mtlr %r0 addi %r1, %r1, 112 bctr 0: lwz %r3, 8(%r1) lwz %r4, 12(%r1) #ifdef OF_PIC lwz %r0, .Lgot_OFMethodNotFound-.Lbiased_got2(%r30) mtctr %r0 lwz %r30, 104(%r1) #endif lwz %r0, 116(%r1) mtlr %r0 addi %r1, %r1, 112 #ifdef OF_PIC bctr #else b OFMethodNotFound #endif .type OFForward, @function .size OFForward, .-OFForward OFForward_stret: stwu %r1, -112(%r1) mflr %r0 stw %r0, 116(%r1) #ifdef OF_PIC stw %r30, 104(%r1) bl 0f 0: mflr %r30 addis %r30, %r30, .Lbiased_got2-0b@ha addi %r30, %r30, .Lbiased_got2-0b@l #endif /* Save all arguments */ stw %r3, 8(%r1) stw %r4, 12(%r1) stw %r5, 16(%r1) stw %r6, 20(%r1) stw %r7, 24(%r1) stw %r8, 28(%r1) stw %r9, 32(%r1) stw %r10, 36(%r1) /* Save all floating point arguments */ stfd %f1, 40(%r1) stfd %f2, 48(%r1) stfd %f3, 56(%r1) stfd %f4, 64(%r1) stfd %f5, 72(%r1) stfd %f6, 80(%r1) stfd %f7, 88(%r1) stfd %f8, 96(%r1) mr %r3, %r4 #ifdef OF_PIC bl object_getClass+0x8000@plt lwz %r4, .Lgot_sel_forwardingTargetForSelector_-.Lbiased_got2(%r30) bl class_respondsToSelector+0x8000@plt #else bl object_getClass lis %r4, .Lsel_forwardingTargetForSelector_@ha la %r4, .Lsel_forwardingTargetForSelector_@l(%r4) bl class_respondsToSelector #endif cmpwi %r3, 0 beq- 0f lwz %r3, 12(%r1) #ifdef OF_PIC lwz %r4, .Lgot_sel_forwardingTargetForSelector_-.Lbiased_got2(%r30) bl objc_msg_lookup+0x8000@plt #else lis %r4, .Lsel_forwardingTargetForSelector_@ha la %r4, .Lsel_forwardingTargetForSelector_@l(%r4) bl objc_msg_lookup #endif mtctr %r3 lwz %r3, 12(%r1) #ifdef OF_PIC lwz %r4, .Lgot_sel_forwardingTargetForSelector_-.Lbiased_got2(%r30) #else lis %r4, .Lsel_forwardingTargetForSelector_@ha la %r4, .Lsel_forwardingTargetForSelector_@l(%r4) #endif lwz %r5, 16(%r1) bctrl cmpwi %r3, 0 beq- 0f lwz %r4, 12(%r1) cmpw %r3, %r4 beq- 0f stw %r3, 12(%r1) lwz %r4, 16(%r1) #ifdef OF_PIC bl objc_msg_lookup_stret+0x8000@plt #else bl objc_msg_lookup_stret #endif mtctr %r3 /* Restore all arguments */ lwz %r3, 8(%r1) lwz %r4, 12(%r1) lwz %r5, 16(%r1) lwz %r6, 20(%r1) lwz %r7, 24(%r1) lwz %r8, 28(%r1) lwz %r9, 32(%r1) lwz %r10, 36(%r1) /* Restore all floating point arguments */ lfd %f1, 40(%r1) lfd %f2, 48(%r1) lfd %f3, 56(%r1) lfd %f4, 64(%r1) lfd %f5, 72(%r1) lfd %f6, 80(%r1) lfd %f7, 88(%r1) lfd %f8, 96(%r1) #ifdef OF_PIC lwz %r30, 104(%r1) #endif lwz %r0, 116(%r1) mtlr %r0 addi %r1, %r1, 112 bctr 0: lwz %r3, 8(%r1) lwz %r4, 12(%r1) lwz %r5, 16(%r1) #ifdef OF_PIC lwz %r0, .Lgot_OFMethodNotFound_stret-.Lbiased_got2(%r30) mtctr %r0 lwz %r30, 104(%r1) #endif lwz %r0, 116(%r1) mtlr %r0 addi %r1, %r1, 112 #ifdef OF_PIC bctr #else b OFMethodNotFound_stret #endif .type OFForward_stret, @function .size OFForward_stret, .-OFForward_stret .Linit: stwu %r1, -16(%r1) mflr %r0 stw %r0, 20(%r1) #ifdef OF_PIC stw %r30, 8(%r1) bl 0f 0: mflr %r30 addis %r30, %r30, .Lbiased_got2-0b@ha addi %r30, %r30, .Lbiased_got2-0b@l lwz %r3, .Lgot_module-.Lbiased_got2(%r30) bl __objc_exec_class+0x8000@plt lwz %r30, 8(%r1) #else lis %r3, .Lmodule@ha la %r3, .Lmodule@l(%r3) bl __objc_exec_class #endif lwz %r0, 20(%r1) addi %r1, %r1, 16 mtlr %r0 blr .section .ctors, "aw", @progbits .long .Linit .section .rodata .Lstr_forwardingTargetForSelector_: .asciz "forwardingTargetForSelector:" .section .data .Lsel_forwardingTargetForSelector_: .long .Lstr_forwardingTargetForSelector_, 0 .long 0, 0 .Lsymtab: .long 0, .Lsel_forwardingTargetForSelector_ .short 0, 0 .long 0 .long 0 .Lmodule: .long 8, 16, 0, .Lsymtab #ifdef OF_PIC .section .got2, "aw" .Lbiased_got2 = .+0x8000 .Lgot_module: .long .Lmodule .Lgot_sel_forwardingTargetForSelector_: .long .Lsel_forwardingTargetForSelector_ .Lgot_OFMethodNotFound: .long OFMethodNotFound .Lgot_OFMethodNotFound_stret: .long OFMethodNotFound_stret #endif #if defined(OF_LINUX) || defined(OF_HAIKU) || defined(OF_HURD) .section .note.GNU-stack, "", @progbits #endif objfw-1.1.6/src/forwarding/forwarding-sparc-elf.S000066400000000000000000000073141465614216400217350ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" .globl OFForward .globl OFForward_stret .section .text OFForward: save %sp, -96, %sp #ifdef OF_PIC sethi %hi(_GLOBAL_OFFSET_TABLE_ - 4), %l7 call add_pc add %l7, %lo(_GLOBAL_OFFSET_TABLE_ + 4), %l7 #endif mov %i0, %o0 call object_getClass nop sethi %hi(.Lsel_forwardingTargetForSelector_), %o1 or %o1, %lo(.Lsel_forwardingTargetForSelector_), %o1 #ifdef OF_PIC ld [%l7 + %o1], %o1 #endif call class_respondsToSelector nop cmp %o0, 0 be 0f mov %i0, %o0 sethi %hi(.Lsel_forwardingTargetForSelector_), %o1 or %o1, %lo(.Lsel_forwardingTargetForSelector_), %o1 #ifdef OF_PIC ld [%l7 + %o1], %o1 #endif call objc_msg_lookup nop mov %o0, %l0 mov %i0, %o0 sethi %hi(.Lsel_forwardingTargetForSelector_), %o1 or %o1, %lo(.Lsel_forwardingTargetForSelector_), %o1 #ifdef OF_PIC ld [%l7 + %o1], %o1 #endif jmpl %l0, %o7 mov %i1, %o2 cmp %o0, 0 be 0f cmp %o0, %i0 be 0f mov %o0, %i0 call objc_msg_lookup mov %i1, %o1 jmpl %o0, %g0 restore 0: call OFMethodNotFound restore .type OFForward, %function .size OFForward, .-OFForward OFForward_stret: save %sp, -96, %sp #ifdef OF_PIC sethi %hi(_GLOBAL_OFFSET_TABLE_ - 4), %l7 call add_pc add %l7, %lo(_GLOBAL_OFFSET_TABLE_ + 4), %l7 #endif mov %i1, %o0 call object_getClass nop sethi %hi(.Lsel_forwardingTargetForSelector_), %o1 or %o1, %lo(.Lsel_forwardingTargetForSelector_), %o1 #ifdef OF_PIC ld [%l7 + %o1], %o1 #endif call class_respondsToSelector nop cmp %o0, 0 be 0f mov %i1, %o0 sethi %hi(.Lsel_forwardingTargetForSelector_), %o1 or %o1, %lo(.Lsel_forwardingTargetForSelector_), %o1 #ifdef OF_PIC ld [%l7 + %o1], %o1 #endif call objc_msg_lookup nop mov %o0, %l0 mov %i1, %o0 sethi %hi(.Lsel_forwardingTargetForSelector_), %o1 or %o1, %lo(.Lsel_forwardingTargetForSelector_), %o1 #ifdef OF_PIC ld [%l7 + %o1], %o1 #endif jmpl %l0, %o7 mov %i2, %o2 cmp %o0, 0 be 0f cmp %o0, %i1 be 0f mov %o0, %i1 call objc_msg_lookup mov %i2, %o1 jmpl %o0, %g0 restore 0: call OFMethodNotFound_stret restore .type OFForward_stret, %function .size OFForward_stret, .-OFForward_stret .Linit: save %sp, -96, %sp #ifdef OF_PIC sethi %hi(_GLOBAL_OFFSET_TABLE_ - 4), %l7 call add_pc add %l7, %lo(_GLOBAL_OFFSET_TABLE_ + 4), %l7 #endif sethi %hi(.Lmodule), %i0 or %i0, %lo(.Lmodule), %i0 #ifdef OF_PIC ld [%l7 + %i0], %i0 #endif call __objc_exec_class restore #ifdef OF_PIC add_pc: jmp %o7 + 8 add %l7, %o7, %l7 #endif #ifdef OF_SOLARIS .section .init_array, "aw" #else .section .ctors, "aw", %progbits #endif .word .Linit .section .rodata .Lstr_forwardingTargetForSelector_: .asciz "forwardingTargetForSelector:" .section .data .Lsel_forwardingTargetForSelector_: .word .Lstr_forwardingTargetForSelector_, 0 .word 0, 0 .Lsymtab: .word 0, .Lsel_forwardingTargetForSelector_ .half 0, 0 .word 0 .word 0 .Lmodule: .word 8, 16, 0, .Lsymtab #if defined(OF_LINUX) || defined(OF_HAIKU) || defined(OF_HURD) .section .note.GNU-stack, "", %progbits #endif objfw-1.1.6/src/forwarding/forwarding-sparc64-elf.S000066400000000000000000000134001465614216400221000ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" .globl OFForward .globl OFForward_stret #define BIAS 2047 .section .text OFForward: save %sp, -304, %sp /* * Save all floating point registers as they can be used for parameter * passing. */ std %f0, [%sp + BIAS + 176] std %f2, [%sp + BIAS + 184] std %f4, [%sp + BIAS + 192] std %f6, [%sp + BIAS + 200] std %f8, [%sp + BIAS + 208] std %f10, [%sp + BIAS + 216] std %f12, [%sp + BIAS + 224] std %f14, [%sp + BIAS + 232] std %f16, [%sp + BIAS + 240] std %f18, [%sp + BIAS + 248] std %f20, [%sp + BIAS + 256] std %f22, [%sp + BIAS + 264] std %f24, [%sp + BIAS + 272] std %f26, [%sp + BIAS + 280] std %f28, [%sp + BIAS + 288] std %f30, [%sp + BIAS + 296] sethi %hi(_GLOBAL_OFFSET_TABLE_ - 4), %l7 call .LaddPC add %l7, %lo(_GLOBAL_OFFSET_TABLE_ + 4), %l7 mov %i0, %o0 call object_getClass nop sethi %hi(.Lsel_forwardingTargetForSelector_), %o1 or %o1, %lo(.Lsel_forwardingTargetForSelector_), %o1 ldx [%l7 + %o1], %o1 call class_respondsToSelector nop brz,pn %o0, 0f mov %i0, %o0 sethi %hi(.Lsel_forwardingTargetForSelector_), %o1 or %o1, %lo(.Lsel_forwardingTargetForSelector_), %o1 ldx [%l7 + %o1], %o1 call objc_msg_lookup nop mov %o0, %l0 mov %i0, %o0 sethi %hi(.Lsel_forwardingTargetForSelector_), %o1 or %o1, %lo(.Lsel_forwardingTargetForSelector_), %o1 ldx [%l7 + %o1], %o1 jmpl %l0, %o7 mov %i1, %o2 brz,pn %o0, 0f cmp %o0, %i0 be,pn %xcc, 0f mov %o0, %i0 call objc_msg_lookup mov %i1, %o1 /* * Restore all floating point registers as they can be used for * parameter passing. */ ldd [%sp + BIAS + 176], %f0 ldd [%sp + BIAS + 184], %f2 ldd [%sp + BIAS + 192], %f4 ldd [%sp + BIAS + 200], %f6 ldd [%sp + BIAS + 208], %f8 ldd [%sp + BIAS + 216], %f10 ldd [%sp + BIAS + 224], %f12 ldd [%sp + BIAS + 232], %f14 ldd [%sp + BIAS + 240], %f16 ldd [%sp + BIAS + 248], %f18 ldd [%sp + BIAS + 256], %f20 ldd [%sp + BIAS + 264], %f22 ldd [%sp + BIAS + 272], %f24 ldd [%sp + BIAS + 280], %f26 ldd [%sp + BIAS + 288], %f28 ldd [%sp + BIAS + 296], %f30 jmpl %o0, %g0 restore 0: call OFMethodNotFound restore .type OFForward, %function .size OFForward, .-OFForward OFForward_stret: save %sp, -304, %sp /* * Save all floating point registers as they can be used for parameter * passing. */ std %f0, [%sp + BIAS + 176] std %f2, [%sp + BIAS + 184] std %f4, [%sp + BIAS + 192] std %f6, [%sp + BIAS + 200] std %f8, [%sp + BIAS + 208] std %f10, [%sp + BIAS + 216] std %f12, [%sp + BIAS + 224] std %f14, [%sp + BIAS + 232] std %f16, [%sp + BIAS + 240] std %f18, [%sp + BIAS + 248] std %f20, [%sp + BIAS + 256] std %f22, [%sp + BIAS + 264] std %f24, [%sp + BIAS + 272] std %f26, [%sp + BIAS + 280] std %f28, [%sp + BIAS + 288] std %f30, [%sp + BIAS + 296] sethi %hi(_GLOBAL_OFFSET_TABLE_ - 4), %l7 call .LaddPC add %l7, %lo(_GLOBAL_OFFSET_TABLE_ + 4), %l7 mov %i1, %o0 call object_getClass nop sethi %hi(.Lsel_forwardingTargetForSelector_), %o1 or %o1, %lo(.Lsel_forwardingTargetForSelector_), %o1 ldx [%l7 + %o1], %o1 call class_respondsToSelector nop brz,pn %o0, 0f mov %i1, %o0 sethi %hi(.Lsel_forwardingTargetForSelector_), %o1 or %o1, %lo(.Lsel_forwardingTargetForSelector_), %o1 ldx [%l7 + %o1], %o1 call objc_msg_lookup nop mov %o0, %l0 mov %i1, %o0 sethi %hi(.Lsel_forwardingTargetForSelector_), %o1 or %o1, %lo(.Lsel_forwardingTargetForSelector_), %o1 ldx [%l7 + %o1], %o1 jmpl %l0, %o7 mov %i2, %o2 brz,pn %o0, 0f cmp %o0, %i1 be,pn %xcc, 0f mov %o0, %i1 call objc_msg_lookup mov %i2, %o1 /* * Restore all floating point registers as they can be used for * parameter passing. */ ldd [%sp + BIAS + 176], %f0 ldd [%sp + BIAS + 184], %f2 ldd [%sp + BIAS + 192], %f4 ldd [%sp + BIAS + 200], %f6 ldd [%sp + BIAS + 208], %f8 ldd [%sp + BIAS + 216], %f10 ldd [%sp + BIAS + 224], %f12 ldd [%sp + BIAS + 232], %f14 ldd [%sp + BIAS + 240], %f16 ldd [%sp + BIAS + 248], %f18 ldd [%sp + BIAS + 256], %f20 ldd [%sp + BIAS + 264], %f22 ldd [%sp + BIAS + 272], %f24 ldd [%sp + BIAS + 280], %f26 ldd [%sp + BIAS + 288], %f28 ldd [%sp + BIAS + 296], %f30 jmpl %o0, %g0 restore 0: call OFMethodNotFound_stret restore .type OFForward_stret, %function .size OFForward_stret, .-OFForward_stret .Linit: save %sp, -176, %sp sethi %hi(_GLOBAL_OFFSET_TABLE_ - 4), %l7 call .LaddPC add %l7, %lo(_GLOBAL_OFFSET_TABLE_ + 4), %l7 sethi %hi(.Lmodule), %i0 or %i0, %lo(.Lmodule), %i0 ldx [%l7 + %i0], %i0 call __objc_exec_class restore .LaddPC: jmp %o7 + 8 add %l7, %o7, %l7 #ifdef OF_SOLARIS .section .init_array, "aw" #else .section .ctors, "aw", %progbits #endif .xword .Linit .section .rodata .Lstr_forwardingTargetForSelector_: .asciz "forwardingTargetForSelector:" .section .data .Lsel_forwardingTargetForSelector_: .xword .Lstr_forwardingTargetForSelector_, 0 .xword 0, 0 .Lsymtab: .xword 0, .Lsel_forwardingTargetForSelector_ .half 0, 0 .word 0 .xword 0 .Lmodule: .xword 8, 32, 0, .Lsymtab #if defined(OF_LINUX) || defined(OF_HAIKU) || defined(OF_HURD) .section .note.GNU-stack, "", %progbits #endif objfw-1.1.6/src/forwarding/forwarding-x86-elf.S000066400000000000000000000074171465614216400212560ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" #ifdef HAVE_CET_H # include #else # define _CET_ENDBR #endif .globl OFForward .globl OFForward_stret .section .text OFForward: _CET_ENDBR pushl %ebp movl %esp, %ebp pushl %ebx subl $20, %esp call .LgetEIP addl $_GLOBAL_OFFSET_TABLE_, %ebx movl 8(%ebp), %eax movl %eax, (%esp) call object_getClass@PLT movl %eax, (%esp) leal .Lsel_forwardingTargetForSelector_@GOTOFF(%ebx), %eax movl %eax, 4(%esp) call class_respondsToSelector@PLT testl %eax, %eax jz 0f movl 8(%ebp), %eax movl %eax, (%esp) leal .Lsel_forwardingTargetForSelector_@GOTOFF(%ebx), %eax movl %eax, 4(%esp) call objc_msg_lookup@PLT movl 8(%ebp), %edx movl %edx, (%esp) leal .Lsel_forwardingTargetForSelector_@GOTOFF(%ebx), %edx movl %edx, 4(%esp) movl 12(%ebp), %edx movl %edx, 8(%esp) call *%eax testl %eax, %eax jz 0f cmpl 8(%ebp), %eax je 0f movl %eax, 8(%ebp) movl %eax, (%esp) movl 12(%ebp), %eax movl %eax, 4(%esp) call objc_msg_lookup@PLT addl $20, %esp popl %ebx popl %ebp jmp *%eax 0: movl OFMethodNotFound@GOT(%ebx), %eax addl $20, %esp popl %ebx popl %ebp jmp *%eax .type OFForward, %function .size OFForward, .-OFForward OFForward_stret: _CET_ENDBR pushl %ebp movl %esp, %ebp pushl %ebx subl $20, %esp call .LgetEIP addl $_GLOBAL_OFFSET_TABLE_, %ebx movl 12(%ebp), %eax movl %eax, (%esp) call object_getClass@PLT movl %eax, (%esp) leal .Lsel_forwardingTargetForSelector_@GOTOFF(%ebx), %eax movl %eax, 4(%esp) call class_respondsToSelector@PLT testl %eax, %eax jz 0f movl 12(%ebp), %eax movl %eax, (%esp) leal .Lsel_forwardingTargetForSelector_@GOTOFF(%ebx), %eax movl %eax, 4(%esp) call objc_msg_lookup@PLT movl 12(%ebp), %edx movl %edx, (%esp) leal .Lsel_forwardingTargetForSelector_@GOTOFF(%ebx), %edx movl %edx, 4(%esp) movl 16(%ebp), %edx movl %edx, 8(%esp) call *%eax testl %eax, %eax jz 0f cmpl 12(%ebp), %eax je 0f movl %eax, 12(%ebp) movl %eax, (%esp) movl 16(%ebp), %eax movl %eax, 4(%esp) call objc_msg_lookup_stret@PLT addl $20, %esp popl %ebx popl %ebp jmp *%eax 0: movl OFMethodNotFound_stret@GOT(%ebx), %eax addl $20, %esp popl %ebx popl %ebp jmp *%eax .type OFForward_stret, %function .size OFForward_stret, .-OFForward_stret .Linit: _CET_ENDBR pushl %ebp movl %esp, %ebp pushl %ebx subl $4, %esp call .LgetEIP addl $_GLOBAL_OFFSET_TABLE_, %ebx leal .Lmodule@GOTOFF(%ebx), %eax movl %eax, (%esp) call __objc_exec_class@PLT addl $4, %esp popl %ebx popl %ebp ret .LgetEIP: movl (%esp), %ebx ret #ifdef OF_SOLARIS .section .init_array, "aw" #else .section .ctors, "aw", %progbits #endif .long .Linit .section .rodata .Lstr_forwardingTargetForSelector_: .asciz "forwardingTargetForSelector:" .section .data .Lsel_forwardingTargetForSelector_: .long .Lstr_forwardingTargetForSelector_, 0 .long 0, 0 .Lsymtab: .long 0, .Lsel_forwardingTargetForSelector_ .short 0, 0 .long 0 .long 0 .Lmodule: .long 8, 16, 0, .Lsymtab #if defined(OF_LINUX) || defined(OF_HAIKU) || defined(OF_HURD) .section .note.GNU-stack, "", %progbits #endif objfw-1.1.6/src/forwarding/forwarding-x86-win32.S000066400000000000000000000062671465614216400214540ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" .globl _OFForward .globl _OFForward_stret #ifdef HAVE_CET_H # include #else # define _CET_ENDBR #endif .section .text _OFForward: _CET_ENDBR pushl %ebp movl %esp, %ebp pushl %ebx subl $20, %esp movl 8(%ebp), %eax movl %eax, (%esp) call _object_getClass movl %eax, (%esp) movl $.Lsel_forwardingTargetForSelector_, %eax movl %eax, 4(%esp) call _class_respondsToSelector testl %eax, %eax jz 0f movl 8(%ebp), %eax movl %eax, (%esp) movl $.Lsel_forwardingTargetForSelector_, %eax movl %eax, 4(%esp) call _objc_msg_lookup movl 8(%ebp), %edx movl %edx, (%esp) movl $.Lsel_forwardingTargetForSelector_, %edx movl %edx, 4(%esp) movl 12(%ebp), %edx movl %edx, 8(%esp) call *%eax testl %eax, %eax jz 0f cmpl 8(%ebp), %eax je 0f movl %eax, 8(%ebp) movl %eax, (%esp) movl 12(%ebp), %eax movl %eax, 4(%esp) call _objc_msg_lookup addl $20, %esp popl %ebx popl %ebp jmp *%eax 0: addl $20, %esp popl %ebx popl %ebp jmp _OFMethodNotFound .def _OFForward .scl 2 .type 32 .endef _OFForward_stret: _CET_ENDBR pushl %ebp movl %esp, %ebp pushl %ebx subl $20, %esp movl 12(%ebp), %eax movl %eax, (%esp) call _object_getClass movl %eax, (%esp) movl $.Lsel_forwardingTargetForSelector_, %eax movl %eax, 4(%esp) call _class_respondsToSelector testl %eax, %eax jz 0f movl 12(%ebp), %eax movl %eax, (%esp) movl $.Lsel_forwardingTargetForSelector_, %eax movl %eax, 4(%esp) call _objc_msg_lookup movl 12(%ebp), %edx movl %edx, (%esp) movl $.Lsel_forwardingTargetForSelector_, %edx movl %edx, 4(%esp) movl 16(%ebp), %edx movl %edx, 8(%esp) call *%eax testl %eax, %eax jz 0f cmpl 12(%ebp), %eax je 0f movl %eax, 12(%ebp) movl %eax, (%esp) movl 16(%ebp), %eax movl %eax, 4(%esp) call _objc_msg_lookup_stret addl $20, %esp popl %ebx popl %ebp jmp *%eax 0: addl $20, %esp popl %ebx popl %ebp jmp _OFMethodNotFound_stret .def _OFForward_stret .scl 2 .type 32 .endef .Linit: _CET_ENDBR pushl %ebp movl %esp, %ebp pushl %ebx subl $4, %esp movl $.Lmodule, %eax movl %eax, (%esp) call ___objc_exec_class addl $4, %esp popl %ebx popl %ebp ret .section .ctors, "aw" .long .Linit .section .rodata .Lstr_forwardingTargetForSelector_: .asciz "forwardingTargetForSelector:" .section .data .Lsel_forwardingTargetForSelector_: .long .Lstr_forwardingTargetForSelector_, 0 .long 0, 0 .Lsymtab: .long 0, .Lsel_forwardingTargetForSelector_ .short 0, 0 .long 0 .long 0 .Lmodule: .long 8, 16, 0, .Lsymtab objfw-1.1.6/src/forwarding/forwarding.S000066400000000000000000000036061465614216400200630ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" #ifdef OF_APPLE_RUNTIME # if defined(OF_AMD64) # include "apple-forwarding-amd64.S" # elif defined(OF_X86) # include "apple-forwarding-x86.S" # elif defined(OF_ARM64) # include "apple-forwarding-arm64.S" # elif defined(OF_ARM) # include "apple-forwarding-arm.S" # elif defined(OF_POWERPC) # include "apple-forwarding-powerpc.S" # endif #else # if defined(OF_ELF) # if defined(OF_AMD64) # include "forwarding-amd64-elf.S" # elif defined(OF_X86) # include "forwarding-x86-elf.S" # elif defined(OF_ARM64) # include "forwarding-arm64-elf.S" # elif defined(OF_ARM) # include "forwarding-arm-elf.S" # elif defined(OF_POWERPC) # include "forwarding-powerpc-elf.S" # elif defined(OF_MIPS) # include "forwarding-mips-elf.S" # elif defined(OF_SPARC64) # include "forwarding-sparc64-elf.S" # elif defined(OF_SPARC) # include "forwarding-sparc-elf.S" # endif # elif defined(OF_MACH_O) # if defined(OF_AMD64) # include "forwarding-amd64-macho.S" # endif # elif defined(OF_WINDOWS) # if defined(OF_AMD64) # include "forwarding-amd64-win64.S" # elif defined(OF_X86) # include "forwarding-x86-win32.S" # endif # endif #endif objfw-1.1.6/src/libbases.m000066400000000000000000000036461465614216400154010ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #define Class IntuitionClass #include #undef Class #import "OFInitializationFailedException.h" #import "macros.h" #ifdef OF_AMIGAOS4 extern struct Library *DOSBase; extern struct DOSIFace *IDOS; #endif struct Library *LocaleBase; #ifdef OF_AMIGAOS4 struct LocaleIFace *ILocale; #endif OF_CONSTRUCTOR() { #ifdef OF_AMIGAOS4 if ((DOSBase = OpenLibrary("dos.library", 36)) == NULL) @throw [OFInitializationFailedException exception]; if ((IDOS = (struct DOSIFace *) GetInterface(DOSBase, "main", 1, NULL)) == NULL) @throw [OFInitializationFailedException exception]; #endif if ((LocaleBase = OpenLibrary("locale.library", 38)) == NULL) @throw [OFInitializationFailedException exception]; #ifdef OF_AMIGAOS4 if ((ILocale = (struct LocaleIFace *) GetInterface(LocaleBase, "main", 1, NULL)) == NULL) @throw [OFInitializationFailedException exception]; #endif } OF_DESTRUCTOR() { #ifdef OF_AMIGAOS4 if (ILocale != NULL) DropInterface((struct Interface *)ILocale); #endif if (LocaleBase != NULL) CloseLibrary(LocaleBase); #ifdef OF_AMIGAOS4 if (DOSBase != NULL) CloseLibrary(DOSBase); if (IDOS != NULL) DropInterface((struct Interface *)IDOS); #endif } objfw-1.1.6/src/macros.h000066400000000000000000000624401465614216400150710ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifndef OBJFW_MACROS_H #define OBJFW_MACROS_H #include "objfw-defs.h" #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif #include #include #include #include #include #include #include #include /** @file */ #include "platform.h" #ifdef OF_OBJFW_RUNTIME # ifdef OF_COMPILING_OBJFW # include "ObjFWRT.h" # else # include # endif #endif #ifdef OF_APPLE_RUNTIME # include # include # include #endif #if defined(__GNUC__) # define restrict __restrict__ #elif __STDC_VERSION__ < 199901L # define restrict #endif #if __STDC_VERSION__ >= 201112L && !defined(static_assert) /* C11 compiler, but old libc */ # define static_assert _Static_assert #endif #if defined(OF_HAVE__THREAD_LOCAL) # define OF_HAVE_COMPILER_TLS # ifdef OF_HAVE_THREADS_H # include # ifdef OF_AIX /* AIX has a bug where thread_local is defined to "Thread_local;". */ # undef thread_local # define thread_local _Thread_local # endif # else # define thread_local _Thread_local # endif #elif defined(OF_HAVE___THREAD) # define OF_HAVE_COMPILER_TLS # define thread_local __thread #endif /* * Do not use compiler TLS when targeting the iOS simulator, as the iOS 9 * simulator does not support it (fails at runtime). */ #if defined(OF_HAVE_COMPILER_TLS) && defined(OF_IOS) && defined(OF_X86) # undef OF_HAVE_COMPILER_TLS #endif #ifdef __GNUC__ # define OF_INLINE inline __attribute__((__always_inline__)) # define OF_LIKELY(cond) (__builtin_expect(!!(cond), 1)) # define OF_UNLIKELY(cond) (__builtin_expect(!!(cond), 0)) # define OF_CONST_FUNC __attribute__((__const__)) # define OF_NO_RETURN_FUNC __attribute__((__noreturn__)) # define OF_WEAK_REF(sym) __attribute__((__weakref__(sym))) # define OF_VISIBILITY_HIDDEN __attribute__((__visibility__("hidden"))) #else # define OF_INLINE inline # define OF_LIKELY(cond) (cond) # define OF_UNLIKELY(cond) (cond) # define OF_CONST_FUNC # define OF_NO_RETURN_FUNC # define OF_WEAK_REF(sym) # define OF_VISIBILITY_HIDDEN #endif #if __STDC_VERSION__ >= 201112L # define OF_ALIGN(size) _Alignas(size) # define OF_ALIGNOF(type) _Alignof(type) # define OF_ALIGNAS(type) _Alignas(type) #else # define OF_ALIGN(size) __attribute__((__aligned__(size))) # define OF_ALIGNOF(type) __alignof__(type) # define OF_ALIGNAS(type) OF_ALIGN(OF_ALIGNOF(type)) #endif #ifdef __BIGGEST_ALIGNMENT__ # define OF_BIGGEST_ALIGNMENT __BIGGEST_ALIGNMENT__ #else /* Hopefully no arch needs more than 16 byte alignment */ # define OF_BIGGEST_ALIGNMENT 16 #endif /* * We use SSE inline assembly on AMD64 and x86, so it must never be smaller * than 16. */ #if (defined(OF_AMD64) || defined(OF_X86)) && OF_BIGGEST_ALIGNMENT < 16 # undef OF_BIGGEST_ALIGNMENT # define OF_BIGGEST_ALIGNMENT 16 #endif #define OF_PREPROCESSOR_CONCAT2(a, b) a##b #define OF_PREPROCESSOR_CONCAT(a, b) OF_PREPROCESSOR_CONCAT2(a, b) #if __OBJFW_RUNTIME_ABI__ || (defined(OF_APPLE_RUNTIME) && defined(__OBJC2__)) # define OF_HAVE_NONFRAGILE_IVARS #endif #ifdef OF_HAVE_NONFRAGILE_IVARS # define OF_RESERVE_IVARS(cls, num) #else # define OF_RESERVE_IVARS(cls, num) \ @private \ void *OF_PREPROCESSOR_CONCAT(_reserved_, cls)[num]; #endif #ifdef __GNUC__ # define OF_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) #else # define OF_GCC_VERSION 0 #endif #define OF_STRINGIFY(s) OF_STRINGIFY2(s) #define OF_STRINGIFY2(s) #s #ifndef __has_feature # define __has_feature(x) 0 #endif #ifndef __has_attribute # define __has_attribute(x) 0 #endif #if __has_feature(objc_bool) # undef YES # define YES __objc_yes # undef NO # define NO __objc_no # ifndef __cplusplus # undef true # define true ((bool)1) # undef false # define false ((bool)0) # endif #endif #if !__has_feature(objc_instancetype) # define instancetype id #endif #if __has_feature(blocks) # define OF_HAVE_BLOCKS #endif #if __has_feature(objc_arc) # define OF_RETURNS_RETAINED __attribute__((__ns_returns_retained__)) # define OF_RETURNS_NOT_RETAINED __attribute__((__ns_returns_not_retained__)) # define OF_RETURNS_INNER_POINTER \ __attribute__((__objc_returns_inner_pointer__)) # define OF_CONSUMED __attribute__((__ns_consumed__)) # define OF_WEAK_UNAVAILABLE __attribute__((__objc_arc_weak_unavailable__)) #else # define OF_RETURNS_RETAINED # define OF_RETURNS_NOT_RETAINED # define OF_RETURNS_INNER_POINTER # define OF_CONSUMED # define OF_WEAK_UNAVAILABLE /* * undef them first, as new Clang versions have these as built-in defines even * when ARC is disabled. */ # undef __unsafe_unretained # undef __bridge # undef __autoreleasing # define __unsafe_unretained # define __bridge # define __autoreleasing #endif #if __has_feature(objc_generics) # define OF_HAVE_GENERICS # define OF_GENERIC(...) <__VA_ARGS__> #else # define OF_GENERIC(...) #endif #if __has_feature(nullability) # define OF_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin") # define OF_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end") # define OF_NULLABLE_PROPERTY(...) (__VA_ARGS__, nullable) # define OF_NULL_RESETTABLE_PROPERTY(...) (__VA_ARGS__, null_resettable) #else # define OF_ASSUME_NONNULL_BEGIN # define OF_ASSUME_NONNULL_END # define _Nonnull # define _Nullable # define _Null_unspecified # define OF_NULLABLE_PROPERTY # define OF_NULL_RESETTABLE_PROPERTY # define nonnull # define nullable # define null_unspecified #endif #if __has_feature(objc_kindof) # define OF_KINDOF(class_) __kindof class_ #else # define OF_KINDOF(class_) id #endif #if __has_feature(objc_class_property) # define OF_HAVE_CLASS_PROPERTIES #endif #if defined(__clang__) || OF_GCC_VERSION >= 405 # define OF_UNREACHABLE __builtin_unreachable(); #else # define OF_UNREACHABLE abort(); #endif #if defined(__clang__) || OF_GCC_VERSION >= 406 # define OF_SENTINEL __attribute__((__sentinel__)) # define OF_NO_RETURN __attribute__((__noreturn__)) #else # define OF_SENTINEL # define OF_NO_RETURN #endif #ifdef __clang__ # define OF_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) #else # define OF_WARN_UNUSED_RESULT #endif #if __has_attribute(__unavailable__) # define OF_UNAVAILABLE __attribute__((__unavailable__)) #else # define OF_UNAVAILABLE #endif #if __has_attribute(__objc_requires_super__) # define OF_REQUIRES_SUPER __attribute__((__objc_requires_super__)) #else # define OF_REQUIRES_SUPER #endif #if __has_attribute(__objc_root_class__) # define OF_ROOT_CLASS __attribute__((__objc_root_class__)) #else # define OF_ROOT_CLASS #endif #if __has_attribute(__objc_subclassing_restricted__) # define OF_SUBCLASSING_RESTRICTED \ __attribute__((__objc_subclassing_restricted__)) #else # define OF_SUBCLASSING_RESTRICTED #endif #if __has_attribute(__objc_method_family__) # define OF_METHOD_FAMILY(f) __attribute__((__objc_method_family__(f))) #else # define OF_METHOD_FAMILY(f) #endif #if __has_attribute(__objc_designated_initializer__) # define OF_DESIGNATED_INITIALIZER \ __attribute__((__objc_designated_initializer__)) #else # define OF_DESIGNATED_INITIALIZER #endif #if defined(__clang__) || OF_GCC_VERSION >= 405 # define OF_DEPRECATED(project, major, minor, msg) \ __attribute__((__deprecated__("Deprecated in " #project " " \ #major "." #minor ": " msg))) #elif defined(__GNUC__) # define OF_DEPRECATED(project, major, minor, msg) \ __attribute__((__deprecated__)) #else # define OF_DEPRECATED(project, major, minor, msg) #endif #if __has_attribute(__objc_boxable__) # define OF_BOXABLE __attribute__((__objc_boxable__)) #else # define OF_BOXABLE #endif #if __has_attribute(__swift_name__) # define OF_SWIFT_NAME(name) __attribute__((__swift_name__(name))) #else # define OF_SWIFT_NAME(name) #endif #if __has_attribute(__objc_direct__) && defined(OF_APPLE_RUNTIME) # define OF_DIRECT __attribute__((__objc_direct__)) #else # define OF_DIRECT #endif #if __has_attribute(__objc_direct_members__) && defined(OF_APPLE_RUNTIME) # define OF_DIRECT_MEMBERS __attribute__((__objc_direct_members__)) #else # define OF_DIRECT_MEMBERS #endif #ifdef OF_APPLE_RUNTIME # if defined(OF_AMD64) || defined(OF_X86) || defined(OF_ARM64) || \ defined(OF_ARM) || defined(OF_POWERPC) # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET # endif #else # if defined(OF_ELF) # if defined(OF_AMD64) || defined(OF_X86) || \ defined(OF_ARM64) || defined(OF_ARM) || defined(OF_POWERPC) || \ defined(OF_MIPS) || defined(OF_SPARC64) || defined(OF_SPARC) # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR # if __OBJFW_RUNTIME_ABI__ >= 800 # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET # endif # endif # elif defined(OF_MACH_O) # if defined(OF_AMD64) # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR # if __OBJFW_RUNTIME_ABI__ >= 800 # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET # endif # endif # elif defined(OF_WINDOWS) # if defined(OF_AMD64) || defined(OF_X86) # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR # if __OBJFW_RUNTIME_ABI__ >= 800 # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET # endif # endif # endif #endif #define OFMaxRetainCount UINT_MAX #ifdef OBJC_COMPILING_RUNTIME # define OFEnsure(cond) \ do { \ if OF_UNLIKELY (!(cond)) \ objc_error("ObjFWRT @ " __FILE__ ":" \ OF_STRINGIFY(__LINE__), \ "Failed to ensure condition:\n" #cond); \ } while(0) #else @class OFConstantString; # ifdef __cplusplus extern "C" { # endif extern void OFLog(OFConstantString *_Nonnull, ...); # ifdef __cplusplus } # endif # define OFEnsure(cond) \ do { \ if OF_UNLIKELY (!(cond)) { \ OFLog(@"Failed to ensure condition in " \ @__FILE__ ":%d: " @#cond, __LINE__); \ abort(); \ } \ } while (0) #endif #ifndef NDEBUG # define OFAssert(...) OFEnsure(__VA_ARGS__) #else # define OFAssert(...) #endif #define OF_UNRECOGNIZED_SELECTOR OFMethodNotFound(self, _cmd); #if __has_feature(objc_arc) # define OF_INVALID_INIT_METHOD OFMethodNotFound(self, _cmd); #else # define OF_INVALID_INIT_METHOD \ @try { \ OFMethodNotFound(self, _cmd); \ } @catch (id e) { \ [self release]; \ @throw e; \ } \ \ abort(); #endif #ifdef __clang__ # define OF_DEALLOC_UNSUPPORTED \ [self doesNotRecognizeSelector: _cmd]; \ \ abort(); \ \ _Pragma("clang diagnostic push"); \ _Pragma("clang diagnostic ignored \"-Wunreachable-code\""); \ [super dealloc]; /* Get rid of a stupid warning */ \ _Pragma("clang diagnostic pop"); #else # define OF_DEALLOC_UNSUPPORTED \ [self doesNotRecognizeSelector: _cmd]; \ \ abort(); \ \ [super dealloc]; /* Get rid of a stupid warning */ #endif #define OF_SINGLETON_METHODS \ - (instancetype)autorelease \ { \ return self; \ } \ \ - (instancetype)retain \ { \ return self; \ } \ \ - (void)release \ { \ } \ \ - (unsigned int)retainCount \ { \ return OFMaxRetainCount; \ } \ \ - (void)dealloc \ { \ OF_DEALLOC_UNSUPPORTED \ } #define OF_CONSTRUCTOR(prio) \ static void __attribute__((__constructor__(prio))) \ OF_PREPROCESSOR_CONCAT(constructor, __LINE__)(void) #define OF_DESTRUCTOR(prio) \ static void __attribute__((__destructor__(prio))) \ OF_PREPROCESSOR_CONCAT(destructor, __LINE__)(void) static OF_INLINE uint16_t OF_CONST_FUNC _OFByteSwap16Const(uint16_t i) { return (i & UINT16_C(0xFF00)) >> 8 | (i & UINT16_C(0x00FF)) << 8; } static OF_INLINE uint32_t OF_CONST_FUNC _OFByteSwap32Const(uint32_t i) { return (i & UINT32_C(0xFF000000)) >> 24 | (i & UINT32_C(0x00FF0000)) >> 8 | (i & UINT32_C(0x0000FF00)) << 8 | (i & UINT32_C(0x000000FF)) << 24; } static OF_INLINE uint64_t OF_CONST_FUNC _OFByteSwap64Const(uint64_t i) { return (i & UINT64_C(0xFF00000000000000)) >> 56 | (i & UINT64_C(0x00FF000000000000)) >> 40 | (i & UINT64_C(0x0000FF0000000000)) >> 24 | (i & UINT64_C(0x000000FF00000000)) >> 8 | (i & UINT64_C(0x00000000FF000000)) << 8 | (i & UINT64_C(0x0000000000FF0000)) << 24 | (i & UINT64_C(0x000000000000FF00)) << 40 | (i & UINT64_C(0x00000000000000FF)) << 56; } static OF_INLINE uint16_t OF_CONST_FUNC _OFByteSwap16NonConst(uint16_t i) { #if defined(OF_HAVE_BUILTIN_BSWAP16) return __builtin_bswap16(i); #elif (defined(OF_AMD64) || defined(OF_X86)) && defined(__GNUC__) __asm__ ( "xchg{b} { %h0, %b0 | %b0, %h0 }" : "=Q" (i) : "0" (i) ); #elif defined(OF_POWERPC) && defined(__GNUC__) __asm__ ( "lhbrx %0, 0, %1" : "=r" (i) : "r" (&i), "m" (i) ); #elif defined(OF_ARMV6) && defined(__GNUC__) __asm__ ( "rev16 %0, %0" : "=r" (i) : "0" (i) ); #else i = (i & UINT16_C(0xFF00)) >> 8 | (i & UINT16_C(0x00FF)) << 8; #endif return i; } static OF_INLINE uint32_t OF_CONST_FUNC _OFByteSwap32NonConst(uint32_t i) { #if defined(OF_HAVE_BUILTIN_BSWAP32) return __builtin_bswap32(i); #elif (defined(OF_AMD64) || defined(OF_X86)) && defined(__GNUC__) __asm__ ( "bswap %0" : "=q" (i) : "0" (i) ); #elif defined(OF_POWERPC) && defined(__GNUC__) __asm__ ( "lwbrx %0, 0, %1" : "=r" (i) : "r" (&i), "m" (i) ); #elif defined(OF_ARMV6) && defined(__GNUC__) __asm__ ( "rev %0, %0" : "=r" (i) : "0" (i) ); #else i = (i & UINT32_C(0xFF000000)) >> 24 | (i & UINT32_C(0x00FF0000)) >> 8 | (i & UINT32_C(0x0000FF00)) << 8 | (i & UINT32_C(0x000000FF)) << 24; #endif return i; } static OF_INLINE uint64_t OF_CONST_FUNC _OFByteSwap64NonConst(uint64_t i) { #if defined(OF_HAVE_BUILTIN_BSWAP64) return __builtin_bswap64(i); #elif defined(OF_AMD64) && defined(__GNUC__) __asm__ ( "bswap %0" : "=r" (i) : "0" (i) ); #elif defined(OF_X86) && defined(__GNUC__) __asm__ ( "bswap {%%}eax\n\t" "bswap {%%}edx\n\t" "xchg{l} { %%eax, %%edx | edx, eax }" : "=A" (i) : "0" (i) ); #else i = (uint64_t)_OFByteSwap32NonConst( (uint32_t)(i & UINT32_C(0xFFFFFFFF))) << 32 | _OFByteSwap32NonConst((uint32_t)(i >> 32)); #endif return i; } #if defined(__GNUC__) || defined(DOXYGEN) /** * @brief Byte swaps the specified 16 bit integer. * * @param i The integer to byte swap * @return The byte swapped integer */ # define OFByteSwap16(i) \ (__builtin_constant_p(i) ? _OFByteSwap16Const(i) : _OFByteSwap16NonConst(i)) /** * @brief Byte swaps the specified 32 bit integer. * * @param i The integer to byte swap * @return The byte swapped integer */ # define OFByteSwap32(i) \ (__builtin_constant_p(i) ? _OFByteSwap32Const(i) : _OFByteSwap32NonConst(i)) /** * @brief Byte swaps the specified 64 bit integer. * * @param i The integer to byte swap * @return The byte swapped integer */ # define OFByteSwap64(i) \ (__builtin_constant_p(i) ? _OFByteSwap64Const(i) : _OFByteSwap64NonConst(i)) #else # define OFByteSwap16(i) _OFByteSwap16Const(i) # define OFByteSwap32(i) _OFByteSwap32Const(i) # define OFByteSwap64(i) _OFByteSwap64Const(i) #endif /** * @brief Bit-converts the specified float to a uint32_t. * * @param f The float to bit-convert * @return The float bit-converted to a uint32_t */ static OF_INLINE uint32_t OF_CONST_FUNC OFBitConvertFloatToUInt32(float f) { uint32_t ret; memcpy(&ret, &f, 4); return ret; } /** * @brief Bit-converts the specified uint32_t to a float. * * @param uInt32 The uint32_t to bit-convert * @return The uint32_t bit-converted to a float */ static OF_INLINE float OF_CONST_FUNC OFBitConvertUInt32ToFloat(uint32_t uInt32) { float ret; memcpy(&ret, &uInt32, 4); return ret; } /** * @brief Bit-converts the specified double to a uint64_t. * * @param d The double to bit-convert * @return The double bit-converted to a uint64_t */ static OF_INLINE uint64_t OF_CONST_FUNC OFBitConvertDoubleToUInt64(double d) { uint64_t ret; memcpy(&ret, &d, 8); return ret; } /** * @brief Bit-converts the specified uint64_t to a double. * * @param uInt64 The uint64_t to bit-convert * @return The uint64_t bit-converted to a double */ static OF_INLINE double OF_CONST_FUNC OFBitConvertUInt64ToDouble(uint64_t uInt64) { double ret; memcpy(&ret, &uInt64, 8); return ret; } /** * @brief Byte swaps the specified float. * * @param f The float to byte swap * @return The byte swapped float */ static OF_INLINE float OF_CONST_FUNC OFByteSwapFloat(float f) { return OFBitConvertUInt32ToFloat(OFByteSwap32( OFBitConvertFloatToUInt32(f))); } /** * @brief Byte swaps the specified double. * * @param d The double to byte swap * @return The byte swapped double */ static OF_INLINE double OF_CONST_FUNC OFByteSwapDouble(double d) { return OFBitConvertUInt64ToDouble(OFByteSwap64( OFBitConvertDoubleToUInt64(d))); } #if defined(OF_BIG_ENDIAN) || defined(DOXYGEN) /** * @brief Converts the specified 16 bit integer from big endian to native * endian. * * @param i The 16 bit integer to convert * @return The 16 bit integer converted to native endian */ # define OFFromBigEndian16(i) (i) /** * @brief Converts the specified 32 bit integer from big endian to native * endian. * * @param i The 32 bit integer to convert * @return The 32 bit integer converted to native endian */ # define OFFromBigEndian32(i) (i) /** * @brief Converts the specified 64 bit integer from big endian to native * endian. * * @param i The 64 bit integer to convert * @return The 64 bit integer converted to native endian */ # define OFFromBigEndian64(i) (i) /** * @brief Converts the specified 16 bit integer from little endian to native * endian. * * @param i The 16 bit integer to convert * @return The 16 bit integer converted to native endian */ # define OFFromLittleEndian16(i) OFByteSwap16(i) /** * @brief Converts the specified 32 bit integer from little endian to native * endian. * * @param i The 32 bit integer to convert * @return The 32 bit integer converted to native endian */ # define OFFromLittleEndian32(i) OFByteSwap32(i) /** * @brief Converts the specified 64 bit integer from little endian to native * endian. * * @param i The 64 bit integer to convert * @return The 64 bit integer converted to native endian */ # define OFFromLittleEndian64(i) OFByteSwap64(i) /** * @brief Converts the specified 16 bit integer from native endian to big * endian. * * @param i The 16 bit integer to convert * @return The 16 bit integer converted to big endian */ # define OFToBigEndian16(i) (i) /** * @brief Converts the specified 32 bit integer from native endian to big * endian. * * @param i The 32 bit integer to convert * @return The 32 bit integer converted to big endian */ # define OFToBigEndian32(i) (i) /** * @brief Converts the specified 64 bit integer from native endian to big * endian. * * @param i The 64 bit integer to convert * @return The 64 bit integer converted to big endian */ # define OFToBigEndian64(i) (i) /** * @brief Converts the specified 16 bit integer from native endian to little * endian. * * @param i The 16 bit integer to convert * @return The 16 bit integer converted to little endian */ # define OFToLittleEndian16(i) OFByteSwap16(i) /** * @brief Converts the specified 32 bit integer from native endian to little * endian. * * @param i The 32 bit integer to convert * @return The 32 bit integer converted to little endian */ # define OFToLittleEndian32(i) OFByteSwap32(i) /** * @brief Converts the specified 64 bit integer from native endian to little * endian. * * @param i The 64 bit integer to convert * @return The 64 bit integer converted to little endian */ # define OFToLittleEndian64(i) OFByteSwap64(i) #else # define OFFromBigEndian16(i) OFByteSwap16(i) # define OFFromBigEndian32(i) OFByteSwap32(i) # define OFFromBigEndian64(i) OFByteSwap64(i) # define OFFromLittleEndian16(i) (i) # define OFFromLittleEndian32(i) (i) # define OFFromLittleEndian64(i) (i) # define OFToBigEndian16(i) OFByteSwap16(i) # define OFToBigEndian32(i) OFByteSwap32(i) # define OFToBigEndian64(i) OFByteSwap64(i) # define OFToLittleEndian16(i) (i) # define OFToLittleEndian32(i) (i) # define OFToLittleEndian64(i) (i) #endif #if defined(OF_FLOAT_BIG_ENDIAN) || defined(DOXYGEN) /** * @brief Converts the specified float from big endian to native endian. * * @param f The float to convert * @return The float converted to native endian */ # define OFFromBigEndianFloat(f) (f) /** * @brief Converts the specified double from big endian to native endian. * * @param d The double to convert * @return The double converted to native endian */ # define OFFromBigEndianDouble(d) (d) /** * @brief Converts the specified float from little endian to native endian. * * @param f The float to convert * @return The float converted to native endian */ # define OFFromLittleEndianFloat(f) OFByteSwapFloat(f) /** * @brief Converts the specified double from little endian to native endian. * * @param d The double to convert * @return The double converted to native endian */ # define OFFromLittleEndianDouble(d) OFByteSwapDouble(d) /** * @brief Converts the specified float from native endian to big endian. * * @param f The float to convert * @return The float converted to big endian */ # define OFToBigEndianFloat(f) (f) /** * @brief Converts the specified double from native endian to big endian. * * @param d The double to convert * @return The double converted to big endian */ # define OFToBigEndianDouble(d) (d) /** * @brief Converts the specified float from native endian to little endian. * * @param f The float to convert * @return The float converted to little endian */ # define OFToLittleEndianFloat(f) OFByteSwapFloat(f) /** * @brief Converts the specified double from native endian to little endian. * * @param d The double to convert * @return The double converted to little endian */ # define OFToLittleEndianDouble(d) OFByteSwapDouble(d) #else # define OFFromBigEndianFloat(f) OFByteSwapFloat(f) # define OFFromBigEndianDouble(d) OFByteSwapDouble(d) # define OFFromLittleEndianFloat(f) (f) # define OFFromLittleEndianDouble(d) (d) # define OFToBigEndianFloat(f) OFByteSwapFloat(f) # define OFToBigEndianDouble(d) OFByteSwapDouble(d) # define OFToLittleEndianFloat(f) (f) # define OFToLittleEndianDouble(d) (d) #endif /** * @brief Rotates the specified value left by the specified amount of bits. * * @param value The value to rotate * @param bits The number of bits to rotate left the value by * @return The value rotated left by the specified amount of bits */ #define OFRotateLeft(value, bits) \ (((bits) % (sizeof(value) * 8)) > 0 \ ? ((value) << ((bits) % (sizeof(value) * 8))) | \ ((value) >> (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8)))) \ : (value)) /** * @brief Rotates the specified value right by the specified amount of bits. * * @param value The value to rotate * @param bits The number of bits to rotate right the value by * @return The value rotated right by the specified amount of bits */ #define OFRotateRight(value, bits) \ (((bits) % (sizeof(value) * 8)) > 0 \ ? ((value) >> ((bits) % (sizeof(value) * 8))) | \ ((value) << (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8)))) \ : (value)) /** * @brief Rounds up the specified value to the specified power of two. * * @param pow2 The power of 2 to round up to * @param value The value to round up to the specified power of two * @return The specified value rounded up to the specified power of two */ #define OFRoundUpToPowerOf2(pow2, value) \ (((value) + (pow2) - 1) & ~((pow2) - 1)) static OF_INLINE bool OFBitsetIsSet(unsigned char *_Nonnull storage, size_t idx) { return storage[idx / CHAR_BIT] & (1u << (idx % CHAR_BIT)); } static OF_INLINE void OFBitsetSet(unsigned char *_Nonnull storage, size_t idx) { storage[idx / CHAR_BIT] |= (1u << (idx % CHAR_BIT)); } static OF_INLINE void OFBitsetClear(unsigned char *_Nonnull storage, size_t idx) { storage[idx / CHAR_BIT] &= ~(1u << (idx % CHAR_BIT)); } static OF_INLINE void OFZeroMemory(void *_Nonnull buffer_, size_t length) { volatile unsigned char *buffer = (volatile unsigned char *)buffer_; while (buffer < (unsigned char *)buffer_ + length) *buffer++ = '\0'; } static OF_INLINE bool OFASCIIIsAlpha(char c) { return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); } static OF_INLINE bool OFASCIIIsDigit(char c) { return (c >= '0' && c <= '9'); } static OF_INLINE bool OFASCIIIsAlnum(char c) { return (OFASCIIIsAlpha(c) || OFASCIIIsDigit(c)); } static OF_INLINE bool OFASCIIIsSpace(char c) { return (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' || c == '\v'); } static OF_INLINE char OFASCIIToUpper(char c) { return (c >= 'a' && c <= 'z' ? 'A' + (c - 'a') : c); } static OF_INLINE char OFASCIIToLower(char c) { return (c >= 'A' && c <= 'Z' ? 'a' + (c - 'A') : c); } #endif objfw-1.1.6/src/module.modulemap000066400000000000000000000005701465614216400166220ustar00rootroot00000000000000framework module ObjFW { umbrella header "ObjFW.h" /* * These are included by OFAtomic.h, but should never be included * directly. */ exclude header "platform/GCC4/OFAtomic.h" exclude header "platform/GCC4.7/OFAtomic.h" exclude header "platform/PowerPC/OFAtomic.h" exclude header "platform/macOS/OFAtomic.h" exclude header "platform/x86/OFAtomic.h" export * } objfw-1.1.6/src/objfw-defs.h.in000066400000000000000000000026071465614216400162370ustar00rootroot00000000000000#undef OF_APPLE_RUNTIME #undef OF_BIG_ENDIAN #undef OF_CLASSIC_MACOS #undef OF_FLOAT_BIG_ENDIAN #undef OF_HAVE_AFUNIX_H #undef OF_HAVE_APPLETALK #undef OF_HAVE_ATOMIC_BUILTINS #undef OF_HAVE_ATOMIC_OPS #undef OF_HAVE_BUILTIN_BSWAP16 #undef OF_HAVE_BUILTIN_BSWAP32 #undef OF_HAVE_BUILTIN_BSWAP64 #undef OF_HAVE_CHMOD #undef OF_HAVE_CHOWN #undef OF_HAVE_FILES #undef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR #undef OF_HAVE_IPV6 #undef OF_HAVE_IPX #undef OF_HAVE_LIMITS_H #undef OF_HAVE_LINK #undef OF_HAVE_NETATALK_AT_H #undef OF_HAVE_NETAT_APPLETALK_H #undef OF_HAVE_NETINET_IN_H #undef OF_HAVE_NETINET_TCP_H #undef OF_HAVE_NETIPX_IPX_H #undef OF_HAVE_OSATOMIC #undef OF_HAVE_OSATOMIC_64 #undef OF_HAVE_PIPE #undef OF_HAVE_PLEDGE #undef OF_HAVE_PLUGINS #undef OF_HAVE_PTHREADS #undef OF_HAVE_PTHREAD_SPINLOCKS #undef OF_HAVE_RECURSIVE_PTHREAD_MUTEXES #undef OF_HAVE_SCHED_YIELD #undef OF_HAVE_SOCKADDR_STORAGE #undef OF_HAVE_SOCKETS #undef OF_HAVE_STDNORETURN #undef OF_HAVE_SUBPROCESSES #undef OF_HAVE_SYMLINK #undef OF_HAVE_SYNC_BUILTINS #undef OF_HAVE_SYS_SOCKET_H #undef OF_HAVE_SYS_TYPES_H #undef OF_HAVE_SYS_UN_H #undef OF_HAVE_THREADS #undef OF_HAVE_UNICODE_TABLES #undef OF_HAVE_UNIX_SOCKETS #undef OF_HAVE__THREAD_LOCAL #undef OF_HAVE___THREAD #undef OF_NINTENDO_3DS #undef OF_NINTENDO_DS #undef OF_NINTENDO_SWITCH #undef OF_NO_SHARED #undef OF_OBJFW_RUNTIME #undef OF_UNIVERSAL #undef OF_WII #undef OF_WII_U objfw-1.1.6/src/platform.h000066400000000000000000000111221465614216400154200ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "objfw-defs.h" /* Required to build universal binaries on OS X */ #ifdef OF_UNIVERSAL # if __BIG_ENDIAN__ # define OF_BIG_ENDIAN # define OF_FLOAT_BIG_ENDIAN # elif !__LITTLE_ENDIAN__ # error OF_UNIVERSAL defined, but neither __BIG_ENDIAN__ nor __LITTLE_ENDIAN__! # endif #endif #if (defined(__x86_64__) || defined(__amd64__)) && defined(__LP64__) # define OF_AMD64 #elif defined(__i386__) # define OF_X86 #elif defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) # define OF_POWERPC64 #elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) # define OF_POWERPC #elif defined(__arm64__) || defined(__aarch64__) || defined(__ARM64_ARCH_8__) # define OF_ARM64 #elif defined(__arm__) || defined(__ARM__) # define OF_ARM # if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || \ defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || \ defined(__ARM_ARCH_7EM__) # define OF_ARMV7 # endif # if defined(OF_ARMV7) || defined(__ARM_ARCH_6__) || \ defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || \ defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || \ defined(__ARM_ARCH_6T2__) # define OF_ARMV6 # endif #elif defined(_MIPS_SIM) # if _MIPS_SIM == _ABI64 # define OF_MIPS64 # define OF_MIPS64_N64 # elif _MIPS_SIM == _ABIN32 # define OF_MIPS64 # define OF_MIPS64_N32 # elif _MIPS_SIM == _ABIO32 # define OF_MIPS # define OF_MIPS_O32 # endif #elif defined(__mips_eabi) && _MIPS_SZPTR == 32 # define OF_MIPS # define OF_MIPS_EABI #elif defined(__sparc64__) || (defined(__sparc__) && defined(__arch64__)) # define OF_SPARC64 #elif defined(__sparc__) && !defined(__arch64__) # define OF_SPARC #elif defined(__hppa64__) || defined(_PA_RISC2_0) # define OF_PA_RISC_2_0 #elif defined(__hppa__) || defined(_PA_RISC1_0) || defined(_PA_RISC1_1) # define OF_PA_RISC #elif defined(__ia64__) || defined(__IA64__) # define OF_ITANIUM #elif defined(__m68k__) # define OF_M68K # ifdef __mc68060__ # define OF_M68060 # endif # if defined(__mc68040__) || defined(OF_M68060) # define OF_M68040 # endif # if defined(__mc68030__) || defined(OF_M68040) # define OF_M68030 # endif # if defined(__mc68020__) || defined(OF_M68030) # define OF_M68020 # endif # if defined(__mc68010__) || defined(OF_M68020) # define OF_M68010 # endif #elif defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen == 64 # define OF_RISC_V_64 #elif defined(__riscv) # define OF_RISC_V #elif defined(__s390x__) # define OF_S390X #elif defined(__s390__) # define OF_S390 #elif defined(__e2k__) # define OF_ELBRUS_2000 #endif #if defined(__APPLE__) # include # if (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) || \ (defined(TARGET_OS_SIMULATOR) && TARGET_OS_SIMULATOR) # define OF_IOS # else # define OF_MACOS # endif #elif defined(__linux__) # define OF_LINUX #elif defined(_WIN32) # define OF_WINDOWS #elif defined(__FreeBSD__) # define OF_FREEBSD #elif defined(__NetBSD__) # define OF_NETBSD #elif defined(__OpenBSD__) # define OF_OPENBSD #elif defined(__DragonFly__) # define OF_DRAGONFLYBSD #elif defined(__ANDROID__) # define OF_ANDROID #elif defined(__HAIKU__) # define OF_HAIKU #elif defined(_AIX) # define OF_AIX #elif defined(__MORPHOS__) # define OF_MORPHOS # define OF_AMIGAOS #elif defined(__amigaos4__) # define OF_AMIGAOS4 # define OF_AMIGAOS #elif defined(__amigaos__) # define OF_AMIGAOS_M68K # define OF_AMIGAOS #elif defined(__sun__) # define OF_SOLARIS #elif defined(__QNX__) # define OF_QNX #elif defined(__hpux__) # define OF_HPUX #elif defined(_PSP) # define OF_PSP #elif defined(__DJGPP__) # define OF_DJGPP # define OF_MSDOS #elif defined(__riscos__) # define OF_ACORN_RISC_OS #elif defined(__MINT__) # define OF_MINT #elif defined(__gnu_hurd__) # define OF_HURD #endif #ifdef __GLIBC__ # define OF_GLIBC #endif #if defined(__ELF__) # define OF_ELF #elif defined(__MACH__) # define OF_MACH_O #endif #if defined(__PIC__) || defined(__pic__) # define OF_PIC #endif objfw-1.1.6/src/platform/000077500000000000000000000000001465614216400152525ustar00rootroot00000000000000objfw-1.1.6/src/platform/AmigaOS/000077500000000000000000000000001465614216400165325ustar00rootroot00000000000000objfw-1.1.6/src/platform/AmigaOS/OFPlainCondition.m000066400000000000000000000125311465614216400220510ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFPlainCondition.h" #define Class IntuitionClass #include #include #ifndef OF_AMIGAOS4 # include #endif #undef Class int OFPlainConditionNew(OFPlainCondition *condition) { condition->waitingTasks = NULL; return 0; } int OFPlainConditionSignal(OFPlainCondition *condition) { Forbid(); @try { if (condition->waitingTasks == NULL) return 0; Signal(condition->waitingTasks->task, (1ul << condition->waitingTasks->sigBit)); condition->waitingTasks = condition->waitingTasks->next; } @finally { Permit(); } return 0; } int OFPlainConditionBroadcast(OFPlainCondition *condition) { Forbid(); @try { if (condition->waitingTasks == NULL) return 0; while (condition->waitingTasks != NULL) { Signal(condition->waitingTasks->task, (1ul << condition->waitingTasks->sigBit)); condition->waitingTasks = condition->waitingTasks->next; } } @finally { Permit(); } return 0; } int OFPlainConditionWait(OFPlainCondition *condition, OFPlainMutex *mutex) { ULONG signalMask = 0; return OFPlainConditionWaitOrExecSignal(condition, mutex, &signalMask); } int OFPlainConditionWaitOrExecSignal(OFPlainCondition *condition, OFPlainMutex *mutex, ULONG *signalMask) { struct _OFPlainConditionWaitingTask waitingTask = { .task = FindTask(NULL), .sigBit = AllocSignal(-1) }; int error = 0; ULONG mask; if (waitingTask.sigBit == -1) return EAGAIN; Forbid(); if ((error = OFPlainMutexUnlock(mutex)) != 0) { FreeSignal(waitingTask.sigBit); return error; } waitingTask.next = condition->waitingTasks; condition->waitingTasks = &waitingTask; mask = Wait((1ul << waitingTask.sigBit) | *signalMask); if (mask & (1ul << waitingTask.sigBit) || (*signalMask &= mask)) error = OFPlainMutexLock(mutex); else /* * This should not happen - it means something interrupted the * Wait(), so the best we can do is return EINTR. */ error = EINTR; FreeSignal(waitingTask.sigBit); Permit(); return error; } int OFPlainConditionTimedWait(OFPlainCondition *condition, OFPlainMutex *mutex, OFTimeInterval timeout) { ULONG signalMask = 0; return OFPlainConditionTimedWaitOrExecSignal(condition, mutex, timeout, &signalMask); } int OFPlainConditionTimedWaitOrExecSignal(OFPlainCondition *condition, OFPlainMutex *mutex, OFTimeInterval timeout, ULONG *signalMask) { struct _OFPlainConditionWaitingTask waitingTask = { .task = FindTask(NULL), .sigBit = AllocSignal(-1) }; struct MsgPort port = { .mp_Node = { .ln_Type = NT_MSGPORT }, .mp_Flags = PA_SIGNAL, .mp_SigTask = waitingTask.task, .mp_SigBit = AllocSignal(-1) }; #ifdef OF_AMIGAOS4 struct TimeRequest request = { .Request = { #else struct timerequest request = { .tr_node = { #endif .io_Message = { .mn_Node = { .ln_Type = NT_MESSAGE }, .mn_ReplyPort = &port, .mn_Length = sizeof(request) }, .io_Command = TR_ADDREQUEST }, #ifdef OF_AMIGAOS4 .Time = { .Seconds = (ULONG)timeout, .Microseconds = (timeout - request.Time.Seconds) * 1000000 #else .tr_time = { .tv_sec = (ULONG)timeout, .tv_micro = (timeout - request.tr_time.tv_sec) * 1000000 #endif } }; int error = 0; ULONG mask; NewList(&port.mp_MsgList); if (waitingTask.sigBit == -1 || port.mp_SigBit == -1) { error = EAGAIN; goto fail; } if (OpenDevice("timer.device", UNIT_MICROHZ, (struct IORequest *)&request, 0) != 0) { error = EAGAIN; goto fail; } Forbid(); if ((error = OFPlainMutexUnlock(mutex)) != 0) { Permit(); goto fail; } waitingTask.next = condition->waitingTasks; condition->waitingTasks = &waitingTask; SendIO((struct IORequest *)&request); mask = Wait((1ul << waitingTask.sigBit) | (1ul << port.mp_SigBit) | *signalMask); if (mask & (1ul << waitingTask.sigBit) || (*signalMask &= mask)) error = OFPlainMutexLock(mutex); else if (mask & (1ul << port.mp_SigBit)) error = ETIMEDOUT; else /* * This should not happen - it means something interrupted the * Wait(), so the best we can do is return EINTR. */ error = EINTR; condition->waitingTasks = waitingTask.next; if (!CheckIO((struct IORequest *)&request)) { AbortIO((struct IORequest *)&request); WaitIO((struct IORequest *)&request); } CloseDevice((struct IORequest *)&request); Permit(); fail: if (waitingTask.sigBit != -1) FreeSignal(waitingTask.sigBit); if (port.mp_SigBit != -1) FreeSignal(port.mp_SigBit); return error; } int OFPlainConditionFree(OFPlainCondition *condition) { Forbid(); @try { if (condition->waitingTasks != NULL) return EBUSY; } @finally { Permit(); } return 0; } objfw-1.1.6/src/platform/AmigaOS/OFPlainMutex.m000066400000000000000000000034001465614216400212200ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFPlainMutex.h" #define Class IntuitionClass #include #undef Class int OFPlainMutexNew(OFPlainMutex *mutex) { InitSemaphore(mutex); return 0; } int OFPlainMutexLock(OFPlainMutex *mutex) { ObtainSemaphore(mutex); return 0; } int OFPlainMutexTryLock(OFPlainMutex *mutex) { if (!AttemptSemaphore(mutex)) return EBUSY; return 0; } int OFPlainMutexUnlock(OFPlainMutex *mutex) { ReleaseSemaphore(mutex); return 0; } int OFPlainMutexFree(OFPlainMutex *mutex) { return 0; } int OFPlainRecursiveMutexNew(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexNew(rmutex); } int OFPlainRecursiveMutexLock(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexLock(rmutex); } int OFPlainRecursiveMutexTryLock(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexTryLock(rmutex); } int OFPlainRecursiveMutexUnlock(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexUnlock(rmutex); } int OFPlainRecursiveMutexFree(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexFree(rmutex); } objfw-1.1.6/src/platform/AmigaOS/OFPlainThread.m000066400000000000000000000112251465614216400213310ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFPlainThread.h" #import "OFData.h" #import "OFString.h" #import "OFTLSKey.h" #define Class IntuitionClass #include #include #include #undef Class #ifndef OF_MORPHOS extern void OFTLSKeyThreadExited(void); #endif static OFTLSKey threadKey; OF_CONSTRUCTOR() { OFEnsure(OFTLSKeyNew(&threadKey) == 0); } static void functionWrapper(void) { bool detached = false; OFPlainThread thread = (OFPlainThread)((struct Process *)FindTask(NULL))->pr_ExitData; OFEnsure(OFTLSKeySet(threadKey, thread) == 0); thread->function(thread->object); ObtainSemaphore(&thread->semaphore); @try { thread->done = true; #ifndef OF_MORPHOS OFTLSKeyThreadExited(); #endif if (thread->detached) detached = true; else if (thread->joinTask != NULL) Signal(thread->joinTask, (1ul << thread->joinSigBit)); } @finally { ReleaseSemaphore(&thread->semaphore); } if (detached) free(thread); } int OFPlainThreadAttributesInit(OFPlainThreadAttributes *attr) { attr->priority = 0; attr->stackSize = 0; return 0; } int OFPlainThreadNew(OFPlainThread *thread, const char *name, void (*function)(id), id object, const OFPlainThreadAttributes *attr) { OFMutableData *tags = nil; if ((*thread = calloc(1, sizeof(**thread))) == NULL) return ENOMEM; @try { (*thread)->function = function; (*thread)->object = object; InitSemaphore(&(*thread)->semaphore); tags = [[OFMutableData alloc] initWithItemSize: sizeof(struct TagItem) capacity: 12]; #define ADD_TAG(tag, data) \ { \ struct TagItem t = { \ .ti_Tag = tag, \ .ti_Data = data \ }; \ [tags addItem: &t]; \ } ADD_TAG(NP_Entry, (ULONG)functionWrapper) ADD_TAG(NP_ExitData, (ULONG)*thread) #ifdef OF_AMIGAOS4 ADD_TAG(NP_Child, TRUE) #endif #ifdef OF_MORPHOS ADD_TAG(NP_CodeType, CODETYPE_PPC); #endif if (name != NULL) ADD_TAG(NP_Name, (ULONG)name); ADD_TAG(NP_Input, ((struct Process *)FindTask(NULL))->pr_CIS) ADD_TAG(NP_Output, ((struct Process *)FindTask(NULL))->pr_COS) ADD_TAG(NP_Error, ((struct Process *)FindTask(NULL))->pr_CES) ADD_TAG(NP_CloseInput, FALSE) ADD_TAG(NP_CloseOutput, FALSE) ADD_TAG(NP_CloseError, FALSE) if (attr != NULL && attr->priority != 0) { if (attr->priority < 1 || attr->priority > 1) return EINVAL; /* * -1 should be -128 (lowest possible priority) while * +1 should be +127 (highest possible priority). */ ADD_TAG(NP_Priority, (attr->priority > 0 ? attr->priority * 127 : attr->priority * 128)) } if (attr != NULL && attr->stackSize != 0) ADD_TAG(NP_StackSize, attr->stackSize) else ADD_TAG(NP_StackSize, ((struct Process *)FindTask(NULL))->pr_StackSize) ADD_TAG(TAG_DONE, 0) #undef ADD_TAG (*thread)->task = (struct Task *)CreateNewProc(tags.items); if ((*thread)->task == NULL) { free(*thread); return EAGAIN; } } @catch (id e) { free(*thread); @throw e; } @finally { [tags release]; } return 0; } OFPlainThread OFCurrentPlainThread(void) { return OFTLSKeyGet(threadKey); } bool OFPlainThreadIsCurrent(OFPlainThread thread) { return (thread->task == FindTask(NULL)); } int OFPlainThreadJoin(OFPlainThread thread) { ObtainSemaphore(&thread->semaphore); if (thread->done) { ReleaseSemaphore(&thread->semaphore); free(thread); return 0; } @try { if (thread->detached || thread->joinTask != NULL) return EINVAL; if ((thread->joinSigBit = AllocSignal(-1)) == -1) return EAGAIN; thread->joinTask = FindTask(NULL); } @finally { ReleaseSemaphore(&thread->semaphore); } Wait(1ul << thread->joinSigBit); FreeSignal(thread->joinSigBit); OFAssert(thread->done); free(thread); return 0; } int OFPlainThreadDetach(OFPlainThread thread) { ObtainSemaphore(&thread->semaphore); if (thread->done) free(thread); else thread->detached = true; ReleaseSemaphore(&thread->semaphore); return 0; } void OFSetThreadName(const char *name) { } objfw-1.1.6/src/platform/AmigaOS/OFString+PathAdditions.m000066400000000000000000000205221465614216400231330ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFString+PathAdditions.h" #import "OFArray.h" #import "OFFileIRIHandler.h" #import "OFOutOfRangeException.h" int _OFString_PathAdditions_reference; @implementation OFString (PathAdditions) + (OFString *)pathWithComponents: (OFArray *)components { OFMutableString *ret = [OFMutableString string]; void *pool = objc_autoreleasePoolPush(); bool firstAfterDevice = true; for (OFString *component in components) { if (component.length == 0) continue; if (!firstAfterDevice) [ret appendString: @"/"]; [ret appendString: component]; if (![component hasSuffix: @":"]) firstAfterDevice = false; } [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } - (bool)isAbsolutePath { return [self containsString: @":"]; } - (OFArray *)pathComponents { OFMutableArray OF_GENERIC(OFString *) *ret = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); const char *cString = self.UTF8String; size_t i, last = 0, cStringLength = self.UTF8StringLength; if (cStringLength == 0) { objc_autoreleasePoolPop(pool); return ret; } for (i = 0; i < cStringLength; i++) { if (cString[i] == '/') { if (i - last != 0) [ret addObject: [OFString stringWithUTF8String: cString + last length: i - last]]; else [ret addObject: @"/"]; last = i + 1; } else if (cString[i] == ':') { [ret addObject: [OFString stringWithUTF8String: cString + last length: i - last + 1]]; last = i + 1; } } if (i - last != 0) [ret addObject: [OFString stringWithUTF8String: cString + last length: i - last]]; [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } - (OFString *)lastPathComponent { /* * AmigaOS needs the full parsing to determine the last path component. * This could be optimized by not creating the temporary objects, * though. */ void *pool = objc_autoreleasePoolPush(); OFString *ret = self.pathComponents.lastObject; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)pathExtension { void *pool = objc_autoreleasePoolPush(); OFString *ret, *fileName; size_t pos; fileName = self.lastPathComponent; pos = [fileName rangeOfString: @"." options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return @""; } ret = [fileName substringFromIndex: pos + 1]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)stringByDeletingLastPathComponent { /* * AmigaOS needs the full parsing to delete the last path component. * This could be optimized, though. */ void *pool = objc_autoreleasePoolPush(); OFArray OF_GENERIC(OFString *) *components = self.pathComponents; size_t count = components.count; OFString *ret; if (count < 2) { if ([components.firstObject hasSuffix: @":"]) { ret = [components.firstObject retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } objc_autoreleasePoolPop(pool); return @""; } components = [components objectsInRange: OFMakeRange(0, components.count - 1)]; ret = [OFString pathWithComponents: components]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)stringByDeletingPathExtension { void *pool; OFMutableArray OF_GENERIC(OFString *) *components; OFString *ret, *fileName; size_t pos; if (self.length == 0) return [[self copy] autorelease]; pool = objc_autoreleasePoolPush(); components = [[self.pathComponents mutableCopy] autorelease]; fileName = components.lastObject; pos = [fileName rangeOfString: @"." options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return [[self copy] autorelease]; } fileName = [fileName substringToIndex: pos]; [components replaceObjectAtIndex: components.count - 1 withObject: fileName]; ret = [OFString pathWithComponents: components]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)stringByStandardizingPath { void *pool = objc_autoreleasePoolPush(); OFArray OF_GENERIC(OFString *) *components; OFMutableArray OF_GENERIC(OFString *) *array; OFString *ret; bool done = false; if (self.length == 0) return @""; components = self.pathComponents; if (components.count == 1) { objc_autoreleasePoolPop(pool); return [[self copy] autorelease]; } array = [[components mutableCopy] autorelease]; while (!done) { size_t length = array.count; done = true; for (size_t i = 0; i < length; i++) { OFString *component = [array objectAtIndex: i]; OFString *parent = (i > 0 ? [array objectAtIndex: i - 1] : 0); if (component.length == 0) { [array removeObjectAtIndex: i]; done = false; break; } if ([component isEqual: @"/"] && parent != nil && ![parent isEqual: @"/"]) { [array removeObjectsInRange: OFMakeRange(i - 1, 2)]; done = false; break; } } } ret = [OFString pathWithComponents: array]; if ([self hasSuffix: @"/"]) ret = [ret stringByAppendingString: @"/"]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)stringByAppendingPathComponent: (OFString *)component { if (self.length == 0) return component; if ([self hasSuffix: @"/"] || [self hasSuffix: @":"]) return [self stringByAppendingString: component]; else { OFMutableString *ret = [[self mutableCopy] autorelease]; [ret appendString: @"/"]; [ret appendString: component]; [ret makeImmutable]; return ret; } } - (OFString *)stringByAppendingPathExtension: (OFString *)extension { if ([self hasSuffix: @"/"]) { void *pool = objc_autoreleasePoolPush(); OFMutableArray *components; OFString *fileName, *ret; components = [[self.pathComponents mutableCopy] autorelease]; fileName = [components.lastObject stringByAppendingFormat: @".%@", extension]; [components replaceObjectAtIndex: components.count - 1 withObject: fileName]; ret = [[OFString pathWithComponents: components] retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } else return [self stringByAppendingFormat: @".%@", extension]; } - (bool)of_isDirectoryPath { return ([self hasSuffix: @"/"] || [self hasSuffix: @":"] || [OFFileIRIHandler of_directoryExistsAtPath: self]); } - (OFString *)of_pathToIRIPathWithPercentEncodedHost: (OFString **)percentEncodedHost { OFArray OF_GENERIC(OFString *) *components = self.pathComponents; OFMutableString *ret = [OFMutableString string]; for (OFString *component in components) { if (component.length == 0) continue; if ([component isEqual: @"/"]) [ret appendString: @"/.."]; else { [ret appendString: @"/"]; [ret appendString: component]; } } [ret makeImmutable]; return ret; } - (OFString *)of_IRIPathToPathWithPercentEncodedHost: (OFString *)percentEncodedHost { OFString *path = self; if (path.length > 1 && [path hasSuffix: @"/"]) path = [path substringToIndex: path.length - 1]; OFMutableArray OF_GENERIC(OFString *) *components; size_t count; path = [path substringFromIndex: 1]; components = [[[path componentsSeparatedByString: @"/"] mutableCopy] autorelease]; count = components.count; for (size_t i = 0; i < count; i++) { OFString *component = [components objectAtIndex: i]; if ([component isEqual: @"."]) { [components removeObjectAtIndex: i]; count--; i--; continue; } if ([component isEqual: @".."]) [components replaceObjectAtIndex: i withObject: @"/"]; } return [OFString pathWithComponents: components]; } - (OFString *)of_pathComponentToIRIPathComponent { return self; } @end objfw-1.1.6/src/platform/AmigaOS/OFTLSKey.m000066400000000000000000000066671465614216400202670ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFTLSKey.h" #define Class IntuitionClass #include #include #undef Class /* * As we use this file in both the runtime and ObjFW, and since AmigaOS always * has the runtime, use the hashtable from the runtime. */ #import "runtime/private.h" static OFTLSKey firstKey = NULL, lastKey = NULL; static struct SignalSemaphore semaphore; static bool semaphoreInitialized = false; static uint32_t hashFunc(const void *ptr) { return (uint32_t)(uintptr_t)ptr; } static bool equalFunc(const void *ptr1, const void *ptr2) { return (ptr1 == ptr2); } OF_CONSTRUCTOR() { if (!semaphoreInitialized) { InitSemaphore(&semaphore); semaphoreInitialized = true; } } int OFTLSKeyNew(OFTLSKey *key) { if (!semaphoreInitialized) { /* * We might be called from another constructor, while ours has * not run yet. This is safe, as the constructor is definitely * run before a thread is spawned. */ InitSemaphore(&semaphore); semaphoreInitialized = true; } if ((*key = malloc(sizeof(**key))) == NULL) return ENOMEM; (*key)->table = NULL; ObtainSemaphore(&semaphore); @try { (*key)->next = NULL; (*key)->previous = lastKey; if (lastKey != NULL) lastKey->next = *key; lastKey = *key; if (firstKey == NULL) firstKey = *key; } @finally { ReleaseSemaphore(&semaphore); } /* We create the hash table lazily. */ return 0; } int OFTLSKeyFree(OFTLSKey key) { ObtainSemaphore(&semaphore); @try { if (key->previous != NULL) key->previous->next = key->next; if (key->next != NULL) key->next->previous = key->previous; if (firstKey == key) firstKey = key->next; if (lastKey == key) lastKey = key->previous; objc_hashtable_free(key->table); free(key); } @finally { ReleaseSemaphore(&semaphore); } return 0; } void * OFTLSKeyGet(OFTLSKey key) { void *ret; ObtainSemaphore(&semaphore); @try { if (key->table == NULL) return NULL; ret = objc_hashtable_get(key->table, FindTask(NULL)); } @finally { ReleaseSemaphore(&semaphore); } return ret; } int OFTLSKeySet(OFTLSKey key, void *ptr) { ObtainSemaphore(&semaphore); @try { struct Task *task = FindTask(NULL); if (key->table == NULL) key->table = objc_hashtable_new(hashFunc, equalFunc, 2); if (ptr == NULL) objc_hashtable_delete(key->table, task); else objc_hashtable_set(key->table, task, ptr); } @finally { ReleaseSemaphore(&semaphore); } return 0; } void OFTLSKeyThreadExited(void) { ObtainSemaphore(&semaphore); @try { struct Task *task = FindTask(NULL); for (OFTLSKey iter = firstKey; iter != NULL; iter = iter->next) if (iter->table != NULL) objc_hashtable_delete(iter->table, task); } @finally { ReleaseSemaphore(&semaphore); } } objfw-1.1.6/src/platform/GCC4.7/000077500000000000000000000000001465614216400160775ustar00rootroot00000000000000objfw-1.1.6/src/platform/GCC4.7/OFAtomic.h000066400000000000000000000074761465614216400177270ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ static OF_INLINE int OFAtomicIntAdd(volatile int *_Nonnull p, int i) { return __atomic_add_fetch(p, i, __ATOMIC_RELAXED); } static OF_INLINE int32_t OFAtomicInt32Add(volatile int32_t *_Nonnull p, int32_t i) { return __atomic_add_fetch(p, i, __ATOMIC_RELAXED); } static OF_INLINE void *_Nullable OFAtomicPointerAdd(void *volatile _Nullable *_Nonnull p, intptr_t i) { return __atomic_add_fetch(p, i, __ATOMIC_RELAXED); } static OF_INLINE int OFAtomicIntSubtract(volatile int *_Nonnull p, int i) { return __atomic_sub_fetch(p, i, __ATOMIC_RELAXED); } static OF_INLINE int32_t OFAtomicInt32Subtract(volatile int32_t *_Nonnull p, int32_t i) { return __atomic_sub_fetch(p, i, __ATOMIC_RELAXED); } static OF_INLINE void *_Nullable OFAtomicPointerSubtract(void *volatile _Nullable *_Nonnull p, intptr_t i) { return __atomic_sub_fetch(p, i, __ATOMIC_RELAXED); } static OF_INLINE int OFAtomicIntIncrease(volatile int *_Nonnull p) { return __atomic_add_fetch(p, 1, __ATOMIC_RELAXED); } static OF_INLINE int32_t OFAtomicInt32Increase(volatile int32_t *_Nonnull p) { return __atomic_add_fetch(p, 1, __ATOMIC_RELAXED); } static OF_INLINE int OFAtomicIntDecrease(volatile int *_Nonnull p) { return __atomic_sub_fetch(p, 1, __ATOMIC_RELAXED); } static OF_INLINE int32_t OFAtomicInt32Decrease(volatile int32_t *_Nonnull p) { return __atomic_sub_fetch(p, 1, __ATOMIC_RELAXED); } static OF_INLINE unsigned int OFAtomicIntOr(volatile unsigned int *_Nonnull p, unsigned int i) { return __atomic_or_fetch(p, i, __ATOMIC_RELAXED); } static OF_INLINE uint32_t OFAtomicInt32Or(volatile uint32_t *_Nonnull p, uint32_t i) { return __atomic_or_fetch(p, i, __ATOMIC_RELAXED); } static OF_INLINE unsigned int OFAtomicIntAnd(volatile unsigned int *_Nonnull p, unsigned int i) { return __atomic_and_fetch(p, i, __ATOMIC_RELAXED); } static OF_INLINE uint32_t OFAtomicInt32And(volatile uint32_t *_Nonnull p, uint32_t i) { return __atomic_and_fetch(p, i, __ATOMIC_RELAXED); } static OF_INLINE unsigned int OFAtomicIntXor(volatile unsigned int *_Nonnull p, unsigned int i) { return __atomic_xor_fetch(p, i, __ATOMIC_RELAXED); } static OF_INLINE uint32_t OFAtomicInt32Xor(volatile uint32_t *_Nonnull p, uint32_t i) { return __atomic_xor_fetch(p, i, __ATOMIC_RELAXED); } static OF_INLINE bool OFAtomicIntCompareAndSwap(volatile int *_Nonnull p, int o, int n) { return __atomic_compare_exchange(p, &o, &n, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED); } static OF_INLINE bool OFAtomicInt32CompareAndSwap(volatile int32_t *_Nonnull p, int32_t o, int32_t n) { return __atomic_compare_exchange(p, &o, &n, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED); } static OF_INLINE bool OFAtomicPointerCompareAndSwap(void *volatile _Nullable *_Nonnull p, void *_Nullable o, void *_Nullable n) { return __atomic_compare_exchange(p, &o, &n, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED); } static OF_INLINE void OFMemoryBarrier(void) { __atomic_thread_fence(__ATOMIC_SEQ_CST); } static OF_INLINE void OFAcquireMemoryBarrier(void) { __atomic_thread_fence(__ATOMIC_ACQUIRE); } static OF_INLINE void OFReleaseMemoryBarrier(void) { __atomic_thread_fence(__ATOMIC_RELEASE); } objfw-1.1.6/src/platform/GCC4/000077500000000000000000000000001465614216400157325ustar00rootroot00000000000000objfw-1.1.6/src/platform/GCC4/OFAtomic.h000066400000000000000000000066101465614216400175470ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ static OF_INLINE int OFAtomicIntAdd(volatile int *_Nonnull p, int i) { return __sync_add_and_fetch(p, i); } static OF_INLINE int32_t OFAtomicInt32Add(volatile int32_t *_Nonnull p, int32_t i) { return __sync_add_and_fetch(p, i); } static OF_INLINE void *_Nullable OFAtomicPointerAdd(void *volatile _Nullable *_Nonnull p, intptr_t i) { return __sync_add_and_fetch(p, (void *)i); } static OF_INLINE int OFAtomicIntSubtract(volatile int *_Nonnull p, int i) { return __sync_sub_and_fetch(p, i); } static OF_INLINE int32_t OFAtomicInt32Subtract(volatile int32_t *_Nonnull p, int32_t i) { return __sync_sub_and_fetch(p, i); } static OF_INLINE void *_Nullable OFAtomicPointerSubtract(void *volatile _Nullable *_Nonnull p, intptr_t i) { return __sync_sub_and_fetch(p, (void *)i); } static OF_INLINE int OFAtomicIntIncrease(volatile int *_Nonnull p) { return __sync_add_and_fetch(p, 1); } static OF_INLINE int32_t OFAtomicInt32Increase(volatile int32_t *_Nonnull p) { return __sync_add_and_fetch(p, 1); } static OF_INLINE int OFAtomicIntDecrease(volatile int *_Nonnull p) { return __sync_sub_and_fetch(p, 1); } static OF_INLINE int32_t OFAtomicInt32Decrease(volatile int32_t *_Nonnull p) { return __sync_sub_and_fetch(p, 1); } static OF_INLINE unsigned int OFAtomicIntOr(volatile unsigned int *_Nonnull p, unsigned int i) { return __sync_or_and_fetch(p, i); } static OF_INLINE uint32_t OFAtomicInt32Or(volatile uint32_t *_Nonnull p, uint32_t i) { return __sync_or_and_fetch(p, i); } static OF_INLINE unsigned int OFAtomicIntAnd(volatile unsigned int *_Nonnull p, unsigned int i) { return __sync_and_and_fetch(p, i); } static OF_INLINE uint32_t OFAtomicInt32And(volatile uint32_t *_Nonnull p, uint32_t i) { return __sync_and_and_fetch(p, i); } static OF_INLINE unsigned int OFAtomicIntXor(volatile unsigned int *_Nonnull p, unsigned int i) { return __sync_xor_and_fetch(p, i); } static OF_INLINE uint32_t OFAtomicInt32Xor(volatile uint32_t *_Nonnull p, uint32_t i) { return __sync_xor_and_fetch(p, i); } static OF_INLINE bool OFAtomicIntCompareAndSwap(volatile int *_Nonnull p, int o, int n) { return __sync_bool_compare_and_swap(p, o, n); } static OF_INLINE bool OFAtomicInt32CompareAndSwap(volatile int32_t *_Nonnull p, int32_t o, int32_t n) { return __sync_bool_compare_and_swap(p, o, n); } static OF_INLINE bool OFAtomicPointerCompareAndSwap(void *volatile _Nullable *_Nonnull p, void *_Nullable o, void *_Nullable n) { return __sync_bool_compare_and_swap(p, o, n); } static OF_INLINE void OFMemoryBarrier(void) { __sync_synchronize(); } static OF_INLINE void OFAcquireMemoryBarrier(void) { __sync_synchronize(); } static OF_INLINE void OFReleaseMemoryBarrier(void) { __sync_synchronize(); } objfw-1.1.6/src/platform/MorphOS/000077500000000000000000000000001465614216400166015ustar00rootroot00000000000000objfw-1.1.6/src/platform/MorphOS/OFTLSKey.m000066400000000000000000000017121465614216400203200ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFTLSKey.h" int OFTLSKeyNew(OFTLSKey *key) { *key = TLSAllocA(NULL); if (*key == TLS_INVALID_INDEX) return EAGAIN; return 0; } int OFTLSKeyFree(OFTLSKey key) { return (TLSFree(key) ? 0 : EINVAL); } objfw-1.1.6/src/platform/POSIX/000077500000000000000000000000001465614216400161545ustar00rootroot00000000000000objfw-1.1.6/src/platform/POSIX/OFPlainCondition.m000066400000000000000000000030741465614216400214750ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFPlainCondition.h" int OFPlainConditionNew(OFPlainCondition *condition) { return pthread_cond_init(condition, NULL); } int OFPlainConditionSignal(OFPlainCondition *condition) { return pthread_cond_signal(condition); } int OFPlainConditionBroadcast(OFPlainCondition *condition) { return pthread_cond_broadcast(condition); } int OFPlainConditionWait(OFPlainCondition *condition, OFPlainMutex *mutex) { return pthread_cond_wait(condition, mutex); } int OFPlainConditionTimedWait(OFPlainCondition *condition, OFPlainMutex *mutex, OFTimeInterval timeout) { struct timespec ts; ts.tv_sec = (time_t)timeout; ts.tv_nsec = (long)((timeout - ts.tv_sec) * 1000000000); return pthread_cond_timedwait(condition, mutex, &ts); } int OFPlainConditionFree(OFPlainCondition *condition) { return pthread_cond_destroy(condition); } objfw-1.1.6/src/platform/POSIX/OFPlainMutex.m000066400000000000000000000075121465614216400206520ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFPlainMutex.h" int OFPlainMutexNew(OFPlainMutex *mutex) { return pthread_mutex_init(mutex, NULL); } int OFPlainMutexLock(OFPlainMutex *mutex) { return pthread_mutex_lock(mutex); } int OFPlainMutexTryLock(OFPlainMutex *mutex) { return pthread_mutex_trylock(mutex); } int OFPlainMutexUnlock(OFPlainMutex *mutex) { return pthread_mutex_unlock(mutex); } int OFPlainMutexFree(OFPlainMutex *mutex) { return pthread_mutex_destroy(mutex); } #ifdef OF_HAVE_RECURSIVE_PTHREAD_MUTEXES int OFPlainRecursiveMutexNew(OFPlainRecursiveMutex *rmutex) { int error; pthread_mutexattr_t attr; if ((error = pthread_mutexattr_init(&attr)) != 0) return error; if ((error = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE)) != 0) return error; if ((error = pthread_mutex_init(rmutex, &attr)) != 0) return error; if ((error = pthread_mutexattr_destroy(&attr)) != 0) return error; return 0; } int OFPlainRecursiveMutexLock(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexLock(rmutex); } int OFPlainRecursiveMutexTryLock(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexTryLock(rmutex); } int OFPlainRecursiveMutexUnlock(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexUnlock(rmutex); } int OFPlainRecursiveMutexFree(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexFree(rmutex); } #else int OFPlainRecursiveMutexNew(OFPlainRecursiveMutex *rmutex) { int error; if ((error = OFPlainMutexNew(&rmutex->mutex)) != 0) return error; if ((error = OFTLSKeyNew(&rmutex->count)) != 0) return error; return 0; } int OFPlainRecursiveMutexLock(OFPlainRecursiveMutex *rmutex) { uintptr_t count = (uintptr_t)OFTLSKeyGet(rmutex->count); int error; if (count > 0) { if ((error = OFTLSKeySet(rmutex->count, (void *)(count + 1))) != 0) return error; return 0; } if ((error = OFPlainMutexLock(&rmutex->mutex)) != 0) return error; if ((error = OFTLSKeySet(rmutex->count, (void *)1)) != 0) { OFPlainMutexUnlock(&rmutex->mutex); return error; } return 0; } int OFPlainRecursiveMutexTryLock(OFPlainRecursiveMutex *rmutex) { uintptr_t count = (uintptr_t)OFTLSKeyGet(rmutex->count); int error; if (count > 0) { if ((error = OFTLSKeySet(rmutex->count, (void *)(count + 1))) != 0) return error; return 0; } if ((error = OFPlainMutexTryLock(&rmutex->mutex)) != 0) return error; if ((error = OFTLSKeySet(rmutex->count, (void *)1)) != 0) { OFPlainMutexUnlock(&rmutex->mutex); return error; } return 0; } int OFPlainRecursiveMutexUnlock(OFPlainRecursiveMutex *rmutex) { uintptr_t count = (uintptr_t)OFTLSKeyGet(rmutex->count); int error; if (count > 1) { if ((error = OFTLSKeySet(rmutex->count, (void *)(count - 1))) != 0) return error; return 0; } if ((error = OFTLSKeySet(rmutex->count, (void *)0)) != 0) return error; if ((error = OFPlainMutexUnlock(&rmutex->mutex)) != 0) return error; return 0; } int OFPlainRecursiveMutexFree(OFPlainRecursiveMutex *rmutex) { int error; if ((error = OFPlainMutexFree(&rmutex->mutex)) != 0) return error; if ((error = OFTLSKeyFree(rmutex->count)) != 0) return error; return 0; } #endif objfw-1.1.6/src/platform/POSIX/OFPlainThread.m000066400000000000000000000111051465614216400207500ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #ifdef HAVE_PTHREAD_NP_H # include #endif #ifdef OF_HAIKU # include #endif #import "OFPlainThread.h" #import "macros.h" static int minPrio = 0, maxPrio = 0, normalPrio = 0; struct ThreadContext { void (*function)(id object); id object; const char *name; }; /* * This is done here to make sure this is done as early as possible in the main * thread. */ OF_CONSTRUCTOR() { pthread_attr_t attr; if (pthread_attr_init(&attr) == 0) { #ifdef HAVE_PTHREAD_ATTR_GETSCHEDPOLICY int policy; #endif struct sched_param param; #ifdef HAVE_PTHREAD_ATTR_GETSCHEDPOLICY if (pthread_attr_getschedpolicy(&attr, &policy) == 0) { minPrio = sched_get_priority_min(policy); maxPrio = sched_get_priority_max(policy); if (minPrio == -1 || maxPrio == -1) minPrio = maxPrio = 0; } #endif if (pthread_attr_getschedparam(&attr, ¶m) != 0) normalPrio = param.sched_priority; else minPrio = maxPrio = 0; pthread_attr_destroy(&attr); } } static void * functionWrapper(void *data) { struct ThreadContext *ctx = data; if (ctx->name != NULL) OFSetThreadName(ctx->name); pthread_cleanup_push(free, data); ctx->function(ctx->object); pthread_cleanup_pop(1); return NULL; } int OFPlainThreadAttributesInit(OFPlainThreadAttributes *attr) { int error; pthread_attr_t POSIXAttr; attr->priority = 0; attr->stackSize = 0; if ((error = pthread_attr_init(&POSIXAttr)) != 0) { if (error == ENOSYS) return 0; return error; } error = pthread_attr_getstacksize(&POSIXAttr, &attr->stackSize); pthread_attr_destroy(&POSIXAttr); return error; } int OFPlainThreadNew(OFPlainThread *thread, const char *name, void (*function)(id), id object, const OFPlainThreadAttributes *attr) { int error = 0; pthread_attr_t POSIXAttr; bool POSIXAttrAvailable = true; if ((error = pthread_attr_init(&POSIXAttr)) != 0) { if (error == ENOSYS) POSIXAttrAvailable = false; else return error; } @try { struct ThreadContext *ctx; if (attr != NULL && POSIXAttrAvailable) { #ifndef OF_HPUX struct sched_param param; #endif if (attr->priority < -1 || attr->priority > 1) return EINVAL; #ifndef OF_HPUX # ifdef HAVE_PTHREAD_ATTR_SETINHERITSCHED if ((error = pthread_attr_setinheritsched(&POSIXAttr, PTHREAD_EXPLICIT_SCHED)) != 0) return error; # endif if ((error = pthread_attr_getschedparam(&POSIXAttr, ¶m)) != 0) return error; if (attr->priority < 0) { param.sched_priority = minPrio + (1.0f + attr->priority) * (normalPrio - minPrio); } else param.sched_priority = normalPrio + attr->priority * (maxPrio - normalPrio); if ((error = pthread_attr_setschedparam(&POSIXAttr, ¶m)) != 0) return error; #endif if (attr->stackSize > 0) { if ((error = pthread_attr_setstacksize( &POSIXAttr, attr->stackSize)) != 0) return error; } } if ((ctx = malloc(sizeof(*ctx))) == NULL) return ENOMEM; ctx->function = function; ctx->object = object; ctx->name = name; error = pthread_create(thread, (POSIXAttrAvailable ? &POSIXAttr : NULL), functionWrapper, ctx); } @finally { if (POSIXAttrAvailable) pthread_attr_destroy(&POSIXAttr); } return error; } int OFPlainThreadJoin(OFPlainThread thread) { void *ret; return pthread_join(thread, &ret); } int OFPlainThreadDetach(OFPlainThread thread) { return pthread_detach(thread); } void OFSetThreadName(const char *name) { #if defined(OF_HAIKU) rename_thread(find_thread(NULL), name); #elif defined(HAVE_PTHREAD_SET_NAME_NP) pthread_set_name_np(pthread_self(), name); #elif defined(HAVE_PTHREAD_SETNAME_NP) # if defined(OF_MACOS) || defined(OF_IOS) pthread_setname_np(name); # elif defined(__GLIBC__) char buffer[16]; strncpy(buffer, name, 15); buffer[15] = 0; pthread_setname_np(pthread_self(), buffer); # endif #endif } objfw-1.1.6/src/platform/POSIX/OFString+PathAdditions.m000066400000000000000000000177021465614216400225630ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFString+PathAdditions.h" #import "OFArray.h" #import "OFFileIRIHandler.h" #import "OFOutOfRangeException.h" int _OFString_PathAdditions_reference; @implementation OFString (PathAdditions) + (OFString *)pathWithComponents: (OFArray *)components { OFMutableString *ret = [OFMutableString string]; void *pool = objc_autoreleasePoolPush(); bool first = true; for (OFString *component in components) { if (component.length == 0) continue; if (!first && [component isEqual: @"/"]) continue; if (!first && ![ret hasSuffix: @"/"]) [ret appendString: @"/"]; [ret appendString: component]; first = false; } [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } - (bool)isAbsolutePath { return [self hasPrefix: @"/"]; } - (OFArray *)pathComponents { OFMutableArray OF_GENERIC(OFString *) *ret = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); const char *cString = self.UTF8String; size_t i, last = 0, cStringLength = self.UTF8StringLength; if (cStringLength == 0) { objc_autoreleasePoolPop(pool); return ret; } for (i = 0; i < cStringLength; i++) { if (cString[i] == '/') { if (i == 0) [ret addObject: @"/"]; else if (i - last != 0) [ret addObject: [OFString stringWithUTF8String: cString + last length: i - last]]; last = i + 1; } } if (i - last != 0) [ret addObject: [OFString stringWithUTF8String: cString + last length: i - last]]; [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } - (OFString *)lastPathComponent { void *pool = objc_autoreleasePoolPush(); const char *cString = self.UTF8String; size_t cStringLength = self.UTF8StringLength; ssize_t i; OFString *ret; if (cStringLength == 0) { objc_autoreleasePoolPop(pool); return @""; } if (cString[cStringLength - 1] == '/') cStringLength--; if (cStringLength == 0) { objc_autoreleasePoolPop(pool); return @"/"; } if (cStringLength - 1 > SSIZE_MAX) @throw [OFOutOfRangeException exception]; for (i = cStringLength - 1; i >= 0; i--) { if (cString[i] == '/') { i++; break; } } /* * Only one component, but the trailing delimiter might have been * removed, so return a new string anyway. */ if (i < 0) i = 0; ret = [[OFString alloc] initWithUTF8String: cString + i length: cStringLength - i]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)pathExtension { void *pool = objc_autoreleasePoolPush(); OFString *ret, *fileName; size_t pos; fileName = self.lastPathComponent; pos = [fileName rangeOfString: @"." options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return @""; } ret = [fileName substringFromIndex: pos + 1]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)stringByDeletingLastPathComponent { void *pool = objc_autoreleasePoolPush(); const char *cString = self.UTF8String; size_t cStringLength = self.UTF8StringLength; OFString *ret; if (cStringLength == 0) { objc_autoreleasePoolPop(pool); return @""; } if (cString[cStringLength - 1] == '/') cStringLength--; if (cStringLength == 0) { objc_autoreleasePoolPop(pool); return @"/"; } for (size_t i = cStringLength; i >= 1; i--) { if (cString[i - 1] == '/') { if (i == 1) { objc_autoreleasePoolPop(pool); return @"/"; } ret = [[OFString alloc] initWithUTF8String: cString length: i - 1]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } } objc_autoreleasePoolPop(pool); return @"."; } - (OFString *)stringByDeletingPathExtension { void *pool; OFMutableArray OF_GENERIC(OFString *) *components; OFString *ret, *fileName; size_t pos; if (self.length == 0) return [[self copy] autorelease]; pool = objc_autoreleasePoolPush(); components = [[self.pathComponents mutableCopy] autorelease]; fileName = components.lastObject; pos = [fileName rangeOfString: @"." options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return [[self copy] autorelease]; } fileName = [fileName substringToIndex: pos]; [components replaceObjectAtIndex: [components count] - 1 withObject: fileName]; ret = [OFString pathWithComponents: components]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)stringByStandardizingPath { void *pool = objc_autoreleasePoolPush(); OFArray OF_GENERIC(OFString *) *components; OFMutableArray OF_GENERIC(OFString *) *array; OFString *ret; bool done = false, startsWithSlash; if (self.length == 0) return @""; components = self.pathComponents; if (components.count == 1) { objc_autoreleasePoolPop(pool); return [[self copy] autorelease]; } array = [[components mutableCopy] autorelease]; startsWithSlash = [self hasPrefix: @"/"]; if (startsWithSlash) [array removeObjectAtIndex: 0]; while (!done) { size_t length = array.count; done = true; for (size_t i = 0; i < length; i++) { OFString *component = [array objectAtIndex: i]; OFString *parent = (i > 0 ? [array objectAtIndex: i - 1] : 0); if ([component isEqual: @"."] || component.length == 0) { [array removeObjectAtIndex: i]; done = false; break; } if ([component isEqual: @".."] && parent != nil && ![parent isEqual: @".."]) { [array removeObjectsInRange: OFMakeRange(i - 1, 2)]; done = false; break; } } } if (startsWithSlash) [array insertObject: @"" atIndex: 0]; if ([self hasSuffix: @"/"]) [array addObject: @""]; ret = [[array componentsJoinedByString: @"/"] retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)stringByAppendingPathComponent: (OFString *)component { if (self.length == 0) return component; if ([self hasSuffix: @"/"]) return [self stringByAppendingString: component]; else { OFMutableString *ret = [[self mutableCopy] autorelease]; [ret appendString: @"/"]; [ret appendString: component]; [ret makeImmutable]; return ret; } } - (OFString *)stringByAppendingPathExtension: (OFString *)extension { if ([self hasSuffix: @"/"]) { void *pool = objc_autoreleasePoolPush(); OFMutableArray *components; OFString *fileName, *ret; components = [[self.pathComponents mutableCopy] autorelease]; fileName = [components.lastObject stringByAppendingFormat: @".%@", extension]; [components replaceObjectAtIndex: components.count - 1 withObject: fileName]; ret = [[OFString pathWithComponents: components] retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } else return [self stringByAppendingFormat: @".%@", extension]; } - (bool)of_isDirectoryPath { return ([self hasSuffix: @"/"] || [OFFileIRIHandler of_directoryExistsAtPath: self]); } - (OFString *)of_pathToIRIPathWithPercentEncodedHost: (OFString **)percentEncodedHost { return self; } - (OFString *)of_IRIPathToPathWithPercentEncodedHost: (OFString *)percentEncodedHost { OFString *path = self; if (path.length > 1 && [path hasSuffix: @"/"]) path = [path substringToIndex: path.length - 1]; return path; } - (OFString *)of_pathComponentToIRIPathComponent { return self; } @end objfw-1.1.6/src/platform/POSIX/OFSubprocess.m000066400000000000000000000226521465614216400207160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #include #ifdef HAVE_SYS_WAIT_H # include #endif #include "unistd_wrapper.h" #ifdef HAVE_SPAWN_H # include #endif #import "OFSubprocess.h" #import "OFString.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFLocale.h" #import "OFInitializationFailedException.h" #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFWriteFailedException.h" #ifndef OF_MACOS extern char **environ; #else # include # define environ (*_NSGetEnviron()) #endif @interface OFSubprocess () - (void)of_getArgv: (char ***)argv forProgramName: (OFString *)programName andArguments: (OFArray *)arguments; - (char **)of_environmentForDictionary: (OFDictionary *)dictionary; @end @implementation OFSubprocess + (instancetype)subprocessWithProgram: (OFString *)program { return [[[self alloc] initWithProgram: program] autorelease]; } + (instancetype)subprocessWithProgram: (OFString *)program arguments: (OFArray *)arguments { return [[[self alloc] initWithProgram: program arguments: arguments] autorelease]; } + (instancetype)subprocessWithProgram: (OFString *)program programName: (OFString *)programName arguments: (OFArray *)arguments { return [[[self alloc] initWithProgram: program programName: programName arguments: arguments] autorelease]; } + (instancetype)subprocessWithProgram: (OFString *)program programName: (OFString *)programName arguments: (OFArray *)arguments environment: (OFDictionary *)environment { return [[[self alloc] initWithProgram: program programName: programName arguments: arguments environment: environment] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithProgram: (OFString *)program { return [self initWithProgram: program programName: program arguments: nil environment: nil]; } - (instancetype)initWithProgram: (OFString *)program arguments: (OFArray *)arguments { return [self initWithProgram: program programName: program arguments: arguments environment: nil]; } - (instancetype)initWithProgram: (OFString *)program programName: (OFString *)programName arguments: (OFArray *)arguments { return [self initWithProgram: program programName: program arguments: arguments environment: nil]; } - (instancetype)initWithProgram: (OFString *)program programName: (OFString *)programName arguments: (OFArray *)arguments environment: (OFDictionary *)environment { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); const char *path; char **argv, **env = NULL; _pid = -1; _readPipe[0] = _writePipe[1] = -1; if (pipe(_readPipe) != 0 || pipe(_writePipe) != 0) @throw [OFInitializationFailedException exceptionWithClass: self.class]; path = [program cStringWithEncoding: [OFLocale encoding]]; [self of_getArgv: &argv forProgramName: programName andArguments: arguments]; @try { env = [self of_environmentForDictionary: environment]; #if defined(HAVE_POSIX_SPAWNP) && defined(HAVE_SPAWN_H) posix_spawn_file_actions_t actions; posix_spawnattr_t attr; if (posix_spawn_file_actions_init(&actions) != 0) @throw [OFInitializationFailedException exceptionWithClass: self.class]; if (posix_spawnattr_init(&attr) != 0) { posix_spawn_file_actions_destroy(&actions); @throw [OFInitializationFailedException exceptionWithClass: self.class]; } @try { if (posix_spawn_file_actions_addclose(&actions, _readPipe[0]) != 0 || posix_spawn_file_actions_addclose(&actions, _writePipe[1]) != 0 || posix_spawn_file_actions_adddup2(&actions, _writePipe[0], 0) != 0 || posix_spawn_file_actions_adddup2(&actions, _readPipe[1], 1) != 0) @throw [OFInitializationFailedException exceptionWithClass: self.class]; # ifdef POSIX_SPAWN_CLOEXEC_DEFAULT if (posix_spawnattr_setflags(&attr, POSIX_SPAWN_CLOEXEC_DEFAULT) != 0) @throw [OFInitializationFailedException exceptionWithClass: self.class]; # endif if (posix_spawnp(&_pid, path, &actions, &attr, argv, (env != NULL ? env : environ)) != 0) @throw [OFInitializationFailedException exceptionWithClass: self.class]; } @finally { posix_spawn_file_actions_destroy(&actions); posix_spawnattr_destroy(&attr); } #else if ((_pid = vfork()) == 0) { if (env != NULL) environ = env; close(_readPipe[0]); close(_writePipe[1]); dup2(_writePipe[0], 0); dup2(_readPipe[1], 1); execvp(path, argv); _exit(EXIT_FAILURE); } if (_pid == -1) @throw [OFInitializationFailedException exceptionWithClass: self.class]; #endif } @finally { char **iter; close(_readPipe[1]); close(_writePipe[0]); OFFreeMemory(argv); if (env != NULL) for (iter = env; *iter != NULL; iter++) OFFreeMemory(*iter); OFFreeMemory(env); } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_readPipe[0] != -1) [self close]; [super dealloc]; } - (void)of_getArgv: (char ***)argv forProgramName: (OFString *)programName andArguments: (OFArray *)arguments { OFString *const *objects = arguments.objects; size_t i, count = arguments.count; OFStringEncoding encoding; *argv = OFAllocMemory(count + 2, sizeof(char *)); encoding = [OFLocale encoding]; (*argv)[0] = (char *)[programName cStringWithEncoding: encoding]; for (i = 0; i < count; i++) (*argv)[i + 1] = (char *)[objects[i] cStringWithEncoding: encoding]; (*argv)[i + 1] = NULL; } - (char **)of_environmentForDictionary: (OFDictionary *)environment { char **envp; size_t count; OFStringEncoding encoding; if (environment == nil) return NULL; encoding = [OFLocale encoding]; count = environment.count; envp = OFAllocZeroedMemory(count + 1, sizeof(char *)); @try { OFEnumerator *keyEnumerator = [environment keyEnumerator]; OFEnumerator *objectEnumerator = [environment objectEnumerator]; for (size_t i = 0; i < count; i++) { OFString *key; OFString *object; size_t keyLen, objectLen; key = [keyEnumerator nextObject]; object = [objectEnumerator nextObject]; keyLen = [key cStringLengthWithEncoding: encoding]; objectLen = [object cStringLengthWithEncoding: encoding]; envp[i] = OFAllocMemory(keyLen + objectLen + 2, 1); memcpy(envp[i], [key cStringWithEncoding: encoding], keyLen); envp[i][keyLen] = '='; memcpy(envp[i] + keyLen + 1, [object cStringWithEncoding: encoding], objectLen); envp[i][keyLen + objectLen + 1] = '\0'; } } @catch (id e) { for (size_t i = 0; i < count; i++) OFFreeMemory(envp[i]); OFFreeMemory(envp); @throw e; } return envp; } - (bool)lowlevelIsAtEndOfStream { if (_readPipe[0] == -1) @throw [OFNotOpenException exceptionWithObject: self]; return _atEndOfStream; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { ssize_t ret; if (_readPipe[0] == -1) @throw [OFNotOpenException exceptionWithObject: self]; if ((ret = read(_readPipe[0], buffer, length)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: errno]; if (ret == 0) _atEndOfStream = true; return ret; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { ssize_t bytesWritten; if (_writePipe[1] == -1) @throw [OFNotOpenException exceptionWithObject: self]; if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = write(_writePipe[1], buffer, length)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: errno]; return (size_t)bytesWritten; } - (int)fileDescriptorForReading { return _readPipe[0]; } - (int)fileDescriptorForWriting { return _writePipe[1]; } - (void)closeForWriting { if (_readPipe[0] == -1 || _writePipe[1] == -1) @throw [OFNotOpenException exceptionWithObject: self]; close(_writePipe[1]); _writePipe[1] = -1; } - (void)close { if (_readPipe[0] == -1) @throw [OFNotOpenException exceptionWithObject: self]; if (_writePipe[1] != -1) [self closeForWriting]; close(_readPipe[0]); if (_pid != -1) { kill(_pid, SIGTERM); waitpid(_pid, &_status, WNOHANG); } _pid = -1; _readPipe[0] = -1; [super close]; } - (int)waitForTermination { if (_readPipe[0] == -1) @throw [OFNotOpenException exceptionWithObject: self]; if (_pid != -1) { waitpid(_pid, &_status, 0); _pid = -1; } return WEXITSTATUS(_status); } @end objfw-1.1.6/src/platform/POSIX/OFSystemInfo+NetworkInterfaces.m000066400000000000000000000456171465614216400243250ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #ifdef HAVE_SYS_IOCTL_H # include #endif #ifdef OF_HAVE_SYS_SOCKET_H # include #endif #ifdef HAVE_SYS_SOCKIO_H # include #endif #ifdef HAVE_NET_IF_H # include #endif #ifdef HAVE_NET_IF_ARP_H # include #endif #ifdef HAVE_NET_IF_DL_H # include #endif #ifdef HAVE_NET_IF_TYPES_H # include #endif #import "OFSystemInfo.h" #import "OFSystemInfo+NetworkInterfaces.h" #import "OFArray.h" #import "OFData.h" #import "OFDictionary.h" #ifdef OF_HAVE_FILES #import "OFFile.h" #endif #import "OFLocale.h" #import "OFNumber.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFString.h" #import "OFInvalidFormatException.h" #import "OFOpenItemFailedException.h" @implementation OFSystemInfo (NetworkInterfaces) static bool queryNetworkInterfaceIndices(OFMutableDictionary *ret) { #ifdef HAVE_IF_NAMEINDEX OFStringEncoding encoding = [OFLocale encoding]; struct if_nameindex *nameindex = if_nameindex(); if (nameindex == NULL) return false; @try { for (size_t i = 0; nameindex[i].if_index != 0; i++) { OFString *name = [OFString stringWithCString: nameindex[i].if_name encoding: encoding]; OFNumber *idx = [OFNumber numberWithUnsignedInt: nameindex[i].if_index]; OFMutableDictionary *interface = [ret objectForKey: name]; if (interface == nil) { interface = [OFMutableDictionary dictionary]; [ret setObject: interface forKey: name]; } [interface setObject: idx forKey: OFNetworkInterfaceIndex]; } } @finally { if_freenameindex(nameindex); } return true; #else return false; #endif } #if defined(HAVE_IOCTL) && defined(HAVE_NET_IF_H) static bool queryNetworkInterfaceAddresses(OFMutableDictionary *ret, OFNetworkInterfaceKey key, OFSocketAddressFamily addressFamily, int family, size_t sockaddrSize) { OFStringEncoding encoding = [OFLocale encoding]; int sock = socket(family, SOCK_DGRAM, 0); OFMutableDictionary *interface; OFEnumerator *enumerator; if (sock < 0) return false; # if defined(HAVE_STRUCT_LIFCONF) && defined(SIOCGLIFCONF) struct lifconf lifc; struct lifreq *lifrs; if ((lifrs = malloc(128 * sizeof(struct lifreq))) == NULL) { closesocket(sock); return false; } @try { char *buffer; memset(&lifc, 0, sizeof(lifc)); lifc.lifc_buf = (void *)lifrs; lifc.lifc_len = 128 * sizeof(struct lifreq); if (ioctl(sock, SIOCGLIFCONF, &lifc) < 0) return false; for (buffer = lifc.lifc_buf; buffer < (char *)lifc.lifc_buf + lifc.lifc_len; buffer += sizeof(struct lifreq)) { struct lifreq *current = (struct lifreq *)(void *)buffer; OFString *name; OFMutableData *addresses; OFSocketAddress address; if (current->lifr_addr.ss_family != family) continue; name = [OFString stringWithCString: current->lifr_name encoding: encoding]; if ((interface = [ret objectForKey: name]) == nil) { interface = [OFMutableDictionary dictionary]; [ret setObject: interface forKey: name]; } addresses = [interface objectForKey: key]; if (addresses == nil) { addresses = [OFMutableData dataWithItemSize: sizeof(OFSocketAddress)]; [interface setObject: addresses forKey: key]; } memset(&address, 0, sizeof(address)); address.family = addressFamily; memcpy(&address.sockaddr.in, ¤t->lifr_addr, sockaddrSize); # if defined(OF_HAVE_IPV6) && defined(HAVE_IF_NAMETOINDEX) if (address.sockaddr.in6.sin6_family == AF_INET6 && address.sockaddr.in6.sin6_addr.s6_addr[0] == 0xFE && (address.sockaddr.in6.sin6_addr.s6_addr[1] & 0xC0) == 0x80) address.sockaddr.in6.sin6_scope_id = if_nametoindex( [name cStringWithEncoding: encoding]); # endif [addresses addItem: &address]; } } @finally { free(lifrs); closesocket(sock); } # else struct ifconf ifc; struct ifreq *ifrs; if (sock < 0) return false; if ((ifrs = malloc(128 * sizeof(struct ifreq))) == NULL) { closesocket(sock); return false; } @try { char *buffer; memset(&ifc, 0, sizeof(ifc)); ifc.ifc_buf = (void *)ifrs; ifc.ifc_len = 128 * sizeof(struct ifreq); if (ioctl(sock, SIOCGIFCONF, &ifc) < 0) return false; buffer = ifc.ifc_buf; while (buffer < (char *)ifc.ifc_buf + ifc.ifc_len) { struct ifreq *current = (struct ifreq *)(void *)buffer; OFString *name; OFMutableData *addresses; OFSocketAddress address; if (current->ifr_addr.sa_family != family) goto next; name = [OFString stringWithCString: current->ifr_name encoding: encoding]; if ((interface = [ret objectForKey: name]) == nil) { interface = [OFMutableDictionary dictionary]; [ret setObject: interface forKey: name]; } addresses = [interface objectForKey: key]; if (addresses == nil) { addresses = [OFMutableData dataWithItemSize: sizeof(OFSocketAddress)]; [interface setObject: addresses forKey: key]; } memset(&address, 0, sizeof(address)); address.family = addressFamily; memcpy(&address.sockaddr.in, ¤t->ifr_addr, sockaddrSize); # if defined(OF_HAVE_IPV6) && defined(HAVE_IF_NAMETOINDEX) if (address.sockaddr.in6.sin6_family == AF_INET6 && address.sockaddr.in6.sin6_addr.s6_addr[0] == 0xFE && (address.sockaddr.in6.sin6_addr.s6_addr[1] & 0xC0) == 0x80) { # if defined(__KAME__) # define addr6 address.sockaddr.in6.sin6_addr.s6_addr address.sockaddr.in6.sin6_scope_id = (addr6[2] << 8) | addr6[3]; addr6[2] = addr6[3] = 0; # undef addr6 # elif defined(HAVE_IF_NAMETOINDEX) address.sockaddr.in6.sin6_scope_id = if_nametoindex( [name cStringWithEncoding: encoding]); # endif } # endif [addresses addItem: &address]; next: # if defined(HAVE_STRUCT_SOCKADDR_SA_LEN) && !defined(OF_NETBSD) if (current->ifr_addr.sa_len > sizeof(struct sockaddr)) buffer += sizeof(struct ifreq) - sizeof(struct sockaddr) + current->ifr_addr.sa_len; else # endif buffer += sizeof(struct ifreq); } } @finally { free(ifrs); closesocket(sock); } # endif enumerator = [ret objectEnumerator]; while ((interface = [enumerator nextObject]) != nil) [[interface objectForKey: key] makeImmutable]; return true; } #endif static bool queryNetworkInterfaceIPv4Addresses(OFMutableDictionary *ret) { #if defined(HAVE_IOCTL) && defined(HAVE_NET_IF_H) return queryNetworkInterfaceAddresses(ret, OFNetworkInterfaceIPv4Addresses, OFSocketAddressFamilyIPv4, AF_INET, sizeof(struct sockaddr_in)); #else return false; #endif } #ifdef OF_HAVE_IPV6 static bool queryNetworkInterfaceIPv6Addresses(OFMutableDictionary *ret) { # if defined(OF_LINUX) && defined(OF_HAVE_FILES) # ifdef HAVE_IF_NAMETOINDEX OFStringEncoding encoding = [OFLocale encoding]; # endif OFFile *file; OFString *line; OFMutableDictionary *interface; OFEnumerator *enumerator; @try { file = [OFFile fileWithPath: @"/proc/net/if_inet6" mode: @"r"]; } @catch (OFOpenItemFailedException *e) { return false; } while ((line = [file readLine]) != nil) { OFArray *components = [line componentsSeparatedByString: @" " options: OFStringSkipEmptyComponents]; OFString *addressString, *name; OFSocketAddress address; OFMutableData *addresses; if (components.count < 6) continue; addressString = [components objectAtIndex: 0]; name = [components objectAtIndex: 5]; if (addressString.length != 32) continue; if ((interface = [ret objectForKey: name]) == nil) { interface = [OFMutableDictionary dictionary]; [ret setObject: interface forKey: name]; } memset(&address, 0, sizeof(address)); address.family = OFSocketAddressFamilyIPv6; address.sockaddr.in6.sin6_family = AF_INET6; for (size_t i = 0; i < 32; i += 2) { unsigned long long byte; @try { byte = [[addressString substringWithRange: OFMakeRange(i, 2)] unsignedLongLongValueWithBase: 16]; } @catch (OFInvalidFormatException *e) { goto next_line; } if (byte > 0xFF) goto next_line; address.sockaddr.in6.sin6_addr.s6_addr[i / 2] = (unsigned char)byte; } # ifdef HAVE_IF_NAMETOINDEX if (address.sockaddr.in6.sin6_addr.s6_addr[0] == 0xFE && (address.sockaddr.in6.sin6_addr.s6_addr[1] & 0xC0) == 0x80) address.sockaddr.in6.sin6_scope_id = if_nametoindex( [name cStringWithEncoding: encoding]); # endif if ((addresses = [interface objectForKey: OFNetworkInterfaceIPv6Addresses]) == nil) { addresses = [OFMutableData dataWithItemSize: sizeof(OFSocketAddress)]; [interface setObject: addresses forKey: OFNetworkInterfaceIPv6Addresses]; } [addresses addItem: &address]; next_line: continue; } enumerator = [ret objectEnumerator]; while ((interface = [enumerator nextObject]) != nil) [[interface objectForKey: OFNetworkInterfaceIPv6Addresses] makeImmutable]; return false; # elif defined(HAVE_IOCTL) && defined(HAVE_NET_IF_H) return queryNetworkInterfaceAddresses(ret, OFNetworkInterfaceIPv6Addresses, OFSocketAddressFamilyIPv6, AF_INET6, sizeof(struct sockaddr_in6)); # else return false; # endif } #endif #ifdef OF_HAVE_IPX static bool queryNetworkInterfaceIPXAddresses(OFMutableDictionary *ret) { # if defined(OF_LINUX) && defined(OF_HAVE_FILES) OFFile *file; OFString *line; OFMutableDictionary *interface; OFEnumerator *enumerator; @try { file = [OFFile fileWithPath: @"/proc/net/ipx/interface" mode: @"r"]; } @catch (OFOpenItemFailedException *e) { return false; } /* First line is "Network Node_Address Primary Device Frame_Type" */ if (![[file readLine] hasPrefix: @"Network "]) return false; while ((line = [file readLine]) != nil) { OFArray *components = [line componentsSeparatedByString: @" " options: OFStringSkipEmptyComponents]; OFString *name; unsigned long long network, nodeLong; unsigned char node[IPX_NODE_LEN]; OFSocketAddress address; OFMutableData *addresses; if (components.count < 5) continue; name = [components objectAtIndex: 3]; if ((interface = [ret objectForKey: name]) == nil) { interface = [OFMutableDictionary dictionary]; [ret setObject: interface forKey: name]; } @try { network = [[components objectAtIndex: 0] unsignedLongLongValueWithBase: 16]; nodeLong = [[components objectAtIndex: 1] unsignedLongLongValueWithBase: 16]; } @catch (OFInvalidFormatException *e) { continue; } if (network > 0xFFFFFFFF || nodeLong > 0xFFFFFFFFFFFF) continue; node[0] = (nodeLong >> 40) & 0xFF; node[1] = (nodeLong >> 32) & 0xFF; node[2] = (nodeLong >> 24) & 0xFF; node[3] = (nodeLong >> 16) & 0xFF; node[4] = (nodeLong >> 8) & 0xFF; node[5] = nodeLong & 0xFF; address = OFSocketAddressMakeIPX((uint32_t)network, node, 0); if ((addresses = [interface objectForKey: OFNetworkInterfaceIPXAddresses]) == nil) { addresses = [OFMutableData dataWithItemSize: sizeof(OFSocketAddress)]; [interface setObject: addresses forKey: OFNetworkInterfaceIPXAddresses]; } [addresses addItem: &address]; } enumerator = [ret objectEnumerator]; while ((interface = [enumerator nextObject]) != nil) [[interface objectForKey: OFNetworkInterfaceIPXAddresses] makeImmutable]; return false; # elif defined(HAVE_IOCTL) && defined(HAVE_NET_IF_H) return queryNetworkInterfaceAddresses(ret, OFNetworkInterfaceIPXAddresses, OFSocketAddressFamilyIPX, AF_IPX, sizeof(struct sockaddr_ipx)); # else return false; # endif } #endif #ifdef OF_HAVE_APPLETALK static bool queryNetworkInterfaceAppleTalkAddresses(OFMutableDictionary *ret) { # if defined(OF_LINUX) && defined(OF_HAVE_FILES) OFFile *file; OFString *line; OFMutableDictionary *interface; OFEnumerator *enumerator; @try { file = [OFFile fileWithPath: @"/proc/net/atalk/interface" mode: @"r"]; } @catch (OFOpenItemFailedException *e) { return false; } /* First line is "Interface Address Networks Status" */ if (![[file readLine] hasPrefix: @"Interface "]) return false; while ((line = [file readLine]) != nil) { OFArray *components = [line componentsSeparatedByString: @" " options: OFStringSkipEmptyComponents]; OFString *addressString, *name; unsigned long long network, node; OFSocketAddress address; OFMutableData *addresses; if (components.count < 4) continue; name = [components objectAtIndex: 0]; addressString = [components objectAtIndex: 1]; if (addressString.length != 7 || [addressString characterAtIndex: 4] != ':') continue; if ((interface = [ret objectForKey: name]) == nil) { interface = [OFMutableDictionary dictionary]; [ret setObject: interface forKey: name]; } @try { network = [[addressString substringWithRange: OFMakeRange(0, 4)] unsignedLongLongValueWithBase: 16]; node = [[addressString substringWithRange: OFMakeRange(5, 2)] unsignedLongLongValueWithBase: 16]; } @catch (OFInvalidFormatException *e) { continue; } if (network > 0xFFFF || node > 0xFF) continue; address = OFSocketAddressMakeAppleTalk( (uint16_t)network, (uint8_t)node, 0); if ((addresses = [interface objectForKey: OFNetworkInterfaceAppleTalkAddresses]) == nil) { addresses = [OFMutableData dataWithItemSize: sizeof(OFSocketAddress)]; [interface setObject: addresses forKey: OFNetworkInterfaceAppleTalkAddresses]; } [addresses addItem: &address]; } enumerator = [ret objectEnumerator]; while ((interface = [enumerator nextObject]) != nil) [[interface objectForKey: OFNetworkInterfaceAppleTalkAddresses] makeImmutable]; return false; # elif defined(HAVE_IOCTL) && defined(HAVE_NET_IF_H) return queryNetworkInterfaceAddresses(ret, OFNetworkInterfaceAppleTalkAddresses, OFSocketAddressFamilyAppleTalk, AF_APPLETALK, sizeof(struct sockaddr_at)); # else return false; # endif } #endif static bool queryNetworkInterfaceHardwareAddress(OFMutableDictionary *ret) { #if defined(HAVE_IOCTL) && defined(HAVE_NET_IF_H) && defined(SIOCGLIFHWADDR) OFStringEncoding encoding = [OFLocale encoding]; int sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) return false; for (OFString *name in ret) { size_t nameLength = [name cStringLengthWithEncoding: encoding]; struct lifreq lifr; struct sockaddr_dl *sdl; OFData *hardwareAddress; if (nameLength > IFNAMSIZ) continue; memset(&lifr, 0, sizeof(lifr)); memcpy(&lifr.lifr_name, [name cStringWithEncoding: encoding], nameLength); if (ioctl(sock, SIOCGLIFHWADDR, &lifr) < 0) continue; if (lifr.lifr_addr.ss_family != AF_LINK) continue; sdl = (struct sockaddr_dl *)(void *)&lifr.lifr_addr; hardwareAddress = [OFData dataWithItems: LLADDR(sdl) count: sdl->sdl_alen]; [[ret objectForKey: name] setObject: hardwareAddress forKey: OFNetworkInterfaceHardwareAddress]; } return true; #elif defined(HAVE_IOCTL) && defined(HAVE_NET_IF_H) && \ defined(SIOCGIFHWADDR) && defined(HAVE_STRUCT_IFREQ_IFR_HWADDR) OFStringEncoding encoding = [OFLocale encoding]; int sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) return false; for (OFString *name in ret) { size_t nameLength = [name cStringLengthWithEncoding: encoding]; struct ifreq ifr; OFData *hardwareAddress; if (nameLength > IFNAMSIZ) continue; memset(&ifr, 0, sizeof(ifr)); memcpy(&ifr.ifr_name, [name cStringWithEncoding: encoding], nameLength); if (ioctl(sock, SIOCGIFHWADDR, &ifr) < 0) continue; if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) continue; hardwareAddress = [OFData dataWithItems: ifr.ifr_hwaddr.sa_data count: 6]; [[ret objectForKey: name] setObject: hardwareAddress forKey: OFNetworkInterfaceHardwareAddress]; } return true; #elif defined(HAVE_IOCTL) && defined(HAVE_NET_IF_H) && \ defined(HAVE_STRUCT_SOCKADDR_DL) && defined(IFT_ETHER) OFStringEncoding encoding = [OFLocale encoding]; int sock = socket(AF_INET, SOCK_DGRAM, 0); struct ifconf ifc; struct ifreq *ifrs; if (sock < 0) return false; ifrs = malloc(128 * sizeof(struct ifreq)); if (ifrs == NULL) { closesocket(sock); return false; } @try { char *buffer; memset(&ifc, 0, sizeof(ifc)); ifc.ifc_buf = (void *)ifrs; ifc.ifc_len = 128 * sizeof(struct ifreq); if (ioctl(sock, SIOCGIFCONF, &ifc) < 0) return false; buffer = ifc.ifc_buf; while (buffer < (char *)ifc.ifc_buf + ifc.ifc_len) { struct ifreq *current = (struct ifreq *)(void *)buffer; struct sockaddr_dl *sdl; OFString *name; OFMutableDictionary *interface; OFData *hardwareAddress; if (current->ifr_addr.sa_family != AF_LINK) goto next; sdl = (struct sockaddr_dl *)(void *)¤t->ifr_addr; if (sdl->sdl_type != IFT_ETHER) goto next; name = [OFString stringWithCString: current->ifr_name encoding: encoding]; if ((interface = [ret objectForKey: name]) == nil) { interface = [OFMutableDictionary dictionary]; [ret setObject: interface forKey: name]; } hardwareAddress = [OFData dataWithItems: LLADDR(sdl) count: sdl->sdl_alen]; [interface setObject: hardwareAddress forKey: OFNetworkInterfaceHardwareAddress]; next: # ifdef _SIZEOF_ADDR_IFREQ buffer += _SIZEOF_ADDR_IFREQ(*current); # else buffer += sizeof(struct ifreq); # endif } } @finally { free(ifrs); closesocket(sock); } return true; #else return false; #endif } + (OFDictionary OF_GENERIC(OFString *, OFNetworkInterface) *)networkInterfaces { void *pool = objc_autoreleasePoolPush(); OFMutableDictionary *ret = [OFMutableDictionary dictionary]; bool success = false; OFEnumerator *enumerator; OFMutableDictionary *interface; success |= queryNetworkInterfaceIndices(ret); success |= queryNetworkInterfaceIPv4Addresses(ret); #ifdef OF_HAVE_IPV6 success |= queryNetworkInterfaceIPv6Addresses(ret); #endif #ifdef OF_HAVE_IPX success |= queryNetworkInterfaceIPXAddresses(ret); #endif #ifdef OF_HAVE_APPLETALK success |= queryNetworkInterfaceAppleTalkAddresses(ret); #endif success |= queryNetworkInterfaceHardwareAddress(ret); if (!success) { objc_autoreleasePoolPop(pool); return nil; } enumerator = [ret objectEnumerator]; while ((interface = [enumerator nextObject]) != nil) [interface makeImmutable]; [ret makeImmutable]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @end objfw-1.1.6/src/platform/POSIX/OFTLSKey.m000066400000000000000000000016261465614216400176770ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFTLSKey.h" int OFTLSKeyNew(OFTLSKey *key) { return pthread_key_create(key, NULL); } int OFTLSKeyFree(OFTLSKey key) { return pthread_key_delete(key); } objfw-1.1.6/src/platform/PowerPC/000077500000000000000000000000001465614216400165715ustar00rootroot00000000000000objfw-1.1.6/src/platform/PowerPC/OFAtomic.h000066400000000000000000000165631465614216400204160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ static OF_INLINE int OFAtomicIntAdd(volatile int *_Nonnull p, int i) { __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %2\n\t" "add %0, %0, %1\n\t" "stwcx. %0, 0, %2\n\t" "bne- 0b" : "=&r" (i) : "r" (i), "r" (p) : "cc", "memory" ); return i; } static OF_INLINE int32_t OFAtomicInt32Add(volatile int32_t *_Nonnull p, int32_t i) { __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %2\n\t" "add %0, %0, %1\n\t" "stwcx. %0, 0, %2\n\t" "bne- 0b" : "=&r" (i) : "r" (i), "r" (p) : "cc", "memory" ); return i; } static OF_INLINE void *_Nullable OFAtomicPointerAdd(void *volatile _Nullable *_Nonnull p, intptr_t i) { __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %2\n\t" "add %0, %0, %1\n\t" "stwcx. %0, 0, %2\n\t" "bne- 0b" : "=&r" (i) : "r" (i), "r" (p) : "cc", "memory" ); return (void *)i; } static OF_INLINE int OFAtomicIntSubtract(volatile int *_Nonnull p, int i) { __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %2\n\t" "sub %0, %0, %1\n\t" "stwcx. %0, 0, %2\n\t" "bne- 0b" : "=&r" (i) : "r" (i), "r" (p) : "cc", "memory" ); return i; } static OF_INLINE int32_t OFAtomicInt32Subtract(volatile int32_t *_Nonnull p, int32_t i) { __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %2\n\t" "sub %0, %0, %1\n\t" "stwcx. %0, 0, %2\n\t" "bne- 0b" : "=&r" (i) : "r" (i), "r" (p) : "cc", "memory" ); return i; } static OF_INLINE void *_Nullable OFAtomicPointerSubtract(void *volatile _Nullable *_Nonnull p, intptr_t i) { __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %2\n\t" "sub %0, %0, %1\n\t" "stwcx. %0, 0, %2\n\t" "bne- 0b" : "=&r" (i) : "r" (i), "r" (p) : "cc", "memory" ); return (void *)i; } static OF_INLINE int OFAtomicIntIncrease(volatile int *_Nonnull p) { int i; __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %1\n\t" "addi %0, %0, 1\n\t" "stwcx. %0, 0, %1\n\t" "bne- 0b" : "=&r" (i) : "r" (p) : "cc", "memory" ); return i; } static OF_INLINE int32_t OFAtomicInt32Increase(volatile int32_t *_Nonnull p) { int32_t i; __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %1\n\t" "addi %0, %0, 1\n\t" "stwcx. %0, 0, %1\n\t" "bne- 0b" : "=&r" (i) : "r" (p) : "cc", "memory" ); return i; } static OF_INLINE int OFAtomicIntDecrease(volatile int *_Nonnull p) { int i; __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %1\n\t" "subi %0, %0, 1\n\t" "stwcx. %0, 0, %1\n\t" "bne- 0b" : "=&r" (i) : "r" (p) : "cc", "memory" ); return i; } static OF_INLINE int32_t OFAtomicInt32Decrease(volatile int32_t *_Nonnull p) { int32_t i; __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %1\n\t" "subi %0, %0, 1\n\t" "stwcx. %0, 0, %1\n\t" "bne- 0b" : "=&r" (i) : "r" (p) : "cc", "memory" ); return i; } static OF_INLINE unsigned int OFAtomicIntOr(volatile unsigned int *_Nonnull p, unsigned int i) { __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %2\n\t" "or %0, %0, %1\n\t" "stwcx. %0, 0, %2\n\t" "bne- 0b" : "=&r" (i) : "r" (i), "r" (p) : "cc", "memory" ); return i; } static OF_INLINE uint32_t OFAtomicInt32Or(volatile uint32_t *_Nonnull p, uint32_t i) { __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %2\n\t" "or %0, %0, %1\n\t" "stwcx. %0, 0, %2\n\t" "bne- 0b" : "=&r" (i) : "r" (i), "r" (p) : "cc", "memory" ); return i; } static OF_INLINE unsigned int OFAtomicIntAnd(volatile unsigned int *_Nonnull p, unsigned int i) { __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %2\n\t" "and %0, %0, %1\n\t" "stwcx. %0, 0, %2\n\t" "bne- 0b" : "=&r" (i) : "r" (i), "r" (p) : "cc", "memory" ); return i; } static OF_INLINE uint32_t OFAtomicInt32And(volatile uint32_t *_Nonnull p, uint32_t i) { __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %2\n\t" "and %0, %0, %1\n\t" "stwcx. %0, 0, %2\n\t" "bne- 0b" : "=&r" (i) : "r" (i), "r" (p) : "cc", "memory" ); return i; } static OF_INLINE unsigned int OFAtomicIntXor(volatile unsigned int *_Nonnull p, unsigned int i) { __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %2\n\t" "xor %0, %0, %1\n\t" "stwcx. %0, 0, %2\n\t" "bne- 0b" : "=&r" (i) : "r" (i), "r" (p) : "cc", "memory" ); return i; } static OF_INLINE uint32_t OFAtomicInt32Xor(volatile uint32_t *_Nonnull p, uint32_t i) { __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %2\n\t" "xor %0, %0, %1\n\t" "stwcx. %0, 0, %2\n\t" "bne- 0b" : "=&r" (i) : "r" (i), "r" (p) : "cc", "memory" ); return i; } static OF_INLINE bool OFAtomicIntCompareAndSwap(volatile int *_Nonnull p, int o, int n) { int r; __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %3\n\t" "cmpw %0, %1\n\t" "bne 1f\n\t" "stwcx. %2, 0, %3\n\t" "bne- 0b\n\t" "li %0, 1\n\t" "b 2f\n\t" "1:\n\t" "stwcx. %0, 0, %3\n\t" "li %0, 0\n\t" "2:" : "=&r" (r) : "r" (o), "r" (n), "r" (p) : "cc", "memory" ); return r; } static OF_INLINE bool OFAtomicInt32CompareAndSwap(volatile int32_t *_Nonnull p, int32_t o, int32_t n) { int r; __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %3\n\t" "cmpw %0, %1\n\t" "bne 1f\n\t" "stwcx. %2, 0, %3\n\t" "bne- 0b\n\t" "li %0, 1\n\t" "b 2f\n\t" "1:\n\t" "stwcx. %0, 0, %3\n\t" "li %0, 0\n\t" "2:" : "=&r" (r) : "r" (o), "r" (n), "r" (p) : "cc", "memory" ); return r; } static OF_INLINE bool OFAtomicPointerCompareAndSwap(void *volatile _Nullable *_Nonnull p, void *_Nullable o, void *_Nullable n) { int r; __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %3\n\t" "cmpw %0, %1\n\t" "bne 1f\n\t" "stwcx. %2, 0, %3\n\t" "bne- 0b\n\t" "li %0, 1\n\t" "b 2f\n\t" "1:\n\t" "stwcx. %0, 0, %3\n\t" "li %0, 0\n\t" "2:" : "=&r" (r) : "r" (o), "r" (n), "r" (p) : "cc", "memory" ); return r; } static OF_INLINE void OFMemoryBarrier(void) { __asm__ __volatile__ ( ".long 0x7C2004AC /* lwsync */" ::: "memory" ); } static OF_INLINE void OFAcquireMemoryBarrier(void) { __asm__ __volatile__ ( ".long 0x7C2004AC /* lwsync */" ::: "memory" ); } static OF_INLINE void OFReleaseMemoryBarrier(void) { __asm__ __volatile__ ( ".long 0x7C2004AC /* lwsync */" ::: "memory" ); } objfw-1.1.6/src/platform/Windows/000077500000000000000000000000001465614216400167045ustar00rootroot00000000000000objfw-1.1.6/src/platform/Windows/OFPlainCondition.m000066400000000000000000000054651465614216400222330ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFPlainCondition.h" #import "OFConstantString.h" #include int OFPlainConditionNew(OFPlainCondition *condition) { condition->count = 0; if ((condition->event = CreateEvent(NULL, FALSE, 0, NULL)) == NULL) return EAGAIN; return 0; } int OFPlainConditionSignal(OFPlainCondition *condition) { if (!SetEvent(condition->event)) { switch (GetLastError()) { case ERROR_INVALID_HANDLE: return EINVAL; default: OFEnsure(0); } } return 0; } int OFPlainConditionBroadcast(OFPlainCondition *condition) { int count = condition->count; for (int i = 0; i < count; i++) { if (!SetEvent(condition->event)) { switch (GetLastError()) { case ERROR_INVALID_HANDLE: return EINVAL; default: OFEnsure(0); } } } return 0; } int OFPlainConditionWait(OFPlainCondition *condition, OFPlainMutex *mutex) { int error; DWORD status; if ((error = OFPlainMutexUnlock(mutex)) != 0) return error; OFAtomicIntIncrease(&condition->count); status = WaitForSingleObject(condition->event, INFINITE); OFAtomicIntDecrease(&condition->count); switch (status) { case WAIT_OBJECT_0: return OFPlainMutexLock(mutex); case WAIT_FAILED: switch (GetLastError()) { case ERROR_INVALID_HANDLE: return EINVAL; default: OFEnsure(0); } default: OFEnsure(0); } } int OFPlainConditionTimedWait(OFPlainCondition *condition, OFPlainMutex *mutex, OFTimeInterval timeout) { int error; DWORD status; if ((error = OFPlainMutexUnlock(mutex)) != 0) return error; OFAtomicIntIncrease(&condition->count); status = WaitForSingleObject(condition->event, timeout * 1000); OFAtomicIntDecrease(&condition->count); switch (status) { case WAIT_OBJECT_0: return OFPlainMutexLock(mutex); case WAIT_TIMEOUT: return ETIMEDOUT; case WAIT_FAILED: switch (GetLastError()) { case ERROR_INVALID_HANDLE: return EINVAL; default: OFEnsure(0); } default: OFEnsure(0); } } int OFPlainConditionFree(OFPlainCondition *condition) { if (condition->count != 0) return EBUSY; return (CloseHandle(condition->event) ? 0 : EINVAL); } objfw-1.1.6/src/platform/Windows/OFPlainMutex.m000066400000000000000000000034171465614216400214020ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFPlainMutex.h" #include int OFPlainMutexNew(OFPlainMutex *mutex) { InitializeCriticalSection(mutex); return 0; } int OFPlainMutexLock(OFPlainMutex *mutex) { EnterCriticalSection(mutex); return 0; } int OFPlainMutexTryLock(OFPlainMutex *mutex) { if (!TryEnterCriticalSection(mutex)) return EBUSY; return 0; } int OFPlainMutexUnlock(OFPlainMutex *mutex) { LeaveCriticalSection(mutex); return 0; } int OFPlainMutexFree(OFPlainMutex *mutex) { DeleteCriticalSection(mutex); return 0; } int OFPlainRecursiveMutexNew(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexNew(rmutex); } int OFPlainRecursiveMutexLock(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexLock(rmutex); } int OFPlainRecursiveMutexTryLock(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexTryLock(rmutex); } int OFPlainRecursiveMutexUnlock(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexUnlock(rmutex); } int OFPlainRecursiveMutexFree(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexFree(rmutex); } objfw-1.1.6/src/platform/Windows/OFPlainThread.m000066400000000000000000000054461465614216400215130ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFPlainThread.h" #import "OFConstantString.h" #include struct ThreadContext { void (*function)(id); id object; }; static WINAPI void functionWrapper(struct ThreadContext *context) { context->function(context->object); free(context); } int OFPlainThreadAttributesInit(OFPlainThreadAttributes *attr) { attr->priority = 0; attr->stackSize = 0; return 0; } int OFPlainThreadNew(OFPlainThread *thread, const char *name, void (*function)(id), id object, const OFPlainThreadAttributes *attr) { DWORD priority = THREAD_PRIORITY_NORMAL; struct ThreadContext *context; DWORD threadID; if (attr != NULL && attr->priority != 0) { if (attr->priority < -1 || attr->priority > 1) return EINVAL; if (attr->priority < 0) priority = THREAD_PRIORITY_LOWEST + (1.0 + attr->priority) * (THREAD_PRIORITY_NORMAL - THREAD_PRIORITY_LOWEST); else priority = THREAD_PRIORITY_NORMAL + attr->priority * (THREAD_PRIORITY_HIGHEST - THREAD_PRIORITY_NORMAL); } if ((context = malloc(sizeof(*context))) == NULL) return ENOMEM; context->function = function; context->object = object; *thread = CreateThread(NULL, (attr != NULL ? attr->stackSize : 0), (LPTHREAD_START_ROUTINE)functionWrapper, context, 0, &threadID); if (thread == NULL) { int error; switch (GetLastError()) { case ERROR_NOT_ENOUGH_MEMORY: error = ENOMEM; break; case ERROR_ACCESS_DENIED: error = EACCES; break; default: OFEnsure(0); } free(context); return error; } if (attr != NULL && attr->priority != 0) OFEnsure(!SetThreadPriority(*thread, priority)); return 0; } int OFPlainThreadJoin(OFPlainThread thread) { switch (WaitForSingleObject(thread, INFINITE)) { case WAIT_OBJECT_0: CloseHandle(thread); return 0; case WAIT_FAILED: switch (GetLastError()) { case ERROR_INVALID_HANDLE: return EINVAL; default: OFEnsure(0); } default: OFEnsure(0); } } int OFPlainThreadDetach(OFPlainThread thread) { CloseHandle(thread); return 0; } void OFSetThreadName(const char *name) { } objfw-1.1.6/src/platform/Windows/OFString+PathAdditions.m000066400000000000000000000233461465614216400233140ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ /* * This file is also used for MS-DOS and MiNT! Don't forget to #ifdef * Windows-specific parts! */ #include "config.h" #import "OFString+PathAdditions.h" #import "OFArray.h" #import "OFFileIRIHandler.h" #import "OFIRI.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" int _OFString_PathAdditions_reference; @implementation OFString (PathAdditions) + (OFString *)pathWithComponents: (OFArray *)components { OFMutableString *ret = [OFMutableString string]; void *pool = objc_autoreleasePoolPush(); bool first = true; for (OFString *component in components) { if (component.length == 0) continue; if (!first && ![ret hasSuffix: @":"] && ([component isEqual: @"\\"] || [component isEqual: @"/"])) continue; if (!first && ![ret hasSuffix: @"\\"] && ![ret hasSuffix: @"/"] && ![ret hasSuffix: @":"]) [ret appendString: @"\\"]; [ret appendString: component]; first = false; } [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } - (bool)isAbsolutePath { #ifdef OF_WINDOWS if ([self hasPrefix: @"\\\\"]) return true; #endif return ([self containsString: @":\\"] || [self containsString: @":/"]); } - (OFArray *)pathComponents { OFMutableArray OF_GENERIC(OFString *) *ret = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); const char *cString = self.UTF8String; size_t i, last = 0, cStringLength = self.UTF8StringLength; bool isUNC = false; if (cStringLength == 0) { objc_autoreleasePoolPop(pool); return ret; } #ifdef OF_WINDOWS if ([self hasPrefix: @"\\\\"]) { isUNC = true; [ret addObject: @"\\\\"]; cString += 2; cStringLength -= 2; } #endif for (i = 0; i < cStringLength; i++) { if (cString[i] == '\\' || cString[i] == '/') { if (i == 0) [ret addObject: [OFString stringWithUTF8String: cString length: 1]]; else if (i - last != 0) [ret addObject: [OFString stringWithUTF8String: cString + last length: i - last]]; last = i + 1; } else if (!isUNC && cString[i] == ':') { if (i + 1 < cStringLength && (cString[i + 1] == '\\' || cString[i + 1] == '/')) i++; [ret addObject: [OFString stringWithUTF8String: cString + last length: i - last + 1]]; last = i + 1; } } if (i - last != 0) [ret addObject: [OFString stringWithUTF8String: cString + last length: i - last]]; [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } - (OFString *)lastPathComponent { /* * Windows/DOS need the full parsing to determine the last path * component. This could be optimized by not creating the temporary * objects, though. */ void *pool = objc_autoreleasePoolPush(); OFString *ret = self.pathComponents.lastObject; if (ret == nil) { objc_autoreleasePoolPop(pool); return @""; } [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)pathExtension { void *pool = objc_autoreleasePoolPush(); OFString *ret, *fileName; size_t pos; fileName = self.lastPathComponent; pos = [fileName rangeOfString: @"." options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return @""; } ret = [fileName substringFromIndex: pos + 1]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)stringByDeletingLastPathComponent { /* * Windows/DOS need the full parsing to delete the last path component. * This could be optimized, though. */ void *pool = objc_autoreleasePoolPush(); OFArray OF_GENERIC(OFString *) *components = self.pathComponents; size_t count = components.count; OFString *ret; if (count == 0) { objc_autoreleasePoolPop(pool); return @""; } if (count == 1) { OFString *firstComponent = components.firstObject; if ([firstComponent hasSuffix: @":"] || [firstComponent hasSuffix: @":\\"] || [firstComponent hasSuffix: @":/"] || [firstComponent hasPrefix: @"\\"]) { ret = [firstComponent retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } objc_autoreleasePoolPop(pool); return @"."; } components = [components objectsInRange: OFMakeRange(0, components.count - 1)]; ret = [OFString pathWithComponents: components]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)stringByDeletingPathExtension { void *pool; OFMutableArray OF_GENERIC(OFString *) *components; OFString *ret, *fileName; size_t pos; if (self.length == 0) return [[self copy] autorelease]; pool = objc_autoreleasePoolPush(); components = [[self.pathComponents mutableCopy] autorelease]; fileName = components.lastObject; pos = [fileName rangeOfString: @"." options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return [[self copy] autorelease]; } fileName = [fileName substringToIndex: pos]; [components replaceObjectAtIndex: components.count - 1 withObject: fileName]; ret = [OFString pathWithComponents: components]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)stringByStandardizingPath { void *pool = objc_autoreleasePoolPush(); OFArray OF_GENERIC(OFString *) *components; OFMutableArray OF_GENERIC(OFString *) *array; OFString *ret; bool done = false; if (self.length == 0) return @""; components = self.pathComponents; if (components.count == 1) { objc_autoreleasePoolPop(pool); return [[self copy] autorelease]; } array = [[components mutableCopy] autorelease]; while (!done) { size_t length = array.count; done = true; for (size_t i = 0; i < length; i++) { OFString *component = [array objectAtIndex: i]; OFString *parent = (i > 0 ? [array objectAtIndex: i - 1] : 0); if ([component isEqual: @"."] || component.length == 0) { [array removeObjectAtIndex: i]; done = false; break; } if ([component isEqual: @".."] && parent != nil && ![parent isEqual: @".."] && ![parent hasSuffix: @":"] && ![parent hasSuffix: @":\\"] && ![parent hasSuffix: @"://"] && (![parent hasPrefix: @"\\"] || i != 1)) { [array removeObjectsInRange: OFMakeRange(i - 1, 2)]; done = false; break; } } } ret = [[OFString pathWithComponents: array] retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)stringByAppendingPathComponent: (OFString *)component { if (self.length == 0) return component; if ([self hasSuffix: @"\\"] || [self hasSuffix: @"/"]) return [self stringByAppendingString: component]; else { OFMutableString *ret = [[self mutableCopy] autorelease]; [ret appendString: @"\\"]; [ret appendString: component]; [ret makeImmutable]; return ret; } } - (OFString *)stringByAppendingPathExtension: (OFString *)extension { if ([self hasSuffix: @"\\"] || [self hasSuffix: @"/"]) { void *pool = objc_autoreleasePoolPush(); OFMutableArray *components; OFString *fileName, *ret; components = [[self.pathComponents mutableCopy] autorelease]; fileName = [components.lastObject stringByAppendingFormat: @".%@", extension]; [components replaceObjectAtIndex: components.count - 1 withObject: fileName]; ret = [[OFString pathWithComponents: components] retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } else return [self stringByAppendingFormat: @".%@", extension]; } - (bool)of_isDirectoryPath { return ([self hasSuffix: @"\\"] || [self hasSuffix: @"/"] || [OFFileIRIHandler of_directoryExistsAtPath: self]); } - (OFString *)of_pathToIRIPathWithPercentEncodedHost: (OFString **)percentEncodedHost { OFString *path = self; if ([path hasPrefix: @"\\\\"]) { OFArray *components = path.pathComponents; if (components.count < 2) @throw [OFInvalidFormatException exception]; *percentEncodedHost = [[components objectAtIndex: 1] stringByAddingPercentEncodingWithAllowedCharacters: [OFCharacterSet IRIHostAllowedCharacterSet]]; path = [OFString pathWithComponents: [components objectsInRange: OFMakeRange(2, components.count - 2)]]; } path = [path stringByReplacingOccurrencesOfString: @"\\" withString: @"/"]; path = [@"/" stringByAppendingString: path]; return path; } - (OFString *)of_IRIPathToPathWithPercentEncodedHost: (OFString *)percentEncodedHost { OFString *path = self; if (path.length > 1 && [path hasSuffix: @"/"] && ![path hasSuffix: @":/"]) path = [path substringToIndex: path.length - 1]; path = [path substringFromIndex: 1]; path = [path stringByReplacingOccurrencesOfString: @"/" withString: @"\\"]; if (percentEncodedHost != nil) { OFString *host = [percentEncodedHost stringByRemovingPercentEncoding]; if (path.length == 0) path = [OFString stringWithFormat: @"\\\\%@", host]; else path = [OFString stringWithFormat: @"\\\\%@\\%@", host, path]; } return path; } - (OFString *)of_pathComponentToIRIPathComponent { return [self stringByReplacingOccurrencesOfString: @"\\" withString: @"/"]; } @end objfw-1.1.6/src/platform/Windows/OFSubprocess.m000066400000000000000000000252271465614216400214470ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "OFSubprocess.h" #import "OFArray.h" #import "OFData.h" #import "OFDictionary.h" #import "OFLocale.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFInitializationFailedException.h" #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFWriteFailedException.h" #include @interface OFSubprocess () - (OFChar16 *)of_wideEnvironmentForDictionary: (OFDictionary *)dictionary; - (char *)of_environmentForDictionary: (OFDictionary *)environment; @end @implementation OFSubprocess + (instancetype)subprocessWithProgram: (OFString *)program { return [[[self alloc] initWithProgram: program] autorelease]; } + (instancetype)subprocessWithProgram: (OFString *)program arguments: (OFArray *)arguments { return [[[self alloc] initWithProgram: program arguments: arguments] autorelease]; } + (instancetype)subprocessWithProgram: (OFString *)program programName: (OFString *)programName arguments: (OFArray *)arguments { return [[[self alloc] initWithProgram: program programName: programName arguments: arguments] autorelease]; } + (instancetype)subprocessWithProgram: (OFString *)program programName: (OFString *)programName arguments: (OFArray *)arguments environment: (OFDictionary *)environment { return [[[self alloc] initWithProgram: program programName: programName arguments: arguments environment: environment] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithProgram: (OFString *)program { return [self initWithProgram: program programName: program arguments: nil environment: nil]; } - (instancetype)initWithProgram: (OFString *)program arguments: (OFArray *)arguments { return [self initWithProgram: program programName: program arguments: arguments environment: nil]; } - (instancetype)initWithProgram: (OFString *)program programName: (OFString *)programName arguments: (OFArray *)arguments { return [self initWithProgram: program programName: program arguments: arguments environment: nil]; } - (instancetype)initWithProgram: (OFString *)program programName: (OFString *)programName arguments: (OFArray *)arguments environment: (OFDictionary *)environment { self = [super init]; @try { SECURITY_ATTRIBUTES sa; PROCESS_INFORMATION pi; void *pool; OFMutableString *argumentsString; _handle = INVALID_HANDLE_VALUE; _readPipe[0] = _writePipe[1] = NULL; sa.nLength = sizeof(sa); sa.bInheritHandle = TRUE; sa.lpSecurityDescriptor = NULL; if (!CreatePipe(&_readPipe[0], &_readPipe[1], &sa, 0)) @throw [OFInitializationFailedException exceptionWithClass: self.class]; if (!SetHandleInformation(_readPipe[0], HANDLE_FLAG_INHERIT, 0)) if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) @throw [OFInitializationFailedException exceptionWithClass: self.class]; if (!CreatePipe(&_writePipe[0], &_writePipe[1], &sa, 0)) @throw [OFInitializationFailedException exceptionWithClass: self.class]; if (!SetHandleInformation(_writePipe[1], HANDLE_FLAG_INHERIT, 0)) if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) @throw [OFInitializationFailedException exceptionWithClass: self.class]; memset(&pi, 0, sizeof(pi)); pool = objc_autoreleasePoolPush(); argumentsString = [OFMutableString stringWithString: programName]; [argumentsString replaceOccurrencesOfString: @"\\\"" withString: @"\\\\\""]; [argumentsString replaceOccurrencesOfString: @"\"" withString: @"\\\""]; if ([argumentsString containsString: @" "]) { [argumentsString insertString: @"\"" atIndex: 0]; [argumentsString appendString: @"\""]; } for (OFString *argument in arguments) { OFMutableString *tmp = [[argument mutableCopy] autorelease]; bool containsSpaces = [tmp containsString: @" "]; [argumentsString appendString: @" "]; if (containsSpaces) [argumentsString appendString: @"\""]; [tmp replaceOccurrencesOfString: @"\\\"" withString: @"\\\\\""]; [tmp replaceOccurrencesOfString: @"\"" withString: @"\\\""]; [argumentsString appendString: tmp]; if (containsSpaces) [argumentsString appendString: @"\""]; } if ([OFSystemInfo isWindowsNT]) { size_t length; OFChar16 *argumentsCopy; STARTUPINFOW si; memset(&si, 0, sizeof(si)); si.cb = sizeof(si); si.hStdInput = _writePipe[0]; si.hStdOutput = _readPipe[1]; si.hStdError = GetStdHandle(STD_ERROR_HANDLE); si.dwFlags |= STARTF_USESTDHANDLES; length = argumentsString.UTF16StringLength; argumentsCopy = OFAllocMemory(length + 1, sizeof(OFChar16)); memcpy(argumentsCopy, argumentsString.UTF16String, (length + 1) * 2); @try { if (!CreateProcessW(program.UTF16String, argumentsCopy, NULL, NULL, TRUE, CREATE_UNICODE_ENVIRONMENT, [self of_wideEnvironmentForDictionary: environment], NULL, &si, &pi)) @throw [OFInitializationFailedException exceptionWithClass: self.class]; } @finally { OFFreeMemory(argumentsCopy); } } else { OFStringEncoding encoding = [OFLocale encoding]; STARTUPINFO si; memset(&si, 0, sizeof(si)); si.cb = sizeof(si); si.hStdInput = _writePipe[0]; si.hStdOutput = _readPipe[1]; si.hStdError = GetStdHandle(STD_ERROR_HANDLE); si.dwFlags |= STARTF_USESTDHANDLES; if (!CreateProcessA([program cStringWithEncoding: encoding], (char *)[argumentsString cStringWithEncoding: encoding], NULL, NULL, TRUE, 0, [self of_environmentForDictionary: environment], NULL, &si, &pi)) @throw [OFInitializationFailedException exceptionWithClass: self.class]; } objc_autoreleasePoolPop(pool); _handle = pi.hProcess; CloseHandle(pi.hThread); CloseHandle(_readPipe[1]); CloseHandle(_writePipe[0]); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_readPipe[0] != NULL) [self close]; [super dealloc]; } - (OFChar16 *)of_wideEnvironmentForDictionary: (OFDictionary *)environment { OFMutableData *env; OFEnumerator *keyEnumerator, *objectEnumerator; OFString *key, *object; const OFChar16 equal = '='; const OFChar16 zero[2] = { 0, 0 }; if (environment == nil) return NULL; env = [OFMutableData dataWithItemSize: sizeof(OFChar16)]; keyEnumerator = [environment keyEnumerator]; objectEnumerator = [environment objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { [env addItems: key.UTF16String count: key.UTF16StringLength]; [env addItems: &equal count: 1]; [env addItems: object.UTF16String count: object.UTF16StringLength]; [env addItems: &zero count: 1]; } [env addItems: zero count: 2]; return env.mutableItems; } - (char *)of_environmentForDictionary: (OFDictionary *)environment { OFStringEncoding encoding = [OFLocale encoding]; OFMutableData *env; OFEnumerator *keyEnumerator, *objectEnumerator; OFString *key, *object; if (environment == nil) return NULL; env = [OFMutableData data]; keyEnumerator = [environment keyEnumerator]; objectEnumerator = [environment objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { [env addItems: [key cStringWithEncoding: encoding] count: [key cStringLengthWithEncoding: encoding]]; [env addItems: "=" count: 1]; [env addItems: [object cStringWithEncoding: encoding] count: [object cStringLengthWithEncoding: encoding]]; [env addItems: "" count: 1]; } [env addItems: "\0" count: 2]; return env.mutableItems; } - (bool)lowlevelIsAtEndOfStream { if (_readPipe[0] == NULL) @throw [OFNotOpenException exceptionWithObject: self]; return _atEndOfStream; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { DWORD ret; if (length > UINT32_MAX) @throw [OFOutOfRangeException exception]; if (_readPipe[0] == NULL) @throw [OFNotOpenException exceptionWithObject: self]; if (!ReadFile(_readPipe[0], buffer, (DWORD)length, &ret, NULL)) { if (GetLastError() == ERROR_BROKEN_PIPE) { _atEndOfStream = true; return 0; } @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: EIO]; } if (ret == 0) _atEndOfStream = true; return ret; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { DWORD bytesWritten; if (length > UINT32_MAX) @throw [OFOutOfRangeException exception]; if (_writePipe[1] == NULL) @throw [OFNotOpenException exceptionWithObject: self]; if (!WriteFile(_writePipe[1], buffer, (DWORD)length, &bytesWritten, NULL)) { int errNo = EIO; if (GetLastError() == ERROR_BROKEN_PIPE) errNo = EPIPE; @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: bytesWritten errNo: errNo]; } return (size_t)bytesWritten; } - (void)closeForWriting { if (_readPipe[0] == NULL || _writePipe[1] == NULL) @throw [OFNotOpenException exceptionWithObject: self]; CloseHandle(_writePipe[1]); _writePipe[1] = NULL; } - (void)close { if (_readPipe[0] == NULL) @throw [OFNotOpenException exceptionWithObject: self]; if (_writePipe[1] != NULL) [self closeForWriting]; CloseHandle(_readPipe[0]); if (_handle != INVALID_HANDLE_VALUE) { TerminateProcess(_handle, 0); CloseHandle(_handle); } _handle = INVALID_HANDLE_VALUE; _readPipe[0] = NULL; [super close]; } - (int)waitForTermination { if (_readPipe[0] == NULL) @throw [OFNotOpenException exceptionWithObject: self]; if (_handle != INVALID_HANDLE_VALUE) { DWORD exitCode; WaitForSingleObject(_handle, INFINITE); if (GetExitCodeProcess(_handle, &exitCode)) _status = exitCode; else _status = GetLastError(); CloseHandle(_handle); _handle = INVALID_HANDLE_VALUE; } return _status; } @end objfw-1.1.6/src/platform/Windows/OFSystemInfo+NetworkInterfaces.m000066400000000000000000000164471465614216400250540ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFSystemInfo.h" #import "OFSystemInfo+NetworkInterfaces.h" #import "OFData.h" #import "OFDictionary.h" #import "OFLocale.h" #import "OFNumber.h" #import "OFOnce.h" #import "OFSocket.h" #import "OFString.h" #include #define interface struct #include #undef interface static WINAPI ULONG (*GetAdaptersAddressesFuncPtr)(ULONG, ULONG, PVOID, PIP_ADAPTER_ADDRESSES, PULONG); static void init(void) { HMODULE module; if ((module = GetModuleHandle("iphlpapi.dll")) != NULL) GetAdaptersAddressesFuncPtr = (WINAPI ULONG (*)(ULONG, ULONG, PVOID, PIP_ADAPTER_ADDRESSES, PULONG)) GetProcAddress(module, "GetAdaptersAddresses"); } static OFMutableDictionary OF_GENERIC(OFString *, OFNetworkInterface) * networkInterfacesFromGetAdaptersAddresses(void) { OFMutableDictionary *ret = [OFMutableDictionary dictionary]; ULONG adapterAddressesSize = sizeof(IP_ADAPTER_ADDRESSES); PIP_ADAPTER_ADDRESSES adapterAddresses; if ((adapterAddresses = malloc(adapterAddressesSize)) == NULL) return nil; @try { OFStringEncoding encoding = [OFLocale encoding]; ULONG error = GetAdaptersAddressesFuncPtr(AF_UNSPEC, 0, NULL, adapterAddresses, &adapterAddressesSize); if (error == ERROR_BUFFER_OVERFLOW) { PIP_ADAPTER_ADDRESSES newAdapterAddresses = realloc(adapterAddresses, adapterAddressesSize); if (newAdapterAddresses == NULL) return nil; adapterAddresses = newAdapterAddresses; error = GetAdaptersAddressesFuncPtr(AF_UNSPEC, 0, NULL, adapterAddresses, &adapterAddressesSize); } if (error != ERROR_SUCCESS) return nil; for (PIP_ADAPTER_ADDRESSES iter = adapterAddresses; iter != NULL; iter = iter->Next) { OFString *name; OFMutableDictionary *interface; OFNumber *index; name = [OFString stringWithCString: iter->AdapterName encoding: encoding]; if ((interface = [ret objectForKey: name]) == nil) { interface = [OFMutableDictionary dictionary]; [ret setObject: interface forKey: name]; } index = [OFNumber numberWithUnsignedInt: iter->IfIndex]; [interface setObject: index forKey: OFNetworkInterfaceIndex]; if (iter->PhysicalAddressLength > 0) { const OFNetworkInterfaceKey key = OFNetworkInterfaceHardwareAddress; OFData *address = [OFData dataWithItems: iter->PhysicalAddress count: iter->PhysicalAddressLength]; [interface setObject: address forKey: key]; } for (__typeof__(iter->FirstUnicastAddress) addrIter = iter->FirstUnicastAddress; addrIter != NULL; addrIter = addrIter->Next) { OFSocketAddress address; int length; OFNetworkInterfaceKey key; OFMutableData *addresses; length = (int)sizeof(address.sockaddr); if (length > addrIter->Address.iSockaddrLength) length = addrIter->Address.iSockaddrLength; memset(&address, 0, sizeof(OFSocketAddress)); memcpy(&address.sockaddr, addrIter->Address.lpSockaddr, (size_t)length); switch (address.sockaddr.in.sin_family) { case AF_INET: address.family = OFSocketAddressFamilyIPv4; key = OFNetworkInterfaceIPv4Addresses; break; case AF_INET6: address.family = OFSocketAddressFamilyIPv6; key = OFNetworkInterfaceIPv6Addresses; break; default: continue; } addresses = [interface objectForKey: key]; if (addresses == nil) { addresses = [OFMutableData dataWithItemSize: sizeof(OFSocketAddress)]; [interface setObject: addresses forKey: key]; } [addresses addItem: &address]; } [[interface objectForKey: OFNetworkInterfaceIPv4Addresses] makeImmutable]; [[interface objectForKey: OFNetworkInterfaceIPv6Addresses] makeImmutable]; } } @finally { free(adapterAddresses); } return ret; } static OFMutableDictionary OF_GENERIC(OFString *, OFNetworkInterface) * networkInterfacesFromGetAdaptersInfo(void) { OFMutableDictionary *ret = [OFMutableDictionary dictionary]; OFStringEncoding encoding = [OFLocale encoding]; ULONG adapterInfoSize = sizeof(IP_ADAPTER_INFO); PIP_ADAPTER_INFO adapterInfo; if ((adapterInfo = malloc(adapterInfoSize)) == NULL) return nil; @try { ULONG error = GetAdaptersInfo(adapterInfo, &adapterInfoSize); if (error == ERROR_BUFFER_OVERFLOW) { PIP_ADAPTER_INFO newAdapterInfo = realloc(adapterInfo, adapterInfoSize); if (newAdapterInfo == NULL) return nil; adapterInfo = newAdapterInfo; error = GetAdaptersInfo(adapterInfo, &adapterInfoSize); } if (error != ERROR_SUCCESS) return nil; for (PIP_ADAPTER_INFO iter = adapterInfo; iter != NULL; iter = iter->Next) { OFMutableDictionary *interface; OFString *name, *IPString; OFNumber *index; OFSocketAddress IPv4Address; OFData *addresses; name = [OFString stringWithFormat: @"%u", iter->Index]; if ((interface = [ret objectForKey: name]) == nil) { interface = [OFMutableDictionary dictionary]; [ret setObject: interface forKey: name]; } index = [OFNumber numberWithUnsignedInt: iter->Index]; [interface setObject: index forKey: OFNetworkInterfaceIndex]; if (iter->AddressLength > 0) { const OFNetworkInterfaceKey key = OFNetworkInterfaceHardwareAddress; OFData *address = [OFData dataWithItems: iter->Address count: iter->AddressLength]; [interface setObject: address forKey: key]; } IPString = [OFString stringWithCString: iter->IpAddressList.IpAddress .String encoding: encoding]; if ([IPString isEqual: @"0.0.0.0"]) continue; IPv4Address = OFSocketAddressParseIPv4(IPString, 0); addresses = [OFData dataWithItems: &IPv4Address count: 1 itemSize: sizeof(IPv4Address)]; [interface setObject: addresses forKey: OFNetworkInterfaceIPv4Addresses]; } } @finally { free(adapterInfo); } return ret; } @implementation OFSystemInfo (NetworkInterfaces) + (OFDictionary OF_GENERIC(OFString *, OFNetworkInterface) *)networkInterfaces { static OFOnceControl onceControl = OFOnceControlInitValue; void *pool = objc_autoreleasePoolPush(); OFMutableDictionary *ret; OFEnumerator *enumerator; OFMutableDictionary *interface; OFOnce(&onceControl, init); if (GetAdaptersAddressesFuncPtr != NULL) ret = networkInterfacesFromGetAdaptersAddresses(); else ret = networkInterfacesFromGetAdaptersInfo(); enumerator = [ret objectEnumerator]; while ((interface = [enumerator nextObject]) != nil) [interface makeImmutable]; [ret makeImmutable]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @end objfw-1.1.6/src/platform/Windows/OFTLSKey.m000066400000000000000000000017061465614216400204260ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFTLSKey.h" int OFTLSKeyNew(OFTLSKey *key) { *key = TlsAlloc(); if (*key == TLS_OUT_OF_INDEXES) return EAGAIN; return 0; } int OFTLSKeyFree(OFTLSKey key) { return (TlsFree(key) ? 0 : EINVAL); } objfw-1.1.6/src/platform/Windows/OFWin32ConsoleStdIOStream.m000066400000000000000000000350311465614216400236150ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ /* * This file tries to make writing UTF-8 strings to the console "just work" on * Windows. * * While Windows does provide a way to change the codepage of the console to * UTF-8, unfortunately, different Windows versions handle that differently. * For example, on Windows XP, when using Windows XP's console, changing the * codepage to UTF-8 mostly breaks write() and completely breaks read(): * write() suddenly returns the number of characters - instead of bytes - * written and read() just returns 0 as soon as a Unicode character is being * read. * * Therefore, instead of just using the UTF-8 codepage, this captures all reads * and writes to OFStd{In,Out,Err} on the low level, interprets the buffer as * UTF-8 and converts to / from UTF-16 to use ReadConsoleW() / WriteConsoleW(). * Doing so is safe, as the console only supports text anyway and thus it does * not matter if binary gets garbled by the conversion (e.g. because invalid * UTF-8 gets converted to U+FFFD). * * In order to not do this when redirecting input / output to a file (as the * file would then be read / written in the wrong encoding and break reading / * writing binary), it checks that the handle is indeed a console. */ #include "config.h" #include #include #import "OFWin32ConsoleStdIOStream.h" #import "OFColor.h" #import "OFData.h" #import "OFStdIOStream+Private.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFWriteFailedException.h" #include static OFStringEncoding codepageToEncoding(UINT codepage) { switch (codepage) { case 437: return OFStringEncodingCodepage437; case 850: return OFStringEncodingCodepage850; case 858: return OFStringEncodingCodepage858; case 1251: return OFStringEncodingWindows1251; case 1252: return OFStringEncodingWindows1252; default: @throw [OFInvalidEncodingException exception]; } } @implementation OFWin32ConsoleStdIOStream + (void)load { int fd; if (self != [OFWin32ConsoleStdIOStream class]) return; if ((fd = _fileno(stdin)) >= 0) OFStdIn = [[OFWin32ConsoleStdIOStream alloc] of_initWithFileDescriptor: fd]; if ((fd = _fileno(stdout)) >= 0) OFStdOut = [[OFWin32ConsoleStdIOStream alloc] of_initWithFileDescriptor: fd]; if ((fd = _fileno(stderr)) >= 0) OFStdErr = [[OFWin32ConsoleStdIOStream alloc] of_initWithFileDescriptor: fd]; } - (instancetype)of_initWithFileDescriptor: (int)fd { self = [super of_initWithFileDescriptor: fd]; @try { DWORD mode; CONSOLE_SCREEN_BUFFER_INFO csbi; _handle = (HANDLE)_get_osfhandle(fd); if (_handle == INVALID_HANDLE_VALUE) @throw [OFInvalidArgumentException exception]; /* Not a console: Treat it as a regular OFStdIOStream */ if (!GetConsoleMode(_handle, &mode)) object_setClass(self, [OFStdIOStream class]); if (GetConsoleScreenBufferInfo(_handle, &csbi)) _attributes = csbi.wAttributes; } @catch (id e) { [self release]; @throw e; } return self; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer_ length: (size_t)length { void *pool = objc_autoreleasePoolPush(); char *buffer = buffer_; OFChar16 *UTF16; size_t j = 0; if (length > UINT32_MAX) @throw [OFOutOfRangeException exception]; UTF16 = OFAllocMemory(length, sizeof(OFChar16)); @try { DWORD UTF16Len; OFMutableData *rest = nil; size_t i = 0; if ([OFSystemInfo isWindowsNT]) { if (!ReadConsoleW(_handle, UTF16, (DWORD)length, &UTF16Len, NULL)) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length * 2 errNo: EIO]; } else { OFStringEncoding encoding; OFString *string; size_t stringLen; if (!ReadConsoleA(_handle, (char *)UTF16, (DWORD)length, &UTF16Len, NULL)) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: EIO]; encoding = codepageToEncoding(GetConsoleCP()); string = [OFString stringWithCString: (char *)UTF16 encoding: encoding length: UTF16Len]; stringLen = string.UTF16StringLength; if (stringLen > length) @throw [OFOutOfRangeException exception]; UTF16Len = (DWORD)stringLen; memcpy(UTF16, string.UTF16String, stringLen); } if (UTF16Len > 0 && _incompleteUTF16Surrogate != 0) { OFUnichar c = (((_incompleteUTF16Surrogate & 0x3FF) << 10) | (UTF16[0] & 0x3FF)) + 0x10000; char UTF8[4]; size_t UTF8Len; if ((UTF8Len = _OFUTF8StringEncode(c, UTF8)) == 0) @throw [OFInvalidEncodingException exception]; if (UTF8Len <= length) { memcpy(buffer, UTF8, UTF8Len); j += UTF8Len; } else { if (rest == nil) rest = [OFMutableData data]; [rest addItems: UTF8 count: UTF8Len]; } _incompleteUTF16Surrogate = 0; i++; } for (; i < UTF16Len; i++) { OFUnichar c = UTF16[i]; char UTF8[4]; size_t UTF8Len; /* Missing high surrogate */ if ((c & 0xFC00) == 0xDC00) @throw [OFInvalidEncodingException exception]; if ((c & 0xFC00) == 0xD800) { OFChar16 next; if (UTF16Len <= i + 1) { _incompleteUTF16Surrogate = c; if (rest != nil) { const char *items = rest.items; size_t count = rest.count; [self unreadFromBuffer: items length: count]; } objc_autoreleasePoolPop(pool); return j; } next = UTF16[i + 1]; if ((next & 0xFC00) != 0xDC00) @throw [OFInvalidEncodingException exception]; c = (((c & 0x3FF) << 10) | (next & 0x3FF)) + 0x10000; i++; } if ((UTF8Len = _OFUTF8StringEncode(c, UTF8)) == 0) @throw [OFInvalidEncodingException exception]; if (j + UTF8Len <= length) { memcpy(buffer + j, UTF8, UTF8Len); j += UTF8Len; } else { if (rest == nil) rest = [OFMutableData data]; [rest addItems: UTF8 count: UTF8Len]; } } if (rest != nil) [self unreadFromBuffer: rest.items length: rest.count]; } @finally { OFFreeMemory(UTF16); } objc_autoreleasePoolPop(pool); return j; } - (size_t)lowlevelWriteBuffer: (const void *)buffer_ length: (size_t)length { const char *buffer = buffer_; OFChar16 *tmp; size_t i = 0, j = 0; if (length > SIZE_MAX / 2) @throw [OFOutOfRangeException exception]; if (_incompleteUTF8SurrogateLen > 0) { OFUnichar c; OFChar16 UTF16[2]; ssize_t UTF8Len; size_t toCopy; DWORD UTF16Len, bytesWritten; UTF8Len = -_OFUTF8StringDecode( _incompleteUTF8Surrogate, _incompleteUTF8SurrogateLen, &c); OFEnsure(UTF8Len > 0); toCopy = UTF8Len - _incompleteUTF8SurrogateLen; if (toCopy > length) toCopy = length; memcpy(_incompleteUTF8Surrogate + _incompleteUTF8SurrogateLen, buffer, toCopy); _incompleteUTF8SurrogateLen += toCopy; if (_incompleteUTF8SurrogateLen < (size_t)UTF8Len) return 0; UTF8Len = _OFUTF8StringDecode( _incompleteUTF8Surrogate, _incompleteUTF8SurrogateLen, &c); if (UTF8Len <= 0 || c > 0x10FFFF) { OFAssert(UTF8Len == 0 || UTF8Len < -4); UTF16[0] = 0xFFFD; UTF16Len = 1; } else { if (c > 0xFFFF) { c -= 0x10000; UTF16[0] = 0xD800 | (c >> 10); UTF16[1] = 0xDC00 | (c & 0x3FF); UTF16Len = 2; } else { UTF16[0] = c; UTF16Len = 1; } } if ([OFSystemInfo isWindowsNT]) { if (!WriteConsoleW(_handle, UTF16, UTF16Len, &bytesWritten, NULL)) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: UTF16Len * 2 bytesWritten: bytesWritten * 2 errNo: EIO]; } else { void *pool = objc_autoreleasePoolPush(); OFString *string = [OFString stringWithUTF16String: UTF16 length: UTF16Len]; OFStringEncoding encoding = codepageToEncoding(GetConsoleOutputCP()); size_t nativeLen = [string cStringLengthWithEncoding: encoding]; if (nativeLen > UINT32_MAX) @throw [OFOutOfRangeException exception]; if (!WriteConsoleA(_handle, [string cStringWithEncoding: encoding], (DWORD)nativeLen, &bytesWritten, NULL)) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: nativeLen bytesWritten: bytesWritten errNo: EIO]; objc_autoreleasePoolPop(pool); } if (bytesWritten != UTF16Len) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: UTF16Len * 2 bytesWritten: bytesWritten * 2 errNo: 0]; _incompleteUTF8SurrogateLen = 0; i += toCopy; } tmp = OFAllocMemory(length * 2, sizeof(OFChar16)); @try { DWORD bytesWritten; while (i < length) { OFUnichar c; ssize_t UTF8Len; UTF8Len = _OFUTF8StringDecode(buffer + i, length - i, &c); if (UTF8Len < 0 && UTF8Len >= -4) { OFEnsure(length - i < 4); memcpy(_incompleteUTF8Surrogate, buffer + i, length - i); _incompleteUTF8SurrogateLen = length - i; break; } if (UTF8Len <= 0 || c > 0x10FFFF) { tmp[j++] = 0xFFFD; i++; continue; } if (c > 0xFFFF) { c -= 0x10000; tmp[j++] = 0xD800 | (c >> 10); tmp[j++] = 0xDC00 | (c & 0x3FF); } else tmp[j++] = c; i += UTF8Len; } if (j > UINT32_MAX) @throw [OFOutOfRangeException exception]; if ([OFSystemInfo isWindowsNT]) { if (!WriteConsoleW(_handle, tmp, (DWORD)j, &bytesWritten, NULL)) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: j * 2 bytesWritten: bytesWritten * 2 errNo: EIO]; } else { void *pool = objc_autoreleasePoolPush(); OFString *string = [OFString stringWithUTF16String: tmp length: j]; OFStringEncoding encoding = codepageToEncoding(GetConsoleOutputCP()); size_t nativeLen = [string cStringLengthWithEncoding: encoding]; if (nativeLen > UINT32_MAX) @throw [OFOutOfRangeException exception]; if (!WriteConsoleA(_handle, [string cStringWithEncoding: encoding], (DWORD)nativeLen, &bytesWritten, NULL)) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: nativeLen bytesWritten: bytesWritten errNo: EIO]; objc_autoreleasePoolPop(pool); } if (bytesWritten != j) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: j * 2 bytesWritten: bytesWritten * 2 errNo: 0]; } @finally { OFFreeMemory(tmp); } /* * We do not count in bytes when writing to the Win32 console. But * since any incomplete write is an exception here anyway, we can just * return length. */ return length; } - (bool)hasTerminal { /* * We can never get here if there is no terminal, as the initializer * changes the class to OFStdIOStream in that case. */ return true; } - (int)columns { CONSOLE_SCREEN_BUFFER_INFO csbi; if (!GetConsoleScreenBufferInfo(_handle, &csbi)) return -1; return csbi.dwSize.X; } - (int)rows { /* * The buffer size returned is almost always larger than the window * size, so this is useless. */ return -1; } - (void)setForegroundColor: (OFColor *)color { CONSOLE_SCREEN_BUFFER_INFO csbi; float red, green, blue; if (!GetConsoleScreenBufferInfo(_handle, &csbi)) return; csbi.wAttributes &= ~(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY); [color getRed: &red green: &green blue: &blue alpha: NULL]; if (red >= 0.25) csbi.wAttributes |= FOREGROUND_RED; if (green >= 0.25) csbi.wAttributes |= FOREGROUND_GREEN; if (blue >= 0.25) csbi.wAttributes |= FOREGROUND_BLUE; if (red >= 0.75 || green >= 0.75 || blue >= 0.75) csbi.wAttributes |= FOREGROUND_INTENSITY; SetConsoleTextAttribute(_handle, csbi.wAttributes); } - (void)setBackgroundColor: (OFColor *)color { CONSOLE_SCREEN_BUFFER_INFO csbi; float red, green, blue; if (!GetConsoleScreenBufferInfo(_handle, &csbi)) return; csbi.wAttributes &= ~(BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY); [color getRed: &red green: &green blue: &blue alpha: NULL]; if (red >= 0.25) csbi.wAttributes |= BACKGROUND_RED; if (green >= 0.25) csbi.wAttributes |= BACKGROUND_GREEN; if (blue >= 0.25) csbi.wAttributes |= BACKGROUND_BLUE; if (red >= 0.75 || green >= 0.75 || blue >= 0.75) csbi.wAttributes |= BACKGROUND_INTENSITY; SetConsoleTextAttribute(_handle, csbi.wAttributes); } - (void)reset { SetConsoleTextAttribute(_handle, _attributes); } - (void)clear { static COORD zero = { 0, 0 }; CONSOLE_SCREEN_BUFFER_INFO csbi; DWORD bytesWritten; if (!GetConsoleScreenBufferInfo(_handle, &csbi)) return; if (!FillConsoleOutputCharacter(_handle, ' ', csbi.dwSize.X * csbi.dwSize.Y, zero, &bytesWritten)) return; if (!FillConsoleOutputAttribute(_handle, csbi.wAttributes, csbi.dwSize.X * csbi.dwSize.Y, zero, &bytesWritten)) return; SetConsoleCursorPosition(_handle, zero); } - (void)eraseLine { CONSOLE_SCREEN_BUFFER_INFO csbi; DWORD bytesWritten; if (!GetConsoleScreenBufferInfo(_handle, &csbi)) return; csbi.dwCursorPosition.X = 0; if (!FillConsoleOutputCharacter(_handle, ' ', csbi.dwSize.X, csbi.dwCursorPosition, &bytesWritten)) return; FillConsoleOutputAttribute(_handle, csbi.wAttributes, csbi.dwSize.X, csbi.dwCursorPosition, &bytesWritten); } - (void)setCursorColumn: (unsigned int)column { CONSOLE_SCREEN_BUFFER_INFO csbi; if (!GetConsoleScreenBufferInfo(_handle, &csbi)) return; csbi.dwCursorPosition.X = column; SetConsoleCursorPosition(_handle, csbi.dwCursorPosition); } - (void)setCursorPosition: (OFPoint)position { if (position.x < 0 || position.y < 0) @throw [OFInvalidArgumentException exception]; SetConsoleCursorPosition(_handle, (COORD){ position.x, position.y }); } - (void)setRelativeCursorPosition: (OFPoint)position { CONSOLE_SCREEN_BUFFER_INFO csbi; if (!GetConsoleScreenBufferInfo(_handle, &csbi)) return; csbi.dwCursorPosition.X += position.x; csbi.dwCursorPosition.Y += position.y; SetConsoleCursorPosition(_handle, csbi.dwCursorPosition); } @end objfw-1.1.6/src/platform/libfat/000077500000000000000000000000001465614216400165135ustar00rootroot00000000000000objfw-1.1.6/src/platform/libfat/OFString+PathAdditions.m000066400000000000000000000176171465614216400231270ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFString+PathAdditions.h" #import "OFArray.h" #import "OFFileIRIHandler.h" #import "OFOutOfRangeException.h" int _OFString_PathAdditions_reference; @implementation OFString (PathAdditions) + (OFString *)pathWithComponents: (OFArray *)components { OFMutableString *ret = [OFMutableString string]; void *pool = objc_autoreleasePoolPush(); bool first = true; for (OFString *component in components) { if (component.length == 0) continue; if ([component isEqual: @"/"]) continue; if (!first && ![ret hasSuffix: @"/"]) [ret appendString: @"/"]; [ret appendString: component]; first = false; } if ([ret hasSuffix: @":"]) [ret appendString: @"/"]; [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } - (bool)isAbsolutePath { return [self containsString: @":/"]; } - (OFArray *)pathComponents { OFMutableArray OF_GENERIC(OFString *) *ret = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); const char *cString = self.UTF8String; size_t i, last = 0, cStringLength = self.UTF8StringLength; if (cStringLength == 0) { objc_autoreleasePoolPop(pool); return ret; } for (i = 0; i < cStringLength; i++) { if (cString[i] == '/') { if (i - last != 0) [ret addObject: [OFString stringWithUTF8String: cString + last length: i - last]]; last = i + 1; } } if (i - last != 0) [ret addObject: [OFString stringWithUTF8String: cString + last length: i - last]]; [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } - (OFString *)lastPathComponent { void *pool = objc_autoreleasePoolPush(); const char *cString; size_t cStringLength; ssize_t i; OFString *ret; if ([self hasSuffix: @":/"]) return self; cString = self.UTF8String; cStringLength = self.UTF8StringLength; if (cStringLength == 0) { objc_autoreleasePoolPop(pool); return @""; } if (cString[cStringLength - 1] == '/') cStringLength--; if (cStringLength == 0) { objc_autoreleasePoolPop(pool); return @""; } if (cStringLength - 1 > SSIZE_MAX) @throw [OFOutOfRangeException exception]; for (i = cStringLength - 1; i >= 0; i--) { if (cString[i] == '/') { i++; break; } } /* * Only one component, but the trailing delimiter might have been * removed, so return a new string anyway. */ if (i < 0) i = 0; ret = [[OFString alloc] initWithUTF8String: cString + i length: cStringLength - i]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)pathExtension { void *pool = objc_autoreleasePoolPush(); OFString *ret, *fileName; size_t pos; fileName = self.lastPathComponent; pos = [fileName rangeOfString: @"." options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return @""; } ret = [fileName substringFromIndex: pos + 1]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)stringByDeletingLastPathComponent { void *pool = objc_autoreleasePoolPush(); const char *cString; size_t cStringLength; OFString *ret; if ([self hasSuffix: @":/"]) return self; cString = self.UTF8String; cStringLength = self.UTF8StringLength; if (cStringLength == 0) { objc_autoreleasePoolPop(pool); return @""; } if (cString[cStringLength - 1] == '/') cStringLength--; if (cStringLength == 0) { objc_autoreleasePoolPop(pool); return @""; } for (size_t i = cStringLength; i >= 1; i--) { if (cString[i - 1] == '/') { ret = [[OFString alloc] initWithUTF8String: cString length: i - 1]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } } objc_autoreleasePoolPop(pool); return @"."; } - (OFString *)stringByDeletingPathExtension { void *pool; OFMutableArray OF_GENERIC(OFString *) *components; OFString *ret, *fileName; size_t pos; if (self.length == 0) return [[self copy] autorelease]; pool = objc_autoreleasePoolPush(); components = [[self.pathComponents mutableCopy] autorelease]; fileName = components.lastObject; pos = [fileName rangeOfString: @"." options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return [[self copy] autorelease]; } fileName = [fileName substringToIndex: pos]; [components replaceObjectAtIndex: components.count - 1 withObject: fileName]; ret = [OFString pathWithComponents: components]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)stringByStandardizingPath { void *pool = objc_autoreleasePoolPush(); OFArray OF_GENERIC(OFString *) *components; OFMutableArray OF_GENERIC(OFString *) *array; OFString *ret; bool done = false; if (self.length == 0) return @""; components = self.pathComponents; if (components.count == 1) { objc_autoreleasePoolPop(pool); return [[self copy] autorelease]; } array = [[components mutableCopy] autorelease]; while (!done) { size_t length = array.count; done = true; for (size_t i = 0; i < length; i++) { OFString *component = [array objectAtIndex: i]; OFString *parent = (i > 0 ? [array objectAtIndex: i - 1] : 0); if ([component isEqual: @"."] || component.length == 0) { [array removeObjectAtIndex: i]; done = false; break; } if ([component isEqual: @".."] && parent != nil && ![parent isEqual: @".."]) { [array removeObjectsInRange: OFMakeRange(i - 1, 2)]; done = false; break; } } } if ([self hasSuffix: @"/"]) [array addObject: @""]; ret = [[array componentsJoinedByString: @"/"] retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)stringByAppendingPathComponent: (OFString *)component { if (self.length == 0) return component; if ([self hasSuffix: @"/"]) return [self stringByAppendingString: component]; else { OFMutableString *ret = [[self mutableCopy] autorelease]; [ret appendString: @"/"]; [ret appendString: component]; [ret makeImmutable]; return ret; } } - (OFString *)stringByAppendingPathExtension: (OFString *)extension { if ([self hasSuffix: @"/"]) { void *pool = objc_autoreleasePoolPush(); OFMutableArray *components; OFString *fileName, *ret; components = [[self.pathComponents mutableCopy] autorelease]; fileName = [components.lastObject stringByAppendingFormat: @".%@", extension]; [components replaceObjectAtIndex: components.count - 1 withObject: fileName]; ret = [[OFString pathWithComponents: components] retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } else return [self stringByAppendingFormat: @".%@", extension]; } - (bool)of_isDirectoryPath { return ([self hasSuffix: @"/"] || [OFFileIRIHandler of_directoryExistsAtPath: self]); } - (OFString *)of_pathToIRIPathWithPercentEncodedHost: (OFString **)percentEncodedHost { return [@"/" stringByAppendingString: self]; } - (OFString *)of_IRIPathToPathWithPercentEncodedHost: (OFString *)percentEncodedHost { OFString *path = self; if (path.length > 1 && [path hasSuffix: @"/"]) path = [path substringToIndex: path.length - 1]; return [path substringFromIndex: 1]; } - (OFString *)of_pathComponentToIRIPathComponent { return self; } @end objfw-1.1.6/src/platform/macOS/000077500000000000000000000000001465614216400162545ustar00rootroot00000000000000objfw-1.1.6/src/platform/macOS/OFAtomic.h000066400000000000000000000067441465614216400201010ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include static OF_INLINE int OFAtomicIntAdd(volatile int *_Nonnull p, int i) { return OSAtomicAdd32(i, p); } static OF_INLINE int32_t OFAtomicInt32Add(volatile int32_t *_Nonnull p, int32_t i) { return OSAtomicAdd32(i, p); } static OF_INLINE void *_Nullable OFAtomicPointerAdd(void *volatile _Nullable *_Nonnull p, intptr_t i) { #ifdef __LP64__ return (void *)OSAtomicAdd64(i, (int64_t *)p); #else return (void *)OSAtomicAdd32(i, (int32_t *)p); #endif } static OF_INLINE int OFAtomicIntSubtract(volatile int *_Nonnull p, int i) { return OSAtomicAdd32(-i, p); } static OF_INLINE int32_t OFAtomicInt32Subtract(volatile int32_t *_Nonnull p, int32_t i) { return OSAtomicAdd32(-i, p); } static OF_INLINE void *_Nullable OFAtomicPointerSubtract(void *volatile _Nullable *_Nonnull p, intptr_t i) { #ifdef __LP64__ return (void *)OSAtomicAdd64(-i, (int64_t *)p); #else return (void *)OSAtomicAdd32(-i, (int32_t *)p); #endif } static OF_INLINE int OFAtomicIntIncrease(volatile int *_Nonnull p) { return OSAtomicIncrement32(p); } static OF_INLINE int32_t OFAtomicInt32Increase(volatile int32_t *_Nonnull p) { return OSAtomicIncrement32(p); } static OF_INLINE int OFAtomicIntDecrease(volatile int *_Nonnull p) { return OSAtomicDecrement32(p); } static OF_INLINE int32_t OFAtomicInt32Decrease(volatile int32_t *_Nonnull p) { return OSAtomicDecrement32(p); } static OF_INLINE unsigned int OFAtomicIntOr(volatile unsigned int *_Nonnull p, unsigned int i) { return OSAtomicOr32(i, p); } static OF_INLINE uint32_t OFAtomicInt32Or(volatile uint32_t *_Nonnull p, uint32_t i) { return OSAtomicOr32(i, p); } static OF_INLINE unsigned int OFAtomicIntAnd(volatile unsigned int *_Nonnull p, unsigned int i) { return OSAtomicAnd32(i, p); } static OF_INLINE uint32_t OFAtomicInt32And(volatile uint32_t *_Nonnull p, uint32_t i) { return OSAtomicAnd32(i, p); } static OF_INLINE unsigned int OFAtomicIntXor(volatile unsigned int *_Nonnull p, unsigned int i) { return OSAtomicXor32(i, p); } static OF_INLINE uint32_t OFAtomicInt32Xor(volatile uint32_t *_Nonnull p, uint32_t i) { return OSAtomicXor32(i, p); } static OF_INLINE bool OFAtomicIntCompareAndSwap(volatile int *_Nonnull p, int o, int n) { return OSAtomicCompareAndSwapInt(o, n, p); } static OF_INLINE bool OFAtomicInt32CompareAndSwap(volatile int32_t *_Nonnull p, int32_t o, int32_t n) { return OSAtomicCompareAndSwap32(o, n, p); } static OF_INLINE bool OFAtomicPointerCompareAndSwap(void *volatile _Nullable *_Nonnull p, void *_Nullable o, void *_Nullable n) { return OSAtomicCompareAndSwapPtr(o, n, p); } static OF_INLINE void OFMemoryBarrier(void) { OSMemoryBarrier(); } static OF_INLINE void OFAcquireMemoryBarrier(void) { OSMemoryBarrier(); } static OF_INLINE void OFReleaseMemoryBarrier(void) { OSMemoryBarrier(); } objfw-1.1.6/src/platform/x86/000077500000000000000000000000001465614216400156775ustar00rootroot00000000000000objfw-1.1.6/src/platform/x86/OFAtomic.h000066400000000000000000000216621465614216400175200ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ OF_ASSUME_NONNULL_BEGIN static OF_INLINE int32_t OFAtomicInt32Add(volatile int32_t *_Nonnull p, int32_t i) { __asm__ __volatile__ ( "lock\n\t" "xadd{l} { %0, %2 | %2, %0 }\n\t" "add{l} { %1, %0 | %0, %1 }" : "+&r" (i) : "r" (i), "m" (*p) ); return i; } static OF_INLINE int OFAtomicIntAdd(volatile int *_Nonnull p, int i) { if (sizeof(int) == 4) return OFAtomicInt32Add(p, i); #ifdef OF_AMD64 else if (sizeof(int) == 8) __asm__ __volatile__ ( "lock\n\t" "xadd{q} { %0, %2 | %2, %0 }\n\t" "add{q} { %1, %0 | %0, %1 }" : "+&r" (i) : "r" (i), "m" (*p) ); #endif else abort(); return i; } static OF_INLINE void *_Nullable OFAtomicPointerAdd(void *volatile _Nullable *_Nonnull p, intptr_t i) { #if defined(OF_AMD64) __asm__ __volatile__ ( "lock\n\t" "xadd{q} { %0, %2 | %2, %0 }\n\t" "add{q} { %1, %0 | %0, %1 }" : "+&r" (i) : "r" (i), "m" (*p) ); return (void *)i; #elif defined(OF_X86) __asm__ __volatile__ ( "lock\n\t" "xadd{l} { %0, %2 | %2, %0 }\n\t" "add{l} { %1, %0 | %0, %1 }" : "+&r" (i) : "r" (i), "m" (*p) ); return (void *)i; #endif } static OF_INLINE int32_t OFAtomicInt32Subtract(volatile int32_t *_Nonnull p, int32_t i) { __asm__ __volatile__ ( "neg{l} %0\n\t" "lock\n\t" "xadd{l} { %0, %2 | %2, %0 }\n\t" "sub{l} { %1, %0 | %0, %1 }" : "+&r" (i) : "r" (i), "m" (*p) ); return i; } static OF_INLINE int OFAtomicIntSubtract(volatile int *_Nonnull p, int i) { if (sizeof(int) == 4) return OFAtomicInt32Subtract(p, i); #ifdef OF_AMD64 else if (sizeof(int) == 8) __asm__ __volatile__ ( "neg{q} %0\n\t" "lock\n\t" "xadd{q} { %0, %2 | %2, %0 }\n\t" "sub{q} { %1, %0 | %0, %1 }" : "+&r" (i) : "r" (i), "m" (*p) ); #endif else abort(); return i; } static OF_INLINE void *_Nullable OFAtomicPointerSubtract(void *volatile _Nullable *_Nonnull p, intptr_t i) { #if defined(OF_AMD64) __asm__ __volatile__ ( "neg{q} %0\n\t" "lock\n\t" "xadd{q} { %0, %2 | %2, %0 }\n\t" "sub{q} { %1, %0 | %0, %1 }" : "+&r" (i) : "r" (i), "m" (*p) ); return (void *)i; #elif defined(OF_X86) __asm__ __volatile__ ( "neg{l} %0\n\t" "lock\n\t" "xadd{l} { %0, %2 | %2, %0 }\n\t" "sub{l} { %1, %0 | %0, %1 }" : "+&r" (i) : "r" (i), "m" (*p) ); return (void *)i; #endif } static OF_INLINE int32_t OFAtomicInt32Increase(volatile int32_t *_Nonnull p) { int32_t i; __asm__ __volatile__ ( "xor{l} %0, %0\n\t" "inc{l} %0\n\t" "lock\n\t" "xadd{l} { %0, %1 | %1, %0 }\n\t" "inc{l} %0" : "=&r" (i) : "m" (*p) ); return i; } static OF_INLINE int OFAtomicIntIncrease(volatile int *_Nonnull p) { int i; if (sizeof(int) == 4) return OFAtomicInt32Increase(p); #ifdef OF_AMD64 else if (sizeof(int) == 8) __asm__ __volatile__ ( "xor{q} %0, %0\n\t" "inc{q} %0\n\t" "lock\n\t" "xadd{q} { %0, %1 | %1, %0 }\n\t" "inc{q} %0" : "=&r" (i) : "m" (*p) ); #endif else abort(); return i; } static OF_INLINE int32_t OFAtomicInt32Decrease(volatile int32_t *_Nonnull p) { int32_t i; __asm__ __volatile__ ( "xor{l} %0, %0\n\t" "dec{l} %0\n\t" "lock\n\t" "xadd{l} { %0, %1 | %1, %0 }\n\t" "dec{l} %0" : "=&r" (i) : "m" (*p) ); return i; } static OF_INLINE int OFAtomicIntDecrease(volatile int *_Nonnull p) { int i; if (sizeof(int) == 4) return OFAtomicInt32Decrease(p); #ifdef OF_AMD64 else if (sizeof(int) == 8) __asm__ __volatile__ ( "xor{q} %0, %0\n\t" "dec{q} %0\n\t" "lock\n\t" "xadd{q} { %0, %1 | %1, %0 }\n\t" "dec{q} %0" : "=&r" (i) : "m" (*p) ); #endif else abort(); return i; } static OF_INLINE uint32_t OFAtomicInt32Or(volatile uint32_t *_Nonnull p, uint32_t i) { __asm__ __volatile__ ( "0:\n\t" "mov{l} { %2, %0 | %0, %2 }\n\t" "mov{l} { %0, %%eax | eax, %0 }\n\t" "or{l} { %1, %0 | %0, %1 }\n\t" "lock\n\t" "cmpxchg{l} { %0, %2 | %2, %0 }\n\t" "jne 0b" : "=&r" (i) : "r" (i), "m" (*p) : "eax", "cc" ); return i; } static OF_INLINE unsigned int OFAtomicIntOr(volatile unsigned int *_Nonnull p, unsigned int i) { if (sizeof(int) == 4) return OFAtomicInt32Or(p, i); #ifdef OF_AMD64 else if (sizeof(int) == 8) __asm__ __volatile__ ( "0:\n\t" "mov{q} { %2, %0 | %0, %2 }\n\t" "mov{q} { %0, %%rax | rax, %0 }\n\t" "or{q} { %1, %0 | %0, %1 }\n\t" "lock\n\t" "cmpxchg{q} { %0, %2 | %2, %0 }\n\t" "jne 0b" : "=&r" (i) : "r" (i), "m" (*p) : "rax", "cc" ); #endif else abort(); return i; } static OF_INLINE uint32_t OFAtomicInt32And(volatile uint32_t *_Nonnull p, uint32_t i) { __asm__ __volatile__ ( "0:\n\t" "mov{l} { %2, %0 | %0, %2 }\n\t" "mov{l} { %0, %%eax | eax, %0 }\n\t" "and{l} { %1, %0 | %0, %1 }\n\t" "lock\n\t" "cmpxchg{l} { %0, %2 | %2, %0 }\n\t" "jne 0b" : "=&r" (i) : "r" (i), "m" (*p) : "eax", "cc" ); return i; } static OF_INLINE unsigned int OFAtomicIntAnd(volatile unsigned int *_Nonnull p, unsigned int i) { if (sizeof(int) == 4) return OFAtomicInt32And(p, i); #ifdef OF_AMD64 else if (sizeof(int) == 8) __asm__ __volatile__ ( "0:\n\t" "mov{q} { %2, %0 | %0, %2 }\n\t" "mov{q} { %0, %%rax | rax, %0 }\n\t" "and{q} { %1, %0 | %0, %1 }\n\t" "lock\n\t" "cmpxchg{q} { %0, %2 | %2, %0 }\n\t" "jne 0b" : "=&r" (i) : "r" (i), "m" (*p) : "rax", "cc" ); #endif else abort(); return i; } static OF_INLINE uint32_t OFAtomicInt32Xor(volatile uint32_t *_Nonnull p, uint32_t i) { __asm__ __volatile__ ( "0:\n\t" "mov{l} { %2, %0 | %0, %2 }\n\t" "mov{l} { %0, %%eax | eax, %0 }\n\t" "xor{l} { %1, %0 | %0, %1 }\n\t" "lock\n\t" "cmpxchg{l} { %0, %2 | %2, %0 }\n\t" "jne 0b" : "=&r" (i) : "r" (i), "m" (*p) : "eax", "cc" ); return i; } static OF_INLINE unsigned int OFAtomicIntXor(volatile unsigned int *_Nonnull p, unsigned int i) { if (sizeof(int) == 4) return OFAtomicInt32Xor(p, i); #ifdef OF_AMD64 else if (sizeof(int) == 8) __asm__ __volatile__ ( "0:\n\t" "mov{q} { %2, %0 | %0, %2 }\n\t" "mov{q} { %0, %%rax | rax, %0 }\n\t" "xor{q} { %1, %0 | %0, %1 }\n\t" "lock\n\t" "cmpxchg{q} { %0, %2 | %2, %0 }\n\t" "jne 0b" : "=&r" (i) : "r" (i), "m" (*p) : "rax", "cc" ); #endif else abort(); return i; } static OF_INLINE bool OFAtomicInt32CompareAndSwap(volatile int32_t *_Nonnull p, int32_t o, int32_t n) { int r; __asm__ __volatile__ ( "lock\n\t" "cmpxchg{l} { %2, %3 | %3, %2 }\n\t" "sete %b0\n\t" "movz{bl|x} { %b0, %0 | %0, %b0 }" : "=&d" (r), /* use d instead of r to avoid a gcc bug */ "+a" (o) : "r" (n), "m" (*p) : "cc" ); return r; } static OF_INLINE bool OFAtomicIntCompareAndSwap(volatile int *_Nonnull p, int o, int n) { int r; __asm__ __volatile__ ( "lock\n\t" "cmpxchg { %2, %3 | %3, %2 }\n\t" "sete %b0\n\t" "movz{bl|x} { %b0, %0 | %0, %b0 }" : "=&d" (r), /* use d instead of r to avoid a gcc bug */ "+a" (o) : "r" (n), "m" (*p) : "cc" ); return r; } static OF_INLINE bool OFAtomicPointerCompareAndSwap(void *volatile _Nullable *_Nonnull p, void *_Nullable o, void *_Nullable n) { int r; __asm__ __volatile__ ( "lock\n\t" "cmpxchg { %2, %3 | %3, %2 }\n\t" "sete %b0\n\t" "movz{bl|x} { %b0, %0 | %0, %b0 }" : "=&d" (r), /* use d instead of r to avoid a gcc bug */ "+a" (o) : "r" (n), "m" (*p) : "cc" ); return r; } static OF_INLINE void OFMemoryBarrier(void) { #ifdef OF_AMD64 __asm__ __volatile__ ( "lock or{q} { $0, (%%rsp) | [rsp], 0 }" ::: "memory", "cc" ); #else __asm__ __volatile__ ( "lock or{l} { $0, (%%esp) | [esp], 0 }" ::: "memory", "cc" ); #endif } static OF_INLINE void OFAcquireMemoryBarrier(void) { __asm__ __volatile__ ("" ::: "memory"); } static OF_INLINE void OFReleaseMemoryBarrier(void) { __asm__ __volatile__ ("" ::: "memory"); } OF_ASSUME_NONNULL_END objfw-1.1.6/src/runtime/000077500000000000000000000000001465614216400151115ustar00rootroot00000000000000objfw-1.1.6/src/runtime/Info.plist.in000066400000000000000000000012421465614216400174650ustar00rootroot00000000000000 CFBundleExecutable ObjFWRT CFBundleName ObjFWRT CFBundleIdentifier im.nil.objfw.rt CFBundleInfoDictionaryVersion 6.0 CFBundlePackageType FMWK CFBundleVersion @BUNDLE_VERSION@ CFBundleShortVersionString @BUNDLE_SHORT_VERSION@ MinimumOSVersion 9.0 objfw-1.1.6/src/runtime/Makefile000066400000000000000000000027731465614216400165620ustar00rootroot00000000000000include ../../extra.mk SUBDIRS = lookup-asm DISTCLEAN = Info.plist SHARED_LIB = ${OBJFWRT_SHARED_LIB} STATIC_LIB = ${OBJFWRT_STATIC_LIB} FRAMEWORK = ${OBJFWRT_FRAMEWORK} LIB_MAJOR = ${OBJFWRT_LIB_MAJOR} LIB_MINOR = ${OBJFWRT_LIB_MINOR} LIB_PATCH = ${OBJFWRT_LIB_PATCH} SRCS = arc.m \ association.m \ autorelease.m \ category.m \ class.m \ dtable.m \ exception.m \ hashtable.m \ init.m \ instance.m \ ivar.m \ lookup.m \ method.m \ misc.m \ property.m \ protocol.m \ selector.m \ sparsearray.m \ static-instances.m \ synchronized.m \ tagged-pointer.m \ ${USE_SRCS_THREADS} \ ${USE_SRCS_WINDOWS} SRCS_THREADS = OFOnce.m \ OFPlainMutex.m \ OFTLSKey.m \ threading.m SRCS_WINDOWS = versioninfo.rc INCLUDES = ObjFWRT.h includesubdir = ObjFWRT OBJS_EXTRA = lookup-asm/lookup-asm.a LIB_OBJS_EXTRA = lookup-asm/lookup-asm.lib.a include ../../buildsys.mk CPPFLAGS += -I. -I.. -I../.. \ -DOBJC_COMPILING_RUNTIME \ -DOBJFWRT_LIB_MAJOR=${OBJFWRT_LIB_MAJOR} \ -DOBJFWRT_LIB_MINOR=${OBJFWRT_LIB_MINOR} LD = ${OBJC} FRAMEWORK_LIBS = ${LIBS} RCFLAGS = --use-temp-file \ -DOBJFWRT_LIB_MAJOR=${OBJFWRT_LIB_MAJOR} \ -DOBJFWRT_LIB_MINOR=${OBJFWRT_LIB_MINOR} \ -DOBJFWRT_LIB_VERSION=\"${OBJFWRT_LIB_MAJOR}.${OBJFWRT_LIB_MINOR}\" \ -DOBJFWRT_SHARED_LIB=\"${OBJFWRT_SHARED_LIB}\" objfw-1.1.6/src/runtime/OFOnce.m000066400000000000000000000014611465614216400164020ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFWRT.h" #import "private.h" #include "../OFOnce.m" objfw-1.1.6/src/runtime/OFPlainMutex.m000066400000000000000000000014671465614216400176120ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFWRT.h" #import "private.h" #include "../OFPlainMutex.m" objfw-1.1.6/src/runtime/OFTLSKey.m000066400000000000000000000014631465614216400166330ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFWRT.h" #import "private.h" #include "../OFTLSKey.m" objfw-1.1.6/src/runtime/ObjFWRT.h000066400000000000000000000605751465614216400165140ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifndef OBJFWRT_OBJFWRT_H #define OBJFWRT_OBJFWRT_H #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif #include #include #include /** @file */ #ifndef __has_feature # define __has_feature(x) 0 #endif #ifndef __has_attribute # define __has_attribute(x) 0 #endif #if !__has_feature(nullability) # ifndef _Nonnull # define _Nonnull # endif # ifndef _Nullable # define _Nullable # endif # ifndef _Null_unspecified # define _Null_unspecified # endif #endif #if !__has_feature(objc_arc) && !defined(__unsafe_unretained) # define __unsafe_unretained #endif /** * @brief A value representing no class. */ #define Nil (Class _Null_unspecified)0 /** * @brief A value representing no object. */ #define nil (id _Null_unspecified)0 /** * @brief An Objective-C boolean representing true. * * @note This is a legacy from before C had a boolean type. Prefer the standard * C99 true instead! */ #define YES true /** * @brief An Objective-C boolean representing false. * * @note This is a legacy from before C had a boolean type. Prefer the standard * C99 false instead! */ #define NO false /** * @brief A pointer to a class. */ typedef struct objc_class *Class; /** * @brief A pointer to any object. */ typedef struct objc_object *id; /** * @brief A selector. * * A selector is the name of a method including the colons and an optional type * encoding. */ typedef const struct objc_selector *SEL; /** * @brief A method. * * A method consists of a selector with a type encoding and an implementation. */ typedef const struct objc_method *Method; /** * @brief A protocol. */ #if defined(__OBJC__) && !defined(DOXYGEN) @class Protocol; #else typedef const struct objc_protocol *Protocol; #endif /** * @brief An instance variable. */ typedef const struct objc_ivar *Ivar; /** * @brief A property. */ typedef const struct objc_property *objc_property_t; #if !defined(__wii__) && !defined(__amigaos__) /** * @brief An Objective-C boolean. Either @ref YES or @ref NO. * * @note This is a legacy from before C had a boolean type. Prefer the standard * C99 bool instead! */ typedef bool BOOL; #endif /** * @brief A method implementation. * * @param object The messaged object * @param selector The selector sent */ typedef id _Nullable (*IMP)(id _Nonnull object, SEL _Nonnull selector, ...); /** * @brief A handler for uncaught exceptions. * * @param exception The exception which was not caught. */ typedef void (*objc_uncaught_exception_handler)(id _Nullable exception); /** * @brief A handler for mutation during enumeration. * * @param object The object that was mutated during enumeration */ typedef void (*objc_enumeration_mutation_handler)(id _Nonnull object); /** * @brief A struct representing a call to super. */ struct objc_super { /** * @brief The object on which to perform the super call. */ id __unsafe_unretained _Nullable self; /** * @brief The class from which to take the method. */ #ifdef __cplusplus Class _Nonnull class_; #else Class _Nonnull class; #endif }; /** * @brief A policy for object association, see @ref objc_setAssociatedObject. */ typedef enum objc_associationPolicy { /** @brief Associate the object like an assigned property. */ OBJC_ASSOCIATION_ASSIGN = 0, /** @brief Associate the object like a retained, nonatomic property. */ OBJC_ASSOCIATION_RETAIN_NONATOMIC = 1, /** @brief Associate the object like a retained property. */ OBJC_ASSOCIATION_RETAIN = OBJC_ASSOCIATION_RETAIN_NONATOMIC | 0x300, /** @brief Associate the object like a copied, nonatomic property. */ OBJC_ASSOCIATION_COPY_NONATOMIC = 3, /** @brief Associate the object like a copied property. */ OBJC_ASSOCIATION_COPY = OBJC_ASSOCIATION_COPY_NONATOMIC | 0x300 } objc_associationPolicy; #ifdef __cplusplus extern "C" { #endif /** * @brief Registers a selector with the specified name with the runtime. * * @param name The name for the selector to register * @return The registered selector */ extern SEL _Nonnull sel_registerName(const char *_Nonnull name); /** * @brief Returns the name of the specified selector. * * @param selector The selector whose name should be returned * @return The name of the specified selector */ extern const char *_Nonnull sel_getName(SEL _Nonnull selector); /** * @brief Checks two selectors for equality. * * Selectors are considered equal if they have the same name - any type * encoding is ignored. * * @param selector1 The first selector * @param selector2 The second selector * @return Whether the two selectors are equal */ extern bool sel_isEqual(SEL _Nonnull selector1, SEL _Nonnull selector2); /** * @brief Allocates a new class and its metaclass. * * @param superclass The superclass for the new class * @param name The name for the new class * @param extraBytes Extra bytes to add to the instance size * @return A new, unregistered class pair */ extern Class _Nonnull objc_allocateClassPair(Class _Nullable superclass, const char *_Nonnull name, size_t extraBytes); /** * @brief Registers an already allocated class pair. * * @param class_ The class pair to register */ extern void objc_registerClassPair(Class _Nonnull class_); /** * @brief Gets the list of all classes known to the runtime. * * @param buffer An array of Class to write to. If the buffer does not have * enough space, the result is truncated. * @param count The number of classes for which there is space in `buffer` * @return The number of classes written */ extern unsigned int objc_getClassList(Class _Nonnull *_Nullable buffer, unsigned int count); /** * @brief Copies the list of all classes known to the runtime. * * This is like @ref objc_getClassList, but allocates a buffer large enough for * all classes. * * @param length An optional pointer to an `unsigned int` that will be set to * the number of classes returned * @return An array of classes, terminated by `Nil`. You need to call `free()` * on it when done. */ extern Class _Nonnull *_Nonnull objc_copyClassList( unsigned int *_Nullable length); /** * @brief Returns whether the specified class is a metaclass. * * @param class_ The class which should be examined * @return Whether the specified class is a metaclass */ extern bool class_isMetaClass(Class _Nullable class_); /** * @brief Returns the name of the specified class. * * @param class_ The class whose name should be returned * @return The name of the specified class */ extern const char *_Nullable class_getName(Class _Nullable class_); /** * @brief Returns the superclass of the specified class. * * @param class_ The class whose superclass should be returned * @return The superclass of the specified class */ extern Class _Nullable class_getSuperclass(Class _Nullable class_); /** * @brief Returns the instance size of the specified class. * * @param class_ The class whose instance size should be returned * @return The instance size of the specified class */ extern unsigned long class_getInstanceSize(Class _Nullable class_); /** * @brief Returns whether the specified class responds to the specified * selector. * * @param class_ The class which should be examined * @param selector The selector which should be checked * @return Whether the specified class responds to the specified selector */ extern bool class_respondsToSelector(Class _Nullable class_, SEL _Nonnull selector); /** * @brief Returns whether the specified class conforms to the specified * protocol. * * @param class_ The class which should be examined * @param protocol The protocol for which conformance should be checked * @return Whether the specified class conforms to the specified protocol */ extern bool class_conformsToProtocol(Class _Nullable class_, Protocol *_Nonnull protocol); /** * @brief Returns the class's method implementation for the specified selector. * * @warning If the method uses the struct return ABI, you need to use * @ref class_getMethodImplementation_stret instead! Depending on the * ABI, small structs might not use the struct return ABI. * * @param class_ The class whose method implementation should be returned * @param selector The selector for the method whose implementation should be * returned * @return The class's method implementation for the specified selector */ extern IMP _Nullable class_getMethodImplementation(Class _Nullable class_, SEL _Nonnull selector); /** * @brief Returns the class's method implementation for the specified selector. * * @warning If the method does not use use the struct return ABI, you need to * use @ref class_getMethodImplementation instead! Depending on the * ABI, small structs might not use the struct return ABI. * * @param class_ The class whose method implementation should be returned * @param selector The selector for the method whose implementation should be * returned * @return The class's method implementation for the specified selector */ extern IMP _Nullable class_getMethodImplementation_stret(Class _Nullable class_, SEL _Nonnull selector); /** * @brief Returns the class's instance method for the specified selector * * @param class_ The class whose instance method should be returned * @param selector The selector of the instance method to return * @return The class's instance method for the specified selector */ extern Method _Nullable class_getInstanceMethod(Class _Nullable class_, SEL _Nonnull selector); /** * @brief Adds the specified method to the class. * * @param class_ The class to which to add the method * @param selector The selector for the method to add * @param implementation The implementation of the method to add * @param typeEncoding The type encoding of the method to add * @return Whether the specified method was added */ extern bool class_addMethod(Class _Nonnull class_, SEL _Nonnull selector, IMP _Nonnull implementation, const char *_Nullable typeEncoding); /** * @brief Replaces or adds the specified method of the class. * * @param class_ The class to which to replace the method * @param selector The selector for the method to replace * @param implementation The implementation of the method to replace * @param typeEncoding The type encoding of the method to replace. Only used if * the method does not exist yet. * @return The old implementation of the method */ extern IMP _Nullable class_replaceMethod(Class _Nonnull class_, SEL _Nonnull selector, IMP _Nonnull implementation, const char *_Nullable typeEncoding); /** * @brief Returns the object's class. * * @param object The object whose class should be returned * @return The object's class */ extern Class _Nullable object_getClass(id _Nullable object); /** * @brief Sets the object's class. * * This can be used to swizzle an object's class. * * @param object The object whose class should be set * @param class_ The new class for the object * @return The old class of the object */ extern Class _Nullable object_setClass(id _Nullable object, Class _Nonnull class_); /** * @brief Returns the object's class name. * * @param object The object whose class name should be returned * @return The object's class name */ extern const char *_Nullable object_getClassName(id _Nullable object); /** * @brief Returns the name of the specified protocol. * * @param protocol The protocol whose name should be returned * @return The name of the specified protocol */ extern const char *_Nonnull protocol_getName(Protocol *_Nonnull protocol); /** * @brief Returns whether two protocols are equal. * * @param protocol1 The first protocol * @param protocol2 The second protocol * @return Whether the two protocols are equal */ extern bool protocol_isEqual(Protocol *_Nonnull protocol1, Protocol *_Nonnull protocol2); /** * @brief Returns whether the first protocol conforms to the second protocol. * * @param protocol1 The first protocol * @param protocol2 The second protocol * @return Whether the first protocol conforms to the second protocol */ extern bool protocol_conformsToProtocol(Protocol *_Nonnull protocol1, Protocol *_Nonnull protocol2); /** * @brief Copies the method list of the specified class. * * @param class_ The class whose method list should be copied * @param outCount An optional pointer to an `unsigned int` that should be set * to the number of methods returned * @return An array of methods, terminated by `NULL`. You need to call `free()` * on it when done. */ extern Method _Nullable *_Nullable class_copyMethodList(Class _Nullable class_, unsigned int *_Nullable outCount); /** * @brief Returns the name of the specified method. * * @param method The method whose name should be returned * @return The name of the specified method */ extern SEL _Nonnull method_getName(Method _Nonnull method); /** * @brief Returns the type encoding of the specified method. * * @param method The method whose type encoding should be returned * @return The type encoding of the specified method */ extern const char *_Nullable method_getTypeEncoding(Method _Nonnull method); /** * @brief Copies the instance variable list of the specified class. * * @param class_ The class whose instance variable list should be copied * @param outCount An optional pointer to an `unsigned int` that should be set * to the number of instance variables returned * @return An array of instance variables, terminated by `NULL`. You need to * call `free()` on it when done. */ extern Ivar _Nullable *_Nullable class_copyIvarList(Class _Nullable class_, unsigned int *_Nullable outCount); /** * @brief Returns the name of the specified instance variable. * * @param ivar The instance variable whose name should be returned * @return The name of the specified instance variable */ extern const char *_Nonnull ivar_getName(Ivar _Nonnull ivar); /** * @brief Returns the type encoding of the specified instance variable. * * @param ivar The instance variable whose type encoding should be returned * @return The type encoding of the specified instance variable */ extern const char *_Nonnull ivar_getTypeEncoding(Ivar _Nonnull ivar); /** * @brief Returns the offset of the specified instance variable. * * @param ivar The instance variable whose offset should be returned * @return The offset of the specified instance variable */ extern ptrdiff_t ivar_getOffset(Ivar _Nonnull ivar); /** * @brief Copies the property list of the specified class. * * @param class_ The class whose property list should be copied * @param outCount An optional pointer to an `unsigned int` that should be set * to the number of properties returned * @return An array of properties, terminated by `NULL`. You need to call * `free()` on it when done. */ extern objc_property_t _Nullable *_Nullable class_copyPropertyList( Class _Nullable class_, unsigned int *_Nullable outCount); /** * @brief Returns the name of the specified property. * * @param property The property whose name should be returned * @return The name of the specified property */ extern const char *_Nonnull property_getName(objc_property_t _Nonnull property); /** * @brief Copies the specified attribute value. * * @param property The property whose attribute value should be copied * @param name The name of the attribute value to copy * @return A copy of the attribute value. You need to call `free()` on it when * done. */ extern char *_Nullable property_copyAttributeValue( objc_property_t _Nonnull property, const char *_Nonnull name); /** * @brief Deinitializes the Objective-C runtime. * * This frees all data structures used by the runtime, after which Objective-C * can no longer be used inside the current process. This is only useful for * debugging and tests. */ extern void objc_deinit(void); /** * @brief Sets the handler for uncaught exceptions. * * @param handler The new handler for uncaught exceptions * @return The old handler for uncaught exceptions */ extern _Nullable objc_uncaught_exception_handler objc_setUncaughtExceptionHandler( objc_uncaught_exception_handler _Nullable handler); /** * @brief Sets the forwarding handler for unimplemented methods. * * @param forward The forwarding handler for regular methods * @param stretForward The forwarding handler for methods using the struct * return ABI */ extern void objc_setForwardHandler(IMP _Nullable forward, IMP _Nullable stretForward); /** * @brief Sets the handler for mutations during enumeration. * * @param handler The handler for mutations during enumeration */ extern void objc_setEnumerationMutationHandler( objc_enumeration_mutation_handler _Nullable handler); /** * @brief Constructs an instance of the specified class in the specified array * of bytes. * * @param class_ The class of which to construct an instance * @param bytes An array of bytes of at least the length of the instance size. * Must be properly aligned for the class. * @return The constructed instance */ extern id _Nullable objc_constructInstance(Class _Nullable class_, void *_Nullable bytes); /** * @brief Destructs the specified object. * * @param object The object to destruct * @return The array of bytes that was used to back the instance */ extern void *_Nullable objc_destructInstance(id _Nullable object); /** * @brief Creates a new autorelease pool and puts it on top of the stack of * autorelease pools. * * @return A new autorelease pool, which is now on the top of the stack of * autorelease pools */ extern void *_Null_unspecified objc_autoreleasePoolPush(void); /** * @brief Drains the specified autorelease pool and all pools on top of it and * removes it from the stack of autorelease pools. * * @param pool The pool which should be drained together with all pools on top * of it */ extern void objc_autoreleasePoolPop(void *_Null_unspecified pool); /** * @brief Adds the specified object to the topmost autorelease pool. * * This is only to be used to implement the `autorelease` method in a root * class. * * @param object The object to add to the topmost autorelease pool * @return The autoreleased object */ extern id _Nullable _objc_rootAutorelease(id _Nullable object); /** * @brief Sets the tagged pointer secret. * * @param secret A secret, random value that will be used to XOR all tagged * pointers with */ extern void objc_setTaggedPointerSecret(uintptr_t secret); /** * @brief Registers a class for tagged pointers. * * @param class_ The class to register for tagged pointers * @return The tagged pointer ID for the registered class */ extern int objc_registerTaggedPointerClass(Class _Nonnull class_); /** * @brief Returns whether the specified object is a tagged pointer. * * @param object The object to inspect * @return Whether the specified object is a tagged pointer */ extern bool object_isTaggedPointer(id _Nullable object); /** * @brief Returns the value of the specified tagged pointer. * * @param object The object whose tagged pointer value should be returned * @return The tagged pointer value of the object */ extern uintptr_t object_getTaggedPointerValue(id _Nonnull object); /** * @brief Creates a new tagged pointer. * * @param class_ The tag ID for the tagged pointer class to use * @param value The value the tagged pointer should have * @return A tagged pointer, or `nil` if it could not be created */ extern id _Nullable objc_createTaggedPointer(int class_, uintptr_t value); /** * @brief Sets an associated object on the specified object for the specified * key. * * @param object The object on which to set an associated object * @param key A unique pointer to use as the key for the association * @param value The object to associate with the specified object * @param policy The association policy, see @ref objc_associationPolicy */ extern void objc_setAssociatedObject(id _Nonnull object, const void *_Nonnull key, id _Nullable value, objc_associationPolicy policy); /** * @brief Returns the associated object on the specified object for the * specified key. * * @param object The object on which to get the associated object * @param key The key of the association * @return The associated object on the specified object for the specified key */ extern id _Nullable objc_getAssociatedObject(id _Nonnull object, const void *_Nonnull key); /** * @brief Removes all associated objects for the specified object. * * @param object The object on which to remove all associated objects */ extern void objc_removeAssociatedObjects(id _Nonnull object); /* * Used by the compiler, but can also be called manually. * * These declarations are also required to prevent Clang's implicit * declarations which include __declspec(dllimport) on Windows. */ struct _objc_module; extern void __objc_exec_class(struct _objc_module *_Nonnull module); extern IMP _Nonnull objc_msg_lookup(id _Nullable object, SEL _Nonnull selector); extern IMP _Nonnull objc_msg_lookup_stret(id _Nullable object, SEL _Nonnull selector); extern IMP _Nonnull objc_msg_lookup_super(struct objc_super *_Nonnull super, SEL _Nonnull selector); extern IMP _Nonnull objc_msg_lookup_super_stret( struct objc_super *_Nonnull super, SEL _Nonnull selector); extern Class _Nullable objc_lookUpClass(const char *_Nonnull name); extern Class _Nullable objc_getClass(const char *_Nonnull name); extern Class _Nonnull objc_getRequiredClass(const char *_Nonnull name); extern Class _Nullable objc_lookup_class(const char *_Nonnull name); extern Class _Nonnull objc_get_class(const char *_Nonnull name); extern void objc_exception_throw(id _Nullable object); extern int objc_sync_enter(id _Nullable object); extern int objc_sync_exit(id _Nullable object); extern id _Nullable objc_getProperty(id _Nonnull self, SEL _Nonnull _cmd, ptrdiff_t offset, bool atomic); extern void objc_setProperty(id _Nonnull self, SEL _Nonnull _cmd, ptrdiff_t offset, id _Nullable value, bool atomic, signed char copy); extern void objc_getPropertyStruct(void *_Nonnull dest, const void *_Nonnull src, ptrdiff_t size, bool atomic, bool strong); extern void objc_setPropertyStruct(void *_Nonnull dest, const void *_Nonnull src, ptrdiff_t size, bool atomic, bool strong); extern void objc_enumerationMutation(id _Nonnull object); #ifndef OBJC_NO_PERSONALITY_DECLARATION /* * No objfw-defs.h or config.h is available for the installed runtime headers, * so we don't know which exceptions we have. */ extern int __gnu_objc_personality_v0(int version, int actions, uint64_t exClass, void *_Nonnull ex, void *_Nonnull ctx); extern int __gnu_objc_personality_sj0(int version, int actions, uint64_t exClass, void *_Nonnull ex, void *_Nonnull ctx); #endif extern id _Nullable objc_retain(id _Nullable object); extern id _Nullable objc_retainBlock(id _Nullable block); extern id _Nullable objc_retainAutorelease(id _Nullable object); extern void objc_release(id _Nullable object); extern id _Nullable objc_autorelease(id _Nullable object); extern id _Nullable objc_autoreleaseReturnValue(id _Nullable object); extern id _Nullable objc_retainAutoreleaseReturnValue(id _Nullable object); extern id _Nullable objc_retainAutoreleasedReturnValue(id _Nullable object); extern id _Nullable objc_storeStrong(id _Nullable *_Nonnull object, id _Nullable value); extern id _Nullable objc_storeWeak(id _Nullable *_Nonnull object, id _Nullable value); extern id _Nullable objc_loadWeakRetained(id _Nullable *_Nonnull object); extern _Nullable id objc_initWeak(id _Nullable *_Nonnull object, id _Nullable value); extern void objc_destroyWeak(id _Nullable *_Nonnull object); extern id _Nullable objc_loadWeak(id _Nullable *_Nonnull object); extern void objc_copyWeak(id _Nullable *_Nonnull dest, id _Nullable *_Nonnull src); extern void objc_moveWeak(id _Nullable *_Nonnull dest, id _Nullable *_Nonnull src); #ifdef __cplusplus } #endif #endif objfw-1.1.6/src/runtime/arc.m000066400000000000000000000130061465614216400160340ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFWRT.h" #import "private.h" #ifdef OF_HAVE_THREADS # import "OFPlainMutex.h" #endif struct WeakRef { id **locations; size_t count; }; static struct objc_hashtable *hashtable; #ifdef OF_HAVE_THREADS static OFSpinlock spinlock; #endif static uint32_t hash(const void *object) { return (uint32_t)(uintptr_t)object; } static bool equal(const void *object1, const void *object2) { return (object1 == object2); } OF_CONSTRUCTOR() { hashtable = objc_hashtable_new(hash, equal, 2); #ifdef OF_HAVE_THREADS if (OFSpinlockNew(&spinlock) != 0) OBJC_ERROR("Failed to create spinlock!"); #endif } id objc_retain(id object) { return [object retain]; } id objc_retainBlock(id block) { return [block copy]; } id objc_retainAutorelease(id object) { return [[object retain] autorelease]; } void objc_release(id object) { [object release]; } id objc_autorelease(id object) { return [object autorelease]; } id objc_autoreleaseReturnValue(id object) { return objc_autorelease(object); } id objc_retainAutoreleaseReturnValue(id object) { return objc_autoreleaseReturnValue(objc_retain(object)); } id objc_retainAutoreleasedReturnValue(id object) { return objc_retain(object); } id objc_storeStrong(id *object, id value) { if (*object != value) { id old = *object; *object = objc_retain(value); objc_release(old); } return value; } id objc_storeWeak(id *object, id value) { struct WeakRef *old; #ifdef OF_HAVE_THREADS if (OFSpinlockLock(&spinlock) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif if (*object != nil && (old = objc_hashtable_get(hashtable, *object)) != NULL) { for (size_t i = 0; i < old->count; i++) { if (old->locations[i] == object) { if (--old->count == 0) { objc_hashtable_delete(hashtable, *object); free(old->locations); free(old); } else { id **locations; old->locations[i] = old->locations[old->count]; /* * We don't care if making it smaller * fails. */ if ((locations = realloc(old->locations, old->count * sizeof(id *))) != NULL) old->locations = locations; } break; } } } if (value != nil && class_respondsToSelector(object_getClass(value), @selector(allowsWeakReference)) && [value allowsWeakReference]) { struct WeakRef *ref = objc_hashtable_get(hashtable, value); if (ref == NULL) { if ((ref = calloc(1, sizeof(*ref))) == NULL) OBJC_ERROR("Not enough memory to allocate weak " "reference!"); objc_hashtable_set(hashtable, value, ref); } if ((ref->locations = realloc(ref->locations, (ref->count + 1) * sizeof(id *))) == NULL) OBJC_ERROR("Not enough memory to allocate weak " "reference!"); ref->locations[ref->count++] = object; } else value = nil; *object = value; #ifdef OF_HAVE_THREADS if (OFSpinlockUnlock(&spinlock) != 0) OBJC_ERROR("Failed to unlock spinlock!"); #endif return value; } id objc_loadWeakRetained(id *object) { id value = nil; #ifdef OF_HAVE_THREADS if (OFSpinlockLock(&spinlock) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif if (*object != nil && objc_hashtable_get(hashtable, *object) != NULL) value = *object; #ifdef OF_HAVE_THREADS if (OFSpinlockUnlock(&spinlock) != 0) OBJC_ERROR("Failed to unlock spinlock!"); #endif if (class_respondsToSelector(object_getClass(value), @selector(retainWeakReference)) && [value retainWeakReference]) return value; return nil; } id objc_initWeak(id *object, id value) { *object = nil; return objc_storeWeak(object, value); } void objc_destroyWeak(id *object) { objc_storeWeak(object, nil); } id objc_loadWeak(id *object) { return objc_autorelease(objc_loadWeakRetained(object)); } void objc_copyWeak(id *dest, id *src) { objc_release(objc_initWeak(dest, objc_loadWeakRetained(src))); } void objc_moveWeak(id *dest, id *src) { struct WeakRef *ref; #ifdef OF_HAVE_THREADS if (OFSpinlockLock(&spinlock) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif if (*src != nil && (ref = objc_hashtable_get(hashtable, *src)) != NULL) { for (size_t i = 0; i < ref->count; i++) { if (ref->locations[i] == src) { ref->locations[i] = dest; break; } } } *dest = *src; *src = nil; #ifdef OF_HAVE_THREADS if (OFSpinlockUnlock(&spinlock) != 0) OBJC_ERROR("Failed to unlock spinlock!"); #endif } void objc_zeroWeakReferences(id value) { struct WeakRef *ref; #ifdef OF_HAVE_THREADS if (OFSpinlockLock(&spinlock) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif if ((ref = objc_hashtable_get(hashtable, value)) != NULL) { for (size_t i = 0; i < ref->count; i++) *ref->locations[i] = nil; objc_hashtable_delete(hashtable, value); free(ref->locations); free(ref); } #ifdef OF_HAVE_THREADS if (OFSpinlockUnlock(&spinlock) != 0) OBJC_ERROR("Failed to unlock spinlock!"); #endif } objfw-1.1.6/src/runtime/association.m000066400000000000000000000147461465614216400176170ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #ifdef OF_OBJFW_RUNTIME # import "ObjFWRT.h" # import "private.h" #else # import "OFObject.h" # import "OFMapTable.h" #endif struct Association { id object; objc_associationPolicy policy; }; #ifdef OF_OBJFW_RUNTIME typedef struct objc_hashtable objc_hashtable; #else typedef OFMapTable objc_hashtable; static const OFMapTableFunctions defaultFunctions = { NULL }; static objc_hashtable * objc_hashtable_new(uint32_t (*hash)(const void *key), bool (*equal)(const void *key1, const void *key2), uint32_t size) { return [[OFMapTable alloc] initWithKeyFunctions: defaultFunctions objectFunctions: defaultFunctions]; } static void objc_hashtable_set(objc_hashtable *hashtable, const void *key, const void *object) { return [hashtable setObject: (void *)object forKey: (void *)key]; } static void * objc_hashtable_get(objc_hashtable *hashtable, const void *key) { return [hashtable objectForKey: (void *)key]; } static void objc_hashtable_delete(objc_hashtable *hashtable, const void *key) { [hashtable removeObjectForKey: (void *)key]; } static void objc_hashtable_free(objc_hashtable *hashtable) { [hashtable release]; } # define OBJC_ERROR(...) abort() #endif #ifdef OF_HAVE_THREADS # define numSlots 8 /* needs to be a power of 2 */ # import "OFPlainMutex.h" static OFSpinlock spinlocks[numSlots]; #else # define numSlots 1 #endif static objc_hashtable *hashtables[numSlots]; static OF_INLINE size_t slotForObject(id object) { return ((size_t)((uintptr_t)object >> 4) & (numSlots - 1)); } static uint32_t hash(const void *object) { return (uint32_t)(uintptr_t)object; } static bool equal(const void *object1, const void *object2) { return (object1 == object2); } OF_CONSTRUCTOR() { for (size_t i = 0; i < numSlots; i++) { hashtables[i] = objc_hashtable_new(hash, equal, 2); #ifdef OF_HAVE_THREADS if (OFSpinlockNew(&spinlocks[i]) != 0) OBJC_ERROR("Failed to create spinlocks!"); #endif } } void objc_setAssociatedObject(id object, const void *key, id value, objc_associationPolicy policy) { size_t slot; switch (policy) { case OBJC_ASSOCIATION_ASSIGN: break; case OBJC_ASSOCIATION_RETAIN: case OBJC_ASSOCIATION_RETAIN_NONATOMIC: value = [value retain]; break; case OBJC_ASSOCIATION_COPY: case OBJC_ASSOCIATION_COPY_NONATOMIC: value = [value copy]; break; default: /* Don't know what to do, so do nothing. */ return; } slot = slotForObject(object); #ifdef OF_HAVE_THREADS if (OFSpinlockLock(&spinlocks[slot]) != 0) OBJC_ERROR("Failed to lock spinlock!"); @try { #endif objc_hashtable *objectHashtable; struct Association *association; objectHashtable = objc_hashtable_get(hashtables[slot], object); if (objectHashtable == NULL) { objectHashtable = objc_hashtable_new(hash, equal, 2); objc_hashtable_set(hashtables[slot], object, objectHashtable); } association = objc_hashtable_get(objectHashtable, key); if (association != NULL) { switch (association->policy) { case OBJC_ASSOCIATION_RETAIN: case OBJC_ASSOCIATION_RETAIN_NONATOMIC: case OBJC_ASSOCIATION_COPY: case OBJC_ASSOCIATION_COPY_NONATOMIC: [association->object release]; break; default: break; } } else { association = malloc(sizeof(*association)); if (association == NULL) OBJC_ERROR("Failed to allocate association!"); objc_hashtable_set(objectHashtable, key, association); } association->policy = policy; association->object = value; #ifdef OF_HAVE_THREADS } @finally { if (OFSpinlockUnlock(&spinlocks[slot]) != 0) OBJC_ERROR("Failed to unlock spinlock!"); } #endif } id objc_getAssociatedObject(id object, const void *key) { size_t slot = slotForObject(object); id ret; #ifdef OF_HAVE_THREADS if (OFSpinlockLock(&spinlocks[slot]) != 0) OBJC_ERROR("Failed to lock spinlock!"); @try { #endif objc_hashtable *objectHashtable; struct Association *association; objectHashtable = objc_hashtable_get(hashtables[slot], object); if (objectHashtable == NULL) return nil; association = objc_hashtable_get(objectHashtable, key); if (association == NULL) return nil; switch (association->policy) { case OBJC_ASSOCIATION_RETAIN: case OBJC_ASSOCIATION_COPY: ret = [[association->object retain] autorelease]; break; default: ret = association->object; break; } #ifdef OF_HAVE_THREADS } @finally { if (OFSpinlockUnlock(&spinlocks[slot]) != 0) OBJC_ERROR("Failed to unlock spinlock!"); } #endif return ret; } void objc_removeAssociatedObjects(id object) { size_t slot = slotForObject(object); #ifdef OF_HAVE_THREADS if (OFSpinlockLock(&spinlocks[slot]) != 0) OBJC_ERROR("Failed to lock spinlock!"); @try { #endif objc_hashtable *objectHashtable; objectHashtable = objc_hashtable_get(hashtables[slot], object); if (objectHashtable == NULL) return; #ifdef OF_OBJFW_RUNTIME for (uint32_t i = 0; i < objectHashtable->size; i++) { struct Association *association; if (objectHashtable->data[i] == NULL || objectHashtable->data[i] == &objc_deletedBucket) continue; association = (struct Association *) objectHashtable->data[i]->object; #else OFMapTableEnumerator *enumerator = [objectHashtable objectEnumerator]; void **iter; while ((iter = [enumerator nextObject]) != NULL) { struct Association *association = *iter; #endif switch (association->policy) { case OBJC_ASSOCIATION_RETAIN: case OBJC_ASSOCIATION_RETAIN_NONATOMIC: case OBJC_ASSOCIATION_COPY: case OBJC_ASSOCIATION_COPY_NONATOMIC: [association->object release]; break; default: break; } free(association); } objc_hashtable_delete(hashtables[slot], object); objc_hashtable_free(objectHashtable); #ifdef OF_HAVE_THREADS } @finally { if (OFSpinlockUnlock(&spinlocks[slot]) != 0) OBJC_ERROR("Failed to unlock spinlock!"); } #endif } objfw-1.1.6/src/runtime/autorelease.m000066400000000000000000000074001465614216400176010ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #ifdef OF_OBJFW_RUNTIME # import "ObjFWRT.h" # import "private.h" #else # import #endif #import "macros.h" #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) # import "OFTLSKey.h" #endif #ifndef OF_OBJFW_RUNTIME @interface DummyObject - (void)release; @end #endif #ifndef OBJC_ERROR /* This is also used with old Apple runtimes that lack autorelease pools. */ # define OBJC_ERROR(...) abort() #endif #if defined(OF_HAVE_COMPILER_TLS) static thread_local id *objects = NULL; static thread_local uintptr_t count = 0; static thread_local uintptr_t size = 0; #elif defined(OF_HAVE_THREADS) static OFTLSKey objectsKey, countKey, sizeKey; #else static id *objects = NULL; static uintptr_t count = 0; static uintptr_t size = 0; #endif #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OF_CONSTRUCTOR() { if (OFTLSKeyNew(&objectsKey) != 0 || OFTLSKeyNew(&countKey) != 0 || OFTLSKeyNew(&sizeKey) != 0) OBJC_ERROR("Failed to create TLS keys!"); } #endif void * objc_autoreleasePoolPush(void) { #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) uintptr_t count = (uintptr_t)OFTLSKeyGet(countKey); #endif return (void *)count; } void objc_autoreleasePoolPop(void *pool) { #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) id *objects = OFTLSKeyGet(objectsKey); uintptr_t count = (uintptr_t)OFTLSKeyGet(countKey); #endif uintptr_t idx = (uintptr_t)pool; bool freeMem = false; if (idx == (uintptr_t)-1) { idx++; freeMem = true; } for (uintptr_t i = idx; i < count; i++) { [objects[i] release]; #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) objects = OFTLSKeyGet(objectsKey); count = (uintptr_t)OFTLSKeyGet(countKey); #endif } count = idx; if (freeMem) { free(objects); objects = NULL; #if defined(OF_HAVE_COMPILER_TLS) || !defined(OF_HAVE_THREADS) size = 0; #else if (OFTLSKeySet(objectsKey, objects) != 0 || OFTLSKeySet(sizeKey, (void *)0) != 0) OBJC_ERROR("Failed to set TLS key!"); #endif } #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) if (OFTLSKeySet(countKey, (void *)count) != 0) OBJC_ERROR("Failed to set TLS key!"); #endif } id _objc_rootAutorelease(id object) { #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) id *objects = OFTLSKeyGet(objectsKey); uintptr_t count = (uintptr_t)OFTLSKeyGet(countKey); uintptr_t size = (uintptr_t)OFTLSKeyGet(sizeKey); #endif if (count >= size) { if (size == 0) size = 16; else size *= 2; if ((objects = realloc(objects, size * sizeof(id))) == NULL) OBJC_ERROR("Failed to resize autorelease pool!"); #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) if (OFTLSKeySet(objectsKey, objects) != 0 || OFTLSKeySet(sizeKey, (void *)size) != 0) OBJC_ERROR("Failed to set TLS key!"); #endif } objects[count++] = object; #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) if (OFTLSKeySet(countKey, (void *)count) != 0) OBJC_ERROR("Failed to set TLS key!"); #endif return object; } objfw-1.1.6/src/runtime/category.m000066400000000000000000000067561465614216400171220ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #include #import "ObjFWRT.h" #import "private.h" static struct objc_hashtable *categoriesMap = NULL; static void registerSelectors(struct objc_category *category) { struct objc_method_list *iter; unsigned int i; for (iter = category->instanceMethods; iter != NULL; iter = iter->next) for (i = 0; i < iter->count; i++) objc_registerSelector(&iter->methods[i].selector); for (iter = category->classMethods; iter != NULL; iter = iter->next) for (i = 0; i < iter->count; i++) objc_registerSelector(&iter->methods[i].selector); } static void registerCategory(struct objc_category *category) { struct objc_category **categories; Class class = objc_classnameToClass(category->className, false); if (categoriesMap == NULL) categoriesMap = objc_hashtable_new( objc_string_hash, objc_string_equal, 2); categories = (struct objc_category **)objc_hashtable_get( categoriesMap, category->className); if (categories != NULL) { struct objc_category **newCategories; size_t i; for (i = 0; categories[i] != NULL; i++); if ((newCategories = realloc(categories, (i + 2) * sizeof(*categories))) == NULL) OBJC_ERROR("Not enough memory for category %s of " "class %s!", category->categoryName, category->className); newCategories[i] = category; newCategories[i + 1] = NULL; objc_hashtable_set(categoriesMap, category->className, newCategories); if (class != Nil && class->info & OBJC_CLASS_INFO_SETUP) { objc_updateDTable(class); objc_updateDTable(class->isa); } return; } if ((categories = malloc(2 * sizeof(*categories))) == NULL) OBJC_ERROR("Not enough memory for category %s of class %s!\n", category->categoryName, category->className); categories[0] = category; categories[1] = NULL; objc_hashtable_set(categoriesMap, category->className, categories); if (class != Nil && class->info & OBJC_CLASS_INFO_SETUP) { objc_updateDTable(class); objc_updateDTable(class->isa); } } void objc_registerAllCategories(struct objc_symtab *symtab) { struct objc_category **categories = (struct objc_category **)symtab->defs + symtab->classDefsCount; for (size_t i = 0; i < symtab->categoryDefsCount; i++) { registerSelectors(categories[i]); registerCategory(categories[i]); } } struct objc_category ** objc_categoriesForClass(Class class) { if (categoriesMap == NULL) return NULL; return (struct objc_category **)objc_hashtable_get(categoriesMap, class->name); } void objc_unregisterAllCategories(void) { if (categoriesMap == NULL) return; for (uint32_t i = 0; i < categoriesMap->size; i++) if (categoriesMap->data[i] != NULL) free((void *)categoriesMap->data[i]->object); objc_hashtable_free(categoriesMap); categoriesMap = NULL; } objfw-1.1.6/src/runtime/class.m000066400000000000000000000541351465614216400164040ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #include #include #import "ObjFWRT.h" #import "private.h" static struct objc_hashtable *classes = NULL; static unsigned classesCount = 0; static Class *loadQueue = NULL; static size_t loadQueueCount = 0; static struct objc_dtable *emptyDTable = NULL; static unsigned lookupsUntilFastPath = 128; static struct objc_sparsearray *fastPath = NULL; static void registerClass(Class class) { if (classes == NULL) classes = objc_hashtable_new( objc_string_hash, objc_string_equal, 2); objc_hashtable_set(classes, class->name, class); if (emptyDTable == NULL) emptyDTable = objc_dtable_new(); class->dTable = emptyDTable; class->isa->dTable = emptyDTable; if (strcmp(class->name, "Protocol") != 0) classesCount++; } bool class_registerAlias_np(Class class, const char *name) { objc_globalMutex_lock(); if (classes == NULL) { objc_globalMutex_unlock(); return false; } objc_hashtable_set(classes, name, (Class)((uintptr_t)class | 1)); objc_globalMutex_unlock(); return true; } static void registerSelectors(Class class) { struct objc_method_list *iter; unsigned int i; for (iter = class->methodList; iter != NULL; iter = iter->next) for (i = 0; i < iter->count; i++) objc_registerSelector(&iter->methods[i].selector); } Class objc_classnameToClass(const char *name, bool cache) { Class class; if (classes == NULL) return Nil; /* * Fast path * * Instead of looking up the string in a dictionary, which needs * locking, we use a sparse array to look up the pointer. If * objc_classnameToClass() gets called a lot, it is most likely that * the GCC ABI is used, which always calls into objc_lookup_class(), or * that it is used in a loop by the user. In both cases, it is very * likely that the same string pointer is passed again and again. * * This is not used before objc_classnameToClass() has been called a * certain amount of times, so that no memory is wasted if it is only * used rarely, for example if the ObjFW ABI is used and the user does * not call it in a loop. * * Runtime internal usage does not use the fast path and does not count * as a call into objc_classnameToClass(). The reason for this is that * if the runtime calls into objc_classnameToClass(), it already has * the lock and thus the performance gain would be small, but it would * waste memory. */ if (cache && fastPath != NULL) { class = objc_sparsearray_get(fastPath, (uintptr_t)name); if (class != Nil) return class; } objc_globalMutex_lock(); class = (Class)((uintptr_t)objc_hashtable_get(classes, name) & ~1); if (cache && fastPath == NULL && --lookupsUntilFastPath == 0) fastPath = objc_sparsearray_new(sizeof(uintptr_t)); if (cache && fastPath != NULL) objc_sparsearray_set(fastPath, (uintptr_t)name, class); objc_globalMutex_unlock(); return class; } static void callSelector(Class class, SEL selector) { for (struct objc_method_list *methodList = class->isa->methodList; methodList != NULL; methodList = methodList->next) for (unsigned int i = 0; i < methodList->count; i++) if (sel_isEqual((SEL)&methodList->methods[i].selector, selector)) ((void (*)(id, SEL))methodList->methods[i] .implementation)(class, selector); } static bool hasLoad(Class class) { static SEL loadSel = NULL; if (loadSel == NULL) loadSel = sel_registerName("load"); for (struct objc_method_list *methodList = class->isa->methodList; methodList != NULL; methodList = methodList->next) for (size_t i = 0; i < methodList->count; i++) if (sel_isEqual((SEL)&methodList->methods[i].selector, loadSel)) return true; return false; } static void callLoad(Class class) { static SEL loadSel = NULL; if (loadSel == NULL) loadSel = sel_registerName("load"); if (class->info & OBJC_CLASS_INFO_LOADED) return; if (class->superclass != Nil) callLoad(class->superclass); callSelector(class, loadSel); class->info |= OBJC_CLASS_INFO_LOADED; } void objc_updateDTable(Class class) { struct objc_category **categories; if (!(class->info & OBJC_CLASS_INFO_DTABLE)) return; if (class->dTable == emptyDTable) class->dTable = objc_dtable_new(); if (class->superclass != Nil) objc_dtable_copy(class->dTable, class->superclass->dTable); for (struct objc_method_list *methodList = class->methodList; methodList != NULL; methodList = methodList->next) for (unsigned int i = 0; i < methodList->count; i++) objc_dtable_set(class->dTable, (uint32_t)methodList->methods[i].selector.UID, methodList->methods[i].implementation); if ((categories = objc_categoriesForClass(class)) != NULL) { for (unsigned int i = 0; categories[i] != NULL; i++) { struct objc_method_list *methodList = (class->info & OBJC_CLASS_INFO_CLASS ? categories[i]->instanceMethods : categories[i]->classMethods); for (; methodList != NULL; methodList = methodList->next) for (unsigned int j = 0; j < methodList->count; j++) objc_dtable_set(class->dTable, (uint32_t)methodList->methods[j] .selector.UID, methodList->methods[j] .implementation); } } if (class->subclassList != NULL) for (Class *iter = class->subclassList; *iter != NULL; iter++) objc_updateDTable(*iter); } static void addSubclass(Class class) { size_t i; if (class->superclass->subclassList == NULL) { if ((class->superclass->subclassList = malloc(2 * sizeof(Class))) == NULL) OBJC_ERROR("Not enough memory for subclass list of " "class %s!", class->superclass->name); class->superclass->subclassList[0] = class; class->superclass->subclassList[1] = Nil; return; } for (i = 0; class->superclass->subclassList[i] != Nil; i++); class->superclass->subclassList = realloc(class->superclass->subclassList, (i + 2) * sizeof(Class)); if (class->superclass->subclassList == NULL) OBJC_ERROR("Not enough memory for subclass list of class %s\n", class->superclass->name); class->superclass->subclassList[i] = class; class->superclass->subclassList[i + 1] = Nil; } static void updateIvarOffsets(Class class) { if (!(class->info & OBJC_CLASS_INFO_NEW_ABI)) return; if (class->instanceSize > 0) return; class->instanceSize = -class->instanceSize; if (class->superclass != Nil) { class->instanceSize += class->superclass->instanceSize; if (class->ivars != NULL) { for (unsigned int i = 0; i < class->ivars->count; i++) { class->ivars->ivars[i].offset += class->superclass->instanceSize; *class->ivarOffsets[i] = class->ivars->ivars[i].offset; } } } else for (unsigned int i = 0; i < class->ivars->count; i++) *class->ivarOffsets[i] = class->ivars->ivars[i].offset; } static void setUpClass(Class class) { const char *superclassName; if (class->info & OBJC_CLASS_INFO_SETUP) return; superclassName = (const char *)class->superclass; if (superclassName != NULL) { Class super = objc_classnameToClass(superclassName, false); Class rootClass; if (super == Nil) return; setUpClass(super); if (!(super->info & OBJC_CLASS_INFO_SETUP)) return; /* * GCC sets class->isa->isa to the name of the root class, * while Clang just sets it to Nil. Therefore always calculate * it. */ for (Class iter = super; iter != NULL; iter = iter->superclass) rootClass = iter; class->superclass = super; class->isa->isa = rootClass->isa; class->isa->superclass = super->isa; addSubclass(class); addSubclass(class->isa); } else { class->isa->isa = class->isa; class->isa->superclass = class; } updateIvarOffsets(class); class->info |= OBJC_CLASS_INFO_SETUP; class->isa->info |= OBJC_CLASS_INFO_SETUP; } static void initializeClass(Class class) { static SEL initializeSel = NULL; if (initializeSel == NULL) initializeSel = sel_registerName("initialize"); if (class->info & OBJC_CLASS_INFO_INITIALIZED) return; if (class->superclass) initializeClass(class->superclass); /* * Avoid double-initialization: One of the superclasses' +[initialize] * might have called this class and hence it already got initialized. */ if (class->info & OBJC_CLASS_INFO_INITIALIZED) return; class->info |= OBJC_CLASS_INFO_DTABLE; class->isa->info |= OBJC_CLASS_INFO_DTABLE; objc_updateDTable(class); objc_updateDTable(class->isa); /* * Set it first to prevent calling it recursively due to message sends * in the initialize method */ class->info |= OBJC_CLASS_INFO_INITIALIZED; class->isa->info |= OBJC_CLASS_INFO_INITIALIZED; /* * +[initialize] might get called from some +[load], before the * constructors of this compilation module have been called, at which * point the selector would not be properly initialized. */ if (class_respondsToSelector(object_getClass(class), initializeSel)) { void (*initialize)(id, SEL) = (void (*)(id, SEL)) objc_msg_lookup(class, initializeSel); initialize(class, initializeSel); } } void objc_initializeClass(Class class) { if (class->info & OBJC_CLASS_INFO_INITIALIZED) return; objc_globalMutex_lock(); /* * It's possible that two threads try to initialize a class at the same * time. Make sure that the thread which held the lock did not already * initialize it. */ if (class->info & OBJC_CLASS_INFO_INITIALIZED) { objc_globalMutex_unlock(); return; } setUpClass(class); if (!(class->info & OBJC_CLASS_INFO_SETUP)) { objc_globalMutex_unlock(); return; } initializeClass(class); objc_globalMutex_unlock(); } static void processLoadQueue(void) { for (size_t i = 0; i < loadQueueCount; i++) { setUpClass(loadQueue[i]); if (loadQueue[i]->info & OBJC_CLASS_INFO_SETUP) { callLoad(loadQueue[i]); loadQueueCount--; if (loadQueueCount == 0) { free(loadQueue); loadQueue = NULL; continue; } loadQueue[i] = loadQueue[loadQueueCount]; loadQueue = realloc(loadQueue, sizeof(Class) * loadQueueCount); if (loadQueue == NULL) OBJC_ERROR("Not enough memory for load queue!"); } } } void objc_registerAllClasses(struct objc_symtab *symtab) { for (uint16_t i = 0; i < symtab->classDefsCount; i++) { Class class = (Class)symtab->defs[i]; registerClass(class); registerSelectors(class); registerSelectors(class->isa); } for (uint16_t i = 0; i < symtab->classDefsCount; i++) { Class class = (Class)symtab->defs[i]; if (hasLoad(class)) { setUpClass(class); if (class->info & OBJC_CLASS_INFO_SETUP) callLoad(class); else { loadQueue = realloc(loadQueue, sizeof(Class) * (loadQueueCount + 1)); if (loadQueue == NULL) OBJC_ERROR("Not enough memory for load " "queue!"); loadQueue[loadQueueCount++] = class; } } else class->info |= OBJC_CLASS_INFO_LOADED; } processLoadQueue(); } Class objc_allocateClassPair(Class superclass, const char *name, size_t extraBytes) { struct objc_class *class, *metaclass; Class iter, rootclass = Nil; if ((class = calloc(1, sizeof(*class))) == NULL || (metaclass = calloc(1, sizeof(*class))) == NULL) OBJC_ERROR("Not enough memory to allocate class pair for class " "%s!", name); class->isa = metaclass; class->superclass = superclass; class->name = name; class->info = OBJC_CLASS_INFO_CLASS; class->instanceSize = (superclass != Nil ? superclass->instanceSize : 0); if (extraBytes > LONG_MAX || LONG_MAX - class->instanceSize < (long)extraBytes) OBJC_ERROR("extraBytes too large!"); class->instanceSize += (long)extraBytes; for (iter = superclass; iter != Nil; iter = iter->superclass) rootclass = iter; metaclass->isa = (rootclass != Nil ? rootclass->isa : class); metaclass->superclass = (superclass != Nil ? superclass->isa : Nil); metaclass->name = name; metaclass->info = OBJC_CLASS_INFO_CLASS; metaclass->instanceSize = (superclass != Nil ? superclass->isa->instanceSize : 0) + (long)extraBytes; return class; } void objc_registerClassPair(Class class) { objc_globalMutex_lock(); registerClass(class); if (class->superclass != Nil) { addSubclass(class); addSubclass(class->isa); } class->info |= OBJC_CLASS_INFO_SETUP; class->isa->info |= OBJC_CLASS_INFO_SETUP; if (hasLoad(class)) callLoad(class); else class->info |= OBJC_CLASS_INFO_LOADED; processLoadQueue(); objc_globalMutex_unlock(); } Class objc_lookUpClass(const char *name) { Class class; if ((class = objc_classnameToClass(name, true)) == NULL) return Nil; if (class->info & OBJC_CLASS_INFO_SETUP) return class; objc_globalMutex_lock(); setUpClass(class); objc_globalMutex_unlock(); if (!(class->info & OBJC_CLASS_INFO_SETUP)) return Nil; return class; } Class objc_getClass(const char *name) { return objc_lookUpClass(name); } Class objc_getRequiredClass(const char *name) { Class class; if ((class = objc_getClass(name)) == Nil) OBJC_ERROR("Class %s not found!", name); return class; } Class objc_lookup_class(const char *name) { return objc_getClass(name); } Class objc_get_class(const char *name) { return objc_getRequiredClass(name); } unsigned int objc_getClassList(Class *buffer, unsigned int count) { unsigned int j; objc_globalMutex_lock(); if (buffer == NULL) { count = classesCount; objc_globalMutex_unlock(); return count; } if (classesCount < count) count = classesCount; j = 0; for (uint32_t i = 0; i < classes->size; i++) { void *class; if (j >= count) { objc_globalMutex_unlock(); return j; } if (classes->data[i] == NULL || classes->data[i] == &objc_deletedBucket) continue; if (strcmp(classes->data[i]->key, "Protocol") == 0) continue; class = (Class)classes->data[i]->object; if (class == Nil || (uintptr_t)class & 1) continue; buffer[j++] = class; } objc_globalMutex_unlock(); return j; } Class * objc_copyClassList(unsigned int *length) { Class *ret; unsigned int count; objc_globalMutex_lock(); if ((ret = malloc((classesCount + 1) * sizeof(Class))) == NULL) OBJC_ERROR("Failed to allocate memory for class list!"); count = objc_getClassList(ret, classesCount); if (count != classesCount) OBJC_ERROR("Fatal internal inconsistency!"); ret[count] = Nil; if (length != NULL) *length = count; objc_globalMutex_unlock(); return ret; } bool class_isMetaClass(Class class) { if (class == Nil) return false; return (class->info & OBJC_CLASS_INFO_METACLASS); } const char * class_getName(Class class) { if (class == Nil) return ""; return class->name; } Class class_getSuperclass(Class class) { if (class == Nil) return Nil; return class->superclass; } unsigned long class_getInstanceSize(Class class) { if (class == Nil) return 0; return class->instanceSize; } IMP class_getMethodImplementation(Class class, SEL selector) { /* * We use a dummy object here so that the normal lookup is used, even * though we don't have an object. Doing so is safe, as objc_msg_lookup * does not access the object, but only its class. * * Just looking it up in the dispatch table could result in returning * NULL instead of the forwarding handler, it would also mean * +[resolveClassMethod:] / +[resolveInstanceMethod:] would not be * called. */ struct { Class isa; } dummy; if (class == Nil) return NULL; dummy.isa = class; return objc_msg_lookup((id)&dummy, selector); } IMP class_getMethodImplementation_stret(Class class, SEL selector) { /* * Same as above, but use objc_msg_lookup_stret instead, so that the * correct forwarding handler is returned. */ struct { Class isa; } dummy; if (class == Nil) return NULL; dummy.isa = class; return objc_msg_lookup_stret((id)&dummy, selector); } static struct objc_method * getMethod(Class class, SEL selector) { struct objc_category **categories; if ((categories = objc_categoriesForClass(class)) != NULL) { for (; *categories != NULL; categories++) { struct objc_method_list *methodList = (class->info & OBJC_CLASS_INFO_METACLASS ? (*categories)->classMethods : (*categories)->instanceMethods); for (; methodList != NULL; methodList = methodList->next) for (unsigned int i = 0; i < methodList->count; i++) if (sel_isEqual((SEL) &methodList->methods[i].selector, selector)) return &methodList->methods[i]; } } for (struct objc_method_list *methodList = class->methodList; methodList != NULL; methodList = methodList->next) for (unsigned int i = 0; i < methodList->count; i++) if (sel_isEqual((SEL)&methodList->methods[i].selector, selector)) return &methodList->methods[i]; return NULL; } static void addMethod(Class class, SEL selector, IMP implementation, const char *typeEncoding) { struct objc_method_list *methodList; /* FIXME: We need a way to free this at objc_deinit() */ if ((methodList = malloc(sizeof(*methodList))) == NULL) OBJC_ERROR("Not enough memory to replace method!"); methodList->next = class->methodList; methodList->count = 1; methodList->methods[0].selector.UID = selector->UID; methodList->methods[0].selector.typeEncoding = typeEncoding; methodList->methods[0].implementation = implementation; class->methodList = methodList; objc_updateDTable(class); } Method #if defined(__clang__) && __has_attribute(__optnone__) && \ __clang_major__ == 3 && __clang_minor__ <= 7 /* Work around an ICE in Clang 3.7.0 on Windows/x86 */ __attribute__((__optnone__)) #endif class_getInstanceMethod(Class class, SEL selector) { Method method; Class superclass; if (class == Nil) return NULL; objc_globalMutex_lock(); if ((method = getMethod(class, selector)) != NULL) { objc_globalMutex_unlock(); return method; } superclass = class->superclass; objc_globalMutex_unlock(); if (superclass != Nil) return class_getInstanceMethod(superclass, selector); return NULL; } bool class_addMethod(Class class, SEL selector, IMP implementation, const char *typeEncoding) { bool ret; objc_globalMutex_lock(); if (getMethod(class, selector) == NULL) { addMethod(class, selector, implementation, typeEncoding); ret = true; } else ret = false; objc_globalMutex_unlock(); return ret; } IMP class_replaceMethod(Class class, SEL selector, IMP implementation, const char *typeEncoding) { struct objc_method *method; IMP oldImplementation; objc_globalMutex_lock(); if ((method = getMethod(class, selector)) != NULL) { oldImplementation = method->implementation; method->implementation = implementation; objc_updateDTable(class); } else { oldImplementation = NULL; addMethod(class, selector, implementation, typeEncoding); } objc_globalMutex_unlock(); return oldImplementation; } Class object_getClass(id object_) { struct objc_object *object; if (object_ == nil) return Nil; if (object_isTaggedPointer(object_)) return object_getTaggedPointerClass(object_); object = (struct objc_object *)object_; return object->isa; } Class object_setClass(id object_, Class class) { struct objc_object *object; Class old; if (object_ == nil) return Nil; object = (struct objc_object *)object_; old = object->isa; object->isa = class; return old; } const char * object_getClassName(id object) { return class_getName(object_getClass(object)); } static void unregisterClass(Class class) { if ((class->info & OBJC_CLASS_INFO_SETUP) && class->superclass != Nil && class->superclass->subclassList != NULL) { size_t i = SIZE_MAX, count = 0; Class *tmp; for (tmp = class->superclass->subclassList; *tmp != Nil; tmp++) { if (*tmp == class) i = count; count++; } if (count > 0 && i < SIZE_MAX) { tmp = class->superclass->subclassList; tmp[i] = tmp[count - 1]; tmp[count - 1] = NULL; if ((tmp = realloc(class->superclass->subclassList, count * sizeof(Class))) != NULL) class->superclass->subclassList = tmp; } } if (class->subclassList != NULL) { free(class->subclassList); class->subclassList = NULL; } if (class->dTable != NULL && class->dTable != emptyDTable) objc_dtable_free(class->dTable); class->dTable = NULL; if ((class->info & OBJC_CLASS_INFO_SETUP) && class->superclass != Nil) class->superclass = (Class)class->superclass->name; class->info &= ~OBJC_CLASS_INFO_SETUP; } void objc_unregisterClass(Class class) { static SEL unloadSel = NULL; objc_globalMutex_lock(); if (unloadSel == NULL) unloadSel = sel_registerName("unload"); while (class->subclassList != NULL && class->subclassList[0] != Nil) objc_unregisterClass(class->subclassList[0]); if (class->info & OBJC_CLASS_INFO_LOADED) callSelector(class, unloadSel); objc_hashtable_delete(classes, class->name); if (strcmp(class_getName(class), "Protocol") != 0) classesCount--; unregisterClass(class); unregisterClass(class->isa); objc_globalMutex_unlock(); } void objc_unregisterAllClasses(void) { if (classes == NULL) return; for (uint32_t i = 0; i < classes->size; i++) { if (classes->data[i] != NULL && classes->data[i] != &objc_deletedBucket) { void *class = (Class)classes->data[i]->object; if (class == Nil || (uintptr_t)class & 1) continue; objc_unregisterClass(class); /* * The table might have been resized, so go back to the * start again. * * Due to the i++ in the for loop, we need to set it to * UINT32_MAX so that it will get increased at the end * of the loop and thus become 0. */ i = UINT32_MAX; } } if (classesCount != 0) OBJC_ERROR("Fatal internal inconsistency!"); if (emptyDTable != NULL) { objc_dtable_free(emptyDTable); emptyDTable = NULL; } objc_sparsearray_free(fastPath); fastPath = NULL; objc_hashtable_free(classes); classes = NULL; } objfw-1.1.6/src/runtime/dtable.m000066400000000000000000000106231465614216400165240ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "ObjFWRT.h" #import "private.h" static struct objc_dtable_level2 *emptyLevel2 = NULL; #ifdef OF_SELUID24 static struct objc_dtable_level3 *emptyLevel3 = NULL; #endif static void init(void) { if ((emptyLevel2 = malloc(sizeof(*emptyLevel2))) == NULL) OBJC_ERROR("Not enough memory to allocate dispatch table!"); #ifdef OF_SELUID24 if ((emptyLevel3 = malloc(sizeof(*emptyLevel3))) == NULL) OBJC_ERROR("Not enough memory to allocate dispatch table!"); #endif #ifdef OF_SELUID24 for (uint_fast16_t i = 0; i < 256; i++) { emptyLevel2->buckets[i] = emptyLevel3; emptyLevel3->buckets[i] = (IMP)0; } #else for (uint_fast16_t i = 0; i < 256; i++) emptyLevel2->buckets[i] = (IMP)0; #endif } struct objc_dtable * objc_dtable_new(void) { struct objc_dtable *dTable; #ifdef OF_SELUID24 if (emptyLevel2 == NULL || emptyLevel3 == NULL) init(); #else if (emptyLevel2 == NULL) init(); #endif if ((dTable = malloc(sizeof(*dTable))) == NULL) OBJC_ERROR("Not enough memory to allocate dispatch table!"); for (uint_fast16_t i = 0; i < 256; i++) dTable->buckets[i] = emptyLevel2; return dTable; } void objc_dtable_copy(struct objc_dtable *dest, struct objc_dtable *src) { for (uint_fast16_t i = 0; i < 256; i++) { if (src->buckets[i] == emptyLevel2) continue; #ifdef OF_SELUID24 for (uint_fast16_t j = 0; j < 256; j++) { if (src->buckets[i]->buckets[j] == emptyLevel3) continue; for (uint_fast16_t k = 0; k < 256; k++) { IMP implementation; uint32_t idx; implementation = src->buckets[i]->buckets[j]->buckets[k]; if (implementation == (IMP)0) continue; idx = (uint32_t) (((uint32_t)i << 16) | (j << 8) | k); objc_dtable_set(dest, idx, implementation); } } #else for (uint_fast16_t j = 0; j < 256; j++) { IMP implementation = src->buckets[i]->buckets[j]; uint32_t idx; if (implementation == (IMP)0) continue; idx = (uint32_t)((i << 8) | j); objc_dtable_set(dest, idx, implementation); } #endif } } void objc_dtable_set(struct objc_dtable *dTable, uint32_t idx, IMP implementation) { #ifdef OF_SELUID24 uint8_t i = idx >> 16; uint8_t j = idx >> 8; uint8_t k = idx; #else uint8_t i = idx >> 8; uint8_t j = idx; #endif if (dTable->buckets[i] == emptyLevel2) { struct objc_dtable_level2 *level2 = malloc(sizeof(*level2)); if (level2 == NULL) OBJC_ERROR("Not enough memory to insert into " "dispatch table!"); for (uint_fast16_t l = 0; l < 256; l++) #ifdef OF_SELUID24 level2->buckets[l] = emptyLevel3; #else level2->buckets[l] = (IMP)0; #endif dTable->buckets[i] = level2; } #ifdef OF_SELUID24 if (dTable->buckets[i]->buckets[j] == emptyLevel3) { struct objc_dtable_level3 *level3 = malloc(sizeof(*level3)); if (level3 == NULL) OBJC_ERROR("Not enough memory to insert into " "dispatch table!"); for (uint_fast16_t l = 0; l < 256; l++) level3->buckets[l] = (IMP)0; dTable->buckets[i]->buckets[j] = level3; } dTable->buckets[i]->buckets[j]->buckets[k] = implementation; #else dTable->buckets[i]->buckets[j] = implementation; #endif } void objc_dtable_free(struct objc_dtable *dTable) { for (uint_fast16_t i = 0; i < 256; i++) { if (dTable->buckets[i] == emptyLevel2) continue; #ifdef OF_SELUID24 for (uint_fast16_t j = 0; j < 256; j++) if (dTable->buckets[i]->buckets[j] != emptyLevel3) free(dTable->buckets[i]->buckets[j]); #endif free(dTable->buckets[i]); } free(dTable); } void objc_dtable_cleanup(void) { if (emptyLevel2 != NULL) free(emptyLevel2); #ifdef OF_SELUID24 if (emptyLevel3 != NULL) free(emptyLevel3); #endif emptyLevel2 = NULL; #ifdef OF_SELUID24 emptyLevel3 = NULL; #endif } objfw-1.1.6/src/runtime/exception.m000066400000000000000000000471671465614216400173040ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #define OBJC_NO_PERSONALITY_DECLARATION #include #include #include #import "ObjFWRT.h" #import "private.h" #import "macros.h" #ifdef OF_HAVE_THREADS # import "OFPlainMutex.h" #endif #ifdef HAVE_SEH_EXCEPTIONS # include #endif #if defined(HAVE_DWARF_EXCEPTIONS) # define PERSONALITY __gnu_objc_personality_v0 # define CXX_PERSONALITY_STR "__gxx_personality_v0" #elif defined(HAVE_SJLJ_EXCEPTIONS) # define PERSONALITY __gnu_objc_personality_sj0 # define CXX_PERSONALITY_STR "__gxx_personality_sj0" # define _Unwind_RaiseException _Unwind_SjLj_RaiseException # define __builtin_eh_return_data_regno(i) (i) #elif defined(HAVE_SEH_EXCEPTIONS) # define PERSONALITY gnu_objc_personality #else # error Unknown exception type! #endif #if defined(OF_ARM) && !defined(__ARM_DWARF_EH__) # define HAVE_ARM_EHABI_EXCEPTIONS #endif #ifndef HAVE_ARM_EHABI_EXCEPTIONS # define PERSONALITY_FUNC(func) \ _Unwind_Reason_Code \ func(int version, int actions, uint64_t exClass, \ struct _Unwind_Exception *ex, struct _Unwind_Context *ctx) # define CALL_PERSONALITY(func) func(version, actions, exClass, ex, ctx) #else # define PERSONALITY_FUNC(func) \ _Unwind_Reason_Code \ func(uint32_t state, struct _Unwind_Exception *ex, \ struct _Unwind_Context *ctx) # define CALL_PERSONALITY(func) func(state, ex, ctx) #endif #define GNUCOBJC_EXCEPTION_CLASS UINT64_C(0x474E55434F424A43) /* GNUCOBJC */ #define GNUCCXX0_EXCEPTION_CLASS UINT64_C(0x474E5543432B2B00) /* GNUCC++\0 */ #define CLNGCXX0_EXCEPTION_CLASS UINT64_C(0x434C4E47432B2B00) /* CLNGC++\0 */ #define numEmergencyExceptions 4 enum { _UA_SEARCH_PHASE = 0x01, _UA_CLEANUP_PHASE = 0x02, _UA_HANDLER_FRAME = 0x04, _UA_FORCE_UNWIND = 0x08 }; enum { DW_EH_PE_absptr = 0x00, DW_EH_PE_uleb128 = 0x01, DW_EH_PE_udata2 = 0x02, DW_EH_PE_udata4 = 0x03, DW_EH_PE_udata8 = 0x04, DW_EH_PE_signed = 0x08, DW_EH_PE_sleb128 = (DW_EH_PE_signed | DW_EH_PE_uleb128), DW_EH_PE_sdata2 = (DW_EH_PE_signed | DW_EH_PE_udata2), DW_EH_PE_sdata4 = (DW_EH_PE_signed | DW_EH_PE_udata4), DW_EH_PE_sdata8 = (DW_EH_PE_signed | DW_EH_PE_udata8), DW_EH_PE_pcrel = 0x10, DW_EH_PE_textrel = 0x20, DW_EH_PE_datarel = 0x30, DW_EH_PE_funcrel = 0x40, DW_EH_PE_aligned = 0x50, DW_EH_PE_indirect = 0x80, DW_EH_PE_omit = 0xFF }; enum { CLEANUP_FOUND = 0x01, HANDLER_FOUND = 0x02 }; struct _Unwind_Context; typedef enum { _URC_OK = 0, _URC_FATAL_PHASE1_ERROR = 3, _URC_END_OF_STACK = 5, _URC_HANDLER_FOUND = 6, _URC_INSTALL_CONTEXT = 7, _URC_CONTINUE_UNWIND = 8, _URC_FAILURE = 9 } _Unwind_Reason_Code; struct objc_exception { struct _Unwind_Exception { uint64_t class; void (*cleanup)( _Unwind_Reason_Code, struct _Unwind_Exception *); #ifndef HAVE_ARM_EHABI_EXCEPTIONS # ifndef HAVE_SEH_EXCEPTIONS /* * The Itanium Exception ABI says to have those and never touch * them. */ uint64_t private1, private2; # else uint64_t private[6]; # endif #else /* From "Exception Handling ABI for the ARM(R) Architecture" */ struct { uint32_t reserved1, reserved2, reserved3, reserved4; uint32_t reserved; } unwinderCache; struct { uint32_t sp; uint32_t bitPattern[5]; } barrierCache; struct { uint32_t bitPattern[4]; } cleanupCache; struct { uint32_t fnstart; uint32_t *ehtp; uint32_t additional; uint32_t reserved1; } PRCache; long long int : 0; #endif } exception; id object; #ifndef HAVE_ARM_EHABI_EXCEPTIONS uintptr_t landingpad; intptr_t filter; #endif }; struct LSDA { uintptr_t regionStart, landingpadsStart; uint8_t typesTableEnc; const uint8_t *typesTable; uintptr_t typesTableBase; uint8_t callsitesEnc; const uint8_t *callsites, *actionTable; }; extern _Unwind_Reason_Code _Unwind_RaiseException(struct _Unwind_Exception *); extern void _Unwind_DeleteException(struct _Unwind_Exception *); extern void *_Unwind_GetLanguageSpecificData(struct _Unwind_Context *); extern uintptr_t _Unwind_GetRegionStart(struct _Unwind_Context *); #ifdef HAVE__UNWIND_GETDATARELBASE extern uintptr_t _Unwind_GetDataRelBase(struct _Unwind_Context *); #endif #ifdef HAVE__UNWIND_GETTEXTRELBASE extern uintptr_t _Unwind_GetTextRelBase(struct _Unwind_Context *); #endif #ifndef HAVE_ARM_EHABI_EXCEPTIONS # define CONTINUE_UNWIND return _URC_CONTINUE_UNWIND extern uintptr_t _Unwind_GetIP(struct _Unwind_Context *); extern uintptr_t _Unwind_GetGR(struct _Unwind_Context *, int); extern void _Unwind_SetIP(struct _Unwind_Context *, uintptr_t); extern void _Unwind_SetGR(struct _Unwind_Context *, int, uintptr_t); #else extern _Unwind_Reason_Code __gnu_unwind_frame(struct _Unwind_Exception *, struct _Unwind_Context *); extern int _Unwind_VRS_Get(struct _Unwind_Context *, int, uint32_t, int, void *); extern int _Unwind_VRS_Set(struct _Unwind_Context *, int, uint32_t, int, void *); # define CONTINUE_UNWIND \ { \ if (__gnu_unwind_frame(ex, ctx) != _URC_OK) \ return _URC_FAILURE; \ \ return _URC_CONTINUE_UNWIND; \ } static inline uintptr_t _Unwind_GetGR(struct _Unwind_Context *ctx, int regNo) { uintptr_t value; _Unwind_VRS_Get(ctx, 0, regNo, 0, &value); return value; } static inline uintptr_t _Unwind_GetIP(struct _Unwind_Context *ctx) { return _Unwind_GetGR(ctx, 15) & ~1; } static inline void _Unwind_SetGR(struct _Unwind_Context *ctx, int regNo, uintptr_t value) { _Unwind_VRS_Set(ctx, 0, regNo, 0, &value); } static inline void _Unwind_SetIP(struct _Unwind_Context *ctx, uintptr_t value) { uintptr_t thumb = _Unwind_GetGR(ctx, 15) & 1; _Unwind_SetGR(ctx, 15, (value | thumb)); } #endif #ifdef CXX_PERSONALITY static PERSONALITY_FUNC(cxx_personality) OF_WEAK_REF(CXX_PERSONALITY_STR); #endif #ifdef HAVE_SEH_EXCEPTIONS extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD, void *, PCONTEXT, PDISPATCHER_CONTEXT, _Unwind_Reason_Code (*)(int, int, uint64_t, struct _Unwind_Exception *, struct _Unwind_Context *)); #endif static objc_uncaught_exception_handler uncaughtExceptionHandler; static struct objc_exception emergencyExceptions[numEmergencyExceptions]; #ifdef OF_HAVE_THREADS static OFSpinlock emergencyExceptionsSpinlock; OF_CONSTRUCTOR() { if (OFSpinlockNew(&emergencyExceptionsSpinlock) != 0) OBJC_ERROR("Failed to create spinlock!"); } #endif static uint64_t readULEB128(const uint8_t **ptr) { uint64_t value = 0; uint8_t shift = 0; do { value |= (**ptr & 0x7F) << shift; (*ptr)++; shift += 7; } while (*(*ptr - 1) & 0x80); return value; } static int64_t readSLEB128(const uint8_t **ptr) { const uint8_t *oldPtr = *ptr; uint8_t bits; int64_t value; value = readULEB128(ptr); bits = (*ptr - oldPtr) * 7; if (bits < 64 && value & (INT64_C(1) << (bits - 1))) value |= -(INT64_C(1) << bits); return value; } static uintptr_t getBase(struct _Unwind_Context *ctx, uint8_t enc) { if (enc == DW_EH_PE_omit) return 0; switch (enc & 0x70) { case DW_EH_PE_absptr: case DW_EH_PE_pcrel: case DW_EH_PE_aligned: return 0; case DW_EH_PE_funcrel: return _Unwind_GetRegionStart(ctx); #ifdef HAVE__UNWIND_GETDATARELBASE case DW_EH_PE_datarel: return _Unwind_GetDataRelBase(ctx); #else case DW_EH_PE_datarel: return _Unwind_GetGR(ctx, 1); #endif #ifdef HAVE__UNWIND_GETTEXTRELBASE case DW_EH_PE_textrel: return _Unwind_GetTextRelBase(ctx); #endif } OBJC_ERROR("Unknown encoding!"); } static size_t sizeForEncoding(uint8_t enc) { if (enc == DW_EH_PE_omit) return 0; switch (enc & 0x07) { case DW_EH_PE_absptr: return sizeof(void *); case DW_EH_PE_udata2: return 2; case DW_EH_PE_udata4: return 4; case DW_EH_PE_udata8: return 8; } OBJC_ERROR("Unknown encoding!"); } static uint64_t readValue(uint8_t enc, const uint8_t **ptr) { uint64_t value; if (enc == DW_EH_PE_aligned) { const uintptr_t *aligned = (const uintptr_t *) OFRoundUpToPowerOf2(sizeof(void *), (uintptr_t)*ptr); *ptr = (const uint8_t *)(aligned + 1); return *aligned; } #define READ(type) \ { \ type tmp; \ memcpy(&tmp, *ptr, sizeof(type)); \ value = tmp; \ *ptr += sizeForEncoding(enc); \ break; \ } switch (enc & 0x0F) { case DW_EH_PE_absptr: READ(uintptr_t) case DW_EH_PE_uleb128: value = readULEB128(ptr); break; case DW_EH_PE_udata2: READ(uint16_t) case DW_EH_PE_udata4: READ(uint32_t) case DW_EH_PE_udata8: READ(uint64_t) case DW_EH_PE_sleb128: value = readSLEB128(ptr); break; case DW_EH_PE_sdata2: READ(int16_t) case DW_EH_PE_sdata4: READ(int32_t) case DW_EH_PE_sdata8: READ(int64_t) default: OBJC_ERROR("Unknown encoding!"); } #undef READ return value; } #ifndef HAVE_ARM_EHABI_EXCEPTIONS static uint64_t resolveValue(uint64_t value, uint8_t enc, const uint8_t *start, uint64_t base) { if (value == 0 || enc == DW_EH_PE_aligned) return value; value += ((enc & 0x70) == DW_EH_PE_pcrel ? (uintptr_t)start : base); if (enc & DW_EH_PE_indirect) value = *(uintptr_t *)(uintptr_t)value; return value; } #endif static void readLSDA(struct _Unwind_Context *ctx, const uint8_t *ptr, struct LSDA *LSDA) { uint8_t landingpadsStartEnc; uintptr_t callsitesSize; LSDA->regionStart = _Unwind_GetRegionStart(ctx); LSDA->landingpadsStart = LSDA->regionStart; LSDA->typesTable = NULL; if ((landingpadsStartEnc = *ptr++) != DW_EH_PE_omit) LSDA->landingpadsStart = (uintptr_t)readValue(landingpadsStartEnc, &ptr); if ((LSDA->typesTableEnc = *ptr++) != DW_EH_PE_omit) { uintptr_t tmp = (uintptr_t)readULEB128(&ptr); LSDA->typesTable = ptr + tmp; } LSDA->typesTableBase = getBase(ctx, LSDA->typesTableEnc); LSDA->callsitesEnc = *ptr++; callsitesSize = (uintptr_t)readULEB128(&ptr); LSDA->callsites = ptr; LSDA->actionTable = LSDA->callsites + callsitesSize; } static bool findCallsite(struct _Unwind_Context *ctx, struct LSDA *LSDA, uintptr_t *landingpad, const uint8_t **actionRecords) { uintptr_t IP = _Unwind_GetIP(ctx); const uint8_t *ptr = LSDA->callsites; *landingpad = 0; *actionRecords = NULL; #ifndef HAVE_SJLJ_EXCEPTIONS while (ptr < LSDA->actionTable) { uintptr_t callsiteStart, callsiteLength, callsiteLandingpad; uintptr_t callsiteAction; callsiteStart = LSDA->regionStart + (uintptr_t)readValue(LSDA->callsitesEnc, &ptr); callsiteLength = (uintptr_t)readValue(LSDA->callsitesEnc, &ptr); callsiteLandingpad = (uintptr_t)readValue(LSDA->callsitesEnc, &ptr); callsiteAction = (uintptr_t)readULEB128(&ptr); /* We can stop if we passed IP, as the table is sorted */ if (callsiteStart >= IP) break; if (callsiteStart + callsiteLength >= IP) { if (callsiteLandingpad != 0) *landingpad = LSDA->landingpadsStart + callsiteLandingpad; if (callsiteAction != 0) *actionRecords = LSDA->actionTable + callsiteAction - 1; return true; } } return false; #else uintptr_t callsiteLandingpad, callsiteAction; if ((intptr_t)IP < 1) return false; do { callsiteLandingpad = (uintptr_t)readULEB128(&ptr); callsiteAction = (uintptr_t)readULEB128(&ptr); } while (--IP > 1); *landingpad = callsiteLandingpad + 1; if (callsiteAction != 0) *actionRecords = LSDA->actionTable + callsiteAction - 1; return true; #endif } static bool classMatches(Class class, id object) { Class iter; if (class == Nil) return true; if (object == nil) return false; for (iter = object_getClass(object); iter != Nil; iter = class_getSuperclass(iter)) if (iter == class) return true; return false; } static uint8_t findActionRecord(const uint8_t *actionRecords, struct LSDA *LSDA, int actions, bool foreign, struct objc_exception *e, intptr_t *filterPtr) { const uint8_t *ptr; intptr_t filter, displacement; do { ptr = actionRecords; filter = (intptr_t)readSLEB128(&ptr); /* * Get the next action record. Since readSLEB128() modifies ptr, * we first set the actionrecord to the current ptr and then * add the displacement. */ actionRecords = ptr; displacement = (intptr_t)readSLEB128(&ptr); actionRecords += displacement; if (filter > 0 && !(actions & _UA_FORCE_UNWIND) && !foreign) { Class class; const char *className; uintptr_t c; const uint8_t *tmp; #ifndef HAVE_ARM_EHABI_EXCEPTIONS uintptr_t i; i = filter * sizeForEncoding(LSDA->typesTableEnc); tmp = LSDA->typesTable - i; c = (uintptr_t)readValue(LSDA->typesTableEnc, &tmp); c = (uintptr_t)resolveValue(c, LSDA->typesTableEnc, LSDA->typesTable - i, LSDA->typesTableBase); #else tmp = LSDA->typesTable - (filter * 4); c = *(uintptr_t *)(void *)tmp; if (c != 0) { c += (uintptr_t)tmp; # if defined(OF_LINUX) || defined(OF_NETBSD) c = *(uintptr_t *)c; # endif } #endif className = (const char *)c; if (className != NULL && *className != '\0' && strcmp(className, "@id") != 0) class = objc_getRequiredClass(className); else class = Nil; if (classMatches(class, e->object)) { *filterPtr = filter; return HANDLER_FOUND; } } else if (filter == 0) return CLEANUP_FOUND; else if (filter < 0) OBJC_ERROR("Invalid filter!"); } while (displacement != 0); return 0; } #ifdef HAVE_SEH_EXCEPTIONS static #endif PERSONALITY_FUNC(PERSONALITY) { #ifdef HAVE_ARM_EHABI_EXCEPTIONS int version = 1; uint64_t exClass = ex->class; int actions; switch (state) { case 0: /* _US_VIRTUAL_UNWIND_FRAME */ actions = _UA_SEARCH_PHASE; break; case 1: /* _US_UNWIND_FRAME_STARTING */ actions = _UA_CLEANUP_PHASE; if ((ex->barrierCache.sp == _Unwind_GetGR(ctx, 13)) != 0) actions |= _UA_HANDLER_FRAME; break; case 2: /* _US_UNWIND_FRAME_RESUME */ CONTINUE_UNWIND; default: return _URC_FAILURE; } _Unwind_SetGR(ctx, 12, (uintptr_t)ex); #endif struct objc_exception *e = (struct objc_exception *)ex; bool foreign = (exClass != GNUCOBJC_EXCEPTION_CLASS); const uint8_t *LSDAAddr, *actionRecords; struct LSDA LSDA; uintptr_t landingpad = 0; uint8_t found = 0; intptr_t filter = 0; if (foreign) { switch (exClass) { #ifdef CXX_PERSONALITY case GNUCCXX0_EXCEPTION_CLASS: case CLNGCXX0_EXCEPTION_CLASS: if (cxx_personality != NULL) return CALL_PERSONALITY(cxx_personality); break; #endif } /* * None matched or none available - we'll try to handle it * anyway, but will most likely fail. */ } if (version != 1 || ctx == NULL) return _URC_FATAL_PHASE1_ERROR; /* * We already cached everything we found in phase 1, so we only need * to install the context in phase 2. */ if (actions & _UA_HANDLER_FRAME && !foreign) { /* * For handlers, reg #0 must be the exception's object and reg * #1 the filter. */ _Unwind_SetGR(ctx, __builtin_eh_return_data_regno(0), (uintptr_t)e->object); #ifndef HAVE_ARM_EHABI_EXCEPTIONS _Unwind_SetGR(ctx, __builtin_eh_return_data_regno(1), e->filter); _Unwind_SetIP(ctx, e->landingpad); #else _Unwind_SetGR(ctx, __builtin_eh_return_data_regno(1), ex->barrierCache.bitPattern[1]); _Unwind_SetIP(ctx, ex->barrierCache.bitPattern[3]); #endif _Unwind_DeleteException(ex); return _URC_INSTALL_CONTEXT; } /* No LSDA -> nothing to handle */ if ((LSDAAddr = _Unwind_GetLanguageSpecificData(ctx)) == NULL) CONTINUE_UNWIND; readLSDA(ctx, LSDAAddr, &LSDA); if (!findCallsite(ctx, &LSDA, &landingpad, &actionRecords)) CONTINUE_UNWIND; if (landingpad != 0 && actionRecords != NULL) found = findActionRecord(actionRecords, &LSDA, actions, foreign, e, &filter); else if (landingpad != 0) found = CLEANUP_FOUND; if (found == 0) CONTINUE_UNWIND; if (actions & _UA_SEARCH_PHASE) { if (!(found & HANDLER_FOUND) || foreign) CONTINUE_UNWIND; /* Cache it so we don't have to search it again in phase 2 */ #ifndef HAVE_ARM_EHABI_EXCEPTIONS e->landingpad = landingpad; e->filter = filter; #else ex->barrierCache.sp = _Unwind_GetGR(ctx, 13); ex->barrierCache.bitPattern[1] = filter; ex->barrierCache.bitPattern[3] = landingpad; #endif return _URC_HANDLER_FOUND; } else if (actions & _UA_CLEANUP_PHASE) { if (!(found & CLEANUP_FOUND)) CONTINUE_UNWIND; _Unwind_SetGR(ctx, __builtin_eh_return_data_regno(0), (uintptr_t)ex); _Unwind_SetGR(ctx, __builtin_eh_return_data_regno(1), filter); _Unwind_SetIP(ctx, landingpad); return _URC_INSTALL_CONTEXT; } OBJC_ERROR( "Neither _UA_SEARCH_PHASE nor _UA_CLEANUP_PHASE in actions!"); } static void cleanup(_Unwind_Reason_Code reason, struct _Unwind_Exception *ex) { free(ex); } static void emergencyExceptionCleanup(_Unwind_Reason_Code reason, struct _Unwind_Exception *ex) { #ifdef OF_HAVE_THREADS if (OFSpinlockLock(&emergencyExceptionsSpinlock) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif ex->class = 0; #ifdef OF_HAVE_THREADS if (OFSpinlockUnlock(&emergencyExceptionsSpinlock) != 0) OBJC_ERROR("Failed to unlock spinlock!"); #endif } void objc_exception_throw(id object) { struct objc_exception *e = calloc(1, sizeof(*e)); bool emergency = false; if (e == NULL) { #ifdef OF_HAVE_THREADS if (OFSpinlockLock(&emergencyExceptionsSpinlock) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif for (uint_fast8_t i = 0; i < numEmergencyExceptions; i++) { if (emergencyExceptions[i].exception.class == 0) { e = &emergencyExceptions[i]; e->exception.class = GNUCOBJC_EXCEPTION_CLASS; emergency = true; break; } } #ifdef OF_HAVE_THREADS if (OFSpinlockUnlock(&emergencyExceptionsSpinlock) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif } if (e == NULL) OBJC_ERROR("Not enough memory to allocate exception!"); e->exception.class = GNUCOBJC_EXCEPTION_CLASS; e->exception.cleanup = (emergency ? emergencyExceptionCleanup : cleanup); e->object = object; _Unwind_RaiseException(&e->exception); if (uncaughtExceptionHandler != NULL) uncaughtExceptionHandler(object); OBJC_ERROR("_Unwind_RaiseException() returned!"); } objc_uncaught_exception_handler objc_setUncaughtExceptionHandler(objc_uncaught_exception_handler handler) { objc_uncaught_exception_handler old = uncaughtExceptionHandler; uncaughtExceptionHandler = handler; return old; } #ifdef HAVE_SEH_EXCEPTIONS typedef EXCEPTION_DISPOSITION (*seh_personality_fn)(PEXCEPTION_RECORD, void *, PCONTEXT, PDISPATCHER_CONTEXT); static seh_personality_fn __gxx_personality_seh0; OF_CONSTRUCTOR() { /* * This only works if the application uses libstdc++-6.dll. * There is unfortunately no other way, as Windows does not support * proper weak linking. */ HMODULE module; if ((module = GetModuleHandle("libstdc++-6")) == NULL) return; __gxx_personality_seh0 = (seh_personality_fn) GetProcAddress(module, "__gxx_personality_seh0"); } EXCEPTION_DISPOSITION __gnu_objc_personality_seh0(PEXCEPTION_RECORD ms_exc, void *this_frame, PCONTEXT ms_orig_context, PDISPATCHER_CONTEXT ms_disp) { struct _Unwind_Exception *ex = (struct _Unwind_Exception *)ms_exc->ExceptionInformation[0]; switch (ex->class) { case GNUCCXX0_EXCEPTION_CLASS: case CLNGCXX0_EXCEPTION_CLASS: if (__gxx_personality_seh0 != NULL) return __gxx_personality_seh0(ms_exc, this_frame, ms_orig_context, ms_disp); } return _GCC_specific_handler(ms_exc, this_frame, ms_orig_context, ms_disp, PERSONALITY); } #endif objfw-1.1.6/src/runtime/hashtable.m000066400000000000000000000122531465614216400172250ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #include #include #include #import "ObjFWRT.h" #import "private.h" struct objc_hashtable_bucket objc_deletedBucket; uint32_t objc_string_hash(const void *str_) { const char *str = str_; uint32_t hash = 0; while (*str != 0) { hash += *str; hash += (hash << 10); hash ^= (hash >> 6); str++; } hash += (hash << 3); hash ^= (hash >> 11); hash += (hash << 15); return hash; } bool objc_string_equal(const void *ptr1, const void *ptr2) { return (strcmp(ptr1, ptr2) == 0); } struct objc_hashtable * objc_hashtable_new(uint32_t (*hash)(const void *), bool (*equal)(const void *, const void *), uint32_t size) { struct objc_hashtable *table; if ((table = malloc(sizeof(*table))) == NULL) OBJC_ERROR("Not enough memory to allocate hash table!"); table->hash = hash; table->equal = equal; table->count = 0; table->size = size; table->data = calloc(size, sizeof(struct objc_hashtable_bucket *)); if (table->data == NULL) OBJC_ERROR("Not enough memory to allocate hash table!"); return table; } static void resize(struct objc_hashtable *table, uint32_t count) { uint32_t fullness, newSize; struct objc_hashtable_bucket **newData; if (count > UINT32_MAX / sizeof(*table->data) || count > UINT32_MAX / 8) OBJC_ERROR("Integer overflow!"); fullness = count * 8 / table->size; if (fullness >= 6) { if (table->size > UINT32_MAX / 2) return; newSize = table->size * 2; } else if (fullness <= 1) newSize = table->size / 2; else return; if (count < table->count && newSize < 16) return; if ((newData = calloc(newSize, sizeof(*newData))) == NULL) OBJC_ERROR("Not enough memory to resize hash table!"); for (uint32_t i = 0; i < table->size; i++) { if (table->data[i] != NULL && table->data[i] != &objc_deletedBucket) { uint32_t j, last; last = newSize; for (j = table->data[i]->hash & (newSize - 1); j < last && newData[j] != NULL; j++); if (j >= last) { last = table->data[i]->hash & (newSize - 1); for (j = 0; j < last && newData[j] != NULL; j++); } if (j >= last) OBJC_ERROR("No free bucket in hash table!"); newData[j] = table->data[i]; } } free(table->data); table->data = newData; table->size = newSize; } static inline bool indexForKey(struct objc_hashtable *table, const void *key, uint32_t *idx) { uint32_t i, hash; hash = table->hash(key) & (table->size - 1); for (i = hash; i < table->size && table->data[i] != NULL; i++) { if (table->data[i] == &objc_deletedBucket) continue; if (table->equal(table->data[i]->key, key)) { *idx = i; return true; } } if (i < table->size) return false; for (i = 0; i < hash && table->data[i] != NULL; i++) { if (table->data[i] == &objc_deletedBucket) continue; if (table->equal(table->data[i]->key, key)) { *idx = i; return true; } } return false; } void objc_hashtable_set(struct objc_hashtable *table, const void *key, const void *object) { uint32_t i, hash, last; struct objc_hashtable_bucket *bucket; if (indexForKey(table, key, &i)) { table->data[i]->object = object; return; } resize(table, table->count + 1); hash = table->hash(key); last = table->size; for (i = hash & (table->size - 1); i < last && table->data[i] != NULL && table->data[i] != &objc_deletedBucket; i++); if (i >= last) { last = hash & (table->size - 1); for (i = 0; i < last && table->data[i] != NULL && table->data[i] != &objc_deletedBucket; i++); } if (i >= last) OBJC_ERROR("No free bucket in hash table!"); if ((bucket = malloc(sizeof(*bucket))) == NULL) OBJC_ERROR("Not enough memory to allocate hash table bucket!"); bucket->key = key; bucket->hash = hash; bucket->object = object; table->data[i] = bucket; table->count++; } void * objc_hashtable_get(struct objc_hashtable *table, const void *key) { uint32_t idx; if (!indexForKey(table, key, &idx)) return NULL; return (void *)table->data[idx]->object; } void objc_hashtable_delete(struct objc_hashtable *table, const void *key) { uint32_t idx; if (!indexForKey(table, key, &idx)) return; free(table->data[idx]); table->data[idx] = &objc_deletedBucket; table->count--; resize(table, table->count); } void objc_hashtable_free(struct objc_hashtable *table) { for (uint32_t i = 0; i < table->size; i++) if (table->data[i] != NULL && table->data[i] != &objc_deletedBucket) free(table->data[i]); free(table->data); free(table); } objfw-1.1.6/src/runtime/init.m000066400000000000000000000024511465614216400162340ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFWRT.h" #import "private.h" void __objc_exec_class(struct _objc_module *module) { objc_globalMutex_lock(); objc_registerAllSelectors(module->symtab); objc_registerAllClasses(module->symtab); objc_registerAllCategories(module->symtab); objc_initStaticInstances(module->symtab); objc_globalMutex_unlock(); } void objc_deinit(void) { objc_globalMutex_lock(); objc_unregisterAllCategories(); objc_unregisterAllClasses(); objc_unregisterAllSelectors(); objc_forgetPendingStaticInstances(); objc_dtable_cleanup(); objc_globalMutex_unlock(); } objfw-1.1.6/src/runtime/instance.m000066400000000000000000000051571465614216400171030ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #ifdef OF_OBJFW_RUNTIME # import "ObjFWRT.h" # import "private.h" #else # import #endif #ifndef OF_OBJFW_RUNTIME extern void objc_removeAssociatedObjects(id object); #endif static SEL constructSelector = NULL; static SEL destructSelector = NULL; static bool callConstructors(Class class, id object) { Class super = class_getSuperclass(class); id (*construct)(id, SEL); id (*last)(id, SEL); if (super != nil) if (!callConstructors(super, object)) return false; if (constructSelector == NULL) constructSelector = sel_registerName(".cxx_construct"); if (!class_respondsToSelector(class, constructSelector)) return true; construct = (id (*)(id, SEL)) class_getMethodImplementation(class, constructSelector); last = (id (*)(id, SEL)) class_getMethodImplementation(super, constructSelector); if (construct == last) return true; return (construct(object, constructSelector) != nil); } id objc_constructInstance(Class class, void *bytes) { id object = (id)bytes; if (class == Nil || bytes == NULL) return nil; object_setClass(object, class); if (!callConstructors(class, object)) return nil; return object; } void * objc_destructInstance(id object) { Class class; void (*last)(id, SEL) = NULL; if (object == nil) return NULL; #ifdef OF_OBJFW_RUNTIME objc_zeroWeakReferences(object); #endif if (destructSelector == NULL) destructSelector = sel_registerName(".cxx_destruct"); for (class = object_getClass(object); class != Nil; class = class_getSuperclass(class)) { void (*destruct)(id, SEL); if (class_respondsToSelector(class, destructSelector)) { if ((destruct = (void (*)(id, SEL)) class_getMethodImplementation(class, destructSelector)) != last) destruct(object, destructSelector); last = destruct; } else break; } objc_removeAssociatedObjects(object); return object; } objfw-1.1.6/src/runtime/ivar.m000066400000000000000000000032221465614216400162270ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFWRT.h" #import "private.h" Ivar * class_copyIvarList(Class class, unsigned int *outCount) { unsigned int count; Ivar *ivars; if (class == Nil) { if (outCount != NULL) *outCount = 0; return NULL; } objc_globalMutex_lock(); count = (class->ivars != NULL ? class->ivars->count : 0); if (count == 0) { if (outCount != NULL) *outCount = 0; objc_globalMutex_unlock(); return NULL; } if ((ivars = malloc((count + 1) * sizeof(Ivar))) == NULL) OBJC_ERROR("Not enough memory to copy ivars!"); for (unsigned int i = 0; i < count; i++) ivars[i] = &class->ivars->ivars[i]; ivars[count] = NULL; if (outCount != NULL) *outCount = count; objc_globalMutex_unlock(); return ivars; } const char * ivar_getName(Ivar ivar) { return ivar->name; } const char * ivar_getTypeEncoding(Ivar ivar) { return ivar->typeEncoding; } ptrdiff_t ivar_getOffset(Ivar ivar) { return ivar->offset; } objfw-1.1.6/src/runtime/lookup-asm/000077500000000000000000000000001465614216400172005ustar00rootroot00000000000000objfw-1.1.6/src/runtime/lookup-asm/Makefile000066400000000000000000000002751465614216400206440ustar00rootroot00000000000000include ../../../extra.mk STATIC_PIC_LIB_NOINST = ${LOOKUP_ASM_LIB_A} STATIC_LIB_NOINST = ${LOOKUP_ASM_A} SRCS = lookup-asm.S include ../../../buildsys.mk ASFLAGS += -I../../.. -I../.. objfw-1.1.6/src/runtime/lookup-asm/lookup-asm-amd64-elf.S000066400000000000000000000045301465614216400230720ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" #ifdef HAVE_CET_H # include #else # define _CET_ENDBR #endif .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text .macro GENERATE_LOOKUP name notFound \name: _CET_ENDBR testq %rdi, %rdi jz .LreturnNilMethod testb $1, %dil jnz .LtaggedPointer_\name movq (%rdi), %r8 movq 64(%r8), %r8 .Lmain_\name: movq (%rsi), %rax movzbl %ah, %ecx movzbl %al, %edx #ifdef OF_SELUID24 shrl $16, %eax movq (%r8,%rax,8), %r8 #endif movq (%r8,%rcx,8), %r8 movq (%r8,%rdx,8), %rax testq %rax, %rax jz \notFound@PLT ret .LtaggedPointer_\name: movq objc_taggedPointerSecret@GOTPCREL(%rip), %rax xorq (%rax), %rdi andb $0xE, %dil movzbl %dil, %r8d movq objc_taggedPointerClasses@GOTPCREL(%rip), %rax movq (%rax,%r8,4), %r8 movq 64(%r8), %r8 jmp .Lmain_\name .type \name, %function .size \name, .-\name .endm .macro GENERATE_LOOKUP_SUPER name lookup \name: _CET_ENDBR movq %rdi, %r8 movq (%rdi), %rdi testq %rdi, %rdi jz .LreturnNilMethod movq 8(%r8), %r8 movq 64(%r8), %r8 jmp .Lmain_\lookup .type \name, %function .size \name, .-\name .endm GENERATE_LOOKUP objc_msg_lookup objc_methodNotFound GENERATE_LOOKUP objc_msg_lookup_stret objc_methodNotFound_stret GENERATE_LOOKUP_SUPER objc_msg_lookup_super objc_msg_lookup GENERATE_LOOKUP_SUPER objc_msg_lookup_super_stret objc_msg_lookup_stret .LreturnNilMethod: leaq .LnilMethod(%rip), %rax ret .LnilMethod: _CET_ENDBR xorq %rax, %rax ret #if defined(OF_LINUX) || defined(OF_HAIKU) || defined(OF_HURD) .section .note.GNU-stack, "", %progbits #endif objfw-1.1.6/src/runtime/lookup-asm/lookup-asm-amd64-macho.S000066400000000000000000000041661465614216400234200ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #ifdef HAVE_CET_H # include #else # define _CET_ENDBR #endif .globl _objc_msg_lookup .globl _objc_msg_lookup_stret .globl _objc_msg_lookup_super .globl _objc_msg_lookup_super_stret .section __TEXT, __text, regular, pure_instructions .macro GENERATE_LOOKUP $0: _CET_ENDBR testq %rdi, %rdi jz LreturnNilMethod testb $$1, %dil jnz LtaggedPointer_$0 movq (%rdi), %r8 movq 64(%r8), %r8 Lmain_$0: movq (%rsi), %rax movzbl %ah, %ecx movzbl %al, %edx #ifdef OF_SELUID24 shrl $$16, %eax movq (%r8,%rax,8), %r8 #endif movq (%r8,%rcx,8), %r8 movq (%r8,%rdx,8), %rax testq %rax, %rax jz $1 ret LtaggedPointer_$0: movq _objc_taggedPointerSecret@GOTPCREL(%rip), %rax xorq (%rax), %rdi andb $$0xE, %dil movzbl %dil, %r8d movq _objc_taggedPointerClasses@GOTPCREL(%rip), %rax movq (%rax,%r8,4), %r8 movq 64(%r8), %r8 jmp Lmain_$0 .endmacro .macro GENERATE_LOOKUP_SUPER $0: _CET_ENDBR movq %rdi, %r8 movq (%rdi), %rdi testq %rdi, %rdi jz LreturnNilMethod movq 8(%r8), %r8 movq 64(%r8), %r8 jmp Lmain_$1 .endmacro GENERATE_LOOKUP _objc_msg_lookup, _objc_methodNotFound GENERATE_LOOKUP _objc_msg_lookup_stret, _objc_methodNotFound_stret GENERATE_LOOKUP_SUPER _objc_msg_lookup_super, _objc_msg_lookup GENERATE_LOOKUP_SUPER _objc_msg_lookup_super_stret, _objc_msg_lookup_stret LreturnNilMethod: leaq LnilMethod(%rip), %rax ret LnilMethod: _CET_ENDBR xorq %rax, %rax ret objfw-1.1.6/src/runtime/lookup-asm/lookup-asm-amd64-win64.S000066400000000000000000000043431465614216400232750ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #ifdef HAVE_CET_H # include #else # define _CET_ENDBR #endif .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text .macro GENERATE_LOOKUP name notFound \name: _CET_ENDBR testq %rcx, %rcx jz .LreturnNilMethod testb $1, %cl jnz .LtaggedPointer_\name movq (%rcx), %r8 movq 56(%r8), %r8 .Lmain_\name: movq %rcx, %r10 movq %rdx, %r11 movq (%rdx), %rax movzbl %ah, %ecx movzbl %al, %edx #ifdef OF_SELUID24 shrl $16, %eax movq (%r8,%rax,8), %r8 #endif movq (%r8,%rcx,8), %r8 movq (%r8,%rdx,8), %rax testq %rax, %rax jz 0f ret 0: movq %r10, %rcx movq %r11, %rdx jmp \notFound .LtaggedPointer_\name: xorq objc_taggedPointerSecret(%rip), %rcx andb $0xE, %cl movzbl %cl, %r8d leaq objc_taggedPointerClasses(%rip), %rax movq (%rax,%r8,4), %r8 movq 56(%r8), %r8 jmp .Lmain_\name .def \name .scl 2 .type 32 .endef .endm .macro GENERATE_LOOKUP_SUPER name lookup \name: _CET_ENDBR movq %rcx, %r8 movq (%rcx), %rcx testq %rcx, %rcx jz .LreturnNilMethod movq 8(%r8), %r8 movq 56(%r8), %r8 jmp .Lmain_\lookup .def \name .scl 2 .type 32 .endef .endm GENERATE_LOOKUP objc_msg_lookup objc_methodNotFound GENERATE_LOOKUP objc_msg_lookup_stret objc_methodNotFound_stret GENERATE_LOOKUP_SUPER objc_msg_lookup_super objc_msg_lookup GENERATE_LOOKUP_SUPER objc_msg_lookup_super_stret objc_msg_lookup_stret .LreturnNilMethod: leaq .LnilMethod(%rip), %rax ret .LnilMethod: _CET_ENDBR xorq %rax, %rax ret objfw-1.1.6/src/runtime/lookup-asm/lookup-asm-arm-elf.S000066400000000000000000000052321465614216400227360ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text .macro GENERATE_LOOKUP name notFound \name: cmp r0, #0 beq .LreturnNilMethod tst r0, #1 bne .LtaggedPointer_\name ldr r2, [r0, #0] ldr r2, [r2, #32] .Lmain_\name: #ifndef OF_BIG_ENDIAN # ifdef OF_SELUID24 ldrb r3, [r1, #2] ldr r2, [r2, r3, lsl #2] # endif ldrb r3, [r1, #1] ldr r2, [r2, r3, lsl #2] ldrb r3, [r1, #0] ldr r2, [r2, r3, lsl #2] #else # ifdef OF_SELUID24 ldrb r3, [r1, #1] ldr r2, [r2, r3, lsl #2] # endif ldrb r3, [r1, #2] ldr r2, [r2, r3, lsl #2] ldrb r3, [r1, #3] ldr r2, [r2, r3, lsl #2] #endif cmp r2, #0 beq \notFound(PLT) mov r0, r2 bx lr .LtaggedPointer_\name: ldr r2, .Lgot$indirect_.LtaggedPointer_\name add r2, pc, r2 ldr r3, .Lgot$indirect_.LtaggedPointer_\name+4 ldr r3, [r2, r3] ldr r3, [r3] eor r0, r0, r3 and r0, r0, #0xE lsl r0, r0, #1 ldr r3, .Lgot$indirect_.LtaggedPointer_\name+8 ldr r3, [r2, r3] ldr r2, [r3, r0] ldr r2, [r2, #32] b .Lmain_\name .type \name, %function .size \name, .-\name .Lgot$indirect_.LtaggedPointer_\name: .long _GLOBAL_OFFSET_TABLE_-(.LtaggedPointer_\name+12) .long objc_taggedPointerSecret(GOT) .long objc_taggedPointerClasses(GOT) .endm .macro GENERATE_LOOKUP_SUPER name lookup \name: mov r2, r0 ldr r0, [r0, #0] cmp r0, #0 beq .LreturnNilMethod ldr r2, [r2, #4] ldr r2, [r2, #32] b .Lmain_\lookup .type \name, %function .size \name, .-\name .endm GENERATE_LOOKUP objc_msg_lookup objc_methodNotFound GENERATE_LOOKUP objc_msg_lookup_stret objc_methodNotFound_stret GENERATE_LOOKUP_SUPER objc_msg_lookup_super objc_msg_lookup GENERATE_LOOKUP_SUPER objc_msg_lookup_super_stret objc_msg_lookup_stret .LreturnNilMethod: adr r0, .LnilMethod bx lr .LnilMethod: mov r0, #0 bx lr #if defined(OF_LINUX) || defined(OF_HAIKU) || defined(OF_HURD) .section .note.GNU-stack, "", %progbits #endif objfw-1.1.6/src/runtime/lookup-asm/lookup-asm-arm64-elf.S000066400000000000000000000045101465614216400231060ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text .macro GENERATE_LOOKUP name notFound \name: #ifdef HAVE_BTI bti c #endif cbz x0, .LreturnNilMethod tbnz x0, #0, .LtaggedPointer_\name ldr x2, [x0] ldr x2, [x2, #64] .Lmain_\name: #ifdef OF_SELUID24 ldrb w3, [x1, #2] ldr x2, [x2, x3, lsl #3] #endif ldrb w3, [x1, #1] ldr x2, [x2, x3, lsl #3] ldrb w3, [x1] ldr x2, [x2, x3, lsl #3] cbz x2, \notFound mov x0, x2 ret .LtaggedPointer_\name: adrp x2, :got:objc_taggedPointerSecret ldr x2, [x2, #:got_lo12:objc_taggedPointerSecret] ldr x2, [x2] eor x0, x0, x2 and x0, x0, #0xE lsl x0, x0, #2 adrp x2, :got:objc_taggedPointerClasses ldr x2, [x2, #:got_lo12:objc_taggedPointerClasses] ldr x2, [x2, x0] ldr x2, [x2, #64] b .Lmain_\name .type \name, %function .size \name, .-\name .endm .macro GENERATE_LOOKUP_SUPER name lookup \name: #ifdef HAVE_BTI bti c #endif mov x2, x0 ldr x0, [x0] cbz x0, .LreturnNilMethod ldr x2, [x2, #8] ldr x2, [x2, #64] b .Lmain_\lookup .type \name, %function .size \name, .-\name .endm GENERATE_LOOKUP objc_msg_lookup objc_methodNotFound GENERATE_LOOKUP objc_msg_lookup_stret objc_methodNotFound_stret GENERATE_LOOKUP_SUPER objc_msg_lookup_super objc_msg_lookup GENERATE_LOOKUP_SUPER objc_msg_lookup_super_stret objc_msg_lookup_stret .LreturnNilMethod: adr x0, .LnilMethod ret .LnilMethod: #ifdef HAVE_BTI bti c #endif mov x0, #0 ret #if defined(OF_LINUX) || defined(OF_HAIKU) || defined(OF_HURD) .section .note.GNU-stack, "", %progbits #endif objfw-1.1.6/src/runtime/lookup-asm/lookup-asm-mips-elf.S000066400000000000000000000060061465614216400231270ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text .macro GENERATE_LOOKUP name notFound \name: beqz $a0, 0f andi $t0, $a0, 1 bnez $t0, .LtaggedPointer_\name lw $t0, 0($a0) lw $t0, 32($t0) .Lmain_\name: #ifdef OF_BIG_ENDIAN # ifdef OF_SELUID24 lbu $t1, 1($a1) # endif lbu $t2, 2($a1) lbu $t3, 3($a1) #else # ifdef OF_SELUID24 lbu $t1, 2($a1) # endif lbu $t2, 1($a1) lbu $t3, 0($a1) #endif #ifdef OF_SELUID24 sll $t1, $t1, 2 #endif sll $t2, $t2, 2 sll $t3, $t3, 2 #ifdef OF_SELUID24 addu $t0, $t0, $t1 lw $t0, 0($t0) #endif addu $t0, $t0, $t2 lw $t0, 0($t0) addu $t0, $t0, $t3 lw $t0, 0($t0) #ifdef OF_PIC beqz $t0, 1f #else beqz $t0, \notFound #endif move $v0, $t0 jr $ra 0: #ifdef OF_PIC addiu $v0, $t9, .LnilMethod-\name #else la $v0, .LnilMethod #endif jr $ra #ifdef OF_PIC 1: lui $gp, %hi(_gp_disp) addiu $gp, $gp, %lo(_gp_disp) addu $gp, $gp, $t9 addiu $gp, $gp, 1b-\name lw $t9, %call16(\notFound)($gp) jr $t9 #endif .LtaggedPointer_\name: #ifdef OF_PIC 0: lui $gp, %hi(_gp_disp) addiu $gp, $gp, %lo(_gp_disp) addu $gp, $gp, $t9 addiu $gp, $gp, 0b-\name lw $t0, %got(objc_taggedPointerSecret)($gp) #else la $t0, objc_taggedPointerSecret #endif lw $t0, 0($t0) xor $t0, $a0, $t0 and $t0, $t0, 0xE sll $t0, $t0, 1 #ifdef OF_PIC lw $t1, %got(objc_taggedPointerClasses)($gp) #else la $t1, objc_taggedPointerClasses #endif addu $t0, $t1, $t0 ld $t0, ($t0) ld $t0, 32($t0) b .Lmain_\name .type \name, %function .size \name, .-\name .endm .macro GENERATE_LOOKUP_SUPER name lookup \name: move $t0, $a0 lw $a0, 0($a0) beqz $a0, 0f lw $t0, 4($t0) lw $t0, 32($t0) addiu $t9, $t9, \lookup-\name b .Lmain_\lookup 0: #ifdef OF_PIC addiu $v0, $t9, .LnilMethod-\name #else la $v0, .LnilMethod #endif jr $ra .type \name, %function .size \name, .-\name .endm GENERATE_LOOKUP objc_msg_lookup objc_methodNotFound GENERATE_LOOKUP objc_msg_lookup_stret objc_methodNotFound_stret GENERATE_LOOKUP_SUPER objc_msg_lookup_super objc_msg_lookup GENERATE_LOOKUP_SUPER objc_msg_lookup_super_stret objc_msg_lookup_stret .LnilMethod: move $v0, $zero jr $ra #if defined(OF_LINUX) || defined(OF_HAIKU) || defined(OF_HURD) .section .note.GNU-stack, "", %progbits #endif objfw-1.1.6/src/runtime/lookup-asm/lookup-asm-mips64-n64-elf.S000066400000000000000000000056741465614216400237200ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text .macro GENERATE_LOOKUP name notFound \name: beqz $a0, 0f andi $t0, $a0, 1 bnez $t0, .LtaggedPointer_\name ld $t0, ($a0) ld $t0, 64($t0) .Lmain_\name: #ifdef OF_BIG_ENDIAN # ifdef OF_SELUID24 lbu $t1, 5($a1) # endif lbu $t2, 6($a1) lbu $t3, 7($a1) #else # ifdef OF_SELUID24 lbu $t1, 2($a1) # endif lbu $t2, 1($a1) lbu $t3, ($a1) #endif #ifdef OF_SELUID24 sll $t1, $t1, 3 #endif sll $t2, $t2, 3 sll $t3, $t3, 3 #ifdef OF_SELUID24 daddu $t0, $t0, $t1 ld $t0, ($t0) #endif daddu $t0, $t0, $t2 ld $t0, ($t0) daddu $t0, $t0, $t3 ld $t0, ($t0) beqz $t0, 1f move $v0, $t0 jr $ra 0: lui $v0, %hi(%neg(%gp_rel(\name))) daddiu $v0, $v0, %lo(%neg(%gp_rel(\name))) daddu $v0, $v0, $t9 ld $v0, %got_disp(.LnilMethod)($v0) jr $ra 1: lui $t0, %hi(%neg(%gp_rel(\name))) daddiu $t0, $t0, %lo(%neg(%gp_rel(\name))) daddu $t0, $t0, $t9 ld $t9, %got_disp(\notFound)($t0) jr $t9 .LtaggedPointer_\name: lui $t0, %hi(%neg(%gp_rel(\name))) daddiu $t0, $t0, %lo(%neg(%gp_rel(\name))) daddu $t0, $t0, $t9 ld $t1, %got_disp(objc_taggedPointerSecret)($t0) ld $t1, 0($t1) xor $t1, $a0, $t1 and $t1, $t1, 0xE dsll $t1, $t1, 2 ld $t0, %got_disp(objc_taggedPointerClasses)($t0) daddu $t0, $t0, $t1 ld $t0, ($t0) ld $t0, 64($t0) b .Lmain_\name .type \name, %function .size \name, .-\name .endm .macro GENERATE_LOOKUP_SUPER name lookup \name: move $t0, $a0 ld $a0, ($a0) beqz $a0, 0f ld $t0, 8($t0) ld $t0, 64($t0) daddiu $t9, $t9, \lookup-\name b .Lmain_\lookup 0: lui $v0, %hi(%neg(%gp_rel(\name))) daddiu $v0, $v0, %lo(%neg(%gp_rel(\name))) daddu $v0, $v0, $t9 ld $v0, %got_disp(.LnilMethod)($v0) jr $ra .type \name, %function .size \name, .-\name .endm GENERATE_LOOKUP objc_msg_lookup objc_methodNotFound GENERATE_LOOKUP objc_msg_lookup_stret objc_methodNotFound_stret GENERATE_LOOKUP_SUPER objc_msg_lookup_super objc_msg_lookup GENERATE_LOOKUP_SUPER objc_msg_lookup_super_stret objc_msg_lookup_stret .LnilMethod: move $v0, $zero jr $ra #if defined(OF_LINUX) || defined(OF_HAIKU) || defined(OF_HURD) .section .note.GNU-stack, "", %progbits #endif objfw-1.1.6/src/runtime/lookup-asm/lookup-asm-powerpc-elf.S000066400000000000000000000070651465614216400236440ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text .macro GENERATE_LOOKUP name notFound \name: cmpwi %r3, 0 beq- .LreturnNilMethod andi. %r0, %r3, 1 bne- .LtaggedPointer_\name lwz %r5, 0(%r3) lwz %r5, 32(%r5) .Lmain_\name: lwz %r8, 0(%r4) #ifdef OF_SELUID24 rlwinm %r6, %r8, 18, 0x3FC #endif rlwinm %r7, %r8, 26, 0x3FC rlwinm %r8, %r8, 2, 0x3FC #ifdef OF_SELUID24 lwzx %r5, %r5, %r6 #endif lwzx %r5, %r5, %r7 lwzx %r5, %r5, %r8 cmpwi %r5, 0 beq- 0f mr %r3, %r5 blr 0: #ifdef OF_PIC stwu %r1, -16(%r1) mflr %r0 stw %r0, 20(%r1) stw %r30, 8(%r1) bl 0f 0: mflr %r30 addis %r30, %r30, .Lbiased_got2-0b@ha addi %r30, %r30, .Lbiased_got2-0b@l lwz %r0, .Lgot_\notFound-.Lbiased_got2(%r30) mtctr %r0 lwz %r30, 8(%r1) lwz %r0, 20(%r1) addi %r1, %r1, 16 mtlr %r0 bctr #else b \notFound #endif .LtaggedPointer_\name: #if defined(OF_PIC) mflr %r7 bl 0f 0: mflr %r6 mtlr %r7 addis %r6, %r6, .Lbiased_got2-0b@ha addi %r6, %r6, .Lbiased_got2-0b@l lwz %r5, .Lgot_objc_taggedPointerSecret-.Lbiased_got2(%r6) lwz %r5, 0(%r5) #elif defined(OF_BASEREL) addis %r5, %r13, objc_taggedPointerSecret@drel@ha lwz %r5, objc_taggedPointerSecret@drel@l(%r5) #else lis %r5, objc_taggedPointerSecret@ha lwz %r5, objc_taggedPointerSecret@l(%r5) #endif xor %r5, %r3, %r5 rlwinm %r5, %r5, 1, 0x1C #if defined(OF_PIC) lwz %r6, .Lgot_objc_taggedPointerClasses-.Lbiased_got2(%r6) #elif defined(OF_BASEREL) addis %r6, %r13, objc_taggedPointerClasses@drel@ha addi %r6, %r6, objc_taggedPointerClasses@drel@l #else lis %r6, objc_taggedPointerClasses@ha addi %r6, %r6, objc_taggedPointerClasses@l #endif lwzx %r5, %r6, %r5 lwz %r5, 32(%r5) b .Lmain_\name .type \name, @function .size \name, .-\name .endm .macro GENERATE_LOOKUP_SUPER name lookup \name: mr %r5, %r3 lwz %r3, 0(%r3) cmpwi %r3, 0 beq- .LreturnNilMethod lwz %r5, 4(%r5) lwz %r5, 32(%r5) b .Lmain_\lookup .type \name, @function .size \name, .-\name .endm GENERATE_LOOKUP objc_msg_lookup objc_methodNotFound GENERATE_LOOKUP objc_msg_lookup_stret objc_methodNotFound_stret GENERATE_LOOKUP_SUPER objc_msg_lookup_super objc_msg_lookup GENERATE_LOOKUP_SUPER objc_msg_lookup_super_stret objc_msg_lookup_stret .LreturnNilMethod: mflr %r0 bl .LgetPC mtlr %r0 0: addi %r3, %r3, .LnilMethod-0b blr .LnilMethod: li %r3, 0 blr .LgetPC: mflr %r3 blr #ifdef OF_PIC .section .got2, "aw" .Lbiased_got2 = .+0x8000 .Lgot_objc_methodNotFound: .long objc_methodNotFound .Lgot_objc_methodNotFound_stret: .long objc_methodNotFound_stret .Lgot_objc_taggedPointerSecret: .long objc_taggedPointerSecret .Lgot_objc_taggedPointerClasses: .long objc_taggedPointerClasses #endif #if defined(OF_LINUX) || defined(OF_HAIKU) || defined(OF_HURD) .section .note.GNU-stack, "", @progbits #endif objfw-1.1.6/src/runtime/lookup-asm/lookup-asm-powerpc64-elf.S000066400000000000000000000067261465614216400240210ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" #if defined(_CALL_ELF) && _CALL_ELF == 2 .abiversion 2 #endif .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text .macro GENERATE_LOOKUP name notFound #if defined(_CALL_ELF) && _CALL_ELF == 2 \name: addis %r2, %r12, .TOC.-\name@ha addi %r2, %r2, .TOC.-\name@l .localentry \name, .-\name #else .section .opd, "aw", @progbits \name: .p2align 3 .quad .Lbegin_\name .quad .TOC.@tocbase .quad 0 .section .text #endif .Lbegin_\name: cmpdi %r3, 0 beq- .LreturnNilMethod andi. %r0, %r3, 1 bne- .LtaggedPointer_\name ld %r5, 0(%r3) ld %r5, 64(%r5) .Lmain_\name: ld %r8, 0(%r4) #ifdef OF_SELUID24 rlwinm %r6, %r8, 19, 0x7F8 #endif rlwinm %r7, %r8, 27, 0x7F8 rlwinm %r8, %r8, 3, 0x7F8 #ifdef OF_SELUID24 ldx %r5, %r5, %r6 #endif ldx %r5, %r5, %r7 ldx %r5, %r5, %r8 cmpdi %r5, 0 beq- 0f mr %r3, %r5 blr 0: mflr %r0 std %r0, 16(%r1) stdu %r1, -112(%r1) bl \notFound nop addi %r1, %r1, 112 ld %r0, 16(%r1) mtlr %r0 blr .LtaggedPointer_\name: addis %r5, %r2, objc_taggedPointerSecret@toc@ha ld %r5, objc_taggedPointerSecret@toc@l(%r5) xor %r5, %r3, %r5 rlwinm %r5, %r5, 2, 0x38 addis %r6, %r2, objc_taggedPointerClasses@toc@ha addi %r6, %r6, objc_taggedPointerClasses@toc@l ldx %r5, %r6, %r5 ld %r5, 64(%r5) b .Lmain_\name .type \name, @function .size \name, .-.Lbegin_\name .endm .macro GENERATE_LOOKUP_SUPER name lookup #if defined(_CALL_ELF) && _CALL_ELF == 2 \name: addis %r2, %r12, .TOC.-\name@ha addi %r2, %r2, .TOC.-\name@l .localentry \name, .-\name #else .section .opd, "aw", @progbits \name: .p2align 3 .quad .Lbegin_\name .quad .TOC.@tocbase .quad 0 .section .text #endif .Lbegin_\name: mr %r5, %r3 ld %r3, 0(%r3) cmpdi %r3, 0 beq- .LreturnNilMethod ld %r5, 8(%r5) ld %r5, 64(%r5) b .Lmain_\lookup .type \name, @function .size \name, .-.Lbegin_\name .endm GENERATE_LOOKUP objc_msg_lookup objc_methodNotFound GENERATE_LOOKUP objc_msg_lookup_stret objc_methodNotFound_stret GENERATE_LOOKUP_SUPER objc_msg_lookup_super objc_msg_lookup GENERATE_LOOKUP_SUPER objc_msg_lookup_super_stret objc_msg_lookup_stret .LreturnNilMethod: addis %r3, %r2, .LnilMethod@toc@ha addi %r3, %r3, .LnilMethod@toc@l blr #if defined(_CALL_ELF) && _CALL_ELF == 2 .LnilMethod: addis %r2, %r12, .TOC.-.LnilMethod@ha addi %r2, %r2, .TOC.-.LnilMethod@l .localentry .LnilMethod, .-.LnilMethod #else .section .opd, "aw", @progbits .LnilMethod: .p2align 3 .quad .Lbegin_nilMethod .quad .TOC.@tocbase .quad 0 .section .text #endif .Lbegin_nilMethod: li %r3, 0 blr .type .LnilMethod, @function .size .LnilMethod, .-.Lbegin_nilMethod #if defined(OF_LINUX) || defined(OF_HAIKU) || defined(OF_HURD) .section .note.GNU-stack, "", @progbits #endif objfw-1.1.6/src/runtime/lookup-asm/lookup-asm-sparc-elf.S000066400000000000000000000057401465614216400232730ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text .macro GENERATE_LOOKUP name notFound \name: tst %o0 bz .LreturnNilMethod btst 1, %o0 bnz .LtaggedPointer_\name nop ld [%o0], %o2 ld [%o2 + 32], %o2 .Lmain_\name: #ifdef OF_SELUID24 ldub [%o1 + 1], %o3 #endif ldub [%o1 + 2], %o4 ldub [%o1 + 3], %o5 #ifdef OF_SELUID24 sll %o3, 2, %o3 #endif sll %o4, 2, %o4 sll %o5, 2, %o5 #ifdef OF_SELUID24 ld [%o2 + %o3], %o2 #endif ld [%o2 + %o4], %o2 ld [%o2 + %o5], %o2 cmp %o2, 0 be 0f nop retl mov %o2, %o0 0: mov %o7, %g1 call \notFound mov %g1, %o7 .LtaggedPointer_\name: #ifdef OF_PIC mov %o7, %g1 sethi %hi(_GLOBAL_OFFSET_TABLE_ - 4), %o3 call 0f or %o3, %lo(_GLOBAL_OFFSET_TABLE_ + 4), %o3 0: add %o7, %o3, %o3 mov %g1, %o7 #endif sethi %hi(objc_taggedPointerSecret), %o2 or %o2, %lo(objc_taggedPointerSecret), %o2 #ifdef OF_PIC ld [%o3 + %o2], %o2 #endif ld [%o2], %o2 xor %o0, %o2, %o0 and %o0, 0xE, %o0 sll %o0, 1, %o0 sethi %hi(objc_taggedPointerClasses), %o2 or %o2, %lo(objc_taggedPointerClasses), %o2 #ifdef OF_PIC ld [%o3 + %o2], %o2 #endif ld [%o2 + %o0], %o2 ba .Lmain_\name ld [%o2 + 32], %o2 .type \name, %function .size \name, .-\name .endm .macro GENERATE_LOOKUP_SUPER name lookup \name: mov %o0, %o2 ld [%o0], %o0 cmp %o0, 0 be .LreturnNilMethod nop ld [%o2 + 4], %o2 ba .Lmain_\lookup ld [%o2 + 32], %o2 .type \name, %function .size \name, .-\name .endm GENERATE_LOOKUP objc_msg_lookup objc_methodNotFound GENERATE_LOOKUP objc_msg_lookup_stret objc_methodNotFound_stret GENERATE_LOOKUP_SUPER objc_msg_lookup_super objc_msg_lookup GENERATE_LOOKUP_SUPER objc_msg_lookup_super_stret objc_msg_lookup_stret .LreturnNilMethod: #ifdef OF_PIC mov %o7, %g1 sethi %hi(_GLOBAL_OFFSET_TABLE_ - 4), %o1 call 0f add %o1, %lo(_GLOBAL_OFFSET_TABLE_ + 4), %o1 0: add %o7, %o1, %o1 sethi %hi(.LnilMethod), %o0 or %o0, %lo(.LnilMethod), %o0 jmpl %g1 + 8, %g0 ld [%o1 + %o0], %o0 #else sethi %hi(.LnilMethod), %o0 retl or %o0, %lo(.LnilMethod), %o0 #endif .LnilMethod: retl clr %o0 #if defined(OF_LINUX) || defined(OF_HAIKU) || defined(OF_HURD) .section .note.GNU-stack, "", %progbits #endif objfw-1.1.6/src/runtime/lookup-asm/lookup-asm-sparc64-elf.S000066400000000000000000000057631465614216400234520ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text .macro GENERATE_LOOKUP name notFound \name: brz,pn %o0, .LreturnNilMethod and %o0, 1, %o2 brnz,pn %o2, .LtaggedPointer_\name nop ldx [%o0], %o2 ldx [%o2 + 64], %o2 .Lmain_\name: #ifdef OF_SELUID24 ldub [%o1 + 5], %o3 #endif ldub [%o1 + 6], %o4 ldub [%o1 + 7], %o5 #ifdef OF_SELUID24 sll %o3, 3, %o3 #endif sll %o4, 3, %o4 sll %o5, 3, %o5 #ifdef OF_SELUID24 ldx [%o2 + %o3], %o2 #endif ldx [%o2 + %o4], %o2 ldx [%o2 + %o5], %o2 brz,pn %o2, 0f nop retl mov %o2, %o0 0: mov %o7, %g1 call \notFound mov %g1, %o7 .LtaggedPointer_\name: #ifdef OF_PIC mov %o7, %g1 sethi %hi(_GLOBAL_OFFSET_TABLE_ - 4), %o3 call 0f or %o3, %lo(_GLOBAL_OFFSET_TABLE_ + 4), %o3 0: add %o7, %o3, %o3 mov %g1, %o7 #endif sethi %hi(objc_taggedPointerSecret), %o2 or %o2, %lo(objc_taggedPointerSecret), %o2 #ifdef OF_PIC ldx [%o3 + %o2], %o2 #endif ldx [%o2], %o2 xor %o0, %o2, %o0 and %o0, 0xE, %o0 sll %o0, 2, %o0 sethi %hi(objc_taggedPointerClasses), %o2 or %o2, %lo(objc_taggedPointerClasses), %o2 #ifdef OF_PIC ldx [%o3 + %o2], %o2 #endif ldx [%o2 + %o0], %o2 ba .Lmain_\name ldx [%o2 + 64], %o2 .type \name, %function .size \name, .-\name .endm .macro GENERATE_LOOKUP_SUPER name lookup \name: mov %o0, %o2 ldx [%o0], %o0 brz,pn %o0, .LreturnNilMethod nop ldx [%o2 + 8], %o2 ba .Lmain_\lookup ldx [%o2 + 64], %o2 .type \name, %function .size \name, .-\name .endm GENERATE_LOOKUP objc_msg_lookup objc_methodNotFound GENERATE_LOOKUP objc_msg_lookup_stret objc_methodNotFound_stret GENERATE_LOOKUP_SUPER objc_msg_lookup_super objc_msg_lookup GENERATE_LOOKUP_SUPER objc_msg_lookup_super_stret objc_msg_lookup_stret .LreturnNilMethod: #ifdef OF_PIC mov %o7, %g1 sethi %hi(_GLOBAL_OFFSET_TABLE_ - 4), %o1 call 0f or %o1, %lo(_GLOBAL_OFFSET_TABLE_ + 4), %o1 0: add %o7, %o1, %o1 sethi %hi(.LnilMethod), %o0 or %o0, %lo(.LnilMethod), %o0 jmpl %g1 + 8, %g0 ldx [%o1 + %o0], %o0 #else sethi %hi(.LnilMethod), %o0 retl or %o0, %lo(.LnilMethod), %o0 #endif .LnilMethod: retl clr %o0 #if defined(OF_LINUX) || defined(OF_HAIKU) || defined(OF_HURD) .section .note.GNU-stack, "", %progbits #endif objfw-1.1.6/src/runtime/lookup-asm/lookup-asm-x86-elf.S000066400000000000000000000053121465614216400226030ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" #ifdef HAVE_CET_H # include #else # define _CET_ENDBR #endif .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text .macro GENERATE_LOOKUP name notFound \name: _CET_ENDBR movl 4(%esp), %edx testl %edx, %edx jz .LreturnNilMethod testb $1, %dl jnz .LtaggedPointer_\name movl (%edx), %edx movl 32(%edx), %edx .Lmain_\name: movl 8(%esp), %eax #ifdef OF_SELUID24 movzbl 2(%eax), %ecx movl (%edx,%ecx,4), %edx #endif movzbl 1(%eax), %ecx movl (%edx,%ecx,4), %edx movzbl (%eax), %ecx movl (%edx,%ecx,4), %eax testl %eax, %eax jz 0f ret 0: call .LgetEIP addl $_GLOBAL_OFFSET_TABLE_, %eax movl \notFound@GOT(%eax), %eax jmp *%eax .LtaggedPointer_\name: call .LgetEIP addl $_GLOBAL_OFFSET_TABLE_, %eax movl objc_taggedPointerSecret@GOT(%eax), %ecx xorl (%ecx), %edx andb $0xE, %dl movzbl %dl, %edx movl objc_taggedPointerClasses@GOT(%eax), %eax movl (%eax,%edx,2), %edx movl 32(%edx), %edx jmp .Lmain_\name .type \name, %function .size \name, .-\name .endm .macro GENERATE_LOOKUP_SUPER name lookup \name: _CET_ENDBR movl 4(%esp), %edx movl (%edx), %eax testl %eax, %eax jz .LreturnNilMethod subl $16, %esp movl %eax, (%esp) movl 24(%esp), %eax movl %eax, 4(%esp) movl 4(%edx), %edx movl 32(%edx), %edx call .Lmain_\lookup addl $16, %esp ret .type \name, %function .size \name, .-\name .endm GENERATE_LOOKUP objc_msg_lookup objc_methodNotFound GENERATE_LOOKUP objc_msg_lookup_stret objc_methodNotFound_stret GENERATE_LOOKUP_SUPER objc_msg_lookup_super objc_msg_lookup GENERATE_LOOKUP_SUPER objc_msg_lookup_super_stret objc_msg_lookup_stret .LreturnNilMethod: call .LgetEIP addl $_GLOBAL_OFFSET_TABLE_, %eax leal .LnilMethod@GOTOFF(%eax), %eax ret .LnilMethod: _CET_ENDBR xorl %eax, %eax ret .LgetEIP: movl (%esp), %eax ret #if defined(OF_LINUX) || defined(OF_HAIKU) || defined(OF_HURD) .section .note.GNU-stack, "", %progbits #endif objfw-1.1.6/src/runtime/lookup-asm/lookup-asm-x86-win32.S000066400000000000000000000044301465614216400227770ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #ifdef HAVE_CET_H # include #else # define _CET_ENDBR #endif .globl _objc_msg_lookup .globl _objc_msg_lookup_stret .globl _objc_msg_lookup_super .globl _objc_msg_lookup_super_stret .section .text .macro GENERATE_LOOKUP name notFound \name: _CET_ENDBR movl 4(%esp), %edx testl %edx, %edx jz .LreturnNilMethod testb $1, %dl jnz .LtaggedPointer_\name movl (%edx), %edx movl 32(%edx), %edx .Lmain_\name: movl 8(%esp), %eax #ifdef OF_SELUID24 movzbl 2(%eax), %ecx movl (%edx,%ecx,4), %edx #endif movzbl 1(%eax), %ecx movl (%edx,%ecx,4), %edx movzbl (%eax), %ecx movl (%edx,%ecx,4), %eax testl %eax, %eax jz \notFound ret .LtaggedPointer_\name: xorl _objc_taggedPointerSecret, %edx andb $0xE, %dl movzbl %dl, %edx movl _objc_taggedPointerClasses(,%edx,2), %edx movl 32(%edx), %edx jmp .Lmain_\name .def \name .scl 2 .type 32 .endef .endm .macro GENERATE_LOOKUP_SUPER name lookup \name: _CET_ENDBR movl 4(%esp), %edx movl (%edx), %eax testl %eax, %eax jz .LreturnNilMethod subl $16, %esp movl %eax, (%esp) movl 24(%esp), %eax movl %eax, 4(%esp) movl 4(%edx), %edx movl 32(%edx), %edx call .Lmain_\lookup addl $16, %esp ret .def \name .scl 2 .type 32 .endef .endm GENERATE_LOOKUP _objc_msg_lookup _objc_methodNotFound GENERATE_LOOKUP _objc_msg_lookup_stret _objc_methodNotFound_stret GENERATE_LOOKUP_SUPER _objc_msg_lookup_super _objc_msg_lookup GENERATE_LOOKUP_SUPER _objc_msg_lookup_super_stret _objc_msg_lookup_stret .LreturnNilMethod: movl $.LnilMethod, %eax ret .LnilMethod: _CET_ENDBR xorl %eax, %eax ret objfw-1.1.6/src/runtime/lookup-asm/lookup-asm.S000066400000000000000000000032231465614216400214130ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include "platform.h" #if defined(OF_ELF) # if defined(OF_AMD64) # include "lookup-asm-amd64-elf.S" # elif defined(OF_X86) # include "lookup-asm-x86-elf.S" # elif defined(OF_ARM64) # include "lookup-asm-arm64-elf.S" # elif defined(OF_ARM) # include "lookup-asm-arm-elf.S" # elif defined(OF_POWERPC64) # include "lookup-asm-powerpc64-elf.S" # elif defined(OF_POWERPC) # include "lookup-asm-powerpc-elf.S" # elif defined(OF_MIPS64_N64) # include "lookup-asm-mips64-n64-elf.S" # elif defined(OF_MIPS) # include "lookup-asm-mips-elf.S" # elif defined(OF_SPARC64) # include "lookup-asm-sparc64-elf.S" # elif defined(OF_SPARC) # include "lookup-asm-sparc-elf.S" # endif #elif defined(OF_MACH_O) # if defined(OF_AMD64) # include "lookup-asm-amd64-macho.S" # endif #elif defined(OF_WINDOWS) # if defined(OF_AMD64) # include "lookup-asm-amd64-win64.S" # elif defined(OF_X86) # include "lookup-asm-x86-win32.S" # endif #endif objfw-1.1.6/src/runtime/lookup.m000066400000000000000000000115631465614216400166060ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "ObjFWRT.h" #import "private.h" #import "macros.h" static IMP forwardHandler = (IMP)0; static IMP stretForwardHandler = (IMP)0; static IMP commonMethodNotFound(id object, SEL selector, IMP (*lookup)(id, SEL), IMP forward) { /* * object might be a dummy object (see class_getMethodImplementation), * so don't access object directly unless it's a class! */ bool isClass = object_getClass(object)->info & OBJC_CLASS_INFO_METACLASS; if (!(object_getClass(object)->info & OBJC_CLASS_INFO_INITIALIZED)) { Class class = (isClass ? (Class)object : object_getClass(object)); objc_initializeClass(class); if (!(class->info & OBJC_CLASS_INFO_SETUP)) OBJC_ERROR("Could not dispatch message %s for " "incomplete class %s!", sel_getName(selector), class_getName(class)); /* * We don't need to handle the case that super was called. * The reason for this is that a call to super is not possible * before a message to the class has been sent and it thus has * been initialized together with its superclasses. */ return lookup(object, selector); } /* Try resolveClassMethod: / resolveInstanceMethod: */ if (class_isMetaClass(object_getClass(object))) { Class class = object_getClass(object); if (class_respondsToSelector(class, @selector(resolveClassMethod:)) && [object resolveClassMethod: selector]) { if (!class_respondsToSelector(class, selector)) OBJC_ERROR("+[%s resolveClassMethod: %s] " "returned true without adding the method!", class_getName(object), sel_getName(selector)); return lookup(object, selector); } } else { Class class = object_getClass(object); Class metaclass = object_getClass(class); if (class_respondsToSelector(metaclass, @selector(resolveInstanceMethod:)) && [class resolveInstanceMethod: selector]) { if (!class_respondsToSelector(class, selector)) OBJC_ERROR("+[%s resolveInstanceMethod: %s] " "returned true without adding the method!", class_getName(object_getClass(object)), sel_getName(selector)); return lookup(object, selector); } } if (forward != (IMP)0) return forward; OBJC_ERROR("Selector %c[%s] is not implemented for class %s!", (isClass ? '+' : '-'), sel_getName(selector), object_getClassName(object)); } IMP objc_methodNotFound(id object, SEL selector) { return commonMethodNotFound(object, selector, objc_msg_lookup, forwardHandler); } IMP objc_methodNotFound_stret(id object, SEL selector) { return commonMethodNotFound(object, selector, objc_msg_lookup_stret, stretForwardHandler); } void objc_setForwardHandler(IMP forward, IMP stretForward) { forwardHandler = forward; stretForwardHandler = stretForward; } bool class_respondsToSelector(Class class, SEL selector) { if (class == Nil) return false; return (objc_dtable_get(class->dTable, (uint32_t)selector->UID) != (IMP)0); } #ifndef OF_ASM_LOOKUP static id nilMethod(id self, SEL _cmd) { return nil; } static OF_INLINE IMP commonLookup(id object, SEL selector, IMP (*notFound)(id, SEL)) { IMP imp; if (object == nil) return (IMP)nilMethod; imp = objc_dtable_get(object_getClass(object)->dTable, (uint32_t)selector->UID); if (imp == (IMP)0) return notFound(object, selector); return imp; } IMP objc_msg_lookup(id object, SEL selector) { return commonLookup(object, selector, objc_methodNotFound); } IMP objc_msg_lookup_stret(id object, SEL selector) { return commonLookup(object, selector, objc_methodNotFound_stret); } static OF_INLINE IMP commonSuperLookup(struct objc_super *super, SEL selector, IMP (*notFound)(id, SEL)) { IMP imp; if (super->self == nil) return (IMP)nilMethod; imp = objc_dtable_get(super->class->dTable, (uint32_t)selector->UID); if (imp == (IMP)0) return notFound(super->self, selector); return imp; } IMP objc_msg_lookup_super(struct objc_super *super, SEL selector) { return commonSuperLookup(super, selector, objc_methodNotFound); } IMP objc_msg_lookup_super_stret(struct objc_super *super, SEL selector) { return commonSuperLookup(super, selector, objc_methodNotFound_stret); } #endif objfw-1.1.6/src/runtime/method.m000066400000000000000000000035341465614216400165540ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFWRT.h" #import "private.h" Method * class_copyMethodList(Class class, unsigned int *outCount) { unsigned int i, count; struct objc_method_list *iter; Method *methods; if (class == Nil) { if (outCount != NULL) *outCount = 0; return NULL; } objc_globalMutex_lock(); count = 0; for (iter = class->methodList; iter != NULL; iter = iter->next) count += iter->count; if (count == 0) { if (outCount != NULL) *outCount = 0; objc_globalMutex_unlock(); return NULL; } if ((methods = malloc((count + 1) * sizeof(Method))) == NULL) OBJC_ERROR("Not enough memory to copy methods"); i = 0; for (iter = class->methodList; iter != NULL; iter = iter->next) for (unsigned int j = 0; j < iter->count; j++) methods[i++] = &iter->methods[j]; if (i != count) OBJC_ERROR("Fatal internal inconsistency!"); methods[count] = NULL; if (outCount != NULL) *outCount = count; objc_globalMutex_unlock(); return methods; } SEL method_getName(Method method) { return (SEL)&method->selector; } const char * method_getTypeEncoding(Method method) { return method->selector.typeEncoding; } objfw-1.1.6/src/runtime/misc.m000066400000000000000000000063541465614216400162320ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #include #include "ObjFWRT.h" #include "private.h" #ifdef OF_WINDOWS # include #endif #ifdef OF_AMIGAOS # define Class IntuitionClass # define USE_INLINE_STDARG # include # include # define __NOLIBBASE__ # include # undef __NOLIBBASE__ # undef Class #endif static objc_enumeration_mutation_handler enumerationMutationHandler = NULL; void objc_enumerationMutation(id object) { if (enumerationMutationHandler != NULL) enumerationMutationHandler(object); else OBJC_ERROR("Object was mutated during enumeration!"); } void objc_setEnumerationMutationHandler(objc_enumeration_mutation_handler handler) { enumerationMutationHandler = handler; } void objc_error(const char *title, const char *format, ...) { #if defined(OF_WINDOWS) || defined(OF_AMIGAOS) # define messageLen 512 char message[messageLen]; int status; va_list args; va_start(args, format); status = vsnprintf(message, messageLen, format, args); if (status <= 0 || status >= messageLen) message[0] = '\0'; va_end(args); # undef BUF_LEN #endif #if defined(OF_WINDOWS) fprintf(stderr, "[%s] %s\n", title, message); fflush(stderr); MessageBoxA(NULL, message, title, MB_OK | MB_SYSTEMMODAL | MB_ICONERROR); exit(EXIT_FAILURE); #elif defined(OF_AMIGAOS) struct Library *IntuitionBase; # ifdef OF_AMIGAOS4 struct IntuitionIFace *IIntuition; # endif struct EasyStruct easy; # ifndef OF_AMIGAOS4 kprintf("[%s] %s\n", title, message); # endif if ((IntuitionBase = OpenLibrary("intuition.library", 0)) == NULL) exit(EXIT_FAILURE); # ifdef OF_AMIGAOS4 if ((IIntuition = (struct IntuitionIFace *)GetInterface(IntuitionBase, "main", 1, NULL)) == NULL) exit(EXIT_FAILURE); # endif easy.es_StructSize = sizeof(easy); easy.es_Flags = 0; easy.es_Title = (void *)title; easy.es_TextFormat = (void *)"%s"; easy.es_GadgetFormat = (void *)"OK"; EasyRequest(NULL, &easy, NULL, (ULONG)message); # ifdef OF_AMIGAOS4 DropInterface((struct Interface *)IIntuition); # endif CloseLibrary(IntuitionBase); exit(EXIT_FAILURE); #else va_list args; va_start(args, format); fprintf(stderr, "[%s] ", title); vfprintf(stderr, format, args); fprintf(stderr, "\n"); fflush(stderr); va_end(args); abort(); #endif OF_UNREACHABLE } char * objc_strdup(const char *string) { char *copy; size_t length = strlen(string); if ((copy = (char *)malloc(length + 1)) == NULL) return NULL; memcpy(copy, string, length + 1); return copy; } objfw-1.1.6/src/runtime/private.h000066400000000000000000000241271465614216400167420ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "macros.h" #if !defined(__has_feature) || !__has_feature(nullability) # ifndef _Nonnull # define _Nonnull # endif # ifndef _Nullable # define _Nullable # endif #endif typedef uint32_t (*_Nonnull objc_hashtable_hash_func)(const void *_Nonnull key); typedef bool (*_Nonnull objc_hashtable_equal_func)(const void *_Nonnull key1, const void *_Nonnull key2); struct objc_class { Class _Nonnull isa; Class _Nullable superclass; const char *_Nonnull name; unsigned long version; unsigned long info; long instanceSize; struct objc_ivar_list *_Nullable ivars; struct objc_method_list *_Nullable methodList; struct objc_dtable *_Nullable dTable; Class _Nullable *_Nullable subclassList; void *_Nullable siblingClass; struct objc_protocol_list *_Nullable protocols; void *_Nullable GCObjectType; unsigned long ABIVersion; int32_t *_Nonnull *_Nullable ivarOffsets; struct objc_property_list *_Nullable propertyList; }; enum objc_class_info { OBJC_CLASS_INFO_CLASS = 0x001, OBJC_CLASS_INFO_METACLASS = 0x002, OBJC_CLASS_INFO_NEW_ABI = 0x010, OBJC_CLASS_INFO_SETUP = 0x100, OBJC_CLASS_INFO_LOADED = 0x200, OBJC_CLASS_INFO_DTABLE = 0x400, OBJC_CLASS_INFO_INITIALIZED = 0x800 }; struct objc_object { Class _Nonnull isa; }; struct objc_selector { uintptr_t UID; const char *_Nullable typeEncoding; }; struct objc_method { struct objc_selector selector; IMP _Nonnull implementation; }; struct objc_method_list { struct objc_method_list *_Nullable next; unsigned int count; struct objc_method methods[1]; }; struct objc_category { const char *_Nonnull categoryName; const char *_Nonnull className; struct objc_method_list *_Nullable instanceMethods; struct objc_method_list *_Nullable classMethods; struct objc_protocol_list *_Nullable protocols; }; struct objc_ivar { const char *_Nonnull name; const char *_Nonnull typeEncoding; unsigned int offset; }; struct objc_ivar_list { unsigned int count; struct objc_ivar ivars[1]; }; struct objc_method_description { const char *_Nonnull name; const char *_Nonnull typeEncoding; }; struct objc_method_description_list { int count; struct objc_method_description list[1]; }; struct objc_protocol_list { struct objc_protocol_list *_Nullable next; long count; Protocol *__unsafe_unretained _Nonnull list[1]; }; #if __has_attribute(__objc_root_class__) __attribute__((__objc_root_class__)) #endif @interface Protocol { @public Class _Nonnull isa; const char *_Nonnull name; struct objc_protocol_list *_Nullable protocolList; struct objc_method_description_list *_Nullable instanceMethods; struct objc_method_description_list *_Nullable classMethods; } @end enum objc_property_attributes { OBJC_PROPERTY_READONLY = 0x01, OBJC_PROPERTY_GETTER = 0x02, OBJC_PROPERTY_ASSIGN = 0x04, OBJC_PROPERTY_READWRITE = 0x08, OBJC_PROPERTY_RETAIN = 0x10, OBJC_PROPERTY_COPY = 0x20, OBJC_PROPERTY_NONATOMIC = 0x40, OBJC_PROPERTY_SETTER = 0x80 }; enum objc_property_extended_attributes { OBJC_PROPERTY_SYNTHESIZED = 0x1, OBJC_PROPERTY_DYNAMIC = 0x2, OBJC_PROPERTY_PROTOCOL = 0x3, OBJC_PROPERTY_ATOMIC = 0x4, OBJC_PROPERTY_WEAK = 0x8, OBJC_PROPERTY_STRONG = 0x10, OBJC_PROPERTY_UNSAFE_UNRETAINED = 0x20 }; struct objc_property { const char *_Nonnull name; unsigned char attributes, extendedAttributes; struct { const char *_Nullable name; const char *_Nullable typeEncoding; } getter, setter; }; struct objc_property_list { unsigned int count; struct objc_property_list *_Nullable next; struct objc_property properties[1]; }; struct objc_static_instances { const char *_Nonnull className; id _Nullable instances[1]; }; struct objc_symtab { unsigned long unknown; struct objc_selector *_Nullable selectorRefs; uint16_t classDefsCount; uint16_t categoryDefsCount; void *_Nonnull defs[1]; }; struct _objc_module { unsigned long version; /* 9 = non-fragile */ unsigned long size; const char *_Nullable name; struct objc_symtab *_Nonnull symtab; }; struct objc_hashtable_bucket { const void *_Nonnull key, *_Nonnull object; uint32_t hash; }; struct objc_hashtable { objc_hashtable_hash_func hash; objc_hashtable_equal_func equal; uint32_t count, size; struct objc_hashtable_bucket *_Nonnull *_Nullable data; }; struct objc_sparsearray { struct objc_sparsearray_data { void *_Nullable next[256]; } *_Nonnull data; uint8_t levels; }; struct objc_dtable { struct objc_dtable_level2 { #ifdef OF_SELUID24 struct objc_dtable_level3 { IMP _Nullable buckets[256]; } *_Nonnull buckets[256]; #else IMP _Nullable buckets[256]; #endif } *_Nonnull buckets[256]; }; extern void objc_registerAllCategories(struct objc_symtab *_Nonnull) OF_VISIBILITY_HIDDEN; extern struct objc_category *_Nullable *_Nullable objc_categoriesForClass(Class _Nonnull) OF_VISIBILITY_HIDDEN; extern void objc_unregisterAllCategories(void) OF_VISIBILITY_HIDDEN; extern void objc_initializeClass(Class _Nonnull) OF_VISIBILITY_HIDDEN; extern void objc_updateDTable(Class _Nonnull) OF_VISIBILITY_HIDDEN; extern void objc_registerAllClasses(struct objc_symtab *_Nonnull) OF_VISIBILITY_HIDDEN; extern Class _Nullable objc_classnameToClass(const char *_Nonnull, bool) OF_VISIBILITY_HIDDEN; extern void objc_unregisterClass(Class _Nonnull) OF_VISIBILITY_HIDDEN; extern void objc_unregisterAllClasses(void) OF_VISIBILITY_HIDDEN; extern uint32_t objc_string_hash(const void *_Nonnull) OF_VISIBILITY_HIDDEN; extern bool objc_string_equal(const void *_Nonnull, const void *_Nonnull) OF_VISIBILITY_HIDDEN; extern struct objc_hashtable *_Nonnull objc_hashtable_new( objc_hashtable_hash_func, objc_hashtable_equal_func, uint32_t) OF_VISIBILITY_HIDDEN; extern struct objc_hashtable_bucket objc_deletedBucket OF_VISIBILITY_HIDDEN; extern void objc_hashtable_set(struct objc_hashtable *_Nonnull, const void *_Nonnull, const void *_Nonnull) OF_VISIBILITY_HIDDEN; extern void *_Nullable objc_hashtable_get(struct objc_hashtable *_Nonnull, const void *_Nonnull) OF_VISIBILITY_HIDDEN; extern void objc_hashtable_delete(struct objc_hashtable *_Nonnull, const void *_Nonnull) OF_VISIBILITY_HIDDEN; extern void objc_hashtable_free(struct objc_hashtable *_Nonnull) OF_VISIBILITY_HIDDEN; extern void objc_registerSelector(struct objc_selector *_Nonnull) OF_VISIBILITY_HIDDEN; extern void objc_registerAllSelectors(struct objc_symtab *_Nonnull) OF_VISIBILITY_HIDDEN; extern void objc_unregisterAllSelectors(void) OF_VISIBILITY_HIDDEN; extern struct objc_sparsearray *_Nonnull objc_sparsearray_new(uint8_t) OF_VISIBILITY_HIDDEN; extern void *_Nullable objc_sparsearray_get(struct objc_sparsearray *_Nonnull, uintptr_t) OF_VISIBILITY_HIDDEN; extern void objc_sparsearray_set(struct objc_sparsearray *_Nonnull, uintptr_t, void *_Nullable) OF_VISIBILITY_HIDDEN; extern void objc_sparsearray_free(struct objc_sparsearray *_Nonnull) OF_VISIBILITY_HIDDEN; extern struct objc_dtable *_Nonnull objc_dtable_new(void) OF_VISIBILITY_HIDDEN; extern void objc_dtable_copy(struct objc_dtable *_Nonnull, struct objc_dtable *_Nonnull) OF_VISIBILITY_HIDDEN; extern void objc_dtable_set(struct objc_dtable *_Nonnull, uint32_t, IMP _Nullable) OF_VISIBILITY_HIDDEN; extern void objc_dtable_free(struct objc_dtable *_Nonnull) OF_VISIBILITY_HIDDEN; extern void objc_dtable_cleanup(void) OF_VISIBILITY_HIDDEN; extern void objc_initStaticInstances(struct objc_symtab *_Nonnull) OF_VISIBILITY_HIDDEN; extern void objc_forgetPendingStaticInstances(void) OF_VISIBILITY_HIDDEN; extern void objc_zeroWeakReferences(id _Nonnull) OF_VISIBILITY_HIDDEN; extern Class _Nullable object_getTaggedPointerClass(id _Nonnull) OF_VISIBILITY_HIDDEN; #ifdef OF_HAVE_THREADS extern void objc_globalMutex_lock(void) OF_VISIBILITY_HIDDEN; extern void objc_globalMutex_unlock(void) OF_VISIBILITY_HIDDEN; extern void objc_globalMutex_free(void) OF_VISIBILITY_HIDDEN; #else # define objc_globalMutex_lock() # define objc_globalMutex_unlock() # define objc_globalMutex_free() #endif extern char *_Nullable objc_strdup(const char *_Nonnull string) OF_VISIBILITY_HIDDEN; static OF_INLINE IMP _Nullable objc_dtable_get(const struct objc_dtable *_Nonnull dtable, uint32_t idx) { #ifdef OF_SELUID24 uint8_t i = idx >> 16; uint8_t j = idx >> 8; uint8_t k = idx; return dtable->buckets[i]->buckets[j]->buckets[k]; #else uint8_t i = idx >> 8; uint8_t j = idx; return dtable->buckets[i]->buckets[j]; #endif } extern void OF_NO_RETURN_FUNC objc_error(const char *_Nonnull title, const char *_Nonnull format, ...) OF_VISIBILITY_HIDDEN; #define OBJC_ERROR(...) \ objc_error("ObjFWRT @ " __FILE__ ":" OF_STRINGIFY(__LINE__), \ __VA_ARGS__) #if defined(OF_ELF) # if defined(OF_AMD64) || defined(OF_X86) || \ defined(OF_POWERPC64) || defined(OF_POWERPC) || \ defined(OF_ARM64) || defined(OF_ARM) || \ defined(OF_MIPS64_N64) || defined(OF_MIPS) || \ defined(OF_SPARC64) || defined(OF_SPARC) # define OF_ASM_LOOKUP # endif #elif defined(OF_MACH_O) # if defined(OF_AMD64) # define OF_ASM_LOOKUP # endif #elif defined(OF_WINDOWS) # if defined(OF_AMD64) || defined(OF_X86) # define OF_ASM_LOOKUP # endif #endif @interface DummyObject { Class _Nonnull isa; } @property (readonly, nonatomic) bool allowsWeakReference; + (void)initialize; + (bool)resolveClassMethod: (nonnull SEL)selector; + (bool)resolveInstanceMethod: (nonnull SEL)selector; - (nonnull id)retain; - (void)release; - (nonnull id)autorelease; - (nonnull id)copy; - (nonnull id)mutableCopy; - (bool)retainWeakReference; @end objfw-1.1.6/src/runtime/property.m000066400000000000000000000136311465614216400171570ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "ObjFWRT.h" #import "private.h" #ifdef OF_HAVE_THREADS # import "OFPlainMutex.h" # define numSpinlocks 8 /* needs to be a power of 2 */ static OFSpinlock spinlocks[numSpinlocks]; static OF_INLINE size_t spinlockSlot(const void *ptr) { return ((size_t)((uintptr_t)ptr >> 4) & (numSpinlocks - 1)); } OF_CONSTRUCTOR() { for (size_t i = 0; i < numSpinlocks; i++) if (OFSpinlockNew(&spinlocks[i]) != 0) OBJC_ERROR("Failed to create spinlocks!"); } #endif id objc_getProperty(id self, SEL _cmd, ptrdiff_t offset, bool atomic) { if (atomic) { id *ptr = (id *)(void *)((char *)self + offset); #ifdef OF_HAVE_THREADS size_t slot = spinlockSlot(ptr); if (OFSpinlockLock(&spinlocks[slot]) != 0) OBJC_ERROR("Failed to lock spinlock!"); @try { return [[*ptr retain] autorelease]; } @finally { if (OFSpinlockUnlock(&spinlocks[slot]) != 0) OBJC_ERROR("Failed to unlock spinlock!"); } #else return [[*ptr retain] autorelease]; #endif } return *(id *)(void *)((char *)self + offset); } void objc_setProperty(id self, SEL _cmd, ptrdiff_t offset, id value, bool atomic, signed char copy) { if (atomic) { id *ptr = (id *)(void *)((char *)self + offset); #ifdef OF_HAVE_THREADS size_t slot = spinlockSlot(ptr); if (OFSpinlockLock(&spinlocks[slot]) != 0) OBJC_ERROR("Failed to lock spinlock!"); @try { #endif id old = *ptr; switch (copy) { case 0: *ptr = [value retain]; break; case 2: *ptr = [value mutableCopy]; break; default: *ptr = [value copy]; } [old release]; #ifdef OF_HAVE_THREADS } @finally { if (OFSpinlockUnlock(&spinlocks[slot]) != 0) OBJC_ERROR("Failed to unlock spinlock!"); } #endif return; } id *ptr = (id *)(void *)((char *)self + offset); id old = *ptr; switch (copy) { case 0: *ptr = [value retain]; break; case 2: *ptr = [value mutableCopy]; break; default: *ptr = [value copy]; } [old release]; } /* The following methods are only required for GCC >= 4.6 */ void objc_getPropertyStruct(void *dest, const void *src, ptrdiff_t size, bool atomic, bool strong) { if (atomic) { #ifdef OF_HAVE_THREADS size_t slot = spinlockSlot(src); if (OFSpinlockLock(&spinlocks[slot]) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif memcpy(dest, src, size); #ifdef OF_HAVE_THREADS if (OFSpinlockUnlock(&spinlocks[slot]) != 0) OBJC_ERROR("Failed to unlock spinlock!"); #endif return; } memcpy(dest, src, size); } void objc_setPropertyStruct(void *dest, const void *src, ptrdiff_t size, bool atomic, bool strong) { if (atomic) { #ifdef OF_HAVE_THREADS size_t slot = spinlockSlot(src); if (OFSpinlockLock(&spinlocks[slot]) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif memcpy(dest, src, size); #ifdef OF_HAVE_THREADS if (OFSpinlockUnlock(&spinlocks[slot]) != 0) OBJC_ERROR("Failed to unlock spinlock!"); #endif return; } memcpy(dest, src, size); } objc_property_t * class_copyPropertyList(Class class, unsigned int *outCount) { unsigned int i, count; struct objc_property_list *iter; objc_property_t *properties; if (class == Nil) { if (outCount != NULL) *outCount = 0; return NULL; } objc_globalMutex_lock(); count = 0; if (class->info & OBJC_CLASS_INFO_NEW_ABI) for (iter = class->propertyList; iter != NULL; iter = iter->next) count += iter->count; if (count == 0) { if (outCount != NULL) *outCount = 0; objc_globalMutex_unlock(); return NULL; } properties = malloc((count + 1) * sizeof(objc_property_t)); if (properties == NULL) OBJC_ERROR("Not enough memory to copy properties"); i = 0; for (iter = class->propertyList; iter != NULL; iter = iter->next) for (unsigned int j = 0; j < iter->count; j++) properties[i++] = &iter->properties[j]; if (i != count) OBJC_ERROR("Fatal internal inconsistency!"); properties[count] = NULL; if (outCount != NULL) *outCount = count; objc_globalMutex_unlock(); return properties; } const char * property_getName(objc_property_t property) { return property->name; } char * property_copyAttributeValue(objc_property_t property, const char *name) { char *ret = NULL; bool nullIsError = false; if (strlen(name) != 1) return NULL; switch (*name) { case 'T': ret = objc_strdup(property->getter.typeEncoding); nullIsError = true; break; case 'G': if (property->attributes & OBJC_PROPERTY_GETTER) { ret = objc_strdup(property->getter.name); nullIsError = true; } break; case 'S': if (property->attributes & OBJC_PROPERTY_SETTER) { ret = objc_strdup(property->setter.name); nullIsError = true; } break; #define BOOL_CASE(name, field, flag) \ case name: \ if (property->field & flag) { \ ret = calloc(1, 1); \ nullIsError = true; \ } \ break; BOOL_CASE('R', attributes, OBJC_PROPERTY_READONLY) BOOL_CASE('C', attributes, OBJC_PROPERTY_COPY) BOOL_CASE('&', attributes, OBJC_PROPERTY_RETAIN) BOOL_CASE('N', attributes, OBJC_PROPERTY_NONATOMIC) BOOL_CASE('D', extendedAttributes, OBJC_PROPERTY_DYNAMIC) BOOL_CASE('W', extendedAttributes, OBJC_PROPERTY_WEAK) #undef BOOL_CASE } if (nullIsError && ret == NULL) OBJC_ERROR("Not enough memory to copy property attribute " "value!"); return ret; } objfw-1.1.6/src/runtime/protocol.m000066400000000000000000000047101465614216400171320ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "ObjFWRT.h" #import "private.h" @implementation Protocol @end const char * protocol_getName(Protocol *protocol) { return protocol->name; } bool protocol_isEqual(Protocol *protocol1, Protocol *protocol2) { return (strcmp(protocol_getName(protocol1), protocol_getName(protocol2)) == 0); } bool protocol_conformsToProtocol(Protocol *protocol1, Protocol *protocol2) { if (protocol_isEqual(protocol1, protocol2)) return true; for (struct objc_protocol_list *protocolList = protocol1->protocolList; protocolList != NULL; protocolList = protocolList->next) for (long i = 0; i < protocolList->count; i++) if (protocol_conformsToProtocol(protocolList->list[i], protocol2)) return true; return false; } bool class_conformsToProtocol(Class class, Protocol *protocol) { struct objc_category **categories; if (class == Nil) return false; for (struct objc_protocol_list *protocolList = class->protocols; protocolList != NULL; protocolList = protocolList->next) for (long i = 0; i < protocolList->count; i++) if (protocol_conformsToProtocol(protocolList->list[i], protocol)) return true; objc_globalMutex_lock(); if ((categories = objc_categoriesForClass(class)) == NULL) { objc_globalMutex_unlock(); return false; } for (long i = 0; categories[i] != NULL; i++) { for (struct objc_protocol_list *protocolList = categories[i]->protocols; protocolList != NULL; protocolList = protocolList->next) { for (long j = 0; j < protocolList->count; j++) { if (protocol_conformsToProtocol( protocolList->list[j], protocol)) { objc_globalMutex_unlock(); return true; } } } } objc_globalMutex_unlock(); return false; } objfw-1.1.6/src/runtime/selector.m000066400000000000000000000071001465614216400171050ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #include #import "ObjFWRT.h" #import "private.h" #import "macros.h" #ifdef OF_SELUID24 static const uint32_t maxSel = 0xFFFFFF; static const uint8_t selLevels = 3; #else static const uint32_t maxSel = 0xFFFF; static const uint8_t selLevels = 2; #endif static struct objc_hashtable *selectors = NULL; static uint32_t selectorsCount = 0; static struct objc_sparsearray *selectorNames = NULL; static void **freeList = NULL; static size_t freeListCount = 0; void objc_registerSelector(struct objc_selector *selector) { SEL existingSelector; const char *name; if (selectorsCount > maxSel) OBJC_ERROR("Out of selector slots!"); if (selectors == NULL) selectors = objc_hashtable_new( objc_string_hash, objc_string_equal, 2); else if ((existingSelector = objc_hashtable_get(selectors, (const char *)selector->UID)) != NULL) { selector->UID = existingSelector->UID; return; } if (selectorNames == NULL) selectorNames = objc_sparsearray_new(selLevels); name = (const char *)selector->UID; selector->UID = selectorsCount++; objc_hashtable_set(selectors, name, selector); objc_sparsearray_set(selectorNames, (uint32_t)selector->UID, (void *)name); } SEL sel_registerName(const char *name) { struct objc_selector *selector; objc_globalMutex_lock(); if (selectors != NULL && (selector = objc_hashtable_get(selectors, name)) != NULL) { objc_globalMutex_unlock(); return (SEL)selector; } if ((selector = malloc(sizeof(*selector))) == NULL || (selector->UID = (uintptr_t)objc_strdup(name)) == 0) OBJC_ERROR("Not enough memory to allocate selector!"); selector->typeEncoding = NULL; if ((freeList = realloc(freeList, sizeof(void *) * (freeListCount + 2))) == NULL) OBJC_ERROR("Not enough memory to allocate selector!"); freeList[freeListCount++] = selector; freeList[freeListCount++] = (char *)selector->UID; objc_registerSelector(selector); objc_globalMutex_unlock(); return (SEL)selector; } void objc_registerAllSelectors(struct objc_symtab *symtab) { struct objc_selector *selector; if (symtab->selectorRefs == NULL) return; for (selector = symtab->selectorRefs; selector->UID != 0; selector++) objc_registerSelector(selector); } const char * sel_getName(SEL selector) { const char *ret; objc_globalMutex_lock(); ret = objc_sparsearray_get(selectorNames, (uint32_t)selector->UID); objc_globalMutex_unlock(); return ret; } bool sel_isEqual(SEL selector1, SEL selector2) { return (selector1->UID == selector2->UID); } void objc_unregisterAllSelectors(void) { objc_hashtable_free(selectors); objc_sparsearray_free(selectorNames); if (freeList != NULL) { for (size_t i = 0; i < freeListCount; i++) free(freeList[i]); free(freeList); } selectors = NULL; selectorsCount = 0; selectorNames = NULL; freeList = NULL; freeListCount = 0; } objfw-1.1.6/src/runtime/sparsearray.m000066400000000000000000000046771465614216400176410ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "ObjFWRT.h" #import "private.h" struct objc_sparsearray * objc_sparsearray_new(uint8_t levels) { struct objc_sparsearray *sparsearray; if ((sparsearray = calloc(1, sizeof(*sparsearray))) == NULL || (sparsearray->data = calloc(1, sizeof(*sparsearray->data))) == NULL) OBJC_ERROR("Failed to allocate memory for sparse array!"); sparsearray->levels = levels; return sparsearray; } void * objc_sparsearray_get(struct objc_sparsearray *sparsearray, uintptr_t idx) { struct objc_sparsearray_data *iter = sparsearray->data; for (uint8_t i = 0; i < sparsearray->levels - 1; i++) { uintptr_t j = (idx >> ((sparsearray->levels - i - 1) * 8)) & 0xFF; if ((iter = iter->next[j]) == NULL) return NULL; } return iter->next[idx & 0xFF]; } void objc_sparsearray_set(struct objc_sparsearray *sparsearray, uintptr_t idx, void *value) { struct objc_sparsearray_data *iter = sparsearray->data; for (uint8_t i = 0; i < sparsearray->levels - 1; i++) { uintptr_t j = (idx >> ((sparsearray->levels - i - 1) * 8)) & 0xFF; if (iter->next[j] == NULL) if ((iter->next[j] = calloc(1, sizeof(struct objc_sparsearray_data))) == NULL) OBJC_ERROR("Failed to allocate memory for " "sparse array!"); iter = iter->next[j]; } iter->next[idx & 0xFF] = value; } static void freeSparsearrayData(struct objc_sparsearray_data *data, uint8_t depth) { if (data == NULL || depth == 0) return; for (uint_fast16_t i = 0; i < 256; i++) freeSparsearrayData(data->next[i], depth - 1); free(data); } void objc_sparsearray_free(struct objc_sparsearray *sparsearray) { freeSparsearrayData(sparsearray->data, sparsearray->levels); free(sparsearray); } objfw-1.1.6/src/runtime/static-instances.m000066400000000000000000000055541465614216400205540ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "ObjFWRT.h" #import "private.h" static struct objc_static_instances **staticInstancesList = NULL; static size_t staticInstancesCount = 0; void objc_initStaticInstances(struct objc_symtab *symtab) { struct objc_static_instances **staticInstances; /* Check if the class for a static instance became available */ for (size_t i = 0; i < staticInstancesCount; i++) { Class class = objc_lookUpClass( staticInstancesList[i]->className); if (class != Nil) { for (id *instances = staticInstancesList[i]->instances; *instances != nil; instances++) object_setClass(*instances, class); staticInstancesCount--; if (staticInstancesCount == 0) { free(staticInstancesList); staticInstancesList = NULL; break; } staticInstancesList[i] = staticInstancesList[staticInstancesCount]; staticInstancesList = realloc(staticInstancesList, sizeof(*staticInstancesList) * staticInstancesCount); if (staticInstancesList == NULL) OBJC_ERROR("Not enough memory for list of " "static instances!"); /* * We moved the last entry to the current index, * therefore we need to run again for the current index. */ i--; } } staticInstances = (struct objc_static_instances **) symtab->defs[symtab->classDefsCount + symtab->categoryDefsCount]; if (staticInstances == NULL) return; for (; *staticInstances != NULL; staticInstances++) { Class class = objc_lookUpClass((*staticInstances)->className); if (class != Nil) { for (id *instances = (*staticInstances)->instances; *instances != nil; instances++) object_setClass(*instances, class); } else { staticInstancesList = realloc(staticInstancesList, sizeof(*staticInstancesList) * (staticInstancesCount + 1)); if (staticInstancesList == NULL) OBJC_ERROR("Not enough memory for list of " "static instances!"); staticInstancesList[staticInstancesCount++] = *staticInstances; } } } void objc_forgetPendingStaticInstances(void) { free(staticInstancesList); staticInstancesList = NULL; staticInstancesCount = 0; } objfw-1.1.6/src/runtime/synchronized.m000066400000000000000000000057011465614216400200110ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "ObjFWRT.h" #import "private.h" #ifdef OF_HAVE_THREADS # import "OFPlainMutex.h" static struct Lock { id object; int count; OFPlainRecursiveMutex rmutex; struct Lock *next; } *locks = NULL; static OFPlainMutex mutex; OF_CONSTRUCTOR() { if (OFPlainMutexNew(&mutex) != 0) OBJC_ERROR("Failed to create mutex!"); } #endif int objc_sync_enter(id object) { if (object == nil) return 0; #ifdef OF_HAVE_THREADS struct Lock *lock; if (OFPlainMutexLock(&mutex) != 0) OBJC_ERROR("Failed to lock mutex!"); /* Look if we already have a lock */ for (lock = locks; lock != NULL; lock = lock->next) { if (lock->object != object) continue; lock->count++; if (OFPlainMutexUnlock(&mutex) != 0) OBJC_ERROR("Failed to unlock mutex!"); if (OFPlainRecursiveMutexLock(&lock->rmutex) != 0) OBJC_ERROR("Failed to lock mutex!"); return 0; } /* Create a new lock */ if ((lock = malloc(sizeof(*lock))) == NULL) OBJC_ERROR("Failed to allocate memory for mutex!"); if (OFPlainRecursiveMutexNew(&lock->rmutex) != 0) OBJC_ERROR("Failed to create mutex!"); lock->object = object; lock->count = 1; lock->next = locks; locks = lock; if (OFPlainMutexUnlock(&mutex) != 0) OBJC_ERROR("Failed to unlock mutex!"); if (OFPlainRecursiveMutexLock(&lock->rmutex) != 0) OBJC_ERROR("Failed to lock mutex!"); #endif return 0; } int objc_sync_exit(id object) { if (object == nil) return 0; #ifdef OF_HAVE_THREADS struct Lock *lock, *last = NULL; if (OFPlainMutexLock(&mutex) != 0) OBJC_ERROR("Failed to lock mutex!"); for (lock = locks; lock != NULL; lock = lock->next) { if (lock->object != object) { last = lock; continue; } if (OFPlainRecursiveMutexUnlock(&lock->rmutex) != 0) OBJC_ERROR("Failed to unlock mutex!"); if (--lock->count == 0) { if (OFPlainRecursiveMutexFree(&lock->rmutex) != 0) OBJC_ERROR("Failed to destroy mutex!"); if (last != NULL) last->next = lock->next; if (locks == lock) locks = lock->next; free(lock); } if (OFPlainMutexUnlock(&mutex) != 0) OBJC_ERROR("Failed to unlock mutex!"); return 0; } OBJC_ERROR("objc_sync_exit() was called for an unlocked object!"); #else return 0; #endif } objfw-1.1.6/src/runtime/tagged-pointer.m000066400000000000000000000044461465614216400202100ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "ObjFWRT.h" #import "private.h" #define numTaggedPointerBits 4 #define maxNumTaggedPointerClasses (1 << (numTaggedPointerBits - 1)) Class objc_taggedPointerClasses[maxNumTaggedPointerClasses]; static int taggedPointerClassesCount; uintptr_t objc_taggedPointerSecret; void objc_setTaggedPointerSecret(uintptr_t secret) { objc_taggedPointerSecret = secret & ~(uintptr_t)1; } int objc_registerTaggedPointerClass(Class class) { int i; objc_globalMutex_lock(); if (taggedPointerClassesCount == maxNumTaggedPointerClasses) { objc_globalMutex_unlock(); return -1; } i = taggedPointerClassesCount++; objc_taggedPointerClasses[i] = class; objc_globalMutex_unlock(); return i; } bool object_isTaggedPointer(id object) { uintptr_t pointer = (uintptr_t)object; return pointer & 1; } Class object_getTaggedPointerClass(id object) { uintptr_t pointer = (uintptr_t)object ^ objc_taggedPointerSecret; pointer &= (1 << numTaggedPointerBits) - 1; pointer >>= 1; if (pointer >= maxNumTaggedPointerClasses) return Nil; return objc_taggedPointerClasses[pointer]; } uintptr_t object_getTaggedPointerValue(id object) { uintptr_t pointer = (uintptr_t)object ^ objc_taggedPointerSecret; pointer >>= numTaggedPointerBits; return pointer; } id objc_createTaggedPointer(int class, uintptr_t value) { uintptr_t pointer; if (class < 0 || class >= maxNumTaggedPointerClasses) return nil; if (value > (UINTPTR_MAX >> numTaggedPointerBits)) return nil; pointer = (class << 1) | 1; pointer |= (value << numTaggedPointerBits); return (id)(pointer ^ objc_taggedPointerSecret); } objfw-1.1.6/src/runtime/threading.m000066400000000000000000000026051465614216400172370ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "ObjFWRT.h" #import "private.h" #import "OFOnce.h" #import "OFPlainMutex.h" static OFPlainRecursiveMutex globalMutex; static void init(void) { if (OFPlainRecursiveMutexNew(&globalMutex) != 0) OBJC_ERROR("Failed to create global mutex!"); } void objc_globalMutex_lock(void) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, init); if (OFPlainRecursiveMutexLock(&globalMutex) != 0) OBJC_ERROR("Failed to lock global mutex!"); } void objc_globalMutex_unlock(void) { if (OFPlainRecursiveMutexUnlock(&globalMutex) != 0) OBJC_ERROR("Failed to unlock global mutex!"); } objfw-1.1.6/src/runtime/versioninfo.rc000066400000000000000000000012451465614216400200020ustar00rootroot00000000000000#include "config.h" #include "winver.h" 1 VERSIONINFO FILEVERSION OBJFWRT_LIB_MAJOR, OBJFWRT_LIB_MINOR, 0, 0 PRODUCTVERSION OBJFW_VERSION_MAJOR, OBJFW_VERSION_MINOR, 0, 0 FILEOS VOS__WINDOWS32 FILETYPE VFT_DLL { BLOCK "StringFileInfo" { BLOCK "040904E4" { VALUE "ProductName", "ObjFW Runtime" VALUE "ProductVersion", PACKAGE_VERSION VALUE "FileVersion", OBJFWRT_LIB_VERSION VALUE "FileDescription", "Objective-C runtime" VALUE "LegalCopyright", "(c) 2008-2024 Jonathan Schleifer" VALUE "InternalName", "ObjFWRT" VALUE "OriginalFilename", OBJFWRT_SHARED_LIB } } BLOCK "VarFileInfo" { VALUE "Translation", 0x409, 1252 } } objfw-1.1.6/src/test/000077500000000000000000000000001465614216400144055ustar00rootroot00000000000000objfw-1.1.6/src/test/Makefile000066400000000000000000000022141465614216400160440ustar00rootroot00000000000000include ../../extra.mk DISTCLEAN = Info.plist STATIC_LIB = libobjfwtest.a SRCS = OTAssert.m \ OTOrderedDictionary.m \ OTTestCase.m INCLUDES := ${SRCS:.m=.h} \ ObjFWTest.h SRCS += OTAppDelegate.m \ OTAssertionFailedException.m \ OTTestSkippedException.m includesubdir = ObjFWTest include ../../buildsys.mk CPPFLAGS += -I. \ -I.. \ -I../.. \ -I../exceptions \ -I../runtime \ -DOBJFWTEST_LOCAL_INCLUDES LD = ${OBJC} FRAMEWORK_LIBS := -F.. \ -framework ObjFW \ -F../runtime \ ${RUNTIME_FRAMEWORK_LIBS} \ ${LIBS} LIBS := -L.. -lobjfw -L../runtime ${RUNTIME_LIBS} ${LIBS} install-extra: i=ObjFWTest.oc; \ ${INSTALL_STATUS}; \ if ${MKDIR_P} ${DESTDIR}${libdir}/objfw-config && \ ${INSTALL} -m 644 $$i ${DESTDIR}${libdir}/objfw-config/$$i; then \ ${INSTALL_OK}; \ else \ ${INSTALL_FAILED}; \ fi uninstall-extra: i=ObjFWTest.oc; \ if test -f ${DESTDIR}${libdir}/objfw-config/$$i; then \ if rm -f ${DESTDIR}${libdir}/objfw-config/$$i; then \ ${DELETE_OK}; \ else \ ${DELETE_FAILED}; \ fi \ fi rmdir ${DESTDIR}${libdir}/objfw-config >/dev/null 2>&1 || true objfw-1.1.6/src/test/OTAppDelegate.m000066400000000000000000000401661465614216400172100ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFApplication.h" #import "OFColor.h" #import "OFDictionary.h" #import "OFMethodSignature.h" #import "OFSet.h" #import "OFStdIOStream.h" #import "OFValue.h" #import "OTTestCase.h" #import "OTAssertionFailedException.h" #import "OTTestSkippedException.h" #ifdef OF_IOS # include #endif #ifdef OF_WII # define asm __asm__ # include # include # undef asm #endif #ifdef OF_NINTENDO_DS # define asm __asm__ # include # undef asm #endif #ifdef OF_NINTENDO_3DS /* Newer versions of libctru started using id as a parameter name. */ # define id id_3ds # include <3ds.h> # undef id #endif #ifdef OF_NINTENDO_SWITCH # define id nx_id # include # undef id static OFDate *lastConsoleUpdate; static void updateConsole(bool force) { if (force || lastConsoleUpdate.timeIntervalSinceNow <= -1.0 / 60) { consoleUpdate(NULL); [lastConsoleUpdate release]; lastConsoleUpdate = [[OFDate alloc] init]; } } #endif @interface OTAppDelegate: OFObject @end enum Status { StatusRunning, StatusOk, StatusFailed, StatusSkipped }; OF_APPLICATION_DELEGATE(OTAppDelegate) static bool isSubclassOfClass(Class class, Class superclass) { for (Class iter = class; iter != Nil; iter = class_getSuperclass(iter)) if (iter == superclass) return true; return false; } @implementation OTAppDelegate + (void)initialize { if (self != [OTAppDelegate class]) return; #if defined(OF_IOS) CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); UInt8 resourcesPath[PATH_MAX]; if (!CFURLGetFileSystemRepresentation(resourcesURL, true, resourcesPath, PATH_MAX)) { [OFStdErr writeLine: @"Failed to locate resources!"]; [OFApplication terminateWithStatus: 1]; } [[OFFileManager defaultManager] changeCurrentDirectoryPath: [OFString stringWithUTF8String: (const char *)resourcesPath]]; CFRelease(resourcesURL); #elif defined(OF_WII) GXRModeObj *mode; void *nextFB; VIDEO_Init(); WPAD_Init(); mode = VIDEO_GetPreferredMode(NULL); nextFB = MEM_K0_TO_K1(SYS_AllocateFramebuffer(mode)); VIDEO_Configure(mode); VIDEO_SetNextFramebuffer(nextFB); VIDEO_SetBlack(FALSE); VIDEO_Flush(); VIDEO_WaitVSync(); if (mode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync(); CON_InitEx(mode, 2, 2, mode->fbWidth - 4, mode->xfbHeight - 4); VIDEO_ClearFrameBuffer(mode, nextFB, COLOR_BLACK); #elif defined(OF_NINTENDO_DS) consoleDemoInit(); #elif defined(OF_NINTENDO_3DS) gfxInitDefault(); atexit(gfxExit); consoleInit(GFX_TOP, NULL); #elif defined(OF_NINTENDO_SWITCH) consoleInit(NULL); padConfigureInput(1, HidNpadStyleSet_NpadStandard); updateConsole(true); #endif } - (OFMutableSet OF_GENERIC(Class) *)testClasses { Class *classes; int classesCount; OFMutableSet *testClasses; classesCount = objc_getClassList(NULL, 0); if (classesCount < 1) return nil; classes = OFAllocMemory(classesCount, sizeof(Class)); @try { if ((int)objc_getClassList(classes, classesCount) != classesCount) return nil; testClasses = [OFMutableSet set]; for (int i = 0; i < classesCount; i++) { /* * Make sure the class is initialized. * Required for the ObjFW runtime, as otherwise * class_getSuperclass() crashes. */ #ifdef OF_OBJFW_RUNTIME [classes[i] class]; #endif /* * Don't use +[isSubclassOfClass:], as the Apple runtime * can return (presumably internal?) classes that don't * implement it, resulting in a crash. */ if (isSubclassOfClass(classes[i], [OTTestCase class])) [testClasses addObject: classes[i]]; } } @finally { OFFreeMemory(classes); } [testClasses removeObject: [OTTestCase class]]; return testClasses; } - (OFSet OF_GENERIC(OFValue *) *)testsInClass: (Class)class { Method *methods = class_copyMethodList(class, NULL); OFMutableSet *tests; if (methods == NULL) return nil; @try { tests = [OFMutableSet set]; for (Method *iter = methods; *iter != NULL; iter++) { SEL selector = method_getName(*iter); void *pool; OFMethodSignature *sig; if (selector == NULL) continue; if (strncmp(sel_getName(selector), "test", 4) != 0) continue; pool = objc_autoreleasePoolPush(); sig = [OFMethodSignature signatureWithObjCTypes: method_getTypeEncoding(*iter)]; if (strcmp(sig.methodReturnType, "v") == 0 && sig.numberOfArguments == 2 && strcmp([sig argumentTypeAtIndex: 0], "@") == 0 && strcmp([sig argumentTypeAtIndex: 1], ":") == 0) [tests addObject: [OFValue valueWithPointer: selector]]; objc_autoreleasePoolPop(pool); } } @finally { OFFreeMemory(methods); } if (class_getSuperclass(class) != Nil) [tests unionSet: [self testsInClass: class_getSuperclass(class)]]; [tests makeImmutable]; return tests; } - (void)printStatusForTest: (SEL)test inClass: (Class)class status: (enum Status)status description: (OFString *)description { switch (status) { case StatusRunning: if (OFStdOut.hasTerminal) { [OFStdOut setForegroundColor: [OFColor olive]]; [OFStdOut writeFormat: @"-[%@ ", class]; [OFStdOut setForegroundColor: [OFColor yellow]]; [OFStdOut writeFormat: @"%s", sel_getName(test)]; [OFStdOut setForegroundColor: [OFColor olive]]; [OFStdOut writeString: @"]: "]; } else [OFStdOut writeFormat: @"-[%@ %s]: ", class, sel_getName(test)]; break; case StatusOk: if (OFStdOut.hasTerminal) { [OFStdOut setCursorColumn: 0]; [OFStdOut eraseLine]; [OFStdOut setForegroundColor: [OFColor green]]; [OFStdOut writeFormat: @"-[%@ ", class]; [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeFormat: @"%s", sel_getName(test)]; [OFStdOut setForegroundColor: [OFColor green]]; [OFStdOut writeLine: @"]: ok"]; } else [OFStdOut writeLine: @"ok"]; break; case StatusFailed: if (OFStdOut.hasTerminal) { [OFStdOut setCursorColumn: 0]; [OFStdOut eraseLine]; [OFStdOut setForegroundColor: [OFColor maroon]]; [OFStdOut writeFormat: @"-[%@ ", class]; [OFStdOut setForegroundColor: [OFColor red]]; [OFStdOut writeFormat: @"%s", sel_getName(test)]; [OFStdOut setForegroundColor: [OFColor maroon]]; [OFStdOut writeLine: @"]: failed"]; } else [OFStdOut writeLine: @"failed"]; if (description != nil) [OFStdOut writeLine: description]; break; case StatusSkipped: if (OFStdOut.hasTerminal) { [OFStdOut setCursorColumn: 0]; [OFStdOut eraseLine]; [OFStdOut setForegroundColor: [OFColor gray]]; [OFStdOut writeFormat: @"-[%@ ", class]; [OFStdOut setForegroundColor: [OFColor silver]]; [OFStdOut writeFormat: @"%s", sel_getName(test)]; [OFStdOut setForegroundColor: [OFColor gray]]; [OFStdOut writeLine: @"]: skipped"]; } else [OFStdOut writeLine: @"skipped"]; if (description != nil) [OFStdOut writeLine: description]; break; } if (status == StatusFailed) { #if defined(OF_WII) [OFStdOut setForegroundColor: [OFColor silver]]; [OFStdOut writeLine: @"Press A to continue"]; for (;;) { WPAD_ScanPads(); if (WPAD_ButtonsDown(0) & WPAD_BUTTON_A) break; VIDEO_WaitVSync(); } #elif defined(OF_NINTENDO_DS) [OFStdOut setForegroundColor: [OFColor silver]]; [OFStdOut writeLine: @"Press A to continue"]; for (;;) { swiWaitForVBlank(); scanKeys(); if (keysDown() & KEY_A) break; } #elif defined(OF_NINTENDO_3DS) [OFStdOut setForegroundColor: [OFColor silver]]; [OFStdOut writeLine: @"Press A to continue"]; for (;;) { hidScanInput(); if (hidKeysDown() & KEY_A) break; gspWaitForVBlank(); } #elif defined(OF_NINTENDO_SWITCH) [OFStdOut setForegroundColor: [OFColor silver]]; [OFStdOut writeLine: @"Press A to continue"]; while (appletMainLoop()) { PadState pad; padUpdate(&pad); updateConsole(true); if (padGetButtonsDown(&pad) & HidNpadButton_A) break; } #endif } } - (OFString *)descriptionForException: (id)exception { OFMutableString *description = [OFMutableString stringWithFormat: @"Unhandled exception: %@", exception]; OFArray OF_GENERIC(OFValue *) *stackTraceAddresses = nil; OFArray OF_GENERIC(OFString *) *stackTraceSymbols = nil; OFStringEncoding encoding = [OFLocale encoding]; if ([exception respondsToSelector: @selector(stackTraceAddresses)]) stackTraceAddresses = [exception stackTraceAddresses]; if (stackTraceAddresses != nil) { size_t count = stackTraceAddresses.count; if ([exception respondsToSelector: @selector(stackTraceSymbols)]) stackTraceSymbols = [exception stackTraceSymbols]; if (stackTraceSymbols.count != count) stackTraceSymbols = nil; [description appendString: @"\n\nStack trace:"]; if (stackTraceSymbols != nil) { for (size_t i = 0; i < count; i++) { void *address = [[stackTraceAddresses objectAtIndex: i] pointerValue]; const char *symbol = [[stackTraceSymbols objectAtIndex: i] cStringWithEncoding: encoding]; [description appendFormat: @"\n %p %s", address, symbol]; } } else { for (size_t i = 0; i < count; i++) { void *address = [[stackTraceAddresses objectAtIndex: i] pointerValue]; [description appendFormat: @"\n %p", address]; } } } [description makeImmutable]; return description; } - (void)applicationDidFinishLaunching: (OFNotification *)notification { OFMutableSet OF_GENERIC(Class) *testClasses; size_t numSucceeded = 0, numFailed = 0, numSkipped = 0; OFMutableDictionary *summaries = [OFMutableDictionary dictionary]; if ([OFApplication arguments].count > 0) { testClasses = [OFMutableSet set]; for (OFString *className in [OFApplication arguments]) { Class class = objc_lookUpClass([className cStringWithEncoding: OFStringEncodingASCII]); if (class == Nil || !isSubclassOfClass(class, [OTTestCase class])) { [OFStdErr writeFormat: @"%@ is not a valid " @"test case!\n", className]; [OFApplication terminateWithStatus: 1]; } [testClasses addObject: class]; } } else testClasses = [self testClasses]; [OFStdOut setForegroundColor: [OFColor purple]]; [OFStdOut writeString: @"Running "]; #if !defined(OF_WII) && !defined(OF_NINTENDO_DS) && \ !defined(OF_NINTENDO_3DS) && !defined(OF_NINTENDO_SWITCH) [OFStdOut setForegroundColor: [OFColor fuchsia]]; #endif [OFStdOut writeFormat: @"%zu", testClasses.count]; [OFStdOut setForegroundColor: [OFColor purple]]; [OFStdOut writeFormat: @" test case%s\n", (testClasses.count != 1 ? "s" : "")]; for (Class class in testClasses) { OFArray *summary; [OFStdOut setForegroundColor: [OFColor teal]]; [OFStdOut writeFormat: @"Running ", class]; [OFStdOut setForegroundColor: [OFColor aqua]]; [OFStdOut writeFormat: @"%@\n", class]; for (OFValue *test in [self testsInClass: class]) { void *pool = objc_autoreleasePoolPush(); bool failed = false, skipped = false; OTTestCase *instance; [self printStatusForTest: test.pointerValue inClass: class status: StatusRunning description: nil]; instance = [[[class alloc] init] autorelease]; @try { [instance setUp]; [instance performSelector: test.pointerValue]; } @catch (OTAssertionFailedException *e) { /* * If an assertion fails during -[setUp], don't * run the test. * If an assertion fails during a test, abort * the test. */ [self printStatusForTest: test.pointerValue inClass: class status: StatusFailed description: e.description]; failed = true; } @catch (OTTestSkippedException *e) { [self printStatusForTest: test.pointerValue inClass: class status: StatusSkipped description: e.description]; skipped = true; } @catch (id e) { OFString *description = [self descriptionForException: e]; [self printStatusForTest: test.pointerValue inClass: class status: StatusFailed description: description]; failed = true; } @try { [instance tearDown]; } @catch (OTAssertionFailedException *e) { /* * If an assertion fails during -[tearDown], * abort the tear down. */ if (!failed) { SEL selector = test.pointerValue; OFString *description = e.description; [self printStatusForTest: selector inClass: class status: StatusFailed description: description]; failed = true; } } @catch (id e) { OFString *description = [self descriptionForException: e]; [self printStatusForTest: test.pointerValue inClass: class status: StatusFailed description: description]; failed = true; } if (failed) numFailed++; else if (skipped) numSkipped++; else { [self printStatusForTest: test.pointerValue inClass: class status: StatusOk description: nil]; numSucceeded++; } objc_autoreleasePoolPop(pool); } summary = [class summary]; if (summary != nil) [summaries setObject: summary forKey: class]; } for (Class class in summaries) { OFArray *summary = [summaries objectForKey: class]; [OFStdOut setForegroundColor: [OFColor teal]]; [OFStdOut writeString: @"Summary for "]; [OFStdOut setForegroundColor: [OFColor aqua]]; [OFStdOut writeFormat: @"%@\n", class]; for (OFPair *line in summary) { [OFStdOut setForegroundColor: [OFColor navy]]; [OFStdOut writeFormat: @"%@: ", line.firstObject]; [OFStdOut setForegroundColor: [OFColor blue]]; [OFStdOut writeFormat: @"%@\n", line.secondObject]; } } #if !defined(OF_WII) && !defined(OF_NINTENDO_DS) && \ !defined(OF_NINTENDO_3DS) && !defined(OF_NINTENDO_SWITCH) [OFStdOut setForegroundColor: [OFColor fuchsia]]; #else [OFStdOut setForegroundColor: [OFColor purple]]; #endif [OFStdOut writeFormat: @"%zu", numSucceeded]; [OFStdOut setForegroundColor: [OFColor purple]]; [OFStdOut writeFormat: @" test%s succeeded, ", (numSucceeded != 1 ? "s" : "")]; #if !defined(OF_WII) && !defined(OF_NINTENDO_DS) && \ !defined(OF_NINTENDO_3DS) && !defined(OF_NINTENDO_SWITCH) [OFStdOut setForegroundColor: [OFColor fuchsia]]; #endif [OFStdOut writeFormat: @"%zu", numFailed]; [OFStdOut setForegroundColor: [OFColor purple]]; [OFStdOut writeFormat: @" test%s failed, ", (numFailed != 1 ? "s" : "")]; #if !defined(OF_WII) && !defined(OF_NINTENDO_DS) && \ !defined(OF_NINTENDO_3DS) && !defined(OF_NINTENDO_SWITCH) [OFStdOut setForegroundColor: [OFColor fuchsia]]; #endif [OFStdOut writeFormat: @"%zu", numSkipped]; [OFStdOut setForegroundColor: [OFColor purple]]; [OFStdOut writeFormat: @" test%s skipped\n", (numSkipped != 1 ? "s" : "")]; [OFStdOut reset]; #if defined(OF_WII) [OFStdOut setForegroundColor: [OFColor silver]]; [OFStdOut writeLine: @"Press home button to exit"]; for (;;) { WPAD_ScanPads(); if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) break; VIDEO_WaitVSync(); } #elif defined(OF_NINTENDO_DS) [OFStdOut setForegroundColor: [OFColor silver]]; [OFStdOut writeLine: @"Press start button to exit"]; for (;;) { swiWaitForVBlank(); scanKeys(); if (keysDown() & KEY_START) break; } #elif defined(OF_NINTENDO_3DS) [OFStdOut setForegroundColor: [OFColor silver]]; [OFStdOut writeLine: @"Press start button to exit"]; for (;;) { hidScanInput(); if (hidKeysDown() & KEY_START) break; gspWaitForVBlank(); } #elif defined(OF_NINTENDO_SWITCH) while (appletMainLoop()) updateConsole(true); consoleExit(NULL); #endif [OFApplication terminateWithStatus: (int)numFailed]; } @end objfw-1.1.6/src/test/OTAssert.h000066400000000000000000000153731465614216400162730ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ /* * Unfortunately, that's the only way to make all compilers happy with the GNU * extensions for variadic macros that are being used here. */ #pragma GCC system_header /** @file */ /** * @brief Asserts that the specified condition condition holds. * * @param condition The condition to check * @param ... An optional format string to print if the assertion failed, * followed by optional arguments */ #define OTAssert(condition, ...) \ _OTAssertImpl(self, _cmd, condition, @#condition, \ @__FILE__, __LINE__, ## __VA_ARGS__, nil) /** * @brief Asserts that the specified condition is true. * * @param condition The condition to check * @param ... An optional format string to print if the assertion failed, * followed by optional arguments */ #define OTAssertTrue(condition, ...) \ OTAssert(condition == true, ## __VA_ARGS__) /** * @brief Asserts that the specified condition is false. * * @param condition The condition to check * @param ... An optional format string to print if the assertion failed, * followed by optional arguments */ #define OTAssertFalse(condition, ...) \ OTAssert(condition == false, ## __VA_ARGS__) /** * @brief Asserts that the two values are equal. * * @param a The value to check * @param b The expected value * @param ... An optional format string to print if the assertion failed, * followed by optional arguments */ #define OTAssertEqual(a, b, ...) OTAssert(a == b, ## __VA_ARGS__) /** * @brief Asserts that the two values are not equal. * * @param a The value to check * @param b The value `a` should not have * @param ... An optional format string to print if the assertion failed, * followed by optional arguments */ #define OTAssertNotEqual(a, b, ...) OTAssert(a != b, ## __VA_ARGS__) /** * @brief Asserts that the value is less than another value. * * @param a The value to check * @param b The value `a` should be less than * @param ... An optional format string to print if the assertion failed, * followed by optional arguments */ #define OTAssertLessThan(a, b, ...) OTAssert(a < b, ## __VA_ARGS__) /** * @brief Asserts that the value is less than or equal to another value. * * @param a The value to check * @param b The value `a` should be less than or equal to * @param ... An optional format string to print if the assertion failed, * followed by optional arguments */ #define OTAssertLessThanOrEqual(a, b, ...) OTAssert(a <= b, ## __VA_ARGS__) /** * @brief Asserts that the value is greater than another value. * * @param a The value to check * @param b The value `a` should be greater than * @param ... An optional format string to print if the assertion failed, * followed by optional arguments */ #define OTAssertGreaterThan(a, b, ...) OTAssert(a > b, ## __VA_ARGS__) /** * @brief Asserts that the value is greater than or equal to another value. * * @param a The value to check * @param b The value `a` should be greater than or equal to * @param ... An optional format string to print if the assertion failed, * followed by optional arguments */ #define OTAssertGreaterThanOrEqual(a, b, ...) OTAssert(a >= b, ## __VA_ARGS__) /** * @brief Asserts that the two objects are equal. * * @param a The object to check * @param b The object `a` is expected to be equal to * @param ... An optional format string to print if the assertion failed, * followed by optional arguments */ #define OTAssertEqualObjects(a, b, ...) OTAssert([a isEqual: b], ## __VA_ARGS__) /** * @brief Asserts that the two objects are not equal. * * @param a The object to check * @param b The object `a` is expected to be not equal to * @param ... An optional format string to print if the assertion failed, * followed by optional arguments */ #define OTAssertNotEqualObjects(a, b, ...) \ OTAssert(![a isEqual: b], ## __VA_ARGS__) /** * @brief Asserts that the specified object is `nil`. * * @param object The object to should be `nil` * @param ... An optional format string to print if the assertion failed, * followed by optional arguments */ #define OTAssertNil(object, ...) OTAssert(object == nil, ## __VA_ARGS__) /** * @brief Asserts that the specified object is not `nil`. * * @param object The object to should not be `nil` * @param ... An optional format string to print if the assertion failed, * followed by optional arguments */ #define OTAssertNotNil(object, ...) OTAssert(object != nil, ## __VA_ARGS__) /** * @brief Asserts that the specified expression throws an exception. * * @param expression The expression that should throw * @param ... An optional format string to print if the assertion failed, * followed by optional arguments */ #define OTAssertThrows(expression, ...) \ { \ bool OTThrown = false; \ @try { \ expression; \ } @catch (id e) { \ OTThrown = true; \ } \ OTAssert(OTThrown, ## __VA_ARGS__); \ } /** * @brief Asserts that the specified expression throws a specific exception. * * @param expression The expression that should throw * @param exception The exception the expression should throw (as just the * class name, without quotes) * @param ... An optional format string to print if the assertion failed, * followed by optional arguments */ #define OTAssertThrowsSpecific(expression, exception, ...) \ { \ bool OTThrown = false; \ @try { \ expression; \ } @catch (exception *e) { \ OTThrown = true; \ } \ OTAssert(OTThrown, ## __VA_ARGS__); \ } /** * @brief Skips the current test, making it neither fail nor succeeed. * * @param ... An optional format string to print why the test was skipped, * followed by optional arguments */ #define OTSkip(...) \ _OTSkipImpl(self, _cmd, @__FILE__, __LINE__, ## __VA_ARGS__, nil) #ifdef __cplusplus extern "C" { #endif extern void _OTAssertImpl(id testCase, SEL test, bool condition, OFString *check, OFString *file, size_t line, ...); extern void _OTSkipImpl(id testCase, SEL test, OFString *file, size_t line, ...); #ifdef __cplusplus } #endif objfw-1.1.6/src/test/OTAssert.m000066400000000000000000000034331465614216400162720ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFString.h" #import "OTAssertionFailedException.h" #import "OTTestSkippedException.h" void _OTAssertImpl(id testCase, SEL test, bool condition, OFString *check, OFString *file, size_t line, ...) { va_list arguments; OFConstantString *format; OFString *message = nil; if (condition) return; va_start(arguments, line); format = va_arg(arguments, OFConstantString *); if (format != nil) message = [[[OFString alloc] initWithFormat: format arguments: arguments] autorelease]; va_end(arguments); @throw [OTAssertionFailedException exceptionWithCondition: check message: message]; } void _OTSkipImpl(id testCase, SEL test, OFString *file, size_t line, ...) { va_list arguments; OFConstantString *format; OFString *message = nil; va_start(arguments, line); format = va_arg(arguments, OFConstantString *); if (format != nil) message = [[[OFString alloc] initWithFormat: format arguments: arguments] autorelease]; va_end(arguments); @throw [OTTestSkippedException exceptionWithMessage: message]; } objfw-1.1.6/src/test/OTAssertionFailedException.h000066400000000000000000000025161465614216400217600ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @interface OTAssertionFailedException: OFException { OFString *_condition; OFString *_Nullable _message; } @property (readonly, nonatomic) OFString *condition; @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *message; + (instancetype)exceptionWithCondition: (OFString *)condition message: (nullable OFString *)message; + (instancetype)exception OF_UNAVAILABLE; - (instancetype)initWithCondition: (OFString *)condition message: (nullable OFString *)message; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/test/OTAssertionFailedException.m000066400000000000000000000033641465614216400217670ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OTAssertionFailedException.h" @implementation OTAssertionFailedException @synthesize condition = _condition, message = _message; + (instancetype)exceptionWithCondition: (OFString *)condition message: (OFString *)message { return [[[self alloc] initWithCondition: condition message: message] autorelease]; } + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithCondition: (OFString *)condition message: (OFString *)message { self = [super init]; @try { _condition = [condition copy]; _message = [message copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_condition release]; [_message release]; [super dealloc]; } - (OFString *)description { if (_message != nil) return [OFString stringWithFormat: @"Assertion failed: %@: %@", _condition, _message]; else return [OFString stringWithFormat: @"Assertion failed: %@", _condition]; } @end objfw-1.1.6/src/test/OTOrderedDictionary.h000066400000000000000000000027171465614216400204420ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifdef OBJFWTEST_LOCAL_INCLUDES # import "ObjFW.h" #else # import #endif OF_ASSUME_NONNULL_BEGIN /** * @brief A dictionary that enumerates keys and objects in the same order they * were specified during initialization. * * @warning This class is only for testing! It is slow and only to be used to * test extensions of OFDictionary, for example serializations such as * JSON, where it is desirable to compare to an expected output. * * @note ABI stability for this and all other classes in ObjFWTest is not * guaranteed! The assumption is that you recompile your tests after * updating ObjFWTest. */ @interface OTOrderedDictionary: OFDictionary { OFArray *_keys; OFArray *_objects; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/test/OTOrderedDictionary.m000066400000000000000000000035611465614216400204450ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OTOrderedDictionary.h" @implementation OTOrderedDictionary - (instancetype)initWithObjects: (id const *)objects forKeys: (id const *)keys count: (size_t)count { self = [super init]; @try { OFMutableArray *mutableKeys, *mutableObjects; mutableKeys = [[OFMutableArray alloc] initWithCapacity: count]; _keys = mutableKeys; mutableObjects = [[OFMutableArray alloc] initWithCapacity: count]; _objects = mutableObjects; for (size_t i = 0; i < count; i++) { [mutableKeys addObject: keys[i]]; [mutableObjects addObject: objects[i]]; } [mutableKeys makeImmutable]; [mutableObjects makeImmutable]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_keys release]; [_objects release]; [super dealloc]; } - (id)objectForKey: (id)key { size_t i = 0; for (id iter in _keys) { if ([iter isEqual: key]) return [_objects objectAtIndex: i]; i++; } return nil; } - (size_t)count { return _keys.count; } - (OFEnumerator *)keyEnumerator { return [_keys objectEnumerator]; } - (OFEnumerator *)objectEnumerator { return [_objects objectEnumerator]; } @end objfw-1.1.6/src/test/OTTestCase.h000066400000000000000000000037211465614216400165370ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #ifdef OBJFWTEST_LOCAL_INCLUDES # import "ObjFW.h" #else # import #endif OF_ASSUME_NONNULL_BEGIN /** * @brief A class meant for subclassing to create a test case, consisting of * one or more tests. * * All methods with the prefix `test` that take no arguments of all classes * that subclass this class are automatically executed by ObjFWTest. * * @note ABI stability for this and all other classes in ObjFWTest is not * guaranteed! The assumption is that you recompile your tests after * updating ObjFWTest. */ @interface OTTestCase: OFObject #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nullable, nonatomic) OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, id) *) *summary; #endif /** * @brief Returns a summary for the test case that should be printed once all * tests in all test cases were run. * * This is mostly useful to print something at the end of all tests that needs * manual verification. */ + (nullable OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, id) *) *)summary; /** * @brief Set up method that is run before every test in the test case. */ - (void)setUp; /** * @brief Tear down method that is run after every test in the test case. */ - (void)tearDown; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/test/OTTestCase.m000066400000000000000000000016621465614216400165460ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OTTestCase.h" @implementation OTTestCase: OFObject + (OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, id) *) *)summary { return nil; } - (void)setUp { } - (void)tearDown { } @end objfw-1.1.6/src/test/OTTestSkippedException.h000066400000000000000000000022551465614216400211430ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFException.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @interface OTTestSkippedException: OFException { OFString *_Nullable _message; } @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *message; + (instancetype)exceptionWithMessage: (nullable OFString *)message; + (instancetype)exception OF_UNAVAILABLE; - (instancetype)initWithMessage: (nullable OFString *)message; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/test/OTTestSkippedException.m000066400000000000000000000027271465614216400211540ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OTTestSkippedException.h" @implementation OTTestSkippedException @synthesize message = _message; + (instancetype)exceptionWithMessage: (OFString *)message { return [[[self alloc] initWithMessage: message] autorelease]; } + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithMessage: (OFString *)message { self = [super init]; @try { _message = [message copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_message release]; [super dealloc]; } - (OFString *)description { if (_message != nil) return [OFString stringWithFormat: @"Test skipped: %@", _message]; else return nil; } @end objfw-1.1.6/src/test/ObjFWTest.h000066400000000000000000000014501465614216400163650ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OTTestCase.h" #import "OTAssert.h" #import "OTOrderedDictionary.h" objfw-1.1.6/src/test/ObjFWTest.oc000066400000000000000000000002131465614216400165330ustar00rootroot00000000000000package_format 1 LIBS="-lobjfwtest $LIBS" FRAMEWORK_LIBS="-lobjfwtest $FRAMEWORK_LIBS" STATIC_LIBS="${libdir}/libobjfwtest.a $STATIC_LIBS" objfw-1.1.6/src/tls/000077500000000000000000000000001465614216400142305ustar00rootroot00000000000000objfw-1.1.6/src/tls/Info.plist.in000066400000000000000000000012451465614216400166070ustar00rootroot00000000000000 CFBundleExecutable ObjFWTLS CFBundleName ObjFWTLS CFBundleIdentifier im.nil.objfw.tls CFBundleInfoDictionaryVersion 6.0 CFBundlePackageType FMWK CFBundleVersion @BUNDLE_VERSION@ CFBundleShortVersionString @BUNDLE_SHORT_VERSION@ MinimumOSVersion 9.0 objfw-1.1.6/src/tls/Makefile000066400000000000000000000022761465614216400156770ustar00rootroot00000000000000include ../../extra.mk DISTCLEAN = Info.plist SHARED_LIB = ${OBJFWTLS_SHARED_LIB} STATIC_LIB = ${OBJFWTLS_STATIC_LIB} FRAMEWORK = ${OBJFWTLS_FRAMEWORK} LIB_MAJOR = ${OBJFWTLS_LIB_MAJOR} LIB_MINOR = ${OBJFWTLS_LIB_MINOR} LIB_PATCH = ${OBJFWTLS_LIB_PATCH} INCLUDES := ObjFWTLS.h SRCS = ${OF_GNUTLS_TLS_STREAM_M} \ ${OF_MBEDTLS_TLS_STREAM_M} \ ${OF_OPENSSL_TLS_STREAM_M} \ ${OF_SECURE_TRANSPORT_TLS_STREAM_M} includesubdir = ObjFWTLS include ../../buildsys.mk install-extra: i=ObjFWTLS.oc; \ ${INSTALL_STATUS}; \ if ${MKDIR_P} ${DESTDIR}${libdir}/objfw-config && \ ${INSTALL} -m 644 $$i ${DESTDIR}${libdir}/objfw-config/$$i; then \ ${INSTALL_OK}; \ else \ ${INSTALL_FAILED}; \ fi uninstall-extra: i=ObjFWTLS.oc; \ if test -f ${DESTDIR}${libdir}/objfw-config/$$i; then \ if rm -f ${DESTDIR}${libdir}/objfw-config/$$i; then \ ${DELETE_OK}; \ else \ ${DELETE_FAILED}; \ fi \ fi rmdir ${DESTDIR}${libdir}/objfw-config >/dev/null 2>&1 || true CPPFLAGS += -I. -I.. -I../.. -I../exceptions -I../runtime ${TLS_CPPFLAGS} LD = ${OBJC} FRAMEWORK_LIBS := ${TLS_LIBS} -F.. -framework ObjFW ${LIBS} LIBS := ${TLS_LIBS} -L.. -lobjfw -L../runtime ${RUNTIME_LIBS} ${LIBS} objfw-1.1.6/src/tls/OFGnuTLSTLSStream.h000066400000000000000000000017311465614216400175030ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFTLSStream.h" #include OF_ASSUME_NONNULL_BEGIN @interface OFGnuTLSTLSStream: OFTLSStream { bool _initialized, _handshakeDone; gnutls_session_t _session; OFString *_host; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/tls/OFGnuTLSTLSStream.m000066400000000000000000000222301465614216400175050ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFGnuTLSTLSStream.h" #import "OFData.h" #import "OFAlreadyOpenException.h" #import "OFInitializationFailedException.h" #import "OFNotOpenException.h" #import "OFReadFailedException.h" #import "OFTLSHandshakeFailedException.h" #import "OFWriteFailedException.h" int _ObjFWTLS_reference; static gnutls_certificate_credentials_t systemTrustCreds; #ifndef GNUTLS_SAFE_PADDING_CHECK /* Some older versions don't have it. */ # define GNUTLS_SAFE_PADDING_CHECK 0 #endif @implementation OFGnuTLSTLSStream static ssize_t readFunc(gnutls_transport_ptr_t transport, void *buffer, size_t length) { OFGnuTLSTLSStream *stream = (OFGnuTLSTLSStream *)transport; @try { length = [stream.underlyingStream readIntoBuffer: buffer length: length]; } @catch (OFReadFailedException *e) { gnutls_transport_set_errno(stream->_session, e.errNo); return -1; } if (length == 0 && !stream.underlyingStream.atEndOfStream) { gnutls_transport_set_errno(stream->_session, EAGAIN); return -1; } return length; } static ssize_t writeFunc(gnutls_transport_ptr_t transport, const void *buffer, size_t length) { OFGnuTLSTLSStream *stream = (OFGnuTLSTLSStream *)transport; @try { [stream.underlyingStream writeBuffer: buffer length: length]; } @catch (OFWriteFailedException *e) { gnutls_transport_set_errno(stream->_session, e.errNo); if (e.errNo == EWOULDBLOCK || e.errNo == EAGAIN) return e.bytesWritten; return -1; } return length; } + (void)load { if (OFTLSStreamImplementation == Nil) OFTLSStreamImplementation = self; } + (void)initialize { if (self != [OFGnuTLSTLSStream class]) return; if (gnutls_certificate_allocate_credentials(&systemTrustCreds) != GNUTLS_E_SUCCESS || gnutls_certificate_set_x509_system_trust(systemTrustCreds) < 0) @throw [OFInitializationFailedException exception]; } - (instancetype)initWithStream: (OFStream *)stream { self = [super initWithStream: stream]; @try { _underlyingStream.delegate = self; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_initialized) [self close]; [_host release]; [super dealloc]; } - (void)close { if (!_initialized) @throw [OFNotOpenException exceptionWithObject: self]; if (_handshakeDone) gnutls_bye(_session, GNUTLS_SHUT_WR); gnutls_deinit(_session); _initialized = _handshakeDone = false; [_host release]; _host = nil; [super close]; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { ssize_t ret; if (!_handshakeDone) @throw [OFNotOpenException exceptionWithObject: self]; if ((ret = gnutls_record_recv(_session, buffer, length)) < 0) { /* * The underlying stream might have had data ready, but not * enough for GnuTLS to return decrypted data. This means the * caller might have observed the TLS stream for reading, got a * ready signal and read - and expects the read to succeed, not * to fail with EWOULDBLOCK/EAGAIN, as it was signaled ready. * Therefore, return 0, as we could read 0 decrypted bytes, but * cleared the ready signal of the underlying stream. */ if (ret == GNUTLS_E_INTERRUPTED || ret == GNUTLS_E_AGAIN) return 0; /* FIXME: Translate error to errNo */ @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: 0]; } return ret; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { ssize_t ret; if (!_handshakeDone) @throw [OFNotOpenException exceptionWithObject: self]; if ((ret = gnutls_record_send(_session, buffer, length)) < 0) { if (ret == GNUTLS_E_INTERRUPTED || ret == GNUTLS_E_AGAIN) return 0; /* FIXME: Translate error to errNo */ @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: ret errNo: 0]; } return ret; } - (bool)lowlevelHasDataInReadBuffer { return (_underlyingStream.hasDataInReadBuffer || gnutls_record_check_pending(_session) > 0); } - (void)asyncPerformClientHandshakeWithHost: (OFString *)host runLoopMode: (OFRunLoopMode)runLoopMode { static const OFTLSStreamErrorCode initFailedErrorCode = OFTLSStreamErrorCodeInitializationFailed; void *pool = objc_autoreleasePoolPush(); id exception = nil; int status; if (_initialized) @throw [OFAlreadyOpenException exceptionWithObject: self]; if (gnutls_init(&_session, GNUTLS_CLIENT | GNUTLS_NONBLOCK | GNUTLS_SAFE_PADDING_CHECK) != GNUTLS_E_SUCCESS) @throw [OFTLSHandshakeFailedException exceptionWithStream: self host: host errorCode: initFailedErrorCode]; _initialized = true; gnutls_transport_set_ptr(_session, self); gnutls_transport_set_pull_function(_session, readFunc); gnutls_transport_set_push_function(_session, writeFunc); if (gnutls_set_default_priority(_session) != GNUTLS_E_SUCCESS || gnutls_credentials_set(_session, GNUTLS_CRD_CERTIFICATE, systemTrustCreds) != GNUTLS_E_SUCCESS) @throw [OFTLSHandshakeFailedException exceptionWithStream: self host: host errorCode: initFailedErrorCode]; _host = [host copy]; if (gnutls_server_name_set(_session, GNUTLS_NAME_DNS, _host.UTF8String, _host.UTF8StringLength) != GNUTLS_E_SUCCESS) @throw [OFTLSHandshakeFailedException exceptionWithStream: self host: host errorCode: initFailedErrorCode]; if (_verifiesCertificates) gnutls_session_set_verify_cert(_session, _host.UTF8String, 0); status = gnutls_handshake(_session); if (status == GNUTLS_E_INTERRUPTED || status == GNUTLS_E_AGAIN) { if (gnutls_record_get_direction(_session) == 1) [_underlyingStream asyncWriteData: [OFData data] runLoopMode: runLoopMode]; else [_underlyingStream asyncReadIntoBuffer: (void *)"" length: 0 runLoopMode: runLoopMode]; [_delegate retain]; objc_autoreleasePoolPop(pool); return; } if (status == GNUTLS_E_SUCCESS) _handshakeDone = true; else /* FIXME: Map to better errors */ exception = [OFTLSHandshakeFailedException exceptionWithStream: self host: host errorCode: OFTLSStreamErrorCodeUnknown]; if ([_delegate respondsToSelector: @selector(stream:didPerformClientHandshakeWithHost:exception:)]) [_delegate stream: self didPerformClientHandshakeWithHost: host exception: exception]; objc_autoreleasePoolPop(pool); } - (bool)stream: (OFStream *)stream didReadIntoBuffer: (void *)buffer length: (size_t)length exception: (id)exception { if (exception == nil) { int status = gnutls_handshake(_session); if (status == GNUTLS_E_INTERRUPTED || status == GNUTLS_E_AGAIN) { if (gnutls_record_get_direction(_session) == 1) { OFRunLoopMode runLoopMode = [OFRunLoop currentRunLoop].currentMode; [_underlyingStream asyncWriteData: [OFData data] runLoopMode: runLoopMode]; return false; } else return true; } if (status == GNUTLS_E_SUCCESS) _handshakeDone = true; else exception = [OFTLSHandshakeFailedException exceptionWithStream: self host: _host errorCode: OFTLSStreamErrorCodeUnknown]; } if ([_delegate respondsToSelector: @selector(stream:didPerformClientHandshakeWithHost:exception:)]) [_delegate stream: self didPerformClientHandshakeWithHost: _host exception: exception]; [_delegate release]; return false; } - (OFData *)stream: (OFStream *)stream didWriteData: (OFData *)data bytesWritten: (size_t)bytesWritten exception: (id)exception { if (exception == nil) { int status = gnutls_handshake(_session); if (status == GNUTLS_E_INTERRUPTED || status == GNUTLS_E_AGAIN) { if (gnutls_record_get_direction(_session) == 1) return data; else { OFRunLoopMode runLoopMode = [OFRunLoop currentRunLoop].currentMode; [_underlyingStream asyncReadIntoBuffer: (void *)"" length: 0 runLoopMode: runLoopMode]; return nil; } } if (status == GNUTLS_E_SUCCESS) _handshakeDone = true; else exception = [OFTLSHandshakeFailedException exceptionWithStream: self host: _host errorCode: OFTLSStreamErrorCodeUnknown]; } if ([_delegate respondsToSelector: @selector(stream:didPerformClientHandshakeWithHost:exception:)]) [_delegate stream: self didPerformClientHandshakeWithHost: _host exception: exception]; [_delegate release]; return nil; } @end objfw-1.1.6/src/tls/OFMbedTLSTLSStream.h000066400000000000000000000020201465614216400176110ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFTLSStream.h" #include OF_ASSUME_NONNULL_BEGIN @interface OFMbedTLSTLSStream: OFTLSStream { bool _initialized, _handshakeDone; mbedtls_ssl_config _config; mbedtls_ssl_context _SSL; mbedtls_x509_crt _CAChain; OFString *_host; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/tls/OFMbedTLSTLSStream.m000066400000000000000000000232641465614216400176330ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFMbedTLSTLSStream.h" #import "OFApplication.h" #import "OFData.h" #import "OFDictionary.h" #import "OFLocale.h" #import "OFAlreadyOpenException.h" #import "OFInitializationFailedException.h" #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFTLSHandshakeFailedException.h" #import "OFWriteFailedException.h" #include #include int _ObjFWTLS_reference; static mbedtls_entropy_context entropy; static mbedtls_ctr_drbg_context CTRDRBG; @implementation OFMbedTLSTLSStream static int readFunc(void *ctx, unsigned char *buffer, size_t length) { OFMbedTLSTLSStream *stream = (OFMbedTLSTLSStream *)ctx; @try { length = [stream.underlyingStream readIntoBuffer: buffer length: length]; } @catch (OFReadFailedException *e) { return -1; } if (length == 0 && !stream.underlyingStream.atEndOfStream) return MBEDTLS_ERR_SSL_WANT_READ; if (length > INT_MAX) @throw [OFOutOfRangeException exception]; return (int)length; } static int writeFunc(void *ctx, const unsigned char *buffer, size_t length) { OFMbedTLSTLSStream *stream = (OFMbedTLSTLSStream *)ctx; @try { [stream.underlyingStream writeBuffer: buffer length: length]; } @catch (OFWriteFailedException *e) { if (e.errNo == EWOULDBLOCK || e.errNo == EAGAIN) { size_t bytesWritten = e.bytesWritten; if (bytesWritten > INT_MAX) @throw [OFOutOfRangeException exception]; return (bytesWritten > 0 ? (int)bytesWritten : MBEDTLS_ERR_SSL_WANT_WRITE); } return -1; } if (length > INT_MAX) @throw [OFOutOfRangeException exception]; return (int)length; } + (void)load { if (OFTLSStreamImplementation == Nil) OFTLSStreamImplementation = self; } + (void)initialize { if (self != [OFMbedTLSTLSStream class]) return; mbedtls_entropy_init(&entropy); if (mbedtls_ctr_drbg_seed(&CTRDRBG, mbedtls_entropy_func, &entropy, NULL, 0) != 0) @throw [OFInitializationFailedException exceptionWithClass: self]; } - (instancetype)initWithStream: (OFStream *)stream { self = [super initWithStream: stream]; @try { _underlyingStream.delegate = self; mbedtls_x509_crt_init(&_CAChain); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_initialized) [self close]; [_host release]; mbedtls_x509_crt_free(&_CAChain); [super dealloc]; } - (void)close { if (!_initialized) @throw [OFNotOpenException exceptionWithObject: self]; if (_handshakeDone) mbedtls_ssl_close_notify(&_SSL); mbedtls_ssl_free(&_SSL); mbedtls_ssl_config_free(&_config); _initialized = _handshakeDone = false; [_host release]; _host = nil; [super close]; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { int ret; if (!_handshakeDone) @throw [OFNotOpenException exceptionWithObject: self]; if ((ret = mbedtls_ssl_read(&_SSL, buffer, length)) < 0) { /* * The underlying stream might have had data ready, but not * enough for MbedTLS to return decrypted data. This means the * caller might have observed the TLS stream for reading, got a * ready signal and read - and expects the read to succeed, not * to fail with EWOULDBLOCK/EAGAIN, as it was signaled ready. * Therefore, return 0, as we could read 0 decrypted bytes, but * cleared the ready signal of the underlying stream. */ if (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE) return 0; /* FIXME: Translate error to errNo */ @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: 0]; } return ret; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { int ret; if (!_handshakeDone) @throw [OFNotOpenException exceptionWithObject: self]; if ((ret = mbedtls_ssl_write(&_SSL, buffer, length)) < 0) { if (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE) return 0; /* FIXME: Translate error to errNo */ @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: ret errNo: 0]; } return ret; } - (bool)lowlevelHasDataInReadBuffer { return (_underlyingStream.hasDataInReadBuffer || mbedtls_ssl_get_bytes_avail(&_SSL)); } - (void)asyncPerformClientHandshakeWithHost: (OFString *)host runLoopMode: (OFRunLoopMode)runLoopMode { static const OFTLSStreamErrorCode initFailedErrorCode = OFTLSStreamErrorCodeInitializationFailed; void *pool = objc_autoreleasePoolPush(); OFString *CAFilePath; id exception = nil; int status; if (_initialized) @throw [OFAlreadyOpenException exceptionWithObject: self]; if (mbedtls_ssl_config_defaults(&_config, MBEDTLS_SSL_IS_CLIENT, MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT) != 0) @throw [OFTLSHandshakeFailedException exceptionWithStream: self host: host errorCode: initFailedErrorCode]; mbedtls_ssl_conf_rng(&_config, mbedtls_ctr_drbg_random, &CTRDRBG); mbedtls_ssl_conf_authmode(&_config, (_verifiesCertificates ? MBEDTLS_SSL_VERIFY_REQUIRED : MBEDTLS_SSL_VERIFY_NONE)); /* TODO: Add other ways to add a CA chain */ CAFilePath = [[OFApplication environment] objectForKey: @"OBJFW_MBEDTLS_CA_PATH"]; if (CAFilePath != nil) { if (mbedtls_x509_crt_parse_file(&_CAChain, [CAFilePath cStringWithEncoding: [OFLocale encoding]]) != 0) @throw [OFTLSHandshakeFailedException exceptionWithStream: self host: host errorCode: initFailedErrorCode]; } mbedtls_ssl_conf_ca_chain(&_config, &_CAChain, NULL); mbedtls_ssl_init(&_SSL); if (mbedtls_ssl_setup(&_SSL, &_config) != 0) @throw [OFTLSHandshakeFailedException exceptionWithStream: self host: host errorCode: initFailedErrorCode]; mbedtls_ssl_set_bio(&_SSL, self, writeFunc, readFunc, NULL); _host = [host copy]; if (mbedtls_ssl_set_hostname(&_SSL, _host.UTF8String) != 0) @throw [OFTLSHandshakeFailedException exceptionWithStream: self host: host errorCode: initFailedErrorCode]; status = mbedtls_ssl_handshake(&_SSL); if (status == MBEDTLS_ERR_SSL_WANT_READ) { [_underlyingStream asyncReadIntoBuffer: (void *)"" length: 0 runLoopMode: runLoopMode]; [_delegate retain]; objc_autoreleasePoolPop(pool); return; } else if (status == MBEDTLS_ERR_SSL_WANT_WRITE) { [_underlyingStream asyncWriteData: [OFData data] runLoopMode: runLoopMode]; [_delegate retain]; objc_autoreleasePoolPop(pool); return; } if (status == 0) _handshakeDone = true; else /* FIXME: Map to better errors */ exception = [OFTLSHandshakeFailedException exceptionWithStream: self host: host errorCode: OFTLSStreamErrorCodeUnknown]; if ([_delegate respondsToSelector: @selector(stream:didPerformClientHandshakeWithHost:exception:)]) [_delegate stream: self didPerformClientHandshakeWithHost: host exception: exception]; objc_autoreleasePoolPop(pool); } - (bool)stream: (OFStream *)stream didReadIntoBuffer: (void *)buffer length: (size_t)length exception: (id)exception { if (exception == nil) { int status = mbedtls_ssl_handshake_step(&_SSL); if (status == MBEDTLS_ERR_SSL_WANT_READ) return true; else if (status == MBEDTLS_ERR_SSL_WANT_WRITE) { OFRunLoopMode runLoopMode = [OFRunLoop currentRunLoop].currentMode; [_underlyingStream asyncWriteData: [OFData data] runLoopMode: runLoopMode]; return false; } if (status == 0) _handshakeDone = true; else exception = [OFTLSHandshakeFailedException exceptionWithStream: self host: _host errorCode: OFTLSStreamErrorCodeUnknown]; } if ([_delegate respondsToSelector: @selector(stream:didPerformClientHandshakeWithHost:exception:)]) [_delegate stream: self didPerformClientHandshakeWithHost: _host exception: exception]; [_delegate release]; return false; } - (OFData *)stream: (OFStream *)stream didWriteData: (OFData *)data bytesWritten: (size_t)bytesWritten exception: (id)exception { if (exception == nil) { int status = mbedtls_ssl_handshake_step(&_SSL); if (status == MBEDTLS_ERR_SSL_WANT_WRITE) return data; else if (status == MBEDTLS_ERR_SSL_WANT_READ) { OFRunLoopMode runLoopMode = [OFRunLoop currentRunLoop].currentMode; [_underlyingStream asyncReadIntoBuffer: (void *)"" length: 0 runLoopMode: runLoopMode]; return nil; } if (status == 0) _handshakeDone = true; else exception = [OFTLSHandshakeFailedException exceptionWithStream: self host: _host errorCode: OFTLSStreamErrorCodeUnknown]; } if ([_delegate respondsToSelector: @selector(stream:didPerformClientHandshakeWithHost:exception:)]) [_delegate stream: self didPerformClientHandshakeWithHost: _host exception: exception]; [_delegate release]; return nil; } @end objfw-1.1.6/src/tls/OFOpenSSLTLSStream.h000066400000000000000000000021061465614216400176470ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFTLSStream.h" #include #include OF_ASSUME_NONNULL_BEGIN #define OFOpenSSLTLSStreamBufferSize 512 @interface OFOpenSSLTLSStream: OFTLSStream { bool _handshakeDone; SSL *_SSL; BIO *_readBIO, *_writeBIO; OFString *_host; char _buffer[OFOpenSSLTLSStreamBufferSize]; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/tls/OFOpenSSLTLSStream.m000066400000000000000000000252361465614216400176650ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFOpenSSLTLSStream.h" #import "OFData.h" #import "OFAlreadyOpenException.h" #import "OFInitializationFailedException.h" #import "OFNotOpenException.h" #import "OFReadFailedException.h" #import "OFTLSHandshakeFailedException.h" #import "OFWriteFailedException.h" #define bufferSize OFOpenSSLTLSStreamBufferSize int _ObjFWTLS_reference; static SSL_CTX *clientContext; @implementation OFOpenSSLTLSStream + (void)load { if (OFTLSStreamImplementation == Nil) OFTLSStreamImplementation = self; } + (void)initialize { if (self != [OFOpenSSLTLSStream class]) return; SSL_load_error_strings(); SSL_library_init(); if ((clientContext = SSL_CTX_new(TLS_client_method())) == NULL || SSL_CTX_set_default_verify_paths(clientContext) != 1) @throw [OFInitializationFailedException exceptionWithClass: self]; } - (instancetype)initWithStream: (OFStream *)stream { self = [super initWithStream: stream]; @try { _underlyingStream.delegate = self; /* * Buffer writes so that nothing gets lost if we write more * than the underlying stream can write. */ _underlyingStream.buffersWrites = true; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_SSL != NULL) [self close]; [_host release]; [super dealloc]; } - (void)close { if (_SSL == NULL) @throw [OFNotOpenException exceptionWithObject: self]; if (_handshakeDone) SSL_shutdown(_SSL); SSL_free(_SSL); _SSL = NULL; _handshakeDone = false; [_host release]; _host = nil; [super close]; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { int ret; size_t bytesRead; if (!_handshakeDone) @throw [OFNotOpenException exceptionWithObject: self]; ret = SSL_read_ex(_SSL, buffer, length, &bytesRead); while (BIO_ctrl_pending(_writeBIO) > 0) { int tmp = BIO_read(_writeBIO, _buffer, bufferSize); OFEnsure(tmp >= 0); [_underlyingStream writeBuffer: _buffer length: tmp]; [_underlyingStream flushWriteBuffer]; } if (ret == 1) return bytesRead; if (SSL_get_error(_SSL, ret) == SSL_ERROR_WANT_READ) { if (BIO_ctrl_pending(_readBIO) < 1) { @try { size_t tmp = [_underlyingStream readIntoBuffer: _buffer length: bufferSize]; OFEnsure(tmp <= INT_MAX); /* Writing to a memory BIO must never fail. */ OFEnsure(BIO_write(_readBIO, _buffer, (int)tmp) == (int)tmp); } @catch (OFReadFailedException *e) { if (e.errNo == EWOULDBLOCK || e.errNo != EAGAIN) return 0; } } ret = SSL_read_ex(_SSL, buffer, length, &bytesRead); while (BIO_ctrl_pending(_writeBIO) > 0) { int tmp = BIO_read(_writeBIO, _buffer, bufferSize); OFEnsure(tmp >= 0); [_underlyingStream writeBuffer: _buffer length: tmp]; [_underlyingStream flushWriteBuffer]; } if (ret == 1) return bytesRead; if (SSL_get_error(_SSL, ret) == SSL_ERROR_WANT_READ) return 0; } /* FIXME: Translate error to errNo */ @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: 0]; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { int ret; size_t bytesWritten; if (!_handshakeDone) @throw [OFNotOpenException exceptionWithObject: self]; if ((ret = SSL_write_ex(_SSL, buffer, length, &bytesWritten)) != 1) { /* FIXME: Translate error to errNo */ int errNo = 0; if (SSL_get_error(_SSL, ret) == SSL_ERROR_WANT_WRITE) return bytesWritten; @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: bytesWritten errNo: errNo]; } while (BIO_ctrl_pending(_writeBIO) > 0) { int tmp = BIO_read(_writeBIO, _buffer, bufferSize); OFEnsure(tmp >= 0); [_underlyingStream writeBuffer: _buffer length: tmp]; [_underlyingStream flushWriteBuffer]; } return bytesWritten; } - (bool)lowlevelHasDataInReadBuffer { #ifdef HAVE_SSL_HAS_PENDING return (_underlyingStream.hasDataInReadBuffer || SSL_has_pending(_SSL) || BIO_ctrl_pending(_readBIO) > 0); #else return (_underlyingStream.hasDataInReadBuffer || SSL_pending(_SSL) > 0 || BIO_ctrl_pending(_readBIO) > 0); #endif } - (void)asyncPerformClientHandshakeWithHost: (OFString *)host runLoopMode: (OFRunLoopMode)runLoopMode { static const OFTLSStreamErrorCode initFailedErrorCode = OFTLSStreamErrorCodeInitializationFailed; void *pool = objc_autoreleasePoolPush(); id exception = nil; int status; if (_SSL != NULL) @throw [OFAlreadyOpenException exceptionWithObject: self]; if ((_readBIO = BIO_new(BIO_s_mem())) == NULL) @throw [OFTLSHandshakeFailedException exceptionWithStream: self host: host errorCode: initFailedErrorCode]; if ((_writeBIO = BIO_new(BIO_s_mem())) == NULL) { BIO_free(_readBIO); @throw [OFTLSHandshakeFailedException exceptionWithStream: self host: host errorCode: initFailedErrorCode]; } BIO_set_mem_eof_return(_readBIO, -1); BIO_set_mem_eof_return(_writeBIO, -1); if ((_SSL = SSL_new(clientContext)) == NULL) { BIO_free(_readBIO); BIO_free(_writeBIO); @throw [OFTLSHandshakeFailedException exceptionWithStream: self host: host errorCode: initFailedErrorCode]; } SSL_set_bio(_SSL, _readBIO, _writeBIO); SSL_set_connect_state(_SSL); _host = [host copy]; if (SSL_set_tlsext_host_name(_SSL, _host.UTF8String) != 1) @throw [OFTLSHandshakeFailedException exceptionWithStream: self host: host errorCode: initFailedErrorCode]; if (_verifiesCertificates) { SSL_set_verify(_SSL, SSL_VERIFY_PEER, NULL); if (SSL_set1_host(_SSL, _host.UTF8String) != 1) @throw [OFTLSHandshakeFailedException exceptionWithStream: self host: host errorCode: initFailedErrorCode]; } status = SSL_do_handshake(_SSL); while (BIO_ctrl_pending(_writeBIO) > 0) { int tmp = BIO_read(_writeBIO, _buffer, bufferSize); OFEnsure(tmp >= 0); [_underlyingStream writeBuffer: _buffer length: tmp]; [_underlyingStream flushWriteBuffer]; } if (status == 1) _handshakeDone = true; else { switch (SSL_get_error(_SSL, status)) { case SSL_ERROR_WANT_READ: [_underlyingStream asyncReadIntoBuffer: _buffer length: bufferSize runLoopMode: runLoopMode]; [_delegate retain]; objc_autoreleasePoolPop(pool); return; case SSL_ERROR_WANT_WRITE: [_underlyingStream asyncWriteData: [OFData data] runLoopMode: runLoopMode]; [_delegate retain]; objc_autoreleasePoolPop(pool); return; default: /* FIXME: Map to better errors */ exception = [OFTLSHandshakeFailedException exceptionWithStream: self host: host errorCode: OFTLSStreamErrorCodeUnknown]; break; } } if ([_delegate respondsToSelector: @selector(stream:didPerformClientHandshakeWithHost:exception:)]) [_delegate stream: self didPerformClientHandshakeWithHost: host exception: exception]; objc_autoreleasePoolPop(pool); } - (bool)stream: (OFStream *)stream didReadIntoBuffer: (void *)buffer length: (size_t)length exception: (nullable id)exception { if (exception == nil) { static const OFTLSStreamErrorCode unknownErrorCode = OFTLSStreamErrorCodeUnknown; int status; OFEnsure(length <= INT_MAX); OFEnsure(BIO_write(_readBIO, buffer, (int)length) == (int)length); status = SSL_do_handshake(_SSL); while (BIO_ctrl_pending(_writeBIO) > 0) { int tmp = BIO_read(_writeBIO, buffer, bufferSize); OFEnsure(tmp >= 0); [_underlyingStream writeBuffer: _buffer length: tmp]; [_underlyingStream flushWriteBuffer]; } if (status == 1) _handshakeDone = true; else { switch (SSL_get_error(_SSL, status)) { case SSL_ERROR_WANT_READ: return true; case SSL_ERROR_WANT_WRITE:; OFRunLoopMode runLoopMode = [OFRunLoop currentRunLoop].currentMode; [_underlyingStream asyncWriteData: [OFData data] runLoopMode: runLoopMode]; return false; default: exception = [OFTLSHandshakeFailedException exceptionWithStream: self host: _host errorCode: unknownErrorCode]; break; } } } if ([_delegate respondsToSelector: @selector(stream:didPerformClientHandshakeWithHost:exception:)]) [_delegate stream: self didPerformClientHandshakeWithHost: _host exception: exception]; [_delegate release]; return false; } - (OFData *)stream: (OFStream *)stream didWriteData: (OFData *)data bytesWritten: (size_t)bytesWritten exception: (id)exception { if (exception == nil) { static const OFTLSStreamErrorCode unknownErrorCode = OFTLSStreamErrorCodeUnknown; int status; OFRunLoopMode runLoopMode; while (BIO_ctrl_pending(_writeBIO) > 0) { int tmp = BIO_read(_writeBIO, _buffer, bufferSize); OFEnsure(tmp >= 0); [_underlyingStream writeBuffer: _buffer length: tmp]; [_underlyingStream flushWriteBuffer]; } status = SSL_do_handshake(_SSL); while (BIO_ctrl_pending(_writeBIO) > 0) { int tmp = BIO_read(_writeBIO, _buffer, bufferSize); OFEnsure(tmp >= 0); [_underlyingStream writeBuffer: _buffer length: tmp]; [_underlyingStream flushWriteBuffer]; } if (status == 1) _handshakeDone = true; else { switch (SSL_get_error(_SSL, status)) { case SSL_ERROR_WANT_READ: runLoopMode = [OFRunLoop currentRunLoop].currentMode; [_underlyingStream asyncReadIntoBuffer: _buffer length: bufferSize runLoopMode: runLoopMode]; return nil; case SSL_ERROR_WANT_WRITE: return data; default: exception = [OFTLSHandshakeFailedException exceptionWithStream: self host: _host errorCode: unknownErrorCode]; break; } } } if ([_delegate respondsToSelector: @selector(stream:didPerformClientHandshakeWithHost:exception:)]) [_delegate stream: self didPerformClientHandshakeWithHost: _host exception: exception]; [_delegate release]; return nil; } @end objfw-1.1.6/src/tls/OFSecureTransportTLSStream.h000066400000000000000000000017061465614216400215340ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFTLSStream.h" #include OF_ASSUME_NONNULL_BEGIN @interface OFSecureTransportTLSStream: OFTLSStream { SSLContextRef _context; OFString *_host; } @end OF_ASSUME_NONNULL_END objfw-1.1.6/src/tls/OFSecureTransportTLSStream.m000066400000000000000000000160521465614216400215410ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFSecureTransportTLSStream.h" #import "OFAlreadyOpenException.h" #import "OFNotOpenException.h" #import "OFReadFailedException.h" #import "OFTLSHandshakeFailedException.h" #import "OFWriteFailedException.h" int _ObjFWTLS_reference; static OSStatus readFunc(SSLConnectionRef connection, void *data, size_t *dataLength) { bool incomplete; size_t length; @try { length = [((OFTLSStream *)connection).underlyingStream readIntoBuffer: data length: *dataLength]; } @catch (OFReadFailedException *e) { if (e.errNo == EWOULDBLOCK || e.errNo == EAGAIN) { *dataLength = 0; return errSSLWouldBlock; } @throw e; } incomplete = (length < *dataLength); *dataLength = length; return (incomplete ? errSSLWouldBlock : noErr); } static OSStatus writeFunc(SSLConnectionRef connection, const void *data, size_t *dataLength) { @try { [((OFTLSStream *)connection).underlyingStream writeBuffer: data length: *dataLength]; } @catch (OFWriteFailedException *e) { *dataLength = e.bytesWritten; if (e.errNo == EWOULDBLOCK || e.errNo == EAGAIN) return errSSLWouldBlock; @throw e; } return noErr; } /* * Apple deprecated Secure Transport without providing a replacement that can * work with any socket. On top of that, their replacement, Network.framework, * doesn't support STARTTLS at all. */ #if OF_GCC_VERSION >= 402 # pragma GCC diagnostic ignored "-Wdeprecated" #endif @implementation OFSecureTransportTLSStream + (void)load { if (OFTLSStreamImplementation == Nil) OFTLSStreamImplementation = self; } - (instancetype)initWithStream: (OFStream *)stream { self = [super initWithStream: stream]; @try { _underlyingStream.delegate = self; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_context != NULL) [self close]; [_host release]; [super dealloc]; } - (void)close { if (_context == NULL) @throw [OFNotOpenException exceptionWithObject: self]; [_host release]; _host = nil; SSLClose(_context); #ifdef HAVE_SSLCREATECONTEXT CFRelease(_context); #else SSLDisposeContext(_context); #endif _context = NULL; [super close]; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { OSStatus status; size_t ret; if (_context == NULL) @throw [OFNotOpenException exceptionWithObject: self]; status = SSLRead(_context, buffer, length, &ret); if (status != noErr && status != errSSLWouldBlock) /* FIXME: Translate status to errNo */ @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: 0]; return ret; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { OSStatus status; size_t bytesWritten = 0; if (_context == NULL) @throw [OFNotOpenException exceptionWithObject: self]; status = SSLWrite(_context, buffer, length, &bytesWritten); if (status != noErr && status != errSSLWouldBlock) /* FIXME: Translate status to errNo */ @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: bytesWritten errNo: 0]; return bytesWritten; } - (bool)lowlevelHasDataInReadBuffer { size_t bufferSize; return (_underlyingStream.hasDataInReadBuffer || (SSLGetBufferedReadSize(_context, &bufferSize) == noErr && bufferSize > 0)); } - (void)asyncPerformClientHandshakeWithHost: (OFString *)host runLoopMode: (OFRunLoopMode)runLoopMode { static const OFTLSStreamErrorCode initFailedErrorCode = OFTLSStreamErrorCodeInitializationFailed; void *pool = objc_autoreleasePoolPush(); id exception = nil; OSStatus status; if (_context != NULL) @throw [OFAlreadyOpenException exceptionWithObject: self]; #ifdef HAVE_SSLCREATECONTEXT if ((_context = SSLCreateContext(kCFAllocatorDefault, kSSLClientSide, kSSLStreamType)) == NULL) #else if (SSLNewContext(false, &_context) != noErr) #endif @throw [OFTLSHandshakeFailedException exceptionWithStream: self host: host errorCode: initFailedErrorCode]; if (SSLSetIOFuncs(_context, readFunc, writeFunc) != noErr || SSLSetConnection(_context, self) != noErr) @throw [OFTLSHandshakeFailedException exceptionWithStream: self host: host errorCode: initFailedErrorCode]; _host = [host copy]; if (_verifiesCertificates) if (SSLSetPeerDomainName(_context, _host.UTF8String, _host.UTF8StringLength) != noErr) @throw [OFTLSHandshakeFailedException exceptionWithStream: self host: _host errorCode: initFailedErrorCode]; status = SSLHandshake(_context); if (status == errSSLWouldBlock) { /* * Theoretically it is possible we block because Secure * Transport cannot write without blocking. But unfortunately, * Secure Transport does not tell us whether it's blocked on * reading or writing. Waiting for the stream to be either * readable or writable doesn't work either, as the stream is * almost always at least ready for one of the two. */ [_underlyingStream asyncReadIntoBuffer: (void *)"" length: 0 runLoopMode: runLoopMode]; [_delegate retain]; objc_autoreleasePoolPop(pool); return; } if (status != noErr) /* FIXME: Map to better errors */ exception = [OFTLSHandshakeFailedException exceptionWithStream: self host: _host errorCode: OFTLSStreamErrorCodeUnknown]; if ([_delegate respondsToSelector: @selector(stream:didPerformClientHandshakeWithHost:exception:)]) [_delegate stream: self didPerformClientHandshakeWithHost: _host exception: exception]; objc_autoreleasePoolPop(pool); } - (bool)stream: (OFStream *)stream didReadIntoBuffer: (void *)buffer length: (size_t)length exception: (nullable id)exception { if (exception == nil) { OSStatus status = SSLHandshake(_context); if (status == errSSLWouldBlock) return true; if (status != noErr) exception = [OFTLSHandshakeFailedException exceptionWithStream: self host: _host errorCode: OFTLSStreamErrorCodeUnknown]; } if ([_delegate respondsToSelector: @selector(stream:didPerformClientHandshakeWithHost:exception:)]) [_delegate stream: self didPerformClientHandshakeWithHost: _host exception: exception]; [_delegate release]; return false; } @end objfw-1.1.6/src/tls/ObjFWTLS.h000066400000000000000000000015231465614216400157340ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "macros.h" #ifdef __cplusplus extern "C" { #endif extern int _ObjFWTLS_reference; #ifdef __cplusplus } #endif objfw-1.1.6/src/tls/ObjFWTLS.oc000066400000000000000000000002211465614216400161000ustar00rootroot00000000000000package_format 1 LIBS="-lobjfwtls $LIBS" FRAMEWORK_LIBS="-framework ObjFWTLS $FRAMEWORK_LIBS" STATIC_LIBS="${libdir}/libobjfwtls.a $STATIC_LIBS" objfw-1.1.6/src/unicode.h000066400000000000000000000027141465614216400152310ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFString.h" #define _OFUnicodeUppercaseTableSize 0x1EA #define _OFUnicodeLowercaseTableSize 0x1EA #define _OFUnicodeTitlecaseTableSize 0x1EA #define _OFUnicodeCaseFoldingTableSize 0x1EA #ifdef __cplusplus extern "C" { #endif extern const OFUnichar *const _Nonnull _OFUnicodeUppercaseTable[_OFUnicodeUppercaseTableSize] OF_VISIBILITY_HIDDEN; extern const OFUnichar *const _Nonnull _OFUnicodeLowercaseTable[_OFUnicodeLowercaseTableSize] OF_VISIBILITY_HIDDEN; extern const OFUnichar *const _Nonnull _OFUnicodeTitlecaseTable[_OFUnicodeTitlecaseTableSize] OF_VISIBILITY_HIDDEN; extern const OFUnichar *const _Nonnull _OFUnicodeCaseFoldingTable[_OFUnicodeCaseFoldingTableSize] OF_VISIBILITY_HIDDEN; #ifdef __cplusplus } #endif objfw-1.1.6/src/unicode.m000066400000000000000000002504421465614216400152410ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "unicode.h" static const OFUnichar emptyPage[0x100] = { 0 }; static const OFUnichar uppercasePage0[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 924, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 0, 216, 217, 218, 219, 220, 221, 222, 376, }; static const OFUnichar uppercasePage1[0x100] = { 0, 256, 0, 258, 0, 260, 0, 262, 0, 264, 0, 266, 0, 268, 0, 270, 0, 272, 0, 274, 0, 276, 0, 278, 0, 280, 0, 282, 0, 284, 0, 286, 0, 288, 0, 290, 0, 292, 0, 294, 0, 296, 0, 298, 0, 300, 0, 302, 0, 73, 0, 306, 0, 308, 0, 310, 0, 0, 313, 0, 315, 0, 317, 0, 319, 0, 321, 0, 323, 0, 325, 0, 327, 0, 0, 330, 0, 332, 0, 334, 0, 336, 0, 338, 0, 340, 0, 342, 0, 344, 0, 346, 0, 348, 0, 350, 0, 352, 0, 354, 0, 356, 0, 358, 0, 360, 0, 362, 0, 364, 0, 366, 0, 368, 0, 370, 0, 372, 0, 374, 0, 0, 377, 0, 379, 0, 381, 83, 579, 0, 0, 386, 0, 388, 0, 0, 391, 0, 0, 0, 395, 0, 0, 0, 0, 0, 401, 0, 0, 502, 0, 0, 0, 408, 573, 0, 0, 0, 544, 0, 0, 416, 0, 418, 0, 420, 0, 0, 423, 0, 0, 0, 0, 428, 0, 0, 431, 0, 0, 0, 435, 0, 437, 0, 0, 440, 0, 0, 0, 444, 0, 503, 0, 0, 0, 0, 0, 452, 452, 0, 455, 455, 0, 458, 458, 0, 461, 0, 463, 0, 465, 0, 467, 0, 469, 0, 471, 0, 473, 0, 475, 398, 0, 478, 0, 480, 0, 482, 0, 484, 0, 486, 0, 488, 0, 490, 0, 492, 0, 494, 0, 0, 497, 497, 0, 500, 0, 0, 0, 504, 0, 506, 0, 508, 0, 510, }; static const OFUnichar uppercasePage2[0x100] = { 0, 512, 0, 514, 0, 516, 0, 518, 0, 520, 0, 522, 0, 524, 0, 526, 0, 528, 0, 530, 0, 532, 0, 534, 0, 536, 0, 538, 0, 540, 0, 542, 0, 0, 0, 546, 0, 548, 0, 550, 0, 552, 0, 554, 0, 556, 0, 558, 0, 560, 0, 562, 0, 0, 0, 0, 0, 0, 0, 0, 571, 0, 0, 11390, 11391, 0, 577, 0, 0, 0, 0, 582, 0, 584, 0, 586, 0, 588, 0, 590, 11375, 11373, 11376, 385, 390, 0, 393, 394, 0, 399, 0, 400, 42923, 0, 0, 0, 403, 42924, 0, 404, 0, 42893, 42922, 0, 407, 406, 42926, 11362, 42925, 0, 0, 412, 0, 11374, 413, 0, 0, 415, 0, 0, 0, 0, 0, 0, 0, 11364, 0, 0, 422, 0, 42949, 425, 0, 0, 0, 42929, 430, 580, 433, 434, 581, 0, 0, 0, 0, 0, 439, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42930, 42928, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage3[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 921, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 880, 0, 882, 0, 0, 0, 886, 0, 0, 0, 1021, 1022, 1023, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 902, 904, 905, 906, 0, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 931, 931, 932, 933, 934, 935, 936, 937, 938, 939, 908, 910, 911, 0, 914, 920, 0, 0, 0, 934, 928, 975, 0, 984, 0, 986, 0, 988, 0, 990, 0, 992, 0, 994, 0, 996, 0, 998, 0, 1000, 0, 1002, 0, 1004, 0, 1006, 922, 929, 1017, 895, 0, 917, 0, 0, 1015, 0, 0, 1018, 0, 0, 0, 0, }; static const OFUnichar uppercasePage4[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1070, 1071, 1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 0, 1120, 0, 1122, 0, 1124, 0, 1126, 0, 1128, 0, 1130, 0, 1132, 0, 1134, 0, 1136, 0, 1138, 0, 1140, 0, 1142, 0, 1144, 0, 1146, 0, 1148, 0, 1150, 0, 1152, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1162, 0, 1164, 0, 1166, 0, 1168, 0, 1170, 0, 1172, 0, 1174, 0, 1176, 0, 1178, 0, 1180, 0, 1182, 0, 1184, 0, 1186, 0, 1188, 0, 1190, 0, 1192, 0, 1194, 0, 1196, 0, 1198, 0, 1200, 0, 1202, 0, 1204, 0, 1206, 0, 1208, 0, 1210, 0, 1212, 0, 1214, 0, 0, 1217, 0, 1219, 0, 1221, 0, 1223, 0, 1225, 0, 1227, 0, 1229, 1216, 0, 1232, 0, 1234, 0, 1236, 0, 1238, 0, 1240, 0, 1242, 0, 1244, 0, 1246, 0, 1248, 0, 1250, 0, 1252, 0, 1254, 0, 1256, 0, 1258, 0, 1260, 0, 1262, 0, 1264, 0, 1266, 0, 1268, 0, 1270, 0, 1272, 0, 1274, 0, 1276, 0, 1278, }; static const OFUnichar uppercasePage5[0x100] = { 0, 1280, 0, 1282, 0, 1284, 0, 1286, 0, 1288, 0, 1290, 0, 1292, 0, 1294, 0, 1296, 0, 1298, 0, 1300, 0, 1302, 0, 1304, 0, 1306, 0, 1308, 0, 1310, 0, 1312, 0, 1314, 0, 1316, 0, 1318, 0, 1320, 0, 1322, 0, 1324, 0, 1326, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1329, 1330, 1331, 1332, 1333, 1334, 1335, 1336, 1337, 1338, 1339, 1340, 1341, 1342, 1343, 1344, 1345, 1346, 1347, 1348, 1349, 1350, 1351, 1352, 1353, 1354, 1355, 1356, 1357, 1358, 1359, 1360, 1361, 1362, 1363, 1364, 1365, 1366, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage16[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7312, 7313, 7314, 7315, 7316, 7317, 7318, 7319, 7320, 7321, 7322, 7323, 7324, 7325, 7326, 7327, 7328, 7329, 7330, 7331, 7332, 7333, 7334, 7335, 7336, 7337, 7338, 7339, 7340, 7341, 7342, 7343, 7344, 7345, 7346, 7347, 7348, 7349, 7350, 7351, 7352, 7353, 7354, 0, 0, 7357, 7358, 7359, }; static const OFUnichar uppercasePage19[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5104, 5105, 5106, 5107, 5108, 5109, 0, 0, }; static const OFUnichar uppercasePage28[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1042, 1044, 1054, 1057, 1058, 1058, 1066, 1122, 42570, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage29[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42877, 0, 0, 0, 11363, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42950, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage30[0x100] = { 0, 7680, 0, 7682, 0, 7684, 0, 7686, 0, 7688, 0, 7690, 0, 7692, 0, 7694, 0, 7696, 0, 7698, 0, 7700, 0, 7702, 0, 7704, 0, 7706, 0, 7708, 0, 7710, 0, 7712, 0, 7714, 0, 7716, 0, 7718, 0, 7720, 0, 7722, 0, 7724, 0, 7726, 0, 7728, 0, 7730, 0, 7732, 0, 7734, 0, 7736, 0, 7738, 0, 7740, 0, 7742, 0, 7744, 0, 7746, 0, 7748, 0, 7750, 0, 7752, 0, 7754, 0, 7756, 0, 7758, 0, 7760, 0, 7762, 0, 7764, 0, 7766, 0, 7768, 0, 7770, 0, 7772, 0, 7774, 0, 7776, 0, 7778, 0, 7780, 0, 7782, 0, 7784, 0, 7786, 0, 7788, 0, 7790, 0, 7792, 0, 7794, 0, 7796, 0, 7798, 0, 7800, 0, 7802, 0, 7804, 0, 7806, 0, 7808, 0, 7810, 0, 7812, 0, 7814, 0, 7816, 0, 7818, 0, 7820, 0, 7822, 0, 7824, 0, 7826, 0, 7828, 0, 0, 0, 0, 0, 7776, 0, 0, 0, 0, 0, 7840, 0, 7842, 0, 7844, 0, 7846, 0, 7848, 0, 7850, 0, 7852, 0, 7854, 0, 7856, 0, 7858, 0, 7860, 0, 7862, 0, 7864, 0, 7866, 0, 7868, 0, 7870, 0, 7872, 0, 7874, 0, 7876, 0, 7878, 0, 7880, 0, 7882, 0, 7884, 0, 7886, 0, 7888, 0, 7890, 0, 7892, 0, 7894, 0, 7896, 0, 7898, 0, 7900, 0, 7902, 0, 7904, 0, 7906, 0, 7908, 0, 7910, 0, 7912, 0, 7914, 0, 7916, 0, 7918, 0, 7920, 0, 7922, 0, 7924, 0, 7926, 0, 7928, 0, 7930, 0, 7932, 0, 7934, }; static const OFUnichar uppercasePage31[0x100] = { 7944, 7945, 7946, 7947, 7948, 7949, 7950, 7951, 0, 0, 0, 0, 0, 0, 0, 0, 7960, 7961, 7962, 7963, 7964, 7965, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7976, 7977, 7978, 7979, 7980, 7981, 7982, 7983, 0, 0, 0, 0, 0, 0, 0, 0, 7992, 7993, 7994, 7995, 7996, 7997, 7998, 7999, 0, 0, 0, 0, 0, 0, 0, 0, 8008, 8009, 8010, 8011, 8012, 8013, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8025, 0, 8027, 0, 8029, 0, 8031, 0, 0, 0, 0, 0, 0, 0, 0, 8040, 8041, 8042, 8043, 8044, 8045, 8046, 8047, 0, 0, 0, 0, 0, 0, 0, 0, 8122, 8123, 8136, 8137, 8138, 8139, 8154, 8155, 8184, 8185, 8170, 8171, 8186, 8187, 0, 0, 8072, 8073, 8074, 8075, 8076, 8077, 8078, 8079, 0, 0, 0, 0, 0, 0, 0, 0, 8088, 8089, 8090, 8091, 8092, 8093, 8094, 8095, 0, 0, 0, 0, 0, 0, 0, 0, 8104, 8105, 8106, 8107, 8108, 8109, 8110, 8111, 0, 0, 0, 0, 0, 0, 0, 0, 8120, 8121, 0, 8124, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 921, 0, 0, 0, 0, 8140, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8152, 8153, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8168, 8169, 0, 0, 0, 8172, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8188, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage33[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8498, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8544, 8545, 8546, 8547, 8548, 8549, 8550, 8551, 8552, 8553, 8554, 8555, 8556, 8557, 8558, 8559, 0, 0, 0, 0, 8579, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage36[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9398, 9399, 9400, 9401, 9402, 9403, 9404, 9405, 9406, 9407, 9408, 9409, 9410, 9411, 9412, 9413, 9414, 9415, 9416, 9417, 9418, 9419, 9420, 9421, 9422, 9423, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage44[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11264, 11265, 11266, 11267, 11268, 11269, 11270, 11271, 11272, 11273, 11274, 11275, 11276, 11277, 11278, 11279, 11280, 11281, 11282, 11283, 11284, 11285, 11286, 11287, 11288, 11289, 11290, 11291, 11292, 11293, 11294, 11295, 11296, 11297, 11298, 11299, 11300, 11301, 11302, 11303, 11304, 11305, 11306, 11307, 11308, 11309, 11310, 11311, 0, 11360, 0, 0, 0, 570, 574, 0, 11367, 0, 11369, 0, 11371, 0, 0, 0, 0, 0, 0, 11378, 0, 0, 11381, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11392, 0, 11394, 0, 11396, 0, 11398, 0, 11400, 0, 11402, 0, 11404, 0, 11406, 0, 11408, 0, 11410, 0, 11412, 0, 11414, 0, 11416, 0, 11418, 0, 11420, 0, 11422, 0, 11424, 0, 11426, 0, 11428, 0, 11430, 0, 11432, 0, 11434, 0, 11436, 0, 11438, 0, 11440, 0, 11442, 0, 11444, 0, 11446, 0, 11448, 0, 11450, 0, 11452, 0, 11454, 0, 11456, 0, 11458, 0, 11460, 0, 11462, 0, 11464, 0, 11466, 0, 11468, 0, 11470, 0, 11472, 0, 11474, 0, 11476, 0, 11478, 0, 11480, 0, 11482, 0, 11484, 0, 11486, 0, 11488, 0, 11490, 0, 0, 0, 0, 0, 0, 0, 0, 11499, 0, 11501, 0, 0, 0, 0, 11506, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage45[0x100] = { 4256, 4257, 4258, 4259, 4260, 4261, 4262, 4263, 4264, 4265, 4266, 4267, 4268, 4269, 4270, 4271, 4272, 4273, 4274, 4275, 4276, 4277, 4278, 4279, 4280, 4281, 4282, 4283, 4284, 4285, 4286, 4287, 4288, 4289, 4290, 4291, 4292, 4293, 0, 4295, 0, 0, 0, 0, 0, 4301, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage166[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42560, 0, 42562, 0, 42564, 0, 42566, 0, 42568, 0, 42570, 0, 42572, 0, 42574, 0, 42576, 0, 42578, 0, 42580, 0, 42582, 0, 42584, 0, 42586, 0, 42588, 0, 42590, 0, 42592, 0, 42594, 0, 42596, 0, 42598, 0, 42600, 0, 42602, 0, 42604, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42624, 0, 42626, 0, 42628, 0, 42630, 0, 42632, 0, 42634, 0, 42636, 0, 42638, 0, 42640, 0, 42642, 0, 42644, 0, 42646, 0, 42648, 0, 42650, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage167[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42786, 0, 42788, 0, 42790, 0, 42792, 0, 42794, 0, 42796, 0, 42798, 0, 0, 0, 42802, 0, 42804, 0, 42806, 0, 42808, 0, 42810, 0, 42812, 0, 42814, 0, 42816, 0, 42818, 0, 42820, 0, 42822, 0, 42824, 0, 42826, 0, 42828, 0, 42830, 0, 42832, 0, 42834, 0, 42836, 0, 42838, 0, 42840, 0, 42842, 0, 42844, 0, 42846, 0, 42848, 0, 42850, 0, 42852, 0, 42854, 0, 42856, 0, 42858, 0, 42860, 0, 42862, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42873, 0, 42875, 0, 0, 42878, 0, 42880, 0, 42882, 0, 42884, 0, 42886, 0, 0, 0, 0, 42891, 0, 0, 0, 0, 42896, 0, 42898, 42948, 0, 0, 42902, 0, 42904, 0, 42906, 0, 42908, 0, 42910, 0, 42912, 0, 42914, 0, 42916, 0, 42918, 0, 42920, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42932, 0, 42934, 0, 42936, 0, 42938, 0, 42940, 0, 42942, 0, 42944, 0, 42946, 0, 0, 0, 0, 42951, 0, 42953, 0, 0, 0, 0, 0, 0, 42960, 0, 0, 0, 0, 0, 42966, 0, 42968, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42997, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage171[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42931, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5024, 5025, 5026, 5027, 5028, 5029, 5030, 5031, 5032, 5033, 5034, 5035, 5036, 5037, 5038, 5039, 5040, 5041, 5042, 5043, 5044, 5045, 5046, 5047, 5048, 5049, 5050, 5051, 5052, 5053, 5054, 5055, 5056, 5057, 5058, 5059, 5060, 5061, 5062, 5063, 5064, 5065, 5066, 5067, 5068, 5069, 5070, 5071, 5072, 5073, 5074, 5075, 5076, 5077, 5078, 5079, 5080, 5081, 5082, 5083, 5084, 5085, 5086, 5087, 5088, 5089, 5090, 5091, 5092, 5093, 5094, 5095, 5096, 5097, 5098, 5099, 5100, 5101, 5102, 5103, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage255[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65313, 65314, 65315, 65316, 65317, 65318, 65319, 65320, 65321, 65322, 65323, 65324, 65325, 65326, 65327, 65328, 65329, 65330, 65331, 65332, 65333, 65334, 65335, 65336, 65337, 65338, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage260[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66560, 66561, 66562, 66563, 66564, 66565, 66566, 66567, 66568, 66569, 66570, 66571, 66572, 66573, 66574, 66575, 66576, 66577, 66578, 66579, 66580, 66581, 66582, 66583, 66584, 66585, 66586, 66587, 66588, 66589, 66590, 66591, 66592, 66593, 66594, 66595, 66596, 66597, 66598, 66599, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66736, 66737, 66738, 66739, 66740, 66741, 66742, 66743, 66744, 66745, 66746, 66747, 66748, 66749, 66750, 66751, 66752, 66753, 66754, 66755, 66756, 66757, 66758, 66759, 66760, 66761, 66762, 66763, 66764, 66765, 66766, 66767, 66768, 66769, 66770, 66771, 0, 0, 0, 0, }; static const OFUnichar uppercasePage261[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66928, 66929, 66930, 66931, 66932, 66933, 66934, 66935, 66936, 66937, 66938, 0, 66940, 66941, 66942, 66943, 66944, 66945, 66946, 66947, 66948, 66949, 66950, 66951, 66952, 66953, 66954, 0, 66956, 66957, 66958, 66959, 66960, 66961, 66962, 0, 66964, 66965, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage268[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 68736, 68737, 68738, 68739, 68740, 68741, 68742, 68743, 68744, 68745, 68746, 68747, 68748, 68749, 68750, 68751, 68752, 68753, 68754, 68755, 68756, 68757, 68758, 68759, 68760, 68761, 68762, 68763, 68764, 68765, 68766, 68767, 68768, 68769, 68770, 68771, 68772, 68773, 68774, 68775, 68776, 68777, 68778, 68779, 68780, 68781, 68782, 68783, 68784, 68785, 68786, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage280[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 71840, 71841, 71842, 71843, 71844, 71845, 71846, 71847, 71848, 71849, 71850, 71851, 71852, 71853, 71854, 71855, 71856, 71857, 71858, 71859, 71860, 71861, 71862, 71863, 71864, 71865, 71866, 71867, 71868, 71869, 71870, 71871, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage366[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 93760, 93761, 93762, 93763, 93764, 93765, 93766, 93767, 93768, 93769, 93770, 93771, 93772, 93773, 93774, 93775, 93776, 93777, 93778, 93779, 93780, 93781, 93782, 93783, 93784, 93785, 93786, 93787, 93788, 93789, 93790, 93791, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage489[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 125184, 125185, 125186, 125187, 125188, 125189, 125190, 125191, 125192, 125193, 125194, 125195, 125196, 125197, 125198, 125199, 125200, 125201, 125202, 125203, 125204, 125205, 125206, 125207, 125208, 125209, 125210, 125211, 125212, 125213, 125214, 125215, 125216, 125217, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage0[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 0, 248, 249, 250, 251, 252, 253, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage1[0x100] = { 257, 0, 259, 0, 261, 0, 263, 0, 265, 0, 267, 0, 269, 0, 271, 0, 273, 0, 275, 0, 277, 0, 279, 0, 281, 0, 283, 0, 285, 0, 287, 0, 289, 0, 291, 0, 293, 0, 295, 0, 297, 0, 299, 0, 301, 0, 303, 0, 105, 0, 307, 0, 309, 0, 311, 0, 0, 314, 0, 316, 0, 318, 0, 320, 0, 322, 0, 324, 0, 326, 0, 328, 0, 0, 331, 0, 333, 0, 335, 0, 337, 0, 339, 0, 341, 0, 343, 0, 345, 0, 347, 0, 349, 0, 351, 0, 353, 0, 355, 0, 357, 0, 359, 0, 361, 0, 363, 0, 365, 0, 367, 0, 369, 0, 371, 0, 373, 0, 375, 0, 255, 378, 0, 380, 0, 382, 0, 0, 0, 595, 387, 0, 389, 0, 596, 392, 0, 598, 599, 396, 0, 0, 477, 601, 603, 402, 0, 608, 611, 0, 617, 616, 409, 0, 0, 0, 623, 626, 0, 629, 417, 0, 419, 0, 421, 0, 640, 424, 0, 643, 0, 0, 429, 0, 648, 432, 0, 650, 651, 436, 0, 438, 0, 658, 441, 0, 0, 0, 445, 0, 0, 0, 0, 0, 0, 0, 454, 454, 0, 457, 457, 0, 460, 460, 0, 462, 0, 464, 0, 466, 0, 468, 0, 470, 0, 472, 0, 474, 0, 476, 0, 0, 479, 0, 481, 0, 483, 0, 485, 0, 487, 0, 489, 0, 491, 0, 493, 0, 495, 0, 0, 499, 499, 0, 501, 0, 405, 447, 505, 0, 507, 0, 509, 0, 511, 0, }; static const OFUnichar lowercasePage2[0x100] = { 513, 0, 515, 0, 517, 0, 519, 0, 521, 0, 523, 0, 525, 0, 527, 0, 529, 0, 531, 0, 533, 0, 535, 0, 537, 0, 539, 0, 541, 0, 543, 0, 414, 0, 547, 0, 549, 0, 551, 0, 553, 0, 555, 0, 557, 0, 559, 0, 561, 0, 563, 0, 0, 0, 0, 0, 0, 0, 11365, 572, 0, 410, 11366, 0, 0, 578, 0, 384, 649, 652, 583, 0, 585, 0, 587, 0, 589, 0, 591, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage3[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 881, 0, 883, 0, 0, 0, 887, 0, 0, 0, 0, 0, 0, 0, 0, 1011, 0, 0, 0, 0, 0, 0, 940, 0, 941, 942, 943, 0, 972, 0, 973, 974, 0, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 0, 963, 964, 965, 966, 967, 968, 969, 970, 971, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 983, 0, 0, 0, 0, 0, 0, 0, 0, 985, 0, 987, 0, 989, 0, 991, 0, 993, 0, 995, 0, 997, 0, 999, 0, 1001, 0, 1003, 0, 1005, 0, 1007, 0, 0, 0, 0, 0, 952, 0, 0, 1016, 0, 1010, 1019, 0, 0, 891, 892, 893, }; static const OFUnichar lowercasePage4[0x100] = { 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1121, 0, 1123, 0, 1125, 0, 1127, 0, 1129, 0, 1131, 0, 1133, 0, 1135, 0, 1137, 0, 1139, 0, 1141, 0, 1143, 0, 1145, 0, 1147, 0, 1149, 0, 1151, 0, 1153, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1163, 0, 1165, 0, 1167, 0, 1169, 0, 1171, 0, 1173, 0, 1175, 0, 1177, 0, 1179, 0, 1181, 0, 1183, 0, 1185, 0, 1187, 0, 1189, 0, 1191, 0, 1193, 0, 1195, 0, 1197, 0, 1199, 0, 1201, 0, 1203, 0, 1205, 0, 1207, 0, 1209, 0, 1211, 0, 1213, 0, 1215, 0, 1231, 1218, 0, 1220, 0, 1222, 0, 1224, 0, 1226, 0, 1228, 0, 1230, 0, 0, 1233, 0, 1235, 0, 1237, 0, 1239, 0, 1241, 0, 1243, 0, 1245, 0, 1247, 0, 1249, 0, 1251, 0, 1253, 0, 1255, 0, 1257, 0, 1259, 0, 1261, 0, 1263, 0, 1265, 0, 1267, 0, 1269, 0, 1271, 0, 1273, 0, 1275, 0, 1277, 0, 1279, 0, }; static const OFUnichar lowercasePage5[0x100] = { 1281, 0, 1283, 0, 1285, 0, 1287, 0, 1289, 0, 1291, 0, 1293, 0, 1295, 0, 1297, 0, 1299, 0, 1301, 0, 1303, 0, 1305, 0, 1307, 0, 1309, 0, 1311, 0, 1313, 0, 1315, 0, 1317, 0, 1319, 0, 1321, 0, 1323, 0, 1325, 0, 1327, 0, 0, 1377, 1378, 1379, 1380, 1381, 1382, 1383, 1384, 1385, 1386, 1387, 1388, 1389, 1390, 1391, 1392, 1393, 1394, 1395, 1396, 1397, 1398, 1399, 1400, 1401, 1402, 1403, 1404, 1405, 1406, 1407, 1408, 1409, 1410, 1411, 1412, 1413, 1414, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage16[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11520, 11521, 11522, 11523, 11524, 11525, 11526, 11527, 11528, 11529, 11530, 11531, 11532, 11533, 11534, 11535, 11536, 11537, 11538, 11539, 11540, 11541, 11542, 11543, 11544, 11545, 11546, 11547, 11548, 11549, 11550, 11551, 11552, 11553, 11554, 11555, 11556, 11557, 0, 11559, 0, 0, 0, 0, 0, 11565, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage19[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 43888, 43889, 43890, 43891, 43892, 43893, 43894, 43895, 43896, 43897, 43898, 43899, 43900, 43901, 43902, 43903, 43904, 43905, 43906, 43907, 43908, 43909, 43910, 43911, 43912, 43913, 43914, 43915, 43916, 43917, 43918, 43919, 43920, 43921, 43922, 43923, 43924, 43925, 43926, 43927, 43928, 43929, 43930, 43931, 43932, 43933, 43934, 43935, 43936, 43937, 43938, 43939, 43940, 43941, 43942, 43943, 43944, 43945, 43946, 43947, 43948, 43949, 43950, 43951, 43952, 43953, 43954, 43955, 43956, 43957, 43958, 43959, 43960, 43961, 43962, 43963, 43964, 43965, 43966, 43967, 5112, 5113, 5114, 5115, 5116, 5117, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage28[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4304, 4305, 4306, 4307, 4308, 4309, 4310, 4311, 4312, 4313, 4314, 4315, 4316, 4317, 4318, 4319, 4320, 4321, 4322, 4323, 4324, 4325, 4326, 4327, 4328, 4329, 4330, 4331, 4332, 4333, 4334, 4335, 4336, 4337, 4338, 4339, 4340, 4341, 4342, 4343, 4344, 4345, 4346, 0, 0, 4349, 4350, 4351, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage30[0x100] = { 7681, 0, 7683, 0, 7685, 0, 7687, 0, 7689, 0, 7691, 0, 7693, 0, 7695, 0, 7697, 0, 7699, 0, 7701, 0, 7703, 0, 7705, 0, 7707, 0, 7709, 0, 7711, 0, 7713, 0, 7715, 0, 7717, 0, 7719, 0, 7721, 0, 7723, 0, 7725, 0, 7727, 0, 7729, 0, 7731, 0, 7733, 0, 7735, 0, 7737, 0, 7739, 0, 7741, 0, 7743, 0, 7745, 0, 7747, 0, 7749, 0, 7751, 0, 7753, 0, 7755, 0, 7757, 0, 7759, 0, 7761, 0, 7763, 0, 7765, 0, 7767, 0, 7769, 0, 7771, 0, 7773, 0, 7775, 0, 7777, 0, 7779, 0, 7781, 0, 7783, 0, 7785, 0, 7787, 0, 7789, 0, 7791, 0, 7793, 0, 7795, 0, 7797, 0, 7799, 0, 7801, 0, 7803, 0, 7805, 0, 7807, 0, 7809, 0, 7811, 0, 7813, 0, 7815, 0, 7817, 0, 7819, 0, 7821, 0, 7823, 0, 7825, 0, 7827, 0, 7829, 0, 0, 0, 0, 0, 0, 0, 0, 0, 223, 0, 7841, 0, 7843, 0, 7845, 0, 7847, 0, 7849, 0, 7851, 0, 7853, 0, 7855, 0, 7857, 0, 7859, 0, 7861, 0, 7863, 0, 7865, 0, 7867, 0, 7869, 0, 7871, 0, 7873, 0, 7875, 0, 7877, 0, 7879, 0, 7881, 0, 7883, 0, 7885, 0, 7887, 0, 7889, 0, 7891, 0, 7893, 0, 7895, 0, 7897, 0, 7899, 0, 7901, 0, 7903, 0, 7905, 0, 7907, 0, 7909, 0, 7911, 0, 7913, 0, 7915, 0, 7917, 0, 7919, 0, 7921, 0, 7923, 0, 7925, 0, 7927, 0, 7929, 0, 7931, 0, 7933, 0, 7935, 0, }; static const OFUnichar lowercasePage31[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 7936, 7937, 7938, 7939, 7940, 7941, 7942, 7943, 0, 0, 0, 0, 0, 0, 0, 0, 7952, 7953, 7954, 7955, 7956, 7957, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7968, 7969, 7970, 7971, 7972, 7973, 7974, 7975, 0, 0, 0, 0, 0, 0, 0, 0, 7984, 7985, 7986, 7987, 7988, 7989, 7990, 7991, 0, 0, 0, 0, 0, 0, 0, 0, 8000, 8001, 8002, 8003, 8004, 8005, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8017, 0, 8019, 0, 8021, 0, 8023, 0, 0, 0, 0, 0, 0, 0, 0, 8032, 8033, 8034, 8035, 8036, 8037, 8038, 8039, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8064, 8065, 8066, 8067, 8068, 8069, 8070, 8071, 0, 0, 0, 0, 0, 0, 0, 0, 8080, 8081, 8082, 8083, 8084, 8085, 8086, 8087, 0, 0, 0, 0, 0, 0, 0, 0, 8096, 8097, 8098, 8099, 8100, 8101, 8102, 8103, 0, 0, 0, 0, 0, 0, 0, 0, 8112, 8113, 8048, 8049, 8115, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8050, 8051, 8052, 8053, 8131, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8144, 8145, 8054, 8055, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8160, 8161, 8058, 8059, 8165, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8056, 8057, 8060, 8061, 8179, 0, 0, 0, }; static const OFUnichar lowercasePage33[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 969, 0, 0, 0, 107, 229, 0, 0, 0, 0, 0, 0, 8526, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8560, 8561, 8562, 8563, 8564, 8565, 8566, 8567, 8568, 8569, 8570, 8571, 8572, 8573, 8574, 8575, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8580, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage36[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9424, 9425, 9426, 9427, 9428, 9429, 9430, 9431, 9432, 9433, 9434, 9435, 9436, 9437, 9438, 9439, 9440, 9441, 9442, 9443, 9444, 9445, 9446, 9447, 9448, 9449, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage44[0x100] = { 11312, 11313, 11314, 11315, 11316, 11317, 11318, 11319, 11320, 11321, 11322, 11323, 11324, 11325, 11326, 11327, 11328, 11329, 11330, 11331, 11332, 11333, 11334, 11335, 11336, 11337, 11338, 11339, 11340, 11341, 11342, 11343, 11344, 11345, 11346, 11347, 11348, 11349, 11350, 11351, 11352, 11353, 11354, 11355, 11356, 11357, 11358, 11359, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11361, 0, 619, 7549, 637, 0, 0, 11368, 0, 11370, 0, 11372, 0, 593, 625, 592, 594, 0, 11379, 0, 0, 11382, 0, 0, 0, 0, 0, 0, 0, 0, 575, 576, 11393, 0, 11395, 0, 11397, 0, 11399, 0, 11401, 0, 11403, 0, 11405, 0, 11407, 0, 11409, 0, 11411, 0, 11413, 0, 11415, 0, 11417, 0, 11419, 0, 11421, 0, 11423, 0, 11425, 0, 11427, 0, 11429, 0, 11431, 0, 11433, 0, 11435, 0, 11437, 0, 11439, 0, 11441, 0, 11443, 0, 11445, 0, 11447, 0, 11449, 0, 11451, 0, 11453, 0, 11455, 0, 11457, 0, 11459, 0, 11461, 0, 11463, 0, 11465, 0, 11467, 0, 11469, 0, 11471, 0, 11473, 0, 11475, 0, 11477, 0, 11479, 0, 11481, 0, 11483, 0, 11485, 0, 11487, 0, 11489, 0, 11491, 0, 0, 0, 0, 0, 0, 0, 0, 11500, 0, 11502, 0, 0, 0, 0, 11507, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage166[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42561, 0, 42563, 0, 42565, 0, 42567, 0, 42569, 0, 42571, 0, 42573, 0, 42575, 0, 42577, 0, 42579, 0, 42581, 0, 42583, 0, 42585, 0, 42587, 0, 42589, 0, 42591, 0, 42593, 0, 42595, 0, 42597, 0, 42599, 0, 42601, 0, 42603, 0, 42605, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42625, 0, 42627, 0, 42629, 0, 42631, 0, 42633, 0, 42635, 0, 42637, 0, 42639, 0, 42641, 0, 42643, 0, 42645, 0, 42647, 0, 42649, 0, 42651, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage167[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42787, 0, 42789, 0, 42791, 0, 42793, 0, 42795, 0, 42797, 0, 42799, 0, 0, 0, 42803, 0, 42805, 0, 42807, 0, 42809, 0, 42811, 0, 42813, 0, 42815, 0, 42817, 0, 42819, 0, 42821, 0, 42823, 0, 42825, 0, 42827, 0, 42829, 0, 42831, 0, 42833, 0, 42835, 0, 42837, 0, 42839, 0, 42841, 0, 42843, 0, 42845, 0, 42847, 0, 42849, 0, 42851, 0, 42853, 0, 42855, 0, 42857, 0, 42859, 0, 42861, 0, 42863, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42874, 0, 42876, 0, 7545, 42879, 0, 42881, 0, 42883, 0, 42885, 0, 42887, 0, 0, 0, 0, 42892, 0, 613, 0, 0, 42897, 0, 42899, 0, 0, 0, 42903, 0, 42905, 0, 42907, 0, 42909, 0, 42911, 0, 42913, 0, 42915, 0, 42917, 0, 42919, 0, 42921, 0, 614, 604, 609, 620, 618, 0, 670, 647, 669, 43859, 42933, 0, 42935, 0, 42937, 0, 42939, 0, 42941, 0, 42943, 0, 42945, 0, 42947, 0, 42900, 642, 7566, 42952, 0, 42954, 0, 0, 0, 0, 0, 0, 42961, 0, 0, 0, 0, 0, 42967, 0, 42969, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42998, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage255[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65345, 65346, 65347, 65348, 65349, 65350, 65351, 65352, 65353, 65354, 65355, 65356, 65357, 65358, 65359, 65360, 65361, 65362, 65363, 65364, 65365, 65366, 65367, 65368, 65369, 65370, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage260[0x100] = { 66600, 66601, 66602, 66603, 66604, 66605, 66606, 66607, 66608, 66609, 66610, 66611, 66612, 66613, 66614, 66615, 66616, 66617, 66618, 66619, 66620, 66621, 66622, 66623, 66624, 66625, 66626, 66627, 66628, 66629, 66630, 66631, 66632, 66633, 66634, 66635, 66636, 66637, 66638, 66639, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66776, 66777, 66778, 66779, 66780, 66781, 66782, 66783, 66784, 66785, 66786, 66787, 66788, 66789, 66790, 66791, 66792, 66793, 66794, 66795, 66796, 66797, 66798, 66799, 66800, 66801, 66802, 66803, 66804, 66805, 66806, 66807, 66808, 66809, 66810, 66811, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage261[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66967, 66968, 66969, 66970, 66971, 66972, 66973, 66974, 66975, 66976, 66977, 0, 66979, 66980, 66981, 66982, 66983, 66984, 66985, 66986, 66987, 66988, 66989, 66990, 66991, 66992, 66993, 0, 66995, 66996, 66997, 66998, 66999, 67000, 67001, 0, 67003, 67004, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage268[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 68800, 68801, 68802, 68803, 68804, 68805, 68806, 68807, 68808, 68809, 68810, 68811, 68812, 68813, 68814, 68815, 68816, 68817, 68818, 68819, 68820, 68821, 68822, 68823, 68824, 68825, 68826, 68827, 68828, 68829, 68830, 68831, 68832, 68833, 68834, 68835, 68836, 68837, 68838, 68839, 68840, 68841, 68842, 68843, 68844, 68845, 68846, 68847, 68848, 68849, 68850, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage280[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 71872, 71873, 71874, 71875, 71876, 71877, 71878, 71879, 71880, 71881, 71882, 71883, 71884, 71885, 71886, 71887, 71888, 71889, 71890, 71891, 71892, 71893, 71894, 71895, 71896, 71897, 71898, 71899, 71900, 71901, 71902, 71903, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage366[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 93792, 93793, 93794, 93795, 93796, 93797, 93798, 93799, 93800, 93801, 93802, 93803, 93804, 93805, 93806, 93807, 93808, 93809, 93810, 93811, 93812, 93813, 93814, 93815, 93816, 93817, 93818, 93819, 93820, 93821, 93822, 93823, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage489[0x100] = { 125218, 125219, 125220, 125221, 125222, 125223, 125224, 125225, 125226, 125227, 125228, 125229, 125230, 125231, 125232, 125233, 125234, 125235, 125236, 125237, 125238, 125239, 125240, 125241, 125242, 125243, 125244, 125245, 125246, 125247, 125248, 125249, 125250, 125251, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar titlecasePage1[0x100] = { 0, 256, 0, 258, 0, 260, 0, 262, 0, 264, 0, 266, 0, 268, 0, 270, 0, 272, 0, 274, 0, 276, 0, 278, 0, 280, 0, 282, 0, 284, 0, 286, 0, 288, 0, 290, 0, 292, 0, 294, 0, 296, 0, 298, 0, 300, 0, 302, 0, 73, 0, 306, 0, 308, 0, 310, 0, 0, 313, 0, 315, 0, 317, 0, 319, 0, 321, 0, 323, 0, 325, 0, 327, 0, 0, 330, 0, 332, 0, 334, 0, 336, 0, 338, 0, 340, 0, 342, 0, 344, 0, 346, 0, 348, 0, 350, 0, 352, 0, 354, 0, 356, 0, 358, 0, 360, 0, 362, 0, 364, 0, 366, 0, 368, 0, 370, 0, 372, 0, 374, 0, 0, 377, 0, 379, 0, 381, 83, 579, 0, 0, 386, 0, 388, 0, 0, 391, 0, 0, 0, 395, 0, 0, 0, 0, 0, 401, 0, 0, 502, 0, 0, 0, 408, 573, 0, 0, 0, 544, 0, 0, 416, 0, 418, 0, 420, 0, 0, 423, 0, 0, 0, 0, 428, 0, 0, 431, 0, 0, 0, 435, 0, 437, 0, 0, 440, 0, 0, 0, 444, 0, 503, 0, 0, 0, 0, 453, 453, 453, 456, 456, 456, 459, 459, 459, 0, 461, 0, 463, 0, 465, 0, 467, 0, 469, 0, 471, 0, 473, 0, 475, 398, 0, 478, 0, 480, 0, 482, 0, 484, 0, 486, 0, 488, 0, 490, 0, 492, 0, 494, 0, 498, 498, 498, 0, 500, 0, 0, 0, 504, 0, 506, 0, 508, 0, 510, }; static const OFUnichar titlecasePage16[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4304, 4305, 4306, 4307, 4308, 4309, 4310, 4311, 4312, 4313, 4314, 4315, 4316, 4317, 4318, 4319, 4320, 4321, 4322, 4323, 4324, 4325, 4326, 4327, 4328, 4329, 4330, 4331, 4332, 4333, 4334, 4335, 4336, 4337, 4338, 4339, 4340, 4341, 4342, 4343, 4344, 4345, 4346, 0, 0, 4349, 4350, 4351, }; static const OFUnichar caseFoldingPage0[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 956, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 0, 248, 249, 250, 251, 252, 253, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar caseFoldingPage1[0x100] = { 257, 0, 259, 0, 261, 0, 263, 0, 265, 0, 267, 0, 269, 0, 271, 0, 273, 0, 275, 0, 277, 0, 279, 0, 281, 0, 283, 0, 285, 0, 287, 0, 289, 0, 291, 0, 293, 0, 295, 0, 297, 0, 299, 0, 301, 0, 303, 0, 0, 0, 307, 0, 309, 0, 311, 0, 0, 314, 0, 316, 0, 318, 0, 320, 0, 322, 0, 324, 0, 326, 0, 328, 0, 0, 331, 0, 333, 0, 335, 0, 337, 0, 339, 0, 341, 0, 343, 0, 345, 0, 347, 0, 349, 0, 351, 0, 353, 0, 355, 0, 357, 0, 359, 0, 361, 0, 363, 0, 365, 0, 367, 0, 369, 0, 371, 0, 373, 0, 375, 0, 255, 378, 0, 380, 0, 382, 0, 115, 0, 595, 387, 0, 389, 0, 596, 392, 0, 598, 599, 396, 0, 0, 477, 601, 603, 402, 0, 608, 611, 0, 617, 616, 409, 0, 0, 0, 623, 626, 0, 629, 417, 0, 419, 0, 421, 0, 640, 424, 0, 643, 0, 0, 429, 0, 648, 432, 0, 650, 651, 436, 0, 438, 0, 658, 441, 0, 0, 0, 445, 0, 0, 0, 0, 0, 0, 0, 454, 454, 0, 457, 457, 0, 460, 460, 0, 462, 0, 464, 0, 466, 0, 468, 0, 470, 0, 472, 0, 474, 0, 476, 0, 0, 479, 0, 481, 0, 483, 0, 485, 0, 487, 0, 489, 0, 491, 0, 493, 0, 495, 0, 0, 499, 499, 0, 501, 0, 405, 447, 505, 0, 507, 0, 509, 0, 511, 0, }; static const OFUnichar caseFoldingPage3[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 953, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 881, 0, 883, 0, 0, 0, 887, 0, 0, 0, 0, 0, 0, 0, 0, 1011, 0, 0, 0, 0, 0, 0, 940, 0, 941, 942, 943, 0, 972, 0, 973, 974, 0, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 0, 963, 964, 965, 966, 967, 968, 969, 970, 971, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 963, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 983, 946, 952, 0, 0, 0, 966, 960, 0, 985, 0, 987, 0, 989, 0, 991, 0, 993, 0, 995, 0, 997, 0, 999, 0, 1001, 0, 1003, 0, 1005, 0, 1007, 0, 954, 961, 0, 0, 952, 949, 0, 1016, 0, 1010, 1019, 0, 0, 891, 892, 893, }; static const OFUnichar caseFoldingPage19[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5104, 5105, 5106, 5107, 5108, 5109, 0, 0, }; static const OFUnichar caseFoldingPage28[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1074, 1076, 1086, 1089, 1090, 1090, 1098, 1123, 42571, 0, 0, 0, 0, 0, 0, 0, 4304, 4305, 4306, 4307, 4308, 4309, 4310, 4311, 4312, 4313, 4314, 4315, 4316, 4317, 4318, 4319, 4320, 4321, 4322, 4323, 4324, 4325, 4326, 4327, 4328, 4329, 4330, 4331, 4332, 4333, 4334, 4335, 4336, 4337, 4338, 4339, 4340, 4341, 4342, 4343, 4344, 4345, 4346, 0, 0, 4349, 4350, 4351, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar caseFoldingPage30[0x100] = { 7681, 0, 7683, 0, 7685, 0, 7687, 0, 7689, 0, 7691, 0, 7693, 0, 7695, 0, 7697, 0, 7699, 0, 7701, 0, 7703, 0, 7705, 0, 7707, 0, 7709, 0, 7711, 0, 7713, 0, 7715, 0, 7717, 0, 7719, 0, 7721, 0, 7723, 0, 7725, 0, 7727, 0, 7729, 0, 7731, 0, 7733, 0, 7735, 0, 7737, 0, 7739, 0, 7741, 0, 7743, 0, 7745, 0, 7747, 0, 7749, 0, 7751, 0, 7753, 0, 7755, 0, 7757, 0, 7759, 0, 7761, 0, 7763, 0, 7765, 0, 7767, 0, 7769, 0, 7771, 0, 7773, 0, 7775, 0, 7777, 0, 7779, 0, 7781, 0, 7783, 0, 7785, 0, 7787, 0, 7789, 0, 7791, 0, 7793, 0, 7795, 0, 7797, 0, 7799, 0, 7801, 0, 7803, 0, 7805, 0, 7807, 0, 7809, 0, 7811, 0, 7813, 0, 7815, 0, 7817, 0, 7819, 0, 7821, 0, 7823, 0, 7825, 0, 7827, 0, 7829, 0, 0, 0, 0, 0, 0, 7777, 0, 0, 223, 0, 7841, 0, 7843, 0, 7845, 0, 7847, 0, 7849, 0, 7851, 0, 7853, 0, 7855, 0, 7857, 0, 7859, 0, 7861, 0, 7863, 0, 7865, 0, 7867, 0, 7869, 0, 7871, 0, 7873, 0, 7875, 0, 7877, 0, 7879, 0, 7881, 0, 7883, 0, 7885, 0, 7887, 0, 7889, 0, 7891, 0, 7893, 0, 7895, 0, 7897, 0, 7899, 0, 7901, 0, 7903, 0, 7905, 0, 7907, 0, 7909, 0, 7911, 0, 7913, 0, 7915, 0, 7917, 0, 7919, 0, 7921, 0, 7923, 0, 7925, 0, 7927, 0, 7929, 0, 7931, 0, 7933, 0, 7935, 0, }; static const OFUnichar caseFoldingPage31[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 7936, 7937, 7938, 7939, 7940, 7941, 7942, 7943, 0, 0, 0, 0, 0, 0, 0, 0, 7952, 7953, 7954, 7955, 7956, 7957, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7968, 7969, 7970, 7971, 7972, 7973, 7974, 7975, 0, 0, 0, 0, 0, 0, 0, 0, 7984, 7985, 7986, 7987, 7988, 7989, 7990, 7991, 0, 0, 0, 0, 0, 0, 0, 0, 8000, 8001, 8002, 8003, 8004, 8005, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8017, 0, 8019, 0, 8021, 0, 8023, 0, 0, 0, 0, 0, 0, 0, 0, 8032, 8033, 8034, 8035, 8036, 8037, 8038, 8039, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8064, 8065, 8066, 8067, 8068, 8069, 8070, 8071, 0, 0, 0, 0, 0, 0, 0, 0, 8080, 8081, 8082, 8083, 8084, 8085, 8086, 8087, 0, 0, 0, 0, 0, 0, 0, 0, 8096, 8097, 8098, 8099, 8100, 8101, 8102, 8103, 0, 0, 0, 0, 0, 0, 0, 0, 8112, 8113, 8048, 8049, 8115, 0, 953, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8050, 8051, 8052, 8053, 8131, 0, 0, 0, 0, 0, 0, 912, 0, 0, 0, 0, 8144, 8145, 8054, 8055, 0, 0, 0, 0, 0, 0, 0, 944, 0, 0, 0, 0, 8160, 8161, 8058, 8059, 8165, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8056, 8057, 8060, 8061, 8179, 0, 0, 0, }; static const OFUnichar caseFoldingPage171[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5024, 5025, 5026, 5027, 5028, 5029, 5030, 5031, 5032, 5033, 5034, 5035, 5036, 5037, 5038, 5039, 5040, 5041, 5042, 5043, 5044, 5045, 5046, 5047, 5048, 5049, 5050, 5051, 5052, 5053, 5054, 5055, 5056, 5057, 5058, 5059, 5060, 5061, 5062, 5063, 5064, 5065, 5066, 5067, 5068, 5069, 5070, 5071, 5072, 5073, 5074, 5075, 5076, 5077, 5078, 5079, 5080, 5081, 5082, 5083, 5084, 5085, 5086, 5087, 5088, 5089, 5090, 5091, 5092, 5093, 5094, 5095, 5096, 5097, 5098, 5099, 5100, 5101, 5102, 5103, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar caseFoldingPage251[0x100] = { 0, 0, 0, 0, 0, 64262, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; const OFUnichar *const _OFUnicodeUppercaseTable[0x1EA] = { uppercasePage0, uppercasePage1, uppercasePage2, uppercasePage3, uppercasePage4, uppercasePage5, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, uppercasePage16, emptyPage, emptyPage, uppercasePage19, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, uppercasePage28, uppercasePage29, uppercasePage30, uppercasePage31, emptyPage, uppercasePage33, emptyPage, emptyPage, uppercasePage36, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, uppercasePage44, uppercasePage45, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, uppercasePage166, uppercasePage167, emptyPage, emptyPage, emptyPage, uppercasePage171, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, uppercasePage255, emptyPage, emptyPage, emptyPage, emptyPage, uppercasePage260, uppercasePage261, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, uppercasePage268, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, uppercasePage280, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, uppercasePage366, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, uppercasePage489 }; const OFUnichar *const _OFUnicodeLowercaseTable[0x1EA] = { lowercasePage0, lowercasePage1, lowercasePage2, lowercasePage3, lowercasePage4, lowercasePage5, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage16, emptyPage, emptyPage, lowercasePage19, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage28, emptyPage, lowercasePage30, lowercasePage31, emptyPage, lowercasePage33, emptyPage, emptyPage, lowercasePage36, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage44, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage166, lowercasePage167, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage255, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage260, lowercasePage261, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage268, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage280, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage366, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage489 }; const OFUnichar *const _OFUnicodeTitlecaseTable[0x1EA] = { uppercasePage0, titlecasePage1, uppercasePage2, uppercasePage3, uppercasePage4, uppercasePage5, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, titlecasePage16, emptyPage, emptyPage, uppercasePage19, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, uppercasePage28, uppercasePage29, uppercasePage30, uppercasePage31, emptyPage, uppercasePage33, emptyPage, emptyPage, uppercasePage36, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, uppercasePage44, uppercasePage45, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, uppercasePage166, uppercasePage167, emptyPage, emptyPage, emptyPage, uppercasePage171, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, uppercasePage255, emptyPage, emptyPage, emptyPage, emptyPage, uppercasePage260, uppercasePage261, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, uppercasePage268, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, uppercasePage280, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, uppercasePage366, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, uppercasePage489 }; const OFUnichar *const _OFUnicodeCaseFoldingTable[0x1EA] = { caseFoldingPage0, caseFoldingPage1, lowercasePage2, caseFoldingPage3, lowercasePage4, lowercasePage5, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage16, emptyPage, emptyPage, caseFoldingPage19, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, caseFoldingPage28, emptyPage, caseFoldingPage30, caseFoldingPage31, emptyPage, lowercasePage33, emptyPage, emptyPage, lowercasePage36, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage44, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage166, lowercasePage167, emptyPage, emptyPage, emptyPage, caseFoldingPage171, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, caseFoldingPage251, emptyPage, emptyPage, emptyPage, lowercasePage255, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage260, lowercasePage261, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage268, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage280, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage366, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage489 }; objfw-1.1.6/src/unistd_wrapper.h000066400000000000000000000017571465614216400166570ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include /* Make sure we have any libc include */ #ifdef HAVE_UNISTD_H # ifdef __GLIBC__ # undef __USE_XOPEN /* Needed to avoid old glibc using __block */ # endif # include # ifdef __GLIBC__ # define __USE_XOPEN 1 # endif #endif objfw-1.1.6/src/versioninfo.rc000066400000000000000000000012251465614216400163150ustar00rootroot00000000000000#include "config.h" #include "winver.h" 1 VERSIONINFO FILEVERSION OBJFW_LIB_MAJOR, OBJFW_LIB_MINOR, 0, 0 PRODUCTVERSION OBJFW_VERSION_MAJOR, OBJFW_VERSION_MINOR, 0, 0 FILEOS VOS__WINDOWS32 FILETYPE VFT_DLL { BLOCK "StringFileInfo" { BLOCK "040904E4" { VALUE "ProductName", "ObjFW" VALUE "ProductVersion", PACKAGE_VERSION VALUE "FileVersion", OBJFW_LIB_VERSION VALUE "FileDescription", "Objective-C framework" VALUE "LegalCopyright", "(c) 2008-2024 Jonathan Schleifer" VALUE "InternalName", "ObjFW" VALUE "OriginalFilename", OBJFW_SHARED_LIB } } BLOCK "VarFileInfo" { VALUE "Translation", 0x409, 1252 } } objfw-1.1.6/tests/000077500000000000000000000000001465614216400140015ustar00rootroot00000000000000objfw-1.1.6/tests/ForwardingTests.m000066400000000000000000000177151465614216400173170ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "ObjFW.h" #import "ObjFWTest.h" #define FORMAT @"%@ %@ %@ %@ %@ %@ %@ %@ %@ %g %g %g %g %g %g %g %g %g" #define ARGS @"a", @"b", @"c", @"d", @"e", @"f", @"g", @"h", @"i", \ 1.5, 2.25, 3.125, 4.0625, 5.03125, 6.5, 7.25, 8.0, 9.0 #define RESULT @"a b c d e f g h i 1.5 2.25 3.125 4.0625 5.03125 6.5 7.25 8 9" @interface ForwardingTests: OTTestCase @end static size_t forwardingsCount = 0; static bool success = false; static id target = nil; struct StretTest { char buffer[1024]; }; @interface ForwardingTestObject: OFObject @end @interface ForwardingTestObject (NonExistentMethods) + (void)test; - (void)test; - (uint32_t)forwardingTargetTest: (intptr_t)a0 : (intptr_t)a1 : (double)a2 : (double)a3; - (OFString *)forwardingTargetVarArgTest: (OFConstantString *)format, ...; - (long double)forwardingTargetFPRetTest; - (struct StretTest)forwardingTargetStRetTest; - (void)forwardingTargetNilTest; - (void)forwardingTargetSelfTest; - (struct StretTest)forwardingTargetNilStRetTest; - (struct StretTest)forwardingTargetSelfStRetTest; @end @interface ForwardingTarget: OFObject @end static void test(id self, SEL _cmd) { success = true; } @implementation ForwardingTests - (void)setUp { [super setUp]; forwardingsCount = 0; success = false; target = nil; } - (void)testForwardingMessageAndAddingClassMethod { [ForwardingTestObject test]; OTAssertTrue(success); OTAssertEqual(forwardingsCount, 1); [ForwardingTestObject test]; OTAssertEqual(forwardingsCount, 1); } - (void)forwardingMessageAndAddingInstanceMethod { ForwardingTestObject *testObject = [[[ForwardingTestObject alloc] init] autorelease]; [testObject test]; OTAssertTrue(success); OTAssertEqual(forwardingsCount, 1); [testObject test]; OTAssertEqual(forwardingsCount, 1); } #ifdef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR - (void)testForwardingTargetForSelector { ForwardingTestObject *testObject = [[[ForwardingTestObject alloc] init] autorelease]; target = [[[ForwardingTarget alloc] init] autorelease]; OTAssertEqual( [testObject forwardingTargetTest: 0xDEADBEEF : -1 : 1.25 : 2.75], 0x12345678); } - (void)testForwardingTargetForSelectorWithVariableArguments { ForwardingTestObject *testObject = [[[ForwardingTestObject alloc] init] autorelease]; target = [[[ForwardingTarget alloc] init] autorelease]; OTAssertEqualObjects( ([testObject forwardingTargetVarArgTest: FORMAT, ARGS]), RESULT); } /* * Don't try fpret on Win64 if we don't have stret forwarding, as long double * is handled as a struct there. */ # if !defined(OF_WINDOWS) || !defined(OF_AMD64) || \ defined(OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET) - (void)testForwardingTargetForSelectorFPRet { ForwardingTestObject *testObject = [[[ForwardingTestObject alloc] init] autorelease]; target = [[[ForwardingTarget alloc] init] autorelease]; OTAssertEqual([testObject forwardingTargetFPRetTest], 12345678.00006103515625); } # endif # ifdef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET - (void)testForwardingTargetForSelectorStRet { ForwardingTestObject *testObject = [[[ForwardingTestObject alloc] init] autorelease]; target = [[[ForwardingTarget alloc] init] autorelease]; OTAssertEqual(memcmp([testObject forwardingTargetStRetTest].buffer, "abcdefghijklmnopqrstuvwxyz", 27), 0); } # endif - (void)testForwardingTargetForSelectorReturningNilThrows { ForwardingTestObject *testObject = [[[ForwardingTestObject alloc] init] autorelease]; target = [[[ForwardingTarget alloc] init] autorelease]; OTAssertThrowsSpecific([testObject forwardingTargetNilTest], OFNotImplementedException); } - (void)testForwardingTargetForSelectorReturningSelfThrows { ForwardingTestObject *testObject = [[[ForwardingTestObject alloc] init] autorelease]; target = [[[ForwardingTarget alloc] init] autorelease]; OTAssertThrowsSpecific([testObject forwardingTargetSelfTest], OFNotImplementedException); } # ifdef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET - (void)testForwardingTargetForSelectorStRetReturningNilThrows { ForwardingTestObject *testObject = [[[ForwardingTestObject alloc] init] autorelease]; target = [[[ForwardingTarget alloc] init] autorelease]; OTAssertThrowsSpecific([testObject forwardingTargetNilStRetTest], OFNotImplementedException); } - (void)testForwardingTargetForSelectorStRetReturningSelfThrows { ForwardingTestObject *testObject = [[[ForwardingTestObject alloc] init] autorelease]; target = [[[ForwardingTarget alloc] init] autorelease]; OTAssertThrowsSpecific([testObject forwardingTargetSelfStRetTest], OFNotImplementedException); } # endif #endif @end @implementation ForwardingTestObject + (bool)resolveClassMethod: (SEL)selector { forwardingsCount++; if (sel_isEqual(selector, @selector(test))) { class_replaceMethod(object_getClass(self), @selector(test), (IMP)test, "v#:"); return YES; } return NO; } + (bool)resolveInstanceMethod: (SEL)selector { forwardingsCount++; if (sel_isEqual(selector, @selector(test))) { class_replaceMethod(self, @selector(test), (IMP)test, "v@:"); return YES; } return NO; } - (id)forwardingTargetForSelector: (SEL)selector { /* * Do some useless calculations in as many registers as possible to * check if the arguments are properly saved and restored. */ volatile register intptr_t r0 = 0, r1 = 1, r2 = 2, r3 = 3, r4 = 4, r5 = 5, r6 = 6, r7 = 7, r8 = 8, r9 = 9, r10 = 10, r11 = 11; volatile register double f0 = 0.5, f1 = 1.5, f2 = 2.5, f3 = 3.5, f4 = 4.5, f5 = 5.5, f6 = 6.5, f7 = 7.5, f8 = 8.5, f9 = 9.5, f10 = 10.5, f11 = 11.5; double add = r0 * r1 * r2 * r3 * r4 * r5 * r6 * r7 * r8 * r9 * r10 * r11 * f0 * f1 * f2 * f3 * f4 * f5 * f6 * f7 * f8 * f9 * f10 * f11; if (sel_isEqual(selector, @selector(forwardingTargetTest::::)) || sel_isEqual(selector, @selector(forwardingTargetVarArgTest:)) || sel_isEqual(selector, @selector(forwardingTargetFPRetTest)) || sel_isEqual(selector, @selector(forwardingTargetStRetTest))) return (id)((char *)target + (ptrdiff_t)add); if (sel_isEqual(selector, @selector(forwardingTargetNilTest)) || sel_isEqual(selector, @selector(forwardingTargetNilStRetTest))) return nil; if (sel_isEqual(selector, @selector(forwardingTargetSelfTest)) || sel_isEqual(selector, @selector(forwardingTargetSelfStRetTest))) return self; abort(); OF_UNREACHABLE } @end @implementation ForwardingTarget - (uint32_t)forwardingTargetTest: (intptr_t)a0 : (intptr_t)a1 : (double)a2 : (double)a3 { OFEnsure(self == target); if (a0 != (intptr_t)0xDEADBEEF) return 0; if (a1 != -1) return 0; if (a2 != 1.25) return 0; if (a3 != 2.75) return 0; return 0x12345678; } - (OFString *)forwardingTargetVarArgTest: (OFConstantString *)format, ... { va_list args; OFString *ret; OFEnsure(self == target); va_start(args, format); ret = [[[OFString alloc] initWithFormat: format arguments: args] autorelease]; va_end(args); return ret; } - (long double)forwardingTargetFPRetTest { OFEnsure(self == target); return 12345678.00006103515625; } - (struct StretTest)forwardingTargetStRetTest { struct StretTest ret = { { 0 } }; OFEnsure(self == target); memcpy(ret.buffer, "abcdefghijklmnopqrstuvwxyz", 27); return ret; } @end objfw-1.1.6/tests/ImportTest.m000066400000000000000000000013531465614216400162730ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ @import ObjFW; objfw-1.1.6/tests/Info.plist.in000066400000000000000000000021471465614216400163620ustar00rootroot00000000000000 CFBundleExecutable $(EXECUTABLE_NAME) CFBundleName $(PRODUCT_NAME) CFBundleIdentifier $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundlePackageType APPL CFBundleVersion @BUNDLE_VERSION@ CFBundleShortVersionString @BUNDLE_SHORT_VERSION@ LSRequiresIPhoneOS UILaunchStoryboardName LaunchScreen UIMainStoryboardFile Main UIRequiredDeviceCapabilities armv7 UISupportedInterfaceOrientations UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight objfw-1.1.6/tests/Makefile000066400000000000000000000200311465614216400154350ustar00rootroot00000000000000include ../extra.mk SUBDIRS = ${TESTPLUGIN} \ ${SUBPROCESS} \ ${OBJC_SYNC} \ terminal CLEAN = EBOOT.PBP \ boot.dol \ ${PROG_NOINST}.arm9 \ ${PROG_NOINST}.nds \ ${PROG_NOINST}.nro \ ${PROG_NOINST}.rpx \ big_dictionary_msgpack.m \ testfile_bin.m \ testfile_ini.m DISTCLEAN = Info.plist PROG_NOINST = tests${PROG_SUFFIX} STATIC_LIB_NOINST = ${TESTS_STATIC_LIB} SRCS = ForwardingTests.m \ OFArrayTests.m \ ${OF_BLOCK_TESTS_M} \ OFCharacterSetTests.m \ OFColorTests.m \ OFConcreteArrayTests.m \ OFConcreteDictionaryTests.m \ OFConcreteMutableArrayTests.m \ OFConcreteMutableDictionaryTests.m \ OFConcreteMutableSetTests.m \ OFConcreteSetTests.m \ OFCryptographicHashTests.m \ OFDataTests.m \ OFDateTests.m \ OFDictionaryTests.m \ OFHMACTests.m \ OFINIFileTests.m \ OFIRITests.m \ OFInvocationTests.m \ OFJSONTests.m \ OFLHAArchiveTests.m \ OFListTests.m \ OFLocaleTests.m \ OFMatrix4x4Tests.m \ OFMemoryStreamTests.m \ OFMessagePackTests.m \ OFMethodSignatureTests.m \ OFMutableArrayTests.m \ OFMutableDataTests.m \ OFMutableDictionaryTests.m \ OFMutableSetTests.m \ OFMutableStringTests.m \ OFMutableUTF8StringTests.m \ OFNotificationCenterTests.m \ OFNumberTests.m \ OFObjectTests.m \ OFPBKDF2Tests.m \ OFPropertyListTests.m \ OFScryptTests.m \ OFSetTests.m \ OFStreamTests.m \ OFStringTests.m \ OFSystemInfoTests.m \ OFTarArchiveTests.m \ OFUTF8StringTests.m \ OFValueTests.m \ OFXMLElementBuilderTests.m \ OFXMLNodeTests.m \ OFXMLParserTests.m \ OFZIPArchiveTests.m \ OFZooArchiveTests.m \ ${RUNTIME_ARC_TESTS_M} \ RuntimeTests.m \ ${USE_SRCS_FILES} \ ${USE_SRCS_PLUGINS} \ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_SUBPROCESSES} \ ${USE_SRCS_THREADS} \ ${USE_SRCS_WINDOWS} \ big_dictionary_msgpack.m \ testfile_bin.m \ testfile_ini.m SRCS_FILES = OFFileManagerTests.m SRCS_PLUGINS = OFPluginTests.m SRCS_SOCKETS = OFDNSResolverTests.m \ ${OF_HTTP_CLIENT_TESTS_M} \ OFHTTPCookieManagerTests.m \ OFHTTPCookieTests.m \ OFKernelEventObserverTests.m \ OFSocketTests.m \ OFTCPSocketTests.m \ OFUDPSocketTests.m \ ${USE_SRCS_APPLETALK} \ ${USE_SRCS_IPX} \ ${USE_SRCS_UNIX_SOCKETS} SRCS_APPLETALK = OFDDPSocketTests.m SRCS_IPX = OFIPXSocketTests.m \ OFSPXSocketTests.m \ OFSPXStreamSocketTests.m SRCS_UNIX_SOCKETS = OFUNIXDatagramSocketTests.m \ OFUNIXStreamSocketTests.m SRCS_SUBPROCESSES = OFSubprocessTests.m SRCS_THREADS = OFThreadTests.m SRCS_WINDOWS = OFWindowsRegistryKeyTests.m include ../buildsys.mk big_dictionary_msgpack.m: ${SHELL} ../utils/objfw-embed \ big_dictionary.msgpack big_dictionary.msgpack $@ testfile_bin.m: testfile.bin ${SHELL} ../utils/objfw-embed testfile.bin testfile.bin $@ testfile_ini.m: testfile.ini ${SHELL} ../utils/objfw-embed testfile.ini testfile.ini $@ .PHONY: run run-on-ios run-on-android run: rm -f libobjfw.so.${OBJFW_LIB_MAJOR} rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} rm -f objfw${OBJFW_LIB_MAJOR}.dll libobjfw.${OBJFW_LIB_MAJOR}.dylib rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR} rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} rm -f objfwrt${OBJFWRT_LIB_MAJOR}.dll rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib if test -f ../src/libobjfw.so; then \ ${LN_S} ../src/libobjfw.so libobjfw.so.${OBJFW_LIB_MAJOR}; \ ${LN_S} ../src/libobjfw.so \ libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ elif test -f ../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; then \ ${LN_S} ../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} \ libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ fi if test -f ../src/objfw${OBJFW_LIB_MAJOR}.dll; then \ ${LN_S} ../src/objfw${OBJFW_LIB_MAJOR}.dll \ objfw${OBJFW_LIB_MAJOR}.dll; \ fi if test -f ../src/libobjfw.dylib; then \ ${LN_S} ../src/libobjfw.dylib \ libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ fi if test -f ../src/runtime/libobjfwrt.so; then \ ${LN_S} ../src/runtime/libobjfwrt.so \ libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ ${LN_S} ../src/runtime/libobjfwrt.so \ libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ elif test -f ../src/runtime/libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; then \ ${LN_S} ../src/runtime/libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ fi if test -f ../src/runtime/objfwrt${OBJFWRT_LIB_MAJOR}.dll; then \ ${LN_S} ../src/runtime/objfwrt${OBJFWRT_LIB_MAJOR}.dll \ objfwrt${OBJFWRT_LIB_MAJOR}.dll; \ fi if test -f ../src/runtime/libobjfwrt.dylib; then \ ${LN_S} ../src/runtime/libobjfwrt.dylib \ libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ fi LD_LIBRARY_PATH=.$${LD_LIBRARY_PATH+:}$$LD_LIBRARY_PATH \ DYLD_FRAMEWORK_PATH=../src:../src/runtime$${DYLD_FRAMEWORK_PATH+:}$$DYLD_FRAMEWORK_PATH \ DYLD_LIBRARY_PATH=.$${DYLD_LIBRARY_PATH+:}$$DYLD_LIBRARY_PATH \ LIBRARY_PATH=.$${LIBRARY_PATH+:}$$LIBRARY_PATH \ ASAN_OPTIONS=allocator_may_return_null=1 \ ${WRAPPER} ./${PROG_NOINST} ${TESTCASES}; EXIT=$$?; \ rm -f libobjfw.so.${OBJFW_LIB_MAJOR}; \ rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ rm -f objfw${OBJFW_LIB_MAJOR}.dll; \ rm -f libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ rm -f objfwrt${OBJFWRT_LIB_MAJOR}.dll; \ rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ exit $$EXIT run-on-android: all echo "Uploading files to Android device..." if test -f ../src/libobjfw.so; then \ adb push ../src/libobjfw.so \ /data/local/tmp/objfw/libobjfw.so.${OBJFW_LIB_MAJOR}; \ fi if test -f ../src/runtime/libobjfwrt.so; then \ adb push ../src/runtime/libobjfwrt.so \ /data/local/tmp/objfw/libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ fi adb push tests /data/local/tmp/objfw/tests adb push testfile.txt /data/local/tmp/objfw/testfile.txt if test -f plugin/TestPlugin.so; then \ adb push plugin/TestPlugin.so \ /data/local/tmp/objfw/plugin/TestPlugin.so; \ fi echo "Running tests binary on Android device..." adb shell 'cd /data/local/tmp/objfw && LD_LIBRARY_PATH=. exec ${WRAPPER} ./tests' EBOOT.PBP: ${PROG_NOINST} psp-fixup-imports ${PROG_NOINST} mksfo "ObjFW Tests" PARAM.SFO psp-strip ${PROG_NOINST} pack-pbp $@ PARAM.SFO NULL NULL NULL NULL NULL ${PROG_NOINST} NULL boot.dol: ${PROG_NOINST} elf2dol ${PROG_NOINST} $@ ${PROG_NOINST}: ${LIBOBJFW_DEP} ${LIBOBJFWRT_DEP} ../src/test/libobjfwtest.a ${PROG_NOINST}.3dsx: ${PROG_NOINST} 3dsxtool $< $@ ${PROG_NOINST}.arm9: ${PROG_NOINST} arm-none-eabi-objcopy -O binary $< $@ ${PROG_NOINST}.nds: ${PROG_NOINST}.arm9 testfile.txt rm -fr nds-data mkdir -p nds-data cp testfile.txt nds-data ndstool -c $@ -9 ${PROG_NOINST} -d nds-data rm -fr nds-data ${PROG_NOINST}.nro: ${PROG_NOINST} testfile.txt rm -fr romfs mkdir -p romfs cp testfile.txt romfs nacptool --create "ObjFW tests" "Jonathan Schleifer" \ "${PACKAGE_VERSION}" tests.nacp elf2nro ${PROG_NOINST} $@ --nacp=tests.nacp --romfsdir=romfs rm -fr romfs tests.nacp ${PROG_NOINST}.rpx: ${PROG_NOINST} elf2rpl $< $@ CPPFLAGS += -I../src \ -I../src/exceptions \ -I../src/runtime \ -I../src/test \ -I.. \ -DOBJFWTEST_LOCAL_INCLUDES \ -DPROG_SUFFIX=\"${PROG_SUFFIX}\" OBJCFLAGS_RuntimeARCTests.m = -fobjc-arc -fobjc-arc-exceptions # Repetition of libraries is required for Wii U, as otherwise it cannot find # main. Just moving -lobjfwtest later doesn't work either, as then the linker # cannot find ObjFW symbols. So the only solution is to list everything twice, # but hide it behind a variable because listing it twice causes a warning on # macOS. LIBS := -L../src/test \ -lobjfwtest \ ${TESTS_LIBS} \ ${LIBS} \ ${WII_U_TESTS_LIBS} LDFLAGS += ${MAP_LDFLAGS} LD = ${OBJC} objfw-1.1.6/tests/OFArrayTests.h000066400000000000000000000015671465614216400165110ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "ObjFW.h" #import "ObjFWTest.h" @interface OFArrayTests: OTTestCase { OFArray *_array; } @property (readonly, nonatomic) Class arrayClass; @end objfw-1.1.6/tests/OFArrayTests.m000066400000000000000000000165431465614216400165160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFArrayTests.h" @interface CustomArray: OFArray { OFArray *_array; } @end static OFString *const cArray[] = { @"Foo", @"Bar", @"Baz" }; @implementation OFArrayTests - (Class)arrayClass { return [CustomArray class]; } - (void)setUp { [super setUp]; _array = [[self.arrayClass alloc] initWithObjects: cArray count: sizeof(cArray) / sizeof(*cArray)]; } - (void)dealloc { [_array release]; [super dealloc]; } - (void)testArray { OFArray *array = [self.arrayClass array]; OTAssertNotNil(array); OTAssertEqual(array.count, 0); } - (void)testArrayWithObjects { OFArray *array = [self.arrayClass arrayWithObjects: @"Foo", @"Bar", @"Baz", nil]; OTAssertNotNil(array); OTAssertEqual(array.count, 3); OTAssertEqualObjects([array objectAtIndex: 0], @"Foo"); OTAssertEqualObjects([array objectAtIndex: 1], @"Bar"); OTAssertEqualObjects([array objectAtIndex: 2], @"Baz"); } - (void)testArrayWithObjectsCount { OFArray *array1 = [self.arrayClass arrayWithObjects: @"Foo", @"Bar", @"Baz", nil]; OFArray *array2 = [self.arrayClass arrayWithObjects: cArray count: 3]; OTAssertEqualObjects(array1, array2); } - (void)testDescription { OTAssertEqualObjects(_array.description, @"(\n\tFoo,\n\tBar,\n\tBaz\n)"); } - (void)testCount { OTAssertEqual(_array.count, 3); } - (void)testIsEqual { OFArray *array = [self.arrayClass arrayWithObjects: cArray count: 3]; OTAssertEqualObjects(array, _array); OTAssertNotEqual(array, _array); } - (void)testHash { OFArray *array = [self.arrayClass arrayWithObjects: cArray count: 3]; OTAssertEqual(array.hash, _array.hash); OTAssertNotEqual(array.hash, [[OFArray array] hash]); } - (void)testCopy { OTAssertEqualObjects([[_array copy] autorelease], _array); } - (void)testMutableCopy { OTAssertEqualObjects([[_array mutableCopy] autorelease], _array); } - (void)testObjectAtIndex { OTAssertEqualObjects([_array objectAtIndex: 0], cArray[0]); OTAssertEqualObjects([_array objectAtIndex: 1], cArray[1]); OTAssertEqualObjects([_array objectAtIndex: 2], cArray[2]); } - (void)testObjectAtIndexFailsWhenOutOfRange { OTAssertThrowsSpecific([_array objectAtIndex: _array.count], OFOutOfRangeException); } - (void)testContainsObject { OTAssertTrue([_array containsObject: cArray[1]]); OTAssertFalse([_array containsObject: @"nonexistent"]); } - (void)testContainsObjectIdenticalTo { OTAssertTrue([_array containsObjectIdenticalTo: cArray[1]]); OTAssertFalse([_array containsObjectIdenticalTo: [OFString stringWithString: cArray[1]]]); } - (void)testIndexOfObject { OTAssertEqual([_array indexOfObject: cArray[1]], 1); OTAssertEqual([_array indexOfObject: @"nonexistent"], OFNotFound); } - (void)testIndexOfObjectIdenticalTo { OTAssertEqual([_array indexOfObjectIdenticalTo: cArray[1]], 1); OTAssertEqual([_array indexOfObjectIdenticalTo: [OFString stringWithString: cArray[1]]], OFNotFound); } - (void)objectsInRange { OTAssertEqualObjects([_array objectsInRange: OFMakeRange(1, 2)], ([self.arrayClass arrayWithObjects: cArray[1], cArray[2], nil])); } - (void)testEnumerator { OFEnumerator *enumerator = [_array objectEnumerator]; OTAssertEqualObjects([enumerator nextObject], cArray[0]); OTAssertEqualObjects([enumerator nextObject], cArray[1]); OTAssertEqualObjects([enumerator nextObject], cArray[2]); OTAssertNil([enumerator nextObject]); } - (void)testFastEnumeration { size_t i = 0; for (OFString *object in _array) { OTAssertLessThan(i, 3); OTAssertEqualObjects(object, cArray[i++]); } } - (void)testComponentsJoinedByString { OFArray *array; array = [self.arrayClass arrayWithObjects: @"", @"a", @"b", @"c", nil]; OTAssertEqualObjects([array componentsJoinedByString: @" "], @" a b c"); array = [self.arrayClass arrayWithObject: @"foo"]; OTAssertEqualObjects([array componentsJoinedByString: @" "], @"foo"); } - (void)testComponentsJoinedByStringOptions { OFArray *array; array = [self.arrayClass arrayWithObjects: @"", @"foo", @"", @"", @"bar", @"", nil]; OTAssertEqualObjects( [array componentsJoinedByString: @" " options: OFArraySkipEmptyComponents], @"foo bar"); } - (void)testSortedArray { OFArray *array = [_array arrayByAddingObjectsFromArray: [OFArray arrayWithObjects: @"0", @"z", nil]]; OTAssertEqualObjects([array sortedArray], ([OFArray arrayWithObjects: @"0", @"Bar", @"Baz", @"Foo", @"z", nil])); OTAssertEqualObjects( [array sortedArrayUsingSelector: @selector(compare:) options: OFArraySortDescending], ([OFArray arrayWithObjects: @"z", @"Foo", @"Baz", @"Bar", @"0", nil])); } - (void)testReversedArray { OTAssertEqualObjects(_array.reversedArray, ([OFArray arrayWithObjects: cArray[2], cArray[1], cArray[0], nil])); } #ifdef OF_HAVE_BLOCKS - (void)testEnumerateObjectsUsingBlock { __block size_t i = 0; [_array enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { OTAssertEqualObjects(object, [_array objectAtIndex: i++]); }]; OTAssertEqual(i, _array.count); } - (void)testMappedArrayUsingBlock { OTAssertEqualObjects( [_array mappedArrayUsingBlock: ^ id (id object, size_t idx) { switch (idx) { case 0: return @"foobar"; case 1: return @"qux"; } return @""; }].description, @"(\n\tfoobar,\n\tqux,\n\t\n)"); } - (void)testFilteredArrayUsingBlock { OTAssertEqualObjects( [_array filteredArrayUsingBlock: ^ bool (id object, size_t idx) { return [object isEqual: @"Foo"]; }].description, @"(\n\tFoo\n)"); } - (void)testFoldUsingBlock { OTAssertEqualObjects( [([self.arrayClass arrayWithObjects: [OFMutableString string], @"foo", @"bar", @"baz", nil]) foldUsingBlock: ^ id (id left, id right) { [left appendString: right]; return left; }], @"foobarbaz"); } #endif - (void)testValueForKey { OTAssertEqualObjects( [([self.arrayClass arrayWithObjects: @"foo", @"bar", @"quxqux", nil]) valueForKey: @"length"], ([self.arrayClass arrayWithObjects: [OFNumber numberWithInt: 3], [OFNumber numberWithInt: 3], [OFNumber numberWithInt: 6], nil])); OTAssertEqualObjects( [([self.arrayClass arrayWithObjects: @"1", @"2", nil]) valueForKey: @"@count"], [OFNumber numberWithInt: 2]); } @end @implementation CustomArray - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { self = [super init]; @try { _array = [[OFArray alloc] initWithObjects: objects count: count]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_array release]; [super dealloc]; } - (id)objectAtIndex: (size_t)idx { return [_array objectAtIndex: idx]; } - (size_t)count { return [_array count]; } @end objfw-1.1.6/tests/OFBlockTests.m000066400000000000000000000063541465614216400164710ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" @interface OFBlockTests: OTTestCase @end #if defined(OF_OBJFW_RUNTIME) extern struct objc_class _NSConcreteStackBlock; extern struct objc_class _NSConcreteGlobalBlock; extern struct objc_class _NSConcreteMallocBlock; #elif defined(OF_APPLE_RUNTIME) extern void *_NSConcreteStackBlock; extern void *_NSConcreteGlobalBlock; extern void *_NSConcreteMallocBlock; #endif /* Clang on Win32 generates broken code that crashes for global blocks. */ #if !defined(OF_WINDOWS) || !defined(__clang__) static void (^globalBlock)(void) = ^ {}; #endif static int (^returnStackBlock(void))(void) { __block int i = 42; return [Block_copy(^ int { return ++i; }) autorelease]; } static double forwardTest(void) { __block double d; void (^block)(void) = Block_copy(^ { d = 5; }); block(); Block_release(block); return d; } @implementation OFBlockTests - (void)testClassOfStackBlock { __block int x; void (^stackBlock)(void) = ^ { x = 0; (void)x; }; OTAssertEqual((Class)&_NSConcreteStackBlock, objc_getClass("OFStackBlock")); OTAssertTrue([stackBlock isKindOfClass: [OFBlock class]]); } #if !defined(OF_WINDOWS) || !defined(__clang__) - (void)testClassOfGlobalBlock { OTAssertEqual((Class)&_NSConcreteGlobalBlock, objc_getClass("OFGlobalBlock")); OTAssertTrue([globalBlock isKindOfClass: [OFBlock class]]); } #endif - (void)testClassOfMallocBlock { OTAssertEqual((Class)&_NSConcreteMallocBlock, objc_getClass("OFMallocBlock")); } - (void)testCopyStackBlock { __block int x; void (^stackBlock)(void) = ^ { x = 0; (void)x; }; void (^mallocBlock)(void); mallocBlock = [[stackBlock copy] autorelease]; OTAssertEqual([mallocBlock class], objc_getClass("OFMallocBlock")); OTAssertTrue([mallocBlock isKindOfClass: [OFBlock class]]); } - (void)testCopyStackBlockAndReferenceVariable { OTAssertEqual(forwardTest(), 5); } - (void)testCopyStackBlockAndReferenceCopiedVariable { int (^voidBlock)(void) = returnStackBlock(); OTAssertEqual(voidBlock(), 43); OTAssertEqual(voidBlock(), 44); OTAssertEqual(voidBlock(), 45); } #if !defined(OF_WINDOWS) || !defined(__clang__) - (void)testCopyGlobalBlock { OTAssertEqual([[globalBlock copy] autorelease], (id)globalBlock); } #endif - (void)testCopyMallocBlock { __block int x; void (^stackBlock)(void) = ^ { x = 0; (void)x; }; void (^mallocBlock)(void); mallocBlock = [[stackBlock copy] autorelease]; OTAssertEqual([[mallocBlock copy] autorelease], (id)mallocBlock); OTAssertEqual([mallocBlock retainCount], 2); } @end objfw-1.1.6/tests/OFCharacterSetTests.m000066400000000000000000000054421465614216400200040ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" #import "OFCharacterSet.h" #import "OFBitSetCharacterSet.h" #import "OFRangeCharacterSet.h" @interface OFCharacterSetTests: OTTestCase @end @interface CustomCharacterSet: OFCharacterSet @end @implementation CustomCharacterSet - (bool)characterIsMember: (OFUnichar)character { return (character % 2 == 0); } @end @implementation OFCharacterSetTests - (void)testCustomCharacterSet { OFCharacterSet *characterSet = [[[CustomCharacterSet alloc] init] autorelease]; for (OFUnichar c = 0; c < 65536; c++) if (c % 2 == 0) OTAssertTrue([characterSet characterIsMember: c]); else OTAssertFalse([characterSet characterIsMember: c]); } - (void)testBitSetCharacterSet { OFCharacterSet *characterSet = [OFCharacterSet characterSetWithCharactersInString: @"0123456789"]; OTAssertTrue( [characterSet isKindOfClass: [OFBitSetCharacterSet class]]); for (OFUnichar c = 0; c < 65536; c++) if (c >= '0' && c <= '9') OTAssertTrue([characterSet characterIsMember: c]); else if ([characterSet characterIsMember: c]) OTAssertFalse([characterSet characterIsMember: c]); } - (void)testRangeCharacterSet { OFCharacterSet *characterSet = [OFCharacterSet characterSetWithRange: OFMakeRange('0', 10)]; OTAssertTrue( [characterSet isKindOfClass: [OFRangeCharacterSet class]]); for (OFUnichar c = 0; c < 65536; c++) if (c >= '0' && c <= '9') OTAssertTrue([characterSet characterIsMember: c]); else OTAssertFalse([characterSet characterIsMember: c]); } - (void)testInvertedCharacterSet { OFCharacterSet *characterSet = [[OFCharacterSet characterSetWithRange: OFMakeRange('0', 10)] invertedSet]; for (OFUnichar c = 0; c < 65536; c++) if (c >= '0' && c <= '9') OTAssertFalse([characterSet characterIsMember: c]); else OTAssertTrue([characterSet characterIsMember: c]); } - (void)testInvertingInvertedSetReturnsOriginal { OFCharacterSet *characterSet = [OFCharacterSet characterSetWithRange: OFMakeRange('0', 10)]; OTAssertEqual(characterSet, characterSet.invertedSet.invertedSet); } @end objfw-1.1.6/tests/OFColorTests.m000066400000000000000000000026661465614216400165170ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" @interface OFColorTests: OTTestCase { OFColor *_color; } @end @implementation OFColorTests - (void)setUp { [super setUp]; _color = [[OFColor alloc] initWithRed: 63.f / 255 green: 127.f / 255 blue: 1 alpha: 1]; } - (void)dealloc { [_color release]; [super dealloc]; } #ifdef OF_OBJFW_RUNTIME - (void)testReturnsTaggedPointer { OTAssertTrue(object_isTaggedPointer(_color)); } #endif - (void)testGetRedGreenBlueAlpha { float red, green, blue, alpha; [_color getRed: &red green: &green blue: &blue alpha: &alpha]; OTAssertEqual(red, 63.f / 255); OTAssertEqual(green, 127.f / 255); OTAssertEqual(blue, 1); OTAssertEqual(alpha, 1); } @end objfw-1.1.6/tests/OFConcreteArrayTests.m000066400000000000000000000016771465614216400202030ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFArrayTests.h" #import "OFConcreteArray.h" @interface OFConcreteArrayTests: OFArrayTests @end @implementation OFConcreteArrayTests - (Class)arrayClass { return [OFConcreteArray class]; } @end objfw-1.1.6/tests/OFConcreteDictionaryTests.m000066400000000000000000000017421465614216400212230ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFDictionaryTests.h" #import "OFConcreteDictionary.h" @interface OFConcreteDictionaryTests: OFDictionaryTests @end @implementation OFConcreteDictionaryTests - (Class)dictionaryClass { return [OFConcreteDictionary class]; } @end objfw-1.1.6/tests/OFConcreteMutableArrayTests.m000066400000000000000000000051121465614216400215010ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFMutableArrayTests.h" #import "OFConcreteMutableArray.h" @interface OFConcreteMutableArrayTests: OFMutableArrayTests @end static OFString *const cArray[] = { @"Foo", @"Bar", @"Baz" }; @implementation OFConcreteMutableArrayTests - (Class)arrayClass { return [OFConcreteMutableArray class]; } - (void)testDetectMutationDuringEnumeration { OFEnumerator *enumerator = [_mutableArray objectEnumerator]; OFString *object; size_t i; i = 0; while ((object = [enumerator nextObject]) != nil) { OTAssertEqualObjects(object, cArray[i]); [_mutableArray replaceObjectAtIndex: i withObject: @""]; i++; } OTAssertEqual(i, _mutableArray.count); [_mutableArray removeObjectAtIndex: 0]; OTAssertThrowsSpecific([enumerator nextObject], OFEnumerationMutationException); } - (void)testDetectMutationDuringFastEnumeration { bool detected = false; size_t i; i = 0; for (OFString *object in _mutableArray) { OTAssertEqualObjects(object, cArray[i]); [_mutableArray replaceObjectAtIndex: i withObject: @""]; i++; } OTAssertEqual(i, _mutableArray.count); @try { for (OFString *object in _mutableArray) { (void)object; [_mutableArray removeObjectAtIndex: 0]; } } @catch (OFEnumerationMutationException *e) { detected = true; } OTAssertTrue(detected); } #ifdef OF_HAVE_BLOCKS - (void)testDetectMutationDuringEnumerateObjectsUsingBlock { __block size_t i; i = 0; [_mutableArray enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { OTAssertEqualObjects(object, cArray[idx]); [_mutableArray replaceObjectAtIndex: idx withObject: @""]; i++; }]; OTAssertEqual(i, _mutableArray.count); OTAssertThrowsSpecific( [_mutableArray enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { [_mutableArray removeObjectAtIndex: 0]; }], OFEnumerationMutationException); } #endif @end objfw-1.1.6/tests/OFConcreteMutableDictionaryTests.m000066400000000000000000000055311465614216400225350ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFMutableDictionaryTests.h" #import "OFConcreteMutableDictionary.h" @interface OFConcreteMutableDictionaryTests: OFMutableDictionaryTests @end @implementation OFConcreteMutableDictionaryTests - (Class)dictionaryClass { return [OFConcreteMutableDictionary class]; } - (void)testDetectMutationDuringEnumeration { OFMutableDictionary *mutableDictionary = [[_dictionary mutableCopy] autorelease]; OFEnumerator *keyEnumerator = [mutableDictionary keyEnumerator]; OFEnumerator *objectEnumerator = [mutableDictionary objectEnumerator]; OFString *key; size_t i; i = 0; while ((key = [keyEnumerator nextObject]) != nil) { [mutableDictionary setObject: @"test" forKey: key]; i++; } OTAssertEqual(i, mutableDictionary.count); [mutableDictionary removeObjectForKey: @"key2"]; OTAssertThrowsSpecific([keyEnumerator nextObject], OFEnumerationMutationException); OTAssertThrowsSpecific([objectEnumerator nextObject], OFEnumerationMutationException); } - (void)testDetectMutationDuringFastEnumeration { OFMutableDictionary *mutableDictionary = [[_dictionary mutableCopy] autorelease]; bool detected = false; size_t i; i = 0; for (OFString *key in mutableDictionary) { [mutableDictionary setObject: @"test" forKey: key]; i++; } OTAssertEqual(i, mutableDictionary.count); @try { for (OFString *key in mutableDictionary) [mutableDictionary removeObjectForKey: key]; } @catch (OFEnumerationMutationException *e) { detected = true; } OTAssertTrue(detected); } #ifdef OF_HAVE_BLOCKS - (void)testDetectMutationDuringEnumerateObjectsUsingBlock { OFMutableDictionary *mutableDictionary = [[_dictionary mutableCopy] autorelease]; __block size_t i; i = 0; [mutableDictionary enumerateKeysAndObjectsUsingBlock: ^ (id key, id object, bool *stop) { [mutableDictionary setObject: @"test" forKey: key]; i++; }]; OTAssertEqual(i, mutableDictionary.count); OTAssertThrowsSpecific( [mutableDictionary enumerateKeysAndObjectsUsingBlock: ^ (id key, id object, bool *stop) { [mutableDictionary removeObjectForKey: key]; }], OFEnumerationMutationException); } #endif @end objfw-1.1.6/tests/OFConcreteMutableSetTests.m000066400000000000000000000033401465614216400211570ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFMutableSetTests.h" #import "OFConcreteMutableSet.h" @interface OFConcreteMutableSetTests: OFMutableSetTests @end @implementation OFConcreteMutableSetTests - (Class)setClass { return [OFConcreteMutableSet class]; } - (void)testDetectMutationDuringEnumeration { OFEnumerator *enumerator = [_mutableSet objectEnumerator]; [_mutableSet removeObject: @"foo"]; OTAssertThrowsSpecific([enumerator nextObject], OFEnumerationMutationException); } - (void)testDetectMutationDuringFastEnumeration { bool detected = false; @try { for (OFString *object in _mutableSet) [_mutableSet removeObject: object]; } @catch (OFEnumerationMutationException *e) { detected = true; } OTAssertTrue(detected); } #ifdef OF_HAVE_BLOCKS - (void)testDetectMutationDuringEnumerateObjectsUsingBlock { OTAssertThrowsSpecific( [_mutableSet enumerateObjectsUsingBlock: ^ (id object, bool *stop) { [_mutableSet removeObject: object]; }], OFEnumerationMutationException); } #endif @end objfw-1.1.6/tests/OFConcreteSetTests.m000066400000000000000000000016611465614216400176510ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFSetTests.h" #import "OFConcreteSet.h" @interface OFConcreteSetTests: OFSetTests @end @implementation OFConcreteSetTests - (Class)setClass { return [OFConcreteSet class]; } @end objfw-1.1.6/tests/OFCryptographicHashTests.m000066400000000000000000000075541465614216400210640ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "ObjFW.h" #import "ObjFWTest.h" @interface OFCryptographicHashTests: OTTestCase { OFStream *_stream; } @end const unsigned char testFileMD5[16] = "\x00\x8B\x9D\x1B\x58\xDF\xF8\xFE\xEE\xF3\xAE\x8D\xBB\x68\x2D\x38"; const unsigned char testFileRIPEMD160[20] = "\x46\x02\x97\xF5\x85\xDF\xB9\x21\x00\xC8\xF9\x87\xC6\xEC\x84\x0D" "\xCE\xE6\x08\x8B"; const unsigned char testFileSHA1[20] = "\xC9\x9A\xB8\x7E\x1E\xC8\xEC\x65\xD5\xEB\xE4\x2E\x0D\xA6\x80\x96" "\xF5\x94\xE7\x17"; const unsigned char testFileSHA224[28] = "\x27\x69\xD8\x04\x2D\x0F\xCA\x84\x6C\xF1\x62\x44\xBA\x0C\xBD\x46" "\x64\x5F\x4F\x20\x02\x4D\x15\xED\x1C\x61\x1F\xF7"; const unsigned char testFileSHA256[32] = "\x1A\x02\xD6\x46\xF5\xA6\xBA\xAA\xFF\x7F\xD5\x87\xBA\xC3\xF6\xC6" "\xB5\x67\x93\x8F\x0F\x44\x90\xB8\xF5\x35\x89\xF0\x5A\x23\x7F\x69"; const unsigned char testFileSHA384[48] = "\x7E\xDE\x62\xE2\x10\xA5\x1E\x18\x8A\x11\x7F\x78\xD7\xC7\x55\xB6" "\x43\x94\x1B\xD2\x78\x5C\xCF\xF3\x8A\xB8\x98\x22\xC7\x0E\xFE\xF1" "\xEC\x53\xE9\x1A\xB3\x51\x70\x8C\x1F\x3F\x56\x12\x44\x01\x91\x54"; const unsigned char testFileSHA512[64] = "\x8F\x36\x6E\x3C\x19\x4B\xBB\xC7\x82\xAA\xCD\x7D\x55\xA2\xD3\x29" "\x29\x97\x6A\x3F\xEB\x9B\xB2\xCB\x75\xC9\xEC\xC8\x10\x07\xD6\x07" "\x31\x4A\xB1\x30\x97\x82\x58\xA5\x1F\x71\x42\xE6\x56\x07\x99\x57" "\xB2\xB8\x3B\xA1\x8A\x41\x64\x33\x69\x21\x8C\x2A\x44\x6D\xF2\xA0"; @implementation OFCryptographicHashTests - (void)setUp { OFIRI *IRI; [super setUp]; IRI = [OFIRI IRIWithString: @"embedded:testfile.bin"]; _stream = [[OFIRIHandler openItemAtIRI: IRI mode: @"r"] retain]; } - (void)tearDown { [_stream close]; [super tearDown]; } - (void)dealloc { [_stream release]; [super dealloc]; } - (void)testHash: (Class)hashClass expectedDigest: (const unsigned char *)expectedDigest { id hash = [hashClass hashWithAllowsSwappableMemory: true]; id copy; OTAssertNotNil(hash); while (!_stream.atEndOfStream) { char buffer[64]; size_t length = [_stream readIntoBuffer: buffer length: 64]; [hash updateWithBuffer: buffer length: length]; } copy = [[hash copy] autorelease]; [hash calculate]; [copy calculate]; OTAssertEqual(memcmp(hash.digest, expectedDigest, hash.digestSize), 0); OTAssertEqual(memcmp(hash.digest, expectedDigest, hash.digestSize), 0); OTAssertThrowsSpecific([hash updateWithBuffer: "" length: 1], OFHashAlreadyCalculatedException); } - (void)testMD5 { [self testHash: [OFMD5Hash class] expectedDigest: testFileMD5]; } - (void)testRIPEMD160 { [self testHash: [OFRIPEMD160Hash class] expectedDigest: testFileRIPEMD160]; } - (void)testSHA1 { [self testHash: [OFSHA1Hash class] expectedDigest: testFileSHA1]; } - (void)testSHA224 { [self testHash: [OFSHA224Hash class] expectedDigest: testFileSHA224]; } - (void)testSHA256 { [self testHash: [OFSHA256Hash class] expectedDigest: testFileSHA256]; } - (void)testSHA384 { [self testHash: [OFSHA384Hash class] expectedDigest: testFileSHA384]; } - (void)testSHA512 { [self testHash: [OFSHA512Hash class] expectedDigest: testFileSHA512]; } @end objfw-1.1.6/tests/OFDDPSocketTests.m000066400000000000000000000033211465614216400172060ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "ObjFW.h" #import "ObjFWTest.h" @interface OFDDPSocketTests: OTTestCase @end @implementation OFDDPSocketTests - (void)testDDPSocket { OFDDPSocket *sock; OFSocketAddress address1, address2; char buffer[5]; sock = [OFDDPSocket socket]; @try { address1 = [sock bindToNetwork: 0 node: 0 port: 0 protocolType: 11]; } @catch (OFBindSocketFailedException *e) { switch (e.errNo) { case EAFNOSUPPORT: case EPROTONOSUPPORT: OTSkip(@"AppleTalk unsupported"); case EADDRNOTAVAIL: OTSkip(@"AppleTalk not configured"); default: @throw e; } } [sock sendBuffer: "Hello" length: 5 receiver: &address1]; OTAssertEqual([sock receiveIntoBuffer: buffer length: 5 sender: &address2], 5); OTAssertEqual(memcmp(buffer, "Hello", 5), 0); OTAssertTrue(OFSocketAddressEqual(&address1, &address2)); OTAssertEqual(OFSocketAddressHash(&address1), OFSocketAddressHash(&address2)); } @end objfw-1.1.6/tests/OFDNSResolverTests.m000066400000000000000000000045661465614216400176100ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" @interface OFDNSResolverTests: OTTestCase @end @implementation OFDNSResolverTests + (OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, id) *) *)summary { OFMutableArray *summary = [OFMutableArray array]; OFDNSResolver *resolver = [OFDNSResolver resolver]; OFMutableString *staticHosts = [OFMutableString string]; #define ADD(name, value) \ [summary addObject: [OFPair pairWithFirstObject: name \ secondObject: value]]; #define ADD_DOUBLE(name, value) \ ADD(name, [OFNumber numberWithDouble: value]) #define ADD_UINT(name, value) \ ADD(name, [OFNumber numberWithUnsignedInt: value]); #define ADD_BOOL(name, value) \ ADD(name, [OFNumber numberWithBool: value]); for (OFString *host in resolver.staticHosts) { OFString *IPs; if (staticHosts.length > 0) [staticHosts appendString: @"; "]; IPs = [[resolver.staticHosts objectForKey: host] componentsJoinedByString: @", "]; [staticHosts appendFormat: @"%@=(%@)", host, IPs]; } ADD(@"Static hosts", staticHosts) ADD(@"Name servers", [resolver.nameServers componentsJoinedByString: @", "]); ADD(@"Local domain", resolver.localDomain); ADD(@"Search domains", [resolver.searchDomains componentsJoinedByString: @", "]); ADD_DOUBLE(@"Timeout", resolver.timeout); ADD_UINT(@"Max attempts", resolver.maxAttempts); ADD_UINT(@"Min number of dots in absolute name", resolver.minNumberOfDotsInAbsoluteName); ADD_BOOL(@"Forces TCP", resolver.forcesTCP); ADD_DOUBLE(@"Config reload interval", resolver.configReloadInterval); #undef ADD #undef ADD_DOUBLE #undef ADD_UINT #undef ADD_BOOL return summary; } @end objfw-1.1.6/tests/OFDataTests.h000066400000000000000000000016231465614216400162750ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "ObjFW.h" #import "ObjFWTest.h" @interface OFDataTests: OTTestCase { OFData *_data; unsigned char _items[2][4096]; } @property (readonly, nonatomic) Class dataClass; @end objfw-1.1.6/tests/OFDataTests.m000066400000000000000000000165431465614216400163110ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFDataTests.h" @implementation OFDataTests - (Class)dataClass { return [OFData class]; } - (void)setUp { [super setUp]; memset(&_items[0], 0xFF, 4096); memset(&_items[1], 0x42, 4096); _data = [[self.dataClass alloc] initWithItems: _items count: 2 itemSize: 4096]; } - (void)dealloc { [_data release]; [super dealloc]; } - (void)testCount { OTAssertEqual(_data.count, 2); } - (void)testItemSize { OTAssertEqual(_data.itemSize, 4096); } - (void)testItems { OTAssertEqual(memcmp(_data.items, _items, 2 * _data.itemSize), 0); } - (void)testItemAtIndex { OTAssertEqual( memcmp([_data itemAtIndex: 1], &_items[1], _data.itemSize), 0); } - (void)testItemAtIndexThrowsOnOutOfRangeIndex { OTAssertThrowsSpecific([_data itemAtIndex: _data.count], OFOutOfRangeException); } - (void)testFirstItem { OTAssertEqual(memcmp(_data.firstItem, &_items[0], _data.itemSize), 0); } - (void)testLastItem { OTAssertEqual(memcmp(_data.lastItem, &_items[1], _data.itemSize), 0); } - (void)testIsEqual { OTAssertEqualObjects( _data, [OFData dataWithItems: _items count: 2 itemSize: 4096]); OTAssertNotEqualObjects( _data, [OFData dataWithItems: _items count: 1 itemSize: 4096]); } - (void)testHash { OTAssertEqual(_data.hash, [[OFData dataWithItems: _items count: 2 itemSize: 4096] hash]); OTAssertNotEqual(_data.hash, [[OFData dataWithItems: _items count: 1 itemSize: 4096] hash]); } - (void)testCompare { OFData *data1 = [self.dataClass dataWithItems: "aa" count: 2]; OFData *data2 = [self.dataClass dataWithItems: "ab" count: 2]; OFData *data3 = [self.dataClass dataWithItems: "aaa" count: 3]; OTAssertEqual([data1 compare: data2], OFOrderedAscending); OTAssertEqual([data2 compare: data1], OFOrderedDescending); OTAssertEqual([data1 compare: data1], OFOrderedSame); OTAssertEqual([data1 compare: data3], OFOrderedAscending); OTAssertEqual([data2 compare: data3], OFOrderedDescending); } - (void)testCopy { OTAssertEqualObjects([[_data copy] autorelease], _data); } - (void)testRangeOfDataOptionsRange { OFData *data = [self.dataClass dataWithItems: "aaabaccdacaabb" count: 7 itemSize: 2]; OFRange range; range = [data rangeOfData: [self.dataClass dataWithItems: "aa" count: 1 itemSize: 2] options: 0 range: OFMakeRange(0, 7)]; OTAssertEqual(range.location, 0); OTAssertEqual(range.length, 1); range = [data rangeOfData: [self.dataClass dataWithItems: "aa" count: 1 itemSize: 2] options: OFDataSearchBackwards range: OFMakeRange(0, 7)]; OTAssertEqual(range.location, 5); OTAssertEqual(range.length, 1); range = [data rangeOfData: [self.dataClass dataWithItems: "ac" count: 1 itemSize: 2] options: 0 range: OFMakeRange(0, 7)]; OTAssertEqual(range.location, 2); OTAssertEqual(range.length, 1); range = [data rangeOfData: [self.dataClass dataWithItems: "aabb" count: 2 itemSize: 2] options: 0 range: OFMakeRange(0, 7)]; OTAssertEqual(range.location, 5); OTAssertEqual(range.length, 2); range = [data rangeOfData: [self.dataClass dataWithItems: "aa" count: 1 itemSize: 2] options: 0 range: OFMakeRange(1, 6)]; OTAssertEqual(range.location, 5); OTAssertEqual(range.length, 1); range = [data rangeOfData: [self.dataClass dataWithItems: "aa" count: 1 itemSize: 2] options: OFDataSearchBackwards range: OFMakeRange(0, 5)]; OTAssertEqual(range.location, 0); OTAssertEqual(range.length, 1); } - (void)testRangeOfDataOptionsRangeThrowsOnDifferentItemSize { OTAssertThrowsSpecific( [_data rangeOfData: [OFData dataWithItems: "a" count: 1] options: 0 range: OFMakeRange(0, 1)], OFInvalidArgumentException); } - (void)testRangeOfDataOptionsRangeThrowsOnOutOfRangeRange { OTAssertThrowsSpecific( [_data rangeOfData: [OFData dataWithItemSize: 4096] options: 0 range: OFMakeRange(1, 2)], OFOutOfRangeException); OTAssertThrowsSpecific( [_data rangeOfData: [OFData dataWithItemSize: 4096] options: 0 range: OFMakeRange(2, 1)], OFOutOfRangeException); } - (void)testSubdataWithRange { OFData *data1 = [self.dataClass dataWithItems: "aaabaccdacaabb" count: 7 itemSize: 2]; OFData *data2 = [self.dataClass dataWithItems: "abcde" count: 5]; OTAssertEqualObjects( [data1 subdataWithRange: OFMakeRange(2, 4)], [OFData dataWithItems: "accdacaa" count: 4 itemSize: 2]); OTAssertEqualObjects( [data2 subdataWithRange: OFMakeRange(2, 3)], [OFData dataWithItems: "cde" count: 3]); } - (void)testSubdataWithRangeThrowsOnOutOfRangeRange { OFData *data1 = [self.dataClass dataWithItems: "aaabaccdacaabb" count: 7 itemSize: 2]; OFData *data2 = [self.dataClass dataWithItems: "abcde" count: 5]; OTAssertThrowsSpecific([data1 subdataWithRange: OFMakeRange(7, 1)], OFOutOfRangeException); OTAssertThrowsSpecific([data1 subdataWithRange: OFMakeRange(8, 0)], OFOutOfRangeException); OTAssertThrowsSpecific([data2 subdataWithRange: OFMakeRange(6, 1)], OFOutOfRangeException); } - (void)testStringByMD5Hashing { OTAssertEqualObjects(_data.stringByMD5Hashing, @"37d65c8816008d58175b1d71ee892de3"); } - (void)testStringByRIPEMD160Hashing { OTAssertEqualObjects(_data.stringByRIPEMD160Hashing, @"ab33a6a725f9fcec6299054dc604c0eb650cd889"); } - (void)testStringBySHA1Hashing { OTAssertEqualObjects(_data.stringBySHA1Hashing, @"eb50cfcc29d0bed96b3bafe03e99110bcf6663b3"); } - (void)testStringBySHA224Hashing { OTAssertEqualObjects(_data.stringBySHA224Hashing, @"204f8418a914a6828f8eb27871e01f74366f6d8fac8936029ebf0041"); } - (void)testStringBySHA256Hashing { OTAssertEqualObjects(_data.stringBySHA256Hashing, @"27c521859f6f5b10aeac4e210a6d005c" @"85e382c594e2622af9c46c6da8906821"); } - (void)testStringBySHA384Hashing { OTAssertEqualObjects(_data.stringBySHA384Hashing, @"af99a52c26c00f01fe649dcc53d7c7a0" @"a9ee0150b971955be2af395708966120" @"5f2634f70df083ef63b232d5b8549db4"); } - (void)testStringBySHA512Hashing { OTAssertEqualObjects(_data.stringBySHA512Hashing, @"1cbd53bf8bed9b45a63edda645ee1217" @"24d2f0323c865e1039ba13320bc6c66e" @"c79b6cdf6d08395c612b7decb1e59ad1" @"e72bfa007c2f76a823d10204d47d2e2d"); } - (void)testStringByBase64Encoding { OTAssertEqualObjects([[self.dataClass dataWithItems: "abcde" count: 5] stringByBase64Encoding], @"YWJjZGU="); } - (void)testDataWithBase64EncodedString { OTAssertEqualObjects( [self.dataClass dataWithBase64EncodedString: @"YWJjZGU="], [OFData dataWithItems: "abcde" count: 5]); } @end objfw-1.1.6/tests/OFDateTests.m000066400000000000000000000107321465614216400163070ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "ObjFW.h" #import "ObjFWTest.h" #import "OFStrPTime.h" @interface OFDateTests: OTTestCase { OFDate *_date[2]; } @end @implementation OFDateTests - (void)setUp { [super setUp]; _date[0] = [[OFDate alloc] initWithTimeIntervalSince1970: 0]; _date[1] = [[OFDate alloc] initWithTimeIntervalSince1970: 3600 * 25 + 5.000002]; } - (void)dealloc { [_date[0] release]; [_date[1] release]; [super dealloc]; } - (void)testStrPTime { struct tm tm; int16_t timeZone; const char *dateString = "Wed, 09 Jun 2021 +0200x"; OTAssertEqual(_OFStrPTime(dateString, "%a, %d %b %Y %z", &tm, &timeZone), dateString + 22); OTAssertEqual(tm.tm_wday, 3); OTAssertEqual(tm.tm_mday, 9); OTAssertEqual(tm.tm_mon, 5); OTAssertEqual(tm.tm_year, 2021 - 1900); OTAssertEqual(timeZone, 2 * 60); } - (void)testDateByAddingTimeInterval { OTAssertEqualObjects( [_date[0] dateByAddingTimeInterval: 3600 * 25 + 5.000002], _date[1]); } - (void)testDescription { OTAssertEqualObjects(_date[0].description, @"1970-01-01T00:00:00Z"); OTAssertEqualObjects(_date[1].description, @"1970-01-02T01:00:05Z"); } - (void)testDateWithDateStringFormat { OTAssertEqualObjects( [[OFDate dateWithDateString: @"2000-06-20T12:34:56+0200" format: @"%Y-%m-%dT%H:%M:%S%z"] description], @"2000-06-20T10:34:56Z"); } - (void)testDateWithDateStringFormatFailsWithTrailingCharacters { OTAssertThrowsSpecific( [OFDate dateWithDateString: @"2000-06-20T12:34:56+0200x" format: @"%Y-%m-%dT%H:%M:%S%z"], OFInvalidFormatException); } - (void)testDateWithLocalDateStringFormatFormat { OTAssertEqualObjects( [[OFDate dateWithLocalDateString: @"2000-06-20T12:34:56" format: @"%Y-%m-%dT%H:%M:%S"] localDateStringWithFormat: @"%Y-%m-%dT%H:%M:%S"], @"2000-06-20T12:34:56"); OTAssertEqualObjects( [[OFDate dateWithLocalDateString: @"2000-06-20T12:34:56-0200" format: @"%Y-%m-%dT%H:%M:%S%z"] description], @"2000-06-20T14:34:56Z"); } - (void)testDateWithLocalDateStringFormatFailsWithTrailingCharacters { OTAssertThrowsSpecific( [OFDate dateWithLocalDateString: @"2000-06-20T12:34:56x" format: @"%Y-%m-%dT%H:%M:%S"], OFInvalidFormatException); OTAssertThrowsSpecific( [OFDate dateWithLocalDateString: @"2000-06-20T12:34:56+0200x" format: @"%Y-%m-%dT%H:%M:%S%z"], OFInvalidFormatException); } - (void)testIsEqual { OTAssertEqualObjects(_date[0], [OFDate dateWithTimeIntervalSince1970: 0]); OTAssertNotEqualObjects(_date[0], [OFDate dateWithTimeIntervalSince1970: 0.0000001]); } - (void)testCompare { OTAssertEqual([_date[0] compare: _date[1]], OFOrderedAscending); } - (void)testSecond { OTAssertEqual(_date[0].second, 0); OTAssertEqual(_date[1].second, 5); } - (void)testMicrosecond { OTAssertEqual(_date[0].microsecond, 0); OTAssertEqual(_date[1].microsecond, 2); } - (void)testMinute { OTAssertEqual(_date[0].minute, 0); OTAssertEqual(_date[1].minute, 0); } - (void)testHour { OTAssertEqual(_date[0].hour, 0); OTAssertEqual(_date[1].hour, 1); } - (void)testDayOfMonth { OTAssertEqual(_date[0].dayOfMonth, 1); OTAssertEqual(_date[1].dayOfMonth, 2); } - (void)testMonthOfYear { OTAssertEqual(_date[0].monthOfYear, 1); OTAssertEqual(_date[1].monthOfYear, 1); } - (void)testYear { OTAssertEqual(_date[0].year, 1970); OTAssertEqual(_date[1].year, 1970); } - (void)testDayOfWeek { OTAssertEqual(_date[0].dayOfWeek, 4); OTAssertEqual(_date[1].dayOfWeek, 5); } - (void)testDayOfYear { OTAssertEqual(_date[0].dayOfYear, 1); OTAssertEqual(_date[1].dayOfYear, 2); } - (void)testEarlierDate { OTAssertEqualObjects([_date[0] earlierDate: _date[1]], _date[0]); } - (void)testLaterDate { OTAssertEqualObjects([_date[0] laterDate: _date[1]], _date[1]); } @end objfw-1.1.6/tests/OFDictionaryTests.h000066400000000000000000000016131465614216400175300ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "ObjFW.h" #import "ObjFWTest.h" @interface OFDictionaryTests: OTTestCase { OFDictionary *_dictionary; } @property (readonly, nonatomic) Class dictionaryClass; @end objfw-1.1.6/tests/OFDictionaryTests.m000066400000000000000000000150201465614216400175320ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFDictionaryTests.h" static OFString *keys[] = { @"key1", @"key2" }; static OFString *objects[] = { @"value1", @"value2" }; @interface CustomDictionary: OFDictionary { OFDictionary *_dictionary; } @end @implementation OFDictionaryTests - (Class)dictionaryClass { return [CustomDictionary class]; } - (void)setUp { [super setUp]; _dictionary = [[self.dictionaryClass alloc] initWithObjects: objects forKeys: keys count: 2]; } - (void)dealloc { [_dictionary release]; [super dealloc]; } - (void)testObjectForKey { OTAssertEqualObjects([_dictionary objectForKey: keys[0]], objects[0]); OTAssertEqualObjects([_dictionary objectForKey: keys[1]], objects[1]); } - (void)testCount { OTAssertEqual(_dictionary.count, 2); } - (void)testIsEqual { OTAssertEqualObjects(_dictionary, [OFDictionary dictionaryWithObjects: objects forKeys: keys count: 2]); OTAssertNotEqualObjects(_dictionary, [OFDictionary dictionaryWithObjects: keys forKeys: objects count: 2]); } - (void)testHash { OTAssertEqual(_dictionary.hash, [[OFDictionary dictionaryWithObjects: objects forKeys: keys count: 2] hash]); OTAssertNotEqual(_dictionary.hash, [[OFDictionary dictionaryWithObject: objects[0] forKey: keys[0]] hash]); } - (void)testCopy { OTAssertEqualObjects([[_dictionary copy] autorelease], _dictionary); } - (void)testMutableCopy { OTAssertEqualObjects( [[_dictionary mutableCopy] autorelease], _dictionary); } - (void)testValueForKey { OTAssertEqualObjects([_dictionary valueForKey: keys[0]], objects[0]); OTAssertEqualObjects([_dictionary valueForKey: keys[1]], objects[1]); OTAssertEqualObjects( [_dictionary valueForKey: @"@count"], [OFNumber numberWithInt: 2]); } - (void)testSetValueForKey { OTAssertThrowsSpecific([_dictionary setValue: @"x" forKey: @"x"], OFUndefinedKeyException); } - (void)testContainsObject { OTAssertTrue([_dictionary containsObject: objects[0]]); OTAssertFalse([_dictionary containsObject: @"nonexistent"]); } - (void)testContainsObjectIdenticalTo { OTAssertTrue([_dictionary containsObjectIdenticalTo: objects[0]]); OTAssertFalse([_dictionary containsObjectIdenticalTo: [[objects[0] mutableCopy] autorelease]]); } - (void)testDescription { OTAssert( [_dictionary.description isEqual: @"{\n\tkey1 = value1;\n\tkey2 = value2;\n}"] || [_dictionary.description isEqual: @"{\n\tkey2 = value2;\n\tkey1 = value1;\n}"]); } - (void)testAllKeys { OTAssert( [_dictionary.allKeys isEqual: ([OFArray arrayWithObjects: keys[0], keys[1], nil])] || [_dictionary.allKeys isEqual: ([OFArray arrayWithObjects: keys[1], keys[0], nil])]); } - (void)testAllObjects { OTAssert( [_dictionary.allObjects isEqual: ([OFArray arrayWithObjects: objects[0], objects[1], nil])] || [_dictionary.allObjects isEqual: ([OFArray arrayWithObjects: objects[1], objects[0], nil])]); } - (void)testKeyEnumerator { OFEnumerator *enumerator = [_dictionary keyEnumerator]; OFString *first, *second; first = [enumerator nextObject]; second = [enumerator nextObject]; OTAssertNil([enumerator nextObject]); OTAssert( ([first isEqual: keys[0]] && [second isEqual: keys[1]]) || ([first isEqual: keys[1]] && [second isEqual: keys[0]])); } - (void)testObjectEnumerator { OFEnumerator *enumerator = [_dictionary objectEnumerator]; OFString *first, *second; first = [enumerator nextObject]; second = [enumerator nextObject]; OTAssertNil([enumerator nextObject]); OTAssert( ([first isEqual: objects[0]] && [second isEqual: objects[1]]) || ([first isEqual: objects[1]] && [second isEqual: objects[0]])); } - (void)testFastEnumeration { size_t i = 0; OFString *first = nil, *second = nil; for (OFString *key in _dictionary) { OTAssertLessThan(i, 2); switch (i++) { case 0: first = key; break; case 1: second = key; break; } } OTAssertEqual(i, 2); OTAssert( ([first isEqual: keys[0]] && [second isEqual: keys[1]]) || ([first isEqual: keys[1]] && [second isEqual: keys[0]])); } #ifdef OF_HAVE_BLOCKS - (void)testEnumerateKeysAndObjectsUsingBlock { __block size_t i = 0; __block OFString *first = nil, *second = nil; [_dictionary enumerateKeysAndObjectsUsingBlock: ^ (id key, id object, bool *stop) { OTAssertLessThan(i, 2); switch (i++) { case 0: first = key; break; case 1: second = key; break; } }]; OTAssertEqual(i, 2); OTAssert( ([first isEqual: keys[0]] && [second isEqual: keys[1]]) || ([first isEqual: keys[1]] && [second isEqual: keys[0]])); } - (void)testMappedDictionaryUsingBlock { OTAssertEqualObjects([_dictionary mappedDictionaryUsingBlock: ^ id (id key, id object) { if ([key isEqual: keys[0]]) return @"val1"; if ([key isEqual: keys[1]]) return @"val2"; return nil; }], ([OFDictionary dictionaryWithKeysAndObjects: @"key1", @"val1", @"key2", @"val2", nil])); } - (void)testFilteredDictionaryUsingBlock { OTAssertEqualObjects([_dictionary filteredDictionaryUsingBlock: ^ bool (id key, id object) { return [key isEqual: keys[0]]; }], [OFDictionary dictionaryWithObject: objects[0] forKey: keys[0]]); } #endif @end @implementation CustomDictionary - (instancetype)initWithObjects: (const id *)objects_ forKeys: (const id *)keys_ count: (size_t)count { self = [super init]; @try { _dictionary = [[OFDictionary alloc] initWithObjects: objects_ forKeys: keys_ count: count]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_dictionary release]; [super dealloc]; } - (id)objectForKey: (id)key { return [_dictionary objectForKey: key]; } - (size_t)count { return _dictionary.count; } - (OFEnumerator *)keyEnumerator { return [_dictionary keyEnumerator]; } @end objfw-1.1.6/tests/OFFileManagerTests.m000066400000000000000000000351571465614216400176140ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "ObjFW.h" #import "ObjFWTest.h" @interface OFFileManagerTests: OTTestCase { OFFileManager *_fileManager; OFIRI *_testsDirectoryIRI, *_testFileIRI; } @end @implementation OFFileManagerTests - (void)setUp { _fileManager = [[OFFileManager defaultManager] retain]; _testsDirectoryIRI = [[[OFSystemInfo temporaryDirectoryIRI] IRIByAppendingPathComponent: @"objfw-tests"] retain]; _testFileIRI = [[_testsDirectoryIRI IRIByAppendingPathComponent: @"test.txt"] retain]; /* In case a previous test run failed and left things. */ if ([_fileManager directoryExistsAtIRI: _testsDirectoryIRI]) [_fileManager removeItemAtIRI: _testsDirectoryIRI]; [_fileManager createDirectoryAtIRI: _testsDirectoryIRI]; [@"test" writeToIRI: _testFileIRI]; } - (void)tearDown { [_fileManager removeItemAtIRI: _testsDirectoryIRI]; } - (void)dealloc { [_fileManager release]; [_testsDirectoryIRI release]; [_testFileIRI release]; [super dealloc]; } - (void)testCurrentDirectoryPath { OTAssertEqualObjects( _fileManager.currentDirectoryPath.lastPathComponent, @"tests"); } - (void)testAttributesOfItemAtPath { OFFileAttributes attributes; attributes = [_fileManager attributesOfItemAtPath: _testsDirectoryIRI.fileSystemRepresentation]; OTAssertEqual(attributes.fileType, OFFileTypeDirectory); attributes = [_fileManager attributesOfItemAtPath: _testFileIRI.fileSystemRepresentation]; OTAssertEqual(attributes.fileType, OFFileTypeRegular); OTAssertEqual(attributes.fileSize, 4); } - (void)testSetAttributesOfItemAtPath { OFDate *date = [OFDate dateWithTimeIntervalSince1970: 946681200]; OFFileAttributes attributes; attributes = [OFDictionary dictionaryWithObject: date forKey: OFFileModificationDate]; [_fileManager setAttributes: attributes ofItemAtPath: _testFileIRI.fileSystemRepresentation]; attributes = [_fileManager attributesOfItemAtPath: _testFileIRI.fileSystemRepresentation]; OTAssertEqual(attributes.fileType, OFFileTypeRegular); OTAssertEqual(attributes.fileSize, 4); OTAssertEqualObjects(attributes.fileModificationDate, date); } - (void)testFileExistsAtPath { OTAssertTrue([_fileManager fileExistsAtPath: _testsDirectoryIRI.fileSystemRepresentation]); OTAssertTrue([_fileManager fileExistsAtPath: _testFileIRI.fileSystemRepresentation]); } - (void)testDirectoryExistsAtPath { OTAssertTrue([_fileManager directoryExistsAtPath: _testsDirectoryIRI.fileSystemRepresentation]); OTAssertFalse([_fileManager directoryExistsAtPath: _testFileIRI.fileSystemRepresentation]); } - (void)testDirectoryAtPathCreateParents { OFIRI *nestedDirectoryIRI = [_testsDirectoryIRI IRIByAppendingPathComponent: @"0/1/2/3/4/5"]; [_fileManager createDirectoryAtPath: nestedDirectoryIRI.fileSystemRepresentation createParents: true]; OTAssertTrue([_fileManager directoryExistsAtPath: nestedDirectoryIRI.fileSystemRepresentation]); } - (void)testContentsOfDirectoryAtPath { OFIRI *file1IRI = [_testsDirectoryIRI IRIByAppendingPathComponent: @"1.txt"]; OFIRI *file2IRI = [_testsDirectoryIRI IRIByAppendingPathComponent: @"2.txt"]; [@"1" writeToIRI: file1IRI]; [@"2" writeToIRI: file2IRI]; OTAssertEqualObjects([_fileManager contentsOfDirectoryAtPath: _testsDirectoryIRI.fileSystemRepresentation].sortedArray, ([OFArray arrayWithObjects: @"1.txt", @"2.txt", @"test.txt", nil])); } - (void)testSubpathsOfDirectoryAtPath { OFIRI *subdirectory1IRI = [_testsDirectoryIRI IRIByAppendingPathComponent: @"a"]; OFIRI *subdirectory2IRI = [_testsDirectoryIRI IRIByAppendingPathComponent: @"b"]; OFIRI *file1IRI = [subdirectory1IRI IRIByAppendingPathComponent: @"1.txt"]; OFIRI *file2IRI = [subdirectory2IRI IRIByAppendingPathComponent: @"2.txt"]; [_fileManager createDirectoryAtIRI: subdirectory1IRI]; [_fileManager createDirectoryAtIRI: subdirectory2IRI]; [@"1" writeToIRI: file1IRI]; [@"2" writeToIRI: file2IRI]; OTAssertEqualObjects([_fileManager subpathsOfDirectoryAtPath: _testsDirectoryIRI.fileSystemRepresentation].sortedArray, ([OFArray arrayWithObjects: _testsDirectoryIRI.fileSystemRepresentation, subdirectory1IRI.fileSystemRepresentation, file1IRI.fileSystemRepresentation, subdirectory2IRI.fileSystemRepresentation, file2IRI.fileSystemRepresentation, _testFileIRI.fileSystemRepresentation, nil])); } - (void)testChangeCurrentDirectoryPath { OFString *oldDirectoryPath = _fileManager.currentDirectoryPath; OTAssertFalse([_fileManager fileExistsAtPath: @"test.txt"]); [_fileManager changeCurrentDirectoryPath: _testsDirectoryIRI.fileSystemRepresentation]; @try { /* * We can't check whether currentDirectoryPath is * _testsDirectoryIRI.fileSystemRepresentation because they * could be different due to symlinks. Therefore check for * presence of test.txt instead. */ OTAssertTrue([_fileManager fileExistsAtPath: @"test.txt"]); } @finally { [_fileManager changeCurrentDirectoryPath: oldDirectoryPath]; } } - (void)testCopyItemAtPathToPath { OFIRI *sourceIRI = [_testsDirectoryIRI IRIByAppendingPathComponent: @"source"]; OFIRI *destinationIRI = [_testsDirectoryIRI IRIByAppendingPathComponent: @"destination"]; OFIRI *subdirectory1IRI = [sourceIRI IRIByAppendingPathComponent: @"a"]; OFIRI *subdirectory2IRI = [sourceIRI IRIByAppendingPathComponent: @"b"]; OFIRI *file1IRI = [subdirectory1IRI IRIByAppendingPathComponent: @"1.txt"]; OFIRI *file2IRI = [subdirectory2IRI IRIByAppendingPathComponent: @"2.txt"]; [_fileManager createDirectoryAtIRI: subdirectory1IRI createParents: true]; [_fileManager createDirectoryAtIRI: subdirectory2IRI createParents: true]; [@"1" writeToIRI: file1IRI]; [@"2" writeToIRI: file2IRI]; subdirectory1IRI = [destinationIRI IRIByAppendingPathComponent: @"a"]; subdirectory2IRI = [destinationIRI IRIByAppendingPathComponent: @"b"]; file1IRI = [subdirectory1IRI IRIByAppendingPathComponent: @"1.txt"]; file2IRI = [subdirectory2IRI IRIByAppendingPathComponent: @"2.txt"]; OTAssertFalse([_fileManager directoryExistsAtIRI: subdirectory1IRI]); OTAssertFalse([_fileManager directoryExistsAtIRI: subdirectory2IRI]); OTAssertFalse([_fileManager fileExistsAtIRI: file1IRI]); OTAssertFalse([_fileManager fileExistsAtIRI: file2IRI]); [_fileManager copyItemAtPath: sourceIRI.fileSystemRepresentation toPath: destinationIRI.fileSystemRepresentation]; OTAssertTrue([_fileManager directoryExistsAtIRI: subdirectory1IRI]); OTAssertTrue([_fileManager directoryExistsAtIRI: subdirectory2IRI]); OTAssertEqualObjects([OFString stringWithContentsOfIRI: file1IRI], @"1"); OTAssertEqualObjects([OFString stringWithContentsOfIRI: file2IRI], @"2"); } - (void)testMoveItemAtPathToPath { OFIRI *sourceIRI = [_testsDirectoryIRI IRIByAppendingPathComponent: @"source"]; OFIRI *destinationIRI = [_testsDirectoryIRI IRIByAppendingPathComponent: @"destination"]; OFIRI *subdirectory1IRI = [sourceIRI IRIByAppendingPathComponent: @"a"]; OFIRI *subdirectory2IRI = [sourceIRI IRIByAppendingPathComponent: @"b"]; OFIRI *file1IRI = [subdirectory1IRI IRIByAppendingPathComponent: @"1.txt"]; OFIRI *file2IRI = [subdirectory2IRI IRIByAppendingPathComponent: @"2.txt"]; [_fileManager createDirectoryAtIRI: subdirectory1IRI createParents: true]; [_fileManager createDirectoryAtIRI: subdirectory2IRI createParents: true]; [@"1" writeToIRI: file1IRI]; [@"2" writeToIRI: file2IRI]; [_fileManager moveItemAtPath: sourceIRI.fileSystemRepresentation toPath: destinationIRI.fileSystemRepresentation]; OTAssertFalse([_fileManager directoryExistsAtIRI: subdirectory1IRI]); OTAssertFalse([_fileManager directoryExistsAtIRI: subdirectory2IRI]); OTAssertFalse([_fileManager fileExistsAtIRI: file1IRI]); OTAssertFalse([_fileManager fileExistsAtIRI: file2IRI]); subdirectory1IRI = [destinationIRI IRIByAppendingPathComponent: @"a"]; subdirectory2IRI = [destinationIRI IRIByAppendingPathComponent: @"b"]; file1IRI = [subdirectory1IRI IRIByAppendingPathComponent: @"1.txt"]; file2IRI = [subdirectory2IRI IRIByAppendingPathComponent: @"2.txt"]; OTAssertTrue([_fileManager directoryExistsAtIRI: subdirectory1IRI]); OTAssertTrue([_fileManager directoryExistsAtIRI: subdirectory2IRI]); OTAssertEqualObjects([OFString stringWithContentsOfIRI: file1IRI], @"1"); OTAssertEqualObjects([OFString stringWithContentsOfIRI: file2IRI], @"2"); } - (void)testRemoveItemAtPath { OFIRI *subdirectoryIRI = [_testsDirectoryIRI IRIByAppendingPathComponent: @"dir"]; OFIRI *fileIRI = [subdirectoryIRI IRIByAppendingPathComponent: @"file.txt"]; [_fileManager createDirectoryAtIRI: subdirectoryIRI]; [@"file" writeToIRI: fileIRI]; OTAssertTrue([_fileManager directoryExistsAtIRI: subdirectoryIRI]); OTAssertTrue([_fileManager fileExistsAtIRI: fileIRI]); [_fileManager removeItemAtPath: subdirectoryIRI.fileSystemRepresentation]; OTAssertFalse([_fileManager fileExistsAtIRI: fileIRI]); OTAssertFalse([_fileManager directoryExistsAtIRI: subdirectoryIRI]); } #ifdef OF_FILE_MANAGER_SUPPORTS_LINKS - (void)testLinkItemAtPathToPath { OFIRI *sourceIRI = [_testsDirectoryIRI IRIByAppendingPathComponent: @"source"]; OFIRI *destinationIRI = [_testsDirectoryIRI IRIByAppendingPathComponent: @"destination"]; OFFileAttributes attributes; [@"test" writeToIRI: sourceIRI]; @try { [_fileManager linkItemAtPath: sourceIRI.fileSystemRepresentation toPath: destinationIRI.fileSystemRepresentation]; } @catch (OFNotImplementedException *e) { OTSkip(@"Links not supported"); } attributes = [_fileManager attributesOfItemAtIRI: destinationIRI]; OTAssertEqual(attributes.fileType, OFFileTypeRegular); OTAssertEqual(attributes.fileSize, 4); OTAssertEqualObjects([OFString stringWithContentsOfIRI: destinationIRI], @"test"); } #endif #ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS - (void)testCreateSymbolicLinkAtPathWithDestinationPath { OFIRI *sourceIRI, *destinationIRI; OFFileAttributes attributes; # ifdef OF_WINDOWS if ([OFSystemInfo wineVersion] != nil) OTSkip(@"Wine creates broken symlinks"); # endif sourceIRI = [_testsDirectoryIRI IRIByAppendingPathComponent: @"source"]; destinationIRI = [_testsDirectoryIRI IRIByAppendingPathComponent: @"destination"]; [@"test" writeToIRI: sourceIRI]; @try { OFString *sourcePath = sourceIRI.fileSystemRepresentation; OFString *destinationPath = destinationIRI.fileSystemRepresentation; [_fileManager createSymbolicLinkAtPath: destinationPath withDestinationPath: sourcePath]; } @catch (OFCreateSymbolicLinkFailedException *e) { if (e.errNo != EPERM) @throw e; OTSkip(@"No permission to create symlink.\n" @"On Windows, only the administrator can create symbolic " @"links."); } @catch (OFNotImplementedException *e) { OTSkip(@"Symlinks not supported"); } attributes = [_fileManager attributesOfItemAtIRI: destinationIRI]; OTAssertEqual(attributes.fileType, OFFileTypeSymbolicLink); OTAssertEqualObjects([OFString stringWithContentsOfIRI: destinationIRI], @"test"); } #endif #ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES - (void)testExtendedAttributes { OFData *data = [OFData dataWithItems: "test" count: 4]; OFString *testFilePath = _testFileIRI.fileSystemRepresentation; OFFileAttributes attributes; OFArray *extendedAttributeNames; @try { [_fileManager setExtendedAttributeData: data forName: @"user.test" ofItemAtPath: testFilePath]; } @catch (OFSetItemAttributesFailedException *e) { if (e.errNo != ENOTSUP && e.errNo != EOPNOTSUPP) @throw e; OTSkip(@"Extended attributes are not supported"); } attributes = [_fileManager attributesOfItemAtIRI: _testFileIRI]; extendedAttributeNames = [attributes objectForKey: OFFileExtendedAttributesNames]; OTAssertNotNil(extendedAttributeNames); OTAssertTrue([extendedAttributeNames containsObject: @"user.test"]); OTAssertEqualObjects( [_fileManager extendedAttributeDataForName: @"user.test" ofItemAtPath: testFilePath], data); [_fileManager removeExtendedAttributeForName: @"user.test" ofItemAtPath: testFilePath]; attributes = [_fileManager attributesOfItemAtIRI: _testFileIRI]; extendedAttributeNames = [attributes objectForKey: OFFileExtendedAttributesNames]; OTAssertNotNil(extendedAttributeNames); OTAssertFalse([extendedAttributeNames containsObject: @"user.test"]); OTAssertThrowsSpecific( [_fileManager extendedAttributeDataForName: @"user.test" ofItemAtPath: testFilePath], OFGetItemAttributesFailedException); } #endif #ifdef OF_HAIKU - (void)testGetExtendedAttributeDataAndTypeForNameOfItemAtPath { OFData *data; id type; [_fileManager getExtendedAttributeData: &data andType: &type forName: @"BEOS:TYPE" ofItemAtPath: @"/boot/system/lib/libbe.so"]; OTAssertEqualObjects(type, [OFNumber numberWithUnsignedLong: B_MIME_STRING_TYPE]); OTAssertEqualObjects(data, [OFData dataWithItems: "application/x-vnd.Be-elfexecutable" count: 35]); } - (void)testSetExtendedAttributeDataAndTypeForNameOfItemAtPath { OFString *testFilePath = _testFileIRI.fileSystemRepresentation; OFData *data, *expectedData = [OFData dataWithItems: "foobar" count: 6]; id type, expectedType = [OFNumber numberWithUnsignedLong: 1234]; [_fileManager setExtendedAttributeData: expectedData andType: expectedType forName: @"testattribute" ofItemAtPath: testFilePath]; [_fileManager getExtendedAttributeData: &data andType: &type forName: @"testattribute" ofItemAtPath: testFilePath]; OTAssertEqualObjects(data, expectedData); OTAssertEqualObjects(type, expectedType); [_fileManager removeExtendedAttributeForName: @"testattribute" ofItemAtPath: testFilePath]; OTAssertThrowsSpecific( [_fileManager getExtendedAttributeData: &data andType: &type forName: @"testattribute" ofItemAtPath: testFilePath], OFGetItemAttributesFailedException); } #endif @end objfw-1.1.6/tests/OFHMACTests.m000066400000000000000000000076161465614216400161510ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "ObjFW.h" #import "ObjFWTest.h" @interface OFHMACTests: OTTestCase { OFStream *_stream; } @end static const uint8_t key[] = "yM9h8K6IWnJRvxC/0F8XRWG7RnACDBz8wqK2tbXrYVLoKC3vPLeJikyJSM47tVHc" "DlXHww9zULAC2sJUlm2Kg1z4oz2aXY3Y1PQSB4VkC/m0DQ7hCI6cAg4TWnKdzWTy" "cvYGX+Y6HWeDY79/PGSd8fNItme6I8w4HDBqU7BP2sum3jbePJqoiSnhcyJZQTeZ" "jw0ZXoyrfHgOYD2M+NsTDaGpLblFtQ7n5CczjKtafG40PkEwx1dcrd46U9i3GyTK"; static const size_t keyLength = sizeof(key); static const uint8_t MD5Digest[] = "\xCC\x1F\xEF\x09\x29\xA3\x25\x1A\x06\xA9\x83\x99\xF9\xBC\x8F\x42"; static const uint8_t SHA1Digest[] = "\x94\xB9\x0A\x6F\xFB\xA7\x13\x6A\x75\x55" "\xD5\x7F\x5D\xB7\xF4\xCA\xEB\x4A\xDE\xBF"; static const uint8_t RIPEMD160Digest[] = "\x2C\xE1\xED\x41\xC6\xF3\x51\xA8\x04\xD2" "\xC3\x9B\x08\x33\x3B\xD5\xC9\x00\x39\x50"; static const uint8_t SHA256Digest[] = "\xFB\x8C\xDA\x88\xB3\x81\x32\x16\xD7\xD8\x62\xD4\xA6\x26\x9D\x77" "\x01\x99\x62\x65\x29\x02\x41\xE6\xEF\xA1\x02\x31\xA8\x9D\x77\x5D"; static const uint8_t SHA384Digest[] = "\x2F\x4A\x47\xAE\x13\x8E\x96\x52\xF1\x8F\x05\xFD\x65\xCD\x9A\x97" "\x93\x2F\xC9\x02\xD6\xC6\xAB\x2E\x15\x76\xC0\xA7\xA0\x05\xF4\xEF" "\x14\x52\x33\x4B\x9C\x5F\xD8\x07\x4E\x98\xAE\x97\x46\x29\x24\xB4"; static const uint8_t SHA512Digest[] = "\xF5\x8C\x3F\x9C\xA2\x2F\x0A\xF3\x26\xD8\xC0\x7E\x20\x63\x88\x61" "\xC9\xE1\x1F\xD7\xC7\xE5\x59\x33\xD5\x2F\xAF\x56\x1C\x94\xC8\xA4" "\x61\xB3\xF9\x1A\xE3\x09\x43\xA6\x5B\x85\xB1\x50\x5B\xCB\x1A\x2E" "\xB7\xE8\x87\xC1\x73\x19\x63\xF6\xA2\x91\x8D\x7E\x2E\xCC\xEC\x99"; @implementation OFHMACTests - (void)setUp { OFIRI *IRI; [super setUp]; IRI = [OFIRI IRIWithString: @"embedded:testfile.bin"]; _stream = [[OFIRIHandler openItemAtIRI: IRI mode: @"r"] retain]; } - (void)tearDown { [_stream close]; [super tearDown]; } - (void)dealloc { [_stream release]; [super dealloc]; } - (void)testWithHashClass: (Class)hashClass expectedDigest: (const unsigned char *)expectedDigest { OFHMAC *HMAC = [OFHMAC HMACWithHashClass: hashClass allowsSwappableMemory: true]; OTAssertNotNil(HMAC); OTAssertThrowsSpecific([HMAC updateWithBuffer: "" length: 0], OFInvalidArgumentException); [HMAC setKey: key length: keyLength]; while (!_stream.atEndOfStream) { char buffer[64]; size_t length = [_stream readIntoBuffer: buffer length: 64]; [HMAC updateWithBuffer: buffer length: length]; } [HMAC calculate]; OTAssertEqual(memcmp(HMAC.digest, expectedDigest, HMAC.digestSize), 0); } - (void)testHMACWithMD5 { [self testWithHashClass: [OFMD5Hash class] expectedDigest: MD5Digest]; } - (void)testHMACWithRIPEMD160 { [self testWithHashClass: [OFRIPEMD160Hash class] expectedDigest: RIPEMD160Digest]; } - (void)testHMACWithSHA1 { [self testWithHashClass: [OFSHA1Hash class] expectedDigest: SHA1Digest]; } - (void)testHMACWithSHA256 { [self testWithHashClass: [OFSHA256Hash class] expectedDigest: SHA256Digest]; } - (void)testHMACWithSHA384 { [self testWithHashClass: [OFSHA384Hash class] expectedDigest: SHA384Digest]; } - (void)testHMACWithSHA512 { [self testWithHashClass: [OFSHA512Hash class] expectedDigest: SHA512Digest]; } @end objfw-1.1.6/tests/OFHTTPClientTests.m000066400000000000000000000110001465614216400173350ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "ObjFW.h" #import "ObjFWTest.h" @interface OFHTTPClientTests: OTTestCase { OFHTTPResponse *_response; } @end @interface HTTPClientTestsServer: OFThread { OFCondition *_condition; uint16_t _port; } @property (readonly, nonatomic) OFCondition *condition; @property (readonly) uint16_t port; @end @implementation OFHTTPClientTests - (void)dealloc { [_response release]; [super dealloc]; } - (void)client: (OFHTTPClient *)client wantsRequestBody: (OFStream *)body request: (OFHTTPRequest *)request { [body writeString: @"Hello"]; } - (void)client: (OFHTTPClient *)client didPerformRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response_ exception: (id)exception { OTAssertNil(exception); [_response release]; _response = [response_ retain]; [[OFRunLoop mainRunLoop] stop]; } - (void)testClient { HTTPClientTestsServer *server; OFIRI *IRI; OFHTTPRequest *request; OFHTTPClient *client; OFData *data; server = [[[HTTPClientTestsServer alloc] init] autorelease]; server.supportsSockets = true; [server.condition lock]; [server start]; [server.condition wait]; [server.condition unlock]; IRI = [OFIRI IRIWithString: [OFString stringWithFormat: @"http://127.0.0.1:%" @PRIu16 "/foo", server.port]]; request = [OFHTTPRequest requestWithIRI: IRI]; request.headers = [OFDictionary dictionaryWithObject: @"5" forKey: @"Content-Length"]; client = [OFHTTPClient client]; client.delegate = self; [client asyncPerformRequest: request]; [[OFRunLoop mainRunLoop] runUntilDate: [OFDate dateWithTimeIntervalSinceNow: 2]]; OTAssertNotNil(_response); OTAssertNotNil([_response.headers objectForKey: @"Content-Length"]); data = [_response readDataUntilEndOfStream]; OTAssertEqual(data.count, 7); OTAssertEqual(data.itemSize, 1); OTAssertEqual(memcmp(data.items, "foo\nbar", 7), 0); OTAssertNil([server join]); } @end @implementation HTTPClientTestsServer @synthesize condition = _condition, port = _port; - (instancetype)init { self = [super init]; @try { _condition = [[OFCondition alloc] init]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_condition release]; [super dealloc]; } - (id)main { OFTCPSocket *listener, *client; OFSocketAddress address; bool sawHost = false, sawContentLength = false, sawContentType = false; bool sawUserAgent = false; char buffer[5]; [_condition lock]; listener = [OFTCPSocket socket]; address = [listener bindToHost: @"127.0.0.1" port: 0]; _port = OFSocketAddressIPPort(&address); [listener listen]; [_condition signal]; [_condition unlock]; client = [listener accept]; if (![[client readLine] isEqual: @"GET /foo HTTP/1.1"]) return @"Wrong request"; for (size_t i = 0; i < 4; i++) { OFString *line = [client readLine]; if ([line isEqual: [OFString stringWithFormat: @"Host: 127.0.0.1:%" @PRIu16, _port]]) sawHost = true; else if ([line isEqual: @"Content-Length: 5"]) sawContentLength = true; if ([line isEqual: @"Content-Type: application/" @"x-www-form-urlencoded; charset=UTF-8"]) sawContentType = true; else if ([line hasPrefix: @"User-Agent:"]) sawUserAgent = true; } if (!sawHost) return @"Missing host"; if (!sawContentLength) return @"Missing content length"; if (!sawContentType) return @"Missing content type"; if (!sawUserAgent) return @"Missing user agent"; if (![[client readLine] isEqual: @""]) return @"Missing empty line"; [client readIntoBuffer: buffer exactLength: 5]; if (memcmp(buffer, "Hello", 5) != 0) return @"Missing body"; [client writeString: @"HTTP/1.0 200 OK\r\n" @"cONTeNT-lENgTH: 7\r\n" @"\r\n" @"foo\n" @"bar"]; [client close]; return nil; } @end objfw-1.1.6/tests/OFHTTPCookieManagerTests.m000066400000000000000000000061731465614216400206420ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" @interface OFHTTPCookieManagerTests: OTTestCase @end @implementation OFHTTPCookieManagerTests - (void)testCookieManager { OFHTTPCookieManager *manager = [OFHTTPCookieManager manager]; OFIRI *IRI1, *IRI2, *IRI3, *IRI4; OFHTTPCookie *cookie1, *cookie2, *cookie3, *cookie4, *cookie5; IRI1 = [OFIRI IRIWithString: @"http://nil.im/foo"]; IRI2 = [OFIRI IRIWithString: @"https://nil.im/foo/bar"]; IRI3 = [OFIRI IRIWithString: @"https://test.nil.im/foo/bar"]; IRI4 = [OFIRI IRIWithString: @"http://webkeks.org/foo/bar"]; cookie1 = [OFHTTPCookie cookieWithName: @"test" value: @"1" domain: @"nil.im"]; [manager addCookie: cookie1 forIRI: IRI1]; OTAssertEqualObjects([manager cookiesForIRI: IRI1], [OFArray arrayWithObject: cookie1]); cookie2 = [OFHTTPCookie cookieWithName: @"test" value: @"2" domain: @"webkeks.org"]; [manager addCookie: cookie2 forIRI: IRI1]; OTAssertEqualObjects([manager cookiesForIRI: IRI1], [OFArray arrayWithObject: cookie1]); OTAssertEqualObjects([manager cookiesForIRI: IRI4], [OFArray array]); cookie3 = [OFHTTPCookie cookieWithName: @"test" value: @"3" domain: @"nil.im"]; cookie3.secure = true; [manager addCookie: cookie3 forIRI: IRI2]; OTAssertEqualObjects([manager cookiesForIRI: IRI2], [OFArray arrayWithObject: cookie3]); OTAssertEqualObjects([manager cookiesForIRI: IRI1], [OFArray array]); cookie3.expires = [OFDate dateWithTimeIntervalSinceNow: -1]; cookie4 = [OFHTTPCookie cookieWithName: @"test" value: @"4" domain: @"nil.im"]; cookie4.domain = @".nil.im"; [manager addCookie: cookie4 forIRI: IRI2]; OTAssertEqualObjects([manager cookiesForIRI: IRI2], [OFArray arrayWithObject: cookie4]); OTAssertEqualObjects([manager cookiesForIRI: IRI3], [OFArray arrayWithObject: cookie4]); cookie5 = [OFHTTPCookie cookieWithName: @"bar" value: @"5" domain: @"test.nil.im"]; [manager addCookie: cookie5 forIRI: IRI1]; OTAssertEqualObjects([manager cookiesForIRI: IRI1], [OFArray arrayWithObject: cookie4]); OTAssertEqualObjects([manager cookiesForIRI: IRI3], ([OFArray arrayWithObjects: cookie4, cookie5, nil])); OTAssertEqualObjects(manager.cookies, ([OFArray arrayWithObjects: cookie3, cookie4, cookie5, nil])); [manager purgeExpiredCookies]; OTAssertEqualObjects(manager.cookies, ([OFArray arrayWithObjects: cookie4, cookie5, nil])); } @end objfw-1.1.6/tests/OFHTTPCookieTests.m000066400000000000000000000060721465614216400173450ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" @interface OFHTTPCookieTests: OTTestCase @end @implementation OFHTTPCookieTests - (void)testCookiesWithResponseHeaderFieldsForIRI { OFIRI *IRI = [OFIRI IRIWithString: @"http://nil.im"]; OFHTTPCookie *cookie1 = [OFHTTPCookie cookieWithName: @"foo" value: @"bar" domain: @"nil.im"]; OFHTTPCookie *cookie2 = [OFHTTPCookie cookieWithName: @"qux" value: @"cookie" domain: @"nil.im"]; OFDictionary *headers; headers = [OFDictionary dictionaryWithObject: @"foo=bar" forKey: @"Set-Cookie"]; OTAssertEqualObjects( [OFHTTPCookie cookiesWithResponseHeaderFields: headers forIRI: IRI], [OFArray arrayWithObject: cookie1]); headers = [OFDictionary dictionaryWithObject: @"foo=bar,qux=cookie" forKey: @"Set-Cookie"]; OTAssertEqualObjects( [OFHTTPCookie cookiesWithResponseHeaderFields: headers forIRI: IRI], ([OFArray arrayWithObjects: cookie1, cookie2, nil])); cookie1.expires = [OFDate dateWithTimeIntervalSince1970: 1234567890]; cookie2.expires = [OFDate dateWithTimeIntervalSince1970: 1234567890]; cookie1.path = @"/x"; cookie2.domain = @"webkeks.org"; cookie2.path = @"/objfw"; cookie2.secure = true; cookie2.HTTPOnly = true; [cookie2.extensions addObject: @"foo"]; [cookie2.extensions addObject: @"bar"]; headers = [OFDictionary dictionaryWithObject: @"foo=bar; " @"Expires=Fri, 13 Feb 2009 23:31:30 GMT; " @"Path=/x," @"qux=cookie; " @"Expires=Fri, 13 Feb 2009 23:31:30 GMT; " @"Domain=webkeks.org; " @"Path=/objfw; " @"Secure; " @"HTTPOnly; " @"foo; " @"bar" forKey: @"Set-Cookie"]; OTAssertEqualObjects( [OFHTTPCookie cookiesWithResponseHeaderFields: headers forIRI: IRI], ([OFArray arrayWithObjects: cookie1, cookie2, nil])); } - (void)testRequestHeaderFieldsWithCookies { OFHTTPCookie *cookie1 = [OFHTTPCookie cookieWithName: @"foo" value: @"bar" domain: @"nil.im"]; OFHTTPCookie *cookie2 = [OFHTTPCookie cookieWithName: @"qux" value: @"cookie" domain: @"nil.im"]; OTAssertEqualObjects([OFHTTPCookie requestHeaderFieldsWithCookies: ([OFArray arrayWithObjects: cookie1, cookie2, nil])], [OFDictionary dictionaryWithObject: @"foo=bar; qux=cookie" forKey: @"Cookie"]); } @end objfw-1.1.6/tests/OFINIFileTests.m000066400000000000000000000110221465614216400166420ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" @interface OFINIFileTests: OTTestCase { OFINIFile *_file; } @end @implementation OFINIFileTests - (void)setUp { OFIRI *IRI; [super setUp]; IRI = [OFIRI IRIWithString: @"embedded:testfile.ini"]; _file = [[OFINIFile alloc] initWithIRI: IRI encoding: OFStringEncodingISO8859_1]; } - (void)dealloc { [_file release]; [super dealloc]; } - (void)testCategoryForName { OTAssertNotNil([_file categoryForName: @"tests"]); OTAssertNotNil([_file categoryForName: @"foobar"]); OTAssertNotNil([_file categoryForName: @"types"]); } - (void)testStringValueForKey { OTAssertEqualObjects( [[_file categoryForName: @"tests"] stringValueForKey: @"foo"], @"bar"); OTAssertEqualObjects([[_file categoryForName: @"foobar"] stringValueForKey: @"quxquxqux"], @"hello\"wörld"); } - (void)testLongLongValueForKeyDefaultValue { OTAssertEqual([[_file categoryForName: @"types"] longLongValueForKey: @"integer" defaultValue: 2], 0x20); } - (void)testBoolValueForKeyDefaultValue { OTAssertTrue([[_file categoryForName: @"types"] boolValueForKey: @"bool" defaultValue: false]); } - (void)testFloatValueForKeyDefaultValue { OTAssertEqual([[_file categoryForName: @"types"] floatValueForKey: @"float" defaultValue: 1], 0.5f); } - (void)testDoubleValueForKeyDefaultValue { OTAssertEqual([[_file categoryForName: @"types"] doubleValueForKey: @"double" defaultValue: 3], 0.25); } - (void)testArrayValueForKey { OFINICategory *types = [_file categoryForName: @"types"]; OFArray *array = [OFArray arrayWithObjects: @"1", @"2", nil]; OTAssertEqualObjects([types arrayValueForKey: @"array1"], array); OTAssertEqualObjects([types arrayValueForKey: @"array2"], array); OTAssertEqualObjects([types arrayValueForKey: @"array3"], [OFArray array]); } - (void)testWriteToIRIEncoding { OFString *expectedOutput = @"[tests]\r\n" @"foo=baz\r\n" @"foobar=baz\r\n" @";comment\r\n" @"new=new\r\n" @"\r\n" @"[foobar]\r\n" @";foobarcomment\r\n" @"qux=\" asd\"\r\n" @"quxquxqux=\"hello\\\"wörld\"\r\n" @"qux2=\"a\\f\"\r\n" @"qux3=a\fb\r\n" @"\r\n" @"[types]\r\n" @"integer=16\r\n" @"bool=false\r\n" @"float=0.25\r\n" @"array1=foo\r\n" @"array1=bar\r\n" @"double=0.75\r\n"; OFINICategory *tests = [_file categoryForName: @"tests"]; OFINICategory *foobar = [_file categoryForName: @"foobar"]; OFINICategory *types = [_file categoryForName: @"types"]; OFArray *array = [OFArray arrayWithObjects: @"foo", @"bar", nil]; #if defined(OF_HAVE_FILES) && !defined(OF_NINTENDO_DS) OFIRI *writeIRI; #endif [tests setStringValue: @"baz" forKey: @"foo"]; [tests setStringValue: @"new" forKey: @"new"]; [foobar setStringValue: @"a\fb" forKey: @"qux3"]; [types setLongLongValue: 0x10 forKey: @"integer"]; [types setBoolValue: false forKey: @"bool"]; [types setFloatValue: 0.25f forKey: @"float"]; [types setDoubleValue: 0.75 forKey: @"double"]; [types setArrayValue: array forKey: @"array1"]; [foobar removeValueForKey: @"quxqux "]; [types removeValueForKey: @"array2"]; /* FIXME: Find a way to write files on Nintendo DS */ #if defined(OF_HAVE_FILES) && !defined(OF_NINTENDO_DS) writeIRI = [OFSystemInfo temporaryDirectoryIRI]; if (writeIRI == nil) writeIRI = [[OFFileManager defaultManager] currentDirectoryIRI]; writeIRI = [writeIRI IRIByAppendingPathComponent: @"objfw-tests.ini" isDirectory: false]; [_file writeToIRI: writeIRI encoding: OFStringEncodingISO8859_1]; @try { OTAssertEqualObjects([OFString stringWithContentsOfIRI: writeIRI encoding: OFStringEncodingISO8859_1], expectedOutput); } @finally { [[OFFileManager defaultManager] removeItemAtIRI: writeIRI]; } #else (void)expectedOutput; #endif } @end objfw-1.1.6/tests/OFIPXSocketTests.m000066400000000000000000000053571465614216400172520ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "ObjFW.h" #import "ObjFWTest.h" @interface OFIPXSocketTests: OTTestCase @end @implementation OFIPXSocketTests - (void)testIPXSocket { OFIPXSocket *sock = [OFIPXSocket socket]; const unsigned char zeroNode[IPX_NODE_LEN] = { 0 }; OFSocketAddress address1, address2; OFDictionary *networkInterfaces; char buffer[5]; unsigned char node1[IPX_NODE_LEN], node2[IPX_NODE_LEN]; unsigned char node[IPX_NODE_LEN]; @try { address1 = [sock bindToNetwork: 0 node: zeroNode port: 0 packetType: 0]; } @catch (OFBindSocketFailedException *e) { switch (e.errNo) { case EAFNOSUPPORT: OTSkip(@"IPX unsupported"); case EADDRNOTAVAIL: OTSkip(@"IPX not configured"); default: @throw e; } } /* * Find any network interface with IPX and send to it. Any should be * fine since we bound to 0.0. */ networkInterfaces = [OFSystemInfo networkInterfaces]; for (OFString *name in networkInterfaces) { OFNetworkInterface interface = [networkInterfaces objectForKey: name]; OFData *addresses = [interface objectForKey: OFNetworkInterfaceIPXAddresses]; if (addresses.count == 0) continue; OFSocketAddressSetIPXNetwork(&address1, OFSocketAddressIPXNetwork([addresses itemAtIndex: 0])); OFSocketAddressGetIPXNode([addresses itemAtIndex: 0], node); OFSocketAddressSetIPXNode(&address1, node); } OFSocketAddressGetIPXNode(&address1, node); if (OFSocketAddressIPXNetwork(&address1) == 0 && memcmp(node, zeroNode, 6) == 0) OTSkip(@"Could not determine own IPX address"); [sock sendBuffer: "Hello" length: 5 receiver: &address1]; OTAssertEqual([sock receiveIntoBuffer: buffer length: 5 sender: &address2], 5); OTAssertEqual(memcmp(buffer, "Hello", 5), 0); OFSocketAddressGetIPXNode(&address1, node1); OFSocketAddressGetIPXNode(&address2, node2); OTAssertEqual(memcmp(node1, node2, IPX_NODE_LEN), 0); OTAssertEqual(OFSocketAddressIPXPort(&address1), OFSocketAddressIPXPort(&address2)); } @end objfw-1.1.6/tests/OFIRITests.m000066400000000000000000000426111465614216400160560ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" @interface OFIRITests: OTTestCase { OFIRI *_IRI[11]; OFMutableIRI *_mutableIRI; } @end static OFString *IRI0String = @"ht+tp://us%3Aer:p%40w@ho%3Ast:1234/" @"pa%3Fth?que%23ry=1&f%26oo=b%3dar#frag%23ment"; @implementation OFIRITests - (void)setUp { [super setUp]; _IRI[0] = [[OFIRI alloc] initWithString: IRI0String]; _IRI[1] = [[OFIRI alloc] initWithString: @"http://foo:80"]; _IRI[2] = [[OFIRI alloc] initWithString: @"http://bar/"]; _IRI[3] = [[OFIRI alloc] initWithString: @"file:///etc/passwd"]; _IRI[4] = [[OFIRI alloc] initWithString: @"http://foo/bar/qux/foo%2fbar"]; _IRI[5] = [[OFIRI alloc] initWithString: @"https://[12:34::56:abcd]/"]; _IRI[6] = [[OFIRI alloc] initWithString: @"https://[12:34::56:abcd]:234/"]; _IRI[7] = [[OFIRI alloc] initWithString: @"urn:qux:foo"]; _IRI[8] = [[OFIRI alloc] initWithString: @"file:/foo?query#frag"]; _IRI[9] = [[OFIRI alloc] initWithString: @"file:foo@bar/qux?query#frag"]; _IRI[10] = [[OFIRI alloc] initWithString: @"http://ä/ö?ü"]; _mutableIRI = [[OFMutableIRI alloc] initWithScheme: @"dummy"]; } - (void)dealloc { for (uint_fast8_t i = 0; i < 11; i++) [_IRI[i] release]; [_mutableIRI release]; [super dealloc]; } - (void)testIRIWithStringFailsWithInvalidCharacters { OTAssertThrowsSpecific([OFIRI IRIWithString: @"ht,tp://foo"], OFInvalidFormatException); OTAssertThrowsSpecific([OFIRI IRIWithString: @"http://f`oo"], OFInvalidFormatException); OTAssertThrowsSpecific([OFIRI IRIWithString: @"http://foo/`"], OFInvalidFormatException); OTAssertThrowsSpecific([OFIRI IRIWithString: @"http://foo/foo?`"], OFInvalidFormatException); OTAssertThrowsSpecific([OFIRI IRIWithString: @"http://foo/foo?foo#`"], OFInvalidFormatException); OTAssertThrowsSpecific([OFIRI IRIWithString: @"https://[g]/"], OFInvalidFormatException); OTAssertThrowsSpecific([OFIRI IRIWithString: @"https://[f]:/"], OFInvalidFormatException); OTAssertThrowsSpecific([OFIRI IRIWithString: @"https://[f]:f/"], OFInvalidFormatException); OTAssertThrowsSpecific([OFIRI IRIWithString: @"foo:"], OFInvalidFormatException); } - (void)testIRIWithStringRelativeToIRI { OTAssertEqualObjects([[OFIRI IRIWithString: @"/foo" relativeToIRI: _IRI[0]] string], @"ht+tp://us%3Aer:p%40w@ho%3Ast:1234/foo"); OTAssertEqualObjects( [[OFIRI IRIWithString: @"foo/bar?q" relativeToIRI: [OFIRI IRIWithString: @"http://h/qux/quux"]] string], @"http://h/qux/foo/bar?q"); OTAssertEqualObjects( [[OFIRI IRIWithString: @"foo/bar" relativeToIRI: [OFIRI IRIWithString: @"http://h/qux/?x"]] string], @"http://h/qux/foo/bar"); OTAssertEqualObjects([[OFIRI IRIWithString: @"http://foo/?q" relativeToIRI: _IRI[0]] string], @"http://foo/?q"); OTAssertEqualObjects( [[OFIRI IRIWithString: @"foo" relativeToIRI: [OFIRI IRIWithString: @"http://foo/bar"]] string], @"http://foo/foo"); OTAssertEqualObjects( [[OFIRI IRIWithString: @"foo" relativeToIRI: [OFIRI IRIWithString: @"http://foo"]] string], @"http://foo/foo"); } - (void)testIRIWithStringRelativeToIRIFailsWithInvalidCharacters { OTAssertThrowsSpecific( [OFIRI IRIWithString: @"`" relativeToIRI: _IRI[0]], OFInvalidFormatException); OTAssertThrowsSpecific( [OFIRI IRIWithString: @"/`" relativeToIRI: _IRI[0]], OFInvalidFormatException); OTAssertThrowsSpecific( [OFIRI IRIWithString: @"?`" relativeToIRI: _IRI[0]], OFInvalidFormatException); OTAssertThrowsSpecific( [OFIRI IRIWithString: @"#`" relativeToIRI: _IRI[0]], OFInvalidFormatException); } #ifdef OF_HAVE_FILES - (void)testFileIRIWithPath { OTAssertEqualObjects( [[OFIRI fileIRIWithPath: @"testfile.txt"] fileSystemRepresentation], [[OFFileManager defaultManager].currentDirectoryPath stringByAppendingPathComponent: @"testfile.txt"]); } # if defined(OF_WINDOWS) || defined(OF_MSDOS) - (void)testFileIRWithPathC { OFIRI *IRI = [OFIRI fileIRIWithPath: @"c:\\"]; OTAssertEqualObjects(IRI.string, @"file:/c:/"); OTAssertEqualObjects(IRI.fileSystemRepresentation, @"c:\\"); } # endif # ifdef OF_WINDOWS - (void)testFileIRIWithPathUNC { OFIRI *IRI; IRI = [OFIRI fileIRIWithPath: @"\\\\foo\\bar" isDirectory: false]; OTAssertEqualObjects(IRI.host, @"foo"); OTAssertEqualObjects(IRI.path, @"/bar"); OTAssertEqualObjects(IRI.string, @"file://foo/bar"); OTAssertEqualObjects(IRI.fileSystemRepresentation, @"\\\\foo\\bar"); IRI = [OFIRI fileIRIWithPath: @"\\\\test" isDirectory: true]; OTAssertEqualObjects(IRI.host, @"test"); OTAssertEqualObjects(IRI.path, @"/"); OTAssertEqualObjects(IRI.string, @"file://test/"); OTAssertEqualObjects(IRI.fileSystemRepresentation, @"\\\\test"); } # endif #endif - (void)testString { OTAssertEqualObjects(_IRI[0].string, IRI0String); OTAssertEqualObjects(_IRI[1].string, @"http://foo:80"); OTAssertEqualObjects(_IRI[2].string, @"http://bar/"); OTAssertEqualObjects(_IRI[3].string, @"file:///etc/passwd"); OTAssertEqualObjects(_IRI[4].string, @"http://foo/bar/qux/foo%2fbar"); OTAssertEqualObjects(_IRI[5].string, @"https://[12:34::56:abcd]/"); OTAssertEqualObjects(_IRI[6].string, @"https://[12:34::56:abcd]:234/"); OTAssertEqualObjects(_IRI[7].string, @"urn:qux:foo"); OTAssertEqualObjects(_IRI[8].string, @"file:/foo?query#frag"); OTAssertEqualObjects(_IRI[9].string, @"file:foo@bar/qux?query#frag"); OTAssertEqualObjects(_IRI[10].string, @"http://ä/ö?ü"); } - (void)testScheme { OTAssertEqualObjects(_IRI[0].scheme, @"ht+tp"); OTAssertEqualObjects(_IRI[3].scheme, @"file"); OTAssertEqualObjects(_IRI[8].scheme, @"file"); OTAssertEqualObjects(_IRI[9].scheme, @"file"); OTAssertEqualObjects(_IRI[10].scheme, @"http"); } - (void)testUser { OTAssertEqualObjects(_IRI[0].user, @"us:er"); OTAssertNil(_IRI[3].user); OTAssertNil(_IRI[9].user); OTAssertNil(_IRI[10].user); } - (void)testPassword { OTAssertEqualObjects(_IRI[0].password, @"p@w"); OTAssertNil(_IRI[3].password); OTAssertNil(_IRI[9].password); OTAssertNil(_IRI[10].password); } - (void)testHost { OTAssertEqualObjects(_IRI[0].host, @"ho:st"); OTAssertEqualObjects(_IRI[5].host, @"12:34::56:abcd"); OTAssertEqualObjects(_IRI[6].host, @"12:34::56:abcd"); OTAssertNil(_IRI[7].host); OTAssertNil(_IRI[8].host); OTAssertNil(_IRI[9].host); OTAssertEqualObjects(_IRI[10].host, @"ä"); } - (void)testPort { OTAssertEqual(_IRI[0].port.unsignedShortValue, 1234); OTAssertNil(_IRI[3].port); OTAssertEqual(_IRI[6].port.unsignedShortValue, 234); OTAssertNil(_IRI[7].port); OTAssertNil(_IRI[8].port); OTAssertNil(_IRI[9].port); OTAssertNil(_IRI[10].port); } - (void)testPath { OTAssertEqualObjects(_IRI[0].path, @"/pa?th"); OTAssertEqualObjects(_IRI[3].path, @"/etc/passwd"); OTAssertEqualObjects(_IRI[7].path, @"qux:foo"); OTAssertEqualObjects(_IRI[8].path, @"/foo"); OTAssertEqualObjects(_IRI[9].path, @"foo@bar/qux"); OTAssertEqualObjects(_IRI[10].path, @"/ö"); } - (void)testPathComponents { OTAssertEqualObjects(_IRI[0].pathComponents, ([OFArray arrayWithObjects: @"/", @"pa?th", nil])); OTAssertEqualObjects(_IRI[3].pathComponents, ([OFArray arrayWithObjects: @"/", @"etc", @"passwd", nil])); OTAssertEqualObjects(_IRI[4].pathComponents, ([OFArray arrayWithObjects: @"/", @"bar", @"qux", @"foo/bar", nil])); } - (void)testLastPathComponent { OTAssertEqualObjects([[OFIRI IRIWithString: @"http://host/foo//bar/baz"] lastPathComponent], @"baz"); OTAssertEqualObjects( [[OFIRI IRIWithString: @"http://host/foo//bar/baz/"] lastPathComponent], @"baz"); OTAssertEqualObjects([[OFIRI IRIWithString: @"http://host/foo/"] lastPathComponent], @"foo"); OTAssertEqualObjects([[OFIRI IRIWithString: @"http://host/"] lastPathComponent], @"/"); OTAssertEqualObjects(_IRI[4].lastPathComponent, @"foo/bar"); } - (void)testPathExtension { OTAssertEqualObjects( [[OFIRI IRIWithString: @"http://host/path.dir/path.file"] pathExtension], @"file"); OTAssertEqualObjects( [[OFIRI IRIWithString: @"http://host/path/path.dir/"] pathExtension], @"dir"); } - (void)testQuery { OTAssertEqualObjects(_IRI[0].query, @"que#ry=1&f&oo=b=ar"); OTAssertNil(_IRI[3].query); OTAssertEqualObjects(_IRI[8].query, @"query"); OTAssertEqualObjects(_IRI[9].query, @"query"); OTAssertEqualObjects(_IRI[10].query, @"ü"); } - (void)testQueryItems { OTAssertEqualObjects(_IRI[0].queryItems, ([OFArray arrayWithObjects: [OFPair pairWithFirstObject: @"que#ry" secondObject: @"1"], [OFPair pairWithFirstObject: @"f&oo" secondObject: @"b=ar"], nil])); } - (void)testFragment { OTAssertEqualObjects(_IRI[0].fragment, @"frag#ment"); OTAssertNil(_IRI[3].fragment); OTAssertEqualObjects(_IRI[8].fragment, @"frag"); OTAssertEqualObjects(_IRI[9].fragment, @"frag"); } - (void)testCopy { OTAssertEqualObjects([[_IRI[0] copy] autorelease], _IRI[0]); } - (void)testIsEqual { OTAssertEqualObjects(_IRI[0], [OFIRI IRIWithString: IRI0String]); OTAssertNotEqualObjects(_IRI[1], _IRI[2]); OTAssertEqualObjects([OFIRI IRIWithString: @"HTTP://bar/"], _IRI[2]); } - (void)testHash { OTAssertEqual(_IRI[0].hash, [[OFIRI IRIWithString: IRI0String] hash]); OTAssertNotEqual(_IRI[1].hash, _IRI[2].hash); } - (void)testIRIWithStringFailsWithInvalidFormat { OTAssertThrowsSpecific([OFIRI IRIWithString: @"http"], OFInvalidFormatException); } - (void)testIRIByAppendingPathComponent { OTAssertEqualObjects( [[[OFIRI IRIWithString: @"http://host/path/component"] IRIByAppendingPathComponent: @"foo/bar"] path], @"/path/component/foo/bar"); OTAssertEqualObjects( [[[OFIRI IRIWithString: @"http://host/path/component/"] IRIByAppendingPathComponent: @"foo/bar"] path], @"/path/component/foo/bar"); OTAssertEqualObjects( [[[OFIRI IRIWithString: @"http://host/path/component/"] IRIByAppendingPathComponent: @"foo/bar" isDirectory: true] path], @"/path/component/foo/bar/"); } - (void)testIRIByDeletingLastPathComponent { OTAssertEqualObjects( [[[OFIRI IRIWithString: @"http://host/path/component"] IRIByDeletingLastPathComponent] path], @"/path/"); OTAssertEqualObjects( [[[OFIRI IRIWithString: @"http://host/path/directory/"] IRIByDeletingLastPathComponent] path], @"/path/"); OTAssertEqualObjects( [[[OFIRI IRIWithString: @"http://host/path"] IRIByDeletingLastPathComponent] path], @"/"); OTAssertEqualObjects( [[[OFIRI IRIWithString: @"http://host/"] IRIByDeletingLastPathComponent] path], @"/"); OTAssertEqualObjects( [[[OFIRI IRIWithString: @"http://host"] IRIByDeletingLastPathComponent] path], @""); } - (void)testIRIByAppendingPathExtension { OTAssertEqualObjects( [[[OFIRI IRIWithString: @"http://host/path.dir/path"] IRIByAppendingPathExtension: @"file"] path], @"/path.dir/path.file"); OTAssertEqualObjects( [[[OFIRI IRIWithString: @"http://host/path/path/"] IRIByAppendingPathExtension: @"dir"] path], @"/path/path.dir/"); } - (void)testIRIByDeletingPathExtension { OTAssertEqualObjects( [[[OFIRI IRIWithString: @"http://host/path.dir/path.file"] IRIByDeletingPathExtension] path], @"/path.dir/path"); OTAssertEqualObjects( [[[OFIRI IRIWithString: @"http://host/path/path.dir/"] IRIByDeletingPathExtension] path], @"/path/path/"); } - (void)testIRIByAddingPercentEncodingForUnicodeCharacters { OTAssertEqualObjects( _IRI[10].IRIByAddingPercentEncodingForUnicodeCharacters, [OFIRI IRIWithString: @"http://%C3%A4/%C3%B6?%C3%BC"]); } - (void)testSetPercentEncodedSchemeFailsWithInvalidCharacters { OTAssertThrowsSpecific(_mutableIRI.scheme = @"%20", OFInvalidFormatException); } - (void)testSetHost { _mutableIRI.host = @"ho:st"; OTAssertEqualObjects(_mutableIRI.percentEncodedHost, @"ho%3Ast"); _mutableIRI.host = @"12:34:ab"; OTAssertEqualObjects(_mutableIRI.percentEncodedHost, @"[12:34:ab]"); _mutableIRI.host = @"12:34:aB"; OTAssertEqualObjects(_mutableIRI.percentEncodedHost, @"[12:34:aB]"); _mutableIRI.host = @"12:34:g"; OTAssertEqualObjects(_mutableIRI.percentEncodedHost, @"12%3A34%3Ag"); } - (void)testSetPercentEncodedHost { _mutableIRI.percentEncodedHost = @"ho%3Ast"; OTAssertEqualObjects(_mutableIRI.host, @"ho:st"); _mutableIRI.percentEncodedHost = @"[12:34]"; OTAssertEqualObjects(_mutableIRI.host, @"12:34"); _mutableIRI.percentEncodedHost = @"[12::ab]"; OTAssertEqualObjects(_mutableIRI.host, @"12::ab"); } - (void)testSetPercentEncodedHostFailsWithInvalidCharacters { OTAssertThrowsSpecific(_mutableIRI.percentEncodedHost = @"/", OFInvalidFormatException); OTAssertThrowsSpecific(_mutableIRI.percentEncodedHost = @"[12:34", OFInvalidFormatException); OTAssertThrowsSpecific(_mutableIRI.percentEncodedHost = @"[a::g]", OFInvalidFormatException); } - (void)testSetUser { _mutableIRI.user = @"us:er"; OTAssertEqualObjects(_mutableIRI.percentEncodedUser, @"us%3Aer"); } - (void)testSetPercentEncodedUser { _mutableIRI.percentEncodedUser = @"us%3Aer"; OTAssertEqualObjects(_mutableIRI.user, @"us:er"); } - (void)testSetPercentEncodedUserFailsWithInvalidCharacters { OTAssertThrowsSpecific(_mutableIRI.percentEncodedHost = @"/", OFInvalidFormatException); } - (void)testSetPassword { _mutableIRI.password = @"pass:word"; OTAssertEqualObjects(_mutableIRI.percentEncodedPassword, @"pass%3Aword"); } - (void)testSetPercentEncodedPassword { _mutableIRI.percentEncodedPassword = @"pass%3Aword"; OTAssertEqualObjects(_mutableIRI.password, @"pass:word"); } - (void)testSetPercentEncodedPasswordFailsWithInvalidCharacters { OTAssertThrowsSpecific(_mutableIRI.percentEncodedPassword = @"/", OFInvalidFormatException); } - (void)testSetPath { _mutableIRI.path = @"pa/th@?"; OTAssertEqualObjects(_mutableIRI.percentEncodedPath, @"pa/th@%3F"); } - (void)testSetPercentEncodedPath { _mutableIRI.percentEncodedPath = @"pa/th@%3F"; OTAssertEqualObjects(_mutableIRI.path, @"pa/th@?"); } - (void)testSetPercentEncodedPathFailsWithInvalidCharacters { OTAssertThrowsSpecific(_mutableIRI.percentEncodedPath = @"?", OFInvalidFormatException); } - (void)testSetQuery { _mutableIRI.query = @"que/ry?#"; OTAssertEqualObjects(_mutableIRI.percentEncodedQuery, @"que/ry?%23"); } - (void)testSetPercentEncodedQuery { _mutableIRI.percentEncodedQuery = @"que/ry?%23"; OTAssertEqualObjects(_mutableIRI.query, @"que/ry?#"); } - (void)testSetPercentEncodedQueryFailsWithInvalidCharacters { OTAssertThrowsSpecific(_mutableIRI.percentEncodedQuery = @"`", OFInvalidFormatException); } - (void)testSetQueryItems { _mutableIRI.queryItems = [OFArray arrayWithObjects: [OFPair pairWithFirstObject: @"foo&bar" secondObject: @"baz=qux"], [OFPair pairWithFirstObject: @"f=oobar" secondObject: @"b&azqux"], nil]; OTAssertEqualObjects(_mutableIRI.percentEncodedQuery, @"foo%26bar=baz%3Dqux&f%3Doobar=b%26azqux"); } - (void)testSetFragment { _mutableIRI.fragment = @"frag/ment?#"; OTAssertEqualObjects(_mutableIRI.percentEncodedFragment, @"frag/ment?%23"); } - (void)testSetPercentEncodedFragment { _mutableIRI.percentEncodedFragment = @"frag/ment?%23"; OTAssertEqualObjects(_mutableIRI.fragment, @"frag/ment?#"); } - (void)testSetPercentEncodedFragmentFailsWithInvalidCharacters { OTAssertThrowsSpecific(_mutableIRI.percentEncodedFragment = @"`", OFInvalidFormatException); } -(void)testIRIByAppendingPathComponentIsDirectory { OTAssertEqualObjects([[OFIRI IRIWithString: @"file:///foo/bar"] IRIByAppendingPathComponent: @"qux" isDirectory: false], [OFIRI IRIWithString: @"file:///foo/bar/qux"]); OTAssertEqualObjects([[OFIRI IRIWithString: @"file:///foo/bar/"] IRIByAppendingPathComponent: @"qux" isDirectory: false], [OFIRI IRIWithString: @"file:///foo/bar/qux"]); OTAssertEqualObjects([[OFIRI IRIWithString: @"file:///foo/bar/"] IRIByAppendingPathComponent: @"qu?x" isDirectory: false], [OFIRI IRIWithString: @"file:///foo/bar/qu%3Fx"]); OTAssertEqualObjects([[OFIRI IRIWithString: @"file:///foo/bar/"] IRIByAppendingPathComponent: @"qu?x" isDirectory: true], [OFIRI IRIWithString: @"file:///foo/bar/qu%3Fx/"]); } - (void)testIRIByStandardizingPath { OTAssertEqualObjects([[OFIRI IRIWithString: @"http://foo/bar/.."] IRIByStandardizingPath], [OFIRI IRIWithString: @"http://foo/"]); OTAssertEqualObjects( [[OFIRI IRIWithString: @"http://foo/bar/%2E%2E/../qux/"] IRIByStandardizingPath], [OFIRI IRIWithString: @"http://foo/bar/qux/"]); OTAssertEqualObjects( [[OFIRI IRIWithString: @"http://foo/bar/./././qux/./"] IRIByStandardizingPath], [OFIRI IRIWithString: @"http://foo/bar/qux/"]); OTAssertEqualObjects([[OFIRI IRIWithString: @"http://foo/bar/../../qux"] IRIByStandardizingPath], [OFIRI IRIWithString: @"http://foo/../qux"]); } @end objfw-1.1.6/tests/OFInvocationTests.m000066400000000000000000000055211465614216400175430ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #if defined(HAVE_COMPLEX_H) && !defined(__STDC_NO_COMPLEX__) # include #endif #import "ObjFW.h" #import "ObjFWTest.h" @interface OFInvocationTests: OTTestCase { OFInvocation *_invocation; } @end struct TestStruct { unsigned char c; unsigned int i; }; @implementation OFInvocationTests - (struct TestStruct)invocationTestMethod1: (unsigned char)c : (unsigned int)i : (struct TestStruct *)testStructPtr : (struct TestStruct)testStruct { return testStruct; } - (void)setUp { [super setUp]; SEL selector = @selector(invocationTestMethod1::::); OFMethodSignature *signature = [self methodSignatureForSelector: selector]; _invocation = [[OFInvocation alloc] initWithMethodSignature: signature]; } - (void)dealloc { [_invocation release]; [super dealloc]; } - (void)testSetAndGetReturnValue { struct TestStruct testStruct, testStruct2; memset(&testStruct, 0xFF, sizeof(testStruct)); testStruct.c = 0x55; testStruct.i = 0xAAAAAAAA; [_invocation setReturnValue: &testStruct]; [_invocation getReturnValue: &testStruct2]; OTAssertEqual(memcmp(&testStruct, &testStruct2, sizeof(testStruct)), 0); } - (void)testSetAndGetArgumentAtIndex { struct TestStruct testStruct, testStruct2; struct TestStruct *testStructPtr = &testStruct, *testStructPtr2; unsigned const char c = 0xAA; unsigned char c2; const unsigned int i = 0x55555555; unsigned int i2; memset(&testStruct, 0xFF, sizeof(testStruct)); testStruct.c = 0x55; testStruct.i = 0xAAAAAAAA; memset(&testStruct2, 0, sizeof(testStruct2)); [_invocation setArgument: &c atIndex: 2]; [_invocation setArgument: &i atIndex: 3]; [_invocation setArgument: &testStructPtr atIndex: 4]; [_invocation setArgument: &testStruct atIndex: 5]; [_invocation getArgument: &c2 atIndex: 2]; OTAssertEqual(c, c2); [_invocation getArgument: &i2 atIndex: 3]; OTAssertEqual(i, i2); [_invocation getArgument: &testStructPtr2 atIndex: 4]; OTAssertEqual(testStructPtr, testStructPtr2); [_invocation getArgument: &testStruct2 atIndex: 5]; OTAssertEqual(memcmp(&testStruct, &testStruct2, sizeof(testStruct)), 0); } @end objfw-1.1.6/tests/OFJSONTests.m000066400000000000000000000073611465614216400162070ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" @interface OFJSONTests: OTTestCase { OFDictionary *_dictionary; } @end static OFString *string = @"{\"foo\"\t:'b\\na\\r', \"x\":/*foo*/ [.5\r,0xF," @"null//bar\n,\"foo\",false]}"; @implementation OFJSONTests - (void)setUp { [super setUp]; _dictionary = [[OTOrderedDictionary alloc] initWithKeysAndObjects: @"foo", @"b\na\r", @"x", [OFArray arrayWithObjects: [OFNumber numberWithFloat: .5f], [OFNumber numberWithInt: 0xF], [OFNull null], @"foo", [OFNumber numberWithBool: false], nil], nil]; } - (void)dealloc { [_dictionary release]; [super dealloc]; } - (void)testObjectByParsingJSON { OTAssertEqualObjects(string.objectByParsingJSON, _dictionary); } - (void)testJSONRepresentation { OTAssert(_dictionary.JSONRepresentation, @"{\"foo\":\"b\\na\\r\",\"x\":[0.5,15,null,\"foo\",false]}"); } - (void)testPrettyJSONRepresentation { OTAssertEqualObjects([_dictionary JSONRepresentationWithOptions: OFJSONRepresentationOptionPretty], @"{\n\t\"foo\": \"b\\na\\r\",\n\t\"x\": [\n\t\t0.5,\n\t\t15," @"\n\t\tnull,\n\t\t\"foo\",\n\t\tfalse\n\t]\n}"); } - (void)testJSON5Representation { OTAssertEqualObjects([_dictionary JSONRepresentationWithOptions: OFJSONRepresentationOptionJSON5], @"{foo:\"b\\\na\\r\",x:[0.5,15,null,\"foo\",false]}"); } - (void)testObjectByParsingJSONFailsWithInvalidJSON { OTAssertThrowsSpecific([@"{" objectByParsingJSON], OFInvalidJSONException); OTAssertThrowsSpecific([@"]" objectByParsingJSON], OFInvalidJSONException); OTAssertThrowsSpecific([@"bar" objectByParsingJSON], OFInvalidJSONException); OTAssertThrowsSpecific([@"[\"a\" \"b\"]" objectByParsingJSON], OFInvalidJSONException); } - (void)testObjectByParsingJSONWithDeepNesting { OTAssertEqualObjects( @"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[{}]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]" .objectByParsingJSON, [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFDictionary dictionary]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]); } - (void)testObjectByParsingJSONFailsWithTooDeepNesting { OTAssertThrowsSpecific( [@"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[{}]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]" objectByParsingJSON], OFInvalidJSONException); } @end objfw-1.1.6/tests/OFKernelEventObserverTests.m000066400000000000000000000066201465614216400213650ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" #ifdef HAVE_KQUEUE # import "OFKqueueKernelEventObserver.h" #endif #ifdef HAVE_EPOLL # import "OFEpollKernelEventObserver.h" #endif #ifdef HAVE_POLL # import "OFPollKernelEventObserver.h" #endif #ifdef HAVE_SELECT # import "OFSelectKernelEventObserver.h" #endif @interface OFKernelEventObserverTests: OTTestCase { OFTCPSocket *_server, *_client, *_accepted; OFKernelEventObserver *_observer; size_t _events; } @end static const size_t numExpectedEvents = 3; @implementation OFKernelEventObserverTests - (void)setUp { OFSocketAddress address; [super setUp]; _server = [[OFTCPSocket alloc] init]; address = [_server bindToHost: @"127.0.0.1" port: 0]; [_server listen]; _client = [[OFTCPSocket alloc] init]; [_client connectToHost: @"127.0.0.1" port: OFSocketAddressIPPort(&address)]; [_client writeBuffer: "0" length: 1]; } - (void)dealloc { [_client release]; [_server release]; [_accepted release]; [_observer release]; [super dealloc]; } - (void)testKernelEventObserverWithClass: (Class)class { bool deadlineExceeded = false; OFDate *deadline; _observer = [[class alloc] init]; _observer.delegate = self; [_observer addObjectForReading: _server]; deadline = [OFDate dateWithTimeIntervalSinceNow: 1]; while (_events < numExpectedEvents) { if (deadline.timeIntervalSinceNow < 0) { deadlineExceeded = true; break; } [_observer observeForTimeInterval: 0.01]; } OTAssertFalse(deadlineExceeded); OTAssertEqual(_events, numExpectedEvents); } - (void)objectIsReadyForReading: (id)object { char buffer; switch (_events++) { case 0: OTAssertEqual(object, _server); _accepted = [[object accept] retain]; [_observer addObjectForReading: _accepted]; break; case 1: OTAssert(object, _accepted); OTAssertEqual([object readIntoBuffer: &buffer length: 1], 1); OTAssertEqual(buffer, '0'); [_client close]; break; case 2: OTAssertEqual(object, _accepted); OTAssertEqual([object readIntoBuffer: &buffer length: 1], 0); break; default: OTAssert(false); } } #ifdef HAVE_SELECT - (void)testSelectKernelEventObserver { [self testKernelEventObserverWithClass: [OFSelectKernelEventObserver class]]; } #endif #ifdef HAVE_POLL - (void)testPollKernelEventObserver { [self testKernelEventObserverWithClass: [OFPollKernelEventObserver class]]; } #endif #ifdef HAVE_EPOLL - (void)testEpollKernelEventObserver { [self testKernelEventObserverWithClass: [OFEpollKernelEventObserver class]]; } #endif #ifdef HAVE_KQUEUE - (void)testKqueueKernelEventObserver { [self testKernelEventObserverWithClass: [OFKqueueKernelEventObserver class]]; } #endif @end objfw-1.1.6/tests/OFLHAArchiveTests.m000066400000000000000000000037101465614216400173360ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" #define bufferSize 4096 @interface OFLHAArchiveTests: OTTestCase { char _buffer[bufferSize]; } @end @implementation OFLHAArchiveTests - (void)testCreateAndExtractArchive { OFMemoryStream *stream = [OFMemoryStream streamWithMemoryAddress: _buffer size: bufferSize writable: true]; OFLHAArchive *archive = [OFLHAArchive archiveWithStream: stream mode: @"w"]; OFLHAArchiveEntry *entry = [OFMutableLHAArchiveEntry entryWithFileName: @"testfile.txt"]; OFStream *entryStream = [archive streamForWritingEntry: entry]; size_t size; [entryStream writeString: @"Hello World!"]; [archive close]; size = (size_t)[stream seekToOffset: 0 whence: OFSeekCurrent]; OTAssertLessThanOrEqual(size, bufferSize); stream = [OFMemoryStream streamWithMemoryAddress: _buffer size: size writable: false]; archive = [OFLHAArchive archiveWithStream: stream mode: @"r"]; entry = [archive nextEntry]; OTAssertEqualObjects(entry.fileName, @"testfile.txt"); entryStream = [archive streamForReadingCurrentEntry]; OTAssertEqualObjects([entryStream readLine], @"Hello World!"); OTAssertNil([entryStream readLine]); OTAssertNil([archive nextEntry]); } @end objfw-1.1.6/tests/OFListTests.m000066400000000000000000000133421465614216400163450ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" @interface OFListTests: OTTestCase { OFList *_list; } @end @implementation OFListTests - (void)setUp { [super setUp]; _list = [[OFList alloc] init]; [_list appendObject: @"Foo"]; [_list appendObject: @"Bar"]; [_list appendObject: @"Baz"]; } - (void)dealloc { [_list release]; [super dealloc]; } - (void)testCount { OTAssertEqual(_list.count, 3); } - (void)testAppendObject { OFListItem item; [_list appendObject: @"Qux"]; item = _list.firstListItem; OTAssertEqualObjects(OFListItemObject(item), @"Foo"); item = OFListItemNext(item); OTAssertEqualObjects(OFListItemObject(item), @"Bar"); item = OFListItemNext(item); OTAssertEqualObjects(OFListItemObject(item), @"Baz"); item = OFListItemNext(item); OTAssertEqualObjects(OFListItemObject(item), @"Qux"); item = OFListItemNext(item); OTAssertEqual(item, NULL); } - (void)testFirstListItem { OTAssertEqualObjects(OFListItemObject(_list.firstListItem), @"Foo"); } - (void)testFirstObject { OTAssertEqualObjects(_list.firstObject, @"Foo"); } - (void)testLastListItem { OTAssertEqualObjects(OFListItemObject(_list.lastListItem), @"Baz"); } - (void)testLastObject { OTAssertEqualObjects(_list.lastObject, @"Baz"); } - (void)testListItemNext { OTAssertEqualObjects( OFListItemObject(OFListItemNext(_list.firstListItem)), @"Bar"); } - (void)testListItemPrevious { OTAssertEqualObjects( OFListItemObject(OFListItemPrevious(_list.lastListItem)), @"Bar"); } - (void)testRemoveListItem { OFListItem item; [_list removeListItem: OFListItemNext(_list.firstListItem)]; item = _list.firstListItem; OTAssertEqualObjects(OFListItemObject(item), @"Foo"); item = OFListItemNext(item); OTAssertEqualObjects(OFListItemObject(item), @"Baz"); item = OFListItemNext(item); OTAssertEqual(item, NULL); } - (void)testInsertObjectBeforeListItem { OFListItem item; [_list insertObject: @"Qux" beforeListItem: _list.lastListItem]; item = _list.firstListItem; OTAssertEqualObjects(OFListItemObject(item), @"Foo"); item = OFListItemNext(item); OTAssertEqualObjects(OFListItemObject(item), @"Bar"); item = OFListItemNext(item); OTAssertEqualObjects(OFListItemObject(item), @"Qux"); item = OFListItemNext(item); OTAssertEqualObjects(OFListItemObject(item), @"Baz"); item = OFListItemNext(item); OTAssertEqual(item, NULL); } - (void)testInsertObjectAfterListItem { OFListItem item; [_list insertObject: @"Qux" afterListItem: _list.firstListItem]; item = _list.firstListItem; OTAssertEqualObjects(OFListItemObject(item), @"Foo"); item = OFListItemNext(item); OTAssertEqualObjects(OFListItemObject(item), @"Qux"); item = OFListItemNext(item); OTAssertEqualObjects(OFListItemObject(item), @"Bar"); item = OFListItemNext(item); OTAssertEqualObjects(OFListItemObject(item), @"Baz"); item = OFListItemNext(item); OTAssertEqual(item, NULL); } - (void)testContainsObject { OTAssertTrue([_list containsObject: @"Foo"]); OTAssertFalse([_list containsObject: @"Qux"]); } - (void)testContainsObjectIdenticalTo { OFString *foo = _list.firstObject; OTAssertTrue([_list containsObjectIdenticalTo: foo]); OTAssertFalse( [_list containsObjectIdenticalTo: [[foo mutableCopy] autorelease]]); } - (void)testIsEqual { OFList *list = [OFList list]; [list appendObject: @"Foo"]; [list appendObject: @"Bar"]; [list appendObject: @"Baz"]; OTAssertEqualObjects(list, _list); [list appendObject: @"Qux"]; OTAssertNotEqualObjects(list, _list); } - (void)testHash { OFList *list = [OFList list]; [list appendObject: @"Foo"]; [list appendObject: @"Bar"]; [list appendObject: @"Baz"]; OTAssertEqual(list.hash, _list.hash); [list appendObject: @"Qux"]; OTAssertNotEqual(list.hash, _list.hash); } - (void)testCopy { OTAssertEqualObjects([[_list copy] autorelease], _list); } - (void)testDescription { OTAssertEqualObjects(_list.description, @"[\n\tFoo,\n\tBar,\n\tBaz\n]"); } - (void)testEnumerator { OFEnumerator *enumerator = [_list objectEnumerator]; OTAssertEqualObjects([enumerator nextObject], @"Foo"); OTAssertEqualObjects([enumerator nextObject], @"Bar"); OTAssertEqualObjects([enumerator nextObject], @"Baz"); OTAssertNil([enumerator nextObject]); } - (void)testDetectMutationDuringEnumeration { OFEnumerator *enumerator = [_list objectEnumerator]; [_list removeListItem: _list.firstListItem]; OTAssertThrowsSpecific([enumerator nextObject], OFEnumerationMutationException); } - (void)testFastEnumeration { size_t i = 0; for (OFString *object in _list) { OTAssertLessThan(i, 3); switch (i++) { case 0: OTAssertEqualObjects(object, @"Foo"); break; case 1: OTAssertEqualObjects(object, @"Bar"); break; case 2: OTAssertEqualObjects(object, @"Baz"); break; } } OTAssertEqual(i, 3); } - (void)testDetectMutationDuringFastEnumeration { bool detected = false; @try { for (OFString *object in _list) { (void)object; [_list removeListItem: _list.firstListItem]; } } @catch (OFEnumerationMutationException *e) { detected = true; } OTAssertTrue(detected); } @end objfw-1.1.6/tests/OFLocaleTests.m000066400000000000000000000025201465614216400166250ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" @interface OFLocaleTests: OTTestCase @end @implementation OFLocaleTests + (OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, id) *) *)summary { OFMutableArray *summary = [OFMutableArray array]; #define ADD(name, value) \ [summary addObject: [OFPair pairWithFirstObject: name \ secondObject: value]]; ADD(@"Language code", [OFLocale languageCode]) ADD(@"Country code", [OFLocale countryCode]) ADD(@"Encoding", OFStringEncodingName([OFLocale encoding])) ADD(@"Decimal separator", [OFLocale decimalSeparator]) #undef ADD return summary; } @end objfw-1.1.6/tests/OFMatrix4x4Tests.m000066400000000000000000000075501465614216400172420ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" @interface OFMatrix4x4Tests: OTTestCase { OFMatrix4x4 *_matrix; } @end @implementation OFMatrix4x4Tests - (void)setUp { [super setUp]; _matrix = [[OFMatrix4x4 alloc] initWithValues: (const float [4][4]){ { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }, { 13, 14, 15, 16 } }]; } - (void)dealloc { [_matrix release]; [super dealloc]; } - (void)testIdentityMatrix { OTAssertEqual(memcmp([[OFMatrix4x4 identityMatrix] values], (const float [4][4]){ { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 } }, 16 * sizeof(float)), 0); } - (void)testDescription { OTAssertEqualObjects(_matrix.description, @""); } - (void)testIsEqual { OTAssertEqualObjects([OFMatrix4x4 identityMatrix], ([OFMatrix4x4 matrixWithValues: (const float [4][4]){ { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 } }])); } - (void)testHash { OTAssertEqual([[OFMatrix4x4 identityMatrix] hash], [([OFMatrix4x4 matrixWithValues: (const float [4][4]){ { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 } }]) hash]); } - (void)testCopy { OTAssertEqualObjects([[_matrix copy] autorelease], _matrix); } - (void)testMultiplyWithMatrix { OFMatrix4x4 *matrix; matrix = [[_matrix copy] autorelease]; [matrix multiplyWithMatrix: [OFMatrix4x4 identityMatrix]]; OTAssertEqualObjects(matrix, _matrix); matrix = [OFMatrix4x4 matrixWithValues: (const float [4][4]){ { 100, 200, 300, 400 }, { 500, 600, 700, 800 }, { 900, 1000, 1100, 1200 }, { 1300, 1400, 1500, 1600 } }]; [matrix multiplyWithMatrix: _matrix]; OTAssertEqualObjects(matrix, ([OFMatrix4x4 matrixWithValues: (const float [4][4]){ { 9000, 10000, 11000, 12000 }, { 20200, 22800, 25400, 28000 }, { 31400, 35600, 39800, 44000 }, { 42600, 48400, 54200, 60000 } }])); } - (void)testTranslateWithVector { OFMatrix4x4 *matrix = [OFMatrix4x4 identityMatrix]; OFVector4D point; [matrix translateWithVector: OFMakeVector3D(1, 2, 3)]; point = [matrix transformedVector: OFMakeVector4D(2, 3, 4, 1)]; OTAssertEqual(point.x, 3); OTAssertEqual(point.y, 5); OTAssertEqual(point.z, 7); OTAssertEqual(point.w, 1); } - (void)testScaleWithVector { OFMatrix4x4 *matrix = [OFMatrix4x4 identityMatrix]; OFVector4D point; [matrix translateWithVector: OFMakeVector3D(1, 2, 3)]; [matrix scaleWithVector: OFMakeVector3D(-1, 0.5f, 2)]; point = [matrix transformedVector: OFMakeVector4D(2, 3, 4, 1)]; OTAssertEqual(point.x, -3); OTAssertEqual(point.y, 2.5); OTAssertEqual(point.z, 14); OTAssertEqual(point.w, 1); } - (void)testTransformVectorsCount { OF_ALIGN(16) OFVector4D points[2] = {{ 1, 2, 3, 1 }, { 7, 8, 9, 2 }}; [_matrix transformVectors: points count: 2]; OTAssertEqual(points[0].x, 18); OTAssertEqual(points[0].y, 46); OTAssertEqual(points[0].z, 74); OTAssertEqual(points[0].w, 102); OTAssertEqual(points[1].x, 58); OTAssertEqual(points[1].y, 162); OTAssertEqual(points[1].z, 266); OTAssertEqual(points[1].w, 370); } @end objfw-1.1.6/tests/OFMemoryStreamTests.m000066400000000000000000000064531465614216400200630ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" @interface OFMemoryStreamTests: OTTestCase @end static const char string[] = "abcdefghijkl"; @implementation OFMemoryStreamTests - (void)testReadOnlyMemoryStream { OFMemoryStream *stream = [OFMemoryStream streamWithMemoryAddress: (char *)string size: sizeof(string) writable: false]; char buffer[10]; /* * Test the lowlevel methods, as otherwise OFStream will do one big * read and we will not test OFMemoryStream. */ OTAssertEqual([stream lowlevelReadIntoBuffer: buffer length: 5], 5); OTAssertEqual(memcmp(buffer, "abcde", 5), 0); OTAssertEqual([stream lowlevelReadIntoBuffer: buffer length: 3], 3); OTAssertEqual(memcmp(buffer, "fgh", 3), 0); OTAssertEqual([stream lowlevelReadIntoBuffer: buffer length: 10], 5); OTAssertEqual(memcmp(buffer, "ijkl", 5), 0); OTAssertTrue([stream lowlevelIsAtEndOfStream]); OTAssertEqual([stream lowlevelSeekToOffset: 0 whence: OFSeekCurrent], sizeof(string)); OTAssertTrue([stream lowlevelIsAtEndOfStream]); OTAssertEqual([stream lowlevelSeekToOffset: 4 whence: OFSeekSet], 4); OTAssertFalse([stream lowlevelIsAtEndOfStream]); OTAssertEqual([stream lowlevelReadIntoBuffer: buffer length: 10], 9); OTAssertEqual(memcmp(buffer, "efghijkl", 9), 0); OTAssertEqual([stream lowlevelSeekToOffset: -2 whence: OFSeekEnd], 11); OTAssertEqual([stream lowlevelReadIntoBuffer: buffer length: 10], 2); OTAssertEqual(memcmp(buffer, "l", 2), 0); OTAssertEqual([stream lowlevelReadIntoBuffer: buffer length: 10], 0); OTAssertThrowsSpecific([stream lowlevelWriteBuffer: "" length: 1], OFWriteFailedException); } - (void)testReadWriteMemoryStream { OFMutableData *data = [OFMutableData dataWithCapacity: 13]; OFMemoryStream *stream; [data increaseCountBy: 13]; stream = [OFMemoryStream streamWithMemoryAddress: data.mutableItems size: data.count writable: true]; OTAssertEqual([stream lowlevelWriteBuffer: "abcde" length: 5], 5); OTAssertEqual([stream lowlevelWriteBuffer: "fgh" length: 3], 3); OTAssertEqual([stream lowlevelWriteBuffer: "ijkl" length: 5], 5); OTAssertEqual(memcmp(data.items, string, data.count), 0); OTAssertEqual([stream lowlevelSeekToOffset: -3 whence: OFSeekEnd], 10); OTAssertThrowsSpecific([stream lowlevelWriteBuffer: "xyz" length: 4], OFWriteFailedException); } - (void)testWritingTooMuchThrows { char buffer; OFMemoryStream *stream = [OFMemoryStream streamWithMemoryAddress: &buffer size: 1 writable: true]; OTAssertThrowsSpecific([stream writeBuffer: "ab" length: 2], OFWriteFailedException); } @end objfw-1.1.6/tests/OFMessagePackTests.m000066400000000000000000000472351465614216400176250ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "ObjFW.h" #import "ObjFWTest.h" @interface OFMessagePackTests: OTTestCase @end const char *smallDictionaryRepresentation = "\xDE\x00\x10\x00\x01\x01\x02\x02\x03\x03\x04\x04\x05\x05\x06\x06" "\x07\x07\x08\x08\x09\x09\x0A\x0A\x0B\x0B\x0C\x0C\x0D\x0D\x0E\x0E" "\x0F\x0F\x10"; @implementation OFMessagePackTests - (void)testMessagePackRepresentationForNull { OTAssertEqualObjects([[OFNull null] messagePackRepresentation], [OFData dataWithItems: "\xC0" count: 1]); } - (void)testObjectByParsingMessagePackForNull { OTAssertEqualObjects([[OFData dataWithItems: "\xC0" count: 1] objectByParsingMessagePack], [OFNull null]); } - (void)testMessagePackRepresentationForNumber { OTAssertEqualObjects([[OFNumber numberWithChar: -30] messagePackRepresentation], [OFData dataWithItems: "\xE2" count: 1]); OTAssertEqualObjects([[OFNumber numberWithChar: -33] messagePackRepresentation], [OFData dataWithItems: "\xD0\xDF" count: 2]); OTAssertEqualObjects([[OFNumber numberWithUnsignedChar: 127] messagePackRepresentation], [OFData dataWithItems: "\x7F" count: 1]); OTAssertEqualObjects([[OFNumber numberWithUnsignedChar: 128] messagePackRepresentation], [OFData dataWithItems: "\xCC\x80" count: 2]); OTAssertEqualObjects([[OFNumber numberWithShort: -129] messagePackRepresentation], [OFData dataWithItems: "\xD1\xFF\x7F" count: 3]); OTAssertEqualObjects([[OFNumber numberWithUnsignedShort: 256] messagePackRepresentation], [OFData dataWithItems: "\xCD\x01\x00" count: 3]); OTAssertEqualObjects([[OFNumber numberWithLong: -32769] messagePackRepresentation], [OFData dataWithItems: "\xD2\xFF\xFF\x7F\xFF" count: 5]); OTAssertEqualObjects([[OFNumber numberWithUnsignedLong: 65536] messagePackRepresentation], [OFData dataWithItems: "\xCE\x00\x01\x00\x00" count: 5]); OTAssertEqualObjects([[OFNumber numberWithLongLong: -2147483649] messagePackRepresentation], [OFData dataWithItems: "\xD3\xFF\xFF\xFF\xFF\x7F\xFF\xFF\xFF" count: 9]); OTAssertEqualObjects([[OFNumber numberWithUnsignedLongLong: 4294967296] messagePackRepresentation], [OFData dataWithItems: "\xCF\x00\x00\x00\x01\x00\x00\x00\x00" count: 9]); OTAssertEqualObjects([[OFNumber numberWithFloat: 1.25f] messagePackRepresentation], [OFData dataWithItems: "\xCA\x3F\xA0\x00\x00" count: 5]); OTAssertEqualObjects([[OFNumber numberWithDouble: 1.25] messagePackRepresentation], [OFData dataWithItems: "\xCB\x3F\xF4\x00\x00\x00\x00\x00\x00" count: 9]); OTAssertEqualObjects( [[OFNumber numberWithBool: true] messagePackRepresentation], [OFData dataWithItems: "\xC3" count: 1]); OTAssertEqualObjects( [[OFNumber numberWithBool: false] messagePackRepresentation], [OFData dataWithItems: "\xC2" count: 1]); } - (void)testObjectByParsingMessagePackForNumber { OTAssertEqualObjects([[OFData dataWithItems: "\xE2" count: 1] objectByParsingMessagePack], [OFNumber numberWithChar: -30]); OTAssertEqualObjects([[OFData dataWithItems: "\xD0\xDF" count: 2] objectByParsingMessagePack], [OFNumber numberWithChar: -33]); OTAssertEqualObjects([[OFData dataWithItems: "\x7F" count: 1] objectByParsingMessagePack], [OFNumber numberWithUnsignedChar: 127]); OTAssertEqualObjects([[OFData dataWithItems: "\xCC\x80" count: 2] objectByParsingMessagePack], [OFNumber numberWithUnsignedChar: 128]); OTAssertEqualObjects([[OFData dataWithItems: "\xD1\xFF\x7F" count: 3] objectByParsingMessagePack], [OFNumber numberWithShort: -129]); OTAssertEqualObjects([[OFData dataWithItems: "\xCD\x01\x00" count: 3] objectByParsingMessagePack], [OFNumber numberWithUnsignedShort: 256]); OTAssertEqualObjects( [[OFData dataWithItems: "\xD2\xFF\xFF\x7F\xFF" count: 5] objectByParsingMessagePack], [OFNumber numberWithLong: -32769]); OTAssertEqualObjects( [[OFData dataWithItems: "\xCE\x00\x01\x00\x00" count: 5] objectByParsingMessagePack], [OFNumber numberWithUnsignedLong: 65536]); OTAssertEqualObjects( [[OFData dataWithItems: "\xD3\xFF\xFF\xFF\xFF\x7F\xFF\xFF\xFF" count: 9] objectByParsingMessagePack], [OFNumber numberWithLongLong: -2147483649]); OTAssertEqualObjects( [[OFData dataWithItems: "\xCF\x00\x00\x00\x01\x00\x00\x00\x00" count: 9] objectByParsingMessagePack], [OFNumber numberWithUnsignedLongLong: 4294967296]); OTAssertEqualObjects( [[OFData dataWithItems: "\xCA\x3F\xA0\x00\x00" count: 5] objectByParsingMessagePack], [OFNumber numberWithFloat: 1.25f]); OTAssertEqualObjects( [[OFData dataWithItems: "\xCB\x3F\xF4\x00\x00\x00\x00\x00\x00" count: 9] objectByParsingMessagePack], [OFNumber numberWithDouble: 1.25]); OTAssertEqualObjects([[OFData dataWithItems: "\xC3" count: 1] objectByParsingMessagePack], [OFNumber numberWithBool: true]); OTAssertEqualObjects([[OFData dataWithItems: "\xC2" count: 1] objectByParsingMessagePack], [OFNumber numberWithBool: false]); } static void generateStringAndData(OFString **string, OFMutableData **data, size_t length, const char *dataPrefix, size_t dataPrefixLength) { *data = [OFMutableData dataWithCapacity: length + dataPrefixLength]; [*data addItems: dataPrefix count: dataPrefixLength]; [*data increaseCountBy: length]; memset([*data mutableItemAtIndex: dataPrefixLength], 'x', length); *string = [OFString stringWithUTF8String: [*data itemAtIndex: dataPrefixLength] length: length]; } - (void)testMessagePackRepresentationForString { OFString *string; OFMutableData *data; OTAssertEqualObjects(@"x".messagePackRepresentation, [OFData dataWithItems: "\xA1x" count: 2]); generateStringAndData(&string, &data, 32, "\xD9\x20", 2); OTAssertEqualObjects(string.messagePackRepresentation, data); generateStringAndData(&string, &data, 256, "\xDA\x01\x00", 3); OTAssertEqualObjects(string.messagePackRepresentation, data); generateStringAndData(&string, &data, 65536, "\xDB\x00\x01\x00\x00", 5); OTAssertEqualObjects(string.messagePackRepresentation, data); } - (void)testObjectByParsingMessagePackForString { OFString *string; OFMutableData *data; OTAssertEqualObjects([[OFData dataWithItems: "\xA1x" count: 2] objectByParsingMessagePack], @"x"); generateStringAndData(&string, &data, 32, "\xD9\x20", 2); OTAssertEqualObjects(data.objectByParsingMessagePack, string); generateStringAndData(&string, &data, 256, "\xDA\x01\x00", 3); OTAssertEqualObjects(data.objectByParsingMessagePack, string); generateStringAndData(&string, &data, 65536, "\xDB\x00\x01\x00\x00", 5); OTAssertEqualObjects(data.objectByParsingMessagePack, string); } - (void)testMessagePackRepresentationForData { OFMutableData *data; OTAssertEqualObjects( [[OFData dataWithItems: "x" count: 1] messagePackRepresentation], [OFData dataWithItems: "\xC4\x01x" count: 3]); data = [OFMutableData data]; [data addItems: "\xC5\x01\x00" count: 3]; [data increaseCountBy: 256]; memset([data mutableItemAtIndex: 3], 'x', 256); OTAssertEqualObjects([[data subdataWithRange: OFMakeRange(3, 256)] messagePackRepresentation], data); data = [OFMutableData data]; [data addItems: "\xC6\x00\x01\x00\x00" count: 5]; [data increaseCountBy: 65536]; memset([data mutableItemAtIndex: 5], 'x', 65536); OTAssertEqualObjects([[data subdataWithRange: OFMakeRange(5, 65536)] messagePackRepresentation], data); } - (void)testObjectByParsingMessagePackForData { OFMutableData *data; OTAssertEqualObjects([[OFData dataWithItems: "\xC4\x01x" count: 3] objectByParsingMessagePack], [OFData dataWithItems: "x" count: 1]); data = [OFMutableData data]; [data addItems: "\xC5\x01\x00" count: 3]; [data increaseCountBy: 256]; memset([data mutableItemAtIndex: 3], 'x', 256); OTAssertEqualObjects(data.objectByParsingMessagePack, [data subdataWithRange: OFMakeRange(3, 256)]); data = [OFMutableData data]; [data addItems: "\xC6\x00\x01\x00\x00" count: 5]; [data increaseCountBy: 65536]; memset([data mutableItemAtIndex: 5], 'x', 65536); OTAssertEqualObjects(data.objectByParsingMessagePack, [data subdataWithRange: OFMakeRange(5, 65536)]); } - (void)testMessagePackRepresentationForArray { OFMutableArray *array = [OFMutableArray arrayWithCapacity: 65536]; OFNumber *number = [OFNumber numberWithUnsignedInt: 1]; OFMutableData *data; OTAssertEqualObjects([[OFArray array] messagePackRepresentation], [OFData dataWithItems: "\x90" count: 1]); OTAssertEqualObjects( [[OFArray arrayWithObject: number] messagePackRepresentation], [OFData dataWithItems: "\x91\x01" count: 2]); data = [OFMutableData dataWithCapacity: 19]; [data addItems: "\xDC\x00\x10" count: 3]; [data increaseCountBy: 16]; memset([data mutableItemAtIndex: 3], '\x01', 16); for (size_t i = 0; i < 16; i++) [array addObject: number]; OTAssertEqualObjects(array.messagePackRepresentation, data); data = [OFMutableData dataWithCapacity: 65541]; [data addItems: "\xDD\x00\x01\x00\x00" count: 5]; [data increaseCountBy: 65536]; memset([data mutableItemAtIndex: 5], '\x01', 65536); for (size_t i = 16; i < 65536; i++) [array addObject: number]; OTAssertEqualObjects(array.messagePackRepresentation, data); } - (void)testObjectByParsingMessagePackForArray { OFMutableArray *array = [OFMutableArray arrayWithCapacity: 65536]; OFNumber *number = [OFNumber numberWithUnsignedInt: 1]; OFMutableData *data; OTAssertEqualObjects([[OFData dataWithItems: "\x90" count: 1] objectByParsingMessagePack], [OFArray array]); OTAssertEqualObjects([[OFData dataWithItems: "\x91\x01" count: 2] objectByParsingMessagePack], [OFArray arrayWithObject: number]); data = [OFMutableData dataWithCapacity: 19]; [data addItems: "\xDC\x00\x10" count: 3]; [data increaseCountBy: 16]; memset([data mutableItemAtIndex: 3], '\x01', 16); for (size_t i = 0; i < 16; i++) [array addObject: number]; OTAssertEqualObjects(data.objectByParsingMessagePack, array); data = [OFMutableData dataWithCapacity: 65541]; [data addItems: "\xDD\x00\x01\x00\x00" count: 5]; [data increaseCountBy: 65536]; memset([data mutableItemAtIndex: 5], '\x01', 65536); for (size_t i = 16; i < 65536; i++) [array addObject: number]; OTAssertEqualObjects(data.objectByParsingMessagePack, array); } - (void)testMessagePackRepresentationForDictionary { OFMutableArray *keys = [OFMutableArray arrayWithCapacity: 65536]; OFMutableArray *objects = [OFMutableArray arrayWithCapacity: 65536]; OTAssertEqualObjects([[OFDictionary dictionary] messagePackRepresentation], [OFData dataWithItems: "\x80" count: 1]); OTAssertEqualObjects([[OFDictionary dictionaryWithObject: [OFNumber numberWithUnsignedInt: 2] forKey: [OFNumber numberWithUnsignedInt: 1]] messagePackRepresentation], [OFData dataWithItems: "\x81\x01\x02" count: 3]); for (unsigned int i = 0; i < 16; i++) { [keys addObject: [OFNumber numberWithUnsignedInt: i]]; [objects addObject: [OFNumber numberWithUnsignedInt: i + 1]]; } OTAssertEqualObjects([[OTOrderedDictionary dictionaryWithObjects: objects.objects forKeys: keys.objects count: 16] messagePackRepresentation], [OFData dataWithItems: smallDictionaryRepresentation count: 35]); for (unsigned int i = 16; i < 65536; i++) { [keys addObject: [OFNumber numberWithUnsignedInt: i]]; [objects addObject: [OFNumber numberWithUnsignedInt: i + 1]]; } OTAssertEqualObjects([[OTOrderedDictionary dictionaryWithObjects: objects.objects forKeys: keys.objects count: 65536] messagePackRepresentation], [OFData dataWithContentsOfIRI: [OFIRI IRIWithString: @"embedded:big_dictionary.msgpack"]]); } - (void)testObjectByParsingMessagePackForDictionary { OFMutableDictionary *dictionary = [OFMutableDictionary dictionaryWithCapacity: 65536]; OTAssertEqualObjects([[OFData dataWithItems: "\x80" count: 1] objectByParsingMessagePack], [OFDictionary dictionary]); OTAssertEqualObjects([[OFData dataWithItems: "\x81\x01\x02" count: 3] objectByParsingMessagePack], [OFDictionary dictionaryWithObject: [OFNumber numberWithUnsignedInt: 2] forKey: [OFNumber numberWithUnsignedInt: 1]]); for (unsigned int i = 0; i < 16; i++) [dictionary setObject: [OFNumber numberWithUnsignedInt: i + 1] forKey: [OFNumber numberWithUnsignedInt: i]]; OTAssertEqualObjects( [[OFData dataWithItems: smallDictionaryRepresentation count: 35] objectByParsingMessagePack], dictionary); for (unsigned int i = 16; i < 65536; i++) [dictionary setObject: [OFNumber numberWithUnsignedInt: i + 1] forKey: [OFNumber numberWithUnsignedInt: i]]; OTAssertEqualObjects(dictionary, [[OFData dataWithContentsOfIRI: [OFIRI IRIWithString: @"embedded:big_dictionary.msgpack"]] objectByParsingMessagePack]); } - (void)testMessagePackRepresentationForExtension { OFMessagePackExtension *extension; OFMutableData *data; extension = [OFMessagePackExtension extensionWithType: 1 data: [OFData dataWithItems: "x" count: 1]]; OTAssertEqualObjects(extension.messagePackRepresentation, [OFData dataWithItems: "\xD4\x01x" count: 3]); extension = [OFMessagePackExtension extensionWithType: 1 data: [OFData dataWithItems: "xy" count: 2]]; OTAssertEqualObjects(extension.messagePackRepresentation, [OFData dataWithItems: "\xD5\x01xy" count: 4]); extension = [OFMessagePackExtension extensionWithType: 1 data: [OFData dataWithItems: "abcd" count: 4]]; OTAssertEqualObjects(extension.messagePackRepresentation, [OFData dataWithItems: "\xD6\x01" "abcd" count: 6]); extension = [OFMessagePackExtension extensionWithType: 1 data: [OFData dataWithItems: "12345678" count: 8]]; OTAssertEqualObjects(extension.messagePackRepresentation, [OFData dataWithItems: "\xD7\x01" "12345678" count: 10]); extension = [OFMessagePackExtension extensionWithType: 1 data: [OFData dataWithItems: "12345678ABCDEFGH" count: 16]]; OTAssertEqualObjects(extension.messagePackRepresentation, [OFData dataWithItems: "\xD8\x01" "12345678ABCDEFGH" count: 18]); extension = [OFMessagePackExtension extensionWithType: 1 data: [OFData data]]; OTAssertEqualObjects(extension.messagePackRepresentation, [OFData dataWithItems: "\xC7\x00\x01" count: 3]); extension = [OFMessagePackExtension extensionWithType: 1 data: [OFData dataWithItems: "abc" count: 3]]; OTAssertEqualObjects(extension.messagePackRepresentation, [OFData dataWithItems: "\xC7\x03\x01" "abc" count: 6]); data = [OFMutableData dataWithCapacity: 260]; [data addItems: "\xC8\x01\x00\x01" count: 4]; [data increaseCountBy: 256]; memset([data mutableItemAtIndex: 4], 'x', 256); extension = [OFMessagePackExtension extensionWithType: 1 data: [data subdataWithRange: OFMakeRange(4, 256)]]; OTAssertEqualObjects(extension.messagePackRepresentation, data); data = [OFMutableData dataWithCapacity: 65542]; [data addItems: "\xC9\x00\x01\x00\x00\x01" count: 6]; [data increaseCountBy: 65536]; memset([data mutableItemAtIndex: 6], 'x', 65536); extension = [OFMessagePackExtension extensionWithType: 1 data: [data subdataWithRange: OFMakeRange(6, 65536)]]; OTAssertEqualObjects(extension.messagePackRepresentation, data); } - (void)testObjectByParsingMessagePackForExtension { OFMessagePackExtension *extension; OFMutableData *data; extension = [OFMessagePackExtension extensionWithType: 1 data: [OFData dataWithItems: "x" count: 1]]; OTAssertEqualObjects([[OFData dataWithItems: "\xD4\x01x" count: 3] objectByParsingMessagePack], extension); extension = [OFMessagePackExtension extensionWithType: 1 data: [OFData dataWithItems: "xy" count: 2]]; OTAssertEqualObjects([[OFData dataWithItems: "\xD5\x01xy" count: 4] objectByParsingMessagePack], extension); extension = [OFMessagePackExtension extensionWithType: 1 data: [OFData dataWithItems: "abcd" count: 4]]; OTAssertEqualObjects( [[OFData dataWithItems: "\xD6\x01" "abcd" count: 6] objectByParsingMessagePack], extension); extension = [OFMessagePackExtension extensionWithType: 1 data: [OFData dataWithItems: "12345678" count: 8]]; OTAssertEqualObjects( [[OFData dataWithItems: "\xD7\x01" "12345678" count: 10] objectByParsingMessagePack], extension); extension = [OFMessagePackExtension extensionWithType: 1 data: [OFData dataWithItems: "12345678ABCDEFGH" count: 16]]; OTAssertEqualObjects( [[OFData dataWithItems: "\xD8\x01" "12345678ABCDEFGH" count: 18] objectByParsingMessagePack], extension); extension = [OFMessagePackExtension extensionWithType: 1 data: [OFData data]]; OTAssertEqualObjects([[OFData dataWithItems: "\xC7\x00\x01" count: 3] objectByParsingMessagePack], extension); extension = [OFMessagePackExtension extensionWithType: 1 data: [OFData dataWithItems: "abc" count: 3]]; OTAssertEqualObjects( [[OFData dataWithItems: "\xC7\x03\x01" "abc" count: 6] objectByParsingMessagePack], extension); data = [OFMutableData dataWithCapacity: 260]; [data addItems: "\xC8\x01\x00\x01" count: 4]; [data increaseCountBy: 256]; memset([data mutableItemAtIndex: 4], 'x', 256); extension = [OFMessagePackExtension extensionWithType: 1 data: [data subdataWithRange: OFMakeRange(4, 256)]]; OTAssertEqualObjects(data.objectByParsingMessagePack, extension); data = [OFMutableData dataWithCapacity: 65542]; [data addItems: "\xC9\x00\x01\x00\x00\x01" count: 6]; [data increaseCountBy: 65536]; memset([data mutableItemAtIndex: 6], 'x', 65536); extension = [OFMessagePackExtension extensionWithType: 1 data: [data subdataWithRange: OFMakeRange(6, 65536)]]; OTAssertEqualObjects(data.objectByParsingMessagePack, extension); } - (void)testMessagePackRepresentationForDate { OTAssertEqualObjects([[OFDate dateWithTimeIntervalSince1970: 1] messagePackRepresentation], [OFData dataWithItems: "\xD6\xFF\x00\x00\x00\x01" count: 6]); OTAssertEqualObjects([[OFDate dateWithTimeIntervalSince1970: 1.25] messagePackRepresentation], [OFData dataWithItems: "\xD7\xFF\x3B\x9A\xCA\x00\x00\x00\x00\x01" count: 10]); OTAssertEqualObjects( [[OFDate dateWithTimeIntervalSince1970: 0x400000000 + 0.25] messagePackRepresentation], [OFData dataWithItems: "\xC7\x0C\xFF\x0E\xE6\xB2\x80\x00\x00\x00" "\x04\x00\x00\x00\x00" count: 15]); } - (void)testObjectByParsingMessagePackForDate { OTAssertEqualObjects( [[OFData dataWithItems: "\xD6\xFF\x00\x00\x00\x01" count: 6] objectByParsingMessagePack], [OFDate dateWithTimeIntervalSince1970: 1]); OTAssertEqualObjects( [[OFData dataWithItems: "\xD7\xFF\x3B\x9A\xCA\x00\x00\x00\x00\x01" count: 10] objectByParsingMessagePack], [OFDate dateWithTimeIntervalSince1970: 1.25]); OTAssertEqualObjects( [[OFData dataWithItems: "\xC7\x0C\xFF\x0E\xE6\xB2\x80\x00\x00\x00" "\x04\x00\x00\x00\x00" count: 15] objectByParsingMessagePack], [OFDate dateWithTimeIntervalSince1970: 0x400000000 + 0.25]); } @end objfw-1.1.6/tests/OFMethodSignatureTests.m000066400000000000000000000121221465614216400205270ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #if !defined(__STDC_NO_COMPLEX__) && defined(HAVE_COMPLEX_H) # include #endif #import "ObjFW.h" #import "ObjFWTest.h" @interface OFMethodSignatureTests: OTTestCase @end struct Test1Struct { char c; int i; char d; }; struct Test2Struct { char c; struct { short s; int i; } st; union { char c; int i; } u; double d; }; #if !defined(__STDC_NO_COMPLEX__) && defined(HAVE_COMPLEX_H) struct Test3Struct { char c; complex double cd; }; #endif union Test3Union { char c; int i; double d; }; union Test4Union { char c; struct { short x, y; } st; int i; union { float f; double d; } u; }; @implementation OFMethodSignatureTests - (void)testSignatureWithObjCTypes { OFMethodSignature *methodSignature; methodSignature = [OFMethodSignature signatureWithObjCTypes: "i28@0:8S16*20"]; OTAssertEqual(methodSignature.numberOfArguments, 4); OTAssertEqual(strcmp(methodSignature.methodReturnType, "i"), 0); OTAssertEqual(strcmp([methodSignature argumentTypeAtIndex: 0], "@"), 0); OTAssertEqual(strcmp([methodSignature argumentTypeAtIndex: 1], ":"), 0); OTAssertEqual(strcmp([methodSignature argumentTypeAtIndex: 2], "S"), 0); OTAssertEqual(strcmp([methodSignature argumentTypeAtIndex: 3], "*"), 0); OTAssertEqual(methodSignature.frameLength, 28); OTAssertEqual([methodSignature argumentOffsetAtIndex: 0], 0); OTAssertEqual([methodSignature argumentOffsetAtIndex: 1], 8); OTAssertEqual([methodSignature argumentOffsetAtIndex: 2], 16); OTAssertEqual([methodSignature argumentOffsetAtIndex: 3], 20); methodSignature = [OFMethodSignature signatureWithObjCTypes: "{s0=csi(u1={s2=iii{s3=(u4=ic^v*)}})}24@0:8" "^{s0=csi(u1={s2=iii{s3=(u4=ic^v*)}})}16"]; OTAssertEqual(methodSignature.numberOfArguments, 3); OTAssertEqual(strcmp(methodSignature.methodReturnType, "{s0=csi(u1={s2=iii{s3=(u4=ic^v*)}})}"), 0); OTAssertEqual(strcmp([methodSignature argumentTypeAtIndex: 0], "@"), 0); OTAssertEqual(strcmp([methodSignature argumentTypeAtIndex: 1], ":"), 0); OTAssertEqual(strcmp([methodSignature argumentTypeAtIndex: 2], "^{s0=csi(u1={s2=iii{s3=(u4=ic^v*)}})}"), 0); OTAssertEqual(methodSignature.frameLength, 24); OTAssertEqual([methodSignature argumentOffsetAtIndex: 0], 0); OTAssertEqual([methodSignature argumentOffsetAtIndex: 1], 8); OTAssertEqual([methodSignature argumentOffsetAtIndex: 2], 16); } - (void)testSignatureWithObjCTypesFailsWithInvalidFormat { OTAssertThrowsSpecific( [OFMethodSignature signatureWithObjCTypes: "{ii"], OFInvalidFormatException); OTAssertThrowsSpecific([OFMethodSignature signatureWithObjCTypes: ""], OFInvalidFormatException); OTAssertThrowsSpecific([OFMethodSignature signatureWithObjCTypes: "0"], OFInvalidFormatException); OTAssertThrowsSpecific( [OFMethodSignature signatureWithObjCTypes: "{{}0"], OFInvalidFormatException); } - (void)testSizeOfTypeEncoding { OTAssertEqual(OFSizeOfTypeEncoding(@encode(struct Test1Struct)), sizeof(struct Test1Struct)); OTAssertEqual(OFSizeOfTypeEncoding(@encode(struct Test2Struct)), sizeof(struct Test2Struct)); #if !defined(__STDC_NO_COMPLEX__) && defined(HAVE_COMPLEX_H) && \ OF_GCC_VERSION >= 402 OTAssertEqual(OFSizeOfTypeEncoding(@encode(struct Test3Struct)), sizeof(struct Test3Struct)); #endif OTAssertEqual(OFSizeOfTypeEncoding(@encode(union Test3Union)), sizeof(union Test3Union)); OTAssertEqual(OFSizeOfTypeEncoding(@encode(union Test4Union)), sizeof(union Test4Union)); OTAssertEqual(OFSizeOfTypeEncoding(@encode(struct Test1Struct [5])), sizeof(struct Test1Struct [5])); } - (void)testAlignmentOfTypeEncoding { OTAssertEqual(OFAlignmentOfTypeEncoding(@encode(struct Test1Struct)), OF_ALIGNOF(struct Test1Struct)); OTAssertEqual(OFAlignmentOfTypeEncoding(@encode(struct Test2Struct)), OF_ALIGNOF(struct Test2Struct)); #if !defined(__STDC_NO_COMPLEX__) && defined(HAVE_COMPLEX_H) && \ OF_GCC_VERSION >= 402 OTAssertEqual(OFAlignmentOfTypeEncoding(@encode(struct Test3Struct)), OF_ALIGNOF(struct Test3Struct)); #endif OTAssertEqual(OFAlignmentOfTypeEncoding(@encode(union Test3Union)), OF_ALIGNOF(union Test3Union)); OTAssertEqual(OFAlignmentOfTypeEncoding(@encode(union Test4Union)), OF_ALIGNOF(union Test4Union)); OTAssertEqual( OFAlignmentOfTypeEncoding(@encode(struct Test1Struct [5])), OF_ALIGNOF(struct Test1Struct [5])); } @end objfw-1.1.6/tests/OFMutableArrayTests.h000066400000000000000000000015141465614216400200130ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFArrayTests.h" @interface OFMutableArrayTests: OFArrayTests { OFMutableArray *_mutableArray; } @end objfw-1.1.6/tests/OFMutableArrayTests.m000066400000000000000000000123231465614216400200200ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFMutableArrayTests.h" #import "OFArray+Private.h" @interface CustomMutableArray: OFMutableArray { OFMutableArray *_array; } @end static OFString *const cArray[] = { @"Foo", @"Bar", @"Baz" }; @implementation OFMutableArrayTests - (Class)arrayClass { return [CustomMutableArray class]; } - (void)setUp { [super setUp]; _mutableArray = [[self.arrayClass alloc] initWithObjects: cArray count: sizeof(cArray) / sizeof(*cArray)]; } - (void)dealloc { [_mutableArray release]; [super dealloc]; } - (void)testAddObject { [_mutableArray addObject: cArray[0]]; [_mutableArray addObject: cArray[2]]; OTAssertEqualObjects(_mutableArray, ([OFArray arrayWithObjects: @"Foo", @"Bar", @"Baz", @"Foo", @"Baz", nil])); } - (void)testInsertObjectAtIndex { [_mutableArray insertObject: cArray[1] atIndex: 1]; OTAssertEqualObjects(_mutableArray, ([OFArray arrayWithObjects: @"Foo", @"Bar", @"Bar", @"Baz", nil])); } - (void)testReplaceObjectWithObject { [_mutableArray insertObject: cArray[1] atIndex: 1]; [_mutableArray replaceObject: cArray[1] withObject: cArray[0]]; OTAssertEqualObjects(_mutableArray, ([OFArray arrayWithObjects: @"Foo", @"Foo", @"Foo", @"Baz", nil])); } - (void)testReplaceObjectIdenticalToWithObject { [_mutableArray insertObject: [[cArray[1] mutableCopy] autorelease] atIndex: 1]; [_mutableArray insertObject: [[cArray[1] mutableCopy] autorelease] atIndex: 4]; [_mutableArray replaceObjectIdenticalTo: cArray[1] withObject: cArray[0]]; OTAssertEqualObjects(_mutableArray, ([OFArray arrayWithObjects: @"Foo", @"Bar", @"Foo", @"Baz", @"Bar", nil])); } - (void)testReplaceObjectAtIndexWithObject { [_mutableArray replaceObjectAtIndex: 1 withObject: cArray[0]]; OTAssertEqualObjects(_mutableArray, ([OFArray arrayWithObjects: @"Foo", @"Foo", @"Baz", nil])); } - (void)testRemoveObject { [_mutableArray removeObject: cArray[1]]; OTAssertEqualObjects(_mutableArray, ([OFArray arrayWithObjects: @"Foo", @"Baz", nil])); } - (void)testRemoveObjectIdenticalTo { [_mutableArray removeObjectIdenticalTo: cArray[1]]; OTAssertEqualObjects(_mutableArray, ([OFArray arrayWithObjects: @"Foo", @"Baz", nil])); } - (void)testRemoveObjectAtIndex { [_mutableArray removeObjectAtIndex: 1]; OTAssertEqualObjects(_mutableArray, ([OFArray arrayWithObjects: @"Foo", @"Baz", nil])); } - (void)testRemoveObjectsInRange { [_mutableArray removeObjectsInRange: OFMakeRange(1, 2)]; OTAssertEqualObjects(_mutableArray, [OFArray arrayWithObject: @"Foo"]); } - (void)testRemoveObjectsInRangeFailsWhenOutOfRange { OTAssertThrowsSpecific([_mutableArray removeObjectsInRange: OFMakeRange(0, _mutableArray.count + 1)], OFOutOfRangeException); } - (void)testReverse { [_mutableArray reverse]; OTAssertEqualObjects(_mutableArray, ([OFArray arrayWithObjects: @"Baz", @"Bar", @"Foo", nil])); } #ifdef OF_HAVE_BLOCKS - (void)testReplaceObjectsUsingBlock { [_mutableArray replaceObjectsUsingBlock: ^ id (id object, size_t idx) { return [object lowercaseString]; }]; OTAssertEqualObjects(_mutableArray, ([OFArray arrayWithObjects: @"foo", @"bar", @"baz", nil])); } #endif - (void)testSetValueForKey { OFMutableArray *array = [self.arrayClass arrayWithObjects: [OFMutableIRI IRIWithString: @"http://foo.bar/"], [OFMutableIRI IRIWithString: @"http://bar.qux/"], [OFMutableIRI IRIWithString: @"http://qux.quxqux/"], nil]; [array setValue: [OFNumber numberWithShort: 1234] forKey: @"port"]; OTAssertEqualObjects(array, ([OFArray arrayWithObjects: [OFIRI IRIWithString: @"http://foo.bar:1234/"], [OFIRI IRIWithString: @"http://bar.qux:1234/"], [OFIRI IRIWithString: @"http://qux.quxqux:1234/"], nil])); } @end @implementation CustomMutableArray - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { self = [super init]; @try { _array = [[OFMutableArray alloc] initWithObjects: objects count: count]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_array release]; [super dealloc]; } - (id)objectAtIndex: (size_t)idx { return [_array objectAtIndex: idx]; } - (size_t)count { return [_array count]; } - (void)insertObject: (id)object atIndex: (size_t)idx { [_array insertObject: object atIndex: idx]; } - (void)replaceObjectAtIndex: (size_t)idx withObject: (id)object { [_array replaceObjectAtIndex: idx withObject: object]; } - (void)removeObjectAtIndex: (size_t)idx { [_array removeObjectAtIndex: idx]; } @end objfw-1.1.6/tests/OFMutableDataTests.m000066400000000000000000000052451465614216400176200ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFDataTests.h" @interface OFMutableDataTests: OFDataTests { OFMutableData *_mutableData; } @end @implementation OFMutableDataTests - (Class)dataClass { return [OFMutableData class]; } - (void)setUp { [super setUp]; _mutableData = [[OFMutableData alloc] initWithItems: "abcdef" count: 6]; } - (void)dealloc { [_mutableData release]; [super dealloc]; } - (void)testMutableCopy { OTAssertEqualObjects([[_data mutableCopy] autorelease], _data); OTAssertNotEqual([[_data mutableCopy] autorelease], _data); } - (void)testAddItem { [_mutableData addItem: "g"]; OTAssertEqualObjects(_mutableData, [OFData dataWithItems: "abcdefg" count: 7]); } - (void)testAddItemsCount { [_mutableData addItems: "gh" count: 2]; OTAssertEqualObjects(_mutableData, [OFData dataWithItems: "abcdefgh" count: 8]); } - (void)testAddItemsCountThrowsOnOutOfRange { OTAssertThrowsSpecific([_mutableData addItems: "" count: SIZE_MAX], OFOutOfRangeException); } - (void)testRemoveLastItem { [_mutableData removeLastItem]; OTAssertEqualObjects(_mutableData, [OFData dataWithItems: "abcde" count: 5]); } - (void)testRemoveItemsInRange { [_mutableData removeItemsInRange: OFMakeRange(1, 2)]; OTAssertEqualObjects(_mutableData, [OFData dataWithItems: "adef" count: 4]); } - (void)testRemoveItemsInRangeThrowsOnOutOfRangeRange { OTAssertThrowsSpecific( [_mutableData removeItemsInRange: OFMakeRange(6, 1)], OFOutOfRangeException); OTAssertThrowsSpecific( [_mutableData removeItemsInRange: OFMakeRange(7, 0)], OFOutOfRangeException); } - (void)testInsertItemsAtIndexCount { [_mutableData insertItems: "BC" atIndex: 1 count: 2]; OTAssertEqualObjects(_mutableData, [OFData dataWithItems: "aBCbcdef" count: 8]); } - (void)testInsertItemsAtIndexCountThrowsOnOutOfRangeIndex { OTAssertThrowsSpecific( [_mutableData insertItems: "a" atIndex: 7 count: 1], OFOutOfRangeException); } @end objfw-1.1.6/tests/OFMutableDictionaryTests.h000066400000000000000000000016161465614216400210450ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "ObjFW.h" #import "ObjFWTest.h" #import "OFDictionaryTests.h" @interface OFMutableDictionaryTests: OFDictionaryTests { OFMutableDictionary *_mutableDictionary; } @end objfw-1.1.6/tests/OFMutableDictionaryTests.m000066400000000000000000000075131465614216400210540ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFMutableDictionaryTests.h" @interface CustomMutableDictionary: OFMutableDictionary { OFMutableDictionary *_dictionary; } @end @implementation OFMutableDictionaryTests - (Class)dictionaryClass { return [CustomMutableDictionary class]; } - (void)setUp { [super setUp]; _mutableDictionary = [[self.dictionaryClass alloc] init]; } - (void)dealloc { [_mutableDictionary release]; [super dealloc]; } - (void)testSetObjectForKey { [_mutableDictionary setObject: @"bar" forKey: @"foo"]; OTAssertEqualObjects([_mutableDictionary objectForKey: @"foo"], @"bar"); [_mutableDictionary setObject: @"qux" forKey: @"baz"]; OTAssertEqualObjects(_mutableDictionary, ([OFDictionary dictionaryWithKeysAndObjects: @"foo", @"bar", @"baz", @"qux", nil])); } - (void)testSetValueForKey { [_mutableDictionary setValue: @"bar" forKey: @"foo"]; OTAssertEqualObjects([_mutableDictionary objectForKey: @"foo"], @"bar"); [_mutableDictionary setValue: @"qux" forKey: @"baz"]; OTAssertEqualObjects(_mutableDictionary, ([OFDictionary dictionaryWithKeysAndObjects: @"foo", @"bar", @"baz", @"qux", nil])); } - (void)testRemoveObjectForKey { [_mutableDictionary addEntriesFromDictionary: _dictionary]; OTAssertEqual(_mutableDictionary.count, 2); [_mutableDictionary removeObjectForKey: @"key2"]; OTAssertEqual(_mutableDictionary.count, 1); OTAssertEqualObjects(_mutableDictionary, [OFDictionary dictionaryWithObject: @"value1" forKey: @"key1"]); } - (void)testMutableCopy { OFMutableDictionary *copy = [[_dictionary mutableCopy] autorelease]; OTAssertEqualObjects(copy, _dictionary); OTAssertNotEqual(copy, _dictionary); } #ifdef OF_HAVE_BLOCKS - (void)testReplaceObjectsUsingBlock { OFMutableDictionary *mutableDictionary = [[_dictionary mutableCopy] autorelease]; [mutableDictionary replaceObjectsUsingBlock: ^ id (id key, id object) { if ([key isEqual: @"key1"]) return @"value_1"; if ([key isEqual: @"key2"]) return @"value_2"; return nil; }]; OTAssertEqualObjects(mutableDictionary, ([OFDictionary dictionaryWithKeysAndObjects: @"key1", @"value_1", @"key2", @"value_2", nil])); } #endif @end @implementation CustomMutableDictionary - (instancetype)init { self = [super init]; @try { _dictionary = [[OFMutableDictionary alloc] init]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithObjects: (const id *)objects_ forKeys: (const id *)keys_ count: (size_t)count { self = [super init]; @try { _dictionary = [[OFMutableDictionary alloc] initWithObjects: objects_ forKeys: keys_ count: count]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_dictionary release]; [super dealloc]; } - (id)objectForKey: (id)key { return [_dictionary objectForKey: key]; } - (size_t)count { return _dictionary.count; } - (OFEnumerator *)keyEnumerator { return [_dictionary keyEnumerator]; } - (void)setObject: (id)object forKey: (id)key { [_dictionary setObject: object forKey: key]; } - (void)removeObjectForKey: (id)key { [_dictionary removeObjectForKey: key]; } @end objfw-1.1.6/tests/OFMutableSetTests.h000066400000000000000000000015021465614216400174650ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFSetTests.h" @interface OFMutableSetTests: OFSetTests { OFMutableSet *_mutableSet; } @end objfw-1.1.6/tests/OFMutableSetTests.m000066400000000000000000000053671465614216400175070ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFMutableSetTests.h" @interface CustomMutableSet: OFMutableSet { OFMutableSet *_set; } @end @implementation OFMutableSetTests - (Class)setClass { return [CustomMutableSet class]; } - (void)setUp { [super setUp]; _mutableSet = [[OFMutableSet alloc] initWithObjects: @"foo", @"bar", @"baz", nil]; } - (void)dealloc { [_mutableSet release]; [super dealloc]; } - (void)testAddObject { [_mutableSet addObject: @"x"]; OTAssertEqualObjects(_mutableSet, ([OFSet setWithObjects: @"foo", @"bar", @"baz", @"x", nil])); } - (void)testRemoveObject { [_mutableSet removeObject: @"foo"]; OTAssertEqualObjects(_mutableSet, ([OFSet setWithObjects: @"bar", @"baz", nil])); } - (void)testMinusSet { [_mutableSet minusSet: [OFSet setWithObjects: @"foo", @"bar", nil]]; OTAssertEqualObjects(_mutableSet, ([OFSet setWithObjects: @"baz", nil])); } - (void)testIntersectSet { [_mutableSet intersectSet: [OFSet setWithObjects: @"foo", @"qux", nil]]; OTAssertEqualObjects(_mutableSet, ([OFSet setWithObjects: @"foo", nil])); } - (void)testUnionSet { [_mutableSet unionSet: [OFSet setWithObjects: @"x", @"y", nil]]; OTAssertEqualObjects(_mutableSet, ([OFSet setWithObjects: @"foo", @"bar", @"baz", @"x", @"y", nil])); } - (void)testRemoveAllObjects { [_mutableSet removeAllObjects]; OTAssertEqual(_mutableSet.count, 0); } @end @implementation CustomMutableSet - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { self = [super init]; @try { _set = [[OFMutableSet alloc] initWithObjects: objects count: count]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_set release]; [super dealloc]; } - (size_t)count { return _set.count; } - (bool)containsObject: (id)object { return [_set containsObject: object]; } - (OFEnumerator *)objectEnumerator { return [_set objectEnumerator]; } - (void)addObject: (id)object { [_set addObject: object]; } - (void)removeObject: (id)object { [_set removeObject: object]; } @end objfw-1.1.6/tests/OFMutableStringTests.h000066400000000000000000000015721465614216400202070ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "ObjFW.h" #import "ObjFWTest.h" #import "OFStringTests.h" @interface OFMutableStringTests: OFStringTests { OFMutableString *_mutableString; } @end objfw-1.1.6/tests/OFMutableStringTests.m000066400000000000000000000222221465614216400202070ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFMutableStringTests.h" @interface CustomMutableString: OFMutableString { OFMutableString *_string; } @end static OFString *const whitespace[] = { @" \r \t\n\t \tasd \t \t\t\r\n", @" \t\t \t\t \t \t" }; @implementation OFMutableStringTests - (Class)stringClass { return [CustomMutableString class]; } - (void)setUp { [super setUp]; _mutableString = [[self.stringClass alloc] initWithString: @"täṠ€🤔"]; } - (void)dealloc { [_mutableString release]; [super dealloc]; } - (void)testAppendString { [_mutableString appendString: @"ö"]; OTAssertEqualObjects(_mutableString, @"täṠ€🤔ö"); } - (void)testAppendUTF8String { [_mutableString appendUTF8String: "ö"]; OTAssertEqualObjects(_mutableString, @"täṠ€🤔ö"); } - (void)testAppendUTF8StringLength { [_mutableString appendUTF8String: "\xEF\xBB\xBF" "öÖ" length: 7]; OTAssertEqualObjects(_mutableString, @"täṠ€🤔öÖ"); } - (void)testAppendFormat { [_mutableString appendFormat: @"%02X", 15]; OTAssertEqualObjects(_mutableString, @"täṠ€🤔0F"); } - (void)testAppendCharactersLength { [_mutableString appendCharacters: (OFUnichar []){ 0xF6, 0xD6 } length: 2]; OTAssertEqualObjects(_mutableString, @"täṠ€🤔öÖ"); } - (void)testUppercase { [_mutableString uppercase]; #ifdef OF_HAVE_UNICODE_TABLES OTAssertEqualObjects(_mutableString, @"TÄṠ€🤔"); #else OTAssertEqualObjects(_mutableString, @"TäṠ€🤔"); #endif } - (void)testLowercase { [_mutableString lowercase]; #ifdef OF_HAVE_UNICODE_TABLES OTAssertEqualObjects(_mutableString, @"täṡ€🤔"); #else OTAssertEqualObjects(_mutableString, @"täṠ€🤔"); #endif } - (void)testCapitalize { OFMutableString *string = [self.stringClass stringWithString: @"täṠ€🤔täṠ€🤔 täṠ€🤔"]; [string capitalize]; #ifdef OF_HAVE_UNICODE_TABLES OTAssertEqualObjects(string, @"Täṡ€🤔täṡ€🤔 Täṡ€🤔"); #else OTAssertEqualObjects(string, @"TäṠ€🤔täṠ€🤔 TäṠ€🤔"); #endif } - (void)testInsertStringAtIndex { [_mutableString insertString: @"fööbär" atIndex: 2]; OTAssertEqualObjects(_mutableString, @"täfööbärṠ€🤔"); } - (void)testSetCharacterAtIndex { [_mutableString setCharacter: 0x1F600 atIndex: 2]; OTAssertEqualObjects(_mutableString, @"tä😀€🤔"); } - (void)testDeleteCharactersInRange { [_mutableString deleteCharactersInRange: OFMakeRange(2, 2)]; OTAssertEqualObjects(_mutableString, @"tä🤔"); } - (void)testDeleteCharactersInRangeThrowsWithOutOfRangeRange { OTAssertThrowsSpecific( [_mutableString deleteCharactersInRange: OFMakeRange(4, 2)], OFOutOfRangeException); OTAssertThrowsSpecific( [_mutableString deleteCharactersInRange: OFMakeRange(5, 1)], OFOutOfRangeException); OTAssertThrowsSpecific( [_mutableString deleteCharactersInRange: OFMakeRange(6, 0)], OFOutOfRangeException); } - (void)testReplaceCharactersInRangeWithString { OFMutableString *string = [self.stringClass stringWithString: @"𝄞öööbä€"]; [string replaceCharactersInRange: OFMakeRange(1, 3) withString: @"äöüß"]; OTAssertEqualObjects(string, @"𝄞äöüßbä€"); [string replaceCharactersInRange: OFMakeRange(4, 2) withString: @"b"]; OTAssertEqualObjects(string, @"𝄞äöübä€"); [string replaceCharactersInRange: OFMakeRange(0, 7) withString: @""]; OTAssertEqualObjects(string, @""); } - (void)testReplaceCharactersInRangeWithStringFailsWithOutOfRangeRange { OTAssertThrowsSpecific( [_mutableString replaceCharactersInRange: OFMakeRange(4, 2) withString: @"abc"], OFOutOfRangeException); OTAssertThrowsSpecific( [_mutableString replaceCharactersInRange: OFMakeRange(5, 1) withString: @"abc"], OFOutOfRangeException); OTAssertThrowsSpecific( [_mutableString replaceCharactersInRange: OFMakeRange(6, 0) withString: @""], OFOutOfRangeException); } - (void)testReplaceOccurrencesOfStringWithString { OFMutableString *string; string = [self.stringClass stringWithString: @"asd fo asd fofo asd"]; [string replaceOccurrencesOfString: @"fo" withString: @"foo"]; OTAssertEqualObjects(string, @"asd foo asd foofoo asd"); string = [self.stringClass stringWithString: @"XX"]; [string replaceOccurrencesOfString: @"X" withString: @"XX"]; OTAssertEqualObjects(string, @"XXXX"); } - (void)testReplaceOccurrencesOfStringWithStringOptionsRange { OFMutableString *string = [self.stringClass stringWithString: @"foofoobarfoobarfoo"]; [string replaceOccurrencesOfString: @"oo" withString: @"óò" options: 0 range: OFMakeRange(2, 15)]; OTAssertEqualObjects(string, @"foofóòbarfóòbarfoo"); } - (void) testReplaceOccurrencesOfStringWithStringOptionsRangeThrowsWithOutOfRangeRange { OTAssertThrowsSpecific( [_mutableString replaceOccurrencesOfString: @"t" withString: @"abc" options: 0 range: OFMakeRange(4, 2)], OFOutOfRangeException); OTAssertThrowsSpecific( [_mutableString replaceOccurrencesOfString: @"t" withString: @"abc" options: 0 range: OFMakeRange(5, 1)], OFOutOfRangeException); OTAssertThrowsSpecific( [_mutableString replaceOccurrencesOfString: @"t" withString: @"" options: 0 range: OFMakeRange(6, 0)], OFOutOfRangeException); } - (void)deleteLeadingWhitespaces { OFMutableString *string; string = [self.stringClass stringWithString: whitespace[0]]; [string deleteLeadingWhitespaces]; OTAssertEqualObjects(string, @"asd \t \t\t\r\n"); string = [self.stringClass stringWithString: whitespace[1]]; [string deleteLeadingWhitespaces]; OTAssertEqualObjects(string, @""); } - (void)deleteTrailingWhitespaces { OFMutableString *string; string = [self.stringClass stringWithString: whitespace[0]]; [string deleteTrailingWhitespaces]; OTAssertEqualObjects(string, @" \r \t\n\t \tasd"); string = [self.stringClass stringWithString: whitespace[1]]; [string deleteTrailingWhitespaces]; OTAssertEqualObjects(string, @""); } - (void)deleteEnclosingWhitespaces { OFMutableString *string; string = [self.stringClass stringWithString: whitespace[0]]; [string deleteEnclosingWhitespaces]; OTAssertEqualObjects(string, @"asd"); string = [self.stringClass stringWithString: whitespace[1]]; [string deleteEnclosingWhitespaces]; OTAssertEqualObjects(string, @""); } @end @implementation CustomMutableString - (instancetype)init { self = [super init]; @try { _string = [[OFMutableString alloc] init]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithString: (OFString *)string { self = [super init]; @try { _string = [string mutableCopy]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)length { self = [super init]; @try { _string = [[OFMutableString alloc] initWithCString: cString encoding: encoding length: length]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithUTF16String: (const OFChar16 *)UTF16String length: (size_t)length byteOrder: (OFByteOrder)byteOrder { self = [super init]; @try { _string = [[OFMutableString alloc] initWithUTF16String: UTF16String length: length byteOrder: byteOrder]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithUTF32String: (const OFChar32 *)UTF32String length: (size_t)length byteOrder: (OFByteOrder)byteOrder { self = [super init]; @try { _string = [[OFMutableString alloc] initWithUTF32String: UTF32String length: length byteOrder: byteOrder]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithFormat: (OFConstantString *)format arguments: (va_list)arguments { self = [super init]; @try { _string = [[OFMutableString alloc] initWithFormat: format arguments: arguments]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_string release]; [super dealloc]; } - (OFUnichar)characterAtIndex: (size_t)idx { return [_string characterAtIndex: idx]; } - (size_t)length { return _string.length; } - (void)replaceCharactersInRange: (OFRange)range withString: (OFString *)string { [_string replaceCharactersInRange: range withString: string]; } @end objfw-1.1.6/tests/OFMutableUTF8StringTests.m000066400000000000000000000017371465614216400206660ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFMutableStringTests.h" #import "OFMutableUTF8String.h" @interface OFMutableUTF8StringTests: OFMutableStringTests @end @implementation OFMutableUTF8StringTests - (Class)arrayClass { return [OFMutableUTF8String class]; } @end objfw-1.1.6/tests/OFNotificationCenterTests.m000066400000000000000000000120761465614216400212240ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" static const OFNotificationName notificationName = @"OFNotificationCenterTestName"; static const OFNotificationName otherNotificationName = @"OFNotificationCenterTestOtherName"; @interface OFNotificationCenterTests: OTTestCase @end @interface OFNotificationCenterTestClass: OFObject { @public id _expectedObject; int _received; } - (void)handleNotification: (OFNotification *)notification; @end @implementation OFNotificationCenterTestClass - (void)handleNotification: (OFNotification *)notification { OFEnsure([notification.name isEqual: notificationName]); OFEnsure(_expectedObject == nil || notification.object == _expectedObject); _received++; } @end @implementation OFNotificationCenterTests - (void)testNotificationCenter { OFNotificationCenter *center = [OFNotificationCenter defaultCenter]; OFNotificationCenterTestClass *test1, *test2, *test3, *test4; OFNotification *notification; test1 = [[[OFNotificationCenterTestClass alloc] init] autorelease]; test1->_expectedObject = self; test2 = [[[OFNotificationCenterTestClass alloc] init] autorelease]; test3 = [[[OFNotificationCenterTestClass alloc] init] autorelease]; test3->_expectedObject = self; test4 = [[[OFNotificationCenterTestClass alloc] init] autorelease]; /* First one intentionally added twice to test deduplication. */ [center addObserver: test1 selector: @selector(handleNotification:) name: notificationName object: self]; [center addObserver: test1 selector: @selector(handleNotification:) name: notificationName object: self]; [center addObserver: test2 selector: @selector(handleNotification:) name: notificationName object: nil]; [center addObserver: test3 selector: @selector(handleNotification:) name: otherNotificationName object: self]; [center addObserver: test4 selector: @selector(handleNotification:) name: otherNotificationName object: nil]; notification = [OFNotification notificationWithName: notificationName object: nil]; [center postNotification: notification]; OTAssertEqual(test1->_received, 0); OTAssertEqual(test2->_received, 1); OTAssertEqual(test3->_received, 0); OTAssertEqual(test4->_received, 0); notification = [OFNotification notificationWithName: notificationName object: self]; [center postNotification: notification]; OTAssertEqual(test1->_received, 1); OTAssertEqual(test2->_received, 2); OTAssertEqual(test3->_received, 0); OTAssertEqual(test4->_received, 0); notification = [OFNotification notificationWithName: notificationName object: @"foo"]; [center postNotification: notification]; OTAssertEqual(test1->_received, 1); OTAssertEqual(test2->_received, 3); OTAssertEqual(test3->_received, 0); OTAssertEqual(test4->_received, 0); #ifdef OF_HAVE_BLOCKS __block bool received = false; id handle; notification = [OFNotification notificationWithName: notificationName object: self]; handle = [center addObserverForName: notificationName object: self usingBlock: ^ (OFNotification *notification_) { OTAssertEqual(notification_, notification); OTAssertFalse(received); received = true; }]; [center postNotification: notification]; OTAssertTrue(received); OTAssertEqual(test1->_received, 2); OTAssertEqual(test2->_received, 4); OTAssertEqual(test3->_received, 0); OTAssertEqual(test4->_received, 0); /* Act like the block test didn't happen. */ [center removeObserver: handle]; test1->_received--; test2->_received--; #endif [center removeObserver: test1 selector: @selector(handleNotification:) name: notificationName object: self]; [center removeObserver: test2 selector: @selector(handleNotification:) name: notificationName object: nil]; [center removeObserver: test3 selector: @selector(handleNotification:) name: otherNotificationName object: self]; [center removeObserver: test4 selector: @selector(handleNotification:) name: otherNotificationName object: nil]; notification = [OFNotification notificationWithName: notificationName object: self]; [center postNotification: notification]; OTAssertEqual(test1->_received, 1); OTAssertEqual(test2->_received, 3); OTAssertEqual(test3->_received, 0); OTAssertEqual(test4->_received, 0); } @end objfw-1.1.6/tests/OFNumberTests.m000066400000000000000000000060771465614216400166710ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" @interface OFNumberTests: OTTestCase { OFNumber *_number; } @end @implementation OFNumberTests - (void)setUp { [super setUp]; _number = [[OFNumber alloc] initWithLongLong: 123456789]; } - (void)dealloc { [_number release]; [super dealloc]; } - (void)testIsEqual { OTAssertEqualObjects(_number, [OFNumber numberWithLong: 123456789]); } - (void)testHash { OTAssertEqual(_number.hash, [[OFNumber numberWithLong: 123456789] hash]); } - (void)testCharValue { OTAssertEqual(_number.charValue, 21); } - (void)testDoubleValue { OTAssertEqual(_number.doubleValue, 123456789.L); } - (void)testSignedCharMinAndMaxUnmodified { OTAssertEqual([[OFNumber numberWithChar: SCHAR_MIN] charValue], SCHAR_MIN); OTAssertEqual([[OFNumber numberWithChar: SCHAR_MAX] charValue], SCHAR_MAX); } - (void)testShortMinAndMaxUnmodified { OTAssertEqual([[OFNumber numberWithShort: SHRT_MIN] shortValue], SHRT_MIN); OTAssertEqual([[OFNumber numberWithShort: SHRT_MAX] shortValue], SHRT_MAX); } - (void)testIntMinAndMaxUnmodified { OTAssertEqual([[OFNumber numberWithInt: INT_MIN] intValue], INT_MIN); OTAssertEqual([[OFNumber numberWithInt: INT_MAX] intValue], INT_MAX); } - (void)testLongMinAndMaxUnmodified { OTAssertEqual([[OFNumber numberWithLong: LONG_MIN] longValue], LONG_MIN); OTAssertEqual([[OFNumber numberWithLong: LONG_MAX] longValue], LONG_MAX);; } - (void)testLongLongMinAndMaxUnmodified { OTAssertEqual([[OFNumber numberWithLongLong: LLONG_MIN] longLongValue], LLONG_MIN); OTAssertEqual([[OFNumber numberWithLongLong: LLONG_MAX] longLongValue], LLONG_MAX); } - (void)testUnsignedCharMaxUnmodified { OTAssertEqual([[OFNumber numberWithUnsignedChar: UCHAR_MAX] unsignedCharValue], UCHAR_MAX); } - (void)testUnsignedShortMaxUnmodified { OTAssertEqual([[OFNumber numberWithUnsignedShort: USHRT_MAX] unsignedShortValue], USHRT_MAX); } - (void)testUnsignedIntMaxUnmodified { OTAssertEqual([[OFNumber numberWithUnsignedInt: UINT_MAX] unsignedIntValue], UINT_MAX); } - (void)testUnsignedLongMaxUnmodified { OTAssertEqual([[OFNumber numberWithUnsignedLong: ULONG_MAX] unsignedLongValue], ULONG_MAX); } - (void)testUnsignedLongLongMaxUnmodified { OTAssertEqual([[OFNumber numberWithUnsignedLongLong: ULLONG_MAX] unsignedLongLongValue], ULLONG_MAX); } @end objfw-1.1.6/tests/OFObjectTests.m000066400000000000000000000206671465614216400166500ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" @interface MyObject: OFObject { id _objectValue; Class _classValue; bool _boolValue; char _charValue; short _shortValue; int _intValue; long _longValue; long long _longLongValue; unsigned char _unsignedCharValue; unsigned short _unsignedShortValue; unsigned int _unsignedIntValue; unsigned long _unsignedLongValue; unsigned long long _unsignedLongLongValue; float _floatValue; double _doubleValue; } @property (nonatomic, retain) id objectValue; @property (nonatomic) Class classValue; @property (nonatomic, getter=isBoolValue) bool boolValue; @property (nonatomic) char charValue; @property (nonatomic) short shortValue; @property (nonatomic) int intValue; @property (nonatomic) long longValue; @property (nonatomic) long long longLongValue; @property (nonatomic) unsigned char unsignedCharValue; @property (nonatomic) unsigned short unsignedShortValue; @property (nonatomic) unsigned int unsignedIntValue; @property (nonatomic) unsigned long unsignedLongValue; @property (nonatomic) unsigned long long unsignedLongLongValue; @property (nonatomic) float floatValue; @property (nonatomic) double doubleValue; @end @interface OFObjectTests: OTTestCase { MyObject *_myObject; } @end @implementation OFObjectTests - (void)setUp { [super setUp]; _myObject = [[MyObject alloc] init]; } - (void)dealloc { [_myObject release]; [super dealloc]; } - (void)testClassDescription { OTAssertEqualObjects([OFObject description], @"OFObject"); OTAssertEqualObjects([MyObject description], @"MyObject"); } - (void)testInstanceDescription { OFObject *object = [[[OFObject alloc] init] autorelease]; OTAssertEqualObjects(object.description, @""); OTAssertEqualObjects(_myObject.description, @""); } - (void)testValueForKey { _myObject.objectValue = @"Hello"; _myObject.classValue = _myObject.class; OTAssertEqualObjects([_myObject valueForKey: @"objectValue"], @"Hello"); OTAssertEqualObjects([_myObject valueForKey: @"classValue"], _myObject.class); OTAssertEqualObjects([_myObject valueForKey: @"class"], _myObject.class); } - (void)testValueForKeyWithUndefinedKeyThrows { OTAssertThrowsSpecific([_myObject valueForKey: @"undefined"], OFUndefinedKeyException); } - (void)testSetValueForKey { [_myObject setValue: @"World" forKey: @"objectValue"]; [_myObject setValue: [OFObject class] forKey: @"classValue"]; OTAssertEqualObjects(_myObject.objectValue, @"World"); OTAssertEqualObjects(_myObject.classValue, [OFObject class]); } - (void)testSetValueWithUndefinedKeyThrows { OTAssertThrowsSpecific([_myObject setValue: @"x" forKey: @"undefined"], OFUndefinedKeyException); } - (void)testAutoWrappingOfValueForKey { _myObject.boolValue = 1; _myObject.charValue = 2; _myObject.shortValue = 3; _myObject.intValue = 4; _myObject.longValue = 5; _myObject.longLongValue = 6; _myObject.unsignedCharValue = 7; _myObject.unsignedShortValue = 8; _myObject.unsignedIntValue = 9; _myObject.unsignedLongValue = 10; _myObject.unsignedLongLongValue = 11; _myObject.floatValue = 12; _myObject.doubleValue = 13; OTAssertEqualObjects([_myObject valueForKey: @"boolValue"], [OFNumber numberWithBool: 1]); OTAssertEqualObjects([_myObject valueForKey: @"charValue"], [OFNumber numberWithChar: 2]); OTAssertEqualObjects([_myObject valueForKey: @"shortValue"], [OFNumber numberWithShort: 3]); OTAssertEqualObjects([_myObject valueForKey: @"intValue"], [OFNumber numberWithInt: 4]); OTAssertEqualObjects([_myObject valueForKey: @"longValue"], [OFNumber numberWithLong: 5]); OTAssertEqualObjects([_myObject valueForKey: @"longLongValue"], [OFNumber numberWithLongLong: 6]); OTAssertEqualObjects([_myObject valueForKey: @"unsignedCharValue"], [OFNumber numberWithUnsignedChar: 7]); OTAssertEqualObjects([_myObject valueForKey: @"unsignedShortValue"], [OFNumber numberWithUnsignedShort: 8]); OTAssertEqualObjects([_myObject valueForKey: @"unsignedIntValue"], [OFNumber numberWithUnsignedInt: 9]); OTAssertEqualObjects([_myObject valueForKey: @"unsignedLongValue"], [OFNumber numberWithUnsignedLong: 10]); OTAssertEqualObjects([_myObject valueForKey: @"unsignedLongLongValue"], [OFNumber numberWithUnsignedLongLong: 11]); OTAssertEqualObjects([_myObject valueForKey: @"floatValue"], [OFNumber numberWithFloat: 12]); OTAssertEqualObjects([_myObject valueForKey: @"doubleValue"], [OFNumber numberWithDouble: 13]); } - (void)testAutoWrappingOfSetValueForKey { [_myObject setValue: [OFNumber numberWithBool: 0] forKey: @"boolValue"]; [_myObject setValue: [OFNumber numberWithChar: 10] forKey: @"charValue"]; [_myObject setValue: [OFNumber numberWithShort: 20] forKey: @"shortValue"]; [_myObject setValue: [OFNumber numberWithInt: 30] forKey: @"intValue"]; [_myObject setValue: [OFNumber numberWithLong: 40] forKey: @"longValue"]; [_myObject setValue: [OFNumber numberWithLongLong: 50] forKey: @"longLongValue"]; [_myObject setValue: [OFNumber numberWithUnsignedChar: 60] forKey: @"unsignedCharValue"]; [_myObject setValue: [OFNumber numberWithUnsignedShort: 70] forKey: @"unsignedShortValue"]; [_myObject setValue: [OFNumber numberWithUnsignedInt: 80] forKey: @"unsignedIntValue"]; [_myObject setValue: [OFNumber numberWithUnsignedLong: 90] forKey: @"unsignedLongValue"]; [_myObject setValue: [OFNumber numberWithUnsignedLongLong: 100] forKey: @"unsignedLongLongValue"]; [_myObject setValue: [OFNumber numberWithFloat: 110] forKey: @"floatValue"]; [_myObject setValue: [OFNumber numberWithDouble: 120] forKey: @"doubleValue"]; OTAssertEqual(_myObject.isBoolValue, 0); OTAssertEqual(_myObject.charValue, 10); OTAssertEqual(_myObject.shortValue, 20); OTAssertEqual(_myObject.intValue, 30); OTAssertEqual(_myObject.longValue, 40); OTAssertEqual(_myObject.longLongValue, 50); OTAssertEqual(_myObject.unsignedCharValue, 60); OTAssertEqual(_myObject.unsignedShortValue, 70); OTAssertEqual(_myObject.unsignedIntValue, 80); OTAssertEqual(_myObject.unsignedLongValue, 90); OTAssertEqual(_myObject.unsignedLongLongValue, 100); OTAssertEqual(_myObject.floatValue, 110); OTAssertEqual(_myObject.doubleValue, 120); } - (void)testSetValueForKeyWithNilThrows { OTAssertThrowsSpecific( [_myObject setValue: (id _Nonnull)nil forKey: @"intValue"], OFInvalidArgumentException); } - (void)testValueForKeyPath { _myObject.objectValue = [[[MyObject alloc] init] autorelease]; [_myObject.objectValue setObjectValue: [[[MyObject alloc] init] autorelease]]; [[_myObject.objectValue objectValue] setDoubleValue: 0.5]; OTAssertEqual([[_myObject valueForKeyPath: @"objectValue.objectValue.doubleValue"] doubleValue], 0.5); } - (void)testSetValueForKeyPath { _myObject.objectValue = [[[MyObject alloc] init] autorelease]; [_myObject.objectValue setObjectValue: [[[MyObject alloc] init] autorelease]]; [_myObject setValue: [OFNumber numberWithDouble: 0.75] forKeyPath: @"objectValue.objectValue.doubleValue"]; OTAssertEqual([[_myObject.objectValue objectValue] doubleValue], 0.75); } @end @implementation MyObject @synthesize objectValue = _objectValue, classValue = _classValue; @synthesize boolValue = _boolValue, charValue = _charValue; @synthesize shortValue = _shortValue, intValue = _intValue; @synthesize longValue = _longValue, longLongValue = _longLongValue; @synthesize unsignedCharValue = _unsignedCharValue; @synthesize unsignedShortValue = _unsignedShortValue; @synthesize unsignedIntValue = _unsignedIntValue; @synthesize unsignedLongValue = _unsignedLongValue; @synthesize unsignedLongLongValue = _unsignedLongLongValue; @synthesize floatValue = _floatValue, doubleValue = _doubleValue; - (void)dealloc { [_objectValue release]; [super dealloc]; } @end objfw-1.1.6/tests/OFPBKDF2Tests.m000066400000000000000000000106421465614216400163420ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "ObjFW.h" #import "ObjFWTest.h" @interface OFPBKDF2Tests: OTTestCase { OFHMAC *_HMAC; } @end @implementation OFPBKDF2Tests - (void)setUp { [super setUp]; _HMAC = [[OFHMAC alloc] initWithHashClass: [OFSHA1Hash class] allowsSwappableMemory: true]; } - (void)dealloc { [_HMAC release]; [super dealloc]; } /* Test vectors from RFC 6070 */ - (void)testRFC6070TestVector1 { unsigned char key[20]; OFPBKDF2((OFPBKDF2Parameters){ .HMAC = _HMAC, .iterations = 1, .salt = (unsigned char *)"salt", .saltLength = 4, .password = "password", .passwordLength = 8, .key = key, .keyLength = 20, .allowsSwappableMemory = true }); OTAssertEqual(memcmp(key, "\x0C\x60\xC8\x0F\x96\x1F\x0E\x71\xF3\xA9\xB5" "\x24\xAF\x60\x12\x06\x2F\xE0\x37\xA6", 20), 0); } - (void)testRFC6070TestVector2 { unsigned char key[20]; OFPBKDF2((OFPBKDF2Parameters){ .HMAC = _HMAC, .iterations = 2, .salt = (unsigned char *)"salt", .saltLength = 4, .password = "password", .passwordLength = 8, .key = key, .keyLength = 20, .allowsSwappableMemory = true }); OTAssertEqual(memcmp(key, "\xEA\x6C\x01\x4D\xC7\x2D\x6F\x8C\xCD\x1E\xD9" "\x2A\xCE\x1D\x41\xF0\xD8\xDE\x89\x57", 20), 0); } - (void)testRFC6070TestVector3 { unsigned char key[20]; OFPBKDF2((OFPBKDF2Parameters){ .HMAC = _HMAC, .iterations = 4096, .salt = (unsigned char *)"salt", .saltLength = 4, .password = "password", .passwordLength = 8, .key = key, .keyLength = 20, .allowsSwappableMemory = true }); OTAssertEqual(memcmp(key, "\x4B\x00\x79\x01\xB7\x65\x48\x9A\xBE\xAD\x49" "\xD9\x26\xF7\x21\xD0\x65\xA4\x29\xC1", 20), 0); } #if 0 /* This test takes too long, even on a fast machine. */ - (void)testRFC6070TestVector4 { unsigned char key[20]; OFPBKDF2((OFPBKDF2Parameters){ .HMAC = _HMAC, .iterations = 16777216, .salt = (unsigned char *)"salt", .saltLength = 4, .password = "password", .passwordLength = 8, .key = key, .keyLength = 20, .allowsSwappableMemory = true }); OTAssertEqual(memcmp(key, "\xEE\xFE\x3D\x61\xCD\x4D\xA4\xE4\xE9\x94\x5B" "\x3D\x6B\xA2\x15\x8C\x26\x34\xE9\x84", 20), 0); } #endif - (void)testRFC6070TestVector5 { unsigned char key[25]; OFPBKDF2((OFPBKDF2Parameters){ .HMAC = _HMAC, .iterations = 4096, .salt = (unsigned char *)"saltSALTsaltSALTsalt" "SALTsaltSALTsalt", .saltLength = 36, .password = "passwordPASSWORDpassword", .passwordLength = 24, .key = key, .keyLength = 25, .allowsSwappableMemory = true }); OTAssertEqual(memcmp(key, "\x3D\x2E\xEC\x4F\xE4\x1C\x84\x9B\x80\xC8\xD8" "\x36\x62\xC0\xE4\x4A\x8B\x29\x1A\x96\x4C\xF2\xF0\x70\x38", 25), 0); } - (void)testRFC6070TestVector6 { unsigned char key[16]; OFPBKDF2((OFPBKDF2Parameters){ .HMAC = _HMAC, .iterations = 4096, .salt = (unsigned char *)"sa\0lt", .saltLength = 5, .password = "pass\0word", .passwordLength = 9, .key = key, .keyLength = 16, .allowsSwappableMemory = true }); OTAssertEqual(memcmp(key, "\x56\xFA\x6A\xA7\x55\x48\x09\x9D\xCC\x37\xD7" "\xF0\x34\x25\xE0\xC3", 16), 0); } @end objfw-1.1.6/tests/OFPluginTests.m000066400000000000000000000026641465614216400166750ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" #import "plugin/TestPlugin.h" @interface OFPluginTests: OTTestCase @end @implementation OFPluginTests - (void)testPlugin { TestPlugin *test = nil; OFString *path; OFPlugin *plugin; Class (*class)(void); #ifndef OF_IOS path = [OFPlugin pathForName: @"plugin/TestPlugin"]; #else path = [OFPlugin pathForName: @"PlugIns/TestPlugin"]; #endif OTAssertNotNil(path); plugin = [OFPlugin pluginWithPath: path]; OTAssertNotNil(plugin); class = (Class (*)(void))(uintptr_t)[plugin addressForSymbol: @"class"]; OTAssert(class != NULL); @try { test = [[class() alloc] init]; OTAssertEqual([test test: 1234], 2468); } @finally { [test release]; } } @end objfw-1.1.6/tests/OFPropertyListTests.m000066400000000000000000000065071465614216400201170ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" @interface OFPropertyListTests: OTTestCase @end #define PLIST(x) \ @"" \ @"" \ @"\n" \ x @"\n" \ @"" @implementation OFPropertyListTests - (void)testObjectByParsingPropertyList { OFArray *array = [OFArray arrayWithObjects: @"Hello", [OFData dataWithItems: "World!" count: 6], [OFDate dateWithTimeIntervalSince1970: 1521030896], [OFNumber numberWithBool: true], [OFNumber numberWithBool: false], [OFNumber numberWithFloat: 12.25f], [OFNumber numberWithInt: -10], nil]; OTAssertEqualObjects([PLIST( @"Hello") objectByParsingPropertyList], @"Hello"); OTAssertEqualObjects([PLIST( @"" @" Hello" @" V29ybGQh" @" 2018-03-14T12:34:56Z" @" " @" " @" 12.25" @" -10" @"") objectByParsingPropertyList], array); OTAssertEqualObjects([PLIST( @"" @" array" @" " @" Hello" @" V29ybGQh" @" 2018-03-14T12:34:56Z" @" " @" " @" 12.25" @" -10" @" " @" foo" @" bar" @"") objectByParsingPropertyList], ([OFDictionary dictionaryWithKeysAndObjects: @"array", array, @"foo", @"bar", nil])); } - (void)testDetectUnsupportedVersion { OTAssertThrowsSpecific( [[PLIST(@"") stringByReplacingOccurrencesOfString: @"1.0" withString: @"1.1"] objectByParsingPropertyList], OFUnsupportedVersionException); } - (void)testDetectInvalidFormat { OTAssertThrowsSpecific( [PLIST(@"") objectByParsingPropertyList], OFInvalidFormatException); OTAssertThrowsSpecific( [PLIST(@"") objectByParsingPropertyList], OFInvalidFormatException); OTAssertThrowsSpecific( [PLIST(@"") objectByParsingPropertyList], OFInvalidFormatException); OTAssertThrowsSpecific( [PLIST(@"") objectByParsingPropertyList], OFInvalidFormatException); OTAssertThrowsSpecific( [PLIST(@"") objectByParsingPropertyList], OFInvalidFormatException); } @end objfw-1.1.6/tests/OFSPXSocketTests.m000066400000000000000000000140111465614216400172470ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "ObjFW.h" #import "ObjFWTest.h" @interface OFSPXSocketTests: OTTestCase { OFSPXSocket *_sockServer; OFSocketAddress _addrServer; } @end @interface SPXSocketDelegate: OFObject { @public OFSequencedPacketSocket *_expectedServerSocket; OFSPXSocket *_expectedClientSocket; unsigned char _expectedNode[IPX_NODE_LEN]; uint32_t _expectedNetwork; uint16_t _expectedPort; bool _accepted; bool _connected; } @end @implementation OFSPXSocketTests - (void)setUp { const unsigned char zeroNode[IPX_NODE_LEN] = { 0 }; _sockServer = [[OFSPXSocket alloc] init]; @try { _addrServer = [_sockServer bindToNetwork: 0 node: zeroNode port: 0]; } @catch (OFBindSocketFailedException *e) { switch (e.errNo) { case EAFNOSUPPORT: OTSkip(@"IPX unsupported"); case ESOCKTNOSUPPORT: OTSkip(@"SPX unsupported"); case EADDRNOTAVAIL: OTSkip(@"IPX not configured"); default: @throw e; } } } - (void)dealloc { [_sockServer release]; [super dealloc]; } - (void)testSPXSocket { OFSPXSocket *sockClient, *sockAccepted; const OFSocketAddress *addrAccepted; uint32_t network; unsigned char node[IPX_NODE_LEN], node2[IPX_NODE_LEN]; uint16_t port; OFDictionary *networkInterfaces; char buffer[5]; sockClient = [OFSPXSocket socket]; network = OFSocketAddressIPXNetwork(&_addrServer); OFSocketAddressGetIPXNode(&_addrServer, node); port = OFSocketAddressIPXPort(&_addrServer); [_sockServer listen]; /* * Find any network interface with IPX and send to it. Any should be * fine since we bound to 0.0. */ networkInterfaces = [OFSystemInfo networkInterfaces]; for (OFString *name in networkInterfaces) { OFNetworkInterface interface = [networkInterfaces objectForKey: name]; OFData *addresses = [interface objectForKey: OFNetworkInterfaceIPXAddresses]; if (addresses.count == 0) continue; network = OFSocketAddressIPXNetwork([addresses itemAtIndex: 0]); OFSocketAddressGetIPXNode([addresses itemAtIndex: 0], node); } [sockClient connectToNetwork: network node: node port: port]; sockAccepted = [_sockServer accept]; [sockAccepted sendBuffer: "Hello" length: 5]; OTAssertEqual([sockClient receiveIntoBuffer: buffer length: 5], 5); OTAssertEqual(memcmp(buffer, "Hello", 5), 0); addrAccepted = sockAccepted.remoteAddress; OFSocketAddressGetIPXNode(addrAccepted, node2); OTAssertEqual(memcmp(node, node2, IPX_NODE_LEN), 0); } - (void)testAsyncSPXSocket { SPXSocketDelegate *delegate = [[[SPXSocketDelegate alloc] init] autorelease]; uint32_t network; unsigned char node[IPX_NODE_LEN]; uint16_t port; OFDictionary *networkInterfaces; OFSPXSocket *sockClient; delegate->_expectedServerSocket = _sockServer; _sockServer.delegate = delegate; sockClient = [OFSPXSocket socket]; delegate->_expectedClientSocket = sockClient; sockClient.delegate = delegate; [_sockServer listen]; [_sockServer asyncAccept]; network = OFSocketAddressIPXNetwork(&_addrServer); OFSocketAddressGetIPXNode(&_addrServer, node); port = OFSocketAddressIPXPort(&_addrServer); /* * Find any network interface with IPX and send to it. Any should be * fine since we bound to 0.0. */ networkInterfaces = [OFSystemInfo networkInterfaces]; for (OFString *name in networkInterfaces) { OFNetworkInterface interface = [networkInterfaces objectForKey: name]; OFData *addresses = [interface objectForKey: OFNetworkInterfaceIPXAddresses]; if (addresses.count == 0) continue; network = OFSocketAddressIPXNetwork([addresses itemAtIndex: 0]); OFSocketAddressGetIPXNode([addresses itemAtIndex: 0], node); } delegate->_expectedNetwork = network = OFSocketAddressIPXNetwork(&_addrServer); OFSocketAddressGetIPXNode(&_addrServer, node); memcpy(delegate->_expectedNode, node, IPX_NODE_LEN); delegate->_expectedPort = port = OFSocketAddressIPXPort(&_addrServer); @try { [sockClient asyncConnectToNetwork: network node: node port: port]; [[OFRunLoop mainRunLoop] runUntilDate: [OFDate dateWithTimeIntervalSinceNow: 2]]; OTAssertTrue(delegate->_accepted); OTAssertTrue(delegate->_connected); } @catch (OFObserveKernelEventsFailedException *e) { /* * Make sure it doesn't stay in the run loop and throws again * next time we run the run loop. */ [sockClient cancelAsyncRequests]; [_sockServer cancelAsyncRequests]; switch (e.errNo) { case ENOTSOCK: OTSkip(@"select() not supported for SPX"); default: @throw e; } } } @end @implementation SPXSocketDelegate - (bool)socket: (OFSequencedPacketSocket *)sock didAcceptSocket: (OFSequencedPacketSocket *)accepted exception: (id)exception { OFEnsure(!_accepted); _accepted = (sock == _expectedServerSocket && accepted != nil && exception == nil); if (_accepted && _connected) [[OFRunLoop mainRunLoop] stop]; return false; } - (void)socket: (OFSPXSocket *)sock didConnectToNetwork: (uint32_t)network node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port exception: (id)exception { OFEnsure(!_connected); _connected = (sock == _expectedClientSocket && network == _expectedNetwork && memcmp(node, _expectedNode, IPX_NODE_LEN) == 0 && port == _expectedPort && exception == nil); if (_accepted && _connected) [[OFRunLoop mainRunLoop] stop]; } @end objfw-1.1.6/tests/OFSPXStreamSocketTests.m000066400000000000000000000143561465614216400204370ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "ObjFW.h" #import "ObjFWTest.h" @interface OFSPXStreamSocketTests: OTTestCase { OFSPXStreamSocket *_sockServer; OFSocketAddress _addrServer; } @end @interface SPXStreamSocketDelegate: OFObject { @public OFStreamSocket *_expectedServerSocket; OFSPXStreamSocket *_expectedClientSocket; uint32_t _expectedNetwork; unsigned char _expectedNode[IPX_NODE_LEN]; uint16_t _expectedPort; bool _accepted; bool _connected; } @end @implementation OFSPXStreamSocketTests - (void)setUp { const unsigned char zeroNode[IPX_NODE_LEN] = { 0 }; _sockServer = [[OFSPXStreamSocket alloc] init]; @try { _addrServer = [_sockServer bindToNetwork: 0 node: zeroNode port: 0]; } @catch (OFBindSocketFailedException *e) { switch (e.errNo) { case EAFNOSUPPORT: OTSkip(@"IPX unsupported"); case ESOCKTNOSUPPORT: case EPROTONOSUPPORT: OTSkip(@"SPX unsupported"); case EADDRNOTAVAIL: OTSkip(@"IPX not configured"); default: @throw e; } } } - (void)dealloc { [_sockServer release]; [super dealloc]; } - (void)testSPXStreamSocket { OFSPXStreamSocket *sockClient, *sockAccepted; const OFSocketAddress *addrAccepted; uint32_t network; unsigned char node[IPX_NODE_LEN], node2[IPX_NODE_LEN]; uint16_t port; OFDictionary *networkInterfaces; char buffer[5]; sockClient = [OFSPXStreamSocket socket]; network = OFSocketAddressIPXNetwork(&_addrServer); OFSocketAddressGetIPXNode(&_addrServer, node); port = OFSocketAddressIPXPort(&_addrServer); [_sockServer listen]; /* * Find any network interface with IPX and send to it. Any should be * fine since we bound to 0.0. */ networkInterfaces = [OFSystemInfo networkInterfaces]; for (OFString *name in networkInterfaces) { OFNetworkInterface interface = [networkInterfaces objectForKey: name]; OFData *addresses = [interface objectForKey: OFNetworkInterfaceIPXAddresses]; if (addresses.count == 0) continue; network = OFSocketAddressIPXNetwork([addresses itemAtIndex: 0]); OFSocketAddressGetIPXNode([addresses itemAtIndex: 0], node); } [sockClient connectToNetwork: network node: node port: port]; sockAccepted = [_sockServer accept]; [sockAccepted writeBuffer: "Hello" length: 5]; /* Test reassembly (this would not work with OFSPXSocket) */ OTAssertEqual([sockClient readIntoBuffer: buffer length: 2], 2); OTAssertEqual([sockClient readIntoBuffer: buffer + 2 length: 3], 3); OTAssertEqual(memcmp(buffer, "Hello", 5), 0); addrAccepted = sockAccepted.remoteAddress; OFSocketAddressGetIPXNode(addrAccepted, node2); OTAssertEqual(memcmp(node, node2, IPX_NODE_LEN), 0); } - (void)testAsyncSPXStreamSocket { SPXStreamSocketDelegate *delegate = [[[SPXStreamSocketDelegate alloc] init] autorelease]; uint32_t network; unsigned char node[IPX_NODE_LEN]; uint16_t port; OFDictionary *networkInterfaces; OFSPXStreamSocket *sockClient; delegate->_expectedServerSocket = _sockServer; _sockServer.delegate = delegate; sockClient = [OFSPXStreamSocket socket]; delegate->_expectedClientSocket = sockClient; sockClient.delegate = delegate; [_sockServer listen]; [_sockServer asyncAccept]; network = OFSocketAddressIPXNetwork(&_addrServer); OFSocketAddressGetIPXNode(&_addrServer, node); port = OFSocketAddressIPXPort(&_addrServer); /* * Find any network interface with IPX and send to it. Any should be * fine since we bound to 0.0. */ networkInterfaces = [OFSystemInfo networkInterfaces]; for (OFString *name in networkInterfaces) { OFNetworkInterface interface = [networkInterfaces objectForKey: name]; OFData *addresses = [interface objectForKey: OFNetworkInterfaceIPXAddresses]; if (addresses.count == 0) continue; network = OFSocketAddressIPXNetwork([addresses itemAtIndex: 0]); OFSocketAddressGetIPXNode([addresses itemAtIndex: 0], node); } delegate->_expectedNetwork = network = OFSocketAddressIPXNetwork(&_addrServer); OFSocketAddressGetIPXNode(&_addrServer, node); memcpy(delegate->_expectedNode, node, IPX_NODE_LEN); delegate->_expectedPort = port = OFSocketAddressIPXPort(&_addrServer); @try { [sockClient asyncConnectToNetwork: network node: node port: port]; [[OFRunLoop mainRunLoop] runUntilDate: [OFDate dateWithTimeIntervalSinceNow: 2]]; OTAssertTrue(delegate->_accepted); OTAssertTrue(delegate->_connected); } @catch (OFObserveKernelEventsFailedException *e) { /* * Make sure it doesn't stay in the run loop and throws again * next time we run the run loop. */ [sockClient cancelAsyncRequests]; [_sockServer cancelAsyncRequests]; switch (e.errNo) { case ENOTSOCK: OTSkip(@"select() not supported for SPX"); default: @throw e; } } } @end @implementation SPXStreamSocketDelegate - (bool)socket: (OFStreamSocket *)sock didAcceptSocket: (OFStreamSocket *)accepted exception: (id)exception { OFEnsure(!_accepted); _accepted = (sock == _expectedServerSocket && accepted != nil && exception == nil); if (_accepted && _connected) [[OFRunLoop mainRunLoop] stop]; return false; } - (void)socket: (OFSPXStreamSocket *)sock didConnectToNetwork: (uint32_t)network node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port exception: (id)exception { OFEnsure(!_connected); _connected = (sock == _expectedClientSocket && network == _expectedNetwork && memcmp(node, _expectedNode, IPX_NODE_LEN) == 0 && port == _expectedPort && exception == nil); if (_accepted && _connected) [[OFRunLoop mainRunLoop] stop]; } @end objfw-1.1.6/tests/OFScryptTests.m000066400000000000000000000240341465614216400167160ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "ObjFW.h" #import "ObjFWTest.h" @interface OFScryptTests: OTTestCase @end /* Test vectors form RFC 7914 */ static const unsigned char salsa20Input[64] = { 0x7E, 0x87, 0x9A, 0x21, 0x4F, 0x3E, 0xC9, 0x86, 0x7C, 0xA9, 0x40, 0xE6, 0x41, 0x71, 0x8F, 0x26, 0xBA, 0xEE, 0x55, 0x5B, 0x8C, 0x61, 0xC1, 0xB5, 0x0D, 0xF8, 0x46, 0x11, 0x6D, 0xCD, 0x3B, 0x1D, 0xEE, 0x24, 0xF3, 0x19, 0xDF, 0x9B, 0x3D, 0x85, 0x14, 0x12, 0x1E, 0x4B, 0x5A, 0xC5, 0xAA, 0x32, 0x76, 0x02, 0x1D, 0x29, 0x09, 0xC7, 0x48, 0x29, 0xED, 0xEB, 0xC6, 0x8D, 0xB8, 0xB8, 0xC2, 0x5E }; static const unsigned char salsa20Output[64] = { 0xA4, 0x1F, 0x85, 0x9C, 0x66, 0x08, 0xCC, 0x99, 0x3B, 0x81, 0xCA, 0xCB, 0x02, 0x0C, 0xEF, 0x05, 0x04, 0x4B, 0x21, 0x81, 0xA2, 0xFD, 0x33, 0x7D, 0xFD, 0x7B, 0x1C, 0x63, 0x96, 0x68, 0x2F, 0x29, 0xB4, 0x39, 0x31, 0x68, 0xE3, 0xC9, 0xE6, 0xBC, 0xFE, 0x6B, 0xC5, 0xB7, 0xA0, 0x6D, 0x96, 0xBA, 0xE4, 0x24, 0xCC, 0x10, 0x2C, 0x91, 0x74, 0x5C, 0x24, 0xAD, 0x67, 0x3D, 0xC7, 0x61, 0x8F, 0x81 }; static const union { unsigned char uc[128]; uint32_t u32[32]; } blockMixInput = { .uc = { 0xF7, 0xCE, 0x0B, 0x65, 0x3D, 0x2D, 0x72, 0xA4, 0x10, 0x8C, 0xF5, 0xAB, 0xE9, 0x12, 0xFF, 0xDD, 0x77, 0x76, 0x16, 0xDB, 0xBB, 0x27, 0xA7, 0x0E, 0x82, 0x04, 0xF3, 0xAE, 0x2D, 0x0F, 0x6F, 0xAD, 0x89, 0xF6, 0x8F, 0x48, 0x11, 0xD1, 0xE8, 0x7B, 0xCC, 0x3B, 0xD7, 0x40, 0x0A, 0x9F, 0xFD, 0x29, 0x09, 0x4F, 0x01, 0x84, 0x63, 0x95, 0x74, 0xF3, 0x9A, 0xE5, 0xA1, 0x31, 0x52, 0x17, 0xBC, 0xD7, 0x89, 0x49, 0x91, 0x44, 0x72, 0x13, 0xBB, 0x22, 0x6C, 0x25, 0xB5, 0x4D, 0xA8, 0x63, 0x70, 0xFB, 0xCD, 0x98, 0x43, 0x80, 0x37, 0x46, 0x66, 0xBB, 0x8F, 0xFC, 0xB5, 0xBF, 0x40, 0xC2, 0x54, 0xB0, 0x67, 0xD2, 0x7C, 0x51, 0xCE, 0x4A, 0xD5, 0xFE, 0xD8, 0x29, 0xC9, 0x0B, 0x50, 0x5A, 0x57, 0x1B, 0x7F, 0x4D, 0x1C, 0xAD, 0x6A, 0x52, 0x3C, 0xDA, 0x77, 0x0E, 0x67, 0xBC, 0xEA, 0xAF, 0x7E, 0x89 }}; static const unsigned char blockMixOutput[128] = { 0xA4, 0x1F, 0x85, 0x9C, 0x66, 0x08, 0xCC, 0x99, 0x3B, 0x81, 0xCA, 0xCB, 0x02, 0x0C, 0xEF, 0x05, 0x04, 0x4B, 0x21, 0x81, 0xA2, 0xFD, 0x33, 0x7D, 0xFD, 0x7B, 0x1C, 0x63, 0x96, 0x68, 0x2F, 0x29, 0xB4, 0x39, 0x31, 0x68, 0xE3, 0xC9, 0xE6, 0xBC, 0xFE, 0x6B, 0xC5, 0xB7, 0xA0, 0x6D, 0x96, 0xBA, 0xE4, 0x24, 0xCC, 0x10, 0x2C, 0x91, 0x74, 0x5C, 0x24, 0xAD, 0x67, 0x3D, 0xC7, 0x61, 0x8F, 0x81, 0x20, 0xED, 0xC9, 0x75, 0x32, 0x38, 0x81, 0xA8, 0x05, 0x40, 0xF6, 0x4C, 0x16, 0x2D, 0xCD, 0x3C, 0x21, 0x07, 0x7C, 0xFE, 0x5F, 0x8D, 0x5F, 0xE2, 0xB1, 0xA4, 0x16, 0x8F, 0x95, 0x36, 0x78, 0xB7, 0x7D, 0x3B, 0x3D, 0x80, 0x3B, 0x60, 0xE4, 0xAB, 0x92, 0x09, 0x96, 0xE5, 0x9B, 0x4D, 0x53, 0xB6, 0x5D, 0x2A, 0x22, 0x58, 0x77, 0xD5, 0xED, 0xF5, 0x84, 0x2C, 0xB9, 0xF1, 0x4E, 0xEF, 0xE4, 0x25 }; static const unsigned char ROMixInput[128] = { 0xF7, 0xCE, 0x0B, 0x65, 0x3D, 0x2D, 0x72, 0xA4, 0x10, 0x8C, 0xF5, 0xAB, 0xE9, 0x12, 0xFF, 0xDD, 0x77, 0x76, 0x16, 0xDB, 0xBB, 0x27, 0xA7, 0x0E, 0x82, 0x04, 0xF3, 0xAE, 0x2D, 0x0F, 0x6F, 0xAD, 0x89, 0xF6, 0x8F, 0x48, 0x11, 0xD1, 0xE8, 0x7B, 0xCC, 0x3B, 0xD7, 0x40, 0x0A, 0x9F, 0xFD, 0x29, 0x09, 0x4F, 0x01, 0x84, 0x63, 0x95, 0x74, 0xF3, 0x9A, 0xE5, 0xA1, 0x31, 0x52, 0x17, 0xBC, 0xD7, 0x89, 0x49, 0x91, 0x44, 0x72, 0x13, 0xBB, 0x22, 0x6C, 0x25, 0xB5, 0x4D, 0xA8, 0x63, 0x70, 0xFB, 0xCD, 0x98, 0x43, 0x80, 0x37, 0x46, 0x66, 0xBB, 0x8F, 0xFC, 0xB5, 0xBF, 0x40, 0xC2, 0x54, 0xB0, 0x67, 0xD2, 0x7C, 0x51, 0xCE, 0x4A, 0xD5, 0xFE, 0xD8, 0x29, 0xC9, 0x0B, 0x50, 0x5A, 0x57, 0x1B, 0x7F, 0x4D, 0x1C, 0xAD, 0x6A, 0x52, 0x3C, 0xDA, 0x77, 0x0E, 0x67, 0xBC, 0xEA, 0xAF, 0x7E, 0x89 }; static const unsigned char ROMixOutput[128] = { 0x79, 0xCC, 0xC1, 0x93, 0x62, 0x9D, 0xEB, 0xCA, 0x04, 0x7F, 0x0B, 0x70, 0x60, 0x4B, 0xF6, 0xB6, 0x2C, 0xE3, 0xDD, 0x4A, 0x96, 0x26, 0xE3, 0x55, 0xFA, 0xFC, 0x61, 0x98, 0xE6, 0xEA, 0x2B, 0x46, 0xD5, 0x84, 0x13, 0x67, 0x3B, 0x99, 0xB0, 0x29, 0xD6, 0x65, 0xC3, 0x57, 0x60, 0x1F, 0xB4, 0x26, 0xA0, 0xB2, 0xF4, 0xBB, 0xA2, 0x00, 0xEE, 0x9F, 0x0A, 0x43, 0xD1, 0x9B, 0x57, 0x1A, 0x9C, 0x71, 0xEF, 0x11, 0x42, 0xE6, 0x5D, 0x5A, 0x26, 0x6F, 0xDD, 0xCA, 0x83, 0x2C, 0xE5, 0x9F, 0xAA, 0x7C, 0xAC, 0x0B, 0x9C, 0xF1, 0xBE, 0x2B, 0xFF, 0xCA, 0x30, 0x0D, 0x01, 0xEE, 0x38, 0x76, 0x19, 0xC4, 0xAE, 0x12, 0xFD, 0x44, 0x38, 0xF2, 0x03, 0xA0, 0xE4, 0xE1, 0xC4, 0x7E, 0xC3, 0x14, 0x86, 0x1F, 0x4E, 0x90, 0x87, 0xCB, 0x33, 0x39, 0x6A, 0x68, 0x73, 0xE8, 0xF9, 0xD2, 0x53, 0x9A, 0x4B, 0x8E }; static const unsigned char testVector1[64] = { 0x77, 0xD6, 0x57, 0x62, 0x38, 0x65, 0x7B, 0x20, 0x3B, 0x19, 0xCA, 0x42, 0xC1, 0x8A, 0x04, 0x97, 0xF1, 0x6B, 0x48, 0x44, 0xE3, 0x07, 0x4A, 0xE8, 0xDF, 0xDF, 0xFA, 0x3F, 0xED, 0xE2, 0x14, 0x42, 0xFC, 0xD0, 0x06, 0x9D, 0xED, 0x09, 0x48, 0xF8, 0x32, 0x6A, 0x75, 0x3A, 0x0F, 0xC8, 0x1F, 0x17, 0xE8, 0xD3, 0xE0, 0xFB, 0x2E, 0x0D, 0x36, 0x28, 0xCF, 0x35, 0xE2, 0x0C, 0x38, 0xD1, 0x89, 0x06 }; /* Nintendo DS does not have enough RAM for the second test vector. */ #ifndef OF_NINTENDO_DS static const unsigned char testVector2[64] = { 0xFD, 0xBA, 0xBE, 0x1C, 0x9D, 0x34, 0x72, 0x00, 0x78, 0x56, 0xE7, 0x19, 0x0D, 0x01, 0xE9, 0xFE, 0x7C, 0x6A, 0xD7, 0xCB, 0xC8, 0x23, 0x78, 0x30, 0xE7, 0x73, 0x76, 0x63, 0x4B, 0x37, 0x31, 0x62, 0x2E, 0xAF, 0x30, 0xD9, 0x2E, 0x22, 0xA3, 0x88, 0x6F, 0xF1, 0x09, 0x27, 0x9D, 0x98, 0x30, 0xDA, 0xC7, 0x27, 0xAF, 0xB9, 0x4A, 0x83, 0xEE, 0x6D, 0x83, 0x60, 0xCB, 0xDF, 0xA2, 0xCC, 0x06, 0x40 }; #endif /* * The third test vector is too expensive for m68k. * Nintendo DS does not have enough RAM for the third test vector. */ #if !defined(OF_M68K) && !defined(OF_NINTENDO_DS) static const unsigned char testVector3[64] = { 0x70, 0x23, 0xBD, 0xCB, 0x3A, 0xFD, 0x73, 0x48, 0x46, 0x1C, 0x06, 0xCD, 0x81, 0xFD, 0x38, 0xEB, 0xFD, 0xA8, 0xFB, 0xBA, 0x90, 0x4F, 0x8E, 0x3E, 0xA9, 0xB5, 0x43, 0xF6, 0x54, 0x5D, 0xA1, 0xF2, 0xD5, 0x43, 0x29, 0x55, 0x61, 0x3F, 0x0F, 0xCF, 0x62, 0xD4, 0x97, 0x05, 0x24, 0x2A, 0x9A, 0xF9, 0xE6, 0x1E, 0x85, 0xDC, 0x0D, 0x65, 0x1E, 0x40, 0xDF, 0xCF, 0x01, 0x7B, 0x45, 0x57, 0x58, 0x87 }; #endif /* The forth test vector is too expensive to include it in the tests. */ #if 0 static const unsigned char testVector4[64] = { 0x21, 0x01, 0xCB, 0x9B, 0x6A, 0x51, 0x1A, 0xAE, 0xAD, 0xDB, 0xBE, 0x09, 0xCF, 0x70, 0xF8, 0x81, 0xEC, 0x56, 0x8D, 0x57, 0x4A, 0x2F, 0xFD, 0x4D, 0xAB, 0xE5, 0xEE, 0x98, 0x20, 0xAD, 0xAA, 0x47, 0x8E, 0x56, 0xFD, 0x8F, 0x4B, 0xA5, 0xD0, 0x9F, 0xFA, 0x1C, 0x6D, 0x92, 0x7C, 0x40, 0xF4, 0xC3, 0x37, 0x30, 0x40, 0x49, 0xE8, 0xA9, 0x52, 0xFB, 0xCB, 0xF4, 0x5C, 0x6F, 0xA7, 0x7A, 0x41, 0xA4 }; #endif @implementation OFScryptTests - (void)testSalsa20_8Core { uint32_t salsa20Buffer[16]; memcpy(salsa20Buffer, salsa20Input, 64); _OFSalsa20_8Core(salsa20Buffer); OTAssertEqual(memcmp(salsa20Buffer, salsa20Output, 64), 0); } - (void)testBlockMix { uint32_t blockMixBuffer[32]; _OFScryptBlockMix(blockMixBuffer, blockMixInput.u32, 1); OTAssertEqual(memcmp(blockMixBuffer, blockMixOutput, 128), 0); } - (void)testROMix { uint32_t ROMixBuffer[32], ROMixTmp[17 * 32]; memcpy(ROMixBuffer, ROMixInput, 128); _OFScryptROMix(ROMixBuffer, 1, 16, ROMixTmp); OTAssertEqual(memcmp(ROMixBuffer, ROMixOutput, 128), 0); } - (void)testRFC7941TestVector1 { unsigned char output[64]; OFScrypt((OFScryptParameters){ .blockSize = 1, .costFactor = 16, .parallelization = 1, .salt = (unsigned char *)"", .saltLength = 0, .password = "", .passwordLength = 0, .key = output, .keyLength = 64, .allowsSwappableMemory = true }); OTAssertEqual(memcmp(output, testVector1, 64), 0); } /* Nintendo DS does not have enough RAM for the second test vector. */ #ifndef OF_NINTENDO_DS - (void)testRFC7941TestVector2 { unsigned char output[64]; OFScrypt((OFScryptParameters){ .blockSize = 8, .costFactor = 1024, .parallelization = 16, .salt = (unsigned char *)"NaCl", .saltLength = 4, .password = "password", .passwordLength = 8, .key = output, .keyLength = 64, .allowsSwappableMemory = true }); OTAssertEqual(memcmp(output, testVector2, 64), 0); } #endif /* * The third test vector is too expensive for m68k. * Nintendo DS does not have enough RAM for the third test vector. */ #if !defined(OF_M68K) && !defined(OF_NINTENDO_DS) - (void)testRFC7941TestVector3 { unsigned char output[64]; OFScrypt((OFScryptParameters){ .blockSize = 8, .costFactor = 16384, .parallelization = 1, .salt = (unsigned char *)"SodiumChloride", .saltLength = 14, .password = "pleaseletmein", .passwordLength = 13, .key = output, .keyLength = 64, .allowsSwappableMemory = true }); OTAssertEqual(memcmp(output, testVector3, 64), 0); } #endif /* The forth test vector is too expensive to include it in the tests. */ #if 0 - (void)testRFC7941TestVector4 { unsigned char output[64]; OFScrypt((OFScryptParameters){ .blockSize = 8, .costFactor = 1048576, .parallelization = 1, .salt = (unsigned char *)"SodiumChloride", .saltLength = 14, .password = "pleaseletmein", .passwordLength = 13, .key = output, .keyLength = 64, .allowsSwappableMemory = true }); OTAssertEqual(memcmp(output, testVector4, 64), 0); } #endif @end objfw-1.1.6/tests/OFSetTests.h000066400000000000000000000015571465614216400161650ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "ObjFW.h" #import "ObjFWTest.h" @interface OFSetTests: OTTestCase { OFSet *_set; } @property (readonly, nonatomic) Class setClass; @end objfw-1.1.6/tests/OFSetTests.m000066400000000000000000000122571465614216400161710ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFSetTests.h" @interface CustomSet: OFSet { OFSet *_set; } @end @implementation OFSetTests - (Class)setClass { return [CustomSet class]; } - (void)setUp { [super setUp]; _set = [[OFSet alloc] initWithObjects: @"foo", @"bar", @"baz", nil]; } - (void)dealloc { [_set release]; [super dealloc]; } - (void)testSetWithArray { OTAssertEqualObjects([self.setClass setWithArray: ([OFArray arrayWithObjects: @"foo", @"bar", @"baz", @"foo", nil])], _set); } - (void)testIsEqual { OTAssertEqualObjects(_set, ([OFSet setWithObjects: @"foo", @"bar", @"baz", nil])); } - (void)testHash { OTAssertEqual(_set.hash, [([OFSet setWithObjects: @"foo", @"bar", @"baz", nil]) hash]); } - (void)testDescription { OFString *description = _set.description; OTAssert( [description isEqual: @"{(\n\tfoo,\n\tbar,\n\tbaz\n)}"] || [description isEqual: @"{(\n\tfoo,\n\tbaz,\n\tbar\n)}"] || [description isEqual: @"{(\n\tbar,\n\tfoo,\n\tbaz\n)}"] || [description isEqual: @"{(\n\tbar,\n\tbaz,\n\tfoo\n)}"] || [description isEqual: @"{(\n\tbaz,\n\tfoo,\n\tbar\n)}"] || [description isEqual: @"{(\n\tbaz,\n\tbar,\n\tfoo\n)}"]); } - (void)testCopy { OTAssertEqualObjects([[_set copy] autorelease], _set); } - (void)testMutableCopy { OTAssertEqualObjects([[_set mutableCopy] autorelease], _set); } - (void)testIsSubsetOfSet { OTAssertTrue([([OFSet setWithObjects: @"foo", nil]) isSubsetOfSet: _set]); OTAssertFalse([([OFSet setWithObjects: @"foo", @"Foo", nil]) isSubsetOfSet: _set]); } - (void)testIntersectsSet { OTAssertTrue([([OFSet setWithObjects: @"foo", @"Foo", nil]) intersectsSet: _set]); OTAssertFalse([([OFSet setWithObjects: @"Foo", nil]) intersectsSet: _set]); } - (void)testEnumerator { OFEnumerator *enumerator = [_set objectEnumerator]; bool seenFoo = false, seenBar = false, seenBaz = false; OFString *object; while ((object = [enumerator nextObject]) != nil) { if ([object isEqual: @"foo"]) { OTAssertFalse(seenFoo); seenFoo = true; } else if ([object isEqual: @"bar"]) { OTAssertFalse(seenBar); seenBar = true; } else if ([object isEqual: @"baz"]) { OTAssertFalse(seenBaz); seenBaz = true; } else OTAssert(false, @"Unexpected object seen: %@", object); } OTAssert(seenFoo && seenBar && seenBaz); } - (void)testFastEnumeration { bool seenFoo = false, seenBar = false, seenBaz = false; for (OFString *object in _set) { if ([object isEqual: @"foo"]) { OTAssertFalse(seenFoo); seenFoo = true; } else if ([object isEqual: @"bar"]) { OTAssertFalse(seenBar); seenBar = true; } else if ([object isEqual: @"baz"]) { OTAssertFalse(seenBaz); seenBaz = true; } else OTAssert(false, @"Unexpected object seen: %@", object); } OTAssert(seenFoo && seenBar && seenBaz); } #ifdef OF_HAVE_BLOCKS - (void)testEnumerateObjectsUsingBlock { __block bool seenFoo = false, seenBar = false, seenBaz = false; [_set enumerateObjectsUsingBlock: ^ (id object, bool *stop) { if ([object isEqual: @"foo"]) { OTAssertFalse(seenFoo); seenFoo = true; } else if ([object isEqual: @"bar"]) { OTAssertFalse(seenBar); seenBar = true; } else if ([object isEqual: @"baz"]) { OTAssertFalse(seenBaz); seenBaz = true; } else OTAssert(false, @"Unexpected object seen: %@", object); }]; OTAssert(seenFoo && seenBar && seenBaz); } - (void)testFilteredSetUsingBlock { OFSet *filteredSet = [_set filteredSetUsingBlock: ^ (id object) { return [object hasPrefix: @"ba"]; }]; OTAssertEqualObjects(filteredSet, ([OFSet setWithObjects: @"bar", @"baz", nil])); } #endif - (void)testValueForKey { OFSet *set = [[self.setClass setWithObjects: @"a", @"ab", @"abc", @"b", nil] valueForKey: @"length"]; OTAssertEqualObjects(set, ([OFSet setWithObjects: [OFNumber numberWithInt: 1], [OFNumber numberWithInt: 2], [OFNumber numberWithInt: 3], nil])); OTAssertEqualObjects([set valueForKey: @"@count"], [OFNumber numberWithInt: 3]); } @end @implementation CustomSet - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { self = [super init]; @try { _set = [[OFSet alloc] initWithObjects: objects count: count]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_set release]; [super dealloc]; } - (size_t)count { return _set.count; } - (bool)containsObject: (id)object { return [_set containsObject: object]; } - (OFEnumerator *)objectEnumerator { return [_set objectEnumerator]; } @end objfw-1.1.6/tests/OFSocketTests.m000066400000000000000000000221231465614216400166570ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" @interface OFSocketTests: OTTestCase @end #define COMPARE_V6(a, a0, a1, a2, a3, a4, a5, a6, a7) \ (a.sockaddr.in6.sin6_addr.s6_addr[0] == (a0 >> 8) && \ a.sockaddr.in6.sin6_addr.s6_addr[1] == (a0 & 0xFF) && \ a.sockaddr.in6.sin6_addr.s6_addr[2] == (a1 >> 8) && \ a.sockaddr.in6.sin6_addr.s6_addr[3] == (a1 & 0xFF) && \ a.sockaddr.in6.sin6_addr.s6_addr[4] == (a2 >> 8) && \ a.sockaddr.in6.sin6_addr.s6_addr[5] == (a2 & 0xFF) && \ a.sockaddr.in6.sin6_addr.s6_addr[6] == (a3 >> 8) && \ a.sockaddr.in6.sin6_addr.s6_addr[7] == (a3 & 0xFF) && \ a.sockaddr.in6.sin6_addr.s6_addr[8] == (a4 >> 8) && \ a.sockaddr.in6.sin6_addr.s6_addr[9] == (a4 & 0xFF) && \ a.sockaddr.in6.sin6_addr.s6_addr[10] == (a5 >> 8) && \ a.sockaddr.in6.sin6_addr.s6_addr[11] == (a5 & 0xFF) && \ a.sockaddr.in6.sin6_addr.s6_addr[12] == (a6 >> 8) && \ a.sockaddr.in6.sin6_addr.s6_addr[13] == (a6 & 0xFF) && \ a.sockaddr.in6.sin6_addr.s6_addr[14] == (a7 >> 8) && \ a.sockaddr.in6.sin6_addr.s6_addr[15] == (a7 & 0xFF)) #define SET_V6(a, a0, a1, a2, a3, a4, a5, a6, a7) \ a.sockaddr.in6.sin6_addr.s6_addr[0] = a0 >> 8; \ a.sockaddr.in6.sin6_addr.s6_addr[1] = a0 & 0xFF; \ a.sockaddr.in6.sin6_addr.s6_addr[2] = a1 >> 8; \ a.sockaddr.in6.sin6_addr.s6_addr[3] = a1 & 0xFF; \ a.sockaddr.in6.sin6_addr.s6_addr[4] = a2 >> 8; \ a.sockaddr.in6.sin6_addr.s6_addr[5] = a2 & 0xFF; \ a.sockaddr.in6.sin6_addr.s6_addr[6] = a3 >> 8; \ a.sockaddr.in6.sin6_addr.s6_addr[7] = a3 & 0xFF; \ a.sockaddr.in6.sin6_addr.s6_addr[8] = a4 >> 8; \ a.sockaddr.in6.sin6_addr.s6_addr[9] = a4 & 0xFF; \ a.sockaddr.in6.sin6_addr.s6_addr[10] = a5 >> 8; \ a.sockaddr.in6.sin6_addr.s6_addr[11] = a5 & 0xFF; \ a.sockaddr.in6.sin6_addr.s6_addr[12] = a6 >> 8; \ a.sockaddr.in6.sin6_addr.s6_addr[13] = a6 & 0xFF; \ a.sockaddr.in6.sin6_addr.s6_addr[14] = a7 >> 8; \ a.sockaddr.in6.sin6_addr.s6_addr[15] = a7 & 0xFF; @implementation OFSocketTests - (void)testParseIPv4 { OFSocketAddress address = OFSocketAddressParseIP(@"127.0.0.1", 1234); OTAssertEqual(OFFromBigEndian32(address.sockaddr.in.sin_addr.s_addr), 0x7F000001); OTAssertEqual(OFFromBigEndian16(address.sockaddr.in.sin_port), 1234); } - (void)testParseRejectsInvalidIPv4 { OTAssertThrowsSpecific(OFSocketAddressParseIP(@"127.0.0.0.1", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"127.0.0.256", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"127.0.0. 1", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@" 127.0.0.1", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"127.0.a.1", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"127.0..1", 1234), OFInvalidFormatException); } - (void)testPortForIPv4 { OFSocketAddress address = OFSocketAddressParseIP(@"127.0.0.1", 1234); OTAssertEqual(OFSocketAddressIPPort(&address), 1234); } - (void)testStringForIPv4 { OFSocketAddress address = OFSocketAddressParseIP(@"127.0.0.1", 1234); OTAssertEqualObjects(OFSocketAddressString(&address), @"127.0.0.1"); } - (void)testParseIPv6 { OFSocketAddress address; address = OFSocketAddressParseIP( @"1122:3344:5566:7788:99aa:bbCc:ddee:ff00", 1234); OTAssert(COMPARE_V6(address, 0x1122, 0x3344, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0xDDEE, 0xFF00)); OTAssertEqual(OFFromBigEndian16(address.sockaddr.in6.sin6_port), 1234); address = OFSocketAddressParseIP(@"::", 1234); OTAssert(COMPARE_V6(address, 0, 0, 0, 0, 0, 0, 0, 0)); OTAssertEqual(OFFromBigEndian16(address.sockaddr.in6.sin6_port), 1234); address = OFSocketAddressParseIP(@"aaAa::bBbb", 1234); OTAssert(COMPARE_V6(address, 0xAAAA, 0, 0, 0, 0, 0, 0, 0xBBBB)); OTAssertEqual(OFFromBigEndian16(address.sockaddr.in6.sin6_port), 1234); address = OFSocketAddressParseIP(@"aaAa::", 1234); OTAssert(COMPARE_V6(address, 0xAAAA, 0, 0, 0, 0, 0, 0, 0)); OTAssertEqual(OFFromBigEndian16(address.sockaddr.in6.sin6_port), 1234); address = OFSocketAddressParseIP(@"::aaAa", 1234); OTAssert(COMPARE_V6(address, 0, 0, 0, 0, 0, 0, 0, 0xAAAA)); OTAssertEqual(OFFromBigEndian16(address.sockaddr.in6.sin6_port), 1234); address = OFSocketAddressParseIP(@"fd00::1%123", 1234); OTAssert(COMPARE_V6(address, 0xFD00, 0, 0, 0, 0, 0, 0, 1)); OTAssertEqual(OFFromBigEndian16(address.sockaddr.in6.sin6_port), 1234); OTAssertEqual(address.sockaddr.in6.sin6_scope_id, 123); address = OFSocketAddressParseIP(@"::ffff:127.0.0.1", 1234); OTAssert(COMPARE_V6(address, 0, 0, 0, 0, 0, 0xFFFF, 0x7F00, 1)); OTAssertEqual(OFFromBigEndian16(address.sockaddr.in6.sin6_port), 1234); address = OFSocketAddressParseIP(@"64:ff9b::127.0.0.1", 1234); OTAssert(COMPARE_V6(address, 0x64, 0xFF9B, 0, 0, 0, 0, 0x7F00, 1)); OTAssertEqual(OFFromBigEndian16(address.sockaddr.in6.sin6_port), 1234); } - (void)testParseRejectsInvalidIPv6 { OTAssertThrowsSpecific(OFSocketAddressParseIP(@"1:::2", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"1: ::2", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"1:: :2", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"1::2::3", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"10000::1", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"::10000", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"::1::", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"1:2:3:4:5:6:7:", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"1:2:3:4:5:6:7::", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"1:2", 1234), OFInvalidFormatException); } - (void)testPortForIPv6 { OFSocketAddress address = OFSocketAddressParseIP(@"::", 1234); OTAssertEqual(OFSocketAddressIPPort(&address), 1234); } - (void)testStringForIPv6 { OFSocketAddress address = OFSocketAddressParseIP(@"::", 1234); OTAssertEqualObjects(OFSocketAddressString(&address), @"::"); SET_V6(address, 0, 0, 0, 0, 0, 0, 0, 1) OTAssertEqualObjects(OFSocketAddressString(&address), @"::1"); SET_V6(address, 1, 0, 0, 0, 0, 0, 0, 0) OTAssertEqualObjects(OFSocketAddressString(&address), @"1::"); SET_V6(address, 0x1122, 0x3344, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0xDDEE, 0xFF00) OTAssertEqualObjects(OFSocketAddressString(&address), @"1122:3344:5566:7788:99aa:bbcc:ddee:ff00"); SET_V6(address, 0x1122, 0x3344, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0xDDEE, 0) OTAssertEqualObjects(OFSocketAddressString(&address), @"1122:3344:5566:7788:99aa:bbcc:ddee:0"); SET_V6(address, 0x1122, 0x3344, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0, 0) OTAssertEqualObjects(OFSocketAddressString(&address), @"1122:3344:5566:7788:99aa:bbcc::"); SET_V6(address, 0, 0x3344, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0xDDEE, 0xFF00) OTAssertEqualObjects(OFSocketAddressString(&address), @"0:3344:5566:7788:99aa:bbcc:ddee:ff00"); SET_V6(address, 0, 0, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0xDDEE, 0xFF00) OTAssertEqualObjects(OFSocketAddressString(&address), @"::5566:7788:99aa:bbcc:ddee:ff00"); SET_V6(address, 0, 0, 0x5566, 0, 0, 0, 0xDDEE, 0xFF00) OTAssertEqualObjects(OFSocketAddressString(&address), @"0:0:5566::ddee:ff00"); SET_V6(address, 0, 0, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0, 0) OTAssertEqualObjects(OFSocketAddressString(&address), @"::5566:7788:99aa:bbcc:0:0"); address.sockaddr.in6.sin6_scope_id = 123; OTAssertEqualObjects(OFSocketAddressString(&address), @"::5566:7788:99aa:bbcc:0:0%123"); } - (void)testAddressEqual { OFSocketAddress addr1 = OFSocketAddressParseIP(@"127.0.0.1", 1234); OFSocketAddress addr2 = OFSocketAddressParseIP(@"127.0.0.1", 1234); OFSocketAddress addr3 = OFSocketAddressParseIP(@"127.0.0.1", 1235); OTAssertTrue(OFSocketAddressEqual(&addr1, &addr2)); OTAssertFalse(OFSocketAddressEqual(&addr1, &addr3)); } - (void)testAddressHash { OFSocketAddress addr1 = OFSocketAddressParseIP(@"127.0.0.1", 1234); OFSocketAddress addr2 = OFSocketAddressParseIP(@"127.0.0.1", 1234); OFSocketAddress addr3 = OFSocketAddressParseIP(@"127.0.0.1", 1235); OTAssertEqual(OFSocketAddressHash(&addr1), OFSocketAddressHash(&addr2)); OTAssertNotEqual(OFSocketAddressHash(&addr1), OFSocketAddressHash(&addr3)); } @end objfw-1.1.6/tests/OFStreamTests.m000066400000000000000000000036461465614216400166730ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" @interface OFStreamTests: OTTestCase @end @interface OFTestStream: OFStream { int _state; } @end @implementation OFStreamTests - (void)testStream { size_t pageSize = [OFSystemInfo pageSize]; OFTestStream *stream = [[[OFTestStream alloc] init] autorelease]; char *cString = OFAllocMemory(pageSize - 2, 1); @try { OFString *string; memset(cString, 'X', pageSize - 3); cString[pageSize - 3] = '\0'; OTAssertEqualObjects([stream readLine], @"foo"); string = [stream readLine]; OTAssertNotNil(string); OTAssertEqual(string.length, pageSize - 3); OTAssertEqual(strcmp(string.UTF8String, cString), 0); } @finally { OFFreeMemory(cString); } } @end @implementation OFTestStream - (bool)lowlevelIsAtEndOfStream { return (_state > 1); } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)size { size_t pageSize = [OFSystemInfo pageSize]; switch (_state) { case 0: if (size < 1) return 0; memcpy(buffer, "f", 1); _state++; return 1; case 1: if (size < pageSize) return 0; memcpy(buffer, "oo\n", 3); memset((char *)buffer + 3, 'X', pageSize - 3); _state++; return pageSize; } return 0; } @end objfw-1.1.6/tests/OFStringTests.h000066400000000000000000000015731465614216400166760ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "ObjFW.h" #import "ObjFWTest.h" @interface OFStringTests: OTTestCase { OFString *_string; } @property (readonly, nonatomic) Class stringClass; @end objfw-1.1.6/tests/OFStringTests.m000066400000000000000000001543631465614216400167110ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #include #import "OFStringTests.h" #ifndef INFINITY # define INFINITY __builtin_inf() #endif static const OFUnichar unicharString[] = { 0xFEFF, 'f', 0xF6, 0xF6, 'b', 0xE4, 'r', 0x1F03A, 0 }; static const OFUnichar swappedUnicharString[] = { 0xFFFE0000, 0x66000000, 0xF6000000, 0xF6000000, 0x62000000, 0xE4000000, 0x72000000, 0x3AF00100, 0 }; static const OFChar16 char16String[] = { 0xFEFF, 'f', 0xF6, 0xF6, 'b', 0xE4, 'r', 0xD83C, 0xDC3A, 0 }; static const OFChar16 swappedChar16String[] = { 0xFFFE, 0x6600, 0xF600, 0xF600, 0x6200, 0xE400, 0x7200, 0x3CD8, 0x3ADC, 0 }; @interface CustomString: OFString { OFMutableString *_string; } @end @interface CustomMutableString: OFMutableString { OFMutableString *_string; } @end @interface EntityHandler: OFObject @end @implementation OFStringTests - (Class)stringClass { return [CustomString class]; } - (void)setUp { [super setUp]; _string = [[self.stringClass alloc] initWithString: @"täṠ€🤔"]; } - (void)dealloc { [_string release]; [super dealloc]; } - (void)testIsEqual { OTAssertEqualObjects(_string, @"täṠ€🤔"); OTAssertEqualObjects(@"täṠ€🤔", _string); OTAssertNotEqualObjects([self.stringClass stringWithString: @"test"], @"täṠ€🤔"); OTAssertNotEqualObjects(@"täṠ€🤔", [self.stringClass stringWithString: @"test"]); } - (void)testHash { OTAssertEqual(_string.hash, @"täṠ€🤔".hash); OTAssertNotEqual([[self.stringClass stringWithString: @"test"] hash], @"täṠ€".hash); } - (void)testCopy { OTAssertEqualObjects([[_string copy] autorelease], _string); } - (void)testMutableCopy { OTAssertEqualObjects([[_string mutableCopy] autorelease], _string); } - (void)testCompare { OTAssertEqual([_string compare: @"täṠ€🤔"], OFOrderedSame); OTAssertEqual([[self.stringClass stringWithString: @""] compare: @"a"], OFOrderedAscending); OTAssertEqual([[self.stringClass stringWithString: @"a"] compare: @"b"], OFOrderedAscending); OTAssertEqual([[self.stringClass stringWithString: @"cd"] compare: @"bc"], OFOrderedDescending); OTAssertEqual([[self.stringClass stringWithString: @"ä"] compare: @"ö"], OFOrderedAscending); OTAssertEqual([[self.stringClass stringWithString: @"€"] compare: @"ß"], OFOrderedDescending); OTAssertEqual([[self.stringClass stringWithString: @"aa"] compare: @"z"], OFOrderedAscending); OTAssertEqual([@"aa" compare: [self.stringClass stringWithString: @"z"]], OFOrderedAscending); } - (void)testCaseInsensitiveCompare { #ifdef OF_HAVE_UNICODE_TABLES OTAssertEqual([[self.stringClass stringWithString: @"a"] caseInsensitiveCompare: @"A"], OFOrderedSame); OTAssertEqual([[self.stringClass stringWithString: @"Ä"] caseInsensitiveCompare: @"ä"], OFOrderedSame); OTAssertEqual([[self.stringClass stringWithString: @"я"] caseInsensitiveCompare: @"Я"], OFOrderedSame); OTAssertEqual([[self.stringClass stringWithString: @"€"] caseInsensitiveCompare: @"ß"], OFOrderedDescending); OTAssertEqual([[self.stringClass stringWithString: @"ß"] caseInsensitiveCompare: @"→"], OFOrderedAscending); OTAssertEqual([[self.stringClass stringWithString: @"AA"] caseInsensitiveCompare: @"z"], OFOrderedAscending); OTAssertEqual([[self.stringClass stringWithString: @"ABC"] caseInsensitiveCompare: @"AbD"], OFOrderedAscending); #else OTAssertEqual([[self.stringClass stringWithString: @"a"] caseInsensitiveCompare: @"A"], OFOrderedSame); OTAssertEqual([[self.stringClass stringWithString: @"AA"] caseInsensitiveCompare: @"z"], OFOrderedAscending); OTAssertEqual([[self.stringClass stringWithString: @"ABC"] caseInsensitiveCompare: @"AbD"], OFOrderedAscending); #endif } - (void)testDescription { OTAssertEqualObjects(_string.description, @"täṠ€🤔"); } - (void)testLength { OTAssertEqual(_string.length, 5); } - (void)testUTF8StringLength { OTAssertEqual(_string.UTF8StringLength, 13); } - (void)testCharacterAtIndex { OTAssertEqual([_string characterAtIndex: 0], 't'); OTAssertEqual([_string characterAtIndex: 1], 0xE4); OTAssertEqual([_string characterAtIndex: 2], 0x1E60); OTAssertEqual([_string characterAtIndex: 3], 0x20AC); OTAssertEqual([_string characterAtIndex: 4], 0x1F914); } - (void)testCharacterAtIndexFailsWithOutOfRangeIndex { OTAssertThrowsSpecific([_string characterAtIndex: 5], OFOutOfRangeException); } - (void)testUppercaseString { #ifdef OF_HAVE_UNICODE_TABLES OTAssertEqualObjects(_string.uppercaseString, @"TÄṠ€🤔"); #else OTAssertEqualObjects(_string.uppercaseString, @"TäṠ€🤔"); #endif } - (void)testLowercaseString { #ifdef OF_HAVE_UNICODE_TABLES OTAssertEqualObjects(_string.lowercaseString, @"täṡ€🤔"); #else OTAssertEqualObjects(_string.lowercaseString, @"täṠ€🤔"); #endif } - (void)testCapitalizedString { #ifdef OF_HAVE_UNICODE_TABLES OTAssertEqualObjects([[self.stringClass stringWithString: @"täṠ€🤔täṠ€🤔 täṠ€🤔"] capitalizedString], @"Täṡ€🤔täṡ€🤔 Täṡ€🤔"); #else OTAssertEqualObjects([[self.stringClass stringWithString: @"täṠ€🤔täṠ€🤔 täṠ€🤔"] capitalizedString], @"TäṠ€🤔täṠ€🤔 TäṠ€🤔"); #endif } - (void)testStringWithUTF8StringLength { OTAssertEqualObjects([self.stringClass stringWithUTF8String: "\xEF\xBB\xBF" "foobar" length: 6], @"foo"); } - (void)testStringWithUTF16String { OTAssertEqualObjects([self.stringClass stringWithUTF16String: char16String], @"fööbär🀺"); OTAssertEqualObjects([self.stringClass stringWithUTF16String: swappedChar16String], @"fööbär🀺"); } - (void)testStringWithUTF32String { OTAssertEqualObjects([self.stringClass stringWithUTF32String: unicharString], @"fööbär🀺"); OTAssertEqualObjects([self.stringClass stringWithUTF32String: swappedUnicharString], @"fööbär🀺"); } - (void)testStringWithUTF8StringFailsWithInvalidUTF8 { OTAssertThrowsSpecific( [self.stringClass stringWithUTF8String: "\xE0\x80"], OFInvalidEncodingException); OTAssertThrowsSpecific( [self.stringClass stringWithUTF8String: "\xF0\x80\x80\xC0"], OFInvalidEncodingException); } - (void)testStringWithCStringEncodingISO8859_1 { OTAssertEqualObjects([self.stringClass stringWithCString: "\xE4\xF6\xFC" encoding: OFStringEncodingISO8859_1], @"äöü"); } #ifdef HAVE_ISO_8859_15 - (void)testStringWithCStringEncodingISO8859_15 { OTAssertEqualObjects([self.stringClass stringWithCString: "\xA4\xA6\xA8\xB4\xB8\xBC\xBD\xBE" encoding: OFStringEncodingISO8859_15], @"€ŠšŽžŒœŸ"); } #endif #ifdef HAVE_WINDOWS_1252 - (void)testStringWithCStringEncodingWindows1252 { OTAssertEqualObjects([self.stringClass stringWithCString: "\x80\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B" "\x8C\x8E\x91\x92\x93\x94\x95\x96\x97\x98\x99" "\x9A\x9B\x9C\x9E\x9F" encoding: OFStringEncodingWindows1252], @"€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ"); } #endif #ifdef HAVE_CODEPAGE_437 - (void)testStringWithCStringEncodingCodepage437 { OTAssertEqualObjects([self.stringClass stringWithCString: "\xB0\xB1\xB2\xDB" encoding: OFStringEncodingCodepage437], @"░▒▓█"); } #endif #ifdef OF_HAVE_FILES - (void)testStringWithContentsOfFileEncoding { OTAssertEqualObjects([self.stringClass stringWithContentsOfFile: @"testfile.txt" encoding: OFStringEncodingISO8859_1], @"testäöü"); } - (void)testStringWithContentsOfIRIEncoding { OTAssertEqualObjects([self.stringClass stringWithContentsOfIRI: [OFIRI fileIRIWithPath: @"testfile.txt"] encoding: OFStringEncodingISO8859_1], @"testäöü"); } #endif - (void)testCStringWithEncodingASCII { OTAssertEqual(strcmp([[self.stringClass stringWithString: @"This is a test"] cStringWithEncoding: OFStringEncodingASCII], "This is a test"), 0); OTAssertThrowsSpecific([[self.stringClass stringWithString: @"This is a tést"] cStringWithEncoding: OFStringEncodingASCII], OFInvalidEncodingException); } - (void)testCStringWithEncodingISO8859_1 { OTAssertEqual(strcmp([[self.stringClass stringWithString: @"This is ä test"] cStringWithEncoding: OFStringEncodingISO8859_1], "This is \xE4 test"), 0); OTAssertThrowsSpecific([[self.stringClass stringWithString: @"This is ä t€st"] cStringWithEncoding: OFStringEncodingISO8859_1], OFInvalidEncodingException); } #ifdef HAVE_ISO_8859_15 - (void)testCStringWithEncodingISO8859_15 { OTAssertEqual(strcmp([[self.stringClass stringWithString: @"This is ä t€st"] cStringWithEncoding: OFStringEncodingISO8859_15], "This is \xE4 t\xA4st"), 0); OTAssertThrowsSpecific( [[self.stringClass stringWithString: @"This is ä t€st…"] cStringWithEncoding: OFStringEncodingISO8859_15], OFInvalidEncodingException); } #endif #ifdef HAVE_WINDOWS_1252 - (void)testCStringWithEncodingWindows1252 { OTAssertEqual( strcmp([[self.stringClass stringWithString: @"This is ä t€st…"] cStringWithEncoding: OFStringEncodingWindows1252], "This is \xE4 t\x80st\x85"), 0); OTAssertThrowsSpecific( [[self.stringClass stringWithString: @"This is ä t€st…‼"] cStringWithEncoding: OFStringEncodingWindows1252], OFInvalidEncodingException); } #endif #ifdef HAVE_CODEPAGE_437 - (void)testCStringWithEncodingCodepage437 { OTAssertEqual( strcmp([[self.stringClass stringWithString: @"Tést strîng ░▒▓"] cStringWithEncoding: OFStringEncodingCodepage437], "T\x82st str\x8Cng \xB0\xB1\xB2"), 0); OTAssertThrowsSpecific( [[self.stringClass stringWithString: @"T€st strîng ░▒▓"] cStringWithEncoding: OFStringEncodingCodepage437], OFInvalidEncodingException); } #endif - (void)testLossyCStringWithEncodingASCII { OTAssertEqual(strcmp([[self.stringClass stringWithString: @"This is a tést"] lossyCStringWithEncoding: OFStringEncodingASCII], "This is a t?st"), 0); } - (void)testLossyCStringWithEncodingISO8859_1 { OTAssertEqual( strcmp([[self.stringClass stringWithString: @"This is ä t€st"] lossyCStringWithEncoding: OFStringEncodingISO8859_1], "This is \xE4 t?st"), 0); } #ifdef HAVE_ISO_8859_15 - (void)testLossyCStringWithEncodingISO8859_15 { OTAssertEqual( strcmp([[self.stringClass stringWithString: @"This is ä t€st…"] lossyCStringWithEncoding: OFStringEncodingISO8859_15], "This is \xE4 t\xA4st?"), 0); } #endif #ifdef HAVE_WINDOWS_1252 - (void)testLossyCStringWithEncodingWindows1252 { OTAssertEqual( strcmp([[self.stringClass stringWithString: @"This is ä t€st…‼"] lossyCStringWithEncoding: OFStringEncodingWindows1252], "This is \xE4 t\x80st\x85?"), 0); } #endif #ifdef HAVE_CODEPAGE_437 - (void)testLossyCStringWithEncodingCodepage437 { OTAssertEqual( strcmp([[self.stringClass stringWithString: @"T€st strîng ░▒▓"] lossyCStringWithEncoding: OFStringEncodingCodepage437], "T?st str\x8Cng \xB0\xB1\xB2"), 0); } #endif - (void)testStringWithFormat { OTAssertEqualObjects( ([self.stringClass stringWithFormat: @"%@:%d", @"test", 123]), @"test:123"); } - (void)testRangeOfString { OFString *string = [self.stringClass stringWithString: @"𝄞öö"]; OTAssertEqual([string rangeOfString: @"öö"].location, 1); OTAssertEqual([string rangeOfString: @"ö"].location, 1); OTAssertEqual([string rangeOfString: @"𝄞"].location, 0); OTAssertEqual([string rangeOfString: @"x"].location, OFNotFound); OTAssertEqual([string rangeOfString: @"öö" options: OFStringSearchBackwards].location, 1); OTAssertEqual([string rangeOfString: @"ö" options: OFStringSearchBackwards].location, 2); OTAssertEqual([string rangeOfString: @"𝄞" options: OFStringSearchBackwards].location, 0); OTAssertEqual([string rangeOfString: @"x" options: OFStringSearchBackwards].location, OFNotFound); } - (void)testRangeOfStringFailsWithOutOfRangeRange { OTAssertThrowsSpecific( [_string rangeOfString: @"t" options: 0 range: OFMakeRange(6, 1)], OFOutOfRangeException); } - (void)testIndexOfCharacterFromSet { OFCharacterSet *characterSet = [OFCharacterSet characterSetWithCharactersInString: @"cđ"]; OTAssertEqual([[self.stringClass stringWithString: @"abcđabcđe"] indexOfCharacterFromSet: characterSet], 2); OTAssertEqual([[self.stringClass stringWithString: @"abcđabcđë"] indexOfCharacterFromSet: characterSet options: OFStringSearchBackwards], 7); OTAssertEqual([[self.stringClass stringWithString: @"abcđabcđë"] indexOfCharacterFromSet: characterSet options: 0 range: OFMakeRange(4, 4)], 6); OTAssertEqual([[self.stringClass stringWithString: @"abcđabcđëf"] indexOfCharacterFromSet: characterSet options: 0 range: OFMakeRange(8, 2)], OFNotFound); } - (void)testIndexOfCharacterFromSetFailsWithOutOfRangeRange { OFCharacterSet *characterSet = [OFCharacterSet characterSetWithCharactersInString: @"cđ"]; OTAssertThrowsSpecific([[self.stringClass stringWithString: @"𝄞öö"] indexOfCharacterFromSet: characterSet options: 0 range: OFMakeRange(3, 1)], OFOutOfRangeException); } - (void)testSubstringWithRange { OTAssertEqualObjects([_string substringWithRange: OFMakeRange(1, 2)], @"äṠ"); OTAssertEqualObjects([_string substringWithRange: OFMakeRange(3, 0)], @""); } - (void)testSubstringWithRangeFailsWithOutOfRangeRange { OTAssertThrowsSpecific([_string substringWithRange: OFMakeRange(4, 2)], OFOutOfRangeException); OTAssertThrowsSpecific([_string substringWithRange: OFMakeRange(6, 0)], OFOutOfRangeException); } - (void)testStringByAppendingString { OTAssertEqualObjects([_string stringByAppendingString: @"äöü"], @"täṠ€🤔äöü"); } - (void)testHasPrefix { OTAssertTrue([_string hasPrefix: @"täṠ"]); OTAssertFalse([_string hasPrefix: @"🤔"]); } - (void)testHasSuffix { OTAssertTrue([_string hasSuffix: @"🤔"]); OTAssertFalse([_string hasSuffix: @"täṠ"]); } - (void)testComponentsSeparatedByString { OTAssertEqualObjects([[self.stringClass stringWithString: @"fooXXbarXXXXbazXXXX"] componentsSeparatedByString: @"XX"], ([OFArray arrayWithObjects: @"foo", @"bar", @"", @"baz", @"", @"", nil])); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo"] componentsSeparatedByString: @""], [OFArray arrayWithObject: @"foo"]); } - (void)testComponentsSeparatedByStringOptions { OTAssertEqualObjects([[self.stringClass stringWithString: @"fooXXbarXXXXbazXXXX"] componentsSeparatedByString: @"XX" options: OFStringSkipEmptyComponents], ([OFArray arrayWithObjects: @"foo", @"bar", @"baz", nil])); } - (void)testComponentsSeparatedByCharactersInSet { OFCharacterSet *characterSet = [OFCharacterSet characterSetWithCharactersInString: @"XYZ"]; OTAssertEqualObjects([[self.stringClass stringWithString: @"fooXYbarXYZXbazXYXZx"] componentsSeparatedByCharactersInSet: characterSet], ([OFArray arrayWithObjects: @"foo", @"", @"bar", @"", @"", @"", @"baz", @"", @"", @"", @"x", nil])); } - (void)testComponentsSeparatedByCharactersInSetOptions { OFCharacterSet *characterSet = [OFCharacterSet characterSetWithCharactersInString: @"XYZ"]; OTAssertEqualObjects([[self.stringClass stringWithString: @"fooXYbarXYZXbazXYXZ"] componentsSeparatedByCharactersInSet: characterSet options: OFStringSkipEmptyComponents], ([OFArray arrayWithObjects: @"foo", @"bar", @"baz", nil])); } - (void)testLongLongValue { OTAssertEqual([[self.stringClass stringWithString: @"1234"] longLongValue], 1234); OTAssertEqual([[self.stringClass stringWithString: @"\r\n+123 "] longLongValue], 123); OTAssertEqual([[self.stringClass stringWithString: @"-500\t"] longLongValue], -500); OTAssertEqual([[self.stringClass stringWithString: @"-0x10\t"] longLongValueWithBase: 0], -0x10); OTAssertEqual([[self.stringClass stringWithString: @"\t\t\r\n"] longLongValue], 0); OTAssertEqual([[self.stringClass stringWithString: @"123f"] longLongValueWithBase: 16], 0x123f); OTAssertEqual([[self.stringClass stringWithString: @"-1234"] longLongValueWithBase: 0], -1234); OTAssertEqual([[self.stringClass stringWithString: @"\t\n0xABcd\r"] longLongValueWithBase: 0], 0xABCD); OTAssertEqual([[self.stringClass stringWithString: @"1234567"] longLongValueWithBase: 8], 01234567); OTAssertEqual([[self.stringClass stringWithString: @"\r\n0123"] longLongValueWithBase: 0], 0123); OTAssertEqual([[self.stringClass stringWithString: @"765\t"] longLongValueWithBase: 8], 0765); OTAssertEqual([[self.stringClass stringWithString: @"\t\t\r\n"] longLongValueWithBase: 8], 0); } - (void)testLongLongValueThrowsOnInvalidFormat { OTAssertThrowsSpecific( [[self.stringClass stringWithString: @"abc"] longLongValue], OFInvalidFormatException); OTAssertThrowsSpecific( [[self.stringClass stringWithString: @"0a"] longLongValue], OFInvalidFormatException); OTAssertThrowsSpecific( [[self.stringClass stringWithString: @"0 1"] longLongValue], OFInvalidFormatException); OTAssertThrowsSpecific( [[self.stringClass stringWithString: @"0xABCDEFG"] longLongValueWithBase: 0], OFInvalidFormatException); OTAssertThrowsSpecific( [[self.stringClass stringWithString: @"0x"] longLongValueWithBase: 0], OFInvalidFormatException); } - (void)testLongLongValueThrowsOnOutOfRange { OTAssertThrowsSpecific([[self.stringClass stringWithString: @"-12345678901234567890123456789012345678901234567890" @"12345678901234567890123456789012345678901234567890"] longLongValueWithBase: 16], OFOutOfRangeException) } - (void)testUnsignedLongLongValue { OTAssertEqual([[self.stringClass stringWithString: @"1234"] unsignedLongLongValue], 1234); OTAssertEqual([[self.stringClass stringWithString: @"\r\n+123 "] unsignedLongLongValue], 123); OTAssertEqual([[self.stringClass stringWithString: @"\t\t\r\n"] unsignedLongLongValue], 0); OTAssertEqual([[self.stringClass stringWithString: @"123f"] unsignedLongLongValueWithBase: 16], 0x123f); OTAssertEqual([[self.stringClass stringWithString: @"1234"] unsignedLongLongValueWithBase: 0], 1234); OTAssertEqual([[self.stringClass stringWithString: @"\t\n0xABcd\r"] unsignedLongLongValueWithBase: 0], 0xABCD); OTAssertEqual([[self.stringClass stringWithString: @"1234567"] unsignedLongLongValueWithBase: 8], 01234567); OTAssertEqual([[self.stringClass stringWithString: @"\r\n0123"] unsignedLongLongValueWithBase: 0], 0123); OTAssertEqual([[self.stringClass stringWithString: @"765\t"] unsignedLongLongValueWithBase: 8], 0765); OTAssertEqual([[self.stringClass stringWithString: @"\t\t\r\n"] unsignedLongLongValueWithBase: 8], 0); } - (void)testUnsignedLongLongValueThrowsOnOutOfRange { OTAssertThrowsSpecific([[self.stringClass stringWithString: @"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" @"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"] unsignedLongLongValueWithBase: 16], OFOutOfRangeException); } - (void)testFloatValue { /* * These test numbers can be generated without rounding if we have IEEE * floating point numbers, thus we can use OTAssertEqual on them. */ OTAssertEqual([[self.stringClass stringWithString: @"\t-0.25 "] floatValue], -0.25); OTAssertEqual([[self.stringClass stringWithString: @"\r\n\tINF\t\n"] floatValue], INFINITY); OTAssertEqual([[self.stringClass stringWithString: @"\r -INFINITY\n"] floatValue], -INFINITY); OTAssertTrue(isnan([[self.stringClass stringWithString: @" NAN\t\t"] floatValue])); OTAssertTrue(isnan([[self.stringClass stringWithString: @" -NaN\t\t"] floatValue])); } - (void)testFloatValueThrowsOnInvalidFormat { OTAssertThrowsSpecific([[self.stringClass stringWithString: @"0.0a"] floatValue], OFInvalidFormatException); OTAssertThrowsSpecific([[self.stringClass stringWithString: @"0 0"] floatValue], OFInvalidFormatException); OTAssertThrowsSpecific([[self.stringClass stringWithString: @"0,0"] floatValue], OFInvalidFormatException); } - (void)testDoubleValue { #if (defined(OF_SOLARIS) && defined(OF_X86)) || defined(OF_AMIGAOS_M68K) /* * Solaris' strtod() has weird rounding on x86, but not on AMD64. * AmigaOS 3 with libnix has weird rounding as well. */ OTAssertEqual([[self.stringClass stringWithString: @"\t-0.125 "] doubleValue], -0.125); #elif defined(OF_ANDROID) || defined(OF_SOLARIS) || defined(OF_HPUX) || \ defined(OF_DJGPP) || defined(OF_AMIGAOS_M68K) /* * Android, Solaris, HP-UX, DJGPP and AmigaOS 3 do not accept 0x for * strtod(). */ OTAssertEqual([[self.stringClass stringWithString: @"\t-0.123456789 "] doubleValue], -0.123456789); #else OTAssertEqual([[self.stringClass stringWithString: @"\t-0x1.FFFFFFFFFFFFFP-1020 "] doubleValue], -0x1.FFFFFFFFFFFFFP-1020); #endif OTAssertEqual([[self.stringClass stringWithString: @"\r\n\tINF\t\n"] doubleValue], INFINITY); OTAssertEqual([[self.stringClass stringWithString: @"\r -INFINITY\n"] doubleValue], -INFINITY); OTAssert(isnan([[self.stringClass stringWithString: @" NAN\t\t"] doubleValue])); OTAssert(isnan([[self.stringClass stringWithString: @" -NaN\t\t"] doubleValue])); } - (void)testDoubleValueThrowsOnInvalidFormat { OTAssertThrowsSpecific([[self.stringClass stringWithString: @"0.0a"] doubleValue], OFInvalidFormatException); OTAssertThrowsSpecific([[self.stringClass stringWithString: @"0 0"] doubleValue], OFInvalidFormatException); OTAssertThrowsSpecific([[self.stringClass stringWithString: @"0,0"] doubleValue], OFInvalidFormatException); } - (void)testCharacters { OTAssertEqual(memcmp([[self.stringClass stringWithString: @"fööbär🀺"] characters], unicharString + 1, sizeof(unicharString) - 8), 0); } - (void)testUTF16String { OFString *string = [self.stringClass stringWithString: @"fööbär🀺"]; OTAssertEqual(memcmp(string.UTF16String, char16String + 1, OFUTF16StringLength(char16String) * 2), 0); #ifdef OF_BIG_ENDIAN OTAssertEqual(memcmp([string UTF16StringWithByteOrder: OFByteOrderLittleEndian], swappedChar16String + 1, OFUTF16StringLength(swappedChar16String) * 2), 0); #else OTAssertEqual(memcmp([string UTF16StringWithByteOrder: OFByteOrderBigEndian], swappedChar16String + 1, OFUTF16StringLength(swappedChar16String) * 2), 0); #endif } - (void)testUTF16StringLength { OTAssertEqual(_string.UTF16StringLength, 6); } - (void)testUTF32String { OFString *string = [self.stringClass stringWithString: @"fööbär🀺"]; OTAssertEqual(memcmp(string.UTF32String, unicharString + 1, OFUTF32StringLength(unicharString) * 4), 0); #ifdef OF_BIG_ENDIAN OTAssertEqual(memcmp([string UTF32StringWithByteOrder: OFByteOrderLittleEndian], swappedUnicharString + 1, OFUTF32StringLength(swappedUnicharString) * 4), 0); #else OTAssertEqual(memcmp([string UTF32StringWithByteOrder: OFByteOrderBigEndian], swappedUnicharString + 1, OFUTF32StringLength(swappedUnicharString) * 4), 0); #endif } - (void)testStringByMD5Hashing { OTAssertEqualObjects(_string.stringByMD5Hashing, @"7e6bef5fe100d93e808d15b1c6e6145a"); } - (void)testStringByRIPEMD160Hashing { OTAssertEqualObjects(_string.stringByRIPEMD160Hashing, @"2fd0ec899c55cf2821a2f844b9d80887fc351103"); } - (void)testStringBySHA1Hashing { OTAssertEqualObjects(_string.stringBySHA1Hashing, @"3f76f9358b372b7147344b7a3ba6d309e4466b3a"); } - (void)testStringBySHA224Hashing { OTAssertEqualObjects(_string.stringBySHA224Hashing, @"6e57ec72e4da55c46d88a15ce7ce4d8db83d0493a263134a3734259d"); } - (void)testStringBySHA256Hashing { OTAssertEqualObjects(_string.stringBySHA256Hashing, @"6eac4d3d0b4152c82ff88599482696ca" @"d6dca0b533e8a2e6963d995b19b0a683"); } - (void)testStringBySHA384Hashing { OTAssertEqualObjects(_string.stringBySHA384Hashing, @"d9bd6a671407d01cee4022888677040d" @"108dd0270c38e0ce755d6dcadb4bf9c1" @"89204dd2a51f954be55ea5d5fe00667b"); } - (void)testStringBySHA512Hashing { OTAssertEqualObjects(_string.stringBySHA512Hashing, @"64bec66b3633c585da6d32760fa3617a" @"47ca4c247472bdbbfb452b2dbf5a3612" @"5629053394a16ecd08f8a21d461537c5" @"f1224cbb379589e73dcd6763ec4f886c"); } - (void)testStringByAddingPercentEncodingWithAllowedCharacters { OFCharacterSet *characterSet = [OFCharacterSet characterSetWithCharactersInString: @"abfo'_~$🍏"]; OTAssertEqualObjects([[self.stringClass stringWithString: @"foo\"ba'_~$]🍏🍌"] stringByAddingPercentEncodingWithAllowedCharacters: characterSet], @"foo%22ba'_~$%5D🍏%F0%9F%8D%8C"); } - (void)testStringByRemovingPercentEncoding { OTAssertEqualObjects([[self.stringClass stringWithString: @"foo%20bar%22+%24%F0%9F%8D%8C"] stringByRemovingPercentEncoding], @"foo bar\"+$🍌"); } - (void)testStringByRemovingPercentEncodingThrowsOnInvalidFormat { OTAssertThrowsSpecific([[self.stringClass stringWithString: @"foo%xbar"] stringByRemovingPercentEncoding], OFInvalidFormatException); } - (void)testStringByRemovingPercentEncodingThrowsOnInvalidEncoding { OTAssertThrowsSpecific([[self.stringClass stringWithString: @"foo%FFbar"] stringByRemovingPercentEncoding], OFInvalidEncodingException); } - (void)testStringByXMLEscaping { OTAssertEqualObjects([[self.stringClass stringWithString: @" &world'\"!&"] stringByXMLEscaping], @"<hello> &world'"!&"); } - (void)testStringByXMLUnescaping { OTAssertEqualObjects([[self.stringClass stringWithString: @"<hello> &world'"!&"] stringByXMLUnescaping], @" &world'\"!&"); OTAssertEqualObjects([[self.stringClass stringWithString: @"y"] stringByXMLUnescaping], @"y"); OTAssertEqualObjects([[self.stringClass stringWithString: @"ä"] stringByXMLUnescaping], @"ä"); OTAssertEqualObjects([[self.stringClass stringWithString: @"€"] stringByXMLUnescaping], @"€"); OTAssertEqualObjects([[self.stringClass stringWithString: @"𝄞"] stringByXMLUnescaping], @"𝄞"); } - (void)testStringByXMLUnescapingThrowsOnUnknownEntities { OTAssertThrowsSpecific([[self.stringClass stringWithString: @"&foo;"] stringByXMLUnescaping], OFUnknownXMLEntityException); } - (void)testStringByXMLUnescapingThrowsOnInvalidFormat { OTAssertThrowsSpecific([[self.stringClass stringWithString: @"x&"] stringByXMLUnescaping], OFInvalidFormatException); OTAssertThrowsSpecific([[self.stringClass stringWithString: @"&#;"] stringByXMLUnescaping], OFInvalidFormatException); OTAssertThrowsSpecific([[self.stringClass stringWithString: @"&#x;"] stringByXMLUnescaping], OFInvalidFormatException); OTAssertThrowsSpecific([[self.stringClass stringWithString: @"&#g;"] stringByXMLUnescaping], OFInvalidFormatException); OTAssertThrowsSpecific([[self.stringClass stringWithString: @"&#xg;"] stringByXMLUnescaping], OFInvalidFormatException); } - (void)testStringByXMLUnescapingWithDelegate { EntityHandler *entityHandler = [[[EntityHandler alloc] init] autorelease]; OTAssertEqualObjects([[self.stringClass stringWithString: @"x&foo;y"] stringByXMLUnescapingWithDelegate: entityHandler], @"xbary"); } #ifdef OF_HAVE_BLOCKS - (void)testStringByXMLUnescapingWithBlock { OTAssertEqualObjects([[self.stringClass stringWithString: @"x&foo;y"] stringByXMLUnescapingWithBlock: ^ OFString * (OFString *string, OFString *entity) { if ([entity isEqual: @"foo"]) return @"bar"; return nil; }], @"xbary"); } - (void)testEnumerateLinesUsingBlock { __block size_t count = 0; [[self.stringClass stringWithString: @"foo\nbar\nbaz"] enumerateLinesUsingBlock: ^ (OFString *line, bool *stop) { switch (count++) { case 0: OTAssertEqualObjects(line, @"foo"); break; case 1: OTAssertEqualObjects(line, @"bar"); break; case 2: OTAssertEqualObjects(line, @"baz"); break; default: OTAssert(false); } }]; OTAssertEqual(count, 3); } #endif #ifdef OF_HAVE_FILES - (void)testIsAbsolutePath { # if defined(OF_WINDOWS) || defined(OF_MSDOS) OTAssertTrue( [[self.stringClass stringWithString: @"C:\\foo"] isAbsolutePath]); OTAssertTrue( [[self.stringClass stringWithString: @"a:/foo"] isAbsolutePath]); OTAssertFalse( [[self.stringClass stringWithString: @"foo"] isAbsolutePath]); OTAssertFalse( [[self.stringClass stringWithString: @"b:foo"] isAbsolutePath]); # ifdef OF_WINDOWS OTAssertTrue( [[self.stringClass stringWithString: @"\\\\foo"] isAbsolutePath]); # endif # elif defined(OF_AMIGAOS) OTAssertTrue( [[self.stringClass stringWithString: @"dh0:foo"] isAbsolutePath]); OTAssertTrue( [[self.stringClass stringWithString: @"dh0:a/b"] isAbsolutePath]); OTAssertFalse( [[self.stringClass stringWithString: @"foo/bar"] isAbsolutePath]); OTAssertFalse( [[self.stringClass stringWithString: @"foo"] isAbsolutePath]); # elif defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS) || \ defined(OF_WII) || defined(OF_NINTENDO_SWITCH) OTAssertTrue( [[self.stringClass stringWithString: @"sdmc:/foo"] isAbsolutePath]); OTAssertFalse( [[self.stringClass stringWithString: @"sdmc:foo"] isAbsolutePath]); OTAssertFalse( [[self.stringClass stringWithString: @"foo/bar"] isAbsolutePath]); OTAssertFalse( [[self.stringClass stringWithString: @"foo"] isAbsolutePath]); # else OTAssertTrue( [[self.stringClass stringWithString: @"/foo"] isAbsolutePath]); OTAssertTrue( [[self.stringClass stringWithString: @"/foo/bar"] isAbsolutePath]); OTAssertFalse( [[self.stringClass stringWithString: @"foo/bar"] isAbsolutePath]); OTAssertFalse( [[self.stringClass stringWithString: @"foo"] isAbsolutePath]); # endif } - (void)testStringByAppendingPathComponent { # if defined(OF_WINDOWS) || defined(OF_MSDOS) OTAssertEqualObjects([[self.stringClass stringWithString: @"foo\\bar"] stringByAppendingPathComponent: @"baz"], @"foo\\bar\\baz"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo\\bar\\"] stringByAppendingPathComponent: @"baz"], @"foo\\bar\\baz"); # else OTAssertEqualObjects([[self.stringClass stringWithString: @"foo/bar"] stringByAppendingPathComponent: @"baz"], @"foo/bar/baz"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo/bar/"] stringByAppendingPathComponent: @"baz"], @"foo/bar/baz"); # endif } - (void)testStringByAppendingPathExtension { # if defined(OF_WINDOWS) || defined(OF_MSDOS) OTAssertEqualObjects([[self.stringClass stringWithString: @"foo"] stringByAppendingPathExtension: @"bar"], @"foo.bar"); OTAssertEqualObjects([[self.stringClass stringWithString: @"c:\\tmp\\foo"] stringByAppendingPathExtension: @"bar"], @"c:\\tmp\\foo.bar"); OTAssertEqualObjects([[self.stringClass stringWithString: @"c:\\tmp\\/\\"] stringByAppendingPathExtension: @"bar"], @"c:\\tmp.bar"); # elif defined(OF_AMIGAOS) OTAssertEqualObjects([[self.stringClass stringWithString: @"foo"] stringByAppendingPathExtension: @"bar"], @"foo.bar"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo/bar"] stringByAppendingPathExtension: @"baz"], @"foo/bar.baz"); # else OTAssertEqualObjects([[self.stringClass stringWithString: @"foo"] stringByAppendingPathExtension: @"bar"], @"foo.bar"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo/bar"] stringByAppendingPathExtension: @"baz"], @"foo/bar.baz"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo///"] stringByAppendingPathExtension: @"bar"], @"foo.bar"); # endif } - (void)testPathWithComponents { # if defined(OF_WINDOWS) || defined(OF_MSDOS) OTAssertEqualObjects([self.stringClass pathWithComponents: ([OFArray arrayWithObjects: @"foo", @"bar", @"baz", nil])], @"foo\\bar\\baz"); OTAssertEqualObjects([self.stringClass pathWithComponents: ([OFArray arrayWithObjects: @"c:\\", @"foo", @"bar", @"baz", nil])], @"c:\\foo\\bar\\baz"); OTAssertEqualObjects([self.stringClass pathWithComponents: ([OFArray arrayWithObjects: @"c:", @"foo", @"bar", @"baz", nil])], @"c:foo\\bar\\baz"); OTAssertEqualObjects([self.stringClass pathWithComponents: ([OFArray arrayWithObjects: @"c:", @"\\", @"foo", @"bar", @"baz", nil])], @"c:\\foo\\bar\\baz"); OTAssertEqualObjects([self.stringClass pathWithComponents: ([OFArray arrayWithObjects: @"c:", @"/", @"foo", @"bar", @"baz", nil])], @"c:/foo\\bar\\baz"); OTAssertEqualObjects([self.stringClass pathWithComponents: ([OFArray arrayWithObjects: @"foo/", @"bar\\", @"", @"baz", @"\\", nil])], @"foo/bar\\baz"); OTAssertEqualObjects([self.stringClass pathWithComponents: [OFArray arrayWithObject: @"foo"]], @"foo"); OTAssertEqualObjects([self.stringClass pathWithComponents: [OFArray arrayWithObject: @"c:"]], @"c:"); OTAssertEqualObjects([self.stringClass pathWithComponents: [OFArray arrayWithObject: @"c:\\"]], @"c:\\"); OTAssertEqualObjects([self.stringClass pathWithComponents: [OFArray arrayWithObject: @"\\"]], @"\\"); OTAssertEqualObjects([self.stringClass pathWithComponents: [OFArray arrayWithObject: @"/"]], @"/"); # ifdef OF_WINDOWS OTAssertEqualObjects([self.stringClass pathWithComponents: ([OFArray arrayWithObjects: @"\\\\", @"foo", @"bar", nil])], @"\\\\foo\\bar"); # endif # elif defined(OF_AMIGAOS) OTAssertEqualObjects([self.stringClass pathWithComponents: ([OFArray arrayWithObjects: @"dh0:", @"foo", @"bar", @"baz", nil])], @"dh0:foo/bar/baz"); OTAssertEqualObjects([self.stringClass pathWithComponents: ([OFArray arrayWithObjects: @"foo", @"bar", @"baz", nil])], @"foo/bar/baz"); OTAssertEqualObjects([self.stringClass pathWithComponents: ([OFArray arrayWithObjects: @"foo/", @"bar", @"", @"baz", @"/", nil])], @"foo//bar/baz//"); OTAssertEqualObjects([self.stringClass pathWithComponents: [OFArray arrayWithObject: @"foo"]], @"foo"); # elif defined(OF_WII) || defined(OF_NINTENDO_DS) || \ defined(OF_NINTENDO_3DS) || defined(OF_NINTENDO_SWITCH) OTAssertEqualObjects([self.stringClass pathWithComponents: ([OFArray arrayWithObjects: @"foo", @"bar", @"baz", nil])], @"foo/bar/baz"); OTAssertEqualObjects([self.stringClass pathWithComponents: ([OFArray arrayWithObjects: @"sdmc:", @"foo", @"bar", @"baz", nil])], @"sdmc:/foo/bar/baz"); OTAssertEqualObjects([self.stringClass pathWithComponents: ([OFArray arrayWithObjects: @"foo/", @"bar/", @"", @"baz", @"/", nil])], @"foo/bar/baz"); OTAssertEqualObjects([self.stringClass pathWithComponents: [OFArray arrayWithObject: @"foo"]], @"foo"); OTAssertEqualObjects([self.stringClass pathWithComponents: [OFArray arrayWithObject: @"sdmc:"]], @"sdmc:/"); # else OTAssertEqualObjects([self.stringClass pathWithComponents: ([OFArray arrayWithObjects: @"/", @"foo", @"bar", @"baz", nil])], @"/foo/bar/baz"); OTAssertEqualObjects([self.stringClass pathWithComponents: ([OFArray arrayWithObjects: @"foo", @"bar", @"baz", nil])], @"foo/bar/baz"); OTAssertEqualObjects([self.stringClass pathWithComponents: ([OFArray arrayWithObjects: @"foo/", @"bar", @"", @"baz", @"/", nil])], @"foo/bar/baz"); OTAssertEqualObjects([self.stringClass pathWithComponents: [OFArray arrayWithObject: @"foo"]], @"foo"); # endif } - (void)testPathComponents { # if defined(OF_WINDOWS) || defined(OF_MSDOS) OTAssertEqualObjects([[self.stringClass stringWithString: @"c:/tmp"] pathComponents], ([OFArray arrayWithObjects: @"c:/", @"tmp", nil])); OTAssertEqualObjects([[self.stringClass stringWithString: @"c:\\tmp\\"] pathComponents], ([OFArray arrayWithObjects: @"c:\\", @"tmp", nil])); OTAssertEqualObjects([[self.stringClass stringWithString: @"c:\\"] pathComponents], [OFArray arrayWithObject: @"c:\\"]); OTAssertEqualObjects([[self.stringClass stringWithString: @"c:/"] pathComponents], [OFArray arrayWithObject: @"c:/"]); OTAssertEqualObjects([[self.stringClass stringWithString: @"c:"] pathComponents], [OFArray arrayWithObject: @"c:"]); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo\\bar"] pathComponents], ([OFArray arrayWithObjects: @"foo", @"bar", nil])); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo\\bar/baz/"] pathComponents], ([OFArray arrayWithObjects: @"foo", @"bar", @"baz", nil])); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo\\/"] pathComponents], [OFArray arrayWithObject: @"foo"]); # ifdef OF_WINDOWS OTAssertEqualObjects([[self.stringClass stringWithString: @"\\\\foo\\bar"] pathComponents], ([OFArray arrayWithObjects: @"\\\\", @"foo", @"bar", nil])); # endif OTAssertEqualObjects([[self.stringClass stringWithString: @""] pathComponents], [OFArray array]); # elif defined(OF_AMIGAOS) OTAssertEqualObjects([[self.stringClass stringWithString: @"dh0:tmp"] pathComponents], ([OFArray arrayWithObjects: @"dh0:", @"tmp", nil])); OTAssertEqualObjects([[self.stringClass stringWithString: @"dh0:tmp/"] pathComponents], ([OFArray arrayWithObjects: @"dh0:", @"tmp", nil])); OTAssertEqualObjects([[self.stringClass stringWithString: @"dh0:/"] pathComponents], ([OFArray arrayWithObjects: @"dh0:", @"/", nil])); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo/bar"] pathComponents], ([OFArray arrayWithObjects: @"foo", @"bar", nil])); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo/bar/baz/"] pathComponents], ([OFArray arrayWithObjects: @"foo", @"bar", @"baz", nil])); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo//"] pathComponents], ([OFArray arrayWithObjects: @"foo", @"/", nil])); OTAssertEqualObjects([[self.stringClass stringWithString: @""] pathComponents], [OFArray array]); # elif defined(OF_NINTENDO_3DS) || defined(OF_WII) || \ defined(OF_NINTENDO_SWITCH) OTAssertEqualObjects([[self.stringClass stringWithString: @"sdmc:/tmp"] pathComponents], ([OFArray arrayWithObjects: @"sdmc:", @"tmp", nil])); OTAssertEqualObjects([[self.stringClass stringWithString: @"sdmc:/"] pathComponents], [OFArray arrayWithObject: @"sdmc:"]); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo/bar"] pathComponents], ([OFArray arrayWithObjects: @"foo", @"bar", nil])); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo/bar/baz/"] pathComponents], ([OFArray arrayWithObjects: @"foo", @"bar", @"baz", nil])); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo//"] pathComponents], [OFArray arrayWithObject: @"foo"]); OTAssertEqualObjects([[self.stringClass stringWithString: @""] pathComponents], [OFArray array]); # else OTAssertEqualObjects([[self.stringClass stringWithString: @"/tmp"] pathComponents], ([OFArray arrayWithObjects: @"/", @"tmp", nil])); OTAssertEqualObjects([[self.stringClass stringWithString: @"/tmp/"] pathComponents], ([OFArray arrayWithObjects: @"/", @"tmp", nil])); OTAssertEqualObjects([[self.stringClass stringWithString: @"/"] pathComponents], [OFArray arrayWithObject: @"/"]); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo/bar"] pathComponents], ([OFArray arrayWithObjects: @"foo", @"bar", nil])); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo/bar/baz/"] pathComponents], ([OFArray arrayWithObjects: @"foo", @"bar", @"baz", nil])); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo//"] pathComponents], [OFArray arrayWithObject: @"foo"]); OTAssertEqualObjects([[self.stringClass stringWithString: @""] pathComponents], [OFArray array]); # endif } - (void)testLastPathComponent { # if defined(OF_WINDOWS) || defined(OF_MSDOS) OTAssertEqualObjects([[self.stringClass stringWithString: @"c:/tmp"] lastPathComponent], @"tmp"); OTAssertEqualObjects([[self.stringClass stringWithString: @"c:\\tmp\\"] lastPathComponent], @"tmp"); OTAssertEqualObjects([[self.stringClass stringWithString: @"c:\\"] lastPathComponent], @"c:\\"); OTAssertEqualObjects([[self.stringClass stringWithString: @"c:/"] lastPathComponent], @"c:/"); OTAssertEqualObjects([[self.stringClass stringWithString: @"\\"] lastPathComponent], @"\\"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo"] lastPathComponent], @"foo"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo\\bar"] lastPathComponent], @"bar"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo/bar/baz/"] lastPathComponent], @"baz"); # ifdef OF_WINDOWS OTAssertEqualObjects([[self.stringClass stringWithString: @"\\\\foo\\bar"] lastPathComponent], @"bar"); OTAssertEqualObjects([[self.stringClass stringWithString: @"\\\\"] lastPathComponent], @"\\\\"); # endif # elif defined(OF_AMIGAOS) OTAssertEqualObjects([[self.stringClass stringWithString: @"dh0:tmp"] lastPathComponent], @"tmp"); OTAssertEqualObjects([[self.stringClass stringWithString: @"dh0:tmp/"] lastPathComponent], @"tmp"); OTAssertEqualObjects([[self.stringClass stringWithString: @"dh0:/"] lastPathComponent], @"/"); OTAssertEqualObjects([[self.stringClass stringWithString: @"dh0:"] lastPathComponent], @"dh0:"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo"] lastPathComponent], @"foo"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo/bar"] lastPathComponent], @"bar"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo/bar/baz/"] lastPathComponent], @"baz"); # elif defined(OF_WII) || defined(OF_NINTENDO_DS) || \ defined(OF_NINTENDO_3DS) || defined(OF_NINTENDO_SWITCH) OTAssertEqualObjects([[self.stringClass stringWithString: @"sdmc:/tmp"] lastPathComponent], @"tmp"); OTAssertEqualObjects([[self.stringClass stringWithString: @"sdmc:/tmp/"] lastPathComponent], @"tmp"); OTAssertEqualObjects([[self.stringClass stringWithString: @"sdmc:/"] lastPathComponent], @"sdmc:/"); OTAssertEqualObjects([[self.stringClass stringWithString: @"sdmc:"] lastPathComponent], @"sdmc:"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo"] lastPathComponent], @"foo"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo/bar"] lastPathComponent], @"bar"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo/bar/baz/"] lastPathComponent], @"baz"); # else OTAssertEqualObjects([[self.stringClass stringWithString: @"/tmp"] lastPathComponent], @"tmp"); OTAssertEqualObjects([[self.stringClass stringWithString: @"/tmp/"] lastPathComponent], @"tmp"); OTAssertEqualObjects([[self.stringClass stringWithString: @"/"] lastPathComponent], @"/"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo"] lastPathComponent], @"foo"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo/bar"] lastPathComponent], @"bar"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo/bar/baz/"] lastPathComponent], @"baz"); # endif } - (void)testPathExtension { OTAssertEqualObjects([[self.stringClass stringWithString: @"foo.bar"] pathExtension], @"bar"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo/.bar"] pathExtension], @""); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo/.bar.baz"] pathExtension], @"baz"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo/bar.baz/"] pathExtension], @"baz"); } - (void)testStringByDeletingLastPathComponent { # if defined(OF_WINDOWS) || defined(OF_MSDOS) OTAssertEqualObjects([[self.stringClass stringWithString: @"\\tmp"] stringByDeletingLastPathComponent], @"\\"); OTAssertEqualObjects([[self.stringClass stringWithString: @"/tmp/"] stringByDeletingLastPathComponent], @"/"); OTAssertEqualObjects([[self.stringClass stringWithString: @"c:\\"] stringByDeletingLastPathComponent], @"c:\\"); OTAssertEqualObjects([[self.stringClass stringWithString: @"c:/"] stringByDeletingLastPathComponent], @"c:/"); OTAssertEqualObjects([[self.stringClass stringWithString: @"c:\\tmp/foo/"] stringByDeletingLastPathComponent], @"c:\\tmp"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo\\bar"] stringByDeletingLastPathComponent], @"foo"); OTAssertEqualObjects([[self.stringClass stringWithString: @"\\"] stringByDeletingLastPathComponent], @"\\"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo"] stringByDeletingLastPathComponent], @"."); # ifdef OF_WINDOWS OTAssertEqualObjects([[self.stringClass stringWithString: @"\\\\foo\\bar"] stringByDeletingLastPathComponent], @"\\\\foo"); OTAssertEqualObjects([[self.stringClass stringWithString: @"\\\\foo"] stringByDeletingLastPathComponent], @"\\\\"); OTAssertEqualObjects([[self.stringClass stringWithString: @"\\\\"] stringByDeletingLastPathComponent], @"\\\\"); # endif # elif defined(OF_AMIGAOS) OTAssertEqualObjects([[self.stringClass stringWithString: @"dh0:"] stringByDeletingLastPathComponent], @"dh0:"); OTAssertEqualObjects([[self.stringClass stringWithString: @"dh0:tmp"] stringByDeletingLastPathComponent], @"dh0:"); OTAssertEqualObjects([[self.stringClass stringWithString: @"dh0:tmp/"] stringByDeletingLastPathComponent], @"dh0:"); OTAssertEqualObjects([[self.stringClass stringWithString: @"dh0:/"] stringByDeletingLastPathComponent], @"dh0:"); OTAssertEqualObjects([[self.stringClass stringWithString: @"dh0:tmp/foo/"] stringByDeletingLastPathComponent], @"dh0:tmp"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo/bar"] stringByDeletingLastPathComponent], @"foo"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo"] stringByDeletingLastPathComponent], @""); # elif defined(OF_NINTENDO_3DS) || defined(OF_WII) || \ defined(OF_NINTENDO_SWITCH) OTAssertEqualObjects([[self.stringClass stringWithString: @"/tmp/"] stringByDeletingLastPathComponent], @""); OTAssertEqualObjects([[self.stringClass stringWithString: @"sdmc:/tmp/foo/"] stringByDeletingLastPathComponent], @"sdmc:/tmp"); OTAssertEqualObjects([[self.stringClass stringWithString: @"sdmc:/"] stringByDeletingLastPathComponent], @"sdmc:/"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo/bar"] stringByDeletingLastPathComponent], @"foo"); OTAssertEqualObjects([[self.stringClass stringWithString: @"/"] stringByDeletingLastPathComponent], @""); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo"] stringByDeletingLastPathComponent], @"."); # else OTAssertEqualObjects([[self.stringClass stringWithString: @"/tmp"] stringByDeletingLastPathComponent], @"/"); OTAssertEqualObjects([[self.stringClass stringWithString: @"/tmp/"] stringByDeletingLastPathComponent], @"/"); OTAssertEqualObjects([[self.stringClass stringWithString: @"/tmp/foo/"] stringByDeletingLastPathComponent], @"/tmp"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo/bar"] stringByDeletingLastPathComponent], @"foo"); OTAssertEqualObjects([[self.stringClass stringWithString: @"/"] stringByDeletingLastPathComponent], @"/"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo"] stringByDeletingLastPathComponent], @"."); # endif } - (void)testStringByDeletingPathExtension { # if defined(OF_WINDOWS) || defined(OF_MSDOS) OTAssertEqualObjects([[self.stringClass stringWithString: @"foo.bar"] stringByDeletingPathExtension], @"foo"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo..bar"] stringByDeletingPathExtension], @"foo."); OTAssertEqualObjects([[self.stringClass stringWithString: @"c:/foo.\\bar"] stringByDeletingPathExtension], @"c:/foo.\\bar"); OTAssertEqualObjects([[self.stringClass stringWithString: @"c:\\foo./bar.baz"] stringByDeletingPathExtension], @"c:\\foo.\\bar"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo.bar/"] stringByDeletingPathExtension], @"foo"); OTAssertEqualObjects([[self.stringClass stringWithString: @".foo"] stringByDeletingPathExtension], @".foo"); OTAssertEqualObjects([[self.stringClass stringWithString: @".foo.bar"] stringByDeletingPathExtension], @".foo"); # elif defined(OF_AMIGAOS) OTAssertEqualObjects([[self.stringClass stringWithString: @"foo.bar"] stringByDeletingPathExtension], @"foo"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo..bar"] stringByDeletingPathExtension], @"foo."); OTAssertEqualObjects([[self.stringClass stringWithString: @"dh0:foo.bar"] stringByDeletingPathExtension], @"dh0:foo"); OTAssertEqualObjects([[self.stringClass stringWithString: @"dh0:foo./bar"] stringByDeletingPathExtension], @"dh0:foo./bar"); OTAssertEqualObjects([[self.stringClass stringWithString: @"dh0:foo./bar.baz"] stringByDeletingPathExtension], @"dh0:foo./bar"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo.bar/"] stringByDeletingPathExtension], @"foo"); OTAssertEqualObjects([[self.stringClass stringWithString: @".foo"] stringByDeletingPathExtension], @".foo"); OTAssertEqualObjects([[self.stringClass stringWithString: @".foo\\bar"] stringByDeletingPathExtension], @".foo\\bar"); OTAssertEqualObjects([[self.stringClass stringWithString: @".foo.bar"] stringByDeletingPathExtension], @".foo"); # elif defined(OF_WII) || defined(OF_NINTENDO_DS) || \ defined(OF_NINTENDO_3DS) || defined(OF_NINTENDO_SWITCH) OTAssertEqualObjects([[self.stringClass stringWithString: @"foo.bar"] stringByDeletingPathExtension], @"foo"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo..bar"] stringByDeletingPathExtension], @"foo."); OTAssertEqualObjects([[self.stringClass stringWithString: @"sdmc:/foo./bar"] stringByDeletingPathExtension], @"sdmc:/foo./bar"); OTAssertEqualObjects([[self.stringClass stringWithString: @"sdmc:/foo./bar.baz"] stringByDeletingPathExtension], @"sdmc:/foo./bar"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo.bar/"] stringByDeletingPathExtension], @"foo"); OTAssertEqualObjects([[self.stringClass stringWithString: @".foo"] stringByDeletingPathExtension], @".foo"); OTAssertEqualObjects([[self.stringClass stringWithString: @".foo.bar"] stringByDeletingPathExtension], @".foo"); # else OTAssertEqualObjects([[self.stringClass stringWithString: @"foo.bar"] stringByDeletingPathExtension], @"foo"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo..bar"] stringByDeletingPathExtension], @"foo."); OTAssertEqualObjects([[self.stringClass stringWithString: @"/foo./bar"] stringByDeletingPathExtension], @"/foo./bar"); OTAssertEqualObjects([[self.stringClass stringWithString: @"/foo./bar.baz"] stringByDeletingPathExtension], @"/foo./bar"); OTAssertEqualObjects([[self.stringClass stringWithString: @"foo.bar/"] stringByDeletingPathExtension], @"foo"); OTAssertEqualObjects([[self.stringClass stringWithString: @".foo"] stringByDeletingPathExtension], @".foo"); OTAssertEqualObjects([[self.stringClass stringWithString: @".foo\\bar"] stringByDeletingPathExtension], @".foo\\bar"); OTAssertEqualObjects([[self.stringClass stringWithString: @".foo.bar"] stringByDeletingPathExtension], @".foo"); # endif } # if defined(OF_WINDOWS) || defined(OF_MSDOS) - (void)testStringByStandardizingPath { /* TODO: Add more tests */ OTAssertEqualObjects([[self.stringClass stringWithString: @"c:\\..\\asd"] stringByStandardizingPath], @"c:\\..\\asd"); # ifndef OF_MSDOS OTAssertEqualObjects([[self.stringClass stringWithString: @"\\\\foo\\..\\bar\\qux"] stringByStandardizingPath], @"\\\\bar\\qux"); # endif } # endif #endif @end @implementation CustomString - (instancetype)init { self = [super init]; @try { _string = [[OFMutableString alloc] init]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithString: (OFString *)string { self = [super init]; @try { _string = [string mutableCopy]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)length { self = [super init]; @try { _string = [[OFMutableString alloc] initWithCString: cString encoding: encoding length: length]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithUTF16String: (const OFChar16 *)UTF16String length: (size_t)length byteOrder: (OFByteOrder)byteOrder { self = [super init]; @try { _string = [[OFMutableString alloc] initWithUTF16String: UTF16String length: length byteOrder: byteOrder]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithUTF32String: (const OFChar32 *)UTF32String length: (size_t)length byteOrder: (OFByteOrder)byteOrder { self = [super init]; @try { _string = [[OFMutableString alloc] initWithUTF32String: UTF32String length: length byteOrder: byteOrder]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithFormat: (OFConstantString *)format arguments: (va_list)arguments { self = [super init]; @try { _string = [[OFMutableString alloc] initWithFormat: format arguments: arguments]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_string release]; [super dealloc]; } - (OFUnichar)characterAtIndex: (size_t)idx { return [_string characterAtIndex: idx]; } - (size_t)length { return _string.length; } @end @implementation EntityHandler - (OFString *)string: (OFString *)string containsUnknownEntityNamed: (OFString *)entity { if ([entity isEqual: @"foo"]) return @"bar"; return nil; } @end objfw-1.1.6/tests/OFSubprocessTests.m000066400000000000000000000034271465614216400175650ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" @interface OFSubprocessTests: OTTestCase @end @implementation OFSubprocessTests - (void)testSubprocess { #ifdef OF_HAVE_FILES OFString *program = [@"subprocess" stringByAppendingPathComponent: @"subprocess" @PROG_SUFFIX]; #else OFString *program = @"subprocess/subprocess" @PROG_SUFFIX; #endif OFArray *arguments = [OFArray arrayWithObjects: @"tést", @"123", nil]; OFMutableDictionary *environment = [[[OFApplication environment] mutableCopy] autorelease]; OFSubprocess *subprocess; [environment setObject: @"yés" forKey: @"tëst"]; subprocess = [OFSubprocess subprocessWithProgram: program programName: program arguments: arguments environment: environment]; [subprocess writeLine: @"Hellö world!"]; #ifdef OF_HAVE_UNICODE_TABLES OTAssertEqualObjects([subprocess readLine], @"HELLÖ WORLD!"); #else OTAssertEqualObjects([subprocess readLine], @"HELLö WORLD!"); #endif [subprocess closeForWriting]; OTAssertEqual([subprocess waitForTermination], 0); } @end objfw-1.1.6/tests/OFSystemInfoTests.m000066400000000000000000000165611465614216400175400ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" @interface OFSystemInfoTests: OTTestCase @end #ifdef OF_HAVE_SOCKETS static void appendAddresses(OFMutableString *string, OFData *addresses, bool *firstAddress) { size_t count = addresses.count; for (size_t i = 0; i < count; i++) { const OFSocketAddress *address = [addresses itemAtIndex: i]; if (!*firstAddress) [string appendString: @", "]; *firstAddress = false; [string appendString: OFSocketAddressString(address)]; } } #endif @implementation OFSystemInfoTests + (OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, id) *) *)summary { OFMutableArray *summary = [OFMutableArray array]; #ifdef OF_HAVE_SOCKETS OFDictionary *networkInterfaces; OFMutableString *networkInterfacesString; bool firstInterface = true; #endif #define ADD(name, value) \ [summary addObject: [OFPair pairWithFirstObject: name \ secondObject: value]]; #define ADD_UINT(name, value) \ ADD(name, [OFNumber numberWithUnsignedInt: value]); #define ADD_ULONGLONG(name, value) \ ADD(name, [OFNumber numberWithUnsignedLongLong: value]); #define ADD_BOOL(name, value) \ ADD(name, [OFNumber numberWithBool: value]); ADD(@"ObjFW version", [OFSystemInfo ObjFWVersion]) ADD_UINT(@"ObjFW version major", [OFSystemInfo ObjFWVersionMajor]) ADD_UINT(@"ObjFW version minor", [OFSystemInfo ObjFWVersionMinor]) ADD(@"Operating system name", [OFSystemInfo operatingSystemName]); ADD(@"Operating system version", [OFSystemInfo operatingSystemVersion]); #ifdef OF_WINDOWS ADD(@"Wine version", [OFSystemInfo wineVersion]); #endif ADD_ULONGLONG(@"Page size", [OFSystemInfo pageSize]); ADD_ULONGLONG(@"Number of CPUs", [OFSystemInfo numberOfCPUs]); ADD(@"User config IRI", [OFSystemInfo userConfigIRI].string); ADD(@"User data IRI", [OFSystemInfo userDataIRI].string); ADD(@"Temporary directory IRI", [OFSystemInfo temporaryDirectoryIRI].string); ADD(@"CPU vendor", [OFSystemInfo CPUVendor]); ADD(@"CPU model", [OFSystemInfo CPUModel]); #if defined(OF_AMD64) || defined(OF_X86) ADD_BOOL(@"Supports MMX", [OFSystemInfo supportsMMX]); ADD_BOOL(@"Supports 3DNow!", [OFSystemInfo supports3DNow]); ADD_BOOL(@"Supports enhanced 3DNow!", [OFSystemInfo supportsEnhanced3DNow]); ADD_BOOL(@"Supports SSE", [OFSystemInfo supportsSSE]); ADD_BOOL(@"Supports SSE2", [OFSystemInfo supportsSSE2]); ADD_BOOL(@"Supports SSE3", [OFSystemInfo supportsSSE3]); ADD_BOOL(@"Supports SSSE3", [OFSystemInfo supportsSSSE3]); ADD_BOOL(@"Supports SSE4.1", [OFSystemInfo supportsSSE41]); ADD_BOOL(@"Supports SSE4.2", [OFSystemInfo supportsSSE42]); ADD_BOOL(@"Supports AVX", [OFSystemInfo supportsAVX]); ADD_BOOL(@"Supports AVX2", [OFSystemInfo supportsAVX2]); ADD_BOOL(@"Supports AES-NI", [OFSystemInfo supportsAESNI]); ADD_BOOL(@"Supports SHA extensions", [OFSystemInfo supportsSHAExtensions]); ADD_BOOL(@"Supports fused multiply-add", [OFSystemInfo supportsFusedMultiplyAdd]); ADD_BOOL(@"Supports F16C", [OFSystemInfo supportsF16C]); ADD_BOOL(@"Supports AVX-512 Foundation", [OFSystemInfo supportsAVX512Foundation]); ADD_BOOL(@"Supports AVX-512 Conflict Detection Instructions", [OFSystemInfo supportsAVX512ConflictDetectionInstructions]); ADD_BOOL(@"Supports AVX-512 Exponential and Reciprocal Instructions", [OFSystemInfo supportsAVX512ExponentialAndReciprocalInstructions]); ADD_BOOL(@"Supports AVX-512 Prefetch Instructions", [OFSystemInfo supportsAVX512PrefetchInstructions]); ADD_BOOL(@"Supports AVX-512 Vector Length Extensions", [OFSystemInfo supportsAVX512VectorLengthExtensions]); ADD_BOOL(@"Supports AVX-512 Doubleword and Quadword Instructions", [OFSystemInfo supportsAVX512DoublewordAndQuadwordInstructions]); ADD_BOOL(@"Supports AVX-512 Byte and Word Instructions", [OFSystemInfo supportsAVX512ByteAndWordInstructions]); ADD_BOOL(@"Supports AVX-512 Integer Fused Multiply Add", [OFSystemInfo supportsAVX512IntegerFusedMultiplyAdd]); ADD_BOOL(@"Supports AVX-512 Vector Byte Manipulation Instructions", [OFSystemInfo supportsAVX512VectorByteManipulationInstructions]); ADD_BOOL(@"Supports AVX-512 Vector Population Count Instruction", [OFSystemInfo supportsAVX512VectorPopulationCountInstruction]); ADD_BOOL(@"Supports AVX-512 Vector Neutral Network Instructions", [OFSystemInfo supportsAVX512VectorNeuralNetworkInstructions]); ADD_BOOL(@"Supports AVX-512 Vector Byte Manipulation Instructions 2", [OFSystemInfo supportsAVX512VectorByteManipulationInstructions2]); ADD_BOOL(@"Supports AVX-512 Bit Algorithms", [OFSystemInfo supportsAVX512BitAlgorithms]); ADD_BOOL(@"Supports AVX-512 Float16 Instructions", [OFSystemInfo supportsAVX512Float16Instructions]); ADD_BOOL(@"Supports AVX-512 BFloat16 Instructions", [OFSystemInfo supportsAVX512BFloat16Instructions]); #endif #ifdef OF_POWERPC ADD_BOOL(@"Supports AltiVec", [OFSystemInfo supportsAltiVec]); #endif #undef ADD #undef ADD_UINT #undef ADD_ULONGLONG #undef ADD_BOOL #ifdef OF_HAVE_SOCKETS networkInterfaces = [OFSystemInfo networkInterfaces]; networkInterfacesString = [OFMutableString string]; for (OFString *name in networkInterfaces) { bool firstAddress = true; OFNetworkInterface interface; OFData *hardwareAddress; if (!firstInterface) [networkInterfacesString appendString: @"; "]; firstInterface = false; [networkInterfacesString appendFormat: @"%@(", name]; interface = [networkInterfaces objectForKey: name]; appendAddresses(networkInterfacesString, [interface objectForKey: OFNetworkInterfaceIPv4Addresses], &firstAddress); # ifdef OF_HAVE_IPV6 appendAddresses(networkInterfacesString, [interface objectForKey: OFNetworkInterfaceIPv6Addresses], &firstAddress); # endif # ifdef OF_HAVE_IPX appendAddresses(networkInterfacesString, [interface objectForKey: OFNetworkInterfaceIPXAddresses], &firstAddress); # endif # ifdef OF_HAVE_APPLETALK appendAddresses(networkInterfacesString, [interface objectForKey: OFNetworkInterfaceAppleTalkAddresses], &firstAddress); # endif hardwareAddress = [interface objectForKey: OFNetworkInterfaceHardwareAddress]; if (hardwareAddress != nil) { const unsigned char *bytes = hardwareAddress.items; size_t length = hardwareAddress.count; if (!firstAddress) [networkInterfacesString appendString: @", "]; for (size_t i = 0; i < length; i++) { if (i > 0) [networkInterfacesString appendString: @":"]; [networkInterfacesString appendFormat: @"%02X", bytes[i]]; } } [networkInterfacesString appendString: @")"]; } [summary addObject: [OFPair pairWithFirstObject: @"Network interfaces" secondObject: networkInterfacesString]]; #endif return summary; } @end objfw-1.1.6/tests/OFTCPSocketTests.m000066400000000000000000000027141465614216400172320ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "ObjFW.h" #import "ObjFWTest.h" @interface OFTCPSocketTests: OTTestCase @end @implementation OFTCPSocketTests - (void)testTCPSocket { OFTCPSocket *server, *client, *accepted; OFSocketAddress address; char buffer[6]; server = [OFTCPSocket socket]; client = [OFTCPSocket socket]; address = [server bindToHost: @"127.0.0.1" port: 0]; [server listen]; [client connectToHost: @"127.0.0.1" port: OFSocketAddressIPPort(&address)]; accepted = [server accept]; OTAssertEqualObjects(OFSocketAddressString(accepted.remoteAddress), @"127.0.0.1"); [client writeString: @"Hello!"]; [accepted readIntoBuffer: buffer exactLength: 6]; OTAssertEqual(memcmp(buffer, "Hello!", 6), 0); } @end objfw-1.1.6/tests/OFTarArchiveTests.m000066400000000000000000000040331465614216400174570ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" #define bufferSize 4096 @interface OFTarArchiveTests: OTTestCase { char _buffer[bufferSize]; } @end @implementation OFTarArchiveTests - (void)testCreateAndExtractArchive { OFMemoryStream *stream = [OFMemoryStream streamWithMemoryAddress: _buffer size: bufferSize writable: true]; OFTarArchive *archive = [OFTarArchive archiveWithStream: stream mode: @"w"]; OFMutableTarArchiveEntry *entry = [OFMutableTarArchiveEntry entryWithFileName: @"testfile.txt"]; OFTarArchiveEntry *entry2; OFStream *entryStream; size_t size; entry.uncompressedSize = 12; entryStream = [archive streamForWritingEntry: entry]; [entryStream writeString: @"Hello World!"]; [archive close]; size = (size_t)[stream seekToOffset: 0 whence: OFSeekCurrent]; OTAssertLessThanOrEqual(size, bufferSize); stream = [OFMemoryStream streamWithMemoryAddress: _buffer size: size writable: false]; archive = [OFTarArchive archiveWithStream: stream mode: @"r"]; entry2 = [archive nextEntry]; OTAssertEqualObjects(entry2.fileName, @"testfile.txt"); entryStream = [archive streamForReadingCurrentEntry]; OTAssertEqualObjects([entryStream readLine], @"Hello World!"); OTAssertNil([entryStream readLine]); OTAssertNil([archive nextEntry]); } @end objfw-1.1.6/tests/OFThreadTests.m000066400000000000000000000024631465614216400166430ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" @interface OFThreadTests: OTTestCase @end @interface TestThread: OFThread @end @implementation TestThread - (id)main { [[OFThread threadDictionary] setObject: @"bar" forKey: @"foo"]; OFEnsure([[[OFThread threadDictionary] objectForKey: @"foo"] isEqual: @"bar"]); return @"success"; } @end @implementation OFThreadTests - (void)testThread { TestThread *thread = [TestThread thread]; [thread start]; OTAssertEqualObjects([thread join], @"success"); OTAssertNil([[OFThread threadDictionary] objectForKey: @"foo"]); } @end objfw-1.1.6/tests/OFUDPSocketTests.m000066400000000000000000000027121465614216400172320ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "ObjFW.h" #import "ObjFWTest.h" @interface OFUDPSocketTests: OTTestCase @end @implementation OFUDPSocketTests - (void)testUDPSocket { OFUDPSocket *sock = [OFUDPSocket socket]; OFSocketAddress addr1, addr2; char buffer[6]; sock = [OFUDPSocket socket]; addr1 = [sock bindToHost: @"127.0.0.1" port: 0]; OTAssertEqualObjects(OFSocketAddressString(&addr1), @"127.0.0.1"); [sock sendBuffer: "Hello" length: 6 receiver: &addr1]; [sock receiveIntoBuffer: buffer length: 6 sender: &addr2]; OTAssertEqual(memcmp(buffer, "Hello", 6), 0); OTAssertEqualObjects(OFSocketAddressString(&addr2), @"127.0.0.1"); OTAssertEqual(OFSocketAddressIPPort(&addr2), OFSocketAddressIPPort(&addr1)); } @end objfw-1.1.6/tests/OFUNIXDatagramSocketTests.m000066400000000000000000000043711465614216400210310ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "ObjFW.h" #import "ObjFWTest.h" @interface OFUNIXDatagramSocketTests: OTTestCase @end @implementation OFUNIXDatagramSocketTests - (void)testUNIXDatagramSocket { OFUNIXDatagramSocket *sock = [OFUNIXDatagramSocket socket]; OFString *path; OFSocketAddress address1, address2; char buffer[5]; #if defined(OF_HAVE_FILES) && !defined(OF_IOS) path = [[OFSystemInfo temporaryDirectoryIRI] IRIByAppendingPathComponent: [[OFUUID UUID] UUIDString]] .fileSystemRepresentation; #else /* * We can have sockets, including UNIX sockets, while file support is * disabled. * * We also use this code path for iOS, as the temporaryDirectoryIRI is * too long on the iOS simulator. */ path = [OFString stringWithFormat: @"/tmp/%@", [[OFUUID UUID] UUIDString]]; #endif @try { address1 = [sock bindToPath: path]; } @catch (OFBindSocketFailedException *e) { switch (e.errNo) { case EAFNOSUPPORT: case EPERM: OTSkip(@"UNIX datagram sockets unsupported"); default: @throw e; } } @try { [sock sendBuffer: "Hello" length: 5 receiver: &address1]; OTAssertEqual([sock receiveIntoBuffer: buffer length: 5 sender: &address2], 5); OTAssertEqual(memcmp(buffer, "Hello", 5), 0); OTAssertTrue(OFSocketAddressEqual(&address1, &address2)); OTAssertEqual(OFSocketAddressHash(&address1), OFSocketAddressHash(&address2)); } @finally { #ifdef OF_HAVE_FILES [[OFFileManager defaultManager] removeItemAtPath: path]; #endif } } @end objfw-1.1.6/tests/OFUNIXStreamSocketTests.m000066400000000000000000000044241465614216400205430ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "ObjFW.h" #import "ObjFWTest.h" @interface OFUNIXStreamSocketTests: OTTestCase @end @implementation OFUNIXStreamSocketTests - (void)testUNIXStreamSocket { OFString *path; OFUNIXStreamSocket *sockClient, *sockServer, *sockAccepted; char buffer[5]; #if defined(OF_HAVE_FILES) && !defined(OF_IOS) path = [[OFSystemInfo temporaryDirectoryIRI] IRIByAppendingPathComponent: [[OFUUID UUID] UUIDString]] .fileSystemRepresentation; #else /* * We can have sockets, including UNIX sockets, while file support is * disabled. * * We also use this code path for iOS, as the temporaryDirectory:RI is * too long on the iOS simulator. */ path = [OFString stringWithFormat: @"/tmp/%@", [[OFUUID UUID] UUIDString]]; #endif sockClient = [OFUNIXStreamSocket socket]; sockServer = [OFUNIXStreamSocket socket]; @try { [sockServer bindToPath: path]; } @catch (OFBindSocketFailedException *e) { switch (e.errNo) { case EAFNOSUPPORT: case EPERM: OTSkip(@"UNIX stream sockets unsupported"); default: @throw e; } } @try { [sockServer listen]; [sockClient connectToPath: path]; sockAccepted = [sockServer accept]; [sockAccepted writeBuffer: "Hello" length: 5]; OTAssertEqual([sockClient readIntoBuffer: buffer length: 5], 5); OTAssertEqual(memcmp(buffer, "Hello", 5), 0); OTAssertEqual(OFSocketAddressUNIXPath( sockAccepted.remoteAddress).length, 0); } @finally { #ifdef OF_HAVE_FILES [[OFFileManager defaultManager] removeItemAtPath: path]; #endif } } @end objfw-1.1.6/tests/OFUTF8StringTests.m000066400000000000000000000016651465614216400173540ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFStringTests.h" #import "OFUTF8String.h" @interface OFUTF8StringTests: OFStringTests @end @implementation OFUTF8StringTests - (Class)arrayClass { return [OFUTF8String class]; } @end objfw-1.1.6/tests/OFValueTests.m000066400000000000000000000116541465614216400165120ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "ObjFW.h" #import "ObjFWTest.h" @interface OFValueTests: OTTestCase @end @implementation OFValueTests - (void)testObjCType { OFRange range = OFMakeRange(1, 64); OFValue *value = [OFValue valueWithBytes: &range objCType: @encode(OFRange)]; OTAssertEqual(strcmp(value.objCType, @encode(OFRange)), 0); } - (void)testGetValueSize { OFRange range = OFMakeRange(1, 64), range2; OFValue *value = [OFValue valueWithBytes: &range objCType: @encode(OFRange)]; [value getValue: &range2 size: sizeof(OFRange)]; OTAssert(OFEqualRanges(range2, range)); } - (void)testGetValueSizeThrowsOnWrongSize { OFRange range = OFMakeRange(1, 64); OFValue *value = [OFValue valueWithBytes: &range objCType: @encode(OFRange)]; OTAssertThrowsSpecific( [value getValue: &range size: sizeof(OFRange) - 1], OFOutOfRangeException); } - (void)testPointer { void *pointer = &pointer; OFValue *value = [OFValue valueWithPointer: pointer]; OTAssertEqual(value.pointerValue, pointer); OTAssertEqual([[OFValue valueWithBytes: &pointer objCType: @encode(void *)] pointerValue], pointer); OTAssertThrowsSpecific( [[OFValue valueWithBytes: "a" objCType: @encode(char)] pointerValue], OFOutOfRangeException); } - (void)testNonretainedObject { id object = (id)&object; OFValue *value = [OFValue valueWithNonretainedObject: object]; OTAssertEqual(value.nonretainedObjectValue, object); OTAssertEqual([[OFValue valueWithBytes: &object objCType: @encode(id)] nonretainedObjectValue], object); OTAssertThrowsSpecific( [[OFValue valueWithBytes: "a" objCType: @encode(char)] nonretainedObjectValue], OFOutOfRangeException); } - (void)testRange { OFRange range = OFMakeRange(1, 64), range2; OFValue *value = [OFValue valueWithRange: range]; OTAssert(OFEqualRanges(value.rangeValue, range)); OTAssert(OFEqualRanges( [[OFValue valueWithBytes: &range objCType: @encode(OFRange)] rangeValue], range)); [value getValue: &range2 size: sizeof(range2)]; OTAssert(OFEqualRanges(range2, range)); OTAssertThrowsSpecific( [[OFValue valueWithBytes: "a" objCType: @encode(char)] rangeValue], OFOutOfRangeException); } - (void)testPoint { OFPoint point = OFMakePoint(1.5f, 3.0f), point2; OFValue *value = [OFValue valueWithPoint: point]; OTAssert(OFEqualPoints(value.pointValue, point)); OTAssert(OFEqualPoints( [[OFValue valueWithBytes: &point objCType: @encode(OFPoint)] pointValue], point)); [value getValue: &point2 size: sizeof(point2)]; OTAssert(OFEqualPoints(point2, point)); OTAssertThrowsSpecific( [[OFValue valueWithBytes: "a" objCType: @encode(char)] pointValue], OFOutOfRangeException); } - (void)testSize { OFSize size = OFMakeSize(4.5f, 5.0f), size2; OFValue *value = [OFValue valueWithSize: size]; OTAssert(OFEqualSizes(value.sizeValue, size)); OTAssert(OFEqualSizes( [[OFValue valueWithBytes: &size objCType: @encode(OFSize)] sizeValue], size)); [value getValue: &size2 size: sizeof(size2)]; OTAssert(OFEqualSizes(size2, size)); OTAssertThrowsSpecific( [[OFValue valueWithBytes: "a" objCType: @encode(char)] sizeValue], OFOutOfRangeException); } - (void)testRect { OFRect rect = OFMakeRect(1.5f, 3.0f, 4.5f, 6.0f), rect2; OFValue *value = [OFValue valueWithRect: rect]; OTAssert(OFEqualRects(value.rectValue, rect)); OTAssert(OFEqualRects( [[OFValue valueWithBytes: &rect objCType: @encode(OFRect)] rectValue], rect)); [value getValue: &rect2 size: sizeof(rect2)]; OTAssert(OFEqualRects(rect2, rect)); OTAssertThrowsSpecific( [[OFValue valueWithBytes: "a" objCType: @encode(char)] rectValue], OFOutOfRangeException); } - (void)testIsEqual { OFRect rect = OFMakeRect(1.5f, 3.0f, 4.5f, 6.0f); OTAssertEqualObjects([OFValue valueWithRect: rect], [OFValue valueWithBytes: &rect objCType: @encode(OFRect)]); OTAssertNotEqualObjects( [OFValue valueWithBytes: "a" objCType: @encode(signed char)], [OFValue valueWithBytes: "a" objCType: @encode(unsigned char)]); OTAssertNotEqualObjects( [OFValue valueWithBytes: "a" objCType: @encode(char)], [OFValue valueWithBytes: "b" objCType: @encode(char)]); } @end objfw-1.1.6/tests/OFWindowsRegistryKeyTests.m000066400000000000000000000063361465614216400212730ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" @interface OFWindowsRegistryKeyTests: OTTestCase { OFWindowsRegistryKey *_softwareKey, *_objFWKey; } @end @implementation OFWindowsRegistryKeyTests - (void)setUp { [super setUp]; _softwareKey = [[[OFWindowsRegistryKey currentUserKey] openSubkeyAtPath: @"Software" accessRights: KEY_ALL_ACCESS options: 0] retain]; _objFWKey = [[_softwareKey createSubkeyAtPath: @"ObjFW" accessRights: KEY_ALL_ACCESS securityAttributes: NULL options: 0 disposition: NULL] retain]; } - (void)tearDown { [_softwareKey deleteSubkeyAtPath: @"ObjFW"]; [super tearDown]; } - (void)dealloc { [_softwareKey release]; [_objFWKey release]; [super dealloc]; } - (void)testClassesRootKey { OTAssertEqual([[OFWindowsRegistryKey classesRootKey] class], [OFWindowsRegistryKey class]); } - (void)testCurrentConfigKey { OTAssertEqual([[OFWindowsRegistryKey currentConfigKey] class], [OFWindowsRegistryKey class]); } - (void)testCurrentUserKey { OTAssertEqual([[OFWindowsRegistryKey currentUserKey] class], [OFWindowsRegistryKey class]); } - (void)testLocalMachineKey { OTAssertEqual([[OFWindowsRegistryKey localMachineKey] class], [OFWindowsRegistryKey class]); } - (void)testOpenSubkeyAtPathAccessRightsOptionsThrowsForNonExistentKey { OTAssertThrowsSpecific([[OFWindowsRegistryKey currentUserKey] openSubkeyAtPath: @"nonexistent" accessRights: KEY_ALL_ACCESS options: 0], OFOpenWindowsRegistryKeyFailedException); } - (void)testSetAndGetData { OFData *data = [OFData dataWithItems: "abcdef" count: 6]; DWORD type; [_objFWKey setData: data forValueNamed: @"data" type: REG_BINARY]; OTAssertEqualObjects([_objFWKey dataForValueNamed: @"data" type: &type], data); OTAssertEqual(type, REG_BINARY); } - (void)testSetAndGetString { DWORD type; [_objFWKey setString: @"foobar" forValueNamed: @"string"]; OTAssertEqualObjects([_objFWKey stringForValueNamed: @"string"], @"foobar"); [_objFWKey setString: @"%PATH%;foo" forValueNamed: @"expand" type: REG_EXPAND_SZ]; OTAssertEqualObjects([_objFWKey stringForValueNamed: @"expand" type: &type], @"%PATH%;foo"); OTAssertEqual(type, REG_EXPAND_SZ); } - (void)testDeleteValue { [_objFWKey setString: @"foobar" forValueNamed: @"deleteme"]; OTAssertEqualObjects([_objFWKey stringForValueNamed: @"deleteme"], @"foobar"); [_objFWKey deleteValueNamed: @"deleteme"]; OTAssertNil([_objFWKey stringForValueNamed: @"deleteme"]); } @end objfw-1.1.6/tests/OFXMLElementBuilderTests.m000066400000000000000000000035671465614216400207230ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" @interface OFXMLElementBuilderTests: OTTestCase { OFXMLNode *_nodes[2]; size_t _i; } @end @implementation OFXMLElementBuilderTests - (void)dealloc { [_nodes[0] release]; [_nodes[1] release]; [super dealloc]; } - (void)elementBuilder: (OFXMLElementBuilder *)builder didBuildElement: (OFXMLElement *)element { OTAssertEqual(_i, 0); _nodes[_i++] = [element retain]; } - (void)elementBuilder: (OFXMLElementBuilder *)builder didBuildOrphanNode: (OFXMLNode *)node { OTAssertEqual(_i, 1); _nodes[_i++] = [node retain]; } - (void)testElementBuilder { OFXMLParser *parser = [OFXMLParser parser]; OFXMLElementBuilder *builder = [OFXMLElementBuilder builder]; OFString *string = @"barbaz" " " ""; parser.delegate = builder; builder.delegate = self; [parser parseString: string]; OTAssertEqualObjects(_nodes[0].XMLString, string); [parser parseString: @""]; OTAssertEqualObjects(_nodes[1].XMLString, @""); OTAssertEqual(_i, 2); } @end objfw-1.1.6/tests/OFXMLNodeTests.m000066400000000000000000000143601465614216400167010ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" @interface OFXMLNodeTests: OTTestCase @end @implementation OFXMLNodeTests - (void)testElementWithName { OTAssertEqualObjects( [[OFXMLElement elementWithName: @"foo"] XMLString], @""); } - (void)testElementWithNameStringValue { OTAssertEqualObjects( [[OFXMLElement elementWithName: @"foo" stringValue: @"b&ar"] XMLString], @"b&ar"); } - (void)testElementWithNameNamespace { OFXMLElement *element; element = [OFXMLElement elementWithName: @"foo" namespace: @"urn:objfw:test"]; [element addAttributeWithName: @"test" stringValue: @"test"]; [element setPrefix: @"objfw-test" forNamespace: @"urn:objfw:test"]; OTAssertEqualObjects(element.XMLString, @""); element = [OFXMLElement elementWithName: @"foo" namespace: @"urn:objfw:test"]; [element addAttributeWithName: @"test" stringValue: @"test"]; OTAssertEqualObjects(element.XMLString, @""); } - (void)testElementWithNameNamespaceStringValue { OFXMLElement *element = [OFXMLElement elementWithName: @"foo" namespace: @"urn:objfw:test" stringValue: @"x"]; [element setPrefix: @"objfw-test" forNamespace: @"urn:objfw:test"]; OTAssertEqualObjects(element.XMLString, @"x"); } - (void)testElementWithXMLStringAndStringValue { OTAssertEqualObjects([[OFXMLElement elementWithXMLString: @"\r\nfoo" @"bazqux"] stringValue], @"foobarbazqux"); } - (void)testCharactersWithString { OTAssertEqualObjects( [[OFXMLCharacters charactersWithString: @""] XMLString], @"<foo>"); } - (void)testCDATAWithString { OTAssertEqualObjects( [[OFXMLCDATA CDATAWithString: @""] XMLString], @"]]>"); } - (void)testCommentWithText { OTAssertEqualObjects( [[OFXMLComment commentWithText: @" comment "] XMLString], @""); } - (void)testIsEqual { OTAssertEqualObjects( [OFXMLElement elementWithXMLString: @""], [OFXMLElement elementWithXMLString: @""]); OTAssertEqualObjects( [OFXMLElement elementWithXMLString: @""], [OFXMLElement elementWithXMLString: @""]); OTAssertNotEqualObjects( [OFXMLElement elementWithXMLString: @""], [OFXMLElement elementWithXMLString: @""]); } - (void)testHash { OTAssertEqual( [[OFXMLElement elementWithXMLString: @""] hash], [[OFXMLElement elementWithXMLString: @""] hash]); OTAssertEqual( [[OFXMLElement elementWithXMLString: @""] hash], [[OFXMLElement elementWithXMLString: @""] hash]); OTAssertNotEqual( [[OFXMLElement elementWithXMLString: @""] hash], [[OFXMLElement elementWithXMLString: @""] hash]); } - (void)testAddAttributeWithNameStringValue { OFXMLElement *element = [OFXMLElement elementWithName: @"foo" stringValue: @"b&ar"]; [element setPrefix: @"objfw-test" forNamespace: @"urn:objfw:test"]; [element addAttributeWithName: @"foo" stringValue: @"b&ar"]; [element addAttributeWithName: @"foo" namespace: @"urn:objfw:test" stringValue: @"bar"]; OTAssertEqualObjects(element.XMLString, @"b&ar"); } - (void)testRemoveAttributeForNameNamespace { OFXMLElement *element = [OFXMLElement elementWithName: @"foo" stringValue: @"b&ar"]; [element setPrefix: @"objfw-test" forNamespace: @"urn:objfw:test"]; [element addAttributeWithName: @"foo" stringValue: @"b&ar"]; [element addAttributeWithName: @"foo" namespace: @"urn:objfw:test" stringValue: @"bar"]; [element removeAttributeForName: @"foo"]; OTAssertEqualObjects(element.XMLString, @"b&ar"); [element removeAttributeForName: @"foo" namespace: @"urn:objfw:test"]; OTAssertEqualObjects(element.XMLString, @"b&ar"); } - (void)testAddChild { OFXMLElement *element; element = [OFXMLElement elementWithName: @"foo"]; [element addAttributeWithName: @"foo" stringValue: @"b&ar"]; [element addChild: [OFXMLElement elementWithName: @"bar"]]; OTAssertEqualObjects(element.XMLString, @""); element = [OFXMLElement elementWithName: @"foo" namespace: @"urn:objfw:test"]; [element setPrefix: @"objfw-test" forNamespace: @"urn:objfw:test"]; [element addAttributeWithName: @"test" stringValue: @"test"]; [element addChild: [OFXMLElement elementWithName: @"bar" namespace: @"urn:objfw:test"]]; OTAssertEqualObjects(element.XMLString, @""); } - (void)testElementsForNameNamespace { OFXMLElement *element = [OFXMLElement elementWithName: @"foo"]; OFXMLElement *bar; [element addChild: [OFXMLElement elementWithName: @"foo"]]; bar = [OFXMLElement elementWithName: @"bar" namespace: @"urn:objfw:test"]; [element addChild: bar]; OTAssertEqualObjects([element elementsForName: @"bar" namespace: @"urn:objfw:test"], [OFArray arrayWithObject: bar]); } - (void)testXMLStringWithIndentation { OTAssertEqualObjects([[OFXMLElement elementWithXMLString: @"a\nb"] XMLStringWithIndentation: 2], @"\n \n a\nb\n \n \n"); } @end objfw-1.1.6/tests/OFXMLParserTests.m000066400000000000000000000266341465614216400172570ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #include #import "ObjFW.h" #import "ObjFWTest.h" @interface OFXMLParserTests: OTTestCase { int _i; } @end enum EventType { eventTypeProcessingInstruction, eventTypeTagOpen, eventTypeTagClose, eventTypeString, eventTypeCDATA, eventTypeComment }; @implementation OFXMLParserTests - (void)parser: (OFXMLParser *)parser didCreateEvent: (enum EventType)type name: (OFString *)name prefix: (OFString *)prefix namespace: (OFString *)namespace attributes: (OFArray *)attrs string: (OFString *)string { switch (_i++) { case 0: OTAssertEqual(type, eventTypeProcessingInstruction); OTAssertEqualObjects(name, @"xml"); OTAssertEqualObjects(string, @"version='1.0'"); break; case 1: OTAssertEqual(type, eventTypeProcessingInstruction); OTAssertEqualObjects(name, @"p?i"); OTAssertNil(string); break; case 2: OTAssertEqual(type, eventTypeTagOpen); OTAssertEqualObjects(name, @"root"); OTAssertNil(prefix); OTAssertNil(namespace); OTAssertEqual(attrs.count, 0); break; case 3: OTAssertEqual(type, eventTypeString); OTAssertEqualObjects(string, @"\n\n "); break; case 4: OTAssertEqual(type, eventTypeCDATA); OTAssertEqualObjects(string, @"f<]]]oo]"); OTAssertEqual(parser.lineNumber, 3); break; case 5: OTAssertEqual(type, eventTypeTagOpen); OTAssertEqualObjects(name, @"bar"); OTAssertNil(prefix); OTAssertNil(namespace); OTAssertNil(attrs); break; case 6: OTAssertEqual(type, eventTypeTagClose); OTAssertEqualObjects(name, @"bar"); OTAssertNil(prefix); OTAssertNil(namespace); OTAssertNil(attrs); break; case 7: OTAssertEqual(type, eventTypeString); OTAssertEqualObjects(string, @"\n "); break; case 8: OTAssertEqual(type, eventTypeTagOpen); OTAssertEqualObjects(name, @"foobar"); OTAssertNil(prefix); OTAssertEqualObjects(namespace, @"urn:objfw:test:foobar"); OTAssertEqualObjects(attrs, [OFArray arrayWithObject: [OFXMLAttribute attributeWithName: @"xmlns" stringValue: @"urn:objfw:test:" @"foobar"]]); break; case 9: OTAssertEqual(type, eventTypeString); OTAssertEqualObjects(string, @"\n "); break; case 10: OTAssertEqual(type, eventTypeTagOpen); OTAssertEqualObjects(name, @"qux"); OTAssertNil(prefix); OTAssertEqualObjects(namespace, @"urn:objfw:test:foobar"); OTAssertEqualObjects(attrs, [OFArray arrayWithObject: [OFXMLAttribute attributeWithName: @"foo" namespace: @"http://www.w3.org/" @"2000/xmlns/" stringValue: @"urn:objfw:test:foo"]]); break; case 11: OTAssertEqual(type, eventTypeString); OTAssertEqualObjects(string, @"\n "); break; case 12: OTAssertEqual(type, eventTypeTagOpen); OTAssertEqualObjects(name, @"bla"); OTAssertEqualObjects(prefix, @"foo"); OTAssertEqualObjects(namespace, @"urn:objfw:test:foo"); OTAssertEqualObjects(attrs, ([OFArray arrayWithObjects: [OFXMLAttribute attributeWithName: @"bla" namespace: @"urn:objfw:test:foo" stringValue: @"bla"], [OFXMLAttribute attributeWithName: @"blafoo" stringValue: @"foo"], nil])); break; case 13: OTAssertEqual(type, eventTypeString); OTAssertEqualObjects(string, @"\n "); break; case 14: OTAssertEqual(type, eventTypeTagOpen); OTAssertEqualObjects(name, @"blup"); OTAssertNil(prefix); OTAssertEqualObjects(namespace, @"urn:objfw:test:foobar"); OTAssertEqualObjects(attrs, ([OFArray arrayWithObjects: [OFXMLAttribute attributeWithName: @"qux" namespace: @"urn:objfw:test:foo" stringValue: @"asd"], [OFXMLAttribute attributeWithName: @"quxqux" stringValue: @"test"], nil])); break; case 15: OTAssertEqual(type, eventTypeTagClose); OTAssertEqualObjects(name, @"blup"); OTAssertNil(prefix); OTAssertEqualObjects(namespace, @"urn:objfw:test:foobar"); break; case 16: OTAssertEqual(type, eventTypeString); OTAssertEqualObjects(string, @"\n "); break; case 17: OTAssertEqual(type, eventTypeTagOpen); OTAssertEqualObjects(name, @"bla"); OTAssertEqualObjects(prefix, @"bla"); OTAssertEqualObjects(namespace, @"urn:objfw:test:bla"); OTAssertEqualObjects(attrs, ([OFArray arrayWithObjects: [OFXMLAttribute attributeWithName: @"bla" namespace: @"http://www.w3.org/" @"2000/xmlns/" stringValue: @"urn:objfw:test:bla"], [OFXMLAttribute attributeWithName: @"qux" stringValue: @"qux"], [OFXMLAttribute attributeWithName: @"foo" namespace: @"urn:objfw:test:bla" stringValue: @"blafoo"], nil])); break; case 18: OTAssertEqual(type, eventTypeTagClose); OTAssertEqualObjects(name, @"bla"); OTAssertEqualObjects(prefix, @"bla"); OTAssertEqualObjects(namespace, @"urn:objfw:test:bla"); break; case 19: OTAssertEqual(type, eventTypeString); OTAssertEqualObjects(string, @"\n "); break; case 20: OTAssertEqual(type, eventTypeTagOpen); OTAssertEqualObjects(name, @"abc"); OTAssertNil(prefix); OTAssertEqualObjects(namespace, @"urn:objfw:test:abc"); OTAssertEqualObjects(attrs, ([OFArray arrayWithObjects: [OFXMLAttribute attributeWithName: @"xmlns" stringValue: @"urn:objfw:test:abc"], [OFXMLAttribute attributeWithName: @"abc" stringValue: @"abc"], [OFXMLAttribute attributeWithName: @"abc" namespace: @"urn:objfw:test:foo" stringValue: @"abc"], nil])); break; case 21: OTAssertEqual(type, eventTypeTagClose); OTAssertEqualObjects(name, @"abc"); OTAssertNil(prefix); OTAssertEqualObjects(namespace, @"urn:objfw:test:abc"); break; case 22: OTAssertEqual(type, eventTypeString); OTAssertEqualObjects(string, @"\n "); break; case 23: OTAssertEqual(type, eventTypeTagClose); OTAssertEqualObjects(name, @"bla"); OTAssertEqualObjects(prefix, @"foo"); OTAssertEqualObjects(namespace, @"urn:objfw:test:foo"); break; case 24: OTAssertEqual(type, eventTypeString); OTAssertEqualObjects(string, @"\n "); break; case 25: OTAssertEqual(type, eventTypeComment); OTAssertEqualObjects(string, @" commänt "); break; case 26: OTAssertEqual(type, eventTypeString); OTAssertEqualObjects(string, @"\n "); break; case 27: OTAssertEqual(type, eventTypeTagClose); OTAssertEqualObjects(name, @"qux"); OTAssertNil(prefix); OTAssertEqualObjects(namespace, @"urn:objfw:test:foobar"); break; case 28: OTAssertEqual(type, eventTypeString); OTAssertEqualObjects(string, @"\n "); break; case 29: OTAssertEqual(type, eventTypeTagClose); OTAssertEqualObjects(name, @"foobar"); OTAssertNil(prefix); OTAssertEqualObjects(namespace, @"urn:objfw:test:foobar"); break; case 30: OTAssertEqual(type, eventTypeString); OTAssertEqualObjects(string, @"\n"); break; case 31: OTAssertEqual(type, eventTypeTagClose); OTAssertEqualObjects(name, @"root"); OTAssertNil(prefix); OTAssertNil(namespace); break; } } - (void)parser: (OFXMLParser *)parser foundProcessingInstructionWithTarget: (OFString *)target text: (OFString *)text { [self parser: parser didCreateEvent: eventTypeProcessingInstruction name: target prefix: nil namespace: nil attributes: nil string: text]; } - (void)parser: (OFXMLParser *)parser didStartElement: (OFString *)name prefix: (OFString *)prefix namespace: (OFString *)namespace attributes: (OFArray *)attrs { [self parser: parser didCreateEvent: eventTypeTagOpen name: name prefix: prefix namespace: namespace attributes: attrs string: nil]; } - (void)parser: (OFXMLParser *)parser didEndElement: (OFString *)name prefix: (OFString *)prefix namespace: (OFString *)namespace { [self parser: parser didCreateEvent: eventTypeTagClose name: name prefix: prefix namespace: namespace attributes: nil string: nil]; } - (void)parser: (OFXMLParser *)parser foundCharacters: (OFString *)string { [self parser: parser didCreateEvent: eventTypeString name: nil prefix: nil namespace: nil attributes: nil string: string]; } - (void)parser: (OFXMLParser *)parser foundCDATA: (OFString *)CDATA { [self parser: parser didCreateEvent: eventTypeCDATA name: nil prefix: nil namespace: nil attributes: nil string: CDATA]; } - (void)parser: (OFXMLParser *)parser foundComment: (OFString *)comment { [self parser: parser didCreateEvent: eventTypeComment name: nil prefix: nil namespace: nil attributes: nil string: comment]; } - (OFString *)parser: (OFXMLParser *)parser foundUnknownEntityNamed: (OFString *)entity { if ([entity isEqual: @"foo"]) return @"foobar"; return nil; } - (void)testParser { static const char *string = "\xEF\xBB\xBF" "\r\r" " \n" " \r\n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" ""; OFXMLParser *parser; size_t j, length; parser = [OFXMLParser parser]; parser.delegate = self; /* Simulate a stream where we only get chunks */ length = strlen(string); for (j = 0; j < length; j+= 2) { if (parser.hasFinishedParsing) abort(); if (j + 2 > length) [parser parseBuffer: string + j length: 1]; else [parser parseBuffer: string + j length: 2]; } OTAssertEqual(_i, 32); OTAssertEqual(parser.lineNumber, 18); OTAssertTrue(parser.hasFinishedParsing); /* Parsing whitespaces after the document */ [parser parseString: @" \t\r\n "]; /* Parsing comments after the document */ [parser parseString: @" \t\r\n "]; /* Detection of junk after the document */ OTAssertThrowsSpecific([parser parseString: @"a"], OFMalformedXMLException); OTAssertThrowsSpecific([parser parseString: @""], OFMalformedXMLException); parser = [OFXMLParser parser]; OTAssertThrowsSpecific([parser parseString: @""], OFMalformedXMLException); } - (void)testDetectionOfInvalidEncoding { OFXMLParser *parser = [OFXMLParser parser]; OTAssertThrowsSpecific( [parser parseString: @""], OFInvalidEncodingException); } @end objfw-1.1.6/tests/OFZIPArchiveTests.m000066400000000000000000000037371465614216400174050ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" #define bufferSize 4096 @interface OFZIPArchiveTests: OTTestCase { char _buffer[bufferSize]; } @end @implementation OFZIPArchiveTests - (void)testCreateAndExtractArchive { OFMemoryStream *stream = [OFMemoryStream streamWithMemoryAddress: _buffer size: bufferSize writable: true]; OFZIPArchive *archive = [OFZIPArchive archiveWithStream: stream mode: @"w"]; OFZIPArchiveEntry *entry = [OFMutableZIPArchiveEntry entryWithFileName: @"testfile.txt"]; OFStream *entryStream = [archive streamForWritingEntry: entry]; size_t size; [entryStream writeString: @"Hello World!"]; [archive close]; size = (size_t)[stream seekToOffset: 0 whence: OFSeekCurrent]; OTAssertLessThanOrEqual(size, bufferSize); stream = [OFMemoryStream streamWithMemoryAddress: _buffer size: size writable: false]; archive = [OFZIPArchive archiveWithStream: stream mode: @"r"]; OTAssertEqual(archive.entries.count, 1); entry = archive.entries.firstObject; OTAssertEqualObjects(entry.fileName, @"testfile.txt"); entryStream = [archive streamForReadingFile: entry.fileName]; OTAssertEqualObjects([entryStream readLine], @"Hello World!"); OTAssertNil([entryStream readLine]); } @end objfw-1.1.6/tests/OFZooArchiveTests.m000066400000000000000000000037101465614216400175010ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" #define bufferSize 4096 @interface OFZooArchiveTests: OTTestCase { char _buffer[bufferSize]; } @end @implementation OFZooArchiveTests - (void)testCreateAndExtractArchive { OFMemoryStream *stream = [OFMemoryStream streamWithMemoryAddress: _buffer size: bufferSize writable: true]; OFZooArchive *archive = [OFZooArchive archiveWithStream: stream mode: @"w"]; OFZooArchiveEntry *entry = [OFMutableZooArchiveEntry entryWithFileName: @"testfile.txt"]; OFStream *entryStream = [archive streamForWritingEntry: entry]; size_t size; [entryStream writeString: @"Hello World!"]; [archive close]; size = (size_t)[stream seekToOffset: 0 whence: OFSeekCurrent]; OTAssertLessThanOrEqual(size, bufferSize); stream = [OFMemoryStream streamWithMemoryAddress: _buffer size: size writable: false]; archive = [OFZooArchive archiveWithStream: stream mode: @"r"]; entry = [archive nextEntry]; OTAssertEqualObjects(entry.fileName, @"testfile.txt"); entryStream = [archive streamForReadingCurrentEntry]; OTAssertEqualObjects([entryStream readLine], @"Hello World!"); OTAssertNil([entryStream readLine]); OTAssertNil([archive nextEntry]); } @end objfw-1.1.6/tests/RuntimeARCTests.m000066400000000000000000000030711465614216400171540ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" @interface RuntimeARCTests: OTTestCase @end @interface RuntimeARCTestClass: OFObject @end @implementation RuntimeARCTests - (void)testExceptionsDuringInit { OTAssertThrows((void)[[RuntimeARCTestClass alloc] init]); } - (void)testWeakReferences { id object = [[OFObject alloc] init]; __weak id weak = object; OTAssertEqual(weak, object); object = nil; OTAssertNil(weak); } @end @implementation RuntimeARCTestClass - (instancetype)init { self = [super init]; #if defined(OF_WINDOWS) && defined(OF_AMD64) /* * Clang has a bug on Windows where it creates an invalid call into * objc_retainAutoreleasedReturnValue(). Work around it by not using an * autoreleased exception. */ @throw [[OFException alloc] init]; #else @throw [OFException exception]; #endif return self; } @end objfw-1.1.6/tests/RuntimeTests.m000066400000000000000000000074631465614216400166370ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" #import "ObjFWTest.h" static void *testKey = &testKey; @interface RuntimeTestClass: OFObject { OFString *_foo, *_bar; } @property (nonatomic, copy) OFString *foo; @property (retain) OFString *bar; - (id)nilSuperTest; @end @interface RuntimeTests: OTTestCase { RuntimeTestClass *_test; } @end @interface OFObject (SuperTest) - (id)superTest; @end @implementation RuntimeTests - (void)setUp { [super setUp]; _test = [[RuntimeTestClass alloc] init]; } - (void)dealloc { [_test release]; [super dealloc]; } - (void)testCallNonExistentMethodViaSuper { OTAssertThrowsSpecific([_test superTest], OFNotImplementedException); } - (void)testCallMethodViaSuperWithNilSelf { OTAssertNil([_test nilSuperTest]); } - (void)testPropertyCopyNonatomic { OFMutableString *string = [OFMutableString stringWithString: @"foo"]; OFString *foo = @"foo"; _test.foo = string; OTAssertEqualObjects(_test.foo, foo); OTAssertNotEqual(_test.foo, foo); OTAssertEqual(_test.foo.retainCount, 1); } - (void)testPropertyRetainAtomic { OFMutableString *string = [OFMutableString stringWithString: @"foo"]; _test.bar = string; OTAssertEqual(_test.bar, string); OTAssertEqual(string.retainCount, 3); } - (void)testAssociatedObjects { objc_setAssociatedObject(self, testKey, _test, OBJC_ASSOCIATION_ASSIGN); OTAssertEqual(_test.retainCount, 1); objc_setAssociatedObject(self, testKey, _test, OBJC_ASSOCIATION_RETAIN); OTAssertEqual(_test.retainCount, 2); OTAssertEqual(objc_getAssociatedObject(self, testKey), _test); OTAssertEqual(_test.retainCount, 3); objc_setAssociatedObject(self, testKey, _test, OBJC_ASSOCIATION_ASSIGN); OTAssertEqual(_test.retainCount, 2); objc_setAssociatedObject(self, testKey, _test, OBJC_ASSOCIATION_RETAIN_NONATOMIC); OTAssertEqual(_test.retainCount, 3); OTAssertEqual(objc_getAssociatedObject(self, testKey), _test); OTAssertEqual(_test.retainCount, 3); objc_removeAssociatedObjects(self); OTAssertEqual(_test.retainCount, 2); } #ifdef OF_OBJFW_RUNTIME - (void)testTaggedPointers { int classID; uintmax_t value; id object; if (sizeof(uintptr_t) == 8) value = 0xDEADBEEFDEADBEF; else if (sizeof(uintptr_t) == 4) value = 0xDEADBEF; else OTAssert(sizeof(uintptr_t) == 8 || sizeof(uintptr_t) == 4); OTAssertNotEqual(objc_registerTaggedPointerClass([OFString class]), -1); classID = objc_registerTaggedPointerClass([OFNumber class]); OTAssertNotEqual(classID, -1); object = objc_createTaggedPointer(classID, (uintptr_t)value); OTAssertNotNil(object); OTAssertEqual(object_getClass(object), [OFNumber class]); OTAssertEqual([object class], [OFNumber class]); OTAssertEqual(object_getTaggedPointerValue(object), value); OTAssertNotNil(objc_createTaggedPointer(classID, UINTPTR_MAX >> 4)); OTAssertNil(objc_createTaggedPointer(classID, (UINTPTR_MAX >> 4) + 1)); } #endif @end @implementation RuntimeTestClass @synthesize foo = _foo; @synthesize bar = _bar; - (void)dealloc { [_foo release]; [_bar release]; [super dealloc]; } - (id)superTest { return [super superTest]; } - (id)nilSuperTest { self = nil; return [self superTest]; } @end objfw-1.1.6/tests/big_dictionary.msgpack000066400000000000000000013764111465614216400203530ustar00rootroot00000000000000  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~̴̴̵̵̶̶̷̷̸̸̡̡̢̢̧̧̨̨̛̛̖̖̗̗̘̘̙̙̜̜̝̝̞̞̟̟̠̠̣̣̤̤̥̥̦̦̩̩̪̪̫̫̬̬̭̭̮̮̯̯̰̰̱̱̲̲̳̳̹̹̺̺̻̻̼̼̀̀́́̂̂̃̃̄̄̅̅̆̆̇̇̈̈̉̉̊̊̋̋̌̌̍̍̎̎̏̏̐̐̑̑̒̒̓̓̔̔̽̽̾̾̿̿̕̕̚̚            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~                                                     ! ! " " # # $ $ % % & & ' ' ( ( ) ) * * + + , , - - . . / / 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 : : ; ; < < = = > > ? ? @ @ A A B B C C D D E E F F G G H H I I J J K K L L M M N N O O P P Q Q R R S S T T U U V V W W X X Y Y Z Z [ [ \ \ ] ] ^ ^ _ _ ` ` a a b b c c d d e e f f g g h h i i j j k k l l m m n n o o p p q q r r s s t t u u v v w w x x y y z z { { | | } } ~ ~                                                       ! ! " " # # $ $ % % & & ' ' ( ( ) ) * * + + , , - - . . / / 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 : : ; ; < < = = > > ? ? @ @ A A B B C C D D E E F F G G H H I I J J K K L L M M N N O O P P Q Q R R S S T T U U V V W W X X Y Y Z Z [ [ \ \ ] ] ^ ^ _ _ ` ` a a b b c c d d e e f f g g h h i i j j k k l l m m n n o o p p q q r r s s t t u u v v w w x x y y z z { { | | } } ~ ~                                                       ! ! " " # # $ $ % % & & ' ' ( ( ) ) * * + + , , - - . . / / 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 : : ; ; < < = = > > ? ? @ @ A A B B C C D D E E F F G G H H I I J J K K L L M M N N O O P P Q Q R R S S T T U U V V W W X X Y Y Z Z [ [ \ \ ] ] ^ ^ _ _ ` ` a a b b c c d d e e f f g g h h i i j j k k l l m m n n o o p p q q r r s s t t u u v v w w x x y y z z { { | | } } ~ ~                                                       ! ! " " # # $ $ % % & & ' ' ( ( ) ) * * + + , , - - . . / / 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 : : ; ; < < = = > > ? ? @ @ A A B B C C D D E E F F G G H H I I J J K K L L M M N N O O P P Q Q R R S S T T U U V V W W X X Y Y Z Z [ [ \ \ ] ] ^ ^ _ _ ` ` a a b b c c d d e e f f g g h h i i j j k k l l m m n n o o p p q q r r s s t t u u v v w w x x y y z z { { | | } } ~ ~                                                       ! ! " " # # $ $ % % & & ' ' ( ( ) ) * * + + , , - - . . / / 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 : : ; ; < < = = > > ? ? @ @ A A B B C C D D E E F F G G H H I I J J K K L L M M N N O O P P Q Q R R S S T T U U V V W W X X Y Y Z Z [ [ \ \ ] ] ^ ^ _ _ ` ` a a b b c c d d e e f f g g h h i i j j k k l l m m n n o o p p q q r r s s t t u u v v w w x x y y z z { { | | } } ~ ~               !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~                                                     ! ! " " # # $ $ % % & & ' ' ( ( ) ) * * + + , , - - . . / / 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 : : ; ; < < = = > > ? ? @ @ A A B B C C D D E E F F G G H H I I J J K K L L M M N N O O P P Q Q R R S S T T U U V V W W X X Y Y Z Z [ [ \ \ ] ] ^ ^ _ _ ` ` a a b b c c d d e e f f g g h h i i j j k k l l m m n n o o p p q q r r s s t t u u v v w w x x y y z z { { | | } } ~ ~   !!!!!!!!!!!!!!!!!!! ! ! ! ! ! ! ! ! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!"!"!#!#!$!$!%!%!&!&!'!'!(!(!)!)!*!*!+!+!,!,!-!-!.!.!/!/!0!0!1!1!2!2!3!3!4!4!5!5!6!6!7!7!8!8!9!9!:!:!;!;!!>!?!?!@!@!A!A!B!B!C!C!D!D!E!E!F!F!G!G!H!H!I!I!J!J!K!K!L!L!M!M!N!N!O!O!P!P!Q!Q!R!R!S!S!T!T!U!U!V!V!W!W!X!X!Y!Y!Z!Z![![!\!\!]!]!^!^!_!_!`!`!a!a!b!b!c!c!d!d!e!e!f!f!g!g!h!h!i!i!j!j!k!k!l!l!m!m!n!n!o!o!p!p!q!q!r!r!s!s!t!t!u!u!v!v!w!w!x!x!y!y!z!z!{!{!|!|!}!}!~!~!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!""""""""""""""""""" " " " " " " " " " """"""""""""""""""""""""""""""""""""" " "!"!"""""#"#"$"$"%"%"&"&"'"'"("(")")"*"*"+"+",","-"-"."."/"/"0"0"1"1"2"2"3"3"4"4"5"5"6"6"7"7"8"8"9"9":":";";"<"<"="=">">"?"?"@"@"A"A"B"B"C"C"D"D"E"E"F"F"G"G"H"H"I"I"J"J"K"K"L"L"M"M"N"N"O"O"P"P"Q"Q"R"R"S"S"T"T"U"U"V"V"W"W"X"X"Y"Y"Z"Z"["["\"\"]"]"^"^"_"_"`"`"a"a"b"b"c"c"d"d"e"e"f"f"g"g"h"h"i"i"j"j"k"k"l"l"m"m"n"n"o"o"p"p"q"q"r"r"s"s"t"t"u"u"v"v"w"w"x"x"y"y"z"z"{"{"|"|"}"}"~"~""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""################### # # # # # # # # # ##################################### # #!#!#"#"#####$#$#%#%#&#&#'#'#(#(#)#)#*#*#+#+#,#,#-#-#.#.#/#/#0#0#1#1#2#2#3#3#4#4#5#5#6#6#7#7#8#8#9#9#:#:#;#;#<#<#=#=#>#>#?#?#@#@#A#A#B#B#C#C#D#D#E#E#F#F#G#G#H#H#I#I#J#J#K#K#L#L#M#M#N#N#O#O#P#P#Q#Q#R#R#S#S#T#T#U#U#V#V#W#W#X#X#Y#Y#Z#Z#[#[#\#\#]#]#^#^#_#_#`#`#a#a#b#b#c#c#d#d#e#e#f#f#g#g#h#h#i#i#j#j#k#k#l#l#m#m#n#n#o#o#p#p#q#q#r#r#s#s#t#t#u#u#v#v#w#w#x#x#y#y#z#z#{#{#|#|#}#}#~#~##################################################################################################################################################################################################################################################################$$$$$$$$$$$$$$$$$$$ $ $ $ $ $ $ $ $ $ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $ $!$!$"$"$#$#$$$$$%$%$&$&$'$'$($($)$)$*$*$+$+$,$,$-$-$.$.$/$/$0$0$1$1$2$2$3$3$4$4$5$5$6$6$7$7$8$8$9$9$:$:$;$;$<$<$=$=$>$>$?$?$@$@$A$A$B$B$C$C$D$D$E$E$F$F$G$G$H$H$I$I$J$J$K$K$L$L$M$M$N$N$O$O$P$P$Q$Q$R$R$S$S$T$T$U$U$V$V$W$W$X$X$Y$Y$Z$Z$[$[$\$\$]$]$^$^$_$_$`$`$a$a$b$b$c$c$d$d$e$e$f$f$g$g$h$h$i$i$j$j$k$k$l$l$m$m$n$n$o$o$p$p$q$q$r$r$s$s$t$t$u$u$v$v$w$w$x$x$y$y$z$z${${$|$|$}$}$~$~$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$%%%%%%%%%%%%%%%%%%% % % % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %!%!%"%"%#%#%$%$%%%%%&%&%'%'%(%(%)%)%*%*%+%+%,%,%-%-%.%.%/%/%0%0%1%1%2%2%3%3%4%4%5%5%6%6%7%7%8%8%9%9%:%:%;%;%<%<%=%=%>%>%?%?%@%@%A%A%B%B%C%C%D%D%E%E%F%F%G%G%H%H%I%I%J%J%K%K%L%L%M%M%N%N%O%O%P%P%Q%Q%R%R%S%S%T%T%U%U%V%V%W%W%X%X%Y%Y%Z%Z%[%[%\%\%]%]%^%^%_%_%`%`%a%a%b%b%c%c%d%d%e%e%f%f%g%g%h%h%i%i%j%j%k%k%l%l%m%m%n%n%o%o%p%p%q%q%r%r%s%s%t%t%u%u%v%v%w%w%x%x%y%y%z%z%{%{%|%|%}%}%~%~%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&&&&&&&&&&&&&&&&&&& & & & & & & & & & &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& & &!&!&"&"&#&#&$&$&%&%&&&&&'&'&(&(&)&)&*&*&+&+&,&,&-&-&.&.&/&/&0&0&1&1&2&2&3&3&4&4&5&5&6&6&7&7&8&8&9&9&:&:&;&;&<&<&=&=&>&>&?&?&@&@&A&A&B&B&C&C&D&D&E&E&F&F&G&G&H&H&I&I&J&J&K&K&L&L&M&M&N&N&O&O&P&P&Q&Q&R&R&S&S&T&T&U&U&V&V&W&W&X&X&Y&Y&Z&Z&[&[&\&\&]&]&^&^&_&_&`&`&a&a&b&b&c&c&d&d&e&e&f&f&g&g&h&h&i&i&j&j&k&k&l&l&m&m&n&n&o&o&p&p&q&q&r&r&s&s&t&t&u&u&v&v&w&w&x&x&y&y&z&z&{&{&|&|&}&}&~&~&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&''''''''''''''''''' ' ' ' ' ' ' ' ' ' ''''''''''''''''''''''''''''''''''''' ' '!'!'"'"'#'#'$'$'%'%'&'&'''''('(')')'*'*'+'+',','-'-'.'.'/'/'0'0'1'1'2'2'3'3'4'4'5'5'6'6'7'7'8'8'9'9':':';';'<'<'='='>'>'?'?'@'@'A'A'B'B'C'C'D'D'E'E'F'F'G'G'H'H'I'I'J'J'K'K'L'L'M'M'N'N'O'O'P'P'Q'Q'R'R'S'S'T'T'U'U'V'V'W'W'X'X'Y'Y'Z'Z'['['\'\']']'^'^'_'_'`'`'a'a'b'b'c'c'd'd'e'e'f'f'g'g'h'h'i'i'j'j'k'k'l'l'm'm'n'n'o'o'p'p'q'q'r'r's's't't'u'u'v'v'w'w'x'x'y'y'z'z'{'{'|'|'}'}'~'~''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''((((((((((((((((((( ( ( ( ( ( ( ( ( ( ((((((((((((((((((((((((((((((((((((( ( (!(!("("(#(#($($(%(%(&(&('('((((()()(*(*(+(+(,(,(-(-(.(.(/(/(0(0(1(1(2(2(3(3(4(4(5(5(6(6(7(7(8(8(9(9(:(:(;(;(<(<(=(=(>(>(?(?(@(@(A(A(B(B(C(C(D(D(E(E(F(F(G(G(H(H(I(I(J(J(K(K(L(L(M(M(N(N(O(O(P(P(Q(Q(R(R(S(S(T(T(U(U(V(V(W(W(X(X(Y(Y(Z(Z([([(\(\(](](^(^(_(_(`(`(a(a(b(b(c(c(d(d(e(e(f(f(g(g(h(h(i(i(j(j(k(k(l(l(m(m(n(n(o(o(p(p(q(q(r(r(s(s(t(t(u(u(v(v(w(w(x(x(y(y(z(z({({(|(|(}(}(~(~(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((())))))))))))))))))) ) ) ) ) ) ) ) ) ) ))))))))))))))))))))))))))))))))))))) ) )!)!)")")#)#)$)$)%)%)&)&)')')()()))))*)*)+)+),),)-)-).).)/)/)0)0)1)1)2)2)3)3)4)4)5)5)6)6)7)7)8)8)9)9):):););)<)<)=)=)>)>)?)?)@)@)A)A)B)B)C)C)D)D)E)E)F)F)G)G)H)H)I)I)J)J)K)K)L)L)M)M)N)N)O)O)P)P)Q)Q)R)R)S)S)T)T)U)U)V)V)W)W)X)X)Y)Y)Z)Z)[)[)\)\)])])^)^)_)_)`)`)a)a)b)b)c)c)d)d)e)e)f)f)g)g)h)h)i)i)j)j)k)k)l)l)m)m)n)n)o)o)p)p)q)q)r)r)s)s)t)t)u)u)v)v)w)w)x)x)y)y)z)z){){)|)|)})})~)~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))******************* * * * * * * * * * ************************************* * *!*!*"*"*#*#*$*$*%*%*&*&*'*'*(*(*)*)*****+*+*,*,*-*-*.*.*/*/*0*0*1*1*2*2*3*3*4*4*5*5*6*6*7*7*8*8*9*9*:*:*;*;*<*<*=*=*>*>*?*?*@*@*A*A*B*B*C*C*D*D*E*E*F*F*G*G*H*H*I*I*J*J*K*K*L*L*M*M*N*N*O*O*P*P*Q*Q*R*R*S*S*T*T*U*U*V*V*W*W*X*X*Y*Y*Z*Z*[*[*\*\*]*]*^*^*_*_*`*`*a*a*b*b*c*c*d*d*e*e*f*f*g*g*h*h*i*i*j*j*k*k*l*l*m*m*n*n*o*o*p*p*q*q*r*r*s*s*t*t*u*u*v*v*w*w*x*x*y*y*z*z*{*{*|*|*}*}*~*~******************************************************************************************************************************************************************************************************************************************************************+++++++++++++++++++ + + + + + + + + + +++++++++++++++++++++++++++++++++++++ + +!+!+"+"+#+#+$+$+%+%+&+&+'+'+(+(+)+)+*+*+++++,+,+-+-+.+.+/+/+0+0+1+1+2+2+3+3+4+4+5+5+6+6+7+7+8+8+9+9+:+:+;+;+<+<+=+=+>+>+?+?+@+@+A+A+B+B+C+C+D+D+E+E+F+F+G+G+H+H+I+I+J+J+K+K+L+L+M+M+N+N+O+O+P+P+Q+Q+R+R+S+S+T+T+U+U+V+V+W+W+X+X+Y+Y+Z+Z+[+[+\+\+]+]+^+^+_+_+`+`+a+a+b+b+c+c+d+d+e+e+f+f+g+g+h+h+i+i+j+j+k+k+l+l+m+m+n+n+o+o+p+p+q+q+r+r+s+s+t+t+u+u+v+v+w+w+x+x+y+y+z+z+{+{+|+|+}+}+~+~++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++,,,,,,,,,,,,,,,,,,, , , , , , , , , , ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, , ,!,!,",",#,#,$,$,%,%,&,&,',',(,(,),),*,*,+,+,,,,,-,-,.,.,/,/,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,:,:,;,;,<,<,=,=,>,>,?,?,@,@,A,A,B,B,C,C,D,D,E,E,F,F,G,G,H,H,I,I,J,J,K,K,L,L,M,M,N,N,O,O,P,P,Q,Q,R,R,S,S,T,T,U,U,V,V,W,W,X,X,Y,Y,Z,Z,[,[,\,\,],],^,^,_,_,`,`,a,a,b,b,c,c,d,d,e,e,f,f,g,g,h,h,i,i,j,j,k,k,l,l,m,m,n,n,o,o,p,p,q,q,r,r,s,s,t,t,u,u,v,v,w,w,x,x,y,y,z,z,{,{,|,|,},},~,~,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,------------------- - - - - - - - - - ------------------------------------- - -!-!-"-"-#-#-$-$-%-%-&-&-'-'-(-(-)-)-*-*-+-+-,-,-----.-.-/-/-0-0-1-1-2-2-3-3-4-4-5-5-6-6-7-7-8-8-9-9-:-:-;-;-<-<-=-=->->-?-?-@-@-A-A-B-B-C-C-D-D-E-E-F-F-G-G-H-H-I-I-J-J-K-K-L-L-M-M-N-N-O-O-P-P-Q-Q-R-R-S-S-T-T-U-U-V-V-W-W-X-X-Y-Y-Z-Z-[-[-\-\-]-]-^-^-_-_-`-`-a-a-b-b-c-c-d-d-e-e-f-f-g-g-h-h-i-i-j-j-k-k-l-l-m-m-n-n-o-o-p-p-q-q-r-r-s-s-t-t-u-u-v-v-w-w-x-x-y-y-z-z-{-{-|-|-}-}-~-~------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------................... . . . . . . . . . ..................................... . .!.!.".".#.#.$.$.%.%.&.&.'.'.(.(.).).*.*.+.+.,.,.-.-....././.0.0.1.1.2.2.3.3.4.4.5.5.6.6.7.7.8.8.9.9.:.:.;.;.<.<.=.=.>.>.?.?.@.@.A.A.B.B.C.C.D.D.E.E.F.F.G.G.H.H.I.I.J.J.K.K.L.L.M.M.N.N.O.O.P.P.Q.Q.R.R.S.S.T.T.U.U.V.V.W.W.X.X.Y.Y.Z.Z.[.[.\.\.].].^.^._._.`.`.a.a.b.b.c.c.d.d.e.e.f.f.g.g.h.h.i.i.j.j.k.k.l.l.m.m.n.n.o.o.p.p.q.q.r.r.s.s.t.t.u.u.v.v.w.w.x.x.y.y.z.z.{.{.|.|.}.}.~.~................................................................................................................................................................................................................................................................../////////////////// / / / / / / / / / ///////////////////////////////////// / /!/!/"/"/#/#/$/$/%/%/&/&/'/'/(/(/)/)/*/*/+/+/,/,/-/-/././////0/0/1/1/2/2/3/3/4/4/5/5/6/6/7/7/8/8/9/9/:/:/;/;//>/?/?/@/@/A/A/B/B/C/C/D/D/E/E/F/F/G/G/H/H/I/I/J/J/K/K/L/L/M/M/N/N/O/O/P/P/Q/Q/R/R/S/S/T/T/U/U/V/V/W/W/X/X/Y/Y/Z/Z/[/[/\/\/]/]/^/^/_/_/`/`/a/a/b/b/c/c/d/d/e/e/f/f/g/g/h/h/i/i/j/j/k/k/l/l/m/m/n/n/o/o/p/p/q/q/r/r/s/s/t/t/u/u/v/v/w/w/x/x/y/y/z/z/{/{/|/|/}/}/~/~//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////0000000000000000000 0 0 0 0 0 0 0 0 0 0000000000000000000000000000000000000 0 0!0!0"0"0#0#0$0$0%0%0&0&0'0'0(0(0)0)0*0*0+0+0,0,0-0-0.0.0/0/00000101020203030404050506060707080809090:0:0;0;0<0<0=0=0>0>0?0?0@0@0A0A0B0B0C0C0D0D0E0E0F0F0G0G0H0H0I0I0J0J0K0K0L0L0M0M0N0N0O0O0P0P0Q0Q0R0R0S0S0T0T0U0U0V0V0W0W0X0X0Y0Y0Z0Z0[0[0\0\0]0]0^0^0_0_0`0`0a0a0b0b0c0c0d0d0e0e0f0f0g0g0h0h0i0i0j0j0k0k0l0l0m0m0n0n0o0o0p0p0q0q0r0r0s0s0t0t0u0u0v0v0w0w0x0x0y0y0z0z0{0{0|0|0}0}0~0~0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111111 1 1 1 1 1 1 1 1 1 1111111111111111111111111111111111111 1 1!1!1"1"1#1#1$1$1%1%1&1&1'1'1(1(1)1)1*1*1+1+1,1,1-1-1.1.1/1/10101111121213131414151516161717181819191:1:1;1;1<1<1=1=1>1>1?1?1@1@1A1A1B1B1C1C1D1D1E1E1F1F1G1G1H1H1I1I1J1J1K1K1L1L1M1M1N1N1O1O1P1P1Q1Q1R1R1S1S1T1T1U1U1V1V1W1W1X1X1Y1Y1Z1Z1[1[1\1\1]1]1^1^1_1_1`1`1a1a1b1b1c1c1d1d1e1e1f1f1g1g1h1h1i1i1j1j1k1k1l1l1m1m1n1n1o1o1p1p1q1q1r1r1s1s1t1t1u1u1v1v1w1w1x1x1y1y1z1z1{1{1|1|1}1}1~1~1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112222222222222222222 2 2 2 2 2 2 2 2 2 2222222222222222222222222222222222222 2 2!2!2"2"2#2#2$2$2%2%2&2&2'2'2(2(2)2)2*2*2+2+2,2,2-2-2.2.2/2/20202121222223232424252526262727282829292:2:2;2;2<2<2=2=2>2>2?2?2@2@2A2A2B2B2C2C2D2D2E2E2F2F2G2G2H2H2I2I2J2J2K2K2L2L2M2M2N2N2O2O2P2P2Q2Q2R2R2S2S2T2T2U2U2V2V2W2W2X2X2Y2Y2Z2Z2[2[2\2\2]2]2^2^2_2_2`2`2a2a2b2b2c2c2d2d2e2e2f2f2g2g2h2h2i2i2j2j2k2k2l2l2m2m2n2n2o2o2p2p2q2q2r2r2s2s2t2t2u2u2v2v2w2w2x2x2y2y2z2z2{2{2|2|2}2}2~2~2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222223333333333333333333 3 3 3 3 3 3 3 3 3 3333333333333333333333333333333333333 3 3!3!3"3"3#3#3$3$3%3%3&3&3'3'3(3(3)3)3*3*3+3+3,3,3-3-3.3.3/3/30303131323233333434353536363737383839393:3:3;3;3<3<3=3=3>3>3?3?3@3@3A3A3B3B3C3C3D3D3E3E3F3F3G3G3H3H3I3I3J3J3K3K3L3L3M3M3N3N3O3O3P3P3Q3Q3R3R3S3S3T3T3U3U3V3V3W3W3X3X3Y3Y3Z3Z3[3[3\3\3]3]3^3^3_3_3`3`3a3a3b3b3c3c3d3d3e3e3f3f3g3g3h3h3i3i3j3j3k3k3l3l3m3m3n3n3o3o3p3p3q3q3r3r3s3s3t3t3u3u3v3v3w3w3x3x3y3y3z3z3{3{3|3|3}3}3~3~3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333334444444444444444444 4 4 4 4 4 4 4 4 4 4444444444444444444444444444444444444 4 4!4!4"4"4#4#4$4$4%4%4&4&4'4'4(4(4)4)4*4*4+4+4,4,4-4-4.4.4/4/40404141424243434444454546464747484849494:4:4;4;4<4<4=4=4>4>4?4?4@4@4A4A4B4B4C4C4D4D4E4E4F4F4G4G4H4H4I4I4J4J4K4K4L4L4M4M4N4N4O4O4P4P4Q4Q4R4R4S4S4T4T4U4U4V4V4W4W4X4X4Y4Y4Z4Z4[4[4\4\4]4]4^4^4_4_4`4`4a4a4b4b4c4c4d4d4e4e4f4f4g4g4h4h4i4i4j4j4k4k4l4l4m4m4n4n4o4o4p4p4q4q4r4r4s4s4t4t4u4u4v4v4w4w4x4x4y4y4z4z4{4{4|4|4}4}4~4~4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444445555555555555555555 5 5 5 5 5 5 5 5 5 5555555555555555555555555555555555555 5 5!5!5"5"5#5#5$5$5%5%5&5&5'5'5(5(5)5)5*5*5+5+5,5,5-5-5.5.5/5/50505151525253535454555556565757585859595:5:5;5;5<5<5=5=5>5>5?5?5@5@5A5A5B5B5C5C5D5D5E5E5F5F5G5G5H5H5I5I5J5J5K5K5L5L5M5M5N5N5O5O5P5P5Q5Q5R5R5S5S5T5T5U5U5V5V5W5W5X5X5Y5Y5Z5Z5[5[5\5\5]5]5^5^5_5_5`5`5a5a5b5b5c5c5d5d5e5e5f5f5g5g5h5h5i5i5j5j5k5k5l5l5m5m5n5n5o5o5p5p5q5q5r5r5s5s5t5t5u5u5v5v5w5w5x5x5y5y5z5z5{5{5|5|5}5}5~5~5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555556666666666666666666 6 6 6 6 6 6 6 6 6 6666666666666666666666666666666666666 6 6!6!6"6"6#6#6$6$6%6%6&6&6'6'6(6(6)6)6*6*6+6+6,6,6-6-6.6.6/6/60606161626263636464656566666767686869696:6:6;6;6<6<6=6=6>6>6?6?6@6@6A6A6B6B6C6C6D6D6E6E6F6F6G6G6H6H6I6I6J6J6K6K6L6L6M6M6N6N6O6O6P6P6Q6Q6R6R6S6S6T6T6U6U6V6V6W6W6X6X6Y6Y6Z6Z6[6[6\6\6]6]6^6^6_6_6`6`6a6a6b6b6c6c6d6d6e6e6f6f6g6g6h6h6i6i6j6j6k6k6l6l6m6m6n6n6o6o6p6p6q6q6r6r6s6s6t6t6u6u6v6v6w6w6x6x6y6y6z6z6{6{6|6|6}6}6~6~6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666667777777777777777777 7 7 7 7 7 7 7 7 7 7777777777777777777777777777777777777 7 7!7!7"7"7#7#7$7$7%7%7&7&7'7'7(7(7)7)7*7*7+7+7,7,7-7-7.7.7/7/70707171727273737474757576767777787879797:7:7;7;7<7<7=7=7>7>7?7?7@7@7A7A7B7B7C7C7D7D7E7E7F7F7G7G7H7H7I7I7J7J7K7K7L7L7M7M7N7N7O7O7P7P7Q7Q7R7R7S7S7T7T7U7U7V7V7W7W7X7X7Y7Y7Z7Z7[7[7\7\7]7]7^7^7_7_7`7`7a7a7b7b7c7c7d7d7e7e7f7f7g7g7h7h7i7i7j7j7k7k7l7l7m7m7n7n7o7o7p7p7q7q7r7r7s7s7t7t7u7u7v7v7w7w7x7x7y7y7z7z7{7{7|7|7}7}7~7~7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777778888888888888888888 8 8 8 8 8 8 8 8 8 8888888888888888888888888888888888888 8 8!8!8"8"8#8#8$8$8%8%8&8&8'8'8(8(8)8)8*8*8+8+8,8,8-8-8.8.8/8/80808181828283838484858586868787888889898:8:8;8;8<8<8=8=8>8>8?8?8@8@8A8A8B8B8C8C8D8D8E8E8F8F8G8G8H8H8I8I8J8J8K8K8L8L8M8M8N8N8O8O8P8P8Q8Q8R8R8S8S8T8T8U8U8V8V8W8W8X8X8Y8Y8Z8Z8[8[8\8\8]8]8^8^8_8_8`8`8a8a8b8b8c8c8d8d8e8e8f8f8g8g8h8h8i8i8j8j8k8k8l8l8m8m8n8n8o8o8p8p8q8q8r8r8s8s8t8t8u8u8v8v8w8w8x8x8y8y8z8z8{8{8|8|8}8}8~8~8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888889999999999999999999 9 9 9 9 9 9 9 9 9 9999999999999999999999999999999999999 9 9!9!9"9"9#9#9$9$9%9%9&9&9'9'9(9(9)9)9*9*9+9+9,9,9-9-9.9.9/9/90909191929293939494959596969797989899999:9:9;9;9<9<9=9=9>9>9?9?9@9@9A9A9B9B9C9C9D9D9E9E9F9F9G9G9H9H9I9I9J9J9K9K9L9L9M9M9N9N9O9O9P9P9Q9Q9R9R9S9S9T9T9U9U9V9V9W9W9X9X9Y9Y9Z9Z9[9[9\9\9]9]9^9^9_9_9`9`9a9a9b9b9c9c9d9d9e9e9f9f9g9g9h9h9i9i9j9j9k9k9l9l9m9m9n9n9o9o9p9p9q9q9r9r9s9s9t9t9u9u9v9v9w9w9x9x9y9y9z9z9{9{9|9|9}9}9~9~999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999::::::::::::::::::: : : : : : : : : : ::::::::::::::::::::::::::::::::::::: : :!:!:":":#:#:$:$:%:%:&:&:':':(:(:):):*:*:+:+:,:,:-:-:.:.:/:/:0:0:1:1:2:2:3:3:4:4:5:5:6:6:7:7:8:8:9:9:::::;:;:<:<:=:=:>:>:?:?:@:@:A:A:B:B:C:C:D:D:E:E:F:F:G:G:H:H:I:I:J:J:K:K:L:L:M:M:N:N:O:O:P:P:Q:Q:R:R:S:S:T:T:U:U:V:V:W:W:X:X:Y:Y:Z:Z:[:[:\:\:]:]:^:^:_:_:`:`:a:a:b:b:c:c:d:d:e:e:f:f:g:g:h:h:i:i:j:j:k:k:l:l:m:m:n:n:o:o:p:p:q:q:r:r:s:s:t:t:u:u:v:v:w:w:x:x:y:y:z:z:{:{:|:|:}:}:~:~::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::;;;;;;;;;;;;;;;;;;; ; ; ; ; ; ; ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ;!;!;";";#;#;$;$;%;%;&;&;';';(;(;););*;*;+;+;,;,;-;-;.;.;/;/;0;0;1;1;2;2;3;3;4;4;5;5;6;6;7;7;8;8;9;9;:;:;;;;;<;<;=;=;>;>;?;?;@;@;A;A;B;B;C;C;D;D;E;E;F;F;G;G;H;H;I;I;J;J;K;K;L;L;M;M;N;N;O;O;P;P;Q;Q;R;R;S;S;T;T;U;U;V;V;W;W;X;X;Y;Y;Z;Z;[;[;\;\;];];^;^;_;_;`;`;a;a;b;b;c;c;d;d;e;e;f;f;g;g;h;h;i;i;j;j;k;k;l;l;m;m;n;n;o;o;p;p;q;q;r;r;s;s;t;t;u;u;v;v;w;w;x;x;y;y;z;z;{;{;|;|;};};~;~;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<<<<<<<<<<<<<<<<<<< < < < < < < < < < <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< < <>=>=?=?=@=@=A=A=B=B=C=C=D=D=E=E=F=F=G=G=H=H=I=I=J=J=K=K=L=L=M=M=N=N=O=O=P=P=Q=Q=R=R=S=S=T=T=U=U=V=V=W=W=X=X=Y=Y=Z=Z=[=[=\=\=]=]=^=^=_=_=`=`=a=a=b=b=c=c=d=d=e=e=f=f=g=g=h=h=i=i=j=j=k=k=l=l=m=m=n=n=o=o=p=p=q=q=r=r=s=s=t=t=u=u=v=v=w=w=x=x=y=y=z=z={={=|=|=}=}=~=~==================================================================================================================================================================================================================================================================>>>>>>>>>>>>>>>>>>> > > > > > > > > > >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > >!>!>">">#>#>$>$>%>%>&>&>'>'>(>(>)>)>*>*>+>+>,>,>->->.>.>/>/>0>0>1>1>2>2>3>3>4>4>5>5>6>6>7>7>8>8>9>9>:>:>;>;><><>=>=>>>>>?>?>@>@>A>A>B>B>C>C>D>D>E>E>F>F>G>G>H>H>I>I>J>J>K>K>L>L>M>M>N>N>O>O>P>P>Q>Q>R>R>S>S>T>T>U>U>V>V>W>W>X>X>Y>Y>Z>Z>[>[>\>\>]>]>^>^>_>_>`>`>a>a>b>b>c>c>d>d>e>e>f>f>g>g>h>h>i>i>j>j>k>k>l>l>m>m>n>n>o>o>p>p>q>q>r>r>s>s>t>t>u>u>v>v>w>w>x>x>y>y>z>z>{>{>|>|>}>}>~>~>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>??????????????????? ? ? ? ? ? ? ? ? ? ????????????????????????????????????? ? ?!?!?"?"?#?#?$?$?%?%?&?&?'?'?(?(?)?)?*?*?+?+?,?,?-?-?.?.?/?/?0?0?1?1?2?2?3?3?4?4?5?5?6?6?7?7?8?8?9?9?:?:?;?;??>?????@?@?A?A?B?B?C?C?D?D?E?E?F?F?G?G?H?H?I?I?J?J?K?K?L?L?M?M?N?N?O?O?P?P?Q?Q?R?R?S?S?T?T?U?U?V?V?W?W?X?X?Y?Y?Z?Z?[?[?\?\?]?]?^?^?_?_?`?`?a?a?b?b?c?c?d?d?e?e?f?f?g?g?h?h?i?i?j?j?k?k?l?l?m?m?n?n?o?o?p?p?q?q?r?r?s?s?t?t?u?u?v?v?w?w?x?x?y?y?z?z?{?{?|?|?}?}?~?~??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????@@@@@@@@@@@@@@@@@@@ @ @ @ @ @ @ @ @ @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ @!@!@"@"@#@#@$@$@%@%@&@&@'@'@(@(@)@)@*@*@+@+@,@,@-@-@.@.@/@/@0@0@1@1@2@2@3@3@4@4@5@5@6@6@7@7@8@8@9@9@:@:@;@;@<@<@=@=@>@>@?@?@@@@@A@A@B@B@C@C@D@D@E@E@F@F@G@G@H@H@I@I@J@J@K@K@L@L@M@M@N@N@O@O@P@P@Q@Q@R@R@S@S@T@T@U@U@V@V@W@W@X@X@Y@Y@Z@Z@[@[@\@\@]@]@^@^@_@_@`@`@a@a@b@b@c@c@d@d@e@e@f@f@g@g@h@h@i@i@j@j@k@k@l@l@m@m@n@n@o@o@p@p@q@q@r@r@s@s@t@t@u@u@v@v@w@w@x@x@y@y@z@z@{@{@|@|@}@}@~@~@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@AAAAAAAAAAAAAAAAAAA A A A A A A A A A AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA A A!A!A"A"A#A#A$A$A%A%A&A&A'A'A(A(A)A)A*A*A+A+A,A,A-A-A.A.A/A/A0A0A1A1A2A2A3A3A4A4A5A5A6A6A7A7A8A8A9A9A:A:A;A;AA>A?A?A@A@AAAAABABACACADADAEAEAFAFAGAGAHAHAIAIAJAJAKAKALALAMAMANANAOAOAPAPAQAQARARASASATATAUAUAVAVAWAWAXAXAYAYAZAZA[A[A\A\A]A]A^A^A_A_A`A`AaAaAbAbAcAcAdAdAeAeAfAfAgAgAhAhAiAiAjAjAkAkAlAlAmAmAnAnAoAoApApAqAqArArAsAsAtAtAuAuAvAvAwAwAxAxAyAyAzAzA{A{A|A|A}A}A~A~AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBB B B B B B B B B B BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB B B!B!B"B"B#B#B$B$B%B%B&B&B'B'B(B(B)B)B*B*B+B+B,B,B-B-B.B.B/B/B0B0B1B1B2B2B3B3B4B4B5B5B6B6B7B7B8B8B9B9B:B:B;B;BB>B?B?B@B@BABABBBBBCBCBDBDBEBEBFBFBGBGBHBHBIBIBJBJBKBKBLBLBMBMBNBNBOBOBPBPBQBQBRBRBSBSBTBTBUBUBVBVBWBWBXBXBYBYBZBZB[B[B\B\B]B]B^B^B_B_B`B`BaBaBbBbBcBcBdBdBeBeBfBfBgBgBhBhBiBiBjBjBkBkBlBlBmBmBnBnBoBoBpBpBqBqBrBrBsBsBtBtBuBuBvBvBwBwBxBxByByBzBzB{B{B|B|B}B}B~B~BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCC C C C C C C C C C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC C C!C!C"C"C#C#C$C$C%C%C&C&C'C'C(C(C)C)C*C*C+C+C,C,C-C-C.C.C/C/C0C0C1C1C2C2C3C3C4C4C5C5C6C6C7C7C8C8C9C9C:C:C;C;CC>C?C?C@C@CACACBCBCCCCCDCDCECECFCFCGCGCHCHCICICJCJCKCKCLCLCMCMCNCNCOCOCPCPCQCQCRCRCSCSCTCTCUCUCVCVCWCWCXCXCYCYCZCZC[C[C\C\C]C]C^C^C_C_C`C`CaCaCbCbCcCcCdCdCeCeCfCfCgCgChChCiCiCjCjCkCkClClCmCmCnCnCoCoCpCpCqCqCrCrCsCsCtCtCuCuCvCvCwCwCxCxCyCyCzCzC{C{C|C|C}C}C~C~CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDD D D D D D D D D D DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD D D!D!D"D"D#D#D$D$D%D%D&D&D'D'D(D(D)D)D*D*D+D+D,D,D-D-D.D.D/D/D0D0D1D1D2D2D3D3D4D4D5D5D6D6D7D7D8D8D9D9D:D:D;D;DD>D?D?D@D@DADADBDBDCDCDDDDDEDEDFDFDGDGDHDHDIDIDJDJDKDKDLDLDMDMDNDNDODODPDPDQDQDRDRDSDSDTDTDUDUDVDVDWDWDXDXDYDYDZDZD[D[D\D\D]D]D^D^D_D_D`D`DaDaDbDbDcDcDdDdDeDeDfDfDgDgDhDhDiDiDjDjDkDkDlDlDmDmDnDnDoDoDpDpDqDqDrDrDsDsDtDtDuDuDvDvDwDwDxDxDyDyDzDzD{D{D|D|D}D}D~D~DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDEEEEEEEEEEEEEEEEEEE E E E E E E E E E EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE E E!E!E"E"E#E#E$E$E%E%E&E&E'E'E(E(E)E)E*E*E+E+E,E,E-E-E.E.E/E/E0E0E1E1E2E2E3E3E4E4E5E5E6E6E7E7E8E8E9E9E:E:E;E;EE>E?E?E@E@EAEAEBEBECECEDEDEEEEEFEFEGEGEHEHEIEIEJEJEKEKELELEMEMENENEOEOEPEPEQEQERERESESETETEUEUEVEVEWEWEXEXEYEYEZEZE[E[E\E\E]E]E^E^E_E_E`E`EaEaEbEbEcEcEdEdEeEeEfEfEgEgEhEhEiEiEjEjEkEkElElEmEmEnEnEoEoEpEpEqEqErErEsEsEtEtEuEuEvEvEwEwExExEyEyEzEzE{E{E|E|E}E}E~E~EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEFFFFFFFFFFFFFFFFFFF F F F F F F F F F FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF F F!F!F"F"F#F#F$F$F%F%F&F&F'F'F(F(F)F)F*F*F+F+F,F,F-F-F.F.F/F/F0F0F1F1F2F2F3F3F4F4F5F5F6F6F7F7F8F8F9F9F:F:F;F;FF>F?F?F@F@FAFAFBFBFCFCFDFDFEFEFFFFFGFGFHFHFIFIFJFJFKFKFLFLFMFMFNFNFOFOFPFPFQFQFRFRFSFSFTFTFUFUFVFVFWFWFXFXFYFYFZFZF[F[F\F\F]F]F^F^F_F_F`F`FaFaFbFbFcFcFdFdFeFeFfFfFgFgFhFhFiFiFjFjFkFkFlFlFmFmFnFnFoFoFpFpFqFqFrFrFsFsFtFtFuFuFvFvFwFwFxFxFyFyFzFzF{F{F|F|F}F}F~F~FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFGGGGGGGGGGGGGGGGGGG G G G G G G G G G GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG G G!G!G"G"G#G#G$G$G%G%G&G&G'G'G(G(G)G)G*G*G+G+G,G,G-G-G.G.G/G/G0G0G1G1G2G2G3G3G4G4G5G5G6G6G7G7G8G8G9G9G:G:G;G;GG>G?G?G@G@GAGAGBGBGCGCGDGDGEGEGFGFGGGGGHGHGIGIGJGJGKGKGLGLGMGMGNGNGOGOGPGPGQGQGRGRGSGSGTGTGUGUGVGVGWGWGXGXGYGYGZGZG[G[G\G\G]G]G^G^G_G_G`G`GaGaGbGbGcGcGdGdGeGeGfGfGgGgGhGhGiGiGjGjGkGkGlGlGmGmGnGnGoGoGpGpGqGqGrGrGsGsGtGtGuGuGvGvGwGwGxGxGyGyGzGzG{G{G|G|G}G}G~G~GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGHHHHHHHHHHHHHHHHHHH H H H H H H H H H HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH H H!H!H"H"H#H#H$H$H%H%H&H&H'H'H(H(H)H)H*H*H+H+H,H,H-H-H.H.H/H/H0H0H1H1H2H2H3H3H4H4H5H5H6H6H7H7H8H8H9H9H:H:H;H;HH>H?H?H@H@HAHAHBHBHCHCHDHDHEHEHFHFHGHGHHHHHIHIHJHJHKHKHLHLHMHMHNHNHOHOHPHPHQHQHRHRHSHSHTHTHUHUHVHVHWHWHXHXHYHYHZHZH[H[H\H\H]H]H^H^H_H_H`H`HaHaHbHbHcHcHdHdHeHeHfHfHgHgHhHhHiHiHjHjHkHkHlHlHmHmHnHnHoHoHpHpHqHqHrHrHsHsHtHtHuHuHvHvHwHwHxHxHyHyHzHzH{H{H|H|H}H}H~H~HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHIIIIIIIIIIIIIIIIIII I I I I I I I I I IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII I I!I!I"I"I#I#I$I$I%I%I&I&I'I'I(I(I)I)I*I*I+I+I,I,I-I-I.I.I/I/I0I0I1I1I2I2I3I3I4I4I5I5I6I6I7I7I8I8I9I9I:I:I;I;II>I?I?I@I@IAIAIBIBICICIDIDIEIEIFIFIGIGIHIHIIIIIJIJIKIKILILIMIMININIOIOIPIPIQIQIRIRISISITITIUIUIVIVIWIWIXIXIYIYIZIZI[I[I\I\I]I]I^I^I_I_I`I`IaIaIbIbIcIcIdIdIeIeIfIfIgIgIhIhIiIiIjIjIkIkIlIlImImInInIoIoIpIpIqIqIrIrIsIsItItIuIuIvIvIwIwIxIxIyIyIzIzI{I{I|I|I}I}I~I~IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJJJJ J J J J J J J J J JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ J J!J!J"J"J#J#J$J$J%J%J&J&J'J'J(J(J)J)J*J*J+J+J,J,J-J-J.J.J/J/J0J0J1J1J2J2J3J3J4J4J5J5J6J6J7J7J8J8J9J9J:J:J;J;JJ>J?J?J@J@JAJAJBJBJCJCJDJDJEJEJFJFJGJGJHJHJIJIJJJJJKJKJLJLJMJMJNJNJOJOJPJPJQJQJRJRJSJSJTJTJUJUJVJVJWJWJXJXJYJYJZJZJ[J[J\J\J]J]J^J^J_J_J`J`JaJaJbJbJcJcJdJdJeJeJfJfJgJgJhJhJiJiJjJjJkJkJlJlJmJmJnJnJoJoJpJpJqJqJrJrJsJsJtJtJuJuJvJvJwJwJxJxJyJyJzJzJ{J{J|J|J}J}J~J~JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJKKKKKKKKKKKKKKKKKKK K K K K K K K K K KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK K K!K!K"K"K#K#K$K$K%K%K&K&K'K'K(K(K)K)K*K*K+K+K,K,K-K-K.K.K/K/K0K0K1K1K2K2K3K3K4K4K5K5K6K6K7K7K8K8K9K9K:K:K;K;KK>K?K?K@K@KAKAKBKBKCKCKDKDKEKEKFKFKGKGKHKHKIKIKJKJKKKKKLKLKMKMKNKNKOKOKPKPKQKQKRKRKSKSKTKTKUKUKVKVKWKWKXKXKYKYKZKZK[K[K\K\K]K]K^K^K_K_K`K`KaKaKbKbKcKcKdKdKeKeKfKfKgKgKhKhKiKiKjKjKkKkKlKlKmKmKnKnKoKoKpKpKqKqKrKrKsKsKtKtKuKuKvKvKwKwKxKxKyKyKzKzK{K{K|K|K}K}K~K~KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKLLLLLLLLLLLLLLLLLLL L L L L L L L L L LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL L L!L!L"L"L#L#L$L$L%L%L&L&L'L'L(L(L)L)L*L*L+L+L,L,L-L-L.L.L/L/L0L0L1L1L2L2L3L3L4L4L5L5L6L6L7L7L8L8L9L9L:L:L;L;LL>L?L?L@L@LALALBLBLCLCLDLDLELELFLFLGLGLHLHLILILJLJLKLKLLLLLMLMLNLNLOLOLPLPLQLQLRLRLSLSLTLTLULULVLVLWLWLXLXLYLYLZLZL[L[L\L\L]L]L^L^L_L_L`L`LaLaLbLbLcLcLdLdLeLeLfLfLgLgLhLhLiLiLjLjLkLkLlLlLmLmLnLnLoLoLpLpLqLqLrLrLsLsLtLtLuLuLvLvLwLwLxLxLyLyLzLzL{L{L|L|L}L}L~L~LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLMMMMMMMMMMMMMMMMMMM M M M M M M M M M MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM M M!M!M"M"M#M#M$M$M%M%M&M&M'M'M(M(M)M)M*M*M+M+M,M,M-M-M.M.M/M/M0M0M1M1M2M2M3M3M4M4M5M5M6M6M7M7M8M8M9M9M:M:M;M;MM>M?M?M@M@MAMAMBMBMCMCMDMDMEMEMFMFMGMGMHMHMIMIMJMJMKMKMLMLMMMMMNMNMOMOMPMPMQMQMRMRMSMSMTMTMUMUMVMVMWMWMXMXMYMYMZMZM[M[M\M\M]M]M^M^M_M_M`M`MaMaMbMbMcMcMdMdMeMeMfMfMgMgMhMhMiMiMjMjMkMkMlMlMmMmMnMnMoMoMpMpMqMqMrMrMsMsMtMtMuMuMvMvMwMwMxMxMyMyMzMzM{M{M|M|M}M}M~M~MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNNNNNNNNNNNNNNNNN N N N N N N N N N NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN N N!N!N"N"N#N#N$N$N%N%N&N&N'N'N(N(N)N)N*N*N+N+N,N,N-N-N.N.N/N/N0N0N1N1N2N2N3N3N4N4N5N5N6N6N7N7N8N8N9N9N:N:N;N;NN>N?N?N@N@NANANBNBNCNCNDNDNENENFNFNGNGNHNHNININJNJNKNKNLNLNMNMNNNNNONONPNPNQNQNRNRNSNSNTNTNUNUNVNVNWNWNXNXNYNYNZNZN[N[N\N\N]N]N^N^N_N_N`N`NaNaNbNbNcNcNdNdNeNeNfNfNgNgNhNhNiNiNjNjNkNkNlNlNmNmNnNnNoNoNpNpNqNqNrNrNsNsNtNtNuNuNvNvNwNwNxNxNyNyNzNzN{N{N|N|N}N}N~N~NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNOOOOOOOOOOOOOOOOOOO O O O O O O O O O OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO O O!O!O"O"O#O#O$O$O%O%O&O&O'O'O(O(O)O)O*O*O+O+O,O,O-O-O.O.O/O/O0O0O1O1O2O2O3O3O4O4O5O5O6O6O7O7O8O8O9O9O:O:O;O;OO>O?O?O@O@OAOAOBOBOCOCODODOEOEOFOFOGOGOHOHOIOIOJOJOKOKOLOLOMOMONONOOOOOPOPOQOQOROROSOSOTOTOUOUOVOVOWOWOXOXOYOYOZOZO[O[O\O\O]O]O^O^O_O_O`O`OaOaObObOcOcOdOdOeOeOfOfOgOgOhOhOiOiOjOjOkOkOlOlOmOmOnOnOoOoOpOpOqOqOrOrOsOsOtOtOuOuOvOvOwOwOxOxOyOyOzOzO{O{O|O|O}O}O~O~OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOPPPPPPPPPPPPPPPPPPP P P P P P P P P P PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP P P!P!P"P"P#P#P$P$P%P%P&P&P'P'P(P(P)P)P*P*P+P+P,P,P-P-P.P.P/P/P0P0P1P1P2P2P3P3P4P4P5P5P6P6P7P7P8P8P9P9P:P:P;P;PP>P?P?P@P@PAPAPBPBPCPCPDPDPEPEPFPFPGPGPHPHPIPIPJPJPKPKPLPLPMPMPNPNPOPOPPPPPQPQPRPRPSPSPTPTPUPUPVPVPWPWPXPXPYPYPZPZP[P[P\P\P]P]P^P^P_P_P`P`PaPaPbPbPcPcPdPdPePePfPfPgPgPhPhPiPiPjPjPkPkPlPlPmPmPnPnPoPoPpPpPqPqPrPrPsPsPtPtPuPuPvPvPwPwPxPxPyPyPzPzP{P{P|P|P}P}P~P~PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQQQQQQQQQQQQ Q Q Q Q Q Q Q Q Q QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ Q Q!Q!Q"Q"Q#Q#Q$Q$Q%Q%Q&Q&Q'Q'Q(Q(Q)Q)Q*Q*Q+Q+Q,Q,Q-Q-Q.Q.Q/Q/Q0Q0Q1Q1Q2Q2Q3Q3Q4Q4Q5Q5Q6Q6Q7Q7Q8Q8Q9Q9Q:Q:Q;Q;QQ>Q?Q?Q@Q@QAQAQBQBQCQCQDQDQEQEQFQFQGQGQHQHQIQIQJQJQKQKQLQLQMQMQNQNQOQOQPQPQQQQQRQRQSQSQTQTQUQUQVQVQWQWQXQXQYQYQZQZQ[Q[Q\Q\Q]Q]Q^Q^Q_Q_Q`Q`QaQaQbQbQcQcQdQdQeQeQfQfQgQgQhQhQiQiQjQjQkQkQlQlQmQmQnQnQoQoQpQpQqQqQrQrQsQsQtQtQuQuQvQvQwQwQxQxQyQyQzQzQ{Q{Q|Q|Q}Q}Q~Q~QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQRRRRRRRRRRRRRRRRRRR R R R R R R R R R RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR R R!R!R"R"R#R#R$R$R%R%R&R&R'R'R(R(R)R)R*R*R+R+R,R,R-R-R.R.R/R/R0R0R1R1R2R2R3R3R4R4R5R5R6R6R7R7R8R8R9R9R:R:R;R;RR>R?R?R@R@RARARBRBRCRCRDRDRERERFRFRGRGRHRHRIRIRJRJRKRKRLRLRMRMRNRNRORORPRPRQRQRRRRRSRSRTRTRURURVRVRWRWRXRXRYRYRZRZR[R[R\R\R]R]R^R^R_R_R`R`RaRaRbRbRcRcRdRdReReRfRfRgRgRhRhRiRiRjRjRkRkRlRlRmRmRnRnRoRoRpRpRqRqRrRrRsRsRtRtRuRuRvRvRwRwRxRxRyRyRzRzR{R{R|R|R}R}R~R~RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRSSSSSSSSSSSSSSSSSSS S S S S S S S S S SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS S S!S!S"S"S#S#S$S$S%S%S&S&S'S'S(S(S)S)S*S*S+S+S,S,S-S-S.S.S/S/S0S0S1S1S2S2S3S3S4S4S5S5S6S6S7S7S8S8S9S9S:S:S;S;SS>S?S?S@S@SASASBSBSCSCSDSDSESESFSFSGSGSHSHSISISJSJSKSKSLSLSMSMSNSNSOSOSPSPSQSQSRSRSSSSSTSTSUSUSVSVSWSWSXSXSYSYSZSZS[S[S\S\S]S]S^S^S_S_S`S`SaSaSbSbScScSdSdSeSeSfSfSgSgShShSiSiSjSjSkSkSlSlSmSmSnSnSoSoSpSpSqSqSrSrSsSsStStSuSuSvSvSwSwSxSxSySySzSzS{S{S|S|S}S}S~S~SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSTTTTTTTTTTTTTTTTTTT T T T T T T T T T TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT T T!T!T"T"T#T#T$T$T%T%T&T&T'T'T(T(T)T)T*T*T+T+T,T,T-T-T.T.T/T/T0T0T1T1T2T2T3T3T4T4T5T5T6T6T7T7T8T8T9T9T:T:T;T;TT>T?T?T@T@TATATBTBTCTCTDTDTETETFTFTGTGTHTHTITITJTJTKTKTLTLTMTMTNTNTOTOTPTPTQTQTRTRTSTSTTTTTUTUTVTVTWTWTXTXTYTYTZTZT[T[T\T\T]T]T^T^T_T_T`T`TaTaTbTbTcTcTdTdTeTeTfTfTgTgThThTiTiTjTjTkTkTlTlTmTmTnTnToToTpTpTqTqTrTrTsTsTtTtTuTuTvTvTwTwTxTxTyTyTzTzT{T{T|T|T}T}T~T~TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTUUUUUUUUUUUUUUUUUUU U U U U U U U U U UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU U U!U!U"U"U#U#U$U$U%U%U&U&U'U'U(U(U)U)U*U*U+U+U,U,U-U-U.U.U/U/U0U0U1U1U2U2U3U3U4U4U5U5U6U6U7U7U8U8U9U9U:U:U;U;UU>U?U?U@U@UAUAUBUBUCUCUDUDUEUEUFUFUGUGUHUHUIUIUJUJUKUKULULUMUMUNUNUOUOUPUPUQUQURURUSUSUTUTUUUUUVUVUWUWUXUXUYUYUZUZU[U[U\U\U]U]U^U^U_U_U`U`UaUaUbUbUcUcUdUdUeUeUfUfUgUgUhUhUiUiUjUjUkUkUlUlUmUmUnUnUoUoUpUpUqUqUrUrUsUsUtUtUuUuUvUvUwUwUxUxUyUyUzUzU{U{U|U|U}U}U~U~UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUVVVVVVVVVVVVVVVVVVV V V V V V V V V V VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV V V!V!V"V"V#V#V$V$V%V%V&V&V'V'V(V(V)V)V*V*V+V+V,V,V-V-V.V.V/V/V0V0V1V1V2V2V3V3V4V4V5V5V6V6V7V7V8V8V9V9V:V:V;V;VV>V?V?V@V@VAVAVBVBVCVCVDVDVEVEVFVFVGVGVHVHVIVIVJVJVKVKVLVLVMVMVNVNVOVOVPVPVQVQVRVRVSVSVTVTVUVUVVVVVWVWVXVXVYVYVZVZV[V[V\V\V]V]V^V^V_V_V`V`VaVaVbVbVcVcVdVdVeVeVfVfVgVgVhVhViViVjVjVkVkVlVlVmVmVnVnVoVoVpVpVqVqVrVrVsVsVtVtVuVuVvVvVwVwVxVxVyVyVzVzV{V{V|V|V}V}V~V~VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVWWWWWWWWWWWWWWWWWWW W W W W W W W W W WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW W W!W!W"W"W#W#W$W$W%W%W&W&W'W'W(W(W)W)W*W*W+W+W,W,W-W-W.W.W/W/W0W0W1W1W2W2W3W3W4W4W5W5W6W6W7W7W8W8W9W9W:W:W;W;WW>W?W?W@W@WAWAWBWBWCWCWDWDWEWEWFWFWGWGWHWHWIWIWJWJWKWKWLWLWMWMWNWNWOWOWPWPWQWQWRWRWSWSWTWTWUWUWVWVWWWWWXWXWYWYWZWZW[W[W\W\W]W]W^W^W_W_W`W`WaWaWbWbWcWcWdWdWeWeWfWfWgWgWhWhWiWiWjWjWkWkWlWlWmWmWnWnWoWoWpWpWqWqWrWrWsWsWtWtWuWuWvWvWwWwWxWxWyWyWzWzW{W{W|W|W}W}W~W~WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWXXXXXXXXXXXXXXXXXXX X X X X X X X X X XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX X X!X!X"X"X#X#X$X$X%X%X&X&X'X'X(X(X)X)X*X*X+X+X,X,X-X-X.X.X/X/X0X0X1X1X2X2X3X3X4X4X5X5X6X6X7X7X8X8X9X9X:X:X;X;XX>X?X?X@X@XAXAXBXBXCXCXDXDXEXEXFXFXGXGXHXHXIXIXJXJXKXKXLXLXMXMXNXNXOXOXPXPXQXQXRXRXSXSXTXTXUXUXVXVXWXWXXXXXYXYXZXZX[X[X\X\X]X]X^X^X_X_X`X`XaXaXbXbXcXcXdXdXeXeXfXfXgXgXhXhXiXiXjXjXkXkXlXlXmXmXnXnXoXoXpXpXqXqXrXrXsXsXtXtXuXuXvXvXwXwXxXxXyXyXzXzX{X{X|X|X}X}X~X~XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXYYYYYYYYYYYYYYYYYYY Y Y Y Y Y Y Y Y Y YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY Y Y!Y!Y"Y"Y#Y#Y$Y$Y%Y%Y&Y&Y'Y'Y(Y(Y)Y)Y*Y*Y+Y+Y,Y,Y-Y-Y.Y.Y/Y/Y0Y0Y1Y1Y2Y2Y3Y3Y4Y4Y5Y5Y6Y6Y7Y7Y8Y8Y9Y9Y:Y:Y;Y;YY>Y?Y?Y@Y@YAYAYBYBYCYCYDYDYEYEYFYFYGYGYHYHYIYIYJYJYKYKYLYLYMYMYNYNYOYOYPYPYQYQYRYRYSYSYTYTYUYUYVYVYWYWYXYXYYYYYZYZY[Y[Y\Y\Y]Y]Y^Y^Y_Y_Y`Y`YaYaYbYbYcYcYdYdYeYeYfYfYgYgYhYhYiYiYjYjYkYkYlYlYmYmYnYnYoYoYpYpYqYqYrYrYsYsYtYtYuYuYvYvYwYwYxYxYyYyYzYzY{Y{Y|Y|Y}Y}Y~Y~YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYZZZZZZZZZZZZZZZZZZZ Z Z Z Z Z Z Z Z Z ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ Z Z!Z!Z"Z"Z#Z#Z$Z$Z%Z%Z&Z&Z'Z'Z(Z(Z)Z)Z*Z*Z+Z+Z,Z,Z-Z-Z.Z.Z/Z/Z0Z0Z1Z1Z2Z2Z3Z3Z4Z4Z5Z5Z6Z6Z7Z7Z8Z8Z9Z9Z:Z:Z;Z;ZZ>Z?Z?Z@Z@ZAZAZBZBZCZCZDZDZEZEZFZFZGZGZHZHZIZIZJZJZKZKZLZLZMZMZNZNZOZOZPZPZQZQZRZRZSZSZTZTZUZUZVZVZWZWZXZXZYZYZZZZZ[Z[Z\Z\Z]Z]Z^Z^Z_Z_Z`Z`ZaZaZbZbZcZcZdZdZeZeZfZfZgZgZhZhZiZiZjZjZkZkZlZlZmZmZnZnZoZoZpZpZqZqZrZrZsZsZtZtZuZuZvZvZwZwZxZxZyZyZzZzZ{Z{Z|Z|Z}Z}Z~Z~ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ[[[[[[[[[[[[[[[[[[[ [ [ [ [ [ [ [ [ [ [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [ [![!["["[#[#[$[$[%[%[&[&['['[([([)[)[*[*[+[+[,[,[-[-[.[.[/[/[0[0[1[1[2[2[3[3[4[4[5[5[6[6[7[7[8[8[9[9[:[:[;[;[<[<[=[=[>[>[?[?[@[@[A[A[B[B[C[C[D[D[E[E[F[F[G[G[H[H[I[I[J[J[K[K[L[L[M[M[N[N[O[O[P[P[Q[Q[R[R[S[S[T[T[U[U[V[V[W[W[X[X[Y[Y[Z[Z[[[[[\[\[][][^[^[_[_[`[`[a[a[b[b[c[c[d[d[e[e[f[f[g[g[h[h[i[i[j[j[k[k[l[l[m[m[n[n[o[o[p[p[q[q[r[r[s[s[t[t[u[u[v[v[w[w[x[x[y[y[z[z[{[{[|[|[}[}[~[~[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[\\\\\\\\\\\\\\\\\\\ \ \ \ \ \ \ \ \ \ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \ \!\!\"\"\#\#\$\$\%\%\&\&\'\'\(\(\)\)\*\*\+\+\,\,\-\-\.\.\/\/\0\0\1\1\2\2\3\3\4\4\5\5\6\6\7\7\8\8\9\9\:\:\;\;\<\<\=\=\>\>\?\?\@\@\A\A\B\B\C\C\D\D\E\E\F\F\G\G\H\H\I\I\J\J\K\K\L\L\M\M\N\N\O\O\P\P\Q\Q\R\R\S\S\T\T\U\U\V\V\W\W\X\X\Y\Y\Z\Z\[\[\\\\\]\]\^\^\_\_\`\`\a\a\b\b\c\c\d\d\e\e\f\f\g\g\h\h\i\i\j\j\k\k\l\l\m\m\n\n\o\o\p\p\q\q\r\r\s\s\t\t\u\u\v\v\w\w\x\x\y\y\z\z\{\{\|\|\}\}\~\~\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\]]]]]]]]]]]]]]]]]]] ] ] ] ] ] ] ] ] ] ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] ] ]!]!]"]"]#]#]$]$]%]%]&]&]']'](](])])]*]*]+]+],],]-]-].].]/]/]0]0]1]1]2]2]3]3]4]4]5]5]6]6]7]7]8]8]9]9]:]:];];]<]<]=]=]>]>]?]?]@]@]A]A]B]B]C]C]D]D]E]E]F]F]G]G]H]H]I]I]J]J]K]K]L]L]M]M]N]N]O]O]P]P]Q]Q]R]R]S]S]T]T]U]U]V]V]W]W]X]X]Y]Y]Z]Z][][]\]\]]]]]^]^]_]_]`]`]a]a]b]b]c]c]d]d]e]e]f]f]g]g]h]h]i]i]j]j]k]k]l]l]m]m]n]n]o]o]p]p]q]q]r]r]s]s]t]t]u]u]v]v]w]w]x]x]y]y]z]z]{]{]|]|]}]}]~]~]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]^^^^^^^^^^^^^^^^^^^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^ ^!^!^"^"^#^#^$^$^%^%^&^&^'^'^(^(^)^)^*^*^+^+^,^,^-^-^.^.^/^/^0^0^1^1^2^2^3^3^4^4^5^5^6^6^7^7^8^8^9^9^:^:^;^;^<^<^=^=^>^>^?^?^@^@^A^A^B^B^C^C^D^D^E^E^F^F^G^G^H^H^I^I^J^J^K^K^L^L^M^M^N^N^O^O^P^P^Q^Q^R^R^S^S^T^T^U^U^V^V^W^W^X^X^Y^Y^Z^Z^[^[^\^\^]^]^^^^^_^_^`^`^a^a^b^b^c^c^d^d^e^e^f^f^g^g^h^h^i^i^j^j^k^k^l^l^m^m^n^n^o^o^p^p^q^q^r^r^s^s^t^t^u^u^v^v^w^w^x^x^y^y^z^z^{^{^|^|^}^}^~^~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^___________________ _ _ _ _ _ _ _ _ _ _____________________________________ _ _!_!_"_"_#_#_$_$_%_%_&_&_'_'_(_(_)_)_*_*_+_+_,_,_-_-_._._/_/_0_0_1_1_2_2_3_3_4_4_5_5_6_6_7_7_8_8_9_9_:_:_;_;_<_<_=_=_>_>_?_?_@_@_A_A_B_B_C_C_D_D_E_E_F_F_G_G_H_H_I_I_J_J_K_K_L_L_M_M_N_N_O_O_P_P_Q_Q_R_R_S_S_T_T_U_U_V_V_W_W_X_X_Y_Y_Z_Z_[_[_\_\_]_]_^_^_____`_`_a_a_b_b_c_c_d_d_e_e_f_f_g_g_h_h_i_i_j_j_k_k_l_l_m_m_n_n_o_o_p_p_q_q_r_r_s_s_t_t_u_u_v_v_w_w_x_x_y_y_z_z_{_{_|_|_}_}_~_~__________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________``````````````````` ` ` ` ` ` ` ` ` ` ````````````````````````````````````` ` `!`!`"`"`#`#`$`$`%`%`&`&`'`'`(`(`)`)`*`*`+`+`,`,`-`-`.`.`/`/`0`0`1`1`2`2`3`3`4`4`5`5`6`6`7`7`8`8`9`9`:`:`;`;`<`<`=`=`>`>`?`?`@`@`A`A`B`B`C`C`D`D`E`E`F`F`G`G`H`H`I`I`J`J`K`K`L`L`M`M`N`N`O`O`P`P`Q`Q`R`R`S`S`T`T`U`U`V`V`W`W`X`X`Y`Y`Z`Z`[`[`\`\`]`]`^`^`_`_`````a`a`b`b`c`c`d`d`e`e`f`f`g`g`h`h`i`i`j`j`k`k`l`l`m`m`n`n`o`o`p`p`q`q`r`r`s`s`t`t`u`u`v`v`w`w`x`x`y`y`z`z`{`{`|`|`}`}`~`~``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````aaaaaaaaaaaaaaaaaaa a a a a a a a a a aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa a a!a!a"a"a#a#a$a$a%a%a&a&a'a'a(a(a)a)a*a*a+a+a,a,a-a-a.a.a/a/a0a0a1a1a2a2a3a3a4a4a5a5a6a6a7a7a8a8a9a9a:a:a;a;aa>a?a?a@a@aAaAaBaBaCaCaDaDaEaEaFaFaGaGaHaHaIaIaJaJaKaKaLaLaMaMaNaNaOaOaPaPaQaQaRaRaSaSaTaTaUaUaVaVaWaWaXaXaYaYaZaZa[a[a\a\a]a]a^a^a_a_a`a`aaaaababacacadadaeaeafafagagahahaiaiajajakakalalamamananaoaoapapaqaqararasasatatauauavavawawaxaxayayazaza{a{a|a|a}a}a~a~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbb b b b b b b b b b bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb b b!b!b"b"b#b#b$b$b%b%b&b&b'b'b(b(b)b)b*b*b+b+b,b,b-b-b.b.b/b/b0b0b1b1b2b2b3b3b4b4b5b5b6b6b7b7b8b8b9b9b:b:b;b;bb>b?b?b@b@bAbAbBbBbCbCbDbDbEbEbFbFbGbGbHbHbIbIbJbJbKbKbLbLbMbMbNbNbObObPbPbQbQbRbRbSbSbTbTbUbUbVbVbWbWbXbXbYbYbZbZb[b[b\b\b]b]b^b^b_b_b`b`bababbbbbcbcbdbdbebebfbfbgbgbhbhbibibjbjbkbkblblbmbmbnbnbobobpbpbqbqbrbrbsbsbtbtbububvbvbwbwbxbxbybybzbzb{b{b|b|b}b}b~b~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccc c c c c c c c c c ccccccccccccccccccccccccccccccccccccc c c!c!c"c"c#c#c$c$c%c%c&c&c'c'c(c(c)c)c*c*c+c+c,c,c-c-c.c.c/c/c0c0c1c1c2c2c3c3c4c4c5c5c6c6c7c7c8c8c9c9c:c:c;c;cc>c?c?c@c@cAcAcBcBcCcCcDcDcEcEcFcFcGcGcHcHcIcIcJcJcKcKcLcLcMcMcNcNcOcOcPcPcQcQcRcRcScScTcTcUcUcVcVcWcWcXcXcYcYcZcZc[c[c\c\c]c]c^c^c_c_c`c`cacacbcbcccccdcdcececfcfcgcgchchcicicjcjckckclclcmcmcncncococpcpcqcqcrcrcscsctctcucucvcvcwcwcxcxcycyczczc{c{c|c|c}c}c~c~ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccddddddddddddddddddd d d d d d d d d d ddddddddddddddddddddddddddddddddddddd d d!d!d"d"d#d#d$d$d%d%d&d&d'd'd(d(d)d)d*d*d+d+d,d,d-d-d.d.d/d/d0d0d1d1d2d2d3d3d4d4d5d5d6d6d7d7d8d8d9d9d:d:d;d;dd>d?d?d@d@dAdAdBdBdCdCdDdDdEdEdFdFdGdGdHdHdIdIdJdJdKdKdLdLdMdMdNdNdOdOdPdPdQdQdRdRdSdSdTdTdUdUdVdVdWdWdXdXdYdYdZdZd[d[d\d\d]d]d^d^d_d_d`d`dadadbdbdcdcdddddededfdfdgdgdhdhdididjdjdkdkdldldmdmdndndododpdpdqdqdrdrdsdsdtdtdududvdvdwdwdxdxdydydzdzd{d{d|d|d}d}d~d~ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddeeeeeeeeeeeeeeeeeee e e e e e e e e e eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee e e!e!e"e"e#e#e$e$e%e%e&e&e'e'e(e(e)e)e*e*e+e+e,e,e-e-e.e.e/e/e0e0e1e1e2e2e3e3e4e4e5e5e6e6e7e7e8e8e9e9e:e:e;e;ee>e?e?e@e@eAeAeBeBeCeCeDeDeEeEeFeFeGeGeHeHeIeIeJeJeKeKeLeLeMeMeNeNeOeOePePeQeQeReReSeSeTeTeUeUeVeVeWeWeXeXeYeYeZeZe[e[e\e\e]e]e^e^e_e_e`e`eaeaebebececededeeeeefefegegeheheieiejejekekelelememeneneoeoepepeqeqerereseseteteueuevevewewexexeyeyezeze{e{e|e|e}e}e~e~eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeefffffffffffffffffff f f f f f f f f f fffffffffffffffffffffffffffffffffffff f f!f!f"f"f#f#f$f$f%f%f&f&f'f'f(f(f)f)f*f*f+f+f,f,f-f-f.f.f/f/f0f0f1f1f2f2f3f3f4f4f5f5f6f6f7f7f8f8f9f9f:f:f;f;ff>f?f?f@f@fAfAfBfBfCfCfDfDfEfEfFfFfGfGfHfHfIfIfJfJfKfKfLfLfMfMfNfNfOfOfPfPfQfQfRfRfSfSfTfTfUfUfVfVfWfWfXfXfYfYfZfZf[f[f\f\f]f]f^f^f_f_f`f`fafafbfbfcfcfdfdfefefffffgfgfhfhfififjfjfkfkflflfmfmfnfnfofofpfpfqfqfrfrfsfsftftfufufvfvfwfwfxfxfyfyfzfzf{f{f|f|f}f}f~f~ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffggggggggggggggggggg g g g g g g g g g ggggggggggggggggggggggggggggggggggggg g g!g!g"g"g#g#g$g$g%g%g&g&g'g'g(g(g)g)g*g*g+g+g,g,g-g-g.g.g/g/g0g0g1g1g2g2g3g3g4g4g5g5g6g6g7g7g8g8g9g9g:g:g;g;gg>g?g?g@g@gAgAgBgBgCgCgDgDgEgEgFgFgGgGgHgHgIgIgJgJgKgKgLgLgMgMgNgNgOgOgPgPgQgQgRgRgSgSgTgTgUgUgVgVgWgWgXgXgYgYgZgZg[g[g\g\g]g]g^g^g_g_g`g`gagagbgbgcgcgdgdgegegfgfggggghghgigigjgjgkgkglglgmgmgngngogogpgpgqgqgrgrgsgsgtgtgugugvgvgwgwgxgxgygygzgzg{g{g|g|g}g}g~g~gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggghhhhhhhhhhhhhhhhhhh h h h h h h h h h hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh h h!h!h"h"h#h#h$h$h%h%h&h&h'h'h(h(h)h)h*h*h+h+h,h,h-h-h.h.h/h/h0h0h1h1h2h2h3h3h4h4h5h5h6h6h7h7h8h8h9h9h:h:h;h;hh>h?h?h@h@hAhAhBhBhChChDhDhEhEhFhFhGhGhHhHhIhIhJhJhKhKhLhLhMhMhNhNhOhOhPhPhQhQhRhRhShShThThUhUhVhVhWhWhXhXhYhYhZhZh[h[h\h\h]h]h^h^h_h_h`h`hahahbhbhchchdhdhehehfhfhghghhhhhihihjhjhkhkhlhlhmhmhnhnhohohphphqhqhrhrhshshththuhuhvhvhwhwhxhxhyhyhzhzh{h{h|h|h}h}h~h~hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhiiiiiiiiiiiiiiiiiii i i i i i i i i i iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii i i!i!i"i"i#i#i$i$i%i%i&i&i'i'i(i(i)i)i*i*i+i+i,i,i-i-i.i.i/i/i0i0i1i1i2i2i3i3i4i4i5i5i6i6i7i7i8i8i9i9i:i:i;i;ii>i?i?i@i@iAiAiBiBiCiCiDiDiEiEiFiFiGiGiHiHiIiIiJiJiKiKiLiLiMiMiNiNiOiOiPiPiQiQiRiRiSiSiTiTiUiUiViViWiWiXiXiYiYiZiZi[i[i\i\i]i]i^i^i_i_i`i`iaiaibibicicididieieififigigihihiiiiijijikikililimimininioioipipiqiqiririsisititiuiuiviviwiwixixiyiyizizi{i{i|i|i}i}i~i~iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiijjjjjjjjjjjjjjjjjjj j j j j j j j j j jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj j j!j!j"j"j#j#j$j$j%j%j&j&j'j'j(j(j)j)j*j*j+j+j,j,j-j-j.j.j/j/j0j0j1j1j2j2j3j3j4j4j5j5j6j6j7j7j8j8j9j9j:j:j;j;jj>j?j?j@j@jAjAjBjBjCjCjDjDjEjEjFjFjGjGjHjHjIjIjJjJjKjKjLjLjMjMjNjNjOjOjPjPjQjQjRjRjSjSjTjTjUjUjVjVjWjWjXjXjYjYjZjZj[j[j\j\j]j]j^j^j_j_j`j`jajajbjbjcjcjdjdjejejfjfjgjgjhjhjijijjjjjkjkjljljmjmjnjnjojojpjpjqjqjrjrjsjsjtjtjujujvjvjwjwjxjxjyjyjzjzj{j{j|j|j}j}j~j~jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjkkkkkkkkkkkkkkkkkkk k k k k k k k k k kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk k k!k!k"k"k#k#k$k$k%k%k&k&k'k'k(k(k)k)k*k*k+k+k,k,k-k-k.k.k/k/k0k0k1k1k2k2k3k3k4k4k5k5k6k6k7k7k8k8k9k9k:k:k;k;kk>k?k?k@k@kAkAkBkBkCkCkDkDkEkEkFkFkGkGkHkHkIkIkJkJkKkKkLkLkMkMkNkNkOkOkPkPkQkQkRkRkSkSkTkTkUkUkVkVkWkWkXkXkYkYkZkZk[k[k\k\k]k]k^k^k_k_k`k`kakakbkbkckckdkdkekekfkfkgkgkhkhkikikjkjkkkkklklkmkmknknkokokpkpkqkqkrkrksksktktkukukvkvkwkwkxkxkykykzkzk{k{k|k|k}k}k~k~kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkklllllllllllllllllll l l l l l l l l l lllllllllllllllllllllllllllllllllllll l l!l!l"l"l#l#l$l$l%l%l&l&l'l'l(l(l)l)l*l*l+l+l,l,l-l-l.l.l/l/l0l0l1l1l2l2l3l3l4l4l5l5l6l6l7l7l8l8l9l9l:l:l;l;ll>l?l?l@l@lAlAlBlBlClClDlDlElElFlFlGlGlHlHlIlIlJlJlKlKlLlLlMlMlNlNlOlOlPlPlQlQlRlRlSlSlTlTlUlUlVlVlWlWlXlXlYlYlZlZl[l[l\l\l]l]l^l^l_l_l`l`lalalblblclcldldlelelflflglglhlhlililjljlklklllllmlmlnlnlololplplqlqlrlrlslsltltlululvlvlwlwlxlxlylylzlzl{l{l|l|l}l}l~l~llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllmmmmmmmmmmmmmmmmmmm m m m m m m m m m mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm m m!m!m"m"m#m#m$m$m%m%m&m&m'm'm(m(m)m)m*m*m+m+m,m,m-m-m.m.m/m/m0m0m1m1m2m2m3m3m4m4m5m5m6m6m7m7m8m8m9m9m:m:m;m;mm>m?m?m@m@mAmAmBmBmCmCmDmDmEmEmFmFmGmGmHmHmImImJmJmKmKmLmLmMmMmNmNmOmOmPmPmQmQmRmRmSmSmTmTmUmUmVmVmWmWmXmXmYmYmZmZm[m[m\m\m]m]m^m^m_m_m`m`mamambmbmcmcmdmdmememfmfmgmgmhmhmimimjmjmkmkmlmlmmmmmnmnmomompmpmqmqmrmrmsmsmtmtmumumvmvmwmwmxmxmymymzmzm{m{m|m|m}m}m~m~mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnnnnnnnnnnn n n n n n n n n n nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn n n!n!n"n"n#n#n$n$n%n%n&n&n'n'n(n(n)n)n*n*n+n+n,n,n-n-n.n.n/n/n0n0n1n1n2n2n3n3n4n4n5n5n6n6n7n7n8n8n9n9n:n:n;n;nn>n?n?n@n@nAnAnBnBnCnCnDnDnEnEnFnFnGnGnHnHnInInJnJnKnKnLnLnMnMnNnNnOnOnPnPnQnQnRnRnSnSnTnTnUnUnVnVnWnWnXnXnYnYnZnZn[n[n\n\n]n]n^n^n_n_n`n`nananbnbncncndndnenenfnfngngnhnhnininjnjnknknlnlnmnmnnnnnononpnpnqnqnrnrnsnsntntnununvnvnwnwnxnxnynynznzn{n{n|n|n}n}n~n~nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnooooooooooooooooooo o o o o o o o o o ooooooooooooooooooooooooooooooooooooo o o!o!o"o"o#o#o$o$o%o%o&o&o'o'o(o(o)o)o*o*o+o+o,o,o-o-o.o.o/o/o0o0o1o1o2o2o3o3o4o4o5o5o6o6o7o7o8o8o9o9o:o:o;o;oo>o?o?o@o@oAoAoBoBoCoCoDoDoEoEoFoFoGoGoHoHoIoIoJoJoKoKoLoLoMoMoNoNoOoOoPoPoQoQoRoRoSoSoToToUoUoVoVoWoWoXoXoYoYoZoZo[o[o\o\o]o]o^o^o_o_o`o`oaoaobobococododoeoeofofogogohohoioiojojokokololomomononooooopopoqoqororososototououovovowowoxoxoyoyozozo{o{o|o|o}o}o~o~ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooppppppppppppppppppp p p p p p p p p p ppppppppppppppppppppppppppppppppppppp p p!p!p"p"p#p#p$p$p%p%p&p&p'p'p(p(p)p)p*p*p+p+p,p,p-p-p.p.p/p/p0p0p1p1p2p2p3p3p4p4p5p5p6p6p7p7p8p8p9p9p:p:p;p;pp>p?p?p@p@pApApBpBpCpCpDpDpEpEpFpFpGpGpHpHpIpIpJpJpKpKpLpLpMpMpNpNpOpOpPpPpQpQpRpRpSpSpTpTpUpUpVpVpWpWpXpXpYpYpZpZp[p[p\p\p]p]p^p^p_p_p`p`papapbpbpcpcpdpdpepepfpfpgpgphphpipipjpjpkpkplplpmpmpnpnpopopppppqpqprprpspsptptpupupvpvpwpwpxpxpypypzpzp{p{p|p|p}p}p~p~ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppqqqqqqqqqqqqqqqqqqq q q q q q q q q q qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq q q!q!q"q"q#q#q$q$q%q%q&q&q'q'q(q(q)q)q*q*q+q+q,q,q-q-q.q.q/q/q0q0q1q1q2q2q3q3q4q4q5q5q6q6q7q7q8q8q9q9q:q:q;q;qq>q?q?q@q@qAqAqBqBqCqCqDqDqEqEqFqFqGqGqHqHqIqIqJqJqKqKqLqLqMqMqNqNqOqOqPqPqQqQqRqRqSqSqTqTqUqUqVqVqWqWqXqXqYqYqZqZq[q[q\q\q]q]q^q^q_q_q`q`qaqaqbqbqcqcqdqdqeqeqfqfqgqgqhqhqiqiqjqjqkqkqlqlqmqmqnqnqoqoqpqpqqqqqrqrqsqsqtqtququqvqvqwqwqxqxqyqyqzqzq{q{q|q|q}q}q~q~qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqrrrrrrrrrrrrrrrrrrr r r r r r r r r r rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr r r!r!r"r"r#r#r$r$r%r%r&r&r'r'r(r(r)r)r*r*r+r+r,r,r-r-r.r.r/r/r0r0r1r1r2r2r3r3r4r4r5r5r6r6r7r7r8r8r9r9r:r:r;r;rr>r?r?r@r@rArArBrBrCrCrDrDrErErFrFrGrGrHrHrIrIrJrJrKrKrLrLrMrMrNrNrOrOrPrPrQrQrRrRrSrSrTrTrUrUrVrVrWrWrXrXrYrYrZrZr[r[r\r\r]r]r^r^r_r_r`r`rararbrbrcrcrdrdrererfrfrgrgrhrhririrjrjrkrkrlrlrmrmrnrnrororprprqrqrrrrrsrsrtrtrururvrvrwrwrxrxryryrzrzr{r{r|r|r}r}r~r~rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrsssssssssssssssssss s s s s s s s s s sssssssssssssssssssssssssssssssssssss s s!s!s"s"s#s#s$s$s%s%s&s&s's's(s(s)s)s*s*s+s+s,s,s-s-s.s.s/s/s0s0s1s1s2s2s3s3s4s4s5s5s6s6s7s7s8s8s9s9s:s:s;s;ss>s?s?s@s@sAsAsBsBsCsCsDsDsEsEsFsFsGsGsHsHsIsIsJsJsKsKsLsLsMsMsNsNsOsOsPsPsQsQsRsRsSsSsTsTsUsUsVsVsWsWsXsXsYsYsZsZs[s[s\s\s]s]s^s^s_s_s`s`sasasbsbscscsdsdsesesfsfsgsgshshsisisjsjskskslslsmsmsnsnsosospspsqsqsrsrssssststsususvsvswswsxsxsysyszszs{s{s|s|s}s}s~s~ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssttttttttttttttttttt t t t t t t t t t ttttttttttttttttttttttttttttttttttttt t t!t!t"t"t#t#t$t$t%t%t&t&t't't(t(t)t)t*t*t+t+t,t,t-t-t.t.t/t/t0t0t1t1t2t2t3t3t4t4t5t5t6t6t7t7t8t8t9t9t:t:t;t;tt>t?t?t@t@tAtAtBtBtCtCtDtDtEtEtFtFtGtGtHtHtItItJtJtKtKtLtLtMtMtNtNtOtOtPtPtQtQtRtRtStStTtTtUtUtVtVtWtWtXtXtYtYtZtZt[t[t\t\t]t]t^t^t_t_t`t`tatatbtbtctctdtdtetetftftgtgththtititjtjtktktltltmtmtntntototptptqtqtrtrtststttttututvtvtwtwtxtxtytytztzt{t{t|t|t}t}t~t~ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttuuuuuuuuuuuuuuuuuuu u u u u u u u u u uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu u u!u!u"u"u#u#u$u$u%u%u&u&u'u'u(u(u)u)u*u*u+u+u,u,u-u-u.u.u/u/u0u0u1u1u2u2u3u3u4u4u5u5u6u6u7u7u8u8u9u9u:u:u;u;uu>u?u?u@u@uAuAuBuBuCuCuDuDuEuEuFuFuGuGuHuHuIuIuJuJuKuKuLuLuMuMuNuNuOuOuPuPuQuQuRuRuSuSuTuTuUuUuVuVuWuWuXuXuYuYuZuZu[u[u\u\u]u]u^u^u_u_u`u`uauaububucucududueueufufuguguhuhuiuiujujukukululumumununuououpupuquqururususututuuuuuvuvuwuwuxuxuyuyuzuzu{u{u|u|u}u}u~u~uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuvvvvvvvvvvvvvvvvvvv v v v v v v v v v vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv v v!v!v"v"v#v#v$v$v%v%v&v&v'v'v(v(v)v)v*v*v+v+v,v,v-v-v.v.v/v/v0v0v1v1v2v2v3v3v4v4v5v5v6v6v7v7v8v8v9v9v:v:v;v;vv>v?v?v@v@vAvAvBvBvCvCvDvDvEvEvFvFvGvGvHvHvIvIvJvJvKvKvLvLvMvMvNvNvOvOvPvPvQvQvRvRvSvSvTvTvUvUvVvVvWvWvXvXvYvYvZvZv[v[v\v\v]v]v^v^v_v_v`v`vavavbvbvcvcvdvdvevevfvfvgvgvhvhvivivjvjvkvkvlvlvmvmvnvnvovovpvpvqvqvrvrvsvsvtvtvuvuvvvvvwvwvxvxvyvyvzvzv{v{v|v|v}v}v~v~vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvwwwwwwwwwwwwwwwwwww w w w w w w w w w wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww w w!w!w"w"w#w#w$w$w%w%w&w&w'w'w(w(w)w)w*w*w+w+w,w,w-w-w.w.w/w/w0w0w1w1w2w2w3w3w4w4w5w5w6w6w7w7w8w8w9w9w:w:w;w;ww>w?w?w@w@wAwAwBwBwCwCwDwDwEwEwFwFwGwGwHwHwIwIwJwJwKwKwLwLwMwMwNwNwOwOwPwPwQwQwRwRwSwSwTwTwUwUwVwVwWwWwXwXwYwYwZwZw[w[w\w\w]w]w^w^w_w_w`w`wawawbwbwcwcwdwdwewewfwfwgwgwhwhwiwiwjwjwkwkwlwlwmwmwnwnwowowpwpwqwqwrwrwswswtwtwuwuwvwvwwwwwxwxwywywzwzw{w{w|w|w}w}w~w~wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxxxxxxxxxxxxxxxxx x x x x x x x x x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx x x!x!x"x"x#x#x$x$x%x%x&x&x'x'x(x(x)x)x*x*x+x+x,x,x-x-x.x.x/x/x0x0x1x1x2x2x3x3x4x4x5x5x6x6x7x7x8x8x9x9x:x:x;x;xx>x?x?x@x@xAxAxBxBxCxCxDxDxExExFxFxGxGxHxHxIxIxJxJxKxKxLxLxMxMxNxNxOxOxPxPxQxQxRxRxSxSxTxTxUxUxVxVxWxWxXxXxYxYxZxZx[x[x\x\x]x]x^x^x_x_x`x`xaxaxbxbxcxcxdxdxexexfxfxgxgxhxhxixixjxjxkxkxlxlxmxmxnxnxoxoxpxpxqxqxrxrxsxsxtxtxuxuxvxvxwxwxxxxxyxyxzxzx{x{x|x|x}x}x~x~xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyy y y y y y y y y y yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy y y!y!y"y"y#y#y$y$y%y%y&y&y'y'y(y(y)y)y*y*y+y+y,y,y-y-y.y.y/y/y0y0y1y1y2y2y3y3y4y4y5y5y6y6y7y7y8y8y9y9y:y:y;y;yy>y?y?y@y@yAyAyByByCyCyDyDyEyEyFyFyGyGyHyHyIyIyJyJyKyKyLyLyMyMyNyNyOyOyPyPyQyQyRyRySySyTyTyUyUyVyVyWyWyXyXyYyYyZyZy[y[y\y\y]y]y^y^y_y_y`y`yayaybybycycydydyeyeyfyfygygyhyhyiyiyjyjykykylylymymynynyoyoypypyqyqyryrysysytytyuyuyvyvywywyxyxyyyyyzyzy{y{y|y|y}y}y~y~yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyzzzzzzzzzzzzzzzzzzz z z z z z z z z z zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz z z!z!z"z"z#z#z$z$z%z%z&z&z'z'z(z(z)z)z*z*z+z+z,z,z-z-z.z.z/z/z0z0z1z1z2z2z3z3z4z4z5z5z6z6z7z7z8z8z9z9z:z:z;z;zz>z?z?z@z@zAzAzBzBzCzCzDzDzEzEzFzFzGzGzHzHzIzIzJzJzKzKzLzLzMzMzNzNzOzOzPzPzQzQzRzRzSzSzTzTzUzUzVzVzWzWzXzXzYzYzZzZz[z[z\z\z]z]z^z^z_z_z`z`zazazbzbzczczdzdzezezfzfzgzgzhzhzizizjzjzkzkzlzlzmzmznznzozozpzpzqzqzrzrzszsztztzuzuzvzvzwzwzxzxzyzyzzzzz{z{z|z|z}z}z~z~zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz{{{{{{{{{{{{{{{{{{{ { { { { { { { { { {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ { {!{!{"{"{#{#{${${%{%{&{&{'{'{({({){){*{*{+{+{,{,{-{-{.{.{/{/{0{0{1{1{2{2{3{3{4{4{5{5{6{6{7{7{8{8{9{9{:{:{;{;{<{<{={={>{>{?{?{@{@{A{A{B{B{C{C{D{D{E{E{F{F{G{G{H{H{I{I{J{J{K{K{L{L{M{M{N{N{O{O{P{P{Q{Q{R{R{S{S{T{T{U{U{V{V{W{W{X{X{Y{Y{Z{Z{[{[{\{\{]{]{^{^{_{_{`{`{a{a{b{b{c{c{d{d{e{e{f{f{g{g{h{h{i{i{j{j{k{k{l{l{m{m{n{n{o{o{p{p{q{q{r{r{s{s{t{t{u{u{v{v{w{w{x{x{y{y{z{z{{{{{|{|{}{}{~{~{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{||||||||||||||||||| | | | | | | | | | ||||||||||||||||||||||||||||||||||||| | |!|!|"|"|#|#|$|$|%|%|&|&|'|'|(|(|)|)|*|*|+|+|,|,|-|-|.|.|/|/|0|0|1|1|2|2|3|3|4|4|5|5|6|6|7|7|8|8|9|9|:|:|;|;|<|<|=|=|>|>|?|?|@|@|A|A|B|B|C|C|D|D|E|E|F|F|G|G|H|H|I|I|J|J|K|K|L|L|M|M|N|N|O|O|P|P|Q|Q|R|R|S|S|T|T|U|U|V|V|W|W|X|X|Y|Y|Z|Z|[|[|\|\|]|]|^|^|_|_|`|`|a|a|b|b|c|c|d|d|e|e|f|f|g|g|h|h|i|i|j|j|k|k|l|l|m|m|n|n|o|o|p|p|q|q|r|r|s|s|t|t|u|u|v|v|w|w|x|x|y|y|z|z|{|{|||||}|}|~|~||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}}}}}}}}}}}}}}}}}}} } } } } } } } } } }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} } }!}!}"}"}#}#}$}$}%}%}&}&}'}'}(}(})})}*}*}+}+},},}-}-}.}.}/}/}0}0}1}1}2}2}3}3}4}4}5}5}6}6}7}7}8}8}9}9}:}:};};}<}<}=}=}>}>}?}?}@}@}A}A}B}B}C}C}D}D}E}E}F}F}G}G}H}H}I}I}J}J}K}K}L}L}M}M}N}N}O}O}P}P}Q}Q}R}R}S}S}T}T}U}U}V}V}W}W}X}X}Y}Y}Z}Z}[}[}\}\}]}]}^}^}_}_}`}`}a}a}b}b}c}c}d}d}e}e}f}f}g}g}h}h}i}i}j}j}k}k}l}l}m}m}n}n}o}o}p}p}q}q}r}r}s}s}t}t}u}u}v}v}w}w}x}x}y}y}z}z}{}{}|}|}}}}}~}~}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}~~~~~~~~~~~~~~~~~~~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~ ~!~!~"~"~#~#~$~$~%~%~&~&~'~'~(~(~)~)~*~*~+~+~,~,~-~-~.~.~/~/~0~0~1~1~2~2~3~3~4~4~5~5~6~6~7~7~8~8~9~9~:~:~;~;~<~<~=~=~>~>~?~?~@~@~A~A~B~B~C~C~D~D~E~E~F~F~G~G~H~H~I~I~J~J~K~K~L~L~M~M~N~N~O~O~P~P~Q~Q~R~R~S~S~T~T~U~U~V~V~W~W~X~X~Y~Y~Z~Z~[~[~\~\~]~]~^~^~_~_~`~`~a~a~b~b~c~c~d~d~e~e~f~f~g~g~h~h~i~i~j~j~k~k~l~l~m~m~n~n~o~o~p~p~q~q~r~r~s~s~t~t~u~u~v~v~w~w~x~x~y~y~z~z~{~{~|~|~}~}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~            !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀ ̀ ̀!̀!̀"̀"̀#̀#̀$̀$̀%̀%̀&̀&̀'̀'̀(̀(̀)̀)̀*̀*̀+̀+̀,̀,̀-̀-̀.̀.̀/̀/̀0̀0̀1̀1̀2̀2̀3̀3̀4̀4̀5̀5̀6̀6̀7̀7̀8̀8̀9̀9̀:̀:̀;̀;̀<̀<̀=̀=̀>̀>̀?̀?̀@̀@̀ÀÀB̀B̀C̀C̀D̀D̀ÈÈF̀F̀G̀G̀H̀H̀ÌÌJ̀J̀K̀K̀L̀L̀M̀M̀ǸǸÒÒP̀P̀Q̀Q̀R̀R̀S̀S̀T̀T̀ÙÙV̀V̀ẀẀX̀X̀ỲỲZ̀Z̀[̀[̀\̀\̀]̀]̀^̀^̀_̀_̀`̀`̀ààb̀b̀c̀c̀d̀d̀èèf̀f̀g̀g̀h̀h̀ììj̀j̀k̀k̀l̀l̀m̀m̀ǹǹòòp̀p̀q̀q̀r̀r̀s̀s̀t̀t̀ùùv̀v̀ẁẁx̀x̀ỳỳz̀z̀{̀{̀|̀|̀}̀}̀~̀~̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀̀́́́́́́́́́́́́́́́́́́́ ́ ́ ́ ́ ́ ́ ́ ́ ́ ́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́ ́ ́!́!́"́"́#́#́$́$́%́%́&́&́'́'́(́(́)́)́*́*́+́+́,́,́-́-́.́.́/́/́0́0́1́1́2́2́3́3́4́4́5́5́6́6́7́7́8́8́9́9́:́:́;́;́<́<́=́=́>́>́?́?́@́@́ÁÁB́B́ĆĆD́D́ÉÉF́F́ǴǴH́H́ÍÍJ́J́ḰḰĹĹḾḾŃŃÓÓṔṔQ́Q́ŔŔŚŚT́T́ÚÚV́V́ẂẂX́X́ÝÝŹŹ[́[́\́\́]́]́^́^́_́_́`́`́ááb́b́ććd́d́ééf́f́ǵǵh́h́ííj́j́ḱḱĺĺḿḿńńóóṕṕq́q́ŕŕśśt́t́úúv́v́ẃẃx́x́ýýźź{́{́|́|́}́}́~́~́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́́͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂ ͂ ͂ ͂ ͂ ͂ ͂ ͂ ͂ ͂ ͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂ ͂ ͂!͂!͂"͂"͂#͂#͂$͂$͂%͂%͂&͂&͂'͂'͂(͂(͂)͂)͂*͂*͂+͂+͂,͂,͂-͂-͂.͂.͂/͂/͂0͂0͂1͂1͂2͂2͂3͂3͂4͂4͂5͂5͂6͂6͂7͂7͂8͂8͂9͂9͂:͂:͂;͂;͂<͂<͂=͂=͂>͂>͂?͂?͂@͂@͂A͂A͂B͂B͂C͂C͂D͂D͂E͂E͂F͂F͂G͂G͂H͂H͂I͂I͂J͂J͂K͂K͂L͂L͂M͂M͂N͂N͂O͂O͂P͂P͂Q͂Q͂R͂R͂S͂S͂T͂T͂U͂U͂V͂V͂W͂W͂X͂X͂Y͂Y͂Z͂Z͂[͂[͂\͂\͂]͂]͂^͂^͂_͂_͂`͂`͂a͂a͂b͂b͂c͂c͂d͂d͂e͂e͂f͂f͂g͂g͂h͂h͂i͂i͂j͂j͂k͂k͂l͂l͂m͂m͂n͂n͂o͂o͂p͂p͂q͂q͂r͂r͂s͂s͂t͂t͂u͂u͂v͂v͂w͂w͂x͂x͂y͂y͂z͂z͂{͂{͂|͂|͂}͂}͂~͂~͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂͂̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓ ̓ ̓ ̓ ̓ ̓ ̓ ̓ ̓ ̓ ̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓ ̓ ̓!̓!̓"̓"̓#̓#̓$̓$̓%̓%̓&̓&̓'̓'̓(̓(̓)̓)̓*̓*̓+̓+̓,̓,̓-̓-̓.̓.̓/̓/̓0̓0̓1̓1̓2̓2̓3̓3̓4̓4̓5̓5̓6̓6̓7̓7̓8̓8̓9̓9̓:̓:̓;̓;̓<̓<̓=̓=̓>̓>̓?̓?̓@̓@̓A̓A̓B̓B̓C̓C̓D̓D̓E̓E̓F̓F̓G̓G̓H̓H̓I̓I̓J̓J̓K̓K̓L̓L̓M̓M̓N̓N̓O̓O̓P̓P̓Q̓Q̓R̓R̓S̓S̓T̓T̓U̓U̓V̓V̓W̓W̓X̓X̓Y̓Y̓Z̓Z̓[̓[̓\̓\̓]̓]̓^̓^̓_̓_̓`̓`̓a̓a̓b̓b̓c̓c̓d̓d̓e̓e̓f̓f̓g̓g̓h̓h̓i̓i̓j̓j̓k̓k̓l̓l̓m̓m̓n̓n̓o̓o̓p̓p̓q̓q̓r̓r̓s̓s̓t̓t̓u̓u̓v̓v̓w̓w̓x̓x̓y̓y̓z̓z̓{̓{̓|̓|̓}̓}̓~̓~̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̓̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́ ̈́ ̈́ ̈́ ̈́ ̈́ ̈́ ̈́ ̈́ ̈́ ̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́ ̈́ ̈́!̈́!̈́"̈́"̈́#̈́#̈́$̈́$̈́%̈́%̈́&̈́&̈́'̈́'̈́(̈́(̈́)̈́)̈́*̈́*̈́+̈́+̈́,̈́,̈́-̈́-̈́.̈́.̈́/̈́/̈́0̈́0̈́1̈́1̈́2̈́2̈́3̈́3̈́4̈́4̈́5̈́5̈́6̈́6̈́7̈́7̈́8̈́8̈́9̈́9̈́:̈́:̈́;̈́;̈́<̈́<̈́=̈́=̈́>̈́>̈́?̈́?̈́@̈́@̈́Ä́Ä́B̈́B̈́C̈́C̈́D̈́D̈́Ë́Ë́F̈́F̈́G̈́G̈́Ḧ́Ḧ́ḮḮJ̈́J̈́K̈́K̈́L̈́L̈́M̈́M̈́N̈́N̈́Ö́Ö́P̈́P̈́Q̈́Q̈́R̈́R̈́S̈́S̈́T̈́T̈́ǗǗV̈́V̈́Ẅ́Ẅ́Ẍ́Ẍ́Ÿ́Ÿ́Z̈́Z̈́[̈́[̈́\̈́\̈́]̈́]̈́^̈́^̈́_̈́_̈́`̈́`̈́ä́ä́b̈́b̈́c̈́c̈́d̈́d̈́ë́ë́f̈́f̈́g̈́g̈́ḧ́ḧ́ḯḯj̈́j̈́k̈́k̈́l̈́l̈́m̈́m̈́n̈́n̈́ö́ö́p̈́p̈́q̈́q̈́r̈́r̈́s̈́s̈́ẗ́ẗ́ǘǘv̈́v̈́ẅ́ẅ́ẍ́ẍ́ÿ́ÿ́z̈́z̈́{̈́{̈́|̈́|̈́}̈́}̈́~̈́~̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́̈́ͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅ ͅ ͅ ͅ ͅ ͅ ͅ ͅ ͅ ͅ ͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅ ͅ ͅ!ͅ!ͅ"ͅ"ͅ#ͅ#ͅ$ͅ$ͅ%ͅ%ͅ&ͅ&ͅ'ͅ'ͅ(ͅ(ͅ)ͅ)ͅ*ͅ*ͅ+ͅ+ͅ,ͅ,ͅ-ͅ-ͅ.ͅ.ͅ/ͅ/ͅ0ͅ0ͅ1ͅ1ͅ2ͅ2ͅ3ͅ3ͅ4ͅ4ͅ5ͅ5ͅ6ͅ6ͅ7ͅ7ͅ8ͅ8ͅ9ͅ9ͅ:ͅ:ͅ;ͅ;ͅ<ͅ<ͅ=ͅ=ͅ>ͅ>ͅ?ͅ?ͅ@ͅ@ͅAͅAͅBͅBͅCͅCͅDͅDͅEͅEͅFͅFͅGͅGͅHͅHͅIͅIͅJͅJͅKͅKͅLͅLͅMͅMͅNͅNͅOͅOͅPͅPͅQͅQͅRͅRͅSͅSͅTͅTͅUͅUͅVͅVͅWͅWͅXͅXͅYͅYͅZͅZͅ[ͅ[ͅ\ͅ\ͅ]ͅ]ͅ^ͅ^ͅ_ͅ_ͅ`ͅ`ͅaͅaͅbͅbͅcͅcͅdͅdͅeͅeͅfͅfͅgͅgͅhͅhͅiͅiͅjͅjͅkͅkͅlͅlͅmͅmͅnͅnͅoͅoͅpͅpͅqͅqͅrͅrͅsͅsͅtͅtͅuͅuͅvͅvͅwͅwͅxͅxͅyͅyͅzͅzͅ{ͅ{ͅ|ͅ|ͅ}ͅ}ͅ~ͅ~͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆ͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅͅ ͆ ͆ ͆ ͆ ͆ ͆ ͆ ͆ ͆ ͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆ ͆ ͆!͆!͆"͆"͆#͆#͆$͆$͆%͆%͆&͆&͆'͆'͆(͆(͆)͆)͆*͆*͆+͆+͆,͆,͆-͆-͆.͆.͆/͆/͆0͆0͆1͆1͆2͆2͆3͆3͆4͆4͆5͆5͆6͆6͆7͆7͆8͆8͆9͆9͆:͆:͆;͆;͆<͆<͆=͆=͆>͆>͆?͆?͆@͆@͆A͆A͆B͆B͆C͆C͆D͆D͆E͆E͆F͆F͆G͆G͆H͆H͆I͆I͆J͆J͆K͆K͆L͆L͆M͆M͆N͆N͆O͆O͆P͆P͆Q͆Q͆R͆R͆S͆S͆T͆T͆U͆U͆V͆V͆W͆W͆X͆X͆Y͆Y͆Z͆Z͆[͆[͆\͆\͆]͆]͆^͆^͆_͆_͆`͆`͆a͆a͆b͆b͆c͆c͆d͆d͆e͆e͆f͆f͆g͆g͆h͆h͆i͆i͆j͆j͆k͆k͆l͆l͆m͆m͆n͆n͆o͆o͆p͆p͆q͆q͆r͆r͆s͆s͆t͆t͆u͆u͆v͆v͆w͆w͆x͆x͆y͆y͆z͆z͆{͆{͆|͆|͆}͆}͆~͆~͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆͆ ͇ ͇ ͇ ͇ ͇ ͇ ͇ ͇ ͇ ͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇ ͇ ͇!͇!͇"͇"͇#͇#͇$͇$͇%͇%͇&͇&͇'͇'͇(͇(͇)͇)͇*͇*͇+͇+͇,͇,͇-͇-͇.͇.͇/͇/͇0͇0͇1͇1͇2͇2͇3͇3͇4͇4͇5͇5͇6͇6͇7͇7͇8͇8͇9͇9͇:͇:͇;͇;͇<͇<͇=͇=͇>͇>͇?͇?͇@͇@͇A͇A͇B͇B͇C͇C͇D͇D͇E͇E͇F͇F͇G͇G͇H͇H͇I͇I͇J͇J͇K͇K͇L͇L͇M͇M͇N͇N͇O͇O͇P͇P͇Q͇Q͇R͇R͇S͇S͇T͇T͇U͇U͇V͇V͇W͇W͇X͇X͇Y͇Y͇Z͇Z͇[͇[͇\͇\͇]͇]͇^͇^͇_͇_͇`͇`͇a͇a͇b͇b͇c͇c͇d͇d͇e͇e͇f͇f͇g͇g͇h͇h͇i͇i͇j͇j͇k͇k͇l͇l͇m͇m͇n͇n͇o͇o͇p͇p͇q͇q͇r͇r͇s͇s͇t͇t͇u͇u͇v͇v͇w͇w͇x͇x͇y͇y͇z͇z͇{͇{͇|͇|͇}͇}͇~͇~͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈ ͈ ͈ ͈ ͈ ͈ ͈ ͈ ͈ ͈ ͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈ ͈ ͈!͈!͈"͈"͈#͈#͈$͈$͈%͈%͈&͈&͈'͈'͈(͈(͈)͈)͈*͈*͈+͈+͈,͈,͈-͈-͈.͈.͈/͈/͈0͈0͈1͈1͈2͈2͈3͈3͈4͈4͈5͈5͈6͈6͈7͈7͈8͈8͈9͈9͈:͈:͈;͈;͈<͈<͈=͈=͈>͈>͈?͈?͈@͈@͈A͈A͈B͈B͈C͈C͈D͈D͈E͈E͈F͈F͈G͈G͈H͈H͈I͈I͈J͈J͈K͈K͈L͈L͈M͈M͈N͈N͈O͈O͈P͈P͈Q͈Q͈R͈R͈S͈S͈T͈T͈U͈U͈V͈V͈W͈W͈X͈X͈Y͈Y͈Z͈Z͈[͈[͈\͈\͈]͈]͈^͈^͈_͈_͈`͈`͈a͈a͈b͈b͈c͈c͈d͈d͈e͈e͈f͈f͈g͈g͈h͈h͈i͈i͈j͈j͈k͈k͈l͈l͈m͈m͈n͈n͈o͈o͈p͈p͈q͈q͈r͈r͈s͈s͈t͈t͈u͈u͈v͈v͈w͈w͈x͈x͈y͈y͈z͈z͈{͈{͈|͈|͈}͈}͈~͈~͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͈͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉ ͉ ͉ ͉ ͉ ͉ ͉ ͉ ͉ ͉ ͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉ ͉ ͉!͉!͉"͉"͉#͉#͉$͉$͉%͉%͉&͉&͉'͉'͉(͉(͉)͉)͉*͉*͉+͉+͉,͉,͉-͉-͉.͉.͉/͉/͉0͉0͉1͉1͉2͉2͉3͉3͉4͉4͉5͉5͉6͉6͉7͉7͉8͉8͉9͉9͉:͉:͉;͉;͉<͉<͉=͉=͉>͉>͉?͉?͉@͉@͉A͉A͉B͉B͉C͉C͉D͉D͉E͉E͉F͉F͉G͉G͉H͉H͉I͉I͉J͉J͉K͉K͉L͉L͉M͉M͉N͉N͉O͉O͉P͉P͉Q͉Q͉R͉R͉S͉S͉T͉T͉U͉U͉V͉V͉W͉W͉X͉X͉Y͉Y͉Z͉Z͉[͉[͉\͉\͉]͉]͉^͉^͉_͉_͉`͉`͉a͉a͉b͉b͉c͉c͉d͉d͉e͉e͉f͉f͉g͉g͉h͉h͉i͉i͉j͉j͉k͉k͉l͉l͉m͉m͉n͉n͉o͉o͉p͉p͉q͉q͉r͉r͉s͉s͉t͉t͉u͉u͉v͉v͉w͉w͉x͉x͉y͉y͉z͉z͉{͉{͉|͉|͉}͉}͉~͉~͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͉͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊ ͊ ͊ ͊ ͊ ͊ ͊ ͊ ͊ ͊ ͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊ ͊ ͊!͊!͊"͊"͊#͊#͊$͊$͊%͊%͊&͊&͊'͊'͊(͊(͊)͊)͊*͊*͊+͊+͊,͊,͊-͊-͊.͊.͊/͊/͊0͊0͊1͊1͊2͊2͊3͊3͊4͊4͊5͊5͊6͊6͊7͊7͊8͊8͊9͊9͊:͊:͊;͊;͊<͊<͊=͊=͊>͊>͊?͊?͊@͊@͊A͊A͊B͊B͊C͊C͊D͊D͊E͊E͊F͊F͊G͊G͊H͊H͊I͊I͊J͊J͊K͊K͊L͊L͊M͊M͊N͊N͊O͊O͊P͊P͊Q͊Q͊R͊R͊S͊S͊T͊T͊U͊U͊V͊V͊W͊W͊X͊X͊Y͊Y͊Z͊Z͊[͊[͊\͊\͊]͊]͊^͊^͊_͊_͊`͊`͊a͊a͊b͊b͊c͊c͊d͊d͊e͊e͊f͊f͊g͊g͊h͊h͊i͊i͊j͊j͊k͊k͊l͊l͊m͊m͊n͊n͊o͊o͊p͊p͊q͊q͊r͊r͊s͊s͊t͊t͊u͊u͊v͊v͊w͊w͊x͊x͊y͊y͊z͊z͊{͊{͊|͊|͊}͊}͊~͊~͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͊͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋ ͋ ͋ ͋ ͋ ͋ ͋ ͋ ͋ ͋ ͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋ ͋ ͋!͋!͋"͋"͋#͋#͋$͋$͋%͋%͋&͋&͋'͋'͋(͋(͋)͋)͋*͋*͋+͋+͋,͋,͋-͋-͋.͋.͋/͋/͋0͋0͋1͋1͋2͋2͋3͋3͋4͋4͋5͋5͋6͋6͋7͋7͋8͋8͋9͋9͋:͋:͋;͋;͋<͋<͋=͋=͋>͋>͋?͋?͋@͋@͋A͋A͋B͋B͋C͋C͋D͋D͋E͋E͋F͋F͋G͋G͋H͋H͋I͋I͋J͋J͋K͋K͋L͋L͋M͋M͋N͋N͋O͋O͋P͋P͋Q͋Q͋R͋R͋S͋S͋T͋T͋U͋U͋V͋V͋W͋W͋X͋X͋Y͋Y͋Z͋Z͋[͋[͋\͋\͋]͋]͋^͋^͋_͋_͋`͋`͋a͋a͋b͋b͋c͋c͋d͋d͋e͋e͋f͋f͋g͋g͋h͋h͋i͋i͋j͋j͋k͋k͋l͋l͋m͋m͋n͋n͋o͋o͋p͋p͋q͋q͋r͋r͋s͋s͋t͋t͋u͋u͋v͋v͋w͋w͋x͋x͋y͋y͋z͋z͋{͋{͋|͋|͋}͋}͋~͋~͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͋͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌ ͌ ͌ ͌ ͌ ͌ ͌ ͌ ͌ ͌ ͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌ ͌ ͌!͌!͌"͌"͌#͌#͌$͌$͌%͌%͌&͌&͌'͌'͌(͌(͌)͌)͌*͌*͌+͌+͌,͌,͌-͌-͌.͌.͌/͌/͌0͌0͌1͌1͌2͌2͌3͌3͌4͌4͌5͌5͌6͌6͌7͌7͌8͌8͌9͌9͌:͌:͌;͌;͌<͌<͌=͌=͌>͌>͌?͌?͌@͌@͌A͌A͌B͌B͌C͌C͌D͌D͌E͌E͌F͌F͌G͌G͌H͌H͌I͌I͌J͌J͌K͌K͌L͌L͌M͌M͌N͌N͌O͌O͌P͌P͌Q͌Q͌R͌R͌S͌S͌T͌T͌U͌U͌V͌V͌W͌W͌X͌X͌Y͌Y͌Z͌Z͌[͌[͌\͌\͌]͌]͌^͌^͌_͌_͌`͌`͌a͌a͌b͌b͌c͌c͌d͌d͌e͌e͌f͌f͌g͌g͌h͌h͌i͌i͌j͌j͌k͌k͌l͌l͌m͌m͌n͌n͌o͌o͌p͌p͌q͌q͌r͌r͌s͌s͌t͌t͌u͌u͌v͌v͌w͌w͌x͌x͌y͌y͌z͌z͌{͌{͌|͌|͌}͌}͌~͌~͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌͌ ͍ ͍ ͍ ͍ ͍ ͍ ͍ ͍ ͍ ͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍ ͍ ͍!͍!͍"͍"͍#͍#͍$͍$͍%͍%͍&͍&͍'͍'͍(͍(͍)͍)͍*͍*͍+͍+͍,͍,͍-͍-͍.͍.͍/͍/͍0͍0͍1͍1͍2͍2͍3͍3͍4͍4͍5͍5͍6͍6͍7͍7͍8͍8͍9͍9͍:͍:͍;͍;͍<͍<͍=͍=͍>͍>͍?͍?͍@͍@͍A͍A͍B͍B͍C͍C͍D͍D͍E͍E͍F͍F͍G͍G͍H͍H͍I͍I͍J͍J͍K͍K͍L͍L͍M͍M͍N͍N͍O͍O͍P͍P͍Q͍Q͍R͍R͍S͍S͍T͍T͍U͍U͍V͍V͍W͍W͍X͍X͍Y͍Y͍Z͍Z͍[͍[͍\͍\͍]͍]͍^͍^͍_͍_͍`͍`͍a͍a͍b͍b͍c͍c͍d͍d͍e͍e͍f͍f͍g͍g͍h͍h͍i͍i͍j͍j͍k͍k͍l͍l͍m͍m͍n͍n͍o͍o͍p͍p͍q͍q͍r͍r͍s͍s͍t͍t͍u͍u͍v͍v͍w͍w͍x͍x͍y͍y͍z͍z͍{͍{͍|͍|͍}͍}͍~͍~͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͍͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎ ͎ ͎ ͎ ͎ ͎ ͎ ͎ ͎ ͎ ͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎ ͎ ͎!͎!͎"͎"͎#͎#͎$͎$͎%͎%͎&͎&͎'͎'͎(͎(͎)͎)͎*͎*͎+͎+͎,͎,͎-͎-͎.͎.͎/͎/͎0͎0͎1͎1͎2͎2͎3͎3͎4͎4͎5͎5͎6͎6͎7͎7͎8͎8͎9͎9͎:͎:͎;͎;͎<͎<͎=͎=͎>͎>͎?͎?͎@͎@͎A͎A͎B͎B͎C͎C͎D͎D͎E͎E͎F͎F͎G͎G͎H͎H͎I͎I͎J͎J͎K͎K͎L͎L͎M͎M͎N͎N͎O͎O͎P͎P͎Q͎Q͎R͎R͎S͎S͎T͎T͎U͎U͎V͎V͎W͎W͎X͎X͎Y͎Y͎Z͎Z͎[͎[͎\͎\͎]͎]͎^͎^͎_͎_͎`͎`͎a͎a͎b͎b͎c͎c͎d͎d͎e͎e͎f͎f͎g͎g͎h͎h͎i͎i͎j͎j͎k͎k͎l͎l͎m͎m͎n͎n͎o͎o͎p͎p͎q͎q͎r͎r͎s͎s͎t͎t͎u͎u͎v͎v͎w͎w͎x͎x͎y͎y͎z͎z͎{͎{͎|͎|͎}͎}͎~͎~͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͎͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏ ͏ ͏!͏!͏"͏"͏#͏#͏$͏$͏%͏%͏&͏&͏'͏'͏(͏(͏)͏)͏*͏*͏+͏+͏,͏,͏-͏-͏.͏.͏/͏/͏0͏0͏1͏1͏2͏2͏3͏3͏4͏4͏5͏5͏6͏6͏7͏7͏8͏8͏9͏9͏:͏:͏;͏;͏<͏<͏=͏=͏>͏>͏?͏?͏@͏@͏A͏A͏B͏B͏C͏C͏D͏D͏E͏E͏F͏F͏G͏G͏H͏H͏I͏I͏J͏J͏K͏K͏L͏L͏M͏M͏N͏N͏O͏O͏P͏P͏Q͏Q͏R͏R͏S͏S͏T͏T͏U͏U͏V͏V͏W͏W͏X͏X͏Y͏Y͏Z͏Z͏[͏[͏\͏\͏]͏]͏^͏^͏_͏_͏`͏`͏a͏a͏b͏b͏c͏c͏d͏d͏e͏e͏f͏f͏g͏g͏h͏h͏i͏i͏j͏j͏k͏k͏l͏l͏m͏m͏n͏n͏o͏o͏p͏p͏q͏q͏r͏r͏s͏s͏t͏t͏u͏u͏v͏v͏w͏w͏x͏x͏y͏y͏z͏z͏{͏{͏|͏|͏}͏}͏~͏~͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͏͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐ ͐ ͐ ͐ ͐ ͐ ͐ ͐ ͐ ͐ ͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐ ͐ ͐!͐!͐"͐"͐#͐#͐$͐$͐%͐%͐&͐&͐'͐'͐(͐(͐)͐)͐*͐*͐+͐+͐,͐,͐-͐-͐.͐.͐/͐/͐0͐0͐1͐1͐2͐2͐3͐3͐4͐4͐5͐5͐6͐6͐7͐7͐8͐8͐9͐9͐:͐:͐;͐;͐<͐<͐=͐=͐>͐>͐?͐?͐@͐@͐A͐A͐B͐B͐C͐C͐D͐D͐E͐E͐F͐F͐G͐G͐H͐H͐I͐I͐J͐J͐K͐K͐L͐L͐M͐M͐N͐N͐O͐O͐P͐P͐Q͐Q͐R͐R͐S͐S͐T͐T͐U͐U͐V͐V͐W͐W͐X͐X͐Y͐Y͐Z͐Z͐[͐[͐\͐\͐]͐]͐^͐^͐_͐_͐`͐`͐a͐a͐b͐b͐c͐c͐d͐d͐e͐e͐f͐f͐g͐g͐h͐h͐i͐i͐j͐j͐k͐k͐l͐l͐m͐m͐n͐n͐o͐o͐p͐p͐q͐q͐r͐r͐s͐s͐t͐t͐u͐u͐v͐v͐w͐w͐x͐x͐y͐y͐z͐z͐{͐{͐|͐|͐}͐}͐~͐~͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͐͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑ ͑ ͑ ͑ ͑ ͑ ͑ ͑ ͑ ͑ ͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑ ͑ ͑!͑!͑"͑"͑#͑#͑$͑$͑%͑%͑&͑&͑'͑'͑(͑(͑)͑)͑*͑*͑+͑+͑,͑,͑-͑-͑.͑.͑/͑/͑0͑0͑1͑1͑2͑2͑3͑3͑4͑4͑5͑5͑6͑6͑7͑7͑8͑8͑9͑9͑:͑:͑;͑;͑<͑<͑=͑=͑>͑>͑?͑?͑@͑@͑A͑A͑B͑B͑C͑C͑D͑D͑E͑E͑F͑F͑G͑G͑H͑H͑I͑I͑J͑J͑K͑K͑L͑L͑M͑M͑N͑N͑O͑O͑P͑P͑Q͑Q͑R͑R͑S͑S͑T͑T͑U͑U͑V͑V͑W͑W͑X͑X͑Y͑Y͑Z͑Z͑[͑[͑\͑\͑]͑]͑^͑^͑_͑_͑`͑`͑a͑a͑b͑b͑c͑c͑d͑d͑e͑e͑f͑f͑g͑g͑h͑h͑i͑i͑j͑j͑k͑k͑l͑l͑m͑m͑n͑n͑o͑o͑p͑p͑q͑q͑r͑r͑s͑s͑t͑t͑u͑u͑v͑v͑w͑w͑x͑x͑y͑y͑z͑z͑{͑{͑|͑|͑}͑}͑~͑~͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͑͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒ ͒ ͒ ͒ ͒ ͒ ͒ ͒ ͒ ͒ ͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒ ͒ ͒!͒!͒"͒"͒#͒#͒$͒$͒%͒%͒&͒&͒'͒'͒(͒(͒)͒)͒*͒*͒+͒+͒,͒,͒-͒-͒.͒.͒/͒/͒0͒0͒1͒1͒2͒2͒3͒3͒4͒4͒5͒5͒6͒6͒7͒7͒8͒8͒9͒9͒:͒:͒;͒;͒<͒<͒=͒=͒>͒>͒?͒?͒@͒@͒A͒A͒B͒B͒C͒C͒D͒D͒E͒E͒F͒F͒G͒G͒H͒H͒I͒I͒J͒J͒K͒K͒L͒L͒M͒M͒N͒N͒O͒O͒P͒P͒Q͒Q͒R͒R͒S͒S͒T͒T͒U͒U͒V͒V͒W͒W͒X͒X͒Y͒Y͒Z͒Z͒[͒[͒\͒\͒]͒]͒^͒^͒_͒_͒`͒`͒a͒a͒b͒b͒c͒c͒d͒d͒e͒e͒f͒f͒g͒g͒h͒h͒i͒i͒j͒j͒k͒k͒l͒l͒m͒m͒n͒n͒o͒o͒p͒p͒q͒q͒r͒r͒s͒s͒t͒t͒u͒u͒v͒v͒w͒w͒x͒x͒y͒y͒z͒z͒{͒{͒|͒|͒}͒}͒~͒~͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒͒ ͓ ͓ ͓ ͓ ͓ ͓ ͓ ͓ ͓ ͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓ ͓ ͓!͓!͓"͓"͓#͓#͓$͓$͓%͓%͓&͓&͓'͓'͓(͓(͓)͓)͓*͓*͓+͓+͓,͓,͓-͓-͓.͓.͓/͓/͓0͓0͓1͓1͓2͓2͓3͓3͓4͓4͓5͓5͓6͓6͓7͓7͓8͓8͓9͓9͓:͓:͓;͓;͓<͓<͓=͓=͓>͓>͓?͓?͓@͓@͓A͓A͓B͓B͓C͓C͓D͓D͓E͓E͓F͓F͓G͓G͓H͓H͓I͓I͓J͓J͓K͓K͓L͓L͓M͓M͓N͓N͓O͓O͓P͓P͓Q͓Q͓R͓R͓S͓S͓T͓T͓U͓U͓V͓V͓W͓W͓X͓X͓Y͓Y͓Z͓Z͓[͓[͓\͓\͓]͓]͓^͓^͓_͓_͓`͓`͓a͓a͓b͓b͓c͓c͓d͓d͓e͓e͓f͓f͓g͓g͓h͓h͓i͓i͓j͓j͓k͓k͓l͓l͓m͓m͓n͓n͓o͓o͓p͓p͓q͓q͓r͓r͓s͓s͓t͓t͓u͓u͓v͓v͓w͓w͓x͓x͓y͓y͓z͓z͓{͓{͓|͓|͓}͓}͓~͓~͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔ ͔ ͔ ͔ ͔ ͔ ͔ ͔ ͔ ͔ ͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔ ͔ ͔!͔!͔"͔"͔#͔#͔$͔$͔%͔%͔&͔&͔'͔'͔(͔(͔)͔)͔*͔*͔+͔+͔,͔,͔-͔-͔.͔.͔/͔/͔0͔0͔1͔1͔2͔2͔3͔3͔4͔4͔5͔5͔6͔6͔7͔7͔8͔8͔9͔9͔:͔:͔;͔;͔<͔<͔=͔=͔>͔>͔?͔?͔@͔@͔A͔A͔B͔B͔C͔C͔D͔D͔E͔E͔F͔F͔G͔G͔H͔H͔I͔I͔J͔J͔K͔K͔L͔L͔M͔M͔N͔N͔O͔O͔P͔P͔Q͔Q͔R͔R͔S͔S͔T͔T͔U͔U͔V͔V͔W͔W͔X͔X͔Y͔Y͔Z͔Z͔[͔[͔\͔\͔]͔]͔^͔^͔_͔_͔`͔`͔a͔a͔b͔b͔c͔c͔d͔d͔e͔e͔f͔f͔g͔g͔h͔h͔i͔i͔j͔j͔k͔k͔l͔l͔m͔m͔n͔n͔o͔o͔p͔p͔q͔q͔r͔r͔s͔s͔t͔t͔u͔u͔v͔v͔w͔w͔x͔x͔y͔y͔z͔z͔{͔{͔|͔|͔}͔}͔~͔~͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͔͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕ ͕ ͕ ͕ ͕ ͕ ͕ ͕ ͕ ͕ ͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕ ͕ ͕!͕!͕"͕"͕#͕#͕$͕$͕%͕%͕&͕&͕'͕'͕(͕(͕)͕)͕*͕*͕+͕+͕,͕,͕-͕-͕.͕.͕/͕/͕0͕0͕1͕1͕2͕2͕3͕3͕4͕4͕5͕5͕6͕6͕7͕7͕8͕8͕9͕9͕:͕:͕;͕;͕<͕<͕=͕=͕>͕>͕?͕?͕@͕@͕A͕A͕B͕B͕C͕C͕D͕D͕E͕E͕F͕F͕G͕G͕H͕H͕I͕I͕J͕J͕K͕K͕L͕L͕M͕M͕N͕N͕O͕O͕P͕P͕Q͕Q͕R͕R͕S͕S͕T͕T͕U͕U͕V͕V͕W͕W͕X͕X͕Y͕Y͕Z͕Z͕[͕[͕\͕\͕]͕]͕^͕^͕_͕_͕`͕`͕a͕a͕b͕b͕c͕c͕d͕d͕e͕e͕f͕f͕g͕g͕h͕h͕i͕i͕j͕j͕k͕k͕l͕l͕m͕m͕n͕n͕o͕o͕p͕p͕q͕q͕r͕r͕s͕s͕t͕t͕u͕u͕v͕v͕w͕w͕x͕x͕y͕y͕z͕z͕{͕{͕|͕|͕}͕}͕~͕~͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͕͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖ ͖ ͖ ͖ ͖ ͖ ͖ ͖ ͖ ͖ ͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖ ͖ ͖!͖!͖"͖"͖#͖#͖$͖$͖%͖%͖&͖&͖'͖'͖(͖(͖)͖)͖*͖*͖+͖+͖,͖,͖-͖-͖.͖.͖/͖/͖0͖0͖1͖1͖2͖2͖3͖3͖4͖4͖5͖5͖6͖6͖7͖7͖8͖8͖9͖9͖:͖:͖;͖;͖<͖<͖=͖=͖>͖>͖?͖?͖@͖@͖A͖A͖B͖B͖C͖C͖D͖D͖E͖E͖F͖F͖G͖G͖H͖H͖I͖I͖J͖J͖K͖K͖L͖L͖M͖M͖N͖N͖O͖O͖P͖P͖Q͖Q͖R͖R͖S͖S͖T͖T͖U͖U͖V͖V͖W͖W͖X͖X͖Y͖Y͖Z͖Z͖[͖[͖\͖\͖]͖]͖^͖^͖_͖_͖`͖`͖a͖a͖b͖b͖c͖c͖d͖d͖e͖e͖f͖f͖g͖g͖h͖h͖i͖i͖j͖j͖k͖k͖l͖l͖m͖m͖n͖n͖o͖o͖p͖p͖q͖q͖r͖r͖s͖s͖t͖t͖u͖u͖v͖v͖w͖w͖x͖x͖y͖y͖z͖z͖{͖{͖|͖|͖}͖}͖~͖~͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͖͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗ ͗ ͗ ͗ ͗ ͗ ͗ ͗ ͗ ͗ ͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗ ͗ ͗!͗!͗"͗"͗#͗#͗$͗$͗%͗%͗&͗&͗'͗'͗(͗(͗)͗)͗*͗*͗+͗+͗,͗,͗-͗-͗.͗.͗/͗/͗0͗0͗1͗1͗2͗2͗3͗3͗4͗4͗5͗5͗6͗6͗7͗7͗8͗8͗9͗9͗:͗:͗;͗;͗<͗<͗=͗=͗>͗>͗?͗?͗@͗@͗A͗A͗B͗B͗C͗C͗D͗D͗E͗E͗F͗F͗G͗G͗H͗H͗I͗I͗J͗J͗K͗K͗L͗L͗M͗M͗N͗N͗O͗O͗P͗P͗Q͗Q͗R͗R͗S͗S͗T͗T͗U͗U͗V͗V͗W͗W͗X͗X͗Y͗Y͗Z͗Z͗[͗[͗\͗\͗]͗]͗^͗^͗_͗_͗`͗`͗a͗a͗b͗b͗c͗c͗d͗d͗e͗e͗f͗f͗g͗g͗h͗h͗i͗i͗j͗j͗k͗k͗l͗l͗m͗m͗n͗n͗o͗o͗p͗p͗q͗q͗r͗r͗s͗s͗t͗t͗u͗u͗v͗v͗w͗w͗x͗x͗y͗y͗z͗z͗{͗{͗|͗|͗}͗}͗~͗~͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͗͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘ ͘ ͘ ͘ ͘ ͘ ͘ ͘ ͘ ͘ ͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘ ͘ ͘!͘!͘"͘"͘#͘#͘$͘$͘%͘%͘&͘&͘'͘'͘(͘(͘)͘)͘*͘*͘+͘+͘,͘,͘-͘-͘.͘.͘/͘/͘0͘0͘1͘1͘2͘2͘3͘3͘4͘4͘5͘5͘6͘6͘7͘7͘8͘8͘9͘9͘:͘:͘;͘;͘<͘<͘=͘=͘>͘>͘?͘?͘@͘@͘A͘A͘B͘B͘C͘C͘D͘D͘E͘E͘F͘F͘G͘G͘H͘H͘I͘I͘J͘J͘K͘K͘L͘L͘M͘M͘N͘N͘O͘O͘P͘P͘Q͘Q͘R͘R͘S͘S͘T͘T͘U͘U͘V͘V͘W͘W͘X͘X͘Y͘Y͘Z͘Z͘[͘[͘\͘\͘]͘]͘^͘^͘_͘_͘`͘`͘a͘a͘b͘b͘c͘c͘d͘d͘e͘e͘f͘f͘g͘g͘h͘h͘i͘i͘j͘j͘k͘k͘l͘l͘m͘m͘n͘n͘o͘o͘p͘p͘q͘q͘r͘r͘s͘s͘t͘t͘u͘u͘v͘v͘w͘w͘x͘x͘y͘y͘z͘z͘{͘{͘|͘|͘}͘}͘~͘~͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘͘ ͙ ͙ ͙ ͙ ͙ ͙ ͙ ͙ ͙ ͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙ ͙ ͙!͙!͙"͙"͙#͙#͙$͙$͙%͙%͙&͙&͙'͙'͙(͙(͙)͙)͙*͙*͙+͙+͙,͙,͙-͙-͙.͙.͙/͙/͙0͙0͙1͙1͙2͙2͙3͙3͙4͙4͙5͙5͙6͙6͙7͙7͙8͙8͙9͙9͙:͙:͙;͙;͙<͙<͙=͙=͙>͙>͙?͙?͙@͙@͙A͙A͙B͙B͙C͙C͙D͙D͙E͙E͙F͙F͙G͙G͙H͙H͙I͙I͙J͙J͙K͙K͙L͙L͙M͙M͙N͙N͙O͙O͙P͙P͙Q͙Q͙R͙R͙S͙S͙T͙T͙U͙U͙V͙V͙W͙W͙X͙X͙Y͙Y͙Z͙Z͙[͙[͙\͙\͙]͙]͙^͙^͙_͙_͙`͙`͙a͙a͙b͙b͙c͙c͙d͙d͙e͙e͙f͙f͙g͙g͙h͙h͙i͙i͙j͙j͙k͙k͙l͙l͙m͙m͙n͙n͙o͙o͙p͙p͙q͙q͙r͙r͙s͙s͙t͙t͙u͙u͙v͙v͙w͙w͙x͙x͙y͙y͙z͙z͙{͙{͙|͙|͙}͙}͙~͙~͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͙͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚ ͚ ͚ ͚ ͚ ͚ ͚ ͚ ͚ ͚ ͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚ ͚ ͚!͚!͚"͚"͚#͚#͚$͚$͚%͚%͚&͚&͚'͚'͚(͚(͚)͚)͚*͚*͚+͚+͚,͚,͚-͚-͚.͚.͚/͚/͚0͚0͚1͚1͚2͚2͚3͚3͚4͚4͚5͚5͚6͚6͚7͚7͚8͚8͚9͚9͚:͚:͚;͚;͚<͚<͚=͚=͚>͚>͚?͚?͚@͚@͚A͚A͚B͚B͚C͚C͚D͚D͚E͚E͚F͚F͚G͚G͚H͚H͚I͚I͚J͚J͚K͚K͚L͚L͚M͚M͚N͚N͚O͚O͚P͚P͚Q͚Q͚R͚R͚S͚S͚T͚T͚U͚U͚V͚V͚W͚W͚X͚X͚Y͚Y͚Z͚Z͚[͚[͚\͚\͚]͚]͚^͚^͚_͚_͚`͚`͚a͚a͚b͚b͚c͚c͚d͚d͚e͚e͚f͚f͚g͚g͚h͚h͚i͚i͚j͚j͚k͚k͚l͚l͚m͚m͚n͚n͚o͚o͚p͚p͚q͚q͚r͚r͚s͚s͚t͚t͚u͚u͚v͚v͚w͚w͚x͚x͚y͚y͚z͚z͚{͚{͚|͚|͚}͚}͚~͚~͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͚͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛ ͛ ͛ ͛ ͛ ͛ ͛ ͛ ͛ ͛ ͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛ ͛ ͛!͛!͛"͛"͛#͛#͛$͛$͛%͛%͛&͛&͛'͛'͛(͛(͛)͛)͛*͛*͛+͛+͛,͛,͛-͛-͛.͛.͛/͛/͛0͛0͛1͛1͛2͛2͛3͛3͛4͛4͛5͛5͛6͛6͛7͛7͛8͛8͛9͛9͛:͛:͛;͛;͛<͛<͛=͛=͛>͛>͛?͛?͛@͛@͛A͛A͛B͛B͛C͛C͛D͛D͛E͛E͛F͛F͛G͛G͛H͛H͛I͛I͛J͛J͛K͛K͛L͛L͛M͛M͛N͛N͛O͛O͛P͛P͛Q͛Q͛R͛R͛S͛S͛T͛T͛U͛U͛V͛V͛W͛W͛X͛X͛Y͛Y͛Z͛Z͛[͛[͛\͛\͛]͛]͛^͛^͛_͛_͛`͛`͛a͛a͛b͛b͛c͛c͛d͛d͛e͛e͛f͛f͛g͛g͛h͛h͛i͛i͛j͛j͛k͛k͛l͛l͛m͛m͛n͛n͛o͛o͛p͛p͛q͛q͛r͛r͛s͛s͛t͛t͛u͛u͛v͛v͛w͛w͛x͛x͛y͛y͛z͛z͛{͛{͛|͛|͛}͛}͛~͛~͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͛͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜ ͜ ͜ ͜ ͜ ͜ ͜ ͜ ͜ ͜ ͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜ ͜ ͜!͜!͜"͜"͜#͜#͜$͜$͜%͜%͜&͜&͜'͜'͜(͜(͜)͜)͜*͜*͜+͜+͜,͜,͜-͜-͜.͜.͜/͜/͜0͜0͜1͜1͜2͜2͜3͜3͜4͜4͜5͜5͜6͜6͜7͜7͜8͜8͜9͜9͜:͜:͜;͜;͜<͜<͜=͜=͜>͜>͜?͜?͜@͜@͜A͜A͜B͜B͜C͜C͜D͜D͜E͜E͜F͜F͜G͜G͜H͜H͜I͜I͜J͜J͜K͜K͜L͜L͜M͜M͜N͜N͜O͜O͜P͜P͜Q͜Q͜R͜R͜S͜S͜T͜T͜U͜U͜V͜V͜W͜W͜X͜X͜Y͜Y͜Z͜Z͜[͜[͜\͜\͜]͜]͜^͜^͜_͜_͜`͜`͜a͜a͜b͜b͜c͜c͜d͜d͜e͜e͜f͜f͜g͜g͜h͜h͜i͜i͜j͜j͜k͜k͜l͜l͜m͜m͜n͜n͜o͜o͜p͜p͜q͜q͜r͜r͜s͜s͜t͜t͜u͜u͜v͜v͜w͜w͜x͜x͜y͜y͜z͜z͜{͜{͜|͜|͜}͜}͜~͜~͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝ ͝ ͝ ͝ ͝ ͝ ͝ ͝ ͝ ͝ ͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝ ͝ ͝!͝!͝"͝"͝#͝#͝$͝$͝%͝%͝&͝&͝'͝'͝(͝(͝)͝)͝*͝*͝+͝+͝,͝,͝-͝-͝.͝.͝/͝/͝0͝0͝1͝1͝2͝2͝3͝3͝4͝4͝5͝5͝6͝6͝7͝7͝8͝8͝9͝9͝:͝:͝;͝;͝<͝<͝=͝=͝>͝>͝?͝?͝@͝@͝A͝A͝B͝B͝C͝C͝D͝D͝E͝E͝F͝F͝G͝G͝H͝H͝I͝I͝J͝J͝K͝K͝L͝L͝M͝M͝N͝N͝O͝O͝P͝P͝Q͝Q͝R͝R͝S͝S͝T͝T͝U͝U͝V͝V͝W͝W͝X͝X͝Y͝Y͝Z͝Z͝[͝[͝\͝\͝]͝]͝^͝^͝_͝_͝`͝`͝a͝a͝b͝b͝c͝c͝d͝d͝e͝e͝f͝f͝g͝g͝h͝h͝i͝i͝j͝j͝k͝k͝l͝l͝m͝m͝n͝n͝o͝o͝p͝p͝q͝q͝r͝r͝s͝s͝t͝t͝u͝u͝v͝v͝w͝w͝x͝x͝y͝y͝z͝z͝{͝{͝|͝|͝}͝}͝~͝~͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͝͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞ ͞ ͞ ͞ ͞ ͞ ͞ ͞ ͞ ͞ ͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞ ͞ ͞!͞!͞"͞"͞#͞#͞$͞$͞%͞%͞&͞&͞'͞'͞(͞(͞)͞)͞*͞*͞+͞+͞,͞,͞-͞-͞.͞.͞/͞/͞0͞0͞1͞1͞2͞2͞3͞3͞4͞4͞5͞5͞6͞6͞7͞7͞8͞8͞9͞9͞:͞:͞;͞;͞<͞<͞=͞=͞>͞>͞?͞?͞@͞@͞A͞A͞B͞B͞C͞C͞D͞D͞E͞E͞F͞F͞G͞G͞H͞H͞I͞I͞J͞J͞K͞K͞L͞L͞M͞M͞N͞N͞O͞O͞P͞P͞Q͞Q͞R͞R͞S͞S͞T͞T͞U͞U͞V͞V͞W͞W͞X͞X͞Y͞Y͞Z͞Z͞[͞[͞\͞\͞]͞]͞^͞^͞_͞_͞`͞`͞a͞a͞b͞b͞c͞c͞d͞d͞e͞e͞f͞f͞g͞g͞h͞h͞i͞i͞j͞j͞k͞k͞l͞l͞m͞m͞n͞n͞o͞o͞p͞p͞q͞q͞r͞r͞s͞s͞t͞t͞u͞u͞v͞v͞w͞w͞x͞x͞y͞y͞z͞z͞{͞{͞|͞|͞}͞}͞~͞~͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞͞ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟ ͟ ͟!͟!͟"͟"͟#͟#͟$͟$͟%͟%͟&͟&͟'͟'͟(͟(͟)͟)͟*͟*͟+͟+͟,͟,͟-͟-͟.͟.͟/͟/͟0͟0͟1͟1͟2͟2͟3͟3͟4͟4͟5͟5͟6͟6͟7͟7͟8͟8͟9͟9͟:͟:͟;͟;͟<͟<͟=͟=͟>͟>͟?͟?͟@͟@͟A͟A͟B͟B͟C͟C͟D͟D͟E͟E͟F͟F͟G͟G͟H͟H͟I͟I͟J͟J͟K͟K͟L͟L͟M͟M͟N͟N͟O͟O͟P͟P͟Q͟Q͟R͟R͟S͟S͟T͟T͟U͟U͟V͟V͟W͟W͟X͟X͟Y͟Y͟Z͟Z͟[͟[͟\͟\͟]͟]͟^͟^͟_͟_͟`͟`͟a͟a͟b͟b͟c͟c͟d͟d͟e͟e͟f͟f͟g͟g͟h͟h͟i͟i͟j͟j͟k͟k͟l͟l͟m͟m͟n͟n͟o͟o͟p͟p͟q͟q͟r͟r͟s͟s͟t͟t͟u͟u͟v͟v͟w͟w͟x͟x͟y͟y͟z͟z͟{͟{͟|͟|͟}͟}͟~͟~͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͟͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠ ͠ ͠ ͠ ͠ ͠ ͠ ͠ ͠ ͠ ͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠ ͠ ͠!͠!͠"͠"͠#͠#͠$͠$͠%͠%͠&͠&͠'͠'͠(͠(͠)͠)͠*͠*͠+͠+͠,͠,͠-͠-͠.͠.͠/͠/͠0͠0͠1͠1͠2͠2͠3͠3͠4͠4͠5͠5͠6͠6͠7͠7͠8͠8͠9͠9͠:͠:͠;͠;͠<͠<͠=͠=͠>͠>͠?͠?͠@͠@͠A͠A͠B͠B͠C͠C͠D͠D͠E͠E͠F͠F͠G͠G͠H͠H͠I͠I͠J͠J͠K͠K͠L͠L͠M͠M͠N͠N͠O͠O͠P͠P͠Q͠Q͠R͠R͠S͠S͠T͠T͠U͠U͠V͠V͠W͠W͠X͠X͠Y͠Y͠Z͠Z͠[͠[͠\͠\͠]͠]͠^͠^͠_͠_͠`͠`͠a͠a͠b͠b͠c͠c͠d͠d͠e͠e͠f͠f͠g͠g͠h͠h͠i͠i͠j͠j͠k͠k͠l͠l͠m͠m͠n͠n͠o͠o͠p͠p͠q͠q͠r͠r͠s͠s͠t͠t͠u͠u͠v͠v͠w͠w͠x͠x͠y͠y͠z͠z͠{͠{͠|͠|͠}͠}͠~͠~͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͠͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡ ͡ ͡ ͡ ͡ ͡ ͡ ͡ ͡ ͡ ͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡ ͡ ͡!͡!͡"͡"͡#͡#͡$͡$͡%͡%͡&͡&͡'͡'͡(͡(͡)͡)͡*͡*͡+͡+͡,͡,͡-͡-͡.͡.͡/͡/͡0͡0͡1͡1͡2͡2͡3͡3͡4͡4͡5͡5͡6͡6͡7͡7͡8͡8͡9͡9͡:͡:͡;͡;͡<͡<͡=͡=͡>͡>͡?͡?͡@͡@͡A͡A͡B͡B͡C͡C͡D͡D͡E͡E͡F͡F͡G͡G͡H͡H͡I͡I͡J͡J͡K͡K͡L͡L͡M͡M͡N͡N͡O͡O͡P͡P͡Q͡Q͡R͡R͡S͡S͡T͡T͡U͡U͡V͡V͡W͡W͡X͡X͡Y͡Y͡Z͡Z͡[͡[͡\͡\͡]͡]͡^͡^͡_͡_͡`͡`͡a͡a͡b͡b͡c͡c͡d͡d͡e͡e͡f͡f͡g͡g͡h͡h͡i͡i͡j͡j͡k͡k͡l͡l͡m͡m͡n͡n͡o͡o͡p͡p͡q͡q͡r͡r͡s͡s͡t͡t͡u͡u͡v͡v͡w͡w͡x͡x͡y͡y͡z͡z͡{͡{͡|͡|͡}͡}͡~͡~͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡͡ ͢ ͢ ͢ ͢ ͢ ͢ ͢ ͢ ͢ ͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢ ͢ ͢!͢!͢"͢"͢#͢#͢$͢$͢%͢%͢&͢&͢'͢'͢(͢(͢)͢)͢*͢*͢+͢+͢,͢,͢-͢-͢.͢.͢/͢/͢0͢0͢1͢1͢2͢2͢3͢3͢4͢4͢5͢5͢6͢6͢7͢7͢8͢8͢9͢9͢:͢:͢;͢;͢<͢<͢=͢=͢>͢>͢?͢?͢@͢@͢A͢A͢B͢B͢C͢C͢D͢D͢E͢E͢F͢F͢G͢G͢H͢H͢I͢I͢J͢J͢K͢K͢L͢L͢M͢M͢N͢N͢O͢O͢P͢P͢Q͢Q͢R͢R͢S͢S͢T͢T͢U͢U͢V͢V͢W͢W͢X͢X͢Y͢Y͢Z͢Z͢[͢[͢\͢\͢]͢]͢^͢^͢_͢_͢`͢`͢a͢a͢b͢b͢c͢c͢d͢d͢e͢e͢f͢f͢g͢g͢h͢h͢i͢i͢j͢j͢k͢k͢l͢l͢m͢m͢n͢n͢o͢o͢p͢p͢q͢q͢r͢r͢s͢s͢t͢t͢u͢u͢v͢v͢w͢w͢x͢x͢y͢y͢z͢z͢{͢{͢|͢|͢}͢}͢~͢~ͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣ͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢͢ ͣ ͣ ͣ ͣ ͣ ͣ ͣ ͣ ͣ ͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣ ͣ ͣ!ͣ!ͣ"ͣ"ͣ#ͣ#ͣ$ͣ$ͣ%ͣ%ͣ&ͣ&ͣ'ͣ'ͣ(ͣ(ͣ)ͣ)ͣ*ͣ*ͣ+ͣ+ͣ,ͣ,ͣ-ͣ-ͣ.ͣ.ͣ/ͣ/ͣ0ͣ0ͣ1ͣ1ͣ2ͣ2ͣ3ͣ3ͣ4ͣ4ͣ5ͣ5ͣ6ͣ6ͣ7ͣ7ͣ8ͣ8ͣ9ͣ9ͣ:ͣ:ͣ;ͣ;ͣ<ͣ<ͣ=ͣ=ͣ>ͣ>ͣ?ͣ?ͣ@ͣ@ͣAͣAͣBͣBͣCͣCͣDͣDͣEͣEͣFͣFͣGͣGͣHͣHͣIͣIͣJͣJͣKͣKͣLͣLͣMͣMͣNͣNͣOͣOͣPͣPͣQͣQͣRͣRͣSͣSͣTͣTͣUͣUͣVͣVͣWͣWͣXͣXͣYͣYͣZͣZͣ[ͣ[ͣ\ͣ\ͣ]ͣ]ͣ^ͣ^ͣ_ͣ_ͣ`ͣ`ͣaͣaͣbͣbͣcͣcͣdͣdͣeͣeͣfͣfͣgͣgͣhͣhͣiͣiͣjͣjͣkͣkͣlͣlͣmͣmͣnͣnͣoͣoͣpͣpͣqͣqͣrͣrͣsͣsͣtͣtͣuͣuͣvͣvͣwͣwͣxͣxͣyͣyͣzͣzͣ{ͣ{ͣ|ͣ|ͣ}ͣ}ͣ~ͣ~ͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͣͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤ ͤ ͤ ͤ ͤ ͤ ͤ ͤ ͤ ͤ ͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤ ͤ ͤ!ͤ!ͤ"ͤ"ͤ#ͤ#ͤ$ͤ$ͤ%ͤ%ͤ&ͤ&ͤ'ͤ'ͤ(ͤ(ͤ)ͤ)ͤ*ͤ*ͤ+ͤ+ͤ,ͤ,ͤ-ͤ-ͤ.ͤ.ͤ/ͤ/ͤ0ͤ0ͤ1ͤ1ͤ2ͤ2ͤ3ͤ3ͤ4ͤ4ͤ5ͤ5ͤ6ͤ6ͤ7ͤ7ͤ8ͤ8ͤ9ͤ9ͤ:ͤ:ͤ;ͤ;ͤ<ͤ<ͤ=ͤ=ͤ>ͤ>ͤ?ͤ?ͤ@ͤ@ͤAͤAͤBͤBͤCͤCͤDͤDͤEͤEͤFͤFͤGͤGͤHͤHͤIͤIͤJͤJͤKͤKͤLͤLͤMͤMͤNͤNͤOͤOͤPͤPͤQͤQͤRͤRͤSͤSͤTͤTͤUͤUͤVͤVͤWͤWͤXͤXͤYͤYͤZͤZͤ[ͤ[ͤ\ͤ\ͤ]ͤ]ͤ^ͤ^ͤ_ͤ_ͤ`ͤ`ͤaͤaͤbͤbͤcͤcͤdͤdͤeͤeͤfͤfͤgͤgͤhͤhͤiͤiͤjͤjͤkͤkͤlͤlͤmͤmͤnͤnͤoͤoͤpͤpͤqͤqͤrͤrͤsͤsͤtͤtͤuͤuͤvͤvͤwͤwͤxͤxͤyͤyͤzͤzͤ{ͤ{ͤ|ͤ|ͤ}ͤ}ͤ~ͤ~ͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͤͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥ ͥ ͥ ͥ ͥ ͥ ͥ ͥ ͥ ͥ ͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥ ͥ ͥ!ͥ!ͥ"ͥ"ͥ#ͥ#ͥ$ͥ$ͥ%ͥ%ͥ&ͥ&ͥ'ͥ'ͥ(ͥ(ͥ)ͥ)ͥ*ͥ*ͥ+ͥ+ͥ,ͥ,ͥ-ͥ-ͥ.ͥ.ͥ/ͥ/ͥ0ͥ0ͥ1ͥ1ͥ2ͥ2ͥ3ͥ3ͥ4ͥ4ͥ5ͥ5ͥ6ͥ6ͥ7ͥ7ͥ8ͥ8ͥ9ͥ9ͥ:ͥ:ͥ;ͥ;ͥ<ͥ<ͥ=ͥ=ͥ>ͥ>ͥ?ͥ?ͥ@ͥ@ͥAͥAͥBͥBͥCͥCͥDͥDͥEͥEͥFͥFͥGͥGͥHͥHͥIͥIͥJͥJͥKͥKͥLͥLͥMͥMͥNͥNͥOͥOͥPͥPͥQͥQͥRͥRͥSͥSͥTͥTͥUͥUͥVͥVͥWͥWͥXͥXͥYͥYͥZͥZͥ[ͥ[ͥ\ͥ\ͥ]ͥ]ͥ^ͥ^ͥ_ͥ_ͥ`ͥ`ͥaͥaͥbͥbͥcͥcͥdͥdͥeͥeͥfͥfͥgͥgͥhͥhͥiͥiͥjͥjͥkͥkͥlͥlͥmͥmͥnͥnͥoͥoͥpͥpͥqͥqͥrͥrͥsͥsͥtͥtͥuͥuͥvͥvͥwͥwͥxͥxͥyͥyͥzͥzͥ{ͥ{ͥ|ͥ|ͥ}ͥ}ͥ~ͥ~ͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͥͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦ ͦ ͦ ͦ ͦ ͦ ͦ ͦ ͦ ͦ ͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦ ͦ ͦ!ͦ!ͦ"ͦ"ͦ#ͦ#ͦ$ͦ$ͦ%ͦ%ͦ&ͦ&ͦ'ͦ'ͦ(ͦ(ͦ)ͦ)ͦ*ͦ*ͦ+ͦ+ͦ,ͦ,ͦ-ͦ-ͦ.ͦ.ͦ/ͦ/ͦ0ͦ0ͦ1ͦ1ͦ2ͦ2ͦ3ͦ3ͦ4ͦ4ͦ5ͦ5ͦ6ͦ6ͦ7ͦ7ͦ8ͦ8ͦ9ͦ9ͦ:ͦ:ͦ;ͦ;ͦ<ͦ<ͦ=ͦ=ͦ>ͦ>ͦ?ͦ?ͦ@ͦ@ͦAͦAͦBͦBͦCͦCͦDͦDͦEͦEͦFͦFͦGͦGͦHͦHͦIͦIͦJͦJͦKͦKͦLͦLͦMͦMͦNͦNͦOͦOͦPͦPͦQͦQͦRͦRͦSͦSͦTͦTͦUͦUͦVͦVͦWͦWͦXͦXͦYͦYͦZͦZͦ[ͦ[ͦ\ͦ\ͦ]ͦ]ͦ^ͦ^ͦ_ͦ_ͦ`ͦ`ͦaͦaͦbͦbͦcͦcͦdͦdͦeͦeͦfͦfͦgͦgͦhͦhͦiͦiͦjͦjͦkͦkͦlͦlͦmͦmͦnͦnͦoͦoͦpͦpͦqͦqͦrͦrͦsͦsͦtͦtͦuͦuͦvͦvͦwͦwͦxͦxͦyͦyͦzͦzͦ{ͦ{ͦ|ͦ|ͦ}ͦ}ͦ~ͦ~ͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͦͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧ ͧ ͧ ͧ ͧ ͧ ͧ ͧ ͧ ͧ ͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧ ͧ ͧ!ͧ!ͧ"ͧ"ͧ#ͧ#ͧ$ͧ$ͧ%ͧ%ͧ&ͧ&ͧ'ͧ'ͧ(ͧ(ͧ)ͧ)ͧ*ͧ*ͧ+ͧ+ͧ,ͧ,ͧ-ͧ-ͧ.ͧ.ͧ/ͧ/ͧ0ͧ0ͧ1ͧ1ͧ2ͧ2ͧ3ͧ3ͧ4ͧ4ͧ5ͧ5ͧ6ͧ6ͧ7ͧ7ͧ8ͧ8ͧ9ͧ9ͧ:ͧ:ͧ;ͧ;ͧ<ͧ<ͧ=ͧ=ͧ>ͧ>ͧ?ͧ?ͧ@ͧ@ͧAͧAͧBͧBͧCͧCͧDͧDͧEͧEͧFͧFͧGͧGͧHͧHͧIͧIͧJͧJͧKͧKͧLͧLͧMͧMͧNͧNͧOͧOͧPͧPͧQͧQͧRͧRͧSͧSͧTͧTͧUͧUͧVͧVͧWͧWͧXͧXͧYͧYͧZͧZͧ[ͧ[ͧ\ͧ\ͧ]ͧ]ͧ^ͧ^ͧ_ͧ_ͧ`ͧ`ͧaͧaͧbͧbͧcͧcͧdͧdͧeͧeͧfͧfͧgͧgͧhͧhͧiͧiͧjͧjͧkͧkͧlͧlͧmͧmͧnͧnͧoͧoͧpͧpͧqͧqͧrͧrͧsͧsͧtͧtͧuͧuͧvͧvͧwͧwͧxͧxͧyͧyͧzͧzͧ{ͧ{ͧ|ͧ|ͧ}ͧ}ͧ~ͧ~ͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͧͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨ ͨ ͨ ͨ ͨ ͨ ͨ ͨ ͨ ͨ ͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨ ͨ ͨ!ͨ!ͨ"ͨ"ͨ#ͨ#ͨ$ͨ$ͨ%ͨ%ͨ&ͨ&ͨ'ͨ'ͨ(ͨ(ͨ)ͨ)ͨ*ͨ*ͨ+ͨ+ͨ,ͨ,ͨ-ͨ-ͨ.ͨ.ͨ/ͨ/ͨ0ͨ0ͨ1ͨ1ͨ2ͨ2ͨ3ͨ3ͨ4ͨ4ͨ5ͨ5ͨ6ͨ6ͨ7ͨ7ͨ8ͨ8ͨ9ͨ9ͨ:ͨ:ͨ;ͨ;ͨ<ͨ<ͨ=ͨ=ͨ>ͨ>ͨ?ͨ?ͨ@ͨ@ͨAͨAͨBͨBͨCͨCͨDͨDͨEͨEͨFͨFͨGͨGͨHͨHͨIͨIͨJͨJͨKͨKͨLͨLͨMͨMͨNͨNͨOͨOͨPͨPͨQͨQͨRͨRͨSͨSͨTͨTͨUͨUͨVͨVͨWͨWͨXͨXͨYͨYͨZͨZͨ[ͨ[ͨ\ͨ\ͨ]ͨ]ͨ^ͨ^ͨ_ͨ_ͨ`ͨ`ͨaͨaͨbͨbͨcͨcͨdͨdͨeͨeͨfͨfͨgͨgͨhͨhͨiͨiͨjͨjͨkͨkͨlͨlͨmͨmͨnͨnͨoͨoͨpͨpͨqͨqͨrͨrͨsͨsͨtͨtͨuͨuͨvͨvͨwͨwͨxͨxͨyͨyͨzͨzͨ{ͨ{ͨ|ͨ|ͨ}ͨ}ͨ~ͨ~ͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͨͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩ ͩ ͩ ͩ ͩ ͩ ͩ ͩ ͩ ͩ ͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩ ͩ ͩ!ͩ!ͩ"ͩ"ͩ#ͩ#ͩ$ͩ$ͩ%ͩ%ͩ&ͩ&ͩ'ͩ'ͩ(ͩ(ͩ)ͩ)ͩ*ͩ*ͩ+ͩ+ͩ,ͩ,ͩ-ͩ-ͩ.ͩ.ͩ/ͩ/ͩ0ͩ0ͩ1ͩ1ͩ2ͩ2ͩ3ͩ3ͩ4ͩ4ͩ5ͩ5ͩ6ͩ6ͩ7ͩ7ͩ8ͩ8ͩ9ͩ9ͩ:ͩ:ͩ;ͩ;ͩ<ͩ<ͩ=ͩ=ͩ>ͩ>ͩ?ͩ?ͩ@ͩ@ͩAͩAͩBͩBͩCͩCͩDͩDͩEͩEͩFͩFͩGͩGͩHͩHͩIͩIͩJͩJͩKͩKͩLͩLͩMͩMͩNͩNͩOͩOͩPͩPͩQͩQͩRͩRͩSͩSͩTͩTͩUͩUͩVͩVͩWͩWͩXͩXͩYͩYͩZͩZͩ[ͩ[ͩ\ͩ\ͩ]ͩ]ͩ^ͩ^ͩ_ͩ_ͩ`ͩ`ͩaͩaͩbͩbͩcͩcͩdͩdͩeͩeͩfͩfͩgͩgͩhͩhͩiͩiͩjͩjͩkͩkͩlͩlͩmͩmͩnͩnͩoͩoͩpͩpͩqͩqͩrͩrͩsͩsͩtͩtͩuͩuͩvͩvͩwͩwͩxͩxͩyͩyͩzͩzͩ{ͩ{ͩ|ͩ|ͩ}ͩ}ͩ~ͩ~ͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪ ͪ ͪ ͪ ͪ ͪ ͪ ͪ ͪ ͪ ͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪ ͪ ͪ!ͪ!ͪ"ͪ"ͪ#ͪ#ͪ$ͪ$ͪ%ͪ%ͪ&ͪ&ͪ'ͪ'ͪ(ͪ(ͪ)ͪ)ͪ*ͪ*ͪ+ͪ+ͪ,ͪ,ͪ-ͪ-ͪ.ͪ.ͪ/ͪ/ͪ0ͪ0ͪ1ͪ1ͪ2ͪ2ͪ3ͪ3ͪ4ͪ4ͪ5ͪ5ͪ6ͪ6ͪ7ͪ7ͪ8ͪ8ͪ9ͪ9ͪ:ͪ:ͪ;ͪ;ͪ<ͪ<ͪ=ͪ=ͪ>ͪ>ͪ?ͪ?ͪ@ͪ@ͪAͪAͪBͪBͪCͪCͪDͪDͪEͪEͪFͪFͪGͪGͪHͪHͪIͪIͪJͪJͪKͪKͪLͪLͪMͪMͪNͪNͪOͪOͪPͪPͪQͪQͪRͪRͪSͪSͪTͪTͪUͪUͪVͪVͪWͪWͪXͪXͪYͪYͪZͪZͪ[ͪ[ͪ\ͪ\ͪ]ͪ]ͪ^ͪ^ͪ_ͪ_ͪ`ͪ`ͪaͪaͪbͪbͪcͪcͪdͪdͪeͪeͪfͪfͪgͪgͪhͪhͪiͪiͪjͪjͪkͪkͪlͪlͪmͪmͪnͪnͪoͪoͪpͪpͪqͪqͪrͪrͪsͪsͪtͪtͪuͪuͪvͪvͪwͪwͪxͪxͪyͪyͪzͪzͪ{ͪ{ͪ|ͪ|ͪ}ͪ}ͪ~ͪ~ͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͪͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫ ͫ ͫ ͫ ͫ ͫ ͫ ͫ ͫ ͫ ͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫ ͫ ͫ!ͫ!ͫ"ͫ"ͫ#ͫ#ͫ$ͫ$ͫ%ͫ%ͫ&ͫ&ͫ'ͫ'ͫ(ͫ(ͫ)ͫ)ͫ*ͫ*ͫ+ͫ+ͫ,ͫ,ͫ-ͫ-ͫ.ͫ.ͫ/ͫ/ͫ0ͫ0ͫ1ͫ1ͫ2ͫ2ͫ3ͫ3ͫ4ͫ4ͫ5ͫ5ͫ6ͫ6ͫ7ͫ7ͫ8ͫ8ͫ9ͫ9ͫ:ͫ:ͫ;ͫ;ͫ<ͫ<ͫ=ͫ=ͫ>ͫ>ͫ?ͫ?ͫ@ͫ@ͫAͫAͫBͫBͫCͫCͫDͫDͫEͫEͫFͫFͫGͫGͫHͫHͫIͫIͫJͫJͫKͫKͫLͫLͫMͫMͫNͫNͫOͫOͫPͫPͫQͫQͫRͫRͫSͫSͫTͫTͫUͫUͫVͫVͫWͫWͫXͫXͫYͫYͫZͫZͫ[ͫ[ͫ\ͫ\ͫ]ͫ]ͫ^ͫ^ͫ_ͫ_ͫ`ͫ`ͫaͫaͫbͫbͫcͫcͫdͫdͫeͫeͫfͫfͫgͫgͫhͫhͫiͫiͫjͫjͫkͫkͫlͫlͫmͫmͫnͫnͫoͫoͫpͫpͫqͫqͫrͫrͫsͫsͫtͫtͫuͫuͫvͫvͫwͫwͫxͫxͫyͫyͫzͫzͫ{ͫ{ͫ|ͫ|ͫ}ͫ}ͫ~ͫ~ͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͫͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬ ͬ ͬ ͬ ͬ ͬ ͬ ͬ ͬ ͬ ͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬ ͬ ͬ!ͬ!ͬ"ͬ"ͬ#ͬ#ͬ$ͬ$ͬ%ͬ%ͬ&ͬ&ͬ'ͬ'ͬ(ͬ(ͬ)ͬ)ͬ*ͬ*ͬ+ͬ+ͬ,ͬ,ͬ-ͬ-ͬ.ͬ.ͬ/ͬ/ͬ0ͬ0ͬ1ͬ1ͬ2ͬ2ͬ3ͬ3ͬ4ͬ4ͬ5ͬ5ͬ6ͬ6ͬ7ͬ7ͬ8ͬ8ͬ9ͬ9ͬ:ͬ:ͬ;ͬ;ͬ<ͬ<ͬ=ͬ=ͬ>ͬ>ͬ?ͬ?ͬ@ͬ@ͬAͬAͬBͬBͬCͬCͬDͬDͬEͬEͬFͬFͬGͬGͬHͬHͬIͬIͬJͬJͬKͬKͬLͬLͬMͬMͬNͬNͬOͬOͬPͬPͬQͬQͬRͬRͬSͬSͬTͬTͬUͬUͬVͬVͬWͬWͬXͬXͬYͬYͬZͬZͬ[ͬ[ͬ\ͬ\ͬ]ͬ]ͬ^ͬ^ͬ_ͬ_ͬ`ͬ`ͬaͬaͬbͬbͬcͬcͬdͬdͬeͬeͬfͬfͬgͬgͬhͬhͬiͬiͬjͬjͬkͬkͬlͬlͬmͬmͬnͬnͬoͬoͬpͬpͬqͬqͬrͬrͬsͬsͬtͬtͬuͬuͬvͬvͬwͬwͬxͬxͬyͬyͬzͬzͬ{ͬ{ͬ|ͬ|ͬ}ͬ}ͬ~ͬ~ͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͬͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭ ͭ ͭ ͭ ͭ ͭ ͭ ͭ ͭ ͭ ͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭ ͭ ͭ!ͭ!ͭ"ͭ"ͭ#ͭ#ͭ$ͭ$ͭ%ͭ%ͭ&ͭ&ͭ'ͭ'ͭ(ͭ(ͭ)ͭ)ͭ*ͭ*ͭ+ͭ+ͭ,ͭ,ͭ-ͭ-ͭ.ͭ.ͭ/ͭ/ͭ0ͭ0ͭ1ͭ1ͭ2ͭ2ͭ3ͭ3ͭ4ͭ4ͭ5ͭ5ͭ6ͭ6ͭ7ͭ7ͭ8ͭ8ͭ9ͭ9ͭ:ͭ:ͭ;ͭ;ͭ<ͭ<ͭ=ͭ=ͭ>ͭ>ͭ?ͭ?ͭ@ͭ@ͭAͭAͭBͭBͭCͭCͭDͭDͭEͭEͭFͭFͭGͭGͭHͭHͭIͭIͭJͭJͭKͭKͭLͭLͭMͭMͭNͭNͭOͭOͭPͭPͭQͭQͭRͭRͭSͭSͭTͭTͭUͭUͭVͭVͭWͭWͭXͭXͭYͭYͭZͭZͭ[ͭ[ͭ\ͭ\ͭ]ͭ]ͭ^ͭ^ͭ_ͭ_ͭ`ͭ`ͭaͭaͭbͭbͭcͭcͭdͭdͭeͭeͭfͭfͭgͭgͭhͭhͭiͭiͭjͭjͭkͭkͭlͭlͭmͭmͭnͭnͭoͭoͭpͭpͭqͭqͭrͭrͭsͭsͭtͭtͭuͭuͭvͭvͭwͭwͭxͭxͭyͭyͭzͭzͭ{ͭ{ͭ|ͭ|ͭ}ͭ}ͭ~ͭ~ͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͭͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮ ͮ ͮ ͮ ͮ ͮ ͮ ͮ ͮ ͮ ͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮ ͮ ͮ!ͮ!ͮ"ͮ"ͮ#ͮ#ͮ$ͮ$ͮ%ͮ%ͮ&ͮ&ͮ'ͮ'ͮ(ͮ(ͮ)ͮ)ͮ*ͮ*ͮ+ͮ+ͮ,ͮ,ͮ-ͮ-ͮ.ͮ.ͮ/ͮ/ͮ0ͮ0ͮ1ͮ1ͮ2ͮ2ͮ3ͮ3ͮ4ͮ4ͮ5ͮ5ͮ6ͮ6ͮ7ͮ7ͮ8ͮ8ͮ9ͮ9ͮ:ͮ:ͮ;ͮ;ͮ<ͮ<ͮ=ͮ=ͮ>ͮ>ͮ?ͮ?ͮ@ͮ@ͮAͮAͮBͮBͮCͮCͮDͮDͮEͮEͮFͮFͮGͮGͮHͮHͮIͮIͮJͮJͮKͮKͮLͮLͮMͮMͮNͮNͮOͮOͮPͮPͮQͮQͮRͮRͮSͮSͮTͮTͮUͮUͮVͮVͮWͮWͮXͮXͮYͮYͮZͮZͮ[ͮ[ͮ\ͮ\ͮ]ͮ]ͮ^ͮ^ͮ_ͮ_ͮ`ͮ`ͮaͮaͮbͮbͮcͮcͮdͮdͮeͮeͮfͮfͮgͮgͮhͮhͮiͮiͮjͮjͮkͮkͮlͮlͮmͮmͮnͮnͮoͮoͮpͮpͮqͮqͮrͮrͮsͮsͮtͮtͮuͮuͮvͮvͮwͮwͮxͮxͮyͮyͮzͮzͮ{ͮ{ͮ|ͮ|ͮ}ͮ}ͮ~ͮ~ͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͮͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯ ͯ ͯ ͯ ͯ ͯ ͯ ͯ ͯ ͯ ͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯ ͯ ͯ!ͯ!ͯ"ͯ"ͯ#ͯ#ͯ$ͯ$ͯ%ͯ%ͯ&ͯ&ͯ'ͯ'ͯ(ͯ(ͯ)ͯ)ͯ*ͯ*ͯ+ͯ+ͯ,ͯ,ͯ-ͯ-ͯ.ͯ.ͯ/ͯ/ͯ0ͯ0ͯ1ͯ1ͯ2ͯ2ͯ3ͯ3ͯ4ͯ4ͯ5ͯ5ͯ6ͯ6ͯ7ͯ7ͯ8ͯ8ͯ9ͯ9ͯ:ͯ:ͯ;ͯ;ͯ<ͯ<ͯ=ͯ=ͯ>ͯ>ͯ?ͯ?ͯ@ͯ@ͯAͯAͯBͯBͯCͯCͯDͯDͯEͯEͯFͯFͯGͯGͯHͯHͯIͯIͯJͯJͯKͯKͯLͯLͯMͯMͯNͯNͯOͯOͯPͯPͯQͯQͯRͯRͯSͯSͯTͯTͯUͯUͯVͯVͯWͯWͯXͯXͯYͯYͯZͯZͯ[ͯ[ͯ\ͯ\ͯ]ͯ]ͯ^ͯ^ͯ_ͯ_ͯ`ͯ`ͯaͯaͯbͯbͯcͯcͯdͯdͯeͯeͯfͯfͯgͯgͯhͯhͯiͯiͯjͯjͯkͯkͯlͯlͯmͯmͯnͯnͯoͯoͯpͯpͯqͯqͯrͯrͯsͯsͯtͯtͯuͯuͯvͯvͯwͯwͯxͯxͯyͯyͯzͯzͯ{ͯ{ͯ|ͯ|ͯ}ͯ}ͯ~ͯ~ͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͯͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰ Ͱ Ͱ Ͱ Ͱ Ͱ Ͱ Ͱ Ͱ Ͱ ͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰ Ͱ Ͱ!Ͱ!Ͱ"Ͱ"Ͱ#Ͱ#Ͱ$Ͱ$Ͱ%Ͱ%Ͱ&Ͱ&Ͱ'Ͱ'Ͱ(Ͱ(Ͱ)Ͱ)Ͱ*Ͱ*Ͱ+Ͱ+Ͱ,Ͱ,Ͱ-Ͱ-Ͱ.Ͱ.Ͱ/Ͱ/Ͱ0Ͱ0Ͱ1Ͱ1Ͱ2Ͱ2Ͱ3Ͱ3Ͱ4Ͱ4Ͱ5Ͱ5Ͱ6Ͱ6Ͱ7Ͱ7Ͱ8Ͱ8Ͱ9Ͱ9Ͱ:Ͱ:Ͱ;Ͱ;Ͱ<Ͱ<Ͱ=Ͱ=Ͱ>Ͱ>Ͱ?Ͱ?Ͱ@Ͱ@ͰAͰAͰBͰBͰCͰCͰDͰDͰEͰEͰFͰFͰGͰGͰHͰHͰIͰIͰJͰJͰKͰKͰLͰLͰMͰMͰNͰNͰOͰOͰPͰPͰQͰQͰRͰRͰSͰSͰTͰTͰUͰUͰVͰVͰWͰWͰXͰXͰYͰYͰZͰZͰ[Ͱ[Ͱ\Ͱ\Ͱ]Ͱ]Ͱ^Ͱ^Ͱ_Ͱ_Ͱ`Ͱ`ͰaͰaͰbͰbͰcͰcͰdͰdͰeͰeͰfͰfͰgͰgͰhͰhͰiͰiͰjͰjͰkͰkͰlͰlͰmͰmͰnͰnͰoͰoͰpͰpͰqͰqͰrͰrͰsͰsͰtͰtͰuͰuͰvͰvͰwͰwͰxͰxͰyͰyͰzͰzͰ{Ͱ{Ͱ|Ͱ|Ͱ}Ͱ}Ͱ~Ͱ~ͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͰͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱ ͱ ͱ ͱ ͱ ͱ ͱ ͱ ͱ ͱ ͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱ ͱ ͱ!ͱ!ͱ"ͱ"ͱ#ͱ#ͱ$ͱ$ͱ%ͱ%ͱ&ͱ&ͱ'ͱ'ͱ(ͱ(ͱ)ͱ)ͱ*ͱ*ͱ+ͱ+ͱ,ͱ,ͱ-ͱ-ͱ.ͱ.ͱ/ͱ/ͱ0ͱ0ͱ1ͱ1ͱ2ͱ2ͱ3ͱ3ͱ4ͱ4ͱ5ͱ5ͱ6ͱ6ͱ7ͱ7ͱ8ͱ8ͱ9ͱ9ͱ:ͱ:ͱ;ͱ;ͱ<ͱ<ͱ=ͱ=ͱ>ͱ>ͱ?ͱ?ͱ@ͱ@ͱAͱAͱBͱBͱCͱCͱDͱDͱEͱEͱFͱFͱGͱGͱHͱHͱIͱIͱJͱJͱKͱKͱLͱLͱMͱMͱNͱNͱOͱOͱPͱPͱQͱQͱRͱRͱSͱSͱTͱTͱUͱUͱVͱVͱWͱWͱXͱXͱYͱYͱZͱZͱ[ͱ[ͱ\ͱ\ͱ]ͱ]ͱ^ͱ^ͱ_ͱ_ͱ`ͱ`ͱaͱaͱbͱbͱcͱcͱdͱdͱeͱeͱfͱfͱgͱgͱhͱhͱiͱiͱjͱjͱkͱkͱlͱlͱmͱmͱnͱnͱoͱoͱpͱpͱqͱqͱrͱrͱsͱsͱtͱtͱuͱuͱvͱvͱwͱwͱxͱxͱyͱyͱzͱzͱ{ͱ{ͱ|ͱ|ͱ}ͱ}ͱ~ͱ~ͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͱͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲ Ͳ Ͳ Ͳ Ͳ Ͳ Ͳ Ͳ Ͳ Ͳ ͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲ Ͳ Ͳ!Ͳ!Ͳ"Ͳ"Ͳ#Ͳ#Ͳ$Ͳ$Ͳ%Ͳ%Ͳ&Ͳ&Ͳ'Ͳ'Ͳ(Ͳ(Ͳ)Ͳ)Ͳ*Ͳ*Ͳ+Ͳ+Ͳ,Ͳ,Ͳ-Ͳ-Ͳ.Ͳ.Ͳ/Ͳ/Ͳ0Ͳ0Ͳ1Ͳ1Ͳ2Ͳ2Ͳ3Ͳ3Ͳ4Ͳ4Ͳ5Ͳ5Ͳ6Ͳ6Ͳ7Ͳ7Ͳ8Ͳ8Ͳ9Ͳ9Ͳ:Ͳ:Ͳ;Ͳ;Ͳ<Ͳ<Ͳ=Ͳ=Ͳ>Ͳ>Ͳ?Ͳ?Ͳ@Ͳ@ͲAͲAͲBͲBͲCͲCͲDͲDͲEͲEͲFͲFͲGͲGͲHͲHͲIͲIͲJͲJͲKͲKͲLͲLͲMͲMͲNͲNͲOͲOͲPͲPͲQͲQͲRͲRͲSͲSͲTͲTͲUͲUͲVͲVͲWͲWͲXͲXͲYͲYͲZͲZͲ[Ͳ[Ͳ\Ͳ\Ͳ]Ͳ]Ͳ^Ͳ^Ͳ_Ͳ_Ͳ`Ͳ`ͲaͲaͲbͲbͲcͲcͲdͲdͲeͲeͲfͲfͲgͲgͲhͲhͲiͲiͲjͲjͲkͲkͲlͲlͲmͲmͲnͲnͲoͲoͲpͲpͲqͲqͲrͲrͲsͲsͲtͲtͲuͲuͲvͲvͲwͲwͲxͲxͲyͲyͲzͲzͲ{Ͳ{Ͳ|Ͳ|Ͳ}Ͳ}Ͳ~Ͳ~ͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͲͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳ ͳ ͳ ͳ ͳ ͳ ͳ ͳ ͳ ͳ ͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳ ͳ ͳ!ͳ!ͳ"ͳ"ͳ#ͳ#ͳ$ͳ$ͳ%ͳ%ͳ&ͳ&ͳ'ͳ'ͳ(ͳ(ͳ)ͳ)ͳ*ͳ*ͳ+ͳ+ͳ,ͳ,ͳ-ͳ-ͳ.ͳ.ͳ/ͳ/ͳ0ͳ0ͳ1ͳ1ͳ2ͳ2ͳ3ͳ3ͳ4ͳ4ͳ5ͳ5ͳ6ͳ6ͳ7ͳ7ͳ8ͳ8ͳ9ͳ9ͳ:ͳ:ͳ;ͳ;ͳ<ͳ<ͳ=ͳ=ͳ>ͳ>ͳ?ͳ?ͳ@ͳ@ͳAͳAͳBͳBͳCͳCͳDͳDͳEͳEͳFͳFͳGͳGͳHͳHͳIͳIͳJͳJͳKͳKͳLͳLͳMͳMͳNͳNͳOͳOͳPͳPͳQͳQͳRͳRͳSͳSͳTͳTͳUͳUͳVͳVͳWͳWͳXͳXͳYͳYͳZͳZͳ[ͳ[ͳ\ͳ\ͳ]ͳ]ͳ^ͳ^ͳ_ͳ_ͳ`ͳ`ͳaͳaͳbͳbͳcͳcͳdͳdͳeͳeͳfͳfͳgͳgͳhͳhͳiͳiͳjͳjͳkͳkͳlͳlͳmͳmͳnͳnͳoͳoͳpͳpͳqͳqͳrͳrͳsͳsͳtͳtͳuͳuͳvͳvͳwͳwͳxͳxͳyͳyͳzͳzͳ{ͳ{ͳ|ͳ|ͳ}ͳ}ͳ~ͳ~ͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳͳʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹ ʹ ʹ ʹ ʹ ʹ ʹ ʹ ʹ ʹ ʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹ ʹ ʹ!ʹ!ʹ"ʹ"ʹ#ʹ#ʹ$ʹ$ʹ%ʹ%ʹ&ʹ&ʹ'ʹ'ʹ(ʹ(ʹ)ʹ)ʹ*ʹ*ʹ+ʹ+ʹ,ʹ,ʹ-ʹ-ʹ.ʹ.ʹ/ʹ/ʹ0ʹ0ʹ1ʹ1ʹ2ʹ2ʹ3ʹ3ʹ4ʹ4ʹ5ʹ5ʹ6ʹ6ʹ7ʹ7ʹ8ʹ8ʹ9ʹ9ʹ:ʹ:ʹ;ʹ;ʹ<ʹ<ʹ=ʹ=ʹ>ʹ>ʹ?ʹ?ʹ@ʹ@ʹAʹAʹBʹBʹCʹCʹDʹDʹEʹEʹFʹFʹGʹGʹHʹHʹIʹIʹJʹJʹKʹKʹLʹLʹMʹMʹNʹNʹOʹOʹPʹPʹQʹQʹRʹRʹSʹSʹTʹTʹUʹUʹVʹVʹWʹWʹXʹXʹYʹYʹZʹZʹ[ʹ[ʹ\ʹ\ʹ]ʹ]ʹ^ʹ^ʹ_ʹ_ʹ`ʹ`ʹaʹaʹbʹbʹcʹcʹdʹdʹeʹeʹfʹfʹgʹgʹhʹhʹiʹiʹjʹjʹkʹkʹlʹlʹmʹmʹnʹnʹoʹoʹpʹpʹqʹqʹrʹrʹsʹsʹtʹtʹuʹuʹvʹvʹwʹwʹxʹxʹyʹyʹzʹzʹ{ʹ{ʹ|ʹ|ʹ}ʹ}ʹ~ʹ~ʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹʹ͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵ ͵ ͵ ͵ ͵ ͵ ͵ ͵ ͵ ͵ ͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵ ͵ ͵!͵!͵"͵"͵#͵#͵$͵$͵%͵%͵&͵&͵'͵'͵(͵(͵)͵)͵*͵*͵+͵+͵,͵,͵-͵-͵.͵.͵/͵/͵0͵0͵1͵1͵2͵2͵3͵3͵4͵4͵5͵5͵6͵6͵7͵7͵8͵8͵9͵9͵:͵:͵;͵;͵<͵<͵=͵=͵>͵>͵?͵?͵@͵@͵A͵A͵B͵B͵C͵C͵D͵D͵E͵E͵F͵F͵G͵G͵H͵H͵I͵I͵J͵J͵K͵K͵L͵L͵M͵M͵N͵N͵O͵O͵P͵P͵Q͵Q͵R͵R͵S͵S͵T͵T͵U͵U͵V͵V͵W͵W͵X͵X͵Y͵Y͵Z͵Z͵[͵[͵\͵\͵]͵]͵^͵^͵_͵_͵`͵`͵a͵a͵b͵b͵c͵c͵d͵d͵e͵e͵f͵f͵g͵g͵h͵h͵i͵i͵j͵j͵k͵k͵l͵l͵m͵m͵n͵n͵o͵o͵p͵p͵q͵q͵r͵r͵s͵s͵t͵t͵u͵u͵v͵v͵w͵w͵x͵x͵y͵y͵z͵z͵{͵{͵|͵|͵}͵}͵~͵~͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵͵ͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶ Ͷ Ͷ Ͷ Ͷ Ͷ Ͷ Ͷ Ͷ Ͷ ͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶ Ͷ Ͷ!Ͷ!Ͷ"Ͷ"Ͷ#Ͷ#Ͷ$Ͷ$Ͷ%Ͷ%Ͷ&Ͷ&Ͷ'Ͷ'Ͷ(Ͷ(Ͷ)Ͷ)Ͷ*Ͷ*Ͷ+Ͷ+Ͷ,Ͷ,Ͷ-Ͷ-Ͷ.Ͷ.Ͷ/Ͷ/Ͷ0Ͷ0Ͷ1Ͷ1Ͷ2Ͷ2Ͷ3Ͷ3Ͷ4Ͷ4Ͷ5Ͷ5Ͷ6Ͷ6Ͷ7Ͷ7Ͷ8Ͷ8Ͷ9Ͷ9Ͷ:Ͷ:Ͷ;Ͷ;Ͷ<Ͷ<Ͷ=Ͷ=Ͷ>Ͷ>Ͷ?Ͷ?Ͷ@Ͷ@ͶAͶAͶBͶBͶCͶCͶDͶDͶEͶEͶFͶFͶGͶGͶHͶHͶIͶIͶJͶJͶKͶKͶLͶLͶMͶMͶNͶNͶOͶOͶPͶPͶQͶQͶRͶRͶSͶSͶTͶTͶUͶUͶVͶVͶWͶWͶXͶXͶYͶYͶZͶZͶ[Ͷ[Ͷ\Ͷ\Ͷ]Ͷ]Ͷ^Ͷ^Ͷ_Ͷ_Ͷ`Ͷ`ͶaͶaͶbͶbͶcͶcͶdͶdͶeͶeͶfͶfͶgͶgͶhͶhͶiͶiͶjͶjͶkͶkͶlͶlͶmͶmͶnͶnͶoͶoͶpͶpͶqͶqͶrͶrͶsͶsͶtͶtͶuͶuͶvͶvͶwͶwͶxͶxͶyͶyͶzͶzͶ{Ͷ{Ͷ|Ͷ|Ͷ}Ͷ}Ͷ~Ͷ~ͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷ ͷ ͷ ͷ ͷ ͷ ͷ ͷ ͷ ͷ ͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷ ͷ ͷ!ͷ!ͷ"ͷ"ͷ#ͷ#ͷ$ͷ$ͷ%ͷ%ͷ&ͷ&ͷ'ͷ'ͷ(ͷ(ͷ)ͷ)ͷ*ͷ*ͷ+ͷ+ͷ,ͷ,ͷ-ͷ-ͷ.ͷ.ͷ/ͷ/ͷ0ͷ0ͷ1ͷ1ͷ2ͷ2ͷ3ͷ3ͷ4ͷ4ͷ5ͷ5ͷ6ͷ6ͷ7ͷ7ͷ8ͷ8ͷ9ͷ9ͷ:ͷ:ͷ;ͷ;ͷ<ͷ<ͷ=ͷ=ͷ>ͷ>ͷ?ͷ?ͷ@ͷ@ͷAͷAͷBͷBͷCͷCͷDͷDͷEͷEͷFͷFͷGͷGͷHͷHͷIͷIͷJͷJͷKͷKͷLͷLͷMͷMͷNͷNͷOͷOͷPͷPͷQͷQͷRͷRͷSͷSͷTͷTͷUͷUͷVͷVͷWͷWͷXͷXͷYͷYͷZͷZͷ[ͷ[ͷ\ͷ\ͷ]ͷ]ͷ^ͷ^ͷ_ͷ_ͷ`ͷ`ͷaͷaͷbͷbͷcͷcͷdͷdͷeͷeͷfͷfͷgͷgͷhͷhͷiͷiͷjͷjͷkͷkͷlͷlͷmͷmͷnͷnͷoͷoͷpͷpͷqͷqͷrͷrͷsͷsͷtͷtͷuͷuͷvͷvͷwͷwͷxͷxͷyͷyͷzͷzͷ{ͷ{ͷ|ͷ|ͷ}ͷ}ͷ~ͷ~ͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷͷ͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸ ͸ ͸ ͸ ͸ ͸ ͸ ͸ ͸ ͸ ͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸ ͸ ͸!͸!͸"͸"͸#͸#͸$͸$͸%͸%͸&͸&͸'͸'͸(͸(͸)͸)͸*͸*͸+͸+͸,͸,͸-͸-͸.͸.͸/͸/͸0͸0͸1͸1͸2͸2͸3͸3͸4͸4͸5͸5͸6͸6͸7͸7͸8͸8͸9͸9͸:͸:͸;͸;͸<͸<͸=͸=͸>͸>͸?͸?͸@͸@͸A͸A͸B͸B͸C͸C͸D͸D͸E͸E͸F͸F͸G͸G͸H͸H͸I͸I͸J͸J͸K͸K͸L͸L͸M͸M͸N͸N͸O͸O͸P͸P͸Q͸Q͸R͸R͸S͸S͸T͸T͸U͸U͸V͸V͸W͸W͸X͸X͸Y͸Y͸Z͸Z͸[͸[͸\͸\͸]͸]͸^͸^͸_͸_͸`͸`͸a͸a͸b͸b͸c͸c͸d͸d͸e͸e͸f͸f͸g͸g͸h͸h͸i͸i͸j͸j͸k͸k͸l͸l͸m͸m͸n͸n͸o͸o͸p͸p͸q͸q͸r͸r͸s͸s͸t͸t͸u͸u͸v͸v͸w͸w͸x͸x͸y͸y͸z͸z͸{͸{͸|͸|͸}͸}͸~͸~͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͸͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹ ͹ ͹ ͹ ͹ ͹ ͹ ͹ ͹ ͹ ͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹ ͹ ͹!͹!͹"͹"͹#͹#͹$͹$͹%͹%͹&͹&͹'͹'͹(͹(͹)͹)͹*͹*͹+͹+͹,͹,͹-͹-͹.͹.͹/͹/͹0͹0͹1͹1͹2͹2͹3͹3͹4͹4͹5͹5͹6͹6͹7͹7͹8͹8͹9͹9͹:͹:͹;͹;͹<͹<͹=͹=͹>͹>͹?͹?͹@͹@͹A͹A͹B͹B͹C͹C͹D͹D͹E͹E͹F͹F͹G͹G͹H͹H͹I͹I͹J͹J͹K͹K͹L͹L͹M͹M͹N͹N͹O͹O͹P͹P͹Q͹Q͹R͹R͹S͹S͹T͹T͹U͹U͹V͹V͹W͹W͹X͹X͹Y͹Y͹Z͹Z͹[͹[͹\͹\͹]͹]͹^͹^͹_͹_͹`͹`͹a͹a͹b͹b͹c͹c͹d͹d͹e͹e͹f͹f͹g͹g͹h͹h͹i͹i͹j͹j͹k͹k͹l͹l͹m͹m͹n͹n͹o͹o͹p͹p͹q͹q͹r͹r͹s͹s͹t͹t͹u͹u͹v͹v͹w͹w͹x͹x͹y͹y͹z͹z͹{͹{͹|͹|͹}͹}͹~͹~͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹͹ͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺ ͺ ͺ ͺ ͺ ͺ ͺ ͺ ͺ ͺ ͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺ ͺ ͺ!ͺ!ͺ"ͺ"ͺ#ͺ#ͺ$ͺ$ͺ%ͺ%ͺ&ͺ&ͺ'ͺ'ͺ(ͺ(ͺ)ͺ)ͺ*ͺ*ͺ+ͺ+ͺ,ͺ,ͺ-ͺ-ͺ.ͺ.ͺ/ͺ/ͺ0ͺ0ͺ1ͺ1ͺ2ͺ2ͺ3ͺ3ͺ4ͺ4ͺ5ͺ5ͺ6ͺ6ͺ7ͺ7ͺ8ͺ8ͺ9ͺ9ͺ:ͺ:ͺ;ͺ;ͺ<ͺ<ͺ=ͺ=ͺ>ͺ>ͺ?ͺ?ͺ@ͺ@ͺAͺAͺBͺBͺCͺCͺDͺDͺEͺEͺFͺFͺGͺGͺHͺHͺIͺIͺJͺJͺKͺKͺLͺLͺMͺMͺNͺNͺOͺOͺPͺPͺQͺQͺRͺRͺSͺSͺTͺTͺUͺUͺVͺVͺWͺWͺXͺXͺYͺYͺZͺZͺ[ͺ[ͺ\ͺ\ͺ]ͺ]ͺ^ͺ^ͺ_ͺ_ͺ`ͺ`ͺaͺaͺbͺbͺcͺcͺdͺdͺeͺeͺfͺfͺgͺgͺhͺhͺiͺiͺjͺjͺkͺkͺlͺlͺmͺmͺnͺnͺoͺoͺpͺpͺqͺqͺrͺrͺsͺsͺtͺtͺuͺuͺvͺvͺwͺwͺxͺxͺyͺyͺzͺzͺ{ͺ{ͺ|ͺ|ͺ}ͺ}ͺ~ͺ~ͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻ ͻ ͻ ͻ ͻ ͻ ͻ ͻ ͻ ͻ ͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻ ͻ ͻ!ͻ!ͻ"ͻ"ͻ#ͻ#ͻ$ͻ$ͻ%ͻ%ͻ&ͻ&ͻ'ͻ'ͻ(ͻ(ͻ)ͻ)ͻ*ͻ*ͻ+ͻ+ͻ,ͻ,ͻ-ͻ-ͻ.ͻ.ͻ/ͻ/ͻ0ͻ0ͻ1ͻ1ͻ2ͻ2ͻ3ͻ3ͻ4ͻ4ͻ5ͻ5ͻ6ͻ6ͻ7ͻ7ͻ8ͻ8ͻ9ͻ9ͻ:ͻ:ͻ;ͻ;ͻ<ͻ<ͻ=ͻ=ͻ>ͻ>ͻ?ͻ?ͻ@ͻ@ͻAͻAͻBͻBͻCͻCͻDͻDͻEͻEͻFͻFͻGͻGͻHͻHͻIͻIͻJͻJͻKͻKͻLͻLͻMͻMͻNͻNͻOͻOͻPͻPͻQͻQͻRͻRͻSͻSͻTͻTͻUͻUͻVͻVͻWͻWͻXͻXͻYͻYͻZͻZͻ[ͻ[ͻ\ͻ\ͻ]ͻ]ͻ^ͻ^ͻ_ͻ_ͻ`ͻ`ͻaͻaͻbͻbͻcͻcͻdͻdͻeͻeͻfͻfͻgͻgͻhͻhͻiͻiͻjͻjͻkͻkͻlͻlͻmͻmͻnͻnͻoͻoͻpͻpͻqͻqͻrͻrͻsͻsͻtͻtͻuͻuͻvͻvͻwͻwͻxͻxͻyͻyͻzͻzͻ{ͻ{ͻ|ͻ|ͻ}ͻ}ͻ~ͻ~ͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͻͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼ ͼ ͼ ͼ ͼ ͼ ͼ ͼ ͼ ͼ ͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼ ͼ ͼ!ͼ!ͼ"ͼ"ͼ#ͼ#ͼ$ͼ$ͼ%ͼ%ͼ&ͼ&ͼ'ͼ'ͼ(ͼ(ͼ)ͼ)ͼ*ͼ*ͼ+ͼ+ͼ,ͼ,ͼ-ͼ-ͼ.ͼ.ͼ/ͼ/ͼ0ͼ0ͼ1ͼ1ͼ2ͼ2ͼ3ͼ3ͼ4ͼ4ͼ5ͼ5ͼ6ͼ6ͼ7ͼ7ͼ8ͼ8ͼ9ͼ9ͼ:ͼ:ͼ;ͼ;ͼ<ͼ<ͼ=ͼ=ͼ>ͼ>ͼ?ͼ?ͼ@ͼ@ͼAͼAͼBͼBͼCͼCͼDͼDͼEͼEͼFͼFͼGͼGͼHͼHͼIͼIͼJͼJͼKͼKͼLͼLͼMͼMͼNͼNͼOͼOͼPͼPͼQͼQͼRͼRͼSͼSͼTͼTͼUͼUͼVͼVͼWͼWͼXͼXͼYͼYͼZͼZͼ[ͼ[ͼ\ͼ\ͼ]ͼ]ͼ^ͼ^ͼ_ͼ_ͼ`ͼ`ͼaͼaͼbͼbͼcͼcͼdͼdͼeͼeͼfͼfͼgͼgͼhͼhͼiͼiͼjͼjͼkͼkͼlͼlͼmͼmͼnͼnͼoͼoͼpͼpͼqͼqͼrͼrͼsͼsͼtͼtͼuͼuͼvͼvͼwͼwͼxͼxͼyͼyͼzͼzͼ{ͼ{ͼ|ͼ|ͼ}ͼ}ͼ~ͼ~ͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͼͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽ ͽ ͽ ͽ ͽ ͽ ͽ ͽ ͽ ͽ ͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽ ͽ ͽ!ͽ!ͽ"ͽ"ͽ#ͽ#ͽ$ͽ$ͽ%ͽ%ͽ&ͽ&ͽ'ͽ'ͽ(ͽ(ͽ)ͽ)ͽ*ͽ*ͽ+ͽ+ͽ,ͽ,ͽ-ͽ-ͽ.ͽ.ͽ/ͽ/ͽ0ͽ0ͽ1ͽ1ͽ2ͽ2ͽ3ͽ3ͽ4ͽ4ͽ5ͽ5ͽ6ͽ6ͽ7ͽ7ͽ8ͽ8ͽ9ͽ9ͽ:ͽ:ͽ;ͽ;ͽ<ͽ<ͽ=ͽ=ͽ>ͽ>ͽ?ͽ?ͽ@ͽ@ͽAͽAͽBͽBͽCͽCͽDͽDͽEͽEͽFͽFͽGͽGͽHͽHͽIͽIͽJͽJͽKͽKͽLͽLͽMͽMͽNͽNͽOͽOͽPͽPͽQͽQͽRͽRͽSͽSͽTͽTͽUͽUͽVͽVͽWͽWͽXͽXͽYͽYͽZͽZͽ[ͽ[ͽ\ͽ\ͽ]ͽ]ͽ^ͽ^ͽ_ͽ_ͽ`ͽ`ͽaͽaͽbͽbͽcͽcͽdͽdͽeͽeͽfͽfͽgͽgͽhͽhͽiͽiͽjͽjͽkͽkͽlͽlͽmͽmͽnͽnͽoͽoͽpͽpͽqͽqͽrͽrͽsͽsͽtͽtͽuͽuͽvͽvͽwͽwͽxͽxͽyͽyͽzͽzͽ{ͽ{ͽ|ͽ|ͽ}ͽ}ͽ~ͽ~ͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽͽ;;;;;;;;;;;;;;;;;;; ; ; ; ; ; ; ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ;!;!;";";#;#;$;$;%;%;&;&;';';(;(;););*;*;+;+;,;,;-;-;.;.;/;/;0;0;1;1;2;2;3;3;4;4;5;5;6;6;7;7;8;8;9;9;:;:;;;;;<;<;=;=;>;>;?;?;@;@;A;A;B;B;C;C;D;D;E;E;F;F;G;G;H;H;I;I;J;J;K;K;L;L;M;M;N;N;O;O;P;P;Q;Q;R;R;S;S;T;T;U;U;V;V;W;W;X;X;Y;Y;Z;Z;[;[;\;\;];];^;^;_;_;`;`;a;a;b;b;c;c;d;d;e;e;f;f;g;g;h;h;i;i;j;j;k;k;l;l;m;m;n;n;o;o;p;p;q;q;r;r;s;s;t;t;u;u;v;v;w;w;x;x;y;y;z;z;{;{;|;|;};};~;~;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿ Ϳ Ϳ Ϳ Ϳ Ϳ Ϳ Ϳ Ϳ Ϳ ͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿ Ϳ Ϳ!Ϳ!Ϳ"Ϳ"Ϳ#Ϳ#Ϳ$Ϳ$Ϳ%Ϳ%Ϳ&Ϳ&Ϳ'Ϳ'Ϳ(Ϳ(Ϳ)Ϳ)Ϳ*Ϳ*Ϳ+Ϳ+Ϳ,Ϳ,Ϳ-Ϳ-Ϳ.Ϳ.Ϳ/Ϳ/Ϳ0Ϳ0Ϳ1Ϳ1Ϳ2Ϳ2Ϳ3Ϳ3Ϳ4Ϳ4Ϳ5Ϳ5Ϳ6Ϳ6Ϳ7Ϳ7Ϳ8Ϳ8Ϳ9Ϳ9Ϳ:Ϳ:Ϳ;Ϳ;Ϳ<Ϳ<Ϳ=Ϳ=Ϳ>Ϳ>Ϳ?Ϳ?Ϳ@Ϳ@ͿAͿAͿBͿBͿCͿCͿDͿDͿEͿEͿFͿFͿGͿGͿHͿHͿIͿIͿJͿJͿKͿKͿLͿLͿMͿMͿNͿNͿOͿOͿPͿPͿQͿQͿRͿRͿSͿSͿTͿTͿUͿUͿVͿVͿWͿWͿXͿXͿYͿYͿZͿZͿ[Ϳ[Ϳ\Ϳ\Ϳ]Ϳ]Ϳ^Ϳ^Ϳ_Ϳ_Ϳ`Ϳ`ͿaͿaͿbͿbͿcͿcͿdͿdͿeͿeͿfͿfͿgͿgͿhͿhͿiͿiͿjͿjͿkͿkͿlͿlͿmͿmͿnͿnͿoͿoͿpͿpͿqͿqͿrͿrͿsͿsͿtͿtͿuͿuͿvͿvͿwͿwͿxͿxͿyͿyͿzͿzͿ{Ϳ{Ϳ|Ϳ|Ϳ}Ϳ}Ϳ~Ϳ~ͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿͿ  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~€€‚‚ƒƒ„„……††‡‡ˆˆ‰‰ŠŠ‹‹ŒŒŽŽ‘‘’’““””••––——˜˜™™šš››œœžžŸŸ  ¡¡¢¢££¤¤¥¥¦¦§§¨¨©©ªª««¬¬­­®®¯¯°°±±²²³³´´µµ¶¶··¸¸¹¹ºº»»¼¼½½¾¾¿¿  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~ÀÀÁÁÂÂÃÃÄÄÅÅÆÆÇÇÈÈÉÉÊÊËËÌÌÍÍÎÎÏÏÐÐÑÑÒÒÓÓÔÔÕÕÖÖ×רØÙÙÚÚÛÛÜÜÝÝÞÞßßààááââããääååææççèèééêêëëììííîîïïððññòòóóôôõõöö÷÷øøùùúúûûüüýýþþÿÿ  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~ĀĀāāĂĂă㥥ąąĆĆććĈĈĉĉĊĊċċČČččĎĎďďĐĐđđĒĒēēĔĔĕĕĖĖėėĘĘęęĚĚěěĜĜĝĝĞĞğğĠĠġġĢĢģģĤĤĥĥĦĦħħĨĨĩĩĪĪīīĬĬĭĭĮĮįįİİııIJIJijijĴĴĵĵĶĶķķĸĸĹĹĺĺĻĻļļĽĽľľĿĿ  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~ŀŀŁŁłłŃŃńńŅŅņņŇŇňňʼnʼnŊŊŋŋŌŌōōŎŎŏŏŐŐőőŒŒœœŔŔŕŕŖŖŗŗŘŘřřŚŚśśŜŜŝŝŞŞşşŠŠššŢŢţţŤŤťťŦŦŧŧŨŨũũŪŪūūŬŬŭŭŮŮůůŰŰűűŲŲųųŴŴŵŵŶŶŷŷŸŸŹŹźźŻŻżżŽŽžžſſ  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~ƀƀƁƁƂƂƃƃƄƄƅƅƆƆƇƇƈƈƉƉƊƊƋƋƌƌƍƍƎƎƏƏƐƐƑƑƒƒƓƓƔƔƕƕƖƖƗƗƘƘƙƙƚƚƛƛƜƜƝƝƞƞƟƟƠƠơơƢƢƣƣƤƤƥƥƦƦƧƧƨƨƩƩƪƪƫƫƬƬƭƭƮƮƯƯưưƱƱƲƲƳƳƴƴƵƵƶƶƷƷƸƸƹƹƺƺƻƻƼƼƽƽƾƾƿƿ  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~ǀǀǁǁǂǂǃǃDŽDŽDžDždždžLJLJLjLjljljNJNJNjNjnjnjǍǍǎǎǏǏǐǐǑǑǒǒǓǓǔǔǕǕǖǖǗǗǘǘǙǙǚǚǛǛǜǜǝǝǞǞǟǟǠǠǡǡǢǢǣǣǤǤǥǥǦǦǧǧǨǨǩǩǪǪǫǫǬǬǭǭǮǮǯǯǰǰDZDZDzDzdzdzǴǴǵǵǶǶǷǷǸǸǹǹǺǺǻǻǼǼǽǽǾǾǿǿ  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~ȀȀȁȁȂȂȃȃȄȄȅȅȆȆȇȇȈȈȉȉȊȊȋȋȌȌȍȍȎȎȏȏȐȐȑȑȒȒȓȓȔȔȕȕȖȖȗȗȘȘșșȚȚțțȜȜȝȝȞȞȟȟȠȠȡȡȢȢȣȣȤȤȥȥȦȦȧȧȨȨȩȩȪȪȫȫȬȬȭȭȮȮȯȯȰȰȱȱȲȲȳȳȴȴȵȵȶȶȷȷȸȸȹȹȺȺȻȻȼȼȽȽȾȾȿȿ  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~ɀɀɁɁɂɂɃɃɄɄɅɅɆɆɇɇɈɈɉɉɊɊɋɋɌɌɍɍɎɎɏɏɐɐɑɑɒɒɓɓɔɔɕɕɖɖɗɗɘɘəəɚɚɛɛɜɜɝɝɞɞɟɟɠɠɡɡɢɢɣɣɤɤɥɥɦɦɧɧɨɨɩɩɪɪɫɫɬɬɭɭɮɮɯɯɰɰɱɱɲɲɳɳɴɴɵɵɶɶɷɷɸɸɹɹɺɺɻɻɼɼɽɽɾɾɿɿ  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~ʀʀʁʁʂʂʃʃʄʄʅʅʆʆʇʇʈʈʉʉʊʊʋʋʌʌʍʍʎʎʏʏʐʐʑʑʒʒʓʓʔʔʕʕʖʖʗʗʘʘʙʙʚʚʛʛʜʜʝʝʞʞʟʟʠʠʡʡʢʢʣʣʤʤʥʥʦʦʧʧʨʨʩʩʪʪʫʫʬʬʭʭʮʮʯʯʰʰʱʱʲʲʳʳʴʴʵʵʶʶʷʷʸʸʹʹʺʺʻʻʼʼʽʽʾʾʿʿ  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~ˀˀˁˁ˂˂˃˃˄˄˅˅ˆˆˇˇˈˈˉˉˊˊˋˋˌˌˍˍˎˎˏˏːːˑˑ˒˒˓˓˔˔˕˕˖˖˗˗˘˘˙˙˚˚˛˛˜˜˝˝˞˞˟˟ˠˠˡˡˢˢˣˣˤˤ˥˥˦˦˧˧˨˨˩˩˪˪˫˫ˬˬ˭˭ˮˮ˯˯˰˰˱˱˲˲˳˳˴˴˵˵˶˶˷˷˸˸˹˹˺˺˻˻˼˼˽˽˾˾˿˿  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~̴̴̵̵̶̶̷̷̸̸̡̡̢̢̧̧̨̨̛̛̖̖̗̗̘̘̙̙̜̜̝̝̞̞̟̟̠̠̣̣̤̤̥̥̦̦̩̩̪̪̫̫̬̬̭̭̮̮̯̯̰̰̱̱̲̲̳̳̹̹̺̺̻̻̼̼̀̀́́̂̂̃̃̄̄̅̅̆̆̇̇̈̈̉̉̊̊̋̋̌̌̍̍̎̎̏̏̐̐̑̑̒̒̓̓̔̔̽̽̾̾̿̿̕̕̚̚  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~͇͇͈͈͉͉͍͍͎͎̀̀́́͂͂̓̓̈́̈́͆͆͊͊͋͋͌͌ͅͅ͏͏͓͓͔͔͕͕͖͖͙͙͚͚͐͐͑͑͒͒͗͗͛͛ͣͣͤͤͥͥͦͦͧͧͨͨͩͩͪͪͫͫͬͬͭͭͮͮͯͯ͘͘͜͜͟͟͢͢͝͝͞͞͠͠͡͡ͰͰͱͱͲͲͳͳʹʹ͵͵ͶͶͷͷ͸͸͹͹ͺͺͻͻͼͼͽͽ;;ͿͿ  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~΀΀΁΁΂΂΃΃΄΄΅΅ΆΆ··ΈΈΉΉΊΊ΋΋ΌΌ΍΍ΎΎΏΏΐΐΑΑΒΒΓΓΔΔΕΕΖΖΗΗΘΘΙΙΚΚΛΛΜΜΝΝΞΞΟΟΠΠΡΡ΢΢ΣΣΤΤΥΥΦΦΧΧΨΨΩΩΪΪΫΫάάέέήήίίΰΰααββγγδδεεζζηηθθιικκλλμμννξξοο  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~ππρρςςσσττυυφφχχψψωωϊϊϋϋόόύύώώϏϏϐϐϑϑϒϒϓϓϔϔϕϕϖϖϗϗϘϘϙϙϚϚϛϛϜϜϝϝϞϞϟϟϠϠϡϡϢϢϣϣϤϤϥϥϦϦϧϧϨϨϩϩϪϪϫϫϬϬϭϭϮϮϯϯϰϰϱϱϲϲϳϳϴϴϵϵ϶϶ϷϷϸϸϹϹϺϺϻϻϼϼϽϽϾϾϿϿ  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~ЀЀЁЁЂЂЃЃЄЄЅЅІІЇЇЈЈЉЉЊЊЋЋЌЌЍЍЎЎЏЏААББВВГГДДЕЕЖЖЗЗИИЙЙККЛЛММННООППРРССТТУУФФХХЦЦЧЧШШЩЩЪЪЫЫЬЬЭЭЮЮЯЯааббввггддеежжззииййккллммнноопп  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~ррссттууффххццччшшщщъъыыььээююяяѐѐёёђђѓѓєєѕѕііїїјјљљњњћћќќѝѝўўџџѠѠѡѡѢѢѣѣѤѤѥѥѦѦѧѧѨѨѩѩѪѪѫѫѬѬѭѭѮѮѯѯѰѰѱѱѲѲѳѳѴѴѵѵѶѶѷѷѸѸѹѹѺѺѻѻѼѼѽѽѾѾѿѿ  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~ҀҀҁҁ҂҂҃҃҄҄҅҅҆҆҇҇҈҈҉҉ҊҊҋҋҌҌҍҍҎҎҏҏҐҐґґҒҒғғҔҔҕҕҖҖҗҗҘҘҙҙҚҚққҜҜҝҝҞҞҟҟҠҠҡҡҢҢңңҤҤҥҥҦҦҧҧҨҨҩҩҪҪҫҫҬҬҭҭҮҮүүҰҰұұҲҲҳҳҴҴҵҵҶҶҷҷҸҸҹҹҺҺһһҼҼҽҽҾҾҿҿ  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~ӀӀӁӁӂӂӃӃӄӄӅӅӆӆӇӇӈӈӉӉӊӊӋӋӌӌӍӍӎӎӏӏӐӐӑӑӒӒӓӓӔӔӕӕӖӖӗӗӘӘәәӚӚӛӛӜӜӝӝӞӞӟӟӠӠӡӡӢӢӣӣӤӤӥӥӦӦӧӧӨӨөөӪӪӫӫӬӬӭӭӮӮӯӯӰӰӱӱӲӲӳӳӴӴӵӵӶӶӷӷӸӸӹӹӺӺӻӻӼӼӽӽӾӾӿӿ  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~ԀԀԁԁԂԂԃԃԄԄԅԅԆԆԇԇԈԈԉԉԊԊԋԋԌԌԍԍԎԎԏԏԐԐԑԑԒԒԓԓԔԔԕԕԖԖԗԗԘԘԙԙԚԚԛԛԜԜԝԝԞԞԟԟԠԠԡԡԢԢԣԣԤԤԥԥԦԦԧԧԨԨԩԩԪԪԫԫԬԬԭԭԮԮԯԯ԰԰ԱԱԲԲԳԳԴԴԵԵԶԶԷԷԸԸԹԹԺԺԻԻԼԼԽԽԾԾԿԿ  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~ՀՀՁՁՂՂՃՃՄՄՅՅՆՆՇՇՈՈՉՉՊՊՋՋՌՌՍՍՎՎՏՏՐՐՑՑՒՒՓՓՔՔՕՕՖՖ՗՗՘՘ՙՙ՚՚՛՛՜՜՝՝՞՞՟՟ՠՠաաբբգգդդեեզզէէըըթթժժիիլլխխծծկկհհձձղղճճմմյյննշշոոչչպպջջռռսսվվտտ  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~րրցցււփփքքօօֆֆևևֈֈ։։֊֊֋֋֌֌֍֍֎֎֏֏֐֐ְְֱֱֲֲֳֳִִֵֵֶֶַַָָֹֹֺֺֻֻּּֽֽ֑֑֖֖֛֛֢֢֣֣֤֤֥֥֦֦֧֧֪֪֚֚֭֭֮֮֒֒֓֓֔֔֕֕֗֗֘֘֙֙֜֜֝֝֞֞֟֟֠֠֡֡֨֨֩֩֫֫֬֬֯֯־־ֿֿ  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~׀׀ׁׁׂׂ׃׃ׅׅׄׄ׆׆ׇׇ׈׈׉׉׊׊׋׋׌׌׍׍׎׎׏׏אאבבגגדדההווזזחחטטייךךככללםםממןןננססעעףףפפץץצצקקררששתת׫׫׬׬׭׭׮׮ׯׯװװױױײײ׳׳״״׵׵׶׶׷׷׸׸׹׹׺׺׻׻׼׼׽׽׾׾׿׿  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~؀؀؁؁؂؂؃؃؄؄؅؅؆؆؇؇؈؈؉؉؊؊؋؋،،؍؍؎؎؏؏ؘؘؙؙؚؚؐؐؑؑؒؒؓؓؔؔؕؕؖؖؗؗ؛؛؜؜؝؝؞؞؟؟ؠؠءءآآأأؤؤإإئئااببةةتتثثججححخخددذذررززسسششصصضضططظظععغغػػؼؼؽؽؾؾؿؿ  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~ــففققككللممننههووىىييًًٌٌٍٍََُُِِّّْْٕٕٖٖٜٜٟٟٓٓٔٔٗٗ٘٘ٙٙٚٚٛٛٝٝٞٞ٠٠١١٢٢٣٣٤٤٥٥٦٦٧٧٨٨٩٩٪٪٫٫٬٬٭٭ٮٮٯٯٰٰٱٱٲٲٳٳٴٴٵٵٶٶٷٷٸٸٹٹٺٺٻٻټټٽٽپپٿٿ  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~ڀڀځځڂڂڃڃڄڄڅڅچچڇڇڈڈډډڊڊڋڋڌڌڍڍڎڎڏڏڐڐڑڑڒڒړړڔڔڕڕږږڗڗژژڙڙښښڛڛڜڜڝڝڞڞڟڟڠڠڡڡڢڢڣڣڤڤڥڥڦڦڧڧڨڨککڪڪګګڬڬڭڭڮڮگگڰڰڱڱڲڲڳڳڴڴڵڵڶڶڷڷڸڸڹڹںںڻڻڼڼڽڽھھڿڿ  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~ۀۀہہۂۂۃۃۄۄۅۅۆۆۇۇۈۈۉۉۊۊۋۋییۍۍێێۏۏېېۑۑےےۓۓ۔۔ەەۖۖۗۗۘۘۙۙۚۚۛۛۜۜ۝۝۞۞ۣۣ۟۟۠۠ۡۡۢۢۤۤۥۥۦۦۧۧۨۨ۩۩۪۪ۭۭ۫۫۬۬ۮۮۯۯ۰۰۱۱۲۲۳۳۴۴۵۵۶۶۷۷۸۸۹۹ۺۺۻۻۼۼ۽۽۾۾ۿۿ  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~܀܀܁܁܂܂܃܃܄܄܅܅܆܆܇܇܈܈܉܉܊܊܋܋܌܌܍܍܎܎܏܏ܐܐܑܑܒܒܓܓܔܔܕܕܖܖܗܗܘܘܙܙܚܚܛܛܜܜܝܝܞܞܟܟܠܠܡܡܢܢܣܣܤܤܥܥܦܦܧܧܨܨܩܩܪܪܫܫܬܬܭܭܮܮܯܯܱܱܴܴܷܷܸܸܹܹܻܻܼܼܾܾܰܰܲܲܳܳܵܵܶܶܺܺܽܽܿܿ  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~݂݂݄݄݆݆݈݈݀݀݁݁݃݃݅݅݇݇݉݉݊݊݋݋݌݌ݍݍݎݎݏݏݐݐݑݑݒݒݓݓݔݔݕݕݖݖݗݗݘݘݙݙݚݚݛݛݜݜݝݝݞݞݟݟݠݠݡݡݢݢݣݣݤݤݥݥݦݦݧݧݨݨݩݩݪݪݫݫݬݬݭݭݮݮݯݯݰݰݱݱݲݲݳݳݴݴݵݵݶݶݷݷݸݸݹݹݺݺݻݻݼݼݽݽݾݾݿݿ  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~ހހށށނނރރބބޅޅކކއއވވމމފފދދތތލލގގޏޏސސޑޑޒޒޓޓޔޔޕޕޖޖޗޗޘޘޙޙޚޚޛޛޜޜޝޝޞޞޟޟޠޠޡޡޢޢޣޣޤޤޥޥަަާާިިީީުުޫޫެެޭޭޮޮޯޯްްޱޱ޲޲޳޳޴޴޵޵޶޶޷޷޸޸޹޹޺޺޻޻޼޼޽޽޾޾޿޿  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~߀߀߁߁߂߂߃߃߄߄߅߅߆߆߇߇߈߈߉߉ߊߊߋߋߌߌߍߍߎߎߏߏߐߐߑߑߒߒߓߓߔߔߕߕߖߖߗߗߘߘߙߙߚߚߛߛߜߜߝߝߞߞߟߟߠߠߡߡߢߢߣߣߤߤߥߥߦߦߧߧߨߨߩߩߪߪ߲߲߫߫߬߬߭߭߮߮߯߯߰߰߱߱߳߳ߴߴߵߵ߶߶߷߷߸߸߹߹ߺߺ߻߻߼߼߽߽߾߾߿߿  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~  !!""##$$%%&&''(())**++,,--..//00112233445566778899::;;<<==>>??@@AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~objfw-1.1.6/tests/iOS.xcodeproj/000077500000000000000000000000001465614216400164675ustar00rootroot00000000000000objfw-1.1.6/tests/iOS.xcodeproj/project.pbxproj000066400000000000000000000336431465614216400215540ustar00rootroot00000000000000// !$*UTF8*$! { archiveVersion = 1; classes = { }; objectVersion = 48; objects = { /* Begin PBXBuildFile section */ 4B1E2CEF2B8294F200BB28B6 /* libobjfwtest.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B1E2CEE2B8294F200BB28B6 /* libobjfwtest.a */; }; 4B6AB9CD202BA431007BAC7D /* TestPlugin.bundle in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4B6AB9CA202BA408007BAC7D /* TestPlugin.bundle */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 4BC7FD07201394F300280496 /* ObjFW.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BC7FD06201394F300280496 /* ObjFW.framework */; }; 4BC7FD092013954B00280496 /* tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BC7FD082013954B00280496 /* tests.a */; }; 4BC7FD0B2013956D00280496 /* ObjFW.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4BC7FD06201394F300280496 /* ObjFW.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 4BC7FD102013960600280496 /* testfile.txt in Resources */ = {isa = PBXBuildFile; fileRef = 4BC7FD0C2013960600280496 /* testfile.txt */; }; 4BC7FD112013960600280496 /* testfile.bin in Resources */ = {isa = PBXBuildFile; fileRef = 4BC7FD0D2013960600280496 /* testfile.bin */; }; 4BC7FD132013960600280496 /* testfile.ini in Resources */ = {isa = PBXBuildFile; fileRef = 4BC7FD0F2013960600280496 /* testfile.ini */; }; 4BEBFB6E2013934E002E8710 /* ImportTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BEBFB6D2013934E002E8710 /* ImportTest.m */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ 4B6AB9CC202BA428007BAC7D /* CopyFiles */ = { isa = PBXCopyFilesBuildPhase; buildActionMask = 2147483647; dstPath = ""; dstSubfolderSpec = 13; files = ( 4B6AB9CD202BA431007BAC7D /* TestPlugin.bundle in CopyFiles */, ); runOnlyForDeploymentPostprocessing = 0; }; 4BC7FD0A2013956200280496 /* CopyFiles */ = { isa = PBXCopyFilesBuildPhase; buildActionMask = 2147483647; dstPath = ""; dstSubfolderSpec = 10; files = ( 4BC7FD0B2013956D00280496 /* ObjFW.framework in CopyFiles */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ 4B1E2CEE2B8294F200BB28B6 /* libobjfwtest.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libobjfwtest.a; path = ../src/test/libobjfwtest.a; sourceTree = ""; }; 4B6AB9CA202BA408007BAC7D /* TestPlugin.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; name = TestPlugin.bundle; path = plugin/TestPlugin.bundle; sourceTree = ""; }; 4BC7FD06201394F300280496 /* ObjFW.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ObjFW.framework; path = ../src/ObjFW.framework; sourceTree = ""; }; 4BC7FD082013954B00280496 /* tests.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = tests.a; sourceTree = ""; }; 4BC7FD0C2013960600280496 /* testfile.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = testfile.txt; sourceTree = ""; }; 4BC7FD0D2013960600280496 /* testfile.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; path = testfile.bin; sourceTree = ""; }; 4BC7FD0F2013960600280496 /* testfile.ini */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = testfile.ini; sourceTree = ""; }; 4BEBFB5B2013934E002E8710 /* tests.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = tests.app; sourceTree = BUILT_PRODUCTS_DIR; }; 4BEBFB6C2013934E002E8710 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = SOURCE_ROOT; }; 4BEBFB6D2013934E002E8710 /* ImportTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ImportTest.m; sourceTree = SOURCE_ROOT; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ 4BEBFB582013934E002E8710 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( 4BC7FD092013954B00280496 /* tests.a in Frameworks */, 4B1E2CEF2B8294F200BB28B6 /* libobjfwtest.a in Frameworks */, 4BC7FD07201394F300280496 /* ObjFW.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ 4BC7FD05201394F300280496 /* Frameworks */ = { isa = PBXGroup; children = ( 4B6AB9CA202BA408007BAC7D /* TestPlugin.bundle */, 4BC7FD082013954B00280496 /* tests.a */, 4B1E2CEE2B8294F200BB28B6 /* libobjfwtest.a */, 4BC7FD06201394F300280496 /* ObjFW.framework */, ); name = Frameworks; sourceTree = ""; }; 4BEBFB522013934E002E8710 = { isa = PBXGroup; children = ( 4BEBFB5D2013934E002E8710 /* tests */, 4BEBFB5C2013934E002E8710 /* Products */, 4BC7FD05201394F300280496 /* Frameworks */, ); sourceTree = ""; }; 4BEBFB5C2013934E002E8710 /* Products */ = { isa = PBXGroup; children = ( 4BEBFB5B2013934E002E8710 /* tests.app */, ); name = Products; sourceTree = ""; }; 4BEBFB5D2013934E002E8710 /* tests */ = { isa = PBXGroup; children = ( 4BEBFB6C2013934E002E8710 /* Info.plist */, 4BEBFB6D2013934E002E8710 /* ImportTest.m */, 4BC7FD0D2013960600280496 /* testfile.bin */, 4BC7FD0F2013960600280496 /* testfile.ini */, 4BC7FD0C2013960600280496 /* testfile.txt */, ); name = tests; sourceTree = ""; }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ 4BEBFB5A2013934E002E8710 /* tests */ = { isa = PBXNativeTarget; buildConfigurationList = 4BEBFB712013934E002E8710 /* Build configuration list for PBXNativeTarget "tests" */; buildPhases = ( 4BEBFB572013934E002E8710 /* Sources */, 4BEBFB582013934E002E8710 /* Frameworks */, 4BC7FD0A2013956200280496 /* CopyFiles */, 4BEBFB592013934E002E8710 /* Resources */, 4B6AB9CC202BA428007BAC7D /* CopyFiles */, ); buildRules = ( ); dependencies = ( ); name = tests; productName = tests; productReference = 4BEBFB5B2013934E002E8710 /* tests.app */; productType = "com.apple.product-type.application"; }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ 4BEBFB532013934E002E8710 /* Project object */ = { isa = PBXProject; attributes = { LastUpgradeCheck = 1330; ORGANIZATIONNAME = "Jonathan Schleifer"; TargetAttributes = { 4BEBFB5A2013934E002E8710 = { CreatedOnToolsVersion = 9.2; ProvisioningStyle = Automatic; }; }; }; buildConfigurationList = 4BEBFB562013934E002E8710 /* Build configuration list for PBXProject "iOS" */; compatibilityVersion = "Xcode 8.0"; developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, Base, ); mainGroup = 4BEBFB522013934E002E8710; productRefGroup = 4BEBFB5C2013934E002E8710 /* Products */; projectDirPath = ""; projectRoot = ""; targets = ( 4BEBFB5A2013934E002E8710 /* tests */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ 4BEBFB592013934E002E8710 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( 4BC7FD102013960600280496 /* testfile.txt in Resources */, 4BC7FD132013960600280496 /* testfile.ini in Resources */, 4BC7FD112013960600280496 /* testfile.bin in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ 4BEBFB572013934E002E8710 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( 4BEBFB6E2013934E002E8710 /* ImportTest.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin XCBuildConfiguration section */ 4BEBFB6F2013934E002E8710 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu11; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", ); GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 11.2; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; }; name = Debug; }; 4BEBFB702013934E002E8710 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu11; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 11.2; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; name = Release; }; 4BEBFB722013934E002E8710 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = MXKNFCKFL6; FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)/../src"; INFOPLIST_FILE = Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)", "$(PROJECT_DIR)/../src/test", ); OTHER_LDFLAGS = "-all_load"; PRODUCT_BUNDLE_IDENTIFIER = im.nil.objfw.tests; PRODUCT_NAME = "$(TARGET_NAME)"; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; }; 4BEBFB732013934E002E8710 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = MXKNFCKFL6; FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)/../src"; INFOPLIST_FILE = Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)", "$(PROJECT_DIR)/../src/test", ); OTHER_LDFLAGS = "-all_load"; PRODUCT_BUNDLE_IDENTIFIER = im.nil.objfw.tests; PRODUCT_NAME = "$(TARGET_NAME)"; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ 4BEBFB562013934E002E8710 /* Build configuration list for PBXProject "iOS" */ = { isa = XCConfigurationList; buildConfigurations = ( 4BEBFB6F2013934E002E8710 /* Debug */, 4BEBFB702013934E002E8710 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; 4BEBFB712013934E002E8710 /* Build configuration list for PBXNativeTarget "tests" */ = { isa = XCConfigurationList; buildConfigurations = ( 4BEBFB722013934E002E8710 /* Debug */, 4BEBFB732013934E002E8710 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; rootObject = 4BEBFB532013934E002E8710 /* Project object */; } objfw-1.1.6/tests/objc_sync/000077500000000000000000000000001465614216400157525ustar00rootroot00000000000000objfw-1.1.6/tests/objc_sync/Makefile000066400000000000000000000050111465614216400174070ustar00rootroot00000000000000include ../../extra.mk PROG_NOINST = objc_sync${PROG_SUFFIX} SRCS = test.m include ../../buildsys.mk .PHONY: run run: rm -f libobjfw.so.${OBJFW_LIB_MAJOR} rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} rm -f objfw${OBJFW_LIB_MAJOR}.dll libobjfw.${OBJFW_LIB_MAJOR}.dylib rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR} rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} rm -f objfwrt${OBJFWRT_LIB_MAJOR}.dll rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib if test -f ../../src/libobjfw.so; then \ ${LN_S} ../../src/libobjfw.so libobjfw.so.${OBJFW_LIB_MAJOR}; \ ${LN_S} ../../src/libobjfw.so \ libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ elif test -f ../../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; then \ ${LN_S} ../../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} \ libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ fi if test -f ../../src/objfw${OBJFW_LIB_MAJOR}.dll; then \ ${LN_S} ../../src/objfw${OBJFW_LIB_MAJOR}.dll \ objfw${OBJFW_LIB_MAJOR}.dll; \ fi if test -f ../../src/libobjfw.dylib; then \ ${LN_S} ../../src/libobjfw.dylib \ libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ fi if test -f ../../src/runtime/libobjfwrt.so; then \ ${LN_S} ../../src/runtime/libobjfwrt.so \ libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ ${LN_S} ../../src/runtime/libobjfwrt.so \ libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ elif test -f ../../src/runtime/libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; then \ ${LN_S} ../../src/runtime/libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ fi if test -f ../../src/runtime/objfwrt${OBJFWRT_LIB_MAJOR}.dll; then \ ${LN_S} ../../src/runtime/objfwrt${OBJFWRT_LIB_MAJOR}.dll \ objfwrt${OBJFWRT_LIB_MAJOR}.dll; \ fi if test -f ../../src/runtime/libobjfwrt.dylib; then \ ${LN_S} ../../src/runtime/libobjfwrt.dylib \ libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ fi LD_LIBRARY_PATH=.$${LD_LIBRARY_PATH+:}$$LD_LIBRARY_PATH \ DYLD_LIBRARY_PATH=.$${DYLD_LIBRARY_PATH+:}$$DYLD_LIBRARY_PATH \ LIBRARY_PATH=.$${LIBRARY_PATH+:}$$LIBRARY_PATH \ ${WRAPPER} ./${PROG_NOINST}; EXIT=$$?; \ rm -f libobjfw.so.${OBJFW_LIB_MAJOR}; \ rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ rm -f objfw${OBJFW_LIB_MAJOR}.dll; \ rm -f libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ rm -f objfwrt${OBJFWRT_LIB_MAJOR}.dll; \ rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ exit $$EXIT CPPFLAGS += -I../../src -I../../src/runtime -I../.. LIBS := -L../../src -lobjfw -L../../src/runtime ${RUNTIME_LIBS} ${LIBS} LD = ${OBJC} objfw-1.1.6/tests/objc_sync/test.m000066400000000000000000000026531465614216400171150ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFString.h" #import "OFThread.h" OFObject *lock; @interface MyThread: OFThread @end @implementation MyThread - (id)main { const char *name = [[[OFThread currentThread] name] UTF8String]; printf("[%s] Entering #1\n", name); @synchronized (lock) { printf("[%s] Entering #2\n", name); @synchronized (lock) { printf("[%s] Hello!\n", name); } printf("[%s] Left #2\n", name); } printf("[%s] Left #1\n", name); return nil; } @end int main(void) { MyThread *t1, *t2; lock = [[OFObject alloc] init]; t1 = [MyThread thread]; t1.name = @"A"; t2 = [MyThread thread]; t2.name = @"B"; [t1 start]; [t2 start]; [t1 join]; [t2 join]; return 0; } objfw-1.1.6/tests/plugin/000077500000000000000000000000001465614216400152775ustar00rootroot00000000000000objfw-1.1.6/tests/plugin/Info.plist.in000066400000000000000000000012621465614216400176550ustar00rootroot00000000000000 CFBundleExecutable TestPlugin CFBundleName TestPlugin CFBundleIdentifier im.nil.objfw.tests.plugin CFBundleInfoDictionaryVersion 6.0 CFBundlePackageType BNDL CFBundleVersion @BUNDLE_VERSION@ CFBundleShortVersionString @BUNDLE_SHORT_VERSION@ MinimumOSVersion 9.0 objfw-1.1.6/tests/plugin/Makefile000066400000000000000000000003561465614216400167430ustar00rootroot00000000000000DISTCLEAN = Info.plist PLUGIN_NOINST = TestPlugin${PLUGIN_SUFFIX} SRCS = TestPlugin.m include ../../buildsys.mk include ../../extra.mk CPPFLAGS += -I../.. -I../../src -I../../src/runtime LIBS := ${TESTPLUGIN_LIBS} ${LIBS} LD = ${OBJC} objfw-1.1.6/tests/plugin/TestPlugin.h000066400000000000000000000014561465614216400175540ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" @interface TestPlugin: OFObject - (int)test: (int)num; @end objfw-1.1.6/tests/plugin/TestPlugin.m000066400000000000000000000016071465614216400175570ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "TestPlugin.h" @implementation TestPlugin - (int)test: (int)num { return num * 2; } @end Class class(void) { return [TestPlugin class]; } objfw-1.1.6/tests/subprocess/000077500000000000000000000000001465614216400161715ustar00rootroot00000000000000objfw-1.1.6/tests/subprocess/Makefile000066400000000000000000000004161465614216400176320ustar00rootroot00000000000000PROG_NOINST = subprocess${PROG_SUFFIX} SRCS = Subprocess.m include ../../buildsys.mk include ../../extra.mk CPPFLAGS += -I../../src -I../../src/exceptions -I../../src/runtime -I../.. LIBS := -L../../src -lobjfw -L../../src/runtime ${RUNTIME_LIBS} ${LIBS} LD = ${OBJC} objfw-1.1.6/tests/subprocess/Subprocess.m000066400000000000000000000031161465614216400205000ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "ObjFW.h" @interface Subprocess: OFObject @end OF_APPLICATION_DELEGATE(Subprocess) @implementation Subprocess - (void)applicationDidFinishLaunching: (OFNotification *)notification { OFString *line; if (![[OFApplication arguments] isEqual: [OFArray arrayWithObjects: @"tést", @"123", nil]]) [OFApplication terminateWithStatus: 1]; if (![[[OFApplication environment] objectForKey: @"tëst"] isEqual: @"yés"]) { [OFApplication terminateWithStatus: 2]; } #ifdef OF_WINDOWS /* On Windows 9x, closing the pipe doesn't seem to cause EOF. */ if (![OFSystemInfo isWindowsNT]) { if ((line = [OFStdIn readLine]) != nil) [OFStdOut writeLine: line.uppercaseString]; } else #endif while ((line = [OFStdIn readLine]) != nil) [OFStdOut writeLine: line.uppercaseString]; [OFApplication terminate]; } @end objfw-1.1.6/tests/terminal/000077500000000000000000000000001465614216400156145ustar00rootroot00000000000000objfw-1.1.6/tests/terminal/Makefile000066400000000000000000000050561465614216400172620ustar00rootroot00000000000000include ../../extra.mk PROG_NOINST = terminal_tests${PROG_SUFFIX} SRCS = TerminalTests.m include ../../buildsys.mk .PHONY: run run: rm -f libobjfw.so.${OBJFW_LIB_MAJOR} rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} rm -f objfw${OBJFW_LIB_MAJOR}.dll libobjfw.${OBJFW_LIB_MAJOR}.dylib rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR} rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} rm -f objfwrt${OBJFWRT_LIB_MAJOR}.dll rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib if test -f ../../src/libobjfw.so; then \ ${LN_S} ../../src/libobjfw.so libobjfw.so.${OBJFW_LIB_MAJOR}; \ ${LN_S} ../../src/libobjfw.so \ libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ elif test -f ../../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; then \ ${LN_S} ../../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} \ libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ fi if test -f ../../src/objfw${OBJFW_LIB_MAJOR}.dll; then \ ${LN_S} ../../src/objfw${OBJFW_LIB_MAJOR}.dll \ objfw${OBJFW_LIB_MAJOR}.dll; \ fi if test -f ../../src/libobjfw.dylib; then \ ${LN_S} ../../src/libobjfw.dylib \ libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ fi if test -f ../../src/runtime/libobjfwrt.so; then \ ${LN_S} ../../src/runtime/libobjfwrt.so \ libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ ${LN_S} ../../src/runtime/libobjfwrt.so \ libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ elif test -f ../../src/runtime/libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; then \ ${LN_S} ../../src/runtime/libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ fi if test -f ../../src/runtime/objfwrt${OBJFWRT_LIB_MAJOR}.dll; then \ ${LN_S} ../../src/runtime/objfwrt${OBJFWRT_LIB_MAJOR}.dll \ objfwrt${OBJFWRT_LIB_MAJOR}.dll; \ fi if test -f ../../src/runtime/libobjfwrt.dylib; then \ ${LN_S} ../../src/runtime/libobjfwrt.dylib \ libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ fi LD_LIBRARY_PATH=.$${LD_LIBRARY_PATH+:}$$LD_LIBRARY_PATH \ DYLD_LIBRARY_PATH=.$${DYLD_LIBRARY_PATH+:}$$DYLD_LIBRARY_PATH \ LIBRARY_PATH=.$${LIBRARY_PATH+:}$$LIBRARY_PATH \ ${WRAPPER} ./${PROG_NOINST}; EXIT=$$?; \ rm -f libobjfw.so.${OBJFW_LIB_MAJOR}; \ rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ rm -f objfw${OBJFW_LIB_MAJOR}.dll; \ rm -f libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ rm -f objfwrt${OBJFWRT_LIB_MAJOR}.dll; \ rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ exit $$EXIT CPPFLAGS += -I../../src -I../../src/exceptions -I../../src/runtime -I../.. LIBS := -L../../src -lobjfw -L../../src/runtime ${RUNTIME_LIBS} ${LIBS} LD = ${OBJC} objfw-1.1.6/tests/terminal/TerminalTests.m000066400000000000000000000071631465614216400205770ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFApplication.h" #import "OFArray.h" #import "OFColor.h" #import "OFStdIOStream.h" #import "OFThread.h" @interface TerminalTests: OFObject @end OF_APPLICATION_DELEGATE(TerminalTests) @implementation TerminalTests - (void)applicationDidFinishLaunching: (OFNotification *)notification { OFArray *colors = [OFArray arrayWithObjects: [OFColor black], [OFColor silver], [OFColor gray], [OFColor white], [OFColor maroon], [OFColor red], [OFColor purple], [OFColor fuchsia], [OFColor green], [OFColor lime], [OFColor olive], [OFColor yellow], [OFColor navy], [OFColor blue], [OFColor teal], [OFColor aqua], nil]; size_t i; OFEnumerator OF_GENERIC(OFColor *) *reverseEnumerator; [OFStdOut writeFormat: @"%dx%d\n", OFStdOut.columns, OFStdOut.rows]; i = 0; for (OFColor *color in colors) { [OFStdOut setForegroundColor: color]; [OFStdOut writeFormat: @"%zx", i++]; } [OFStdOut reset]; [OFStdOut writeLine: @"R"]; i = 0; for (OFColor *color in colors) { [OFStdOut setBackgroundColor: color]; [OFStdOut writeFormat: @"%zx", i++]; } [OFStdOut reset]; [OFStdOut writeLine: @"R"]; i = 0; reverseEnumerator = [colors.reversedArray objectEnumerator]; for (OFColor *color in colors) { [OFStdOut setForegroundColor: color]; [OFStdOut setBackgroundColor: [reverseEnumerator nextObject]]; [OFStdOut writeFormat: @"%zx", i++]; } [OFStdOut reset]; [OFStdOut writeLine: @"R"]; for (i = 0; i < colors.count * 2; i++) { if (i % 2) [OFStdOut setBackgroundColor: [colors objectAtIndex: ((i / 2) + 2) % colors.count]]; else [OFStdOut setForegroundColor: [colors objectAtIndex: i / 2]]; [OFStdOut writeFormat: @"%zx", i / 2]; } [OFStdOut reset]; [OFStdOut writeLine: @"R"]; [OFStdOut writeLine: @"Press return"]; [OFStdIn readLine]; [OFStdOut setBackgroundColor: [OFColor green]]; [OFStdOut writeString: @"Hello!"]; [OFThread sleepForTimeInterval: 2]; [OFStdOut eraseLine]; [OFStdOut writeString: @"World!"]; [OFThread sleepForTimeInterval: 2]; [OFStdOut clear]; [OFThread sleepForTimeInterval: 2]; [OFStdOut setCursorPosition: OFMakePoint(5, 3)]; [OFStdOut writeString: @"Text at (5, 3)"]; [OFThread sleepForTimeInterval: 2]; [OFStdOut setRelativeCursorPosition: OFMakePoint(-2, 0)]; [OFThread sleepForTimeInterval: 2]; [OFStdOut setRelativeCursorPosition: OFMakePoint(2, 0)]; [OFThread sleepForTimeInterval: 2]; [OFStdOut setRelativeCursorPosition: OFMakePoint(0, -2)]; [OFThread sleepForTimeInterval: 2]; [OFStdOut setRelativeCursorPosition: OFMakePoint(0, 2)]; [OFThread sleepForTimeInterval: 2]; [OFStdOut setRelativeCursorPosition: OFMakePoint(1, 1)]; [OFThread sleepForTimeInterval: 2]; [OFStdOut setRelativeCursorPosition: OFMakePoint(-1, -1)]; [OFThread sleepForTimeInterval: 2]; [OFStdOut setCursorColumn: 2]; [OFThread sleepForTimeInterval: 2]; [OFStdOut reset]; [OFApplication terminate]; } @end objfw-1.1.6/tests/testfile.bin000066400000000000000000000020001465614216400163020ustar00rootroot00000000000000'D|?SeKj)G|tm;>rqqPC`ȇU*@E!nZ6>)j\WR LŲǺH{GH:Q¿=6]OKf FdK֭j.'HtԮ6cݕVzE-7%2r},΅ {ENl.'xŦF58/ܮ ]+ ңh*I} B3;!JjWW.= c":$3W'NQgMɶc?tGp`d}n#ak5 :yA,Ub '{w"GFi TCq2as7r?c%-&{ 0SVS ў|#C&üCVMߢ_s 'e5(D~׌L$h %tLq3PykilxOa2/Nmf zp,,/W´kKh5k?hznpHSa fV{ȿ#2_CP894;%\*B֎D rs]EAFeB B_Ntlt|nCc˪}^!gqSXE &S6m5Wyn&4^ )q":D7kZ I`TO9;H$!BFWgz@2c St]] #:xK+e &"%U%kŕ4Ÿr)f@Э%o Z'kg'+{چi"";EsSD!*@[Q%R#C: a6k uv#8JzBLVKe\[3|[m䵓zFx y-Wޗ,׼t[mbpbGoMfj~ jobjfw-1.1.6/tests/testfile.ini000066400000000000000000000003751465614216400163260ustar00rootroot00000000000000[tests] foo = bar foobar=baz ;comment [foobar] ;foobarcomment qux=" asd" "quxqux " = asd quxquxqux="hello\"wrld" qux2="a\f" [types] integer = 0x20 bool = true float = 0.5 array1 = 1 array2 = 1 double = 0.25 array1 = 2 array2 = 2 objfw-1.1.6/tests/testfile.txt000066400000000000000000000000071465614216400163560ustar00rootroot00000000000000testobjfw-1.1.6/tests/tests.xml000066400000000000000000000015551465614216400156730ustar00rootroot00000000000000 0004000000033600 0004000000033600 0004000000033500 0004000000033500 0004000000125600 0004000000125600 0004000000125500 0004000000125500 00040000000CCD00 00040000000B0F00 objfw-1.1.6/utils/000077500000000000000000000000001465614216400137775ustar00rootroot00000000000000objfw-1.1.6/utils/Makefile000066400000000000000000000013411465614216400154360ustar00rootroot00000000000000include ../extra.mk SUBDIRS += ${OBJFW_NEW} \ ${OFARC} \ ${OFDNS} \ ${OFHASH} \ ${OFHTTP} include ../buildsys.mk DISTCLEAN = objfw-config install-extra: objfw-config objfw-compile objfw-embed for i in objfw-config objfw-compile objfw-embed; do \ ${INSTALL_STATUS}; \ if ${MKDIR_P} ${DESTDIR}${bindir} && ${INSTALL} -m 755 $$i \ ${DESTDIR}${bindir}/${BIN_PREFIX}$$i; then \ ${INSTALL_OK}; \ else \ ${INSTALL_FAILED}; \ fi \ done uninstall-extra: for i in objfw-config objfw-compile objfw-embed; do \ if test -f ${DESTDIR}${bindir}/${BIN_PREFIX}$$i; then \ if rm -f ${DESTDIR}${bindir}/${BIN_PREFIX}$$i; then \ ${DELETE_OK}; \ else \ ${DELETE_FAILED}; \ fi \ fi \ done objfw-1.1.6/utils/objfw-compile000066400000000000000000000172511465614216400164650ustar00rootroot00000000000000#!/bin/sh # # Copyright (c) 2008-2024 Jonathan Schleifer # # All rights reserved. # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License version 3.0 only, # as published by the Free Software Foundation. # # 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 Lesser General Public License # version 3.0 for more details. # # You should have received a copy of the GNU Lesser General Public License # version 3.0 along with this program. If not, see # . # if test x"$(basename "$0")" != x"objfw-compile"; then OBJFW_CONFIG="$(basename "$0" | sed 's/-objfw-compile$//')-objfw-config" else OBJFW_CONFIG="objfw-config" fi if ! which $OBJFW_CONFIG >/dev/null 2>&1; then echo "You need to have ObjFW and $OBJFW_CONFIG installed!" exit 1 fi parse_packages() { packages="" while test x"$1" != "x"; do case "$1" in --package) shift packages="$packages --package $1" ;; esac shift done } parse_packages "$@" show_help() { cat >&2 <<__EOF__ Syntax: objfw-compile -o output [flags] source1.m source2.mm ... -o name Specify the output name (not file name!) --arc Use automatic reference counting --lib version Compile a library (with the specified version) instead of an application --plugin Compile a plugin instead of an application --package name Use the specified package --builddir dir Place built objects into the specified directory -D* -D * Pass the specified define to the compiler -framework * Pass the specified -framework argument to the linker (macOS / iOS only) -f* Pass the specified -f flag to the compiler -F* -F * Pass the specified -F flag to the linker (macOS / iOS only) -g* Pass the specified -g flag to the compiler -I* -I * Pass the specified -I flag to the compiler -l* -l * Pass the specified -l flag to the linker -L* -L * Pass the specified -L flag to the linker -m* Pass the specified -m flag to the compiler -O* Pass the specified -O flag to the compiler -pthread Pass -pthread to the compiler and linker -std=* Pass the specified -std= flag to the compiler -Wl,* Pass the specified -Wl, flag to the linker -W* Pass the specified -W flag to the compiler --help Show this help __EOF__ } CPPFLAGS="$CPPFLAGS $($OBJFW_CONFIG $packages --cppflags)" OBJC="$($OBJFW_CONFIG --objc)" OBJCFLAGS="$OBJCFLAGS $($OBJFW_CONFIG $packages --objcflags) -Wall -g" LIBS="$LIBS $($OBJFW_CONFIG $packages --libs)" LDFLAGS="$LDFLAGS $($OBJFW_CONFIG $packages --ldflags --rpath)" if test x"$1" = "x"; then show_help exit 1 fi status_compiling() { printf "\033[K\033[0;33mCompiling \033[1;33m%s\033[0;33m...\033[0m\r" \ "$1" } status_compiled() { printf "\033[K\033[0;32mSuccessfully compiled \033[1;32m%s\033[0;32m." \ "$1" printf "\033[0m\n" } status_compile_failed() { printf "\033[K\033[0;31mFailed to compile \033[1;31m%s\033[0;31m!" "$1" printf "\033[0m\n" exit $2 } status_linking() { printf "\033[K\033[0;33mLinking \033[1;33m%s\033[0;33m...\033[0m\r" "$1" } status_linked() { printf "\033[K\033[0;32mSuccessfully linked \033[1;32m%s\033[0;32m." \ "$1" printf "\033[0m\n" } status_link_failed() { printf "\033[K\033[0;31mFailed to link \033[1;31m%s\033[0;31m!" "$1" printf "\033[0m\n" exit $2 } srcs="" out="" objs="" builddir="" link="no" link_stdcpp="no" lib="no" plugin="no" out_prefix="" out_suffix="" while test x"$1" != "x"; do case "$1" in -o|--out) shift out="$1" ;; --lib) if test x"$plugin" = x"yes"; then echo "You can't use --lib and --plugin!" exit 1 fi shift if ! echo "$1" | grep "^[0-9]\+\.[0-9]\+$" >/dev/null; then echo "$1 is not a valid library version!" exit 1 fi export LIB_MAJOR="${1%.*}" export LIB_MINOR="${1#*.}" lib="yes" OBJCFLAGS="$OBJCFLAGS $($OBJFW_CONFIG --lib-cflags)" out_prefix="$($OBJFW_CONFIG --lib-prefix)" out_suffix="$($OBJFW_CONFIG --lib-suffix)" ;; --package) # Already included into the flags. shift ;; --plugin) if test x"$lib" = x"yes"; then echo "You can't use --lib and --plugin!" exit 1 fi plugin="yes" OBJCFLAGS="$OBJCFLAGS $($OBJFW_CONFIG --plugin-cflags)" LDFLAGS="$LDFLAGS $($OBJFW_CONFIG --plugin-ldflags)" out_suffix="$($OBJFW_CONFIG --plugin-suffix)" ;; --arc) OBJCFLAGS="$OBJCFLAGS $($OBJFW_CONFIG --arc)" ;; --builddir) shift builddir="$1" ;; -D) shift CPPFLAGS="$CPPFLAGS -D$1" ;; -D*) CPPFLAGS="$CPPFLAGS $1" ;; -framework) shift LIBS="$LIBS -framework $1" ;; -f*) OBJCFLAGS="$OBJCFLAGS $1" ;; -F) shift LIBS="$LIBS -F$1" ;; -F*) LIBS="$LIBS $1" ;; -g*) OBJCFLAGS="$OBJCFLAGS $1" ;; -I) shift CPPFLAGS="$CPPFLAGS -I$1" ;; -I*) CPPFLAGS="$CPPFLAGS $1" ;; -l) shift LIBS="$LIBS -l$1" ;; -l*) LIBS="$LIBS $1" ;; -L) shift LIBS="$LIBS -L$1" ;; -L*) LIBS="$LIBS $1" ;; -m*) OBJCFLAGS="$OBJCFLAGS $1" ;; -O*) OBJCFLAGS="$OBJCFLAGS $1" ;; -pthread) OBJCFLAGS="$OBJCFLAGS $1" LDFLAGS="$LDFLAGS $1" ;; -std=*) OBJCFLAGS="$OBJCFLAGS $1" ;; -Wl,*) LDFLAGS="$LDFLAGS $1" ;; -W*) OBJCFLAGS="$OBJCFLAGS $1" ;; --help) show_help exit 0 ;; -*) echo "Unknown option: $1" exit 1 ;; *.m) srcs="$srcs $1" ;; *.mm) srcs="$srcs $1" link_stdcpp="yes" ;; *) echo "Only .m and .mm files can be compiled!" 1>&2 exit 1 ;; esac shift done if test x"$out" = x""; then echo "No output name specified! Use -o or --out!" exit 1 fi case "$builddir" in "") ;; */) ;; *) builddir="$builddir/" ;; esac for i in $srcs; do case $i in *.m) if test x"$lib" = x"yes"; then obj="$builddir${i%.m}.lib.o" elif test x"$plugin" = x"yes"; then obj="$builddir${i%.m}.plugin.o" else obj="$builddir${i%.m}.o" fi ;; *.mm) if test x"$lib" = x"yes"; then obj="$builddir${i%.mm}.lib.o" elif test x"$plugin" = x"yes"; then obj="$builddir${i%.mm}.plugin.o" else obj="$builddir${i%.mm}.o" fi ;; esac objs="$objs $obj" build="no" if test ! -f "$obj" -o "$i" -nt "$obj"; then build="yes" else deps=$($OBJC -E -M $CPPFLAGS $OBJCFLAGS $i | sed -e 's/.*: //' -e 's/\\//g') for dep in $deps; do test "$dep" -nt $obj && build="yes" done fi if test x"$build" = x"yes"; then link="yes" status_compiling $i mkdir -p "$(dirname $obj)" || status_compile_failed $i $? $OBJC $CPPFLAGS $OBJCFLAGS -c -o $obj $i || \ status_compile_failed $i $? status_compiled $i fi done test x"$lib" = x"no" -a x"$plugin" = x"no" && \ out_suffix="$($OBJFW_CONFIG --prog-suffix)" test x"$link_stdcpp" = x"yes" && LIBS="$LIBS -lstdc++" if test x"$lib" = x"yes"; then export SHARED_LIB="$out_prefix$out$out_suffix" LDFLAGS="$LDFLAGS $($OBJFW_CONFIG --lib-ldflags)" fi if test x"$plugin" = x"yes" -a x"$out_suffix" = x".bundle"; then # If $out_suffix is .bundle, it means we are creating a macOS bundle. # These are not just a single file, but have a certain directory # structure. Therefore we amend the output path to match the expected # directory structure. mkdir -p $out$out_suffix/Contents/MacOS out="$out$out_suffix/Contents/MacOS/$(basename $out)" out_suffix="" fi if test ! -f "$out_prefix$out$out_suffix" -o x"$link" = x"yes"; then status_linking $out_prefix$out$out_suffix $OBJC -o $out_prefix$out$out_suffix $objs $LIBS $LDFLAGS || \ status_link_failed $out $? status_linked $out_prefix$out$out_suffix fi objfw-1.1.6/utils/objfw-config.in000066400000000000000000000132641465614216400167070ustar00rootroot00000000000000#!/bin/sh # # Copyright (c) 2008-2024 Jonathan Schleifer # # All rights reserved. # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License version 3.0 only, # as published by the Free Software Foundation. # # 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 Lesser General Public License # version 3.0 for more details. # # You should have received a copy of the GNU Lesser General Public License # version 3.0 along with this program. If not, see # . # prefix="@prefix@" exec_prefix="@exec_prefix@" libdir="@libdir@" packagesdir="$libdir/objfw-config" CFLAGS="" CPPFLAGS="@OBJFW_CPPFLAGS@ -I@includedir@" CXXFLAGS="" OBJC="@OBJC@" OBJCFLAGS="@OBJFW_OBJCFLAGS@" LIB_CFLAGS="@LIB_CFLAGS@" LIB_LDFLAGS="@LIB_LDFLAGS@" LIB_PREFIX="@LIB_PREFIX@" LIB_SUFFIX="@LIB_SUFFIX@" LDFLAGS="@LDFLAGS@" LDFLAGS_REEXPORT="@LDFLAGS_REEXPORT@" LDFLAGS_RPATH="@LDFLAGS_RPATH@" LIBS="-lobjfw @RUNTIME_LIBS@ @LIBS@" FRAMEWORK_LIBS="-framework ObjFW" FRAMEWORK_LIBS="$FRAMEWORK_LIBS @RUNTIME_FRAMEWORK_LIBS@ @LIBS@" PLUGIN_CFLAGS="@PLUGIN_CFLAGS@" PLUGIN_LDFLAGS="@PLUGIN_LDFLAGS@" PLUGIN_SUFFIX="@PLUGIN_SUFFIX@" PROG_SUFFIX="@EXEEXT@" STATIC_LIBS="${libdir}/libobjfw.a @LIBS@" VERSION="@PACKAGE_VERSION@" show_help() { cat >&2 <<__EOF__ objfw-config: Available arguments are: --all Outputs all flags + libs --arc Outputs the required OBJCFLAGS to use ARC --cflags Outputs the required CFLAGS --cppflags Outputs the required CPPFLAGS --cxxflags Outputs the required CXXFLAGS --framework-libs Outputs the required LIBS, preferring frameworks --help Print this help --ldflags Outputs the required LDFLAGS --libs Outputs the required LIBS --lib-cflags Outputs CFLAGS for building a library --lib-ldflags Outputs LDFLAGS for building a library --lib-prefix Outputs the prefix for libraries --lib-suffix Outputs the suffix for libraries --objc Outputs the OBJC used to compile ObjFW --objcflags Outputs the required OBJCFLAGS --package Additionally outputs the flags for the specified package --packages-dir Outputs the directory where flags for packages are stored --plugin-cflags Outputs CFLAGS for building a plugin --plugin-ldflags Outputs LDFLAGS for building a plugin --plugin-suffix Outputs the suffix for plugins --prog-suffix Outputs the suffix for binaries --reexport Outputs LDFLAGS to reexport ObjFW --rpath Outputs LDFLAGS for using rpath --static-libs Outputs the required LIBS to link ObjFW statically --version Outputs the installed version __EOF__ exit $1 } test -z "$1" && show_help 1 package_format() { if test "$1" != "1"; then echo "Unsupported package format version: $1" 1>&2 exit 1 fi } package_depends_on() { if ! test -f "$packagesdir/$1.oc"; then echo "No such package: $1" 1>&2 exit 1 fi set -e . "$packagesdir/$1.oc" set +e } parse_packages() { while test x"$1" != "x"; do case "$1" in --package) shift package_depends_on "$1" ;; esac shift done } parse_packages "$@" # Add search directories after all packages have been processed so that they # always come first. LIBS="-L${libdir} $LIBS" FRAMEWORK_LIBS="-F${prefix}/Library/Frameworks $FRAMEWORK_LIBS" flag_printed="no" output_flag() { if test x"$flag_printed" = x"yes"; then printf " %s" "$1" else printf "%s" "$1" flag_printed="yes" fi } while test x"$1" != "x"; do case "$1" in --all) output_flag "$CFLAGS $CPPFLAGS $CXXFLAGS $OBJCFLAGS" output_flag "$LDFLAGS $LDFLAGS_REEXPORT $LDFLAGS_RPATH $LIBS" ;; --arc) output_flag "-fobjc-arc -fobjc-arc-exceptions" ;; --cflags) output_flag "$CFLAGS" ;; --cppflags) output_flag "$CPPFLAGS" ;; --cxxflags) output_flag "$CXXFLAGS" ;; --framework-libs) output_flag "$FRAMEWORK_LIBS" ;; --help) show_help 0 ;; --objc) output_flag "$OBJC" ;; --objcflags) output_flag "$OBJCFLAGS" ;; --libs) output_flag "$LIBS" ;; --lib-cflags) if test x"$LIB_MAJOR" = x"" -o x"$LIB_MINOR" = x""; then echo "LIB_MAJOR and LIB_MINOR need to be set!" 1>&2 exit 1 fi output_flag "$LIB_CFLAGS" ;; --lib-ldflags) if test x"$SHARED_LIB" = x"" -o x"$LIB_MAJOR" = x"" \ -o x"$LIB_MINOR" = x""; then printf "SHARED_LIB, LIB_MAJOR and " 2>&1 echo "LIB_MINOR need to be set!" 1>&2 exit 1 fi output_flag "$LIB_LDFLAGS" ;; --lib-prefix) if test x"$LIB_MAJOR" = x"" -o x"$LIB_MINOR" = x""; then echo "LIB_MAJOR and LIB_MINOR need to be set!" 1>&2 exit 1 fi output_flag "$LIB_PREFIX" ;; --lib-suffix) if test x"$LIB_MAJOR" = x"" -o x"$LIB_MINOR" = x""; then echo "LIB_MAJOR and LIB_MINOR need to be set!" 1>&2 exit 1 fi output_flag "$LIB_SUFFIX" ;; --ldflags) output_flag "$LDFLAGS" ;; --reexport) output_flag "$LDFLAGS_REEXPORT" ;; --rpath) output_flag "$LDFLAGS_RPATH" ;; --package) # Already included into the flags. shift ;; --packages-dir) output_flag "$packagesdir" ;; --plugin-cflags) output_flag "$PLUGIN_CFLAGS" ;; --plugin-ldflags) output_flag "$PLUGIN_LDFLAGS" ;; --plugin-suffix) output_flag "$PLUGIN_SUFFIX" ;; --prog-suffix) output_flag "$PROG_SUFFIX" ;; --static-libs) output_flag "$STATIC_LIBS" ;; --version) output_flag "$VERSION" ;; *) echo "Invalid option: $1" 1>&2 exit 1 ;; esac shift done test x"$flag_printed" = x"yes" && echo exit 0 objfw-1.1.6/utils/objfw-embed000066400000000000000000000023711465614216400161060ustar00rootroot00000000000000#!/bin/sh # # Copyright (c) 2008-2024 Jonathan Schleifer # # All rights reserved. # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License version 3.0 only, # as published by the Free Software Foundation. # # 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 Lesser General Public License # version 3.0 for more details. # # You should have received a copy of the GNU Lesser General Public License # version 3.0 along with this program. If not, see # . # if test $# != 3; then echo "Usage: $0 source_file filename output.m" 1>&2 exit 1 fi exec 1>$3 cat < #include #ifdef OF_COMPILING_OBJFW # import "OFEmbeddedIRIHandler.h" #else # import #endif static const uint8_t bytes[] = { EOF od -vtx1 "$1" | cut -d' ' -sf2- | \ sed '/^ *$/d;s/^ *//;s/ *$//;s/ */ /g;s/^/0x/;s/ /, 0x/g;s/$/,/' cat < * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFApplication.h" #import "OFFile.h" #import "OFStdIOStream.h" #import "OFString.h" #import "OFOpenItemFailedException.h" void newApp(OFString *name) { OFString *path = [name stringByAppendingPathExtension: @"m"]; OFFile *file = nil; @try { file = [OFFile fileWithPath: path mode: @"wx"]; } @catch (OFOpenItemFailedException *e) { if (e.errNo != EEXIST) @throw e; [OFStdErr writeFormat: @"File %@ already exists! Aborting...\n", e.path]; [OFApplication terminateWithStatus: 1]; } [file writeFormat: @"#import \n" @"\n" @"@interface %@: OFObject \n" @"@end\n" @"\n" @"OF_APPLICATION_DELEGATE(%@)\n" @"\n" @"@implementation %@\n" @"- (void)applicationDidFinishLaunching: " @"(OFNotification *)notification\n" @"{\n" @" [OFApplication terminate];\n" @"}\n" @"@end\n", name, name, name]; [file close]; } objfw-1.1.6/utils/objfw-new/NewClass.m000066400000000000000000000074511465614216400176010ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "Property.h" #import "OFApplication.h" #import "OFArray.h" #import "OFFile.h" #import "OFStdIOStream.h" #import "OFString.h" #import "OFOpenItemFailedException.h" void newClass(OFString *name, OFString *superclass, OFMutableArray *properties) { OFString *headerPath = [name stringByAppendingPathExtension: @"h"]; OFString *implPath = [name stringByAppendingPathExtension: @"m"]; OFFile *headerFile = nil, *implFile = nil; bool needsDealloc = false; @try { headerFile = [OFFile fileWithPath: headerPath mode: @"wx"]; implFile = [OFFile fileWithPath: implPath mode: @"wx"]; } @catch (OFOpenItemFailedException *e) { if (e.errNo != EEXIST) @throw e; [OFStdErr writeFormat: @"File %@ already exists! Aborting...\n", e.path]; [OFApplication terminateWithStatus: 1]; } if (superclass == nil) superclass = @"OFObject"; for (size_t i = 0; i < properties.count; i++) { Property *property = [Property propertyWithString: [properties objectAtIndex: i]]; [properties replaceObjectAtIndex: i withObject: property]; } [headerFile writeFormat: @"#import \n" @"\n" @"OF_ASSUME_NONNULL_BEGIN\n" @"\n" @"@interface %@: %@\n", name, superclass]; if (properties.count > 0) [headerFile writeString: @"{\n"]; for (Property *property in properties) [headerFile writeFormat: @"\t%@_%@;\n", property.type, property.name]; if (properties.count > 0) [headerFile writeString: @"}\n\n"]; for (Property *property in properties) { [headerFile writeString: @"@property "]; if (property.attributes.count > 0) { bool first = true; if ([property.attributes containsObject: @"nullable"]) [headerFile writeString: @"OF_NULLABLE_PROPERTY "]; [headerFile writeString: @"("]; for (OFString *attribute in property.attributes) { if ([attribute isEqual: @"nullable"]) continue; if ([attribute isEqual: @"retain"] || [attribute isEqual: @"copy"]) needsDealloc = true; if (!first) [headerFile writeString: @", "]; [headerFile writeString: attribute]; first = false; } [headerFile writeString: @") "]; } [headerFile writeFormat: @"%@%@;\n", property.type, property.name]; } [headerFile writeString: @"@end\n" @"\n" @"OF_ASSUME_NONNULL_END\n"]; [implFile writeFormat: @"#import \"%@\"\n" @"\n" @"@implementation %@\n", headerPath, name]; for (Property *property in properties) [implFile writeFormat: @"@synthesize %@ = _%@;\n", property.name, property.name]; if (needsDealloc) { [implFile writeString: @"\n" @"- (void)dealloc\n" @"{\n"]; for (Property *property in properties) if ([property.attributes containsObject: @"retain"] || [property.attributes containsObject: @"copy"]) [implFile writeFormat: @"\t[_%@ release];\n", property.name]; [implFile writeString: @"\n" @"\t[super dealloc];\n" @"}\n"]; } [implFile writeString: @"@end\n"]; [headerFile close]; [implFile close]; } objfw-1.1.6/utils/objfw-new/NewTest.m000066400000000000000000000030121465614216400174400ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFApplication.h" #import "OFFile.h" #import "OFStdIOStream.h" #import "OFString.h" #import "OFOpenItemFailedException.h" void newTest(OFString *name) { OFString *path = [name stringByAppendingPathExtension: @"m"]; OFFile *file = nil; @try { file = [OFFile fileWithPath: path mode: @"wx"]; } @catch (OFOpenItemFailedException *e) { if (e.errNo != EEXIST) @throw e; [OFStdErr writeFormat: @"File %@ already exists! Aborting...\n", e.path]; [OFApplication terminateWithStatus: 1]; } [file writeFormat: @"#import \n" @"#import \n" @"\n" @"@interface %@: OTTestCase\n" @"@end\n" @"\n" @"@implementation %@\n" @"@end\n", name, name]; [file close]; } objfw-1.1.6/utils/objfw-new/ObjFWNew.m000066400000000000000000000067471465614216400175120ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFApplication.h" #import "OFArray.h" #import "OFObject.h" #import "OFOptionsParser.h" #import "OFStdIOStream.h" #import "OFString.h" @interface ObjFWNew: OFObject @end extern void newApp(OFString *); extern void newClass(OFString *, OFString *, OFMutableArray *); extern void newTest(OFString *); OF_APPLICATION_DELEGATE(ObjFWNew) static void help(OFStream *stream, bool full, int status) { [stream writeFormat: @"Usage: %@ --app|--class|--test [--superclass=] [--property=] name" @"\n", [OFApplication programName]]; if (full) { [stream writeString: @"\n"]; [stream writeLine: @"Options:\n" @" -a --app Create a new app\n" @" -c --class Create a new class\n" @" -h --help Show this help\n" @" -p --property= Add a property to the class.\n" @" E.g.: --property='(readonly, " @"nonatomic) id foo'\n" @" -s --superclass= Specify the superclass for the " @"class\n" @" -t --test Create a new test\n"]; } [OFApplication terminateWithStatus: status]; } @implementation ObjFWNew - (void)applicationDidFinishLaunching: (OFNotification *)notification { bool app, class, test; OFString *superclass = nil, *name; OFMutableArray OF_GENERIC(OFString *) *properties = nil; const OFOptionsParserOption options[] = { { 'a', @"app", 0, &app, NULL }, { 'c', @"class", 0, &class, NULL }, { 'h', @"help", 0, NULL, NULL }, { 'p', @"property", 1, NULL, NULL }, { 's', @"superclass", 1, NULL, &superclass }, { 't', @"test", 0, &test, NULL }, { '\0', nil, 0, NULL, NULL } }; OFOptionsParser *optionsParser; OFUnichar option; if ([OFApplication arguments].count == 0) help(OFStdErr, true, 1); optionsParser = [OFOptionsParser parserWithOptions: options]; while ((option = [optionsParser nextOption]) != '\0') { switch (option) { case 'h': help(OFStdOut, true, 0); break; case 'p': if (properties == nil) properties = [OFMutableArray array]; [properties addObject: optionsParser.argument]; break; case '?': case ':': case '=': help(OFStdErr, false, 1); break; } } if (app + class + test != 1 || optionsParser.remainingArguments.count != 1) help(OFStdErr, false, 1); if ((superclass && !class) || (properties != nil && !class)) help(OFStdErr, false, 1); name = optionsParser.remainingArguments.firstObject; if ([name rangeOfString: @"."].location != OFNotFound) { [OFStdErr writeLine: @"Name must not contain dots!"]; [OFApplication terminate]; } if (app) newApp(name); else if (class) newClass(name, superclass, properties); else if (test) newTest(name); else help(OFStdErr, false, 1); [OFApplication terminate]; } @end objfw-1.1.6/utils/objfw-new/Property.h000066400000000000000000000023001465614216400176650ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @interface Property: OFObject { OFString *_name, *_type; OFArray OF_GENERIC(OFString *) *_attributes; } + (instancetype)propertyWithString: (OFString *)string; - (instancetype)initWithString: (OFString *)string; @property (readonly, nonatomic) OFString *name; @property (readonly, nonatomic) OFString *type; @property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *attributes; @end OF_ASSUME_NONNULL_END objfw-1.1.6/utils/objfw-new/Property.m000066400000000000000000000060071465614216400177020ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "Property.h" #import "OFArray.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" @interface Property () - (void)parseString: (OFString *)string; @end @implementation Property @synthesize name = _name, type = _type, attributes = _attributes; + (instancetype)propertyWithString: (OFString *)string { return [[[self alloc] initWithString: string] autorelease]; } - (instancetype)initWithString: (OFString *)string { self = [super init]; @try { [self parseString: string]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)parseString: (OFString *)string { void *pool = objc_autoreleasePoolPush(); const char *UTF8String = string.UTF8String; size_t length = string.UTF8StringLength; ssize_t nameIdx = -1; OFMutableArray *attributes = nil; if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if (UTF8String[0] == '(') { for (size_t i = 0, level = 0; i < length; i++) { if (UTF8String[i] == '(') level++; else if (UTF8String[i] == ')') { if (--level == 0) { OFString *attributesString = [OFString stringWithUTF8String: UTF8String + 1 length: i - 1]; attributes = [[[attributesString componentsSeparatedByString: @","] mutableCopy] autorelease]; UTF8String += i + 1; length += i + 1; while (*UTF8String == ' ' || *UTF8String == '\t') { UTF8String++; length--; } break; } } } } for (size_t i = 0; i < attributes.count; i++) { OFString *attribute = [[attributes objectAtIndex: i] stringByDeletingEnclosingWhitespaces]; [attributes replaceObjectAtIndex: i withObject: attribute]; } [attributes makeImmutable]; _attributes = [attributes copy]; for (ssize_t i = (ssize_t)length - 1; i > 0; i--) { if (UTF8String[i] == '*' || UTF8String[i] == ' ' || UTF8String[i] == '\t') { nameIdx = i + 1; break; } } if (nameIdx < 0) @throw [OFInvalidArgumentException exception]; _name = [[OFString alloc] initWithUTF8String: UTF8String + nameIdx]; _type = [[OFString alloc] initWithUTF8String: UTF8String length: (size_t)nameIdx]; objc_autoreleasePoolPop(pool); } - (void)dealloc { [_name release]; [_type release]; [super dealloc]; } @end objfw-1.1.6/utils/ofarc/000077500000000000000000000000001465614216400150715ustar00rootroot00000000000000objfw-1.1.6/utils/ofarc/Archive.h000066400000000000000000000027761465614216400166370ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFIRI; @class OFStream; @protocol Archive + (instancetype)archiveWithIRI: (nullable OFIRI *)IRI stream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (OFStringEncoding)encoding; - (instancetype)initWithIRI: (nullable OFIRI *)IRI stream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (OFStringEncoding)encoding; - (void)listFiles; - (void)extractFiles: (OFArray OF_GENERIC(OFString *) *)files; - (void)printFiles: (OFArray OF_GENERIC(OFString *) *)files; @optional - (void)addFiles: (OFArray OF_GENERIC(OFString *) *)files archiveComment: (nullable OFString *)archiveComment; @end OF_ASSUME_NONNULL_END objfw-1.1.6/utils/ofarc/GZIPArchive.h000066400000000000000000000015541465614216400173220ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFGZIPStream.h" #import "Archive.h" @interface GZIPArchive: OFObject { OFGZIPStream *_stream; OFIRI *_archiveIRI; } @end objfw-1.1.6/utils/ofarc/GZIPArchive.m000066400000000000000000000111261465614216400173230ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFApplication.h" #import "OFArray.h" #import "OFFile.h" #import "OFFileManager.h" #import "OFIRI.h" #import "OFLocale.h" #import "OFStdIOStream.h" #import "GZIPArchive.h" #import "OFArc.h" static OFArc *app; static void setPermissions(OFString *destination, OFIRI *source) { #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS OFFileManager *fileManager = [OFFileManager defaultManager]; OFFileAttributes attributes = [fileManager attributesOfItemAtIRI: source]; OFFileAttributeKey key = OFFilePOSIXPermissions; OFFileAttributes destinationAttributes = [OFDictionary dictionaryWithObject: [attributes objectForKey: key] forKey: key]; [fileManager setAttributes: destinationAttributes ofItemAtPath: destination]; #endif [app quarantineFile: destination]; } static void setModificationDate(OFString *path, OFGZIPStream *stream) { OFDate *modificationDate = stream.modificationDate; OFFileAttributes attributes; if (modificationDate == nil) return; attributes = [OFDictionary dictionaryWithObject: modificationDate forKey: OFFileModificationDate]; [[OFFileManager defaultManager] setAttributes: attributes ofItemAtPath: path]; } @implementation GZIPArchive + (void)initialize { if (self == [GZIPArchive class]) app = (OFArc *)[OFApplication sharedApplication].delegate; } + (instancetype)archiveWithIRI: (OFIRI *)IRI stream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithIRI: IRI stream: stream mode: mode encoding: encoding] autorelease]; } - (instancetype)initWithIRI: (OFIRI *)IRI stream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (OFStringEncoding)encoding { self = [super init]; @try { _stream = [[OFGZIPStream alloc] initWithStream: stream mode: mode]; _archiveIRI = [IRI copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_stream release]; [_archiveIRI release]; [super dealloc]; } - (void)listFiles { [OFStdErr writeLine: OF_LOCALIZED(@"cannot_list_gz", @"Cannot list files of a .gz archive!")]; app->_exitStatus = 1; } - (void)extractFiles: (OFArray OF_GENERIC(OFString *) *)files { OFString *fileName; OFFile *output; if (files.count != 0) { [OFStdErr writeLine: OF_LOCALIZED( @"cannot_extract_specific_file_from_gz", @"Cannot extract a specific file of a .gz archive!")]; app->_exitStatus = 1; return; } fileName = _archiveIRI.IRIByDeletingPathExtension.lastPathComponent; if (app->_outputLevel >= 0) [OFStdOut writeString: OF_LOCALIZED(@"extracting_file", @"Extracting %[file]...", @"file", fileName)]; if (![app shouldExtractFile: fileName outFileName: fileName]) return; output = [OFFile fileWithPath: fileName mode: @"w"]; setPermissions(fileName, _archiveIRI); while (!_stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: _stream toStream: output fileName: fileName]; if (length < 0) { app->_exitStatus = 1; return; } } [output close]; setModificationDate(fileName, _stream); if (app->_outputLevel >= 0) { [OFStdOut writeString: @"\r"]; [OFStdOut writeLine: OF_LOCALIZED(@"extracting_file_done", @"Extracting %[file]... done", @"file", fileName)]; } } - (void)printFiles: (OFArray OF_GENERIC(OFString *) *)files { OFString *fileName = _archiveIRI.IRIByDeletingPathExtension.lastPathComponent; if (files.count > 0) { [OFStdErr writeLine: OF_LOCALIZED( @"cannot_print_specific_file_from_gz", @"Cannot print a specific file of a .gz archive!")]; app->_exitStatus = 1; return; } while (!_stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: _stream toStream: OFStdOut fileName: fileName]; if (length < 0) { app->_exitStatus = 1; return; } } } @end objfw-1.1.6/utils/ofarc/LHAArchive.h000066400000000000000000000015271465614216400171550ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFLHAArchive.h" #import "Archive.h" @interface LHAArchive: OFObject { OFLHAArchive *_archive; } @end objfw-1.1.6/utils/ofarc/LHAArchive.m000066400000000000000000000350071465614216400171620ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFApplication.h" #import "OFArray.h" #import "OFDate.h" #import "OFFile.h" #import "OFFileManager.h" #import "OFIRI.h" #import "OFLocale.h" #import "OFNumber.h" #import "OFPair.h" #import "OFSet.h" #import "OFStdIOStream.h" #import "OFString.h" #import "LHAArchive.h" #import "OFArc.h" #import "OFSetItemAttributesFailedException.h" static OFArc *app; static OFString * indent(OFString *string) { return [string stringByReplacingOccurrencesOfString: @"\n" withString: @"\n\t"]; } static void setPermissions(OFString *path, OFLHAArchiveEntry *entry) { #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS OFNumber *POSIXPermissions = entry.POSIXPermissions; if (POSIXPermissions != nil) { OFFileAttributes attributes; POSIXPermissions = [OFNumber numberWithUnsignedShort: POSIXPermissions.unsignedShortValue & 0777]; attributes = [OFDictionary dictionaryWithObject: POSIXPermissions forKey: OFFilePOSIXPermissions]; [[OFFileManager defaultManager] setAttributes: attributes ofItemAtPath: path]; } #endif [app quarantineFile: path]; } static void setModificationDate(OFString *path, OFLHAArchiveEntry *entry) { OFFileAttributes attributes = [OFDictionary dictionaryWithObject: entry.modificationDate forKey: OFFileModificationDate]; @try { [[OFFileManager defaultManager] setAttributes: attributes ofItemAtPath: path]; } @catch (OFSetItemAttributesFailedException *e) { if (e.errNo != EISDIR) @throw e; } } @implementation LHAArchive + (void)initialize { if (self == [LHAArchive class]) app = (OFArc *)[OFApplication sharedApplication].delegate; } + (instancetype)archiveWithIRI: (OFIRI *)IRI stream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithIRI: IRI stream: stream mode: mode encoding: encoding] autorelease]; } - (instancetype)initWithIRI: (OFIRI *)IRI stream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (OFStringEncoding)encoding { self = [super init]; @try { _archive = [[OFLHAArchive alloc] initWithStream: stream mode: mode]; if (encoding != OFStringEncodingAutodetect) _archive.encoding = encoding; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_archive release]; [super dealloc]; } - (void)listFiles { OFLHAArchiveEntry *entry; while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); [OFStdOut writeLine: entry.fileName]; if (app->_outputLevel >= 1) { OFString *modificationDate = [entry.modificationDate localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; OFString *compressedSize = [OFString stringWithFormat: @"%llu", entry.compressedSize]; OFString *uncompressedSize = [OFString stringWithFormat: @"%llu", entry.uncompressedSize]; OFString *CRC16 = [OFString stringWithFormat: @"%04" PRIX16, entry.CRC16]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_compressed_size", @"[" @" 'Compressed: '," @" [" @" {'size == 1': '1 byte'}," @" {'': '%[size] bytes'}" @" ]" @"]".objectByParsingJSON, @"size", compressedSize)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_uncompressed_size", @"[" @" 'Uncompressed: '," @" [" @" {'size == 1': '1 byte'}," @" {'': '%[size] bytes'}" @" ]" @"]".objectByParsingJSON, @"size", uncompressedSize)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_compression_method", @"Compression method: %[method]", @"method", entry.compressionMethod)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED(@"list_crc16", @"CRC16: %[crc16]", @"crc16", CRC16)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_modification_date", @"Modification date: %[date]", @"date", modificationDate)]; if (entry.POSIXPermissions != nil) { OFString *permissionsString = [OFString stringWithFormat: @"%llo", entry.POSIXPermissions .unsignedLongLongValue]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_posix_permissions", @"POSIX permissions: %[perm]", @"perm", permissionsString)]; } if (entry.ownerAccountID != nil) { [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_owner_account_id", @"Owner account ID: %[id]", @"id", entry.ownerAccountID)]; } if (entry.groupOwnerAccountID != nil) { [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED(@"list_gid", @"Group owner account ID: %[id]", @"id", entry.groupOwnerAccountID)]; } if (entry.ownerAccountName != nil) { [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_owner_account_name", @"Owner account name: %[name]", @"name", entry.ownerAccountName)]; } if (entry.groupOwnerAccountName != nil) { [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_group_owner_account_name", @"Group: %[name]", @"name", entry.groupOwnerAccountName)]; } if (app->_outputLevel >= 2) { OFString *headerLevel = [OFString stringWithFormat: @"%" PRIu8, entry.headerLevel]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_header_level", @"Header level: %[level]", @"level", headerLevel)]; if (entry.operatingSystemIdentifier != '\0') { OFString *OSID = [OFString stringWithFormat: @"%c", entry.operatingSystemIdentifier]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_osid", @"Operating system identifier: " @"%[osid]", @"osid", OSID)]; } } if (app->_outputLevel >= 3) { OFString *extensions = indent(entry.extensions.description); [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_extensions", @"Extensions: %[extensions]", @"extensions", extensions)]; } } objc_autoreleasePoolPop(pool); } } - (void)extractFiles: (OFArray OF_GENERIC(OFString *) *)files { OFFileManager *fileManager = [OFFileManager defaultManager]; bool all = (files.count == 0); OFMutableArray *delayedModificationDates = [OFMutableArray array]; OFMutableSet OF_GENERIC(OFString *) *missing = [OFMutableSet setWithArray: files]; OFLHAArchiveEntry *entry; while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); OFString *fileName = entry.fileName; OFString *outFileName, *directory; OFFile *output; OFStream *stream; unsigned long long written = 0, size = entry.uncompressedSize; int8_t percent = -1, newPercent; if (!all && ![files containsObject: fileName]) continue; [missing removeObject: fileName]; outFileName = [app safeLocalPathForPath: fileName]; if (outFileName == nil) { [OFStdErr writeLine: OF_LOCALIZED( @"refusing_to_extract_file", @"Refusing to extract %[file]!", @"file", fileName)]; app->_exitStatus = 1; goto outer_loop_end; } if (app->_outputLevel >= 0) [OFStdOut writeString: OF_LOCALIZED(@"extracting_file", @"Extracting %[file]...", @"file", fileName)]; if ([fileName hasSuffix: @"/"]) { [fileManager createDirectoryAtPath: outFileName createParents: true]; setPermissions(outFileName, entry); /* * As creating a new file in a directory changes its * modification date, we can only set it once all files * have been created. */ [delayedModificationDates addObject: [OFPair pairWithFirstObject: outFileName secondObject: entry]]; if (app->_outputLevel >= 0) { [OFStdOut writeString: @"\r"]; [OFStdOut writeLine: OF_LOCALIZED( @"extracting_file_done", @"Extracting %[file]... done", @"file", fileName)]; } goto outer_loop_end; } directory = outFileName.stringByDeletingLastPathComponent; if (![fileManager directoryExistsAtPath: directory]) [fileManager createDirectoryAtPath: directory createParents: true]; if (![app shouldExtractFile: fileName outFileName: outFileName]) goto outer_loop_end; stream = [_archive streamForReadingCurrentEntry]; output = [OFFile fileWithPath: outFileName mode: @"w"]; setPermissions(outFileName, entry); while (!stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: stream toStream: output fileName: fileName]; if (length < 0) { app->_exitStatus = 1; goto outer_loop_end; } written += length; newPercent = (written == size ? 100 : (int8_t)(written * 100 / size)); if (app->_outputLevel >= 0 && percent != newPercent) { OFString *percentString; percent = newPercent; percentString = [OFString stringWithFormat: @"%3u", percent]; [OFStdOut writeString: @"\r"]; [OFStdOut writeString: OF_LOCALIZED( @"extracting_file_percent", @"Extracting %[file]... %[percent]%", @"file", fileName, @"percent", percentString)]; } } [output close]; setModificationDate(outFileName, entry); if (app->_outputLevel >= 0) { [OFStdOut writeString: @"\r"]; [OFStdOut writeLine: OF_LOCALIZED( @"extracting_file_done", @"Extracting %[file]... done", @"file", fileName)]; } outer_loop_end: objc_autoreleasePoolPop(pool); } for (OFPair *pair in delayedModificationDates) setModificationDate(pair.firstObject, pair.secondObject); if (missing.count > 0) { for (OFString *file in missing) [OFStdErr writeLine: OF_LOCALIZED( @"file_not_in_archive", @"File %[file] is not in the archive!", @"file", file)]; app->_exitStatus = 1; } } - (void)printFiles: (OFArray OF_GENERIC(OFString *) *)files_ { OFMutableSet *files; OFLHAArchiveEntry *entry; if (files_.count < 1) { [OFStdErr writeLine: OF_LOCALIZED(@"print_no_file_specified", @"Need one or more files to print!")]; app->_exitStatus = 1; return; } files = [OFMutableSet setWithArray: files_]; while ((entry = [_archive nextEntry]) != nil) { OFString *fileName = entry.fileName; OFStream *stream; if (![files containsObject: fileName]) continue; stream = [_archive streamForReadingCurrentEntry]; while (!stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: stream toStream: OFStdOut fileName: fileName]; if (length < 0) { app->_exitStatus = 1; return; } } [files removeObject: fileName]; [stream close]; if (files.count == 0) break; } for (OFString *file in files) { [OFStdErr writeLine: OF_LOCALIZED(@"file_not_in_archive", @"File %[file] is not in the archive!", @"file", file)]; app->_exitStatus = 1; } } - (void)addFiles: (OFArray OF_GENERIC(OFString *) *)files archiveComment: (OFString *)archiveComment { OFFileManager *fileManager = [OFFileManager defaultManager]; for (OFString *fileName in files) { void *pool = objc_autoreleasePoolPush(); OFFileAttributes attributes; OFFileAttributeType type; OFMutableLHAArchiveEntry *entry; OFStream *output; if (app->_outputLevel >= 0) [OFStdOut writeString: OF_LOCALIZED(@"adding_file", @"Adding %[file]...", @"file", fileName)]; attributes = [fileManager attributesOfItemAtPath: fileName]; type = attributes.fileType; entry = [OFMutableLHAArchiveEntry entryWithFileName: fileName]; #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS entry.POSIXPermissions = [attributes objectForKey: OFFilePOSIXPermissions]; #endif entry.modificationDate = attributes.fileModificationDate; #ifdef OF_FILE_MANAGER_SUPPORTS_OWNER entry.ownerAccountID = [attributes objectForKey: OFFileOwnerAccountID]; entry.groupOwnerAccountID = [attributes objectForKey: OFFileGroupOwnerAccountID]; entry.ownerAccountName = [attributes objectForKey: OFFileOwnerAccountName]; entry.groupOwnerAccountName = [attributes objectForKey: OFFileGroupOwnerAccountName]; #endif if ([type isEqual: OFFileTypeDirectory]) { entry.compressionMethod = @"-lhd-"; if (![entry.fileName hasSuffix: @"/"]) entry.fileName = [entry.fileName stringByAppendingString: @"/"]; } output = [_archive streamForWritingEntry: entry]; if ([type isEqual: OFFileTypeRegular]) { unsigned long long written = 0; unsigned long long size = attributes.fileSize; int8_t percent = -1, newPercent; OFFile *input = [OFFile fileWithPath: fileName mode: @"r"]; while (!input.atEndOfStream) { ssize_t length = [app copyBlockFromStream: input toStream: output fileName: fileName]; if (length < 0) { app->_exitStatus = 1; goto outer_loop_end; } written += length; newPercent = (written == size ? 100 : (int8_t)(written * 100 / size)); if (app->_outputLevel >= 0 && percent != newPercent) { OFString *percentString; percent = newPercent; percentString = [OFString stringWithFormat: @"%3u", percent]; [OFStdOut writeString: @"\r"]; [OFStdOut writeString: OF_LOCALIZED( @"adding_file_percent", @"Adding %[file]... %[percent]%", @"file", fileName, @"percent", percentString)]; } } } if (app->_outputLevel >= 0) { [OFStdOut writeString: @"\r"]; [OFStdOut writeLine: OF_LOCALIZED( @"adding_file_done", @"Adding %[file]... done", @"file", fileName)]; } [output close]; outer_loop_end: objc_autoreleasePoolPop(pool); } [_archive close]; } @end objfw-1.1.6/utils/ofarc/Makefile000066400000000000000000000012531465614216400165320ustar00rootroot00000000000000include ../../extra.mk PROG = ofarc${PROG_SUFFIX} SRCS = GZIPArchive.m \ LHAArchive.m \ OFArc.m \ TarArchive.m \ ZIPArchive.m \ ZooArchive.m DATA = localization/de.json \ localization/localizations.json include ../../buildsys.mk PACKAGE_NAME = ofarc ${PROG}: ${LIBOBJFW_DEP_LVL2} ${LIBOBJFWRT_DEP_LVL2} CPPFLAGS += -I../../src \ -I../../src/runtime \ -I../../src/exceptions \ -I../.. \ -DLOCALIZATION_DIR=\"${datadir}/ofarc/localization\" LIBS := -L../../src -L../../src/tls ${OFHTTP_LIBS} -lobjfw \ -L../../src/runtime ${RUNTIME_LIBS} \ ${LIBS} LD = ${OBJC} LDFLAGS += ${LDFLAGS_RPATH} objfw-1.1.6/utils/ofarc/OFArc.h000066400000000000000000000030531465614216400161750ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" #import "OFString.h" #import "Archive.h" OF_ASSUME_NONNULL_BEGIN @class OFIRI; #ifndef S_IRWXG # define S_IRWXG 0 #endif #ifndef S_IRWXO # define S_IRWXO 0 #endif @interface OFArc: OFObject { OFData *_quarantine; int8_t _overwrite; @public int8_t _outputLevel; int _exitStatus; } - (id )openArchiveWithIRI: (nullable OFIRI *)IRI type: (OFString *)type mode: (char)mode encoding: (OFStringEncoding)encoding; - (bool)shouldExtractFile: (OFString *)fileName outFileName: (OFString *)outFileName; - (ssize_t)copyBlockFromStream: (OFStream *)input toStream: (OFStream *)output fileName: (OFString *)fileName; - (nullable OFString *)safeLocalPathForPath: (OFString *)path; - (void)quarantineFile: (OFString *)path; @end OF_ASSUME_NONNULL_END objfw-1.1.6/utils/ofarc/OFArc.m000066400000000000000000000556371465614216400162210ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFApplication.h" #import "OFArray.h" #import "OFFile.h" #import "OFFileManager.h" #import "OFIRI.h" #import "OFIRIHandler.h" #import "OFLocale.h" #import "OFOptionsParser.h" #import "OFSandbox.h" #import "OFStdIOStream.h" #import "OFArc.h" #import "GZIPArchive.h" #import "LHAArchive.h" #import "TarArchive.h" #import "ZIPArchive.h" #import "ZooArchive.h" #import "OFCreateDirectoryFailedException.h" #import "OFGetItemAttributesFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFOpenItemFailedException.h" #import "OFReadFailedException.h" #import "OFSeekFailedException.h" #import "OFWriteFailedException.h" #define bufferSize 4096 OF_APPLICATION_DELEGATE(OFArc) static void help(OFStream *stream, bool full, int status) { [stream writeLine: OF_LOCALIZED(@"usage", @"Usage: %[prog] -[acCfhlnpqtvx] archive.zip [file1 file2 ...]", @"prog", [OFApplication programName])]; if (full) { [stream writeString: @"\n"]; [stream writeLine: OF_LOCALIZED(@"full_usage", @"Options:\n" @" -a --append Append to archive\n" @" --archive-comment= Archive comment to use when " @"creating or appending\n" @" -c --create Create archive\n" @" -C --directory= Extract into the specified " @"directory\n" @" -E --encoding= The encoding used by the " @"archive\n" @" (only tar, lha and zoo files)" @"\n" @" -f --force Force / overwrite files\n" @" -h --help Show this help\n" @" --iri Use an IRI to access the " @"archive\n" @" -l --list List all files in the archive" @"\n" @" -n --no-clobber Never overwrite files\n" @" -p --print Print one or more files from " @"the archive\n" @" -q --quiet Quiet mode (no output, " @"except errors)\n" @" -t --type= Archive type (gz, lha, tar, " @"tgz, zip, zoo)\n" @" -v --verbose Verbose output for file list" @"\n" @" -x --extract Extract files")]; } [OFApplication terminateWithStatus: status]; } static void mutuallyExclusiveError(OFUnichar shortOption1, OFString *longOption1, OFUnichar shortOption2, OFString *longOption2) { OFString *shortOption1Str = [OFString stringWithFormat: @"%C", shortOption1]; OFString *shortOption2Str = [OFString stringWithFormat: @"%C", shortOption2]; [OFStdErr writeLine: OF_LOCALIZED(@"2_options_mutually_exclusive", @"Error: -%[shortopt1] / --%[longopt1] and " @"-%[shortopt2] / --%[longopt2] " @"are mutually exclusive!", @"shortopt1", shortOption1Str, @"longopt1", longOption1, @"shortopt2", shortOption2Str, @"longopt2", longOption2)]; [OFApplication terminateWithStatus: 1]; } static OFIRI * argumentToIRI(OFString *argument, bool isIRI) { if (isIRI) return [OFIRI IRIWithString: argument]; if ([argument isEqual: @"-"]) return nil; return [OFIRI fileIRIWithPath: argument]; } static void mutuallyExclusiveError5(OFUnichar shortOption1, OFString *longOption1, OFUnichar shortOption2, OFString *longOption2, OFUnichar shortOption3, OFString *longOption3, OFUnichar shortOption4, OFString *longOption4, OFUnichar shortOption5, OFString *longOption5) { OFString *shortOption1Str = [OFString stringWithFormat: @"%C", shortOption1]; OFString *shortOption2Str = [OFString stringWithFormat: @"%C", shortOption2]; OFString *shortOption3Str = [OFString stringWithFormat: @"%C", shortOption3]; OFString *shortOption4Str = [OFString stringWithFormat: @"%C", shortOption4]; OFString *shortOption5Str = [OFString stringWithFormat: @"%C", shortOption5]; [OFStdErr writeLine: OF_LOCALIZED(@"5_options_mutually_exclusive", @"Error: -%[shortopt1] / --%[longopt1], " @"-%[shortopt2] / --%[longopt2], -%[shortopt3] / --%[longopt3], " @"-%[shortopt4] / --%[longopt4] and\n" @" -%[shortopt5] / --%[longopt5] are mutually exclusive!", @"shortopt1", shortOption1Str, @"longopt1", longOption1, @"shortopt2", shortOption2Str, @"longopt2", longOption2, @"shortopt3", shortOption3Str, @"longopt3", longOption3, @"shortopt4", shortOption4Str, @"longopt4", longOption4, @"shortopt5", shortOption5Str, @"longopt5", longOption5)]; [OFApplication terminateWithStatus: 1]; } static void writingNotSupported(OFString *type) { [OFStdErr writeLine: OF_LOCALIZED( @"writing_not_supported", @"Writing archives of type %[type] is not (yet) supported!", @"type", type)]; } static void addFiles(id archive, OFArray OF_GENERIC(OFString *) *files, OFString *archiveComment) { OFMutableArray *expandedFiles = [OFMutableArray arrayWithCapacity: files.count]; OFFileManager *fileManager = [OFFileManager defaultManager]; for (OFString *file in files) { OFFileAttributes attributes = [fileManager attributesOfItemAtPath: file]; if ([attributes.fileType isEqual: OFFileTypeDirectory]) [expandedFiles addObjectsFromArray: [fileManager subpathsOfDirectoryAtPath: file]]; else [expandedFiles addObject: file]; } if (expandedFiles.count < 1) { [OFStdErr writeLine: OF_LOCALIZED(@"add_no_file_specified", @"Need one or more files to add!")]; [OFApplication terminateWithStatus: 1]; } [archive addFiles: expandedFiles archiveComment: archiveComment]; } @implementation OFArc - (void)applicationDidFinishLaunching: (OFNotification *)notification { OFString *archiveComment, *outputDir, *encodingString, *type; bool isIRI; const OFOptionsParserOption options[] = { { 'a', @"append", 0, NULL, NULL }, { 0, @"archive-comment", 1, NULL, &archiveComment }, { 'c', @"create", 0, NULL, NULL }, { 'C', @"directory", 1, NULL, &outputDir }, { 'E', @"encoding", 1, NULL, &encodingString }, { 'f', @"force", 0, NULL, NULL }, { 'h', @"help", 0, NULL, NULL }, { 0, @"iri", 0, &isIRI, NULL }, { 'l', @"list", 0, NULL, NULL }, { 'n', @"no-clobber", 0, NULL, NULL }, { 'p', @"print", 0, NULL, NULL }, { 'q', @"quiet", 0, NULL, NULL }, { 't', @"type", 1, NULL, &type }, { 'v', @"verbose", 0, NULL, NULL }, { 'x', @"extract", 0, NULL, NULL }, { '\0', nil, 0, NULL, NULL } }; OFUnichar option, mode = '\0'; OFStringEncoding encoding = OFStringEncodingAutodetect; OFOptionsParser *optionsParser; OFArray OF_GENERIC(OFString *) *remainingArguments, *files; OFIRI *IRI; id archive; #ifdef OF_HAVE_SANDBOX OFSandbox *sandbox = [OFSandbox sandbox]; sandbox.allowsStdIO = true; sandbox.allowsReadingFiles = true; sandbox.allowsWritingFiles = true; sandbox.allowsCreatingFiles = true; sandbox.allowsChangingFileAttributes = true; sandbox.allowsUserDatabaseReading = true; /* Dropped after parsing options */ sandbox.allowsUnveil = true; [OFApplication of_activateSandbox: sandbox]; #endif #ifndef OF_AMIGAOS [OFLocale addLocalizationDirectoryIRI: [OFIRI fileIRIWithPath: @LOCALIZATION_DIR]]; #else [OFLocale addLocalizationDirectoryIRI: [OFIRI fileIRIWithPath: @"PROGDIR:/share/ofarc/localization"]]; #endif optionsParser = [OFOptionsParser parserWithOptions: options]; while ((option = [optionsParser nextOption]) != '\0') { switch (option) { case 'f': if (_overwrite < 0) mutuallyExclusiveError( 'f', @"force", 'n', @"no-clobber"); _overwrite = 1; break; case 'n': if (_overwrite > 0) mutuallyExclusiveError( 'f', @"force", 'n', @"no-clobber"); _overwrite = -1; break; case 'v': if (_outputLevel < 0) mutuallyExclusiveError( 'q', @"quiet", 'v', @"verbose"); _outputLevel++; break; case 'q': if (_outputLevel > 0) mutuallyExclusiveError( 'q', @"quiet", 'v', @"verbose"); _outputLevel--; break; case 'a': case 'c': case 'l': case 'p': case 'x': if (mode != '\0') mutuallyExclusiveError5( 'a', @"append", 'c', @"create", 'l', @"list", 'p', @"print", 'x', @"extract"); mode = option; break; case 'h': help(OFStdOut, true, 0); break; case '=': [OFStdErr writeLine: OF_LOCALIZED( @"option_takes_no_argument", @"%[prog]: Option --%[opt] takes no argument", @"prog", [OFApplication programName], @"opt", optionsParser.lastLongOption)]; [OFApplication terminateWithStatus: 1]; break; case ':': if (optionsParser.lastLongOption != nil) [OFStdErr writeLine: OF_LOCALIZED( @"long_option_requires_argument", @"%[prog]: Option --%[opt] requires an " @"argument", @"prog", [OFApplication programName], @"opt", optionsParser.lastLongOption)]; else { OFString *optStr = [OFString stringWithFormat: @"%C", optionsParser.lastOption]; [OFStdErr writeLine: OF_LOCALIZED( @"option_requires_argument", @"%[prog]: Option -%[opt] requires an " @"argument", @"prog", [OFApplication programName], @"opt", optStr)]; } [OFApplication terminateWithStatus: 1]; break; case '?': if (optionsParser.lastLongOption != nil) [OFStdErr writeLine: OF_LOCALIZED( @"unknown_long_option", @"%[prog]: Unknown option: --%[opt]", @"prog", [OFApplication programName], @"opt", optionsParser.lastLongOption)]; else { OFString *optStr = [OFString stringWithFormat: @"%C", optionsParser.lastOption]; [OFStdErr writeLine: OF_LOCALIZED( @"unknown_option", @"%[prog]: Unknown option: -%[opt]", @"prog", [OFApplication programName], @"opt", optStr)]; } [OFApplication terminateWithStatus: 1]; break; } } @try { if (encodingString != nil) encoding = OFStringEncodingParseName(encodingString); } @catch (OFInvalidArgumentException *e) { [OFStdErr writeLine: OF_LOCALIZED( @"invalid_encoding", @"%[prog]: Invalid encoding: %[encoding]", @"prog", [OFApplication programName], @"encoding", encodingString)]; [OFApplication terminateWithStatus: 1]; } remainingArguments = optionsParser.remainingArguments; switch (mode) { case 'a': case 'c': if (remainingArguments.count < 1) help(OFStdErr, false, 1); IRI = argumentToIRI(remainingArguments.firstObject, isIRI); files = [remainingArguments objectsInRange: OFMakeRange(1, remainingArguments.count - 1)]; #ifdef OF_HAVE_SANDBOX if ([IRI.scheme isEqual: @"file"]) [sandbox unveilPath: IRI.fileSystemRepresentation permissions: (mode == 'a' ? @"rwc" : @"wc")]; for (OFString *path in files) [sandbox unveilPath: path permissions: @"r"]; sandbox.allowsUnveil = false; [OFApplication of_activateSandbox: sandbox]; #endif archive = [self openArchiveWithIRI: IRI type: type mode: mode encoding: encoding]; addFiles(archive, files, archiveComment); break; case 'l': if (remainingArguments.count != 1) help(OFStdErr, false, 1); IRI = argumentToIRI(remainingArguments.firstObject, isIRI); #ifdef OF_HAVE_SANDBOX if ([IRI.scheme isEqual: @"file"]) [sandbox unveilPath: IRI.fileSystemRepresentation permissions: @"r"]; sandbox.allowsUnveil = false; [OFApplication of_activateSandbox: sandbox]; #endif archive = [self openArchiveWithIRI: IRI type: type mode: mode encoding: encoding]; [archive listFiles]; break; case 'p': if (remainingArguments.count < 1) help(OFStdErr, false, 1); IRI = argumentToIRI(remainingArguments.firstObject, isIRI); files = [remainingArguments objectsInRange: OFMakeRange(1, remainingArguments.count - 1)]; #ifdef OF_HAVE_SANDBOX if ([IRI.scheme isEqual: @"file"]) [sandbox unveilPath: IRI.fileSystemRepresentation permissions: @"r"]; sandbox.allowsUnveil = false; [OFApplication of_activateSandbox: sandbox]; #endif archive = [self openArchiveWithIRI: IRI type: type mode: mode encoding: encoding]; [archive printFiles: files]; break; case 'x': if (remainingArguments.count < 1) help(OFStdErr, false, 1); IRI = argumentToIRI(remainingArguments.firstObject, isIRI); files = [remainingArguments objectsInRange: OFMakeRange(1, remainingArguments.count - 1)]; #ifdef OF_HAVE_SANDBOX if ([IRI.scheme isEqual: @"file"]) [sandbox unveilPath: IRI.fileSystemRepresentation permissions: @"r"]; if (files.count > 0) for (OFString *path in files) [sandbox unveilPath: path permissions: @"wc"]; else { OFString *path = outputDir; if (path == nil) path = [[OFFileManager defaultManager] currentDirectoryPath]; /* We need 'r' to change the directory to it. */ [sandbox unveilPath: path permissions: @"rwc"]; } sandbox.allowsUnveil = false; [OFApplication of_activateSandbox: sandbox]; #endif archive = [self openArchiveWithIRI: IRI type: type mode: mode encoding: encoding]; #ifdef OF_MACOS if ([IRI.scheme isEqual: @"file"]) { @try { OFString *attributeName = @"com.apple.quarantine"; _quarantine = [[[OFFileManager defaultManager] extendedAttributeDataForName: attributeName ofItemAtIRI: IRI] retain]; } @catch (OFGetItemAttributesFailedException *e) { if (e.errNo != /*ENOATTR*/ 93) @throw e; } } #endif if (outputDir != nil) { OFFileManager *fileManager = [OFFileManager defaultManager]; if (![fileManager directoryExistsAtPath: outputDir]) [fileManager createDirectoryAtPath: outputDir createParents: true]; [fileManager changeCurrentDirectoryPath: outputDir]; } @try { [archive extractFiles: files]; } @catch (OFCreateDirectoryFailedException *e) { [OFStdErr writeString: @"\r"]; [OFStdErr writeLine: OF_LOCALIZED( @"failed_to_create_directory", @"Failed to create directory %[dir]: %[error]", @"dir", e.IRI.fileSystemRepresentation, @"error", OFStrError(e.errNo))]; _exitStatus = 1; } @catch (OFOpenItemFailedException *e) { [OFStdErr writeString: @"\r"]; [OFStdErr writeLine: OF_LOCALIZED( @"failed_to_open_file", @"Failed to open file %[file]: %[error]", @"file", e.path, @"error", OFStrError(e.errNo))]; _exitStatus = 1; } break; default: help(OFStdErr, true, 1); break; } [OFApplication terminateWithStatus: _exitStatus]; } - (id )openArchiveWithIRI: (OFIRI *)IRI type: (OFString *)type mode: (char)mode encoding: (OFStringEncoding)encoding { /* To make clang-analyzer happy about assigning nil to path later. */ OFString *modeString, *fileModeString; OFStream *file = nil; id archive = nil; switch (mode) { case 'a': modeString = @"a"; fileModeString = @"r+"; break; case 'c': modeString = @"w"; fileModeString = @"w+"; break; case 'l': case 'p': case 'x': modeString = fileModeString = @"r"; break; default: @throw [OFInvalidArgumentException exception]; } if (IRI == nil) { switch (mode) { case 'a': case 'c': file = OFStdOut; break; case 'l': case 'p': case 'x': file = OFStdIn; break; default: @throw [OFInvalidArgumentException exception]; } } else { @try { file = [OFIRIHandler openItemAtIRI: IRI mode: fileModeString]; } @catch (OFOpenItemFailedException *e) { [OFStdErr writeString: @"\r"]; [OFStdErr writeLine: OF_LOCALIZED( @"failed_to_open_file", @"Failed to open file %[file]: %[error]", @"file", e.IRI.string, @"error", OFStrError(e.errNo))]; [OFApplication terminateWithStatus: 1]; } } if (type == nil || [type isEqual: @"auto"]) { OFString *lowercasePath = IRI.path.lowercaseString; /* This one has to be first for obvious reasons */ if ([lowercasePath hasSuffix: @".tar.gz"] || [lowercasePath hasSuffix: @".tgz"]) type = @"tgz"; else if ([lowercasePath hasSuffix: @".gz"]) type = @"gz"; else if ([lowercasePath hasSuffix: @".lha"] || [lowercasePath hasSuffix: @".lzh"] || [lowercasePath hasSuffix: @".lzs"] || [lowercasePath hasSuffix: @".pma"]) type = @"lha"; else if ([lowercasePath hasSuffix: @".tar"]) type = @"tar"; else if ([lowercasePath hasSuffix: @".zoo"]) type = @"zoo"; else type = @"zip"; } @try { if ([type isEqual: @"gz"]) archive = [GZIPArchive archiveWithIRI: IRI stream: file mode: modeString encoding: encoding]; else if ([type isEqual: @"lha"]) archive = [LHAArchive archiveWithIRI: IRI stream: file mode: modeString encoding: encoding]; else if ([type isEqual: @"tar"]) archive = [TarArchive archiveWithIRI: IRI stream: file mode: modeString encoding: encoding]; else if ([type isEqual: @"tgz"]) { OFStream *GZIPStream = [OFGZIPStream streamWithStream: file mode: modeString]; archive = [TarArchive archiveWithIRI: IRI stream: GZIPStream mode: modeString encoding: encoding]; } else if ([type isEqual: @"zip"]) archive = [ZIPArchive archiveWithIRI: IRI stream: file mode: modeString encoding: encoding]; else if ([type isEqual: @"zoo"]) archive = [ZooArchive archiveWithIRI: IRI stream: file mode: modeString encoding: encoding]; else { [OFStdErr writeLine: OF_LOCALIZED( @"unknown_archive_type", @"Unknown archive type: %[type]", @"type", type)]; goto error; } } @catch (OFNotImplementedException *e) { if ((mode == 'a' || mode == 'c') && sel_isEqual(e.selector, @selector(initWithStream:mode:))) { writingNotSupported(type); goto error; } @throw e; } @catch (OFReadFailedException *e) { [OFStdErr writeLine: OF_LOCALIZED(@"failed_to_read_file", @"Failed to read file %[file]: %[error]", @"file", IRI.string, @"error", OFStrError(e.errNo))]; goto error; } @catch (OFSeekFailedException *e) { [OFStdErr writeLine: OF_LOCALIZED(@"failed_to_seek_in_file", @"Failed to seek in file %[file]: %[error]", @"file", IRI.string, @"error", OFStrError(e.errNo))]; goto error; } @catch (OFInvalidFormatException *e) { [OFStdErr writeLine: OF_LOCALIZED( @"file_is_not_a_valid_archive", @"File %[file] is not a valid archive!", @"file", IRI.string)]; goto error; } if ((mode == 'a' || mode == 'c') && ![archive respondsToSelector: @selector(addFiles:archiveComment:)]) { writingNotSupported(type); goto error; } return archive; error: if (mode == 'c' && IRI != nil) [[OFFileManager defaultManager] removeItemAtIRI: IRI]; [OFApplication terminateWithStatus: 1]; abort(); } - (bool)shouldExtractFile: (OFString *)fileName outFileName: (OFString *)outFileName { OFString *line; if (_overwrite == 1 || ![[OFFileManager defaultManager] fileExistsAtPath: outFileName]) return true; if (_overwrite == -1) { if (_outputLevel >= 0) { [OFStdOut writeString: @" "]; [OFStdOut writeLine: OF_LOCALIZED(@"file_skipped", @"skipped")]; } return false; } do { [OFStdErr writeString: @"\r"]; [OFStdErr writeString: OF_LOCALIZED(@"ask_overwrite", @"Overwrite %[file]? [ynAN?]", @"file", fileName)]; [OFStdErr writeString: @" "]; line = [OFStdIn readLine]; if ([line isEqual: @"?"]) [OFStdErr writeLine: OF_LOCALIZED( @"ask_overwrite_help", @" y: yes\n" @" n: no\n" @" A: always\n" @" N: never")]; } while (![line isEqual: @"y"] && ![line isEqual: @"n"] && ![line isEqual: @"N"] && ![line isEqual: @"A"]); if ([line isEqual: @"A"]) _overwrite = 1; else if ([line isEqual: @"N"]) _overwrite = -1; if ([line isEqual: @"n"] || [line isEqual: @"N"]) { if (_outputLevel >= 0) [OFStdOut writeLine: OF_LOCALIZED(@"skipping_file", @"Skipping %[file]...", @"file", fileName)]; return false; } if (_outputLevel >= 0) [OFStdOut writeString: OF_LOCALIZED(@"extracting_file", @"Extracting %[file]...", @"file", fileName)]; return true; } - (ssize_t)copyBlockFromStream: (OFStream *)input toStream: (OFStream *)output fileName: (OFString *)fileName { char buffer[bufferSize]; size_t length; @try { length = [input readIntoBuffer: buffer length: bufferSize]; } @catch (OFReadFailedException *e) { [OFStdOut writeString: @"\r"]; [OFStdErr writeLine: OF_LOCALIZED(@"failed_to_read_file", @"Failed to read file %[file]: %[error]", @"file", fileName, @"error", OFStrError(e.errNo))]; return -1; } @try { [output writeBuffer: buffer length: length]; } @catch (OFWriteFailedException *e) { [OFStdOut writeString: @"\r"]; [OFStdErr writeLine: OF_LOCALIZED(@"failed_to_write_file", @"Failed to write file %[file]: %[error]", @"file", fileName, @"error", OFStrError(e.errNo))]; return -1; } return length; } - (OFString *)safeLocalPathForPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); path = path.stringByStandardizingPath; #if defined(OF_WINDOWS) || defined(OF_MSDOS) if ([path containsString: @":"] || [path hasPrefix: @"\\"]) { #elif defined(OF_AMIGAOS) if ([path containsString: @":"] || [path hasPrefix: @"/"]) { #else if ([path hasPrefix: @"/"]) { #endif objc_autoreleasePoolPop(pool); return nil; } if (path.length == 0) { objc_autoreleasePoolPop(pool); return nil; } /* * After -[stringByStandardizingPath], everything representing parent * directory should be at the beginning, so in theory checking the * first component should be enough. But it does not hurt being * paranoid and checking all components, just in case. */ for (OFString *component in path.pathComponents) { #ifdef OF_AMIGAOS if (component.length == 0 || [component isEqual: @"/"]) { #else if (component.length == 0 || [component isEqual: @".."]) { #endif objc_autoreleasePoolPop(pool); return nil; } } [path retain]; objc_autoreleasePoolPop(pool); return [path autorelease]; } - (void)quarantineFile: (OFString *)path { #ifdef OF_MACOS if (_quarantine != nil) [[OFFileManager defaultManager] setExtendedAttributeData: _quarantine forName: @"com.apple.quarantine" ofItemAtPath: path]; #endif } @end objfw-1.1.6/utils/ofarc/TarArchive.h000066400000000000000000000015271465614216400172770ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFTarArchive.h" #import "Archive.h" @interface TarArchive: OFObject { OFTarArchive *_archive; } @end objfw-1.1.6/utils/ofarc/TarArchive.m000066400000000000000000000376061465614216400173130ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFApplication.h" #import "OFArray.h" #import "OFDate.h" #import "OFFile.h" #import "OFFileManager.h" #import "OFLocale.h" #import "OFNumber.h" #import "OFPair.h" #import "OFSet.h" #import "OFStdIOStream.h" #import "OFString.h" #import "TarArchive.h" #import "OFArc.h" #import "OFSetItemAttributesFailedException.h" static OFArc *app; static void setPermissions(OFString *path, OFTarArchiveEntry *entry) { #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS OFNumber *POSIXPermissions = [OFNumber numberWithUnsignedLongLong: entry.POSIXPermissions.longLongValue & 0777]; OFFileAttributes attributes = [OFDictionary dictionaryWithObject: POSIXPermissions forKey: OFFilePOSIXPermissions]; [[OFFileManager defaultManager] setAttributes: attributes ofItemAtPath: path]; #endif [app quarantineFile: path]; } static void setModificationDate(OFString *path, OFTarArchiveEntry *entry) { OFDate *modificationDate = entry.modificationDate; OFFileAttributes attributes; if (modificationDate == nil) return; attributes = [OFDictionary dictionaryWithObject: modificationDate forKey: OFFileModificationDate]; @try { [[OFFileManager defaultManager] setAttributes: attributes ofItemAtPath: path]; } @catch (OFSetItemAttributesFailedException *e) { if (e.errNo != EISDIR) @throw e; } } @implementation TarArchive + (void)initialize { if (self == [TarArchive class]) app = (OFArc *)[OFApplication sharedApplication].delegate; } + (instancetype)archiveWithIRI: (OFIRI *)IRI stream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithIRI: IRI stream: stream mode: mode encoding: encoding] autorelease]; } - (instancetype)initWithIRI: (OFIRI *)IRI stream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (OFStringEncoding)encoding { self = [super init]; @try { _archive = [[OFTarArchive alloc] initWithStream: stream mode: mode]; if (encoding != OFStringEncodingAutodetect) _archive.encoding = encoding; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_archive release]; [super dealloc]; } - (void)listFiles { OFTarArchiveEntry *entry; while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); [OFStdOut writeLine: entry.fileName]; if (app->_outputLevel >= 1) { OFString *date = [entry.modificationDate localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; OFString *size = [OFString stringWithFormat: @"%llu", entry.uncompressedSize]; OFString *permissionsString = [OFString stringWithFormat: @"%llo", entry.POSIXPermissions .unsignedLongLongValue]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED(@"list_size", @"[" @" 'Size: '," @" [" @" {'size == 1': '1 byte'}," @" {'': '%[size] bytes'}" @" ]" @"]".objectByParsingJSON, @"size", size)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED(@"list_posix_permissions", @"POSIX permissions: %[perm]", @"perm", permissionsString)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_owner_account_id", @"Owner account ID: %[id]", @"id", entry.ownerAccountID)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_group_owner_account_id", @"Group owner account ID: %[id]", @"id", entry.groupOwnerAccountID)]; if (entry.ownerAccountName != nil) { [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_owner_account_name", @"Owner account name: %[name]", @"name", entry.ownerAccountName)]; } if (entry.groupOwnerAccountName != nil) { [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_group_owner_account_name", @"Group owner account name: %[name]", @"name", entry.groupOwnerAccountName)]; } [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_modification_date", @"Modification date: %[date]", @"date", date)]; } if (app->_outputLevel >= 2) { [OFStdOut writeString: @"\t"]; switch (entry.type) { case OFTarArchiveEntryTypeFile: [OFStdOut writeLine: OF_LOCALIZED( @"list_type_normal", @"Type: Normal file")]; break; case OFTarArchiveEntryTypeLink: [OFStdOut writeLine: OF_LOCALIZED( @"list_type_hardlink", @"Type: Hard link")]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_link_target", @"Target file name: %[target]", @"target", entry.targetFileName)]; break; case OFTarArchiveEntryTypeSymlink: [OFStdOut writeLine: OF_LOCALIZED( @"list_type_symlink", @"Type: Symbolic link")]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_link_target", @"Target file name: %[target]", @"target", entry.targetFileName)]; break; case OFTarArchiveEntryTypeCharacterDevice: { OFString *majorString = [OFString stringWithFormat: @"%d", entry.deviceMajor]; OFString *minorString = [OFString stringWithFormat: @"%d", entry.deviceMinor]; [OFStdOut writeLine: OF_LOCALIZED( @"list_type_character_device", @"Type: Character device")]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_device_major", @"Device major: %[major]", @"major", majorString)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_device_minor", @"Device minor: %[minor]", @"minor", minorString)]; break; } case OFTarArchiveEntryTypeBlockDevice: { OFString *majorString = [OFString stringWithFormat: @"%d", entry.deviceMajor]; OFString *minorString = [OFString stringWithFormat: @"%d", entry.deviceMinor]; [OFStdOut writeLine: OF_LOCALIZED( @"list_type_block_device", @"Type: Block device")]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_device_major", @"Device major: %[major]", @"major", majorString)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_device_minor", @"Device minor: %[minor]", @"minor", minorString)]; break; } case OFTarArchiveEntryTypeDirectory: [OFStdOut writeLine: OF_LOCALIZED( @"list_type_directory", @"Type: Directory")]; break; case OFTarArchiveEntryTypeFIFO: [OFStdOut writeLine: OF_LOCALIZED( @"list_type_fifo", @"Type: FIFO")]; break; case OFTarArchiveEntryTypeContiguousFile: [OFStdOut writeLine: OF_LOCALIZED( @"list_type_contiguous_file", @"Type: Contiguous file")]; break; default: [OFStdOut writeLine: OF_LOCALIZED( @"list_type_unknown", @"Type: Unknown")]; break; } } objc_autoreleasePoolPop(pool); } } - (void)extractFiles: (OFArray OF_GENERIC(OFString *) *)files { OFFileManager *fileManager = [OFFileManager defaultManager]; bool all = (files.count == 0); OFMutableArray *delayedModificationDates = [OFMutableArray array]; OFMutableSet OF_GENERIC(OFString *) *missing = [OFMutableSet setWithArray: files]; OFTarArchiveEntry *entry; while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); OFString *fileName = entry.fileName; OFTarArchiveEntryType type = entry.type; OFString *outFileName, *directory; OFFile *output; OFStream *stream; unsigned long long written = 0, size = entry.uncompressedSize; int8_t percent = -1, newPercent; if (!all && ![files containsObject: fileName]) continue; if (type != OFTarArchiveEntryTypeFile && type != OFTarArchiveEntryTypeDirectory) { if (app->_outputLevel >= 0) [OFStdOut writeLine: OF_LOCALIZED( @"skipping_file", @"Skipping %[file]...", @"file", fileName)]; continue; } [missing removeObject: fileName]; outFileName = [app safeLocalPathForPath: fileName]; if (outFileName == nil) { [OFStdErr writeLine: OF_LOCALIZED( @"refusing_to_extract_file", @"Refusing to extract %[file]!", @"file", fileName)]; app->_exitStatus = 1; goto outer_loop_end; } if (app->_outputLevel >= 0) [OFStdOut writeString: OF_LOCALIZED(@"extracting_file", @"Extracting %[file]...", @"file", fileName)]; if (type == OFTarArchiveEntryTypeDirectory || (type == OFTarArchiveEntryTypeFile && [fileName hasSuffix: @"/"])) { [fileManager createDirectoryAtPath: outFileName createParents: true]; setPermissions(outFileName, entry); /* * As creating a new file in a directory changes its * modification date, we can only set it once all files * have been created. */ [delayedModificationDates addObject: [OFPair pairWithFirstObject: outFileName secondObject: entry]]; if (app->_outputLevel >= 0) { [OFStdOut writeString: @"\r"]; [OFStdOut writeLine: OF_LOCALIZED( @"extracting_file_done", @"Extracting %[file]... done", @"file", fileName)]; } goto outer_loop_end; } directory = outFileName.stringByDeletingLastPathComponent; if (![fileManager directoryExistsAtPath: directory]) [fileManager createDirectoryAtPath: directory createParents: true]; if (![app shouldExtractFile: fileName outFileName: outFileName]) goto outer_loop_end; stream = [_archive streamForReadingCurrentEntry]; output = [OFFile fileWithPath: outFileName mode: @"w"]; setPermissions(outFileName, entry); while (!stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: stream toStream: output fileName: fileName]; if (length < 0) { app->_exitStatus = 1; goto outer_loop_end; } written += length; newPercent = (written == size ? 100 : (int8_t)(written * 100 / size)); if (app->_outputLevel >= 0 && percent != newPercent) { OFString *percentString; percent = newPercent; percentString = [OFString stringWithFormat: @"%3u", percent]; [OFStdOut writeString: @"\r"]; [OFStdOut writeString: OF_LOCALIZED( @"extracting_file_percent", @"Extracting %[file]... %[percent]%", @"file", fileName, @"percent", percentString)]; } } [output close]; setModificationDate(outFileName, entry); if (app->_outputLevel >= 0) { [OFStdOut writeString: @"\r"]; [OFStdOut writeLine: OF_LOCALIZED( @"extracting_file_done", @"Extracting %[file]... done", @"file", fileName)]; } outer_loop_end: objc_autoreleasePoolPop(pool); } for (OFPair *pair in delayedModificationDates) setModificationDate(pair.firstObject, pair.secondObject); if (missing.count > 0) { for (OFString *file in missing) [OFStdErr writeLine: OF_LOCALIZED( @"file_not_in_archive", @"File %[file] is not in the archive!", @"file", file)]; app->_exitStatus = 1; } } - (void)printFiles: (OFArray OF_GENERIC(OFString *) *)files_ { OFMutableSet *files; OFTarArchiveEntry *entry; if (files_.count < 1) { [OFStdErr writeLine: OF_LOCALIZED(@"print_no_file_specified", @"Need one or more files to print!")]; app->_exitStatus = 1; return; } files = [OFMutableSet setWithArray: files_]; while ((entry = [_archive nextEntry]) != nil) { OFString *fileName = entry.fileName; OFStream *stream; if (![files containsObject: fileName]) continue; stream = [_archive streamForReadingCurrentEntry]; while (!stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: stream toStream: OFStdOut fileName: fileName]; if (length < 0) { app->_exitStatus = 1; return; } } [files removeObject: fileName]; [stream close]; if (files.count == 0) break; } for (OFString *file in files) { [OFStdErr writeLine: OF_LOCALIZED(@"file_not_in_archive", @"File %[file] is not in the archive!", @"file", file)]; app->_exitStatus = 1; } } - (void)addFiles: (OFArray OF_GENERIC(OFString *) *)files archiveComment: (OFString *)archiveComment { OFFileManager *fileManager = [OFFileManager defaultManager]; for (OFString *fileName in files) { void *pool = objc_autoreleasePoolPush(); OFFileAttributes attributes; OFFileAttributeType type; OFMutableTarArchiveEntry *entry; OFStream *output; if (app->_outputLevel >= 0) [OFStdOut writeString: OF_LOCALIZED(@"adding_file", @"Adding %[file]...", @"file", fileName)]; attributes = [fileManager attributesOfItemAtPath: fileName]; type = attributes.fileType; entry = [OFMutableTarArchiveEntry entryWithFileName: fileName]; #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS entry.POSIXPermissions = [attributes objectForKey: OFFilePOSIXPermissions]; #endif entry.uncompressedSize = attributes.fileSize; entry.modificationDate = attributes.fileModificationDate; #ifdef OF_FILE_MANAGER_SUPPORTS_OWNER entry.ownerAccountID = [attributes objectForKey: OFFileOwnerAccountID]; entry.groupOwnerAccountID = [attributes objectForKey: OFFileGroupOwnerAccountID]; entry.ownerAccountName = attributes.fileOwnerAccountName; entry.groupOwnerAccountName = attributes.fileGroupOwnerAccountName; #endif if ([type isEqual: OFFileTypeRegular]) entry.type = OFTarArchiveEntryTypeFile; else if ([type isEqual: OFFileTypeDirectory]) { entry.type = OFTarArchiveEntryTypeDirectory; entry.uncompressedSize = 0; } else if ([type isEqual: OFFileTypeSymbolicLink]) { entry.type = OFTarArchiveEntryTypeSymlink; entry.targetFileName = attributes.fileSymbolicLinkDestination; entry.uncompressedSize = 0; } [entry makeImmutable]; output = [_archive streamForWritingEntry: entry]; if (entry.type == OFTarArchiveEntryTypeFile) { unsigned long long written = 0; unsigned long long size = entry.uncompressedSize; int8_t percent = -1, newPercent; OFFile *input = [OFFile fileWithPath: fileName mode: @"r"]; while (!input.atEndOfStream) { ssize_t length = [app copyBlockFromStream: input toStream: output fileName: fileName]; if (length < 0) { app->_exitStatus = 1; goto outer_loop_end; } written += length; newPercent = (written == size ? 100 : (int8_t)(written * 100 / size)); if (app->_outputLevel >= 0 && percent != newPercent) { OFString *percentString; percent = newPercent; percentString = [OFString stringWithFormat: @"%3u", percent]; [OFStdOut writeString: @"\r"]; [OFStdOut writeString: OF_LOCALIZED( @"adding_file_percent", @"Adding %[file]... %[percent]%", @"file", fileName, @"percent", percentString)]; } } } if (app->_outputLevel >= 0) { [OFStdOut writeString: @"\r"]; [OFStdOut writeLine: OF_LOCALIZED( @"adding_file_done", @"Adding %[file]... done", @"file", fileName)]; } [output close]; outer_loop_end: objc_autoreleasePoolPop(pool); } [_archive close]; } @end objfw-1.1.6/utils/ofarc/ZIPArchive.h000066400000000000000000000016021465614216400172050ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFZIPArchive.h" #import "Archive.h" @interface ZIPArchive: OFObject { OFIRI *_archiveIRI; OFZIPArchive *_archive; } @end objfw-1.1.6/utils/ofarc/ZIPArchive.m000066400000000000000000000356071465614216400172260ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFApplication.h" #import "OFArray.h" #import "OFData.h" #import "OFDate.h" #import "OFFile.h" #import "OFFileManager.h" #import "OFIRI.h" #import "OFIRIHandler.h" #import "OFLocale.h" #import "OFNumber.h" #import "OFPair.h" #import "OFSet.h" #import "OFStdIOStream.h" #import "OFString.h" #import "ZIPArchive.h" #import "OFArc.h" #import "OFInvalidFormatException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfRangeException.h" #import "OFSetItemAttributesFailedException.h" static OFArc *app; static void setPermissions(OFString *path, OFZIPArchiveEntry *entry) { #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS if ((entry.versionMadeBy >> 8) == OFZIPArchiveEntryAttributeCompatibilityUNIX) { OFNumber *mode = [OFNumber numberWithUnsignedShort: (entry.versionSpecificAttributes >> 16) & 0777]; OFFileAttributes attributes = [OFDictionary dictionaryWithObject: mode forKey: OFFilePOSIXPermissions]; [[OFFileManager defaultManager] setAttributes: attributes ofItemAtPath: path]; } #endif [app quarantineFile: path]; } static void setModificationDate(OFString *path, OFZIPArchiveEntry *entry) { OFDate *modificationDate = entry.modificationDate; OFFileAttributes attributes; if (modificationDate == nil) return; attributes = [OFDictionary dictionaryWithObject: modificationDate forKey: OFFileModificationDate]; @try { [[OFFileManager defaultManager] setAttributes: attributes ofItemAtPath: path]; } @catch (OFSetItemAttributesFailedException *e) { if (e.errNo != EISDIR) @throw e; } } @implementation ZIPArchive + (void)initialize { if (self == [ZIPArchive class]) app = (OFArc *)[OFApplication sharedApplication].delegate; } + (instancetype)archiveWithIRI: (OFIRI *)IRI stream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithIRI: IRI stream: stream mode: mode encoding: encoding] autorelease]; } - (instancetype)initWithIRI: (OFIRI *)IRI stream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (OFStringEncoding)encoding { self = [super init]; @try { _archiveIRI = [IRI copy]; _archive = [[OFZIPArchive alloc] initWithStream: stream mode: mode]; _archive.delegate = self; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_archiveIRI release]; [_archive release]; [super dealloc]; } - (OFSeekableStream *)archive: (OFZIPArchive *)archive wantsPartNumbered: (unsigned int)partNumber lastPartNumber: (unsigned int)lastPartNumber { OFIRI *IRI; if ([_archiveIRI.pathExtension caseInsensitiveCompare: @"zip"] != OFOrderedSame) return nil; if (partNumber > 98) return nil; if (partNumber == lastPartNumber) IRI = _archiveIRI; else { OFMutableIRI *copy = [[_archiveIRI mutableCopy] autorelease]; [copy deletePathExtension]; [copy appendPathExtension: [OFString stringWithFormat: @"z%02u", partNumber + 1]]; [copy makeImmutable]; IRI = copy; } return (OFSeekableStream *)[OFIRIHandler openItemAtIRI: IRI mode: @"r"]; } - (void)listFiles { if (app->_outputLevel >= 1 && _archive.archiveComment != nil) { [OFStdOut writeLine: OF_LOCALIZED( @"list_archive_comment", @"Archive comment:")]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: [_archive.archiveComment stringByReplacingOccurrencesOfString: @"\n" withString: @"\n\t"]]; [OFStdOut writeLine: @""]; } for (OFZIPArchiveEntry *entry in _archive.entries) { void *pool = objc_autoreleasePoolPush(); [OFStdOut writeLine: entry.fileName]; if (app->_outputLevel >= 1) { OFString *compressedSize = [OFString stringWithFormat: @"%" PRIu64, entry.compressedSize]; OFString *uncompressedSize = [OFString stringWithFormat: @"%" PRIu64, entry.uncompressedSize]; OFString *compressionMethod = OFZIPArchiveEntryCompressionMethodName( entry.compressionMethod); OFString *CRC32 = [OFString stringWithFormat: @"%08" PRIX32, entry.CRC32]; OFString *modificationDate = [entry.modificationDate localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_compressed_size", @"[" @" 'Compressed: '," @" [" @" {'size == 1': '1 byte'}," @" {'': '%[size] bytes'}" @" ]" @"]".objectByParsingJSON, @"size", compressedSize)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_uncompressed_size", @"[" @" 'Uncompressed: '," @" [" @" {'size == 1': '1 byte'}," @" {'': '%[size] bytes'}" @" ]" @"]".objectByParsingJSON, @"size", uncompressedSize)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_compression_method", @"Compression method: %[method]", @"method", compressionMethod)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED(@"list_crc32", @"CRC32: %[crc32]", @"crc32", CRC32)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_modification_date", @"Modification date: %[date]", @"date", modificationDate)]; if (app->_outputLevel >= 2) { uint16_t versionMadeBy = entry.versionMadeBy; OFZIPArchiveEntryAttributeCompatibility UNIX = OFZIPArchiveEntryAttributeCompatibilityUNIX; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_version_made_by", @"Version made by: %[version]", @"version", OFZIPArchiveEntryVersionToString( versionMadeBy))]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_min_version_needed", @"Minimum version needed: %[version]", @"version", OFZIPArchiveEntryVersionToString( entry.minVersionNeeded))]; if ((versionMadeBy >> 8) == UNIX) { uint32_t mode = entry .versionSpecificAttributes >> 16; OFString *modeString = [OFString stringWithFormat: @"%06o", mode]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_mode", @"Mode: %[mode]", @"mode", modeString)]; } } if (app->_outputLevel >= 3) { OFString *GPBF = [OFString stringWithFormat: @"%04" PRIx16, entry.generalPurposeBitFlag]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_general_purpose_bit_flag", @"General purpose bit flag: %[gpbf]", @"gpbf", GPBF)]; if (entry.extraField != nil) { [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_extra_field", @"Extra field: %[extra]", @"extra", entry.extraField.description)]; } } if (entry.fileComment.length > 0) { [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_comment", @"Comment: %[comment]", @"comment", entry.fileComment)]; } } objc_autoreleasePoolPop(pool); } } - (void)extractFiles: (OFArray OF_GENERIC(OFString *) *)files { OFFileManager *fileManager = [OFFileManager defaultManager]; bool all = (files.count == 0); OFMutableArray *delayedModificationDates = [OFMutableArray array]; OFMutableSet OF_GENERIC(OFString *) *missing = [OFMutableSet setWithArray: files]; for (OFZIPArchiveEntry *entry in _archive.entries) { void *pool = objc_autoreleasePoolPush(); OFString *fileName = entry.fileName; OFString *outFileName, *directory; OFStream *stream; OFFile *output; unsigned long long written = 0, size = entry.uncompressedSize; int8_t percent = -1, newPercent; if (!all && ![files containsObject: fileName]) continue; [missing removeObject: fileName]; outFileName = [app safeLocalPathForPath: fileName]; if (outFileName == nil) { [OFStdErr writeLine: OF_LOCALIZED( @"refusing_to_extract_file", @"Refusing to extract %[file]!", @"file", fileName)]; app->_exitStatus = 1; goto outer_loop_end; } if (app->_outputLevel >= 0) [OFStdOut writeString: OF_LOCALIZED(@"extracting_file", @"Extracting %[file]...", @"file", fileName)]; if ([fileName hasSuffix: @"/"]) { [fileManager createDirectoryAtPath: outFileName createParents: true]; setPermissions(outFileName, entry); /* * As creating a new file in a directory changes its * modification date, we can only set it once all files * have been created. */ [delayedModificationDates addObject: [OFPair pairWithFirstObject: outFileName secondObject: entry]]; if (app->_outputLevel >= 0) { [OFStdOut writeString: @"\r"]; [OFStdOut writeLine: OF_LOCALIZED( @"extracting_file_done", @"Extracting %[file]... done", @"file", fileName)]; } goto outer_loop_end; } directory = outFileName.stringByDeletingLastPathComponent; if (![fileManager directoryExistsAtPath: directory]) [fileManager createDirectoryAtPath: directory createParents: true]; if (![app shouldExtractFile: fileName outFileName: outFileName]) goto outer_loop_end; stream = [_archive streamForReadingFile: fileName]; output = [OFFile fileWithPath: outFileName mode: @"w"]; setPermissions(outFileName, entry); while (!stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: stream toStream: output fileName: fileName]; if (length < 0) { app->_exitStatus = 1; goto outer_loop_end; } written += length; newPercent = (written == size ? 100 : (int8_t)(written * 100 / size)); if (app->_outputLevel >= 0 && percent != newPercent) { OFString *percentString; percent = newPercent; percentString = [OFString stringWithFormat: @"%3u", percent]; [OFStdOut writeString: @"\r"]; [OFStdOut writeString: OF_LOCALIZED( @"extracting_file_percent", @"Extracting %[file]... %[percent]%", @"file", fileName, @"percent", percentString)]; } } [output close]; setModificationDate(outFileName, entry); if (app->_outputLevel >= 0) { [OFStdOut writeString: @"\r"]; [OFStdOut writeLine: OF_LOCALIZED( @"extracting_file_done", @"Extracting %[file]... done", @"file", fileName)]; } outer_loop_end: objc_autoreleasePoolPop(pool); } for (OFPair *pair in delayedModificationDates) setModificationDate(pair.firstObject, pair.secondObject); if (missing.count > 0) { for (OFString *file in missing) [OFStdErr writeLine: OF_LOCALIZED( @"file_not_in_archive", @"File %[file] is not in the archive!", @"file", file)]; app->_exitStatus = 1; } } - (void)printFiles: (OFArray OF_GENERIC(OFString *) *)files { OFStream *stream; if (files.count < 1) { [OFStdErr writeLine: OF_LOCALIZED(@"print_no_file_specified", @"Need one or more files to print!")]; app->_exitStatus = 1; return; } for (OFString *path in files) { @try { stream = [_archive streamForReadingFile: path]; } @catch (OFOpenItemFailedException *e) { if (e.errNo == ENOENT) { [OFStdErr writeLine: OF_LOCALIZED( @"file_not_in_archive", @"File %[file] is not in the archive!", @"file", e.path)]; app->_exitStatus = 1; continue; } @throw e; } while (!stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: stream toStream: OFStdOut fileName: path]; if (length < 0) { app->_exitStatus = 1; return; } } [stream close]; } } - (void)addFiles: (OFArray OF_GENERIC(OFString *) *)files archiveComment: (OFString *)archiveComment { OFFileManager *fileManager = [OFFileManager defaultManager]; _archive.archiveComment = archiveComment; for (OFString *localFileName in files) { void *pool = objc_autoreleasePoolPush(); OFArray OF_GENERIC (OFString *) *components; OFString *fileName; OFFileAttributes attributes; bool isDirectory = false; OFMutableZIPArchiveEntry *entry; unsigned long long size; OFStream *output; components = localFileName.pathComponents; fileName = [components componentsJoinedByString: @"/"]; attributes = [fileManager attributesOfItemAtPath: localFileName]; if ([attributes.fileType isEqual: OFFileTypeDirectory]) { isDirectory = true; fileName = [fileName stringByAppendingString: @"/"]; } if (app->_outputLevel >= 0) [OFStdOut writeString: OF_LOCALIZED(@"adding_file", @"Adding %[file]...", @"file", fileName)]; entry = [OFMutableZIPArchiveEntry entryWithFileName: fileName]; size = (isDirectory ? 0 : attributes.fileSize); entry.compressedSize = size; entry.uncompressedSize = size; entry.compressionMethod = OFZIPArchiveEntryCompressionMethodNone; entry.modificationDate = attributes.fileModificationDate; [entry makeImmutable]; output = [_archive streamForWritingEntry: entry]; if (!isDirectory) { unsigned long long written = 0; int8_t percent = -1, newPercent; OFFile *input = [OFFile fileWithPath: fileName mode: @"r"]; while (!input.atEndOfStream) { ssize_t length = [app copyBlockFromStream: input toStream: output fileName: fileName]; if (length < 0) { app->_exitStatus = 1; goto outer_loop_end; } written += length; newPercent = (written == size ? 100 : (int8_t)(written * 100 / size)); if (app->_outputLevel >= 0 && percent != newPercent) { OFString *percentString; percent = newPercent; percentString = [OFString stringWithFormat: @"%3u", percent]; [OFStdOut writeString: @"\r"]; [OFStdOut writeString: OF_LOCALIZED( @"adding_file_percent", @"Adding %[file]... %[percent]%", @"file", fileName, @"percent", percentString)]; } } } if (app->_outputLevel >= 0) { [OFStdOut writeString: @"\r"]; [OFStdOut writeLine: OF_LOCALIZED( @"adding_file_done", @"Adding %[file]... done", @"file", fileName)]; } [output close]; outer_loop_end: objc_autoreleasePoolPop(pool); } [_archive close]; } @end objfw-1.1.6/utils/ofarc/ZooArchive.h000066400000000000000000000015271465614216400173200ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFZooArchive.h" #import "Archive.h" @interface ZooArchive: OFObject { OFZooArchive *_archive; } @end objfw-1.1.6/utils/ofarc/ZooArchive.m000066400000000000000000000343771465614216400173360ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFApplication.h" #import "OFArray.h" #import "OFDate.h" #import "OFFile.h" #import "OFFileManager.h" #import "OFLocale.h" #import "OFNumber.h" #import "OFSet.h" #import "OFStdIOStream.h" #import "OFString.h" #import "ZooArchive.h" #import "OFArc.h" #import "OFSetItemAttributesFailedException.h" static OFArc *app; static void setPermissions(OFString *path, OFZooArchiveEntry *entry) { #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS OFNumber *POSIXPermissions = entry.POSIXPermissions; if (POSIXPermissions != nil) { OFFileAttributes attributes; POSIXPermissions = [OFNumber numberWithUnsignedShort: POSIXPermissions.unsignedShortValue & 0777]; attributes = [OFDictionary dictionaryWithObject: POSIXPermissions forKey: OFFilePOSIXPermissions]; [[OFFileManager defaultManager] setAttributes: attributes ofItemAtPath: path]; } #endif [app quarantineFile: path]; } static void setModificationDate(OFString *path, OFZooArchiveEntry *entry) { OFFileAttributes attributes = [OFDictionary dictionaryWithObject: entry.modificationDate forKey: OFFileModificationDate]; @try { [[OFFileManager defaultManager] setAttributes: attributes ofItemAtPath: path]; } @catch (OFSetItemAttributesFailedException *e) { if (e.errNo != EISDIR) @throw e; } } @implementation ZooArchive + (void)initialize { if (self == [ZooArchive class]) app = (OFArc *)[OFApplication sharedApplication].delegate; } + (instancetype)archiveWithIRI: (OFIRI *)IRI stream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithIRI: IRI stream: stream mode: mode encoding: encoding] autorelease]; } - (instancetype)initWithIRI: (OFIRI *)IRI stream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (OFStringEncoding)encoding { self = [super init]; @try { _archive = [[OFZooArchive alloc] initWithStream: stream mode: mode]; if (encoding != OFStringEncodingAutodetect) _archive.encoding = encoding; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_archive release]; [super dealloc]; } - (void)listFiles { OFZooArchiveEntry *entry; if (app->_outputLevel >= 1 && _archive.archiveComment != nil) { [OFStdOut writeLine: OF_LOCALIZED( @"list_archive_comment", @"Archive comment:")]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: [_archive.archiveComment stringByReplacingOccurrencesOfString: @"\n" withString: @"\n\t"]]; [OFStdOut writeLine: @""]; } while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); if (app->_outputLevel < 1 && entry.deleted) { objc_autoreleasePoolPop(pool); continue; } [OFStdOut writeLine: entry.fileName]; if (app->_outputLevel >= 1) { OFString *modificationDate = [entry.modificationDate localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; OFString *compressedSize = [OFString stringWithFormat: @"%llu", entry.compressedSize]; OFString *uncompressedSize = [OFString stringWithFormat: @"%llu", entry.uncompressedSize]; OFString *compressionMethod = [OFString stringWithFormat: @"%" PRIu8, entry.compressionMethod]; OFString *CRC16 = [OFString stringWithFormat: @"%04" PRIX16, entry.CRC16]; OFString *deleted = [OFString stringWithFormat: @"%" PRIu8, entry.deleted]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_compressed_size", @"[" @" 'Compressed: '," @" [" @" {'size == 1': '1 byte'}," @" {'': '%[size] bytes'}" @" ]" @"]".objectByParsingJSON, @"size", compressedSize)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_uncompressed_size", @"[" @" 'Uncompressed: '," @" [" @" {'size == 1': '1 byte'}," @" {'': '%[size] bytes'}" @" ]" @"]".objectByParsingJSON, @"size", uncompressedSize)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_compression_method", @"Compression method: %[method]", @"method", compressionMethod)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED(@"list_crc16", @"CRC16: %[crc16]", @"crc16", CRC16)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_modification_date", @"Modification date: %[date]", @"date", modificationDate)]; if (entry.timeZone != nil) { float timeZone = entry.timeZone.floatValue; int hours = (int)timeZone; unsigned char minutes = (timeZone - hours) * 60; OFString *timeZoneString; if (hours > 0) timeZoneString = [OFString stringWithFormat: @"UTC+%02d:%02u", hours, minutes]; else timeZoneString = [OFString stringWithFormat: @"UTC-%02d:%02u", -hours, minutes]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_timezone", @"Time zone: %[timezone]", @"timezone", timeZoneString)]; } [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_deleted", @"[" @" 'Deleted: '," @" [" @" {'deleted == 0': 'No'}," @" {'': 'Yes'}" @" ]" @"]".objectByParsingJSON, @"deleted", deleted)]; if (entry.fileComment.length > 0) { [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_comment", @"Comment: %[comment]", @"comment", entry.fileComment)]; } } if (app->_outputLevel >= 2) { uint16_t minVersionNeeded = entry.minVersionNeeded; OFString *minVersionNeededString = [OFString stringWithFormat: @"%" PRIu8 @".%" PRIu8, minVersionNeeded >> 8, minVersionNeeded & 0xFF]; OFString *headerType = [OFString stringWithFormat: @"%" PRIu8, entry.headerType]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_min_version_needed", @"Minimum version needed: %[version]", @"version", minVersionNeededString)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_header_type", @"Header type: %[type]", @"type", headerType)]; if (entry.headerType >= 2) { OFString *OSID = [OFString stringWithFormat: @"%u", entry.operatingSystemIdentifier]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_osid", @"Operating system identifier: " @"%[osid]", @"osid", OSID)]; } if (entry.POSIXPermissions != nil) { OFString *permissionsString = [OFString stringWithFormat: @"%llo", entry.POSIXPermissions .unsignedLongLongValue]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_posix_permissions", @"POSIX permissions: %[perm]", @"perm", permissionsString)]; } } objc_autoreleasePoolPop(pool); } } - (void)extractFiles: (OFArray OF_GENERIC(OFString *) *)files { OFFileManager *fileManager = [OFFileManager defaultManager]; bool all = (files.count == 0); OFMutableSet OF_GENERIC(OFString *) *missing = [OFMutableSet setWithArray: files]; OFZooArchiveEntry *entry; while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); OFString *fileName = entry.fileName; OFString *outFileName, *directory; OFFile *output; OFStream *stream; unsigned long long written = 0, size = entry.uncompressedSize; int8_t percent = -1, newPercent; if (!all && ![files containsObject: fileName]) continue; if (all && entry.deleted) continue; [missing removeObject: fileName]; outFileName = [app safeLocalPathForPath: fileName]; if (outFileName == nil) { [OFStdErr writeLine: OF_LOCALIZED( @"refusing_to_extract_file", @"Refusing to extract %[file]!", @"file", fileName)]; app->_exitStatus = 1; goto outer_loop_end; } if (app->_outputLevel >= 0) [OFStdOut writeString: OF_LOCALIZED(@"extracting_file", @"Extracting %[file]...", @"file", fileName)]; directory = outFileName.stringByDeletingLastPathComponent; if (![fileManager directoryExistsAtPath: directory]) [fileManager createDirectoryAtPath: directory createParents: true]; if (![app shouldExtractFile: fileName outFileName: outFileName]) goto outer_loop_end; stream = [_archive streamForReadingCurrentEntry]; output = [OFFile fileWithPath: outFileName mode: @"w"]; setPermissions(outFileName, entry); while (!stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: stream toStream: output fileName: fileName]; if (length < 0) { app->_exitStatus = 1; goto outer_loop_end; } written += length; newPercent = (written == size ? 100 : (int8_t)(written * 100 / size)); if (app->_outputLevel >= 0 && percent != newPercent) { OFString *percentString; percent = newPercent; percentString = [OFString stringWithFormat: @"%3u", percent]; [OFStdOut writeString: @"\r"]; [OFStdOut writeString: OF_LOCALIZED( @"extracting_file_percent", @"Extracting %[file]... %[percent]%", @"file", fileName, @"percent", percentString)]; } } [output close]; setModificationDate(outFileName, entry); if (app->_outputLevel >= 0) { [OFStdOut writeString: @"\r"]; [OFStdOut writeLine: OF_LOCALIZED( @"extracting_file_done", @"Extracting %[file]... done", @"file", fileName)]; } outer_loop_end: objc_autoreleasePoolPop(pool); } if (missing.count > 0) { for (OFString *file in missing) [OFStdErr writeLine: OF_LOCALIZED( @"file_not_in_archive", @"File %[file] is not in the archive!", @"file", file)]; app->_exitStatus = 1; } } - (void)printFiles: (OFArray OF_GENERIC(OFString *) *)files_ { OFMutableSet *files; OFZooArchiveEntry *entry; if (files_.count < 1) { [OFStdErr writeLine: OF_LOCALIZED(@"print_no_file_specified", @"Need one or more files to print!")]; app->_exitStatus = 1; return; } files = [OFMutableSet setWithArray: files_]; while ((entry = [_archive nextEntry]) != nil) { OFString *fileName = entry.fileName; OFStream *stream; if (![files containsObject: fileName]) continue; stream = [_archive streamForReadingCurrentEntry]; while (!stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: stream toStream: OFStdOut fileName: fileName]; if (length < 0) { app->_exitStatus = 1; return; } } [files removeObject: fileName]; [stream close]; if (files.count == 0) break; } for (OFString *file in files) { [OFStdErr writeLine: OF_LOCALIZED(@"file_not_in_archive", @"File %[file] is not in the archive!", @"file", file)]; app->_exitStatus = 1; } } - (void)addFiles: (OFArray OF_GENERIC(OFString *) *)files archiveComment: (OFString *)archiveComment { OFFileManager *fileManager = [OFFileManager defaultManager]; _archive.archiveComment = archiveComment; for (OFString *fileName in files) { void *pool = objc_autoreleasePoolPush(); OFFileAttributes attributes; OFFileAttributeType type; OFMutableZooArchiveEntry *entry; OFStream *output; if (app->_outputLevel >= 0) [OFStdOut writeString: OF_LOCALIZED(@"adding_file", @"Adding %[file]...", @"file", fileName)]; attributes = [fileManager attributesOfItemAtPath: fileName]; type = attributes.fileType; if ([type isEqual: OFFileTypeDirectory]) { if (app->_outputLevel >= 0) { [OFStdOut writeString: @"\r"]; [OFStdOut writeLine: OF_LOCALIZED( @"adding_file_skipped", @"Adding %[file]... skipped", @"file", fileName)]; } continue; } entry = [OFMutableZooArchiveEntry entryWithFileName: fileName]; entry.timeZone = [OFNumber numberWithFloat: 0]; entry.modificationDate = attributes.fileModificationDate; #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS entry.POSIXPermissions = [attributes objectForKey: OFFilePOSIXPermissions]; #endif output = [_archive streamForWritingEntry: entry]; if ([type isEqual: OFFileTypeRegular]) { unsigned long long written = 0; unsigned long long size = attributes.fileSize; int8_t percent = -1, newPercent; OFFile *input = [OFFile fileWithPath: fileName mode: @"r"]; while (!input.atEndOfStream) { ssize_t length = [app copyBlockFromStream: input toStream: output fileName: fileName]; if (length < 0) { app->_exitStatus = 1; goto outer_loop_end; } written += length; newPercent = (written == size ? 100 : (int8_t)(written * 100 / size)); if (app->_outputLevel >= 0 && percent != newPercent) { OFString *percentString; percent = newPercent; percentString = [OFString stringWithFormat: @"%3u", percent]; [OFStdOut writeString: @"\r"]; [OFStdOut writeString: OF_LOCALIZED( @"adding_file_percent", @"Adding %[file]... %[percent]%", @"file", fileName, @"percent", percentString)]; } } } if (app->_outputLevel >= 0) { [OFStdOut writeString: @"\r"]; [OFStdOut writeLine: OF_LOCALIZED( @"adding_file_done", @"Adding %[file]... done", @"file", fileName)]; } [output close]; outer_loop_end: objc_autoreleasePoolPop(pool); } [_archive close]; } @end objfw-1.1.6/utils/ofarc/localization/000077500000000000000000000000001465614216400175615ustar00rootroot00000000000000objfw-1.1.6/utils/ofarc/localization/de.json000066400000000000000000000152641465614216400210540ustar00rootroot00000000000000/* * German localization for ofarc. * * Copyright (c) 2017-2024 Jonathan Schleifer * * Permission to use, copy, modify, and/or distribute this localization for * any purpose with or without fee is hereby granted. */ /* vim: se ft=javascript sw=4 et: */ { usage: [ "Benutzung: %[prog] -[acCfhlnpqtvx] archiv.zip [datei1 datei2 ...]" ], full_usage: [ "Optionen:\n", " -a --append Zu Archiv hinzufügen\n", " --archive-comment= Zu benutzender Archivkommentar beim ", "Erstellen oder\n", " Hinzufügen\n", " -c --create Archiv erstellen\n", " -C --directory= In angegebenes Verzeichnis entpacken\n", " -E --encoding= Das Encoding des Archivs\n", " (nur tar-, lha- und zoo-Dateien)\n", " -f --force Existierende Dateien überschreiben\n", " -h --help Diese Hilfe anzeigen\n", " --iri Eine IRI benutzen um auf das Archiv ", "zuzugreifen\n", " -l --list Alle Dateien im Archiv auflisten\n", " -n --no-clobber Dateien niemals überschreiben\n", " -p --print Eine oder mehr Dateien aus dem Archiv ", "ausgeben\n", " -q --quiet Ruhiger Modus (keine Ausgabe außer ", "Fehler)\n", " -t --type= Archiv-Typ (gz, lha, tar, tgz, zip, ", "zoo)\n", " -v --verbose Ausführlicher Modus für Datei-Liste\n", " -x --extract Dateien entpacken" ], "2_options_mutually_exclusive": [ "Fehler: -%[shortopt1] / --%[longopt1] und ", "-%[shortopt2] / --%[longopt2] schließen sich gegenseitig aus!" ], "5_options_mutually_exclusive": [ "Fehler: -%[shortopt1] / --%[longopt1], -%[shortopt2] / ", "--%[longopt2], -%[shortopt3] / --%[longopt3], ", "-%[shortopt4] / --%[longopt4] und\n", " -%[shortopt5] / --%[longopt5] schließen sich gegenseitig aus!" ], option_takes_no_argument: "%[prog]: Option --%[opt] nimmt kein Argument", long_option_requires_argument: [ "%[prog]: Option --%[opt] benötigt ein Argument" ], option_requires_argument: "%[prog]: Option -%[opt] benötigt ein Argument", unknown_long_option: "%[prog]: Unbekannte Option: --%[opt]", unknown_option: "%[prog]: Unbekannte Option: -%[opt]", invalid_encoding: "%[prog]: Invalid encoding: %[encoding]", writing_not_supported: [ "Schreiben von Dateien des Typs %[type] wird (noch) nicht unterstützt!" ], failed_to_create_directory: [ "Fehler beim Erstellen des Verzeichnis %[dir]: %[error]" ], failed_to_open_file: "Fehler beim Öffnen der Datei %[file]: %[error]", unknown_archive_type: "Unbekannter Archivtyp: %[type]", failed_to_read_file: "Fehler beim Lesen der Datei %[file]: %[error]", failed_to_write_file: "Fehler beim Schreiben der Datei %[file]: %[error]", failed_to_seek_in_file: "Fehler beim Suchen in Datei %[file]: %[error]", file_is_not_a_valid_archive: "Datei %[file] ist kein gültiges Archiv!", file_skipped: "übersprungen", ask_overwrite: "%[file] überschreiben? [ynAN?]", ask_overwrite_help: [ " y: Ja\n", " n: Nein\n", " A: Immer\n", " N: Nie" ], skipping_file: "Überspringe %[file]...", extracting_file: "Entpacke %[file]...", extracting_file_percent: "Entpacke %[file]... %[percent]%", extracting_file_done: "Entpacke %[file]... fertig", cannot_list_gz: "Kann Dateien eines .gz-Archivs nicht auflisten!", cannot_extract_specific_file_from_gz: [ "Kann keine spezifische Datei aus einem .gz-Archiv entpacken!" ], cannot_print_specific_file_from_gz: [ "Kann keine spezifische Datei aus einem .gz-Archiv ausgeben!" ], list_archive_comment: "Archivkommentar:", list_size: [ "Größe: ", [ {"size == 1": "1 Byte"}, {"": "%[size] Bytes"} ] ], list_posix_permissions: "POSIX-Berechtigungen: %[perm]", list_owner_account_id: "Besitzerkontennummer: %[id]", list_group_owner_account_id: "Gruppenbesitzerkontennummer: %[id]", list_owner_account_name: "Besitzerkontenname: %[name]", list_group_owner_account_name: "Gruppenbesitzerkontenname: %[name]", list_header_level: "Header-Level: %[level]", list_header_type: "Header-Typ: %[type]", list_modification_date: "Änderungsdatum: %[date]", list_type_normal: "Typ: Normale Datei", list_type_hardlink: "Typ: Harter Link", list_type_symlink: "Typ: Symbolischer Link", list_link_target: "Zieldateiname: %[target]", list_type_character_device: "Typ: Zeichenorientiertes Gerät", list_type_block_device: "Typ: Blockorientiertes Gerät", list_device_major: "Major-Nummer des Geräts: %[major]", list_device_minor: "Minor-Nummer des Geräts: %[minor]", list_type_directory: "Typ: Verzeichnis", list_type_fifo: "Typ: FIFO", list_type_contiguous_file: "Typ: Zusammenhängende Datei", list_type_unknown: "Typ: Unbekannt", list_compressed_size: [ "Komprimierte Größe: ", [ {"size == 1": "1 Byte"}, {"": "%[size] Bytes"} ] ], list_uncompressed_size: [ "Unkomprimierte Größe: ", [ {"size == 1": "1 Byte"}, {"": "%[size] Bytes"} ] ], list_compression_method: "Kompressionsmethode: %[method]", list_osid: "Betriebssystem-Identifikator: %[osid]", list_extensions: "Erweiterungen: %[extensions]", list_version_made_by: "Erstellt mit Version: %[version]", list_min_version_needed: "Mindestens benötigte Version: %[version]", list_general_purpose_bit_flag: "General Purpose Bit Flag: %[gpbf]", list_extra_field: "Extra-Feld: %[extra]", list_comment: "Kommentar: %[comment]", list_timezone: "Zeitzone: %[timezone]", list_deleted: [ "Gelöscht: ", [ {"deleted == 0": "Nein"}, {"": "Ja"} ] ], refusing_to_extract_file: "Verweigere Entpacken von %[file]!", file_not_in_archive: "Datei %[file] ist nicht im Archiv!", print_no_file_specified: [ "Benötige eine oder mehrere Dateien zum Ausgeben!" ], add_no_file_specified: [ "Benötige eine oder mehrere Dateien zum Hinzufügen!" ], adding_file: "Füge %[file] hinzu...", adding_file_percent: "Füge %[file] hinzu... %[percent]%", adding_file_done: "Füge %[file] hinzu... fertig", adding_file_skipped: "Füge %[file] hinzu... übersprungen", } objfw-1.1.6/utils/ofarc/localization/localizations.json000066400000000000000000000006011465614216400233240ustar00rootroot00000000000000/* * Localization mapping for ofarc. * * Copyright (c) 2017-2023 Jonathan Schleifer * * Permission to use, copy, modify, and/or distribute this mapping for any * purpose with or without fee is hereby granted. */ /* vim: se ft=javascript sw=4 et: */ { de: { "": "de" }, deutsch: { "": "de" }, german: { "": "de" }, } objfw-1.1.6/utils/ofdns/000077500000000000000000000000001465614216400151105ustar00rootroot00000000000000objfw-1.1.6/utils/ofdns/Makefile000066400000000000000000000010221465614216400165430ustar00rootroot00000000000000include ../../extra.mk PROG = ofdns${PROG_SUFFIX} SRCS = OFDNS.m DATA = localization/de.json \ localization/localizations.json include ../../buildsys.mk PACKAGE_NAME = ofdns ${PROG}: ${LIBOBJFW_DEP_LVL2} ${LIBOBJFWRT_DEP_LVL2} CPPFLAGS += -I../../src \ -I../../src/runtime \ -I../../src/exceptions \ -I../.. \ -DLOCALIZATION_DIR=\"${datadir}/ofdns/localization\" LIBS := -L../../src -lobjfw -L../../src/runtime ${RUNTIME_LIBS} ${LIBS} LD = ${OBJC} LDFLAGS += ${LDFLAGS_RPATH} objfw-1.1.6/utils/ofdns/OFDNS.m000066400000000000000000000134431465614216400161440ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFApplication.h" #import "OFArray.h" #import "OFDNSResolver.h" #import "OFIRI.h" #import "OFLocale.h" #import "OFOptionsParser.h" #import "OFSandbox.h" #import "OFStdIOStream.h" @interface OFDNS: OFObject { size_t _inFlight; int _errors; } @end OF_APPLICATION_DELEGATE(OFDNS) static void help(OFStream *stream, bool full, int status) { [OFStdErr writeLine: OF_LOCALIZED(@"usage", @"Usage: %[prog] -[chst] domain1 [domain2 ...]", @"prog", [OFApplication programName])]; if (full) { [stream writeString: @"\n"]; [stream writeLine: OF_LOCALIZED(@"full_usage", @"Options:\n " @"-c --class= " @" The DNS class to query (defaults to IN)\n " @"-h --help " @" Show this help\n " @"-s --server=" @" The server to query\n " @"-t --type= " @" The record type to query (defaults to ALL, can be " @"repeated)\n " @" --tcp " @" Force using TCP for the query")]; } [OFApplication terminateWithStatus: status]; } @implementation OFDNS - (void)resolver: (OFDNSResolver *)resolver didPerformQuery: (OFDNSQuery *)query response: (OFDNSResponse *)response exception: (id)exception { _inFlight--; if (exception == nil) [OFStdOut writeFormat: @"%@\n", response]; else { [OFStdErr writeLine: OF_LOCALIZED(@"failed_to_resolve", @"Failed to resolve: %[exception]", @"exception", exception)]; _errors++; } if (_inFlight == 0) [OFApplication terminateWithStatus: _errors]; } - (void)applicationDidFinishLaunching: (OFNotification *)notification { OFString *DNSClassString, *server; bool forceTCP; const OFOptionsParserOption options[] = { { 'c', @"class", 1, NULL, &DNSClassString }, { 'h', @"help", 0, NULL, NULL }, { 's', @"server", 1, NULL, &server }, { 't', @"type", 1, NULL, NULL }, { '\0', @"tcp", 0, &forceTCP, NULL }, { '\0', nil, 0, NULL, NULL } }; OFMutableArray OF_GENERIC(OFString *) *recordTypes; OFOptionsParser *optionsParser; OFUnichar option; OFArray OF_GENERIC(OFString *) *remainingArguments; OFDNSResolver *resolver; OFDNSClass DNSClass; #ifdef OF_HAVE_FILES # ifndef OF_AMIGAOS [OFLocale addLocalizationDirectoryIRI: [OFIRI fileIRIWithPath: @LOCALIZATION_DIR]]; # else [OFLocale addLocalizationDirectoryIRI: [OFIRI fileIRIWithPath: @"PROGDIR:/share/ofdns/localization"]]; # endif #endif #ifdef OF_HAVE_SANDBOX OFSandbox *sandbox = [[OFSandbox alloc] init]; @try { sandbox.allowsStdIO = true; sandbox.allowsDNS = true; [OFApplication of_activateSandbox: sandbox]; } @finally { [sandbox release]; } #endif recordTypes = [OFMutableArray array]; optionsParser = [OFOptionsParser parserWithOptions: options]; while ((option = [optionsParser nextOption]) != '\0') { switch (option) { case 't': [recordTypes addObject: optionsParser.argument]; break; case 'h': help(OFStdOut, true, 0); break; case ':': if (optionsParser.lastLongOption != nil) [OFStdErr writeLine: OF_LOCALIZED( @"long_option_required_argument", @"%[prog]: Option --%[opt] requires an " @"argument", @"prog", [OFApplication programName], @"opt", optionsParser.lastLongOption)]; else { OFString *optStr = [OFString stringWithFormat: @"%C", optionsParser.lastOption]; [OFStdErr writeLine: OF_LOCALIZED( @"option_requires_argument", @"%[prog]: Option -%[opt] requires an " @"argument", @"prog", [OFApplication programName], @"opt", optStr)]; } [OFApplication terminateWithStatus: 1]; break; case '?': if (optionsParser.lastLongOption != nil) [OFStdErr writeLine: OF_LOCALIZED( @"unknown_long_option", @"%[prog]: Unknown option: --%[opt]", @"prog", [OFApplication programName], @"opt", optionsParser.lastLongOption)]; else { OFString *optStr = [OFString stringWithFormat: @"%C", optionsParser.lastOption]; [OFStdErr writeLine: OF_LOCALIZED( @"Unknown_option", @"%[prog]: Unknown option: -%[opt]", @"prog", [OFApplication programName], @"opt", optStr)]; } [OFApplication terminateWithStatus: 1]; break; } } remainingArguments = optionsParser.remainingArguments; if (remainingArguments.count < 1) help(OFStdErr, false, 1); resolver = [OFDNSResolver resolver]; resolver.configReloadInterval = 0; resolver.forcesTCP = forceTCP; DNSClass = (DNSClassString != nil ? OFDNSClassParseName(DNSClassString) : OFDNSClassIN); if (recordTypes.count == 0) [recordTypes addObject: @"ALL"]; if (server != nil) resolver.nameServers = [OFArray arrayWithObject: server]; for (OFString *domainName in remainingArguments) { for (OFString *recordTypeString in recordTypes) { OFDNSRecordType recordType = OFDNSRecordTypeParseName(recordTypeString); OFDNSQuery *query = [OFDNSQuery queryWithDomainName: domainName DNSClass: DNSClass recordType: recordType]; _inFlight++; [resolver asyncPerformQuery: query delegate: self]; } } } @end objfw-1.1.6/utils/ofdns/localization/000077500000000000000000000000001465614216400176005ustar00rootroot00000000000000objfw-1.1.6/utils/ofdns/localization/de.json000066400000000000000000000021711465614216400210640ustar00rootroot00000000000000/* * German localization for ofdns. * * Copyright (c) 2020-2024 Jonathan Schleifer * * Permission to use, copy, modify, and/or distribute this localization for * any purpose with or without fee is hereby granted. */ /* vim: se ft=javascript sw=4 et: */ { usage: "Benutzung: %[prog] -[chst] domain1 [domain2 ...]", full_usage: [ "Optionen:\n", " -c --class= Die anzufragende DNS-Klasse (standardmäßig IN)\n", " -h --help Diese Hilfe anzeigen\n", " -s --server= Der abzufragende Server\n", " -t --type= Der anzufragende Record-Typ (standardmäßig ALL,\n", " kann wiederholt werden)\n", " --tcp Benutzung von TCP erzwingen" ], long_option_requires_argument: [ "%[prog]: Option --%[opt] benötigt ein Argument" ], option_requires_argument: "%[prog]: Option -%[opt] benötigt ein Argument", unknown_long_option: "%[prog]: Unbekannte Option: --%[opt]", unknown_option: "%[prog]: Unbekannte Option: -%[opt]", failed_to_resolve: "Auflösen fehlgeschlagen: %[exception]", } objfw-1.1.6/utils/ofdns/localization/localizations.json000066400000000000000000000006011465614216400233430ustar00rootroot00000000000000/* * Localization mapping for ofdns. * * Copyright (c) 2020-2023 Jonathan Schleifer * * Permission to use, copy, modify, and/or distribute this mapping for any * purpose with or without fee is hereby granted. */ /* vim: se ft=javascript sw=4 et: */ { de: { "": "de" }, deutsch: { "": "de" }, german: { "": "de" }, } objfw-1.1.6/utils/ofhash/000077500000000000000000000000001465614216400152475ustar00rootroot00000000000000objfw-1.1.6/utils/ofhash/Makefile000066400000000000000000000010771465614216400167140ustar00rootroot00000000000000include ../../extra.mk PROG = ofhash${PROG_SUFFIX} SRCS = OFHash.m DATA = localization/de.json \ localization/localizations.json include ../../buildsys.mk PACKAGE_NAME = ofhash ${PROG}: ${LIBOBJFW_DEP_LVL2} ${LIBOBJFWRT_DEP_LVL2} CPPFLAGS += -I../../src \ -I../../src/runtime \ -I../../src/exceptions \ -I../.. \ -DLOCALIZATION_DIR=\"${datadir}/ofhash/localization\" LIBS := -L../../src -L../../src/tls ${OFHASH_LIBS} -lobjfw \ -L../../src/runtime ${RUNTIME_LIBS} \ ${LIBS} LD = ${OBJC} LDFLAGS += ${LDFLAGS_RPATH} objfw-1.1.6/utils/ofhash/OFHash.m000066400000000000000000000176341465614216400165500ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFApplication.h" #import "OFArray.h" #import "OFFile.h" #import "OFIRI.h" #import "OFIRIHandler.h" #import "OFLocale.h" #import "OFMD5Hash.h" #import "OFOptionsParser.h" #import "OFRIPEMD160Hash.h" #import "OFSHA1Hash.h" #import "OFSHA224Hash.h" #import "OFSHA256Hash.h" #import "OFSHA384Hash.h" #import "OFSHA512Hash.h" #import "OFSandbox.h" #import "OFSecureData.h" #import "OFStdIOStream.h" #import "OFOpenItemFailedException.h" #import "OFReadFailedException.h" @interface OFHash: OFObject @end OF_APPLICATION_DELEGATE(OFHash) static void help(void) { [OFStdErr writeLine: OF_LOCALIZED(@"usage", @"Usage: %[prog] [--md5] [--ripemd160] [--sha1] [--sha224] " @"[--sha256] [--sha384] [--sha512] [--iri] file1 [file2 ...]", @"prog", [OFApplication programName])]; [OFApplication terminateWithStatus: 1]; } static void printHash(OFString *algo, OFString *path, id hash) { size_t digestSize = hash.digestSize; const unsigned char *digest; [hash calculate]; digest = hash.digest; [OFStdOut writeFormat: @"%@ ", algo]; for (size_t i = 0; i < digestSize; i++) [OFStdOut writeFormat: @"%02x", digest[i]]; [OFStdOut writeFormat: @" %@\n", path]; } @implementation OFHash - (void)applicationDidFinishLaunching: (OFNotification *)notification { int exitStatus = 0; bool calculateMD5, calculateRIPEMD160, calculateSHA1, calculateSHA224; bool calculateSHA256, calculateSHA384, calculateSHA512, isIRI; const OFOptionsParserOption options[] = { { '\0', @"md5", 0, &calculateMD5, NULL }, { '\0', @"ripemd160", 0, &calculateRIPEMD160, NULL }, { '\0', @"sha1", 0, &calculateSHA1, NULL }, { '\0', @"sha224", 0, &calculateSHA224, NULL }, { '\0', @"sha256", 0, &calculateSHA256, NULL }, { '\0', @"sha384", 0, &calculateSHA384, NULL }, { '\0', @"sha512", 0, &calculateSHA512, NULL }, { '\0', @"iri", 0, &isIRI, NULL }, { '\0', nil, 0, NULL, NULL } }; OFOptionsParser *optionsParser = [OFOptionsParser parserWithOptions: options]; OFUnichar option; OFMD5Hash *MD5Hash = nil; OFRIPEMD160Hash *RIPEMD160Hash = nil; OFSHA1Hash *SHA1Hash = nil; OFSHA224Hash *SHA224Hash = nil; OFSHA256Hash *SHA256Hash = nil; OFSHA384Hash *SHA384Hash = nil; OFSHA512Hash *SHA512Hash = nil; #ifndef OF_AMIGAOS [OFLocale addLocalizationDirectoryIRI: [OFIRI fileIRIWithPath: @LOCALIZATION_DIR]]; #else [OFLocale addLocalizationDirectoryIRI: [OFIRI fileIRIWithPath: @"PROGDIR:/share/ofhash/localization"]]; #endif while ((option = [optionsParser nextOption]) != '\0') { switch (option) { case '?': if (optionsParser.lastLongOption != nil) [OFStdErr writeLine: OF_LOCALIZED( @"unknown_long_option", @"%[prog]: Unknown option: --%[opt]", @"prog", [OFApplication programName], @"opt", optionsParser.lastLongOption)]; else { OFString *optStr = [OFString stringWithFormat: @"%C", optionsParser.lastOption]; [OFStdErr writeLine: OF_LOCALIZED( @"unknown_option", @"%[prog]: Unknown option: -%[opt]", @"prog", [OFApplication programName], @"opt", optStr)]; } [OFApplication terminateWithStatus: 1]; break; } } #ifdef OF_HAVE_SANDBOX OFSandbox *sandbox = [OFSandbox sandbox]; @try { sandbox.allowsStdIO = true; sandbox.allowsReadingFiles = true; sandbox.allowsUserDatabaseReading = true; if (!isIRI) for (OFString *path in optionsParser.remainingArguments) [sandbox unveilPath: path permissions: @"r"]; [sandbox unveilPath: @LOCALIZATION_DIR permissions: @"r"]; [OFApplication of_activateSandbox: sandbox]; } @finally { [sandbox release]; } #endif if (!calculateMD5 && !calculateRIPEMD160 && !calculateSHA1 && !calculateSHA224 && !calculateSHA256 && !calculateSHA384 && !calculateSHA512) help(); if (optionsParser.remainingArguments.count < 1) help(); if (calculateMD5) MD5Hash = [OFMD5Hash hashWithAllowsSwappableMemory: true]; if (calculateRIPEMD160) RIPEMD160Hash = [OFRIPEMD160Hash hashWithAllowsSwappableMemory: true]; if (calculateSHA1) SHA1Hash = [OFSHA1Hash hashWithAllowsSwappableMemory: true]; if (calculateSHA224) SHA224Hash = [OFSHA224Hash hashWithAllowsSwappableMemory: true]; if (calculateSHA256) SHA256Hash = [OFSHA256Hash hashWithAllowsSwappableMemory: true]; if (calculateSHA384) SHA384Hash = [OFSHA384Hash hashWithAllowsSwappableMemory: true]; if (calculateSHA512) SHA512Hash = [OFSHA512Hash hashWithAllowsSwappableMemory: true]; for (OFString *path in optionsParser.remainingArguments) { void *pool = objc_autoreleasePoolPush(); OFStream *file; if (!isIRI && [path isEqual: @"-"]) file = OFStdIn; else { @try { if (isIRI) { OFIRI *IRI = [OFIRI IRIWithString: path]; file = [OFIRIHandler openItemAtIRI: IRI mode: @"r"]; } else file = [OFFile fileWithPath: path mode: @"r"]; } @catch (OFOpenItemFailedException *e) { OFString *error = [OFString stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; OFString *filePath = (e.IRI != nil ? e.IRI.string : e.path); [OFStdErr writeLine: OF_LOCALIZED( @"failed_to_open_file", @"Failed to open file %[file]: %[error]", @"file", filePath, @"error", error)]; exitStatus = 1; goto outer_loop_end; } } [MD5Hash reset]; [RIPEMD160Hash reset]; [SHA1Hash reset]; [SHA224Hash reset]; [SHA256Hash reset]; [SHA384Hash reset]; [SHA512Hash reset]; while (!file.atEndOfStream) { uint8_t buffer[1024]; size_t length; @try { length = [file readIntoBuffer: buffer length: 1024]; } @catch (OFReadFailedException *e) { OFString *error = [OFString stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; [OFStdErr writeLine: OF_LOCALIZED( @"failed_to_read_file", @"Failed to read %[file]: %[error]", @"file", path, @"error", error)]; exitStatus = 1; goto outer_loop_end; } if (calculateMD5) [MD5Hash updateWithBuffer: buffer length: length]; if (calculateRIPEMD160) [RIPEMD160Hash updateWithBuffer: buffer length: length]; if (calculateSHA1) [SHA1Hash updateWithBuffer: buffer length: length]; if (calculateSHA224) [SHA224Hash updateWithBuffer: buffer length: length]; if (calculateSHA256) [SHA256Hash updateWithBuffer: buffer length: length]; if (calculateSHA384) [SHA384Hash updateWithBuffer: buffer length: length]; if (calculateSHA512) [SHA512Hash updateWithBuffer: buffer length: length]; } [file close]; if (calculateMD5) printHash(@"MD5", path, MD5Hash); if (calculateRIPEMD160) printHash(@"RIPEMD160", path, RIPEMD160Hash); if (calculateSHA1) printHash(@"SHA1", path, SHA1Hash); if (calculateSHA224) printHash(@"SHA224", path, SHA224Hash); if (calculateSHA256) printHash(@"SHA256", path, SHA256Hash); if (calculateSHA384) printHash(@"SHA384", path, SHA384Hash); if (calculateSHA512) printHash(@"SHA512", path, SHA512Hash); outer_loop_end: objc_autoreleasePoolPop(pool); } [OFApplication terminateWithStatus: exitStatus]; } @end objfw-1.1.6/utils/ofhash/localization/000077500000000000000000000000001465614216400177375ustar00rootroot00000000000000objfw-1.1.6/utils/ofhash/localization/de.json000066400000000000000000000013151465614216400212220ustar00rootroot00000000000000/* * German localization for ofhash. * * Copyright (c) 2017-2024 Jonathan Schleifer * * Permission to use, copy, modify, and/or distribute this localization for * any purpose with or without fee is hereby granted. */ /* vim: se ft=javascript sw=4 et: */ { usage: [ "Benutzung: %[prog] [--md5] [--ripemd160] [--sha1] [--sha224] ", "[--sha256] [--sha384] [--sha512] [--iri] datei1 [datei2 ...]" ], unknown_long_option: "%[prog]: Unbekannte Option: --%[opt]", unknown_option: "%[prog]: Unbekannte Option: -%[opt]", failed_to_open_file: "Fehler beim Öffnen der Datei %[file]: %[error]", failed_to_read_file: "Fehler beim Lesen der Datei %[file]: %[error]", } objfw-1.1.6/utils/ofhash/localization/localizations.json000066400000000000000000000006021465614216400235030ustar00rootroot00000000000000/* * Localization mapping for ofhash. * * Copyright (c) 2017-2023 Jonathan Schleifer * * Permission to use, copy, modify, and/or distribute this mapping for any * purpose with or without fee is hereby granted. */ /* vim: se ft=javascript sw=4 et: */ { de: { "": "de" }, deutsch: { "": "de" }, german: { "": "de" }, } objfw-1.1.6/utils/ofhttp/000077500000000000000000000000001465614216400153035ustar00rootroot00000000000000objfw-1.1.6/utils/ofhttp/Makefile000066400000000000000000000011631465614216400167440ustar00rootroot00000000000000include ../../extra.mk PROG = ofhttp${PROG_SUFFIX} SRCS = OFHTTP.m \ ProgressBar.m DATA = localization/de.json \ localization/localizations.json include ../../buildsys.mk PACKAGE_NAME = ofhttp ${PROG}: ${LIBOBJFW_DEP_LVL2} ${LIBOBJFWRT_DEP_LVL2} CPPFLAGS += -I../../src \ -I../../src/runtime \ -I../../src/exceptions \ -I../../src/tls \ -I../.. \ -DLOCALIZATION_DIR='"${datadir}/ofhttp/localization"' LIBS := -L../../src -L../../src/tls ${OFHTTP_LIBS} -lobjfw \ -L../../src/runtime ${RUNTIME_LIBS} \ ${LIBS} LD = ${OBJC} LDFLAGS += ${LDFLAGS_RPATH} objfw-1.1.6/utils/ofhttp/OFHTTP.m000066400000000000000000000764551465614216400165060ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #import "OFApplication.h" #import "OFArray.h" #import "OFData.h" #import "OFDate.h" #import "OFDictionary.h" #import "OFFile.h" #import "OFFileManager.h" #import "OFHTTPClient.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" #import "OFIRI.h" #import "OFLocale.h" #import "OFOptionsParser.h" #ifdef OF_HAVE_PLUGINS # import "OFPlugin.h" #endif #import "OFSandbox.h" #import "OFStdIOStream.h" #import "OFSystemInfo.h" #import "OFTCPSocket.h" #import "OFTLSStream.h" #ifdef HAVE_TLS_SUPPORT # import "ObjFWTLS.h" #endif #import "OFConnectSocketFailedException.h" #import "OFGetItemAttributesFailedException.h" #import "OFHTTPRequestFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFInvalidServerResponseException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFResolveHostFailedException.h" #import "OFSetItemAttributesFailedException.h" #import "OFTLSHandshakeFailedException.h" #import "OFUnsupportedProtocolException.h" #import "OFWriteFailedException.h" #import "ProgressBar.h" #define GIBIBYTE (1024 * 1024 * 1024) #define MEBIBYTE (1024 * 1024) #define KIBIBYTE (1024) @interface OFHTTP: OFObject { OFArray OF_GENERIC(OFString *) *_IRIs; size_t _IRIIndex; int _errorCode; OFString *_outputPath, *_currentFileName; bool _continue, _force, _detectFileName, _detectFileNameRequest; bool _detectedFileName, _quiet, _verbose, _insecure, _ignoreStatus; bool _useUnicode; OFStream *_body; OFHTTPRequestMethod _method; OFMutableDictionary *_clientHeaders; OFHTTPClient *_HTTPClient; char *_buffer; OFStream *_output; unsigned long long _received, _length, _resumedFrom; ProgressBar *_progressBar; } - (void)downloadNextIRI; @end #ifdef HAVE_TLS_SUPPORT void _reference_to_ObjFWTLS(void) { _ObjFWTLS_reference = 1; } #endif OF_APPLICATION_DELEGATE(OFHTTP) static void help(OFStream *stream, bool full, int status) { [OFStdErr writeLine: OF_LOCALIZED(@"usage", @"Usage: %[prog] -[cehHmoOPqv] iri1 [iri2 ...]", @"prog", [OFApplication programName])]; if (full) { [stream writeString: @"\n"]; [stream writeLine: OF_LOCALIZED(@"full_usage", @"Options:\n " @"-b --body= " @" Specify the file to send as body\n " @" " @" (- for standard input)\n " @"-c --continue " @" Continue download of existing file\n " @"-f --force " @" Force / overwrite existing file\n " @"-h --help " @" Show this help\n " @"-H --header= " @" Add a header (e.g. X-Foo:Bar)\n " @"-m --method= " @" Set the method of the HTTP request\n " @"-o --output= " @" Specify output file name\n " @"-O --detect-filename" @" Do a HEAD request to detect the file name\n " @"-P --proxy= " @" Specify SOCKS5 proxy\n " @"-q --quiet " @" Quiet mode (no output, except errors)\n " @"-v --verbose " @" Verbose mode (print headers)\n " @" --insecure " @" Ignore TLS errors and allow insecure redirects\n " @" --ignore-status " @" Ignore HTTP status code")]; } [OFApplication terminateWithStatus: status]; } static OFString * fileNameFromContentDisposition(OFString *contentDisposition) { void *pool; const char *UTF8String; size_t UTF8StringLength; enum { stateDispositionType, stateDispositionTypeSemicolon, stateDispositionParamNameSkipSpace, stateDispositionParamName, stateDispositionParamValue, stateDispositionParamQuoted, stateDispositionParamUnquoted, stateDispositionExpectSemicolon } state; size_t last; OFString *type = nil, *paramName = nil, *paramValue; OFMutableDictionary *params; OFString *fileName; if (contentDisposition == nil) return nil; pool = objc_autoreleasePoolPush(); UTF8String = contentDisposition.UTF8String; UTF8StringLength = contentDisposition.UTF8StringLength; state = stateDispositionType; params = [OFMutableDictionary dictionary]; last = 0; for (size_t i = 0; i < UTF8StringLength; i++) { switch (state) { case stateDispositionType: if (UTF8String[i] == ';' || UTF8String[i] == ' ') { type = [OFString stringWithUTF8String: UTF8String length: i]; state = (UTF8String[i] == ';' ? stateDispositionParamNameSkipSpace : stateDispositionTypeSemicolon); last = i + 1; } break; case stateDispositionTypeSemicolon: if (UTF8String[i] == ';') { state = stateDispositionParamNameSkipSpace; last = i + 1; } else if (UTF8String[i] != ' ') { objc_autoreleasePoolPop(pool); return nil; } break; case stateDispositionParamNameSkipSpace: if (UTF8String[i] != ' ') { state = stateDispositionParamName; last = i; i--; } break; case stateDispositionParamName: if (UTF8String[i] == '=') { paramName = [OFString stringWithUTF8String: UTF8String + last length: i - last]; state = stateDispositionParamValue; } break; case stateDispositionParamValue: if (UTF8String[i] == '"') { state = stateDispositionParamQuoted; last = i + 1; } else { state = stateDispositionParamUnquoted; last = i; i--; } break; case stateDispositionParamQuoted: if (UTF8String[i] == '"') { paramValue = [OFString stringWithUTF8String: UTF8String + last length: i - last]; [params setObject: paramValue forKey: paramName.lowercaseString]; state = stateDispositionExpectSemicolon; } break; case stateDispositionParamUnquoted: if (UTF8String[i] <= 31 || UTF8String[i] >= 127) return nil; switch (UTF8String[i]) { case ' ': case '"': case '(': case ')': case ',': case '/': case ':': case '<': case '=': case '>': case '?': case '@': case '[': case '\\': case ']': case '{': case '}': return nil; case ';': paramValue = [OFString stringWithUTF8String: UTF8String + last length: i - last]; [params setObject: paramValue forKey: paramName.lowercaseString]; state = stateDispositionParamNameSkipSpace; break; } break; case stateDispositionExpectSemicolon: if (UTF8String[i] == ';') { state = stateDispositionParamNameSkipSpace; last = i + 1; } else if (UTF8String[i] != ' ') { objc_autoreleasePoolPop(pool); return nil; } break; } } if (state == stateDispositionParamUnquoted) { paramValue = [OFString stringWithUTF8String: UTF8String + last length: UTF8StringLength - last]; [params setObject: paramValue forKey: paramName.lowercaseString]; } else if (state != stateDispositionExpectSemicolon) { objc_autoreleasePoolPop(pool); return nil; } if (![type isEqual: @"attachment"] || (fileName = [params objectForKey: @"filename"]) == nil) { objc_autoreleasePoolPop(pool); return nil; } fileName = fileName.lastPathComponent; [fileName retain]; objc_autoreleasePoolPop(pool); return [fileName autorelease]; } @implementation OFHTTP - (instancetype)init { self = [super init]; @try { _method = OFHTTPRequestMethodGet; _clientHeaders = [[OFMutableDictionary alloc] initWithObject: @"OFHTTP" forKey: @"User-Agent"]; _HTTPClient = [[OFHTTPClient alloc] init]; _HTTPClient.delegate = self; _buffer = OFAllocMemory(1, [OFSystemInfo pageSize]); } @catch (id e) { [self release]; @throw e; } return self; } - (void)addHeader: (OFString *)header { size_t pos = [header rangeOfString: @":"].location; OFString *name, *value; if (pos == OFNotFound) { [OFStdErr writeLine: OF_LOCALIZED(@"invalid_input_header", @"%[prog]: Headers must to be in format name:value!", @"prog", [OFApplication programName])]; [OFApplication terminateWithStatus: 1]; } name = [header substringToIndex: pos] .stringByDeletingEnclosingWhitespaces; value = [header substringFromIndex: pos + 1] .stringByDeletingEnclosingWhitespaces; [_clientHeaders setObject: value forKey: name]; } - (void)setBody: (OFString *)path { OFString *contentLength = nil; [_body release]; _body = nil; if ([path isEqual: @"-"]) _body = [OFStdIn copy]; else { _body = [[OFFile alloc] initWithPath: path mode: @"r"]; @try { unsigned long long fileSize = [[OFFileManager defaultManager] attributesOfItemAtPath: path].fileSize; contentLength = [OFString stringWithFormat: @"%ju", fileSize]; [_clientHeaders setObject: contentLength forKey: @"Content-Length"]; } @catch (OFGetItemAttributesFailedException *e) { } } if (contentLength == nil) [_clientHeaders setObject: @"chunked" forKey: @"Transfer-Encoding"]; } - (void)setMethod: (OFString *)method { void *pool = objc_autoreleasePoolPush(); method = method.uppercaseString; @try { _method = OFHTTPRequestMethodParseString(method); } @catch (OFInvalidArgumentException *e) { [OFStdErr writeLine: OF_LOCALIZED(@"invalid_input_method", @"%[prog]: Invalid request method %[method]!", @"prog", [OFApplication programName], @"method", method)]; [OFApplication terminateWithStatus: 1]; } objc_autoreleasePoolPop(pool); } - (void)setProxy: (OFString *)proxy { @try { size_t pos = [proxy rangeOfString: @":" options: OFStringSearchBackwards].location; OFString *host; unsigned long long port; if (pos == OFNotFound) @throw [OFInvalidFormatException exception]; host = [proxy substringToIndex: pos]; port = [proxy substringFromIndex: pos + 1] .unsignedLongLongValue; if (port > UINT16_MAX) @throw [OFOutOfRangeException exception]; [OFTCPSocket setSOCKS5Host: host]; [OFTCPSocket setSOCKS5Port: (uint16_t)port]; } @catch (OFInvalidFormatException *e) { [OFStdErr writeLine: OF_LOCALIZED(@"invalid_input_proxy", @"%[prog]: Proxy must to be in format host:port!", @"prog", [OFApplication programName])]; [OFApplication terminateWithStatus: 1]; } } - (void)applicationDidFinishLaunching: (OFNotification *)notification { OFString *outputPath; const OFOptionsParserOption options[] = { { 'b', @"body", 1, NULL, NULL }, { 'c', @"continue", 0, &_continue, NULL }, { 'f', @"force", 0, &_force, NULL }, { 'h', @"help", 0, NULL, NULL }, { 'H', @"header", 1, NULL, NULL }, { 'm', @"method", 1, NULL, NULL }, { 'o', @"output", 1, NULL, &outputPath }, { 'O', @"detect-filename", 0, &_detectFileName, NULL }, { 'P', @"socks5-proxy", 1, NULL, NULL }, { 'q', @"quiet", 0, &_quiet, NULL }, { 'v', @"verbose", 0, &_verbose, NULL }, { '\0', @"insecure", 0, &_insecure, NULL }, { '\0', @"ignore-status", 0, &_ignoreStatus, NULL }, { '\0', nil, 0, NULL, NULL } }; OFOptionsParser *optionsParser; OFUnichar option; #ifdef OF_HAVE_SANDBOX OFSandbox *sandbox = [OFSandbox sandbox]; sandbox.allowsStdIO = true; sandbox.allowsReadingFiles = true; sandbox.allowsWritingFiles = true; sandbox.allowsCreatingFiles = true; sandbox.allowsIPSockets = true; sandbox.allowsDNS = true; sandbox.allowsUserDatabaseReading = true; sandbox.allowsTTY = true; /* Dropped after parsing options */ sandbox.allowsUnveil = true; [OFApplication of_activateSandbox: sandbox]; #endif #ifndef OF_AMIGAOS [OFLocale addLocalizationDirectoryIRI: [OFIRI fileIRIWithPath: @LOCALIZATION_DIR]]; #else [OFLocale addLocalizationDirectoryIRI: [OFIRI fileIRIWithPath: @"PROGDIR:/share/ofhttp/localization"]]; #endif optionsParser = [OFOptionsParser parserWithOptions: options]; while ((option = [optionsParser nextOption]) != '\0') { switch (option) { case 'b': [self setBody: optionsParser.argument]; break; case 'h': help(OFStdOut, true, 0); break; case 'H': [self addHeader: optionsParser.argument]; break; case 'm': [self setMethod: optionsParser.argument]; break; case 'P': [self setProxy: optionsParser.argument]; break; case ':': if (optionsParser.lastLongOption != nil) [OFStdErr writeLine: OF_LOCALIZED( @"long_argument_missing", @"%[prog]: Argument for option --%[opt] " @"missing", @"prog", [OFApplication programName], @"opt", optionsParser.lastLongOption)]; else { OFString *optStr = [OFString stringWithFormat: @"%C", optionsParser.lastOption]; [OFStdErr writeLine: OF_LOCALIZED( @"argument_missing", @"%[prog]: Argument for option -%[opt] " @"missing", @"prog", [OFApplication programName], @"opt", optStr)]; } [OFApplication terminateWithStatus: 1]; break; case '=': [OFStdErr writeLine: OF_LOCALIZED( @"option_takes_no_argument", @"%[prog]: Option --%[opt] takes no argument", @"prog", [OFApplication programName], @"opt", optionsParser.lastLongOption)]; [OFApplication terminateWithStatus: 1]; break; case '?': if (optionsParser.lastLongOption != nil) [OFStdErr writeLine: OF_LOCALIZED( @"unknown_long_option", @"%[prog]: Unknown option: --%[opt]", @"prog", [OFApplication programName], @"opt", optionsParser.lastLongOption)]; else { OFString *optStr = [OFString stringWithFormat: @"%C", optionsParser.lastOption]; [OFStdErr writeLine: OF_LOCALIZED( @"unknown_option", @"%[prog]: Unknown option: -%[opt]", @"prog", [OFApplication programName], @"opt", optStr)]; } [OFApplication terminateWithStatus: 1]; break; } } #ifdef OF_HAVE_SANDBOX if (outputPath != nil) [sandbox unveilPath: outputPath permissions: (_continue ? @"rwc" : @"wc")]; else [sandbox unveilPath: [[OFFileManager defaultManager] currentDirectoryPath] permissions: (_continue ? @"rwc" : @"wc")]; /* In case we use OpenSSL for HTTPS later */ [sandbox unveilPath: @"/etc/ssl" permissions: @"r"]; sandbox.allowsUnveil = false; [OFApplication of_activateSandbox: sandbox]; #endif _outputPath = [outputPath copy]; _IRIs = [optionsParser.remainingArguments copy]; if (_IRIs.count < 1) help(OFStdErr, false, 1); if (_quiet && _verbose) { [OFStdErr writeLine: OF_LOCALIZED(@"quiet_xor_verbose", @"%[prog]: -q / --quiet and -v / --verbose are mutually " @"exclusive!", @"prog", [OFApplication programName])]; [OFApplication terminateWithStatus: 1]; } if (_outputPath != nil && _detectFileName) { [OFStdErr writeLine: OF_LOCALIZED( @"output_xor_detect_filename", @"%[prog]: -o / --output and -O / --detect-filename are " @"mutually exclusive!", @"prog", [OFApplication programName])]; [OFApplication terminateWithStatus: 1]; } if (_outputPath != nil && _IRIs.count > 1) { [OFStdErr writeLine: OF_LOCALIZED( @"output_only_with_one_iri", @"%[prog]: Cannot use -o / --output when more than one IRI " @"has been specified!", @"prog", [OFApplication programName])]; [OFApplication terminateWithStatus: 1]; } if (_insecure) _HTTPClient.allowsInsecureRedirects = true; #ifdef OF_WINDOWS _useUnicode = [OFSystemInfo isWindowsNT]; #else _useUnicode = ([OFLocale encoding] == OFStringEncodingUTF8); #endif [self performSelector: @selector(downloadNextIRI) afterDelay: 0]; } - (void)client: (OFHTTPClient *)client didCreateTLSStream: (OFTLSStream *)stream request: (OFHTTPRequest *)request { /* Use setter instead of property access to work around GCC bug. */ [stream setVerifiesCertificates: !_insecure]; } - (void)client: (OFHTTPClient *)client wantsRequestBody: (OFStream *)body request: (OFHTTPRequest *)request { /* TODO: Do asynchronously and print status */ while (!_body.atEndOfStream) { char buffer[4096]; size_t length = [_body readIntoBuffer: buffer length: 4096]; [body writeBuffer: buffer length: length]; } } - (bool)client: (OFHTTPClient *)client shouldFollowRedirectToIRI: (OFIRI *)IRI statusCode: (short)statusCode request: (OFHTTPRequest *)request response: (OFHTTPResponse *)response { if (_verbose) { void *pool = objc_autoreleasePoolPush(); OFDictionary OF_GENERIC(OFString *, OFString *) *headers = response.headers; OFEnumerator *keyEnumerator = [headers keyEnumerator]; OFEnumerator *objectEnumerator = [headers objectEnumerator]; OFString *key, *object; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) [OFStdOut writeFormat: @" %@: %@\n", key, object]; objc_autoreleasePoolPop(pool); } if (!_quiet) { if (_useUnicode) [OFStdOut writeFormat: @"☇ %@", IRI.string]; else [OFStdOut writeFormat: @"< %@", IRI.string]; } _length = 0; return true; } - (bool)stream: (OFStream *)response didReadIntoBuffer: (void *)buffer length: (size_t)length exception: (id)exception { if (exception != nil) { OFString *IRI; [_progressBar stop]; [_progressBar draw]; [_progressBar release]; _progressBar = nil; if (!_quiet) { [OFStdOut writeString: @"\n "]; [OFStdOut writeLine: OF_LOCALIZED(@"download_error", @"Error!")]; } IRI = [_IRIs objectAtIndex: _IRIIndex - 1]; [OFStdErr writeLine: OF_LOCALIZED( @"download_failed_exception", @"%[prog]: Failed to download <%[iri]>!\n" @" %[exception]", @"prog", [OFApplication programName], @"iri", IRI, @"exception", exception)]; _errorCode = 1; [self performSelector: @selector(downloadNextIRI) afterDelay: 0]; return false; } [_output writeBuffer: buffer length: length]; _received += length; [_progressBar setReceived: _received]; if (response.atEndOfStream) { [_progressBar stop]; [_progressBar draw]; [_progressBar release]; _progressBar = nil; if (!_quiet) { [OFStdOut writeString: @"\n "]; [OFStdOut writeLine: OF_LOCALIZED(@"download_done", @"Done!")]; } [self performSelector: @selector(downloadNextIRI) afterDelay: 0]; return false; } return true; } - (void)client: (OFHTTPClient *)client didReceiveHeaders: (OFDictionary OF_GENERIC(OFString *, OFString *) *)headers statusCode: (short)statusCode request: (OFHTTPRequest *)request { if (statusCode != 206) _resumedFrom = 0; if (!_quiet) { OFString *lengthString = [headers objectForKey: @"Content-Length"]; OFString *type = [headers objectForKey: @"Content-Type"]; if (_useUnicode) [OFStdOut writeFormat: @" ➜ %hd\n", statusCode]; else [OFStdOut writeFormat: @" -> %hd\n", statusCode]; if (type == nil) type = OF_LOCALIZED(@"type_unknown", @"unknown"); if (lengthString != nil) { _length = lengthString.unsignedLongLongValue; if (_resumedFrom + _length >= GIBIBYTE) { lengthString = [OFString stringWithFormat: @"%,.2f", (float)(_resumedFrom + _length) / GIBIBYTE]; lengthString = OF_LOCALIZED(@"size_gib", @"%[num] GiB", @"num", lengthString); } else if (_resumedFrom + _length >= MEBIBYTE) { lengthString = [OFString stringWithFormat: @"%,.2f", (float)(_resumedFrom + _length) / MEBIBYTE]; lengthString = OF_LOCALIZED(@"size_mib", @"%[num] MiB", @"num", lengthString); } else if (_resumedFrom + _length >= KIBIBYTE) { lengthString = [OFString stringWithFormat: @"%,.2f", (float)(_resumedFrom + _length) / KIBIBYTE]; lengthString = OF_LOCALIZED(@"size_kib", @"%[num] KiB", @"num", lengthString); } else { lengthString = [OFString stringWithFormat: @"%jd", _resumedFrom + _length]; lengthString = OF_LOCALIZED(@"size_bytes", @"[" @" [" @" {'num == 1': '1 byte'}," @" {'': '%[num] bytes'}" @" ]" @"]".objectByParsingJSON, @"num", lengthString); } } else lengthString = OF_LOCALIZED(@"size_unknown", @"unknown"); if (_verbose) { void *pool = objc_autoreleasePoolPush(); OFEnumerator OF_GENERIC(OFString *) *keyEnumerator = [headers keyEnumerator]; OFEnumerator OF_GENERIC(OFString *) *objectEnumerator = [headers objectEnumerator]; OFString *key, *object; if (statusCode / 100 == 2 && _currentFileName != nil) { [OFStdOut writeString: @" "]; [OFStdOut writeLine: OF_LOCALIZED( @"info_name_unaligned", @"Name: %[name]", @"name", _currentFileName)]; } while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) [OFStdOut writeFormat: @" %@: %@\n", key, object]; objc_autoreleasePoolPop(pool); } else if (statusCode / 100 == 2 && !_detectFileNameRequest) { [OFStdOut writeString: @" "]; if (_currentFileName != nil) [OFStdOut writeLine: OF_LOCALIZED(@"info_name", @"Name: %[name]", @"name", _currentFileName)]; [OFStdOut writeString: @" "]; [OFStdOut writeLine: OF_LOCALIZED(@"info_type", @"Type: %[type]", @"type", type)]; [OFStdOut writeString: @" "]; [OFStdOut writeLine: OF_LOCALIZED(@"info_size", @"Size: %[size]", @"size", lengthString)]; } } } - (void)client: (OFHTTPClient *)client didPerformRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response exception: (id)exception { if (exception != nil) { if ([exception isKindOfClass: [OFResolveHostFailedException class]]) { if (!_quiet) [OFStdOut writeString: @"\n"]; [OFStdErr writeLine: OF_LOCALIZED( @"download_resolve_host_failed", @"%[prog]: Failed to download <%[iri]>!\n" @" Failed to resolve host: %[exception]", @"prog", [OFApplication programName], @"iri", request.IRI.string, @"exception", exception)]; } else if ([exception isKindOfClass: [OFConnectSocketFailedException class]]) { if (!_quiet) [OFStdOut writeString: @"\n"]; [OFStdErr writeLine: OF_LOCALIZED( @"download_failed_connection_failed", @"%[prog]: Failed to download <%[iri]>!\n" @" Connection failed: %[exception]", @"prog", [OFApplication programName], @"iri", request.IRI.string, @"exception", exception)]; } else if ([exception isKindOfClass: [OFInvalidServerResponseException class]]) { if (!_quiet) [OFStdOut writeString: @"\n"]; [OFStdErr writeLine: OF_LOCALIZED( @"download_failed_invalid_server_response", @"%[prog]: Failed to download <%[iri]>!\n" @" Invalid server response!", @"prog", [OFApplication programName], @"iri", request.IRI.string)]; } else if ([exception isKindOfClass: [OFUnsupportedProtocolException class]]) { if (!_quiet) [OFStdOut writeString: @"\n"]; [OFStdErr writeLine: OF_LOCALIZED(@"no_tls_support", @"%[prog]: No TLS support in ObjFW!\n" @" In order to download via HTTPS, you need to " @"either build ObjFW with TLS\n" @" support or preload a library adding TLS " @"support to ObjFW!", @"prog", [OFApplication programName])]; } else if ([exception isKindOfClass: [OFTLSHandshakeFailedException class]]) { OFString *error = OFTLSStreamErrorCodeDescription( ((OFTLSHandshakeFailedException *)exception) .errorCode); if (!_quiet) [OFStdOut writeString: @"\n"]; [OFStdErr writeLine: OF_LOCALIZED( @"download_failed_tls_handshake_failed", @"%[prog]: Failed to download <%[iri]>!\n" @" TLS handshake failed: %[error]", @"prog", [OFApplication programName], @"iri", request.IRI.string, @"error", error)]; } else if ([exception isKindOfClass: [OFReadOrWriteFailedException class]]) { OFString *error = OF_LOCALIZED( @"download_failed_read_or_write_failed_any", @"Read or write failed"); if (!_quiet) [OFStdOut writeString: @"\n"]; if ([exception isKindOfClass: [OFReadFailedException class]]) error = OF_LOCALIZED( @"download_failed_read_or_write_failed_" @"read", @"Read failed"); else if ([exception isKindOfClass: [OFWriteFailedException class]]) error = OF_LOCALIZED( @"download_failed_read_or_write_failed_" @"write", @"Write failed"); [OFStdErr writeLine: OF_LOCALIZED( @"download_failed_read_or_write_failed", @"%[prog]: Failed to download <%[iri]>!\n" @" %[error]: %[exception]", @"prog", [OFApplication programName], @"iri", request.IRI.string, @"error", error, @"exception", exception)]; } else if ([exception isKindOfClass: [OFHTTPRequestFailedException class]]) { short statusCode; OFString *codeString; if (_ignoreStatus) { exception = nil; goto after_exception_handling; } statusCode = response.statusCode; codeString = [OFString stringWithFormat: @"%hd %@", statusCode, OFHTTPStatusCodeString(statusCode)]; [OFStdErr writeLine: OF_LOCALIZED(@"download_failed", @"%[prog]: Failed to download <%[iri]>!\n" @" HTTP status code: %[code]", @"prog", [OFApplication programName], @"iri", request.IRI.string, @"code", codeString)]; } else @throw exception; _errorCode = 1; [self performSelector: @selector(downloadNextIRI) afterDelay: 0]; return; } after_exception_handling: if (_method == OFHTTPRequestMethodHead) goto next; if (_detectFileNameRequest) { _currentFileName = [fileNameFromContentDisposition( [response.headers objectForKey: @"Content-Disposition"]) copy]; _detectedFileName = true; /* Handle this IRI on the next -[downloadNextIRI] call */ _IRIIndex--; [self performSelector: @selector(downloadNextIRI) afterDelay: 0]; return; } if ([_outputPath isEqual: @"-"]) _output = [OFStdOut copy]; else { if (!_continue && !_force && [[OFFileManager defaultManager] fileExistsAtPath: _currentFileName]) { [OFStdErr writeLine: OF_LOCALIZED(@"output_already_exists", @"%[prog]: File %[filename] already exists!", @"prog", [OFApplication programName], @"filename", _currentFileName)]; _errorCode = 1; goto next; } @try { OFString *mode = (response.statusCode == 206 ? @"a" : @"w"); _output = [[OFFile alloc] initWithPath: _currentFileName mode: mode]; } @catch (OFOpenItemFailedException *e) { [OFStdErr writeLine: OF_LOCALIZED(@"failed_to_open_output", @"%[prog]: Failed to open file %[filename]: " @"%[exception]", @"prog", [OFApplication programName], @"filename", _currentFileName, @"exception", e)]; _errorCode = 1; goto next; } #ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES @try { OFString *IRIString = request.IRI.string; OFData *downloadedFromData = [OFData dataWithItems: IRIString.UTF8String count: IRIString.UTF8StringLength + 1]; [[OFFileManager defaultManager] setExtendedAttributeData: downloadedFromData forName: @"user.ofhttp." @"downloaded_from" ofItemAtPath: _currentFileName]; } @catch (OFSetItemAttributesFailedException *) { /* Ignore */ } #endif #ifdef OF_MACOS @try { OFString *quarantine = [OFString stringWithFormat: @"0000;%08" @PRIx64 @";ofhttp;", (uint64_t)[[OFDate date] timeIntervalSince1970]]; OFData *quarantineData = [OFData dataWithItems: quarantine.UTF8String count: quarantine.UTF8StringLength]; [[OFFileManager defaultManager] setExtendedAttributeData: quarantineData forName: @"com.apple.quarantine" ofItemAtPath: _currentFileName]; } @catch (OFSetItemAttributesFailedException *e) { /* Ignore */ } #endif } if (!_quiet) { _progressBar = [[ProgressBar alloc] initWithLength: _length resumedFrom: _resumedFrom useUnicode: _useUnicode]; [_progressBar setReceived: _received]; [_progressBar draw]; } [_currentFileName release]; _currentFileName = nil; response.delegate = self; [response asyncReadIntoBuffer: _buffer length: [OFSystemInfo pageSize]]; return; next: [_currentFileName release]; _currentFileName = nil; [self performSelector: @selector(downloadNextIRI) afterDelay: 0]; } - (void)downloadNextIRI { OFString *IRIString = nil; OFIRI *IRI; OFMutableDictionary *clientHeaders; OFHTTPRequest *request; _received = _length = _resumedFrom = 0; if (_output != OFStdOut) [_output release]; _output = nil; if (_IRIIndex >= _IRIs.count) [OFApplication terminateWithStatus: _errorCode]; @try { IRIString = [_IRIs objectAtIndex: _IRIIndex++]; IRI = [OFIRI IRIWithString: IRIString]; } @catch (OFInvalidFormatException *e) { [OFStdErr writeLine: OF_LOCALIZED(@"invalid_iri", @"%[prog]: Invalid IRI: <%[iri]>!", @"prog", [OFApplication programName], @"iri", IRIString)]; _errorCode = 1; goto next; } if (![IRI.scheme isEqual: @"http"] && ![IRI.scheme isEqual: @"https"]) { [OFStdErr writeLine: OF_LOCALIZED(@"invalid_scheme", @"%[prog]: Invalid scheme: <%[iri]>!", @"prog", [OFApplication programName], @"iri", IRIString)]; _errorCode = 1; goto next; } clientHeaders = [[_clientHeaders mutableCopy] autorelease]; if (_detectFileName && !_detectedFileName) { if (!_quiet) { if (_useUnicode) [OFStdOut writeFormat: @"⠒ %@", IRI.string]; else [OFStdOut writeFormat: @"? %@", IRI.string]; } request = [OFHTTPRequest requestWithIRI: IRI]; request.headers = clientHeaders; request.method = OFHTTPRequestMethodHead; _detectFileNameRequest = true; [_HTTPClient asyncPerformRequest: request]; return; } if (!_detectedFileName) { [_currentFileName release]; _currentFileName = nil; } else _detectedFileName = false; if (_currentFileName == nil) _currentFileName = [_outputPath copy]; if (_currentFileName == nil) _currentFileName = [IRI.path.lastPathComponent copy]; if ([_currentFileName isEqual: @"/"] || _currentFileName.length == 0) { [_currentFileName release]; _currentFileName = nil; } if (_currentFileName == nil) _currentFileName = @"unnamed"; if (_continue) { @try { unsigned long long size = [[OFFileManager defaultManager] attributesOfItemAtPath: _currentFileName].fileSize; OFString *range; if (size > ULLONG_MAX) @throw [OFOutOfRangeException exception]; _resumedFrom = (unsigned long long)size; range = [OFString stringWithFormat: @"bytes=%ju-", _resumedFrom]; [clientHeaders setObject: range forKey: @"Range"]; } @catch (OFGetItemAttributesFailedException *e) { } } if (!_quiet) { if (_useUnicode) [OFStdOut writeFormat: @"⇣ %@", IRI.string]; else [OFStdOut writeFormat: @"< %@", IRI.string]; } request = [OFHTTPRequest requestWithIRI: IRI]; request.headers = clientHeaders; request.method = _method; _detectFileNameRequest = false; [_HTTPClient asyncPerformRequest: request]; return; next: [self performSelector: @selector(downloadNextIRI) afterDelay: 0]; } @end objfw-1.1.6/utils/ofhttp/ProgressBar.h000066400000000000000000000026141465614216400177100ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #import "OFObject.h" @class OFDate; @class OFTimer; #define BPS_WINDOW_SIZE 10 @interface ProgressBar: OFObject { bool _useUnicode; unsigned long long _received, _lastReceived, _length, _resumedFrom; OFDate *_startDate, *_lastReceivedDate; OFTimer *_drawTimer, *_BPSTimer; bool _stopped; float _BPS; double _ETA; float _BPSWindow[BPS_WINDOW_SIZE]; size_t _BPSWindowIndex, _BPSWindowLength; } - (instancetype)initWithLength: (unsigned long long)length resumedFrom: (unsigned long long)resumedFrom useUnicode: (bool)useUnicode OF_DESIGNATED_INITIALIZER; - (void)setReceived: (unsigned long long)received; - (void)draw; - (void)calculateBPSAndETA; - (void)stop; @end objfw-1.1.6/utils/ofhttp/ProgressBar.m000066400000000000000000000201551465614216400177150ustar00rootroot00000000000000/* * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * 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 Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ #include "config.h" #include #import "OFDate.h" #import "OFStdIOStream.h" #import "OFTimer.h" #import "OFLocale.h" #import "ProgressBar.h" static const float oneKibibyte = 1024; static const float oneMebibyte = 1024 * 1024; static const float oneGibibyte = 1024 * 1024 * 1024; static const OFTimeInterval updateInterval = 0.1; #ifdef OF_MINT /* freemint-gcc does not have trunc() */ # define trunc(x) ((int64_t)(x)) #endif #ifndef HAVE_TRUNCF # define truncf(x) trunc(x) #endif @implementation ProgressBar - (instancetype)initWithLength: (unsigned long long)length resumedFrom: (unsigned long long)resumedFrom useUnicode: (bool)useUnicode { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); _useUnicode = useUnicode; _length = length; _resumedFrom = resumedFrom; _startDate = [[OFDate alloc] init]; _lastReceivedDate = [[OFDate alloc] init]; _drawTimer = [[OFTimer scheduledTimerWithTimeInterval: updateInterval target: self selector: @selector(draw) repeats: true] retain]; _BPSTimer = [[OFTimer scheduledTimerWithTimeInterval: 1.0 target: self selector: @selector( calculateBPSAndETA) repeats: true] retain]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [self stop]; [_startDate release]; [_lastReceivedDate release]; [_drawTimer release]; [_BPSTimer release]; [super dealloc]; } - (void)setReceived: (unsigned long long)received { _received = received; } - (void)_drawProgress { float bars, percent; int columns, barWidth; if ((columns = OFStdOut.columns) >= 0) { if (columns > 37) barWidth = columns - 37; else barWidth = 0; } else barWidth = 43; bars = (float)(_resumedFrom + _received) / (float)(_resumedFrom + _length) * barWidth; percent = (float)(_resumedFrom + _received) / (float)(_resumedFrom + _length) * 100; if (_useUnicode) { [OFStdOut writeString: @"\r ▕"]; for (size_t i = 0; i < (size_t)bars; i++) [OFStdOut writeString: @"█"]; if (bars < barWidth) { float rem = bars - truncf(bars); if (rem >= 0.875) [OFStdOut writeString: @"▉"]; else if (rem >= 0.75) [OFStdOut writeString: @"▊"]; else if (rem >= 0.625) [OFStdOut writeString: @"▋"]; else if (rem >= 0.5) [OFStdOut writeString: @"▌"]; else if (rem >= 0.375) [OFStdOut writeString: @"▍"]; else if (rem >= 0.25) [OFStdOut writeString: @"▎"]; else if (rem >= 0.125) [OFStdOut writeString: @"▏"]; else [OFStdOut writeString: @" "]; for (size_t i = 0; i < barWidth - (size_t)bars - 1; i++) [OFStdOut writeString: @" "]; } [OFStdOut writeFormat: @"▏ %,6.2f%% ", percent]; } else { [OFStdOut writeString: @"\r ["]; for (size_t i = 0; i < (size_t)bars; i++) [OFStdOut writeString: @"#"]; if (bars < barWidth) { float rem = bars - truncf(bars); if (rem >= 0.75) [OFStdOut writeString: @"O"]; else if (rem >= 0.5) [OFStdOut writeString: @"o"]; else if (rem >= 0.25) [OFStdOut writeString: @"."]; else [OFStdOut writeString: @" "]; for (size_t i = 0; i < barWidth - (size_t)bars - 1; i++) [OFStdOut writeString: @" "]; } [OFStdOut writeFormat: @"] %,6.2f%% ", percent]; } if (percent == 100) { double timeInterval = -_startDate.timeIntervalSinceNow; _BPS = (float)_received / (float)timeInterval; _ETA = timeInterval; } if (isinf(_ETA)) [OFStdOut writeString: @"--:--:-- "]; else if (_ETA >= 99 * 3600) { OFString *num = [OFString stringWithFormat: @"%,4.2f", _ETA / (24 * 3600)]; [OFStdOut writeString: OF_LOCALIZED(@"eta_days", @"%[num] d ", @"num", num)]; } else [OFStdOut writeFormat: @"%2u:%02u:%02u ", (uint8_t)(_ETA / 3600), (uint8_t)(_ETA / 60) % 60, (uint8_t)_ETA % 60]; if (_BPS >= oneGibibyte) { OFString *num = [OFString stringWithFormat: @"%,7.2f", _BPS / oneGibibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_gibs", @"%[num] GiB/s", @"num", num)]; } else if (_BPS >= oneMebibyte) { OFString *num = [OFString stringWithFormat: @"%,7.2f", _BPS / oneMebibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_mibs", @"%[num] MiB/s", @"num", num)]; } else if (_BPS >= oneKibibyte) { OFString *num = [OFString stringWithFormat: @"%,7.2f", _BPS / oneKibibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_kibs", @"%[num] KiB/s", @"num", num)]; } else { OFString *num = [OFString stringWithFormat: @"%,7.2f", _BPS]; [OFStdOut writeString: OF_LOCALIZED(@"progress_bps", @"%[num] B/s ", @"num", num)]; } } - (void)_drawReceived { [OFStdOut writeString: @"\r "]; if (_resumedFrom + _received >= oneGibibyte) { OFString *num = [OFString stringWithFormat: @"%,7.2f", (float)(_resumedFrom + _received) / oneGibibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_gib", @"%[num] GiB", @"num", num)]; } else if (_resumedFrom + _received >= oneMebibyte) { OFString *num = [OFString stringWithFormat: @"%,7.2f", (float)(_resumedFrom + _received) / oneMebibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_mib", @"%[num] MiB", @"num", num)]; } else if (_resumedFrom + _received >= oneKibibyte) { OFString *num = [OFString stringWithFormat: @"%,7.2f", (float)(_resumedFrom + _received) / oneKibibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_kib", @"%[num] KiB", @"num", num)]; } else { OFString *num = [OFString stringWithFormat: @"%jd", _resumedFrom + _received]; [OFStdOut writeString: OF_LOCALIZED(@"progress_bytes", @"[" @" [" @" {'num == 1': '1 byte '}," @" {'': '%[num] bytes'}" @" ]" @"]".objectByParsingJSON, @"num", num)]; } [OFStdOut writeString: @" "]; if (_stopped) _BPS = (float)_received / -(float)_startDate.timeIntervalSinceNow; if (_BPS >= oneGibibyte) { OFString *num = [OFString stringWithFormat: @"%,7.2f", _BPS / oneGibibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_gibs", @"%[num] GiB/s", @"num", num)]; } else if (_BPS >= oneMebibyte) { OFString *num = [OFString stringWithFormat: @"%,7.2f", _BPS / oneMebibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_mibs", @"%[num] MiB/s", @"num", num)]; } else if (_BPS >= oneKibibyte) { OFString *num = [OFString stringWithFormat: @"%,7.2f", _BPS / oneKibibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_kibs", @"%[num] KiB/s", @"num", num)]; } else { OFString *num = [OFString stringWithFormat: @"%,7.2f", _BPS]; [OFStdOut writeString: OF_LOCALIZED(@"progress_bps", @"%[num] B/s ", @"num", num)]; } } - (void)draw { if (_length > 0) [self _drawProgress]; else [self _drawReceived]; } - (void)calculateBPSAndETA { _BPSWindow[_BPSWindowIndex++ % BPS_WINDOW_SIZE] = (float)(_received - _lastReceived) / -(float)_lastReceivedDate.timeIntervalSinceNow; if (_BPSWindowLength < BPS_WINDOW_SIZE) _BPSWindowLength++; _BPS = 0; for (size_t i = 0; i < _BPSWindowLength; i++) _BPS += _BPSWindow[i]; _BPS /= _BPSWindowLength; _ETA = (double)(_length - _received) / _BPS; _lastReceived = _received; [_lastReceivedDate release]; _lastReceivedDate = [[OFDate alloc] init]; } - (void)stop { [_drawTimer invalidate]; [_BPSTimer invalidate]; _stopped = true; } @end objfw-1.1.6/utils/ofhttp/localization/000077500000000000000000000000001465614216400177735ustar00rootroot00000000000000objfw-1.1.6/utils/ofhttp/localization/de.json000066400000000000000000000115011465614216400212540ustar00rootroot00000000000000/* * German localization for ofhttp. * * Copyright (c) 2017-2024 Jonathan Schleifer * * Permission to use, copy, modify, and/or distribute this localization for * any purpose with or without fee is hereby granted. */ /* vim: se ft=javascript sw=4 et: */ { usage: "Benutzung: %[prog] -[cehHmoOPqv] iri1 [iri2 ...]", full_usage: [ "Optionen:\n", " -b --body= Angegebene Datei als Body übergeben\n", " (- für Standard-Eingabe)\n", " -c --continue Download von existierender Datei ", "fortsetzen\n", " -f --force Existierende Datei überschreiben\n", " -h --help Diese Hilfe anzeigen\n", " -H --header= Einen Header (z.B. X-Foo:Bar) hinzufügen\n", " -m --method= HTTP Request-Methode setzen\n", " -o --output= Ausgabe-Dateiname angeben\n", " -O --detect-filename Dateiname mittels HEAD-Request ermitteln\n", " -P --proxy= SOCKS5-Proxy angeben\n", " -q --quiet Ruhiger Modus (keine Ausgabe außer Fehler)", "\n", " -v --verbose Ausführlicher Modus (gibt Header aus)\n", " --insecure TLS-Fehler ignorieren und unsichere\n", " Weiterleitungen erlauben\n", " --ignore-status HTTP Status-Code ignorieren" ], invalid_input_header: "%[prog]: Header müssen im Format Name:Wert sein!", invalid_input_method: "%[prog]: Ungültige Request-Methode %[method]!", invalid_input_proxy: "%[prog]: Proxy muss im Format Host:Port sein!", long_argument_missing: "%[prog]: Argument für Option --%[opt] fehlt", argument_missing: "%[prog]: Argument für option -%[opt] fehlt", option_takes_no_argument: "%[prog]: Option --%[opt] nimmt kein Argument", unknown_long_option: "%[prog]: Unbekannte Option: --%[opt]", unknown_option: "%[prog]: Unbekannte Option: -%[opt]", quiet_xor_verbose: [ "%[prog]: -q / --quiet und -v / --verbose schließen sich gegenseitig ", "aus!" ], output_xor_detect_filename: [ "%[prog]: -o / --output und -O / --detect-filename schließen sich ", "gegenseitig aus!" ], output_only_with_one_iri: [ "%[prog]: -o / --output kann nicht mit mehr als einer IRI benutzt ", "werden!" ], download_resolve_host_failed: [ "%[prog]: Fehler beim Download von <%[iri]>!\n", " Host auflösen fehlgeschlagen: %[exception]" ], download_failed_connection_failed: [ "%[prog]: Fehler beim Download von <%[iri]>!\n", " Verbindung fehlgeschlagen: %[exception]" ], download_failed_invalid_server_response: [ "%[prog]: Fehler beim Download von <%[iri]>!\n", " Ungültige Antwort vom Server!" ], no_tls_support: [ "%[prog]: Keine TLS-Unterstützung in ObjFW!\n", " Um via HTTPS runterzuladen müssen Sie entweder ObjFW mit TLS-", "Unterstützung\n", " kompilieren oder eine Bibliothek mittels „preload” laden, welche ", "TLS-Support\n", " zu ObjFW hinzufügt!" ], download_failed_tls_handshake_failed: [ "%[prog]: Fehler beim Download von <%[iri]>!\n", " TLS-Handshake fehlgeschlagen: %[error]" ], download_failed_read_or_write_failed_any: "Lesen oder Schreiben", download_failed_read_or_write_failed_read: "Lesen", download_failed_read_or_write_failed_write: "Schreiben", download_failed_read_or_write_failed: [ "%[prog]: Fehler beim Download von <%[iri]>!\n", " %[error]: %[exception]" ], download_failed: [ "%[prog]: Fehler beim Download von <%[iri]>!\n", " HTTP Status-Code: %[code]" ], download_error: "Fehler!", download_failed_exception: [ "%[prog]: Fehler beim Download von <%[iri]>!\n", " %[exception]" ], download_done: "Fertig!", invalid_iri: "%[prog]: Ungültige IRI: <%[iri]>!", invalid_scheme: "%[prog]: Ungültiges Schema: <%[iri]>!", type_unknown: "unbekannt", size_gib: "%[num] GiB", size_mib: "%[num] MiB", size_kib: "%[num] KiB", size_bytes: [ [ {"num == 1": "1 Byte"}, {"": "%[num] Bytes"} ] ], size_unknown: "unbekannt", info_name_unaligned: "Name: %[name]", info_name: "Name: %[name]", info_type: "Typ: %[type]", info_size: "Größe: %[size]", output_already_exists: "%[prog]: Datei %[filename] existiert bereits!", failed_to_open_output: [ "%[prog]: Kann Datei %[filename] nicht öffnen: %[exception]" ], eta_days: "%[num] t ", progress_bytes: [ [ {"num == 1": "1 Byte "}, {"": "%[num] Bytes"} ] ], } objfw-1.1.6/utils/ofhttp/localization/localizations.json000066400000000000000000000006021465614216400235370ustar00rootroot00000000000000/* * Localization mapping for ofhttp. * * Copyright (c) 2017-2023 Jonathan Schleifer * * Permission to use, copy, modify, and/or distribute this mapping for any * purpose with or without fee is hereby granted. */ /* vim: se ft=javascript sw=4 et: */ { de: { "": "de" }, deutsch: { "": "de" }, german: { "": "de" }, }