From ff4360527cf3d026447997e70258e4ffa15cbbfa Mon Sep 17 00:00:00 2001 From: Cedric Roux <cedric.roux@eurecom.fr> Date: Fri, 18 Oct 2013 15:24:52 +0000 Subject: [PATCH] git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4233 818b1a75-f10b-46b9-bf7c-635c3b92a50f --- common/utils/itti_analyzer/AUTHORS | 0 common/utils/itti_analyzer/COPYING | 674 ++++++++++++++++ common/utils/itti_analyzer/ChangeLog | 0 common/utils/itti_analyzer/INSTALL | 370 +++++++++ common/utils/itti_analyzer/Makefile.am | 16 + common/utils/itti_analyzer/NEWS | 0 common/utils/itti_analyzer/README | 0 common/utils/itti_analyzer/autogen.sh | 6 + common/utils/itti_analyzer/configure.ac | 93 +++ common/utils/itti_analyzer/itti_analyzer.c | 26 + .../itti_analyzer/libbuffers/Makefile.am | 13 + .../utils/itti_analyzer/libbuffers/buffers.c | 242 ++++++ .../utils/itti_analyzer/libbuffers/buffers.h | 53 ++ common/utils/itti_analyzer/libbuffers/file.c | 50 ++ common/utils/itti_analyzer/libbuffers/file.h | 6 + .../utils/itti_analyzer/libbuffers/socket.c | 282 +++++++ .../utils/itti_analyzer/libbuffers/socket.h | 19 + .../utils/itti_analyzer/libparser/Makefile.am | 23 + .../itti_analyzer/libparser/array_type.c | 113 +++ .../itti_analyzer/libparser/array_type.h | 13 + .../utils/itti_analyzer/libparser/enum_type.c | 97 +++ .../utils/itti_analyzer/libparser/enum_type.h | 14 + .../itti_analyzer/libparser/enum_value_type.c | 61 ++ .../itti_analyzer/libparser/enum_value_type.h | 14 + .../itti_analyzer/libparser/field_type.c | 143 ++++ .../itti_analyzer/libparser/field_type.h | 13 + .../utils/itti_analyzer/libparser/file_type.c | 30 + .../utils/itti_analyzer/libparser/file_type.h | 10 + .../libparser/fundamental_type.c | 111 +++ .../libparser/fundamental_type.h | 15 + .../libparser/intertask_contexts.h | 14 + common/utils/itti_analyzer/libparser/parser.y | 181 +++++ .../itti_analyzer/libparser/pointer_type.c | 84 ++ .../itti_analyzer/libparser/pointer_type.h | 13 + .../itti_analyzer/libparser/reference_type.c | 71 ++ .../itti_analyzer/libparser/reference_type.h | 13 + .../utils/itti_analyzer/libparser/scanner.l | 123 +++ .../itti_analyzer/libparser/struct_type.c | 109 +++ .../itti_analyzer/libparser/struct_type.h | 13 + .../itti_analyzer/libparser/typedef_type.c | 69 ++ .../itti_analyzer/libparser/typedef_type.h | 13 + common/utils/itti_analyzer/libparser/types.c | 123 +++ common/utils/itti_analyzer/libparser/types.h | 159 ++++ .../itti_analyzer/libparser/union_type.c | 126 +++ .../itti_analyzer/libparser/union_type.h | 16 + .../utils/itti_analyzer/libparser/xml_parse.c | 757 ++++++++++++++++++ .../utils/itti_analyzer/libparser/xml_parse.h | 13 + .../itti_analyzer/libresolver/Makefile.am | 12 + .../itti_analyzer/libresolver/locate_root.c | 82 ++ .../itti_analyzer/libresolver/locate_root.h | 10 + .../libresolver/resolve_typedef.c | 25 + .../itti_analyzer/libresolver/resolvers.c | 330 ++++++++ .../itti_analyzer/libresolver/resolvers.h | 22 + common/utils/itti_analyzer/libui/Makefile.am | 17 + .../utils/itti_analyzer/libui/ui_callbacks.c | 111 +++ .../utils/itti_analyzer/libui/ui_callbacks.h | 31 + .../utils/itti_analyzer/libui/ui_interface.c | 34 + .../utils/itti_analyzer/libui/ui_interface.h | 61 ++ .../itti_analyzer/libui/ui_main_screen.c | 74 ++ .../itti_analyzer/libui/ui_main_screen.h | 22 + .../utils/itti_analyzer/libui/ui_menu_bar.c | 131 +++ .../utils/itti_analyzer/libui/ui_menu_bar.h | 8 + .../utils/itti_analyzer/libui/ui_notebook.c | 33 + .../utils/itti_analyzer/libui/ui_notebook.h | 6 + .../itti_analyzer/libui/ui_notifications.c | 108 +++ .../itti_analyzer/libui/ui_notifications.h | 16 + .../libui/ui_signal_dissect_view.c | 74 ++ .../libui/ui_signal_dissect_view.h | 10 + .../utils/itti_analyzer/libui/ui_tree_view.c | 122 +++ .../utils/itti_analyzer/libui/ui_tree_view.h | 10 + common/utils/itti_analyzer/queue.h | 592 ++++++++++++++ common/utils/itti_analyzer/rc.h | 47 ++ 72 files changed, 6392 insertions(+) create mode 100644 common/utils/itti_analyzer/AUTHORS create mode 100644 common/utils/itti_analyzer/COPYING create mode 100644 common/utils/itti_analyzer/ChangeLog create mode 100644 common/utils/itti_analyzer/INSTALL create mode 100644 common/utils/itti_analyzer/Makefile.am create mode 100644 common/utils/itti_analyzer/NEWS create mode 100644 common/utils/itti_analyzer/README create mode 100755 common/utils/itti_analyzer/autogen.sh create mode 100644 common/utils/itti_analyzer/configure.ac create mode 100644 common/utils/itti_analyzer/itti_analyzer.c create mode 100644 common/utils/itti_analyzer/libbuffers/Makefile.am create mode 100644 common/utils/itti_analyzer/libbuffers/buffers.c create mode 100644 common/utils/itti_analyzer/libbuffers/buffers.h create mode 100644 common/utils/itti_analyzer/libbuffers/file.c create mode 100644 common/utils/itti_analyzer/libbuffers/file.h create mode 100644 common/utils/itti_analyzer/libbuffers/socket.c create mode 100644 common/utils/itti_analyzer/libbuffers/socket.h create mode 100644 common/utils/itti_analyzer/libparser/Makefile.am create mode 100644 common/utils/itti_analyzer/libparser/array_type.c create mode 100644 common/utils/itti_analyzer/libparser/array_type.h create mode 100644 common/utils/itti_analyzer/libparser/enum_type.c create mode 100644 common/utils/itti_analyzer/libparser/enum_type.h create mode 100644 common/utils/itti_analyzer/libparser/enum_value_type.c create mode 100644 common/utils/itti_analyzer/libparser/enum_value_type.h create mode 100644 common/utils/itti_analyzer/libparser/field_type.c create mode 100644 common/utils/itti_analyzer/libparser/field_type.h create mode 100644 common/utils/itti_analyzer/libparser/file_type.c create mode 100644 common/utils/itti_analyzer/libparser/file_type.h create mode 100644 common/utils/itti_analyzer/libparser/fundamental_type.c create mode 100644 common/utils/itti_analyzer/libparser/fundamental_type.h create mode 100644 common/utils/itti_analyzer/libparser/intertask_contexts.h create mode 100644 common/utils/itti_analyzer/libparser/parser.y create mode 100644 common/utils/itti_analyzer/libparser/pointer_type.c create mode 100644 common/utils/itti_analyzer/libparser/pointer_type.h create mode 100644 common/utils/itti_analyzer/libparser/reference_type.c create mode 100644 common/utils/itti_analyzer/libparser/reference_type.h create mode 100644 common/utils/itti_analyzer/libparser/scanner.l create mode 100644 common/utils/itti_analyzer/libparser/struct_type.c create mode 100644 common/utils/itti_analyzer/libparser/struct_type.h create mode 100644 common/utils/itti_analyzer/libparser/typedef_type.c create mode 100644 common/utils/itti_analyzer/libparser/typedef_type.h create mode 100644 common/utils/itti_analyzer/libparser/types.c create mode 100644 common/utils/itti_analyzer/libparser/types.h create mode 100644 common/utils/itti_analyzer/libparser/union_type.c create mode 100644 common/utils/itti_analyzer/libparser/union_type.h create mode 100644 common/utils/itti_analyzer/libparser/xml_parse.c create mode 100644 common/utils/itti_analyzer/libparser/xml_parse.h create mode 100644 common/utils/itti_analyzer/libresolver/Makefile.am create mode 100644 common/utils/itti_analyzer/libresolver/locate_root.c create mode 100644 common/utils/itti_analyzer/libresolver/locate_root.h create mode 100644 common/utils/itti_analyzer/libresolver/resolve_typedef.c create mode 100644 common/utils/itti_analyzer/libresolver/resolvers.c create mode 100644 common/utils/itti_analyzer/libresolver/resolvers.h create mode 100644 common/utils/itti_analyzer/libui/Makefile.am create mode 100644 common/utils/itti_analyzer/libui/ui_callbacks.c create mode 100644 common/utils/itti_analyzer/libui/ui_callbacks.h create mode 100644 common/utils/itti_analyzer/libui/ui_interface.c create mode 100644 common/utils/itti_analyzer/libui/ui_interface.h create mode 100644 common/utils/itti_analyzer/libui/ui_main_screen.c create mode 100644 common/utils/itti_analyzer/libui/ui_main_screen.h create mode 100644 common/utils/itti_analyzer/libui/ui_menu_bar.c create mode 100644 common/utils/itti_analyzer/libui/ui_menu_bar.h create mode 100644 common/utils/itti_analyzer/libui/ui_notebook.c create mode 100644 common/utils/itti_analyzer/libui/ui_notebook.h create mode 100644 common/utils/itti_analyzer/libui/ui_notifications.c create mode 100644 common/utils/itti_analyzer/libui/ui_notifications.h create mode 100644 common/utils/itti_analyzer/libui/ui_signal_dissect_view.c create mode 100644 common/utils/itti_analyzer/libui/ui_signal_dissect_view.h create mode 100644 common/utils/itti_analyzer/libui/ui_tree_view.c create mode 100644 common/utils/itti_analyzer/libui/ui_tree_view.h create mode 100644 common/utils/itti_analyzer/queue.h create mode 100644 common/utils/itti_analyzer/rc.h diff --git a/common/utils/itti_analyzer/AUTHORS b/common/utils/itti_analyzer/AUTHORS new file mode 100644 index 0000000000..e69de29bb2 diff --git a/common/utils/itti_analyzer/COPYING b/common/utils/itti_analyzer/COPYING new file mode 100644 index 0000000000..94a9ed024d --- /dev/null +++ b/common/utils/itti_analyzer/COPYING @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + 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. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + 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 <http://www.gnu.org/licenses/>. + +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: + + <program> Copyright (C) <year> <name of author> + 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 +<http://www.gnu.org/licenses/>. + + 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 +<http://www.gnu.org/philosophy/why-not-lgpl.html>. diff --git a/common/utils/itti_analyzer/ChangeLog b/common/utils/itti_analyzer/ChangeLog new file mode 100644 index 0000000000..e69de29bb2 diff --git a/common/utils/itti_analyzer/INSTALL b/common/utils/itti_analyzer/INSTALL new file mode 100644 index 0000000000..a1e89e18ad --- /dev/null +++ b/common/utils/itti_analyzer/INSTALL @@ -0,0 +1,370 @@ +Installation Instructions +************************* + +Copyright (C) 1994-1996, 1999-2002, 2004-2011 Free Software Foundation, +Inc. + + Copying and distribution of this file, with or without modification, +are permitted in any medium without royalty provided the copyright +notice and this notice are preserved. This file is offered as-is, +without warranty of any kind. + +Basic Installation +================== + + Briefly, the shell commands `./configure; make; make install' should +configure, build, and install this package. The following +more-detailed instructions are generic; see the `README' file for +instructions specific to this package. Some packages provide this +`INSTALL' file but do not implement all of the features documented +below. The lack of an optional feature in a given package is not +necessarily a bug. More recommendations for GNU packages can be found +in *note Makefile Conventions: (standards)Makefile Conventions. + + The `configure' shell script attempts to guess correct values for +various system-dependent variables used during compilation. It uses +those values to create a `Makefile' in each directory of the package. +It may also create one or more `.h' files containing system-dependent +definitions. Finally, it creates a shell script `config.status' that +you can run in the future to recreate the current configuration, and a +file `config.log' containing compiler output (useful mainly for +debugging `configure'). + + It can also use an optional file (typically called `config.cache' +and enabled with `--cache-file=config.cache' or simply `-C') that saves +the results of its tests to speed up reconfiguring. Caching is +disabled by default to prevent problems with accidental use of stale +cache files. + + If you need to do unusual things to compile the package, please try +to figure out how `configure' could check whether to do them, and mail +diffs or instructions to the address given in the `README' so they can +be considered for the next release. If you are using the cache, and at +some point `config.cache' contains results you don't want to keep, you +may remove or edit it. + + The file `configure.ac' (or `configure.in') is used to create +`configure' by a program called `autoconf'. You need `configure.ac' if +you want to change it or regenerate `configure' using a newer version +of `autoconf'. + + The simplest way to compile this package is: + + 1. `cd' to the directory containing the package's source code and type + `./configure' to configure the package for your system. + + Running `configure' might take a while. While running, it prints + some messages telling which features it is checking for. + + 2. Type `make' to compile the package. + + 3. Optionally, type `make check' to run any self-tests that come with + the package, generally using the just-built uninstalled binaries. + + 4. Type `make install' to install the programs and any data files and + documentation. When installing into a prefix owned by root, it is + recommended that the package be configured and built as a regular + user, and only the `make install' phase executed with root + privileges. + + 5. Optionally, type `make installcheck' to repeat any self-tests, but + this time using the binaries in their final installed location. + This target does not install anything. Running this target as a + regular user, particularly if the prior `make install' required + root privileges, verifies that the installation completed + correctly. + + 6. You can remove the program binaries and object files from the + source code directory by typing `make clean'. To also remove the + files that `configure' created (so you can compile the package for + a different kind of computer), type `make distclean'. There is + also a `make maintainer-clean' target, but that is intended mainly + for the package's developers. If you use it, you may have to get + all sorts of other programs in order to regenerate files that came + with the distribution. + + 7. Often, you can also type `make uninstall' to remove the installed + files again. In practice, not all packages have tested that + uninstallation works correctly, even though it is required by the + GNU Coding Standards. + + 8. Some packages, particularly those that use Automake, provide `make + distcheck', which can by used by developers to test that all other + targets like `make install' and `make uninstall' work correctly. + This target is generally not run by end users. + +Compilers and Options +===================== + + Some systems require unusual options for compilation or linking that +the `configure' script does not know about. Run `./configure --help' +for details on some of the pertinent environment variables. + + You can give `configure' initial values for configuration parameters +by setting variables in the command line or in the environment. Here +is an example: + + ./configure CC=c99 CFLAGS=-g LIBS=-lposix + + *Note Defining Variables::, for more details. + +Compiling For Multiple Architectures +==================================== + + You can compile the package for more than one kind of computer at the +same time, by placing the object files for each architecture in their +own directory. To do this, you can use GNU `make'. `cd' to the +directory where you want the object files and executables to go and run +the `configure' script. `configure' automatically checks for the +source code in the directory that `configure' is in and in `..'. This +is known as a "VPATH" build. + + With a non-GNU `make', it is safer to compile the package for one +architecture at a time in the source code directory. After you have +installed the package for one architecture, use `make distclean' before +reconfiguring for another architecture. + + On MacOS X 10.5 and later systems, you can create libraries and +executables that work on multiple system types--known as "fat" or +"universal" binaries--by specifying multiple `-arch' options to the +compiler but only a single `-arch' option to the preprocessor. Like +this: + + ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ + CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ + CPP="gcc -E" CXXCPP="g++ -E" + + This is not guaranteed to produce working output in all cases, you +may have to build one architecture at a time and combine the results +using the `lipo' tool if you have problems. + +Installation Names +================== + + By default, `make install' installs the package's commands under +`/usr/local/bin', include files under `/usr/local/include', etc. You +can specify an installation prefix other than `/usr/local' by giving +`configure' the option `--prefix=PREFIX', where PREFIX must be an +absolute file name. + + You can specify separate installation prefixes for +architecture-specific files and architecture-independent files. If you +pass the option `--exec-prefix=PREFIX' to `configure', the package uses +PREFIX as the prefix for installing programs and libraries. +Documentation and other data files still use the regular prefix. + + In addition, if you use an unusual directory layout you can give +options like `--bindir=DIR' to specify different values for particular +kinds of files. Run `configure --help' for a list of the directories +you can set and what kinds of files go in them. In general, the +default for these options is expressed in terms of `${prefix}', so that +specifying just `--prefix' will affect all of the other directory +specifications that were not explicitly provided. + + The most portable way to affect installation locations is to pass the +correct locations to `configure'; however, many packages provide one or +both of the following shortcuts of passing variable assignments to the +`make install' command line to change installation locations without +having to reconfigure or recompile. + + The first method involves providing an override variable for each +affected directory. For example, `make install +prefix=/alternate/directory' will choose an alternate location for all +directory configuration variables that were expressed in terms of +`${prefix}'. Any directories that were specified during `configure', +but not in terms of `${prefix}', must each be overridden at install +time for the entire installation to be relocated. The approach of +makefile variable overrides for each directory variable is required by +the GNU Coding Standards, and ideally causes no recompilation. +However, some platforms have known limitations with the semantics of +shared libraries that end up requiring recompilation when using this +method, particularly noticeable in packages that use GNU Libtool. + + The second method involves providing the `DESTDIR' variable. For +example, `make install DESTDIR=/alternate/directory' will prepend +`/alternate/directory' before all installation names. The approach of +`DESTDIR' overrides is not required by the GNU Coding Standards, and +does not work on platforms that have drive letters. On the other hand, +it does better at avoiding recompilation issues, and works well even +when some directory options were not specified in terms of `${prefix}' +at `configure' time. + +Optional Features +================= + + If the package supports it, you can cause programs to be installed +with an extra prefix or suffix on their names by giving `configure' the +option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. + + Some packages pay attention to `--enable-FEATURE' options to +`configure', where FEATURE indicates an optional part of the package. +They may also pay attention to `--with-PACKAGE' options, where PACKAGE +is something like `gnu-as' or `x' (for the X Window System). The +`README' should mention any `--enable-' and `--with-' options that the +package recognizes. + + For packages that use the X Window System, `configure' can usually +find the X include and library files automatically, but if it doesn't, +you can use the `configure' options `--x-includes=DIR' and +`--x-libraries=DIR' to specify their locations. + + Some packages offer the ability to configure how verbose the +execution of `make' will be. For these packages, running `./configure +--enable-silent-rules' sets the default to minimal output, which can be +overridden with `make V=1'; while running `./configure +--disable-silent-rules' sets the default to verbose, which can be +overridden with `make V=0'. + +Particular systems +================== + + On HP-UX, the default C compiler is not ANSI C compatible. If GNU +CC is not installed, it is recommended to use the following options in +order to use an ANSI C compiler: + + ./configure CC="cc -Ae -D_XOPEN_SOURCE=500" + +and if that doesn't work, install pre-built binaries of GCC for HP-UX. + + HP-UX `make' updates targets which have the same time stamps as +their prerequisites, which makes it generally unusable when shipped +generated files such as `configure' are involved. Use GNU `make' +instead. + + On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot +parse its `<wchar.h>' header file. The option `-nodtk' can be used as +a workaround. If GNU CC is not installed, it is therefore recommended +to try + + ./configure CC="cc" + +and if that doesn't work, try + + ./configure CC="cc -nodtk" + + On Solaris, don't put `/usr/ucb' early in your `PATH'. This +directory contains several dysfunctional programs; working variants of +these programs are available in `/usr/bin'. So, if you need `/usr/ucb' +in your `PATH', put it _after_ `/usr/bin'. + + On Haiku, software installed for all users goes in `/boot/common', +not `/usr/local'. It is recommended to use the following options: + + ./configure --prefix=/boot/common + +Specifying the System Type +========================== + + There may be some features `configure' cannot figure out +automatically, but needs to determine by the type of machine the package +will run on. Usually, assuming the package is built to be run on the +_same_ architectures, `configure' can figure that out, but if it prints +a message saying it cannot guess the machine type, give it the +`--build=TYPE' option. TYPE can either be a short name for the system +type, such as `sun4', or a canonical name which has the form: + + CPU-COMPANY-SYSTEM + +where SYSTEM can have one of these forms: + + OS + KERNEL-OS + + See the file `config.sub' for the possible values of each field. If +`config.sub' isn't included in this package, then this package doesn't +need to know the machine type. + + If you are _building_ compiler tools for cross-compiling, you should +use the option `--target=TYPE' to select the type of system they will +produce code for. + + If you want to _use_ a cross compiler, that generates code for a +platform different from the build platform, you should specify the +"host" platform (i.e., that on which the generated programs will +eventually be run) with `--host=TYPE'. + +Sharing Defaults +================ + + If you want to set default values for `configure' scripts to share, +you can create a site shell script called `config.site' that gives +default values for variables like `CC', `cache_file', and `prefix'. +`configure' looks for `PREFIX/share/config.site' if it exists, then +`PREFIX/etc/config.site' if it exists. Or, you can set the +`CONFIG_SITE' environment variable to the location of the site script. +A warning: not all `configure' scripts look for a site script. + +Defining Variables +================== + + Variables not defined in a site shell script can be set in the +environment passed to `configure'. However, some packages may run +configure again during the build, and the customized values of these +variables may be lost. In order to avoid this problem, you should set +them in the `configure' command line, using `VAR=value'. For example: + + ./configure CC=/usr/local2/bin/gcc + +causes the specified `gcc' to be used as the C compiler (unless it is +overridden in the site shell script). + +Unfortunately, this technique does not work for `CONFIG_SHELL' due to +an Autoconf bug. Until the bug is fixed you can use this workaround: + + CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash + +`configure' Invocation +====================== + + `configure' recognizes the following options to control how it +operates. + +`--help' +`-h' + Print a summary of all of the options to `configure', and exit. + +`--help=short' +`--help=recursive' + Print a summary of the options unique to this package's + `configure', and exit. The `short' variant lists options used + only in the top level, while the `recursive' variant lists options + also present in any nested packages. + +`--version' +`-V' + Print the version of Autoconf used to generate the `configure' + script, and exit. + +`--cache-file=FILE' + Enable the cache: use and save the results of the tests in FILE, + traditionally `config.cache'. FILE defaults to `/dev/null' to + disable caching. + +`--config-cache' +`-C' + Alias for `--cache-file=config.cache'. + +`--quiet' +`--silent' +`-q' + Do not print messages saying which checks are being made. To + suppress all normal output, redirect it to `/dev/null' (any error + messages will still be shown). + +`--srcdir=DIR' + Look for the package's source code in directory DIR. Usually + `configure' can determine that directory automatically. + +`--prefix=DIR' + Use DIR as the installation prefix. *note Installation Names:: + for more details, including other options available for fine-tuning + the installation locations. + +`--no-create' +`-n' + Run the configure checks, but stop before creating any output + files. + +`configure' also accepts some other, not widely useful, options. Run +`configure --help' for more details. + diff --git a/common/utils/itti_analyzer/Makefile.am b/common/utils/itti_analyzer/Makefile.am new file mode 100644 index 0000000000..6fa0fe69b0 --- /dev/null +++ b/common/utils/itti_analyzer/Makefile.am @@ -0,0 +1,16 @@ +AM_CFLAGS = \ + @ADD_CFLAGS@ \ + -I$(top_srcdir)/libparser \ + -I$(top_srcdir)/libresolver \ + -I$(top_srcdir)/libbuffers \ + -I$(top_srcdir)/libui + +SUBDIRS = libparser libresolver libbuffers libui . + +itti_analyzer_LDADD = \ + $(top_builddir)/libui/libui.la \ + $(top_builddir)/libparser/libparser.la \ + $(top_builddir)/libresolver/libresolver.la \ + $(top_builddir)/libbuffers/libbuffers.la + +bin_PROGRAMS = itti_analyzer diff --git a/common/utils/itti_analyzer/NEWS b/common/utils/itti_analyzer/NEWS new file mode 100644 index 0000000000..e69de29bb2 diff --git a/common/utils/itti_analyzer/README b/common/utils/itti_analyzer/README new file mode 100644 index 0000000000..e69de29bb2 diff --git a/common/utils/itti_analyzer/autogen.sh b/common/utils/itti_analyzer/autogen.sh new file mode 100755 index 0000000000..6d08b67921 --- /dev/null +++ b/common/utils/itti_analyzer/autogen.sh @@ -0,0 +1,6 @@ +#! /bin/sh + +aclocal \ +&& autoheader \ +&& automake --add-missing \ +&& autoconf \ No newline at end of file diff --git a/common/utils/itti_analyzer/configure.ac b/common/utils/itti_analyzer/configure.ac new file mode 100644 index 0000000000..72f542f82d --- /dev/null +++ b/common/utils/itti_analyzer/configure.ac @@ -0,0 +1,93 @@ +AC_PREREQ([2.68]) + +define([svnversion], esyscmd([sh -c "svnversion ..|tr -d '\n'"])) + +AC_DEFINE(SVN_REVISION, "svnversion", [SVN Revision]) + +AC_INIT([itti_debugger], [0.1.svnversion], [openair_admin@eurecom.fr]) +AC_CANONICAL_BUILD +AC_CANONICAL_TARGET +AM_INIT_AUTOMAKE([1.11 silent-rules]) + +AC_CONFIG_MACRO_DIR([m4]) + +AC_CONFIG_HEADERS([config.h]) + +AM_MAINTAINER_MODE + +AM_SILENT_RULES([yes]) + +AM_PROG_LIBTOOL + +AC_PROG_RANLIB +AC_PROG_CXX + +AC_FUNC_ALLOCA +AC_FUNC_MALLOC +AC_FUNC_REALLOC + +AC_TYPE_SIZE_T +AC_TYPE_SSIZE_T +AC_TYPE_INT8_T +AC_TYPE_INT16_T +AC_TYPE_INT32_T +AC_TYPE_INT64_T +AC_TYPE_UINT8_T +AC_TYPE_UINT16_T +AC_TYPE_UINT32_T +AC_TYPE_UINT64_T + +AC_CHECK_FUNCS([memset]) +AC_CHECK_FUNCS([socket]) +AC_CHECK_FUNCS([strdup]) +AC_CHECK_FUNCS([strerror]) + +AC_CHECK_HEADERS([arpa/inet.h]) +AC_CHECK_HEADERS([fcntl.h]) +AC_CHECK_HEADERS([libintl.h]) +AC_CHECK_HEADERS([malloc.h]) +AC_CHECK_HEADERS([stddef.h]) +AC_CHECK_HEADERS([netinet/in.h]) + +PKG_CHECK_MODULES(XML2, [libxml-2.0 >= 2.7.8], [HAVE_XML2=true], [AC_MSG_ERROR(lixml-2.0 not installed)]) +CFLAGS="$CFLAGS $XML2_CFLAGS" +LIBS="$LIBS $XML2_LIBS" + +AM_PATH_GTK_3_0(3.0.0, [], AC_MSG_ERROR(Requirement not met: gtk >= 3.0.0)) +CFLAGS="$CFLAGS $GTK_CFLAGS" +LIBS="$LIBS $GTK_LIBS" + +dnl Add these flags +CFLAGS="$CFLAGS -Wall" +CFLAGS="$CFLAGS -Wshadow" +CFLAGS="$CFLAGS -Wcast-align" +CFLAGS="$CFLAGS -Wchar-subscripts" +CFLAGS="$CFLAGS -Wmissing-prototypes" +CFLAGS="$CFLAGS -Wmissing-declarations" +CFLAGS="$CFLAGS -Werror=implicit-function-declaration" + +AC_SUBST([AM_CFLAGS]) +AC_SUBST(ADD_CFLAGS) + +dnl *** Autoconf support *** +AC_ARG_ENABLE(autoconf, + [ --disable-autoconf disable automatic generation of configure script ], + enable_autoconf=$enableval, enable_autoconf=yes +) +AC_PATH_PROG(AUTOCONF, autoconf, @echo autoconf not available) +AC_PATH_PROG(AUTOHEADER, autoheader, @echo autoheader not available) +if test -z "$AUTOCONF"; then enable_autoconf=no ; fi +if test -z "$AUTOHEADER"; then enable_autoconf=no ; fi +if test x$enable_autoconf = xyes; then + CONFIGURE_DEPENDS="configure.in aclocal.m4" +fi +AC_SUBST(CONFIGURE_DEPENDS) + +AC_CONFIG_FILES( + libbuffers/Makefile \ + libparser/Makefile \ + libresolver/Makefile \ + libui/Makefile \ + Makefile \ +) +AC_OUTPUT \ No newline at end of file diff --git a/common/utils/itti_analyzer/itti_analyzer.c b/common/utils/itti_analyzer/itti_analyzer.c new file mode 100644 index 0000000000..31a0faaba3 --- /dev/null +++ b/common/utils/itti_analyzer/itti_analyzer.c @@ -0,0 +1,26 @@ +#include <stdlib.h> +#include <stdio.h> +#include <errno.h> +#include <string.h> + +#include <gtk/gtk.h> + +#include "xml_parse.h" +#include "resolvers.h" +#include "locate_root.h" +#include "file.h" +#include "ui_main_screen.h" + +#include "rc.h" + +int debug_buffers = 1; +int debug_parser = 0; + +int main(int argc, char *argv[]) +{ + int ret = 0; + + CHECK_FCT(ui_gtk_initialize(argc, argv)); + + return ret; +} diff --git a/common/utils/itti_analyzer/libbuffers/Makefile.am b/common/utils/itti_analyzer/libbuffers/Makefile.am new file mode 100644 index 0000000000..3a54bd3c38 --- /dev/null +++ b/common/utils/itti_analyzer/libbuffers/Makefile.am @@ -0,0 +1,13 @@ +AM_CFLAGS = \ + @ADD_CFLAGS@ \ + -I$(top_srcdir) \ + -I$(top_srcdir)/libparser \ + -I$(top_srcdir)/libui + +noinst_LTLIBRARIES = libbuffers.la + +libbuffers_la_LDFLAGS = -all-static +libbuffers_la_SOURCES = \ + buffers.c buffers.h \ + file.c file.h \ + socket.c socket.h diff --git a/common/utils/itti_analyzer/libbuffers/buffers.c b/common/utils/itti_analyzer/libbuffers/buffers.c new file mode 100644 index 0000000000..1d7ad911b4 --- /dev/null +++ b/common/utils/itti_analyzer/libbuffers/buffers.c @@ -0,0 +1,242 @@ +#include <pthread.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "../rc.h" +#include "buffers.h" + +extern int debug_buffers; + +buffer_list_t list = { + .head = NULL, + .tail = NULL, + .count = 0, +}; +pthread_mutex_t buffer_list_mutex = PTHREAD_MUTEX_INITIALIZER; + +static +int buffer_fetch(buffer_t *buffer, uint32_t offset, int size, void *value); + +/* Try to fetch 8 bits unsigned from the buffer */ +uint8_t buffer_get_uint8_t(buffer_t *buffer, uint32_t offset) +{ + uint8_t value; + + buffer_fetch(buffer, offset, 1, &value); + + return value; +} + +/* Try to fetch 16 bits unsigned from the buffer */ +uint16_t buffer_get_uint16_t(buffer_t *buffer, uint32_t offset) +{ + uint16_t value; + + buffer_fetch(buffer, offset, 2, &value); + + return value; +} + +/* Try to fetch 32 bits unsigned from the buffer */ +uint32_t buffer_get_uint32_t(buffer_t *buffer, uint32_t offset) +{ + uint32_t value; + + buffer_fetch(buffer, offset, 4, &value); + + return value; +} + +static +int buffer_fetch(buffer_t *buffer, uint32_t offset, int size, void *value) +{ + if (buffer == NULL || value == NULL) + return -1; + if (size <= 0) + return -1; + + if (buffer->size_bytes < ((offset >> 3) + size)) { + printf("Not enough data to fetch\n"); + return -1; + } + + memcpy(value, &buffer->data[offset >> 3], size); + buffer->buffer_current = &buffer->data[(offset >> 3) + size]; + + return 0; +} + +int buffer_fetch_bits(buffer_t *buffer, uint32_t offset, int nbits, uint32_t *value) +{ + uint32_t temp = 0; + int i; + + if (buffer == NULL || value == NULL) + return RC_BAD_PARAM; + + /* We cannot fetch more than 32 bits */ + if (nbits > 32) + return RC_BAD_PARAM; + + for (i = 0; i < nbits; i++) + { + temp |= ((buffer->data[(offset + i) / 8] >> ((offset + i) % 8)) & 1) << i; + } + + *value = temp; + + return RC_OK; +} + +/** + * @brief Create a new buffer from data + * @param buffer caller reference where created buffer will be stored + * @param data Data to attach to the new buffer + * @param length Length of data buffer + * @param data_static flag that indicates if data pointer has been statically (= 0) or not (!= 0) + */ +int buffer_new_from_data(buffer_t **buffer, uint8_t *data, const uint32_t length, + int data_static) +{ + buffer_t *new; + + if (!buffer) + return RC_BAD_PARAM; + + new = malloc(sizeof(buffer_t)); + + new->size_bytes = length; + if (data && length > 0) { + if (data_static == 0) { + new->data = malloc(sizeof(uint8_t) * new->size_bytes); + memcpy(new->data, data, new->size_bytes); + } else { + new->data = data; + } + new->buffer_current = &new->data[0]; + } else { + new->buffer_current = NULL; + } + + new->next = NULL; + + *buffer = new; + + return 0; +} + +#define INDENTED(fILE, x, y) \ +do { \ + int indentation = x; \ + while(indentation--) fprintf(fILE, " "); \ + y; \ +} while(0) + +#define INDENT_BREAK 20 + +void buffer_dump(buffer_t *buffer, FILE *to) +{ + FILE *file = to; + uint32_t i; + + if (!buffer) + return; + if (!to) + to = stdout; + + fprintf(file, "<Buffer>\n"); + INDENTED(file, 4, fprintf(file, "<Length>%u<Length>\n", buffer->size_bytes)); + INDENTED(file, 4, fprintf(file, "<Bytes>\n")); + for (i = 0; i < buffer->size_bytes; i++) + { + if ((i % INDENT_BREAK) == 0) + fprintf(file, " "); + fprintf(file, "0x%02x ", buffer->data[i]); + if ((i % INDENT_BREAK) == (INDENT_BREAK - 1)) + fprintf(file, "\n"); + } + if ((i % INDENT_BREAK) != (INDENT_BREAK - 1)) + fprintf(file, "\n"); + INDENTED(file, 4, fprintf(file, "</Bytes>\n")); + fprintf(file, "</Buffer>\n"); +} + +int buffer_append_data(buffer_t *buffer, const uint8_t *data, const uint32_t length) +{ + if (!buffer) + return -1; + + if (data && length > 0) { + if (!buffer->data) { + buffer->size_bytes = length; + buffer->data = malloc(sizeof(uint8_t) * buffer->size_bytes); + memcpy(buffer->data, data, buffer->size_bytes); + } else { + buffer->data = realloc(buffer->data, sizeof(uint8_t) * (buffer->size_bytes + length)); + memcpy(&buffer->data[buffer->size_bytes], data, length); + buffer->size_bytes += length; + } + buffer->buffer_current = &buffer->data[0]; + } + + return 0; +} + +int buffer_has_enouch_data(buffer_t *buffer, uint32_t offset, uint32_t to_get) +{ + int underflow; + if (!buffer) + return -1; + underflow = (buffer->size_bytes >= ((offset + to_get) / 8)) ? 0 : -1; + if (underflow && debug_buffers) + printf("Detected Underflow offset %u, to_get %u, buffer size %u\n", + offset, to_get, buffer->size_bytes); + return underflow; +} + +int buffer_get_from_mn(const uint32_t message_number, buffer_t **buffer) +{ + buffer_t *temp_buf; + + if (!buffer) + return RC_BAD_PARAM; + + for (temp_buf = list.head; temp_buf; temp_buf = temp_buf->next) { + if (temp_buf->message_number == message_number) { + break; + } + } + + *buffer = temp_buf; + + return RC_OK; +} + +int buffer_add_to_list(buffer_t *new_buf) +{ + if (!new_buf) + return RC_BAD_PARAM; + + pthread_mutex_lock(&buffer_list_mutex); + + /* No element at tail */ + if (list.tail == NULL) { + if (list.head == NULL) { + list.head = new_buf; + list.tail = list.head; + } else { + return RC_FAIL; + } + } else { + list.tail->next = new_buf; + new_buf->previous = list.tail; + list.tail = new_buf; + } + + list.count++; + + pthread_mutex_unlock(&buffer_list_mutex); + + return RC_OK; +} diff --git a/common/utils/itti_analyzer/libbuffers/buffers.h b/common/utils/itti_analyzer/libbuffers/buffers.h new file mode 100644 index 0000000000..4bffc1543c --- /dev/null +++ b/common/utils/itti_analyzer/libbuffers/buffers.h @@ -0,0 +1,53 @@ +#include <stdint.h> + +#ifndef BUFFERS_H_ +#define BUFFERS_H_ + +typedef struct buffer_s { + /* The size in bytes as read from socket */ + uint32_t size_bytes; + + /* Current position */ + uint8_t *buffer_current; + + /* The complete data */ + uint8_t *data; + + /* The message number as read from socket */ + uint32_t message_number; + + uint32_t message_id; + + struct buffer_s *previous; + struct buffer_s *next; +} buffer_t; + +typedef struct { + buffer_t *head; + buffer_t *tail; + + uint32_t count; +} buffer_list_t; + +uint8_t buffer_get_uint8_t(buffer_t *buffer, uint32_t offset); + +uint16_t buffer_get_uint16_t(buffer_t *buffer, uint32_t offset); + +uint32_t buffer_get_uint32_t(buffer_t *buffer, uint32_t offset); + +int buffer_fetch_bits(buffer_t *buffer, uint32_t offset, int nbits, uint32_t *value); + +void buffer_dump(buffer_t *buffer, FILE *to); + +int buffer_append_data(buffer_t *buffer, const uint8_t *data, const uint32_t length); + +int buffer_new_from_data(buffer_t **buffer, uint8_t *data, const uint32_t length, + int data_static); + +int buffer_has_enouch_data(buffer_t *buffer, uint32_t offset, uint32_t to_get); + +int buffer_add_to_list(buffer_t *new_buf); + +int buffer_get_from_mn(const uint32_t message_number, buffer_t **buffer); + +#endif /* BUFFERS_H_ */ diff --git a/common/utils/itti_analyzer/libbuffers/file.c b/common/utils/itti_analyzer/libbuffers/file.c new file mode 100644 index 0000000000..6106e9719f --- /dev/null +++ b/common/utils/itti_analyzer/libbuffers/file.c @@ -0,0 +1,50 @@ +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <unistd.h> +#include <sys/stat.h> +#include <fcntl.h> + +#include "../rc.h" +#include "buffers.h" +#include "file.h" + +#define READ_BUFFER_SIZE 1024 + +int file_read_dump(buffer_t **buffer, const char *filename) +{ + int fd = -1; + buffer_t *new_buf = NULL; + uint8_t data[READ_BUFFER_SIZE]; + ssize_t current_read; + + if (!filename) + return RC_BAD_PARAM; + + if ((fd = open(filename, O_RDONLY)) == -1) { + fprintf(stderr, "Cannot open %s for reading, returned %d:%s\n", + filename, errno, strerror(errno)); + return RC_FAIL; + } + + CHECK_FCT(buffer_new_from_data(&new_buf, NULL, 0, 0)); + + do { + current_read = read(fd, data, READ_BUFFER_SIZE); + if (current_read == -1) + { + fprintf(stderr, "Failed to read data from file, returned %d:%s\n", + errno, strerror(errno)); + return RC_FAIL; + } + CHECK_FCT(buffer_append_data(new_buf, data, current_read)); + } while(current_read == READ_BUFFER_SIZE); + + *buffer = new_buf; + + buffer_dump(new_buf, stdout); + + close(fd); + + return RC_OK; +} diff --git a/common/utils/itti_analyzer/libbuffers/file.h b/common/utils/itti_analyzer/libbuffers/file.h new file mode 100644 index 0000000000..8dc4b141cc --- /dev/null +++ b/common/utils/itti_analyzer/libbuffers/file.h @@ -0,0 +1,6 @@ +#ifndef FILE_H_ +#define FILE_H_ + +int file_read_dump(buffer_t **buffer, const char *filename); + +#endif /* FILE_H_ */ diff --git a/common/utils/itti_analyzer/libbuffers/socket.c b/common/utils/itti_analyzer/libbuffers/socket.c new file mode 100644 index 0000000000..f22f71e2e1 --- /dev/null +++ b/common/utils/itti_analyzer/libbuffers/socket.c @@ -0,0 +1,282 @@ +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <string.h> +#include <unistd.h> +#include <errno.h> + +#include <gtk/gtk.h> + +#include "../rc.h" + +#include "ui_interface.h" +#include "ui_notifications.h" + +#include "socket.h" +#include "buffers.h" + +#include "xml_parse.h" + +#define BUFFER_SIZE 3000 +#define MAX_ATTEMPTS 10 + +socket_data_t socket_data; + +typedef struct { + char ip_address[16]; + uint16_t port; +} socket_arg_t; + +/* Message header is the common part that should never change between + * remote process and this one. + */ +typedef struct { + /* The size of this structure */ + uint32_t message_size; + uint32_t message_type; +} itti_socket_header_t; + +typedef struct { + uint32_t message_number; + char signal_name[50]; +} itti_dump_message_t; + +void *socket_read_data(void *arg); + +void *socket_read_data(void *arg) +{ + int ret; + int attempts = MAX_ATTEMPTS; + int *sd = &socket_data.sd; + struct sockaddr_in *si_me = &socket_data.si_me; + socket_arg_t *socket_arg; + + socket_arg = (socket_arg_t *)arg; + + memset(&socket_data, 0, sizeof(socket_data_t)); + + /* Enable the cancel attribute for the thread. + * Set the cancel type to asynchronous. The thread termination is requested + * to happen now. + */ + pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + + *sd = -1; + + if ((*sd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) { + fprintf(stderr, "socket failed\n"); + goto fail; + } + memset((void *)si_me, 0, sizeof(si_me)); + + si_me->sin_family = AF_INET; + si_me->sin_port = htons(socket_arg->port); + if (inet_aton(socket_arg->ip_address, &si_me->sin_addr) == 0) { + fprintf(stderr, "inet_aton() failed\n"); + goto fail; + } + + do { + ret = connect(*sd, (struct sockaddr *)si_me, sizeof(struct sockaddr_in)); + if (ret == 0) { + break; + } + attempts --; + sleep(1); + if (attempts == 0) { + printf("Cannot connect to %s with port %u:\n" + "Reached maximum retry count\nEnsure host is alive", + socket_arg->ip_address, socket_arg->port); + /* ????? */ + ui_interface.ui_notification_dialog( + DIALOG_ERROR, "Cannot connect to %s with port %u:\n" + "Reached maximum retry count\nEnsure host is alive", + socket_arg->ip_address, socket_arg->port); + ui_interface.ui_enable_connect_button(); + + pthread_exit(NULL); + } + } while(ret != 0); + + while(1) { + uint8_t *data; + size_t data_length; + itti_socket_header_t message_header; + int recv_ret; + buffer_t *buffer; + + memset(&message_header, 0, sizeof(itti_socket_header_t)); + + /* First run acquire message header + * TODO: check for remote endianness when retrieving the structure... + */ + recv_ret = recvfrom(socket_data.sd, &message_header, sizeof(itti_socket_header_t), MSG_WAITALL, NULL, 0); + if (recv_ret == -1) { + /* Failure case */ + fprintf(stderr, "recvfrom failed\n"); + ui_interface.ui_notification_dialog( + DIALOG_ERROR, "Unexpected error while reading from socket\n%d:%s", + errno, strerror(errno)); + ui_interface.ui_enable_connect_button(); + pthread_exit(NULL); + } else if (recv_ret == 0) { + /* We lost the connection with other peer or shutdown asked */ + ui_interface.ui_notification_dialog( + DIALOG_ERROR, "Connection with remote host has been lost"); + ui_interface.ui_enable_connect_button(); + pthread_exit(NULL); + } + + switch(message_header.message_type) { + case 1: { + itti_dump_message_t itti_dump_header; + + memset(&itti_dump_header, 0, sizeof(itti_dump_message_t)); + + /* second run: acquire the sub-header for itti dump message type */ + recv_ret = recvfrom(socket_data.sd, &itti_dump_header, sizeof(itti_dump_message_t), MSG_WAITALL, NULL, 0); + if (recv_ret == -1) { + /* Failure case */ + fprintf(stderr, "recvfrom failed\n"); + ui_interface.ui_notification_dialog( + DIALOG_ERROR, "Unexpected error while reading from socket\n%d:%s", + errno, strerror(errno)); + ui_interface.ui_enable_connect_button(); + pthread_exit(NULL); + } else if (recv_ret == 0) { + /* We lost the connection with other peer or shutdown asked */ + ui_interface.ui_notification_dialog( + DIALOG_ERROR, "Connection with remote host has been lost"); + ui_interface.ui_enable_connect_button(); + pthread_exit(NULL); + } + + data_length = message_header.message_size - sizeof(itti_socket_header_t) - sizeof(itti_dump_message_t); + data = malloc(sizeof(uint8_t) * data_length); + + /* third run: acquire the MessageDef part */ + recv_ret = recvfrom(socket_data.sd, data, data_length, MSG_WAITALL, NULL, 0); + if (recv_ret == -1) { + /* Failure case */ + fprintf(stderr, "recvfrom failed\n"); + ui_interface.ui_notification_dialog( + DIALOG_ERROR, "Unexpected error while reading from socket\n%d:%s", + errno, strerror(errno)); + ui_interface.ui_enable_connect_button(); + pthread_exit(NULL); + } else if (recv_ret == 0) { + /* We lost the connection with other peer or shutdown asked */ + ui_interface.ui_notification_dialog( + DIALOG_ERROR, "Connection with remote host has been lost"); + ui_interface.ui_enable_connect_button(); + pthread_exit(NULL); + } + + /* Create the new buffer */ + if (buffer_new_from_data(&buffer, data, data_length, 1) != RC_OK) { + ui_interface.ui_notification_dialog( + DIALOG_ERROR, "Cannot connect to %s with port %u", + socket_arg->ip_address, socket_arg->port); + ui_interface.ui_enable_connect_button(); + pthread_exit(NULL); + } + + buffer->message_number = itti_dump_header.message_number; + buffer_dump(buffer, stdout); + + CHECK_FCT_DO(buffer_add_to_list(buffer), pthread_exit(NULL)); + + ui_interface.ui_tree_view_new_signal_ind(itti_dump_header.message_number, + itti_dump_header.signal_name); + } break; + case 2: + /* The received message is a statistic signal */ + break; + case 3: { + char *xml_definition; + uint32_t xml_definition_length; + + xml_definition_length = message_header.message_size - sizeof(message_header); + + xml_definition = malloc(xml_definition_length); + + recv_ret = recvfrom(socket_data.sd, xml_definition, xml_definition_length, MSG_WAITALL, NULL, 0); + if (recv_ret == -1) { + /* Failure case */ + fprintf(stderr, "recvfrom failed\n"); + ui_interface.ui_notification_dialog( + DIALOG_ERROR, "Unexpected error while reading from socket\n%d:%s", + errno, strerror(errno)); + ui_interface.ui_enable_connect_button(); + pthread_exit(NULL); + } else if (recv_ret == 0) { + /* We lost the connection with other peer or shutdown asked */ + ui_interface.ui_notification_dialog( + DIALOG_ERROR, "Connection with remote host has been lost"); + ui_interface.ui_enable_connect_button(); + pthread_exit(NULL); + } + + fprintf(stdout, "Received XML definition of length %u\n", + xml_definition_length); + + xml_parse_buffer(xml_definition, xml_definition_length); + } break; + default: + ui_interface.ui_notification_dialog( + DIALOG_ERROR, "Received unknown message type\n"); + break; + } + } + + return NULL; + +fail: + ui_interface.ui_notification_dialog( + DIALOG_ERROR, "Cannot connect to %s with port %u", + socket_arg->ip_address, socket_arg->port); + ui_interface.ui_enable_connect_button(); + pthread_exit(NULL); +} + +int socket_disconnect_from_remote_host(void) +{ + void *ret_val; + + printf("Closing socket %d\n", socket_data.sd); + + /* Cancel the thread */ + pthread_cancel(socket_data.thread); + pthread_join(socket_data.thread, &ret_val); + + /* Send shutdown to remote host */ + CHECK_FCT_POSIX(shutdown(socket_data.sd, SHUT_RDWR)); + CHECK_FCT_POSIX(close(socket_data.sd)); + + socket_data.sd = -1; + ui_interface.ui_enable_connect_button(); + + return RC_OK; +} + +int socket_connect_to_remote_host(const char *remote_ip, const uint16_t port) +{ + socket_arg_t *socket_arg; + + socket_arg = malloc(sizeof(socket_arg_t)); + + ui_interface.ui_disable_connect_button(); + + memcpy(socket_arg->ip_address, remote_ip, strlen(remote_ip) + 1); + socket_arg->port = port; + + if (pthread_create(&socket_data.thread, NULL, socket_read_data, socket_arg) != 0) { + fprintf(stderr, "pthread_create failed\n"); + ui_interface.ui_enable_connect_button(); + return RC_FAIL; + } + + return RC_OK; +} diff --git a/common/utils/itti_analyzer/libbuffers/socket.h b/common/utils/itti_analyzer/libbuffers/socket.h new file mode 100644 index 0000000000..05a14491c4 --- /dev/null +++ b/common/utils/itti_analyzer/libbuffers/socket.h @@ -0,0 +1,19 @@ +#include <arpa/inet.h> +#include <netinet/in.h> + +#ifndef SOCKET_H_ +#define SOCKET_H_ + +typedef struct { + pthread_t thread; + uint16_t port; + char *remote_ip; + int sd; + struct sockaddr_in si_me; +} socket_data_t; + +int socket_connect_to_remote_host(const char *remote_ip, const uint16_t port); + +int socket_disconnect_from_remote_host(void); + +#endif /* SOCKET_H_ */ diff --git a/common/utils/itti_analyzer/libparser/Makefile.am b/common/utils/itti_analyzer/libparser/Makefile.am new file mode 100644 index 0000000000..cb975b6ce2 --- /dev/null +++ b/common/utils/itti_analyzer/libparser/Makefile.am @@ -0,0 +1,23 @@ +AM_CFLAGS = \ + @ADD_CFLAGS@ \ + -I$(top_srcdir) \ + -I$(top_srcdir)/libbuffers \ + -I$(top_srcdir)/libui + +noinst_LTLIBRARIES = libparser.la + +libparser_la_LDFLAGS = -all-static +libparser_la_SOURCES = \ + xml_parse.c \ + array_type.c array_type.h \ + enum_type.c enum_type.h \ + enum_value_type.c enum_value_type.h \ + file_type.c file_type.h \ + field_type.c field_type.h \ + fundamental_type.c fundamental_type.h \ + pointer_type.h pointer_type.c \ + reference_type.c reference_type.h \ + struct_type.c struct_type.h \ + typedef_type.c typedef_type.h \ + types.h types.c \ + union_type.c union_type.h diff --git a/common/utils/itti_analyzer/libparser/array_type.c b/common/utils/itti_analyzer/libparser/array_type.c new file mode 100644 index 0000000000..139e5889df --- /dev/null +++ b/common/utils/itti_analyzer/libparser/array_type.c @@ -0,0 +1,113 @@ +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> +#include <string.h> + +#include "array_type.h" +#include "fundamental_type.h" +#include "ui_interface.h" + +int array_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset, + int indent) { + struct types_s *type_child; + + DISPLAY_PARSE_INFO("array", type->name, offset, parent_offset); + + /* Ignore TYPEDEF children */ + for (type_child = type->child; type_child != NULL && type_child->type == TYPE_TYPEDEF; + type_child = type_child->child) { + } + + if (type->name) { + INDENTED(stdout, indent, fprintf(stdout, "<%s>\n", type->name)); + } + if (type->child != NULL) { + int items = type->size / type_child->size; + int i; + int zero_counter = 0; + + /* Factorizes trailing 0 */ + if ((items > 1) && (type_child->type == TYPE_FUNDAMENTAL)) + { + for (i = items - 1; i >= 0; i--) + { + if (fundamental_read_from_buffer(type_child, buffer, parent_offset, offset + i * type_child->size) == 0) + { + zero_counter ++; + } + else + { + break; + } + } + /* Do not factorize if there is only one item */ + if (zero_counter <= 1) + { + zero_counter = 0; + } + } + for (i = 0; i < (items - zero_counter); i++) + type->child->type_dissect_from_buffer (type->child, buffer, parent_offset, offset + i * type_child->size, + type->name == NULL ? indent : indent + 4); + if (zero_counter > 0) + { + int length = 0; + char cbuf[50]; + char *cpy = NULL; + + INDENTED_STRING(cbuf, type->name == NULL ? indent : indent + 4,); + + length = sprintf(cbuf, "[%d .. %d] ", i, items -1); + cpy = malloc(sizeof(char) * length); + memcpy(cpy, cbuf, length); + ui_interface.ui_signal_set_text(cpy, length); + if (cpy) + free(cpy); + + type->child->type_dissect_from_buffer (type->child, buffer, parent_offset, offset + i * type_child->size, 0); + } + } + if (type->name) { + INDENTED(stdout, indent, fprintf(stdout, "</%s>\n", type->name)); + } + + return 0; +} + +int array_type_file_print(struct types_s *type, int indent, FILE *file) { + if (type == NULL) + return -1; + INDENTED(file, indent, fprintf(file, "<Array>\n")); + INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id)); + INDENTED(file, indent+4, fprintf(file, "Min ........: %d\n", type->min)); + INDENTED(file, indent+4, fprintf(file, "Max ........: %d\n", type->max)); + INDENTED(file, indent+4, fprintf(file, "Type .......: %d\n", type->type_xml)); + INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size)); + INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align)); + if (type->file_ref != NULL) + type->file_ref->type_file_print (type->file_ref, indent + 4, file); + if (type->child != NULL) + type->child->type_file_print (type->child, indent + 4, file); + INDENTED(file, indent, fprintf(file, "</Array>\n")); + + return 0; +} + +int array_type_hr_display(struct types_s *type, int indent) { + if (type == NULL) + return -1; + INDENTED(stdout, indent, printf("<Array>\n")); + INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id)); + INDENTED(stdout, indent+4, printf("Min ........: %d\n", type->min)); + INDENTED(stdout, indent+4, printf("Max ........: %d\n", type->max)); + INDENTED(stdout, indent+4, printf("Type .......: %d\n", type->type_xml)); + INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size)); + INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align)); + if (type->file_ref != NULL) + type->file_ref->type_hr_display (type->file_ref, indent + 4); + if (type->child != NULL) + type->child->type_hr_display (type->child, indent + 4); + INDENTED(stdout, indent, printf("</Array>\n")); + + return 0; +} diff --git a/common/utils/itti_analyzer/libparser/array_type.h b/common/utils/itti_analyzer/libparser/array_type.h new file mode 100644 index 0000000000..e21f279b32 --- /dev/null +++ b/common/utils/itti_analyzer/libparser/array_type.h @@ -0,0 +1,13 @@ +#include "types.h" + +#ifndef ARRAY_TYPE_H_ +#define ARRAY_TYPE_H_ + +int array_dissect_from_buffer(struct types_s *type, buffer_t *buffer, + uint32_t offset, uint32_t parent_offset, int indent); + +int array_type_hr_display(struct types_s *type, int indent); + +int array_type_file_print(struct types_s *type, int indent, FILE *file); + +#endif /* ARRAY_TYPE_H_ */ diff --git a/common/utils/itti_analyzer/libparser/enum_type.c b/common/utils/itti_analyzer/libparser/enum_type.c new file mode 100644 index 0000000000..2ea2bf7832 --- /dev/null +++ b/common/utils/itti_analyzer/libparser/enum_type.c @@ -0,0 +1,97 @@ +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> +#include <string.h> + +#include "enum_type.h" +#include "ui_interface.h" + +int enum_type_dissect_from_buffer( + struct types_s *type, buffer_t *buffer, uint32_t offset, + uint32_t parent_offset, int indent) +{ + uint32_t value = 0; + types_t *values; + + DISPLAY_PARSE_INFO("enum", type->name, offset, parent_offset); + + value = buffer_get_uint32_t(buffer, parent_offset + offset); + +// if (type->name) { +// INDENTED(stdout, indent, fprintf(stdout, "<%s>\n", type->name)); +// } + for (values = type->child; values; values = values->next) { + if (value == values->init_value) { + values->type_dissect_from_buffer( + values, buffer, offset, parent_offset, + type->name == NULL ? indent: indent+4); + break; + } + } + if (values == NULL) { +// INDENTED(stdout, indent+4, fprintf(stdout, "<UNKNOWN/>\n")); + int length = 0; + char cbuf[50]; + char *cpy = NULL; + + length = sprintf(cbuf, "(0x%08x) UNKNOWN;\n", value); + cpy = malloc(sizeof(char) * length); + memcpy(cpy, cbuf, length); + ui_interface.ui_signal_set_text(cpy, length); + if (cpy) + free(cpy); + } +// if (type->name) { +// INDENTED(stdout, indent, fprintf(stdout, "</%s>\n", type->name)); +// } + + return 0; +} + +int enum_type_file_print(struct types_s *type, int indent, FILE *file) +{ + types_t *values; + + if (type == NULL) + return -1; + INDENTED(file, indent, fprintf(file, "<Enumeration>\n")); + INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name)); + INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size)); + INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align)); + INDENTED(file, indent+4, fprintf(file, "Artificial .: %d\n", type->artificial)); + INDENTED(file, indent+4, fprintf(file, "File .......: %s\n", type->file)); + INDENTED(file, indent+4, fprintf(file, "Line .......: %d\n", type->line)); + if (type->file_ref != NULL) + type->file_ref->type_file_print(type->file_ref, indent+4, file); + /* Call enum values display */ + for (values = type->child; values; values = values->next) { + values->type_file_print(values, indent + 4, file); + } + INDENTED(file, indent, fprintf(file, "</Enumeration>\n")); + + return 0; +} + +int enum_type_hr_display(struct types_s *type, int indent) +{ + types_t *values; + + if (type == NULL) + return -1; + INDENTED(stdout, indent, printf("<Enumeration>\n")); + INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name)); + INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size)); + INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align)); + INDENTED(stdout, indent+4, printf("Artificial .: %d\n", type->artificial)); + INDENTED(stdout, indent+4, printf("File .......: %s\n", type->file)); + INDENTED(stdout, indent+4, printf("Line .......: %d\n", type->line)); + if (type->file_ref != NULL) + type->file_ref->type_hr_display(type->file_ref, indent+4); + /* Call enum values display */ + for (values = type->child; values; values = values->next) { + values->type_hr_display(values, indent + 4); + } + INDENTED(stdout, indent, printf("</Enumeration>\n")); + + return 0; +} diff --git a/common/utils/itti_analyzer/libparser/enum_type.h b/common/utils/itti_analyzer/libparser/enum_type.h new file mode 100644 index 0000000000..7544d78660 --- /dev/null +++ b/common/utils/itti_analyzer/libparser/enum_type.h @@ -0,0 +1,14 @@ +#include "types.h" + +#ifndef ENUM_TYPE_H_ +#define ENUM_TYPE_H_ + +int enum_type_dissect_from_buffer( + struct types_s *type, buffer_t *buffer, uint32_t offset, + uint32_t parent_offset, int indent); + +int enum_type_file_print(struct types_s *type, int indent, FILE *file); + +int enum_type_hr_display(struct types_s *type, int indent); + +#endif /* ENUM_TYPE_H_ */ diff --git a/common/utils/itti_analyzer/libparser/enum_value_type.c b/common/utils/itti_analyzer/libparser/enum_value_type.c new file mode 100644 index 0000000000..e4f0a38f64 --- /dev/null +++ b/common/utils/itti_analyzer/libparser/enum_value_type.c @@ -0,0 +1,61 @@ +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> +#include <string.h> + +#include "enum_value_type.h" +#include "ui_interface.h" + +int enum_value_dissect_from_buffer( + struct types_s *type, buffer_t *buffer, uint32_t offset, + uint32_t parent_offset, int indent) +{ + uint32_t value = 0; + + DISPLAY_PARSE_INFO("enum_value", type->name, offset, parent_offset); + + value = buffer_get_uint32_t(buffer, parent_offset + offset); + if (type->name) { + int length = 0; + char cbuf[50 + strlen(type->name)]; + char *cpy = NULL; + + sprintf(cbuf, "(0x%08x) %s;\n", value, type->name); + length = strlen(cbuf); + cpy = malloc(sizeof(char) * length); + memcpy(cpy, cbuf, length); + ui_interface.ui_signal_set_text(cpy, length); + if (cpy) + free(cpy); + } + + return 0; +} + +int enum_value_file_print(struct types_s *type, int indent, FILE *file) +{ + if (type == NULL) + return -1; + INDENTED(file, indent, fprintf(file, "<Value>\n")); + INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name)); + INDENTED(file, indent+4, fprintf(file, "Value ......: %d\n", type->init_value)); + if (type->file_ref != NULL) + type->file_ref->type_file_print(type->file_ref, indent+4, file); + INDENTED(file, indent, fprintf(file, "</Value>\n")); + + return 0; +} + +int enum_value_type_hr_display(struct types_s *type, int indent) +{ + if (type == NULL) + return -1; + INDENTED(stdout, indent, printf("<Value>\n")); + INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name)); + INDENTED(stdout, indent+4, printf("Value ......: %d\n", type->init_value)); + if (type->file_ref != NULL) + type->file_ref->type_hr_display(type->file_ref, indent+4); + INDENTED(stdout, indent, printf("</Value>\n")); + + return 0; +} diff --git a/common/utils/itti_analyzer/libparser/enum_value_type.h b/common/utils/itti_analyzer/libparser/enum_value_type.h new file mode 100644 index 0000000000..3aad409edb --- /dev/null +++ b/common/utils/itti_analyzer/libparser/enum_value_type.h @@ -0,0 +1,14 @@ +#include "types.h" + +#ifndef ENUM_VALUE_TYPE_H_ +#define ENUM_VALUE_TYPE_H_ + +int enum_value_dissect_from_buffer( + struct types_s *type, buffer_t *buffer, uint32_t offset, + uint32_t parent_offset, int indent); + +int enum_value_file_print(struct types_s *type, int indent, FILE *file); + +int enum_value_type_hr_display(struct types_s *type, int indent); + +#endif /* ENUM_VALUE_TYPE_H_ */ diff --git a/common/utils/itti_analyzer/libparser/field_type.c b/common/utils/itti_analyzer/libparser/field_type.c new file mode 100644 index 0000000000..8434540cd6 --- /dev/null +++ b/common/utils/itti_analyzer/libparser/field_type.c @@ -0,0 +1,143 @@ +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> +#include <string.h> + +#include "../rc.h" + +#include "field_type.h" +#include "buffers.h" +#include "ui_interface.h" + +int field_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset, + int indent) { + int length = 0; + char cbuf[50]; + char *cpy = NULL; + struct types_s *type_child; + char array_info[50]; + int indent_child; + + DISPLAY_PARSE_INFO("field", type->name, offset, parent_offset); + + CHECK_FCT(buffer_has_enouch_data(buffer, parent_offset + offset, type->size / 8)); + + if (type->bits == -1) { + if (type->child != NULL) { + /* Ignore TYPEDEF children */ + for (type_child = type->child; type_child != NULL && type_child->type == TYPE_TYPEDEF; type_child = + type_child->child) { + } + + if (type_child->type == TYPE_ARRAY) { + struct types_s *type_array_child; + + /* Ignore TYPEDEF children */ + for (type_array_child = type_child->child; + type_array_child != NULL && type_array_child->type == TYPE_TYPEDEF; type_array_child = + type_array_child->child) { + } + + sprintf (array_info, "[%d]", type_child->size / type_array_child->size); + } + else { + array_info[0] = '\0'; + } + + DISPLAY_TYPE("Fld"); + INDENTED_STRING(cbuf, indent, sprintf(cbuf, ".%s%s = ", type->name ? type->name : "Field", array_info)); + length = strlen (cbuf); + cpy = malloc (sizeof(char) * length); + memcpy (cpy, cbuf, length); + ui_interface.ui_signal_set_text (cpy, length); + if (cpy) + free (cpy); + + indent_child = indent; + if (type_child->type == TYPE_ARRAY || type_child->type == TYPE_STRUCT || type_child->type == TYPE_UNION) { + DISPLAY_BRACE(ui_interface.ui_signal_set_text ("{", 1);) + ui_interface.ui_signal_set_text ("\n", 1); + indent_child += 4; + } + if (type_child->type == TYPE_FUNDAMENTAL || type_child->type == TYPE_POINTER) { + indent_child = 0; + } + + CHECK_FCT( + type->child->type_dissect_from_buffer( type->child, buffer, parent_offset, offset + type->offset, indent_child)); + + DISPLAY_BRACE( + if (type_child->type == TYPE_ARRAY || type_child->type == TYPE_STRUCT || type_child->type == TYPE_UNION) { + DISPLAY_TYPE("Fld"); + INDENTED_STRING(cbuf, indent, sprintf(cbuf, "};\n")); + length = strlen (cbuf); + cpy = malloc (sizeof(char) * length); memcpy (cpy, cbuf, length); + ui_interface.ui_signal_set_text (cpy, length); + if (cpy) + free (cpy); + }); + } + } + else { + /* The field is only composed of bits */ + uint32_t value = 0; + + CHECK_FCT(buffer_fetch_bits(buffer, offset + type->offset + parent_offset, type->bits, &value)); + + DISPLAY_TYPE("Fld"); + INDENTED_STRING( + cbuf, + indent, + sprintf(cbuf, ".%s:%d = (0x%0*x) %d;\n", type->name ? type->name : "Field", type->bits, (type->bits + 3) / 4, value, value)); + length = strlen (cbuf); + cpy = malloc (sizeof(char) * length); + memcpy (cpy, cbuf, length); + ui_interface.ui_signal_set_text (cpy, length); + if (cpy) + free (cpy); + } + + return 0; +} + +int field_type_file_print(struct types_s *type, int indent, FILE *file) { + if (type == NULL) + return -1; + INDENTED(file, indent, fprintf(file, "<Field>\n")); + INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id)); + INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name)); + INDENTED(file, indent+4, fprintf(file, "Bits .......: %d\n", type->bits)); + INDENTED(file, indent+4, fprintf(file, "Type .......: %d\n", type->type_xml)); + INDENTED(file, indent+4, fprintf(file, "Offset .....: %d\n", type->offset)); + INDENTED(file, indent+4, fprintf(file, "Context ....: %d\n", type->context)); + INDENTED(file, indent+4, fprintf(file, "File .......: %s\n", type->file)); + INDENTED(file, indent+4, fprintf(file, "Line .......: %d\n", type->line)); + if (type->file_ref != NULL) + type->file_ref->type_file_print (type->file_ref, indent + 4, file); + if (type->child != NULL) + type->child->type_file_print (type->child, indent + 4, file); + INDENTED(file, indent, fprintf(file, "</Field>\n")); + + return 0; +} + +int field_type_hr_display(struct types_s *type, int indent) { + if (type == NULL) + return -1; + INDENTED(stdout, indent, printf("<Field>\n")); + INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id)); + INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name)); + INDENTED(stdout, indent+4, printf("Bits .......: %d\n", type->bits)); + INDENTED(stdout, indent+4, printf("Type .......: %d\n", type->type_xml)); + INDENTED(stdout, indent+4, printf("Offset .....: %d\n", type->offset)); + INDENTED(stdout, indent+4, printf("Context ....: %d\n", type->context)); + INDENTED(stdout, indent+4, printf("File .......: %s\n", type->file)); + INDENTED(stdout, indent+4, printf("Line .......: %d\n", type->line)); + if (type->file_ref != NULL) + type->file_ref->type_hr_display (type->file_ref, indent + 4); + if (type->child != NULL) + type->child->type_hr_display (type->child, indent + 4); + INDENTED(stdout, indent, printf("</Field>\n")); + + return 0; +} diff --git a/common/utils/itti_analyzer/libparser/field_type.h b/common/utils/itti_analyzer/libparser/field_type.h new file mode 100644 index 0000000000..dcbbc8c206 --- /dev/null +++ b/common/utils/itti_analyzer/libparser/field_type.h @@ -0,0 +1,13 @@ +#include "types.h" + +#ifndef FIELD_TYPE_H_ +#define FIELD_TYPE_H_ + +int field_dissect_from_buffer(struct types_s *type, buffer_t *buffer, + uint32_t offset, uint32_t parent_offset, int indent); + +int field_type_file_print(struct types_s *type, int indent, FILE *file); + +int field_type_hr_display(struct types_s *type, int indent); + +#endif /* FIELD_TYPE_H_ */ diff --git a/common/utils/itti_analyzer/libparser/file_type.c b/common/utils/itti_analyzer/libparser/file_type.c new file mode 100644 index 0000000000..36db678f20 --- /dev/null +++ b/common/utils/itti_analyzer/libparser/file_type.c @@ -0,0 +1,30 @@ +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> +#include <string.h> + +#include "file_type.h" + +int file_type_file_print(struct types_s *type, int indent, FILE *file) +{ + if (type == NULL) + return -1; + INDENTED(file, indent, fprintf(file, "<File>\n")); + INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id)); + INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name)); + INDENTED(file, indent, fprintf(file, "</File>\n")); + + return 0; +} + +int file_type_hr_display(struct types_s *type, int indent) +{ + if (type == NULL) + return -1; + INDENTED(stdout, indent, printf("<File>\n")); + INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id)); + INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name)); + INDENTED(stdout, indent, printf("</File>\n")); + + return 0; +} diff --git a/common/utils/itti_analyzer/libparser/file_type.h b/common/utils/itti_analyzer/libparser/file_type.h new file mode 100644 index 0000000000..a2ad0cc460 --- /dev/null +++ b/common/utils/itti_analyzer/libparser/file_type.h @@ -0,0 +1,10 @@ +#include "types.h" + +#ifndef FILE_TYPE_H_ +#define FILE_TYPE_H_ + +int file_type_file_print(struct types_s *type, int indent, FILE *file); + +int file_type_hr_display(struct types_s *type, int indent); + +#endif /* FILE_TYPE_H_ */ diff --git a/common/utils/itti_analyzer/libparser/fundamental_type.c b/common/utils/itti_analyzer/libparser/fundamental_type.c new file mode 100644 index 0000000000..8442fa0eaa --- /dev/null +++ b/common/utils/itti_analyzer/libparser/fundamental_type.c @@ -0,0 +1,111 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <ctype.h> + +#include "fundamental_type.h" +#include "ui_interface.h" + +uint32_t fundamental_read_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset) { + uint32_t value; + + switch (type->size) { + case 8: { + value = buffer_get_uint8_t (buffer, offset + parent_offset); + } + break; + case 16: { + value = buffer_get_uint16_t (buffer, offset + parent_offset); + } + break; + case 32: { + value = buffer_get_uint32_t (buffer, offset + parent_offset); + } + break; + default: + /* ??? */ + value = 0; + break; + } + return value; +} + +int fundamental_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset, + int indent) { + int length = 0; + char cbuf[200]; + char *cpy = NULL; + int type_unsigned; + uint32_t value; + + DISPLAY_PARSE_INFO("fundamental", type->name, offset, parent_offset); + + memset (cbuf, 0, 200); + + type_unsigned = strstr (type->name, "unsigned") == NULL ? 0 : 1; + + value = fundamental_read_from_buffer(type, buffer, offset, parent_offset); + + if (indent > 0) + { + DISPLAY_TYPE("Fun"); + } + switch (type->size) { + case 8: { + INDENTED_STRING(cbuf, indent, + sprintf(cbuf, type_unsigned ? "(0x%02x) %3u '%c';\n" : "(0x%02x) %4d '%c';\n", value, value, isprint(value) ? value : '.')); + } + break; + case 16: { + INDENTED_STRING(cbuf, indent, + sprintf(cbuf, type_unsigned ? "(0x%04x) %5u;\n" : "(0x%04x) %6d;\n", value, value)); + } + break; + case 32: { + INDENTED_STRING(cbuf, indent, + sprintf(cbuf, type_unsigned ? "(0x%08x) %9u;\n" : "(0x%08x) %10d;\n", value, value)); + } + break; + default: + /* ??? */ + break; + } + + length = strlen (cbuf); + cpy = malloc (length * sizeof(char)); + memcpy (cpy, cbuf, length); + ui_interface.ui_signal_set_text (cpy, length); + + if (cpy) + free (cpy); + + return 0; +} + +int fundamental_type_file_print(struct types_s *type, int indent, FILE *file) { + if (type == NULL) + return -1; + INDENTED(file, indent, fprintf(file, "<Fundamental>\n")); + INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name)); + INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id)); + INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size)); + INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align)); + if (type->file_ref != NULL) + type->file_ref->type_file_print (type->file_ref, indent + 4, file); + INDENTED(file, indent, fprintf(file, "</Fundamental>\n")); + return 0; +} + +int fundamental_type_hr_display(struct types_s *type, int indent) { + if (type == NULL) + return -1; + INDENTED(stdout, indent, printf("<Fundamental>\n")); + INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name)); + INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id)); + INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size)); + INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align)); + if (type->file_ref != NULL) + type->file_ref->type_hr_display (type->file_ref, indent + 4); + INDENTED(stdout, indent, printf("</Fundamental>\n")); + return 0; +} diff --git a/common/utils/itti_analyzer/libparser/fundamental_type.h b/common/utils/itti_analyzer/libparser/fundamental_type.h new file mode 100644 index 0000000000..710ce6dad8 --- /dev/null +++ b/common/utils/itti_analyzer/libparser/fundamental_type.h @@ -0,0 +1,15 @@ +#include "types.h" + +#ifndef FUNDAMENTAL_TYPE_H_ +#define FUNDAMENTAL_TYPE_H_ + +uint32_t fundamental_read_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset); + +int fundamental_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset, + int indent); + +int fundamental_type_file_print(struct types_s *type, int indent, FILE *file); + +int fundamental_type_hr_display(struct types_s *type, int indent); + +#endif /* FUNDAMENTAL_TYPE_H_ */ diff --git a/common/utils/itti_analyzer/libparser/intertask_contexts.h b/common/utils/itti_analyzer/libparser/intertask_contexts.h new file mode 100644 index 0000000000..0968d8f6aa --- /dev/null +++ b/common/utils/itti_analyzer/libparser/intertask_contexts.h @@ -0,0 +1,14 @@ +#include "fundamental_type.h" +#include "struct_type.h" + +#ifndef INTERTASK_CONTEXTS_H_ +#define INTERTASK_CONTEXTS_H_ + +typedef struct { + /* List of fundamental types that can contruct any other type */ + fundamental_type_t *ft_list; + + struct_type_t *struct_list; +} intertask_context_t; + +#endif /* INTERTASK_CONTEXTS_H_ */ diff --git a/common/utils/itti_analyzer/libparser/parser.y b/common/utils/itti_analyzer/libparser/parser.y new file mode 100644 index 0000000000..dcdd9927d1 --- /dev/null +++ b/common/utils/itti_analyzer/libparser/parser.y @@ -0,0 +1,181 @@ +/* For development only : */ +%debug +%error-verbose + +/* Keep track of location */ +%locations +%defines +%pure-parser + +%{ +#include <stdlib.h> +#include <stdio.h> +#include <errno.h> + +#include "parser.h" + +int +yyerror(const char *msg); + +extern int yywrap(); +extern int yylex(); + +extern int yylineno; + +/* The Lex parser prototype */ +int fddlex(YYSTYPE *lvalp, YYLTYPE *llocp); +%} + +/* Values returned by lex for token */ +%union { + char *string; /* The string is allocated by strdup in lex.*/ + int integer; /* Store integer values */ +} + +%token LEX_ERROR + +%token <string> QSTRING +%token <string> STRING +%token <integer> INTEGER +%token Y_TYPEDEF +%token Y_STRUCT +%token Y_UNION +%token Y_CHARTYPE +%token Y_SHORTTYPE +%token Y_INTTYPE +%token Y_LONGTYPE +%token Y_ENUM +%token Y_UNSIGNED +%token Y_SIGNED +%token Y_EXTENSION +%token Y_ATTRIBUTE +%token Y_ATTRIBUTE_MODE +%token Y_ATTRIBUTE_HI +%token Y_ATTRIBUTE_SI +%token Y_VOIDTYPE +%token Y_POINTER +%token Y_SIZEOF + +%% +messages: + | messages definition + | messages errors + { + yyerror("An error occurred while parsing the configuration file"); + return EINVAL; + } + ; + +definition: + | Y_EXTENSION definition + | Y_TYPEDEF enumerate + | Y_TYPEDEF structure + | structure + | enumerate + | Y_STRUCT STRING ';' + | Y_TYPEDEF singletype attribute ';' + ; + +enumerate: + | Y_ENUM '{' enumlist '}' STRING ';' + | Y_ENUM STRING '{' enumlist '}' ';' + | Y_ENUM STRING '{' enumlist '}' STRING ';' + ; + +enumlist: + | enumitem ',' enumlist + | enumitem + ; + +enumitem: STRING '=' INTEGER + | STRING '=' STRING + | STRING + ; + +structure: Y_STRUCT STRING '{' paramlist '}' STRING ';' + | Y_STRUCT '{' paramlist '}' STRING ';' + | Y_STRUCT STRING '{' paramlist '}' ';' + | Y_STRUCT STRING ';' + | Y_STRUCT STRING STRING attribute ';' + | Y_STRUCT singletype ';' + ; + +paramlist: + | paramlist singletype ';' + | paramlist union + | paramlist structure + ; + +union: Y_UNION STRING '{' paramlist '}' STRING ';' + | Y_UNION '{' paramlist '}' STRING ';' + | Y_UNION STRING '{' paramlist '}' ';' + ; + +singletype: + | Y_SIGNED singletype + | Y_UNSIGNED singletype + | STRING STRING + | Y_CHARTYPE STRING + | Y_SHORTTYPE STRING + | Y_INTTYPE STRING + | Y_SHORTTYPE Y_INTTYPE STRING + | Y_LONGTYPE STRING + | Y_LONGTYPE Y_INTTYPE STRING + | Y_LONGTYPE Y_LONGTYPE Y_INTTYPE STRING + | Y_VOIDTYPE Y_POINTER STRING + | Y_VOIDTYPE STRING + | STRING Y_POINTER STRING + | basictype Y_POINTER STRING + | singletype '[' arraydef ']' + | structure + ; + +arraydef: + | INTEGER arraydef + | '*' arraydef + | Y_POINTER arraydef + | Y_SIZEOF arraydef + | '(' arraydef + | ')' arraydef + | basictype arraydef + | '-' arraydef + | STRING arraydef + ; + +attribute: + | Y_ATTRIBUTE '(' attributevalue ')' + ; + +attributevalue: + | '(' Y_ATTRIBUTE_MODE attributeparam ')' + | Y_ATTRIBUTE_MODE attributeparam + ; + +attributeparam: + | '(' Y_ATTRIBUTE_HI ')' + | '(' Y_ATTRIBUTE_SI ')' + ; + +basictype: + | Y_CHARTYPE + | Y_SHORTTYPE + | Y_INTTYPE + | Y_LONGTYPE + | Y_VOIDTYPE + ; + + /* Lexical or syntax error */ +errors: LEX_ERROR + | error + ; + +%% + +int +yyerror(const char *msg) { + extern char *yytext; + fprintf(stderr, + "Parse error near line %d (token \"%s\"): %s\n", + yylineno, yytext, msg); + return -1; +} diff --git a/common/utils/itti_analyzer/libparser/pointer_type.c b/common/utils/itti_analyzer/libparser/pointer_type.c new file mode 100644 index 0000000000..27b695b7f4 --- /dev/null +++ b/common/utils/itti_analyzer/libparser/pointer_type.c @@ -0,0 +1,84 @@ +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> +#include <string.h> + +#include "pointer_type.h" +#include "ui_interface.h" + +int pointer_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset, + int indent) { + int length = 0; + char cbuf[200]; + char *cpy = NULL; + + DISPLAY_PARSE_INFO("pointer", type->name, offset, parent_offset); + + memset (cbuf, 0, 200); + +// int i; +// CHECK_FCT(buffer_has_enouch_data(buffer, offset, type->size / 8)); + uint32_t value; + + value = buffer_get_uint32_t (buffer, parent_offset + offset); + + DISPLAY_TYPE("Ptr"); + if (type->child->name) { + /* + INDENTED(stdout, indent, fprintf(stdout, "<%s>0x%08x</%s>\n", + type->child->name, value, type->child->name)); + */ + INDENTED_STRING(cbuf, indent, sprintf(cbuf, "(%s *) 0x%08x;\n", type->child->name, value)); + } + else { + /* + INDENTED(stdout, indent, fprintf(stdout, "<Pointer>0x%08x</Pointer>\n", + value)); + */ + INDENTED_STRING(cbuf, indent, sprintf(cbuf, "(void *) 0x%08x;\n", value)); + } + + length = strlen (cbuf); + cpy = malloc (length * sizeof(char)); + memcpy (cpy, cbuf, length); + ui_interface.ui_signal_set_text (cpy, length); + + if (cpy) + free (cpy); + + return 0; +} + +int pointer_type_file_print(struct types_s *type, int indent, FILE *file) { + if (type == NULL) + return -1; + INDENTED(file, indent, fprintf(file, "<Pointer>\n")); + INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id)); + INDENTED(file, indent+4, fprintf(file, "Type .......: %d\n", type->type_xml)); + INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size)); + INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align)); + if (type->child != NULL) + type->child->type_file_print (type->child, indent + 4, file); + if (type->file_ref != NULL) + type->file_ref->type_file_print (type->file_ref, indent + 4, file); + INDENTED(file, indent, fprintf(file, "</Pointer>\n")); + + return 0; +} + +int pointer_type_hr_display(struct types_s *type, int indent) { + if (type == NULL) + return -1; + INDENTED(stdout, indent, printf("<Pointer>\n")); + INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id)); + INDENTED(stdout, indent+4, printf("Type .......: %d\n", type->type_xml)); + INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size)); + INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align)); + if (type->child != NULL) + type->child->type_hr_display (type->child, indent + 4); + if (type->file_ref != NULL) + type->file_ref->type_hr_display (type->file_ref, indent + 4); + INDENTED(stdout, indent, printf("</Pointer>\n")); + + return 0; +} diff --git a/common/utils/itti_analyzer/libparser/pointer_type.h b/common/utils/itti_analyzer/libparser/pointer_type.h new file mode 100644 index 0000000000..b0d76f981f --- /dev/null +++ b/common/utils/itti_analyzer/libparser/pointer_type.h @@ -0,0 +1,13 @@ +#include "types.h" + +#ifndef POINTER_TYPE_H_ +#define POINTER_TYPE_H_ + +int pointer_dissect_from_buffer(struct types_s *type, buffer_t *buffer, + uint32_t offset, uint32_t parent_offset, int indent); + +int pointer_type_file_print(struct types_s *type, int indent, FILE *file); + +int pointer_type_hr_display(struct types_s *type, int indent); + +#endif /* POINTER_TYPE_H_ */ diff --git a/common/utils/itti_analyzer/libparser/reference_type.c b/common/utils/itti_analyzer/libparser/reference_type.c new file mode 100644 index 0000000000..82e3257227 --- /dev/null +++ b/common/utils/itti_analyzer/libparser/reference_type.c @@ -0,0 +1,71 @@ +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> +#include <string.h> + +#include "reference_type.h" +#include "ui_interface.h" + +int reference_dissect_from_buffer(struct types_s *type, buffer_t *buffer, + uint32_t offset, uint32_t parent_offset, int indent) +{ + DISPLAY_PARSE_INFO("reference", type->name, offset, parent_offset); + + if (type->name) { + INDENTED(stdout, indent, fprintf(stdout, "<%s>\n", type->name)); + } + if (type->child != NULL) + type->child->type_dissect_from_buffer(type->child, buffer, offset, parent_offset, + type->name == NULL ? indent: indent+4); + if (type->name) { + INDENTED(stdout, indent, fprintf(stdout, "</%s>\n", type->name)); + } + + return 0; +} + +int reference_type_file_print(struct types_s *type, int indent, FILE *file) +{ + if (type == NULL) + return -1; + INDENTED(file, indent, fprintf(file, "<Reference>\n")); + INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name)); + INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id)); + INDENTED(file, indent+4, fprintf(file, "Type .......: %d\n", type->type_xml)); + INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size)); + INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align)); + INDENTED(file, indent+4, fprintf(file, "Context ....: %d\n", type->context)); + INDENTED(file, indent+4, fprintf(file, "Offset .....: %d\n", type->offset)); + INDENTED(file, indent+4, fprintf(file, "Line .......: %d\n", type->line)); + INDENTED(file, indent+4, fprintf(file, "File .......: %s\n", type->file)); + if (type->child != NULL) + type->child->type_file_print(type->child, indent+4, file); + if (type->file_ref != NULL) + type->file_ref->type_file_print(type->file_ref, indent+4, file); + INDENTED(file, indent, fprintf(file, "</Reference>\n")); + + return 0; +} + +int reference_type_hr_display(struct types_s *type, int indent) +{ + if (type == NULL) + return -1; + INDENTED(stdout, indent, printf("<Reference>\n")); + INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name)); + INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id)); + INDENTED(stdout, indent+4, printf("Type .......: %d\n", type->type_xml)); + INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size)); + INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align)); + INDENTED(stdout, indent+4, printf("Context ....: %d\n", type->context)); + INDENTED(stdout, indent+4, printf("Offset .....: %d\n", type->offset)); + INDENTED(stdout, indent+4, printf("Line .......: %d\n", type->line)); + INDENTED(stdout, indent+4, printf("File .......: %s\n", type->file)); + if (type->child != NULL) + type->child->type_hr_display(type->child, indent+4); + if (type->file_ref != NULL) + type->file_ref->type_hr_display(type->file_ref, indent+4); + INDENTED(stdout, indent, printf("</Reference>\n")); + + return 0; +} diff --git a/common/utils/itti_analyzer/libparser/reference_type.h b/common/utils/itti_analyzer/libparser/reference_type.h new file mode 100644 index 0000000000..245bd024f6 --- /dev/null +++ b/common/utils/itti_analyzer/libparser/reference_type.h @@ -0,0 +1,13 @@ +#include "types.h" + +#ifndef REFERENCE_TYPE_H_ +#define REFERENCE_TYPE_H_ + +int reference_dissect_from_buffer(struct types_s *type, buffer_t *buffer, + uint32_t offset, uint32_t parent_offset, int indent); + +int reference_type_file_print(struct types_s *type, int indent, FILE *file); + +int reference_type_hr_display(struct types_s *type, int indent); + +#endif /* REFERENCE_TYPE_H_ */ diff --git a/common/utils/itti_analyzer/libparser/scanner.l b/common/utils/itti_analyzer/libparser/scanner.l new file mode 100644 index 0000000000..02d2b9c5df --- /dev/null +++ b/common/utils/itti_analyzer/libparser/scanner.l @@ -0,0 +1,123 @@ + +/* Lex configuration parser. + * + * This file defines the token for parsing the configuration file + * + * Note : This module is NOT thread-safe. All processing must be done from one thread only. + */ +%{ +#include <stdio.h> + +/* Include yacc tokens definitions */ +#include "parser.h" + +/* Update the column information */ +#ifdef DEBUG_LEX +#define YY_USER_ACTION { \ + yylloc->first_column = yylloc->last_column + 1; \ + yylloc->last_column = yylloc->first_column + yyleng - 1; \ + TRACE_DEBUG(FULL, \ + "(%d:%d-%d:%d) matched rule %d, length=%d, txt='%s'\n", \ + yylloc->first_line, yylloc->first_column, \ + yylloc->last_line, yylloc->last_column, \ + yy_act, yyleng, yytext); \ +} +#else /* DEBUG_LEX */ +#define YY_USER_ACTION { \ + yylloc->first_column = yylloc->last_column + 1; \ + yylloc->last_column = yylloc->first_column + yyleng - 1; \ +} +#endif + +#define YY_NO_INPUT +%} + +%option bison-bridge bison-locations +%option noyywrap +%option nounput +%option yylineno + +/* Quoted string. Multilines do not match. */ +qstring \"[^\"\n]*\" + +%% + + /* List of patterns and actions */ + +<*>\n { + /* Update the line count */ + yylloc->first_line++; + yylloc->last_line++; + yylloc->last_column=0; +} + +<*>([[:space:]]{-}[\n])+ ; /* Eat all spaces, not new lines */ +<*>#.*$ ; /* Eat all comments */ + + /* Full words tokens (keywords) */ +(?i:"typedef") { return Y_TYPEDEF; } +(?i:"struct") { return Y_STRUCT; } +(?i:"union") { return Y_UNION; } +(?i:"enum") { return Y_ENUM; } +(?i:"signed") { return Y_SIGNED; } +(?i:"unsigned") { return Y_UNSIGNED; } +(?i:"short") { return Y_SHORTTYPE; } +(?i:"char") { return Y_CHARTYPE; } +(?i:"int") { return Y_INTTYPE; } +(?i:"long") { return Y_LONGTYPE; } +(?i:"void") { return Y_VOIDTYPE; } +(?i:"__extension__") { return Y_EXTENSION; } +(?i:"__attribute__") { return Y_ATTRIBUTE; } +(?i:"__mode__") { return Y_ATTRIBUTE_MODE; } +(?i:"__HI__") { return Y_ATTRIBUTE_HI; } +(?i:"__SI__") { return Y_ATTRIBUTE_SI; } +(?i:"sizeof") { return Y_SIZEOF; } + +[A-Za-z_][A-Za-z0-9_]* { + /* First copy the string without the quotes for use in the yacc parser */ + if ((yylval->string = strdup(yytext+1)) == NULL) { /* This allocates one useless tail char but... it's easier :D */ + return LEX_ERROR;/* on error, trig an error in yacc parser */ + } + yylval->string[yyleng-2] = '\0'; + + /* the yacc parser will check the string is valid */ + return STRING; +} + +{qstring} { + /* First copy the string without the quotes for use in the yacc parser */ + if ((yylval->string = strdup(yytext+1)) == NULL) { /* This allocates one useless tail char but... it's easier :D */ + return LEX_ERROR;/* on error, trig an error in yacc parser */ + } + yylval->string[yyleng-2] = '\0'; + + /* the yacc parser will check the string is valid */ + return QSTRING; +} + +[[:digit:]]+ { + /* Convert this to an integer value */ + int ret = sscanf(yytext, "%i", &yylval->integer); + if (ret != 1) { + /* No matching: an error occurred */ + fprintf(stderr, "Unable to convert the value '%s' to a valid number: %s\n", + yytext, strerror(errno)); + return LEX_ERROR; /* trig an error in yacc parser */ + /* Maybe we could REJECT instead of failing here? */ + } + return INTEGER; +} + + /* Valid single characters for yyparse */ +<*>[\-+=,:;{}\[\]\(\)] { return yytext[0]; } +<*>[*]* { return Y_POINTER; } + +<*>[[:alnum:]]+ | /* This rule is only useful to print a complete token in error messages */ + /* Unrecognized character */ +<*>. { + fprintf(stderr, "Unrecognized text on line %d col %d: '%s'.\n", + yylloc->first_line, yylloc->first_column, yytext); + return LEX_ERROR; +} + +%% diff --git a/common/utils/itti_analyzer/libparser/struct_type.c b/common/utils/itti_analyzer/libparser/struct_type.c new file mode 100644 index 0000000000..03d436ce1e --- /dev/null +++ b/common/utils/itti_analyzer/libparser/struct_type.c @@ -0,0 +1,109 @@ +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> +#include <string.h> + +#include "rc.h" + +#include "struct_type.h" +#include "buffers.h" +#include "ui_interface.h" + +int struct_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset, + int indent) { + int i; + int length = 0; + char cbuf[200]; + char *cpy = NULL; + + DISPLAY_PARSE_INFO("structure", type->name, offset, parent_offset); + + memset (cbuf, 0, 200); + + if (type->name) { + DISPLAY_TYPE("Str"); + INDENTED_STRING(cbuf, indent, sprintf (cbuf, "%s =%s\n", type->name, "" DISPLAY_BRACE(" {"))); + } + + length = strlen (cbuf); + cpy = malloc (length * sizeof(char)); + memcpy (cpy, cbuf, length); + ui_interface.ui_signal_set_text (cpy, length); + + if (cpy) + free (cpy); + + for (i = 0; i < type->nb_members; i++) { + if (type->members_child[i] != NULL) + type->members_child[i]->type_dissect_from_buffer (type->members_child[i], buffer, offset, parent_offset, + type->name == NULL ? indent : indent + 4); + } + + DISPLAY_BRACE( + if (type->name) { + DISPLAY_TYPE("Str"); + INDENTED_STRING(cbuf, indent, sprintf(cbuf, "};\n")); + } + length = strlen (cbuf); + cpy = malloc (length * sizeof(char)); + memcpy (cpy, cbuf, length); + ui_interface.ui_signal_set_text (cpy, length); + if (cpy) + free (cpy);) + + return 0; +} + +int struct_type_file_print(struct types_s *type, int indent, FILE *file) { + int i; + if (type == NULL) + return -1; + if (file == NULL) + return -1; + INDENTED(file, indent, fprintf(file, "<Struct>\n")); + INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name)); + INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id)); + INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size)); + INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align)); + INDENTED(file, indent+4, fprintf(file, "Artificial .: %d\n", type->artificial)); + INDENTED(file, indent+4, fprintf(file, "File .......: %s\n", type->file)); + INDENTED(file, indent+4, fprintf(file, "Line .......: %d\n", type->line)); + INDENTED(file, indent+4, fprintf(file, "Members ....: %s\n", type->members)); + INDENTED(file, indent+4, fprintf(file, "Mangled ....: %s\n", type->mangled)); + INDENTED(file, indent+4, fprintf(file, "Demangled ..: %s\n", type->demangled)); + if (type->file_ref != NULL) + type->file_ref->type_file_print (type->file_ref, indent + 4, file); + for (i = 0; i < type->nb_members; i++) { + if (type->members_child[i] != NULL) + type->members_child[i]->type_file_print (type->members_child[i], indent + 4, file); + } + INDENTED(file, indent, fprintf(file, "</Struct>\n")); + + return 0; +} + +int struct_type_hr_display(struct types_s *type, int indent) { + int i; + if (type == NULL) + return -1; + INDENTED(stdout, indent, printf("<Struct>\n")); + INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name)); + INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id)); + INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size)); + INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align)); + INDENTED(stdout, indent+4, printf("Artificial .: %d\n", type->artificial)); + INDENTED(stdout, indent+4, printf("File .......: %s\n", type->file)); + INDENTED(stdout, indent+4, printf("Line .......: %d\n", type->line)); + INDENTED(stdout, indent+4, printf("Members ....: %s\n", type->members)); + INDENTED(stdout, indent+4, printf("Mangled ....: %s\n", type->mangled)); + INDENTED(stdout, indent+4, printf("Demangled ..: %s\n", type->demangled)); + if (type->file_ref != NULL) + type->file_ref->type_hr_display (type->file_ref, indent + 4); + for (i = 0; i < type->nb_members; i++) { + if (type->members_child[i] != NULL) + type->members_child[i]->type_hr_display (type->members_child[i], indent + 4); + } + INDENTED(stdout, indent, printf("</Struct>\n")); + + return 0; +} diff --git a/common/utils/itti_analyzer/libparser/struct_type.h b/common/utils/itti_analyzer/libparser/struct_type.h new file mode 100644 index 0000000000..c808ef29d0 --- /dev/null +++ b/common/utils/itti_analyzer/libparser/struct_type.h @@ -0,0 +1,13 @@ +#include "types.h" + +#ifndef STRUCT_TYPE_H_ +#define STRUCT_TYPE_H_ + +int struct_dissect_from_buffer(struct types_s *type, buffer_t *buffer, + uint32_t offset, uint32_t parent_offset, int indent); + +int struct_type_hr_display(struct types_s *type, int indent); + +int struct_type_file_print(struct types_s *type, int indent, FILE *file); + +#endif /* STRUCT_TYPE_H_ */ diff --git a/common/utils/itti_analyzer/libparser/typedef_type.c b/common/utils/itti_analyzer/libparser/typedef_type.c new file mode 100644 index 0000000000..7cccda453c --- /dev/null +++ b/common/utils/itti_analyzer/libparser/typedef_type.c @@ -0,0 +1,69 @@ +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> +#include <string.h> + +#include "typedef_type.h" +#include "ui_interface.h" + +int typedef_dissect_from_buffer(struct types_s *type, buffer_t *buffer, + uint32_t offset, uint32_t parent_offset, int indent) +{ + DISPLAY_PARSE_INFO("typedef", type->name, offset, parent_offset); + + /* Simply call next_type */ + if (type->child != NULL) { + type->child->type_dissect_from_buffer( + type->child, buffer, offset, parent_offset, indent); + } + + return 0; +} + +int typedef_type_file_print(struct types_s *type, int indent, FILE *file) +{ + if (type == NULL) + return -1; + INDENTED(file, indent, fprintf(file, "<Typedef>\n")); + INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name)); + INDENTED(file, indent+4, fprintf(file, "Type .......: %d\n", type->type_xml)); + INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size)); + INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align)); + INDENTED(file, indent+4, fprintf(file, "Artificial .: %d\n", type->artificial)); + INDENTED(file, indent+4, fprintf(file, "File .......: %s\n", type->file)); + INDENTED(file, indent+4, fprintf(file, "Line .......: %d\n", type->line)); + INDENTED(file, indent+4, fprintf(file, "Members ....: %s\n", type->members)); + INDENTED(file, indent+4, fprintf(file, "Mangled ....: %s\n", type->mangled)); + INDENTED(file, indent+4, fprintf(file, "Demangled ..: %s\n", type->demangled)); + if (type->file_ref != NULL) + type->file_ref->type_file_print(type->file_ref, indent+4, file); + if (type->child != NULL) + type->child->type_file_print(type->child, indent+4, file); + INDENTED(file, indent, fprintf(file, "</Typedef>\n")); + + return 0; +} + +int typedef_type_hr_display(struct types_s *type, int indent) +{ + if (type == NULL) + return -1; + INDENTED(stdout, indent, printf("<Typedef>\n")); + INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name)); + INDENTED(stdout, indent+4, printf("Type .......: %d\n", type->type_xml)); + INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size)); + INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align)); + INDENTED(stdout, indent+4, printf("Artificial .: %d\n", type->artificial)); + INDENTED(stdout, indent+4, printf("File .......: %s\n", type->file)); + INDENTED(stdout, indent+4, printf("Line .......: %d\n", type->line)); + INDENTED(stdout, indent+4, printf("Members ....: %s\n", type->members)); + INDENTED(stdout, indent+4, printf("Mangled ....: %s\n", type->mangled)); + INDENTED(stdout, indent+4, printf("Demangled ..: %s\n", type->demangled)); + if (type->file_ref != NULL) + type->file_ref->type_hr_display(type->file_ref, indent+4); + if (type->child != NULL) + type->child->type_hr_display(type->child, indent+4); + INDENTED(stdout, indent, printf("</Typedef>\n")); + + return 0; +} diff --git a/common/utils/itti_analyzer/libparser/typedef_type.h b/common/utils/itti_analyzer/libparser/typedef_type.h new file mode 100644 index 0000000000..f9f384cce5 --- /dev/null +++ b/common/utils/itti_analyzer/libparser/typedef_type.h @@ -0,0 +1,13 @@ +#include "types.h" + +#ifndef TYPEDEF_TYPE_H_ +#define TYPEDEF_TYPE_H_ + +int typedef_type_file_print(struct types_s *type, int indent, FILE *file); + +int typedef_type_hr_display(struct types_s *type, int indent); + +int typedef_dissect_from_buffer(struct types_s *type, buffer_t *buffer, + uint32_t offset, uint32_t parent_offset, int indent); + +#endif /* TYPEDEF_TYPE_H_ */ diff --git a/common/utils/itti_analyzer/libparser/types.c b/common/utils/itti_analyzer/libparser/types.c new file mode 100644 index 0000000000..e30bfb5161 --- /dev/null +++ b/common/utils/itti_analyzer/libparser/types.c @@ -0,0 +1,123 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "types.h" +#include "array_type.h" +#include "enum_type.h" +#include "fundamental_type.h" +#include "struct_type.h" +#include "union_type.h" +#include "typedef_type.h" +#include "enum_value_type.h" +#include "file_type.h" +#include "field_type.h" +#include "reference_type.h" +#include "pointer_type.h" + +types_t *type_new(enum type_e type) +{ + types_t *new_p; + + new_p = malloc(sizeof(types_t)); + + memset(new_p, 0, sizeof(types_t)); + + new_p->type = type; + + switch(type) { + case TYPE_ENUMERATION: + new_p->type_hr_display = enum_type_hr_display; + new_p->type_file_print = enum_type_file_print; + new_p->type_dissect_from_buffer = enum_type_dissect_from_buffer; + break; + case TYPE_FUNDAMENTAL: + new_p->type_hr_display = fundamental_type_hr_display; + new_p->type_file_print = fundamental_type_file_print; + new_p->type_dissect_from_buffer = fundamental_dissect_from_buffer; + break; + case TYPE_STRUCT: + new_p->type_hr_display = struct_type_hr_display; + new_p->type_file_print = struct_type_file_print; + new_p->type_dissect_from_buffer = struct_dissect_from_buffer; + break; + case TYPE_UNION: + new_p->type_hr_display = union_type_hr_display; + new_p->type_file_print = union_type_file_print; + new_p->type_dissect_from_buffer = union_dissect_from_buffer; + break; + case TYPE_TYPEDEF: + new_p->type_hr_display = typedef_type_hr_display; + new_p->type_file_print = typedef_type_file_print; + new_p->type_dissect_from_buffer = typedef_dissect_from_buffer; + break; + case TYPE_ENUMERATION_VALUE: + new_p->type_hr_display = enum_value_type_hr_display; + new_p->type_file_print = enum_value_file_print; + new_p->type_dissect_from_buffer = enum_value_dissect_from_buffer; + break; + case TYPE_FILE: + new_p->type_hr_display = file_type_hr_display; + new_p->type_file_print = file_type_file_print; +// new_p->type_dissect_from_buffer = file_dissect_from_buffer; + break; + case TYPE_FIELD: + new_p->type_hr_display = field_type_hr_display; + new_p->type_file_print = field_type_file_print; + new_p->type_dissect_from_buffer = field_dissect_from_buffer; + break; + case TYPE_REFERENCE: + new_p->type_hr_display = reference_type_hr_display; + new_p->type_file_print = reference_type_file_print; + new_p->type_dissect_from_buffer = reference_dissect_from_buffer; + break; + case TYPE_ARRAY: + new_p->type_hr_display = array_type_hr_display; + new_p->type_file_print = array_type_file_print; + new_p->type_dissect_from_buffer = array_dissect_from_buffer; + break; + case TYPE_POINTER: + new_p->type_hr_display = pointer_type_hr_display; + new_p->type_file_print = pointer_type_file_print; + new_p->type_dissect_from_buffer = pointer_dissect_from_buffer; + break; + default: + break; + } + + return new_p; +} + +int types_insert_tail(types_t **head, types_t *to_insert) +{ + if (to_insert == NULL || head == NULL) + return -1; + if (*head == NULL) { + *head = to_insert; + } else { + types_t *last = *head; + while(last->next != NULL) { + last = last->next; + } + last->next = to_insert; + to_insert->previous = last; + } + to_insert->head = *head; + return 0; +} + +void types_hr_display(types_t *head) +{ + types_t *current = head; + + if (head == NULL) { + printf("Empty list\n"); + /* Empty list */ + return; + } + + while((current = current->next) != NULL) + { + current->type_hr_display(current, 0); + } +} diff --git a/common/utils/itti_analyzer/libparser/types.h b/common/utils/itti_analyzer/libparser/types.h new file mode 100644 index 0000000000..1f8333222b --- /dev/null +++ b/common/utils/itti_analyzer/libparser/types.h @@ -0,0 +1,159 @@ +#include <stdio.h> + +#include "buffers.h" + +#ifndef TYPES_H_ +#define TYPES_H_ + +/* Activate to display the type at the beginning of the line (debug option) */ +#define ENABLE_DISPLAY_TYPE 0 + +/* Activate to display the parse information before processing each item (debug option) */ +#define ENABLE_DISPLAY_PARSE_INFO 0 + +/* Activate to show braces, in increase the number of displayed lines (formating option)*/ +#define ENABLE_DISPLAY_BRACE 0 + +#if (ENABLE_DISPLAY_TYPE != 0) +# define DISPLAY_TYPE(tYPE) ui_interface.ui_signal_set_text(tYPE, strlen(tYPE)); +#else +# define DISPLAY_TYPE(tYPE) +#endif + +#if (ENABLE_DISPLAY_PARSE_INFO != 0) +# define DISPLAY_PARSE_INFO(tYPE, nAME, oFFSET, pARENToFFSET) \ + { \ + char buf[200]; \ + sprintf(buf, "/* %s \"%s\" %d %d */\n", tYPE, nAME, oFFSET, pARENToFFSET); \ + ui_interface.ui_signal_set_text(buf, strlen(buf)); \ + } +#else +# define DISPLAY_PARSE_INFO(tYPE, nAME, oFFSET, pARENToFFSET) +#endif + +#if (ENABLE_DISPLAY_BRACE != 0) +# define DISPLAY_BRACE(cODE) cODE +#else +# define DISPLAY_BRACE(cODE) +#endif + +enum type_e { + TYPE_ENUMERATION, + TYPE_ENUMERATION_VALUE, + TYPE_STRUCT, + TYPE_UNION, + TYPE_FUNDAMENTAL, + TYPE_TYPEDEF, + TYPE_ARRAY, + TYPE_REFERENCE, + TYPE_FIELD, + TYPE_FUNCTION, + TYPE_ARGUMENT, + TYPE_POINTER, + TYPE_FILE, +}; + +/* Forward declarations */ +struct types_s; + +typedef int (*type_hr_display_t)(struct types_s *type, int indent); +typedef int (*type_ui_display_t)(struct types_s *type, int indent); +typedef int (*type_file_print_t)(struct types_s *type, int indent, FILE *file); + +/** + * type_dissect_from_buffer_t + * @param type The current type + * @param buffer The buffer containing data to dissect + * @param offset offset of field from the beginning of the parent + * @param parent_offset offset of the parent from begining + **/ +typedef int (*type_dissect_from_buffer_t)(struct types_s *type, buffer_t *buffer, + uint32_t offset, uint32_t parent_offset, int indent); + +typedef struct types_s { + /* The type of the current description */ + enum type_e type; + + /* Printable name for the current type */ + char *name; + + int type_xml; + + int size; + int align; + int bits; + + /* Used only for arrays */ + int min; + int max; + + int context; + + /* Init value for enumerations */ + int init_value; + + int incomplete; + + /* Id of the type as defined in XML file */ + int id; + int artificial; + + char *mangled; + char *demangled; + + /* List of members in constructed types */ + char *members; + + /* The file containing the definition */ + char *file; + /* Line number of the current definition */ + int line; + + /* offset of the field in the parent type + * -1 means no parent + */ + int offset; + + struct types_s *previous; + struct types_s *next; + struct types_s *parent; + struct types_s *child; + struct types_s *file_ref; + /* Reference to the head */ + struct types_s *head; + + /* For structures or union */ + int nb_members; + struct types_s **members_child; + + /* Some procedures to display the type on terminal */ + type_hr_display_t type_hr_display; + /* Some procedures to display the type on UI */ + type_ui_display_t type_ui_display; + /* Procedure to display the type to a file */ + type_file_print_t type_file_print; + /* Dissect the type */ + type_dissect_from_buffer_t type_dissect_from_buffer; +} types_t; + +types_t *type_new(enum type_e type); + +int types_insert_tail(types_t **head, types_t *to_insert); + +void types_hr_display(types_t *head); + +#define INDENTED(fILE, x, y) \ +do { \ + int indentation = x; \ + while(indentation--) fprintf(fILE, " "); \ + y; \ +} while(0) + +#define INDENTED_STRING(sTR, x, y) \ +do { \ + int indentation = x; \ + while(indentation--) ui_interface.ui_signal_set_text(" ", 1); \ + y; \ +} while(0) + +#endif /* TYPES_H_ */ diff --git a/common/utils/itti_analyzer/libparser/union_type.c b/common/utils/itti_analyzer/libparser/union_type.c new file mode 100644 index 0000000000..d62a438f42 --- /dev/null +++ b/common/utils/itti_analyzer/libparser/union_type.c @@ -0,0 +1,126 @@ +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> +#include <string.h> + +#include "rc.h" + +#include "union_type.h" +#include "../libresolver/locate_root.h" +#include "ui_interface.h" + +/* There is only one special case of union which is associated to an index: the message id */ +int union_msg_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset, + int indent) { + uint32_t message_id; + + DISPLAY_PARSE_INFO("union_msg", type->name, offset, parent_offset); + + CHECK_FCT(get_message_id(type->head, buffer, &message_id)); + + if (type->members_child[message_id] != NULL) + type->members_child[message_id]->type_dissect_from_buffer (type->members_child[message_id], buffer, offset, + parent_offset, indent); + + return RC_OK; +} + +int union_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset, + int indent) { + int length = 0; + char cbuf[200]; + char *cpy = NULL; + + DISPLAY_PARSE_INFO("union", type->name, offset, parent_offset); + + memset (cbuf, 0, 200); + +// CHECK_FCT(buffer_has_enouch_data(buffer, offset + parent_offset, type->size / 8)); + + if (type->name) { +// INDENTED(stdout, indent, fprintf(stdout, "<%s>\n", type->name)); + DISPLAY_TYPE("Uni"); + INDENTED_STRING(cbuf, indent, sprintf(cbuf, "%s {\n", type->name)); + } + + length = strlen (cbuf); + cpy = malloc (length * sizeof(char)); + memcpy (cpy, cbuf, length); + ui_interface.ui_signal_set_text (cpy, length); + + if (cpy) + free (cpy); + + /* Only dissect the first field present in unions */ + if (type->members_child[0] != NULL) + type->members_child[0]->type_dissect_from_buffer (type->members_child[0], buffer, offset, parent_offset, + type->name == NULL ? indent : indent + 4); + + if (type->name) { +// INDENTED(stdout, indent, fprintf(stdout, "</%s>\n", type->name)); + DISPLAY_TYPE("Uni"); + INDENTED_STRING(cbuf, indent, sprintf(cbuf, "};\n")); + } + + length = strlen (cbuf); + cpy = malloc (length * sizeof(char)); + memcpy (cpy, cbuf, length); + ui_interface.ui_signal_set_text (cpy, length); + + if (cpy) + free (cpy); + + return 0; +} + +int union_type_file_print(struct types_s *type, int indent, FILE *file) { + int i; + if (type == NULL) + return -1; + INDENTED(file, indent, fprintf(file, "<Union>\n")); + INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name)); + INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id)); + INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size)); + INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align)); + INDENTED(file, indent+4, fprintf(file, "Artificial .: %d\n", type->artificial)); + INDENTED(file, indent+4, fprintf(file, "File .......: %s\n", type->file)); + INDENTED(file, indent+4, fprintf(file, "Line .......: %d\n", type->line)); + INDENTED(file, indent+4, fprintf(file, "Members ....: %s\n", type->members)); + INDENTED(file, indent+4, fprintf(file, "Mangled ....: %s\n", type->mangled)); + INDENTED(file, indent+4, fprintf(file, "Demangled ..: %s\n", type->demangled)); + if (type->file_ref != NULL) + type->file_ref->type_file_print (type->file_ref, indent + 4, file); + for (i = 0; i < type->nb_members; i++) { + if (type->members_child[i] != NULL) + type->members_child[i]->type_file_print (type->members_child[i], indent + 4, file); + } + INDENTED(file, indent, fprintf(file, "</Union>\n")); + + return 0; +} + +int union_type_hr_display(struct types_s *type, int indent) { + int i; + if (type == NULL) + return -1; + INDENTED(stdout, indent, printf("<Union>\n")); + INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name)); + INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id)); + INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size)); + INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align)); + INDENTED(stdout, indent+4, printf("Artificial .: %d\n", type->artificial)); + INDENTED(stdout, indent+4, printf("File .......: %s\n", type->file)); + INDENTED(stdout, indent+4, printf("Line .......: %d\n", type->line)); + INDENTED(stdout, indent+4, printf("Members ....: %s\n", type->members)); + INDENTED(stdout, indent+4, printf("Mangled ....: %s\n", type->mangled)); + INDENTED(stdout, indent+4, printf("Demangled ..: %s\n", type->demangled)); + if (type->file_ref != NULL) + type->file_ref->type_hr_display (type->file_ref, indent + 4); + for (i = 0; i < type->nb_members; i++) { + if (type->members_child[i] != NULL) + type->members_child[i]->type_hr_display (type->members_child[i], indent + 4); + } + INDENTED(stdout, indent, printf("</Union>\n")); + + return 0; +} diff --git a/common/utils/itti_analyzer/libparser/union_type.h b/common/utils/itti_analyzer/libparser/union_type.h new file mode 100644 index 0000000000..f29a2098c6 --- /dev/null +++ b/common/utils/itti_analyzer/libparser/union_type.h @@ -0,0 +1,16 @@ +#include "types.h" + +#ifndef UNION_TYPE_H_ +#define UNION_TYPE_H_ + +int union_msg_dissect_from_buffer(struct types_s *type, buffer_t *buffer, + uint32_t offset, uint32_t parent_offset, int indent); + +int union_dissect_from_buffer(struct types_s *type, buffer_t *buffer, + uint32_t offset, uint32_t parent_offset, int indent); + +int union_type_file_print(struct types_s *type, int indent, FILE *file); + +int union_type_hr_display(struct types_s *type, int indent); + +#endif /* UNION_TYPE_H_ */ diff --git a/common/utils/itti_analyzer/libparser/xml_parse.c b/common/utils/itti_analyzer/libparser/xml_parse.c new file mode 100644 index 0000000000..4412d93541 --- /dev/null +++ b/common/utils/itti_analyzer/libparser/xml_parse.c @@ -0,0 +1,757 @@ +#include <string.h> +#include <unistd.h> + +#include <libxml/parser.h> +#include <libxml/tree.h> + +#include "types.h" +#include "xml_parse.h" +#include "union_type.h" + +#include "ui_interface.h" + +#include "../libresolver/locate_root.h" +#include "../libresolver/resolvers.h" + +extern int debug_parser; + +#if (ENABLE_DISPLAY_PARSE_INFO != 0) +# define INDENT_START 30 +#else +# define INDENT_START 0 +#endif + +#define PARSER_DEBUG(fmt, args...) \ +do { \ + if (debug_parser) \ + fprintf(stdout, "WARNING: "fmt, ##args); \ +} while(0) + +#define PARSER_ERROR(fmt, args...) \ +do { \ + fprintf(stderr, "FATAL: "fmt, ##args); \ +} while(0) + +types_t *root = NULL; + +static int xml_parse_doc(xmlDocPtr doc); + +static int parse_attribute_name(xmlNode *node, types_t *type, int mandatory) { + xmlAttrPtr node_attribute; + if ((node_attribute = xmlHasProp (node, (xmlChar *) "name")) == NULL) { + if (mandatory) { + PARSER_ERROR("cannot retrieve name attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + return -1; + } + else { + PARSER_DEBUG("cannot retrieve name attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + return 0; + } + } + type->name = strdup ((char *) node_attribute->children->content); + return 0; +} + +static int parse_attribute_id(xmlNode *node, types_t *type) { + xmlAttrPtr node_attribute; + if ((node_attribute = xmlHasProp (node, (xmlChar *) "id")) == NULL) { + PARSER_ERROR("cannot retrieve id attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + return -1; + } + type->id = atoi ((char *) &node_attribute->children->content[1]); + return 0; +} + +static int parse_attribute_size(xmlNode *node, types_t *type, int mandatory) { + xmlAttrPtr node_attribute; + if ((node_attribute = xmlHasProp (node, (xmlChar *) "size")) == NULL) { + if (mandatory) { + PARSER_ERROR("cannot retrieve size attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + type->size = -1; + return -1; + } + else { + PARSER_DEBUG("cannot retrieve size attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + type->size = -1; + return 0; + } + } + type->size = atoi ((char *) node_attribute->children->content); + return 0; +} + +static int parse_attribute_align(xmlNode *node, types_t *type, int mandatory) { + xmlAttrPtr node_attribute; + if ((node_attribute = xmlHasProp (node, (xmlChar *) "align")) == NULL) { + if (mandatory) { + PARSER_ERROR("cannot retrieve align attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + type->align = -1; + return -1; + } + else { + PARSER_DEBUG("cannot retrieve align attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + type->align = -1; + return 0; + } + } + type->align = atoi ((char *) node_attribute->children->content); + return 0; +} + +static int parse_attribute_line(xmlNode *node, types_t *type) { + xmlAttrPtr node_attribute; + if ((node_attribute = xmlHasProp (node, (xmlChar *) "line")) == NULL) { + type->line = -1; + return 0; + } + type->line = atoi ((char *) node_attribute->children->content); + return 0; +} + +static int parse_attribute_file(xmlNode *node, types_t *type) { + xmlAttrPtr node_attribute; + if ((node_attribute = xmlHasProp (node, (xmlChar *) "file")) == NULL) { + type->file = NULL; + return 0; + } + type->file = strdup ((char *) node_attribute->children->content); + return 0; +} + +static int parse_attribute_context(xmlNode *node, types_t *type, int mandatory) { + xmlAttrPtr node_attribute; + if ((node_attribute = xmlHasProp (node, (xmlChar *) "context")) == NULL) { + if (mandatory) { + PARSER_ERROR("cannot retrieve context attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + type->context = -1; + return -1; + } + else { + type->context = -1; + return 0; + } + } + type->context = atoi ((char *) &node_attribute->children->content[1]); + return 0; +} + +static int parse_attribute_artificial(xmlNode *node, types_t *type) { + xmlAttrPtr node_attribute; + if ((node_attribute = xmlHasProp (node, (xmlChar *) "artificial")) == NULL) { + PARSER_DEBUG("cannot retrieve artificial attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + type->artificial = -1; + return 0; + } + type->artificial = atoi ((char *) &node_attribute->children->content[1]); + return 0; +} + +static int parse_attribute_init(xmlNode *node, types_t *type) { + xmlAttrPtr node_attribute; + if ((node_attribute = xmlHasProp (node, (xmlChar *) "init")) == NULL) { + PARSER_ERROR("cannot retrieve init attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + type->init_value = -1; + return 0; + } + type->init_value = atoi ((char *) node_attribute->children->content); + return 0; +} + +static int parse_attribute_members(xmlNode *node, types_t *type, int mandatory) { + xmlAttrPtr node_attribute; + if ((node_attribute = xmlHasProp (node, (xmlChar *) "members")) == NULL) { + if (mandatory) { + PARSER_ERROR("cannot retrieve members attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + type->members = 0; + return -1; + } + else { + PARSER_DEBUG("cannot retrieve members attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + type->members = 0; + return 0; + } + } + type->members = strdup ((char *) node_attribute->children->content); + return 0; +} + +static int parse_attribute_mangled(xmlNode *node, types_t *type, int mandatory) { + xmlAttrPtr node_attribute; + if ((node_attribute = xmlHasProp (node, (xmlChar *) "mangled")) == NULL) { + if (mandatory) { + PARSER_ERROR("cannot retrieve mangled attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + type->mangled = 0; + return -1; + } + else { + PARSER_DEBUG("cannot retrieve mangled attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + type->mangled = 0; + return 0; + } + } + type->mangled = strdup ((char *) node_attribute->children->content); + return 0; +} + +static int parse_attribute_demangled(xmlNode *node, types_t *type, int mandatory) { + xmlAttrPtr node_attribute; + if ((node_attribute = xmlHasProp (node, (xmlChar *) "mangled")) == NULL) { + if (mandatory) { + PARSER_ERROR("cannot retrieve demangled attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + type->demangled = 0; + return -1; + } + else { + PARSER_DEBUG("cannot retrieve demangled attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + type->demangled = 0; + return 0; + } + } + type->demangled = strdup ((char *) node_attribute->children->content); + return 0; +} + +static int parse_attribute_offset(xmlNode *node, types_t *type, int mandatory) { + xmlAttrPtr node_attribute; + if ((node_attribute = xmlHasProp (node, (xmlChar *) "offset")) == NULL) { + if (mandatory) { + PARSER_ERROR("cannot retrieve offset attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + type->offset = -1; + return -1; + } + else { + PARSER_DEBUG("cannot retrieve offset attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + type->offset = -1; + return 0; + } + } + type->offset = atoi ((char *) node_attribute->children->content); + return 0; +} + +static int parse_attribute_bits(xmlNode *node, types_t *type, int mandatory) { + xmlAttrPtr node_attribute; + if ((node_attribute = xmlHasProp (node, (xmlChar *) "bits")) == NULL) { + if (mandatory) { + PARSER_ERROR("cannot retrieve bits attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + type->bits = -1; + return -1; + } + else { + PARSER_DEBUG("cannot retrieve bits attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + type->bits = -1; + return 0; + } + } + type->bits = atoi ((char *) node_attribute->children->content); + return 0; +} + +static int parse_attribute_type(xmlNode *node, types_t *type, int mandatory) { + xmlAttrPtr node_attribute; + if ((node_attribute = xmlHasProp (node, (xmlChar *) "type")) == NULL) { + if (mandatory) { + PARSER_ERROR("cannot retrieve type attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + type->type_xml = 0; + return -1; + } + else { + PARSER_DEBUG("cannot retrieve type attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + type->type_xml = 0; + return 0; + } + } + type->type_xml = atoi ((char *) &node_attribute->children->content[1]); + return 0; +} + +static int parse_attribute_min(xmlNode *node, types_t *type, int mandatory) { + xmlAttrPtr node_attribute; + if ((node_attribute = xmlHasProp (node, (xmlChar *) "min")) == NULL) { + if (mandatory) { + PARSER_ERROR("cannot retrieve min attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + type->min = 0; + return -1; + } + else { + PARSER_DEBUG("cannot retrieve min attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + type->min = 0; + return 0; + } + } + type->min = atoi ((char *) node_attribute->children->content); + return 0; +} + +static int parse_attribute_max(xmlNode *node, types_t *type, int mandatory) { + xmlAttrPtr node_attribute; + if ((node_attribute = xmlHasProp (node, (xmlChar *) "max")) == NULL) { + if (mandatory) { + PARSER_ERROR("cannot retrieve max attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + type->max = 0; + return -1; + } + else { + PARSER_DEBUG("cannot retrieve max attribute in node %s, %s:%ld\n", + (char *)node->name, node->doc->URL, XML_GET_LINE(node)); + type->max = 0; + return 0; + } + } + type->max = atoi ((char *) &node_attribute->children->content[1]); + return 0; +} + +static int parse_enum_values(xmlNode *node, types_t *parent) { + types_t *new; + + if (node == NULL || parent == NULL) + return -1; + + new = type_new (TYPE_ENUMERATION_VALUE); + + CHECK_FCT(parse_attribute_name(node, new, 1)); + CHECK_FCT(parse_attribute_init(node, new)); + + CHECK_FCT(types_insert_tail(&parent->child, new)); + + return 0; +} + +static int parse_enumeration(xmlNode *node, types_t **head) { + types_t *new; + xmlNode *enum_value_node; + + if (node == NULL) + return -1; + + new = type_new (TYPE_ENUMERATION); + + CHECK_FCT(parse_attribute_name(node, new, 1)); + CHECK_FCT(parse_attribute_id(node, new)); + CHECK_FCT(parse_attribute_size(node, new, 1)); + CHECK_FCT(parse_attribute_align(node, new, 1)); + CHECK_FCT(parse_attribute_context(node, new, 0)); + CHECK_FCT(parse_attribute_line(node, new)); + CHECK_FCT(parse_attribute_file(node, new)); + CHECK_FCT(parse_attribute_artificial(node, new)); + + CHECK_FCT(types_insert_tail(head, new)); + + /* Parse enum values */ + for (enum_value_node = node->children; enum_value_node; enum_value_node = enum_value_node->next) { + if (strcmp ((char *) enum_value_node->name, "EnumValue") == 0) + CHECK_FCT(parse_enum_values(enum_value_node, new)); + } + + return 0; +} + +static int parse_union(xmlNode *node, types_t **head) { + types_t *new; + + if (node == NULL) + return -1; + + new = type_new (TYPE_UNION); + + CHECK_FCT(parse_attribute_name(node, new, 0)); + CHECK_FCT(parse_attribute_id(node, new)); + CHECK_FCT(parse_attribute_size(node, new, 1)); + CHECK_FCT(parse_attribute_align(node, new, 1)); + CHECK_FCT(parse_attribute_context(node, new, 0)); + CHECK_FCT(parse_attribute_members(node, new, 0)); + CHECK_FCT(parse_attribute_line(node, new)); + CHECK_FCT(parse_attribute_file(node, new)); + CHECK_FCT(parse_attribute_artificial(node, new)); + CHECK_FCT(parse_attribute_mangled(node, new, 0)); + CHECK_FCT(parse_attribute_demangled(node, new, 0)); + + if (new->name) + if (strcmp (new->name, "msg_s") == 0) + new->type_dissect_from_buffer = union_msg_dissect_from_buffer; + + CHECK_FCT(types_insert_tail(head, new)); + + return 0; +} + +static int parse_fundamental(xmlNode *node, types_t **head) { + types_t *new; + + if (node == NULL) + return -1; + + new = type_new (TYPE_FUNDAMENTAL); + + CHECK_FCT(parse_attribute_name(node, new, 1)); + CHECK_FCT(parse_attribute_id(node, new)); + CHECK_FCT(parse_attribute_size(node, new, 0)); + CHECK_FCT(parse_attribute_align(node, new, 0)); + + CHECK_FCT(types_insert_tail(head, new)); + + return 0; +} + +static int parse_struct(xmlNode *node, types_t **head) { + types_t *new; + + if (node == NULL) + return -1; + + new = type_new (TYPE_STRUCT); + + CHECK_FCT(parse_attribute_name(node, new, 0)); + CHECK_FCT(parse_attribute_id(node, new)); + CHECK_FCT(parse_attribute_size(node, new, 0)); + CHECK_FCT(parse_attribute_align(node, new, 0)); + CHECK_FCT(parse_attribute_file(node, new)); + CHECK_FCT(parse_attribute_line(node, new)); + CHECK_FCT(parse_attribute_context(node, new, 0)); + CHECK_FCT(parse_attribute_artificial(node, new)); + CHECK_FCT(parse_attribute_members(node, new, 0)); + CHECK_FCT(parse_attribute_mangled(node, new, 0)); + CHECK_FCT(parse_attribute_demangled(node, new, 0)); + + CHECK_FCT(types_insert_tail(head, new)); + + return 0; +} + +static int parse_typedef(xmlNode *node, types_t **head) { + types_t *new; + + if (node == NULL) + return -1; + + new = type_new (TYPE_TYPEDEF); + + CHECK_FCT(parse_attribute_name(node, new, 1)); + CHECK_FCT(parse_attribute_id(node, new)); + CHECK_FCT(parse_attribute_file(node, new)); + CHECK_FCT(parse_attribute_line(node, new)); + CHECK_FCT(parse_attribute_type(node, new, 1)); + CHECK_FCT(parse_attribute_size(node, new, 0)); + CHECK_FCT(parse_attribute_align(node, new, 0)); + CHECK_FCT(parse_attribute_context(node, new, 0)); + CHECK_FCT(parse_attribute_artificial(node, new)); + CHECK_FCT(parse_attribute_members(node, new, 0)); + CHECK_FCT(parse_attribute_mangled(node, new, 0)); + CHECK_FCT(parse_attribute_demangled(node, new, 0)); + + CHECK_FCT(types_insert_tail(head, new)); + + return 0; +} + +static int parse_field(xmlNode *node, types_t **head) { + types_t *new; + + if (node == NULL) + return -1; + + new = type_new (TYPE_FIELD); + + CHECK_FCT(parse_attribute_name(node, new, 1)); + CHECK_FCT(parse_attribute_id(node, new)); + CHECK_FCT(parse_attribute_type(node, new, 1)); + CHECK_FCT(parse_attribute_size(node, new, 0)); + CHECK_FCT(parse_attribute_bits(node, new, 0)); + CHECK_FCT(parse_attribute_offset(node, new, 0)); + CHECK_FCT(parse_attribute_align(node, new, 0)); + CHECK_FCT(parse_attribute_context(node, new, 0)); + CHECK_FCT(parse_attribute_artificial(node, new)); + CHECK_FCT(parse_attribute_members(node, new, 0)); + CHECK_FCT(parse_attribute_mangled(node, new, 0)); + CHECK_FCT(parse_attribute_demangled(node, new, 0)); + + CHECK_FCT(types_insert_tail(head, new)); + + return 0; +} + +static int parse_file(xmlNode *node, types_t **head) { + types_t *new; + + if (node == NULL) + return -1; + + new = type_new (TYPE_FILE); + + CHECK_FCT(parse_attribute_name(node, new, 1)); + CHECK_FCT(parse_attribute_id(node, new)); + + CHECK_FCT(types_insert_tail(head, new)); + + return 0; +} + +static int parse_reference_type(xmlNode *node, types_t **head) { + types_t *new; + + if (node == NULL) + return -1; + + new = type_new (TYPE_REFERENCE); + + CHECK_FCT(parse_attribute_id(node, new)); + CHECK_FCT(parse_attribute_type(node, new, 1)); + CHECK_FCT(parse_attribute_size(node, new, 1)); + CHECK_FCT(parse_attribute_align(node, new, 1)); + CHECK_FCT(parse_attribute_context(node, new, 0)); + CHECK_FCT(parse_attribute_offset(node, new, 0)); + CHECK_FCT(parse_attribute_file(node, new)); + CHECK_FCT(parse_attribute_line(node, new)); + + CHECK_FCT(types_insert_tail(head, new)); + + return 0; +} + +static int parse_array_type(xmlNode *node, types_t **head) { + types_t *new; + + if (node == NULL) + return -1; + + new = type_new (TYPE_ARRAY); + + CHECK_FCT(parse_attribute_id(node, new)); + CHECK_FCT(parse_attribute_type(node, new, 1)); + CHECK_FCT(parse_attribute_size(node, new, 0)); + CHECK_FCT(parse_attribute_align(node, new, 1)); + CHECK_FCT(parse_attribute_min(node, new, 1)); + CHECK_FCT(parse_attribute_max(node, new, 1)); + + CHECK_FCT(types_insert_tail(head, new)); + + return 0; +} + +static int parse_pointer_type(xmlNode *node, types_t **head) { + types_t *new; + + if (node == NULL) + return -1; + + new = type_new (TYPE_POINTER); + + CHECK_FCT(parse_attribute_id(node, new)); + CHECK_FCT(parse_attribute_type(node, new, 1)); + CHECK_FCT(parse_attribute_size(node, new, 1)); + CHECK_FCT(parse_attribute_align(node, new, 1)); + + CHECK_FCT(types_insert_tail(head, new)); + + return 0; +} + +/** + * print_element_names: + * @a_node: the initial xml node to consider. + * + * Prints the names of the all the xml elements + * that are siblings or children of a given xml node. + */ +static int parse_elements(xmlNode * a_node, types_t **head) { + xmlNode *cur_node = NULL; + xmlNode *child_node = NULL; + unsigned long nb_nodes; + unsigned long node_count = 0; + + nb_nodes = xmlChildElementCount (a_node); + + for (cur_node = a_node; cur_node; cur_node = cur_node->next) { + node_count++; + sleep (1); + ui_interface.ui_progress_bar_set_fraction ((double) node_count / nb_nodes); + for (child_node = cur_node->children; child_node; child_node = child_node->next) { + if (child_node->type == XML_ELEMENT_NODE) { + if (strcmp ((char *) child_node->name, "Enumeration") == 0) { + CHECK_FCT_DO(parse_enumeration(child_node, head), goto fail); + } + else + if (strcmp ((char *) child_node->name, "FundamentalType") == 0) { + CHECK_FCT_DO(parse_fundamental(child_node, head), goto fail); + } + else + if (strcmp ((char *) child_node->name, "Struct") == 0) { + CHECK_FCT_DO(parse_struct(child_node, head), goto fail); + } + else + if (strcmp ((char *) child_node->name, "Union") == 0) { + CHECK_FCT_DO(parse_union(child_node, head), goto fail); + } + else + if (strcmp ((char *) child_node->name, "Typedef") == 0) { + CHECK_FCT_DO(parse_typedef(child_node, head), goto fail); + } + else + if (strcmp ((char *) child_node->name, "File") == 0) { + CHECK_FCT_DO(parse_file(child_node, head), goto fail); + } + else + if (strcmp ((char *) child_node->name, "Field") == 0) { + CHECK_FCT_DO(parse_field(child_node, head), goto fail); + } + else + if (strcmp ((char *) child_node->name, "ReferenceType") == 0) { + CHECK_FCT_DO(parse_reference_type(child_node, head), goto fail); + } + else + if (strcmp ((char *) child_node->name, "ArrayType") == 0) { + CHECK_FCT_DO(parse_array_type(child_node, head), goto fail); + } + else + if (strcmp ((char *) child_node->name, "PointerType") == 0) { + CHECK_FCT_DO(parse_pointer_type(child_node, head), goto fail); + } + } + } + } + + ui_interface.ui_progress_bar_terminate (); + + return RC_OK; + + fail: ui_interface.ui_progress_bar_terminate (); + return RC_FAIL; +} + +int xml_parse_buffer(const char *xml_buffer, const int size) { + xmlDocPtr doc; /* the resulting document tree */ + + if (xml_buffer == NULL) { + return -1; + } + + fprintf(stdout, "Parsing XML definition from buffer\n"); + + /* This initialize the library and check potential ABI mismatches + * between the version it was compiled for and the actual shared + * library used. + */ + LIBXML_TEST_VERSION + + doc = xmlReadMemory(xml_buffer, size, NULL, NULL, 0); + + if (doc == NULL) { + fprintf (stderr, "Failed to parse buffer: %s\n", xml_buffer); + ui_interface.ui_notification_dialog (DIALOG_WARNING, "Fail to parse XML buffer"); + return RC_FAIL; + } + + return xml_parse_doc(doc); +} + +int xml_parse_file(const char *filename) { + xmlDocPtr doc; /* the resulting document tree */ + + /* This initialize the library and check potential ABI mismatches + * between the version it was compiled for and the actual shared + * library used. + */ + LIBXML_TEST_VERSION + + if (filename == NULL) { + return -1; + } + + doc = xmlReadFile (filename, NULL, 0); + + if (doc == NULL) { + fprintf (stderr, "Failed to parse %s\n", filename); + ui_interface.ui_notification_dialog (DIALOG_WARNING, "Failed to parse file %s", filename); + return RC_FAIL; + } + + return xml_parse_doc(doc); +} + +static int xml_parse_doc(xmlDocPtr doc) { + xmlNode *root_element = NULL; + types_t *head = NULL; + int ret = 0; + FILE *dissect_file; + + dissect_file = fopen ("./dissect_xml.txt", "w"); + + /* Get the root element node */ + root_element = xmlDocGetRootElement (doc); + + ret = parse_elements (root_element, &head); + + /* Free the document */ + xmlFreeDoc (doc); + + /* Free the global variables that may + * have been allocated by the parser. + */ + xmlCleanupParser (); + + if (ret == RC_OK) { + resolve_typedefs (&head); + resolve_pointer_type (&head); + resolve_field (&head); + resolve_array (&head); + resolve_reference (&head); + resolve_struct (&head); + resolve_file (&head); + resolve_union (&head); + CHECK_FCT(locate_root("MessageDef", head, &root)); + // root->type_hr_display(root, 0); + if (dissect_file != NULL) { + root->type_file_print (root, 0, dissect_file); + } + ui_interface.dissector_ready = 1; + } + + fclose (dissect_file); + return ret; +} + +int dissect_signal(const uint32_t message_number) { + buffer_t *buffer; + + if (root == NULL) { + ui_interface.ui_notification_dialog (DIALOG_ERROR, "No message XML file provided"); + return RC_FAIL; + } + + CHECK_FCT(buffer_get_from_mn(message_number, &buffer)); + + if (buffer == NULL) { + fprintf (stderr, "Failed buffer %u in list\n", message_number); + return RC_FAIL; + } + + root->type_dissect_from_buffer (root, buffer, 0, 0, INDENT_START); + + return RC_OK; +} diff --git a/common/utils/itti_analyzer/libparser/xml_parse.h b/common/utils/itti_analyzer/libparser/xml_parse.h new file mode 100644 index 0000000000..982e357dc2 --- /dev/null +++ b/common/utils/itti_analyzer/libparser/xml_parse.h @@ -0,0 +1,13 @@ +#include "../rc.h" +#include "types.h" + +#ifndef XML_PARSE_H_ +#define XML_PARSE_H_ + +int xml_parse_file(const char *filename); + +int xml_parse_buffer(const char *xml_buffer, const int size); + +int dissect_signal(const uint32_t message_number); + +#endif /* XML_PARSE_H_ */ diff --git a/common/utils/itti_analyzer/libresolver/Makefile.am b/common/utils/itti_analyzer/libresolver/Makefile.am new file mode 100644 index 0000000000..eb8c34abc0 --- /dev/null +++ b/common/utils/itti_analyzer/libresolver/Makefile.am @@ -0,0 +1,12 @@ +AM_CFLAGS = \ + @ADD_CFLAGS@ \ + -I$(top_srcdir) \ + -I$(top_srcdir)/libparser \ + -I$(top_srcdir)/libbuffers + +noinst_LTLIBRARIES = libresolver.la + +libresolver_la_LDFLAGS = -all-static +libresolver_la_SOURCES = \ + locate_root.c locate_root.h \ + resolvers.c resolvers.h diff --git a/common/utils/itti_analyzer/libresolver/locate_root.c b/common/utils/itti_analyzer/libresolver/locate_root.c new file mode 100644 index 0000000000..a42e33fffc --- /dev/null +++ b/common/utils/itti_analyzer/libresolver/locate_root.c @@ -0,0 +1,82 @@ +#include <stdio.h> +#include <string.h> + +#include "../rc.h" + +#include "types.h" +#include "locate_root.h" + +int locate_root(const char *root_name, types_t *head, types_t **root) { + types_t *next_type; + + /* The root element is for example : MessageDef. + * This element is the entry for other sub-types. + */ + if (!root_name || (strlen (root_name) == 0)) { + printf ("FATAL: no root element name provided\n"); + return -1; + } + if (!head) { + printf ("Empty list detected\n"); + return -1; + } + if (!root) { + printf ("NULL root reference\n"); + return -1; + } + + for (next_type = head; next_type; next_type = next_type->next) { + if (next_type->name == NULL) + continue; + if (strcmp (root_name, next_type->name) == 0) { + /* Matching reference */ + break; + } + } + *root = next_type; + return (next_type == NULL) ? -2 : 0; +} + +int locate_type(const char *type_name, types_t *head, types_t **type) { + types_t *next_type; + + /* The root element is for example : MessageDef. + * This element is the entry for other sub-types. + */ + if (!type_name) { + printf ("FATAL: no root element name provided\n"); + return RC_BAD_PARAM; + } + if (!head) { + printf ("Empty list detected\n"); + return RC_BAD_PARAM; + } + + for (next_type = head; next_type; next_type = next_type->next) { + if (next_type->name == NULL) + continue; + if (strcmp (type_name, next_type->name) == 0) { + /* Matching reference */ + break; + } + } + if (type) + *type = next_type; + return (next_type == NULL) ? RC_FAIL : RC_OK; +} + +int get_message_id(types_t *head, buffer_t *buffer, uint32_t *message_id) { + uint32_t value; + types_t *type_message_id; + + if (!head || !message_id || !buffer) + return RC_BAD_PARAM; + + CHECK_FCT(locate_type("messageId", head, &type_message_id)); + + /* MessageId is an offset from start of buffer */ + value = buffer_get_uint32_t (buffer, type_message_id->offset); + + *message_id = value; + return RC_OK; +} diff --git a/common/utils/itti_analyzer/libresolver/locate_root.h b/common/utils/itti_analyzer/libresolver/locate_root.h new file mode 100644 index 0000000000..0cfab65fe2 --- /dev/null +++ b/common/utils/itti_analyzer/libresolver/locate_root.h @@ -0,0 +1,10 @@ +#ifndef LOCATE_ROOT_H_ +#define LOCATE_ROOT_H_ + +int locate_root(const char *root_name, types_t *head, types_t **root); + +int locate_type(const char *type_name, types_t *head, types_t **type); + +int get_message_id(types_t *head, buffer_t *buffer, uint32_t *message_id); + +#endif /* LOCATE_ROOT_H_ */ diff --git a/common/utils/itti_analyzer/libresolver/resolve_typedef.c b/common/utils/itti_analyzer/libresolver/resolve_typedef.c new file mode 100644 index 0000000000..24036e7a2f --- /dev/null +++ b/common/utils/itti_analyzer/libresolver/resolve_typedef.c @@ -0,0 +1,25 @@ +#include <stdio.h> +#include <string.h> + +#include "types.h" + +int resolve_typedefs(types_t **head) +{ + types_t *next_type; + + if (!head) { + printf("Empty list detected\n"); + return -1; + } + + for (next_type = head; next_type; next_type = next_type->next) + { + /* Only resolve typedef */ + if (next_type->type != TYPE_TYPEDEF) + continue; + + printf("Trying to resolve typedef %s\n", next_type->name); + } + + return 0; +} diff --git a/common/utils/itti_analyzer/libresolver/resolvers.c b/common/utils/itti_analyzer/libresolver/resolvers.c new file mode 100644 index 0000000000..ffc143096a --- /dev/null +++ b/common/utils/itti_analyzer/libresolver/resolvers.c @@ -0,0 +1,330 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "types.h" +#include "resolvers.h" + +typedef enum { + RESOLV_OK = 0, + RESOLV_ERROR = -1, + RESOLV_LIST_EMPTY = -2, + RESOLV_NOT_FOUND = -3, +} resolv_rc_e; + +int search_id(types_t *head, types_t **found, int id) +{ + types_t *next_type; + + if (!head) { + printf("Empty list detected\n"); + return RESOLV_LIST_EMPTY; + } + + for (next_type = head; next_type; next_type = next_type->next) + { + if (next_type->id == id && next_type->type != TYPE_FILE) + break; + } + if (found) + *found = next_type; + + return next_type == NULL ? RESOLV_NOT_FOUND : RESOLV_OK; +} + +int search_file(types_t *head, types_t **found, int file_id) +{ + types_t *next_type; + + if (!head) { + printf("Empty list detected\n"); + return RESOLV_LIST_EMPTY; + } + + for (next_type = head; next_type; next_type = next_type->next) + { + if (next_type->type != TYPE_FILE) + continue; + if (file_id == next_type->id) + break; + } + if (found) + *found = next_type; + + return next_type == NULL ? RESOLV_NOT_FOUND : RESOLV_OK; +} + +int resolve_typedefs(types_t **head) +{ + types_t *next_type; + + if (!head) { + printf("Empty list detected\n"); + return RESOLV_LIST_EMPTY; + } + + for (next_type = *head; next_type; next_type = next_type->next) + { + /* Only resolve typedef */ + if (next_type->type != TYPE_TYPEDEF) + continue; + +// printf("Trying to resolve typedef %s with type %d\n", next_type->name, next_type->id); + + if (search_id(*head, &next_type->child, next_type->type_xml) != RESOLV_OK) { + /* We have to remove this reference */ + }/* else { + next_type->type_hr_display(next_type, 0); + }*/ + } + + return 0; +} + +int resolve_struct(types_t **head) +{ + types_t *next_type; + + if (!head) { + printf("Empty list detected\n"); + return RESOLV_LIST_EMPTY; + } + + for (next_type = *head; next_type; next_type = next_type->next) + { + char *member; + char *members; + + /* Only resolve typedef */ + if (next_type->type != TYPE_STRUCT) + continue; + +// printf("Trying to resolve struct members %s with type %d\n", next_type->name, next_type->id); + + /* Struct may have no member */ + if (next_type->members == NULL) + continue; + + /* We have to copy the string as strtok will split the string in argument */ + members = strdup(next_type->members); + + /* Split the string on spaces and _ */ + member = strtok(members, " _"); + while(member != NULL) + { + if (next_type->nb_members == 0) { + next_type->members_child = malloc(sizeof(struct types_s *)); + } else { + next_type->members_child = realloc(next_type->members_child, + (next_type->nb_members + 1) * sizeof(struct types_s *)); + } + if (search_id(*head, &next_type->members_child[next_type->nb_members], atoi(member)) != RESOLV_OK) { + /* We have to remove this reference */ + } + if ((next_type->members_child[next_type->nb_members] != NULL) + && (next_type->members_child[next_type->nb_members]->type != TYPE_FIELD)) + { + /* Only keep field child for structure, other member can be present + * for defining types (union or struct) used by fields but should not be considered. */ + next_type->members_child[next_type->nb_members] = NULL; + /* We have to remove this reference */ + } + next_type->nb_members++; + /* Pick up the next string available */ + member = strtok(NULL, " _"); + } +// next_type->type_hr_display(next_type, 0); + } + + return 0; +} + +int resolve_union(types_t **head) +{ + types_t *next_type; + + if (!head) { + printf("Empty list detected\n"); + return RESOLV_LIST_EMPTY; + } + + for (next_type = *head; next_type; next_type = next_type->next) + { + char *member; + char *members; + + /* Only resolve typedef */ + if (next_type->type != TYPE_UNION) + continue; + +// printf("Trying to resolve struct members %s with type %d\n", next_type->name, next_type->id); + + /* Struct may have no member */ + if (next_type->members == NULL) + continue; + + /* We have to copy the string as strtok will modify the string in argument */ + members = strdup(next_type->members); + + /* Split the string on spaces and _ */ + member = strtok(members, " _"); + while(member != NULL) + { + if (next_type->nb_members == 0) { + next_type->members_child = malloc(sizeof(struct types_s *)); + } else { + next_type->members_child = realloc(next_type->members_child, + (next_type->nb_members + 1) * sizeof(struct types_s *)); + } + if (search_id(*head, &next_type->members_child[next_type->nb_members], atoi(member)) != RESOLV_OK) { + /* We have to remove this reference */ + } + next_type->nb_members++; + /* Pick up the next string available */ + member = strtok(NULL, " _"); + } +// next_type->type_hr_display(next_type, 0); + } + + return 0; +} + +int resolve_pointer_type(types_t **head) +{ + types_t *next_type; + + if (!head) { + printf("Empty list detected\n"); + return RESOLV_LIST_EMPTY; + } + + for (next_type = *head; next_type; next_type = next_type->next) + { + /* Only resolve typedef */ + if (next_type->type != TYPE_POINTER) + continue; + +// printf("Trying to resolve pointer id %d with type %d\n", +// next_type->id, next_type->type_xml); + + if (search_id(*head, &next_type->child, next_type->type_xml) != RESOLV_OK) { + /* We have to remove this reference */ + } +// next_type->type_hr_display(next_type, 0); + } + + return 0; +} + +int resolve_reference(types_t **head) +{ + types_t *next_type; + + if (!head) { + printf("Empty list detected\n"); + return RESOLV_LIST_EMPTY; + } + + for (next_type = *head; next_type; next_type = next_type->next) + { + /* Only resolve typedef */ + if (next_type->type != TYPE_REFERENCE) + continue; + +// printf("Trying to resolve reference id %d with type %d\n", +// next_type->id, next_type->type_xml); + + if (search_id(*head, &next_type->child, next_type->type_xml) != RESOLV_OK) { + /* We have to remove this reference */ + } +// next_type->type_hr_display(next_type, 0); + } + + return 0; +} + +int resolve_field(types_t **head) +{ + types_t *next_type; + + if (!head) { + printf("Empty list detected\n"); + return RESOLV_LIST_EMPTY; + } + + for (next_type = *head; next_type; next_type = next_type->next) + { + /* Only resolve typedef */ + if (next_type->type != TYPE_FIELD) + continue; + +// printf("Trying to resolve pointer id %d with type %d\n", +// next_type->id, next_type->type_xml); + + if (search_id(*head, &next_type->child, next_type->type_xml) != RESOLV_OK) { + /* We have to remove this reference */ + } +// next_type->type_hr_display(next_type, 0); + } + + return 0; +} + +int resolve_array(types_t **head) +{ + types_t *next_type; + + if (!head) { + printf("Empty list detected\n"); + return RESOLV_LIST_EMPTY; + } + + for (next_type = *head; next_type; next_type = next_type->next) + { + /* Only resolve typedef */ + if (next_type->type != TYPE_ARRAY) + continue; + +// printf("Trying to resolve array id %d with type %d\n", +// next_type->id, next_type->type_xml); + + if (search_id(*head, &next_type->child, next_type->type_xml) != RESOLV_OK) { + /* We have to remove this reference */ + } +// next_type->type_hr_display(next_type, 0); + } + + return 0; +} + +int resolve_file(types_t **head) +{ + types_t *next_type; + + if (!head) { + printf("Empty list detected\n"); + return RESOLV_LIST_EMPTY; + } + + for (next_type = *head; next_type; next_type = next_type->next) + { + /* Only resolve typedef */ + if (next_type->type == TYPE_FILE) + continue; + + /* No reference to a file */ + if (next_type->file == NULL) { + continue; + } + +// printf("Trying to resolve file %s\n", next_type->file); + + if (search_file(*head, &next_type->file_ref, atoi(&next_type->file[1])) != RESOLV_OK) { + /* We have to remove this reference */ + } +// next_type->type_hr_display(next_type, 0); + } + + return 0; +} + diff --git a/common/utils/itti_analyzer/libresolver/resolvers.h b/common/utils/itti_analyzer/libresolver/resolvers.h new file mode 100644 index 0000000000..04d6c103ac --- /dev/null +++ b/common/utils/itti_analyzer/libresolver/resolvers.h @@ -0,0 +1,22 @@ +#ifndef RESOLVERS_H_ +#define RESOLVERS_H_ + +int resolve_typedefs(types_t **head); + +int resolve_struct(types_t **head); + +int resolve_pointer_type(types_t **head); + +int resolve_field(types_t **head); + +int resolve_array(types_t **head); + +int resolve_reference(types_t **head); + +int resolve_union(types_t **head); + +int resolve_file(types_t **head); + +int search_file(types_t *head, types_t **found, int id); + +#endif /* RESOLVERS_H_ */ diff --git a/common/utils/itti_analyzer/libui/Makefile.am b/common/utils/itti_analyzer/libui/Makefile.am new file mode 100644 index 0000000000..5ff5826156 --- /dev/null +++ b/common/utils/itti_analyzer/libui/Makefile.am @@ -0,0 +1,17 @@ +AM_CFLAGS = \ + @ADD_CFLAGS@ \ + -I$(top_srcdir)/libbuffers \ + -I$(top_srcdir)/libparser + +noinst_LTLIBRARIES = libui.la + +libui_la_LDFLAGS = -all-static +libui_la_SOURCES = \ + ui_main_screen.c ui_main_screen.h \ + ui_menu_bar.c ui_menu_bar.h \ + ui_callbacks.c ui_callbacks.h \ + ui_tree_view.c ui_tree_view.h \ + ui_signal_dissect_view.c ui_signal_dissect_view.h \ + ui_notifications.c ui_notifications.h \ + ui_interface.c ui_interface.h \ + ui_notebook.c ui_notebook.h diff --git a/common/utils/itti_analyzer/libui/ui_callbacks.c b/common/utils/itti_analyzer/libui/ui_callbacks.c new file mode 100644 index 0000000000..7331d696c5 --- /dev/null +++ b/common/utils/itti_analyzer/libui/ui_callbacks.c @@ -0,0 +1,111 @@ +#include <stdlib.h> +#include <stdint.h> + +#include <gtk/gtk.h> + +#include "../rc.h" + +#include "ui_main_screen.h" +#include "ui_callbacks.h" +#include "ui_interface.h" +#include "ui_notifications.h" +#include "ui_tree_view.h" +#include "ui_signal_dissect_view.h" + +gboolean ui_callback_on_open(GtkWidget *widget, + GdkEvent *event, + gpointer data) +{ + g_print ("Open event occurred\n"); + CHECK_FCT(ui_file_chooser()); + return TRUE; +} + +gboolean ui_callback_on_about(GtkWidget *widget, + GdkEvent *event, + gpointer data) +{ + + return TRUE; +} + +gboolean +ui_callback_on_select_signal(GtkTreeSelection *selection, + GtkTreeModel *model, + GtkTreePath *path, + gboolean path_currently_selected, + gpointer userdata) +{ + GtkTreeIter iter; + + if (gtk_tree_model_get_iter(model, &iter, path)) + { + gchar *name; + + gtk_tree_model_get(model, &iter, 0, &name, -1); + + if (!path_currently_selected) + { + if (ui_interface.dissector_ready != 0) { + uint32_t message_number; + + sscanf(name, "%u", &message_number); + /* Clear the view */ + CHECK_FCT_DO(ui_signal_dissect_clear_view(), return FALSE); + // g_print ("%s is going to be selected.\n", name); + CHECK_FCT_DO(ui_interface.dissect_signal(message_number), return FALSE); + } else { + ui_notification_dialog(DIALOG_ERROR, "No XML signal description" + " provided\n"); + } + } + else + { + g_print ("%s is going to be unselected.\n", name); + } + + g_free(name); + } + return TRUE; +} + +gboolean ui_callback_on_connect(GtkWidget *widget, + GdkEvent *event, + gpointer data) +{ + /* We have to retrieve the ip address and port of remote host */ + uint16_t port; + const char *ip; + + g_print ("Connect event occurred\n"); + + port = atoi(gtk_entry_get_text(GTK_ENTRY(ui_main_data.portentry))); + ip = gtk_entry_get_text(GTK_ENTRY(ui_main_data.ipentry)); + +// ui_tree_view_destroy_list(); + ui_interface.socket_connect(ip, port); + + return TRUE; +} + +gboolean ui_callback_on_disconnect(GtkWidget *widget, + GdkEvent *event, + gpointer data) +{ + /* We have to retrieve the ip address and port of remote host */ + + g_print ("Disconnect event occurred\n"); + ui_interface.socket_disconnect(); + return TRUE; +} + +gboolean ui_callback_on_tree_view_select(GtkWidget *widget, + GdkEvent *event, + gpointer data) +{ + /* We have to retrieve the ip address and port of remote host */ + + g_print ("List selection event occurred\n"); + return TRUE; +} + diff --git a/common/utils/itti_analyzer/libui/ui_callbacks.h b/common/utils/itti_analyzer/libui/ui_callbacks.h new file mode 100644 index 0000000000..cf5e37d898 --- /dev/null +++ b/common/utils/itti_analyzer/libui/ui_callbacks.h @@ -0,0 +1,31 @@ +#ifndef UI_CALLBACKS_H_ +#define UI_CALLBACKS_H_ + +gboolean ui_callback_on_open(GtkWidget *widget, + GdkEvent *event, + gpointer data); + +gboolean ui_callback_on_about(GtkWidget *widget, + GdkEvent *event, + gpointer data); + +gboolean ui_callback_on_connect(GtkWidget *widget, + GdkEvent *event, + gpointer data); + +gboolean ui_callback_on_disconnect(GtkWidget *widget, + GdkEvent *event, + gpointer data); + +gboolean ui_callback_on_tree_view_select(GtkWidget *widget, + GdkEvent *event, + gpointer data); + +gboolean +ui_callback_on_select_signal(GtkTreeSelection *selection, + GtkTreeModel *model, + GtkTreePath *path, + gboolean path_currently_selected, + gpointer userdata); + +#endif /* UI_CALLBACKS_H_ */ diff --git a/common/utils/itti_analyzer/libui/ui_interface.c b/common/utils/itti_analyzer/libui/ui_interface.c new file mode 100644 index 0000000000..ae40d0d97c --- /dev/null +++ b/common/utils/itti_analyzer/libui/ui_interface.c @@ -0,0 +1,34 @@ +#include <pthread.h> +#include <stdint.h> +#include <unistd.h> + +#include <gtk/gtk.h> + +#include "ui_interface.h" + +#include "ui_tree_view.h" +#include "ui_notifications.h" +#include "ui_signal_dissect_view.h" + +#include "socket.h" +#include "xml_parse.h" + +ui_interface_t ui_interface = { + .dissector_ready = 0, + + /** core program -> UI **/ + .ui_notification_dialog = ui_notification_dialog, + .ui_disable_connect_button = ui_disable_connect_button, + .ui_enable_connect_button = ui_enable_connect_button, + .ui_progress_bar_set_fraction = ui_progress_bar_set_fraction, + .ui_progress_bar_terminate = ui_progress_bar_terminate, + .ui_tree_view_new_signal_ind = ui_tree_view_new_signal_ind, + .ui_signal_set_text = ui_signal_set_text, + + /** UI -> core program **/ + .socket_connect = socket_connect_to_remote_host, + .socket_disconnect = socket_disconnect_from_remote_host, + + .parse_signal_file = xml_parse_file, + .dissect_signal = dissect_signal, +}; diff --git a/common/utils/itti_analyzer/libui/ui_interface.h b/common/utils/itti_analyzer/libui/ui_interface.h new file mode 100644 index 0000000000..0b8f94085d --- /dev/null +++ b/common/utils/itti_analyzer/libui/ui_interface.h @@ -0,0 +1,61 @@ +#ifndef UI_INTERFACE_H_ +#define UI_INTERFACE_H_ + +typedef enum dialog_type_e { + DIALOG_INFO, + DIALOG_WARNING, + DIALOG_QUESTION, + DIALOG_ERROR, + DIALOG_OTHER, + DIALOG_MAX +} dialog_type_t; + +/** + * socket_connect_t + * @param remote_ip Remote ipv4 address + * @param port Remote port number + * @return RC_OK on Success, < 0 on failure + **/ +typedef int (*socket_connect_t)(const char *remote_ip, const uint16_t port); +typedef int (*socket_disconnect_t)(void); + +typedef int (*parse_signal_file_t)(const char *filename); +typedef int (*dissect_signal_t)(const uint32_t message_number); + +/** + * ui_notification_dialog_t + * @param type Type for the new dialog box + * @param fmt String formater + * @param ... argument list + * @return RC_OK on Success, < 0 on failure + **/ +typedef int (*ui_notification_dialog_t)(dialog_type_t type, const char *fmt, ...); +typedef int (*ui_disable_connect_button_t)(void); +typedef int (*ui_enable_connect_button_t)(void); +typedef int (*ui_progress_bar_set_fraction_t)(double fraction); +typedef int (*ui_progress_bar_terminate_t)(void); + +typedef int (*ui_tree_view_new_signal_ind_t)(const uint32_t message_number, const char *signal_name); +typedef int (*ui_signal_set_text_t)(char *text, int length); + +typedef struct { + /** UI -> core program */ + socket_connect_t socket_connect; + socket_disconnect_t socket_disconnect; + parse_signal_file_t parse_signal_file; + dissect_signal_t dissect_signal; + + /** core program -> UI */ + int dissector_ready; + ui_notification_dialog_t ui_notification_dialog; + ui_disable_connect_button_t ui_disable_connect_button; + ui_enable_connect_button_t ui_enable_connect_button; + ui_progress_bar_set_fraction_t ui_progress_bar_set_fraction; + ui_progress_bar_terminate_t ui_progress_bar_terminate; + ui_tree_view_new_signal_ind_t ui_tree_view_new_signal_ind; + ui_signal_set_text_t ui_signal_set_text; +} ui_interface_t; + +extern ui_interface_t ui_interface; + +#endif /* UI_INTERFACE_H_ */ diff --git a/common/utils/itti_analyzer/libui/ui_main_screen.c b/common/utils/itti_analyzer/libui/ui_main_screen.c new file mode 100644 index 0000000000..fd4973a222 --- /dev/null +++ b/common/utils/itti_analyzer/libui/ui_main_screen.c @@ -0,0 +1,74 @@ + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include <stdio.h> +#include <stdint.h> +#include <string.h> + +#include <gtk/gtk.h> + +#include "../rc.h" + +#include "ui_interface.h" +#include "ui_main_screen.h" +#include "ui_menu_bar.h" +#include "ui_tree_view.h" +#include "ui_notebook.h" +#include "ui_notifications.h" + +ui_main_data_t ui_main_data; + +int ui_gtk_initialize(int argc, char *argv[]) +{ + GtkWidget *vbox; + + memset(&ui_main_data, 0, sizeof(ui_main_data_t)); + + if (!g_thread_supported()) + g_thread_init(NULL); + + /* Secure gtk */ + gdk_threads_init(); + + /* Obtain gtk's global lock */ + gdk_threads_enter(); + + /* Initialize the widget set */ + gtk_init(&argc, &argv); + + /* Create the main window */ + ui_main_data.window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + gtk_window_set_position(GTK_WINDOW(ui_main_data.window), GTK_WIN_POS_CENTER); + gtk_window_set_default_size(GTK_WINDOW(ui_main_data.window), 1024, 800); +#if defined(PACKAGE_STRING) + gtk_window_set_title(GTK_WINDOW(ui_main_data.window), PACKAGE_STRING); +#else + gtk_window_set_title(GTK_WINDOW(ui_main_data.window), "itti debugger"); +#endif + gtk_window_set_resizable(GTK_WINDOW(ui_main_data.window), TRUE); + + vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + + CHECK_FCT(ui_menu_bar_create(vbox)); + CHECK_FCT(ui_toolbar_create(vbox)); +// CHECK_FCT(ui_tree_view_create(ui_main_data.window, vbox)); + CHECK_FCT(ui_notebook_create(vbox)); + + gtk_container_add(GTK_CONTAINER(ui_main_data.window), vbox); + /* Assign the destroy event */ + g_signal_connect(ui_main_data.window, "destroy", G_CALLBACK (gtk_main_quit), NULL); + + /* Show the application window */ + gtk_widget_show_all (ui_main_data.window); + + /* Enter the main event loop, and wait for user interaction */ + gtk_main (); + + /* Release gtk's global lock */ + gdk_threads_leave(); + + return RC_OK; +} diff --git a/common/utils/itti_analyzer/libui/ui_main_screen.h b/common/utils/itti_analyzer/libui/ui_main_screen.h new file mode 100644 index 0000000000..7d5be66797 --- /dev/null +++ b/common/utils/itti_analyzer/libui/ui_main_screen.h @@ -0,0 +1,22 @@ +#ifndef UI_MAIN_SCREEN_H_ +#define UI_MAIN_SCREEN_H_ + +typedef struct { + GtkWidget *window; + GtkWidget *ipentry; + GtkWidget *portentry; + + GtkWidget *progressbar; + GtkWidget *signalslist; + GtkWidget *textview; + + /* Buttons */ + GtkToolItem *connect; + GtkToolItem *disconnect; +} ui_main_data_t; + +extern ui_main_data_t ui_main_data; + +int ui_gtk_initialize(int argc, char *argv[]); + +#endif /* UI_MAIN_SCREEN_H_ */ diff --git a/common/utils/itti_analyzer/libui/ui_menu_bar.c b/common/utils/itti_analyzer/libui/ui_menu_bar.c new file mode 100644 index 0000000000..485a65e872 --- /dev/null +++ b/common/utils/itti_analyzer/libui/ui_menu_bar.c @@ -0,0 +1,131 @@ +#include <gtk/gtk.h> + +#include "../rc.h" +#include "ui_main_screen.h" +#include "ui_menu_bar.h" +#include "ui_callbacks.h" + +int ui_menu_bar_create(GtkWidget *vbox) +{ + GtkWidget *menubar; + GtkWidget *filemenu, *helpmenu; + GtkWidget *file; + GtkWidget *help; + GtkWidget *quit; + GtkWidget *about; + + if (!vbox) + return RC_BAD_PARAM; + + menubar = gtk_menu_bar_new(); + + /* Create the File submenu */ + filemenu = gtk_menu_new(); + + file = gtk_menu_item_new_with_label("File"); + quit = gtk_menu_item_new_with_label("Quit"); + + gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), filemenu); + + gtk_menu_shell_append(GTK_MENU_SHELL(menubar), file); + gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit); + + /* Create the Help submenu */ + helpmenu = gtk_menu_new(); + + help = gtk_menu_item_new_with_label("Help"); + about = gtk_menu_item_new_with_label("About"); + + gtk_menu_item_set_submenu(GTK_MENU_ITEM(help), helpmenu); + + gtk_menu_shell_append(GTK_MENU_SHELL(menubar), help); + gtk_menu_shell_append(GTK_MENU_SHELL(helpmenu), about); + + /* Add the menubar to the vbox */ + gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 3); + + g_signal_connect(G_OBJECT(quit), "activate", + G_CALLBACK(gtk_main_quit), NULL); + + g_signal_connect(G_OBJECT(about), "activate", + G_CALLBACK(ui_callback_on_about), NULL); + + return RC_OK; +} + +int ui_toolbar_create(GtkWidget *vbox) +{ + GtkWidget *toolbar; + GtkWidget *hbox; + GtkWidget *iplabel; + GtkWidget *portlabel; + GtkToolItem *open; + + if (!vbox) + return RC_BAD_PARAM; + + hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + + toolbar = gtk_toolbar_new(); + gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS); + + gtk_container_set_border_width(GTK_CONTAINER(toolbar), 2); + + /* Button to open file */ + open = gtk_tool_button_new_from_stock(GTK_STOCK_OPEN); + gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(open), + "Open new dump file"); + gtk_toolbar_insert(GTK_TOOLBAR(toolbar), open, -1); + + /* Button to connect to remote */ + ui_main_data.connect = gtk_tool_button_new_from_stock(GTK_STOCK_CONNECT); + /* Set the tooltip text */ + gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(ui_main_data.connect), + "Connect to remote host"); + gtk_toolbar_insert(GTK_TOOLBAR(toolbar), ui_main_data.connect, -1); + + /* Button to connect to remote */ + ui_main_data.disconnect = gtk_tool_button_new_from_stock(GTK_STOCK_DISCONNECT); + /* Set the tooltip text */ + gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(ui_main_data.disconnect), + "Disconnect from remote host"); + gtk_toolbar_insert(GTK_TOOLBAR(toolbar), ui_main_data.disconnect, -1); + + /* Disabled at startup. Will be activated when a connection is established */ + gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.disconnect), FALSE); + + /* No overflow menu */ + gtk_toolbar_set_show_arrow(GTK_TOOLBAR(toolbar), FALSE); + + iplabel = gtk_label_new("ip:"); + portlabel = gtk_label_new("port:"); + + ui_main_data.ipentry = gtk_entry_new(); + /* Width of 15 characters for port number (ipv4 address) */ + gtk_entry_set_width_chars(GTK_ENTRY(ui_main_data.ipentry), 15); + gtk_entry_set_text(GTK_ENTRY(ui_main_data.ipentry), "127.0.0.1"); + + ui_main_data.portentry = gtk_entry_new(); + /* Width of 5 characters for port number (uint16_t) */ + gtk_entry_set_width_chars(GTK_ENTRY(ui_main_data.portentry), 5); + gtk_entry_set_text(GTK_ENTRY(ui_main_data.portentry), "10007"); + + gtk_box_pack_start(GTK_BOX(hbox), toolbar, FALSE, FALSE, 5); + gtk_box_pack_start(GTK_BOX(hbox), iplabel, FALSE, FALSE, 2); + gtk_box_pack_start(GTK_BOX(hbox), ui_main_data.ipentry, FALSE, FALSE, 5); + gtk_box_pack_start(GTK_BOX(hbox), portlabel, FALSE, FALSE, 2); + gtk_box_pack_start(GTK_BOX(hbox), ui_main_data.portentry, FALSE, FALSE, 5); + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); + + /* Some callbacks associated to buttons */ + g_signal_connect(G_OBJECT(open), "clicked", + G_CALLBACK(ui_callback_on_open), NULL); + + g_signal_connect(G_OBJECT(ui_main_data.connect), "clicked", + G_CALLBACK(ui_callback_on_connect), NULL); + + g_signal_connect(G_OBJECT(ui_main_data.disconnect), "clicked", + G_CALLBACK(ui_callback_on_disconnect), NULL); + + return RC_OK; +} diff --git a/common/utils/itti_analyzer/libui/ui_menu_bar.h b/common/utils/itti_analyzer/libui/ui_menu_bar.h new file mode 100644 index 0000000000..2253207945 --- /dev/null +++ b/common/utils/itti_analyzer/libui/ui_menu_bar.h @@ -0,0 +1,8 @@ +#ifndef UI_MENU_BAR_H_ +#define UI_MENU_BAR_H_ + +int ui_menu_bar_create(GtkWidget *vbox); + +int ui_toolbar_create(GtkWidget *vbox); + +#endif /* UI_MENU_BAR_H_ */ diff --git a/common/utils/itti_analyzer/libui/ui_notebook.c b/common/utils/itti_analyzer/libui/ui_notebook.c new file mode 100644 index 0000000000..9aaa480e62 --- /dev/null +++ b/common/utils/itti_analyzer/libui/ui_notebook.c @@ -0,0 +1,33 @@ +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include <stdio.h> +#include <stdint.h> +#include <gtk/gtk.h> + +#include "../rc.h" + +#include "ui_notebook.h" +#include "ui_tree_view.h" + +int ui_notebook_create(GtkWidget *vbox) +{ + GtkWidget *notebook; + GtkWidget *vbox_notebook; + + if (!vbox) + return RC_BAD_PARAM; + + notebook = gtk_notebook_new(); + + vbox_notebook = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + ui_tree_view_create(NULL, vbox_notebook); + + gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox_notebook, NULL); + + /* Add the notebook to the vbox of the main window */ + gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0); + + return RC_OK; +} diff --git a/common/utils/itti_analyzer/libui/ui_notebook.h b/common/utils/itti_analyzer/libui/ui_notebook.h new file mode 100644 index 0000000000..84d9ffaf17 --- /dev/null +++ b/common/utils/itti_analyzer/libui/ui_notebook.h @@ -0,0 +1,6 @@ +#ifndef UI_NOTEBOOK_H_ +#define UI_NOTEBOOK_H_ + +int ui_notebook_create(GtkWidget *vbox); + +#endif /* UI_NOTEBOOK_H_ */ diff --git a/common/utils/itti_analyzer/libui/ui_notifications.c b/common/utils/itti_analyzer/libui/ui_notifications.c new file mode 100644 index 0000000000..d900ceac05 --- /dev/null +++ b/common/utils/itti_analyzer/libui/ui_notifications.c @@ -0,0 +1,108 @@ +#include <stdlib.h> +#include <stdint.h> +#include <stdarg.h> + +#include <gtk/gtk.h> + +#include "../rc.h" + +#include "ui_interface.h" +#include "ui_main_screen.h" +#include "ui_notifications.h" + +int ui_notification_dialog(dialog_type_t type, const char *fmt, ...) +{ + va_list ap; + GtkWidget *dialogbox; + + va_start(ap, fmt); + + /* In multi-threaded environnements gtk calls should be protected by + * gdk_threads_enter before calling the GTK function + * gdk_threads_leave when GTK function has exited + */ + gdk_threads_enter(); + + dialogbox = gtk_message_dialog_new( + GTK_WINDOW(ui_main_data.window), GTK_DIALOG_MODAL, type, + GTK_BUTTONS_OK, fmt, ap); + + gtk_dialog_run(GTK_DIALOG (dialogbox)); + + gtk_widget_destroy (dialogbox); + + gdk_threads_leave(); + + va_end(ap); + + return RC_OK; +} + +int ui_disable_connect_button(void) +{ + /* Disable Connect button and enable disconnect button */ + gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.connect), FALSE); + gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.disconnect), TRUE); + + return RC_OK; +} + +int ui_enable_connect_button(void) +{ + /* Disable Disconnect button and enable connect button */ + gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.connect), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.disconnect), FALSE); + + return RC_OK; +} + +int ui_file_chooser(void) +{ + GtkWidget *filechooser; + + filechooser = gtk_file_chooser_dialog_new( + "Select file", GTK_WINDOW(ui_main_data.window), + GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL); + + /* Process the response */ + if (gtk_dialog_run (GTK_DIALOG (filechooser)) == GTK_RESPONSE_ACCEPT) + { + char *filename; + + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser)); + ui_interface.parse_signal_file(filename); + g_free (filename); + } + + gtk_widget_destroy (filechooser); + + return RC_OK; +} + +int ui_progress_bar_set_fraction(double fraction) +{ +// /* If not exist instantiate */ +// if (!ui_main_data.progressbar) { +// ui_main_data.progressbar = gtk_progress_bar_new(); +// } +// +// gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ui_main_data.progressbar), fraction); +// +// gtk_widget_show(ui_main_data.progressbar); +// +// gtk_main_iteration(); + + return RC_OK; +} + +int ui_progress_bar_terminate(void) +{ +// if (!ui_main_data.progressbar) +// return RC_FAIL; +// +// gtk_widget_destroy(ui_main_data.progressbar); +// ui_main_data.progressbar = NULL; + + return RC_OK; +} diff --git a/common/utils/itti_analyzer/libui/ui_notifications.h b/common/utils/itti_analyzer/libui/ui_notifications.h new file mode 100644 index 0000000000..cbc669fde9 --- /dev/null +++ b/common/utils/itti_analyzer/libui/ui_notifications.h @@ -0,0 +1,16 @@ +#ifndef UI_NOTIFICATIONS_H_ +#define UI_NOTIFICATIONS_H_ + +int ui_notification_dialog(dialog_type_t type, const char *fmt, ...); + +int ui_disable_connect_button(void); + +int ui_enable_connect_button(void); + +int ui_file_chooser(void); + +int ui_progress_bar_set_fraction(double fraction); + +int ui_progress_bar_terminate(void); + +#endif /* UI_NOTIFICATIONS_H_ */ diff --git a/common/utils/itti_analyzer/libui/ui_signal_dissect_view.c b/common/utils/itti_analyzer/libui/ui_signal_dissect_view.c new file mode 100644 index 0000000000..82f6af0ae1 --- /dev/null +++ b/common/utils/itti_analyzer/libui/ui_signal_dissect_view.c @@ -0,0 +1,74 @@ +#include <string.h> + +#include <gtk/gtk.h> + +#include "../rc.h" + +#include "ui_main_screen.h" +#include "ui_menu_bar.h" +#include "ui_signal_dissect_view.h" + +int ui_signal_dissect_new(GtkWidget *hbox) +{ + GtkWidget *scrolled_window; + + ui_main_data.textview = gtk_text_view_new(); + scrolled_window = gtk_scrolled_window_new(NULL, NULL); + + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), + GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); + + CHECK_BUFFER(ui_main_data.textview); + + /* Disable editable attribute */ + gtk_text_view_set_editable(GTK_TEXT_VIEW(ui_main_data.textview), FALSE); + + gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), + ui_main_data.textview); + + gtk_box_pack_start(GTK_BOX(hbox), scrolled_window, TRUE, TRUE, 5); + + return 0; +} + +int ui_signal_dissect_clear_view(void) +{ + GtkTextBuffer *textbuffer; + + textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(ui_main_data.textview)); + + CHECK_BUFFER(textbuffer); + + /* If a text buffer is present for the textview remove it */ + if (textbuffer) { + gtk_text_view_set_buffer(GTK_TEXT_VIEW(ui_main_data.textview), NULL); +// g_object_unref(textbuffer); + } + return RC_OK; +} + +int ui_signal_set_text(char *text, int length) +{ + GtkTextBuffer *textbuffer; + + if (length < 0) + return RC_BAD_PARAM; + + CHECK_BUFFER(text); + + // fprintf (stdout, "%*s", length, text); + + textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(ui_main_data.textview)); + + if (textbuffer) { + /* We already have a text buffer, use it */ + gtk_text_buffer_insert_at_cursor(textbuffer, text, length); + } else { + /* No buffer currently in use, create a new one */ + textbuffer = gtk_text_buffer_new(NULL); + gtk_text_buffer_set_text(textbuffer, text, length); + gtk_text_view_set_buffer(GTK_TEXT_VIEW(ui_main_data.textview), textbuffer); + } + + return RC_OK; +} diff --git a/common/utils/itti_analyzer/libui/ui_signal_dissect_view.h b/common/utils/itti_analyzer/libui/ui_signal_dissect_view.h new file mode 100644 index 0000000000..b1082a20b5 --- /dev/null +++ b/common/utils/itti_analyzer/libui/ui_signal_dissect_view.h @@ -0,0 +1,10 @@ +#ifndef UI_SIGNAL_DISSECT_VIEW_H_ +#define UI_SIGNAL_DISSECT_VIEW_H_ + +int ui_signal_dissect_new(GtkWidget *hbox); + +int ui_signal_set_text(char *text, int length); + +int ui_signal_dissect_clear_view(void); + +#endif /*UI_SIGNAL_DISSECT_VIEW_H_ */ diff --git a/common/utils/itti_analyzer/libui/ui_tree_view.c b/common/utils/itti_analyzer/libui/ui_tree_view.c new file mode 100644 index 0000000000..0963950eb8 --- /dev/null +++ b/common/utils/itti_analyzer/libui/ui_tree_view.c @@ -0,0 +1,122 @@ +#include <stdlib.h> +#include <stdint.h> + +#include <gtk/gtk.h> + +#include "../rc.h" + +#include "ui_main_screen.h" +#include "ui_tree_view.h" +#include "ui_callbacks.h" + +#include "ui_signal_dissect_view.h" + +enum +{ + COL_MSG_NUM = 0, + COL_SIGNAL, + NUM_COLS +} ; + +static void +init_list(GtkWidget *list) +{ + GtkCellRenderer *renderer; + GtkTreeViewColumn *column; + GtkListStore *store; + + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes( + "Message Number", renderer, "text", COL_MSG_NUM, NULL); + gtk_tree_view_append_column(GTK_TREE_VIEW(list), column); + + column = gtk_tree_view_column_new_with_attributes( + "Signal", renderer, "text", COL_SIGNAL, NULL); + gtk_tree_view_append_column(GTK_TREE_VIEW(list), column); + + store = gtk_list_store_new(NUM_COLS, G_TYPE_STRING, G_TYPE_STRING); + + gtk_tree_view_set_model(GTK_TREE_VIEW(list), GTK_TREE_MODEL(store)); + + g_object_unref(store); +} + +static void +add_to_list(GtkWidget *list, const gchar *message_number, const gchar *signal_name) +{ + GtkListStore *store; + GtkTreeIter iter; + + store = GTK_LIST_STORE(gtk_tree_view_get_model + (GTK_TREE_VIEW(list))); + + gtk_list_store_append(store, &iter); + gtk_list_store_set(store, &iter, COL_MSG_NUM, message_number, + COL_SIGNAL, signal_name, -1); +} + +void ui_tree_view_destroy_list(GtkWidget *list) +{ + GtkListStore *store; + + g_assert(list != NULL); + + store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(list))); + + gtk_list_store_clear(store); +} + +int ui_tree_view_create(GtkWidget *window, GtkWidget *vbox) +{ + GtkWidget *hbox; + GtkTreeSelection *selection; + GtkWidget *scrolled_window; +// gint width; + + scrolled_window = gtk_scrolled_window_new(NULL, NULL); + + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), + GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); + + //gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 5); + + ui_main_data.signalslist = gtk_tree_view_new(); + gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(ui_main_data.signalslist), TRUE); + + /* Disable multiple selection */ + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ui_main_data.signalslist)); + gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE); + + hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + + gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), + ui_main_data.signalslist); + + init_list(ui_main_data.signalslist); + +// gtk_widget_get_size_request(GTK_WIDGET(ui_main_data.signalslist), &width, NULL); + gtk_widget_set_size_request(GTK_WIDGET(scrolled_window), 350, -1); + gtk_box_pack_start(GTK_BOX(hbox), scrolled_window, FALSE, FALSE, 0); + CHECK_FCT(ui_signal_dissect_new(hbox)); + + gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 5); + +// g_signal_connect(G_OBJECT(ui_main_data.signalslist), "cursor-changed", +// G_CALLBACK(ui_callback_on_select_signal), NULL); + + /* Connect callback on row selection */ + gtk_tree_selection_set_select_function(selection, ui_callback_on_select_signal, NULL, NULL); + + return 0; +} + +int ui_tree_view_new_signal_ind(const uint32_t message_number, const char *signal_name) +{ + gchar message_number_str[11]; + + sprintf(message_number_str, "%u", message_number); + + add_to_list(ui_main_data.signalslist, message_number_str, signal_name); + + return RC_OK; +} diff --git a/common/utils/itti_analyzer/libui/ui_tree_view.h b/common/utils/itti_analyzer/libui/ui_tree_view.h new file mode 100644 index 0000000000..38f1ad8f66 --- /dev/null +++ b/common/utils/itti_analyzer/libui/ui_tree_view.h @@ -0,0 +1,10 @@ +#ifndef UI_TREE_VIEW_H_ +#define UI_TREE_VIEW_H_ + +int ui_tree_view_create(GtkWidget *window, GtkWidget *vbox); + +int ui_tree_view_new_signal_ind(const uint32_t message_number, const char *signal_name); + +void ui_tree_view_destroy_list(GtkWidget *list); + +#endif /* UI_TREE_VIEW_H_ */ diff --git a/common/utils/itti_analyzer/queue.h b/common/utils/itti_analyzer/queue.h new file mode 100644 index 0000000000..294d485110 --- /dev/null +++ b/common/utils/itti_analyzer/queue.h @@ -0,0 +1,592 @@ +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)queue.h 8.5 (Berkeley) 8/20/94 + */ + +#ifndef _SYS_QUEUE_H_ +#define _SYS_QUEUE_H_ + +/* + * This file defines five types of data structures: singly-linked lists, + * lists, simple queues, tail queues, and circular queues. + * + * A singly-linked list is headed by a single forward pointer. The + * elements are singly linked for minimum space and pointer manipulation + * overhead at the expense of O(n) removal for arbitrary elements. New + * elements can be added to the list after an existing element or at the + * head of the list. Elements being removed from the head of the list + * should use the explicit macro for this purpose for optimum + * efficiency. A singly-linked list may only be traversed in the forward + * direction. Singly-linked lists are ideal for applications with large + * datasets and few or no removals or for implementing a LIFO queue. + * + * A list is headed by a single forward pointer (or an array of forward + * pointers for a hash table header). The elements are doubly linked + * so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before + * or after an existing element or at the head of the list. A list + * may only be traversed in the forward direction. + * + * A simple queue is headed by a pair of pointers, one the head of the + * list and the other to the tail of the list. The elements are singly + * linked to save space, so elements can only be removed from the + * head of the list. New elements can be added to the list after + * an existing element, at the head of the list, or at the end of the + * list. A simple queue may only be traversed in the forward direction. + * + * A tail queue is headed by a pair of pointers, one to the head of the + * list and the other to the tail of the list. The elements are doubly + * linked so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before or + * after an existing element, at the head of the list, or at the end of + * the list. A tail queue may be traversed in either direction. + * + * A circle queue is headed by a pair of pointers, one to the head of the + * list and the other to the tail of the list. The elements are doubly + * linked so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before or after + * an existing element, at the head of the list, or at the end of the list. + * A circle queue may be traversed in either direction, but has a more + * complex end of list detection. + * + * For details on the use of these macros, see the queue(3) manual page. + * SLIST LIST STAILQ TAILQ CIRCLEQ + * _HEAD + + + + + + * _HEAD_INITIALIZER + + + + + + * _ENTRY + + + + + + * _INIT + + + + + + * _EMPTY + + + + + + * _FIRST + + + + + + * _NEXT + + + + + + * _PREV - - - + + + * _LAST - - + + + + * _FOREACH + + + + + + * _FOREACH_REVERSE - - - + + + * _INSERT_HEAD + + + + + + * _INSERT_BEFORE - + - + + + * _INSERT_AFTER + + + + + + * _INSERT_TAIL - - + + + + * _REMOVE_HEAD + - + - - + * _REMOVE + + + + + + */ + +/* + * List definitions. + */ +#define LIST_HEAD(name, type) \ +struct name { \ + struct type *lh_first; /* first element */ \ +} + +#define LIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define LIST_ENTRY(type) \ +struct { \ + struct type *le_next; /* next element */ \ + struct type **le_prev; /* address of previous next element */ \ +} + +/* + * List functions. + */ +#define LIST_INIT(head) do { \ + (head)->lh_first = NULL; \ +} while (/*CONSTCOND*/0) + +#define LIST_INSERT_AFTER(listelm, elm, field) do { \ + if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \ + (listelm)->field.le_next->field.le_prev = \ + &(elm)->field.le_next; \ + (listelm)->field.le_next = (elm); \ + (elm)->field.le_prev = &(listelm)->field.le_next; \ +} while (/*CONSTCOND*/0) + +#define LIST_INSERT_BEFORE(listelm, elm, field) do { \ + (elm)->field.le_prev = (listelm)->field.le_prev; \ + (elm)->field.le_next = (listelm); \ + *(listelm)->field.le_prev = (elm); \ + (listelm)->field.le_prev = &(elm)->field.le_next; \ +} while (/*CONSTCOND*/0) + +#define LIST_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.le_next = (head)->lh_first) != NULL) \ + (head)->lh_first->field.le_prev = &(elm)->field.le_next;\ + (head)->lh_first = (elm); \ + (elm)->field.le_prev = &(head)->lh_first; \ +} while (/*CONSTCOND*/0) + +#define LIST_REMOVE(elm, field) do { \ + if ((elm)->field.le_next != NULL) \ + (elm)->field.le_next->field.le_prev = \ + (elm)->field.le_prev; \ + *(elm)->field.le_prev = (elm)->field.le_next; \ +} while (/*CONSTCOND*/0) + +#define LIST_FOREACH(var, head, field) \ + for ((var) = ((head)->lh_first); \ + (var); \ + (var) = ((var)->field.le_next)) + +/* + * List access methods. + */ +#define LIST_EMPTY(head) ((head)->lh_first == NULL) +#define LIST_FIRST(head) ((head)->lh_first) +#define LIST_NEXT(elm, field) ((elm)->field.le_next) + + +/* + * Singly-linked List definitions. + */ +#define SLIST_HEAD(name, type) \ +struct name { \ + struct type *slh_first; /* first element */ \ +} + +#define SLIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define SLIST_ENTRY(type) \ +struct { \ + struct type *sle_next; /* next element */ \ +} + +/* + * Singly-linked List functions. + */ +#define SLIST_INIT(head) do { \ + (head)->slh_first = NULL; \ +} while (/*CONSTCOND*/0) + +#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \ + (elm)->field.sle_next = (slistelm)->field.sle_next; \ + (slistelm)->field.sle_next = (elm); \ +} while (/*CONSTCOND*/0) + +#define SLIST_INSERT_HEAD(head, elm, field) do { \ + (elm)->field.sle_next = (head)->slh_first; \ + (head)->slh_first = (elm); \ +} while (/*CONSTCOND*/0) + +#define SLIST_REMOVE_HEAD(head, field) do { \ + (head)->slh_first = (head)->slh_first->field.sle_next; \ +} while (/*CONSTCOND*/0) + +#define SLIST_REMOVE(head, elm, type, field) do { \ + if ((head)->slh_first == (elm)) { \ + SLIST_REMOVE_HEAD((head), field); \ + } \ + else { \ + struct type *curelm = (head)->slh_first; \ + while(curelm->field.sle_next != (elm)) \ + curelm = curelm->field.sle_next; \ + curelm->field.sle_next = \ + curelm->field.sle_next->field.sle_next; \ + } \ +} while (/*CONSTCOND*/0) + +#define SLIST_FOREACH(var, head, field) \ + for((var) = (head)->slh_first; (var); (var) = (var)->field.sle_next) + +/* + * Singly-linked List access methods. + */ +#define SLIST_EMPTY(head) ((head)->slh_first == NULL) +#define SLIST_FIRST(head) ((head)->slh_first) +#define SLIST_NEXT(elm, field) ((elm)->field.sle_next) + + +/* + * Singly-linked Tail queue declarations. + */ +#define STAILQ_HEAD(name, type) \ +struct name { \ + struct type *stqh_first; /* first element */ \ + struct type **stqh_last; /* addr of last next element */ \ +} + +#define STAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).stqh_first } + +#define STAILQ_ENTRY(type) \ +struct { \ + struct type *stqe_next; /* next element */ \ +} + +/* + * Singly-linked Tail queue functions. + */ +#define STAILQ_INIT(head) do { \ + (head)->stqh_first = NULL; \ + (head)->stqh_last = &(head)->stqh_first; \ +} while (/*CONSTCOND*/0) + +#define STAILQ_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.stqe_next = (head)->stqh_first) == NULL) \ + (head)->stqh_last = &(elm)->field.stqe_next; \ + (head)->stqh_first = (elm); \ +} while (/*CONSTCOND*/0) + +#define STAILQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.stqe_next = NULL; \ + *(head)->stqh_last = (elm); \ + (head)->stqh_last = &(elm)->field.stqe_next; \ +} while (/*CONSTCOND*/0) + +#define STAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if (((elm)->field.stqe_next = (listelm)->field.stqe_next) == NULL)\ + (head)->stqh_last = &(elm)->field.stqe_next; \ + (listelm)->field.stqe_next = (elm); \ +} while (/*CONSTCOND*/0) + +#define STAILQ_REMOVE_HEAD(head, field) do { \ + if (((head)->stqh_first = (head)->stqh_first->field.stqe_next) == NULL) \ + (head)->stqh_last = &(head)->stqh_first; \ +} while (/*CONSTCOND*/0) + +#define STAILQ_REMOVE(head, elm, type, field) do { \ + if ((head)->stqh_first == (elm)) { \ + STAILQ_REMOVE_HEAD((head), field); \ + } else { \ + struct type *curelm = (head)->stqh_first; \ + while (curelm->field.stqe_next != (elm)) \ + curelm = curelm->field.stqe_next; \ + if ((curelm->field.stqe_next = \ + curelm->field.stqe_next->field.stqe_next) == NULL) \ + (head)->stqh_last = &(curelm)->field.stqe_next; \ + } \ +} while (/*CONSTCOND*/0) + +#define STAILQ_FOREACH(var, head, field) \ + for ((var) = ((head)->stqh_first); \ + (var); \ + (var) = ((var)->field.stqe_next)) + +#define STAILQ_CONCAT(head1, head2) do { \ + if (!STAILQ_EMPTY((head2))) { \ + *(head1)->stqh_last = (head2)->stqh_first; \ + (head1)->stqh_last = (head2)->stqh_last; \ + STAILQ_INIT((head2)); \ + } \ +} while (/*CONSTCOND*/0) + +/* + * Singly-linked Tail queue access methods. + */ +#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL) +#define STAILQ_FIRST(head) ((head)->stqh_first) +#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next) + + +/* + * Simple queue definitions. + */ +#define SIMPLEQ_HEAD(name, type) \ +struct name { \ + struct type *sqh_first; /* first element */ \ + struct type **sqh_last; /* addr of last next element */ \ +} + +#define SIMPLEQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).sqh_first } + +#define SIMPLEQ_ENTRY(type) \ +struct { \ + struct type *sqe_next; /* next element */ \ +} + +/* + * Simple queue functions. + */ +#define SIMPLEQ_INIT(head) do { \ + (head)->sqh_first = NULL; \ + (head)->sqh_last = &(head)->sqh_first; \ +} while (/*CONSTCOND*/0) + +#define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \ + (head)->sqh_last = &(elm)->field.sqe_next; \ + (head)->sqh_first = (elm); \ +} while (/*CONSTCOND*/0) + +#define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.sqe_next = NULL; \ + *(head)->sqh_last = (elm); \ + (head)->sqh_last = &(elm)->field.sqe_next; \ +} while (/*CONSTCOND*/0) + +#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\ + (head)->sqh_last = &(elm)->field.sqe_next; \ + (listelm)->field.sqe_next = (elm); \ +} while (/*CONSTCOND*/0) + +#define SIMPLEQ_REMOVE_HEAD(head, field) do { \ + if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \ + (head)->sqh_last = &(head)->sqh_first; \ +} while (/*CONSTCOND*/0) + +#define SIMPLEQ_REMOVE(head, elm, type, field) do { \ + if ((head)->sqh_first == (elm)) { \ + SIMPLEQ_REMOVE_HEAD((head), field); \ + } else { \ + struct type *curelm = (head)->sqh_first; \ + while (curelm->field.sqe_next != (elm)) \ + curelm = curelm->field.sqe_next; \ + if ((curelm->field.sqe_next = \ + curelm->field.sqe_next->field.sqe_next) == NULL) \ + (head)->sqh_last = &(curelm)->field.sqe_next; \ + } \ +} while (/*CONSTCOND*/0) + +#define SIMPLEQ_FOREACH(var, head, field) \ + for ((var) = ((head)->sqh_first); \ + (var); \ + (var) = ((var)->field.sqe_next)) + +/* + * Simple queue access methods. + */ +#define SIMPLEQ_EMPTY(head) ((head)->sqh_first == NULL) +#define SIMPLEQ_FIRST(head) ((head)->sqh_first) +#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next) + + +/* + * Tail queue definitions. + */ +#define _TAILQ_HEAD(name, type, qual) \ +struct name { \ + qual type *tqh_first; /* first element */ \ + qual type *qual *tqh_last; /* addr of last next element */ \ +} +#define TAILQ_HEAD(name, type) _TAILQ_HEAD(name, struct type,) + +#define TAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).tqh_first } + +#define _TAILQ_ENTRY(type, qual) \ +struct { \ + qual type *tqe_next; /* next element */ \ + qual type *qual *tqe_prev; /* address of previous next element */\ +} +#define TAILQ_ENTRY(type) _TAILQ_ENTRY(struct type,) + +/* + * Tail queue functions. + */ +#define TAILQ_INIT(head) do { \ + (head)->tqh_first = NULL; \ + (head)->tqh_last = &(head)->tqh_first; \ +} while (/*CONSTCOND*/0) + +#define TAILQ_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \ + (head)->tqh_first->field.tqe_prev = \ + &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (head)->tqh_first = (elm); \ + (elm)->field.tqe_prev = &(head)->tqh_first; \ +} while (/*CONSTCOND*/0) + +#define TAILQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.tqe_next = NULL; \ + (elm)->field.tqe_prev = (head)->tqh_last; \ + *(head)->tqh_last = (elm); \ + (head)->tqh_last = &(elm)->field.tqe_next; \ +} while (/*CONSTCOND*/0) + +#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\ + (elm)->field.tqe_next->field.tqe_prev = \ + &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (listelm)->field.tqe_next = (elm); \ + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \ +} while (/*CONSTCOND*/0) + +#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ + (elm)->field.tqe_next = (listelm); \ + *(listelm)->field.tqe_prev = (elm); \ + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ +} while (/*CONSTCOND*/0) + +#define TAILQ_REMOVE(head, elm, field) do { \ + if (((elm)->field.tqe_next) != NULL) \ + (elm)->field.tqe_next->field.tqe_prev = \ + (elm)->field.tqe_prev; \ + else \ + (head)->tqh_last = (elm)->field.tqe_prev; \ + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ +} while (/*CONSTCOND*/0) + +#define TAILQ_FOREACH(var, head, field) \ + for ((var) = ((head)->tqh_first); \ + (var); \ + (var) = ((var)->field.tqe_next)) + +#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ + for ((var) = (*(((struct headname *)((head)->tqh_last))->tqh_last)); \ + (var); \ + (var) = (*(((struct headname *)((var)->field.tqe_prev))->tqh_last))) + +#define TAILQ_CONCAT(head1, head2, field) do { \ + if (!TAILQ_EMPTY(head2)) { \ + *(head1)->tqh_last = (head2)->tqh_first; \ + (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \ + (head1)->tqh_last = (head2)->tqh_last; \ + TAILQ_INIT((head2)); \ + } \ +} while (/*CONSTCOND*/0) + +/* + * Tail queue access methods. + */ +#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL) +#define TAILQ_FIRST(head) ((head)->tqh_first) +#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) + +#define TAILQ_LAST(head, headname) \ + (*(((struct headname *)((head)->tqh_last))->tqh_last)) +#define TAILQ_PREV(elm, headname, field) \ + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) + + +/* + * Circular queue definitions. + */ +#define CIRCLEQ_HEAD(name, type) \ +struct name { \ + struct type *cqh_first; /* first element */ \ + struct type *cqh_last; /* last element */ \ +} + +#define CIRCLEQ_HEAD_INITIALIZER(head) \ + { (void *)&head, (void *)&head } + +#define CIRCLEQ_ENTRY(type) \ +struct { \ + struct type *cqe_next; /* next element */ \ + struct type *cqe_prev; /* previous element */ \ +} + +/* + * Circular queue functions. + */ +#define CIRCLEQ_INIT(head) do { \ + (head)->cqh_first = (void *)(head); \ + (head)->cqh_last = (void *)(head); \ +} while (/*CONSTCOND*/0) + +#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ + (elm)->field.cqe_next = (listelm)->field.cqe_next; \ + (elm)->field.cqe_prev = (listelm); \ + if ((listelm)->field.cqe_next == (void *)(head)) \ + (head)->cqh_last = (elm); \ + else \ + (listelm)->field.cqe_next->field.cqe_prev = (elm); \ + (listelm)->field.cqe_next = (elm); \ +} while (/*CONSTCOND*/0) + +#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \ + (elm)->field.cqe_next = (listelm); \ + (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \ + if ((listelm)->field.cqe_prev == (void *)(head)) \ + (head)->cqh_first = (elm); \ + else \ + (listelm)->field.cqe_prev->field.cqe_next = (elm); \ + (listelm)->field.cqe_prev = (elm); \ +} while (/*CONSTCOND*/0) + +#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \ + (elm)->field.cqe_next = (head)->cqh_first; \ + (elm)->field.cqe_prev = (void *)(head); \ + if ((head)->cqh_last == (void *)(head)) \ + (head)->cqh_last = (elm); \ + else \ + (head)->cqh_first->field.cqe_prev = (elm); \ + (head)->cqh_first = (elm); \ +} while (/*CONSTCOND*/0) + +#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.cqe_next = (void *)(head); \ + (elm)->field.cqe_prev = (head)->cqh_last; \ + if ((head)->cqh_first == (void *)(head)) \ + (head)->cqh_first = (elm); \ + else \ + (head)->cqh_last->field.cqe_next = (elm); \ + (head)->cqh_last = (elm); \ +} while (/*CONSTCOND*/0) + +#define CIRCLEQ_REMOVE(head, elm, field) do { \ + if ((elm)->field.cqe_next == (void *)(head)) \ + (head)->cqh_last = (elm)->field.cqe_prev; \ + else \ + (elm)->field.cqe_next->field.cqe_prev = \ + (elm)->field.cqe_prev; \ + if ((elm)->field.cqe_prev == (void *)(head)) \ + (head)->cqh_first = (elm)->field.cqe_next; \ + else \ + (elm)->field.cqe_prev->field.cqe_next = \ + (elm)->field.cqe_next; \ +} while (/*CONSTCOND*/0) + +#define CIRCLEQ_FOREACH(var, head, field) \ + for ((var) = ((head)->cqh_first); \ + (var) != (const void *)(head); \ + (var) = ((var)->field.cqe_next)) + +#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \ + for ((var) = ((head)->cqh_last); \ + (var) != (const void *)(head); \ + (var) = ((var)->field.cqe_prev)) + +/* + * Circular queue access methods. + */ +#define CIRCLEQ_EMPTY(head) ((head)->cqh_first == (void *)(head)) +#define CIRCLEQ_FIRST(head) ((head)->cqh_first) +#define CIRCLEQ_LAST(head) ((head)->cqh_last) +#define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next) +#define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev) + +#define CIRCLEQ_LOOP_NEXT(head, elm, field) \ + (((elm)->field.cqe_next == (void *)(head)) \ + ? ((head)->cqh_first) \ + : (elm->field.cqe_next)) +#define CIRCLEQ_LOOP_PREV(head, elm, field) \ + (((elm)->field.cqe_prev == (void *)(head)) \ + ? ((head)->cqh_last) \ + : (elm->field.cqe_prev)) + +#endif /* sys/queue.h */ diff --git a/common/utils/itti_analyzer/rc.h b/common/utils/itti_analyzer/rc.h new file mode 100644 index 0000000000..174f725c11 --- /dev/null +++ b/common/utils/itti_analyzer/rc.h @@ -0,0 +1,47 @@ +#include <errno.h> +#include <string.h> + +#ifndef RC_H_ +#define RC_H_ + +#define RC_OK 0 +#define RC_FAIL -1 +#define RC_BAD_PARAM -2 +#define RC_NULL_POINTER -3 + +#define CHECK_FCT(fCT) \ +do { \ + int rET; \ + if ((rET = fCT) != RC_OK) { \ + fprintf(stderr, #fCT" has failed (%s:%d)\n", __FILE__, __LINE__); \ + return rET; \ + } \ +} while(0) + +#define CHECK_FCT_POSIX(fCT) \ +do { \ + if (fCT == -1) { \ + fprintf(stderr, #fCT" has failed (%d:%s) (%s:%d)\n", errno, \ + strerror(errno), __FILE__, __LINE__); \ + return RC_FAIL; \ + } \ +} while(0) + +#define CHECK_FCT_DO(fCT, dO) \ +do { \ + int rET; \ + if ((rET = fCT) != RC_OK) { \ + fprintf(stderr, #fCT" has returned %d (%s:%d)\n", rET, __FILE__, __LINE__); \ + dO; \ + } \ +} while(0) + +#define CHECK_BUFFER(bUFFER) \ +do { \ + if ((bUFFER) == NULL) { \ + fprintf(stderr, #bUFFER" is NULL (%s:%d)\n", __FILE__, __LINE__); \ + return RC_NULL_POINTER; \ + } \ +} while(0) + +#endif /* RC_H_ */ -- GitLab