libsml-0.1.1+git20170608/0000755000175000017500000000000013136144555014225 5ustar andreasandreaslibsml-0.1.1+git20170608/COPYING0000644000175000017500000010451312734144572015266 0ustar andreasandreas 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 . libsml-0.1.1+git20170608/examples/0000755000175000017500000000000012734144572016045 5ustar andreasandreaslibsml-0.1.1+git20170608/examples/sml_server.c0000644000175000017500000000500412734144572020371 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include #include #include #include #include #include #include #include #include #include int serial_port_open(const char* device) { int bits; struct termios config; memset(&config, 0, sizeof(config)); int fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY); if (fd < 0) { fprintf(stderr,"error: open(%s): %s\n", device, strerror(errno)); return -1; } // set RTS ioctl(fd, TIOCMGET, &bits); bits |= TIOCM_RTS; ioctl(fd, TIOCMSET, &bits); tcgetattr( fd, &config ) ; // set 8-N-1 config.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); config.c_oflag &= ~OPOST; config.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); config.c_cflag &= ~(CSIZE | PARENB | PARODD | CSTOPB); config.c_cflag |= CS8; // set speed to 9600 baud cfsetispeed( &config, B9600); cfsetospeed( &config, B9600); tcsetattr(fd, TCSANOW, &config); return fd; } void transport_receiver(unsigned char *buffer, size_t buffer_len) { // the buffer contains the whole message, with transport escape sequences. // these escape sequences are stripped here. sml_file *file = sml_file_parse(buffer + 8, buffer_len - 16); // the sml file is parsed now // read here some values .. // this prints some information about the file sml_file_print(file); // free the malloc'd memory sml_file_free(file); } int main(void) { // this example assumes that a EDL21 meter sending SML messages via a // serial device. Adjust as needed. char *device = "/dev/cu.usbserial"; int fd = serial_port_open(device); if (fd > 0) { // listen on the serial device, this call is blocking. sml_transport_listen(fd, &transport_receiver); close(fd); } return 0; } libsml-0.1.1+git20170608/examples/Makefile0000644000175000017500000000056312734144572017511 0ustar andreasandreasUNAME := $(shell uname) CFLAGS += -I../sml/include/ -g -std=c99 -Wall -Wextra -pedantic OBJS = sml_server.o LIBSML = ../sml/lib/libsml.a ifeq ($(UNAME), Linux) LIBS = -luuid endif sml_server : $(OBJS) $(LIBSML) $(CC) $(CFLAGS) $(OBJS) $(LIBS) $(LIBSML) -o sml_server $(LIBS) %.o : %.c $(CC) $(CFLAGS) -c $^ -o $@ .PHONY: clean clean: @rm -f *.o @rm -f sml_server libsml-0.1.1+git20170608/README.md0000644000175000017500000000153312734144572015510 0ustar andreasandreaslibSML ====== libSML is a library which implements the Smart Message Language (SML) protocol specified by VDE's Forum Netztechnik/Netzbetrieb (FNN). It can be utilized to communicate to FNN specified Smart Meters or Smart Meter components (EDL/MUC). ### Usage An example how to use libSML is in the examples directory. #### Dependencies Ubuntu apt-get install uuid-dev uuid-runtime #### Compilation make The resulting binaries are located in sml/lib ### License Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed - DAI-Labor, TU-Berlin libSML is licensed with the GPL, other licenses are available. ### Thanks Steffen Vogel, Thorben Thuermer, Daniel Pauli, He Bowei #### Thirdparty Acknowledgements This product includes software developed for the Unity Project, by Mike Karlesky, Mark VanderVoord, and Greg Williams and other contributorslibsml-0.1.1+git20170608/test/0000755000175000017500000000000012734144572015206 5ustar andreasandreaslibsml-0.1.1+git20170608/test/unity/0000755000175000017500000000000012734144572016356 5ustar andreasandreaslibsml-0.1.1+git20170608/test/unity/unity_fixture_malloc_overrides.h0000644000175000017500000000112712734144572025057 0ustar andreasandreas//- Copyright (c) 2010 James Grenning and Contributed to Unity Project /* ========================================== Unity Project - A Test Framework for C Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams [Released under MIT License. Please refer to license.txt for details] ========================================== */ #ifndef UNITY_FIXTURE_MALLOC_OVERRIDES_H_ #define UNITY_FIXTURE_MALLOC_OVERRIDES_H_ #define malloc unity_malloc #define calloc unity_calloc #define realloc unity_realloc #define free unity_free #endif /* UNITY_FIXTURE_MALLOC_OVERRIDES_H_ */ libsml-0.1.1+git20170608/test/unity/unity.c0000644000175000017500000010262412734144572017677 0ustar andreasandreas/* ========================================== Unity Project - A Test Framework for C Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams [Released under MIT License. Please refer to license.txt for details] ========================================== */ #include "unity.h" #include #include #define UNITY_FAIL_AND_BAIL { Unity.CurrentTestFailed = 1; UNITY_OUTPUT_CHAR('\n'); longjmp(Unity.AbortFrame, 1); } #define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; UNITY_OUTPUT_CHAR('\n'); longjmp(Unity.AbortFrame, 1); } /// return prematurely if we are already in failure or ignore state #define UNITY_SKIP_EXECUTION { if ((Unity.CurrentTestFailed != 0) || (Unity.CurrentTestIgnored != 0)) {return;} } #define UNITY_PRINT_EOL { UNITY_OUTPUT_CHAR('\n'); } struct _Unity Unity = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , { 0 } }; const char* UnityStrNull = "NULL"; const char* UnityStrSpacer = ". "; const char* UnityStrExpected = " Expected "; const char* UnityStrWas = " Was "; const char* UnityStrTo = " To "; const char* UnityStrElement = " Element "; const char* UnityStrByte = " Byte "; const char* UnityStrMemory = " Memory Mismatch."; const char* UnityStrDelta = " Values Not Within Delta "; const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless."; const char* UnityStrNullPointerForExpected= " Expected pointer to be NULL"; const char* UnityStrNullPointerForActual = " Actual pointer was NULL"; const char* UnityStrInf = "Infinity"; const char* UnityStrNegInf = "Negative Infinity"; const char* UnityStrNaN = "NaN"; // Dividing by these constants produces +/- infinity. // The rationale is given in UnityAssertFloatIsInf's body. static const _UF f_zero = 0.0f; #ifndef UNITY_EXCLUDE_DOUBLE static const _UD d_zero = 0.0; #endif // compiler-generic print formatting masks const _U_UINT UnitySizeMask[] = { 255u, // 0xFF 65535u, // 0xFFFF 65535u, 4294967295u, // 0xFFFFFFFF 4294967295u, 4294967295u, 4294967295u #ifdef UNITY_SUPPORT_64 ,0xFFFFFFFFFFFFFFFF #endif }; void UnityPrintFail(void); void UnityPrintOk(void); //----------------------------------------------- // Pretty Printers & Test Result Output Handlers //----------------------------------------------- void UnityPrint(const char* string) { const char* pch = string; if (pch != NULL) { while (*pch) { // printable characters plus CR & LF are printed if ((*pch <= 126) && (*pch >= 32)) { UNITY_OUTPUT_CHAR(*pch); } //write escaped carriage returns else if (*pch == 13) { UNITY_OUTPUT_CHAR('\\'); UNITY_OUTPUT_CHAR('r'); } //write escaped line feeds else if (*pch == 10) { UNITY_OUTPUT_CHAR('\\'); UNITY_OUTPUT_CHAR('n'); } // unprintable characters are shown as codes else { UNITY_OUTPUT_CHAR('\\'); UnityPrintNumberHex((_U_SINT)*pch, 2); } pch++; } } } //----------------------------------------------- void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style) { if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) { UnityPrintNumber(number); } else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT) { UnityPrintNumberUnsigned( (_U_UINT)number & UnitySizeMask[((_U_UINT)style & (_U_UINT)0x0F) - 1] ); } else { UnityPrintNumberHex((_U_UINT)number, (style & 0x000F) << 1); } } //----------------------------------------------- /// basically do an itoa using as little ram as possible void UnityPrintNumber(const _U_SINT number_to_print) { _U_SINT divisor = 1; _U_SINT next_divisor; _U_SINT number = number_to_print; if (number < 0) { UNITY_OUTPUT_CHAR('-'); number = -number; } // figure out initial divisor while (number / divisor > 9) { next_divisor = divisor * 10; if (next_divisor > divisor) divisor = next_divisor; else break; } // now mod and print, then divide divisor do { UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10))); divisor /= 10; } while (divisor > 0); } //----------------------------------------------- /// basically do an itoa using as little ram as possible void UnityPrintNumberUnsigned(const _U_UINT number) { _U_UINT divisor = 1; _U_UINT next_divisor; // figure out initial divisor while (number / divisor > 9) { next_divisor = divisor * 10; if (next_divisor > divisor) divisor = next_divisor; else break; } // now mod and print, then divide divisor do { UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10))); divisor /= 10; } while (divisor > 0); } //----------------------------------------------- void UnityPrintNumberHex(const _U_UINT number, const char nibbles_to_print) { _U_UINT nibble; char nibbles = nibbles_to_print; UNITY_OUTPUT_CHAR('0'); UNITY_OUTPUT_CHAR('x'); while (nibbles > 0) { nibble = (number >> (--nibbles << 2)) & 0x0000000F; if (nibble <= 9) { UNITY_OUTPUT_CHAR((char)('0' + nibble)); } else { UNITY_OUTPUT_CHAR((char)('A' - 10 + nibble)); } } } //----------------------------------------------- void UnityPrintMask(const _U_UINT mask, const _U_UINT number) { _U_UINT current_bit = (_U_UINT)1 << (UNITY_INT_WIDTH - 1); _US32 i; for (i = 0; i < UNITY_INT_WIDTH; i++) { if (current_bit & mask) { if (current_bit & number) { UNITY_OUTPUT_CHAR('1'); } else { UNITY_OUTPUT_CHAR('0'); } } else { UNITY_OUTPUT_CHAR('X'); } current_bit = current_bit >> 1; } } //----------------------------------------------- #ifdef UNITY_FLOAT_VERBOSE void UnityPrintFloat(_UF number) { char TempBuffer[32]; sprintf(TempBuffer, "%.6f", number); UnityPrint(TempBuffer); } #endif //----------------------------------------------- void UnityPrintFail(void) { UnityPrint("FAIL"); } void UnityPrintOk(void) { UnityPrint("OK"); } //----------------------------------------------- void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line) { UnityPrint(file); UNITY_OUTPUT_CHAR(':'); UnityPrintNumber(line); UNITY_OUTPUT_CHAR(':'); UnityPrint(Unity.CurrentTestName); UNITY_OUTPUT_CHAR(':'); } //----------------------------------------------- void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line) { UnityTestResultsBegin(Unity.TestFile, line); UnityPrint("FAIL:"); } //----------------------------------------------- void UnityConcludeTest(void) { if (Unity.CurrentTestIgnored) { Unity.TestIgnores++; } else if (!Unity.CurrentTestFailed) { UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber); UnityPrint("PASS"); UNITY_PRINT_EOL; } else { Unity.TestFailures++; } Unity.CurrentTestFailed = 0; Unity.CurrentTestIgnored = 0; } //----------------------------------------------- void UnityAddMsgIfSpecified(const char* msg) { if (msg) { UnityPrint(UnityStrSpacer); UnityPrint(msg); } } //----------------------------------------------- void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual) { UnityPrint(UnityStrExpected); if (expected != NULL) { UNITY_OUTPUT_CHAR('\''); UnityPrint(expected); UNITY_OUTPUT_CHAR('\''); } else { UnityPrint(UnityStrNull); } UnityPrint(UnityStrWas); if (actual != NULL) { UNITY_OUTPUT_CHAR('\''); UnityPrint(actual); UNITY_OUTPUT_CHAR('\''); } else { UnityPrint(UnityStrNull); } } //----------------------------------------------- // Assertion & Control Helpers //----------------------------------------------- int UnityCheckArraysForNull(const void* expected, const void* actual, const UNITY_LINE_TYPE lineNumber, const char* msg) { //return true if they are both NULL if ((expected == NULL) && (actual == NULL)) return 1; //throw error if just expected is NULL if (expected == NULL) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrNullPointerForExpected); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } //throw error if just actual is NULL if (actual == NULL) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrNullPointerForActual); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } //return false if neither is NULL return 0; } //----------------------------------------------- // Assertion Functions //----------------------------------------------- void UnityAssertBits(const _U_SINT mask, const _U_SINT expected, const _U_SINT actual, const char* msg, const UNITY_LINE_TYPE lineNumber) { UNITY_SKIP_EXECUTION; if ((mask & expected) != (mask & actual)) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrExpected); UnityPrintMask(mask, expected); UnityPrint(UnityStrWas); UnityPrintMask(mask, actual); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } } //----------------------------------------------- void UnityAssertEqualNumber(const _U_SINT expected, const _U_SINT actual, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style) { UNITY_SKIP_EXECUTION; if (expected != actual) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrExpected); UnityPrintNumberByStyle(expected, style); UnityPrint(UnityStrWas); UnityPrintNumberByStyle(actual, style); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } } //----------------------------------------------- void UnityAssertEqualIntArray(const _U_SINT* expected, const _U_SINT* actual, const _UU32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style) { _UU32 elements = num_elements; const _US8* ptr_exp = (_US8*)expected; const _US8* ptr_act = (_US8*)actual; UNITY_SKIP_EXECUTION; if (elements == 0) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrPointless); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1) return; switch(style) { case UNITY_DISPLAY_STYLE_HEX8: case UNITY_DISPLAY_STYLE_INT8: case UNITY_DISPLAY_STYLE_UINT8: while (elements--) { if (*ptr_exp != *ptr_act) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT); UnityPrint(UnityStrExpected); UnityPrintNumberByStyle(*ptr_exp, style); UnityPrint(UnityStrWas); UnityPrintNumberByStyle(*ptr_act, style); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } ptr_exp += 1; ptr_act += 1; } break; case UNITY_DISPLAY_STYLE_HEX16: case UNITY_DISPLAY_STYLE_INT16: case UNITY_DISPLAY_STYLE_UINT16: while (elements--) { if (*(_US16*)ptr_exp != *(_US16*)ptr_act) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT); UnityPrint(UnityStrExpected); UnityPrintNumberByStyle(*(_US16*)ptr_exp, style); UnityPrint(UnityStrWas); UnityPrintNumberByStyle(*(_US16*)ptr_act, style); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } ptr_exp += 2; ptr_act += 2; } break; #ifdef UNITY_SUPPORT_64 case UNITY_DISPLAY_STYLE_HEX64: case UNITY_DISPLAY_STYLE_INT64: case UNITY_DISPLAY_STYLE_UINT64: while (elements--) { if (*(_US64*)ptr_exp != *(_US64*)ptr_act) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT); UnityPrint(UnityStrExpected); UnityPrintNumberByStyle(*(_US64*)ptr_exp, style); UnityPrint(UnityStrWas); UnityPrintNumberByStyle(*(_US64*)ptr_act, style); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } ptr_exp += 8; ptr_act += 8; } break; #endif default: while (elements--) { if (*(_US32*)ptr_exp != *(_US32*)ptr_act) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT); UnityPrint(UnityStrExpected); UnityPrintNumberByStyle(*(_US32*)ptr_exp, style); UnityPrint(UnityStrWas); UnityPrintNumberByStyle(*(_US32*)ptr_act, style); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } ptr_exp += 4; ptr_act += 4; } break; } } //----------------------------------------------- #ifndef UNITY_EXCLUDE_FLOAT void UnityAssertEqualFloatArray(const _UF* expected, const _UF* actual, const _UU32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber) { _UU32 elements = num_elements; const _UF* ptr_expected = expected; const _UF* ptr_actual = actual; _UF diff, tol; UNITY_SKIP_EXECUTION; if (elements == 0) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrPointless); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1) return; while (elements--) { diff = *ptr_expected - *ptr_actual; if (diff < 0.0f) diff = 0.0f - diff; tol = UNITY_FLOAT_PRECISION * *ptr_expected; if (tol < 0.0f) tol = 0.0f - tol; //This first part of this condition will catch any NaN or Infinite values if ((diff * 0.0f != 0.0f) || (diff > tol)) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT); #ifdef UNITY_FLOAT_VERBOSE UnityPrint(UnityStrExpected); UnityPrintFloat(*ptr_expected); UnityPrint(UnityStrWas); UnityPrintFloat(*ptr_actual); #else UnityPrint(UnityStrDelta); #endif UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } ptr_expected++; ptr_actual++; } } //----------------------------------------------- void UnityAssertFloatsWithin(const _UF delta, const _UF expected, const _UF actual, const char* msg, const UNITY_LINE_TYPE lineNumber) { _UF diff = actual - expected; _UF pos_delta = delta; UNITY_SKIP_EXECUTION; if (diff < 0.0f) { diff = 0.0f - diff; } if (pos_delta < 0.0f) { pos_delta = 0.0f - pos_delta; } //This first part of this condition will catch any NaN or Infinite values if ((diff * 0.0f != 0.0f) || (pos_delta < diff)) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_FLOAT_VERBOSE UnityPrint(UnityStrExpected); UnityPrintFloat(expected); UnityPrint(UnityStrWas); UnityPrintFloat(actual); #else UnityPrint(UnityStrDelta); #endif UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } } //----------------------------------------------- void UnityAssertFloatIsInf(const _UF actual, const char* msg, const UNITY_LINE_TYPE lineNumber) { UNITY_SKIP_EXECUTION; // In Microsoft Visual C++ Express Edition 2008, // if ((1.0f / f_zero) != actual) // produces // error C2124: divide or mod by zero // As a workaround, place 0 into a variable. if ((1.0f / f_zero) != actual) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_FLOAT_VERBOSE UnityPrint(UnityStrExpected); UnityPrint(UnityStrInf); UnityPrint(UnityStrWas); UnityPrintFloat(actual); #else UnityPrint(UnityStrDelta); #endif UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } } //----------------------------------------------- void UnityAssertFloatIsNegInf(const _UF actual, const char* msg, const UNITY_LINE_TYPE lineNumber) { UNITY_SKIP_EXECUTION; // The rationale for not using 1.0f/0.0f is given in UnityAssertFloatIsInf's body. if ((-1.0f / f_zero) != actual) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_FLOAT_VERBOSE UnityPrint(UnityStrExpected); UnityPrint(UnityStrNegInf); UnityPrint(UnityStrWas); UnityPrintFloat(actual); #else UnityPrint(UnityStrDelta); #endif UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } } //----------------------------------------------- void UnityAssertFloatIsNaN(const _UF actual, const char* msg, const UNITY_LINE_TYPE lineNumber) { UNITY_SKIP_EXECUTION; if (actual == actual) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_FLOAT_VERBOSE UnityPrint(UnityStrExpected); UnityPrint(UnityStrNaN); UnityPrint(UnityStrWas); UnityPrintFloat(actual); #else UnityPrint(UnityStrDelta); #endif UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } } #endif //not UNITY_EXCLUDE_FLOAT //----------------------------------------------- #ifndef UNITY_EXCLUDE_DOUBLE void UnityAssertEqualDoubleArray(const _UD* expected, const _UD* actual, const _UU32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber) { _UU32 elements = num_elements; const _UD* ptr_expected = expected; const _UD* ptr_actual = actual; _UD diff, tol; UNITY_SKIP_EXECUTION; if (elements == 0) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrPointless); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1) return; while (elements--) { diff = *ptr_expected - *ptr_actual; if (diff < 0.0) diff = 0.0 - diff; tol = UNITY_DOUBLE_PRECISION * *ptr_expected; if (tol < 0.0) tol = 0.0 - tol; //This first part of this condition will catch any NaN or Infinite values if ((diff * 0.0 != 0.0) || (diff > tol)) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT); #ifdef UNITY_DOUBLE_VERBOSE UnityPrint(UnityStrExpected); UnityPrintFloat((float)(*ptr_expected)); UnityPrint(UnityStrWas); UnityPrintFloat((float)(*ptr_actual)); #else UnityPrint(UnityStrDelta); #endif UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } ptr_expected++; ptr_actual++; } } //----------------------------------------------- void UnityAssertDoublesWithin(const _UD delta, const _UD expected, const _UD actual, const char* msg, const UNITY_LINE_TYPE lineNumber) { _UD diff = actual - expected; _UD pos_delta = delta; UNITY_SKIP_EXECUTION; if (diff < 0.0) { diff = 0.0 - diff; } if (pos_delta < 0.0) { pos_delta = 0.0 - pos_delta; } //This first part of this condition will catch any NaN or Infinite values if ((diff * 0.0 != 0.0) || (pos_delta < diff)) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_DOUBLE_VERBOSE UnityPrint(UnityStrExpected); UnityPrintFloat((float)expected); UnityPrint(UnityStrWas); UnityPrintFloat((float)actual); #else UnityPrint(UnityStrDelta); #endif UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } } //----------------------------------------------- void UnityAssertDoubleIsInf(const _UD actual, const char* msg, const UNITY_LINE_TYPE lineNumber) { UNITY_SKIP_EXECUTION; // The rationale for not using 1.0/0.0 is given in UnityAssertFloatIsInf's body. if ((1.0 / d_zero) != actual) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_DOUBLE_VERBOSE UnityPrint(UnityStrExpected); UnityPrint(UnityStrInf); UnityPrint(UnityStrWas); UnityPrintFloat((float)actual); #else UnityPrint(UnityStrDelta); #endif UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } } //----------------------------------------------- void UnityAssertDoubleIsNegInf(const _UD actual, const char* msg, const UNITY_LINE_TYPE lineNumber) { UNITY_SKIP_EXECUTION; // The rationale for not using 1.0/0.0 is given in UnityAssertFloatIsInf's body. if ((-1.0 / d_zero) != actual) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_DOUBLE_VERBOSE UnityPrint(UnityStrExpected); UnityPrint(UnityStrNegInf); UnityPrint(UnityStrWas); UnityPrintFloat((float)actual); #else UnityPrint(UnityStrDelta); #endif UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } } //----------------------------------------------- void UnityAssertDoubleIsNaN(const _UD actual, const char* msg, const UNITY_LINE_TYPE lineNumber) { UNITY_SKIP_EXECUTION; if (actual == actual) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_DOUBLE_VERBOSE UnityPrint(UnityStrExpected); UnityPrint(UnityStrNaN); UnityPrint(UnityStrWas); UnityPrintFloat((float)actual); #else UnityPrint(UnityStrDelta); #endif UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } } #endif // not UNITY_EXCLUDE_DOUBLE //----------------------------------------------- void UnityAssertNumbersWithin( const _U_SINT delta, const _U_SINT expected, const _U_SINT actual, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style) { UNITY_SKIP_EXECUTION; if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) { if (actual > expected) Unity.CurrentTestFailed = ((actual - expected) > delta); else Unity.CurrentTestFailed = ((expected - actual) > delta); } else { if ((_U_UINT)actual > (_U_UINT)expected) Unity.CurrentTestFailed = ((_U_UINT)(actual - expected) > (_U_UINT)delta); else Unity.CurrentTestFailed = ((_U_UINT)(expected - actual) > (_U_UINT)delta); } if (Unity.CurrentTestFailed) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrDelta); UnityPrintNumberByStyle(delta, style); UnityPrint(UnityStrExpected); UnityPrintNumberByStyle(expected, style); UnityPrint(UnityStrWas); UnityPrintNumberByStyle(actual, style); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } } //----------------------------------------------- void UnityAssertEqualString(const char* expected, const char* actual, const char* msg, const UNITY_LINE_TYPE lineNumber) { _UU32 i; UNITY_SKIP_EXECUTION; // if both pointers not null compare the strings if (expected && actual) { for (i = 0; expected[i] || actual[i]; i++) { if (expected[i] != actual[i]) { Unity.CurrentTestFailed = 1; break; } } } else { // handle case of one pointers being null (if both null, test should pass) if (expected != actual) { Unity.CurrentTestFailed = 1; } } if (Unity.CurrentTestFailed) { UnityTestResultsFailBegin(lineNumber); UnityPrintExpectedAndActualStrings(expected, actual); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } } //----------------------------------------------- void UnityAssertEqualStringArray( const char** expected, const char** actual, const _UU32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber) { _UU32 i, j = 0; UNITY_SKIP_EXECUTION; // if no elements, it's an error if (num_elements == 0) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrPointless); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1) return; do { // if both pointers not null compare the strings if (expected[j] && actual[j]) { for (i = 0; expected[j][i] || actual[j][i]; i++) { if (expected[j][i] != actual[j][i]) { Unity.CurrentTestFailed = 1; break; } } } else { // handle case of one pointers being null (if both null, test should pass) if (expected[j] != actual[j]) { Unity.CurrentTestFailed = 1; } } if (Unity.CurrentTestFailed) { UnityTestResultsFailBegin(lineNumber); if (num_elements > 1) { UnityPrint(UnityStrElement); UnityPrintNumberByStyle((num_elements - j - 1), UNITY_DISPLAY_STYLE_UINT); } UnityPrintExpectedAndActualStrings((const char*)(expected[j]), (const char*)(actual[j])); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } } while (++j < num_elements); } //----------------------------------------------- void UnityAssertEqualMemory( const void* expected, const void* actual, const _UU32 length, const _UU32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber) { unsigned char* ptr_exp = (unsigned char*)expected; unsigned char* ptr_act = (unsigned char*)actual; _UU32 elements = num_elements; _UU32 bytes; UNITY_SKIP_EXECUTION; if ((elements == 0) || (length == 0)) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrPointless); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1) return; while (elements--) { ///////////////////////////////////// bytes = length; while (bytes--) { if (*ptr_exp != *ptr_act) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrMemory); if (num_elements > 1) { UnityPrint(UnityStrElement); UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT); } UnityPrint(UnityStrByte); UnityPrintNumberByStyle((length - bytes - 1), UNITY_DISPLAY_STYLE_UINT); UnityPrint(UnityStrExpected); UnityPrintNumberByStyle(*ptr_exp, UNITY_DISPLAY_STYLE_HEX8); UnityPrint(UnityStrWas); UnityPrintNumberByStyle(*ptr_act, UNITY_DISPLAY_STYLE_HEX8); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } ptr_exp += 1; ptr_act += 1; } ///////////////////////////////////// } } //----------------------------------------------- // Control Functions //----------------------------------------------- void UnityFail(const char* msg, const UNITY_LINE_TYPE line) { UNITY_SKIP_EXECUTION; UnityTestResultsBegin(Unity.TestFile, line); UnityPrintFail(); if (msg != NULL) { UNITY_OUTPUT_CHAR(':'); if (msg[0] != ' ') { UNITY_OUTPUT_CHAR(' '); } UnityPrint(msg); } UNITY_FAIL_AND_BAIL; } //----------------------------------------------- void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line) { UNITY_SKIP_EXECUTION; UnityTestResultsBegin(Unity.TestFile, line); UnityPrint("IGNORE"); if (msg != NULL) { UNITY_OUTPUT_CHAR(':'); UNITY_OUTPUT_CHAR(' '); UnityPrint(msg); } UNITY_IGNORE_AND_BAIL; } //----------------------------------------------- void setUp(void); void tearDown(void); void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum) { Unity.CurrentTestName = FuncName; Unity.CurrentTestLineNumber = FuncLineNum; Unity.NumberOfTests++; if (TEST_PROTECT()) { setUp(); Func(); } if (TEST_PROTECT() && !(Unity.CurrentTestIgnored)) { tearDown(); } UnityConcludeTest(); } //----------------------------------------------- void UnityBegin(void) { Unity.NumberOfTests = 0; Unity.TestFailures = 0; Unity.TestIgnores = 0; Unity.CurrentTestFailed = 0; Unity.CurrentTestIgnored = 0; } //----------------------------------------------- int UnityEnd(void) { UnityPrint("-----------------------"); UNITY_PRINT_EOL; UnityPrintNumber(Unity.NumberOfTests); UnityPrint(" Tests "); UnityPrintNumber(Unity.TestFailures); UnityPrint(" Failures "); UnityPrintNumber(Unity.TestIgnores); UnityPrint(" Ignored"); UNITY_PRINT_EOL; if (Unity.TestFailures == 0U) { UnityPrintOk(); } else { UnityPrintFail(); } UNITY_PRINT_EOL; return Unity.TestFailures; } libsml-0.1.1+git20170608/test/unity/unity_fixture.h0000644000175000017500000000556712734144572021462 0ustar andreasandreas//- Copyright (c) 2010 James Grenning and Contributed to Unity Project /* ========================================== Unity Project - A Test Framework for C Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams [Released under MIT License. Please refer to license.txt for details] ========================================== */ #ifndef UNITY_FIXTURE_H_ #define UNITY_FIXTURE_H_ #include "unity.h" #include "unity_internals.h" #include "unity_fixture_malloc_overrides.h" #include "unity_fixture_internals.h" int UnityMain(int argc, char* argv[], void (*runAllTests)()); #define TEST_GROUP(group)\ int TEST_GROUP_##group = 0 #define TEST_SETUP(group) void TEST_##group##_SETUP() #define TEST_TEAR_DOWN(group) void TEST_##group##_TEAR_DOWN() #define TEST(group, name) \ void TEST_##group##_##name##_();\ void TEST_##group##_##name##_run()\ {\ UnityTestRunner(TEST_##group##_SETUP,\ TEST_##group##_##name##_,\ TEST_##group##_TEAR_DOWN,\ "TEST(" #group ", " #name ")",\ #group, #name,\ __FILE__, __LINE__);\ }\ void TEST_##group##_##name##_() #define IGNORE_TEST(group, name) \ void TEST_##group##_##name##_();\ void TEST_##group##_##name##_run()\ {\ UnityIgnoreTest("IGNORE_TEST(" #group ", " #name ")");\ }\ void TEST_##group##_##name##_() #define DECLARE_TEST_CASE(group, name) \ void TEST_##group##_##name##_run() #define RUN_TEST_CASE(group, name) \ { DECLARE_TEST_CASE(group, name);\ TEST_##group##_##name##_run(); } //This goes at the bottom of each test file or in a separate c file #define TEST_GROUP_RUNNER(group)\ void TEST_##group##_GROUP_RUNNER_runAll();\ void TEST_##group##_GROUP_RUNNER()\ {\ TEST_##group##_GROUP_RUNNER_runAll();\ }\ void TEST_##group##_GROUP_RUNNER_runAll() //Call this from main #define RUN_TEST_GROUP(group)\ { void TEST_##group##_GROUP_RUNNER();\ TEST_##group##_GROUP_RUNNER(); } //CppUTest Compatibility Macros #define UT_PTR_SET(ptr, newPointerValue) UnityPointer_Set((void**)&ptr, (void*)newPointerValue) #define TEST_ASSERT_POINTERS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_PTR(expected, actual) #define TEST_ASSERT_BYTES_EQUAL(expected, actual) TEST_ASSERT_EQUAL_HEX8(0xff & (expected), 0xff & (actual)) #define FAIL(message) TEST_FAIL((message)) #define CHECK(condition) TEST_ASSERT_TRUE((condition)) #define LONGS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_INT((expected), (actual)) #define STRCMP_EQUAL(expected, actual) TEST_ASSERT_EQUAL_STRING((expected), (actual)) #define DOUBLES_EQUAL(expected, actual, delta) TEST_ASSERT_FLOAT_WITHIN(((expected), (actual), (delta)) void UnityMalloc_MakeMallocFailAfterCount(int count); #endif /* UNITY_FIXTURE_H_ */ libsml-0.1.1+git20170608/test/unity/unity_fixture.c0000644000175000017500000001767712734144572021462 0ustar andreasandreas//- Copyright (c) 2010 James Grenning and Contributed to Unity Project /* ========================================== Unity Project - A Test Framework for C Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams [Released under MIT License. Please refer to license.txt for details] ========================================== */ #include #include "unity_fixture.h" #include "unity_internals.h" UNITY_FIXTURE_T UnityFixture; //If you decide to use the function pointer approach. int (*outputChar)(int) = putchar; int verbose = 0; void setUp(void) { /*does nothing*/ } void tearDown(void) { /*does nothing*/ } void announceTestRun(unsigned int runNumber) { UnityPrint("Unity test run "); UnityPrintNumber(runNumber+1); UnityPrint(" of "); UnityPrintNumber(UnityFixture.RepeatCount); UNITY_OUTPUT_CHAR('\n'); } int UnityMain(int argc, char* argv[], void (*runAllTests)()) { int result = UnityGetCommandLineOptions(argc, argv); unsigned int r; if (result != 0) return result; for (r = 0; r < UnityFixture.RepeatCount; r++) { announceTestRun(r); UnityBegin(); runAllTests(); UNITY_OUTPUT_CHAR('\n'); UnityEnd(); } return UnityFailureCount(); } static int selected(const char * filter, const char * name) { if (filter == 0) return 1; return strstr(name, filter) ? 1 : 0; } static int testSelected(const char* test) { return selected(UnityFixture.NameFilter, test); } static int groupSelected(const char* group) { return selected(UnityFixture.GroupFilter, group); } static void runTestCase() { } void UnityTestRunner(unityfunction* setup, unityfunction* testBody, unityfunction* teardown, const char * printableName, const char * group, const char * name, const char * file, int line) { if (testSelected(name) && groupSelected(group)) { Unity.CurrentTestFailed = 0; Unity.TestFile = file; Unity.CurrentTestName = printableName; Unity.CurrentTestLineNumber = line; if (!UnityFixture.Verbose) UNITY_OUTPUT_CHAR('.'); else UnityPrint(printableName); Unity.NumberOfTests++; UnityMalloc_StartTest(); UnityPointer_Init(); runTestCase(); if (TEST_PROTECT()) { setup(); testBody(); } if (TEST_PROTECT()) { teardown(); } if (TEST_PROTECT()) { UnityPointer_UndoAllSets(); if (!Unity.CurrentTestFailed) UnityMalloc_EndTest(); } UnityConcludeFixtureTest(); } } void UnityIgnoreTest(const char * printableName) { Unity.NumberOfTests++; Unity.CurrentTestIgnored = 1; if (!UnityFixture.Verbose) UNITY_OUTPUT_CHAR('!'); else UnityPrint(printableName); UnityConcludeFixtureTest(); } //------------------------------------------------- //Malloc and free stuff // #define MALLOC_DONT_FAIL -1 static int malloc_count; static int malloc_fail_countdown = MALLOC_DONT_FAIL; void UnityMalloc_StartTest() { malloc_count = 0; malloc_fail_countdown = MALLOC_DONT_FAIL; } void UnityMalloc_EndTest() { malloc_fail_countdown = MALLOC_DONT_FAIL; if (malloc_count != 0) { TEST_FAIL_MESSAGE("This test leaks!"); } } void UnityMalloc_MakeMallocFailAfterCount(int countdown) { malloc_fail_countdown = countdown; } #ifdef malloc #undef malloc #endif #ifdef free #undef free #endif #include #include typedef struct GuardBytes { size_t size; char guard[sizeof(size_t)]; } Guard; static const char * end = "END"; void * unity_malloc(size_t size) { char* mem; Guard* guard; if (malloc_fail_countdown != MALLOC_DONT_FAIL) { if (malloc_fail_countdown == 0) return 0; malloc_fail_countdown--; } malloc_count++; guard = (Guard*)malloc(size + sizeof(Guard) + 4); guard->size = size; mem = (char*)&(guard[1]); memcpy(&mem[size], end, strlen(end) + 1); return (void*)mem; } static int isOverrun(void * mem) { Guard* guard = (Guard*)mem; char* memAsChar = (char*)mem; guard--; return strcmp(&memAsChar[guard->size], end) != 0; } static void release_memory(void * mem) { Guard* guard = (Guard*)mem; guard--; malloc_count--; free(guard); } void unity_free(void * mem) { int overrun = isOverrun(mem);//strcmp(&memAsChar[guard->size], end) != 0; release_memory(mem); if (overrun) { TEST_FAIL_MESSAGE("Buffer overrun detected during free()"); } } void* unity_calloc(size_t num, size_t size) { void* mem = unity_malloc(num * size); memset(mem, 0, num*size); return mem; } void* unity_realloc(void * oldMem, size_t size) { Guard* guard = (Guard*)oldMem; // char* memAsChar = (char*)oldMem; void* newMem; if (oldMem == 0) return unity_malloc(size); guard--; if (isOverrun(oldMem)) { release_memory(oldMem); TEST_FAIL_MESSAGE("Buffer overrun detected during realloc()"); } if (size == 0) { release_memory(oldMem); return 0; } if (guard->size >= size) return oldMem; newMem = unity_malloc(size); memcpy(newMem, oldMem, guard->size); unity_free(oldMem); return newMem; } //-------------------------------------------------------- //Automatic pointer restoration functions typedef struct _PointerPair { struct _PointerPair * next; void ** pointer; void * old_value; } PointerPair; enum {MAX_POINTERS=50}; static PointerPair pointer_store[MAX_POINTERS]; static int pointer_index = 0; void UnityPointer_Init() { pointer_index = 0; } void UnityPointer_Set(void ** pointer, void * newValue) { if (pointer_index >= MAX_POINTERS) TEST_FAIL_MESSAGE("Too many pointers set"); pointer_store[pointer_index].pointer = pointer; pointer_store[pointer_index].old_value = *pointer; *pointer = newValue; pointer_index++; } void UnityPointer_UndoAllSets() { while (pointer_index > 0) { pointer_index--; *(pointer_store[pointer_index].pointer) = pointer_store[pointer_index].old_value; } } int UnityFailureCount() { return Unity.TestFailures; } int UnityGetCommandLineOptions(int argc, char* argv[]) { int i; UnityFixture.Verbose = 0; UnityFixture.GroupFilter = 0; UnityFixture.NameFilter = 0; UnityFixture.RepeatCount = 1; if (argc == 1) return 0; for (i = 1; i < argc; ) { if (strcmp(argv[i], "-v") == 0) { UnityFixture.Verbose = 1; i++; } else if (strcmp(argv[i], "-g") == 0) { i++; if (i >= argc) return 1; UnityFixture.GroupFilter = argv[i]; i++; } else if (strcmp(argv[i], "-n") == 0) { i++; if (i >= argc) return 1; UnityFixture.NameFilter = argv[i]; i++; } else if (strcmp(argv[i], "-r") == 0) { UnityFixture.RepeatCount = 2; i++; if (i < argc) { if (*(argv[i]) >= '0' && *(argv[i]) <= '9') { UnityFixture.RepeatCount = atoi(argv[i]); i++; } } } } return 0; } void UnityConcludeFixtureTest() { if (Unity.CurrentTestIgnored) { if (UnityFixture.Verbose) { UNITY_OUTPUT_CHAR('\n'); } Unity.TestIgnores++; } else if (!Unity.CurrentTestFailed) { if (UnityFixture.Verbose) { UnityPrint(" PASS"); UNITY_OUTPUT_CHAR('\n'); } } else if (Unity.CurrentTestFailed) { Unity.TestFailures++; } Unity.CurrentTestFailed = 0; Unity.CurrentTestIgnored = 0; } libsml-0.1.1+git20170608/test/unity/license.txt0000644000175000017500000000312512734144572020542 0ustar andreasandreas Copyright (c) 2007-2010 Mike Karlesky, Mark VanderVoord, Greg Williams 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 end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed for the Unity Project, by Mike Karlesky, Mark VanderVoord, and Greg Williams and other contributors", in the same place and form as other third-party acknowledgments. Alternately, this acknowledgment may appear in the software itself, in the same form and location as other such third-party acknowledgments. 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 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.libsml-0.1.1+git20170608/test/unity/unity_internals.h0000644000175000017500000007365012734144572021771 0ustar andreasandreas/* ========================================== Unity Project - A Test Framework for C Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams [Released under MIT License. Please refer to license.txt for details] ========================================== */ #ifndef UNITY_INTERNALS_H #define UNITY_INTERNALS_H #include #include // Unity attempts to determine sizeof(various types) // based on UINT_MAX, ULONG_MAX, etc. These are typically // defined in limits.h. #ifdef UNITY_USE_LIMITS_H #include #endif // As a fallback, hope that including stdint.h will // provide this information. #ifndef UNITY_EXCLUDE_STDINT_H #include #endif //------------------------------------------------------- // Guess Widths If Not Specified //------------------------------------------------------- // Determine the size of an int, if not already specificied. // We cannot use sizeof(int), because it is not yet defined // at this stage in the trnslation of the C program. // Therefore, infer it from UINT_MAX if possible. #ifndef UNITY_INT_WIDTH #ifdef UINT_MAX #if (UINT_MAX == 0xFFFF) #define UNITY_INT_WIDTH (16) #elif (UINT_MAX == 0xFFFFFFFF) #define UNITY_INT_WIDTH (32) #elif (UINT_MAX == 0xFFFFFFFFFFFFFFFF) #define UNITY_INT_WIDTH (64) #ifndef UNITY_SUPPORT_64 #define UNITY_SUPPORT_64 #endif #endif #endif #endif #ifndef UNITY_INT_WIDTH #define UNITY_INT_WIDTH (32) #endif // Determine the size of a long, if not already specified, // by following the process used above to define // UNITY_INT_WIDTH. #ifndef UNITY_LONG_WIDTH #ifdef ULONG_MAX #if (ULONG_MAX == 0xFFFF) #define UNITY_LONG_WIDTH (16) #elif (ULONG_MAX == 0xFFFFFFFF) #define UNITY_LONG_WIDTH (32) #elif (ULONG_MAX == 0xFFFFFFFFFFFFFFFF) #define UNITY_LONG_WIDTH (64) #ifndef UNITY_SUPPORT_64 #define UNITY_SUPPORT_64 #endif #endif #endif #endif #ifndef UNITY_LONG_WIDTH #define UNITY_LONG_WIDTH (32) #endif // Determine the size of a pointer, if not already specified, // by following the process used above to define // UNITY_INT_WIDTH. #ifndef UNITY_POINTER_WIDTH #ifdef UINTPTR_MAX #if (UINTPTR_MAX <= 0xFFFF) #define UNITY_POINTER_WIDTH (16) #elif (UINTPTR_MAX <= 0xFFFFFFFF) #define UNITY_POINTER_WIDTH (32) #elif (UINTPTR_MAX <= 0xFFFFFFFFFFFFFFFF) #define UNITY_POINTER_WIDTH (64) #ifndef UNITY_SUPPORT_64 #define UNITY_SUPPORT_64 #endif #endif #endif #endif #ifndef UNITY_POINTER_WIDTH #ifdef INTPTR_MAX #if (INTPTR_MAX <= 0x7FFF) #define UNITY_POINTER_WIDTH (16) #elif (INTPTR_MAX <= 0x7FFFFFFF) #define UNITY_POINTER_WIDTH (32) #elif (INTPTR_MAX <= 0x7FFFFFFFFFFFFFFF) #define UNITY_POINTER_WIDTH (64) #ifndef UNITY_SUPPORT_64 #define UNITY_SUPPORT_64 #endif #endif #endif #endif #ifndef UNITY_POINTER_WIDTH #define UNITY_POINTER_WIDTH (32) #endif //------------------------------------------------------- // Int Support //------------------------------------------------------- #if (UNITY_INT_WIDTH == 32) typedef unsigned char _UU8; typedef unsigned short _UU16; typedef unsigned int _UU32; typedef signed char _US8; typedef signed short _US16; typedef signed int _US32; #elif (UNITY_INT_WIDTH == 16) typedef unsigned char _UU8; typedef unsigned int _UU16; typedef unsigned long _UU32; typedef signed char _US8; typedef signed int _US16; typedef signed long _US32; #else #error Invalid UNITY_INT_WIDTH specified! (16 or 32 are supported) #endif //------------------------------------------------------- // 64-bit Support //------------------------------------------------------- #ifndef UNITY_SUPPORT_64 //No 64-bit Support typedef _UU32 _U_UINT; typedef _US32 _U_SINT; #else //64-bit Support #if (UNITY_LONG_WIDTH == 32) typedef unsigned long long _UU64; typedef signed long long _US64; #elif (UNITY_LONG_WIDTH == 64) typedef unsigned long _UU64; typedef signed long _US64; #else #error Invalid UNITY_LONG_WIDTH specified! (32 or 64 are supported) #endif typedef _UU64 _U_UINT; typedef _US64 _U_SINT; #endif //------------------------------------------------------- // Pointer Support //------------------------------------------------------- #if (UNITY_POINTER_WIDTH == 32) typedef _UU32 _UP; #define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX32 #elif (UNITY_POINTER_WIDTH == 64) #ifndef UNITY_SUPPORT_64 #error "You've Specified 64-bit pointers without enabling 64-bit Support. Define UNITY_SUPPORT_64" #endif typedef _UU64 _UP; #define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX64 #elif (UNITY_POINTER_WIDTH == 16) typedef _UU16 _UP; #define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX16 #else #error Invalid UNITY_POINTER_WIDTH specified! (16, 32 or 64 are supported) #endif //------------------------------------------------------- // Float Support //------------------------------------------------------- #ifdef UNITY_EXCLUDE_FLOAT //No Floating Point Support #undef UNITY_FLOAT_PRECISION #undef UNITY_FLOAT_TYPE #undef UNITY_FLOAT_VERBOSE #else //Floating Point Support #ifndef UNITY_FLOAT_PRECISION #define UNITY_FLOAT_PRECISION (0.00001f) #endif #ifndef UNITY_FLOAT_TYPE #define UNITY_FLOAT_TYPE float #endif typedef UNITY_FLOAT_TYPE _UF; #endif //------------------------------------------------------- // Double Float Support //------------------------------------------------------- //unlike FLOAT, we DON'T include by default #ifndef UNITY_EXCLUDE_DOUBLE #ifndef UNITY_INCLUDE_DOUBLE #define UNITY_EXCLUDE_DOUBLE #endif #endif #ifdef UNITY_EXCLUDE_DOUBLE //No Floating Point Support #undef UNITY_DOUBLE_PRECISION #undef UNITY_DOUBLE_TYPE #undef UNITY_DOUBLE_VERBOSE #else //Floating Point Support #ifndef UNITY_DOUBLE_PRECISION #define UNITY_DOUBLE_PRECISION (1e-12f) #endif #ifndef UNITY_DOUBLE_TYPE #define UNITY_DOUBLE_TYPE double #endif typedef UNITY_DOUBLE_TYPE _UD; #endif //------------------------------------------------------- // Output Method //------------------------------------------------------- #ifndef UNITY_OUTPUT_CHAR //Default to using putchar, which is defined in stdio.h above #define UNITY_OUTPUT_CHAR(a) putchar(a) #else //If defined as something else, make sure we declare it here so it's ready for use extern int UNITY_OUTPUT_CHAR(int); #endif //------------------------------------------------------- // Footprint //------------------------------------------------------- #ifndef UNITY_LINE_TYPE #define UNITY_LINE_TYPE _U_UINT #endif #ifndef UNITY_COUNTER_TYPE #define UNITY_COUNTER_TYPE _U_UINT #endif //------------------------------------------------------- // Internal Structs Needed //------------------------------------------------------- typedef void (*UnityTestFunction)(void); #define UNITY_DISPLAY_RANGE_INT (0x10) #define UNITY_DISPLAY_RANGE_UINT (0x20) #define UNITY_DISPLAY_RANGE_HEX (0x40) #define UNITY_DISPLAY_RANGE_AUTO (0x80) typedef enum { #if (UNITY_INT_WIDTH == 16) UNITY_DISPLAY_STYLE_INT = 2 + UNITY_DISPLAY_RANGE_INT + UNITY_DISPLAY_RANGE_AUTO, #elif (UNITY_INT_WIDTH == 32) UNITY_DISPLAY_STYLE_INT = 4 + UNITY_DISPLAY_RANGE_INT + UNITY_DISPLAY_RANGE_AUTO, #elif (UNITY_INT_WIDTH == 64) UNITY_DISPLAY_STYLE_INT = 8 + UNITY_DISPLAY_RANGE_INT + UNITY_DISPLAY_RANGE_AUTO, #endif UNITY_DISPLAY_STYLE_INT8 = 1 + UNITY_DISPLAY_RANGE_INT, UNITY_DISPLAY_STYLE_INT16 = 2 + UNITY_DISPLAY_RANGE_INT, UNITY_DISPLAY_STYLE_INT32 = 4 + UNITY_DISPLAY_RANGE_INT, #ifdef UNITY_SUPPORT_64 UNITY_DISPLAY_STYLE_INT64 = 8 + UNITY_DISPLAY_RANGE_INT, #endif #if (UNITY_INT_WIDTH == 16) UNITY_DISPLAY_STYLE_UINT = 2 + UNITY_DISPLAY_RANGE_UINT + UNITY_DISPLAY_RANGE_AUTO, #elif (UNITY_INT_WIDTH == 32) UNITY_DISPLAY_STYLE_UINT = 4 + UNITY_DISPLAY_RANGE_UINT + UNITY_DISPLAY_RANGE_AUTO, #elif (UNITY_INT_WIDTH == 64) UNITY_DISPLAY_STYLE_UINT = 8 + UNITY_DISPLAY_RANGE_UINT + UNITY_DISPLAY_RANGE_AUTO, #endif UNITY_DISPLAY_STYLE_UINT8 = 1 + UNITY_DISPLAY_RANGE_UINT, UNITY_DISPLAY_STYLE_UINT16 = 2 + UNITY_DISPLAY_RANGE_UINT, UNITY_DISPLAY_STYLE_UINT32 = 4 + UNITY_DISPLAY_RANGE_UINT, #ifdef UNITY_SUPPORT_64 UNITY_DISPLAY_STYLE_UINT64 = 8 + UNITY_DISPLAY_RANGE_UINT, #endif UNITY_DISPLAY_STYLE_HEX8 = 1 + UNITY_DISPLAY_RANGE_HEX, UNITY_DISPLAY_STYLE_HEX16 = 2 + UNITY_DISPLAY_RANGE_HEX, UNITY_DISPLAY_STYLE_HEX32 = 4 + UNITY_DISPLAY_RANGE_HEX, #ifdef UNITY_SUPPORT_64 UNITY_DISPLAY_STYLE_HEX64 = 8 + UNITY_DISPLAY_RANGE_HEX, #endif UNITY_DISPLAY_STYLE_UNKNOWN } UNITY_DISPLAY_STYLE_T; struct _Unity { const char* TestFile; const char* CurrentTestName; UNITY_LINE_TYPE CurrentTestLineNumber; UNITY_COUNTER_TYPE NumberOfTests; UNITY_COUNTER_TYPE TestFailures; UNITY_COUNTER_TYPE TestIgnores; UNITY_COUNTER_TYPE CurrentTestFailed; UNITY_COUNTER_TYPE CurrentTestIgnored; jmp_buf AbortFrame; }; extern struct _Unity Unity; //------------------------------------------------------- // Test Suite Management //------------------------------------------------------- void UnityBegin(void); int UnityEnd(void); void UnityConcludeTest(void); void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum); //------------------------------------------------------- // Test Output //------------------------------------------------------- void UnityPrint(const char* string); void UnityPrintMask(const _U_UINT mask, const _U_UINT number); void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style); void UnityPrintNumber(const _U_SINT number); void UnityPrintNumberUnsigned(const _U_UINT number); void UnityPrintNumberHex(const _U_UINT number, const char nibbles); #ifdef UNITY_FLOAT_VERBOSE void UnityPrintFloat(const _UF number); #endif //------------------------------------------------------- // Test Assertion Fuctions //------------------------------------------------------- // Use the macros below this section instead of calling // these directly. The macros have a consistent naming // convention and will pull in file and line information // for you. void UnityAssertEqualNumber(const _U_SINT expected, const _U_SINT actual, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style); void UnityAssertEqualIntArray(const _U_SINT* expected, const _U_SINT* actual, const _UU32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style); void UnityAssertBits(const _U_SINT mask, const _U_SINT expected, const _U_SINT actual, const char* msg, const UNITY_LINE_TYPE lineNumber); void UnityAssertEqualString(const char* expected, const char* actual, const char* msg, const UNITY_LINE_TYPE lineNumber); void UnityAssertEqualStringArray( const char** expected, const char** actual, const _UU32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber); void UnityAssertEqualMemory( const void* expected, const void* actual, const _UU32 length, const _UU32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber); void UnityAssertNumbersWithin(const _U_SINT delta, const _U_SINT expected, const _U_SINT actual, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style); void UnityFail(const char* message, const UNITY_LINE_TYPE line); void UnityIgnore(const char* message, const UNITY_LINE_TYPE line); #ifndef UNITY_EXCLUDE_FLOAT void UnityAssertFloatsWithin(const _UF delta, const _UF expected, const _UF actual, const char* msg, const UNITY_LINE_TYPE lineNumber); void UnityAssertEqualFloatArray(const _UF* expected, const _UF* actual, const _UU32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber); void UnityAssertFloatIsInf(const _UF actual, const char* msg, const UNITY_LINE_TYPE lineNumber); void UnityAssertFloatIsNegInf(const _UF actual, const char* msg, const UNITY_LINE_TYPE lineNumber); void UnityAssertFloatIsNaN(const _UF actual, const char* msg, const UNITY_LINE_TYPE lineNumber); #endif #ifndef UNITY_EXCLUDE_DOUBLE void UnityAssertDoublesWithin(const _UD delta, const _UD expected, const _UD actual, const char* msg, const UNITY_LINE_TYPE lineNumber); void UnityAssertEqualDoubleArray(const _UD* expected, const _UD* actual, const _UU32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber); void UnityAssertDoubleIsInf(const _UD actual, const char* msg, const UNITY_LINE_TYPE lineNumber); void UnityAssertDoubleIsNegInf(const _UD actual, const char* msg, const UNITY_LINE_TYPE lineNumber); void UnityAssertDoubleIsNaN(const _UD actual, const char* msg, const UNITY_LINE_TYPE lineNumber); #endif //------------------------------------------------------- // Basic Fail and Ignore //------------------------------------------------------- #define UNITY_TEST_FAIL(line, message) UnityFail( (message), (UNITY_LINE_TYPE)line); #define UNITY_TEST_IGNORE(line, message) UnityIgnore( (message), (UNITY_LINE_TYPE)line); //------------------------------------------------------- // Test Asserts //------------------------------------------------------- #define UNITY_TEST_ASSERT(condition, line, message) if (condition) {} else {UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, message);} #define UNITY_TEST_ASSERT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) == NULL), (UNITY_LINE_TYPE)line, message) #define UNITY_TEST_ASSERT_NOT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) != NULL), (UNITY_LINE_TYPE)line, message) #define UNITY_TEST_ASSERT_EQUAL_INT(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT) #define UNITY_TEST_ASSERT_EQUAL_INT8(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(_US8 )(expected), (_U_SINT)(_US8 )(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT) #define UNITY_TEST_ASSERT_EQUAL_INT16(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(_US16)(expected), (_U_SINT)(_US16)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT) #define UNITY_TEST_ASSERT_EQUAL_INT32(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(_US32)(expected), (_U_SINT)(_US32)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT) #define UNITY_TEST_ASSERT_EQUAL_UINT(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT) #define UNITY_TEST_ASSERT_EQUAL_UINT8(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(_US8 )(expected), (_U_SINT)(_US8 )(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT) #define UNITY_TEST_ASSERT_EQUAL_UINT16(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(_US16)(expected), (_U_SINT)(_US16)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT) #define UNITY_TEST_ASSERT_EQUAL_UINT32(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(_US32)(expected), (_U_SINT)(_US32)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT) #define UNITY_TEST_ASSERT_EQUAL_HEX8(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(_US8 )(expected), (_U_SINT)(_US8 )(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8) #define UNITY_TEST_ASSERT_EQUAL_HEX16(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(_US16)(expected), (_U_SINT)(_US16)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16) #define UNITY_TEST_ASSERT_EQUAL_HEX32(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(_US32)(expected), (_U_SINT)(_US32)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32) #define UNITY_TEST_ASSERT_BITS(mask, expected, actual, line, message) UnityAssertBits((_U_SINT)(mask), (_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT) #define UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT) #define UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(_U_UINT)(_UU8 )(delta), (_U_SINT)(_U_UINT)(_UU8 )(expected), (_U_SINT)(_U_UINT)(_UU8 )(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8) #define UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(_U_UINT)(_UU16)(delta), (_U_SINT)(_U_UINT)(_UU16)(expected), (_U_SINT)(_U_UINT)(_UU16)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16) #define UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(_U_UINT)(_UU32)(delta), (_U_SINT)(_U_UINT)(_UU32)(expected), (_U_SINT)(_U_UINT)(_UU32)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32) #define UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(_UP)(expected), (_U_SINT)(_UP)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_POINTER) #define UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, line, message) UnityAssertEqualString((const char*)(expected), (const char*)(actual), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, line, message) UnityAssertEqualMemory((void*)(expected), (void*)(actual), (_UU32)(len), 1, (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT) #define UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT8) #define UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT16) #define UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT32) #define UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT) #define UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT8) #define UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT16) #define UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT32) #define UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8) #define UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16) #define UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32) #define UNITY_TEST_ASSERT_EQUAL_PTR_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(_UP*)(expected), (const _U_SINT*)(_UP*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_POINTER) #define UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualStringArray((const char**)(expected), (const char**)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, line, message) UnityAssertEqualMemory((void*)(expected), (void*)(actual), (_UU32)(len), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line) #ifdef UNITY_SUPPORT_64 #define UNITY_TEST_ASSERT_EQUAL_INT64(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT64) #define UNITY_TEST_ASSERT_EQUAL_UINT64(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT64) #define UNITY_TEST_ASSERT_EQUAL_HEX64(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64) #define UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT64) #define UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT64) #define UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64) #define UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64) #endif #ifdef UNITY_EXCLUDE_FLOAT #define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") #define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") #define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") #define UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") #define UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") #define UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") #else #define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UnityAssertFloatsWithin((_UF)(delta), (_UF)(expected), (_UF)(actual), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_ASSERT_FLOAT_WITHIN((_UF)(expected) * (_UF)UNITY_FLOAT_PRECISION, (_UF)expected, (_UF)actual, (UNITY_LINE_TYPE)line, message) #define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualFloatArray((_UF*)(expected), (_UF*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, line, message) UnityAssertFloatIsInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, line, message) UnityAssertFloatIsNegInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, line, message) UnityAssertFloatIsNaN((_UF)(actual), (message), (UNITY_LINE_TYPE)line) #endif #ifdef UNITY_EXCLUDE_DOUBLE #define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") #define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") #define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") #define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") #define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") #define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") #else #define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UnityAssertDoublesWithin((_UD)(delta), (_UD)(expected), (_UD)(actual), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN((_UF)(expected) * (_UD)UNITY_DOUBLE_PRECISION, (_UD)expected, (_UD)actual, (UNITY_LINE_TYPE)line, message) #define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray((_UD*)(expected), (_UD*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) UnityAssertFloatIsInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) UnityAssertFloatIsNegInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) UnityAssertFloatIsNaN((_UF)(actual), (message), (UNITY_LINE_TYPE)line) #endif #endif libsml-0.1.1+git20170608/test/unity/unity_fixture_internals.h0000644000175000017500000000263212734144572023527 0ustar andreasandreas//- Copyright (c) 2010 James Grenning and Contributed to Unity Project /* ========================================== Unity Project - A Test Framework for C Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams [Released under MIT License. Please refer to license.txt for details] ========================================== */ #ifndef UNITY_FIXTURE_INTERNALS_H_ #define UNITY_FIXTURE_INTERNALS_H_ typedef struct _UNITY_FIXTURE_T { int Verbose; unsigned int RepeatCount; const char* NameFilter; const char* GroupFilter; } UNITY_FIXTURE_T; typedef void unityfunction(); void UnityTestRunner(unityfunction * setup, unityfunction * body, unityfunction * teardown, const char * printableName, const char * group, const char * name, const char * file, int line); void UnityIgnoreTest(const char * printableName); void UnityMalloc_StartTest(); void UnityMalloc_EndTest(); int UnityFailureCount(); int UnityGetCommandLineOptions(int argc, char* argv[]); void UnityConcludeFixtureTest(); void UnityPointer_Set(void ** ptr, void * newValue); void UnityPointer_UndoAllSets(); void UnityPointer_Init(); void UnityAssertEqualPointer(const void * expected, const void * actual, const char* msg, const UNITY_LINE_TYPE lineNumber); #endif /* UNITY_FIXTURE_INTERNALS_H_ */ libsml-0.1.1+git20170608/test/unity/unity.h0000644000175000017500000006664112734144572017714 0ustar andreasandreas/* ========================================== Unity Project - A Test Framework for C Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams [Released under MIT License. Please refer to license.txt for details] ========================================== */ #ifndef UNITY_FRAMEWORK_H #define UNITY_FRAMEWORK_H #define UNITY #include "unity_internals.h" //------------------------------------------------------- // Configuration Options //------------------------------------------------------- // All options described below should be passed as a compiler flag to all files using Unity. If you must add #defines, place them BEFORE the #include above. // Integers/longs/pointers // - Unity assumes 32 bit integers, longs, and pointers by default // - If your compiler treats ints of a different size, options are: // - define UNITY_USE_LIMITS_H to use limits.h to determine sizes // - define UNITY_INT_WIDTH, UNITY_LONG_WIDTH, nand UNITY_POINTER_WIDTH // Floats // - define UNITY_EXCLUDE_FLOAT to disallow floating point comparisons // - define UNITY_FLOAT_PRECISION to specify the precision to use when doing TEST_ASSERT_EQUAL_FLOAT // - define UNITY_FLOAT_TYPE to specify doubles instead of single precision floats // - define UNITY_FLOAT_VERBOSE to print floating point values in errors (uses sprintf) // - define UNITY_INCLUDE_DOUBLE to allow double floating point comparisons // - define UNITY_EXCLUDE_DOUBLE to disallow double floating point comparisons (default) // - define UNITY_DOUBLE_PRECISION to specify the precision to use when doing TEST_ASSERT_EQUAL_DOUBLE // - define UNITY_DOUBLE_TYPE to specify something other than double // - define UNITY_DOUBLE_VERBOSE to print floating point values in errors (uses sprintf) // Output // - by default, Unity prints to standard out with putchar. define UNITY_OUTPUT_CHAR(a) with a different function if desired // Optimization // - by default, line numbers are stored in unsigned shorts. Define UNITY_LINE_TYPE with a different type if your files are huge // - by default, test and failure counters are unsigned shorts. Define UNITY_COUNTER_TYPE with a different type if you want to save space or have more than 65535 Tests. // Test Cases // - define UNITY_SUPPORT_TEST_CASES to include the TEST_CASE macro, though really it's mostly about the runner generator script // Parameterized Tests // - you'll want to create a define of TEST_CASE(...) which basically evaluates to nothing //------------------------------------------------------- // Test Running Macros //------------------------------------------------------- #define TEST_PROTECT() (setjmp(Unity.AbortFrame) == 0) #define TEST_ABORT() {longjmp(Unity.AbortFrame, 1);} #ifndef RUN_TEST #define RUN_TEST(func, line_num) UnityDefaultTestRun(func, #func, line_num) #endif #define TEST_LINE_NUM (Unity.CurrentTestLineNumber) #define TEST_IS_IGNORED (Unity.CurrentTestIgnored) //------------------------------------------------------- // Basic Fail and Ignore //------------------------------------------------------- #define TEST_FAIL_MESSAGE(message) UNITY_TEST_FAIL(__LINE__, message) #define TEST_FAIL() UNITY_TEST_FAIL(__LINE__, NULL) #define TEST_IGNORE_MESSAGE(message) UNITY_TEST_IGNORE(__LINE__, message) #define TEST_IGNORE() UNITY_TEST_IGNORE(__LINE__, NULL) #define TEST_ONLY() //------------------------------------------------------- // Test Asserts (simple) //------------------------------------------------------- //Boolean #define TEST_ASSERT(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expression Evaluated To FALSE") #define TEST_ASSERT_TRUE(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expected TRUE Was FALSE") #define TEST_ASSERT_UNLESS(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expression Evaluated To TRUE") #define TEST_ASSERT_FALSE(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expected FALSE Was TRUE") #define TEST_ASSERT_NULL(pointer) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, " Expected NULL") #define TEST_ASSERT_NOT_NULL(pointer) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, " Expected Non-NULL") //Integers (of all sizes) #define TEST_ASSERT_EQUAL_INT(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_INT8(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT8((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_INT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT16((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_INT32(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT32((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_INT64(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT64((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, " Expected Not-Equal") #define TEST_ASSERT_EQUAL_UINT(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_UINT8(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT8( (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_UINT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT16( (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_UINT32(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT32( (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_UINT64(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT64( (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_HEX(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_HEX8(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX8( (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_HEX16(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX16((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_HEX32(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_HEX64(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX64((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_BITS(mask, expected, actual) UNITY_TEST_ASSERT_BITS((mask), (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_BITS_HIGH(mask, actual) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(-1), (actual), __LINE__, NULL) #define TEST_ASSERT_BITS_LOW(mask, actual) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(0), (actual), __LINE__, NULL) #define TEST_ASSERT_BIT_HIGH(bit, actual) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(-1), (actual), __LINE__, NULL) #define TEST_ASSERT_BIT_LOW(bit, actual) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(0), (actual), __LINE__, NULL) //Integer Ranges (of all sizes) #define TEST_ASSERT_INT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, __LINE__, NULL) #define TEST_ASSERT_UINT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, __LINE__, NULL) #define TEST_ASSERT_HEX_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, NULL) #define TEST_ASSERT_HEX8_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, __LINE__, NULL) #define TEST_ASSERT_HEX16_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, __LINE__, NULL) #define TEST_ASSERT_HEX32_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, NULL) #define TEST_ASSERT_HEX64_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, __LINE__, NULL) //Structs and Strings #define TEST_ASSERT_EQUAL_PTR(expected, actual) UNITY_TEST_ASSERT_EQUAL_PTR((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_STRING(expected, actual) UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, __LINE__, NULL) #define TEST_ASSERT_EQUAL_MEMORY(expected, actual, len) UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, __LINE__, NULL) //Arrays #define TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, __LINE__, NULL) #define TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, __LINE__, NULL) #define TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, __LINE__, NULL) #define TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, __LINE__, NULL) #define TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, __LINE__, NULL) #define TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, __LINE__, NULL) #define TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, __LINE__, NULL) #define TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, __LINE__, NULL) #define TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, __LINE__, NULL) #define TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, __LINE__, NULL) #define TEST_ASSERT_EQUAL_HEX_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, NULL) #define TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, __LINE__, NULL) #define TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, __LINE__, NULL) #define TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, NULL) #define TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, __LINE__, NULL) #define TEST_ASSERT_EQUAL_PTR_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_PTR_ARRAY(expected, actual, num_elements, __LINE__, NULL) #define TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, __LINE__, NULL) #define TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements) UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, __LINE__, NULL) //Floating Point (If Enabled) #define TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, NULL) #define TEST_ASSERT_EQUAL_FLOAT(expected, actual) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, NULL) #define TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, NULL) #define TEST_ASSERT_FLOAT_IS_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, __LINE__, NULL) #define TEST_ASSERT_FLOAT_IS_NEG_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, __LINE__, NULL) #define TEST_ASSERT_FLOAT_IS_NAN(actual) UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, __LINE__, NULL) //Double (If Enabled) #define TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, __LINE__, NULL) #define TEST_ASSERT_EQUAL_DOUBLE(expected, actual) UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, __LINE__, NULL) #define TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, __LINE__, NULL) #define TEST_ASSERT_DOUBLE_IS_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, __LINE__, NULL) #define TEST_ASSERT_DOUBLE_IS_NEG_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, __LINE__, NULL) #define TEST_ASSERT_DOUBLE_IS_NAN(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, __LINE__, NULL) //------------------------------------------------------- // Test Asserts (with additional messages) //------------------------------------------------------- //Boolean #define TEST_ASSERT_MESSAGE(condition, message) UNITY_TEST_ASSERT( (condition), __LINE__, message) #define TEST_ASSERT_TRUE_MESSAGE(condition, message) UNITY_TEST_ASSERT( (condition), __LINE__, message) #define TEST_ASSERT_UNLESS_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, message) #define TEST_ASSERT_FALSE_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, message) #define TEST_ASSERT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, message) #define TEST_ASSERT_NOT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, message) //Integers (of all sizes) #define TEST_ASSERT_EQUAL_INT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, message) #define TEST_ASSERT_EQUAL_INT8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT8((expected), (actual), __LINE__, message) #define TEST_ASSERT_EQUAL_INT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT16((expected), (actual), __LINE__, message) #define TEST_ASSERT_EQUAL_INT32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT32((expected), (actual), __LINE__, message) #define TEST_ASSERT_EQUAL_INT64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT64((expected), (actual), __LINE__, message) #define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, message) #define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, message) #define TEST_ASSERT_EQUAL_UINT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, message) #define TEST_ASSERT_EQUAL_UINT8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT8( (expected), (actual), __LINE__, message) #define TEST_ASSERT_EQUAL_UINT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT16( (expected), (actual), __LINE__, message) #define TEST_ASSERT_EQUAL_UINT32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT32( (expected), (actual), __LINE__, message) #define TEST_ASSERT_EQUAL_UINT64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT64( (expected), (actual), __LINE__, message) #define TEST_ASSERT_EQUAL_HEX_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, message) #define TEST_ASSERT_EQUAL_HEX8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX8( (expected), (actual), __LINE__, message) #define TEST_ASSERT_EQUAL_HEX16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX16((expected), (actual), __LINE__, message) #define TEST_ASSERT_EQUAL_HEX32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, message) #define TEST_ASSERT_EQUAL_HEX64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX64((expected), (actual), __LINE__, message) #define TEST_ASSERT_BITS_MESSAGE(mask, expected, actual, message) UNITY_TEST_ASSERT_BITS((mask), (expected), (actual), __LINE__, message) #define TEST_ASSERT_BITS_HIGH_MESSAGE(mask, actual, message) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(-1), (actual), __LINE__, message) #define TEST_ASSERT_BITS_LOW_MESSAGE(mask, actual, message) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(0), (actual), __LINE__, message) #define TEST_ASSERT_BIT_HIGH_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(-1), (actual), __LINE__, message) #define TEST_ASSERT_BIT_LOW_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(0), (actual), __LINE__, message) //Integer Ranges (of all sizes) #define TEST_ASSERT_INT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, __LINE__, message) #define TEST_ASSERT_UINT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, __LINE__, message) #define TEST_ASSERT_HEX_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, message) #define TEST_ASSERT_HEX8_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, __LINE__, message) #define TEST_ASSERT_HEX16_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, __LINE__, message) #define TEST_ASSERT_HEX32_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, message) #define TEST_ASSERT_HEX64_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, __LINE__, message) //Structs and Strings #define TEST_ASSERT_EQUAL_PTR_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, __LINE__, message) #define TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, __LINE__, message) #define TEST_ASSERT_EQUAL_MEMORY_MESSAGE(expected, actual, len, message) UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, __LINE__, message) //Arrays #define TEST_ASSERT_EQUAL_INT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, __LINE__, message) #define TEST_ASSERT_EQUAL_INT8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, __LINE__, message) #define TEST_ASSERT_EQUAL_INT16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, __LINE__, message) #define TEST_ASSERT_EQUAL_INT32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, __LINE__, message) #define TEST_ASSERT_EQUAL_INT64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, __LINE__, message) #define TEST_ASSERT_EQUAL_UINT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, __LINE__, message) #define TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, __LINE__, message) #define TEST_ASSERT_EQUAL_UINT16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, __LINE__, message) #define TEST_ASSERT_EQUAL_UINT32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, __LINE__, message) #define TEST_ASSERT_EQUAL_UINT64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, __LINE__, message) #define TEST_ASSERT_EQUAL_HEX_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, message) #define TEST_ASSERT_EQUAL_HEX8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, __LINE__, message) #define TEST_ASSERT_EQUAL_HEX16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, __LINE__, message) #define TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, message) #define TEST_ASSERT_EQUAL_HEX64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, __LINE__, message) #define TEST_ASSERT_EQUAL_PTR_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_PTR_ARRAY(expected, actual, num_elements, __LINE__, message) #define TEST_ASSERT_EQUAL_STRING_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, __LINE__, message) #define TEST_ASSERT_EQUAL_MEMORY_ARRAY_MESSAGE(expected, actual, len, num_elements, message) UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, __LINE__, message) //Floating Point (If Enabled) #define TEST_ASSERT_FLOAT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, message) #define TEST_ASSERT_EQUAL_FLOAT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, message) #define TEST_ASSERT_EQUAL_FLOAT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, message) #define TEST_ASSERT_FLOAT_IS_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, __LINE__, message) #define TEST_ASSERT_FLOAT_IS_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, __LINE__, message) #define TEST_ASSERT_FLOAT_IS_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, __LINE__, message) //Double (If Enabled) #define TEST_ASSERT_DOUBLE_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, __LINE__, message) #define TEST_ASSERT_EQUAL_DOUBLE_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, __LINE__, message) #define TEST_ASSERT_EQUAL_DOUBLE_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, __LINE__, message) #define TEST_ASSERT_DOUBLE_IS_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, __LINE__, message) #define TEST_ASSERT_DOUBLE_IS_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, __LINE__, message) #define TEST_ASSERT_DOUBLE_IS_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, __LINE__, message) #endif libsml-0.1.1+git20170608/test/src/0000755000175000017500000000000012734144572015775 5ustar andreasandreaslibsml-0.1.1+git20170608/test/src/sml_value_test.c0000644000175000017500000000776512734144572021206 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include "test_helper.h" #include TEST_GROUP(sml_value); sml_buffer *buf; TEST_SETUP(sml_value) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_value) { sml_buffer_free(buf); } TEST(sml_value, init) { sml_value *v = sml_value_init(); TEST_ASSERT_NOT_NULL(v); sml_value_free( v ); } TEST(sml_value, parse_octet_string) { hex2binary("0648616C6C6F", sml_buf_get_current_buf(buf)); sml_value *v = sml_value_parse(buf); TEST_ASSERT_NOT_NULL(v); TEST_ASSERT_EQUAL(SML_TYPE_OCTET_STRING, v->type); expected_octet_string(v->data.bytes, "Hallo", 5); sml_value_free( v ); } TEST(sml_value, parse_boolean) { hex2binary("4200", sml_buf_get_current_buf(buf)); sml_value *v = sml_value_parse(buf); TEST_ASSERT_NOT_NULL(v); TEST_ASSERT_EQUAL(SML_TYPE_BOOLEAN, v->type); TEST_ASSERT_FALSE(*(v->data.boolean)); sml_value_free( v ); } TEST(sml_value, parse_unsigned32) { hex2binary("6500000001", sml_buf_get_current_buf(buf)); sml_value *v = sml_value_parse(buf); TEST_ASSERT_NOT_NULL(v); TEST_ASSERT_EQUAL(1, *(v->data.uint32)); TEST_ASSERT_EQUAL((SML_TYPE_UNSIGNED | SML_TYPE_NUMBER_32), v->type); TEST_ASSERT_EQUAL(5, buf->cursor); sml_value_free( v ); } TEST(sml_value, parse_integer64_fewer_bytes) { hex2binary("58FFFFFFFFFFFF0F", sml_buf_get_current_buf(buf)); sml_value *v = sml_value_parse(buf); TEST_ASSERT_EQUAL(-241, *(v->data.int64)); TEST_ASSERT_EQUAL((SML_TYPE_INTEGER | SML_TYPE_NUMBER_64), v->type); sml_value_free( v ); } TEST(sml_value, parse_optional) { hex2binary("01", sml_buf_get_current_buf(buf)); sml_value *v = sml_value_parse(buf); TEST_ASSERT_NULL(v); TEST_ASSERT_EQUAL(1, buf->cursor); sml_value_free( v ); } TEST(sml_value, write_octet_string) { sml_value *v = sml_value_init(); v->type = SML_TYPE_OCTET_STRING; v->data.bytes = sml_octet_string_init((unsigned char *)"Hallo", 5); sml_value_write(v, buf); expected_buf(buf, "0648616C6C6F", 6); sml_value_free( v ); } TEST(sml_value, write_boolean) { sml_value *v = sml_value_init(); v->type = SML_TYPE_BOOLEAN; v->data.boolean = sml_boolean_init(SML_BOOLEAN_FALSE); sml_value_write(v, buf); expected_buf(buf, "4200", 2); sml_value_free( v ); } TEST(sml_value, write_unsigned32) { sml_value *v = sml_value_init(); v->type = SML_TYPE_UNSIGNED | SML_TYPE_NUMBER_32; v->data.uint32 = sml_u32_init(42); sml_value_write(v, buf); expected_buf(buf, "650000002A", 5); sml_value_free( v ); } TEST(sml_value, write_integer16) { sml_value *v = sml_value_init(); v->type = SML_TYPE_INTEGER | SML_TYPE_NUMBER_16; v->data.int16 = sml_i16_init(-5); sml_value_write(v, buf); expected_buf(buf, "53FFFB", 3); sml_value_free( v ); } TEST(sml_value, write_optional) { sml_value_write(0, buf); expected_buf(buf, "01", 1); } TEST_GROUP_RUNNER(sml_value) { RUN_TEST_CASE(sml_value, init); RUN_TEST_CASE(sml_value, parse_octet_string); RUN_TEST_CASE(sml_value, parse_boolean); RUN_TEST_CASE(sml_value, parse_unsigned32); RUN_TEST_CASE(sml_value, parse_integer64_fewer_bytes); RUN_TEST_CASE(sml_value, parse_optional); RUN_TEST_CASE(sml_value, write_octet_string); RUN_TEST_CASE(sml_value, write_boolean); RUN_TEST_CASE(sml_value, write_unsigned32); RUN_TEST_CASE(sml_value, write_integer16); RUN_TEST_CASE(sml_value, write_optional); } libsml-0.1.1+git20170608/test/src/sml_time_test.c0000644000175000017500000000462212734144572021015 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include "test_helper.h" #include TEST_GROUP(sml_time); sml_buffer *buf; TEST_SETUP(sml_time) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_time) { sml_buffer_free(buf); } TEST(sml_time, init) { sml_time *t = sml_time_init(); TEST_ASSERT_NOT_NULL(t); sml_time_free( t ); } TEST(sml_time, parse_sec_index) { hex2binary("72620165000000FF", sml_buf_get_current_buf(buf)); sml_time *t = sml_time_parse(buf); TEST_ASSERT_NOT_NULL(t); TEST_ASSERT_EQUAL(SML_TIME_SEC_INDEX, *(t->tag)); TEST_ASSERT_EQUAL(8, buf->cursor); sml_time_free( t ); } TEST(sml_time, parse_timestamp) { hex2binary("72620265000000FF", sml_buf_get_current_buf(buf)); sml_time *t = sml_time_parse(buf); TEST_ASSERT_NOT_NULL(t); TEST_ASSERT_EQUAL(SML_TIME_TIMESTAMP, *(t->tag)); TEST_ASSERT_EQUAL(8, buf->cursor); sml_time_free( t ); } TEST(sml_time, parse_optional) { hex2binary("01", sml_buf_get_current_buf(buf)); sml_time *t = sml_time_parse(buf); TEST_ASSERT_NULL(t); TEST_ASSERT_EQUAL(1, buf->cursor); sml_time_free( t ); } TEST(sml_time, write_sec_index) { sml_time *t = sml_time_init(); t->data.sec_index = sml_u32_init(255); t->tag = sml_u8_init(SML_TIME_SEC_INDEX); sml_time_write(t, buf); expected_buf(buf, "72620165000000FF", 8); sml_time_free( t ); } TEST(sml_time, write_optional) { sml_time_write(0, buf); expected_buf(buf, "01", 1); } TEST_GROUP_RUNNER(sml_time) { RUN_TEST_CASE(sml_time, init); RUN_TEST_CASE(sml_time, parse_sec_index); RUN_TEST_CASE(sml_time, parse_timestamp); RUN_TEST_CASE(sml_time, parse_optional); RUN_TEST_CASE(sml_time, write_sec_index); RUN_TEST_CASE(sml_time, write_optional); } libsml-0.1.1+git20170608/test/src/sml_get_profile_pack_request_test.c0000644000175000017500000000354412734144572025126 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include "test_helper.h" #include TEST_GROUP(sml_get_profile_pack_request); sml_buffer *buf; TEST_SETUP(sml_get_profile_pack_request) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_get_profile_pack_request) { sml_buffer_free(buf); } TEST(sml_get_profile_pack_request, init) { sml_get_profile_pack_request *r = sml_get_profile_pack_request_init(); TEST_ASSERT_NOT_NULL(r); sml_get_profile_pack_request_free( r ); } TEST(sml_get_profile_pack_request, parse) { hex2binary("7901010101010101730648616C6C6F0648616C6C6F0648616C6C6F01", sml_buf_get_current_buf(buf)); sml_get_profile_pack_request *r = sml_get_profile_pack_request_parse(buf); TEST_ASSERT_NOT_NULL(r); TEST_ASSERT_NOT_NULL(r->object_list); TEST_ASSERT_NOT_NULL(r->object_list->next); TEST_ASSERT_NOT_NULL(r->object_list->next->next); TEST_ASSERT_NULL(r->object_list->next->next->next); sml_get_profile_pack_request_free( r ); } TEST_GROUP_RUNNER(sml_get_profile_pack_request) { RUN_TEST_CASE(sml_get_profile_pack_request, init); RUN_TEST_CASE(sml_get_profile_pack_request, parse); } libsml-0.1.1+git20170608/test/src/sml_message_test.c0000644000175000017500000000351512734144572021503 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include "test_helper.h" #include TEST_GROUP(sml_message); sml_buffer *buf; TEST_SETUP(sml_message) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_message) { sml_buffer_free(buf); } TEST(sml_message, init) { sml_message *msg = sml_message_init(); TEST_ASSERT_NOT_NULL(msg); TEST_ASSERT_NOT_NULL(msg->transaction_id); sml_message_free( msg ); } TEST(sml_message, init_unique_transaction_id) { sml_message *msg1 = sml_message_init(); sml_message *msg2 = sml_message_init(); TEST_ASSERT_TRUE(sml_octet_string_cmp(msg1->transaction_id, msg2->transaction_id) != 0); sml_message_free( msg2 ); sml_message_free( msg1 ); } TEST(sml_message, parse) { hex2binary("7607003800003FB662006200726301017601010700380042153D0B06454D48010271533BCD010163820800", sml_buf_get_current_buf(buf)); sml_message *msg = sml_message_parse(buf); TEST_ASSERT_NOT_NULL(msg); sml_message_free( msg ); } TEST_GROUP_RUNNER(sml_message) { RUN_TEST_CASE(sml_message, init); RUN_TEST_CASE(sml_message, init_unique_transaction_id); RUN_TEST_CASE(sml_message, parse); } libsml-0.1.1+git20170608/test/src/sml_buffer_test.c0000644000175000017500000000247112734144572021330 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include TEST_GROUP(sml_buffer); int buffer_len = 512; sml_buffer *buf; TEST_SETUP(sml_buffer) { buf = sml_buffer_init(buffer_len); } TEST_TEAR_DOWN(sml_buffer) { sml_buffer_free( buf ); } TEST(sml_buffer, init_defaults) { TEST_ASSERT_NOT_NULL(buf); TEST_ASSERT_NOT_NULL(buf->buffer); TEST_ASSERT_EQUAL(buffer_len, buf->buffer_len); TEST_ASSERT_EQUAL(0, buf->cursor); TEST_ASSERT_EQUAL(0, buf->error); TEST_ASSERT_NULL(buf->error_msg); } TEST_GROUP_RUNNER(sml_buffer) { RUN_TEST_CASE(sml_buffer, init_defaults); } libsml-0.1.1+git20170608/test/src/sml_open_request_test.c0000644000175000017500000000232612734144572022567 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include "test_helper.h" #include TEST_GROUP(sml_open_request); sml_buffer *buf; TEST_SETUP(sml_open_request) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_open_request) { sml_buffer_free(buf); } TEST(sml_open_request, init) { sml_open_request *m = sml_open_request_init(); TEST_ASSERT_NOT_NULL(m); sml_open_request_free( m ); } TEST_GROUP_RUNNER(sml_open_request) { RUN_TEST_CASE(sml_open_request, init); } libsml-0.1.1+git20170608/test/src/sml_number_test.c0000644000175000017500000001114312734144572021343 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include "../unity/unity.h" #include "test_helper.h" #include TEST_GROUP(sml_number); sml_buffer *buf; TEST_SETUP(sml_number) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_number) { sml_buffer_free(buf); } TEST(sml_number, init_unsigned8) { u8 *n = sml_u8_init(1); TEST_ASSERT_NOT_NULL(n); TEST_ASSERT_EQUAL(1, *n); sml_u8_free( n ); } TEST(sml_number, init_integer16) { i16 *n = sml_i16_init(-1); TEST_ASSERT_NOT_NULL(n); TEST_ASSERT_EQUAL(-1, *n); sml_i16_free( n ); } TEST(sml_number, parse_unsigned8) { hex2binary("6201", sml_buf_get_current_buf(buf)); u8 *n = sml_u8_parse(buf); TEST_ASSERT_EQUAL(1, *n); TEST_ASSERT_EQUAL(2, buf->cursor); sml_u8_free( n ); } TEST(sml_number, parse_unsigned16) { hex2binary("630101", sml_buf_get_current_buf(buf)); u16 *n = sml_u16_parse(buf); TEST_ASSERT_EQUAL(257, *n); sml_u16_free( n ); } TEST(sml_number, parse_unsigned32) { hex2binary("6500000001", sml_buf_get_current_buf(buf)); u32 *n = sml_u32_parse(buf); TEST_ASSERT_EQUAL(1, *n); sml_u32_free( n ); } TEST(sml_number, parse_unsigned32_fewer_bytes) { hex2binary("64010001", sml_buf_get_current_buf(buf)); u32 *n = sml_u32_parse(buf); TEST_ASSERT_EQUAL(65537, *n); sml_u32_free( n ); } TEST(sml_number, parse_unsigned32_optional) { hex2binary("01", sml_buf_get_current_buf(buf)); u32 *n = sml_u32_parse(buf); TEST_ASSERT_NULL(n); TEST_ASSERT_EQUAL(1, buf->cursor); sml_u32_free( n ); } TEST(sml_number, parse_unsigned64) { hex2binary("690000000000000001", sml_buf_get_current_buf(buf)); u64 *n = sml_u64_parse(buf); TEST_ASSERT_EQUAL(1, *n); sml_u64_free( n ); } TEST(sml_number, parse_unsigned64_fewer_bytes) { hex2binary("67000000000001", sml_buf_get_current_buf(buf)); u64 *n = sml_u64_parse(buf); TEST_ASSERT_EQUAL(1, *n); sml_u64_free( n ); } TEST(sml_number, parse_int8) { hex2binary("52FF", sml_buf_get_current_buf(buf)); i8 *n = sml_i8_parse(buf); TEST_ASSERT_EQUAL(-1, *n); sml_i8_free( n ); } TEST(sml_number, parse_int16) { hex2binary("53EC78", sml_buf_get_current_buf(buf)); i16 *n = sml_i16_parse(buf); TEST_ASSERT_EQUAL(-5000, *n); sml_i16_free( n ); } TEST(sml_number, parse_int32) { hex2binary("55FFFFEC78", sml_buf_get_current_buf(buf)); i32 *n = sml_i32_parse(buf); TEST_ASSERT_EQUAL(-5000, *n); sml_i32_free( n ); } TEST(sml_number, parse_int64) { hex2binary("59FFFFFFFFFFFFFFFF", sml_buf_get_current_buf(buf)); i64 *n = sml_i64_parse(buf); TEST_ASSERT_EQUAL(-1, *n); sml_i64_free( n ); } TEST(sml_number, parse_int64_fewer_bytes) { hex2binary("58FFFFFFFFFFEC78", sml_buf_get_current_buf(buf)); i64 *n = sml_i64_parse(buf); TEST_ASSERT_EQUAL(-5000, *n); sml_i64_free( n ); } TEST(sml_number, write_unsigned8) { u8 *n = sml_u8_init(1); sml_u8_write(n, buf); expected_buf(buf, "6201", 2); sml_u8_free( n ); } TEST(sml_number, write_integer32) { i32 *n = sml_i32_init(-5000); sml_i32_write(n, buf); expected_buf(buf, "55FFFFEC78", 5); sml_i32_free( n ); } TEST(sml_number, write_integer8_optional) { sml_i8_write(0, buf); expected_buf(buf, "01", 1); } TEST_GROUP_RUNNER(sml_number) { RUN_TEST_CASE(sml_number, init_unsigned8); RUN_TEST_CASE(sml_number, init_integer16); RUN_TEST_CASE(sml_number, parse_unsigned8); RUN_TEST_CASE(sml_number, parse_unsigned16); RUN_TEST_CASE(sml_number, parse_unsigned32); RUN_TEST_CASE(sml_number, parse_unsigned64); RUN_TEST_CASE(sml_number, parse_unsigned32_fewer_bytes); RUN_TEST_CASE(sml_number, parse_unsigned64_fewer_bytes); RUN_TEST_CASE(sml_number, parse_unsigned32_optional); RUN_TEST_CASE(sml_number, parse_int8); RUN_TEST_CASE(sml_number, parse_int16); RUN_TEST_CASE(sml_number, parse_int32); RUN_TEST_CASE(sml_number, parse_int64); RUN_TEST_CASE(sml_number, parse_int64_fewer_bytes); RUN_TEST_CASE(sml_number, write_unsigned8); RUN_TEST_CASE(sml_number, write_integer32); RUN_TEST_CASE(sml_number, write_integer8_optional); } libsml-0.1.1+git20170608/test/src/sml_status_test.c0000644000175000017500000000472712734144572021410 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include "test_helper.h" #include TEST_GROUP(sml_status); sml_buffer *buf; TEST_SETUP(sml_status) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_status) { sml_buffer_free(buf); } TEST(sml_status, init) { sml_status *s = sml_status_init(); TEST_ASSERT_NOT_NULL(s); sml_status_free( s ); } TEST(sml_status, parse_status8) { hex2binary("6201", sml_buf_get_current_buf(buf)); sml_status *s = sml_status_parse(buf); TEST_ASSERT_NOT_NULL(s); TEST_ASSERT_EQUAL(1, *(s->data.status8)); TEST_ASSERT_EQUAL((SML_TYPE_UNSIGNED | SML_TYPE_NUMBER_8), s->type); sml_status_free( s ); } TEST(sml_status, parse_optional) { hex2binary("01", sml_buf_get_current_buf(buf)); sml_status *s = sml_status_parse(buf); TEST_ASSERT_NULL(s); TEST_ASSERT_FALSE(sml_buf_has_errors(buf)); TEST_ASSERT_EQUAL(1, buf->cursor); sml_status_free( s ); } TEST(sml_status, parse_not_unsigned) { hex2binary("5001", sml_buf_get_current_buf(buf)); sml_status *s = sml_status_parse(buf); TEST_ASSERT_NULL(s); TEST_ASSERT_TRUE(sml_buf_has_errors(buf)); sml_status_free( s ); } TEST(sml_status, write_status32) { sml_status *s = sml_status_init(); s->type = SML_TYPE_UNSIGNED | SML_TYPE_NUMBER_32; s->data.status32 = sml_u32_init(42); sml_status_write(s, buf); expected_buf(buf, "650000002A", 5); sml_status_free( s ); } TEST(sml_status, write_optional) { sml_status_write(0, buf); expected_buf(buf, "01", 1); } TEST_GROUP_RUNNER(sml_status) { RUN_TEST_CASE(sml_status, init); RUN_TEST_CASE(sml_status, parse_status8); RUN_TEST_CASE(sml_status, parse_optional); RUN_TEST_CASE(sml_status, parse_not_unsigned); RUN_TEST_CASE(sml_status, write_status32); RUN_TEST_CASE(sml_status, write_optional); } libsml-0.1.1+git20170608/test/src/test_helper.h0000644000175000017500000000202312734144572020461 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef TEST_HELPER_H_ #define TEST_HELPER_H_ #include #include int hex2binary(char *hex, unsigned char *buf); void expected_buf(sml_buffer *buf, char *hex, int len); void expected_octet_string(octet_string *str, char *content, int len); #endif libsml-0.1.1+git20170608/test/src/sml_tree_test.c0000644000175000017500000001164712734144572021023 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include "test_helper.h" #include #include TEST_GROUP(sml_tree); sml_buffer *buf; TEST_SETUP(sml_tree) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_tree) { sml_buffer_free(buf); } TEST(sml_tree, init) { sml_tree *t = sml_tree_init(); TEST_ASSERT_NOT_NULL(t); sml_tree_free( t ); } TEST(sml_tree, add_tree) { sml_tree *t = sml_tree_init(); sml_tree_add_tree(t, sml_tree_init()); TEST_ASSERT_NOT_NULL(t->child_list[0]); TEST_ASSERT_EQUAL(1, t->child_list_len); sml_tree_free( t ); } TEST(sml_tree, write) { sml_tree *t = sml_tree_init(); t->parameter_name = sml_octet_string_init((unsigned char *)"Hallo", 5); sml_tree_write(t, buf); expected_buf(buf, "730648616C6C6F0101", 9); sml_tree_free( t ); } TEST(sml_tree, parse_with_child) { hex2binary("730648616C6C6F0171730648616C6C6F0101", sml_buf_get_current_buf(buf)); sml_tree *t = sml_tree_parse(buf); TEST_ASSERT_NOT_NULL(t); TEST_ASSERT_NOT_NULL(t->child_list[0]); TEST_ASSERT_EQUAL(1, t->child_list_len); sml_tree_free( t ); } TEST(sml_tree, parse_with_error_child) { hex2binary("730648616C6C6F0171720648616C6C6F0101", sml_buf_get_current_buf(buf)); sml_tree *t = sml_tree_parse(buf); TEST_ASSERT_NULL(t); sml_tree_free( t ); } TEST_GROUP_RUNNER(sml_tree) { RUN_TEST_CASE(sml_tree, init); RUN_TEST_CASE(sml_tree, add_tree); RUN_TEST_CASE(sml_tree, write); RUN_TEST_CASE(sml_tree, parse_with_child); RUN_TEST_CASE(sml_tree, parse_with_error_child); } TEST_GROUP(sml_tree_path); TEST_SETUP(sml_tree_path) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_tree_path) { sml_buffer_free(buf); } TEST(sml_tree_path, init) { sml_tree_path *t = sml_tree_path_init(); TEST_ASSERT_NOT_NULL(t); sml_tree_path_free( t ); } TEST(sml_tree_path, add_entry) { sml_tree_path *t = sml_tree_path_init(); TEST_ASSERT_NOT_NULL(t); TEST_ASSERT_EQUAL(0, t->path_entries_len); sml_tree_path_add_path_entry(t, sml_octet_string_init((unsigned char *)"tree", 4)); TEST_ASSERT_EQUAL(1, t->path_entries_len); sml_tree_path_free( t ); } TEST(sml_tree_path, parse) { hex2binary("720648616C6C6F0264", sml_buf_get_current_buf(buf)); sml_tree_path *t = sml_tree_path_parse(buf); TEST_ASSERT_NOT_NULL(t); TEST_ASSERT_EQUAL(2, t->path_entries_len); TEST_ASSERT_EQUAL(0, sml_octet_string_cmp_with_hex(t->path_entries[0], "48616C6C6F")); TEST_ASSERT_EQUAL(0, sml_octet_string_cmp_with_hex(t->path_entries[1], "64")); sml_tree_path_free( t ); } TEST(sml_tree_path, write) { sml_tree_path *t = sml_tree_path_init(); sml_tree_path_add_path_entry(t, sml_octet_string_init((unsigned char *)"Hallo", 5)); sml_tree_path_add_path_entry(t, sml_octet_string_init((unsigned char *)"Hallo", 5)); sml_tree_path_write(t, buf); expected_buf(buf, "720648616C6C6F0648616C6C6F", 13); sml_tree_path_free( t ); } TEST_GROUP_RUNNER(sml_tree_path) { RUN_TEST_CASE(sml_tree_path, init); RUN_TEST_CASE(sml_tree_path, add_entry); RUN_TEST_CASE(sml_tree_path, parse); RUN_TEST_CASE(sml_tree_path, write); } TEST_GROUP(sml_proc_par_value); TEST_SETUP(sml_proc_par_value) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_proc_par_value) { sml_buffer_free(buf); } TEST(sml_proc_par_value, init) { sml_proc_par_value *t = sml_proc_par_value_init(); TEST_ASSERT_NOT_NULL(t); sml_proc_par_value_free( t ); } TEST(sml_proc_par_value, parse_time) { hex2binary("72620472620265000000FF", sml_buf_get_current_buf(buf)); sml_proc_par_value *t = sml_proc_par_value_parse(buf); TEST_ASSERT_NOT_NULL(t); TEST_ASSERT_EQUAL(SML_PROC_PAR_VALUE_TAG_TIME, *(t->tag)); TEST_ASSERT_EQUAL(11, buf->cursor); sml_proc_par_value_free( t ); } TEST(sml_proc_par_value, write_time) { sml_proc_par_value *ppv = sml_proc_par_value_init(); ppv->tag = sml_u8_init(SML_PROC_PAR_VALUE_TAG_TIME); sml_time *t = sml_time_init(); t->data.sec_index = sml_u32_init(255); t->tag = sml_u8_init(SML_TIME_SEC_INDEX); ppv->data.time = t; sml_proc_par_value_write(ppv, buf); expected_buf(buf, "72620472620165000000FF", 11); sml_proc_par_value_free( ppv ); } TEST_GROUP_RUNNER(sml_proc_par_value) { RUN_TEST_CASE(sml_proc_par_value, init); RUN_TEST_CASE(sml_proc_par_value, parse_time); RUN_TEST_CASE(sml_proc_par_value, write_time); } libsml-0.1.1+git20170608/test/src/sml_boolean_test.c0000644000175000017500000000512412734144572021474 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include "test_helper.h" #include TEST_GROUP(sml_boolean); sml_buffer *buf; TEST_SETUP(sml_boolean) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_boolean) { sml_buffer_free(buf); } TEST(sml_boolean, init) { sml_boolean *b = sml_boolean_init(SML_BOOLEAN_TRUE); TEST_ASSERT_NOT_NULL(b); TEST_ASSERT_EQUAL(SML_BOOLEAN_TRUE, *b); sml_boolean_free( b ); } TEST(sml_boolean, parse_true) { hex2binary("420F", sml_buf_get_current_buf(buf)); sml_boolean *b = sml_boolean_parse(buf); TEST_ASSERT_NOT_NULL(b); TEST_ASSERT_EQUAL(SML_BOOLEAN_TRUE, *b); sml_boolean_free( b ); } TEST(sml_boolean, parse_false) { hex2binary("4200", sml_buf_get_current_buf(buf)); sml_boolean *b = sml_boolean_parse(buf); TEST_ASSERT_NOT_NULL(b); TEST_ASSERT_EQUAL(SML_BOOLEAN_FALSE, *b); TEST_ASSERT_EQUAL(2, buf->cursor); sml_boolean_free( b ); } TEST(sml_boolean, parse_optional) { hex2binary("01", sml_buf_get_current_buf(buf)); sml_boolean *b = sml_boolean_parse(buf); TEST_ASSERT_NULL(b); TEST_ASSERT_FALSE(sml_buf_has_errors(buf)); sml_boolean_free( b ); } TEST(sml_boolean, write_true) { sml_boolean *b = sml_boolean_init(SML_BOOLEAN_TRUE); sml_boolean_write(b, buf); expected_buf(buf, "42FF", 2); sml_boolean_free( b ); } TEST(sml_boolean, write_false) { sml_boolean *b = sml_boolean_init(SML_BOOLEAN_FALSE); sml_boolean_write(b, buf); expected_buf(buf, "4200", 2); sml_boolean_free( b ); } TEST(sml_boolean, write_optional) { sml_boolean_write(0, buf); expected_buf(buf, "01", 1); } TEST_GROUP_RUNNER(sml_boolean) { RUN_TEST_CASE(sml_boolean, init); RUN_TEST_CASE(sml_boolean, parse_true); RUN_TEST_CASE(sml_boolean, parse_false); RUN_TEST_CASE(sml_boolean, parse_optional); RUN_TEST_CASE(sml_boolean, write_true); RUN_TEST_CASE(sml_boolean, write_false); RUN_TEST_CASE(sml_boolean, write_optional); } libsml-0.1.1+git20170608/test/src/test_helper.c0000644000175000017500000000370412734144572020463 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include "test_helper.h" #include "../unity/unity_fixture.h" #include #include uint8_t test_helper_ctoi(uint8_t c){ uint8_t ret = 0; if((c >= '0') && (c <= '9')){ ret = c - '0'; } else if((c >= 'a') && (c <= 'f')){ ret = c - 'a' + 10; } else if((c >= 'A') && (c <= 'F')){ ret = c - 'A' + 10; } return ret; } static inline uint8_t test_helper_c2toi(uint8_t c1, uint8_t c2){ return test_helper_ctoi(c1) << 4 | test_helper_ctoi(c2); } static inline uint8_t test_helper_c2ptoi(char* c){ return test_helper_ctoi((uint8_t)c[0]) << 4 | test_helper_ctoi((uint8_t)c[1]); } int hex2binary(char *hex, unsigned char *buf) { int i; int len = strlen(hex); for (i = 0; i < (len /2); i++) { buf[i] = test_helper_c2ptoi(&(hex[i * 2])); } return i; } void expected_buf(sml_buffer *buf, char *hex, int len) { unsigned char expected_buf[len]; hex2binary(hex, expected_buf); TEST_ASSERT_EQUAL_MEMORY(expected_buf, buf->buffer, len); TEST_ASSERT_EQUAL(len, buf->cursor); } void expected_octet_string(octet_string *str, char *content, int len) { TEST_ASSERT_NOT_NULL(str); TEST_ASSERT_EQUAL(len, str->len); TEST_ASSERT_EQUAL_MEMORY(content, str->str, len); } libsml-0.1.1+git20170608/test/src/sml_octet_string_test.c0000644000175000017500000000721612734144572022565 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include "test_helper.h" #include TEST_GROUP(sml_octet_string); sml_buffer *buf; TEST_SETUP(sml_octet_string) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_octet_string) { sml_buffer_free(buf); } TEST(sml_octet_string, init) { octet_string *str = sml_octet_string_init((unsigned char *)"hallo", 5); TEST_ASSERT_EQUAL(5, str->len); TEST_ASSERT_EQUAL_MEMORY("hallo", str->str, 5); sml_octet_string_free( str ); } TEST(sml_octet_string, parse) { hex2binary("0648616C6C6F", sml_buf_get_current_buf(buf)); octet_string *str = sml_octet_string_parse(buf); expected_octet_string(str, "Hallo", 5); sml_octet_string_free( str ); } TEST(sml_octet_string, parse_multiple_tl_fields) { hex2binary("8102616161616F6161616161616161616161", sml_buf_get_current_buf(buf)); octet_string *str = sml_octet_string_parse(buf); expected_octet_string(str, "aaaaoaaaaaaaaaaa", 16); sml_octet_string_free( str ); } TEST(sml_octet_string, parse_optional) { hex2binary("01", sml_buf_get_current_buf(buf)); octet_string *str = sml_octet_string_parse(buf); TEST_ASSERT_FALSE(sml_buf_has_errors(buf)); TEST_ASSERT_NULL(str); TEST_ASSERT_EQUAL(1, buf->cursor); sml_octet_string_free( str ); } TEST(sml_octet_string, write) { octet_string *str = sml_octet_string_init((unsigned char *)"Hallo", 5); sml_octet_string_write(str, buf); expected_buf(buf, "0648616C6C6F", 6); sml_octet_string_free( str ); } TEST(sml_octet_string, write_multiple_tl_fields) { octet_string *str = sml_octet_string_init((unsigned char *)"aaaaoaaaaaaaaaaa", 16); sml_octet_string_write(str, buf); expected_buf(buf, "8102616161616F6161616161616161616161", 18); sml_octet_string_free( str ); } TEST(sml_octet_string, write_optional) { sml_octet_string_write(0, buf); expected_buf(buf, "01", 1); } TEST(sml_octet_string, cmp) { octet_string *s1 = sml_octet_string_init((unsigned char *)"Hallo", 5); octet_string *s2 = sml_octet_string_init((unsigned char *)"Hi", 2); octet_string *s3 = sml_octet_string_init((unsigned char *)"Hallo", 5); TEST_ASSERT_TRUE(sml_octet_string_cmp(s1, s2) != 0); TEST_ASSERT_EQUAL(0, sml_octet_string_cmp(s1, s3)); sml_octet_string_free( s3 ); sml_octet_string_free( s2 ); sml_octet_string_free( s1 ); } TEST(sml_octet_string, cmp_with_hex) { octet_string *s = sml_octet_string_init((unsigned char *)"Hallo", 5); TEST_ASSERT_EQUAL(0, sml_octet_string_cmp_with_hex(s, "48616C6C6F")); sml_octet_string_free( s ); } TEST_GROUP_RUNNER(sml_octet_string) { RUN_TEST_CASE(sml_octet_string, init); RUN_TEST_CASE(sml_octet_string, parse); RUN_TEST_CASE(sml_octet_string, parse_multiple_tl_fields); RUN_TEST_CASE(sml_octet_string, parse_optional); RUN_TEST_CASE(sml_octet_string, write); RUN_TEST_CASE(sml_octet_string, write_multiple_tl_fields); RUN_TEST_CASE(sml_octet_string, write_optional); RUN_TEST_CASE(sml_octet_string, cmp); RUN_TEST_CASE(sml_octet_string, cmp_with_hex); } libsml-0.1.1+git20170608/test/src/sml_list_test.c0000644000175000017500000001045512734144572021033 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include "test_helper.h" #include TEST_GROUP(sml_list); sml_buffer *buf; TEST_SETUP(sml_list) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_list) { sml_buffer_free(buf); } TEST(sml_list, init) { sml_list *l = sml_list_init(); TEST_ASSERT_NOT_NULL(l); TEST_ASSERT_NULL(l->next); sml_list_free( l ); } TEST(sml_list, add) { sml_list *l = sml_list_init(); sml_list *n = sml_list_init(); sml_list_add(l, n); TEST_ASSERT_NOT_NULL(l); TEST_ASSERT_NOT_NULL(l->next); TEST_ASSERT_TRUE(n == l->next); sml_list_free( l ); } TEST(sml_list, parse_two_entries) { hex2binary("727702610101010142000177026101010101420001", sml_buf_get_current_buf(buf)); sml_list *l = sml_list_parse(buf); TEST_ASSERT_FALSE(sml_buf_has_errors(buf)); TEST_ASSERT_NOT_NULL(l); TEST_ASSERT_NOT_NULL(l->next); TEST_ASSERT_EQUAL(0, sml_octet_string_cmp_with_hex(l->obj_name, "61")); sml_list_free( l ); } TEST(sml_list, parse_optional) { hex2binary("01", sml_buf_get_current_buf(buf)); sml_list *l = sml_list_parse(buf); TEST_ASSERT_NULL(l); TEST_ASSERT_FALSE(sml_buf_has_errors(buf)); sml_list_free( l ); } TEST(sml_list, write_one_entry) { sml_list *l = sml_list_init(); l->obj_name = sml_octet_string_init((unsigned char *)"Hallo", 5); l->value = sml_value_init(); l->value->type = SML_TYPE_OCTET_STRING; l->value->data.bytes = sml_octet_string_init((unsigned char *)"Hallo", 5); sml_list_write(l, buf); expected_buf(buf, "71770648616C6C6F010101010648616C6C6F01", 19); sml_list_free( l ); } TEST(sml_list, write_optional) { sml_list_write(0, buf); expected_buf(buf, "01", 1); } TEST_GROUP_RUNNER(sml_list) { RUN_TEST_CASE(sml_list, init); RUN_TEST_CASE(sml_list, add); RUN_TEST_CASE(sml_list, parse_two_entries); RUN_TEST_CASE(sml_list, parse_optional); RUN_TEST_CASE(sml_list, write_one_entry); RUN_TEST_CASE(sml_list, write_optional); } TEST_GROUP(sml_sequence); sml_buffer *buf; TEST_SETUP(sml_sequence) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_sequence) { sml_buffer_free(buf); } TEST(sml_sequence, init) { sml_sequence *seq = sml_sequence_init(&free); TEST_ASSERT_NOT_NULL(seq); sml_sequence_free( seq ); } static void * sml_octet_string_parse_( sml_buffer * buf ) { return sml_octet_string_parse( buf ); } static void sml_octet_string_free_( void * p ) { sml_octet_string_free( p ); } TEST(sml_sequence, parse_octet_string) { hex2binary("720648616C6C6F0648616C6C6F", sml_buf_get_current_buf(buf)); sml_sequence *seq = sml_sequence_parse(buf, sml_octet_string_parse_, sml_octet_string_free_); TEST_ASSERT_NOT_NULL(seq); TEST_ASSERT_EQUAL(2, seq->elems_len); sml_sequence_free( seq ); } static void sml_octet_string_write_( void * p, sml_buffer * buf ) { sml_octet_string_write( p, buf ); } TEST(sml_sequence, write_octet_string) { sml_sequence *seq = sml_sequence_init( sml_octet_string_free_ ); sml_sequence_add(seq, sml_octet_string_init((unsigned char *)"Hallo", 5)); sml_sequence_add(seq, sml_octet_string_init((unsigned char *)"Hallo", 5)); sml_sequence_write(seq, buf, sml_octet_string_write_ ); expected_buf(buf, "720648616C6C6F0648616C6C6F", 13); sml_sequence_free( seq ); } TEST(sml_sequence, free_octet_string) { sml_sequence *seq = sml_sequence_init( sml_octet_string_free_ ); sml_sequence_add(seq, sml_octet_string_init((unsigned char *)"Hallo", 5)); sml_sequence_free(seq); } TEST_GROUP_RUNNER(sml_sequence) { RUN_TEST_CASE(sml_sequence, init); RUN_TEST_CASE(sml_sequence, parse_octet_string); RUN_TEST_CASE(sml_sequence, write_octet_string); RUN_TEST_CASE(sml_sequence, free_octet_string); } libsml-0.1.1+git20170608/test/src/sml_file_test.c0000644000175000017500000000240012734144572020766 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include "test_helper.h" #include TEST_GROUP(sml_file); sml_buffer *buf; TEST_SETUP(sml_file) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_file) { sml_buffer_free(buf); } TEST(sml_file, init) { sml_file *file = sml_file_init(); TEST_ASSERT_NOT_NULL(file); TEST_ASSERT_EQUAL(0, file->messages_len); TEST_ASSERT_NULL(file->messages); TEST_ASSERT_NOT_NULL(file->buf); sml_file_free( file ); } TEST_GROUP_RUNNER(sml_file) { RUN_TEST_CASE(sml_file, init); } libsml-0.1.1+git20170608/test/test_main.c0000644000175000017500000000256512734144572017345 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include "unity/unity_fixture.h" static void runAllTests() { RUN_TEST_GROUP(sml_octet_string); RUN_TEST_GROUP(sml_buffer); RUN_TEST_GROUP(sml_number); RUN_TEST_GROUP(sml_boolean); RUN_TEST_GROUP(sml_value); RUN_TEST_GROUP(sml_status); RUN_TEST_GROUP(sml_list); RUN_TEST_GROUP(sml_sequence); RUN_TEST_GROUP(sml_time); RUN_TEST_GROUP(sml_tree); RUN_TEST_GROUP(sml_tree_path); RUN_TEST_GROUP(sml_proc_par_value); RUN_TEST_GROUP(sml_open_request); RUN_TEST_GROUP(sml_get_profile_pack_request); RUN_TEST_GROUP(sml_message); RUN_TEST_GROUP(sml_file); } int main(int argc, char * argv[]) { return UnityMain(argc, argv, runAllTests); }libsml-0.1.1+git20170608/test/Makefile0000644000175000017500000000154012734144572016646 0ustar andreasandreasUNAME := $(shell uname) CFLAGS += -I../sml/include/ -std=c99 -Wall -Wextra -pedantic LIBSML = ../sml/lib/libsml.a ifeq ($(UNAME), Linux) LIBS = -luuid endif UNITY = \ unity/unity.o \ unity/unity_fixture.o OBJS = \ src/test_helper.o \ src/sml_octet_string_test.o \ src/sml_buffer_test.o \ src/sml_number_test.o \ src/sml_boolean_test.o \ src/sml_value_test.o \ src/sml_status_test.o \ src/sml_list_test.o \ src/sml_time_test.o \ src/sml_tree_test.o \ src/sml_file_test.o \ src/sml_open_request_test.o \ src/sml_get_profile_pack_request_test.o \ src/sml_message_test.o test_run: libsml test @./test test : $(UNITY) $(OBJS) $(LIBSML) $(CC) $(CFLAGS) $(LIBS) $^ test_main.c -o test $(LIBS) .PHONY: code libsml : @$(MAKE) -C ../sml %.o : %.c $(CC) $(CFLAGS) -c $^ -o $@ .PHONY: clean clean : @rm -f unity/*.o @rm -f src/*.o @rm -f test libsml-0.1.1+git20170608/debian/0000755000175000017500000000000012734144572015451 5ustar andreasandreaslibsml-0.1.1+git20170608/debian/rules0000755000175000017500000000171012734144572016530 0ustar andreasandreas#!/usr/bin/make -f # -*- makefile -*- # Sample debian/rules that uses debhelper. # This file was originally written by Joey Hess and Craig Small. # As a special exception, when this file is copied by dh-make into a # dh-make output file, you may use that output file without restriction. # This special exception was added by Craig Small in version 0.37 of dh-make. # Uncomment this to turn on verbose mode. #export DH_VERBOSE=1 %: dh $@ # Skip some commands override_dh_pysupport: override_dh_installwm: override_dh_installxfonts: override_dh_installgsettings: override_dh_installmenu: override_dh_icons: override_dh_gconf: override_dh_installcron: override_dh_installdebconf: override_dh_installemacsen: override_dh_installifupdown: override_dh_installinit: override_dh_installmime: override_dh_installmodules: override_dh_installlogcheck: override_dh_installlogrotate: override_dh_installpam: override_dh_installppp: override_dh_installudev: override_dh_perl: libsml-0.1.1+git20170608/debian/compat0000644000175000017500000000000212734144572016647 0ustar andreasandreas7 libsml-0.1.1+git20170608/debian/watch0000644000175000017500000000065612734144572016511 0ustar andreasandreas# Example watch control file for uscan # Rename this file to "watch" and then you can run the "uscan" command # to check for upstream updates and more. # See uscan(1) for format # Compulsory line, this is a version 3 file version=3 # Find new releases on GitHub # (uses redirector service from Gunnar Wolf: # http://githubredir.debian.net) http://githubredir.debian.net/githubredir.cgi?author=dailab&project=libsml (.*).tar.gz libsml-0.1.1+git20170608/debian/libsml-dev.install0000644000175000017500000000006512734144572021100 0ustar andreasandreassml/include/* /usr/include sml.pc /usr/lib/pkgconfig libsml-0.1.1+git20170608/debian/libsml1.install0000644000175000017500000000003212734144572020377 0ustar andreasandreassml/lib/libsml.* /usr/lib libsml-0.1.1+git20170608/debian/changelog0000644000175000017500000000254612734144572017332 0ustar andreasandreaslibsml (0.1.1-1~wip) unstable; urgency=low * Added sml_value_to_double() * Implemented sml_octet_string_generate_uuid() when not linking against libuuid * Removed trailing whitespaces & unified codestyle * implemented sml profile stuff -- Steffen Vogel Fri, 30 Sep 2011 19:16:59 +0200 libsml (0.1-5~wip) unstable; urgency=low * Adapted sml_transport_ for vzlogger -- Steffen Vogel Fri, 09 Sep 2011 14:52:56 +0200 libsml (0.1-4~wip) unstable; urgency=low * Fixed bug in sml_message_body_free (#1) * Fixed bug in sml_list_entry_parse (#2) -- Steffen Vogel Thu, 01 Sep 2011 23:22:33 +0200 libsml (0.1-3~wip) unstable; urgency=low * fixed invalid destination for libs * added SONAME to shared library -- Steffen Vogel Thu, 01 Sep 2011 21:05:40 +0200 libsml (0.1-2~wip) unstable; urgency=low * Added information for pkg-config * Eased dependency for libuuid from version 2.17 to 2.16 as there were no changes in the symbols * Changed architecture for developement files to 'all' -- Steffen Vogel Thu, 01 Sep 2011 12:06:39 +0200 libsml (0.1-1~wip) unstable; urgency=low * Work in Progress of current git commit * No ITP issue yet available -- Steffen Vogel Wed, 31 Aug 2011 18:59:39 +0200 libsml-0.1.1+git20170608/debian/libsml-dev.examples0000644000175000017500000000003712734144572021247 0ustar andreasandreasexamples/*.c examples/Makefile libsml-0.1.1+git20170608/debian/source/0000755000175000017500000000000012734144572016751 5ustar andreasandreaslibsml-0.1.1+git20170608/debian/source/options0000644000175000017500000000002412734144572020363 0ustar andreasandreassingle-debian-patch libsml-0.1.1+git20170608/debian/source/format0000644000175000017500000000001412734144572020157 0ustar andreasandreas3.0 (quilt) libsml-0.1.1+git20170608/debian/docs0000644000175000017500000000001212734144572016315 0ustar andreasandreasREADME.md libsml-0.1.1+git20170608/debian/control0000644000175000017500000000166112734144572017060 0ustar andreasandreasSource: libsml Priority: extra Maintainer: Steffen Vogel Build-Depends: debhelper (>= 7.0.50~), uuid-dev (>= 2.16) Standards-Version: 3.9.2 Section: libs Homepage: http://github.com/dailab/libsml Vcs-Git: git://github.com/dailab/libsml.git Vcs-Browser: http://github.com/dailab/libsml Package: libsml-dev Section: libdevel Architecture: any Depends: libsml1 (= ${binary:Version}), uuid-dev (>= 2.16), ${misc:Depends} Description: Header files for libSML This package includes header include files and an example for libSML Package: libsml1 Section: libs Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} Description: Library for the Smart Messaging Language (SML) libSML is a library which implements the Smart Messaging Language (SML) protocol specified by VDE's Forum Netztechnik/Netzbetrieb (FNN). It can be utilized to communicate to FNN specified Smart Meters or Smart Meter components (EDL/MUC). libsml-0.1.1+git20170608/debian/copyright0000644000175000017500000000243112734144572017404 0ustar andreasandreasThis work was packaged for Debian by: Steffen Vogel on Wed, 31 Aug 2011 18:59:39 +0200 It was downloaded from: https://github.com/dailab/libsml Upstream Authors: Juri Glass, Mathias Runge, Nadim El Sayed, Steffen Vogel Copyright: Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed - DAI-Labor, TU-Berlin License: 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 package is distributed in the hope that 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 . On Debian systems, the complete text of the GNU General Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". The Debian packaging is: Copyright (C) 2011 Steffen Vogel and is licensed under the GPL version 3, see above. libsml-0.1.1+git20170608/.gitignore0000644000175000017500000000047012734144572016220 0ustar andreasandreas# Debian Packaging /.pc/ /debian/files /debian/libsml1/ /debian/libsml-dev/ /debian/*.debhelper* /debian/*.substvars # Binaries /test/test /examples/sml_server # Compiled Object files *.slo *.lo *.o # Compiled Dynamic libraries *.so.* *.so # Compiled Static libraries *.lai *.la *.a # Editor files *~ *.swp libsml-0.1.1+git20170608/sml.pc0000644000175000017500000000046612734144572015354 0ustar andreasandreasprefix=/usr exec_prefix=${prefix} libdir=${exec_prefix}/lib includedir=${prefix}/include Name: libSML Description: Library for the Smart Messaging Language (SML) Version: 0.1 URL: http://github.com/dailab/libsml Requires: uuid >= 2.16 Libs: -L${libdir} -lsml Libs.private: -luuid Cflags: -I${includedir}/sml libsml-0.1.1+git20170608/sml/0000755000175000017500000000000012734144572015022 5ustar andreasandreaslibsml-0.1.1+git20170608/sml/src/0000755000175000017500000000000012734144572015611 5ustar andreasandreaslibsml-0.1.1+git20170608/sml/src/sml_get_profile_list_response.c0000644000175000017500000000740412734144572024105 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include // sml_get_profile_list_response; sml_get_profile_list_response *sml_get_profile_list_response_init() { sml_get_profile_list_response *msg = (sml_get_profile_list_response *) malloc(sizeof(sml_get_profile_list_response)); *msg = ( sml_get_profile_list_response ) { .server_id = NULL, .act_time = NULL, .reg_period = NULL, .parameter_tree_path = NULL, .val_time = NULL, .status = NULL, .period_list = NULL, .rawdata = NULL, .period_signature = NULL }; return msg; } static void * sml_period_entry_parse_( sml_buffer * buf ) { return sml_period_entry_parse( buf ); } static void sml_period_entry_free_( void * p ) { sml_period_entry_free( p ); } sml_get_profile_list_response *sml_get_profile_list_response_parse(sml_buffer *buf) { sml_get_profile_list_response *msg = sml_get_profile_list_response_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 9) { buf->error = 1; goto error; } msg->server_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->act_time = sml_time_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->reg_period = sml_u32_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->parameter_tree_path = sml_tree_path_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->val_time = sml_time_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->status = sml_u64_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->period_list = sml_sequence_parse(buf, sml_period_entry_parse_, sml_period_entry_free_); if (sml_buf_has_errors(buf)) goto error; msg->rawdata = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->period_signature = sml_signature_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: buf->error = 1; sml_get_profile_list_response_free(msg); return 0; } static void sml_period_entry_write_( void * p, sml_buffer * buf ) { sml_period_entry_write( p, buf ); } void sml_get_profile_list_response_write(sml_get_profile_list_response *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 9); sml_octet_string_write(msg->server_id, buf); sml_time_write(msg->act_time, buf); sml_u32_write(msg->reg_period, buf); sml_tree_path_write(msg->parameter_tree_path, buf); sml_time_write(msg->val_time, buf); sml_u64_write(msg->status, buf); sml_sequence_write(msg->period_list, buf, sml_period_entry_write_); sml_octet_string_write(msg->rawdata, buf); sml_signature_write(msg->period_signature, buf); } void sml_get_profile_list_response_free(sml_get_profile_list_response *msg) { if (msg) { sml_octet_string_free(msg->server_id); sml_time_free(msg->act_time); sml_number_free(msg->reg_period); sml_tree_path_free(msg->parameter_tree_path); sml_time_free(msg->val_time); sml_number_free(msg->status); sml_sequence_free(msg->period_list); sml_octet_string_free(msg->rawdata); sml_signature_free(msg->period_signature); free(msg); } } libsml-0.1.1+git20170608/sml/src/sml_time.c0000644000175000017500000000357512734144572017600 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include #include #include #include sml_time *sml_time_init() { sml_time *t = (sml_time *) malloc(sizeof(sml_time)); *t = ( sml_time ) { .tag = NULL, .data.sec_index = NULL }; return t; } sml_time *sml_time_parse(sml_buffer *buf) { if (sml_buf_optional_is_skipped(buf)) { return 0; } sml_time *tme = sml_time_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 2) { buf->error = 1; goto error; } tme->tag = sml_u8_parse(buf); if (sml_buf_has_errors(buf)) goto error; tme->data.timestamp = sml_u32_parse(buf); if (sml_buf_has_errors(buf)) goto error; return tme; error: sml_time_free(tme); return 0; } void sml_time_write(sml_time *t, sml_buffer *buf) { if (t == 0) { sml_buf_optional_write(buf); return; } sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 2); sml_u8_write(t->tag, buf); sml_u32_write(t->data.timestamp, buf); } void sml_time_free(sml_time *tme) { if (tme) { sml_number_free(tme->tag); sml_number_free(tme->data.timestamp); free(tme); } } libsml-0.1.1+git20170608/sml/src/sml_tree.c0000644000175000017500000003477512734144572017607 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include #include #include // sml_tree_path; sml_tree_path *sml_tree_path_init() { sml_tree_path *tree_path = (sml_tree_path *) malloc(sizeof(sml_tree_path)); *tree_path = ( sml_tree_path ) { .path_entries_len = 0, .path_entries = NULL }; return tree_path; } sml_tree_path *sml_tree_path_parse(sml_buffer *buf) { if (sml_buf_optional_is_skipped(buf)) { return 0; } sml_tree_path *tree_path = sml_tree_path_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; return 0; } octet_string *s; int elems; for (elems = sml_buf_get_next_length(buf); elems > 0; elems--) { s = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; if (s) { sml_tree_path_add_path_entry(tree_path, s); } } return tree_path; error: buf->error = 1; sml_tree_path_free(tree_path); return 0; } void sml_tree_path_add_path_entry(sml_tree_path *tree_path, octet_string *entry) { tree_path->path_entries_len++; tree_path->path_entries = (octet_string **) realloc(tree_path->path_entries, sizeof(octet_string *) * tree_path->path_entries_len); tree_path->path_entries[tree_path->path_entries_len - 1] = entry; } void sml_tree_path_write(sml_tree_path *tree_path, sml_buffer *buf) { if (tree_path == 0) { sml_buf_optional_write(buf); return; } if (tree_path->path_entries && tree_path->path_entries_len > 0) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, tree_path->path_entries_len); int i; for (i = 0; i < tree_path->path_entries_len; i++) { sml_octet_string_write(tree_path->path_entries[i], buf); } } } void sml_tree_path_free(sml_tree_path *tree_path) { if (tree_path) { if (tree_path->path_entries && tree_path->path_entries_len > 0) { int i; for (i = 0; i < tree_path->path_entries_len; i++) { sml_octet_string_free(tree_path->path_entries[i]); } free(tree_path->path_entries); } free(tree_path); } } // sml_tree; sml_tree *sml_tree_init() { sml_tree *tree = (sml_tree *) malloc(sizeof(sml_tree)); *tree = ( sml_tree ) { .parameter_name = NULL, .parameter_value = NULL, .child_list = NULL, .child_list_len = 0 }; return tree; } sml_tree *sml_tree_parse(sml_buffer *buf) { if (sml_buf_optional_is_skipped(buf)) { return 0; } sml_tree *tree = sml_tree_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 3) { buf->error = 1; goto error; } tree->parameter_name = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; tree->parameter_value = sml_proc_par_value_parse(buf); if (sml_buf_has_errors(buf)) goto error; if (!sml_buf_optional_is_skipped(buf)) { if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } sml_tree *c; int elems; for (elems = sml_buf_get_next_length(buf); elems > 0; elems--) { c = sml_tree_parse(buf); if (sml_buf_has_errors(buf)) goto error; if (c) { sml_tree_add_tree(tree, c); } } } return tree; error: sml_tree_free(tree); return 0; } void sml_tree_add_tree(sml_tree *base_tree, sml_tree *tree) { base_tree->child_list_len++; base_tree->child_list = (sml_tree **) realloc(base_tree->child_list, sizeof(sml_tree *) * base_tree->child_list_len); base_tree->child_list[base_tree->child_list_len - 1] = tree; } void sml_tree_free(sml_tree *tree) { if (tree) { sml_octet_string_free(tree->parameter_name); sml_proc_par_value_free(tree->parameter_value); int i; for (i = 0; i < tree->child_list_len; i++) { sml_tree_free(tree->child_list[i]); } free(tree->child_list); free(tree); } } void sml_tree_write(sml_tree *tree, sml_buffer *buf) { if (tree == 0) { sml_buf_optional_write(buf); return; } sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 3); sml_octet_string_write(tree->parameter_name, buf); sml_proc_par_value_write(tree->parameter_value, buf); if (tree->child_list && tree->child_list_len > 0) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, tree->child_list_len); int i; for (i = 0; i < tree->child_list_len; i++) { sml_tree_write(tree->child_list[i], buf); } } else { sml_buf_optional_write(buf); } } // sml_proc_par_value; sml_proc_par_value *sml_proc_par_value_init() { sml_proc_par_value *value = (sml_proc_par_value *) malloc(sizeof(sml_proc_par_value)); *value = ( sml_proc_par_value ) { .tag = NULL, .data.value = NULL }; return value; } sml_proc_par_value *sml_proc_par_value_parse(sml_buffer *buf) { if (sml_buf_optional_is_skipped(buf)) { return 0; } sml_proc_par_value *ppv = sml_proc_par_value_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 2) { buf->error = 1; goto error; } ppv->tag = sml_u8_parse(buf); if (sml_buf_has_errors(buf)) goto error; switch (*(ppv->tag)) { case SML_PROC_PAR_VALUE_TAG_VALUE: ppv->data.value = sml_value_parse(buf); break; case SML_PROC_PAR_VALUE_TAG_PERIOD_ENTRY: ppv->data.period_entry = sml_period_entry_parse(buf); break; case SML_PROC_PAR_VALUE_TAG_TUPEL_ENTRY: ppv->data.tupel_entry = sml_tupel_entry_parse(buf); break; case SML_PROC_PAR_VALUE_TAG_TIME: ppv->data.time = sml_time_parse(buf); break; default: buf->error = 1; goto error; } return ppv; error: sml_proc_par_value_free(ppv); return 0; } void sml_proc_par_value_write(sml_proc_par_value *value, sml_buffer *buf) { if (value == 0) { sml_buf_optional_write(buf); return; } sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 2); sml_u8_write(value->tag, buf); switch (*(value->tag)) { case SML_PROC_PAR_VALUE_TAG_VALUE: sml_value_write(value->data.value, buf); break; case SML_PROC_PAR_VALUE_TAG_PERIOD_ENTRY: sml_period_entry_write(value->data.period_entry, buf); break; case SML_PROC_PAR_VALUE_TAG_TUPEL_ENTRY: sml_tupel_entry_write(value->data.tupel_entry, buf); break; case SML_PROC_PAR_VALUE_TAG_TIME: sml_time_write(value->data.time, buf); break; default: fprintf(stderr,"libsml: error: unknown tag in %s\n", __FUNCTION__); } } void sml_proc_par_value_free(sml_proc_par_value *ppv) { if (ppv) { if (ppv->tag) { switch (*(ppv->tag)) { case SML_PROC_PAR_VALUE_TAG_VALUE: sml_value_free(ppv->data.value); break; case SML_PROC_PAR_VALUE_TAG_PERIOD_ENTRY: sml_period_entry_free(ppv->data.period_entry); break; case SML_PROC_PAR_VALUE_TAG_TUPEL_ENTRY: sml_tupel_entry_free(ppv->data.tupel_entry); break; case SML_PROC_PAR_VALUE_TAG_TIME: sml_time_free(ppv->data.time); break; default: if (ppv->data.value) { free(ppv->data.value); } } sml_number_free(ppv->tag); } else { // Without the tag, there might be a memory leak. if (ppv->data.value) { free(ppv->data.value); } } free(ppv); } } // sml_tuple_entry; sml_tupel_entry *sml_tupel_entry_init() { sml_tupel_entry *tupel = (sml_tupel_entry *) malloc(sizeof(sml_tupel_entry)); *tupel = ( sml_tupel_entry ) { .server_id = NULL, .sec_index = NULL, .status = NULL, .unit_pA = NULL, .scaler_pA = NULL, .value_pA = NULL, .unit_R1 = NULL, .scaler_R1 = NULL, .value_R1 = NULL, .unit_R4 = NULL, .scaler_R4 = NULL, .value_R4 = NULL, .signature_pA_R1_R4 = NULL, .unit_mA = NULL, .scaler_mA = NULL, .value_mA = NULL, .unit_R2 = NULL, .scaler_R2 = NULL, .value_R2 = NULL, .unit_R3 = NULL, .scaler_R3 = NULL, .value_R3 = NULL, .signature_mA_R2_R3 = NULL }; return tupel; } sml_tupel_entry *sml_tupel_entry_parse(sml_buffer *buf) { if (sml_buf_optional_is_skipped(buf)) { return 0; } sml_tupel_entry *tupel = sml_tupel_entry_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 23) { buf->error = 1; goto error; } tupel->server_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->sec_index = sml_time_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->status = sml_u64_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->unit_pA = sml_unit_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->scaler_pA = sml_i8_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->value_pA = sml_i64_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->unit_R1 = sml_unit_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->scaler_R1 = sml_i8_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->value_R1 = sml_i64_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->unit_R4 = sml_unit_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->scaler_R4 = sml_i8_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->value_R4 = sml_i64_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->signature_pA_R1_R4 = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->unit_mA = sml_unit_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->scaler_mA = sml_i8_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->value_mA = sml_i64_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->unit_R2 = sml_unit_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->scaler_R2 = sml_i8_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->value_R2 = sml_i64_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->unit_R3 = sml_unit_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->scaler_R3 = sml_i8_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->value_R3 = sml_i64_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->signature_mA_R2_R3 = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; return tupel; error: sml_tupel_entry_free(tupel); return 0; } void sml_tupel_entry_write(sml_tupel_entry *tupel, sml_buffer *buf) { if (tupel == 0) { sml_buf_optional_write(buf); return; } sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 23); sml_octet_string_write(tupel->server_id, buf); sml_time_write(tupel->sec_index, buf); sml_u64_write(tupel->status, buf); sml_unit_write(tupel->unit_pA, buf); sml_i8_write(tupel->scaler_pA, buf); sml_i64_write(tupel->value_pA, buf); sml_unit_write(tupel->unit_R1, buf); sml_i8_write(tupel->scaler_R1, buf); sml_i64_write(tupel->value_R1, buf); sml_unit_write(tupel->unit_R4, buf); sml_i8_write(tupel->scaler_R4, buf); sml_i64_write(tupel->value_R4, buf); sml_octet_string_write(tupel->signature_pA_R1_R4, buf); sml_unit_write(tupel->unit_mA, buf); sml_i8_write(tupel->scaler_mA, buf); sml_i64_write(tupel->value_mA, buf); sml_unit_write(tupel->unit_R2, buf); sml_i8_write(tupel->scaler_R2, buf); sml_i64_write(tupel->value_R2, buf); sml_unit_write(tupel->unit_R3, buf); sml_i8_write(tupel->scaler_R3, buf); sml_i64_write(tupel->value_R3, buf); sml_octet_string_write(tupel->signature_mA_R2_R3, buf); } void sml_tupel_entry_free(sml_tupel_entry *tupel) { if (tupel) { sml_octet_string_free(tupel->server_id); sml_time_free(tupel->sec_index); sml_number_free(tupel->status); sml_unit_free(tupel->unit_pA); sml_number_free(tupel->scaler_pA); sml_number_free(tupel->value_pA); sml_unit_free(tupel->unit_R1); sml_number_free(tupel->scaler_R1); sml_number_free(tupel->value_R1); sml_unit_free(tupel->unit_R4); sml_number_free(tupel->scaler_R4); sml_number_free(tupel->value_R4); sml_octet_string_free(tupel->signature_pA_R1_R4); sml_unit_free(tupel->unit_mA); sml_number_free(tupel->scaler_mA); sml_number_free(tupel->value_mA); sml_unit_free(tupel->unit_R2); sml_number_free(tupel->scaler_R2); sml_number_free(tupel->value_R2); sml_unit_free(tupel->unit_R3); sml_number_free(tupel->scaler_R3); sml_number_free(tupel->value_R3); sml_octet_string_free(tupel->signature_mA_R2_R3); free(tupel); } } // sml_period_entry; sml_period_entry *sml_period_entry_init() { sml_period_entry *period = (sml_period_entry *) malloc(sizeof(sml_period_entry)); *period = ( sml_period_entry ) { .obj_name = NULL, .unit = NULL, .scaler = NULL, .value = NULL, .value_signature = NULL }; return period; } static void * sml_period_entry_parse_(sml_buffer *buf) { if (sml_buf_optional_is_skipped(buf)) { return 0; } sml_period_entry *period = sml_period_entry_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 5) { buf->error = 1; goto error; } period->obj_name = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; period->unit = sml_unit_parse(buf); if (sml_buf_has_errors(buf)) goto error; period->scaler = sml_i8_parse(buf); if (sml_buf_has_errors(buf)) goto error; period->value = sml_value_parse(buf); if (sml_buf_has_errors(buf)) goto error; period->value_signature = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; return period; error: sml_period_entry_free(period); return 0; } sml_period_entry * sml_period_entry_parse( sml_buffer * buf ) { return sml_period_entry_parse_( buf ); } void sml_period_entry_write(sml_period_entry *period, sml_buffer *buf) { if (period == 0) { sml_buf_optional_write(buf); return; } sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 5); sml_octet_string_write(period->obj_name, buf); sml_unit_write(period->unit, buf); sml_i8_write(period->scaler, buf); sml_value_write(period->value, buf); sml_octet_string_write(period->value_signature, buf); } static void sml_period_entry_free_( void * p ) { sml_period_entry * period = p; if (period) { sml_octet_string_free(period->obj_name); sml_unit_free(period->unit); sml_number_free(period->scaler); sml_value_free(period->value); sml_octet_string_free(period->value_signature); free(period); } } void sml_period_entry_free( sml_period_entry * period ) { sml_period_entry_free_( period ); } libsml-0.1.1+git20170608/sml/src/sml_set_proc_parameter_request.c0000644000175000017500000000527312734144572024265 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include sml_set_proc_parameter_request *sml_set_proc_parameter_request_init() { sml_set_proc_parameter_request *msg = (sml_set_proc_parameter_request *) malloc(sizeof (sml_set_proc_parameter_request)); *msg = ( sml_set_proc_parameter_request ) { .server_id = NULL, .username = NULL, .password = NULL, .parameter_tree_path = NULL, .parameter_tree = NULL }; return msg; } sml_set_proc_parameter_request *sml_set_proc_parameter_request_parse(sml_buffer *buf) { sml_set_proc_parameter_request *msg = sml_set_proc_parameter_request_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 5) { buf->error = 1; goto error; } msg->server_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->username = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->password = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->parameter_tree_path = sml_tree_path_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->parameter_tree = sml_tree_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: sml_set_proc_parameter_request_free(msg); return 0; } void sml_set_proc_parameter_request_write(sml_set_proc_parameter_request *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 5); sml_octet_string_write(msg->server_id, buf); sml_octet_string_write(msg->username, buf); sml_octet_string_write(msg->password, buf); sml_tree_path_write(msg->parameter_tree_path, buf); sml_tree_write(msg->parameter_tree, buf); } void sml_set_proc_parameter_request_free(sml_set_proc_parameter_request *msg) { if (msg) { sml_octet_string_free(msg->server_id); sml_octet_string_free(msg->username); sml_octet_string_free(msg->password); sml_tree_path_free(msg->parameter_tree_path); sml_tree_free(msg->parameter_tree); free(msg); } } libsml-0.1.1+git20170608/sml/src/sml_get_profile_pack_request.c0000644000175000017500000001100212734144572023667 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include #include #include #include #include sml_get_profile_pack_request *sml_get_profile_pack_request_init(){ sml_get_profile_pack_request *msg = (sml_get_profile_pack_request *) malloc(sizeof(sml_get_profile_pack_request)); *msg = ( sml_get_profile_pack_request ) { .server_id = NULL, .username = NULL, .password = NULL, .with_rawdata = NULL, .begin_time = NULL, .end_time = NULL, .parameter_tree_path = NULL, .object_list = NULL, .das_details = NULL }; return msg; } void sml_get_profile_pack_request_write(sml_get_profile_pack_request *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 9); sml_octet_string_write(msg->server_id, buf); sml_octet_string_write(msg->username, buf); sml_octet_string_write(msg->password, buf); sml_boolean_write(msg->with_rawdata, buf); sml_time_write(msg->begin_time, buf); sml_time_write(msg->end_time, buf); sml_tree_path_write(msg->parameter_tree_path, buf); if (msg->object_list) { int len = 1; sml_obj_req_entry_list *l = msg->object_list; for (l = msg->object_list; l->next; l = l->next) { len++; } sml_buf_set_type_and_length(buf, SML_TYPE_LIST, len); for (l = msg->object_list; l->next; l = l->next) { sml_obj_req_entry_write(l->object_list_entry, buf); } } else { sml_buf_optional_write(buf); } sml_tree_write(msg->das_details, buf); } sml_get_profile_pack_request *sml_get_profile_pack_request_parse(sml_buffer *buf) { sml_get_profile_pack_request *msg = sml_get_profile_pack_request_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 9) { buf->error = 1; goto error; } msg->server_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->username = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->password = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->with_rawdata = sml_boolean_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->begin_time = sml_time_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->end_time = sml_time_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->parameter_tree_path = sml_tree_path_parse(buf); if (sml_buf_has_errors(buf)) goto error; if (!sml_buf_optional_is_skipped(buf)) { if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } int i, len = sml_buf_get_next_length(buf); sml_obj_req_entry_list *last = 0, *n = 0; for (i = len; i > 0; i--) { n = (sml_obj_req_entry_list *) malloc(sizeof(sml_obj_req_entry_list)); *n = ( sml_obj_req_entry_list ) { .object_list_entry = NULL, .next = NULL }; n->object_list_entry = sml_obj_req_entry_parse(buf); if (sml_buf_has_errors(buf)) goto error; if (msg->object_list == 0) { msg->object_list = n; last = msg->object_list; } else { last->next = n; last = n; } } } msg->das_details = sml_tree_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: sml_get_profile_pack_request_free(msg); return 0; } void sml_get_profile_pack_request_free(sml_get_profile_pack_request *msg){ if (msg) { sml_octet_string_free(msg->server_id); sml_octet_string_free(msg->username); sml_octet_string_free(msg->password); sml_boolean_free(msg->with_rawdata); sml_time_free(msg->begin_time); sml_time_free(msg->end_time); sml_tree_path_free(msg->parameter_tree_path); if (msg->object_list) { sml_obj_req_entry_list *n = 0, *d = msg->object_list; do { n = d->next; sml_obj_req_entry_free(d->object_list_entry); free(d); d = n; } while (d); } sml_tree_free(msg->das_details); free(msg); } } libsml-0.1.1+git20170608/sml/src/sml_transport.c0000644000175000017500000000705712734144572020675 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include #include #include #include #include #include #include #include #define MC_SML_BUFFER_LEN 8096 unsigned char esc_seq[] = {0x1b, 0x1b, 0x1b, 0x1b}; unsigned char start_seq[] = {0x1b, 0x1b, 0x1b, 0x1b, 0x01, 0x01, 0x01, 0x01}; unsigned char end_seq[] = {0x1b, 0x1b, 0x1b, 0x1b, 0x1a}; size_t sml_read(int fd, fd_set *set, unsigned char *buffer, size_t len) { ssize_t r = 0; size_t tr = 0; while (tr < len) { select(fd + 1, set, 0, 0, 0); if (FD_ISSET(fd, set)) { r = read(fd, &(buffer[tr]), len - tr); if (r < 0) continue; tr += r; } } return tr; } size_t sml_transport_read(int fd, unsigned char *buffer, size_t max_len) { fd_set readfds; FD_ZERO(&readfds); FD_SET(fd, &readfds); unsigned char buf[max_len]; memset(buf, 0, max_len); unsigned int len = 0; while (len < 8) { sml_read(fd, &readfds, &(buf[len]), 1); if ((buf[len] == 0x1b && len < 4) || (buf[len] == 0x01 && len >= 4)) { len++; } else { len = 0; } } // found start sequence while ((len+8) < max_len) { sml_read(fd, &readfds, &(buf[len]), 4); if (memcmp(&buf[len], esc_seq, 4) == 0) { // found esc sequence len += 4; sml_read(fd, &readfds, &(buf[len]), 4); if (buf[len] == 0x1a) { // found end sequence len += 4; memcpy(buffer, &(buf[0]), len); return len; } else { // dont read other escaped sequences yet fprintf(stderr,"libsml: error: unrecognized sequence\n"); return 0; } } len += 4; } return 0; } void sml_transport_listen(int fd, void (*sml_transport_receiver)(unsigned char *buffer, size_t buffer_len)) { unsigned char buffer[MC_SML_BUFFER_LEN]; size_t bytes; while (1) { bytes = sml_transport_read(fd, buffer, MC_SML_BUFFER_LEN); if (bytes > 0) { sml_transport_receiver(buffer, bytes); } } } int sml_transport_write(int fd, sml_file *file) { sml_buffer *buf = file->buf; buf->cursor = 0; // add start sequence memcpy(sml_buf_get_current_buf(buf), start_seq, 8); buf->cursor += 8; // add file sml_file_write(file); // add padding bytes int padding = (buf->cursor % 4) ? (4 - buf->cursor % 4) : 0; if (padding) { // write zeroed bytes memset(sml_buf_get_current_buf(buf), 0, padding); buf->cursor += padding; } // begin end sequence memcpy(sml_buf_get_current_buf(buf), end_seq, 5); buf->cursor += 5; // add padding info buf->buffer[buf->cursor++] = (unsigned char) padding; // add crc checksum u16 crc = sml_crc16_calculate(buf->buffer, buf->cursor); buf->buffer[buf->cursor++] = (unsigned char) ((crc & 0xFF00) >> 8); buf->buffer[buf->cursor++] = (unsigned char) (crc & 0x00FF); size_t wr = write(fd, buf->buffer, buf->cursor); if (wr == buf->cursor) { return wr; } return 0; } libsml-0.1.1+git20170608/sml/src/sml_get_profile_list_request.c0000644000175000017500000000156412734144572023740 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include // this file is just there for symmetry void sml_get_profile_list_request_noop() {} libsml-0.1.1+git20170608/sml/src/sml_number.c0000644000175000017500000000600112734144572020115 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include #include #include #define SML_BIG_ENDIAN 1 #define SML_LITTLE_ENDIAN 0 int sml_number_endian(); void sml_number_byte_swap(unsigned char *bytes, int bytes_len); void *sml_number_init(u64 number, unsigned char type __attribute__ ((unused)), int size) { const char * bytes = ( const char * ) &number; // Swap bytes of big-endian number so that // memcpy copies the right part if (sml_number_endian() == SML_BIG_ENDIAN) { bytes += sizeof(u64) - size; } char * np = malloc( size ); if ( np == NULL ) { goto error; } memcpy(np, bytes, size); return np; error: return NULL; } void *sml_number_parse(sml_buffer *buf, unsigned char type, int max_size) { if (sml_buf_optional_is_skipped(buf)) { return 0; } int l, i; unsigned char b; short negative_int = 0; if (sml_buf_get_next_type(buf) != type) { buf->error = 1; return 0; } l = sml_buf_get_next_length(buf); if (l < 0 || l > max_size) { buf->error = 1; return 0; } unsigned char *np = malloc(max_size); memset(np, 0, max_size); b = sml_buf_get_current_byte(buf); if (type == SML_TYPE_INTEGER && (b & 128)) { negative_int = 1; } int missing_bytes = max_size - l; memcpy(&(np[missing_bytes]), sml_buf_get_current_buf(buf), l); if (negative_int) { for (i = 0; i < missing_bytes; i++) { np[i] = 0xFF; } } if (!(sml_number_endian() == SML_BIG_ENDIAN)) { sml_number_byte_swap(np, max_size); } sml_buf_update_bytes_read(buf, l); return np; } void sml_number_write(void *np, unsigned char type, int size, sml_buffer *buf) { if (np == 0) { sml_buf_optional_write(buf); return; } sml_buf_set_type_and_length(buf, type, size); memcpy(sml_buf_get_current_buf(buf), np, size); if (!(sml_number_endian() == SML_BIG_ENDIAN)) { sml_number_byte_swap(sml_buf_get_current_buf(buf), size); } sml_buf_update_bytes_read(buf, size); } void sml_number_byte_swap(unsigned char *bytes, int bytes_len) { int i; unsigned char ob[bytes_len]; memcpy(&ob, bytes, bytes_len); for (i = 0; i < bytes_len; i++) { bytes[i] = ob[bytes_len - (i + 1)]; } } int sml_number_endian() { int i = 1; char *p = (char *)&i; if (p[0] == 1) return SML_LITTLE_ENDIAN; else return SML_BIG_ENDIAN; } void sml_number_free(void *np) { if (np) { free(np); } } libsml-0.1.1+git20170608/sml/src/sml_value.c0000644000175000017500000000636312734144572017754 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include #include sml_value *sml_value_parse(sml_buffer *buf) { if (sml_buf_optional_is_skipped(buf)) { return 0; } int max = 1; int type = sml_buf_get_next_type(buf); unsigned char byte = sml_buf_get_current_byte(buf); sml_value *value = sml_value_init(); value->type = type; switch (type) { case SML_TYPE_OCTET_STRING: value->data.bytes = sml_octet_string_parse(buf); break; case SML_TYPE_BOOLEAN: value->data.boolean = sml_boolean_parse(buf); break; case SML_TYPE_UNSIGNED: case SML_TYPE_INTEGER: // get maximal size, if not all bytes are used (example: only 6 bytes for a u64) while (max < ((byte & SML_LENGTH_FIELD) - 1)) { max <<= 1; } value->data.uint8 = sml_number_parse(buf, type, max); value->type |= max; break; default: buf->error = 1; break; } if (sml_buf_has_errors(buf)) { sml_value_free(value); return 0; } return value; } void sml_value_write(sml_value *value, sml_buffer *buf) { if (value == 0) { sml_buf_optional_write(buf); return; } switch (value->type & SML_TYPE_FIELD) { case SML_TYPE_OCTET_STRING: sml_octet_string_write(value->data.bytes, buf); break; case SML_TYPE_BOOLEAN: sml_boolean_write(value->data.boolean, buf); break; case SML_TYPE_UNSIGNED: case SML_TYPE_INTEGER: sml_number_write(value->data.uint8, (value->type & SML_TYPE_FIELD), (value->type & SML_LENGTH_FIELD), buf); break; } } sml_value *sml_value_init() { sml_value *value = (sml_value *) malloc(sizeof(sml_value)); *value = ( sml_value ) { .type = SML_TYPE_OCTET_STRING, .data.bytes = NULL }; return value; } void sml_value_free(sml_value *value) { if (value) { switch (value->type) { case SML_TYPE_OCTET_STRING: sml_octet_string_free(value->data.bytes); break; case SML_TYPE_BOOLEAN: sml_boolean_free(value->data.boolean); break; default: sml_number_free(value->data.int8); break; } free(value); } } double sml_value_to_double(sml_value *value) { switch (value->type) { case 0x51: return *value->data.int8; break; case 0x52: return *value->data.int16; break; case 0x54: return *value->data.int32; break; case 0x58: return *value->data.int64; break; case 0x61: return *value->data.uint8; break; case 0x62: return *value->data.uint16; break; case 0x64: return *value->data.uint32; break; case 0x68: return *value->data.uint64; break; default: fprintf(stderr,"libsml: error: unknown type %d in %s\n", value->type, __FUNCTION__); return 0; } } libsml-0.1.1+git20170608/sml/src/sml_attention_response.c0000644000175000017500000000470112734144572022555 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include #include sml_attention_response *sml_attention_response_init() { sml_attention_response *msg = (sml_attention_response *) malloc(sizeof(sml_attention_response)); *msg = ( sml_attention_response ) { .server_id = NULL, .attention_number = NULL, .attention_message = NULL, .attention_details = NULL }; return msg; } sml_attention_response *sml_attention_response_parse(sml_buffer *buf){ sml_attention_response *msg = sml_attention_response_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 4) { buf->error = 1; goto error; } msg->server_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->attention_number = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->attention_message = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->attention_details = sml_tree_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: sml_attention_response_free(msg); return 0; } void sml_attention_response_write(sml_attention_response *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 4); sml_octet_string_write(msg->server_id, buf); sml_octet_string_write(msg->attention_number, buf); sml_octet_string_write(msg->attention_message, buf); sml_tree_write(msg->attention_details, buf); } void sml_attention_response_free(sml_attention_response *msg){ if (msg) { sml_octet_string_free(msg->server_id); sml_octet_string_free(msg->attention_number); sml_octet_string_free(msg->attention_message); sml_tree_free(msg->attention_details); free(msg); } } libsml-0.1.1+git20170608/sml/src/sml_get_profile_pack_response.c0000644000175000017500000002230512734144572024045 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include #include static void * sml_prof_obj_header_entry_parse_(sml_buffer *buf); static void * sml_value_entry_parse_(sml_buffer *buf); static void sml_value_entry_free_( void * p ); static void sml_value_entry_write_( void * p, sml_buffer *buf); static void sml_prof_obj_header_entry_free_( void * p ) { sml_prof_obj_header_entry * entry = p; if (entry) { sml_octet_string_free(entry->obj_name); sml_unit_free(entry->unit); sml_number_free(entry->scaler); free(entry); } } static void * sml_prof_obj_period_entry_parse_(sml_buffer *buf) { sml_prof_obj_period_entry *entry = sml_prof_obj_period_entry_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 4) { buf->error = 1; goto error; } entry->val_time = sml_time_parse(buf); if (sml_buf_has_errors(buf)) goto error; entry->status = sml_u64_parse(buf); if (sml_buf_has_errors(buf)) goto error; entry->value_list = sml_sequence_parse(buf, sml_value_entry_parse_, sml_value_entry_free_); if (sml_buf_has_errors(buf)) goto error; entry->period_signature = sml_signature_parse(buf); if (sml_buf_has_errors(buf)) goto error; return entry; error: buf->error = 1; sml_prof_obj_period_entry_free(entry); return 0; } static void sml_prof_obj_period_entry_free_( void * p ) { sml_prof_obj_period_entry * entry = p; if (entry) { sml_time_free(entry->val_time); sml_number_free(entry->status); sml_sequence_free(entry->value_list); sml_signature_free(entry->period_signature); free(entry); } } static void sml_prof_obj_header_entry_write_( void * p, sml_buffer *buf) { sml_prof_obj_header_entry * entry = p; sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 3); sml_octet_string_write(entry->obj_name, buf); sml_unit_write(entry->unit, buf); sml_i8_write(entry->scaler, buf); } static void sml_prof_obj_period_entry_write_( void * p, sml_buffer *buf) { sml_prof_obj_period_entry * entry = p; sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 4); sml_time_write(entry->val_time, buf); sml_u64_write(entry->status, buf); sml_sequence_write(entry->value_list, buf, sml_value_entry_write_); sml_signature_write(entry->period_signature, buf); } static void * sml_value_entry_parse_(sml_buffer *buf) { sml_value_entry *entry = sml_value_entry_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 2) { buf->error = 1; goto error; } entry->value = sml_value_parse(buf); if (sml_buf_has_errors(buf)) goto error; entry->value_signature = sml_signature_parse(buf); if (sml_buf_has_errors(buf)) goto error; return entry; error: buf->error = 1; sml_value_entry_free(entry); return 0; } static void sml_value_entry_write_( void * p, sml_buffer *buf) { sml_value_entry * entry = p; sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 2); sml_value_write(entry->value, buf); sml_signature_write(entry->value_signature, buf); } static void sml_value_entry_free_( void * p ) { sml_value_entry * entry = p; if (entry) { sml_value_free(entry->value); sml_signature_free(entry->value_signature); free(entry); } } // sml_get_profile_pack_response; sml_get_profile_pack_response *sml_get_profile_pack_response_init() { sml_get_profile_pack_response *msg = (sml_get_profile_pack_response *) malloc(sizeof(sml_get_profile_pack_response)); *msg = ( sml_get_profile_pack_response ) { .server_id = NULL, .act_time = NULL, .reg_period = NULL, .parameter_tree_path = NULL, .header_list = NULL, .period_list = NULL, .rawdata = NULL, .profile_signature = NULL }; return msg; } sml_get_profile_pack_response *sml_get_profile_pack_response_parse(sml_buffer *buf){ sml_get_profile_pack_response *msg = sml_get_profile_pack_response_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 8) { buf->error = 1; goto error; } msg->server_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->act_time = sml_time_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->reg_period = sml_u32_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->parameter_tree_path = sml_tree_path_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->header_list = sml_sequence_parse(buf, sml_prof_obj_header_entry_parse_, sml_prof_obj_header_entry_free_); if (sml_buf_has_errors(buf)) goto error; msg->period_list = sml_sequence_parse(buf, sml_prof_obj_period_entry_parse_, sml_prof_obj_period_entry_free_); if (sml_buf_has_errors(buf)) goto error; msg->rawdata = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->profile_signature = sml_signature_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: buf->error = 1; sml_get_profile_pack_response_free(msg); return 0; } void sml_get_profile_pack_response_write(sml_get_profile_pack_response *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 8); sml_octet_string_write(msg->server_id, buf); sml_time_write(msg->act_time, buf); sml_u32_write(msg->reg_period, buf); sml_tree_path_write(msg->parameter_tree_path, buf); sml_sequence_write(msg->header_list, buf, sml_prof_obj_header_entry_write_); sml_sequence_write(msg->period_list, buf, sml_prof_obj_period_entry_write_); sml_octet_string_write(msg->rawdata, buf); sml_signature_write(msg->profile_signature, buf); } void sml_get_profile_pack_response_free(sml_get_profile_pack_response *msg){ if (msg) { sml_octet_string_free(msg->server_id); sml_time_free(msg->act_time); sml_number_free(msg->reg_period); sml_tree_path_free(msg->parameter_tree_path); sml_sequence_free(msg->header_list); sml_sequence_free(msg->period_list); sml_octet_string_free(msg->rawdata); sml_signature_free(msg->profile_signature); free(msg); } } // sml_prof_obj_header_entry; sml_prof_obj_header_entry *sml_prof_obj_header_entry_init() { sml_prof_obj_header_entry *entry = (sml_prof_obj_header_entry *) malloc(sizeof(sml_prof_obj_header_entry)); *entry = ( sml_prof_obj_header_entry ) { .obj_name = NULL, .unit = NULL, .scaler = NULL }; return entry; } static void * sml_prof_obj_header_entry_parse_(sml_buffer *buf) { sml_prof_obj_header_entry *entry = sml_prof_obj_header_entry_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 3) { buf->error = 1; goto error; } entry->obj_name = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; entry->unit = sml_unit_parse(buf); if (sml_buf_has_errors(buf)) goto error; entry->scaler = sml_i8_parse(buf); if (sml_buf_has_errors(buf)) goto error; return entry; error: buf->error = 1; sml_prof_obj_header_entry_free(entry); return 0; } sml_prof_obj_header_entry * sml_prof_obj_header_entry_parse( sml_buffer * buf ) { return sml_prof_obj_header_entry_parse_( buf ); } void sml_prof_obj_header_entry_write( sml_prof_obj_header_entry * entry, sml_buffer * buf ) { sml_prof_obj_header_entry_write_( entry, buf ); } void sml_prof_obj_header_entry_free( sml_prof_obj_header_entry * entry ) { sml_prof_obj_header_entry_free_( entry ); } // sml_prof_obj_period_entry; sml_prof_obj_period_entry *sml_prof_obj_period_entry_init() { sml_prof_obj_period_entry *entry = (sml_prof_obj_period_entry *) malloc(sizeof(sml_prof_obj_period_entry)); *entry = ( sml_prof_obj_period_entry ) { .val_time = NULL, .status = NULL, .value_list = NULL, .period_signature = NULL }; return entry; } sml_prof_obj_period_entry * sml_prof_obj_period_entry_parse( sml_buffer * buf ) { return sml_prof_obj_period_entry_parse_( buf ); } void sml_prof_obj_period_entry_write( sml_prof_obj_period_entry * entry, sml_buffer * buf ) { sml_prof_obj_period_entry_write_( entry, buf ); } void sml_prof_obj_period_entry_free( sml_prof_obj_period_entry * entry ) { sml_prof_obj_period_entry_free_( entry ); } // sml_value_entry; sml_value_entry *sml_value_entry_init() { sml_value_entry *entry = (sml_value_entry *) malloc(sizeof(sml_value_entry)); *entry = ( sml_value_entry ) { .value = NULL, .value_signature = NULL }; return entry; } sml_value_entry * sml_value_entry_parse( sml_buffer * buf ) { return sml_value_entry_parse_( buf ); } void sml_value_entry_write( sml_value_entry * entry, sml_buffer * buf ) { sml_value_entry_write_( entry, buf ); } void sml_value_entry_free( sml_value_entry * entry ) { sml_value_entry_free_( entry ); } libsml-0.1.1+git20170608/sml/src/sml_file.c0000644000175000017500000000575412734144572017562 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include #include #include #include #include #include #include // EDL meter must provide at least 250 bytes as a receive buffer #define SML_FILE_BUFFER_LENGTH 512 sml_file *sml_file_parse(unsigned char *buffer, size_t buffer_len) { sml_file *file = (sml_file*) malloc(sizeof(sml_file)); *file = ( sml_file ) { .messages = NULL, .messages_len = 0, .buf = NULL }; sml_buffer *buf = sml_buffer_init(buffer_len); memcpy(buf->buffer, buffer, buffer_len); file->buf = buf; sml_message *msg; // parsing all messages for (; buf->cursor < buf->buffer_len;) { if(sml_buf_get_current_byte(buf) == SML_MESSAGE_END) { // reading trailing zeroed bytes sml_buf_update_bytes_read(buf, 1); continue; } msg = sml_message_parse(buf); if (sml_buf_has_errors(buf)) { fprintf(stderr,"libsml: warning: could not read the whole file\n"); break; } sml_file_add_message(file, msg); } return file; } sml_file *sml_file_init() { sml_file *file = (sml_file*) malloc(sizeof(sml_file)); *file = ( sml_file ) { .messages = NULL, .messages_len = 0, .buf = NULL }; sml_buffer *buf = sml_buffer_init(SML_FILE_BUFFER_LENGTH); file->buf = buf; return file; } void sml_file_add_message(sml_file *file, sml_message *message) { file->messages_len++; file->messages = (sml_message **) realloc(file->messages, sizeof(sml_message *) * file->messages_len); file->messages[file->messages_len - 1] = message; } void sml_file_write(sml_file *file) { int i; if (file->messages && file->messages_len > 0) { for (i = 0; i < file->messages_len; i++) { sml_message_write(file->messages[i], file->buf); } } } void sml_file_free(sml_file *file) { if (file) { if (file->messages) { int i; for (i = 0; i < file->messages_len; i++) { sml_message_free(file->messages[i]); } free(file->messages); } if (file->buf) { sml_buffer_free(file->buf); } free(file); } } void sml_file_print(sml_file *file) { int i; printf("SML file (%d SML messages, %zu bytes)\n", file->messages_len, file->buf->cursor); for (i = 0; i < file->messages_len; i++) { printf("SML message %4.X\n", *(file->messages[i]->message_body->tag)); } } libsml-0.1.1+git20170608/sml/src/sml_crc16.c0000644000175000017500000000622612734144572017554 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include #define PPPINITFCS16 0xffff // initial FCS value // table taken from DIN EN 62056-46 static u16 fcstab [256] = { 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a, 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb, 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 }; u16 sml_crc16_calculate(unsigned char *cp, int len) { u16 fcs = PPPINITFCS16; while (len--) { fcs = (fcs >> 8) ^ fcstab[(fcs ^ *cp++) & 0xff]; } fcs ^= 0xffff; fcs = ((fcs & 0xff) << 8) | ((fcs & 0xff00) >> 8); return fcs; } libsml-0.1.1+git20170608/sml/src/sml_get_proc_parameter_request.c0000644000175000017500000000535512734144572024252 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include #include #include sml_get_proc_parameter_request *sml_get_proc_parameter_request_init() { sml_get_proc_parameter_request *msg = (sml_get_proc_parameter_request *) malloc(sizeof (sml_get_proc_parameter_request)); *msg = ( sml_get_proc_parameter_request ) { .server_id = NULL, .username = NULL, .password = NULL, .parameter_tree_path = NULL, .attribute = NULL }; return msg; } sml_get_proc_parameter_request *sml_get_proc_parameter_request_parse(sml_buffer *buf) { sml_get_proc_parameter_request *msg = sml_get_proc_parameter_request_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 5) { buf->error = 1; goto error; } msg->server_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->username = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->password = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->parameter_tree_path = sml_tree_path_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->attribute = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: sml_get_proc_parameter_request_free(msg); return 0; } void sml_get_proc_parameter_request_write(sml_get_proc_parameter_request *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 5); sml_octet_string_write(msg->server_id, buf); sml_octet_string_write(msg->username, buf); sml_octet_string_write(msg->password, buf); sml_tree_path_write(msg->parameter_tree_path, buf); sml_octet_string_write(msg->attribute, buf); } void sml_get_proc_parameter_request_free(sml_get_proc_parameter_request *msg) { if (msg) { sml_octet_string_free(msg->server_id); sml_octet_string_free(msg->username); sml_octet_string_free(msg->password); sml_tree_path_free(msg->parameter_tree_path); sml_octet_string_free(msg->attribute); free(msg); } } libsml-0.1.1+git20170608/sml/src/sml_get_proc_parameter_response.c0000644000175000017500000000452712734144572024420 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include #include sml_get_proc_parameter_response *sml_get_proc_parameter_response_init() { sml_get_proc_parameter_response *msg = (sml_get_proc_parameter_response *)malloc(sizeof(sml_get_proc_parameter_response)); *msg = ( sml_get_proc_parameter_response ) { .server_id = NULL, .parameter_tree_path = NULL, .parameter_tree = NULL }; return msg; } sml_get_proc_parameter_response *sml_get_proc_parameter_response_parse(sml_buffer *buf) { sml_get_proc_parameter_response *msg = sml_get_proc_parameter_response_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 3) { buf->error = 1; goto error; } msg->server_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->parameter_tree_path = sml_tree_path_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->parameter_tree = sml_tree_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: sml_get_proc_parameter_response_free(msg); return 0; } void sml_get_proc_parameter_response_write(sml_get_proc_parameter_response *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 3); sml_octet_string_write(msg->server_id, buf); sml_tree_path_write(msg->parameter_tree_path, buf); sml_tree_write(msg->parameter_tree, buf); } void sml_get_proc_parameter_response_free(sml_get_proc_parameter_response *msg) { if (msg) { sml_octet_string_free(msg->server_id); sml_tree_path_free(msg->parameter_tree_path); sml_tree_free(msg->parameter_tree); free(msg); } } libsml-0.1.1+git20170608/sml/src/sml_status.c0000644000175000017500000000400712734144572020154 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include sml_status *sml_status_init() { sml_status *status = (sml_status *) malloc(sizeof(sml_status)); *status = ( sml_status ) { .type = SML_TYPE_UNSIGNED, .data.status8 = NULL }; return status; } sml_status *sml_status_parse(sml_buffer *buf) { if (sml_buf_optional_is_skipped(buf)) { return 0; } int max = 1; int type = sml_buf_get_next_type(buf); unsigned char byte = sml_buf_get_current_byte(buf); sml_status *status = sml_status_init(); status->type = type; switch (type) { case SML_TYPE_UNSIGNED: // get maximal size, if not all bytes are used (example: only 6 bytes for a u64) while (max < ((byte & SML_LENGTH_FIELD) - 1)) { max <<= 1; } status->data.status8 = sml_number_parse(buf, type, max); status->type |= max; break; default: buf->error = 1; break; } if (sml_buf_has_errors(buf)) { sml_status_free(status); return 0; } return status; } void sml_status_write(sml_status *status, sml_buffer *buf) { if (status == 0) { sml_buf_optional_write(buf); return; } sml_number_write(status->data.status8, (status->type & SML_TYPE_FIELD), (status->type & SML_LENGTH_FIELD), buf); } void sml_status_free(sml_status *status) { if (status) { sml_number_free(status->data.status8); free(status); } } libsml-0.1.1+git20170608/sml/src/sml_open_request.c0000644000175000017500000000560612734144572021350 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include #include #include sml_open_request *sml_open_request_init(){ sml_open_request *open_request = (sml_open_request *) malloc(sizeof(sml_open_request)); *open_request = ( sml_open_request ) { .codepage = NULL, .client_id = NULL, .req_file_id = NULL, .server_id = NULL, .username = NULL, .password = NULL, .sml_version = NULL }; return open_request; } sml_open_request *sml_open_request_parse(sml_buffer *buf) { sml_open_request *msg = sml_open_request_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 7) { buf->error = 1; goto error; } msg->codepage = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->client_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->req_file_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->server_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->username = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->password = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->sml_version = sml_u8_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: sml_open_request_free(msg); return 0; } void sml_open_request_write(sml_open_request *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 7); sml_octet_string_write(msg->codepage, buf); sml_octet_string_write(msg->client_id, buf); sml_octet_string_write(msg->req_file_id, buf); sml_octet_string_write(msg->server_id, buf); sml_octet_string_write(msg->username,buf); sml_octet_string_write(msg->password,buf); sml_u8_write(msg->sml_version, buf); } void sml_open_request_free(sml_open_request *msg) { if (msg) { sml_octet_string_free(msg->codepage); sml_octet_string_free(msg->client_id); sml_octet_string_free(msg->req_file_id); sml_octet_string_free(msg->server_id); sml_octet_string_free(msg->username); sml_octet_string_free(msg->password); sml_number_free(msg->sml_version); free(msg); } } libsml-0.1.1+git20170608/sml/src/sml_boolean.c0000644000175000017500000000346212734144572020254 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include #include sml_boolean *sml_boolean_init(u8 b) { sml_boolean *boolean = malloc(sizeof(u8)); *boolean = b; return boolean; } sml_boolean *sml_boolean_parse(sml_buffer *buf) { if (sml_buf_optional_is_skipped(buf)) { return 0; } if (sml_buf_get_next_type(buf) != SML_TYPE_BOOLEAN) { buf->error = 1; return 0; } int l = sml_buf_get_next_length(buf); if (l != 1) { buf->error = 1; return 0; } if (sml_buf_get_current_byte(buf)) { sml_buf_update_bytes_read(buf, 1); return sml_boolean_init(SML_BOOLEAN_TRUE); } else { sml_buf_update_bytes_read(buf, 1); return sml_boolean_init(SML_BOOLEAN_FALSE); } } void sml_boolean_write(sml_boolean *boolean, sml_buffer *buf) { if (boolean == 0) { sml_buf_optional_write(buf); return; } sml_buf_set_type_and_length(buf, SML_TYPE_BOOLEAN, 1); if (*boolean == SML_BOOLEAN_FALSE) { buf->buffer[buf->cursor] = SML_BOOLEAN_FALSE; } else { buf->buffer[buf->cursor] = SML_BOOLEAN_TRUE; } buf->cursor++; } void sml_boolean_free(sml_boolean *b) { if (b) { free(b); } } libsml-0.1.1+git20170608/sml/src/sml_close_response.c0000644000175000017500000000337512734144572021663 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include #include sml_close_response *sml_close_response_init() { sml_close_response *msg = (sml_close_response *) malloc(sizeof(sml_close_response)); *msg = ( sml_close_response ) { .global_signature = NULL }; return msg; } sml_close_response *sml_close_response_parse(sml_buffer *buf) { sml_close_response *msg = sml_close_response_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 1) { buf->error = 1; goto error; } msg->global_signature = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: sml_close_response_free(msg); return 0; } void sml_close_response_write(sml_close_response *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 1); sml_octet_string_write(msg->global_signature,buf); } void sml_close_response_free(sml_close_response *msg) { if (msg) { sml_octet_string_free(msg->global_signature); free(msg); } } libsml-0.1.1+git20170608/sml/src/sml_get_list_response.c0000644000175000017500000000564112734144572022366 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include sml_get_list_response *sml_get_list_response_init() { sml_get_list_response *msg = (sml_get_list_response *) malloc(sizeof(sml_get_list_response)); *msg = ( sml_get_list_response ) { .client_id = NULL, .server_id = NULL, .list_name = NULL, .act_sensor_time = NULL, .val_list = NULL, .list_signature = NULL, .act_gateway_time = NULL }; return msg; } sml_get_list_response *sml_get_list_response_parse(sml_buffer *buf) { sml_get_list_response *msg = sml_get_list_response_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 7) { buf->error = 1; goto error; } msg->client_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->server_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->list_name = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->act_sensor_time = sml_time_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->val_list = sml_list_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->list_signature = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->act_gateway_time = sml_time_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: sml_get_list_response_free(msg); return 0; } void sml_get_list_response_write(sml_get_list_response *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 7); sml_octet_string_write(msg->client_id, buf); sml_octet_string_write(msg->server_id, buf); sml_octet_string_write(msg->list_name, buf); sml_time_write(msg->act_sensor_time, buf); sml_list_write(msg->val_list, buf); sml_octet_string_write(msg->list_signature, buf); sml_time_write(msg->act_gateway_time, buf); } void sml_get_list_response_free(sml_get_list_response *msg) { if (msg) { sml_octet_string_free(msg->client_id); sml_octet_string_free(msg->server_id); sml_octet_string_free(msg->list_name); sml_time_free(msg->act_sensor_time); sml_list_free(msg->val_list); sml_octet_string_free(msg->list_signature); sml_time_free(msg->act_gateway_time); free(msg); } } libsml-0.1.1+git20170608/sml/src/sml_shared.c0000644000175000017500000000752012734144572020102 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include #include #include int sml_buf_get_next_length(sml_buffer *buf) { int length = 0; unsigned char byte = sml_buf_get_current_byte(buf); int list = ((byte & SML_TYPE_FIELD) == SML_TYPE_LIST) ? 0 : -1; for (;buf->cursor < buf->buffer_len;) { byte = sml_buf_get_current_byte(buf); length <<= 4; length |= (byte & SML_LENGTH_FIELD); if ((byte & SML_ANOTHER_TL) != SML_ANOTHER_TL) { break; } sml_buf_update_bytes_read(buf, 1); if(list) { list += -1; } } sml_buf_update_bytes_read(buf, 1); return length + list; } void sml_buf_set_type_and_length(sml_buffer *buf, unsigned int type, unsigned int l) { // set the type buf->buffer[buf->cursor] = type; if (type != SML_TYPE_LIST) { l++; } if (l > SML_LENGTH_FIELD) { // how much shifts are necessary int mask_pos = (sizeof(unsigned int) * 2) - 1; // the 4 most significant bits of l (1111 0000 0000 ...) unsigned int mask = 0xF0 << (8 * (sizeof(unsigned int) - 1)); // select the next 4 most significant bits with a bit set until there // is something while (!(mask & l)) { mask >>= 4; mask_pos--; } l += mask_pos; // for every TL-field if ((0x0F << (4 * (mask_pos + 1))) & l) { // for the rare case that the addition of the number of TL-fields // result in another TL-field. mask_pos++; l++; } // copy 4 bits of the number to the buffer while (mask > SML_LENGTH_FIELD) { buf->buffer[buf->cursor] |= SML_ANOTHER_TL; buf->buffer[buf->cursor] |= ((mask & l) >> (4 * mask_pos)); mask >>= 4; mask_pos--; buf->cursor++; } } buf->buffer[buf->cursor] |= (l & SML_LENGTH_FIELD); buf->cursor++; } int sml_buf_has_errors(sml_buffer *buf) { return buf->error != 0; } int sml_buf_get_next_type(sml_buffer *buf) { return (buf->buffer[buf->cursor] & SML_TYPE_FIELD); } unsigned char sml_buf_get_current_byte(sml_buffer *buf) { return buf->buffer[buf->cursor]; } unsigned char *sml_buf_get_current_buf(sml_buffer *buf) { return &(buf->buffer[buf->cursor]); } void sml_buf_update_bytes_read(sml_buffer *buf, int bytes) { buf->cursor += bytes; } sml_buffer *sml_buffer_init(size_t length) { sml_buffer *buf = (sml_buffer *) malloc(sizeof(sml_buffer)); *buf = ( sml_buffer ) { .buffer = NULL, .buffer_len = 0, .cursor = 0, .error = 0, .error_msg = NULL }; buf->buffer = (unsigned char *) malloc(length); buf->buffer_len = length; memset(buf->buffer, 0, buf->buffer_len); return buf; } void sml_buf_optional_write(sml_buffer *buf) { buf->buffer[buf->cursor] = SML_OPTIONAL_SKIPPED; buf->cursor++; } void sml_buffer_free(sml_buffer *buf) { if (buf) { if (buf->buffer) free(buf->buffer); if (buf->error_msg) free(buf->error_msg); free(buf); } } int sml_buf_optional_is_skipped(sml_buffer *buf) { if (sml_buf_get_current_byte(buf) == SML_OPTIONAL_SKIPPED) { sml_buf_update_bytes_read(buf, 1); return 1; } return 0; } void hexdump(unsigned char *buffer, size_t buffer_len) { for ( size_t i = 0; i < buffer_len; i++) { printf("%02X ", (unsigned char) buffer[i]); if ((i + 1) % 8 == 0) { printf("\n"); } } puts( "" ); } libsml-0.1.1+git20170608/sml/src/sml_message.c0000644000175000017500000002361112734144572020257 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include #include #include #include #include #include #include #include #include #include // sml_message; sml_message *sml_message_parse(sml_buffer *buf) { sml_message *msg = (sml_message *) malloc(sizeof(sml_message)); *msg = ( sml_message ) { .transaction_id = NULL, .group_id = NULL, .abort_on_error = NULL, .message_body = NULL, .crc = NULL }; if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 6) { buf->error = 1; goto error; } msg->transaction_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->group_id = sml_u8_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->abort_on_error = sml_u8_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->message_body = sml_message_body_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->crc = sml_u16_parse(buf); if (sml_buf_has_errors(buf)) goto error; if (sml_buf_get_current_byte(buf) == SML_MESSAGE_END) { sml_buf_update_bytes_read(buf, 1); } return msg; error: sml_message_free(msg); return 0; } sml_message *sml_message_init() { sml_message *msg = (sml_message *) malloc(sizeof(sml_message)); *msg = ( sml_message ) { .transaction_id = NULL, .group_id = NULL, .abort_on_error = NULL, .message_body = NULL, .crc = NULL }; msg->transaction_id = sml_octet_string_generate_uuid(); return msg; } void sml_message_free(sml_message *msg) { if (msg) { sml_octet_string_free(msg->transaction_id); sml_number_free(msg->group_id); sml_number_free(msg->abort_on_error); sml_message_body_free(msg->message_body); sml_number_free(msg->crc); free(msg); } } void sml_message_write(sml_message *msg, sml_buffer *buf) { int msg_start = buf->cursor; sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 6); sml_octet_string_write(msg->transaction_id, buf); sml_u8_write(msg->group_id, buf); sml_u8_write(msg->abort_on_error, buf); sml_message_body_write(msg->message_body, buf); msg->crc = sml_u16_init(sml_crc16_calculate(&(buf->buffer[msg_start]), buf->cursor - msg_start)); sml_u16_write(msg->crc, buf); // end of message buf->buffer[buf->cursor] = 0x0; buf->cursor++; } // sml_message_body; sml_message_body *sml_message_body_parse(sml_buffer *buf) { sml_message_body *msg_body = (sml_message_body *) malloc(sizeof(sml_message_body)); *msg_body = ( sml_message_body ) { .tag = NULL, .data = NULL }; if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 2) { buf->error = 1; goto error; } msg_body->tag = sml_u32_parse(buf); if (sml_buf_has_errors(buf)) goto error; switch (*(msg_body->tag)) { case SML_MESSAGE_OPEN_REQUEST: msg_body->data = sml_open_request_parse(buf); break; case SML_MESSAGE_OPEN_RESPONSE: msg_body->data = sml_open_response_parse(buf); break; case SML_MESSAGE_CLOSE_REQUEST: msg_body->data = sml_close_request_parse(buf); break; case SML_MESSAGE_CLOSE_RESPONSE: msg_body->data = sml_close_response_parse(buf); break; case SML_MESSAGE_GET_PROFILE_PACK_REQUEST: msg_body->data = sml_get_profile_pack_request_parse(buf); break; case SML_MESSAGE_GET_PROFILE_PACK_RESPONSE: msg_body->data = sml_get_profile_pack_response_parse(buf); break; case SML_MESSAGE_GET_PROFILE_LIST_REQUEST: msg_body->data = sml_get_profile_list_request_parse(buf); break; case SML_MESSAGE_GET_PROFILE_LIST_RESPONSE: msg_body->data = sml_get_profile_list_response_parse(buf); break; case SML_MESSAGE_GET_PROC_PARAMETER_REQUEST: msg_body->data = sml_get_proc_parameter_request_parse(buf); break; case SML_MESSAGE_GET_PROC_PARAMETER_RESPONSE: msg_body->data = sml_get_proc_parameter_response_parse(buf); break; case SML_MESSAGE_SET_PROC_PARAMETER_REQUEST: msg_body->data = sml_set_proc_parameter_request_parse(buf); break; case SML_MESSAGE_GET_LIST_REQUEST: msg_body->data = sml_get_list_request_parse(buf); break; case SML_MESSAGE_GET_LIST_RESPONSE: msg_body->data = sml_get_list_response_parse(buf); break; case SML_MESSAGE_ATTENTION_RESPONSE: msg_body->data = sml_attention_response_parse(buf); break; default: fprintf(stderr,"libsml: error: message type %04X not yet implemented\n", *(msg_body->tag)); break; } return msg_body; error: free(msg_body); return 0; } sml_message_body *sml_message_body_init(u32 tag, void *data) { sml_message_body *message_body = (sml_message_body *) malloc(sizeof(sml_message_body)); *message_body = ( sml_message_body ) { .tag = sml_u32_init( tag ), .data = data }; return message_body; } void sml_message_body_write(sml_message_body *message_body, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 2); sml_u32_write(message_body->tag, buf); switch (*(message_body->tag)) { case SML_MESSAGE_OPEN_REQUEST: sml_open_request_write((sml_open_request *) message_body->data, buf); break; case SML_MESSAGE_OPEN_RESPONSE: sml_open_response_write((sml_open_response *) message_body->data, buf); break; case SML_MESSAGE_CLOSE_REQUEST: sml_close_request_write((sml_close_request *) message_body->data, buf); break; case SML_MESSAGE_CLOSE_RESPONSE: sml_close_response_write((sml_close_response *) message_body->data, buf); break; case SML_MESSAGE_GET_PROFILE_PACK_REQUEST: sml_get_profile_pack_request_write((sml_get_profile_pack_request *) message_body->data, buf); break; case SML_MESSAGE_GET_PROFILE_PACK_RESPONSE: sml_get_profile_pack_response_write((sml_get_profile_pack_response *) message_body->data, buf); break; case SML_MESSAGE_GET_PROFILE_LIST_REQUEST: sml_get_profile_list_request_write((sml_get_profile_list_request *) message_body->data, buf); break; case SML_MESSAGE_GET_PROFILE_LIST_RESPONSE: sml_get_profile_list_response_write((sml_get_profile_list_response *) message_body->data, buf); break; case SML_MESSAGE_GET_PROC_PARAMETER_REQUEST: sml_get_proc_parameter_request_write((sml_get_proc_parameter_request *) message_body->data, buf); break; case SML_MESSAGE_GET_PROC_PARAMETER_RESPONSE: sml_get_proc_parameter_response_write((sml_get_proc_parameter_response *) message_body->data, buf); break; case SML_MESSAGE_SET_PROC_PARAMETER_REQUEST: sml_set_proc_parameter_request_write((sml_set_proc_parameter_request *) message_body->data, buf); break; case SML_MESSAGE_GET_LIST_REQUEST: sml_get_list_request_write((sml_get_list_request *)message_body->data, buf); break; case SML_MESSAGE_GET_LIST_RESPONSE: sml_get_list_response_write((sml_get_list_response *) message_body->data, buf); break; case SML_MESSAGE_ATTENTION_RESPONSE: sml_attention_response_write((sml_attention_response *) message_body->data, buf); break; default: fprintf(stderr,"libsml: error: message type %04X not yet implemented\n", *(message_body->tag)); break; } } void sml_message_body_free(sml_message_body *message_body) { if (message_body) { switch (*(message_body->tag)) { case SML_MESSAGE_OPEN_REQUEST: sml_open_request_free((sml_open_request *) message_body->data); break; case SML_MESSAGE_OPEN_RESPONSE: sml_open_response_free((sml_open_response *) message_body->data); break; case SML_MESSAGE_CLOSE_REQUEST: sml_close_request_free((sml_close_request *) message_body->data); break; case SML_MESSAGE_CLOSE_RESPONSE: sml_close_response_free((sml_close_response *) message_body->data); break; case SML_MESSAGE_GET_PROFILE_PACK_REQUEST: sml_get_profile_pack_request_free((sml_get_profile_pack_request *) message_body->data); break; case SML_MESSAGE_GET_PROFILE_PACK_RESPONSE: sml_get_profile_pack_response_free((sml_get_profile_pack_response *) message_body->data); break; case SML_MESSAGE_GET_PROFILE_LIST_REQUEST: sml_get_profile_list_request_free((sml_get_profile_list_request *) message_body->data); break; case SML_MESSAGE_GET_PROFILE_LIST_RESPONSE: sml_get_profile_list_response_free((sml_get_profile_list_response *) message_body->data); break; case SML_MESSAGE_GET_PROC_PARAMETER_REQUEST: sml_get_proc_parameter_request_free((sml_get_proc_parameter_request *) message_body->data); break; case SML_MESSAGE_GET_PROC_PARAMETER_RESPONSE: sml_get_proc_parameter_response_free((sml_get_proc_parameter_response *) message_body->data); break; case SML_MESSAGE_SET_PROC_PARAMETER_REQUEST: sml_set_proc_parameter_request_free((sml_set_proc_parameter_request *) message_body->data); break; case SML_MESSAGE_GET_LIST_REQUEST: sml_get_list_request_free((sml_get_list_request *) message_body->data); break; case SML_MESSAGE_GET_LIST_RESPONSE: sml_get_list_response_free((sml_get_list_response *) message_body->data); break; case SML_MESSAGE_ATTENTION_RESPONSE: sml_attention_response_free((sml_attention_response *) message_body->data); break; default: fprintf(stderr,"libsml: NYI: %s for message type %04X\n", __FUNCTION__, *(message_body->tag)); break; } sml_number_free(message_body->tag); free(message_body); } } libsml-0.1.1+git20170608/sml/src/sml_list.c0000644000175000017500000001307312734144572017607 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include #include #include #include #include #include #include // sml_sequence; sml_sequence *sml_sequence_init(void (*elem_free) (void *elem)) { sml_sequence *seq = (sml_sequence *) malloc(sizeof(sml_sequence)); *seq = ( sml_sequence ) { .elems = NULL, .elems_len = 0, .elem_free = elem_free }; return seq; } sml_sequence *sml_sequence_parse(sml_buffer *buf, void *(*elem_parse) (sml_buffer *buf), void (*elem_free) (void *elem)) { if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { goto error; } sml_sequence *seq = sml_sequence_init(elem_free); int i, len = sml_buf_get_next_length(buf); void *p; for (i = 0; i < len; i++) { p = elem_parse(buf); if (sml_buf_has_errors(buf)) { goto haserrors; } sml_sequence_add(seq, p); } return seq; haserrors: sml_sequence_free(seq); error: buf->error = 1; return 0; } void sml_sequence_write(sml_sequence *seq, sml_buffer *buf, void (*elem_write) (void *elem, sml_buffer *buf)) { if (seq == 0) { sml_buf_optional_write(buf); return; } sml_buf_set_type_and_length(buf, SML_TYPE_LIST, seq->elems_len); int i; for (i = 0; i < seq->elems_len; i++) { elem_write((seq->elems)[i], buf); } } void sml_sequence_free(sml_sequence *seq) { if (seq) { int i; for (i = 0; i < seq->elems_len; i++) { seq->elem_free((seq->elems)[i]); } if (seq->elems != 0) { free(seq->elems); } free(seq); } } void sml_sequence_add(sml_sequence *seq, void *new_entry) { seq->elems_len++; seq->elems = (void **) realloc(seq->elems, sizeof(void *) * seq->elems_len); seq->elems[seq->elems_len - 1] = new_entry; } // sml_list; sml_list *sml_list_init(){ sml_list *s = (sml_list *)malloc(sizeof(sml_list)); *s = ( sml_list ) { .obj_name = NULL, .status = NULL, .val_time = NULL, .unit = NULL, .scaler = NULL, .value = NULL, .value_signature = NULL, .next = NULL }; return s; } void sml_list_add(sml_list *list, sml_list *new_entry) { list->next = new_entry; } sml_list *sml_list_entry_parse(sml_buffer *buf) { if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 7) { buf->error = 1; goto error; } sml_list *l = sml_list_init(); l->obj_name = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; l->status = sml_status_parse(buf); if (sml_buf_has_errors(buf)) goto error; l->val_time = sml_time_parse(buf); if (sml_buf_has_errors(buf)) goto error; l->unit = sml_u8_parse(buf); if (sml_buf_has_errors(buf)) goto error; l->scaler = sml_i8_parse(buf); if (sml_buf_has_errors(buf)) goto error; l->value = sml_value_parse(buf); if (sml_buf_has_errors(buf)) goto error; l->value_signature = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; return l; // This function doesn't free the allocated memory in error cases, // this is done in sml_list_parse. error: buf->error = 1; return 0; } sml_list *sml_list_parse(sml_buffer *buf) { if (sml_buf_optional_is_skipped(buf)) { return 0; } if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; return 0; } sml_list *first = 0; sml_list *last = 0; int elems; elems = sml_buf_get_next_length(buf); if (elems > 0) { first = sml_list_entry_parse(buf); if (sml_buf_has_errors(buf)) goto error; last = first; elems--; } while(elems > 0) { last->next = sml_list_entry_parse(buf); if (sml_buf_has_errors(buf)) goto error; last = last->next; elems--; } return first; error: buf->error = 1; sml_list_free(first); return 0; } void sml_list_entry_write(sml_list *list, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 7); sml_octet_string_write(list->obj_name, buf); sml_status_write(list->status, buf); sml_time_write(list->val_time, buf); sml_u8_write(list->unit, buf); sml_i8_write(list->scaler, buf); sml_value_write(list->value, buf); sml_octet_string_write(list->value_signature, buf); } void sml_list_write(sml_list *list, sml_buffer *buf){ if (list == 0) { sml_buf_optional_write(buf); return; } sml_list *i = list; int len = 0; while(i) { i = i->next; len++; } sml_buf_set_type_and_length(buf, SML_TYPE_LIST, len); i = list; while(i) { sml_list_entry_write(i, buf); i = i->next; } } void sml_list_entry_free(sml_list *list) { if (list) { sml_octet_string_free(list->obj_name); sml_status_free(list->status); sml_time_free(list->val_time); sml_number_free(list->unit); sml_number_free(list->scaler); sml_value_free(list->value); sml_octet_string_free(list->value_signature); free(list); } } void sml_list_free(sml_list *list) { if (list) { sml_list *f = list; sml_list *n = list->next; while(f) { sml_list_entry_free(f); f = n; if (f) { n = f->next; } } } } libsml-0.1.1+git20170608/sml/src/sml_close_request.c0000644000175000017500000000341312734144572021506 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include #include sml_close_request *sml_close_request_init() { sml_close_request *close_request = (sml_close_request *) malloc(sizeof(sml_close_request)); *close_request = ( sml_close_request ) { .global_signature = NULL }; return close_request; } sml_close_request * sml_close_request_parse(sml_buffer *buf) { sml_close_request *msg = sml_close_request_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 1) { buf->error = 1; goto error; } msg->global_signature = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: sml_close_request_free(msg); return 0; } void sml_close_request_write(sml_close_request *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 1); sml_octet_string_write(msg->global_signature,buf); } void sml_close_request_free(sml_close_request *msg) { if (msg) { sml_octet_string_free(msg->global_signature); free(msg); } } libsml-0.1.1+git20170608/sml/src/sml_get_list_request.c0000644000175000017500000000530212734144572022212 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include #include sml_get_list_request* sml_get_list_request_init() { sml_get_list_request *msg = (sml_get_list_request *) malloc(sizeof(sml_get_list_request)); *msg = ( sml_get_list_request ) { .client_id = NULL, .server_id = NULL, .username = NULL, .password = NULL, .list_name = NULL }; return msg; } void sml_get_list_request_write(sml_get_list_request *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 5); sml_octet_string_write(msg->client_id, buf); sml_octet_string_write(msg->server_id, buf); sml_octet_string_write(msg->username, buf); sml_octet_string_write(msg->password, buf); sml_octet_string_write(msg->list_name,buf); } sml_get_list_request *sml_get_list_request_parse(sml_buffer *buf) { sml_get_list_request *msg = (sml_get_list_request *) malloc(sizeof(sml_get_list_request)); *msg = ( sml_get_list_request ) { .client_id = NULL, .server_id = NULL, .username = NULL, .password = NULL, .list_name = NULL }; if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 5) { buf->error = 1; goto error; } msg->client_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->server_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->username = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->password = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->list_name = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: sml_get_list_request_free(msg); return 0; } void sml_get_list_request_free(sml_get_list_request *msg) { if (msg) { sml_octet_string_free(msg->client_id); sml_octet_string_free(msg->server_id); sml_octet_string_free(msg->list_name); sml_octet_string_free(msg->username); sml_octet_string_free(msg->password); free(msg); } } libsml-0.1.1+git20170608/sml/src/sml_open_response.c0000644000175000017500000000521712734144572021514 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include #include sml_open_response *sml_open_response_init() { sml_open_response *msg = (sml_open_response *) malloc(sizeof(sml_open_response)); *msg = ( sml_open_response ) { .codepage = NULL, .client_id = NULL, .req_file_id = NULL, .server_id = NULL, .ref_time = NULL, .sml_version = NULL }; return msg; } sml_open_response *sml_open_response_parse(sml_buffer *buf) { sml_open_response *msg = sml_open_response_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 6) { buf->error = 1; goto error; } msg->codepage = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->client_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->req_file_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->server_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->ref_time = sml_time_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->sml_version = sml_u8_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: sml_open_response_free(msg); return 0; } void sml_open_response_write(sml_open_response *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 6); sml_octet_string_write(msg->codepage, buf); sml_octet_string_write(msg->client_id, buf); sml_octet_string_write(msg->req_file_id, buf); sml_octet_string_write(msg->server_id, buf); sml_time_write(msg->ref_time, buf); sml_u8_write(msg->sml_version, buf); } void sml_open_response_free(sml_open_response *msg) { if (msg) { sml_octet_string_free(msg->codepage); sml_octet_string_free(msg->client_id); sml_octet_string_free(msg->req_file_id); sml_octet_string_free(msg->server_id); sml_time_free(msg->ref_time); sml_number_free(msg->sml_version); free(msg); } } libsml-0.1.1+git20170608/sml/src/sml_octet_string.c0000644000175000017500000000744312734144572021344 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #include #include #include #include #include #ifndef SML_NO_UUID_LIB #include #else #include // for rand() #endif uint8_t ctoi(uint8_t c); uint8_t c2toi(uint8_t c1, uint8_t c2); uint8_t c2ptoi(char* c); octet_string *sml_octet_string_init(unsigned char *str, int length) { octet_string *s = (octet_string *)malloc(sizeof(octet_string)); *s = ( octet_string ) { .str = NULL, .len = 0 }; if (length > 0) { s->str = (unsigned char *)malloc(length); memcpy(s->str, str, length); s->len = length; } return s; } octet_string *sml_octet_string_init_from_hex(char *str) { int i, len = strlen(str); if (len % 2 != 0) { return 0; } unsigned char bytes[len / 2]; for (i = 0; i < (len / 2); i++) { bytes[i] = c2ptoi(&(str[i * 2])); } return sml_octet_string_init(bytes, len / 2); } void sml_octet_string_free(octet_string *str) { if (str) { if (str->str) { free(str->str); } free(str); } } octet_string *sml_octet_string_parse(sml_buffer *buf) { if (sml_buf_optional_is_skipped(buf)) { return 0; } int l; if (sml_buf_get_next_type(buf) != SML_TYPE_OCTET_STRING) { buf->error = 1; return 0; } l = sml_buf_get_next_length(buf); if (l < 0) { buf->error = 1; return 0; } octet_string *str = sml_octet_string_init(sml_buf_get_current_buf(buf), l); sml_buf_update_bytes_read(buf, l); return str; } void sml_octet_string_write(octet_string *str, sml_buffer *buf) { if (str == 0) { sml_buf_optional_write(buf); return; } sml_buf_set_type_and_length(buf, SML_TYPE_OCTET_STRING, (unsigned int) str->len); memcpy(sml_buf_get_current_buf(buf), str->str, str->len); buf->cursor += str->len; } octet_string *sml_octet_string_generate_uuid() { #ifndef SML_NO_UUID_LIB uuid_t uuid; uuid_generate(uuid); #else char uuid[16]; // TODO add support for WIN32 systems #ifdef __linux__ int fd = open("/dev/urandom", O_RDONLY); read(fd, uuid, 16); #else int i; for(i = 0; i < 16; i++) { uuid[i] = rand() % 0xFF; } #endif /* __linux__ */ uuid[6] = (uuid[6] & 0x0F) | 0x40; // set version uuid[8] = (uuid[8] & 0x3F) | 0x80; // set reserved bits #endif /* SML_NO_UUID_LIB */ return sml_octet_string_init(uuid, 16); } int sml_octet_string_cmp(octet_string *s1, octet_string *s2) { if (s1->len != s2->len) { return -1; } return memcmp(s1->str, s2->str, s1->len); } int sml_octet_string_cmp_with_hex(octet_string *str, char *hex) { octet_string *hstr = sml_octet_string_init_from_hex(hex); if (str->len != hstr->len) { sml_octet_string_free(hstr); return -1; } int result = memcmp(str->str, hstr->str, str->len); sml_octet_string_free(hstr); return result; } uint8_t ctoi(uint8_t c){ uint8_t ret = 0; if((c >= '0') && (c <= '9')) { ret = c - '0'; } else if((c >= 'a') && (c <= 'f')) { ret = c - 'a' + 10; } else if((c >= 'A') && (c <= 'F')) { ret = c - 'A' + 10; } return ret; } uint8_t c2toi(uint8_t c1, uint8_t c2) { return ctoi(c1) << 4 | ctoi(c2); } uint8_t c2ptoi(char* c) { return ctoi((uint8_t)c[0]) << 4 | ctoi((uint8_t)c[1]); } libsml-0.1.1+git20170608/sml/include/0000755000175000017500000000000012734144572016445 5ustar andreasandreaslibsml-0.1.1+git20170608/sml/include/sml/0000755000175000017500000000000012734144572017240 5ustar andreasandreaslibsml-0.1.1+git20170608/sml/include/sml/sml_close_request.h0000644000175000017500000000240712734144572023144 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_CLOSE_REQUEST_H_ #define SML_CLOSE_REQUEST_H_ #include "sml_shared.h" #include "sml_octet_string.h" #ifdef __cplusplus extern "C" { #endif typedef struct { sml_signature *global_signature; // optional } sml_close_request; sml_close_request *sml_close_request_init(); sml_close_request * sml_close_request_parse(sml_buffer *buf); void sml_close_request_write(sml_close_request *msg, sml_buffer *buf); void sml_close_request_free(sml_close_request *msg); #ifdef __cplusplus } #endif #endif /* SML_CLOSE_REQUEST_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_transport.h0000644000175000017500000000353112734144572022322 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_TRANSPORT_H_ #define SML_TRANSPORT_H_ #include #include #ifdef __cplusplus extern "C" { #endif // sml_transport_read reads continously bytes from fd and scans // for the SML transport protocol escape sequences. If a SML file // is detected it will be copied into the buffer. The total amount of bytes read // will be returned. If the SML file exceeds the len of the buffer, -1 will be returned size_t sml_transport_read(int fd, unsigned char *buffer, size_t max_len); // sml_transport_listen is an endless loop which reads continously // via sml_transport_read and calls the sml_transporter_receiver void sml_transport_listen(int fd, void (*sml_transport_receiver)(unsigned char *buffer, size_t buffer_len)); // sml_transport_writes adds the SML transport protocol escape // sequences and writes the given file to fd. The file must be // in the parsed format. // The number of bytes written is returned, 0 if there was an // error. // The sml_file must be free'd elsewhere. int sml_transport_write(int fd, sml_file *file); #ifdef __cplusplus } #endif #endif /* SML_TRANSPORT_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_shared.h0000644000175000017500000000667012734144572021543 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_SHARED_H_ #define SML_SHARED_H_ #include #include #include #ifdef __cplusplus extern "C" { #endif typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; typedef uint64_t u64; typedef int8_t i8; typedef int16_t i16; typedef int32_t i32; typedef int64_t i64; #define SML_MESSAGE_END 0x0 #define SML_TYPE_FIELD 0x70 #define SML_LENGTH_FIELD 0xF #define SML_ANOTHER_TL 0x80 #define SML_TYPE_OCTET_STRING 0x0 #define SML_TYPE_BOOLEAN 0x40 #define SML_TYPE_INTEGER 0x50 #define SML_TYPE_UNSIGNED 0x60 #define SML_TYPE_LIST 0x70 #define SML_OPTIONAL_SKIPPED 0x1 #define SML_TYPE_NUMBER_8 sizeof(u8) #define SML_TYPE_NUMBER_16 sizeof(u16) #define SML_TYPE_NUMBER_32 sizeof(u32) #define SML_TYPE_NUMBER_64 sizeof(u64) // This sml_buffer is used in two different use-cases. // // Parsing: the raw data is in the buffer field, // the buffer_len is the number of raw bytes received, // the cursor points to the current position during parsing // // Writing: At the beginning the buffer field is malloced and zeroed with // a default length, this default length is stored in buffer_len // (i.e. the maximum bytes one can write to this buffer) // cursor points to the position, where on can write during the // writing process. If a file is completely written to the buffer, // cursor is the number of bytes written to the buffer. typedef struct { unsigned char *buffer; size_t buffer_len; size_t cursor; int error; char *error_msg; } sml_buffer; sml_buffer *sml_buffer_init(size_t length); void sml_buffer_free(sml_buffer *buf); // Returns the length of the following data structure. Sets the cursor position to // the value field. int sml_buf_get_next_length(sml_buffer *buf); void sml_buf_set_type_and_length(sml_buffer *buf, unsigned int type, unsigned int l); // Checks if a error is occured. int sml_buf_has_errors(sml_buffer *buf); // Returns the type field of the current byte. int sml_buf_get_next_type(sml_buffer *buf); // Returns the current byte. unsigned char sml_buf_get_current_byte(sml_buffer *buf); // Returns a pointer to the current buffer position. unsigned char *sml_buf_get_current_buf(sml_buffer *buf); void sml_buf_optional_write(sml_buffer *buf); // Sets the number of bytes read (moves the cursor forward) void sml_buf_update_bytes_read(sml_buffer *buf, int bytes); // Checks if the next field is a skipped optional field, updates the buffer accordingly int sml_buf_optional_is_skipped(sml_buffer *buf); // Prints arbitrarily byte string to stdout with printf void hexdump(unsigned char *buffer, size_t buffer_len); #ifdef __cplusplus } #endif #endif /* SML_SHARED_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_number.h0000644000175000017500000001010412734144572021550 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_NUMBER_H_ #define SML_NUMBER_H_ #include "sml_shared.h" #ifdef __cplusplus extern "C" { #endif void *sml_number_init(u64 number, unsigned char type, int size); // Parses a number. Identified by type (SML_TYPE_INTEGER or SML_TYPE_UNSIGNED) // and maximal number of bytes (SML_TYPE_NUMBER_8, SML_TYPE_NUMBER_16, // SML_TYPE_NUMBER_32, SML_TYPE_NUMBER_64) void *sml_number_parse(sml_buffer *buf, unsigned char type, int max_size); void sml_number_write(void *np, unsigned char type, int size, sml_buffer *buf); void sml_number_free(void *np); #define sml_u8_init(n) (u8 *) sml_number_init(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_8) #define sml_u16_init(n) (u16 *) sml_number_init(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_16) #define sml_u32_init(n) (u32 *) sml_number_init(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_32) #define sml_u64_init(n) (u64 *) sml_number_init(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_64) #define sml_i8_init(n) (i8 *) sml_number_init(n, SML_TYPE_INTEGER, SML_TYPE_NUMBER_8) #define sml_i16_init(n) (i16 *) sml_number_init(n, SML_TYPE_INTEGER, SML_TYPE_NUMBER_16) #define sml_i32_init(n) (i32 *) sml_number_init(n, SML_TYPE_INTEGER, SML_TYPE_NUMBER_32) #define sml_i64_init(n) (i64 *) sml_number_init(n, SML_TYPE_INTEGER, SML_TYPE_NUMBER_64) #define sml_u8_parse(buf) (u8 *) sml_number_parse(buf, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_8) #define sml_u16_parse(buf) (u16 *) sml_number_parse(buf, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_16) #define sml_u32_parse(buf) (u32 *) sml_number_parse(buf, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_32) #define sml_u64_parse(buf) (u64 *) sml_number_parse(buf, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_64) #define sml_i8_parse(buf) (i8 *) sml_number_parse(buf, SML_TYPE_INTEGER, SML_TYPE_NUMBER_8) #define sml_i16_parse(buf) (i16 *) sml_number_parse(buf, SML_TYPE_INTEGER, SML_TYPE_NUMBER_16) #define sml_i32_parse(buf) (i32 *) sml_number_parse(buf, SML_TYPE_INTEGER, SML_TYPE_NUMBER_32) #define sml_i64_parse(buf) (i64 *) sml_number_parse(buf, SML_TYPE_INTEGER, SML_TYPE_NUMBER_64) #define sml_u8_write(n, buf) sml_number_write(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_8, buf) #define sml_u16_write(n, buf) sml_number_write(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_16, buf) #define sml_u32_write(n, buf) sml_number_write(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_32, buf) #define sml_u64_write(n, buf) sml_number_write(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_64, buf) #define sml_i8_write(n, buf) sml_number_write(n, SML_TYPE_INTEGER, SML_TYPE_NUMBER_8, buf) #define sml_i16_write(n, buf) sml_number_write(n, SML_TYPE_INTEGER, SML_TYPE_NUMBER_16, buf) #define sml_i32_write(n, buf) sml_number_write(n, SML_TYPE_INTEGER, SML_TYPE_NUMBER_32, buf) #define sml_i64_write(n, buf) sml_number_write(n, SML_TYPE_INTEGER, SML_TYPE_NUMBER_64, buf) #define sml_u8_free( n ) sml_number_free( n ) #define sml_u16_free( n ) sml_number_free( n ) #define sml_u32_free( n ) sml_number_free( n ) #define sml_u64_free( n ) sml_number_free( n ) #define sml_i8_free( n ) sml_number_free( n ) #define sml_i16_free( n ) sml_number_free( n ) #define sml_i32_free( n ) sml_number_free( n ) #define sml_i64_free( n ) sml_number_free( n ) typedef u8 sml_unit; #define sml_unit_init(n) sml_u8_init(n) #define sml_unit_parse(buf) sml_u8_parse(buf) #define sml_unit_write(n, buf) sml_u8_write(n, buf) #define sml_unit_free(np) sml_number_free(np) #ifdef __cplusplus } #endif #endif /* SML_NUMBER_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_get_list_response.h0000644000175000017500000000305612734144572024020 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_GET_LIST_RESPONSE_H_ #define SML_GET_LIST_RESPONSE_H_ #include "sml_shared.h" #include "sml_octet_string.h" #include "sml_time.h" #include "sml_list.h" #ifdef __cplusplus extern "C" { #endif typedef struct { octet_string *client_id; // optional octet_string *server_id; octet_string *list_name; // optional sml_time *act_sensor_time; // optional sml_list *val_list; sml_signature *list_signature; // optional sml_time *act_gateway_time; // optional } sml_get_list_response; sml_get_list_response *sml_get_list_response_init(); sml_get_list_response *sml_get_list_response_parse(sml_buffer *buf); void sml_get_list_response_write(sml_get_list_response *msg, sml_buffer *buf); void sml_get_list_response_free(sml_get_list_response *msg); #ifdef __cplusplus } #endif #endif /* SML_GET_LIST_RESPONSE_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_octet_string.h0000644000175000017500000000343312734144572022773 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_OCTET_STRING_H_ #define SML_OCTET_STRING_H_ #include #include "sml_shared.h" #ifdef __cplusplus extern "C" { #endif typedef struct { unsigned char *str; int len; } octet_string; octet_string *sml_octet_string_init(unsigned char *str, int length); octet_string *sml_octet_string_init_from_hex(char *str); // Parses a octet string, updates the buffer accordingly, memory must be free'd elsewhere. octet_string *sml_octet_string_parse(sml_buffer *buf); octet_string *sml_octet_string_generate_uuid(); void sml_octet_string_write(octet_string *str, sml_buffer *buf); void sml_octet_string_free(octet_string *str); int sml_octet_string_cmp(octet_string *s1, octet_string *s2); int sml_octet_string_cmp_with_hex(octet_string *str, char *hex); // sml signature typedef octet_string sml_signature; #define sml_signature_parse(buf) sml_octet_string_parse(buf) #define sml_signature_write(s, buf) sml_octet_string_write(s, buf) #define sml_signature_free(s) sml_octet_string_free(s) #ifdef __cplusplus } #endif #endif /* SML_OCTET_STRING_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_get_profile_pack_request.h0000644000175000017500000000423212734144572025332 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_GET_PROFILE_PACK_REQUEST_H_ #define SML_GET_PROFILE_PACK_REQUEST_H_ #include "sml_shared.h" #include "sml_octet_string.h" #include "sml_time.h" #include "sml_list.h" #include "sml_tree.h" #ifdef __cplusplus extern "C" { #endif typedef octet_string sml_obj_req_entry; #define sml_obj_req_entry_parse(buf) sml_octet_string_parse(buf) #define sml_obj_req_entry_write(p, buf) sml_octet_string_write(p, buf) #define sml_obj_req_entry_free(p) sml_octet_string_free(p) typedef struct sml_obj_req_entry_list_entry { sml_obj_req_entry *object_list_entry; // list specific struct sml_obj_req_entry_list_entry *next; } sml_obj_req_entry_list; typedef struct { octet_string *server_id; // optional octet_string *username; // optional octet_string *password; // optional sml_boolean *with_rawdata; // optional sml_time *begin_time; // optional sml_time *end_time; // optional sml_tree_path *parameter_tree_path; sml_obj_req_entry_list *object_list; // optional sml_tree *das_details; // optional } sml_get_profile_pack_request; sml_get_profile_pack_request *sml_get_profile_pack_request_parse(sml_buffer *buf); sml_get_profile_pack_request *sml_get_profile_pack_request_init(); void sml_get_profile_pack_request_write(sml_get_profile_pack_request *msg, sml_buffer *buf); void sml_get_profile_pack_request_free(sml_get_profile_pack_request *msg); #ifdef __cplusplus } #endif #endif /* SML_GET_PROFILE_PACK_REQUEST_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_attention_response.h0000644000175000017500000000267712734144572024223 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_ATTENTION_RESPONSE_H_ #define SML_ATTENTION_RESPONSE_H_ #include "sml_shared.h" #include "sml_octet_string.h" #include "sml_tree.h" #ifdef __cplusplus extern "C" { #endif typedef struct { octet_string *server_id; octet_string *attention_number; octet_string *attention_message; // optional sml_tree *attention_details; // optional } sml_attention_response; sml_attention_response *sml_attention_response_init(); sml_attention_response *sml_attention_response_parse(sml_buffer *buf); void sml_attention_response_write(sml_attention_response *msg, sml_buffer *buf); void sml_attention_response_free(sml_attention_response *msg); #ifdef __cplusplus } #endif #endif /* SML_ATTENTION_RESPONSE_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_file.h0000644000175000017500000000257112734144572021210 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_FILE_H_ #define SML_FILE_H_ #include "sml_message.h" #include "sml_shared.h" #include #ifdef __cplusplus extern "C" { #endif // a SML file consist of multiple SML messages typedef struct { sml_message **messages; short messages_len; sml_buffer *buf; } sml_file; sml_file *sml_file_init(); // parses a SML file. sml_file *sml_file_parse(unsigned char *buffer, size_t buffer_len); void sml_file_add_message(sml_file *file, sml_message *message); void sml_file_write(sml_file *file); void sml_file_free(sml_file *file); void sml_file_print(sml_file *file); #ifdef __cplusplus } #endif #endif /* SML_FILE_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_boolean.h0000644000175000017500000000225612734144572021710 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_BOOLEAN_H_ #define SML_BOOLEAN_H_ #define SML_BOOLEAN_TRUE 0xFF #define SML_BOOLEAN_FALSE 0x00 #include "sml_shared.h" #ifdef __cplusplus extern "C" { #endif typedef u8 sml_boolean; sml_boolean *sml_boolean_init(u8 b); sml_boolean *sml_boolean_parse(sml_buffer *buf); void sml_boolean_write(sml_boolean *boolean, sml_buffer *buf); void sml_boolean_free(sml_boolean *b); #ifdef __cplusplus } #endif #endif /* SML_BOOLEAN_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_open_request.h0000644000175000017500000000267012734144572023002 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_OPEN_REQUEST_H_ #define SML_OPEN_REQUEST_H_ #include "sml_shared.h" #include "sml_octet_string.h" #ifdef __cplusplus extern "C" { #endif typedef struct { octet_string *codepage; // optional octet_string *client_id; octet_string *req_file_id; octet_string *server_id; // optional octet_string *username; // optional octet_string *password; // optional u8 *sml_version; // optional } sml_open_request; sml_open_request *sml_open_request_init(); sml_open_request *sml_open_request_parse(sml_buffer *buf); void sml_open_request_write(sml_open_request *msg, sml_buffer *buf); void sml_open_request_free(sml_open_request *msg); #ifdef __cplusplus } #endif #endif /* SML_OPEN_REQUEST_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_crc16.h0000644000175000017500000000177512734144572021214 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_CRC16_H_ #define SML_CRC16_H_ #include "sml_shared.h" #ifdef __cplusplus extern "C" { #endif // CRC16 FSC implementation based on DIN 62056-46 u16 sml_crc16_calculate(unsigned char *cp, int len) ; #ifdef __cplusplus } #endif #endif /* SML_CRC16_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_get_proc_parameter_request.h0000644000175000017500000000312412734144572025676 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_GET_PROC_PARAMETER_REQUEST_H_ #define SML_GET_PROC_PARAMETER_REQUEST_H_ #include "sml_shared.h" #include "sml_octet_string.h" #include "sml_tree.h" #ifdef __cplusplus extern "C" { #endif typedef struct { octet_string *server_id; // optional octet_string *username; // optional octet_string *password; // optional sml_tree_path *parameter_tree_path; octet_string *attribute; // optional } sml_get_proc_parameter_request; sml_get_proc_parameter_request *sml_get_proc_parameter_request_init(); sml_get_proc_parameter_request *sml_get_proc_parameter_request_parse(sml_buffer *buf); void sml_get_proc_parameter_request_write(sml_get_proc_parameter_request *msg, sml_buffer *buf); void sml_get_proc_parameter_request_free(sml_get_proc_parameter_request *msg); #ifdef __cplusplus } #endif #endif /* SML_GET_PROC_PARAMETER_REQUEST_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_get_proc_parameter_response.h0000644000175000017500000000276012734144572026051 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_GET_PROC_PARAMETER_RESPONSE_H_ #define SML_GET_PROC_PARAMETER_RESPONSE_H_ #include "sml_shared.h" #include "sml_octet_string.h" #include "sml_tree.h" #ifdef __cplusplus extern "C" { #endif typedef struct { octet_string *server_id; sml_tree_path *parameter_tree_path; sml_tree *parameter_tree; } sml_get_proc_parameter_response; sml_get_proc_parameter_response *sml_get_proc_parameter_response_init(); sml_get_proc_parameter_response *sml_get_proc_parameter_response_parse(sml_buffer *buf); void sml_get_proc_parameter_response_write(sml_get_proc_parameter_response *msg, sml_buffer *buf); void sml_get_proc_parameter_response_free(sml_get_proc_parameter_response *msg); #ifdef __cplusplus } #endif #endif /* SML_GET_PROC_PARAMETER_RESPONSE_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_set_proc_parameter_request.h0000644000175000017500000000307212734144572025714 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_SET_PROC_PARAMETER_REQUEST_H_ #define SML_SET_PROC_PARAMETER_REQUEST_H_ #include "sml_shared.h" #include "sml_octet_string.h" #include "sml_tree.h" #ifdef __cplusplus extern "C" { #endif typedef struct { octet_string *server_id; // optional octet_string *username; // optional octet_string *password; // optional sml_tree_path *parameter_tree_path; sml_tree *parameter_tree; } sml_set_proc_parameter_request; sml_set_proc_parameter_request *sml_set_proc_parameter_request_init(); sml_set_proc_parameter_request *sml_set_proc_parameter_request_parse(sml_buffer *buf); void sml_set_proc_parameter_request_write(sml_set_proc_parameter_request *msg, sml_buffer *buf); void sml_set_proc_parameter_request_free(sml_set_proc_parameter_request *msg); #ifdef __cplusplus } #endif #endif /* SML_SET_PROC_PARAMETER_REQUEST_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_list.h0000644000175000017500000000376012734144572021245 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_LIST_H_ #define SML_LIST_H_ #include "sml_time.h" #include "sml_octet_string.h" #include "sml_number.h" #include "sml_status.h" #include "sml_value.h" #ifdef __cplusplus extern "C" { #endif typedef struct { void **elems; int elems_len; void (*elem_free) (void *elem); } sml_sequence; sml_sequence *sml_sequence_init(void (*elem_free) (void *elem)); sml_sequence *sml_sequence_parse(sml_buffer *buf, void *(*elem_parse) (sml_buffer *buf), void (*elem_free) (void *elem)); void sml_sequence_write(sml_sequence *seq, sml_buffer *buf, void (*elem_write) (void *elem, sml_buffer *buf)); void sml_sequence_free(sml_sequence *seq); void sml_sequence_add(sml_sequence *list, void *new_entry); typedef struct sml_list_entry { octet_string *obj_name; sml_status *status; // optional sml_time *val_time; // optional sml_unit *unit; // optional i8 *scaler; // optional sml_value *value; sml_signature *value_signature; // optional // list specific struct sml_list_entry *next; } sml_list; sml_list *sml_list_init(); sml_list *sml_list_parse(sml_buffer *buf); void sml_list_write(sml_list *list, sml_buffer *buf); void sml_list_add(sml_list *list, sml_list *new_entry); void sml_list_free(sml_list *list); #ifdef __cplusplus } #endif #endif /* SML_LIST_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_close_response.h0000644000175000017500000000232412734144572023310 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_CLOSE_RESPONSE_H_ #define SML_CLOSE_RESPONSE_H_ #include "sml_close_request.h" #ifdef __cplusplus extern "C" { #endif typedef sml_close_request sml_close_response; sml_close_response *sml_close_response_init(); sml_close_response *sml_close_response_parse(sml_buffer *buf); void sml_close_response_write(sml_close_response *msg, sml_buffer *buf); void sml_close_response_free(sml_close_response *msg); #ifdef __cplusplus } #endif #endif /* SML_CLOSE_RESPONSE_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_get_profile_pack_response.h0000644000175000017500000000564312734144572025507 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_GET_PROFILE_PACK_RESPONSE_H_ #define SML_GET_PROFILE_PACK_RESPONSE_H_ #include "sml_shared.h" #include "sml_octet_string.h" #include "sml_time.h" #include "sml_list.h" #include "sml_tree.h" #ifdef __cplusplus extern "C" { #endif typedef struct { octet_string *server_id; sml_time *act_time; // specified by germans (current time was meant) ;) u32 *reg_period; sml_tree_path *parameter_tree_path; sml_sequence *header_list; // list of sml_prof_obj_header_entry sml_sequence *period_list; // list of sml_prof_obj_period_entry octet_string *rawdata; // optional sml_signature *profile_signature; // optional } sml_get_profile_pack_response; sml_get_profile_pack_response *sml_get_profile_pack_response_init(); sml_get_profile_pack_response *sml_get_profile_pack_response_parse(sml_buffer *buf); void sml_get_profile_pack_response_write(sml_get_profile_pack_response *msg, sml_buffer *buf); void sml_get_profile_pack_response_free(sml_get_profile_pack_response *msg); typedef struct { octet_string *obj_name; sml_unit *unit; i8 *scaler; } sml_prof_obj_header_entry; sml_prof_obj_header_entry *sml_prof_obj_header_entry_init(); sml_prof_obj_header_entry *sml_prof_obj_header_entry_parse(sml_buffer *buf); void sml_prof_obj_header_entry_write(sml_prof_obj_header_entry *entry, sml_buffer *buf); void sml_prof_obj_header_entry_free(sml_prof_obj_header_entry *entry); typedef struct { sml_time *val_time; u64 *status; sml_sequence *value_list; sml_signature *period_signature; } sml_prof_obj_period_entry; sml_prof_obj_period_entry *sml_prof_obj_period_entry_init(); sml_prof_obj_period_entry *sml_prof_obj_period_entry_parse(sml_buffer *buf); void sml_prof_obj_period_entry_write(sml_prof_obj_period_entry *entry, sml_buffer *buf); void sml_prof_obj_period_entry_free(sml_prof_obj_period_entry *entry); typedef struct { sml_value *value; sml_signature *value_signature; } sml_value_entry; sml_value_entry *sml_value_entry_init(); sml_value_entry *sml_value_entry_parse(sml_buffer *buf); void sml_value_entry_write(sml_value_entry *entry, sml_buffer *buf); void sml_value_entry_free(sml_value_entry *entry); #ifdef __cplusplus } #endif #endif /* SML_GET_PROFILE_PACK_RESPONSE_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_status.h0000644000175000017500000000234212734144572021610 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_STATUS_H_ #define SML_STATUS_H_ #include "sml_number.h" #include "sml_shared.h" #ifdef __cplusplus extern "C" { #endif typedef struct { u8 type; union { u8 *status8; u16 *status16; u32 *status32; u64 *status64; } data; } sml_status; sml_status *sml_status_init(); sml_status *sml_status_parse(sml_buffer *buf); void sml_status_write(sml_status *status, sml_buffer *buf); void sml_status_free(sml_status *status); #ifdef __cplusplus } #endif #endif /* SML_STATUS_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_get_list_request.h0000644000175000017500000000273612734144572023656 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_GET_LIST_REQUEST_H_ #define SML_GET_LIST_REQUEST_H_ #include "sml_shared.h" #include "sml_octet_string.h" #include "sml_time.h" #include "sml_list.h" #ifdef __cplusplus extern "C" { #endif typedef struct { octet_string *client_id; octet_string *server_id; // optional octet_string *username; // optional octet_string *password; // optional octet_string *list_name; // optional } sml_get_list_request; sml_get_list_request* sml_get_list_request_init(); sml_get_list_request *sml_get_list_request_parse(sml_buffer *buf); void sml_get_list_request_write(sml_get_list_request *msg, sml_buffer *buf); void sml_get_list_request_free(sml_get_list_request *msg); #ifdef __cplusplus } #endif #endif /* SML_GET_LIST_REQUEST_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_value.h0000644000175000017500000000273312734144572021405 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_VALUE_H_ #define SML_VALUE_H_ #include "sml_shared.h" #include "sml_octet_string.h" #include "sml_number.h" #include "sml_boolean.h" #ifdef __cplusplus extern "C" { #endif typedef struct { u8 type; union { sml_boolean *boolean; octet_string *bytes; // can have zero length i8 *int8; i16 *int16; i32 *int32; i64 *int64; u8 *uint8; u16 *uint16; u32 *uint32; u64 *uint64; } data; } sml_value; sml_value *sml_value_init(); sml_value *sml_value_parse(sml_buffer *buf); void sml_value_write(sml_value *value, sml_buffer *buf); void sml_value_free(sml_value *value); // Cast arbitrary sized sml_value to double double sml_value_to_double(sml_value *value); #ifdef __cplusplus } #endif #endif /* SML_VALUE_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_open_response.h0000644000175000017500000000265612734144572023154 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_OPEN_RESPONSE_H_ #define SML_OPEN_RESPONSE_H_ #include "sml_shared.h" #include "sml_octet_string.h" #include "sml_time.h" #ifdef __cplusplus extern "C" { #endif typedef struct { octet_string *codepage; // optional octet_string *client_id; // optional octet_string *req_file_id; octet_string *server_id; sml_time *ref_time; // optional u8 *sml_version; // optional } sml_open_response; sml_open_response *sml_open_response_init(); sml_open_response *sml_open_response_parse(sml_buffer *buf); void sml_open_response_write(sml_open_response *msg, sml_buffer *buf); void sml_open_response_free(sml_open_response *msg); #ifdef __cplusplus } #endif #endif /* SML_OPEN_RESPONSE_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_time.h0000644000175000017500000000235112734144572021223 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_TIME_H_ #define SML_TIME_H_ #include "sml_shared.h" #include "sml_number.h" #ifdef __cplusplus extern "C" { #endif #define SML_TIME_SEC_INDEX 0x01 #define SML_TIME_TIMESTAMP 0x02 typedef struct { u8 *tag; union { u32 *sec_index; u32 *timestamp; } data; } sml_time; sml_time *sml_time_init(); sml_time *sml_time_parse(sml_buffer *buf); void sml_time_write(sml_time *time, sml_buffer *buf); void sml_time_free(sml_time *time); #ifdef __cplusplus } #endif #endif /* SML_TIME_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_get_profile_list_response.h0000644000175000017500000000321112734144572025531 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_GET_PROFILE_LIST_RESPONSE_H_ #define SML_GET_PROFILE_LIST_RESPONSE_H_ #include "sml_shared.h" #include "sml_octet_string.h" #include "sml_time.h" #include "sml_list.h" #include "sml_tree.h" #ifdef __cplusplus extern "C" { #endif typedef struct { octet_string *server_id; sml_time *act_time; u32 *reg_period; sml_tree_path *parameter_tree_path; sml_time *val_time; u64 *status; sml_sequence *period_list; octet_string *rawdata; sml_signature *period_signature; } sml_get_profile_list_response; sml_get_profile_list_response *sml_get_profile_list_response_init(); sml_get_profile_list_response *sml_get_profile_list_response_parse(sml_buffer *buf); void sml_get_profile_list_response_write(sml_get_profile_list_response *msg, sml_buffer *buf); void sml_get_profile_list_response_free(sml_get_profile_list_response *msg); #ifdef __cplusplus } #endif #endif /* SML_GET_PROFILE_LIST_RESPONSE_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_tree.h0000644000175000017500000000676612734144572021242 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_TREE_H_ #define SML_TREE_H_ #include "sml_shared.h" #include "sml_octet_string.h" #include "sml_value.h" #include "sml_time.h" #ifdef __cplusplus extern "C" { #endif #define SML_PROC_PAR_VALUE_TAG_VALUE 0x01 #define SML_PROC_PAR_VALUE_TAG_PERIOD_ENTRY 0x02 #define SML_PROC_PAR_VALUE_TAG_TUPEL_ENTRY 0x03 #define SML_PROC_PAR_VALUE_TAG_TIME 0x04 // what a messy tupel ... typedef struct { octet_string *server_id; sml_time *sec_index; u64 *status; sml_unit *unit_pA; i8 *scaler_pA; i64 *value_pA; sml_unit *unit_R1; i8 *scaler_R1; i64 *value_R1; sml_unit *unit_R4; i8 *scaler_R4; i64 *value_R4; octet_string *signature_pA_R1_R4; sml_unit *unit_mA; i8 *scaler_mA; i64 *value_mA; sml_unit *unit_R2; i8 *scaler_R2; i64 *value_R2; sml_unit *unit_R3; i8 *scaler_R3; i64 *value_R3; octet_string *signature_mA_R2_R3; } sml_tupel_entry; typedef struct { octet_string *obj_name; sml_unit *unit; i8 *scaler; sml_value *value; octet_string *value_signature; } sml_period_entry; typedef struct { u8 *tag; union { sml_value *value; sml_period_entry *period_entry; sml_tupel_entry *tupel_entry; sml_time *time; } data; } sml_proc_par_value; typedef struct s_tree{ octet_string *parameter_name; sml_proc_par_value *parameter_value; // optional struct s_tree **child_list; // optional int child_list_len; } sml_tree; typedef struct { int path_entries_len; octet_string **path_entries; } sml_tree_path; // sml_tree; sml_tree *sml_tree_init(); sml_tree *sml_tree_parse(sml_buffer *buf); void sml_tree_add_tree(sml_tree *base_tree, sml_tree *tree); void sml_tree_write(sml_tree *tree, sml_buffer *buf); void sml_tree_free(sml_tree *tree); // sml_tree_path; sml_tree_path *sml_tree_path_init(); sml_tree_path *sml_tree_path_parse(sml_buffer *buf); void sml_tree_path_add_path_entry(sml_tree_path *tree_path, octet_string *entry); void sml_tree_path_write(sml_tree_path *tree_path, sml_buffer *buf); void sml_tree_path_free(sml_tree_path *tree_path); // sml_proc_par_value; sml_proc_par_value *sml_proc_par_value_init(); sml_proc_par_value *sml_proc_par_value_parse(sml_buffer *buf); void sml_proc_par_value_write(sml_proc_par_value *value, sml_buffer *buf); void sml_proc_par_value_free(sml_proc_par_value *value); // sml_tupel_entry; sml_tupel_entry *sml_tupel_entry_init(); sml_tupel_entry *sml_tupel_entry_parse(sml_buffer *buf); void sml_tupel_entry_write(sml_tupel_entry *tupel, sml_buffer *buf); void sml_tupel_entry_free(sml_tupel_entry *tupel); // sml_period_entry; sml_period_entry *sml_period_entry_init(); sml_period_entry *sml_period_entry_parse(sml_buffer *buf); void sml_period_entry_write(sml_period_entry *period, sml_buffer *buf); void sml_period_entry_free(sml_period_entry *period); #ifdef __cplusplus } #endif #endif /* SML_TREE_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_message.h0000644000175000017500000000606312734144572021715 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_MESSAGE_H_ #define SML_MESSAGE_H_ #include #include "sml_octet_string.h" #include "sml_time.h" #include "sml_list.h" #include "sml_tree.h" #include "sml_open_request.h" #include "sml_open_response.h" #include "sml_close_request.h" #include "sml_close_response.h" #include "sml_get_profile_pack_request.h" #include "sml_get_profile_pack_response.h" #include "sml_get_profile_list_request.h" #include "sml_get_profile_list_response.h" #include "sml_get_proc_parameter_request.h" #include "sml_get_proc_parameter_response.h" #include "sml_set_proc_parameter_request.h" #include "sml_get_list_request.h" #include "sml_get_list_response.h" #include "sml_attention_response.h" #define SML_MESSAGE_OPEN_REQUEST 0x00000100 #define SML_MESSAGE_OPEN_RESPONSE 0x00000101 #define SML_MESSAGE_CLOSE_REQUEST 0x00000200 #define SML_MESSAGE_CLOSE_RESPONSE 0x00000201 #define SML_MESSAGE_GET_PROFILE_PACK_REQUEST 0x00000300 #define SML_MESSAGE_GET_PROFILE_PACK_RESPONSE 0x00000301 #define SML_MESSAGE_GET_PROFILE_LIST_REQUEST 0x00000400 #define SML_MESSAGE_GET_PROFILE_LIST_RESPONSE 0x00000401 #define SML_MESSAGE_GET_PROC_PARAMETER_REQUEST 0x00000500 #define SML_MESSAGE_GET_PROC_PARAMETER_RESPONSE 0x00000501 #define SML_MESSAGE_SET_PROC_PARAMETER_REQUEST 0x00000600 #define SML_MESSAGE_SET_PROC_PARAMETER_RESPONSE 0x00000601 // This doesn't exist in the spec #define SML_MESSAGE_GET_LIST_REQUEST 0x00000700 #define SML_MESSAGE_GET_LIST_RESPONSE 0x00000701 #define SML_MESSAGE_ATTENTION_RESPONSE 0x0000FF01 #ifdef __cplusplus extern "C" { #endif typedef struct { u32 *tag; void *data; } sml_message_body; typedef struct { octet_string *transaction_id; u8 *group_id; u8 *abort_on_error; sml_message_body *message_body; u16 *crc; /* end of message */ } sml_message; // SML MESSAGE sml_message *sml_message_parse(sml_buffer *buf); sml_message *sml_message_init(); // Sets a transaction id. void sml_message_free(sml_message *msg); void sml_message_write(sml_message *msg, sml_buffer *buf); // SML_MESSAGE_BODY sml_message_body *sml_message_body_parse(sml_buffer *buf); sml_message_body *sml_message_body_init(u32 tag, void *data); void sml_message_body_free(sml_message_body *message_body); void sml_message_body_write(sml_message_body *message_body, sml_buffer *buf); #ifdef __cplusplus } #endif #endif /* SML_MESSAGE_H_ */ libsml-0.1.1+git20170608/sml/include/sml/sml_get_profile_list_request.h0000644000175000017500000000271712734144572025375 0ustar andreasandreas// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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. // // libSML is distributed in the hope that 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 libSML. If not, see . #ifndef SML_GET_PROFILE_LIST_REQUEST_H_ #define SML_GET_PROFILE_LIST_REQUEST_H_ #include "sml_get_profile_pack_request.h" #ifdef __cplusplus extern "C" { #endif // Apparently SML_GetProfilePack.Req is the same as SML_GetProfileList.Req typedef sml_get_profile_pack_request sml_get_profile_list_request; #define sml_get_profile_list_request_init() sml_get_profile_pack_request_init() #define sml_get_profile_list_request_parse(buf) sml_get_profile_pack_request_parse(buf) #define sml_get_profile_list_request_write(msg, buf) sml_get_profile_pack_request_write(msg, buf) #define sml_get_profile_list_request_free(msg) sml_get_profile_pack_request_free(msg) #ifdef __cplusplus } #endif #endif /* SML_GET_PROFILE_LIST_REQUEST_H_ */ libsml-0.1.1+git20170608/sml/lib/0000755000175000017500000000000012734144572015570 5ustar andreasandreaslibsml-0.1.1+git20170608/sml/lib/.gitdir0000644000175000017500000000000012734144572017041 0ustar andreasandreaslibsml-0.1.1+git20170608/sml/Makefile0000644000175000017500000000270312734144572016464 0ustar andreasandreasUNAME := $(shell uname) CFLAGS += -I./include/ -fPIC -fno-stack-protector -g -std=c99 -Wall -Wextra -pedantic # Available Flags: # SML_NO_UUID_LIB - compile without uuid lib ifeq ($(UNAME), Linux) LIBS=-luuid endif NAME=libsml SOVERSION=1 SONAME=$(NAME).so.$(SOVERSION) LIB_DIR=./lib OBJ_LIB=$(LIB_DIR)/$(NAME).o DYN_LIB=$(LIB_DIR)/$(SONAME) ST_LIB=$(LIB_DIR)/$(NAME).a OBJS = \ src/sml_file.o \ src/sml_attention_response.o \ src/sml_transport.o \ src/sml_octet_string.o \ src/sml_shared.o \ src/sml_number.o \ src/sml_message.o \ src/sml_time.o \ src/sml_list.o \ src/sml_status.o \ src/sml_value.o \ src/sml_tree.o \ src/sml_boolean.o \ src/sml_crc16.o \ src/sml_open_request.o \ src/sml_open_response.o \ src/sml_get_list_request.o \ src/sml_get_list_response.o \ src/sml_close_request.o \ src/sml_close_response.o \ src/sml_set_proc_parameter_request.o \ src/sml_get_proc_parameter_request.o \ src/sml_get_proc_parameter_response.o \ src/sml_get_profile_pack_request.o \ src/sml_get_profile_pack_response.o \ src/sml_get_profile_list_request.o \ src/sml_get_profile_list_response.o ifeq ($(UNAME), Linux) libsml: $(DYN_LIB) $(ST_LIB) $(OBJ_LIB) endif ifeq ($(UNAME), Darwin) libsml: $(ST_LIB) $(OBJ_LIB) endif $(DYN_LIB): $(OBJS) $(LD) $(LIBS) -shared -soname $(SONAME) -o $@ $^ $(OBJ_LIB): $(OBJS) $(LD) -r -o $@ $^ $(ST_LIB): $(OBJS) $(AR) -rs $@ $^ .PHONY: clean clean: @rm -f src/*.o @rm -f $(DYN_LIB) $(OBJ_LIB) $(ST_LIB) libsml-0.1.1+git20170608/Makefile0000644000175000017500000000024212734144572015665 0ustar andreasandreas all: @$(MAKE) -C sml @$(MAKE) -C examples @$(MAKE) -C test .PHONY: clean clean : @$(MAKE) -C sml clean @$(MAKE) -C examples clean @$(MAKE) -C test clean