pax_global_header00006660000000000000000000000064136635146410014523gustar00rootroot0000000000000052 comment=388605e86ed6140be6f05d116a40e7fed57db7db purple-lurch-0.6.8+git20200527.388605/000077500000000000000000000000001366351464100163355ustar00rootroot00000000000000purple-lurch-0.6.8+git20200527.388605/.appveyor.yml000066400000000000000000000014721366351464100210070ustar00rootroot00000000000000version: 0.6.9-dev-{build} image: Ubuntu1804 install: - sh: sudo apt-get update - sh: sudo apt-get install -y git cmake libpurple-dev libmxml-dev libxml2-dev libsqlite3-dev libgcrypt20-dev build-essential libglib2.0-dev libcmocka-dev --no-install-recommends - sh: git submodule update --init --recursive build_script: - sh: make test_script: - sh: CMOCKA_MESSAGE_OUTPUT=XML CMOCKA_XML_FILE=build/cmocka_results_%g.xml make test --ignore-errors after_test: - sh: find build/ -type f -name *.xml -exec curl -v -F "file=@$APPVEYOR_BUILD_FOLDER/{}" "https://ci.appveyor.com/api/testresults/junit/$APPVEYOR_JOB_ID" \; - sh: bash <(curl -s https://codecov.io/bash) -g test/ -B $APPVEYOR_REPO_BRANCH -b $APPVEYOR_BUILD_VERSION artifacts: - path: build/lurch.so name: lurch-$APPVEYOR_BUILD_VERSION-$APPVEYOR_REPO_COMMIT.sopurple-lurch-0.6.8+git20200527.388605/.gitignore000066400000000000000000000000201366351464100203150ustar00rootroot00000000000000build/ .vscode/ purple-lurch-0.6.8+git20200527.388605/.gitmodules000066400000000000000000000001671366351464100205160ustar00rootroot00000000000000[submodule "lib/axc"] path = lib/axc url = ../axc [submodule "lib/libomemo"] path = lib/libomemo url = ../libomemo purple-lurch-0.6.8+git20200527.388605/LICENSE000066400000000000000000001045141366351464100173470ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . purple-lurch-0.6.8+git20200527.388605/Makefile000066400000000000000000000142171366351464100200020ustar00rootroot00000000000000### toolchain # CC ?= gcc PKG_CONFIG ?= pkg-config XML2_CONFIG ?= xml2-config LIBGCRYPT_CONFIG ?= libgcrypt-config MKDIR = mkdir MKDIR_P = mkdir -p INSTALL = install INSTALL_LIB = $(INSTALL) -m 755 INSTALL_DIR = $(INSTALL) -d -m 755 RM = rm RM_RF = $(RM) -rf CMAKE ?= cmake CMAKE_FLAGS = -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS=-fPIC ### flags # GLIB_CFLAGS ?= $(shell $(PKG_CONFIG) --cflags glib-2.0) GLIB_LDFLAGS ?= $(shell $(PKG_CONFIG) --libs glib-2.0) LIBPURPLE_CFLAGS=$(shell $(PKG_CONFIG) --cflags purple) PURPLE_DIR=$(shell $(PKG_CONFIG) --variable=plugindir purple) LIBPURPLE_LDFLAGS=$(shell $(PKG_CONFIG) --cflags purple) \ -L$(PURPLE_DIR) XML2_CFLAGS ?= $(shell $(XML2_CONFIG) --cflags) XML2_LDFLAGS ?= $(shell $(XML2_CONFIG) --libs) LIBGCRYPT_LDFLAGS ?= $(shell $(LIBGCRYPT_CONFIG) --libs) PKGCFG_C=$(GLIB_CFLAGS) \ $(LIBPURPLE_CFLAGS) \ $(XML2_CFLAGS) PKGCFG_L=$(shell $(PKG_CONFIG) --libs sqlite3 mxml) \ $(GLIB_LDFLAGS) \ $(LIBPURPLE_LDFLAGS) \ $(XML2_LDFLAGS) \ $(LIBGCRYPT_LDFLAGS) ifneq ("$(wildcard /etc/redhat-release)","") LJABBER= -lxmpp else ifneq ("$(wildcard /etc/SuSE-release)","") LJABBER= -lxmpp else LJABBER= -ljabber endif endif HEADERS=-I$(HDIR)/jabber -I$(LOMEMO_SRC) -I$(AXC_SRC) -I$(AX_DIR)/src CFLAGS += -std=c11 -Wall -g -Wstrict-overflow $(PKGCFG_C) $(HEADERS) PLUGIN_CPPFLAGS=-DPURPLE_PLUGINS # -D_BSD_SOURCE can be removed once nobody uses glibc <= 2.18 any more CPPFLAGS += -D_XOPEN_SOURCE=700 -D_BSD_SOURCE -D_DEFAULT_SOURCE LDFLAGS += -ldl -lm $(PKGCFG_L) $(LJABBER) -Wl,-rpath,$(PURPLE_PLUGIN_DIR) LDFLAGS_T=$(LDFLAGS) -lpurple -lcmocka ### directories # PURPLE_HOME_PLUGIN_DIR=$(HOME)/.purple/plugins PURPLE_PLUGIN_DIR = $(shell $(PKG_CONFIG) --variable=plugindir purple) LDIR=./lib BDIR=./build SDIR=./src HDIR=./headers TDIR=./test LOMEMO_DIR=$(LDIR)/libomemo LOMEMO_SRC=$(LOMEMO_DIR)/src LOMEMO_BUILD=$(LOMEMO_DIR)/build LOMEMO_PATH=$(LOMEMO_BUILD)/libomemo-conversations.a AXC_DIR=$(LDIR)/axc AXC_SRC=$(AXC_DIR)/src AXC_BUILD=$(AXC_DIR)/build AXC_PATH=$(AXC_BUILD)/libaxc-nt.a AX_DIR=$(AXC_DIR)/lib/libsignal-protocol-c AX_PATH=$(AX_DIR)/build/src/libsignal-protocol-c.a SOURCES := $(wildcard $(SDIR)/*.c) OBJECTS := $(patsubst $(SDIR)/%.c, $(BDIR)/%.o, $(SOURCES)) OBJECTS_W_COVERAGE := $(patsubst $(SDIR)/%.c, $(BDIR)/%_w_coverage.o, $(SOURCES)) TEST_SOURCES := $(wildcard $(TDIR)/test_*.c) TEST_OBJECTS := $(patsubst $(TDIR)/test_%.c, $(BDIR)/test_%.o, $(TEST_SOURCES)) TEST_TARGETS := $(patsubst $(TDIR)/test_%.c, $(BDIR)/test_%, $(TEST_SOURCES)) VENDOR_LIBS=$(LOMEMO_PATH) $(AXC_PATH) $(AX_PATH) ### make rules # all: $(BDIR)/lurch.so $(BDIR): $(MKDIR_P) build $(AX_PATH): cd $(AX_DIR)/ && \ $(MKDIR_P) build && \ cd build && \ $(CMAKE) $(CMAKE_FLAGS) .. \ && $(MAKE) $(AXC_PATH): $(MAKE) -C "$(AXC_DIR)" build/libaxc-nt.a $(LOMEMO_PATH): $(MAKE) -C "$(LOMEMO_DIR)" build/libomemo-conversations.a $(BDIR)/%.o: $(SDIR)/%.c | $(BDIR) $(CC) -fPIC $(CFLAGS) $(CPPFLAGS) $(PLUGIN_CPPFLAGS) -c $(SDIR)/$*.c -o $@ $(BDIR)/%_w_coverage.o: $(SDIR)/%.c | $(BDIR) $(CC) -O0 --coverage $(CFLAGS) $(CPPFLAGS) $(PLUGIN_CPPFLAGS) -c $(SDIR)/$*.c -o $@ $(BDIR)/test_%.o: $(TDIR)/test_%.c | $(BDIR) $(CC) $(CFLAGS) -O0 -c $(TDIR)/test_$*.c -o $@ $(BDIR)/lurch.so: $(OBJECTS) $(VENDOR_LIBS) $(CC) -fPIC -shared $(CFLAGS) $(CPPFLAGS) $(PLUGIN_CPPFLAGS) \ $^ \ -o $@ $(LDFLAGS) $(BDIR)/lurch.a: $(BDIR)/lurch.o $(VENDOR_LIBS) $(AR) rcs $@ $^ install: $(BDIR)/lurch.so [ -e "$(DESTDIR)/$(PURPLE_PLUGIN_DIR)" ] || \ $(INSTALL_DIR) "$(DESTDIR)/$(PURPLE_PLUGIN_DIR)" $(INSTALL_LIB) "$(BDIR)/lurch.so" "$(DESTDIR)/$(PURPLE_PLUGIN_DIR)/lurch.so" install-home: $(BDIR)/lurch.so [ -e "$(PURPLE_HOME_PLUGIN_DIR)" ] || \ $(INSTALL_DIR) "$(PURPLE_HOME_PLUGIN_DIR)" $(INSTALL_LIB) "$(BDIR)/lurch.so" "$(PURPLE_HOME_PLUGIN_DIR)/lurch.so" LURCH_VERSION ?= 0.0.0 TARBALL_DIR_NAME=lurch-$(LURCH_VERSION) TARBALL_FILE_NAME=$(TARBALL_DIR_NAME)-src.tar.gz tarball: | clean-all $(BDIR) $(MKDIR) $(TARBALL_DIR_NAME) rsync -av --progress . $(TARBALL_DIR_NAME)/ --exclude $(TARBALL_DIR_NAME)/ --exclude-from=.gitignore -find $(TARBALL_DIR_NAME)/ -name "*.git*" -exec rm -rf "{}" \; tar czf $(TARBALL_FILE_NAME) $(TARBALL_DIR_NAME)/ mv $(TARBALL_FILE_NAME) $(TARBALL_DIR_NAME)/ mv $(TARBALL_DIR_NAME) $(BDIR)/ $(BDIR)/test_lurch_util: $(OBJECTS_W_COVERAGE) $(VENDOR_LIBS) $(BDIR)/test_lurch_util.o $(CC) $(CFLAGS) $(CPPFLAGS) -O0 --coverage $^ $(PURPLE_DIR)/libjabber.so.0 -o $@ $(LDFLAGS_T) \ -Wl,--wrap=purple_user_dir \ -Wl,--wrap=purple_prefs_get_bool \ -Wl,--wrap=purple_prefs_get_int \ -Wl,--wrap=purple_debug_error \ -Wl,--wrap=purple_debug_info \ -Wl,--wrap=purple_debug_misc \ -Wl,--wrap=purple_base16_encode_chunked bash -c "set -o pipefail; $@ 2>&1 | grep -Ev ".*CRITICAL.*" | tr -s '\n'" # filter annoying and irrelevant glib output $(BDIR)/test_lurch_api: $(OBJECTS_W_COVERAGE) $(VENDOR_LIBS) $(BDIR)/test_lurch_api.o $(CC) $(CFLAGS) $(CPPFLAGS) -O0 --coverage $^ $(PURPLE_DIR)/libjabber.so.0 -o $@ $(LDFLAGS_T) \ -Wl,--wrap=purple_account_get_username \ -Wl,--wrap=purple_account_get_connection \ -Wl,--wrap=purple_signal_register \ -Wl,--wrap=purple_signal_unregister \ -Wl,--wrap=purple_signal_connect \ -Wl,--wrap=purple_signal_disconnect \ -Wl,--wrap=purple_find_conversation_with_account \ -Wl,--wrap=jabber_pep_publish \ -Wl,--wrap=jabber_chat_find_by_conv \ -Wl,--wrap=axc_get_device_id \ -Wl,--wrap=axc_key_load_public_own \ -Wl,--wrap=axc_key_load_public_addr \ -Wl,--wrap=axc_session_exists_any \ -Wl,--wrap=omemo_storage_user_devicelist_retrieve \ -Wl,--wrap=omemo_storage_chatlist_delete \ -Wl,--wrap=omemo_storage_chatlist_save \ -Wl,--wrap=omemo_storage_chatlist_exists \ -Wl,--wrap=omemo_storage_user_devicelist_retrieve \ -Wl,--wrap=lurch_util_fp_get_printable bash -c "set -o pipefail; $@ 2>&1 | grep -Ev ".*CRITICAL.*" | tr -s '\n'" # filter annoying and irrelevant glib output test: $(OBJECTS_W_COVERAGE) $(VENDOR_LIBS) $(TEST_TARGETS) coverage: test gcovr -r . --html --html-details -o build/coverage.html gcovr -r . -s clean: $(RM_RF) "$(BDIR)" clean-all: clean $(MAKE) -C "$(LOMEMO_DIR)" clean $(MAKE) -C "$(AXC_DIR)" clean-all .PHONY: clean clean-all install install-home tarball test coverage purple-lurch-0.6.8+git20200527.388605/README.md000066400000000000000000000250661366351464100176250ustar00rootroot00000000000000# lurch 0.6.9-dev /lʊʁç/. In German, an Axolotl is a type of Lurch, which simply means 'amphibian'. This plugin brings _Axolotl_, by now renamed to _double ratchet_, to _libpurple_ applications such as [Pidgin](https://www.pidgin.im/) by implementing the [XEP-0384: OMEMO Encryption](https://xmpp.org/extensions/xep-0384.html). For a higher-level overview, see [the official OMEMO homepage](https://conversations.im/omemo/). (Plus I thought the word sounds funny.) ## News I rewrote how MUCs are handled and they should work much better now. If not, feel free to open an issue, as usual. The first Windows build of 0.6.6 was missing a compile-time flag, so if it does not work for you download it again, or get this version once available. Version 0.2 of the _OMEMO XEP_ adopted the namespace actually implemented by all the clients, so there is no need for a 'compatible' version of the plugin any longer. This mostly concerns Windows users who used the `lurch_compat.dll`, so don't be confused if it's not there. If you use a version <0.6.5, you should still definitely update for security reasons. ## Table of Contents 1. [Installation](#installation) 1. [Linux](#linux) 1. [Windows](#windows) 1. [MacOS](#macos) 1. [Additional plugins](#additional-plugins) 1. [Usage](#usage) 1. [General](#general) 1. [Group Chats](#group-chats) 1. [Uninstallation](#uninstallation) 1. [Troubleshooting](#troubleshooting) 1. [FAQ](#faq) 1. [Caveats](#caveats) ## Installation ### Linux ##### 1. Install the (submodules') dependencies Below you can find the command to install the dependencies for popular distribution families. Make sure that you use at least version 2.7 of _mxml_, and 2.10.10 of _libpurple_. __Debian, Ubuntu__ ``` bash sudo apt install git cmake libpurple-dev libmxml-dev libxml2-dev libsqlite3-dev libgcrypt20-dev build-essential ``` __ArchLinux, Parabola__ ``` bash sudo pacman -S base-devel git cmake pidgin libpurple mxml libxml2 sqlite libgcrypt ``` __Fedora__ ``` bash sudo dnf install git cmake libpurple-devel mxml-devel libxml2-devel libsqlite3x-devel libgcrypt-devel ``` ##### 2A. EITHER: Build and install from source ``` bash git clone https://github.com/gkdr/lurch/ cd lurch git submodule update --init --recursive make install-home ``` If you just pull a newer version (`git pull`), remember to also update the submodules as they might have changed! The last command compiles the whole thing and copies the plugin into your local _libpurple_ plugin directory. The next time you start Pidgin, or another libpurple client, you should be able to activate it in the "Plugins" window. ##### 2B. OR: Install from a community repo * Arch - AUR: https://aur.archlinux.org/packages/libpurple-lurch-git/ * Fedora - COPR: https://copr.fedorainfracloud.org/coprs/treba/pidgin-lurch/ ### Windows Thanks to [EionRobb](https://github.com/EionRobb), Windows users can use the dlls he compiled and provides here: https://eion.robbmob.com/lurch/ 1. Download the plugin (_lurch.dll_) and put it in the `Program Files (x86)\Pidgin\plugins` directory. 2. Download _libgcrypt-20.dll_ and _libgpg-error-0.dll_ and put them in the `Program Files (x86)\Pidgin` directory. These instructions can also be found at the provided link. ### MacOS Homebrew should have all dependencies: ``` brew install cmake pidgin glib libxml2 libmxml sqlite libgcrypt ``` This should work on newer versions of MacOS, but if you run into problems check out [#8](https://github.com/gkdr/lurch/issues/8#issuecomment-285937828) for some hints. Complete instructions on how to get this running with Pidgin appreciated! Alternatively, if you use Adium, you should definitely check out [shtrom](https://github.com/shtrom)'s [Lurch4Adium](https://github.com/shtrom/Lurch4Adium)! ### Additional plugins The current version of _libpurple_'s _XMPP_ protocol plugin does not support many _XEPs_ by itself. For more features and compatibility with other clients such as _Conversations_ you can install the pulgins below. #### carbons If you have multiple devices and want messages sent and received by one device show up on all others, [XEP-0280: Message Carbons](https://xmpp.org/extensions/xep-0280.html) is what you are looking for. You can find my plugin for it here: https://github.com/gkdr/carbons #### pidgin-xmpp-receipts In order to support the checkmarks for delivered messages, you could install this plugin implementing [XEP-0184: Message Delivery Receipts](https://xmpp.org/extensions/xep-0184.html): https://app.assembla.com/spaces/pidgin-xmpp-receipts/git/source ## Usage ### General The first thing you can do to check if this plugin works is enter the `/lurch help` command in any conversation window. You will receive a list of the other commands you can use. I know this is a bit clunky, but using the command interface for interactions makes the plugin usable in clients that do not have a GUI. After you have made sure it was installed correctly, you do not have to activate it specifically for each conversation partner you want to use it with, unlike with e.g. _OTR_. If it detects that the other side is using _OMEMO_ (by the existence of an _OMEMO_ devicelist), the conversation will be encrypted automatically. If you do not want this, you can blacklist the user by typing `/lurch blacklist add` in the conversation window. This plugin will set the window title to notify the user if encryption is enabled or not. If it is, it will generally not send plaintext messages. If a plaintext message is received in a chat that is supposed to be encrypted, the user will be warned. ### Group Chats Group chats (via [XEP-0045: Multi-User Chat](https://xmpp.org/extensions/xep-0045.html) aka MUCs) are __not__ part of the _OMEMO_ specification, but can work under specific circumstances as outlined on the [_Conversations_ README](https://github.com/siacs/Conversations/blob/master/README.md#omemo). These are: * The MUC has to be non-anonymous so the real JID of each participant is visible. The channel owner has to set this property. In Pidgin you can get there by typing `/config`. * Every participant has to be in every other participant's contact list! This is why this really only makes sense for member-only MUCs. Once you have confirmed these conditions are met, every member has to activate _OMEMO_ him- or herself. Using this plugin it works by typing `/lurch enable`. Warning messages are displayed if it does not work for every user in the conference, hopefully helping to fix the issue. It is __recommended__ you confirm the fingerprints look the same on each device, including among your own. To do this, you can e.g. display all fingerprints participating in a conversation using `/lurch show fp conv`. ## Uninstallation In order to uninstall this plugin, you should call the `/lurch uninstall` command. It will remove this client from the _OMEMO_ device list, notifying other _OMEMO_ clients that they do not need to encrypt messages for it any longer. Afterwards, you can just deactivate the plugin in the _Tools > Plugins_ window. In order to completely remove all data related to this plugin, e.g. for a fresh installation, you will need to delete the following files from your _.purple_ directory: * _your@xmpp.account_omemo_db.sqlite_ to delete the device list cache * _your@xmpp.account_axc_db.sqlite_ to delete your keypair and all sessions with other devices * and finally, _lurch.[so|dll]_ found in the _plugins_ directory ## Troubleshooting If something does not work as expected, don't hesitate to open an issue. You can also reach me on the Pidgin IRC channel (#pidgin on freenode) as `riba`, or send me an email. It will usually be helpful (i.e. I will probably ask for it anyway) if you provide me with some information from the debug log, which you can find at _Help > Debug Window_ in Pidgin. There, you will see a scary error from the XML parser every time you receive a message, which you can safely ignore. It is due to the nonstandard namespace used by _OMEMO_ and looks something like this: `jabber: XML parser error for JabberStream 0x5631ed678670: Domain 3, code 100, level 1: xmlns: URI eu.siacs.conversations.axolotl is not absolute`. In addition to just reading logs, you can get a bit more active, as again I will probably ask for this anyway. Pidgin comes with an XMPP console, but you have to activate the plugin first (_Tools > Plugins_). Afterwards you can find it at _Tools > XMPP Console_ and send queries to the server. If you are having trouble sending or receiving messages, you should look up if you can find the device in the _device list_. You can do so by pasting the following into the XMPP console, replacing the `to` attribute with the device's owner's JID: ```XML ``` Sometimes, a device might be on the list, but it did not publish a _bundle_, which is necessary to establish a session. In this case, you can query this bundle by pasting the following, replacing the `to` attribute as well as the `DEVICE_ID` suffix of the `bundles` node: ```XML ``` Finally, in case it is more serious and Pidgin crashes, I will have to ask you for a backtrace. You can obtain it in the following way: * Open Pidgin in gdb: `gdb pidgin` * Run it: `run` * Do whatever you were doing to make it crash * When it does crash, type `bt` (or `backtrace`) * Copy the whole thing ## FAQ ### Can it talk to other OMEMO clients? __Yes__, it was (briefly) tested with: * [Conversations](https://conversations.im/) (Android) * [The gajim OMEMO plugin](https://dev.gajim.org/gajim/gajim-plugins/wikis/OmemoGajimPlugin) (Desktop OSs) * [ChatSecure](https://chatsecure.org/) (iOS) See https://omemo.top/ for additional clients. ### Does it work with Finch? It should, but I only tried it briefly. ## Caveats _OMEMO_ is not 'whatever Conversations can do', but a very specific _XEP_. For instance, if you don't install the additional plugin mentioned above, this is probably not the right thing to use if you have multiple clients running at the same time, as there is no message carbons support in libpurple as of now. At the moment, there is no [XEP-0313: Message Archive Management](https://xmpp.org/extensions/xep-0313.html) aka _MAM_ support in _libpurple_, so there are no 'offline messages'. Finally, I can't stress this enough: This plugin is _highly experimental_, so you __should not trust your life on it__. purple-lurch-0.6.8+git20200527.388605/headers/000077500000000000000000000000001366351464100177505ustar00rootroot00000000000000purple-lurch-0.6.8+git20200527.388605/headers/jabber/000077500000000000000000000000001366351464100211755ustar00rootroot00000000000000purple-lurch-0.6.8+git20200527.388605/headers/jabber/adhoccommands.h000066400000000000000000000032241366351464100241470ustar00rootroot00000000000000/* * purple - Jabber Protocol Plugin * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA * */ #ifndef PURPLE_JABBER_ADHOCCOMMANDS_H_ #define PURPLE_JABBER_ADHOCCOMMANDS_H_ #include "jabber.h" /* Implementation of XEP-0050 */ void jabber_adhoc_disco_result_cb(JabberStream *js, const char *from, JabberIqType type, const char *id, xmlnode *packet, gpointer data); void jabber_adhoc_execute(JabberStream *js, JabberAdHocCommands *cmd); void jabber_adhoc_execute_action(PurpleBlistNode *node, gpointer data); void jabber_adhoc_got_list(JabberStream *js, const char *from, xmlnode *query); void jabber_adhoc_server_get_list(JabberStream *js); void jabber_adhoc_init_server_commands(JabberStream *js, GList **m); #endif /* PURPLE_JABBER_ADHOCCOMMANDS_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/auth.h000066400000000000000000000050631366351464100223130ustar00rootroot00000000000000/** * @file auth.h Authentication routines * * purple * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #ifndef PURPLE_JABBER_AUTH_H_ #define PURPLE_JABBER_AUTH_H_ typedef struct _JabberSaslMech JabberSaslMech; #include "jabber.h" #include "xmlnode.h" typedef enum { JABBER_SASL_STATE_FAIL = -1, /* Abort, Retry, Fail? */ JABBER_SASL_STATE_OK = 0, /* Hooray! */ JABBER_SASL_STATE_CONTINUE = 1 /* More authentication required */ } JabberSaslState; struct _JabberSaslMech { gint8 priority; /* Higher priority will be tried before lower priority */ const gchar *name; JabberSaslState (*start)(JabberStream *js, xmlnode *mechanisms, xmlnode **reply, char **msg); JabberSaslState (*handle_challenge)(JabberStream *js, xmlnode *packet, xmlnode **reply, char **msg); JabberSaslState (*handle_success)(JabberStream *js, xmlnode *packet, char **msg); JabberSaslState (*handle_failure)(JabberStream *js, xmlnode *packet, xmlnode **reply, char **msg); void (*dispose)(JabberStream *js); }; void jabber_auth_start(JabberStream *js, xmlnode *packet); void jabber_auth_start_old(JabberStream *js); void jabber_auth_handle_challenge(JabberStream *js, xmlnode *packet); void jabber_auth_handle_success(JabberStream *js, xmlnode *packet); void jabber_auth_handle_failure(JabberStream *js, xmlnode *packet); JabberSaslMech *jabber_auth_get_plain_mech(void); JabberSaslMech *jabber_auth_get_digest_md5_mech(void); JabberSaslMech **jabber_auth_get_scram_mechs(gint *count); #ifdef HAVE_CYRUS_SASL JabberSaslMech *jabber_auth_get_cyrus_mech(void); #endif void jabber_auth_add_mech(JabberSaslMech *); void jabber_auth_remove_mech(JabberSaslMech *); void jabber_auth_init(void); void jabber_auth_uninit(void); #endif /* PURPLE_JABBER_AUTH_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/auth_digest_md5.h000066400000000000000000000025631366351464100244210ustar00rootroot00000000000000/** * @file auth_digest_md5.h Implementation of SASL DIGEST-MD5 authentication * * purple * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #ifndef PURPLE_JABBER_AUTH_DIGEST_MD5_H_ #define PURPLE_JABBER_AUTH_DIGEST_MD5_H_ #include "internal.h" /* * Every function in this file is ONLY exposed for tests. * DO NOT USE ANYTHING HERE OR YOU WILL BE SENT TO THE PIT OF DESPAIR. */ /* * Parse a DIGEST-MD5 challenge. */ GHashTable *jabber_auth_digest_md5_parse(const char *challenge); #endif /* PURPLE_JABBER_AUTH_DIGEST_MD5_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/auth_scram.h000066400000000000000000000061001366351464100234710ustar00rootroot00000000000000/** * @file auth_scram.h Implementation of SASL-SCRAM authentication * * purple * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #ifndef PURPLE_JABBER_AUTH_SCRAM_H_ #define PURPLE_JABBER_AUTH_SCRAM_H_ /* * Every function in this file is ONLY exposed for tests. * DO NOT USE ANYTHING HERE OR YOU WILL BE SENT TO THE PIT OF DESPAIR. */ /* Per-connection state stored between messages. * This is stored in js->auth_data_mech. */ typedef struct { const char *mech_substr; const char *name; guint size; } JabberScramHash; typedef struct { const JabberScramHash *hash; char *cnonce; GString *auth_message; GString *client_proof; GString *server_signature; gchar *password; gboolean channel_binding; int step; } JabberScramData; #include "auth.h" /** * Implements the Hi() function as described in the SASL-SCRAM I-D. * * @param hash The struct corresponding to the hash function to be used. * @param str The string to perform the PBKDF2 operation on. * @param salt The salt. * @param iterations The number of iterations to perform. * * @returns A newly allocated string containing the result. The string is * NOT null-terminated and its length is the length of the binary * output of the hash function in-use. */ guchar *jabber_scram_hi(const JabberScramHash *hash, const GString *str, GString *salt, guint iterations); /** * Calculates the proofs as described in Section 3 of the SASL-SCRAM I-D. * * @param data A JabberScramData structure. hash and auth_message must be * set. client_proof and server_signature will be set as a result * of this function. * @param salt The salt (as specified by the server) * @param iterations The number of iterations to perform. * * @returns TRUE if the proofs were successfully calculated. FALSE otherwise. */ gboolean jabber_scram_calc_proofs(JabberScramData *data, GString *salt, guint iterations); /** * Feed the algorithm with the data from the server. */ gboolean jabber_scram_feed_parser(JabberScramData *data, gchar *in, gchar **out); /** * Clean up and destroy the data struct */ void jabber_scram_data_destroy(JabberScramData *data); #endif /* PURPLE_JABBER_AUTH_SCRAM_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/bosh.h000066400000000000000000000033361366351464100223060ustar00rootroot00000000000000/** * @file bosh.h Bidirectional-streams over Synchronous HTTP (BOSH) (XEP-0124 and XEP-0206) * * purple * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #ifndef PURPLE_JABBER_BOSH_H_ #define PURPLE_JABBER_BOSH_H_ typedef struct _PurpleBOSHConnection PurpleBOSHConnection; #include "jabber.h" void jabber_bosh_init(void); void jabber_bosh_uninit(void); PurpleBOSHConnection* jabber_bosh_connection_init(JabberStream *js, const char *url); void jabber_bosh_connection_destroy(PurpleBOSHConnection *conn); gboolean jabber_bosh_connection_is_ssl(PurpleBOSHConnection *conn); void jabber_bosh_connection_send_keepalive(PurpleBOSHConnection *conn); void jabber_bosh_connection_connect(PurpleBOSHConnection *conn); void jabber_bosh_connection_close(PurpleBOSHConnection *conn); void jabber_bosh_connection_send_raw(PurpleBOSHConnection *conn, const char *data); #endif /* PURPLE_JABBER_BOSH_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/buddy.h000066400000000000000000000075271366351464100224700ustar00rootroot00000000000000/** * @file buddy.h Buddy handlers * * purple * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #ifndef PURPLE_JABBER_BUDDY_H_ #define PURPLE_JABBER_BUDDY_H_ typedef struct _JabberBuddy JabberBuddy; #include "jabber.h" #include "caps.h" #include "jutil.h" struct _JabberBuddy { /** * A sorted list of resources in priority descending order. * This means that the first resource in the list is the * "most available" (see resource_compare_cb in buddy.c for * details). Don't play with this yourself, let * jabber_buddy_track_resource and jabber_buddy_remove_resource do it. */ GList *resources; char *error_msg; enum { JABBER_INVISIBLE_NONE = 0, JABBER_INVISIBLE_SERVER = 1 << 1, JABBER_INVIS_BUDDY = 1 << 2 } invisible; enum { JABBER_SUB_NONE = 0, JABBER_SUB_PENDING = 1 << 1, JABBER_SUB_TO = 1 << 2, JABBER_SUB_FROM = 1 << 3, JABBER_SUB_BOTH = (JABBER_SUB_TO | JABBER_SUB_FROM), JABBER_SUB_REMOVE = 1 << 4 } subscription; }; typedef struct _JabberAdHocCommands { char *jid; char *node; char *name; } JabberAdHocCommands; typedef struct _JabberBuddyResource { JabberBuddy *jb; char *name; int priority; JabberBuddyState state; char *status; time_t idle; JabberCapabilities capabilities; char *thread_id; enum { JABBER_CHAT_STATES_UNKNOWN, JABBER_CHAT_STATES_UNSUPPORTED, JABBER_CHAT_STATES_SUPPORTED } chat_states; struct { char *version; char *name; char *os; } client; /* tz_off == PURPLE_NO_TZ_OFF when unset */ long tz_off; struct { JabberCapsClientInfo *info; GList *exts; } caps; GList *commands; gboolean commands_fetched; } JabberBuddyResource; void jabber_buddy_free(JabberBuddy *jb); JabberBuddy *jabber_buddy_find(JabberStream *js, const char *name, gboolean create); JabberBuddyResource *jabber_buddy_find_resource(JabberBuddy *jb, const char *resource); JabberBuddyResource *jabber_buddy_track_resource(JabberBuddy *jb, const char *resource, int priority, JabberBuddyState state, const char *status); void jabber_buddy_remove_resource(JabberBuddy *jb, const char *resource); void jabber_buddy_get_info(PurpleConnection *gc, const char *who); GList *jabber_blist_node_menu(PurpleBlistNode *node); void jabber_set_info(PurpleConnection *gc, const char *info); void jabber_setup_set_info(PurplePluginAction *action); void jabber_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img); void jabber_user_search(JabberStream *js, const char *directory); void jabber_user_search_begin(PurplePluginAction *); void jabber_buddy_remove_all_pending_buddy_info_requests(JabberStream *js); void jabber_vcard_fetch_mine(JabberStream *js); gboolean jabber_resource_know_capabilities(const JabberBuddyResource *jbr); gboolean jabber_resource_has_capability(const JabberBuddyResource *jbr, const gchar *cap); gboolean jabber_buddy_has_capability(const JabberBuddy *jb, const gchar *cap); const gchar * jabber_resource_get_identity_category_type(const JabberBuddyResource *jbr, const gchar *category); #endif /* PURPLE_JABBER_BUDDY_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/caps.h000066400000000000000000000102561366351464100223000ustar00rootroot00000000000000/* * purple - Jabber Protocol Plugin * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA * */ #ifndef PURPLE_JABBER_CAPS_H_ #define PURPLE_JABBER_CAPS_H_ typedef struct _JabberCapsClientInfo JabberCapsClientInfo; #include "jabber.h" /* Implementation of XEP-0115 - Entity Capabilities */ typedef struct _JabberCapsNodeExts JabberCapsNodeExts; typedef struct _JabberCapsTuple { const char *node; const char *ver; const char *hash; } JabberCapsTuple; struct _JabberCapsClientInfo { GList *identities; /* JabberIdentity */ GList *features; /* char * */ GList *forms; /* xmlnode * */ JabberCapsNodeExts *exts; const JabberCapsTuple tuple; }; /* * This stores a set of exts "known" for a specific node (which indicates * a specific client -- for reference, Pidgin, Finch, Meebo, et al share one * node.) In XEP-0115 v1.3, exts are used for features that may or may not be * present at a given time (PEP things, buzz might be disabled, etc). * * This structure is shared among all JabberCapsClientInfo instances matching * a specific node (if the capstable key->hash == NULL, which indicates that * the ClientInfo is using v1.3 caps as opposed to v1.5 caps). * * It's only exposed so that jabber_resource_has_capability can use it. * Everyone else, STAY AWAY! */ struct _JabberCapsNodeExts { guint ref; GHashTable *exts; /* char *ext_name -> GList *features */ }; typedef void (*jabber_caps_get_info_cb)(JabberCapsClientInfo *info, GList *exts, gpointer user_data); void jabber_caps_init(void); void jabber_caps_uninit(void); /** * Check whether all of the exts in a char* array are known to the given info. */ gboolean jabber_caps_exts_known(const JabberCapsClientInfo *info, char **exts); /** * Main entity capabilites function to get the capabilities of a contact. * * The callback will be called synchronously if we already have the * capabilities for the specified (node,ver,hash) (and, if exts are specified, * if we know what each means) * * @param exts A g_strsplit'd (NULL-terminated) array of strings. This * function is responsible for freeing it. */ void jabber_caps_get_info(JabberStream *js, const char *who, const char *node, const char *ver, const char *hash, char **exts, jabber_caps_get_info_cb cb, gpointer user_data); /** * Takes a JabberCapsClientInfo pointer and returns the caps hash according to * XEP-0115 Version 1.5. * * @param info A JabberCapsClientInfo pointer. * @param hash Hash cipher to be used. Either sha-1 or md5. * @return The base64 encoded SHA-1 hash; must be freed by caller */ gchar *jabber_caps_calculate_hash(JabberCapsClientInfo *info, const char *hash); /** * Calculate SHA1 hash for own featureset. */ void jabber_caps_calculate_own_hash(JabberStream *js); /** Get the current caps hash. * @ret hash **/ const gchar* jabber_caps_get_own_hash(JabberStream *js); /** * Broadcast a new calculated hash using a stanza. */ void jabber_caps_broadcast_change(void); /** * Parse the element from an IQ stanza into a JabberCapsClientInfo * struct. * * Exposed for tests * * @param query The 'query' element from an IQ reply stanza. * @returns A JabberCapsClientInfo struct, or NULL on error */ JabberCapsClientInfo *jabber_caps_parse_client_info(xmlnode *query); #endif /* PURPLE_JABBER_CAPS_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/chat.h000066400000000000000000000107441366351464100222730ustar00rootroot00000000000000/** * @file chat.h Chat stuff * * purple * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #ifndef PURPLE_JABBER_CHAT_H_ #define PURPLE_JABBER_CHAT_H_ //#include "internal.h" #include "connection.h" #include "conversation.h" #include "request.h" #include "roomlist.h" #include "jabber.h" typedef struct _JabberChatMember { char *handle; char *jid; } JabberChatMember; typedef struct _JabberChat { JabberStream *js; char *room; char *server; char *handle; GHashTable *components; int id; PurpleConversation *conv; gboolean muc; gboolean xhtml; PurpleRequestType config_dialog_type; void *config_dialog_handle; GHashTable *members; gboolean left; time_t joined; } JabberChat; GList *jabber_chat_info(PurpleConnection *gc); GHashTable *jabber_chat_info_defaults(PurpleConnection *gc, const char *chat_name); char *jabber_get_chat_name(GHashTable *data); /** * in-prpl function for joining a chat room. Doesn't require sticking goop * into a hash table. * * @param room The room to join. This MUST be normalized already. * @param server The server the room is on. This MUST be normalized already. * @param password The password (if required) to join the room. May be NULL. * @param data The chat hash table. May be NULL (it will be generated * for current core<>prpl API interface.) */ JabberChat *jabber_join_chat(JabberStream *js, const char *room, const char *server, const char *handle, const char *password, GHashTable *data); void jabber_chat_join(PurpleConnection *gc, GHashTable *data); JabberChat *jabber_chat_find(JabberStream *js, const char *room, const char *server); JabberChat *jabber_chat_find_by_id(JabberStream *js, int id); JabberChat *jabber_chat_find_by_conv(PurpleConversation *conv); void jabber_chat_destroy(JabberChat *chat); void jabber_chat_free(JabberChat *chat); gboolean jabber_chat_find_buddy(PurpleConversation *conv, const char *name); void jabber_chat_invite(PurpleConnection *gc, int id, const char *message, const char *name); void jabber_chat_leave(PurpleConnection *gc, int id); char *jabber_chat_buddy_real_name(PurpleConnection *gc, int id, const char *who); void jabber_chat_request_room_configure(JabberChat *chat); void jabber_chat_create_instant_room(JabberChat *chat); void jabber_chat_register(JabberChat *chat); void jabber_chat_change_topic(JabberChat *chat, const char *topic); void jabber_chat_set_topic(PurpleConnection *gc, int id, const char *topic); gboolean jabber_chat_change_nick(JabberChat *chat, const char *nick); void jabber_chat_part(JabberChat *chat, const char *msg); void jabber_chat_track_handle(JabberChat *chat, const char *handle, const char *jid, const char *affiliation, const char *role); void jabber_chat_remove_handle(JabberChat *chat, const char *handle); gboolean jabber_chat_ban_user(JabberChat *chat, const char *who, const char *why); gboolean jabber_chat_affiliate_user(JabberChat *chat, const char *who, const char *affiliation); gboolean jabber_chat_affiliation_list(JabberChat *chat, const char *affiliation); gboolean jabber_chat_role_user(JabberChat *chat, const char *who, const char *role, const char *why); gboolean jabber_chat_role_list(JabberChat *chat, const char *role); PurpleRoomlist *jabber_roomlist_get_list(PurpleConnection *gc); void jabber_roomlist_cancel(PurpleRoomlist *list); void jabber_chat_disco_traffic(JabberChat *chat); char *jabber_roomlist_room_serialize(PurpleRoomlistRoom *room); gboolean jabber_chat_all_participants_have_capability(const JabberChat *chat, const gchar *cap); guint jabber_chat_get_num_participants(const JabberChat *chat); #endif /* PURPLE_JABBER_CHAT_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/data.h000066400000000000000000000061241366351464100222620ustar00rootroot00000000000000/* * purple - Jabber Service Discovery * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA * */ #ifndef PURPLE_JABBER_DATA_H #define PURPLE_JABBER_DATA_H #include "xmlnode.h" #include "jabber.h" #include #define JABBER_DATA_MAX_SIZE 8192 typedef struct { char *cid; char *type; gsize size; gpointer data; gboolean ephemeral; } JabberData; typedef void (JabberDataRequestCallback)(JabberData *data, gchar *alt, gpointer userdata); /* creates a JabberData instance from raw data */ JabberData *jabber_data_create_from_data(gconstpointer data, gsize size, const char *type, gboolean ephemeral, JabberStream *js); /* create a JabberData instance from an XML "data" element (as defined by XEP 0231 */ JabberData *jabber_data_create_from_xml(xmlnode *tag); /* destroy a JabberData instance, NOT to be used on data that has been associated, since they get "owned" */ void jabber_data_destroy(JabberData *data); const char *jabber_data_get_cid(const JabberData *data); const char *jabber_data_get_type(const JabberData *data); gsize jabber_data_get_size(const JabberData *data); gpointer jabber_data_get_data(const JabberData *data); /* returns the XML definition for the data element */ xmlnode *jabber_data_get_xml_definition(const JabberData *data); /* returns an XHTML-IM "img" tag given a data instance */ xmlnode *jabber_data_get_xhtml_im(const JabberData *data, const gchar *alt); void jabber_data_request(JabberStream *js, const gchar *cid, const gchar *who, gchar *alt, gboolean ephemeral, JabberDataRequestCallback cb, gpointer userdata); /* lookup functions */ const JabberData *jabber_data_find_local_by_alt(const gchar *alt); const JabberData *jabber_data_find_local_by_cid(const gchar *cid); const JabberData *jabber_data_find_remote_by_cid(JabberStream *js, const gchar *who, const gchar *cid); /* store data objects */ void jabber_data_associate_local(JabberData *data, const gchar *alt); void jabber_data_associate_remote(JabberStream *js, const gchar *who, JabberData *data); /* handles iq requests */ void jabber_data_parse(JabberStream *js, const char *who, JabberIqType type, const char *id, xmlnode *data_node); void jabber_data_init(void); void jabber_data_uninit(void); #endif /* PURPLE_JABBER_DATA_H */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/disco.h000066400000000000000000000036341366351464100224550ustar00rootroot00000000000000/** * @file disco.h Jabber Service Discovery * * purple * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #ifndef PURPLE_JABBER_DISCO_H_ #define PURPLE_JABBER_DISCO_H_ #include "jabber.h" typedef struct _JabberDiscoItem { const char *jid; /* MUST */ const char *node; /* SHOULD */ const char *name; /* MAY */ } JabberDiscoItem; typedef void (JabberDiscoInfoCallback)(JabberStream *js, const char *who, JabberCapabilities capabilities, gpointer data); typedef void (JabberDiscoItemsCallback)(JabberStream *js, const char *jid, const char *node, GSList *items, gpointer data); void jabber_disco_info_parse(JabberStream *js, const char *from, JabberIqType type, const char *id, xmlnode *in_query); void jabber_disco_items_parse(JabberStream *js, const char *from, JabberIqType type, const char *id, xmlnode *query); void jabber_disco_items_server(JabberStream *js); void jabber_disco_info_do(JabberStream *js, const char *who, JabberDiscoInfoCallback *callback, gpointer data); #endif /* PURPLE_JABBER_DISCO_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/facebook_roster.h000066400000000000000000000024141366351464100245160ustar00rootroot00000000000000/** * purple * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #ifndef PURPLE_XMPP_FACEBOOK_ROSTER_H_ #define PURPLE_XMPP_FACEBOOK_ROSTER_H_ #include "jabber.h" /* removes deleted buddies from the list */ void jabber_facebook_roster_cleanup(JabberStream *js, xmlnode *query); /* ignores facebook roster quirks */ gboolean jabber_facebook_roster_incoming(JabberStream *js, xmlnode *item); #endif /* PURPLE_XMPP_FACEBOOK_ROSTER_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/ibb.h000066400000000000000000000110411366351464100220770ustar00rootroot00000000000000/* * purple - Jabber Service Discovery * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA * */ #ifndef PURPLE_JABBER_IBB_H_ #define PURPLE_JABBER_IBB_H_ #include "jabber.h" #include "iq.h" typedef struct _JabberIBBSession JabberIBBSession; typedef void (JabberIBBDataCallback)(JabberIBBSession *, const gpointer data, gsize size); typedef void (JabberIBBOpenedCallback)(JabberIBBSession *); typedef void (JabberIBBClosedCallback)(JabberIBBSession *); typedef void (JabberIBBErrorCallback)(JabberIBBSession *); typedef void (JabberIBBSentCallback)(JabberIBBSession *); typedef gboolean (JabberIBBOpenHandler)(JabberStream *js, const char *from, const char *id, xmlnode *open); typedef enum { JABBER_IBB_SESSION_NOT_OPENED, JABBER_IBB_SESSION_OPENED, JABBER_IBB_SESSION_CLOSED, JABBER_IBB_SESSION_ERROR } JabberIBBSessionState; struct _JabberIBBSession { JabberStream *js; gchar *who; gchar *sid; gchar *id; guint16 send_seq; guint16 recv_seq; gsize block_size; /* session state */ JabberIBBSessionState state; /* user data (f.ex. a handle to a PurpleXfer) */ gpointer user_data; /* callbacks */ JabberIBBOpenedCallback *opened_cb; JabberIBBSentCallback *data_sent_cb; JabberIBBClosedCallback *closed_cb; /* callback for receiving data */ JabberIBBDataCallback *data_received_cb; JabberIBBErrorCallback *error_cb; /* store the last sent IQ (to permit cancel of callback) */ gchar *last_iq_id; }; JabberIBBSession *jabber_ibb_session_create(JabberStream *js, const gchar *sid, const gchar *who, gpointer user_data); JabberIBBSession *jabber_ibb_session_create_from_xmlnode(JabberStream *js, const gchar *from, const gchar *id, xmlnode *open, gpointer user_data); void jabber_ibb_session_destroy(JabberIBBSession *sess); void jabber_ibb_session_set_opened_callback(JabberIBBSession *sess, JabberIBBOpenedCallback *cb); void jabber_ibb_session_set_data_sent_callback(JabberIBBSession *sess, JabberIBBSentCallback *cb); void jabber_ibb_session_set_closed_callback(JabberIBBSession *sess, JabberIBBClosedCallback *cb); void jabber_ibb_session_set_data_received_callback(JabberIBBSession *sess, JabberIBBDataCallback *cb); void jabber_ibb_session_set_error_callback(JabberIBBSession *sess, JabberIBBErrorCallback *cb); void jabber_ibb_session_open(JabberIBBSession *sess); void jabber_ibb_session_close(JabberIBBSession *sess); void jabber_ibb_session_accept(JabberIBBSession *sess); void jabber_ibb_session_send_data(JabberIBBSession *sess, gconstpointer data, gsize size); const gchar *jabber_ibb_session_get_sid(const JabberIBBSession *sess); JabberStream *jabber_ibb_session_get_js(JabberIBBSession *sess); const gchar *jabber_ibb_session_get_who(const JabberIBBSession *sess); guint16 jabber_ibb_session_get_send_seq(const JabberIBBSession *sess); guint16 jabber_ibb_session_get_recv_seq(const JabberIBBSession *sess); JabberIBBSessionState jabber_ibb_session_get_state(const JabberIBBSession *sess); gsize jabber_ibb_session_get_block_size(const JabberIBBSession *sess); void jabber_ibb_session_set_block_size(JabberIBBSession *sess, gsize size); /* get maximum size data block to send (in bytes) (before encoded to BASE64) */ gsize jabber_ibb_session_get_max_data_size(const JabberIBBSession *sess); gpointer jabber_ibb_session_get_user_data(JabberIBBSession *sess); /* handle incoming packet */ void jabber_ibb_parse(JabberStream *js, const char *who, JabberIqType type, const char *id, xmlnode *child); /* add a handler for open session */ void jabber_ibb_register_open_handler(JabberIBBOpenHandler *cb); void jabber_ibb_unregister_open_handler(JabberIBBOpenHandler *cb); void jabber_ibb_init(void); void jabber_ibb_uninit(void); #endif /* PURPLE_JABBER_IBB_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/iq.h000066400000000000000000000103341366351464100217600ustar00rootroot00000000000000/** * @file iq.h JabberID handlers * * purple * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #ifndef PURPLE_JABBER_IQ_H_ #define PURPLE_JABBER_IQ_H_ typedef enum { JABBER_IQ_SET, JABBER_IQ_GET, JABBER_IQ_RESULT, JABBER_IQ_ERROR, JABBER_IQ_NONE } JabberIqType; #include "jabber.h" #include "connection.h" typedef struct _JabberIq JabberIq; typedef struct _JabberIqCallbackData JabberIqCallbackData; /** * A JabberIqHandler is called to process an incoming IQ stanza. * Handlers typically process unsolicited incoming GETs or SETs for their * registered namespace, but may be called to handle the results of a * GET or SET that we generated if no JabberIqCallback was generated * The handler may be called for the results of a GET or SET (RESULT or ERROR) * that we generated * if the generating function did not register a JabberIqCallback. * * @param js The JabberStream object. * @param from The remote entity (the from attribute on the stanza) * @param type The IQ type. * @param id The IQ id (the id attribute on the stanza) * @param child The child element of the stanza that matches the name * and namespace registered with jabber_iq_register_handler. * * @see jabber_iq_register_handler() * @see JabberIqCallback */ typedef void (JabberIqHandler)(JabberStream *js, const char *from, JabberIqType type, const char *id, xmlnode *child); /** * A JabberIqCallback is called to process the results of a GET or SET that * we send to a remote entity. The callback is matched based on the id * of the incoming stanza (which matches the one on the initial stanza). * * @param js The JabberStream object. * @param from The remote entity (the from attribute on the stanza) * @param type The IQ type. The only possible values are JABBER_IQ_RESULT * and JABBER_IQ_ERROR. * @param id The IQ id (the id attribute on the stanza) * @param packet The stanza * @param data The callback data passed to jabber_iq_set_callback() * * @see jabber_iq_set_callback() */ typedef void (JabberIqCallback)(JabberStream *js, const char *from, JabberIqType type, const char *id, xmlnode *packet, gpointer data); struct _JabberIq { JabberIqType type; char *id; xmlnode *node; JabberIqCallback *callback; gpointer callback_data; JabberStream *js; }; JabberIq *jabber_iq_new(JabberStream *js, JabberIqType type); JabberIq *jabber_iq_new_query(JabberStream *js, JabberIqType type, const char *xmlns); void jabber_iq_parse(JabberStream *js, xmlnode *packet); void jabber_iq_callbackdata_free(JabberIqCallbackData *jcd); void jabber_iq_remove_callback_by_id(JabberStream *js, const char *id); void jabber_iq_set_callback(JabberIq *iq, JabberIqCallback *cb, gpointer data); void jabber_iq_set_id(JabberIq *iq, const char *id); void jabber_iq_send(JabberIq *iq); void jabber_iq_free(JabberIq *iq); void jabber_iq_init(void); void jabber_iq_uninit(void); void jabber_iq_register_handler(const char *node, const char *xmlns, JabberIqHandler *func); /* Connected to namespace-handler registration signals */ void jabber_iq_signal_register(const gchar *node, const gchar *xmlns); void jabber_iq_signal_unregister(const gchar *node, const gchar *xmlns); #endif /* PURPLE_JABBER_IQ_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/jabber.h000066400000000000000000000311301366351464100225710ustar00rootroot00000000000000/** * @file jabber.h * * purple * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #ifndef PURPLE_JABBER_H_ #define PURPLE_JABBER_H_ typedef enum { JABBER_CAP_NONE = 0, /* JABBER_CAP_XHTML = 1 << 0, */ /* JABBER_CAP_COMPOSING = 1 << 1, */ JABBER_CAP_SI = 1 << 2, JABBER_CAP_SI_FILE_XFER = 1 << 3, JABBER_CAP_BYTESTREAMS = 1 << 4, JABBER_CAP_IBB = 1 << 5, JABBER_CAP_CHAT_STATES = 1 << 6, JABBER_CAP_IQ_SEARCH = 1 << 7, JABBER_CAP_IQ_REGISTER = 1 << 8, /* Google Talk extensions: * http://code.google.com/apis/talk/jep_extensions/extensions.html */ JABBER_CAP_GMAIL_NOTIFY = 1 << 9, JABBER_CAP_GOOGLE_ROSTER = 1 << 10, JABBER_CAP_PING = 1 << 11, JABBER_CAP_ADHOC = 1 << 12, JABBER_CAP_BLOCKING = 1 << 13, JABBER_CAP_ITEMS = 1 << 14, JABBER_CAP_ROSTER_VERSIONING = 1 << 15, JABBER_CAP_FACEBOOK = 1 << 16, JABBER_CAP_RETRIEVED = 1 << 31 } JabberCapabilities; typedef struct _JabberStream JabberStream; #include #include #include "circbuffer.h" #include "connection.h" #include "dnsquery.h" #include "dnssrv.h" #include "media.h" #include "mediamanager.h" #include "roomlist.h" #include "sslconn.h" #include "namespaces.h" #include "auth.h" #include "iq.h" #include "jutil.h" #include "xmlnode.h" #include "buddy.h" #include "bosh.h" #ifdef HAVE_CYRUS_SASL #include #endif #define CAPS0115_NODE "http://pidgin.im/" #define JABBER_DEFAULT_REQUIRE_TLS "require_starttls" #define JABBER_DEFAULT_FT_PROXIES "proxy.eu.jabber.org" /* Index into attention_types list */ #define JABBER_BUZZ 0 typedef enum { JABBER_STREAM_OFFLINE, JABBER_STREAM_CONNECTING, JABBER_STREAM_INITIALIZING, JABBER_STREAM_INITIALIZING_ENCRYPTION, JABBER_STREAM_AUTHENTICATING, JABBER_STREAM_POST_AUTH, JABBER_STREAM_CONNECTED } JabberStreamState; struct _JabberStream { int fd; PurpleSrvTxtQueryData *srv_query_data; xmlParserCtxt *context; xmlnode *current; struct { guint8 major; guint8 minor; } protocol_version; JabberSaslMech *auth_mech; gpointer auth_mech_data; /** * The header from the opening tag. This being NULL is treated * as a special condition in the parsing code (signifying the next * stanza started is an opening stream tag), and its being missing on * the stream header is treated as a fatal error. */ char *stream_id; JabberStreamState state; GHashTable *buddies; /* * This boolean was added to eliminate a heinous bug where we would * get into a loop with the server and move a buddy back and forth * from one group to another. * * The sequence goes something like this: * 1. Our resource and another resource both approve an authorization * request at the exact same time. We put the buddy in group A and * the other resource put the buddy in group B. * 2. The server receives the roster add for group B and sends us a * roster push. * 3. We receive this roster push and modify our local blist. This * triggers us to send a roster add for group B. * 4. The server recieves our earlier roster add for group A and sends * us a roster push. * 5. We receive this roster push and modify our local blist. This * triggers us to send a roster add for group A. * 6. The server receives our earlier roster add for group B and sends * us a roster push. * (repeat steps 3 through 6 ad infinitum) * * This boolean is used to short-circuit the sending of a roster add * when we receive a roster push. * * See these bug reports: * http://trac.adiumx.com/ticket/8834 * http://developer.pidgin.im/ticket/5484 * http://developer.pidgin.im/ticket/6188 */ gboolean currently_parsing_roster_push; GHashTable *chats; GList *chat_servers; PurpleRoomlist *roomlist; GList *user_directories; GHashTable *iq_callbacks; int next_id; GList *bs_proxies; GList *oob_file_transfers; GList *file_transfers; time_t idle; time_t old_idle; /** When we last pinged the server, so we don't ping more * often than once every minute. */ time_t last_ping; JabberID *user; JabberBuddy *user_jb; PurpleConnection *gc; PurpleSslConnection *gsc; gboolean registration; char *initial_avatar_hash; char *avatar_hash; GSList *pending_avatar_requests; GSList *pending_buddy_info_requests; PurpleCircBuffer *write_buffer; guint writeh; gboolean reinit; JabberCapabilities server_caps; gboolean googletalk; char *server_name; char *gmail_last_time; char *gmail_last_tid; char *serverFQDN; #ifdef HAVE_CYRUS_SASL sasl_conn_t *sasl; sasl_callback_t *sasl_cb; sasl_secret_t *sasl_secret; const char *current_mech; int auth_fail_count; int sasl_state; int sasl_maxbuf; GString *sasl_mechs; #endif gboolean unregistration; PurpleAccountUnregistrationCb unregistration_cb; void *unregistration_user_data; gboolean vcard_fetched; /* Timer at login to push updated avatar */ guint vcard_timer; /* Entity Capabilities hash */ char *caps_hash; /* does the local server support PEP? */ gboolean pep; /* Is Buzz enabled? */ gboolean allowBuzz; /* A list of JabberAdHocCommands supported by the server */ GList *commands; /* last presence update to check for differences */ JabberBuddyState old_state; char *old_msg; int old_priority; char *old_avatarhash; /* same for user tune */ char *old_artist; char *old_title; char *old_source; char *old_uri; int old_length; char *old_track; char *certificate_CN; /* A purple timeout tag for the keepalive */ guint keepalive_timeout; guint max_inactivity; guint inactivity_timer; PurpleSrvResponse *srv_rec; guint srv_rec_idx; guint max_srv_rec_idx; /* BOSH stuff */ PurpleBOSHConnection *bosh; /** * This linked list contains PurpleUtilFetchUrlData structs * for when we lookup buddy icons from a url */ GSList *url_datas; /* keep a hash table of JingleSessions */ GHashTable *sessions; /* maybe this should only be present when USE_VV? */ gchar *stun_ip; int stun_port; PurpleDnsQueryData *stun_query; /* stuff for Google's relay handling */ gchar *google_relay_token; gchar *google_relay_host; GList *google_relay_requests; /* the HTTP requests to get */ /* relay info */ /* facebook quirks */ gboolean facebook_roster_cleanup_performed; }; typedef gboolean (JabberFeatureEnabled)(JabberStream *js, const gchar *namespace); typedef struct _JabberFeature { gchar *namespace; JabberFeatureEnabled *is_enabled; } JabberFeature; typedef struct _JabberIdentity { gchar *category; gchar *type; gchar *name; gchar *lang; } JabberIdentity; typedef struct _JabberBytestreamsStreamhost { char *jid; char *host; int port; char *zeroconf; } JabberBytestreamsStreamhost; /* what kind of additional features as returned from disco#info are supported? */ extern GList *jabber_features; /* A sorted list of identities advertised. Use jabber_add_identity to add * so it remains sorted. */ extern GList *jabber_identities; void jabber_stream_features_parse(JabberStream *js, xmlnode *packet); void jabber_process_packet(JabberStream *js, xmlnode **packet); void jabber_send(JabberStream *js, xmlnode *data); void jabber_send_raw(JabberStream *js, const char *data, int len); void jabber_send_signal_cb(PurpleConnection *pc, xmlnode **packet, gpointer unused); void jabber_stream_set_state(JabberStream *js, JabberStreamState state); void jabber_register_parse(JabberStream *js, const char *from, JabberIqType type, const char *id, xmlnode *query); void jabber_register_start(JabberStream *js); char *jabber_get_next_id(JabberStream *js); /** Parse an error into a human-readable string and optionally a disconnect * reason. * @param js the stream on which the error occurred. * @param packet the error packet * @param reason where to store the disconnection reason, or @c NULL if you * don't care or you don't intend to close the connection. */ char *jabber_parse_error(JabberStream *js, xmlnode *packet, PurpleConnectionError *reason); /** * Add a feature to the list of features advertised via disco#info. If you * call this while accounts are connected, Bad Things(TM) will happen because * the Entity Caps hash will be out-of-date (which should be fixed :/) * * @param namespace The namespace of the feature * @param cb A callback determining whether or not this feature * will advertised; may be NULL. */ void jabber_add_feature(const gchar *namespace, JabberFeatureEnabled cb); void jabber_remove_feature(const gchar *namespace); /** Adds an identity to this jabber library instance. For list of valid values * visit the website of the XMPP Registrar * (http://www.xmpp.org/registrar/disco-categories.html#client). * * Like with jabber_add_feature, if you call this while accounts are connected, * Bad Things will happen. * * @param category the category of the identity. * @param type the type of the identity. * @param language the language localization of the name. Can be NULL. * @param name the name of the identity. */ void jabber_add_identity(const gchar *category, const gchar *type, const gchar *lang, const gchar *name); /** * GCompareFunc for JabberIdentity structs. */ gint jabber_identity_compare(gconstpointer a, gconstpointer b); /** * Returns true if this connection is over a secure (SSL) stream. Use this * instead of checking js->gsc because BOSH stores its PurpleSslConnection * members in its own data structure. */ gboolean jabber_stream_is_ssl(JabberStream *js); /** * Restart the "we haven't sent anything in a while and should send * something or the server will kick us off" timer (obviously * called when sending something. It's exposed for BOSH.) */ void jabber_stream_restart_inactivity_timer(JabberStream *js); /** PRPL functions */ const char *jabber_list_icon(PurpleAccount *a, PurpleBuddy *b); const char* jabber_list_emblem(PurpleBuddy *b); char *jabber_status_text(PurpleBuddy *b); void jabber_tooltip_text(PurpleBuddy *b, PurpleNotifyUserInfo *user_info, gboolean full); GList *jabber_status_types(PurpleAccount *account); void jabber_login(PurpleAccount *account); void jabber_close(PurpleConnection *gc); void jabber_idle_set(PurpleConnection *gc, int idle); void jabber_blocklist_parse_push(JabberStream *js, const char *from, JabberIqType type, const char *id, xmlnode *child); void jabber_request_block_list(JabberStream *js); void jabber_add_deny(PurpleConnection *gc, const char *who); void jabber_rem_deny(PurpleConnection *gc, const char *who); void jabber_keepalive(PurpleConnection *gc); void jabber_register_gateway(JabberStream *js, const char *gateway); void jabber_register_account(PurpleAccount *account); void jabber_unregister_account(PurpleAccount *account, PurpleAccountUnregistrationCb cb, void *user_data); gboolean jabber_send_attention(PurpleConnection *gc, const char *username, guint code); GList *jabber_attention_types(PurpleAccount *account); void jabber_convo_closed(PurpleConnection *gc, const char *who); PurpleChat *jabber_find_blist_chat(PurpleAccount *account, const char *name); gboolean jabber_offline_message(const PurpleBuddy *buddy); int jabber_prpl_send_raw(PurpleConnection *gc, const char *buf, int len); GList *jabber_actions(PurplePlugin *plugin, gpointer context); gboolean jabber_audio_enabled(JabberStream *js, const char *unused); gboolean jabber_video_enabled(JabberStream *js, const char *unused); gboolean jabber_initiate_media(PurpleAccount *account, const char *who, PurpleMediaSessionType type); PurpleMediaCaps jabber_get_media_caps(PurpleAccount *account, const char *who); gboolean jabber_can_receive_file(PurpleConnection *gc, const gchar *who); void jabber_plugin_init(PurplePlugin *plugin); void jabber_plugin_uninit(PurplePlugin *plugin); #endif /* PURPLE_JABBER_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/jutil.h000066400000000000000000000065411366351464100225030ustar00rootroot00000000000000/** * @file jutil.h utility functions * * purple * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #ifndef PURPLE_JABBER_JUTIL_H_ #define PURPLE_JABBER_JUTIL_H_ typedef struct _JabberID { char *node; char *domain; char *resource; } JabberID; typedef enum { JABBER_BUDDY_STATE_UNKNOWN = -2, JABBER_BUDDY_STATE_ERROR = -1, JABBER_BUDDY_STATE_UNAVAILABLE = 0, JABBER_BUDDY_STATE_ONLINE, JABBER_BUDDY_STATE_CHAT, JABBER_BUDDY_STATE_AWAY, JABBER_BUDDY_STATE_XA, JABBER_BUDDY_STATE_DND } JabberBuddyState; #include "jabber.h" JabberID* jabber_id_new(const char *str); /** * Compare two JIDs for equality. In addition to the node and domain, * the resources of the two JIDs must also be equal (or both absent). */ gboolean jabber_id_equal(const JabberID *jid1, const JabberID *jid2); void jabber_id_free(JabberID *jid); char *jabber_get_domain(const char *jid); char *jabber_get_resource(const char *jid); char *jabber_get_bare_jid(const char *jid); char *jabber_id_get_bare_jid(const JabberID *jid); char *jabber_id_get_full_jid(const JabberID *jid); JabberID *jabber_id_to_bare_jid(const JabberID *jid); gboolean jabber_jid_is_domain(const char *jid); const char *jabber_normalize(const PurpleAccount *account, const char *in); /* Returns true if JID is the bare JID of our server. */ gboolean jabber_is_own_server(JabberStream *js, const char *jid); /* Returns true if JID is the bare JID of our account. */ gboolean jabber_is_own_account(JabberStream *js, const char *jid); gboolean jabber_nodeprep_validate(const char *); gboolean jabber_domain_validate(const char *); gboolean jabber_resourceprep_validate(const char *); /** * Apply the SASLprep profile of stringprep to the string passed in. * * @returns A newly allocated string containing the normalized version * of the input, or NULL if an error occurred (the string could * not be normalized) */ char *jabber_saslprep(const char *); /* state -> readable name */ const char *jabber_buddy_state_get_name(JabberBuddyState state); /* state -> core id */ const char *jabber_buddy_state_get_status_id(JabberBuddyState state); /* state -> show attr (for presence stanza) */ const char *jabber_buddy_state_get_show(JabberBuddyState state); /* core id -> state */ JabberBuddyState jabber_buddy_status_id_get_state(const char *id); /* show attr (presence stanza) -> state */ JabberBuddyState jabber_buddy_show_get_state(const char *id); char *jabber_calculate_data_hash(gconstpointer data, size_t len, const gchar *hash_algo); #endif /* PURPLE_JABBER_JUTIL_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/message.h000066400000000000000000000045421366351464100227770ustar00rootroot00000000000000/** * @file message.h Message handlers * * purple * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #ifndef PURPLE_JABBER_MESSAGE_H_ #define PURPLE_JABBER_MESSAGE_H_ #include "buddy.h" #include "jabber.h" #include "xmlnode.h" typedef struct _JabberMessage { JabberStream *js; enum { JABBER_MESSAGE_NORMAL, JABBER_MESSAGE_CHAT, JABBER_MESSAGE_GROUPCHAT, JABBER_MESSAGE_HEADLINE, JABBER_MESSAGE_ERROR, JABBER_MESSAGE_GROUPCHAT_INVITE, JABBER_MESSAGE_EVENT, JABBER_MESSAGE_OTHER } type; time_t sent; gboolean delayed; gboolean hasBuzz; char *id; char *from; char *to; char *subject; char *body; char *xhtml; char *password; char *error; char *thread_id; enum { JM_STATE_NONE, JM_STATE_ACTIVE, JM_STATE_COMPOSING, JM_STATE_PAUSED, JM_STATE_INACTIVE, JM_STATE_GONE } chat_state; GList *etc; GList *eventitems; } JabberMessage; void jabber_message_free(JabberMessage *jm); void jabber_message_send(JabberMessage *jm); void jabber_message_parse(JabberStream *js, xmlnode *packet); int jabber_message_send_im(PurpleConnection *gc, const char *who, const char *msg, PurpleMessageFlags flags); int jabber_message_send_chat(PurpleConnection *gc, int id, const char *message, PurpleMessageFlags flags); unsigned int jabber_send_typing(PurpleConnection *gc, const char *who, PurpleTypingState state); gboolean jabber_buzz_isenabled(JabberStream *js, const gchar *namespace); gboolean jabber_custom_smileys_isenabled(JabberStream *js, const gchar *namespace); #endif /* PURPLE_JABBER_MESSAGE_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/namespaces.h000066400000000000000000000101521366351464100234640ustar00rootroot00000000000000/* * purple - Jabber Protocol Plugin * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA * */ #ifndef PURPLE_JABBER_NAMESPACES_H_ #define PURPLE_JABBER_NAMESPACES_H_ #define NS_XMPP_BIND "urn:ietf:params:xml:ns:xmpp-bind" #define NS_XMPP_CLIENT "jabber:client" #define NS_XMPP_SASL "urn:ietf:params:xml:ns:xmpp-sasl" #define NS_XMPP_SESSION "urn:ietf:params:xml:ns:xmpp-session" #define NS_XMPP_STANZAS "urn:ietf:params:xml:ns:xmpp-stanzas" #define NS_XMPP_STREAMS "http://etherx.jabber.org/streams" #define NS_XMPP_TLS "urn:ietf:params:xml:ns:xmpp-tls" /* XEP-0012 Last Activity (and XEP-0256 Last Activity in Presence) */ #define NS_LAST_ACTIVITY "jabber:iq:last" /* XEP-0030 Service Discovery */ #define NS_DISCO_INFO "http://jabber.org/protocol/disco#info" #define NS_DISCO_ITEMS "http://jabber.org/protocol/disco#items" /* XEP-0047 IBB (In-band bytestreams) */ #define NS_IBB "http://jabber.org/protocol/ibb" /* XEP-0065 SOCKS5 Bytestreams */ #define NS_BYTESTREAMS "http://jabber.org/protocol/bytestreams" /* XEP-0066 Out of Band Data (OOB) */ #define NS_OOB_IQ_DATA "jabber:iq:oob" #define NS_OOB_X_DATA "jabber:x:oob" /* XEP-0071 XHTML-IM (rich-text messages) */ #define NS_XHTML_IM "http://jabber.org/protocol/xhtml-im" #define NS_XHTML "http://www.w3.org/1999/xhtml" /* XEP-0084 v0.12 User Avatar */ #define NS_AVATAR_0_12_DATA "http://www.xmpp.org/extensions/xep-0084.html#ns-data" #define NS_AVATAR_0_12_METADATA "http://www.xmpp.org/extensions/xep-0084.html#ns-metadata" /* XEP-0084 v1.1 User Avatar */ #define NS_AVATAR_1_1_DATA "urn:xmpp:avatar:data" #define NS_AVATAR_1_1_METADATA "urn:xmpp:avatar:metadata" /* XEP-0096 SI File Transfer */ #define NS_SI_FILE_TRANSFER "http://jabber.org/protocol/si/profile/file-transfer" /* XEP-0124 Bidirectional-streams Over Synchronous HTTP (BOSH) */ #define NS_BOSH "http://jabber.org/protocol/httpbind" /* XEP-0191 Simple Communications Blocking */ #define NS_SIMPLE_BLOCKING "urn:xmpp:blocking" /* XEP-0199 Ping */ #define NS_PING "urn:xmpp:ping" /* XEP-0202 Entity Time */ #define NS_ENTITY_TIME "urn:xmpp:time" /* XEP-0203 Delayed Delivery (and legacy delayed delivery) */ #define NS_DELAYED_DELIVERY "urn:xmpp:delay" #define NS_DELAYED_DELIVERY_LEGACY "jabber:x:delay" /* XEP-0206 XMPP over BOSH */ #define NS_XMPP_BOSH "urn:xmpp:xbosh" /* XEP-0224 Attention */ #define NS_ATTENTION "urn:xmpp:attention:0" /* XEP-0231 BoB (Bits of Binary) */ #define NS_BOB "urn:xmpp:bob" /* XEP-0237 Roster Versioning */ #define NS_ROSTER_VERSIONING "urn:xmpp:features:rosterver" /* XEP-0264 File Transfer Thumbnails (Thumbs) */ #define NS_THUMBS "urn:xmpp:thumbs:0" /* Google extensions */ #define NS_GOOGLE_CAMERA "http://www.google.com/xmpp/protocol/camera/v1" #define NS_GOOGLE_VIDEO "http://www.google.com/xmpp/protocol/video/v1" #define NS_GOOGLE_VOICE "http://www.google.com/xmpp/protocol/voice/v1" #define NS_GOOGLE_JINGLE_INFO "google:jingleinfo" #define NS_GOOGLE_MAIL_NOTIFY "google:mail:notify" #define NS_GOOGLE_ROSTER "google:roster" #define NS_GOOGLE_PROTOCOL_SESSION "http://www.google.com/xmpp/protocol/session" #define NS_GOOGLE_SESSION "http://www.google.com/session" #define NS_GOOGLE_SESSION_PHONE "http://www.google.com/session/phone" #define NS_GOOGLE_SESSION_VIDEO "http://www.google.com/session/video" #endif /* PURPLE_JABBER_NAMESPACES_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/oob.h000066400000000000000000000023051366351464100221250ustar00rootroot00000000000000/** * @file oob.h out-of-band transfer functions * * purple * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #ifndef PURPLE_JABBER_OOB_H_ #define PURPLE_JABBER_OOB_H_ #include "jabber.h" void jabber_oob_parse(JabberStream *js, const char *from, JabberIqType type, const char *id, xmlnode *querynode); #endif /* PURPLE_JABBER_OOB_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/parser.h000066400000000000000000000023361366351464100226460ustar00rootroot00000000000000/** * @file parser.h XML parser functions * * purple * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #ifndef PURPLE_JABBER_PARSER_H_ #define PURPLE_JABBER_PARSER_H_ #include "jabber.h" void jabber_parser_setup(JabberStream *js); void jabber_parser_free(JabberStream *js); void jabber_parser_process(JabberStream *js, const char *buf, int len); #endif /* PURPLE_JABBER_PARSER_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/pep.h000066400000000000000000000065161366351464100221420ustar00rootroot00000000000000/* * purple - Jabber Protocol Plugin * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA * */ #ifndef PURPLE_JABBER_PEP_H_ #define PURPLE_JABBER_PEP_H_ #include "jabber.h" #include "message.h" #include "buddy.h" void jabber_pep_init(void); void jabber_pep_uninit(void); void jabber_pep_init_actions(GList **m); /* * Callback for receiving PEP events. * * @parameter js The JabberStream this item was received on * @parameter items The <items/>-tag with the <item/>-children */ typedef void (JabberPEPHandler)(JabberStream *js, const char *from, xmlnode *items); /* * Registers a callback for PEP events. Also automatically announces this receiving capability via disco#info. * Don't forget to use jabber_add_feature when supporting the sending of PEP events of this type. * * @parameter xmlns The namespace for this event * @parameter handlerfunc The callback to be used when receiving an event with this namespace */ void jabber_pep_register_handler(const char *xmlns, JabberPEPHandler handlerfunc); /* * Request a specific item from another PEP node. * * @parameter js The JabberStream that should be used * @parameter to The target PEP node * @parameter node The node name of the item that is requested * @parameter id The item id of the requested item (may be NULL) * @parameter cb The callback to be used when this item is received * * The items element passed to the callback will be NULL if any error occurred (like a permission error, node doesn't exist etc.) */ void jabber_pep_request_item(JabberStream *js, const char *to, const char *node, const char *id, JabberPEPHandler cb); /* * Default callback that can be used for namespaces which should only be enabled when PEP is supported * * @parameter js The JabberStream struct for this connection * @parameter namespace The namespace that's queried, ignored. * * @returns TRUE when PEP is enabled, FALSE otherwise */ gboolean jabber_pep_namespace_only_when_pep_enabled_cb(JabberStream *js, const gchar *namespace); void jabber_handle_event(JabberMessage *jm); /** * Delete the specified PEP node. */ void jabber_pep_delete_node(JabberStream *js, const gchar *node); /* * Publishes PEP item(s) * * @parameter js The JabberStream associated with the connection this event should be published * @parameter publish The publish node. This could be for example <publish node='http://jabber.org/protocol/tune'/> with an <item/> as subnode */ void jabber_pep_publish(JabberStream *js, xmlnode *publish); #endif /* PURPLE_JABBER_PEP_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/ping.h000066400000000000000000000025021366351464100223020ustar00rootroot00000000000000/** * @file ping.h ping functions * * purple * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #ifndef PURPLE_JABBER_PING_H_ #define PURPLE_JABBER_PING_H_ #include "jabber.h" #include "iq.h" #include "xmlnode.h" void jabber_ping_parse(JabberStream *js, const char *from, JabberIqType, const char *id, xmlnode *child); gboolean jabber_ping_jid(JabberStream *js, const char *jid); void jabber_keepalive_ping(JabberStream *js); #endif /* PURPLE_JABBER_PING_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/presence.h000066400000000000000000000063211366351464100231540ustar00rootroot00000000000000/** * @file presence.h Presence * * purple * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #ifndef PURPLE_JABBER_PRESENCE_H_ #define PURPLE_JABBER_PRESENCE_H_ typedef enum { JABBER_PRESENCE_ERROR = -2, JABBER_PRESENCE_PROBE = -1, JABBER_PRESENCE_AVAILABLE, JABBER_PRESENCE_UNAVAILABLE, JABBER_PRESENCE_SUBSCRIBE, JABBER_PRESENCE_SUBSCRIBED, JABBER_PRESENCE_UNSUBSCRIBE, JABBER_PRESENCE_UNSUBSCRIBED } JabberPresenceType; typedef struct _JabberPresenceChatInfo JabberPresenceChatInfo; typedef struct _JabberPresence JabberPresence; #include "buddy.h" #include "chat.h" #include "jabber.h" #include "jutil.h" #include "xmlnode.h" struct _JabberPresenceChatInfo { GSList *codes; xmlnode *item; }; struct _JabberPresence { JabberPresenceType type; JabberID *jid_from; const char *from; const char *to; const char *id; JabberBuddy *jb; JabberChat *chat; JabberPresenceChatInfo chat_info; xmlnode *caps; /* TODO: Temporary, see presence.c:parse_caps */ JabberBuddyState state; gchar *status; int priority; char *vcard_avatar_hash; char *nickname; gboolean delayed; time_t sent; int idle; }; typedef void (JabberPresenceHandler)(JabberStream *js, JabberPresence *presence, xmlnode *child); void jabber_presence_register_handler(const char *node, const char *xmlns, JabberPresenceHandler *handler); void jabber_presence_init(void); void jabber_presence_uninit(void); void jabber_set_status(PurpleAccount *account, PurpleStatus *status); /** * Send a full presence stanza. * * @param js A JabberStream object. * @param force Force sending the presence stanza, irrespective of whether * the contents seem to have changed. */ void jabber_presence_send(JabberStream *js, gboolean force); xmlnode *jabber_presence_create(JabberBuddyState state, const char *msg, int priority); /* DEPRECATED */ xmlnode *jabber_presence_create_js(JabberStream *js, JabberBuddyState state, const char *msg, int priority); void jabber_presence_parse(JabberStream *js, xmlnode *packet); void jabber_presence_subscription_set(JabberStream *js, const char *who, const char *type); void jabber_presence_fake_to_self(JabberStream *js, PurpleStatus *status); void purple_status_to_jabber(const PurpleStatus *status, JabberBuddyState *state, char **msg, int *priority); #endif /* PURPLE_JABBER_PRESENCE_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/roster.h000066400000000000000000000036371366351464100226750ustar00rootroot00000000000000/** * @file roster.h Roster manipulation * * purple * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #ifndef PURPLE_JABBER_ROSTER_H_ #define PURPLE_JABBER_ROSTER_H_ /* it must *not* be localized */ #define JABBER_ROSTER_DEFAULT_GROUP "Buddies" #include "jabber.h" void jabber_roster_request(JabberStream *js); void jabber_roster_parse(JabberStream *js, const char *from, JabberIqType type, const char *id, xmlnode *query); void jabber_roster_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group); void jabber_roster_alias_change(PurpleConnection *gc, const char *name, const char *alias); void jabber_roster_group_change(PurpleConnection *gc, const char *name, const char *old_group, const char *new_group); void jabber_roster_group_rename(PurpleConnection *gc, const char *old_name, PurpleGroup *group, GList *moved_buddies); void jabber_roster_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group); const gchar * jabber_roster_group_get_global_name(PurpleGroup *group); #endif /* PURPLE_JABBER_ROSTER_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/si.h000066400000000000000000000030461366351464100217640ustar00rootroot00000000000000/** * @file si.h SI transfer functions * * purple * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #ifndef PURPLE_JABBER_SI_H_ #define PURPLE_JABBER_SI_H_ #include "ft.h" #include "jabber.h" void jabber_bytestreams_parse(JabberStream *js, const char *from, JabberIqType type, const char *id, xmlnode *query); void jabber_si_parse(JabberStream *js, const char *from, JabberIqType type, const char *id, xmlnode *si); PurpleXfer *jabber_si_new_xfer(PurpleConnection *gc, const char *who); void jabber_si_xfer_send(PurpleConnection *gc, const char *who, const char *file); void jabber_si_init(void); void jabber_si_uninit(void); #endif /* PURPLE_JABBER_SI_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/useravatar.h000066400000000000000000000024131366351464100235230ustar00rootroot00000000000000/* * purple - Jabber Protocol Plugin * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA * */ #ifndef _PURPLE_JABBER_USERAVATAR_H_ #define _PURPLE_JABBER_USERAVATAR_H_ #include "jabber.h" #include "imgstore.h" /* Implementation of XEP-0084 */ void jabber_avatar_init(void); void jabber_avatar_set(JabberStream *js, PurpleStoredImage *img); void jabber_avatar_fetch_mine(JabberStream *js); #endif /* _PURPLE_JABBER_USERAVATAR_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/usermood.h000066400000000000000000000025261366351464100232100ustar00rootroot00000000000000/* * purple - Jabber Protocol Plugin * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA * */ #ifndef PURPLE_JABBER_USERMOOD_H_ #define PURPLE_JABBER_USERMOOD_H_ #include "jabber.h" /* Implementation of XEP-0107 */ void jabber_mood_init(void); void jabber_mood_set(JabberStream *js, const char *mood, /* must be one of the valid strings defined in the XEP */ const char *text /* might be NULL */); PurpleMood *jabber_get_moods(PurpleAccount *account); #endif /* PURPLE_JABBER_USERMOOD_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/usernick.h000066400000000000000000000022371366351464100231750ustar00rootroot00000000000000/* * purple - Jabber Protocol Plugin * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA * */ #ifndef PURPLE_JABBER_USERNICK_H_ #define PURPLE_JABBER_USERNICK_H_ #include "jabber.h" /* Implementation of XEP-0172 */ void jabber_nick_init(void); void jabber_nick_init_action(GList **m); #endif /* PURPLE_JABBER_USERNICK_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/usertune.h000066400000000000000000000027411366351464100232240ustar00rootroot00000000000000/* * purple - Jabber Protocol Plugin * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA * */ #ifndef PURPLE_JABBER_USERTUNE_H_ #define PURPLE_JABBER_USERTUNE_H_ #include "jabber.h" /* Implementation of XEP-0118 */ typedef struct _PurpleJabberTuneInfo PurpleJabberTuneInfo; struct _PurpleJabberTuneInfo { char *artist; char *title; char *album; char *track; /* either the index of the track in the album or the URL for a stream */ int time; /* in seconds, -1 for unknown */ char *url; }; void jabber_tune_init(void); void jabber_tune_set(PurpleConnection *gc, const PurpleJabberTuneInfo *tuneinfo); #endif /* PURPLE_JABBER_USERTUNE_H_ */ purple-lurch-0.6.8+git20200527.388605/headers/jabber/xdata.h000066400000000000000000000041661366351464100224560ustar00rootroot00000000000000/** * @file xdata.h utility functions * * purple * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * 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 2 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #ifndef PURPLE_JABBER_XDATA_H_ #define PURPLE_JABBER_XDATA_H_ #include "jabber.h" #include "xmlnode.h" typedef struct _JabberXDataAction { char *name; char *handle; } JabberXDataAction; typedef void (*jabber_x_data_cb)(JabberStream *js, xmlnode *result, gpointer user_data); typedef void (*jabber_x_data_action_cb)(JabberStream *js, xmlnode *result, const char *actionhandle, gpointer user_data); void *jabber_x_data_request(JabberStream *js, xmlnode *packet, jabber_x_data_cb cb, gpointer user_data); void *jabber_x_data_request_with_actions(JabberStream *js, xmlnode *packet, GList *actions, int defaultaction, jabber_x_data_action_cb cb, gpointer user_data); /* * Return the form type (the CDATA of the value child of the FORM_TYPE * field entry. * E.g., for the following, "http://jabber.org/protocol/muc#roominfo". * * * http://jabber.org/protocol/muc#roominfo * * * * @param form The xmlnode for the form (the 'x' element) * @returns The FORM_TYPE. Must be freed by caller. */ gchar *jabber_x_data_get_formtype(const xmlnode *form); #endif /* PURPLE_JABBER_XDATA_H_ */ purple-lurch-0.6.8+git20200527.388605/src/000077500000000000000000000000001366351464100171245ustar00rootroot00000000000000purple-lurch-0.6.8+git20200527.388605/src/lurch.c000066400000000000000000002643171366351464100204220ustar00rootroot00000000000000#include #include #include #include #include #include "chat.h" #include "jabber.h" #include "jutil.h" #include "pep.h" #include "libomemo.h" #include "libomemo_crypto.h" #include "libomemo_storage.h" #include "axc.h" #include "axc_store.h" // included for error codes #include "signal_protocol.h" #include "lurch.h" #include "lurch_api.h" #include "lurch_cmd_ui.h" #include "lurch_util.h" #ifdef _WIN32 #define strnlen(a, b) (MIN(strlen(a), (b))) #endif #define JABBER_PROTOCOL_ID "prpl-jabber" // see https://www.ietf.org/rfc/rfc3920.txt #define JABBER_MAX_LEN_NODE 1023 #define JABBER_MAX_LEN_DOMAIN 1023 #define JABBER_MAX_LEN_BARE JABBER_MAX_LEN_NODE + JABBER_MAX_LEN_DOMAIN + 1 #define LURCH_ERR_STRING_ENCRYPT "There was an error encrypting the message and it was not sent. " \ "You can try again, or try to find the problem by looking at the debug log." #define LURCH_ERR_STRING_DECRYPT "There was an error decrypting an OMEMO message addressed to this device. " \ "See the debug log for details." typedef struct lurch_addr { char * jid; uint32_t device_id; } lurch_addr; typedef struct lurch_queued_msg { omemo_message * om_msg_p; GList * recipient_addr_l_p; GList * no_sess_l_p; GHashTable * sess_handled_p; } lurch_queued_msg; omemo_crypto_provider crypto = { .random_bytes_func = omemo_default_crypto_random_bytes, .aes_gcm_encrypt_func = omemo_default_crypto_aes_gcm_encrypt, .aes_gcm_decrypt_func = omemo_default_crypto_aes_gcm_decrypt }; int topic_changed = 0; int uninstall = 0; PurpleCmdId lurch_cmd_handle_id = 0; PurpleCmdId lurch_cmd_v2_handle_id = 0; static void lurch_addr_list_destroy_func(gpointer data) { lurch_addr * addr_p = (lurch_addr *) data; free(addr_p->jid); free(addr_p); } /** * Creates a queued msg. * Note that it just saves the pointers, so make sure they are not freed during * the lifetime of this struct and instead use the destroy function when done. * * @param om_msg_p Pointer to the omemo_message. * @param recipient_addr_l_p Pointer to the list of recipient addresses. * @param no_sess_l_p Pointer to the list that contains the addresses that do * not have sessions, i.e. for which bundles were requested. * @param cmsg_pp Will point to the pointer of the created queued msg struct. * @return 0 on success, negative on error. */ static int lurch_queued_msg_create(omemo_message * om_msg_p, GList * recipient_addr_l_p, GList * no_sess_l_p, lurch_queued_msg ** qmsg_pp) { int ret_val = 0; char * err_msg_dbg = (void *) 0; lurch_queued_msg * qmsg_p = (void *) 0; GHashTable * sess_handled_p = (void *) 0; qmsg_p = malloc(sizeof(lurch_queued_msg)); if (!qmsg_p) { ret_val = LURCH_ERR_NOMEM; err_msg_dbg = g_strdup_printf("failed to malloc space for queued msg struct"); goto cleanup; } sess_handled_p = g_hash_table_new(g_str_hash, g_str_equal); qmsg_p->om_msg_p = om_msg_p; qmsg_p->recipient_addr_l_p = recipient_addr_l_p; qmsg_p->no_sess_l_p = no_sess_l_p; qmsg_p->sess_handled_p = sess_handled_p; *qmsg_pp = qmsg_p; cleanup: if (ret_val) { free(qmsg_p); } if (err_msg_dbg) { purple_debug_error("lurch", "%s: %s (%i)\n", __func__, err_msg_dbg, ret_val); free(err_msg_dbg); } return ret_val; } static int lurch_queued_msg_is_handled(const lurch_queued_msg * qmsg_p) { return (g_list_length(qmsg_p->no_sess_l_p) == g_hash_table_size(qmsg_p->sess_handled_p)) ? 1 : 0; } /** * Frees all the memory used by the queued msg. */ static void lurch_queued_msg_destroy(lurch_queued_msg * qmsg_p) { if (qmsg_p) { omemo_message_destroy(qmsg_p->om_msg_p); g_list_free_full(qmsg_p->recipient_addr_l_p, free); g_hash_table_destroy(qmsg_p->sess_handled_p); free(qmsg_p); } } static char * lurch_queue_make_key_string_s(const char * name, const char * device_id) { return g_strconcat(name, "/", device_id, NULL); } /** * Does the first-time install of the axc DB. * As specified in OMEMO, it checks if the generated device ID already exists. * Therefore, it should be called at a point in time when other entries exist. * * If an initialized DB already exists, this function exits with success without doing anything. * This is checked by trying to retrieve the device ID from it. * * @param uname The username. * @return 0 on success, negative on error. */ static int lurch_axc_prepare(char * uname) { int ret_val = 0; char * err_msg_dbg = (void *) 0; axc_context * axc_ctx_p = (void *) 0; uint32_t device_id = 0; char * db_fn_omemo = (void *) 0; ret_val = lurch_util_axc_get_init_ctx(uname, &axc_ctx_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to get init axc ctx"); goto cleanup; } ret_val = axc_get_device_id(axc_ctx_p, &device_id); if (!ret_val) { // already installed goto cleanup; } db_fn_omemo = lurch_util_uname_get_db_fn(uname, LURCH_DB_NAME_OMEMO); while (1) { ret_val = axc_install(axc_ctx_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to install axc"); goto cleanup; } ret_val = axc_get_device_id(axc_ctx_p, &device_id); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to get own device id"); goto cleanup; } ret_val = omemo_storage_global_device_id_exists(device_id, db_fn_omemo); if (ret_val == 1) { ret_val = axc_db_init_status_set(AXC_DB_NEEDS_ROLLBACK, axc_ctx_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to set axc db to rollback"); goto cleanup; } } else if (ret_val < 0) { err_msg_dbg = g_strdup_printf("failed to access the db %s", db_fn_omemo); goto cleanup; } else { break; } } cleanup: if (err_msg_dbg) { purple_debug_error("lurch", "%s: %s (%i)\n", __func__, err_msg_dbg, ret_val); free(err_msg_dbg); } axc_context_destroy_all(axc_ctx_p); free(db_fn_omemo); return ret_val; } /** * Encrypts a data buffer, usually the omemo symmetric key, using axolotl. * Assumes a valid session already exists. * * @param recipient_addr_p Pointer to the lurch_addr of the recipient. * @param key_p Pointer to the key data. * @param key_len Length of the key data. * @param axc_ctx_p Pointer to the axc_context to use. * @param key_ct_pp Will point to a pointer to an axc_buf containing the key ciphertext on success. * @return 0 on success, negative on error */ static int lurch_key_encrypt(const lurch_addr * recipient_addr_p, const uint8_t * key_p, size_t key_len, axc_context * axc_ctx_p, axc_buf ** key_ct_buf_pp) { int ret_val = 0; char * err_msg_dbg = (void *) 0; axc_buf * key_buf_p = (void *) 0; axc_buf * key_ct_buf_p = (void *) 0; axc_address axc_addr = {0}; purple_debug_info("lurch", "%s: encrypting key for %s:%i\n", __func__, recipient_addr_p->jid, recipient_addr_p->device_id); key_buf_p = axc_buf_create(key_p, key_len); if (!key_buf_p) { err_msg_dbg = g_strdup_printf("failed to create buffer for the key"); goto cleanup; } axc_addr.name = recipient_addr_p->jid; axc_addr.name_len = strnlen(axc_addr.name, JABBER_MAX_LEN_BARE); axc_addr.device_id = recipient_addr_p->device_id; ret_val = axc_message_encrypt_and_serialize(key_buf_p, &axc_addr, axc_ctx_p, &key_ct_buf_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to encrypt the key"); goto cleanup; } *key_ct_buf_pp = key_ct_buf_p; cleanup: if (ret_val) { axc_buf_free(key_ct_buf_p); } if (err_msg_dbg) { purple_debug_error("lurch", "%s: %s (%i)\n", __func__, err_msg_dbg, ret_val); free(err_msg_dbg); } axc_buf_free(key_buf_p); return ret_val; } /** * For each of the recipients, encrypts the symmetric key using the existing axc session, * then adds it to the omemo message. * If the session does not exist, the recipient is skipped. * * @param om_msg_p Pointer to the omemo message. * @param addr_l_p Pointer to the head of a list of the intended recipients' lurch_addrs. * @param axc_ctx_p Pointer to the axc_context to use. * @return 0 on success, negative on error. */ static int lurch_msg_encrypt_for_addrs(omemo_message * om_msg_p, GList * addr_l_p, axc_context * axc_ctx_p) { int ret_val = 0; char * err_msg_dbg = (void *) 0; GList * curr_l_p = (void *) 0; lurch_addr * curr_addr_p = (void *) 0; axc_address addr = {0}; axc_buf * curr_key_ct_buf_p = (void *) 0; purple_debug_info("lurch", "%s: trying to encrypt key for %i devices\n", __func__, g_list_length(addr_l_p)); for (curr_l_p = addr_l_p; curr_l_p; curr_l_p = curr_l_p->next) { curr_addr_p = (lurch_addr *) curr_l_p->data; addr.name = curr_addr_p->jid; addr.name_len = strnlen(addr.name, JABBER_MAX_LEN_BARE); addr.device_id = curr_addr_p->device_id; ret_val = axc_session_exists_initiated(&addr, axc_ctx_p); if (ret_val < 0) { err_msg_dbg = g_strdup_printf("failed to check if session exists, aborting"); goto cleanup; } else if (!ret_val) { continue; } else { ret_val = lurch_key_encrypt(curr_addr_p, omemo_message_get_key(om_msg_p), omemo_message_get_key_len(om_msg_p), axc_ctx_p, &curr_key_ct_buf_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to encrypt key for %s:%i", curr_addr_p->jid, curr_addr_p->device_id); goto cleanup; } ret_val = omemo_message_add_recipient(om_msg_p, curr_addr_p->device_id, axc_buf_get_data(curr_key_ct_buf_p), axc_buf_get_len(curr_key_ct_buf_p)); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to add recipient to omemo msg"); goto cleanup; } axc_buf_free(curr_key_ct_buf_p); curr_key_ct_buf_p = (void *) 0; } } cleanup: if (err_msg_dbg) { purple_debug_error("lurch", "%s: %s (%i)\n", __func__, err_msg_dbg, ret_val); free(err_msg_dbg); } axc_buf_free(curr_key_ct_buf_p); return ret_val; } /** * Collects the information needed for a bundle and publishes it. * * @param uname The username. * @param js_p Pointer to the connection to use for publishing. */ static int lurch_bundle_publish_own(JabberStream * js_p) { int ret_val = 0; char * err_msg_dbg = (void *) 0; char * uname = (void *) 0; axc_context * axc_ctx_p = (void *) 0; axc_bundle * axcbundle_p = (void *) 0; omemo_bundle * omemobundle_p = (void *) 0; axc_buf * curr_buf_p = (void *) 0; axc_buf_list_item * next_p = (void *) 0; char * bundle_xml = (void *) 0; xmlnode * publish_node_bundle_p = (void *) 0; uname = lurch_util_uname_strip(purple_account_get_username(purple_connection_get_account(js_p->gc))); ret_val = lurch_util_axc_get_init_ctx(uname, &axc_ctx_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to init axc ctx"); goto cleanup; } ret_val = axc_bundle_collect(AXC_PRE_KEYS_AMOUNT, axc_ctx_p, &axcbundle_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to collect axc bundle"); goto cleanup; } ret_val = omemo_bundle_create(&omemobundle_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to create omemo_bundle"); goto cleanup; } ret_val = omemo_bundle_set_device_id(omemobundle_p, axc_bundle_get_reg_id(axcbundle_p)); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to set device id in omemo bundle"); goto cleanup; } curr_buf_p = axc_bundle_get_signed_pre_key(axcbundle_p); ret_val = omemo_bundle_set_signed_pre_key(omemobundle_p, axc_bundle_get_signed_pre_key_id(axcbundle_p), axc_buf_get_data(curr_buf_p), axc_buf_get_len(curr_buf_p)); if(ret_val) { err_msg_dbg = g_strdup_printf("failed to set signed pre key in omemo bundle"); goto cleanup; } curr_buf_p = axc_bundle_get_signature(axcbundle_p); ret_val = omemo_bundle_set_signature(omemobundle_p, axc_buf_get_data(curr_buf_p), axc_buf_get_len(curr_buf_p)); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to set signature in omemo bundle"); goto cleanup; } curr_buf_p = axc_bundle_get_identity_key(axcbundle_p); ret_val = omemo_bundle_set_identity_key(omemobundle_p, axc_buf_get_data(curr_buf_p), axc_buf_get_len(curr_buf_p)); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to set public identity key in omemo bundle"); goto cleanup; } next_p = axc_bundle_get_pre_key_list(axcbundle_p); while (next_p) { curr_buf_p = axc_buf_list_item_get_buf(next_p); ret_val = omemo_bundle_add_pre_key(omemobundle_p, axc_buf_list_item_get_id(next_p), axc_buf_get_data(curr_buf_p), axc_buf_get_len(curr_buf_p)); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to add public pre key to omemo bundle"); goto cleanup; } next_p = axc_buf_list_item_get_next(next_p); } ret_val = omemo_bundle_export(omemobundle_p, &bundle_xml); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to export omemo bundle to xml"); goto cleanup; } publish_node_bundle_p = xmlnode_from_str(bundle_xml, -1); jabber_pep_publish(js_p, publish_node_bundle_p); purple_debug_info("lurch", "%s: published own bundle for %s\n", __func__, uname); cleanup: if (err_msg_dbg) { purple_debug_error("lurch", "%s: %s (%i)\n", __func__, err_msg_dbg, ret_val); free(err_msg_dbg); } free(uname); axc_context_destroy_all(axc_ctx_p); axc_bundle_destroy(axcbundle_p); omemo_bundle_destroy(omemobundle_p); free(bundle_xml); return ret_val; } /** * Parses the device ID from a received bundle update. * * @param bundle_node_ns The node name. * @return The ID. */ static uint32_t lurch_bundle_name_get_device_id(const char * bundle_node_name) { char ** split = (void *) 0; uint32_t id = 0; split = g_strsplit(bundle_node_name, ":", -1); id = strtol(split[5], (void *) 0, 0); g_strfreev(split); return id; } /** * Creates an axc session from a received bundle. * * @param uname The own username. * @param from The sender of the bundle. * @param items_p The bundle update as received in the PEP request handler. */ static int lurch_bundle_create_session(const char * uname, const char * from, const xmlnode * items_p, axc_context * axc_ctx_p) { int ret_val = 0; char * err_msg_dbg = (void *) 0; int len; omemo_bundle * om_bundle_p = (void *) 0; axc_address remote_addr = {0}; uint32_t pre_key_id = 0; uint8_t * pre_key_p = (void *) 0; size_t pre_key_len = 0; uint32_t signed_pre_key_id = 0; uint8_t * signed_pre_key_p = (void *) 0; size_t signed_pre_key_len = 0; uint8_t * signature_p = (void *) 0; size_t signature_len = 0; uint8_t * identity_key_p = (void *) 0; size_t identity_key_len = 0; axc_buf * pre_key_buf_p = (void *) 0; axc_buf * signed_pre_key_buf_p = (void *) 0; axc_buf * signature_buf_p = (void *) 0; axc_buf * identity_key_buf_p = (void *) 0; purple_debug_info("lurch", "%s: creating a session between %s and %s from a received bundle\n", __func__, uname, from); ret_val = omemo_bundle_import(xmlnode_to_str(items_p, &len), &om_bundle_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to import xml into bundle"); goto cleanup; } remote_addr.name = from; remote_addr.name_len = strnlen(from, JABBER_MAX_LEN_BARE); remote_addr.device_id = omemo_bundle_get_device_id(om_bundle_p); purple_debug_info("lurch", "%s: bundle's device id is %i\n", __func__, remote_addr.device_id); ret_val = omemo_bundle_get_random_pre_key(om_bundle_p, &pre_key_id, &pre_key_p, &pre_key_len); if (ret_val) { err_msg_dbg = g_strdup_printf("failed get a random pre key from the bundle"); goto cleanup; } ret_val = omemo_bundle_get_signed_pre_key(om_bundle_p, &signed_pre_key_id, &signed_pre_key_p, &signed_pre_key_len); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to get the signed pre key from the bundle"); goto cleanup; } ret_val = omemo_bundle_get_signature(om_bundle_p, &signature_p, &signature_len); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to get the signature from the bundle"); goto cleanup; } ret_val = omemo_bundle_get_identity_key(om_bundle_p, &identity_key_p, &identity_key_len); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to get the public identity key from the bundle"); goto cleanup; } pre_key_buf_p = axc_buf_create(pre_key_p, pre_key_len); signed_pre_key_buf_p = axc_buf_create(signed_pre_key_p, signed_pre_key_len); signature_buf_p = axc_buf_create(signature_p, signature_len); identity_key_buf_p = axc_buf_create(identity_key_p, identity_key_len); if (!pre_key_buf_p || !signed_pre_key_buf_p || !signature_buf_p || !identity_key_buf_p) { ret_val = LURCH_ERR; err_msg_dbg = g_strdup_printf("failed to create one of the buffers"); goto cleanup; } ret_val = axc_session_from_bundle(pre_key_id, pre_key_buf_p, signed_pre_key_id, signed_pre_key_buf_p, signature_buf_p, identity_key_buf_p, &remote_addr, axc_ctx_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to create a session from a bundle"); goto cleanup; } cleanup: if (err_msg_dbg) { purple_debug_error("lurch", "%s: %s (%i)\n", __func__, err_msg_dbg, ret_val); free(err_msg_dbg); } omemo_bundle_destroy(om_bundle_p); free(pre_key_p); free(signed_pre_key_p); free(signature_p); free(identity_key_p); axc_buf_free(pre_key_buf_p); axc_buf_free(signed_pre_key_buf_p); axc_buf_free(signature_buf_p); axc_buf_free(identity_key_buf_p); return ret_val; } /** * Wraps the omemo_message_export_encrypted message, so that it is called with the same options throughout. */ static int lurch_export_encrypted(omemo_message * om_msg_p, char ** xml_pp) { return omemo_message_export_encrypted(om_msg_p, OMEMO_ADD_MSG_EME, xml_pp); } /** * Implements JabberIqCallback. * Callback for a bundle request. */ static void lurch_bundle_request_cb(JabberStream * js_p, const char * from, JabberIqType type, const char * id, xmlnode * packet_p, gpointer data_p) { int ret_val = 0; char * err_msg_conv = (void *) 0; char * err_msg_dbg = (void *) 0; char * uname = (void *) 0; char ** split = (void *) 0; char * device_id_str = (void *) 0; axc_address addr = {0}; axc_context * axc_ctx_p = (void *) 0; char * recipient = (void *) 0; xmlnode * pubsub_node_p = (void *) 0; xmlnode * items_node_p = (void *) 0; int msg_handled = 0; char * addr_key = (void *) 0; char * msg_xml = (void *) 0; xmlnode * msg_node_p = (void *) 0; lurch_queued_msg * qmsg_p = (lurch_queued_msg *) data_p; uname = lurch_util_uname_strip(purple_account_get_username(purple_connection_get_account(js_p->gc))); recipient = omemo_message_get_recipient_name_bare(qmsg_p->om_msg_p); if (!from) { // own user from = uname; } split = g_strsplit(id, "#", 3); device_id_str = split[1]; purple_debug_info("lurch", "%s: %s received bundle update from %s:%s\n", __func__, uname, from, device_id_str); addr.name = from; addr.name_len = strnlen(from, JABBER_MAX_LEN_BARE); addr.device_id = strtol(device_id_str, (void *) 0, 10); ret_val = lurch_util_axc_get_init_ctx(uname, &axc_ctx_p); if (ret_val) { err_msg_dbg = "failed to get axc ctx"; goto cleanup; } if (type == JABBER_IQ_ERROR) { err_msg_conv = g_strdup_printf("The device %s owned by %s does not have a bundle and will be skipped. " "The owner should fix this, or remove the device from the list.", device_id_str, from); } else { pubsub_node_p = xmlnode_get_child(packet_p, "pubsub"); if (!pubsub_node_p) { ret_val = LURCH_ERR; err_msg_dbg = "no node in response"; goto cleanup; } items_node_p = xmlnode_get_child(pubsub_node_p, "items"); if (!items_node_p) { ret_val = LURCH_ERR; err_msg_dbg = "no node in response"; goto cleanup; } ret_val = axc_session_exists_initiated(&addr, axc_ctx_p); if (!ret_val) { ret_val = lurch_bundle_create_session(uname, from, items_node_p, axc_ctx_p); if (ret_val) { err_msg_dbg = "failed to create a session"; goto cleanup; } } else if (ret_val < 0) { err_msg_dbg = "failed to check if session exists"; goto cleanup; } } addr_key = lurch_queue_make_key_string_s(from, device_id_str); if (!addr_key) { err_msg_dbg = "failed to make a key string"; ret_val = LURCH_ERR; goto cleanup; } (void) g_hash_table_replace(qmsg_p->sess_handled_p, addr_key, addr_key); if (lurch_queued_msg_is_handled(qmsg_p)) { msg_handled = 1; } if (msg_handled) { ret_val = lurch_msg_encrypt_for_addrs(qmsg_p->om_msg_p, qmsg_p->recipient_addr_l_p, axc_ctx_p); if (ret_val) { err_msg_dbg = "failed to encrypt the symmetric key"; goto cleanup; } ret_val = lurch_export_encrypted(qmsg_p->om_msg_p, &msg_xml); if (ret_val) { err_msg_dbg = "failed to export the message to xml"; goto cleanup; } msg_node_p = xmlnode_from_str(msg_xml, -1); if (!msg_node_p) { err_msg_dbg = "failed to parse xml from string"; ret_val = LURCH_ERR; goto cleanup; } purple_debug_info("lurch", "sending encrypted msg\n"); purple_signal_emit(purple_plugins_find_with_id("prpl-jabber"), "jabber-sending-xmlnode", js_p->gc, &msg_node_p); lurch_queued_msg_destroy(qmsg_p); } cleanup: if (err_msg_conv) { purple_conv_present_error(recipient, purple_connection_get_account(js_p->gc), err_msg_conv); g_free(err_msg_conv); } if (err_msg_dbg) { purple_conv_present_error(recipient, purple_connection_get_account(js_p->gc), LURCH_ERR_STRING_ENCRYPT); purple_debug_error("lurch", "%s: %s (%i)\n", __func__, err_msg_dbg, ret_val); } free(uname); g_strfreev(split); axc_context_destroy_all(axc_ctx_p); free(addr_key); free(recipient); free(msg_xml); if (msg_node_p) { xmlnode_free(msg_node_p); } } /** * Requests a bundle. * * @param js_p Pointer to the JabberStream to use. * @param to The recipient of this request. * @param device_id The ID of the device whose bundle is needed. * @param qmsg_p Pointer to the queued message waiting on (at least) this bundle. * @return 0 on success, negative on error. */ static int lurch_bundle_request_do(JabberStream * js_p, const char * to, uint32_t device_id, lurch_queued_msg * qmsg_p) { int ret_val = 0; JabberIq * jiq_p = (void *) 0; xmlnode * pubsub_node_p = (void *) 0; char * device_id_str = (void *) 0; char * rand_str = (void *) 0; char * req_id = (void *) 0; char * bundle_node_name = (void *) 0; xmlnode * items_node_p = (void *) 0; purple_debug_info("lurch", "%s: %s is requesting bundle from %s:%i\n", __func__, purple_account_get_username(purple_connection_get_account(js_p->gc)), to, device_id); jiq_p = jabber_iq_new(js_p, JABBER_IQ_GET); xmlnode_set_attrib(jiq_p->node, "to", to); pubsub_node_p = xmlnode_new_child(jiq_p->node, "pubsub"); xmlnode_set_namespace(pubsub_node_p, "http://jabber.org/protocol/pubsub"); device_id_str = g_strdup_printf("%i", device_id); rand_str = g_strdup_printf("%i", g_random_int()); req_id = g_strconcat(to, "#", device_id_str, "#", rand_str, NULL); ret_val = omemo_bundle_get_pep_node_name(device_id, &bundle_node_name); if (ret_val) { purple_debug_error("lurch", "%s: failed to get bundle pep node name for %s:%i\n", __func__, to, device_id); goto cleanup; } items_node_p = xmlnode_new_child(pubsub_node_p, "items"); xmlnode_set_attrib(items_node_p, "node", bundle_node_name); xmlnode_set_attrib(items_node_p, "max_items", "1"); jabber_iq_set_id(jiq_p, req_id); jabber_iq_set_callback(jiq_p, lurch_bundle_request_cb, qmsg_p); jabber_iq_send(jiq_p); purple_debug_info("lurch", "%s: ...request sent\n", __func__); cleanup: g_free(device_id_str); g_free(rand_str); g_free(req_id); g_free(bundle_node_name); return ret_val; } /** * A JabberPEPHandler function. * When a prekey message containing an invalid key ID is received, * the bundle of the sender is requested and a KeyTransport message is sent * in response so that a session can still be established. */ static void lurch_pep_bundle_for_keytransport(JabberStream * js_p, const char * from, xmlnode * items_p) { int ret_val = 0; char * err_msg_dbg = (void *) 0; char * uname = (void *) 0; axc_context * axc_ctx_p = (void *) 0; uint32_t own_id = 0; omemo_message * msg_p = (void *) 0; axc_address addr = {0}; lurch_addr laddr = {0}; axc_buf * key_ct_buf_p = (void *) 0; char * msg_xml = (void *) 0; xmlnode * msg_node_p = (void *) 0; void * jabber_handle_p = purple_plugins_find_with_id("prpl-jabber"); uname = lurch_util_uname_strip(purple_account_get_username(purple_connection_get_account(js_p->gc))); addr.name = from; addr.name_len = strnlen(from, JABBER_MAX_LEN_BARE); addr.device_id = lurch_bundle_name_get_device_id(xmlnode_get_attrib(items_p, "node")); purple_debug_info("lurch", "%s: %s received bundle from %s:%i\n", __func__, uname, from, addr.device_id); laddr.jid = g_strndup(addr.name, addr.name_len); laddr.device_id = addr.device_id; ret_val = lurch_util_axc_get_init_ctx(uname, &axc_ctx_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to init axc ctx"); goto cleanup; } // make sure it's gonna be a pre_key_message ret_val = axc_session_delete(addr.name, addr.device_id, axc_ctx_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to delete possibly existing session"); goto cleanup; } ret_val = lurch_bundle_create_session(uname, from, items_p, axc_ctx_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to create session"); goto cleanup; } purple_debug_info("lurch", "%s: %s created session with %s:%i\n", __func__, uname, from, addr.device_id); ret_val = axc_get_device_id(axc_ctx_p, &own_id); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to get own device id"); goto cleanup; } ret_val = omemo_message_create(own_id, &crypto, &msg_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to create omemo msg"); goto cleanup; } ret_val = lurch_key_encrypt(&laddr, omemo_message_get_key(msg_p), omemo_message_get_key_len(msg_p), axc_ctx_p, &key_ct_buf_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to encrypt key for %s:%i", addr.name, addr.device_id); goto cleanup; } ret_val = omemo_message_add_recipient(msg_p, addr.device_id, axc_buf_get_data(key_ct_buf_p), axc_buf_get_len(key_ct_buf_p)); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to add %s:%i as recipient to message", addr.name, addr.device_id); goto cleanup; } // don't call wrapper function here as EME is not necessary ret_val = omemo_message_export_encrypted(msg_p, OMEMO_ADD_MSG_NONE, &msg_xml); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to export encrypted msg"); goto cleanup; } msg_node_p = xmlnode_from_str(msg_xml, -1); if (!msg_node_p) { err_msg_dbg = g_strdup_printf("failed to create xml node from xml string"); goto cleanup; } purple_signal_emit(jabber_handle_p, "jabber-sending-xmlnode", js_p->gc, &msg_node_p); purple_debug_info("lurch", "%s: %s sent keytransportmsg to %s:%i\n", __func__, uname, from, addr.device_id); cleanup: if (err_msg_dbg) { purple_debug_error("lurch", "%s: %s (%i)\n", __func__, err_msg_dbg, ret_val); free(err_msg_dbg); } free(laddr.jid); free(uname); axc_context_destroy_all(axc_ctx_p); omemo_message_destroy(msg_p); axc_buf_free(key_ct_buf_p); free(msg_xml); if (msg_node_p) { xmlnode_free(msg_node_p); } } /** * Processes a devicelist by updating the database with it. * * @param uname The username. * @param dl_in_p Pointer to the incoming devicelist. * @param js_p Pointer to the JabberStream. * @return 0 on success, negative on error. */ static int lurch_devicelist_process(char * uname, omemo_devicelist * dl_in_p, JabberStream * js_p) { int ret_val = 0; char * err_msg_dbg = (void *) 0; const char * from = (void *) 0; char * db_fn_omemo = (void *) 0; axc_context * axc_ctx_p = (void *) 0; omemo_devicelist * dl_db_p = (void *) 0; GList * add_l_p = (void *) 0; GList * del_l_p = (void *) 0; GList * curr_p = (void *) 0; uint32_t curr_id = 0; char * bundle_node_name = (void *) 0; char * debug_str = (void *) 0; from = omemo_devicelist_get_owner(dl_in_p); db_fn_omemo = lurch_util_uname_get_db_fn(uname, LURCH_DB_NAME_OMEMO); purple_debug_info("lurch", "%s: processing devicelist from %s for %s\n", __func__, from, uname); ret_val = omemo_storage_user_devicelist_retrieve(from, db_fn_omemo, &dl_db_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to retrieve cached devicelist for %s from db %s", from, db_fn_omemo); goto cleanup; } omemo_devicelist_export(dl_db_p, &debug_str); purple_debug_info("lurch", "%s: %s\n%s\n", __func__, "cached devicelist is", debug_str); ret_val = omemo_devicelist_diff(dl_in_p, dl_db_p, &add_l_p, &del_l_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to diff devicelists"); goto cleanup; } for (curr_p = add_l_p; curr_p; curr_p = curr_p->next) { curr_id = omemo_devicelist_list_data(curr_p); purple_debug_info("lurch", "%s: saving %i for %s to db %s\n", __func__, curr_id, from, db_fn_omemo); ret_val = omemo_storage_user_device_id_save(from, curr_id, db_fn_omemo); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to save %i for %s to %s", curr_id, from, db_fn_omemo); goto cleanup; } } ret_val = lurch_util_axc_get_init_ctx(uname, &axc_ctx_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to init axc ctx"); goto cleanup; } for (curr_p = del_l_p; curr_p; curr_p = curr_p->next) { curr_id = omemo_devicelist_list_data(curr_p); purple_debug_info("lurch", "%s: deleting %i for %s to db %s\n", __func__, curr_id, from, db_fn_omemo); ret_val = omemo_storage_user_device_id_delete(from, curr_id, db_fn_omemo); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to delete %i for %s from %s", curr_id, from, db_fn_omemo); goto cleanup; } } cleanup: if (err_msg_dbg) { purple_debug_error("lurch", "%s: %s (%i)\n", __func__, err_msg_dbg, ret_val); free(err_msg_dbg); } free(db_fn_omemo); omemo_devicelist_destroy(dl_db_p); axc_context_destroy_all(axc_ctx_p); g_list_free_full(add_l_p, free); g_list_free_full(del_l_p, free); free(bundle_node_name); free(debug_str); return ret_val; } /** * A JabberPEPHandler function. * Is used to handle the own devicelist and also perform install-time functions. */ static void lurch_pep_own_devicelist_request_handler(JabberStream * js_p, const char * from, xmlnode * items_p) { int ret_val = 0; char * err_msg_dbg = (void *) 0; int len = 0; PurpleAccount * acc_p = (void *) 0; char * uname = (void *) 0; axc_context * axc_ctx_p = (void *) 0; uint32_t own_id = 0; int needs_publishing = 1; omemo_devicelist * dl_p = (void *) 0; char * dl_xml = (void *) 0; xmlnode * publish_node_dl_p = (void *) 0; acc_p = purple_connection_get_account(js_p->gc); uname = lurch_util_uname_strip(purple_account_get_username(acc_p)); if (!uninstall) { purple_debug_info("lurch", "%s: %s\n", __func__, "preparing installation..."); ret_val = lurch_axc_prepare(uname); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to prepare axc"); goto cleanup; } purple_debug_info("lurch", "%s: %s\n", __func__, "...done"); } ret_val = lurch_util_axc_get_init_ctx(uname, &axc_ctx_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to init axc ctx"); goto cleanup; } ret_val = axc_get_device_id(axc_ctx_p, &own_id); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to get own id"); goto cleanup; } if (!items_p) { purple_debug_info("lurch", "%s: %s\n", __func__, "no devicelist yet, creating it"); ret_val = omemo_devicelist_create(uname, &dl_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to create devicelist"); goto cleanup; } ret_val = omemo_devicelist_add(dl_p, own_id); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to add own id %i to devicelist", own_id); goto cleanup; } } else { purple_debug_info("lurch", "%s: %s\n", __func__, "comparing received devicelist with cached one"); ret_val = omemo_devicelist_import(xmlnode_to_str(items_p, &len), uname, &dl_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to import received devicelist"); goto cleanup; } ret_val = omemo_devicelist_contains_id(dl_p, own_id); if (ret_val == 1) { purple_debug_info("lurch", "%s: %s\n", __func__, "own id was already contained in received devicelist, doing nothing"); needs_publishing = 0; } else if (ret_val == 0) { if (!uninstall) { purple_debug_info("lurch", "%s: %s\n", __func__, "own id was missing, adding it"); ret_val = omemo_devicelist_add(dl_p, own_id); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to add own id %i to devicelist", own_id); goto cleanup; } } else { needs_publishing = 0; } } else { err_msg_dbg = g_strdup_printf("failed to look up if the devicelist contains the own id"); goto cleanup; } } if (needs_publishing) { purple_debug_info("lurch", "%s: %s\n", __func__, "devicelist needs publishing..."); ret_val = omemo_devicelist_export(dl_p, &dl_xml); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to export new devicelist"); goto cleanup; } publish_node_dl_p = xmlnode_from_str(dl_xml, -1); jabber_pep_publish(js_p, publish_node_dl_p); purple_debug_info("lurch", "%s: \n%s:\n", __func__, "...done"); } ret_val = lurch_bundle_publish_own(js_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to publish own bundle"); goto cleanup; } ret_val = lurch_devicelist_process(uname, dl_p, js_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to process the devicelist"); goto cleanup; } cleanup: if (err_msg_dbg) { purple_debug_error("lurch", "%s: %s (%i)\n", __func__, err_msg_dbg, ret_val); free(err_msg_dbg); } g_free(uname); axc_context_destroy_all(axc_ctx_p); omemo_devicelist_destroy(dl_p); free(dl_xml); } /** * A JabberPEPHandler function. * On receiving a devicelist PEP updates the database entry. */ static void lurch_pep_devicelist_event_handler(JabberStream * js_p, const char * from, xmlnode * items_p) { int ret_val = 0; int len = 0; char * err_msg_dbg = (void *) 0; char * uname = (void *) 0; omemo_devicelist * dl_in_p = (void *) 0; uname = lurch_util_uname_strip(purple_account_get_username(purple_connection_get_account(js_p->gc))); if (!strncmp(uname, from, strnlen(uname, JABBER_MAX_LEN_BARE))) { //own devicelist is dealt with in own handler lurch_pep_own_devicelist_request_handler(js_p, from, items_p); goto cleanup; } purple_debug_info("lurch", "%s: %s received devicelist update from %s\n", __func__, uname, from); ret_val = omemo_devicelist_import(xmlnode_to_str(items_p, &len), from, &dl_in_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to import devicelist"); goto cleanup; } ret_val = lurch_devicelist_process(uname, dl_in_p, js_p); if(ret_val) { err_msg_dbg = g_strdup_printf("failed to process devicelist"); goto cleanup; } cleanup: if (err_msg_dbg) { purple_debug_error("lurch", "%s: %s (%i)\n", __func__, err_msg_dbg, ret_val); g_free(err_msg_dbg); } g_free(uname); omemo_devicelist_destroy(dl_in_p); } /** * Set as callback for the "account connected" signal. * Requests the own devicelist, as that requires an active connection (as opposed to just registering PEP handlers). */ static void lurch_account_connect_cb(PurpleAccount * acc_p) { int ret_val = 0; JabberStream * js_p = (void *) 0; char * uname = (void *) 0; char * dl_ns = (void *) 0; js_p = purple_connection_get_protocol_data(purple_account_get_connection(acc_p)); if (strncmp(purple_account_get_protocol_id(acc_p), JABBER_PROTOCOL_ID, strlen(JABBER_PROTOCOL_ID))) { return; } // remove unused account preferences purple_account_remove_setting(acc_p, "lurch_initialised"); ret_val = omemo_devicelist_get_pep_node_name(&dl_ns); if (ret_val) { purple_debug_error("lurch", "%s: %s (%i)\n", __func__, "failed to get devicelist pep node name", ret_val); goto cleanup; } uname = lurch_util_uname_strip(purple_account_get_username(acc_p)); jabber_pep_request_item(js_p, uname, dl_ns, (void *) 0, lurch_pep_own_devicelist_request_handler); cleanup: g_free(uname); free(dl_ns); } /** * For a list of lurch_addrs, checks which ones do not have an active session. * Note that the structs are not copied, the returned list is just a subset * of the pointers of the input list. * * @param addr_l_p A list of pointers to lurch_addr structs. * @param axc_ctx_p The axc_context to use. * @param no_sess_l_pp Will point to a list that contains pointers to those * addresses that do not have a session. * @return 0 on success, negative on error. */ static int lurch_axc_sessions_exist(GList * addr_l_p, axc_context * axc_ctx_p, GList ** no_sess_l_pp){ int ret_val = 0; GList * no_sess_l_p = (void *) 0; GList * curr_p; lurch_addr * curr_addr_p; axc_address curr_axc_addr = {0}; for (curr_p = addr_l_p; curr_p; curr_p = curr_p->next) { curr_addr_p = (lurch_addr *) curr_p->data; curr_axc_addr.name = curr_addr_p->jid; curr_axc_addr.name_len = strnlen(curr_axc_addr.name, JABBER_MAX_LEN_BARE); curr_axc_addr.device_id = curr_addr_p->device_id; ret_val = axc_session_exists_initiated(&curr_axc_addr, axc_ctx_p); if (ret_val < 0) { purple_debug_error("lurch", "%s: %s (%i)\n", __func__, "failed to see if session exists", ret_val); goto cleanup; } else if (ret_val > 0) { ret_val = 0; continue; } else { no_sess_l_p = g_list_prepend(no_sess_l_p, curr_addr_p); ret_val = 0; } } *no_sess_l_pp = no_sess_l_p; cleanup: return ret_val; } /** * Adds an omemo devicelist to a GList of lurch_addrs. * * @param addrs_p Pointer to the list to add to. Remember NULL is a valid GList *. * @param dl_p Pointer to the omemo devicelist to add. * @param exclude_id_p Pointer to an ID that is not to be added. Useful when adding the own devicelist. Can be NULL. * @return Pointer to the updated GList on success, NULL on error. */ static GList * lurch_addr_list_add(GList * addrs_p, const omemo_devicelist * dl_p, const uint32_t * exclude_id_p) { int ret_val = 0; GList * new_l_p = addrs_p; GList * dl_l_p = (void *) 0; GList * curr_p = (void *) 0; lurch_addr curr_addr = {0}; uint32_t curr_id = 0; lurch_addr * temp_addr_p = (void *) 0; curr_addr.jid = g_strdup(omemo_devicelist_get_owner(dl_p)); dl_l_p = omemo_devicelist_get_id_list(dl_p); for (curr_p = dl_l_p; curr_p; curr_p = curr_p->next) { curr_id = omemo_devicelist_list_data(curr_p); if (exclude_id_p && *exclude_id_p == curr_id) { continue; } curr_addr.device_id = curr_id; temp_addr_p = malloc(sizeof(lurch_addr)); if (!temp_addr_p) { ret_val = LURCH_ERR_NOMEM; goto cleanup; } memcpy(temp_addr_p, &curr_addr, sizeof(lurch_addr)); new_l_p = g_list_prepend(new_l_p, temp_addr_p); } cleanup: g_list_free_full(dl_l_p, free); if (ret_val) { g_list_free_full(new_l_p, lurch_addr_list_destroy_func); return (void *) 0; } else { return new_l_p; } } /** * Does the final steps of encrypting the message. * If all devices have sessions, does the actual encrypting. * If not, saves it and sends bundle request to the missing devices so that the message can be sent at a later time. * * Note that if msg_stanza_pp points to NULL, both om_msg_p and addr_l_p must not be freed by the calling function. * * @param js_p Pointer to the JabberStream to use. * @param axc_ctx_p Pointer to the axc_context to use. * @param om_msg_p Pointer to the omemo message. * @param addr_l_p Pointer to a GList of lurch_addr structs that are supposed to receive the message. * @param msg_stanza_pp Pointer to the pointer to the stanza. * Is either changed to point to the encrypted message, or to NULL if the message is to be sent later. * @return 0 on success, negative on error. * */ static int lurch_msg_finalize_encryption(JabberStream * js_p, axc_context * axc_ctx_p, omemo_message * om_msg_p, GList * addr_l_p, xmlnode ** msg_stanza_pp) { int ret_val = 0; char * err_msg_dbg = (void *) 0; GList * no_sess_l_p = (void *) 0; char * xml = (void *) 0; xmlnode * temp_node_p = (void *) 0; lurch_queued_msg * qmsg_p = (void *) 0; GList * curr_item_p = (void *) 0; lurch_addr curr_addr = {0}; ret_val = lurch_axc_sessions_exist(addr_l_p, axc_ctx_p, &no_sess_l_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to check if sessions exist"); goto cleanup; } if (!no_sess_l_p) { ret_val = lurch_msg_encrypt_for_addrs(om_msg_p, addr_l_p, axc_ctx_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to encrypt symmetric key for addrs"); goto cleanup; } ret_val = lurch_export_encrypted(om_msg_p, &xml); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to export omemo msg to xml"); goto cleanup; } omemo_message_destroy(om_msg_p); temp_node_p = xmlnode_from_str(xml, -1); *msg_stanza_pp = temp_node_p; } else { ret_val = lurch_queued_msg_create(om_msg_p, addr_l_p, no_sess_l_p, &qmsg_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to create queued message"); goto cleanup; } for (curr_item_p = no_sess_l_p; curr_item_p; curr_item_p = curr_item_p->next) { curr_addr.jid = ((lurch_addr *)curr_item_p->data)->jid; curr_addr.device_id = ((lurch_addr *)curr_item_p->data)->device_id; purple_debug_info("lurch", "%s: %s has device without session %i, requesting bundle\n", __func__, curr_addr.jid, curr_addr.device_id); lurch_bundle_request_do(js_p, curr_addr.jid, curr_addr.device_id, qmsg_p); } *msg_stanza_pp = (void *) 0; } cleanup: if (err_msg_dbg) { purple_debug_error("lurch", "%s: %s (%i)\n", __func__, err_msg_dbg, ret_val); free(err_msg_dbg); *msg_stanza_pp = (void *) 0; } if (!qmsg_p || ret_val) { free(qmsg_p); } free(xml); return ret_val; } /** * Set as callback for the "sending xmlnode" signal. * Encrypts the message body, if applicable. */ static void lurch_message_encrypt_im(PurpleConnection * gc_p, xmlnode ** msg_stanza_pp) { int ret_val = 0; char * err_msg_dbg = (void *) 0; int len = 0; PurpleAccount * acc_p = (void *) 0; char * uname = (void *) 0; char * db_fn_omemo = (void *) 0; const char * to = (void *) 0; omemo_devicelist * dl_p = (void *) 0; GList * recipient_dl_p = (void *) 0; omemo_devicelist * user_dl_p = (void *) 0; GList * own_dl_p = (void *) 0; axc_context * axc_ctx_p = (void *) 0; uint32_t own_id = 0; omemo_message * msg_p = (void *) 0; GList * addr_l_p = (void *) 0; char * recipient = (void *) 0; char * tempxml = (void *) 0; recipient = jabber_get_bare_jid(xmlnode_get_attrib(*msg_stanza_pp, "to")); acc_p = purple_connection_get_account(gc_p); uname = lurch_util_uname_strip(purple_account_get_username(acc_p)); db_fn_omemo = lurch_util_uname_get_db_fn(uname, LURCH_DB_NAME_OMEMO); ret_val = omemo_storage_chatlist_exists(recipient, db_fn_omemo); if (ret_val < 0) { err_msg_dbg = g_strdup_printf("failed to look up %s in DB %s", recipient, db_fn_omemo); goto cleanup; } else if (ret_val == 1) { purple_debug_info("lurch", "%s: %s is on blacklist, skipping encryption\n", __func__, recipient); goto cleanup; } ret_val = lurch_util_axc_get_init_ctx(uname, &axc_ctx_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to get axc ctx for %s", uname); goto cleanup; } ret_val = axc_get_device_id(axc_ctx_p, &own_id); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to get device id"); goto cleanup; } tempxml = xmlnode_to_str(*msg_stanza_pp, &len); ret_val = omemo_message_prepare_encryption(tempxml, own_id, &crypto, OMEMO_STRIP_ALL, &msg_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to construct omemo message"); goto cleanup; } to = omemo_message_get_recipient_name_bare(msg_p); // determine if recipient is omemo user ret_val = omemo_storage_user_devicelist_retrieve(to, db_fn_omemo, &dl_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to retrieve devicelist for %s", to); goto cleanup; } free(tempxml); ret_val = omemo_devicelist_export(dl_p, &tempxml); if(ret_val) { err_msg_dbg = g_strdup_printf("failed to export devicelist for %s", to); goto cleanup; } purple_debug_info("lurch", "retrieved devicelist for %s:\n%s\n", to, tempxml); recipient_dl_p = omemo_devicelist_get_id_list(dl_p); if (!recipient_dl_p) { ret_val = axc_session_exists_any(to, axc_ctx_p); if (ret_val < 0) { err_msg_dbg = g_strdup_printf("failed to check if session exists for %s in %s's db\n", to, uname); goto cleanup; } else if (ret_val == 1) { purple_conv_present_error(recipient, purple_connection_get_account(gc_p), "Even though an encrypted session exists, the recipient's devicelist is empty." "The user probably uninstalled OMEMO, so you can add this conversation to the blacklist."); } else { goto cleanup; } } ret_val = omemo_storage_user_devicelist_retrieve(uname, db_fn_omemo, &user_dl_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to retrieve devicelist for %s", uname); goto cleanup; } omemo_devicelist_export(user_dl_p, &tempxml); purple_debug_info("lurch", "retrieved own devicelist:\n%s\n", tempxml); own_dl_p = omemo_devicelist_get_id_list(user_dl_p); if (!own_dl_p) { err_msg_dbg = g_strdup_printf("no own devicelist"); goto cleanup; } addr_l_p = lurch_addr_list_add(addr_l_p, user_dl_p, &own_id); if (g_strcmp0(uname, to)) { addr_l_p = lurch_addr_list_add(addr_l_p, dl_p, (void *) 0); } ret_val = lurch_msg_finalize_encryption(purple_connection_get_protocol_data(gc_p), axc_ctx_p, msg_p, addr_l_p, msg_stanza_pp); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to finalize omemo message"); goto cleanup; } cleanup: if (err_msg_dbg) { purple_conv_present_error(recipient, purple_connection_get_account(gc_p), LURCH_ERR_STRING_ENCRYPT); purple_debug_error("lurch", "%s: %s (%i)\n", __func__, err_msg_dbg, ret_val); free(err_msg_dbg); *msg_stanza_pp = (void *) 0; } if (ret_val) { omemo_message_destroy(msg_p); g_list_free_full(addr_l_p, lurch_addr_list_destroy_func); } free(recipient); free(uname); free(db_fn_omemo); omemo_devicelist_destroy(dl_p); g_list_free_full(recipient_dl_p, free); omemo_devicelist_destroy(user_dl_p); g_list_free_full(own_dl_p, free); axc_context_destroy_all(axc_ctx_p); free(tempxml); } static void lurch_message_encrypt_groupchat(PurpleConnection * gc_p, xmlnode ** msg_stanza_pp) { int ret_val = 0; char * err_msg_dbg = (void *) 0; int len; char * uname = (void *) 0; char * db_fn_omemo = (void *) 0; axc_context * axc_ctx_p = (void *) 0; uint32_t own_id = 0; char * tempxml = (void *) 0; omemo_message * om_msg_p = (void *) 0; omemo_devicelist * user_dl_p = (void *) 0; GList * addr_l_p = (void *) 0; PurpleConversation * conv_p = (void *) 0; PurpleConvChat * chat_p = (void *) 0; JabberChat * muc_p = (void *) 0; JabberChatMember * curr_muc_member_p = (void *) 0; xmlnode * body_node_p = (void *) 0; GList * curr_item_p = (void *) 0; char * curr_muc_member_jid = (void *) 0; omemo_devicelist * curr_dl_p = (void *) 0; const char * to = xmlnode_get_attrib(*msg_stanza_pp, "to"); uname = lurch_util_uname_strip(purple_account_get_username(purple_connection_get_account(gc_p))); db_fn_omemo = lurch_util_uname_get_db_fn(uname, LURCH_DB_NAME_OMEMO); ret_val = omemo_storage_chatlist_exists(to, db_fn_omemo); if (ret_val < 0) { err_msg_dbg = g_strdup_printf("failed to access db %s", db_fn_omemo); goto cleanup; } else if (ret_val == 0) { goto cleanup; } ret_val = lurch_util_axc_get_init_ctx(uname, &axc_ctx_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to get axc ctx for %s", uname); goto cleanup; } ret_val = axc_get_device_id(axc_ctx_p, &own_id); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to get device id"); goto cleanup; } tempxml = xmlnode_to_str(*msg_stanza_pp, &len); ret_val = omemo_message_prepare_encryption(tempxml, own_id, &crypto, OMEMO_STRIP_ALL, &om_msg_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to construct omemo message"); goto cleanup; } ret_val = omemo_storage_user_devicelist_retrieve(uname, db_fn_omemo, &user_dl_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to retrieve devicelist for %s", uname); goto cleanup; } addr_l_p = lurch_addr_list_add(addr_l_p, user_dl_p, &own_id); conv_p = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, to, purple_connection_get_account(gc_p)); if (!conv_p) { err_msg_dbg = g_strdup_printf("could not find groupchat %s", to); goto cleanup; } chat_p = purple_conversation_get_chat_data(conv_p); muc_p = jabber_chat_find_by_conv(conv_p); if (!muc_p) { err_msg_dbg = g_strdup_printf("could not find muc struct for groupchat %s", to); goto cleanup; } for (curr_item_p = g_hash_table_get_values(muc_p->members); curr_item_p; curr_item_p = curr_item_p->next) { curr_muc_member_p = (JabberChatMember *) curr_item_p->data; curr_muc_member_jid = jabber_get_bare_jid(curr_muc_member_p->jid); if (!curr_muc_member_jid) { err_msg_dbg = g_strdup_printf("Could not find the JID for %s - the channel needs to be non-anonymous!", curr_muc_member_p->handle); purple_conv_present_error(purple_conversation_get_name(conv_p), purple_connection_get_account(gc_p), err_msg_dbg); g_free(err_msg_dbg); err_msg_dbg = (void *) 0; continue; } // libpurple (rightly) assumes that in MUCs the message will come back anyway so it's not written to the chat // but encrypting and decrypting for yourself should not be done with the double ratchet, so the own device is skipped // and the typed message written to the chat window manually without sending if (!g_strcmp0(curr_muc_member_jid, uname)) { body_node_p = xmlnode_get_child(*msg_stanza_pp, "body"); purple_conv_chat_write(chat_p, curr_muc_member_p->handle, xmlnode_get_data(body_node_p), PURPLE_MESSAGE_SEND, time((void *) 0)); continue; } ret_val = omemo_storage_user_devicelist_retrieve(curr_muc_member_jid, db_fn_omemo, &curr_dl_p); if (ret_val) { err_msg_dbg = g_strdup_printf("Could not retrieve the devicelist for %s from %s", curr_muc_member_jid, db_fn_omemo); goto cleanup; } if (omemo_devicelist_is_empty(curr_dl_p)) { err_msg_dbg = g_strdup_printf("User %s is no OMEMO user (does not have a devicelist). " "This user cannot read any incoming encrypted messages and will send his own messages in the clear!", curr_muc_member_jid); purple_conv_present_error(purple_conversation_get_name(conv_p), purple_connection_get_account(gc_p), err_msg_dbg); g_free(err_msg_dbg); err_msg_dbg = (void *) 0; continue; } addr_l_p = lurch_addr_list_add(addr_l_p, curr_dl_p, (void *) 0); omemo_devicelist_destroy(curr_dl_p); curr_dl_p = (void *) 0; } ret_val = lurch_msg_finalize_encryption(purple_connection_get_protocol_data(gc_p), axc_ctx_p, om_msg_p, addr_l_p, msg_stanza_pp); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to finalize msg"); goto cleanup; } //TODO: properly handle this instead of removing the body completely, necessary for full EME support body_node_p = xmlnode_get_child(*msg_stanza_pp, "body"); xmlnode_free(body_node_p); cleanup: if (err_msg_dbg) { purple_conv_present_error(purple_conversation_get_name(conv_p), purple_connection_get_account(gc_p), LURCH_ERR_STRING_ENCRYPT); purple_debug_error("lurch", "%s: %s (%i)\n", __func__, err_msg_dbg, ret_val); free(err_msg_dbg); *msg_stanza_pp = (void *) 0; } if (ret_val) { omemo_message_destroy(om_msg_p); g_list_free_full(addr_l_p, lurch_addr_list_destroy_func); } free(uname); free(db_fn_omemo); axc_context_destroy_all(axc_ctx_p); free(tempxml); omemo_devicelist_destroy(user_dl_p); } static void lurch_xml_sent_cb(PurpleConnection * gc_p, xmlnode ** stanza_pp) { xmlnode * body_node_p = (void *) 0; xmlnode * encrypted_node_p = (void *) 0; char * node_name = (void *) 0; const char * type = (void *) 0; if (uninstall) { return; } if (!stanza_pp || !*stanza_pp) { return; } node_name = (*stanza_pp)->name; type = xmlnode_get_attrib(*stanza_pp, "type"); if (!g_strcmp0(node_name, "message")) { body_node_p = xmlnode_get_child(*stanza_pp, "body"); if (!body_node_p) { return; } encrypted_node_p = xmlnode_get_child(*stanza_pp, "encrypted"); if (encrypted_node_p) { return; } if (!g_strcmp0(type, "chat")) { lurch_message_encrypt_im(gc_p, stanza_pp); } else if (!g_strcmp0(type, "groupchat")) { lurch_message_encrypt_groupchat(gc_p, stanza_pp); } } } /** * Callback for the "receiving xmlnode" signal. * Decrypts message, if applicable. */ static void lurch_message_decrypt(PurpleConnection * gc_p, xmlnode ** msg_stanza_pp) { int ret_val = 0; char * err_msg_dbg = (void *) 0; int len; omemo_message * msg_p = (void *) 0; char * uname = (void *) 0; char * db_fn_omemo = (void *) 0; axc_context * axc_ctx_p = (void *) 0; uint32_t own_id = 0; uint8_t * key_p = (void *) 0; size_t key_len = 0; axc_buf * key_buf_p = (void *) 0; axc_buf * key_decrypted_p = (void *) 0; char * sender_name = (void *) 0; axc_address sender_addr = {0}; char * bundle_node_name = (void *) 0; omemo_message * keytransport_msg_p = (void *) 0; char * xml = (void *) 0; char * sender = (void *) 0; char ** split = (void *) 0; char * room_name = (void *) 0; char * buddy_nick = (void *) 0; xmlnode * plaintext_msg_node_p = (void *) 0; char * recipient_bare_jid = (void *) 0; PurpleConversation * conv_p = (void *) 0; JabberChat * muc_p = (void *) 0; JabberChatMember * muc_member_p = (void *) 0; const char * type = xmlnode_get_attrib(*msg_stanza_pp, "type"); const char * from = xmlnode_get_attrib(*msg_stanza_pp, "from"); const char * to = xmlnode_get_attrib(*msg_stanza_pp, "to"); if (uninstall) { goto cleanup; } uname = lurch_util_uname_strip(purple_account_get_username(purple_connection_get_account(gc_p))); db_fn_omemo = lurch_util_uname_get_db_fn(uname, LURCH_DB_NAME_OMEMO); // on prosody and possibly other servers, messages to the own account do not have a recipient if (!to) { recipient_bare_jid = g_strdup(uname); } else { recipient_bare_jid = jabber_get_bare_jid(to); } if (!g_strcmp0(type, "chat")) { sender = jabber_get_bare_jid(from); ret_val = omemo_storage_chatlist_exists(sender, db_fn_omemo); if (ret_val < 0) { err_msg_dbg = g_strdup_printf("failed to look up %s in %s", sender, db_fn_omemo); goto cleanup; } else if (ret_val == 1) { purple_conv_present_error(sender, purple_connection_get_account(gc_p), "Received encrypted message in blacklisted conversation."); } } else if (!g_strcmp0(type, "groupchat")) { split = g_strsplit(from, "/", 2); room_name = split[0]; buddy_nick = split[1]; ret_val = omemo_storage_chatlist_exists(room_name, db_fn_omemo); if (ret_val < 0) { err_msg_dbg = g_strdup_printf("failed to look up %s in %s", room_name, db_fn_omemo); goto cleanup; } else if (ret_val == 0) { purple_conv_present_error(room_name, purple_connection_get_account(gc_p), "Received encrypted message in non-OMEMO room."); } conv_p = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, room_name, purple_connection_get_account(gc_p)); if (!conv_p) { err_msg_dbg = g_strdup_printf("could not find groupchat %s", room_name); goto cleanup; } muc_p = jabber_chat_find_by_conv(conv_p); if (!muc_p) { err_msg_dbg = g_strdup_printf("could not find muc struct for groupchat %s", room_name); goto cleanup; } muc_member_p = g_hash_table_lookup(muc_p->members, buddy_nick); if (!muc_member_p) { purple_debug_misc("lurch", "Received OMEMO message in MUC %s, but the sender %s is not present in the room, which can happen during history catchup. Skipping.\n", room_name, buddy_nick); goto cleanup; } if (!muc_member_p->jid) { err_msg_dbg = g_strdup_printf("jid for user %s in muc %s not found, is the room anonymous?", buddy_nick, room_name); goto cleanup; } sender = jabber_get_bare_jid(muc_member_p->jid); } ret_val = omemo_message_prepare_decryption(xmlnode_to_str(*msg_stanza_pp, &len), &msg_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed import msg for decryption"); goto cleanup; } ret_val = lurch_util_axc_get_init_ctx(uname, &axc_ctx_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to get axc ctx for %s", uname); goto cleanup; } ret_val = axc_get_device_id(axc_ctx_p, &own_id); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to get own device id"); goto cleanup; } ret_val = omemo_message_get_encrypted_key(msg_p, own_id, &key_p, &key_len); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to get key for own id %i", own_id); goto cleanup; } if (!key_p) { purple_debug_info("lurch", "received omemo message that does not contain a key for this device, skipping\n"); goto cleanup; } key_buf_p = axc_buf_create(key_p, key_len); if (!key_buf_p) { err_msg_dbg = g_strdup_printf("failed to create buf for key"); goto cleanup; } sender_addr.name = sender; sender_addr.name_len = strnlen(sender_addr.name, JABBER_MAX_LEN_BARE); sender_addr.device_id = omemo_message_get_sender_id(msg_p); ret_val = axc_pre_key_message_process(key_buf_p, &sender_addr, axc_ctx_p, &key_decrypted_p); if (ret_val == AXC_ERR_NOT_A_PREKEY_MSG) { if (axc_session_exists_initiated(&sender_addr, axc_ctx_p)) { ret_val = axc_message_decrypt_from_serialized(key_buf_p, &sender_addr, axc_ctx_p, &key_decrypted_p); if (ret_val) { if (ret_val == SG_ERR_DUPLICATE_MESSAGE && !g_strcmp0(sender, uname) && !g_strcmp0(recipient_bare_jid, uname)) { // in combination with message carbons, sending a message to your own account results in it arriving twice purple_debug_warning("lurch", "ignoring decryption error due to a duplicate message from own account to own account\n"); *msg_stanza_pp = (void *) 0; goto cleanup; } else { err_msg_dbg = g_strdup_printf("failed to decrypt key"); goto cleanup; } } } else { purple_debug_info("lurch", "received omemo message but no session with the device exists, ignoring\n"); goto cleanup; } } else if (ret_val == AXC_ERR_INVALID_KEY_ID) { ret_val = omemo_bundle_get_pep_node_name(sender_addr.device_id, &bundle_node_name); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to get bundle pep node name"); goto cleanup; } jabber_pep_request_item(purple_connection_get_protocol_data(gc_p), sender_addr.name, bundle_node_name, (void *) 0, lurch_pep_bundle_for_keytransport); } else if (ret_val) { err_msg_dbg = g_strdup_printf("failed to prekey msg"); goto cleanup; } else { lurch_bundle_publish_own(purple_connection_get_protocol_data(gc_p)); } if (!omemo_message_has_payload(msg_p)) { purple_debug_info("lurch", "received keytransportmsg\n"); goto cleanup; } ret_val = omemo_message_export_decrypted(msg_p, axc_buf_get_data(key_decrypted_p), axc_buf_get_len(key_decrypted_p), &crypto, &xml); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to decrypt payload"); goto cleanup; } plaintext_msg_node_p = xmlnode_from_str(xml, -1); // libpurple doesn't know what to do with incoming messages addressed to someone else, so they need to be written to the conversation manually // incoming messages from the own account in MUCs are fine though if (!g_strcmp0(sender, uname) && !g_strcmp0(type, "chat")) { conv_p = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, recipient_bare_jid, purple_connection_get_account(gc_p)); if (!conv_p) { conv_p = purple_conversation_new(PURPLE_CONV_TYPE_IM, purple_connection_get_account(gc_p), recipient_bare_jid); } purple_conversation_write(conv_p, uname, xmlnode_get_data(xmlnode_get_child(plaintext_msg_node_p, "body")), PURPLE_MESSAGE_SEND, time((void *) 0)); *msg_stanza_pp = (void *) 0; } else { *msg_stanza_pp = plaintext_msg_node_p; } cleanup: if (err_msg_dbg) { purple_conv_present_error(sender, purple_connection_get_account(gc_p), LURCH_ERR_STRING_DECRYPT); purple_debug_error("lurch", "%s: %s (%i)\n", __func__, err_msg_dbg, ret_val); free(err_msg_dbg); } g_strfreev(split); free(sender); free(xml); free(bundle_node_name); free(sender_name); axc_buf_free(key_decrypted_p); axc_buf_free(key_buf_p); free(key_p); axc_context_destroy_all(axc_ctx_p); free(uname); free(db_fn_omemo); free(recipient_bare_jid); omemo_message_destroy(keytransport_msg_p); omemo_message_destroy(msg_p); } static void lurch_message_warn(PurpleConnection * gc_p, xmlnode ** msg_stanza_pp) { int ret_val = 0; xmlnode * temp_node_p = (void *) 0; char * uname = (void *) 0; char * db_fn_omemo = (void *) 0; axc_context * axc_ctx_p = (void *) 0; char * conv_name = (void *) 0; char ** split = (void *) 0; char * room_name = (void *) 0; const char * type = xmlnode_get_attrib(*msg_stanza_pp, "type"); const char * from = xmlnode_get_attrib(*msg_stanza_pp, "from"); uname = lurch_util_uname_strip(purple_account_get_username(purple_connection_get_account(gc_p))); db_fn_omemo = lurch_util_uname_get_db_fn(uname, LURCH_DB_NAME_OMEMO); ret_val = lurch_util_axc_get_init_ctx(uname, &axc_ctx_p); if (ret_val) { goto cleanup; } temp_node_p = xmlnode_get_child(*msg_stanza_pp, "body"); if (!temp_node_p) { goto cleanup; } if (!g_strcmp0(type, "chat")) { conv_name = jabber_get_bare_jid(from); ret_val = axc_session_exists_any(conv_name, axc_ctx_p); if (ret_val < 0) { goto cleanup; } else if (ret_val == 0) { goto cleanup; } else if (ret_val == 1) { ret_val = omemo_storage_chatlist_exists(conv_name, db_fn_omemo); if (ret_val == 0) { purple_conv_present_error(conv_name, purple_connection_get_account(gc_p), "Even though you have an encryption session with this user, you received a plaintext message."); } } } else if (!g_strcmp0(type, "groupchat")) { split = g_strsplit(from, "/", 2); room_name = split[0]; ret_val = omemo_storage_chatlist_exists(room_name, db_fn_omemo); if (ret_val < 0) { goto cleanup; } else if (ret_val == 0) { goto cleanup; } else if (ret_val == 1) { purple_conv_present_error(room_name, purple_connection_get_account(gc_p), "This groupchat is set to encrypted, but you received a plaintext message."); } } cleanup: free(uname); free(db_fn_omemo); free(conv_name); g_strfreev(split); axc_context_destroy_all(axc_ctx_p); } static void lurch_xml_received_cb(PurpleConnection * gc_p, xmlnode ** stanza_pp) { xmlnode * temp_node_p = (void *) 0; char * node_name = (void *) 0; if (uninstall) { return; } if (!stanza_pp || !*stanza_pp) { return; } node_name = (*stanza_pp)->name; if (!g_strcmp0(node_name, "message")) { temp_node_p = xmlnode_get_child(*stanza_pp, "encrypted"); if (temp_node_p) { lurch_message_decrypt(gc_p, stanza_pp); } else { lurch_message_warn(gc_p, stanza_pp); } } } static int lurch_topic_update_im(PurpleConversation * conv_p) { int ret_val = 0; char * uname = (void *) 0; const char * partner_name = purple_conversation_get_name(conv_p); char * partner_name_bare = (void *) 0; axc_context * axc_ctx_p = (void *) 0; char * db_fn_omemo = (void *) 0; omemo_devicelist * dl_p = (void *) 0; char * new_title = (void *) 0; uname = lurch_util_uname_strip(purple_account_get_username(purple_conversation_get_account(conv_p))); db_fn_omemo = lurch_util_uname_get_db_fn(uname, LURCH_DB_NAME_OMEMO); partner_name_bare = jabber_get_bare_jid(partner_name); if (uninstall) { goto cleanup; } ret_val = omemo_storage_chatlist_exists(partner_name_bare, db_fn_omemo); if (ret_val < 0 || ret_val > 0) { goto cleanup; } ret_val = lurch_util_axc_get_init_ctx(uname, &axc_ctx_p); if (ret_val) { goto cleanup; } ret_val = axc_session_exists_any(partner_name_bare, axc_ctx_p); if (ret_val < 0) { goto cleanup; } else if (ret_val) { new_title = g_strdup_printf("%s (%s)", partner_name, "OMEMO"); } else { ret_val = omemo_storage_user_devicelist_retrieve(partner_name_bare, db_fn_omemo, &dl_p); if (ret_val) { goto cleanup; } if (!omemo_devicelist_is_empty(dl_p)) { new_title = g_strdup_printf("%s (%s)", partner_name, "OMEMO available"); } } if (new_title) { purple_conversation_set_title(conv_p, new_title); } cleanup: free(uname); free(new_title); axc_context_destroy_all(axc_ctx_p); free(db_fn_omemo); omemo_devicelist_destroy(dl_p); free(partner_name_bare); return ret_val; } static int lurch_topic_update_chat(PurpleConversation * conv_p) { int ret_val = 0; char * uname = (void *) 0; char * db_fn_omemo = (void *) 0; char * new_title = (void *) 0; uname = lurch_util_uname_strip(purple_account_get_username(purple_conversation_get_account(conv_p))); db_fn_omemo = lurch_util_uname_get_db_fn(uname, LURCH_DB_NAME_OMEMO); if (uninstall) { goto cleanup; } ret_val = omemo_storage_chatlist_exists(purple_conversation_get_name(conv_p), db_fn_omemo); if (ret_val < 1) { goto cleanup; } new_title = g_strdup_printf("%s (%s)", purple_conversation_get_title(conv_p), "OMEMO"); purple_conversation_set_title(conv_p, new_title); cleanup: free(uname); free(db_fn_omemo); free(new_title); return ret_val; } static void lurch_conv_created_cb(PurpleConversation * conv_p) { if (strncmp(purple_account_get_protocol_id(purple_conversation_get_account(conv_p)), JABBER_PROTOCOL_ID, strlen(JABBER_PROTOCOL_ID))) { return; } if (purple_conversation_get_type(conv_p) == PURPLE_CONV_TYPE_IM) { lurch_topic_update_im(conv_p); } else if (purple_conversation_get_type(conv_p) == PURPLE_CONV_TYPE_CHAT) { lurch_topic_update_chat(conv_p); } } static void lurch_conv_updated_cb(PurpleConversation * conv_p, PurpleConvUpdateType type) { if (strncmp(purple_account_get_protocol_id(purple_conversation_get_account(conv_p)), JABBER_PROTOCOL_ID, strlen(JABBER_PROTOCOL_ID))) { return; } if (type == PURPLE_CONV_UPDATE_TITLE) { if (!topic_changed) { topic_changed = 1; if (purple_conversation_get_type(conv_p) == PURPLE_CONV_TYPE_IM) { lurch_topic_update_im(conv_p); } else if (purple_conversation_get_type(conv_p) == PURPLE_CONV_TYPE_CHAT) { lurch_topic_update_chat(conv_p); } topic_changed = 0; } else { topic_changed = 0; } } } static PurpleCmdRet lurch_cmd_func(PurpleConversation * conv_p, const gchar * cmd, gchar ** args, gchar ** error, void * data_p) { int ret_val = 0; char * err_msg = (void *) 0; char * uname = (void *) 0; char * db_fn_omemo = (void *) 0; axc_context * axc_ctx_p = (void *) 0; uint32_t id = 0; uint32_t remove_id = 0; axc_buf * key_buf_p = (void *) 0; char * fp_printable = (void *) 0; omemo_devicelist * own_dl_p = (void *) 0; omemo_devicelist * other_dl_p = (void *) 0; GList * own_l_p = (void *) 0; GList * other_l_p = (void *) 0; GList * curr_p = (void *) 0; char * temp_msg_1 = (void *) 0; char * temp_msg_2 = (void *) 0; char * temp_msg_3 = (void *) 0; xmlnode * dl_node_p = (void *) 0; char * bare_jid = (void *) 0; char * msg = (void *) 0; uname = lurch_util_uname_strip(purple_account_get_username(purple_conversation_get_account(conv_p))); db_fn_omemo = lurch_util_uname_get_db_fn(uname, LURCH_DB_NAME_OMEMO); ret_val = lurch_util_axc_get_init_ctx(uname, &axc_ctx_p); if (ret_val) { err_msg = g_strdup("Failed to create axc ctx."); goto cleanup; } ret_val = axc_get_device_id(axc_ctx_p, &id); if (ret_val) { err_msg = g_strdup_printf("Failed to access axc db %s. Does the path seem correct?", axc_context_get_db_fn(axc_ctx_p)); goto cleanup; } if (!g_strcmp0(args[0], "uninstall")) { if (!g_strcmp0(args[1], "yes")) { ret_val = omemo_devicelist_get_pep_node_name(&temp_msg_1); if (ret_val) { err_msg = g_strdup("Failed to get devicelist PEP node name."); goto cleanup; } ret_val = omemo_storage_user_devicelist_retrieve(uname, db_fn_omemo, &own_dl_p); if (ret_val) { err_msg = g_strdup_printf("Failed to access omemo db %s. Does the path seem correct?", db_fn_omemo); goto cleanup; } ret_val = axc_get_device_id(axc_ctx_p, &remove_id); if (ret_val) { err_msg = g_strdup_printf("Failed to get own ID from DB %s.", axc_context_get_db_fn(axc_ctx_p)); goto cleanup; } ret_val = omemo_devicelist_remove(own_dl_p, remove_id); if (ret_val) { err_msg = g_strdup_printf("Failed to remove %i from the list in DB %s.", remove_id, db_fn_omemo); goto cleanup; } ret_val = omemo_devicelist_export(own_dl_p, &temp_msg_1); if (ret_val) { err_msg = g_strdup("Failed to export new devicelist to xml string."); goto cleanup; } uninstall = 1; dl_node_p = xmlnode_from_str(temp_msg_1, -1); jabber_pep_publish(purple_connection_get_protocol_data(purple_conversation_get_gc(conv_p)), dl_node_p); msg = g_strdup_printf("Published devicelist minus this device's ID. " "You can deactivate the plugin now, otherwise it will be republished at the next startup. " "To delete all existing data you also have to delete the DB files in your ~/.pidgin folder."); } else { msg = g_strdup("To uninstall lurch for this device, type 'lurch uninstall yes'."); } } else if (!g_strcmp0(args[0], "help")) { msg = g_strdup("The following commands exist to interact with the lurch plugin:\n\n" "In conversations with one user:\n" " - '/lurch blacklist add': Adds conversation partner to blacklist.\n" " - '/lurch blacklist remove': Removes conversation partner from blacklist.\n" " - '/lurch show id own': Displays this device's ID.\n" " - '/lurch show id list': Displays this account's devicelist.\n" " - '/lurch show fp own': Displays this device's key fingerprint.\n" " - '/lurch show fp conv': Displays the fingerprints of all participating devices.\n" " - '/lurch remove id ': Removes a device ID from the own devicelist.\n" "\n" "In conversations with multiple users:\n" " - '/lurch enable': Enables OMEMO encryption for the conversation.\n" " - '/lurch disable': Disables OMEMO encryption for the conversation.\n" "\n" "In all types of conversations:\n" " - '/lurch help': Displays this message.\n" " - '/lurch uninstall': Uninstalls this device from OMEMO by removing its device ID from the devicelist."); } else { if(purple_conversation_get_type(conv_p) == PURPLE_CONV_TYPE_IM) { if (!g_strcmp0(args[0], "blacklist")) { if (!g_strcmp0(args[1], "add")) { temp_msg_1 = jabber_get_bare_jid(purple_conversation_get_name(conv_p)); ret_val = omemo_storage_chatlist_save(temp_msg_1, db_fn_omemo); if (ret_val) { err_msg = g_strdup_printf("Failed to look up %s in DB %s.", temp_msg_1, db_fn_omemo); goto cleanup; } purple_conversation_autoset_title(conv_p); msg = g_strdup_printf("Added %s to your blacklist. Even if OMEMO is available, it will not be used.", temp_msg_1); } else if (!g_strcmp0(args[1], "remove")) { temp_msg_1 = jabber_get_bare_jid(purple_conversation_get_name(conv_p)); ret_val = omemo_storage_chatlist_delete(temp_msg_1, db_fn_omemo); if (ret_val) { err_msg = g_strdup_printf("Failed to delete %s in DB %s.", temp_msg_1, db_fn_omemo); goto cleanup; } msg = g_strdup_printf("Removed %s from your blacklist. If OMEMO is available, it will be used.", temp_msg_1); topic_changed = 1; lurch_topic_update_im(conv_p); } else { msg = g_strdup("Valid arguments for 'lurch blacklist' are 'add' and 'remove'."); } } else if (!g_strcmp0(args[0], "show")) { if (!g_strcmp0(args[1], "id")) { if (!g_strcmp0(args[2], "own")) { msg = g_strdup_printf("Your own device ID is %i.", id); } else if (!g_strcmp0(args[2], "list")) { ret_val = omemo_storage_user_devicelist_retrieve(uname, db_fn_omemo, &own_dl_p); if (ret_val) { err_msg = g_strdup_printf("Failed to access omemo db %s.", db_fn_omemo); goto cleanup; } temp_msg_1 = g_strdup_printf("This user (%s) has the following devices:\n" "%i (this device)\n", uname, id); own_l_p = omemo_devicelist_get_id_list(own_dl_p); for (curr_p = own_l_p; curr_p; curr_p = curr_p->next) { if (omemo_devicelist_list_data(curr_p) != id) { temp_msg_2 = g_strdup_printf("%i\n", omemo_devicelist_list_data(curr_p)); temp_msg_3 = g_strconcat(temp_msg_1, temp_msg_2, NULL); g_free(temp_msg_1); temp_msg_1 = temp_msg_3; g_free(temp_msg_2); temp_msg_2 = (void *) 0; temp_msg_3 = (void *) 0; } } msg = g_strdup(temp_msg_1); } else { msg = g_strdup("Valid arguments for 'lurch show id' are 'own' to display this device's ID " "and 'list' to display this user's device list."); } } else if (!g_strcmp0(args[1], "fp")) { if (!g_strcmp0(args[2], "own")) { ret_val = axc_key_load_public_own(axc_ctx_p, &key_buf_p); if (ret_val) { err_msg = g_strdup_printf("Failed to access axc db %s.", axc_context_get_db_fn(axc_ctx_p)); goto cleanup; } fp_printable = lurch_util_fp_get_printable(key_buf_p); msg = g_strdup_printf("This device's fingerprint is:\n%s\n" "You should make sure that your conversation partner gets displayed the same for this device.", fp_printable); } else if (!g_strcmp0(args[2], "conv")) { ret_val = axc_key_load_public_own(axc_ctx_p, &key_buf_p); if (ret_val) { err_msg = g_strdup_printf("Failed to access axc db %s.", axc_context_get_db_fn(axc_ctx_p)); goto cleanup; } fp_printable = lurch_util_fp_get_printable(key_buf_p); temp_msg_1 = g_strdup_printf("The devices participating in this conversation and their fingerprints are as follows:\n" "This device's (%s:%i) fingerprint:\n%s\n", uname, id, fp_printable); ret_val = omemo_storage_user_devicelist_retrieve(uname, db_fn_omemo, &own_dl_p); if (ret_val) { err_msg = g_strdup_printf("Failed to access omemo db %s.", db_fn_omemo); goto cleanup; } own_l_p = omemo_devicelist_get_id_list(own_dl_p); for (curr_p = own_l_p; curr_p; curr_p = curr_p->next) { if (omemo_devicelist_list_data(curr_p) != id) { ret_val = axc_key_load_public_addr(uname, omemo_devicelist_list_data(curr_p), axc_ctx_p, &key_buf_p); if (ret_val < 0) { err_msg = g_strdup_printf("Failed to access axc db %s.", axc_context_get_db_fn(axc_ctx_p)); goto cleanup; } else if (ret_val == 0) { continue; } fp_printable = lurch_util_fp_get_printable(key_buf_p); axc_buf_free(key_buf_p); key_buf_p = (void *) 0; temp_msg_2 = g_strdup_printf("%s:%i's fingerprint:\n%s\n", uname, omemo_devicelist_list_data(curr_p), fp_printable); temp_msg_3 = g_strconcat(temp_msg_1, temp_msg_2, NULL); g_free(temp_msg_1); temp_msg_1 = temp_msg_3; temp_msg_3 = (void *) 0; g_free(temp_msg_2); temp_msg_2 = (void *) 0; } } bare_jid = jabber_get_bare_jid(purple_conversation_get_name(conv_p)); ret_val = omemo_storage_user_devicelist_retrieve(bare_jid, db_fn_omemo, &other_dl_p); if (ret_val) { err_msg = g_strdup_printf("Failed to access omemo db %s.", db_fn_omemo); goto cleanup; } other_l_p = omemo_devicelist_get_id_list(other_dl_p); for (curr_p = other_l_p; curr_p; curr_p = curr_p->next) { ret_val = axc_key_load_public_addr(bare_jid, omemo_devicelist_list_data(curr_p), axc_ctx_p, &key_buf_p); if (ret_val < 0) { err_msg = g_strdup_printf("Failed to access axc db %s.", axc_context_get_db_fn(axc_ctx_p)); goto cleanup; } else if (ret_val == 0) { continue; } fp_printable = lurch_util_fp_get_printable(key_buf_p); axc_buf_free(key_buf_p); key_buf_p = (void *) 0; temp_msg_2 = g_strdup_printf("%s:%i's fingerprint:\n%s\n", bare_jid, omemo_devicelist_list_data(curr_p), fp_printable); temp_msg_3 = g_strconcat(temp_msg_1, temp_msg_2, NULL); g_free(temp_msg_1); temp_msg_1 = temp_msg_3; temp_msg_3 = (void *) 0; g_free(temp_msg_2); temp_msg_2 = (void *) 0; } msg = g_strdup(temp_msg_1); } else { msg = g_strdup("Valid arguments for 'lurch show fp' are 'own' for displaying this device's fingerprint, " "and 'conv' for displaying all devices participating in this conversation and their fingerprints."); } } else { msg = g_strdup("Valid arguments for 'lurch show' are 'id' and 'fp'."); } } else if (!g_strcmp0(args[0], "remove")) { if (!g_strcmp0(args[1], "id")) { if (!args[2]) { msg = g_strdup("The command 'lurch remove id' must be followed by a device ID."); } else { ret_val = omemo_storage_user_devicelist_retrieve(uname, db_fn_omemo, &own_dl_p); if (ret_val) { err_msg = g_strdup_printf("Failed to access omemo db %s.", db_fn_omemo); goto cleanup; } remove_id = strtol(args[2], (void *) 0, 10); if (!omemo_devicelist_contains_id(own_dl_p, remove_id)) { msg = g_strdup_printf("Your devicelist does not contain the ID %s.", args[2]); } else { ret_val = omemo_devicelist_remove(own_dl_p, remove_id); if (ret_val) { err_msg = g_strdup_printf("Failed to remove %i from the list.", remove_id); goto cleanup; } ret_val = omemo_devicelist_export(own_dl_p, &temp_msg_1); if (ret_val) { err_msg = g_strdup("Failed to export new devicelist to xml string."); goto cleanup; } dl_node_p = xmlnode_from_str(temp_msg_1, -1); jabber_pep_publish(purple_connection_get_protocol_data(purple_conversation_get_gc(conv_p)), dl_node_p); msg = g_strdup_printf("Removed %i from devicelist and republished it.", remove_id); } } } else { msg = g_strdup("Valid argument for 'lurch remove' is 'id'."); } } else { msg = g_strdup("Valid arguments for 'lurch' in IMs are 'show', 'remove', 'blacklist', 'uninstall', and 'help'."); } } else if (purple_conversation_get_type(conv_p) == PURPLE_CONV_TYPE_CHAT) { if (!g_strcmp0(args[0], "enable")) { ret_val = omemo_storage_chatlist_save(purple_conversation_get_name(conv_p), db_fn_omemo); if (ret_val) { err_msg = g_strdup_printf("Failed to look up %s in DB %s.", purple_conversation_get_name(conv_p), db_fn_omemo); goto cleanup; } topic_changed = 1; lurch_topic_update_chat(conv_p); msg = g_strdup_printf("Activated OMEMO for this chat. This is a client-side setting, so every participant needs to activate it to work."); } else if (!g_strcmp0(args[0], "disable")) { ret_val = omemo_storage_chatlist_delete(purple_conversation_get_name(conv_p), db_fn_omemo); if (ret_val) { err_msg = g_strdup_printf("Failed to delete %s in DB %s.\n", purple_conversation_get_name(conv_p), db_fn_omemo); goto cleanup; } msg = g_strdup_printf("Deactivated OMEMO for this chat. " "This is a client-side setting and if other users still have it activated, you will not be able to read their messages."); purple_conversation_autoset_title(conv_p); } else { msg = g_strdup("Valid arguments for 'lurch' in groupchats are 'enable', 'disable', 'uninstall', and 'help'."); } } } if (msg) { purple_conversation_write(conv_p, "lurch", msg, PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG, time((void *) 0)); } cleanup: g_free (uname); g_free(db_fn_omemo); axc_context_destroy_all(axc_ctx_p); g_free(msg); axc_buf_free(key_buf_p); g_free(fp_printable); omemo_devicelist_destroy(own_dl_p); omemo_devicelist_destroy(other_dl_p); g_list_free_full(own_l_p, free); g_list_free_full(other_l_p, free); g_free(temp_msg_1); g_free(temp_msg_2); g_free(temp_msg_3); g_free(bare_jid); if (ret_val < 0) { *error = err_msg; return PURPLE_CMD_RET_FAILED; } else { return PURPLE_CMD_RET_OK; } } /** * Actions to perform on plugin load. * Inits the crypto and registers signal and PEP handlers. */ static gboolean lurch_plugin_load(PurplePlugin * plugin_p) { int ret_val = 0; char * err_msg_dbg = (void *) 0; char * dl_ns = (void *) 0; void * jabber_handle_p = (void *) 0; GList * accs_l_p = (void *) 0; GList * curr_p = (void *) 0; PurpleAccount * acc_p = (void *) 0; omemo_default_crypto_init(); lurch_api_init(); ret_val = omemo_devicelist_get_pep_node_name(&dl_ns); if (ret_val) { err_msg_dbg = "failed to get devicelist pep node name"; goto cleanup; } lurch_cmd_handle_id = purple_cmd_register("lurch", "wwws", PURPLE_CMD_P_PLUGIN, PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY | PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, JABBER_PROTOCOL_ID, lurch_cmd_func, "lurch <help>: " "Interface to the lurch plugin. For details, use the 'help' argument.", (void *) 0); lurch_cmd_v2_handle_id = purple_cmd_register("lurch-v2", "wwws", PURPLE_CMD_P_PLUGIN, PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY | PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, JABBER_PROTOCOL_ID, lurch_cmd_func_v2, "lurch <help>: " "NEW interface to the lurch plugin. For details, use the 'help' argument.", (void *) 0); // register handlers jabber_handle_p = purple_plugins_find_with_id(JABBER_PROTOCOL_ID); (void) purple_signal_connect_priority(jabber_handle_p, "jabber-receiving-xmlnode", plugin_p, PURPLE_CALLBACK(lurch_xml_received_cb), NULL, PURPLE_PRIORITY_HIGHEST - 100); (void) purple_signal_connect_priority(jabber_handle_p, "jabber-sending-xmlnode", plugin_p, PURPLE_CALLBACK(lurch_xml_sent_cb), NULL, PURPLE_PRIORITY_HIGHEST - 100); jabber_pep_register_handler(dl_ns, lurch_pep_devicelist_event_handler); jabber_add_feature(dl_ns, jabber_pep_namespace_only_when_pep_enabled_cb); // manually call init code if there are already accounts connected, e.g. when plugin is loaded manually accs_l_p = purple_accounts_get_all_active(); for (curr_p = accs_l_p; curr_p; curr_p = curr_p->next) { acc_p = (PurpleAccount *) curr_p->data; if (purple_account_is_connected(acc_p)) { if (!g_strcmp0(purple_account_get_protocol_id(acc_p), JABBER_PROTOCOL_ID)) { lurch_account_connect_cb(acc_p); } } } // register install callback (void) purple_signal_connect(purple_accounts_get_handle(), "account-signed-on", plugin_p, PURPLE_CALLBACK(lurch_account_connect_cb), NULL); (void) purple_signal_connect(purple_conversations_get_handle(), "conversation-created", plugin_p, PURPLE_CALLBACK(lurch_conv_created_cb), NULL); (void) purple_signal_connect(purple_conversations_get_handle(), "conversation-updated", plugin_p, PURPLE_CALLBACK(lurch_conv_updated_cb), NULL); cleanup: free(dl_ns); g_list_free(accs_l_p); if (ret_val) { purple_debug_error("lurch", "%s: %s (%i)\n", __func__, err_msg_dbg, ret_val); omemo_default_crypto_teardown(); return FALSE; } return TRUE; } static gboolean lurch_plugin_unload(PurplePlugin * plugin_p) { purple_cmd_unregister(lurch_cmd_handle_id); purple_cmd_unregister(lurch_cmd_v2_handle_id); lurch_api_unload(); omemo_default_crypto_teardown(); return TRUE; } static PurplePluginPrefFrame * lurch_get_plugin_pref_frame(PurplePlugin * plugin_p) { PurplePluginPrefFrame * frame_p; PurplePluginPref * ppref_p; frame_p = purple_plugin_pref_frame_new(); ppref_p = purple_plugin_pref_new_with_label("Extended logging"); purple_plugin_pref_frame_add(frame_p, ppref_p); ppref_p = purple_plugin_pref_new_with_name_and_label( LURCH_PREF_AXC_LOGGING, "Show log output from underlying libraries"); purple_plugin_pref_frame_add(frame_p, ppref_p); ppref_p = purple_plugin_pref_new_with_name_and_label( LURCH_PREF_AXC_LOGGING_LEVEL, "Log level"); purple_plugin_pref_set_type(ppref_p, PURPLE_PLUGIN_PREF_CHOICE); purple_plugin_pref_add_choice(ppref_p, "ERROR", GINT_TO_POINTER(AXC_LOG_ERROR)); purple_plugin_pref_add_choice(ppref_p, "WARNING", GINT_TO_POINTER(AXC_LOG_WARNING)); purple_plugin_pref_add_choice(ppref_p, "NOTICE", GINT_TO_POINTER(AXC_LOG_NOTICE)); purple_plugin_pref_add_choice(ppref_p, "INFO", GINT_TO_POINTER(AXC_LOG_INFO)); purple_plugin_pref_add_choice(ppref_p, "DEBUG", GINT_TO_POINTER(AXC_LOG_DEBUG)); purple_plugin_pref_frame_add(frame_p, ppref_p); return frame_p; } static PurplePluginUiInfo prefs_info = { lurch_get_plugin_pref_frame, 0, /* page_num (Reserved) */ NULL, /* frame (Reserved) */ /* padding */ NULL, NULL, NULL, NULL }; static PurplePluginInfo info = { PURPLE_PLUGIN_MAGIC, PURPLE_MAJOR_VERSION, PURPLE_MINOR_VERSION, PURPLE_PLUGIN_STANDARD, NULL, 0, NULL, PURPLE_PRIORITY_DEFAULT, "core-riba-lurch", "lurch", LURCH_VERSION, "Implements OMEMO for libpurple.", "End-to-end encryption using the Signal protocol, adapted for XMPP.", LURCH_AUTHOR, "https://github.com/gkdr/lurch", lurch_plugin_load, lurch_plugin_unload, NULL, NULL, NULL, &prefs_info, // plugin config, see libpurple/plugins/pluginpref_example.c NULL, // plugin actions, see https://developer.pidgin.im/wiki/CHowTo/PluginActionsHowTo NULL, NULL, NULL, NULL }; static void lurch_plugin_init(PurplePlugin * plugin_p) { PurplePluginInfo * info_p = plugin_p->info; info_p->dependencies = g_list_prepend(info_p->dependencies, "prpl-jabber"); purple_prefs_add_none(LURCH_PREF_ROOT); purple_prefs_add_bool(LURCH_PREF_AXC_LOGGING, FALSE); purple_prefs_add_int(LURCH_PREF_AXC_LOGGING_LEVEL, AXC_LOG_INFO); } PURPLE_INIT_PLUGIN(lurch, lurch_plugin_init, info) purple-lurch-0.6.8+git20200527.388605/src/lurch.h000066400000000000000000000002341366351464100204110ustar00rootroot00000000000000#ifndef __LURCH_H # define __LURCH_H # define LURCH_VERSION "0.6.9-dev" # define LURCH_AUTHOR "Richard Bayerle " #endif /* __LURCH_H */ purple-lurch-0.6.8+git20200527.388605/src/lurch_api.c000066400000000000000000000543731366351464100212520ustar00rootroot00000000000000#include #include #include #include "chat.h" #include "pep.h" #include "axc.h" #include "libomemo.h" #include "libomemo_storage.h" #include "lurch_api.h" #include "lurch_util.h" #define MODULE_NAME "lurch-api" /** * Returns a GList of int32_t * containing the devices of the calling account. * If the current device is contained in it (which it should be!), it will be first in the list. */ static int32_t lurch_api_id_list_get_own(PurpleAccount * acc_p, GList ** list_pp) { int32_t ret_val = 0; char * uname = (void *) 0; char * db_fn_omemo = (void *) 0; omemo_devicelist * dl_p = (void *) 0; axc_context * axc_ctx_p = (void *) 0; uint32_t own_id = 0; GList * id_list = (void *) 0; uint32_t * id_p = (void *) 0; uname = lurch_util_uname_strip(purple_account_get_username(acc_p)); db_fn_omemo = lurch_util_uname_get_db_fn(uname, LURCH_DB_NAME_OMEMO); ret_val = omemo_storage_user_devicelist_retrieve(uname, db_fn_omemo, &dl_p); if (ret_val) { purple_debug_error(MODULE_NAME, "Failed to access OMEMO DB %s.", db_fn_omemo); goto cleanup; } ret_val = lurch_util_axc_get_init_ctx(uname, &axc_ctx_p); if (ret_val) { purple_debug_error(MODULE_NAME, "Failed to create axc ctx."); goto cleanup; } ret_val = axc_get_device_id(axc_ctx_p, &own_id); if (ret_val) { purple_debug_error(MODULE_NAME, "Failed to access axc db %s. Does the path seem correct?", axc_context_get_db_fn(axc_ctx_p)); goto cleanup; } if (!omemo_devicelist_contains_id(dl_p, own_id)) { purple_debug_warning(MODULE_NAME, "This device's ID is not contained in your devicelist?"); goto cleanup; } ret_val = omemo_devicelist_remove(dl_p, own_id); if (ret_val) { purple_debug_error(MODULE_NAME, "Failed to remove the ID from the devicelist."); goto cleanup; } id_list = omemo_devicelist_get_id_list(dl_p); id_p = g_malloc(sizeof(uint32_t)); if (!id_p) { ret_val = LURCH_ERR_NOMEM; goto cleanup; } *id_p = own_id; id_list = g_list_prepend(id_list, id_p); cleanup: if (!ret_val) { *list_pp = id_list; } g_free(uname); g_free(db_fn_omemo); omemo_devicelist_destroy(dl_p); axc_context_destroy_all(axc_ctx_p); return ret_val; } void lurch_api_id_list_handler(PurpleAccount * acc_p, void (*cb)(int32_t err, GList * id_list, void * user_data_p), void * user_data_p) { int32_t ret_val = 0; GList * id_list = (void *) 0; ret_val = lurch_api_id_list_get_own(acc_p, &id_list); if (ret_val) { purple_debug_error(MODULE_NAME, "Failed to get the own, sorted ID list."); goto cleanup; } cleanup: cb(ret_val, id_list, user_data_p); g_list_free_full(id_list, free); } void lurch_api_id_remove_handler(PurpleAccount * acc_p, uint32_t device_id, void (*cb)(int32_t err, void * user_data_p), void * user_data_p) { int32_t ret_val = 0; char * uname = (void *) 0; char * db_fn_omemo = (void *) 0; omemo_devicelist * dl_p = (void *) 0; char * exported_devicelist = (void *) 0; xmlnode * publish_node_p = (void *) 0; uname = lurch_util_uname_strip(purple_account_get_username(acc_p)); db_fn_omemo = lurch_util_uname_get_db_fn(uname, LURCH_DB_NAME_OMEMO); ret_val = omemo_storage_user_devicelist_retrieve(uname, db_fn_omemo, &dl_p); if (ret_val) { purple_debug_error(MODULE_NAME, "Failed to access the OMEMO DB %s to retrieve the devicelist.", db_fn_omemo); goto cleanup; } if (!omemo_devicelist_contains_id(dl_p, device_id)) { ret_val = LURCH_ERR_DEVICE_NOT_IN_LIST; purple_debug_error(MODULE_NAME, "Your devicelist does not contain the device ID %i.", device_id); goto cleanup; } ret_val = omemo_devicelist_remove(dl_p, device_id); if (ret_val) { purple_debug_error(MODULE_NAME, "Failed to remove the device ID %i from %s's devicelist.", device_id, uname); goto cleanup; } ret_val = omemo_devicelist_export(dl_p, &exported_devicelist); if (ret_val) { purple_debug_error(MODULE_NAME, "Failed to export new devicelist without device ID %i.", device_id); goto cleanup; } publish_node_p = xmlnode_from_str(exported_devicelist, -1); jabber_pep_publish(purple_connection_get_protocol_data(purple_account_get_connection(acc_p)), publish_node_p); // publish_node_p will be freed by the jabber prpl cleanup: cb(ret_val, user_data_p); g_free(uname); g_free(db_fn_omemo); omemo_devicelist_destroy(dl_p); g_free(exported_devicelist); } void lurch_api_enable_im_handler(PurpleAccount * acc_p, const char * contact_bare_jid, void (*cb)(int32_t err, void * user_data_p), void * user_data_p) { int32_t ret_val = 0; char * uname = (void *) 0; char * db_fn_omemo = (void *) 0; uname = lurch_util_uname_strip(purple_account_get_username(acc_p)); db_fn_omemo = lurch_util_uname_get_db_fn(uname, LURCH_DB_NAME_OMEMO); ret_val = omemo_storage_chatlist_delete(contact_bare_jid, db_fn_omemo); if (ret_val) { purple_debug_error(MODULE_NAME, "Failed to delete %s from the blacklist in OMEMO DB %s.", contact_bare_jid, db_fn_omemo); } cb(ret_val, user_data_p); g_free(uname); g_free(db_fn_omemo); } void lurch_api_disable_im_handler(PurpleAccount * acc_p, const char * contact_bare_jid, void (*cb)(int32_t err, void * user_data_p), void * user_data_p) { int32_t ret_val = 0; char * uname = (void *) 0; char * db_fn_omemo = (void *) 0; uname = lurch_util_uname_strip(purple_account_get_username(acc_p)); db_fn_omemo = lurch_util_uname_get_db_fn(uname, LURCH_DB_NAME_OMEMO); ret_val = omemo_storage_chatlist_save(contact_bare_jid, db_fn_omemo); if (ret_val) { purple_debug_error(MODULE_NAME, "Failed to add %s to the blacklist in OMEMO DB %s.", contact_bare_jid, db_fn_omemo); } cb(ret_val, user_data_p); g_free(uname); g_free(db_fn_omemo); } void lurch_api_enable_chat_handler(PurpleAccount * acc_p, const char * full_conversation_name, void (*cb)(int32_t err, void * user_data_p), void * user_data_p) { int32_t ret_val = 0; char * uname = (void *) 0; char * db_fn_omemo = (void *) 0; uname = lurch_util_uname_strip(purple_account_get_username(acc_p)); db_fn_omemo = lurch_util_uname_get_db_fn(uname, LURCH_DB_NAME_OMEMO); ret_val = omemo_storage_chatlist_save(full_conversation_name, db_fn_omemo); if (ret_val) { purple_debug_error(MODULE_NAME, "Failed to enable OMEMO for chat %s using DB %s.\n", full_conversation_name, db_fn_omemo); } cb(ret_val, user_data_p); g_free(uname); g_free(db_fn_omemo); } void lurch_api_disable_chat_handler(PurpleAccount * acc_p, const char * full_conversation_name, void (*cb)(int32_t err, void * user_data_p), void * user_data_p) { int32_t ret_val = 0; char * uname = (void *) 0; char * db_fn_omemo = (void *) 0; uname = lurch_util_uname_strip(purple_account_get_username(acc_p)); db_fn_omemo = lurch_util_uname_get_db_fn(uname, LURCH_DB_NAME_OMEMO); ret_val = omemo_storage_chatlist_delete(full_conversation_name, db_fn_omemo); if (ret_val) { purple_debug_error(MODULE_NAME, "Failed to disable OMEMO for chat %s using DB %s.\n", full_conversation_name, db_fn_omemo); } cb(ret_val, user_data_p); g_free(uname); g_free(db_fn_omemo); } void lurch_api_fp_get_handler(PurpleAccount * acc_p, void (*cb)(int32_t err, const char * fp_printable, void * user_data_p), void * user_data_p) { int32_t ret_val = 0; char * uname = (void *) 0; axc_context * axc_ctx_p = (void *) 0; axc_buf * key_buf_p = (void *) 0; char * fp_printable = (void *) 0; uname = lurch_util_uname_strip(purple_account_get_username(acc_p)); ret_val = lurch_util_axc_get_init_ctx(uname, &axc_ctx_p); if (ret_val) { purple_debug_error(MODULE_NAME, "Failed to create axc ctx.\n"); goto cleanup; } ret_val = axc_key_load_public_own(axc_ctx_p, &key_buf_p); if (ret_val) { purple_debug_error(MODULE_NAME, "Failed to load public key from axc db %s.", axc_context_get_db_fn(axc_ctx_p)); goto cleanup; } fp_printable = lurch_util_fp_get_printable(key_buf_p); cleanup: cb(ret_val, fp_printable, user_data_p); g_free(fp_printable); axc_buf_free(key_buf_p); axc_context_destroy_all(axc_ctx_p); } /** * Given a list of IDs, retrieves the public keys from the libsignal sessions and creates a hash table with ID to fingerprint pairs. * If there is an entry in the devicelist, but no session yet, the fingerprint cannot be retrieved this way and the value will be NULL. * g_hash_table_destroy() the table when done with it. */ static int32_t lurch_api_fp_create_table(const char * jid, axc_context * axc_ctx_p, const GList * id_list, GHashTable ** id_fp_table_pp) { int32_t ret_val = 0; GHashTable * id_fp_table = (void *) 0; const GList * curr_p = (void *) 0; uint32_t curr_device_id = 0; axc_buf * key_buf_p = (void *) 0; id_fp_table = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, g_free); for (curr_p = id_list; curr_p; curr_p = curr_p->next) { curr_device_id = omemo_devicelist_list_data(curr_p); ret_val = axc_key_load_public_addr(jid, curr_device_id, axc_ctx_p, &key_buf_p); if (ret_val < 0) { purple_debug_error(MODULE_NAME, "Failed to load key for %s:%i", jid, curr_device_id); goto cleanup; } else if (ret_val == 0) { purple_debug_warning(MODULE_NAME, "Tried to load public key for %s:%i, but no session exists", jid, curr_device_id); (void) g_hash_table_insert(id_fp_table, curr_p->data, NULL); continue; } (void) g_hash_table_insert(id_fp_table, curr_p->data, lurch_util_fp_get_printable(key_buf_p)); axc_buf_free(key_buf_p); key_buf_p = (void *) 0; ret_val = 0; } cleanup: if (ret_val) { g_hash_table_destroy(id_fp_table); } else { *id_fp_table_pp = id_fp_table; } return ret_val; } // returns NULL as hash table if devicelist is empty void lurch_api_fp_list_handler(PurpleAccount * acc_p, void (*cb)(int32_t err, GHashTable * id_fp_table, void * user_data_p), void * user_data_p) { int32_t ret_val = 0; GList * own_id_list = (void *) 0; char * uname = (void *) 0; axc_context * axc_ctx_p = (void *) 0; GHashTable * id_fp_table = (void *) 0; axc_buf * key_buf_p = (void *) 0; ret_val = lurch_api_id_list_get_own(acc_p, &own_id_list); if (ret_val) { purple_debug_error(MODULE_NAME, "Failed to get the own, sorted ID list."); goto cleanup; } if (g_list_length(own_id_list) == 0) { goto cleanup; } uname = lurch_util_uname_strip(purple_account_get_username(acc_p)); ret_val = lurch_util_axc_get_init_ctx(uname, &axc_ctx_p); if (ret_val) { purple_debug_error(MODULE_NAME, "Failed to create axc ctx for %s.", uname); goto cleanup; } ret_val = lurch_api_fp_create_table(uname, axc_ctx_p, own_id_list->next, &id_fp_table); if (ret_val) { goto cleanup; } ret_val = axc_key_load_public_own(axc_ctx_p, &key_buf_p); if (ret_val) { purple_debug_error(MODULE_NAME, "Failed to load public key from axc db %s.", axc_context_get_db_fn(axc_ctx_p)); goto cleanup; } (void) g_hash_table_insert(id_fp_table, own_id_list->data, lurch_util_fp_get_printable(key_buf_p)); cleanup: cb(ret_val, id_fp_table, user_data_p); g_list_free_full(own_id_list, g_free); g_free(uname); axc_context_destroy_all(axc_ctx_p); g_hash_table_destroy(id_fp_table); axc_buf_free(key_buf_p); } // returns NULL as hash table if devicelist is empty void lurch_api_fp_other_handler(PurpleAccount * acc_p, const char * contact_bare_jid, void (*cb)(int32_t err, GHashTable * id_fp_table, void * user_data_p), void * user_data_p) { int32_t ret_val = 0; char * uname = (void *) 0; char * db_fn_omemo = (void *) 0; omemo_devicelist * dl_p = (void *) 0; axc_context * axc_ctx_p = (void *) 0; GHashTable * id_fp_table = (void *) 0; GList * id_list = (void *) 0; axc_buf * key_buf_p = (void *) 0; uname = lurch_util_uname_strip(purple_account_get_username(acc_p)); db_fn_omemo = lurch_util_uname_get_db_fn(uname, LURCH_DB_NAME_OMEMO); ret_val = omemo_storage_user_devicelist_retrieve(contact_bare_jid, db_fn_omemo, &dl_p); if (ret_val) { purple_debug_error(MODULE_NAME, "Failed to access OMEMO DB %s.", db_fn_omemo); goto cleanup; } if (omemo_devicelist_is_empty(dl_p)) { goto cleanup; } ret_val = lurch_util_axc_get_init_ctx(uname, &axc_ctx_p); if (ret_val) { purple_debug_error(MODULE_NAME, "Failed to create axc ctx for %s.", uname); goto cleanup; } id_list = omemo_devicelist_get_id_list(dl_p); ret_val = lurch_api_fp_create_table(contact_bare_jid, axc_ctx_p, id_list, &id_fp_table); cleanup: cb(ret_val, id_fp_table, user_data_p); g_free(uname); g_free(db_fn_omemo); omemo_devicelist_destroy(dl_p); axc_context_destroy_all(axc_ctx_p); g_list_free_full(id_list, free); axc_buf_free(key_buf_p); if (id_fp_table) { g_hash_table_destroy(id_fp_table); } } void lurch_api_status_im_handler(PurpleAccount * acc_p, const char * contact_bare_jid, void (*cb)(int32_t err, lurch_status_t status, void * user_data_p), void * user_data_p) { int32_t ret_val = 0; lurch_status_t status = LURCH_STATUS_DISABLED; char * uname = (void *) 0; char * db_fn_omemo = (void *) 0; omemo_devicelist * dl_p = (void *) 0; axc_context * axc_ctx_p = (void *) 0; uname = lurch_util_uname_strip(purple_account_get_username(acc_p)); db_fn_omemo = lurch_util_uname_get_db_fn(uname, LURCH_DB_NAME_OMEMO); ret_val = omemo_storage_chatlist_exists(contact_bare_jid, db_fn_omemo); if (ret_val < 0 || ret_val > 1) { purple_debug_error(MODULE_NAME, "Failed to look up %s in file %s.", contact_bare_jid, db_fn_omemo); goto cleanup; } else if (ret_val == 0) { // conversation is not on blacklist, continue } else if (ret_val == 1) { ret_val = 0; status = LURCH_STATUS_DISABLED; goto cleanup; } ret_val = omemo_storage_user_devicelist_retrieve(contact_bare_jid, db_fn_omemo, &dl_p); if (ret_val) { purple_debug_error(MODULE_NAME, "Failed to get the devicelist for %s from %s.", contact_bare_jid, db_fn_omemo); goto cleanup; } if (omemo_devicelist_is_empty(dl_p)) { ret_val = 0; status = LURCH_STATUS_NOT_SUPPORTED; goto cleanup; } ret_val = lurch_util_axc_get_init_ctx(uname, &axc_ctx_p); if (ret_val) { purple_debug_error(MODULE_NAME, "Failed to create axc ctx for %s.", uname); goto cleanup; } ret_val = axc_session_exists_any(contact_bare_jid, axc_ctx_p); if (ret_val < 0) { purple_debug_error(MODULE_NAME, "Failed to look up session with %s.", contact_bare_jid); goto cleanup; } else if (ret_val == 0) { ret_val = 0; status = LURCH_STATUS_NO_SESSION; } else { ret_val = 0; status = LURCH_STATUS_OK; } cleanup: cb(ret_val, status, user_data_p); g_free(uname); g_free(db_fn_omemo); omemo_devicelist_destroy(dl_p); axc_context_destroy_all(axc_ctx_p); } void lurch_api_status_chat_handler(PurpleAccount * acc_p, const char * full_conversation_name, void (*cb)(int32_t err, lurch_status_chat_t status, void * user_data_p), void * user_data_p) { int32_t ret_val = 0; lurch_status_chat_t status = LURCH_STATUS_CHAT_DISABLED; char * uname = (void *) 0; char * db_fn_omemo = (void *) 0; PurpleConversation * conv_p = (void *) 0; JabberChat * muc_p = (void *) 0; GList * curr_item_p = (void *) 0; JabberChatMember * curr_muc_member_p = (void *) 0; char * curr_muc_member_bare_jid = (void *) 0; omemo_devicelist * curr_dl_p = (void *) 0; uname = lurch_util_uname_strip(purple_account_get_username(acc_p)); db_fn_omemo = lurch_util_uname_get_db_fn(uname, LURCH_DB_NAME_OMEMO); ret_val = omemo_storage_chatlist_exists(full_conversation_name, db_fn_omemo); if (ret_val < 0 || ret_val > 1) { purple_debug_error(MODULE_NAME, "Failed to look up %s in file %s.", full_conversation_name, db_fn_omemo); goto cleanup; } else if (ret_val == 0) { ret_val = 0; status = LURCH_STATUS_CHAT_DISABLED; goto cleanup; } else if (ret_val == 1) { // omemo enabled for chat, continue ret_val = 0; } conv_p = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, full_conversation_name, acc_p); if (!conv_p) { purple_debug_error(MODULE_NAME, "Could not find groupchat %s.\n", full_conversation_name); ret_val = EXIT_FAILURE; goto cleanup; } muc_p = jabber_chat_find_by_conv(conv_p); if (!muc_p) { purple_debug_error(MODULE_NAME, "Could not find the data for groupchat %s.\n", full_conversation_name); ret_val = EXIT_FAILURE; goto cleanup; } for (curr_item_p = g_hash_table_get_values(muc_p->members); curr_item_p; curr_item_p = curr_item_p->next) { curr_muc_member_p = (JabberChatMember *) curr_item_p->data; curr_muc_member_bare_jid = jabber_get_bare_jid(curr_muc_member_p->jid); if (!curr_muc_member_bare_jid) { purple_debug_warning( MODULE_NAME, "Could not get the JID of chat member with handle %s, which probably means the chat is anonymous.\n", curr_muc_member_p->handle ); status = LURCH_STATUS_CHAT_ANONYMOUS; goto cleanup; } ret_val = omemo_storage_user_devicelist_retrieve(curr_muc_member_bare_jid, db_fn_omemo, &curr_dl_p); if (ret_val) { purple_debug_error(MODULE_NAME, "Could not retrieve the devicelist for %s from %s.\n", curr_muc_member_bare_jid, db_fn_omemo); goto cleanup; } if (omemo_devicelist_is_empty(curr_dl_p)) { purple_debug_warning( MODULE_NAME, "Could not find %s's devicelist in chat %s. The user is probably not in %s's contact list.\n", curr_muc_member_bare_jid, full_conversation_name, uname ); status = LURCH_STATUS_CHAT_NO_DEVICELIST; goto cleanup; } g_free(curr_muc_member_bare_jid); curr_muc_member_bare_jid = (void *) 0; omemo_devicelist_destroy(curr_dl_p); curr_dl_p = (void *) 0; } status = LURCH_STATUS_CHAT_OK; cleanup: cb(ret_val, status, user_data_p); g_free(uname); g_free(db_fn_omemo); // if loop was exited early g_free(curr_muc_member_bare_jid); omemo_devicelist_destroy(curr_dl_p); } static void lurch_api_marshal_VOID__POINTER_INT_POINTER_POINTER(PurpleCallback cb, va_list args, void * data, void ** return_val) { void * arg1 = va_arg(args, void *); gint32 arg2 = va_arg(args, guint); void * arg3 = va_arg(args, void *); void * arg4 = va_arg(args, void *); ((void (*)(void *, guint, void *, void *, void *))cb)(arg1, arg2, arg3, arg4, data); } typedef enum { LURCH_API_HANDLER_ACC_CB_DATA = 0, LURCH_API_HANDLER_ACC_JID_CB_DATA, LURCH_API_HANDLER_ACC_DID_CB_DATA } lurch_api_handler_t; typedef struct { const char * name; void * handler; lurch_api_handler_t handler_type; } lurch_signal_info; const lurch_signal_info signal_infos[] = { { .name = "lurch-id-list", .handler = lurch_api_id_list_handler, .handler_type = LURCH_API_HANDLER_ACC_CB_DATA, }, { .name = "lurch-id-remove", .handler = lurch_api_id_remove_handler, .handler_type = LURCH_API_HANDLER_ACC_DID_CB_DATA, }, { .name = "lurch-enable-im", .handler = lurch_api_enable_im_handler, .handler_type = LURCH_API_HANDLER_ACC_JID_CB_DATA, }, { .name = "lurch-disable-im", .handler = lurch_api_disable_im_handler, .handler_type = LURCH_API_HANDLER_ACC_JID_CB_DATA, }, { .name = "lurch-enable-chat", .handler = lurch_api_enable_chat_handler, .handler_type = LURCH_API_HANDLER_ACC_JID_CB_DATA, }, { .name = "lurch-disable-chat", .handler = lurch_api_disable_chat_handler, .handler_type = LURCH_API_HANDLER_ACC_JID_CB_DATA, }, { .name = "lurch-fp-get", .handler = lurch_api_fp_get_handler, .handler_type = LURCH_API_HANDLER_ACC_CB_DATA, }, { .name = "lurch-fp-list", .handler = lurch_api_fp_list_handler, .handler_type = LURCH_API_HANDLER_ACC_CB_DATA, }, { .name = "lurch-fp-other", .handler = lurch_api_fp_other_handler, .handler_type = LURCH_API_HANDLER_ACC_JID_CB_DATA, }, { .name = "lurch-status-im", .handler = lurch_api_status_im_handler, .handler_type = LURCH_API_HANDLER_ACC_JID_CB_DATA, }, { .name = "lurch-status-chat", .handler = lurch_api_status_chat_handler, .handler_type = LURCH_API_HANDLER_ACC_JID_CB_DATA, }, }; static int get_num_of_signals() { return (sizeof signal_infos) / (sizeof signal_infos[0]); } void lurch_api_init() { void * plugins_handle_p = purple_plugins_get_handle(); for (int i = 0; i < get_num_of_signals(); i++) { lurch_signal_info signal_info = signal_infos[i]; const char * signal_name = signal_info.name; switch (signal_info.handler_type) { case LURCH_API_HANDLER_ACC_CB_DATA: purple_signal_register( plugins_handle_p, signal_name, purple_marshal_VOID__POINTER_POINTER_POINTER, NULL, 3, purple_value_new(PURPLE_TYPE_SUBTYPE, PURPLE_SUBTYPE_ACCOUNT), purple_value_new(PURPLE_TYPE_POINTER), purple_value_new(PURPLE_TYPE_POINTER) ); break; case LURCH_API_HANDLER_ACC_JID_CB_DATA: purple_signal_register( plugins_handle_p, signal_name, purple_marshal_VOID__POINTER_POINTER_POINTER_POINTER, NULL, 4, purple_value_new(PURPLE_TYPE_SUBTYPE, PURPLE_SUBTYPE_ACCOUNT), purple_value_new(PURPLE_TYPE_STRING), purple_value_new(PURPLE_TYPE_POINTER), purple_value_new(PURPLE_TYPE_POINTER) ); break; case LURCH_API_HANDLER_ACC_DID_CB_DATA: purple_signal_register( plugins_handle_p, signal_name, lurch_api_marshal_VOID__POINTER_INT_POINTER_POINTER, NULL, 4, purple_value_new(PURPLE_TYPE_SUBTYPE, PURPLE_SUBTYPE_ACCOUNT), purple_value_new(PURPLE_TYPE_INT), purple_value_new(PURPLE_TYPE_POINTER), purple_value_new(PURPLE_TYPE_POINTER) ); break; default: purple_debug_fatal(MODULE_NAME, "Unknown handler function type, aborting initialization."); } purple_signal_connect( plugins_handle_p, signal_name, MODULE_NAME, PURPLE_CALLBACK(signal_info.handler), NULL ); } } void lurch_api_unload() { void * plugins_handle_p = purple_plugins_get_handle(); for (int i = 0; i < get_num_of_signals(); i++) { lurch_signal_info signal_info = signal_infos[i]; const char * signal_name = signal_info.name; purple_signal_disconnect( plugins_handle_p, signal_name, MODULE_NAME, PURPLE_CALLBACK(signal_info.handler) ); purple_signal_unregister(plugins_handle_p, signal_name); } } purple-lurch-0.6.8+git20200527.388605/src/lurch_api.h000066400000000000000000000136201366351464100212450ustar00rootroot00000000000000#pragma once #define LURCH_ERR -1000000 #define LURCH_ERR_NOMEM -1000001 #define LURCH_ERR_NO_BUNDLE -1000010 #define LURCH_ERR_DEVICE_NOT_IN_LIST -1000100 typedef enum { LURCH_STATUS_DISABLED = 0, // manually disabled LURCH_STATUS_NOT_SUPPORTED, // no OMEMO support, i.e. there is no devicelist node LURCH_STATUS_NO_SESSION, // OMEMO is supported, but there is no libsignal session yet LURCH_STATUS_OK // OMEMO is supported and session exists } lurch_status_t; typedef enum { LURCH_STATUS_CHAT_DISABLED = 0, // OMEMO was not manually enabled LURCH_STATUS_CHAT_ANONYMOUS, // chat is anonymous, i.e. a member's JID could not be accessed LURCH_STATUS_CHAT_NO_DEVICELIST, // a member's devicelist could not be accessed, probably because s/he is not a contact LURCH_STATUS_CHAT_OK // in theory, OMEMO should work } lurch_status_chat_t; /** * Initializes the API by registering the signals and signal handlers. */ void lurch_api_init(); /** * Unregisters the signals and disconnects the signal handlers. */ void lurch_api_unload(); /** * USAGE * * Some functions users might be interested in can be called via libpurple signals. * Thus, the libpurple commands interface uses these as well and lurch_cmd_ui.c is therefore full of examples. * Generally, the workflow is as follows: * * - Find the signal you need and check the handler function's parameters. * Generally, you will need to pass the user's PurpleAccount, a callback, and the data to be passed to the callback. * For some functions, the conversation partner's or chat's JID is also required. * * - Write the callback function needed by the handler. * The first parameter is an error value. It is generally the return value from the called functions. * If it is non-zero, an error occured somewhere and there should be more information in the debug log. * Otherwise, the call succeeded and the following parameters will be set. * The last parameter is the data given when emitting the signal. * * - Emit the signal using the plugin system handle as the instance and pass the necessary data. * If you do it wrong, there will be no compiler errors and the pointers are gibberish, so take care. * You can easily get the plugin system handle anywhere by calling purple_plugins_get_handle(). */ /** * SIGNAL: lurch-id-list * * Gets the specified account's OMEMO devicelist and passes it to the callback as a GList containing uint32_t *. * To access the actual ID, cast the data member to a uint32_t * and dereference it. * This device's ID will be the first item in the list. */ void lurch_api_id_list_handler(PurpleAccount * acc_p, void (*cb)(int32_t err, GList * id_list, void * user_data_p), void * user_data_p); /** * SIGNAL: lurch-id-remove * * Removes the specified OMEMO device ID from the specified account's devicelist. */ void lurch_api_id_remove_handler(PurpleAccount * acc_p, uint32_t device_id, void (*cb)(int32_t err, void * user_data_p), void * user_data_p); /** * SIGNAL: lurch-enable-im * * Enables OMEMO for the specified contact. */ void lurch_api_enable_im_handler(PurpleAccount * acc_p, const char * contact_bare_jid, void (*cb)(int32_t err, void * user_data_p), void * user_data_p); /** * SIGNAL: lurch-disable-im * * Disables OMEMO for the specified contact. */ void lurch_api_disable_im_handler(PurpleAccount * acc_p, const char * contact_bare_jid, void (*cb)(int32_t err, void * user_data_p), void * user_data_p); /** * SIGNAL: lurch-enable-chat * * Enables OMEMO for the specified chat. The conversation name can be obtained by simply calling purple_conversation_get_name(). */ void lurch_api_enable_chat_handler(PurpleAccount * acc_p, const char * full_conversation_name, void (*cb)(int32_t err, void * user_data_p), void * user_data_p); /** * SIGNAL: lurch-disable-chat * * Disables OMEMO for the specified chat. */ void lurch_api_disable_chat_handler(PurpleAccount * acc_p, const char * full_conversation_name, void (*cb)(int32_t err, void * user_data_p), void * user_data_p); /** * SIGNAL: lurch-fp-get * * Gets the this device's fingerprint in a printable format. */ void lurch_api_fp_get_handler(PurpleAccount * acc_p, void (*cb)(int32_t err, const char * fp_printable, void * user_data_p), void * user_data_p); /** * SIGNAL: lurch-fp-list * * Gets the fingerprints of all devices belonging to the specified account and creates a device-ID-to-fingerprint table. * This is based on sessions, so if there is an entry in the OMEMO devicelist, but no libsignal session yet, the value will be NULL. * If the whole devicelist is empty, i.e. the account is not an OMEMO user, the whole table will be NULL. * Watch out as this is not a valid GHashTable. */ void lurch_api_fp_list_handler(PurpleAccount * acc_p, void (*cb)(int32_t err, GHashTable * id_fp_table, void * user_data_p), void * user_data_p); /** * SIGNAL: lurch-fp-other * * Same as above, but for the specified contact. */ void lurch_api_fp_other_handler(PurpleAccount * acc_p, const char * contact_bare_jid, void (*cb)(int32_t err, GHashTable * id_fp_table, void * user_data_p), void * user_data_p); /** * SIGNAL: lurch-status-im * * Checks the OMEMO status for the given contact. Result is one of lurch_status_t. */ void lurch_api_status_im_handler(PurpleAccount * acc_p, const char * contact_bare_jid, void (*cb)(int32_t err, lurch_status_t status, void * user_data_p), void * user_data_p); /** * SIGNAL: lurch-status-chat * * Checks the OMEMO status for a MUC. * It not only looks up whether OMEMO was enabled, but also checks the preconditions for this feature, i.e. * whether all chat members' JIDs are visible (non-anonymous) and their devicelists accessible (in contact list). */ void lurch_api_status_chat_handler(PurpleAccount * acc_p, const char * full_conversation_name, void (*cb)(int32_t err, lurch_status_chat_t status, void * user_data_p), void * user_data_p); purple-lurch-0.6.8+git20200527.388605/src/lurch_cmd_ui.c000066400000000000000000000301111366351464100217210ustar00rootroot00000000000000#include #include #include #include #include "jutil.h" #include "libomemo.h" #include "lurch_api.h" static void lurch_cmd_print(PurpleConversation * conv_p, const char * msg) { purple_conversation_write(conv_p, "lurch", msg, PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG, time((void *) 0)); } static void lurch_cmd_print_err(PurpleConversation * conv_p, const char * msg) { purple_conversation_write(conv_p, "lurch", msg, PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG | PURPLE_MESSAGE_ERROR, time((void *) 0)); } static void lurch_cmd_help(PurpleConversation * conv_p) { const char * help_message = "The following commands exist to interact with the lurch plugin:\n\n" " - '/lurch enable': Enables OMEMO encryption for this conversation. On by default for regular conversations, off for group chats.\n" " - '/lurch disable': Disables OMEMO encryption for this conversation.\n" " - '/lurch id list': Displays this account's device list.\n" " - '/lurch id remove ': Removes the device ID from this account's device list.\n" " - '/lurch fp show': Displays this device's key fingerprint.\n" " - '/lurch fp list': Displays the fingerprints of all your devices.\n" " - '/lurch fp other': Displays the fingerprints of all of your conversation partner's devices.\n" " - '/lurch status': Shows the OMEMO status of this conversation from your point of view.\n" " - '/lurch help': Displays this message.\n" " - '/lurch uninstall': Uninstalls this device from OMEMO by removing its device ID from the devicelist."; lurch_cmd_print(conv_p, help_message); } void lurch_id_list_print(int32_t err, GList * id_list, void * user_data_p) { PurpleConversation * conv_p = (PurpleConversation *) user_data_p; char * temp_msg_1 = g_strdup_printf("\nYour devicelist is:\n%i (this device)\n", omemo_devicelist_list_data(id_list)); char * temp_msg_2 = (void *) 0; char * temp_msg_3 = (void *) 0; GList * curr_p = (void *) 0; if (err) { lurch_cmd_print_err(conv_p, "An error occured when trying to retrieve your ID list. Check the debug log for details."); return; } for (curr_p = id_list->next; curr_p; curr_p = curr_p->next) { temp_msg_2 = g_strdup_printf("%i\n", omemo_devicelist_list_data(curr_p)); temp_msg_3 = g_strconcat(temp_msg_1, temp_msg_2, NULL); g_free(temp_msg_1); temp_msg_1 = temp_msg_3; g_free(temp_msg_2); temp_msg_2 = (void *) 0; temp_msg_3 = (void *) 0; } lurch_cmd_print(conv_p, temp_msg_1); g_free(temp_msg_1); } void lurch_id_remove_print(int32_t err, void * user_data_p) { PurpleConversation * conv_p = (PurpleConversation *) user_data_p; if (err) { lurch_cmd_print_err(conv_p, "Failed to remove the ID from your devicelist. Check the debug log for details."); return; } lurch_cmd_print(conv_p, "Successfully removed the ID from your devicelist."); } void lurch_enable_print(int32_t err, void * user_data_p) { PurpleConversation * conv_p = (PurpleConversation *) user_data_p; if (err) { lurch_cmd_print_err(conv_p, "Failed to enable OMEMO for this conversation."); return; } purple_conversation_autoset_title(conv_p); lurch_cmd_print(conv_p, "Successfully enabled OMEMO."); } void lurch_disable_print(int32_t err, void * user_data_p) { PurpleConversation * conv_p = (PurpleConversation *) user_data_p; if (err) { lurch_cmd_print_err(conv_p, "Failed to disable OMEMO for this conversation."); return; } purple_conversation_autoset_title(conv_p); lurch_cmd_print(conv_p, "Successfully disabled OMEMO."); } void lurch_fp_show_print(int32_t err, const char * fp_printable, void * user_data_p) { PurpleConversation * conv_p = (PurpleConversation *) user_data_p; char * msg = (void *) 0; if (err) { lurch_cmd_print_err(conv_p, "Failed to get this device's fingerprint. Check the debug log for details."); return; } msg = g_strdup_printf("This device's fingerprint is %s.", fp_printable); lurch_cmd_print(conv_p, msg); g_free(msg); } void lurch_fp_print(int32_t err, GHashTable * id_fp_table, void * user_data_p) { PurpleConversation * conv_p = (PurpleConversation *) user_data_p; GString * msg = (void *) 0; GList * key_list = (void *) 0; const GList * curr_p = (void *) 0; const char * fp = (void *) 0; if (err) { lurch_cmd_print_err(conv_p, "Failed to get the fingerprints. Check the debug log for details."); return; } if (!id_fp_table) { lurch_cmd_print(conv_p, "The devicelist is empty, so there is nothing to show!"); return; } msg = g_string_new("\n"); key_list = g_hash_table_get_keys(id_fp_table); for (curr_p = key_list; curr_p; curr_p = curr_p->next) { fp = (char *) g_hash_table_lookup(id_fp_table, curr_p->data); g_string_append_printf(msg, "%i's fingerprint:\n%s\n", *((uint32_t *) curr_p->data), fp ? fp : "(no session)"); } lurch_cmd_print(conv_p, msg->str); g_string_free(msg, TRUE); g_list_free(key_list); } void lurch_status_im_print(int32_t err, lurch_status_t status, void * user_data_p) { PurpleConversation * conv_p = (PurpleConversation *) user_data_p; const char * msg = (void *) 0; if (err) { lurch_cmd_print_err(conv_p, "Failed to get the conversation status. Check the debug log for details."); return; } switch (status) { case LURCH_STATUS_DISABLED: msg = "You disabled OMEMO for this conversation. Type '/lurch enable' to switch it back on."; break; case LURCH_STATUS_NOT_SUPPORTED: msg = "Your contact does not support OMEMO. No devicelist could be found."; break; case LURCH_STATUS_NO_SESSION: msg = "Your contact supports OMEMO, but you have not established a session yet. Just start messaging!"; break; case LURCH_STATUS_OK: msg = "OMEMO is enabled for this conversation. You can turn it off by typing '/lurch disable'."; break; default: msg = "Received unknown status code."; } lurch_cmd_print(conv_p, msg); } void lurch_status_chat_print(int32_t err, lurch_status_chat_t status, void * user_data_p) { PurpleConversation * conv_p = (PurpleConversation *) user_data_p; const char * msg = (void *) 0; if (err) { lurch_cmd_print_err(conv_p, "Failed to get the conversation status. Check the debug log for details."); return; } switch (status) { case LURCH_STATUS_CHAT_DISABLED: msg = "OMEMO was not enabled for this conversation. Type '/lurch enable' to switch it on."; break; case LURCH_STATUS_CHAT_ANONYMOUS: msg = "Could not access the JID of at least one of the chat members. The MUC is probably set to anonymous."; break; case LURCH_STATUS_CHAT_NO_DEVICELIST: msg = "Could not access the OMEMO devicelist of at least one of the chat members. Make sure every member is in every other member's contact list."; break; case LURCH_STATUS_CHAT_OK: msg = "OMEMO is enabled for this conversation and everything should work. You can turn it off by typing '/lurch disable'."; break; default: msg = "Received unknown status code."; } lurch_cmd_print(conv_p, msg); } static void lurch_cmd_id(PurpleConversation * conv_p, const char * arg, const char * param) { PurpleAccount * acc_p = purple_conversation_get_account(conv_p); void * plugins_handle = purple_plugins_get_handle(); if (!g_strcmp0(arg, "list")) { purple_signal_emit(plugins_handle, "lurch-id-list", acc_p, lurch_id_list_print, conv_p); } else if (!g_strcmp0(arg, "remove")) { if (!param) { lurch_cmd_print_err(conv_p, "You have to specify the device ID to remove."); } else { purple_signal_emit(plugins_handle, "lurch-id-remove", acc_p, strtol(param, (void *) 0, 10), lurch_id_remove_print, conv_p); } } else { lurch_cmd_print(conv_p, "Valid arguments for 'id' are list' and 'remove '."); } } static void lurch_cmd_enable(PurpleConversation * conv_p) { char * bare_jid = (void *) 0; void * plugins_handle = purple_plugins_get_handle(); PurpleConversationType conv_type = purple_conversation_get_type(conv_p); PurpleAccount * acc_p = purple_conversation_get_account(conv_p); const char * conv_name = purple_conversation_get_name(conv_p); switch (conv_type) { case PURPLE_CONV_TYPE_IM: bare_jid = jabber_get_bare_jid(conv_name); purple_signal_emit(plugins_handle, "lurch-enable-im", acc_p, bare_jid, lurch_enable_print, conv_p); break; case PURPLE_CONV_TYPE_CHAT: purple_signal_emit(plugins_handle, "lurch-enable-chat", acc_p, conv_name, lurch_enable_print, conv_p); break; default: lurch_cmd_print_err(conv_p, "Conversation type not supported."); break; } g_free(bare_jid); } static void lurch_cmd_disable(PurpleConversation * conv_p) { char * bare_jid = (void *) 0; void * plugins_handle = purple_plugins_get_handle(); PurpleConversationType conv_type = purple_conversation_get_type(conv_p); PurpleAccount * acc_p = purple_conversation_get_account(conv_p); const char * conv_name = purple_conversation_get_name(conv_p); switch (conv_type) { case PURPLE_CONV_TYPE_IM: bare_jid = jabber_get_bare_jid(conv_name); purple_signal_emit(plugins_handle, "lurch-disable-im", acc_p, bare_jid, lurch_disable_print, conv_p); break; case PURPLE_CONV_TYPE_CHAT: purple_signal_emit(plugins_handle, "lurch-disable-chat", acc_p, conv_name, lurch_disable_print, conv_p); break; default: lurch_cmd_print_err(conv_p, "Conversation type not supported."); break; } g_free(bare_jid); } static void lurch_cmd_fp(PurpleConversation * conv_p, const char * arg) { PurpleAccount * acc_p = purple_conversation_get_account(conv_p); void * plugins_handle = purple_plugins_get_handle(); char * conv_bare_jid = jabber_get_bare_jid(purple_conversation_get_name(conv_p)); if (!g_strcmp0(arg, "show")) { purple_signal_emit(plugins_handle, "lurch-fp-get", acc_p, lurch_fp_show_print, conv_p); } else if (!g_strcmp0(arg, "list")) { lurch_cmd_print(conv_p, "Your devices' fingerprints are:"); purple_signal_emit(plugins_handle, "lurch-fp-list", acc_p, lurch_fp_print, conv_p); } else if (!g_strcmp0(arg, "other")) { lurch_cmd_print(conv_p, "Your contact's devices' fingerprints are:"); purple_signal_emit(plugins_handle, "lurch-fp-other", acc_p, conv_bare_jid, lurch_fp_print, conv_p); } else { lurch_cmd_print(conv_p, "Valid arguments for 'fp' are 'show', 'list', and 'other'."); } } static void lurch_cmd_status(PurpleConversation * conv_p) { char * bare_jid = (void *) 0; const char * conv_name = purple_conversation_get_name(conv_p); PurpleConversationType conv_type = purple_conversation_get_type(conv_p); void * plugins_handle = purple_plugins_get_handle(); PurpleAccount * acc_p = purple_conversation_get_account(conv_p); switch (conv_type) { case PURPLE_CONV_TYPE_IM: bare_jid = jabber_get_bare_jid(conv_name); purple_signal_emit(plugins_handle, "lurch-status-im", acc_p, bare_jid, lurch_status_im_print, conv_p); break; case PURPLE_CONV_TYPE_CHAT: purple_signal_emit(plugins_handle, "lurch-status-chat", acc_p, conv_name, lurch_status_chat_print, conv_p); break; default: lurch_cmd_print_err(conv_p, "Conversation type not supported."); } g_free(bare_jid); } PurpleCmdRet lurch_cmd_func_v2(PurpleConversation * conv_p, const gchar * cmd, gchar ** args, gchar ** error, void * data_p) { const char * command = args[0]; if (!g_strcmp0(command, "help")) { lurch_cmd_help(conv_p); } else if (!g_strcmp0(command, "enable")) { lurch_cmd_enable(conv_p); } else if (!g_strcmp0(command, "disable")) { lurch_cmd_disable(conv_p); } else if (!g_strcmp0(command, "id")) { lurch_cmd_id(conv_p, args[1], args[2]); } else if (!g_strcmp0(command, "fp")) { lurch_cmd_fp(conv_p, args[1]); } else if (!g_strcmp0(command, "status")) { lurch_cmd_status(conv_p); } else { lurch_cmd_print(conv_p, "No such command. Type '/lurch help' for a list of available commands."); } return PURPLE_CMD_RET_OK; } purple-lurch-0.6.8+git20200527.388605/src/lurch_cmd_ui.h000066400000000000000000000004761366351464100217410ustar00rootroot00000000000000#pragma once #include #include PurpleCmdRet lurch_cmd_func_v2(PurpleConversation * conv_p, const gchar * cmd, gchar ** args, gchar ** error, void * data_p);purple-lurch-0.6.8+git20200527.388605/src/lurch_util.c000066400000000000000000000102621366351464100214430ustar00rootroot00000000000000#include #include #include "axc.h" #include "lurch_util.h" /** * Log wrapper for AXC * * @param level an AXC_LOG level * @param msg the log message * @param len the length of the message * @param ctx_p the axc context */ void lurch_util_axc_log_func(int level, const char * msg, size_t len, void * user_data) { (void) len; axc_context * ctx_p = (axc_context *) user_data; int log_level = axc_context_get_log_level(ctx_p); switch(level) { case AXC_LOG_ERROR: if (log_level >= AXC_LOG_ERROR) { purple_debug_error("lurch", "[AXC ERROR] %s\n", msg); } break; case AXC_LOG_WARNING: if (log_level >= AXC_LOG_WARNING) { purple_debug_warning("lurch", "[AXC WARNING] %s\n", msg); } break; case AXC_LOG_NOTICE: if (log_level >= AXC_LOG_NOTICE) { purple_debug_info("lurch", "[AXC NOTICE] %s\n", msg); } break; case AXC_LOG_INFO: if (log_level >= AXC_LOG_INFO) { purple_debug_info("lurch", "[AXC INFO] %s\n", msg); } break; case AXC_LOG_DEBUG: if (log_level >= AXC_LOG_DEBUG) { purple_debug_misc("lurch", "[AXC DEBUG] %s\n", msg); } break; default: purple_debug_misc("lurch", "[AXC %d] %s\n", level, msg); break; } } /** * Creates and initializes the axc context. * * @param uname The username. * @param ctx_pp Will point to an initialized axc context on success. * @return 0 on success, negative on error. */ int lurch_util_axc_get_init_ctx(char * uname, axc_context ** ctx_pp) { int ret_val = 0; char * err_msg_dbg = (void *) 0; axc_context * ctx_p = (void *) 0; char * db_fn = (void *) 0; ret_val = axc_context_create(&ctx_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to create axc context"); goto cleanup; } db_fn = lurch_util_uname_get_db_fn(uname, LURCH_DB_NAME_AXC); ret_val = axc_context_set_db_fn(ctx_p, db_fn, strlen(db_fn)); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to set axc db filename"); goto cleanup; } if (purple_prefs_get_bool(LURCH_PREF_AXC_LOGGING)) { axc_context_set_log_func(ctx_p, lurch_util_axc_log_func); axc_context_set_log_level(ctx_p, purple_prefs_get_int(LURCH_PREF_AXC_LOGGING_LEVEL)); } ret_val = axc_init(ctx_p); if (ret_val) { err_msg_dbg = g_strdup_printf("failed to init axc context"); goto cleanup; } if (purple_prefs_get_bool(LURCH_PREF_AXC_LOGGING)) { signal_context_set_log_function(axc_context_get_axolotl_ctx(ctx_p), lurch_util_axc_log_func); } *ctx_pp = ctx_p; cleanup: if (ret_val) { axc_context_destroy_all(ctx_p); } if (err_msg_dbg) { purple_debug_error("lurch", "%s: %s (%i)\n", __func__, err_msg_dbg, ret_val); free(err_msg_dbg); } free (db_fn); return ret_val; } char * lurch_util_uname_strip(const char * uname) { char ** split; char * stripped; if (!uname || strlen(uname) == 0) { return (void *) 0; } split = g_strsplit(uname, "/", 2); stripped = g_strdup(split[0]); g_strfreev(split); return stripped; } char * lurch_util_uname_get_db_fn(const char * uname, const char * which) { return g_strconcat(purple_user_dir(), "/", uname, "_", which, LURCH_DB_SUFFIX, NULL); } char * lurch_util_fp_get_printable(axc_buf * key_buf_p) { gchar * fp = (void *) 0; char ** split = (void *) 0; const size_t fp_parts_len = 32; char * printable = (void *) 0; const size_t printable_len = 72; if (!key_buf_p) { purple_debug_warning("lurch", "%s: Key buffer is null, aborting\n", __func__); goto cleanup; } fp = purple_base16_encode_chunked(axc_buf_get_data(key_buf_p), axc_buf_get_len(key_buf_p)); if (!fp || strlen(fp) != 98) { purple_debug_warning("lurch", "%s: Unexpected fingerprint length, aborting\n", __func__); goto cleanup; } // first part is dismissed for display split = g_strsplit(fp, ":", fp_parts_len + 1); printable = g_malloc0(printable_len); for (int i = 1; i <= fp_parts_len; i++) { g_strlcat(printable, split[i], printable_len); if (i % 4 == 0 && i != fp_parts_len) { g_strlcat(printable, " ", printable_len); } } cleanup: g_free(fp); g_strfreev(split); return printable; } purple-lurch-0.6.8+git20200527.388605/src/lurch_util.h000066400000000000000000000032501366351464100214470ustar00rootroot00000000000000#pragma once #include "axc.h" #define LURCH_PREF_ROOT "/plugins/core/lurch" #define LURCH_PREF_AXC_LOGGING LURCH_PREF_ROOT "/axc_logging" #define LURCH_PREF_AXC_LOGGING_LEVEL LURCH_PREF_AXC_LOGGING "/level" #define LURCH_DB_SUFFIX "_db.sqlite" #define LURCH_DB_NAME_OMEMO "omemo" #define LURCH_DB_NAME_AXC "axc" /** * Creates and initializes the axc context. * * @param uname The username. * @param ctx_pp Will point to an initialized axc context on success. * @return 0 on success, negative on error. */ int lurch_util_axc_get_init_ctx(char * uname, axc_context ** ctx_pp); /** * For some reason pidgin returns account names with a trailing "/". * This function removes it. * All other functions asking for the username assume the "/" is already stripped. * jabber_get_bare_jid returns null for some reason or other. * * @param uname The username. * @return A duplicated string with the trailing "/" removed. free() when done with it. */ char * lurch_util_uname_strip(const char * uname); /** * Returns the db name, has to be g_free()d. * * @param uname The username. * @param which Either LURCH_DB_NAME_OMEMO or LURCH_DB_NAME_AXC * @return The path string. free() when done with it. */ char * lurch_util_uname_get_db_fn(const char * uname, const char * which); /** * Creates a fingerprint which resembles the one displayed by Conversations etc. * Also useful for avoiding the smileys produced by ':d'... * * @param key_buf_p The buffer containing the public key data. * @return A newly allocated string which contains the fingerprint in printable format, or NULL. g_free() when done. */ char * lurch_util_fp_get_printable(axc_buf * key_buf_p);purple-lurch-0.6.8+git20200527.388605/test/000077500000000000000000000000001366351464100173145ustar00rootroot00000000000000purple-lurch-0.6.8+git20200527.388605/test/test_lurch_api.c000066400000000000000000001354101366351464100224710ustar00rootroot00000000000000#include #include #include #include #include #include "jabber.h" #include "chat.h" #include "axc.h" #include "libomemo.h" #include "../src/lurch_api.h" char * __wrap_purple_account_get_username(PurpleAccount * acc_p) { char * username; username = mock_ptr_type(char *); return username; } int __wrap_omemo_storage_user_devicelist_retrieve(const char * user, const char * db_fn, omemo_devicelist ** dl_pp) { omemo_devicelist * dl_p; dl_p = mock_ptr_type(omemo_devicelist *); *dl_pp = dl_p; int ret_val; ret_val = mock_type(int); return ret_val; } void __wrap_purple_account_get_connection(PurpleAccount * acc_p) { function_called(); } void __wrap_purple_signal_register() { function_called(); } void __wrap_purple_signal_connect() { function_called(); } void __wrap_purple_signal_unregister() { function_called(); } void __wrap_purple_signal_disconnect() { function_called(); } int __wrap_axc_get_device_id(axc_context * ctx_p, uint32_t * id_p) { uint32_t id; int ret_val; id = mock_type(uint32_t); *id_p = id; ret_val = mock_type(int); return ret_val; } PurpleConversation * __wrap_purple_find_conversation_with_account(PurpleConversationType type, const char *name, const PurpleAccount *account) { check_expected(type); check_expected(name); PurpleConversation * ret_val; ret_val = mock_ptr_type(PurpleConversation *); return ret_val; } void __wrap_jabber_pep_publish(JabberStream * js_p, xmlnode * publish_node_p) { xmlnode * item_node_p = xmlnode_get_child(publish_node_p, "item"); xmlnode * list_node_p = xmlnode_get_child(item_node_p, "list"); xmlnode * device_node_p = xmlnode_get_child(list_node_p, "device"); const char * device_id = xmlnode_get_attrib(device_node_p, "id"); check_expected(device_id); check_expected_ptr(device_node_p->next); } JabberChat * __wrap_jabber_chat_find_by_conv(PurpleConversation * conv_p) { JabberChat * ret_val; ret_val = mock_ptr_type(JabberChat *); return ret_val; } int __wrap_omemo_storage_chatlist_delete(const char * chat, const char * db_fn) { check_expected(chat); int ret_val; ret_val = mock_type(int); return ret_val; } int __wrap_omemo_storage_chatlist_save(const char * chat, const char * db_fn) { check_expected(chat); int ret_val; ret_val = mock_type(int); return ret_val; } int __wrap_omemo_storage_chatlist_exists(const char * chat, const char * db_fn) { check_expected(chat); int ret_val; ret_val = mock_type(int); return ret_val; } int __wrap_axc_key_load_public_own(axc_context * ctx_p, axc_buf ** pubkey_data_pp) { void * pubkey_data_p; int ret_val; pubkey_data_p = mock_ptr_type(void *); *pubkey_data_pp = pubkey_data_p; ret_val = mock_type(int); return ret_val; } int __wrap_axc_key_load_public_addr(const char * name, uint32_t device_id, axc_context * ctx_p, axc_buf ** pubkey_data_pp) { void * pubkey_data_p; int ret_val; check_expected(name); check_expected(device_id); pubkey_data_p = mock_ptr_type(void *); *pubkey_data_pp = pubkey_data_p; ret_val = mock_type(int); return ret_val; } int __wrap_axc_session_exists_any(const char * name, axc_context * ctx_p) { int ret_val; check_expected(name); ret_val = mock_type(int); return ret_val; } char * __wrap_lurch_util_fp_get_printable(axc_buf * key_buf_p) { function_called(); check_expected(key_buf_p); char * ret_val; ret_val = mock_ptr_type(char *); return ret_val; } void lurch_api_id_list_handler_cb_mock(int32_t err, GList * id_list, void * user_data_p) { check_expected(err); int32_t first_id = omemo_devicelist_list_data(id_list); check_expected(first_id); int32_t second_id = omemo_devicelist_list_data(id_list->next); check_expected(second_id); GList * third_item = id_list->next->next; check_expected(third_item); check_expected(user_data_p); } void lurch_api_id_list_handler_cb_err_mock(int32_t err, GList * id_list, void * user_data_p) { check_expected(err); check_expected(user_data_p); } /** * Calls the supplied callback with the devicelist and the supplied user data, making sure the own ID comes first. */ static void test_lurch_api_id_list_handler(void ** state) { (void) state; const char * test_jid = "me-testing@test.org/resource"; will_return(__wrap_purple_account_get_username, test_jid); char * devicelist = "" "" "" "" "" "" "" ""; omemo_devicelist * dl_p; omemo_devicelist_import(devicelist, test_jid, &dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, EXIT_SUCCESS); uint32_t test_own_id = 1337; will_return(__wrap_axc_get_device_id, test_own_id); will_return(__wrap_axc_get_device_id, EXIT_SUCCESS); expect_value(lurch_api_id_list_handler_cb_mock, err, 0); expect_value(lurch_api_id_list_handler_cb_mock, first_id, test_own_id); expect_value(lurch_api_id_list_handler_cb_mock, second_id, 4223); expect_value(lurch_api_id_list_handler_cb_mock, third_item, NULL); char * test_user_data = "TEST USER DATA"; expect_value(lurch_api_id_list_handler_cb_mock, user_data_p, test_user_data); lurch_api_id_list_handler(NULL, lurch_api_id_list_handler_cb_mock, test_user_data); } /** * When an error occurs, the supplied callback is called with the error code and the supplied user data. */ static void test_lurch_api_id_list_handler_error(void ** state) { (void) state; const char * test_jid = "me-testing@test.org/resource"; will_return(__wrap_purple_account_get_username, test_jid); int test_errcode = -12345; will_return(__wrap_omemo_storage_user_devicelist_retrieve, NULL); will_return(__wrap_omemo_storage_user_devicelist_retrieve, test_errcode); char * test_user_data = "TEST USER DATA"; expect_value(lurch_api_id_list_handler_cb_err_mock, err, test_errcode); expect_value(lurch_api_id_list_handler_cb_err_mock, user_data_p, test_user_data); lurch_api_id_list_handler(NULL, lurch_api_id_list_handler_cb_err_mock, test_user_data); } static void lurch_api_id_remove_handler_cb_mock(int32_t err, void * user_data_p) { check_expected(err); check_expected(user_data_p); } /** * Success case for removing a device ID from the own device list. */ static void test_lurch_api_id_remove_handler(void ** state) { (void) state; const char * test_jid = "me-testing@test.org/resource"; will_return(__wrap_purple_account_get_username, test_jid); char * devicelist = "" "" "" "" "" "" "" ""; omemo_devicelist * dl_p; omemo_devicelist_import(devicelist, test_jid, &dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, EXIT_SUCCESS); expect_function_call(__wrap_purple_account_get_connection); expect_string(__wrap_jabber_pep_publish, device_id, "4223"); expect_value(__wrap_jabber_pep_publish, device_node_p->next, NULL); char * test_user_data = "TEST USER DATA"; expect_value(lurch_api_id_remove_handler_cb_mock, err, EXIT_SUCCESS); expect_value(lurch_api_id_remove_handler_cb_mock, user_data_p, test_user_data); lurch_api_id_remove_handler((void *) "ignored", 1337, lurch_api_id_remove_handler_cb_mock, test_user_data); } /** * Fails when the device ID to remove is not in the own devicelist, and call the callback with the correct error code. */ static void test_lurch_api_id_remove_handler_id_not_in_list(void ** state) { (void) state; const char * test_jid = "me-testing@test.org/resource"; will_return(__wrap_purple_account_get_username, test_jid); char * devicelist = "" "" "" "" "" "" "" ""; omemo_devicelist * dl_p; omemo_devicelist_import(devicelist, test_jid, &dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, EXIT_SUCCESS); char * test_user_data = "TEST USER DATA"; expect_value(lurch_api_id_remove_handler_cb_mock, err, LURCH_ERR_DEVICE_NOT_IN_LIST); expect_value(lurch_api_id_remove_handler_cb_mock, user_data_p, test_user_data); lurch_api_id_remove_handler((void *) "ignored", 7331, lurch_api_id_remove_handler_cb_mock, test_user_data); } static void lurch_api_enable_disable_handler_cb_mock(int32_t err, void * user_data_p) { check_expected(err); check_expected(user_data_p); } /** * Deletes contact from 'the list' in the OMEMO DB when the signal is received, enabling OMEMO for this contact. */ static void test_lurch_api_enable_im_handler(void ** state) { (void) state; const char * contact_bare_jid = "contact_bare_jid"; const char * test_jid = "me-testing@test.org/resource"; will_return(__wrap_purple_account_get_username, test_jid); expect_string(__wrap_omemo_storage_chatlist_delete, chat, contact_bare_jid); will_return(__wrap_omemo_storage_chatlist_delete, EXIT_SUCCESS); char * test_user_data = "TEST USER DATA"; expect_value(lurch_api_enable_disable_handler_cb_mock, err, EXIT_SUCCESS); expect_value(lurch_api_enable_disable_handler_cb_mock, user_data_p, test_user_data); lurch_api_enable_im_handler((void *) "ignored", contact_bare_jid, lurch_api_enable_disable_handler_cb_mock, test_user_data); } /** * Calls the callback with the return code in case of an error. */ static void test_lurch_api_enable_im_handler_err(void ** state) { (void) state; const char * contact_bare_jid = "contact_bare_jid"; const char * test_jid = "me-testing@test.org/resource"; will_return(__wrap_purple_account_get_username, test_jid); expect_string(__wrap_omemo_storage_chatlist_delete, chat, contact_bare_jid); will_return(__wrap_omemo_storage_chatlist_delete, EXIT_FAILURE); char * test_user_data = "TEST USER DATA"; expect_value(lurch_api_enable_disable_handler_cb_mock, err, EXIT_FAILURE); expect_value(lurch_api_enable_disable_handler_cb_mock, user_data_p, test_user_data); lurch_api_enable_im_handler((void *) "ignored", contact_bare_jid, lurch_api_enable_disable_handler_cb_mock, test_user_data); } /** * Adds conversation name to 'the list' to enable OMEMO for it. */ static void test_lurch_api_enable_chat_handler(void ** state) { (void) state; const char * conv_name = "conversation name"; const char * user_jid = "me-testing@test.org/resource"; will_return(__wrap_purple_account_get_username, user_jid); expect_string(__wrap_omemo_storage_chatlist_save, chat, conv_name); will_return(__wrap_omemo_storage_chatlist_save, EXIT_SUCCESS); char * test_user_data = "TEST USER DATA"; expect_value(lurch_api_enable_disable_handler_cb_mock, err, EXIT_SUCCESS); expect_value(lurch_api_enable_disable_handler_cb_mock, user_data_p, test_user_data); lurch_api_enable_chat_handler((void *) "ignored", conv_name, lurch_api_enable_disable_handler_cb_mock, test_user_data); } /** * Calls the callback with the return value in case of an error. */ static void test_lurch_api_enable_chat_handler_err(void ** state) { (void) state; const char * conv_name = "conversation name"; const char * user_jid = "me-testing@test.org/resource"; will_return(__wrap_purple_account_get_username, user_jid); expect_string(__wrap_omemo_storage_chatlist_save, chat, conv_name); will_return(__wrap_omemo_storage_chatlist_save, EXIT_FAILURE); char * test_user_data = "TEST USER DATA"; expect_value(lurch_api_enable_disable_handler_cb_mock, err, EXIT_FAILURE); expect_value(lurch_api_enable_disable_handler_cb_mock, user_data_p, test_user_data); lurch_api_enable_chat_handler((void *) "ignored", conv_name, lurch_api_enable_disable_handler_cb_mock, test_user_data); } /** * Saves contact to 'the list' in the OMEMO DB when the signal is received, disabling OMEMO for this contact. */ static void test_lurch_api_disable_im_handler(void ** state) { (void) state; const char * contact_bare_jid = "contact_bare_jid"; const char * test_jid = "me-testing@test.org/resource"; will_return(__wrap_purple_account_get_username, test_jid); expect_string(__wrap_omemo_storage_chatlist_save, chat, contact_bare_jid); will_return(__wrap_omemo_storage_chatlist_save, EXIT_SUCCESS); char * test_user_data = "TEST USER DATA"; expect_value(lurch_api_enable_disable_handler_cb_mock, err, EXIT_SUCCESS); expect_value(lurch_api_enable_disable_handler_cb_mock, user_data_p, test_user_data); lurch_api_disable_im_handler((void *) "ignored", contact_bare_jid, lurch_api_enable_disable_handler_cb_mock, test_user_data); } /** * Calls the callback with the return code in case of an error. */ static void test_lurch_api_disable_im_handler_err(void ** state) { (void) state; const char * contact_bare_jid = "contact_bare_jid"; const char * test_jid = "me-testing@test.org/resource"; will_return(__wrap_purple_account_get_username, test_jid); expect_string(__wrap_omemo_storage_chatlist_save, chat, contact_bare_jid); will_return(__wrap_omemo_storage_chatlist_save, 12345); char * test_user_data = "TEST USER DATA"; expect_value(lurch_api_enable_disable_handler_cb_mock, err, 12345); expect_value(lurch_api_enable_disable_handler_cb_mock, user_data_p, test_user_data); lurch_api_disable_im_handler((void *) "ignored", contact_bare_jid, lurch_api_enable_disable_handler_cb_mock, test_user_data); } /** * Removes the specified conversation name from 'the list' to disable OMEMO for it. */ static void test_lurch_api_disable_chat_handler(void ** state) { (void) state; const char * conv_name = "conversation name"; const char * user_jid = "me-testing@test.org/resource"; will_return(__wrap_purple_account_get_username, user_jid); expect_string(__wrap_omemo_storage_chatlist_delete, chat, conv_name); will_return(__wrap_omemo_storage_chatlist_delete, EXIT_SUCCESS); char * test_user_data = "TEST USER DATA"; expect_value(lurch_api_enable_disable_handler_cb_mock, err, EXIT_SUCCESS); expect_value(lurch_api_enable_disable_handler_cb_mock, user_data_p, test_user_data); lurch_api_disable_chat_handler((void *) "ignoed", conv_name, lurch_api_enable_disable_handler_cb_mock, test_user_data); } /** * Calls the callback with a non-zero return value as well. */ static void test_lurch_api_disable_chat_handler_err(void ** state) { (void) state; const char * conv_name = "conversation name"; const char * user_jid = "me-testing@test.org/resource"; will_return(__wrap_purple_account_get_username, user_jid); expect_string(__wrap_omemo_storage_chatlist_delete, chat, conv_name); will_return(__wrap_omemo_storage_chatlist_delete, EXIT_FAILURE); char * test_user_data = "TEST USER DATA"; expect_value(lurch_api_enable_disable_handler_cb_mock, err, EXIT_FAILURE); expect_value(lurch_api_enable_disable_handler_cb_mock, user_data_p, test_user_data); lurch_api_disable_chat_handler((void *) "ignoed", conv_name, lurch_api_enable_disable_handler_cb_mock, test_user_data); } void lurch_api_fp_get_handler_cb_mock(int32_t err, const char * fp_printable, void * user_data_p) { check_expected(err); check_expected(fp_printable); check_expected(user_data_p); } /** * Loads the account's public identity key and returns a fingerprint suitable for display. */ static void test_lurch_api_fp_get_handler(void ** state) { (void) state; const char * test_jid = "me-testing@test.org/resource"; will_return(__wrap_purple_account_get_username, test_jid); axc_buf * mock_key_buf_own = axc_buf_create(NULL, 0); will_return(__wrap_axc_key_load_public_own, mock_key_buf_own); will_return(__wrap_axc_key_load_public_own, EXIT_SUCCESS); expect_function_call(__wrap_lurch_util_fp_get_printable); expect_value(__wrap_lurch_util_fp_get_printable, key_buf_p, mock_key_buf_own); char * mock_fp_own = g_strdup("MOCK FINGERPRINT"); will_return(__wrap_lurch_util_fp_get_printable, mock_fp_own); char * test_user_data = "TEST USER DATA"; expect_value(lurch_api_fp_get_handler_cb_mock, err, EXIT_SUCCESS); expect_string(lurch_api_fp_get_handler_cb_mock, fp_printable, mock_fp_own); expect_value(lurch_api_fp_get_handler_cb_mock, user_data_p, test_user_data); lurch_api_fp_get_handler(NULL, lurch_api_fp_get_handler_cb_mock, test_user_data); } /** * Calls the callback with the return code in case of an error. */ static void test_lurch_api_fp_get_handler_err(void ** state) { (void) state; const char * test_jid = "me-testing@test.org/resource"; will_return(__wrap_purple_account_get_username, test_jid); will_return(__wrap_axc_key_load_public_own, NULL); will_return(__wrap_axc_key_load_public_own, EXIT_FAILURE); char * test_user_data = "TEST USER DATA"; expect_value(lurch_api_fp_get_handler_cb_mock, err, EXIT_FAILURE); expect_value(lurch_api_fp_get_handler_cb_mock, fp_printable, NULL); expect_value(lurch_api_fp_get_handler_cb_mock, user_data_p, test_user_data); lurch_api_fp_get_handler(NULL, lurch_api_fp_get_handler_cb_mock, test_user_data); } /** * Mock callback that checks whether the given table is the same as the expected table passed through the user data. */ static void list_handling_cb_mock(int32_t err, GHashTable * id_fp_table, void * user_data_p) { check_expected(err); if (err) { return; } GHashTable * expected_table = (GHashTable *) user_data_p; if (!expected_table) { assert_null(id_fp_table); return; } GHashTableIter iter; gpointer key, value; char * generated_fp = (void *) 0; g_hash_table_iter_init (&iter, expected_table); while (g_hash_table_iter_next (&iter, &key, &value)) { generated_fp = g_hash_table_lookup(id_fp_table, key); // assert_non_null(generated_fp); assert_ptr_equal(generated_fp, value); generated_fp = (void *) 0; } } /** * Loads the devicelist, then each device's public key, then gets their fingerprints, and finally puts everything * into a single table of device ID to fingerprint. */ static void test_lurch_api_fp_list_handler(void ** state) { (void) state; const char * bare_jid = "me-testing@test.org"; const char * test_jid = "me-testing@test.org/resource"; will_return_always(__wrap_purple_account_get_username, test_jid); char * devicelist = "" "" "" "" "" "" "" "" ""; omemo_devicelist * dl_p; omemo_devicelist_import(devicelist, test_jid, &dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, EXIT_SUCCESS); uint32_t test_own_id = 1337; will_return(__wrap_axc_get_device_id, test_own_id); will_return(__wrap_axc_get_device_id, EXIT_SUCCESS); int id_4223 = 4223; expect_string(__wrap_axc_key_load_public_addr, name, bare_jid); expect_value(__wrap_axc_key_load_public_addr, device_id, id_4223); char * mock_key_4223 = "FAKE KEY 4223"; axc_buf * mock_key_buf_4223 = axc_buf_create((unsigned char *) mock_key_4223, strlen(mock_key_4223)); will_return(__wrap_axc_key_load_public_addr, mock_key_buf_4223); will_return(__wrap_axc_key_load_public_addr, 1); expect_function_call(__wrap_lurch_util_fp_get_printable); expect_value(__wrap_lurch_util_fp_get_printable, key_buf_p, mock_key_buf_4223); char * mock_fp_4223 = g_strdup("FAKE FP 4223"); will_return(__wrap_lurch_util_fp_get_printable, mock_fp_4223); int id_1338 = 1338; expect_string(__wrap_axc_key_load_public_addr, name, bare_jid); expect_value(__wrap_axc_key_load_public_addr, device_id, id_1338); char * mock_key_1338 = "FAKE KEY 1338"; axc_buf * mock_key_buf_1338 = axc_buf_create((unsigned char *) mock_key_1338, strlen(mock_key_1338)); will_return(__wrap_axc_key_load_public_addr, mock_key_buf_1338); will_return(__wrap_axc_key_load_public_addr, 0); axc_buf * mock_key_buf_own = axc_buf_create(NULL, 0); will_return(__wrap_axc_key_load_public_own, mock_key_buf_own); will_return(__wrap_axc_key_load_public_own, EXIT_SUCCESS); char * mock_fp_own = g_strdup("MOCK FINGERPRINT"); expect_function_call(__wrap_lurch_util_fp_get_printable); expect_value(__wrap_lurch_util_fp_get_printable, key_buf_p, mock_key_buf_own); will_return(__wrap_lurch_util_fp_get_printable, mock_fp_own); GHashTable * expected_table = g_hash_table_new(g_int_hash, g_int_equal); g_hash_table_insert(expected_table, &test_own_id, mock_fp_own); g_hash_table_insert(expected_table, &id_4223, mock_fp_4223); g_hash_table_insert(expected_table, &id_1338, NULL); expect_value(list_handling_cb_mock, err, EXIT_SUCCESS); lurch_api_fp_list_handler(NULL, list_handling_cb_mock, expected_table); } /** * Calls the callback with the return code in case of an error. */ static void test_lurch_api_fp_list_handler_err(void ** state) { (void) state; const char * test_jid = "me-testing@test.org/resource"; will_return_always(__wrap_purple_account_get_username, test_jid); char * devicelist = "" "" "" "" "" ""; omemo_devicelist * dl_p; omemo_devicelist_import(devicelist, test_jid, &dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, EXIT_SUCCESS); uint32_t id_which_does_not_matter = 123; will_return(__wrap_axc_get_device_id, id_which_does_not_matter); will_return(__wrap_axc_get_device_id, EXIT_FAILURE); expect_value(list_handling_cb_mock, err, EXIT_FAILURE); lurch_api_fp_list_handler(NULL, list_handling_cb_mock, NULL); } /** * Generates the same table, but for a contact. */ static void test_lurch_api_fp_other_handler(void ** state) { (void) state; const char * own_jid = "me-testing@test.org/resource"; const char * other_jid = "other-guy-testing@test.org/resource"; const char * other_bare_jid = "other-guy-testing@test.org"; will_return(__wrap_purple_account_get_username, own_jid); char * devicelist = "" "" "" "" "" "" ""; omemo_devicelist * dl_p; omemo_devicelist_import(devicelist, other_jid, &dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, EXIT_SUCCESS); int id_4223 = 4223; expect_string(__wrap_axc_key_load_public_addr, name, other_bare_jid); expect_value(__wrap_axc_key_load_public_addr, device_id, id_4223); char * mock_key_4223 = "FAKE KEY 4223"; axc_buf * mock_key_buf_4223 = axc_buf_create((unsigned char *) mock_key_4223, strlen(mock_key_4223)); will_return(__wrap_axc_key_load_public_addr, mock_key_buf_4223); will_return(__wrap_axc_key_load_public_addr, 1); expect_function_call(__wrap_lurch_util_fp_get_printable); expect_value(__wrap_lurch_util_fp_get_printable, key_buf_p, mock_key_buf_4223); char * mock_fp_4223 = g_strdup("FAKE FP 4223"); will_return(__wrap_lurch_util_fp_get_printable, mock_fp_4223); GHashTable * expected_table = g_hash_table_new(g_int_hash, g_int_equal); g_hash_table_insert(expected_table, &id_4223, mock_fp_4223); expect_value(list_handling_cb_mock, err, EXIT_SUCCESS); lurch_api_fp_other_handler(NULL, other_bare_jid, list_handling_cb_mock, expected_table); } /** * Correctly handles a key retrieval error when building the table. */ static void test_lurch_api_fp_other_handler_keyerr(void ** state) { (void) state; const char * own_jid = "me-testing@test.org/resource"; const char * other_jid = "other-guy-testing@test.org/resource"; const char * other_bare_jid = "other-guy-testing@test.org"; will_return(__wrap_purple_account_get_username, own_jid); char * devicelist = "" "" "" "" "" "" ""; omemo_devicelist * dl_p; omemo_devicelist_import(devicelist, other_jid, &dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, EXIT_SUCCESS); int id_4223 = 4223; expect_string(__wrap_axc_key_load_public_addr, name, other_bare_jid); expect_value(__wrap_axc_key_load_public_addr, device_id, id_4223); char * mock_key_4223 = "FAKE KEY 4223"; axc_buf * mock_key_buf_4223 = axc_buf_create((unsigned char *) mock_key_4223, strlen(mock_key_4223)); will_return(__wrap_axc_key_load_public_addr, mock_key_buf_4223); will_return(__wrap_axc_key_load_public_addr, -11); expect_value(list_handling_cb_mock, err, -11); lurch_api_fp_other_handler(NULL, other_bare_jid, list_handling_cb_mock, NULL); } /** * Hands over NULL as the table if the contact's devicelist is empty. */ static void test_lurch_api_fp_other_handler_empty(void ** state) { (void) state; const char * own_jid = "me-testing@test.org/resource"; const char * other_jid = "other-guy-testing@test.org/resource"; const char * other_bare_jid = "other-guy-testing@test.org"; will_return(__wrap_purple_account_get_username, own_jid); char * devicelist = "" "" "" "" "" ""; omemo_devicelist * dl_p; omemo_devicelist_import(devicelist, other_jid, &dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, EXIT_SUCCESS); expect_value(list_handling_cb_mock, err, EXIT_SUCCESS); lurch_api_fp_other_handler(NULL, other_bare_jid, list_handling_cb_mock, NULL); } /** * Calls the callback with the return code in case of an error. */ static void test_lurch_api_fp_other_handler_err(void ** state) { (void) state; const char * own_jid = "me-testing@test.org/resource"; const char * other_bare_jid = "other-guy-testing@test.org"; will_return(__wrap_purple_account_get_username, own_jid); int test_errcode = -1234; will_return(__wrap_omemo_storage_user_devicelist_retrieve, NULL); will_return(__wrap_omemo_storage_user_devicelist_retrieve, test_errcode); expect_value(list_handling_cb_mock, err, test_errcode); lurch_api_fp_other_handler(NULL, other_bare_jid, list_handling_cb_mock, NULL); } static void lurch_api_status_im_handler_cb_mock(int32_t err, lurch_status_t status, void * user_data_p) { check_expected(err); check_expected(status); check_expected(user_data_p); } /** * Passes the "disabled" status if the chat is found in the blacklist. */ static void test_lurch_api_status_im_handler_disabled(void ** state) { (void) state; const char * own_jid = "me-testing@test.org/resource"; const char * other_bare_jid = "other-guy-testing@test.org"; will_return(__wrap_purple_account_get_username, own_jid); expect_value(__wrap_omemo_storage_chatlist_exists, chat, other_bare_jid); will_return(__wrap_omemo_storage_chatlist_exists, 1); expect_value(lurch_api_status_im_handler_cb_mock, err, 0); expect_value(lurch_api_status_im_handler_cb_mock, status, LURCH_STATUS_DISABLED); const char * mock_user_data = "MOCK_USER_DATA"; expect_value(lurch_api_status_im_handler_cb_mock, user_data_p, mock_user_data); lurch_api_status_im_handler(NULL, other_bare_jid, lurch_api_status_im_handler_cb_mock, mock_user_data); } /** * Passes the "not supported" status if the contact does not have a devicelist. */ static void test_lurch_api_status_im_handler_not_supported(void ** state) { (void) state; const char * own_jid = "me-testing@test.org/resource"; const char * other_jid = "other-guy-testing@test.org/resource"; const char * other_bare_jid = "other-guy-testing@test.org"; will_return(__wrap_purple_account_get_username, own_jid); expect_value(__wrap_omemo_storage_chatlist_exists, chat, other_bare_jid); will_return(__wrap_omemo_storage_chatlist_exists, 0); char * devicelist = "" "" "" "" "" ""; omemo_devicelist * dl_p; omemo_devicelist_import(devicelist, other_jid, &dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, EXIT_SUCCESS); expect_value(lurch_api_status_im_handler_cb_mock, err, 0); expect_value(lurch_api_status_im_handler_cb_mock, status, LURCH_STATUS_NOT_SUPPORTED); const char * mock_user_data = "MOCK_USER_DATA"; expect_value(lurch_api_status_im_handler_cb_mock, user_data_p, mock_user_data); lurch_api_status_im_handler(NULL, other_bare_jid, lurch_api_status_im_handler_cb_mock, mock_user_data); } /** * Passes the "no session" status if the contact has a devicelist, but there is no libsignal session. */ static void test_lurch_api_status_im_handler_no_session(void ** state) { (void) state; const char * own_jid = "me-testing@test.org/resource"; const char * other_jid = "other-guy-testing@test.org/resource"; const char * other_bare_jid = "other-guy-testing@test.org"; will_return(__wrap_purple_account_get_username, own_jid); expect_value(__wrap_omemo_storage_chatlist_exists, chat, other_bare_jid); will_return(__wrap_omemo_storage_chatlist_exists, 0); char * devicelist = "" "" "" "" "" "" ""; omemo_devicelist * dl_p; omemo_devicelist_import(devicelist, other_jid, &dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, EXIT_SUCCESS); expect_value(__wrap_axc_session_exists_any, name, other_bare_jid); will_return(__wrap_axc_session_exists_any, 0); expect_value(lurch_api_status_im_handler_cb_mock, err, 0); expect_value(lurch_api_status_im_handler_cb_mock, status, LURCH_STATUS_NO_SESSION); const char * mock_user_data = "MOCK_USER_DATA"; expect_value(lurch_api_status_im_handler_cb_mock, user_data_p, mock_user_data); lurch_api_status_im_handler(NULL, other_bare_jid, lurch_api_status_im_handler_cb_mock, mock_user_data); } /** * Passes the "OK" status if contact has a devicelist and a session exists. */ static void test_lurch_api_status_im_handler_ok(void ** state) { (void) state; const char * own_jid = "me-testing@test.org/resource"; const char * other_jid = "other-guy-testing@test.org/resource"; const char * other_bare_jid = "other-guy-testing@test.org"; will_return(__wrap_purple_account_get_username, own_jid); expect_value(__wrap_omemo_storage_chatlist_exists, chat, other_bare_jid); will_return(__wrap_omemo_storage_chatlist_exists, 0); char * devicelist = "" "" "" "" "" "" ""; omemo_devicelist * dl_p; omemo_devicelist_import(devicelist, other_jid, &dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, EXIT_SUCCESS); expect_value(__wrap_axc_session_exists_any, name, other_bare_jid); will_return(__wrap_axc_session_exists_any, 1); expect_value(lurch_api_status_im_handler_cb_mock, err, 0); expect_value(lurch_api_status_im_handler_cb_mock, status, LURCH_STATUS_OK); const char * mock_user_data = "MOCK_USER_DATA"; expect_value(lurch_api_status_im_handler_cb_mock, user_data_p, mock_user_data); lurch_api_status_im_handler(NULL, other_bare_jid, lurch_api_status_im_handler_cb_mock, mock_user_data); } /** * Passes "disabled" and the exact error code if something goes wrong. */ static void test_lurch_api_status_im_handler_err(void ** state) { (void) state; const char * own_jid = "me-testing@test.org/resource"; const char * other_bare_jid = "other-guy-testing@test.org"; will_return(__wrap_purple_account_get_username, own_jid); int fake_errcode = -1337; expect_value(__wrap_omemo_storage_chatlist_exists, chat, other_bare_jid); will_return(__wrap_omemo_storage_chatlist_exists, fake_errcode); expect_value(lurch_api_status_im_handler_cb_mock, err, fake_errcode); expect_value(lurch_api_status_im_handler_cb_mock, status, LURCH_STATUS_DISABLED); const char * mock_user_data = "MOCK_USER_DATA"; expect_value(lurch_api_status_im_handler_cb_mock, user_data_p, mock_user_data); lurch_api_status_im_handler(NULL, other_bare_jid, lurch_api_status_im_handler_cb_mock, mock_user_data); } static void lurch_api_status_chat_handler_cb_mock(int32_t err, lurch_status_chat_t status, void * user_data_p) { check_expected(err); check_expected(status); check_expected(user_data_p); } /** * Returns the 'disabled' status if the chat is not on 'the list'. */ static void test_lurch_api_status_chat_handler_disabled(void ** state) { (void) state; const char * own_jid = "me-testing@test.org/resource"; const char * test_conversation_name = "test-room@conference.test.org"; will_return(__wrap_purple_account_get_username, own_jid); expect_value(__wrap_omemo_storage_chatlist_exists, chat, test_conversation_name); will_return(__wrap_omemo_storage_chatlist_exists, 0); expect_value(lurch_api_status_chat_handler_cb_mock, err, EXIT_SUCCESS); expect_value(lurch_api_status_chat_handler_cb_mock, status, LURCH_STATUS_CHAT_DISABLED); const char * mock_user_data = "MOCK_USER_DATA"; expect_value(lurch_api_status_chat_handler_cb_mock, user_data_p, mock_user_data); lurch_api_status_chat_handler(NULL, test_conversation_name, lurch_api_status_chat_handler_cb_mock, mock_user_data); } /** * Returns the "anonymous" status when a chat members' JID cannot be accessed, i.e. the chat is anonymous. */ static void test_lurch_api_status_chat_handler_anonymous(void ** state) { (void) state; const char * own_jid = "me-testing@test.org/resource"; const char * test_conversation_name = "test-room@conference.test.org"; will_return(__wrap_purple_account_get_username, own_jid); expect_value(__wrap_omemo_storage_chatlist_exists, chat, test_conversation_name); will_return(__wrap_omemo_storage_chatlist_exists, 1); PurpleConversation conversation_mock = { .name = test_conversation_name }; expect_value(__wrap_purple_find_conversation_with_account, type, PURPLE_CONV_TYPE_CHAT); expect_value(__wrap_purple_find_conversation_with_account, name, test_conversation_name); will_return(__wrap_purple_find_conversation_with_account, &conversation_mock); JabberChatMember member = { .handle = "anonymous member without jid" }; // keys do not really matter as the tests function loops over the values GHashTable * member_table_mock = g_hash_table_new(g_str_hash, g_str_equal); g_hash_table_insert(member_table_mock, "anon member", &member); JabberChat muc_mock = { .members = member_table_mock }; will_return(__wrap_jabber_chat_find_by_conv, &muc_mock); expect_value(lurch_api_status_chat_handler_cb_mock, err, EXIT_SUCCESS); expect_value(lurch_api_status_chat_handler_cb_mock, status, LURCH_STATUS_CHAT_ANONYMOUS); const char * mock_user_data = "MOCK_USER_DATA"; expect_value(lurch_api_status_chat_handler_cb_mock, user_data_p, mock_user_data); lurch_api_status_chat_handler(NULL, test_conversation_name, lurch_api_status_chat_handler_cb_mock, mock_user_data); } /** * Returns the "no devicelist" status when a devicelist for a chat member can not be found. * This usually means the member is not in the user's contact list. */ static void test_lurch_api_status_chat_handler_no_devicelist(void ** state) { (void) state; const char * own_jid = "me-testing@test.org/resource"; const char * test_conversation_name = "test-room@conference.test.org"; will_return(__wrap_purple_account_get_username, own_jid); expect_value(__wrap_omemo_storage_chatlist_exists, chat, test_conversation_name); will_return(__wrap_omemo_storage_chatlist_exists, 1); PurpleConversation conversation_mock = { .name = test_conversation_name }; expect_value(__wrap_purple_find_conversation_with_account, type, PURPLE_CONV_TYPE_CHAT); expect_value(__wrap_purple_find_conversation_with_account, name, test_conversation_name); will_return(__wrap_purple_find_conversation_with_account, &conversation_mock); JabberChatMember member = { .handle = "n0t4fr13nd", .jid = "not-a-contact@test.org/phone" }; // keys do not really matter as the tests function loops over the values GHashTable * member_table_mock = g_hash_table_new(g_str_hash, g_str_equal); g_hash_table_insert(member_table_mock, "non-contact member", &member); JabberChat muc_mock = { .members = member_table_mock }; will_return(__wrap_jabber_chat_find_by_conv, &muc_mock); char * devicelist = "" "" "" "" "" ""; omemo_devicelist * dl_p; omemo_devicelist_import(devicelist, member.jid, &dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, EXIT_SUCCESS); expect_value(lurch_api_status_chat_handler_cb_mock, err, EXIT_SUCCESS); expect_value(lurch_api_status_chat_handler_cb_mock, status, LURCH_STATUS_CHAT_NO_DEVICELIST); const char * mock_user_data = "MOCK_USER_DATA"; expect_value(lurch_api_status_chat_handler_cb_mock, user_data_p, mock_user_data); lurch_api_status_chat_handler(NULL, test_conversation_name, lurch_api_status_chat_handler_cb_mock, mock_user_data); } /** * Returns the "OK" status when for all members all necessary information could be found. */ static void test_lurch_api_status_chat_handler_ok(void ** state) { (void) state; const char * own_jid = "me-testing@test.org/resource"; const char * test_conversation_name = "test-room@conference.test.org"; will_return(__wrap_purple_account_get_username, own_jid); expect_value(__wrap_omemo_storage_chatlist_exists, chat, test_conversation_name); will_return(__wrap_omemo_storage_chatlist_exists, 1); PurpleConversation conversation_mock = { .name = test_conversation_name }; expect_value(__wrap_purple_find_conversation_with_account, type, PURPLE_CONV_TYPE_CHAT); expect_value(__wrap_purple_find_conversation_with_account, name, test_conversation_name); will_return(__wrap_purple_find_conversation_with_account, &conversation_mock); JabberChatMember member = { .handle = "perfect-contact", .jid = "perfect-contact@test.org/lurch" }; // keys do not really matter as the tests function loops over the values GHashTable * member_table_mock = g_hash_table_new(g_str_hash, g_str_equal); g_hash_table_insert(member_table_mock, "contact member", &member); JabberChat muc_mock = { .members = member_table_mock }; will_return(__wrap_jabber_chat_find_by_conv, &muc_mock); char * devicelist = "" "" "" "" "" "" ""; omemo_devicelist * dl_p; omemo_devicelist_import(devicelist, member.jid, &dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, dl_p); will_return(__wrap_omemo_storage_user_devicelist_retrieve, EXIT_SUCCESS); expect_value(lurch_api_status_chat_handler_cb_mock, err, EXIT_SUCCESS); expect_value(lurch_api_status_chat_handler_cb_mock, status, LURCH_STATUS_CHAT_OK); const char * mock_user_data = "MOCK_USER_DATA"; expect_value(lurch_api_status_chat_handler_cb_mock, user_data_p, mock_user_data); lurch_api_status_chat_handler(NULL, test_conversation_name, lurch_api_status_chat_handler_cb_mock, mock_user_data); } /** * Returns "disabled" and an error return value when the conversation could not be found, i.e. an error. */ static void test_lurch_api_status_chat_handler_conv_not_found(void ** state) { (void) state; const char * own_jid = "me-testing@test.org/resource"; const char * test_conversation_name = "nonexistent-test-room@conference.test.org"; will_return(__wrap_purple_account_get_username, own_jid); expect_value(__wrap_omemo_storage_chatlist_exists, chat, test_conversation_name); will_return(__wrap_omemo_storage_chatlist_exists, 1); expect_value(__wrap_purple_find_conversation_with_account, type, PURPLE_CONV_TYPE_CHAT); expect_value(__wrap_purple_find_conversation_with_account, name, test_conversation_name); will_return(__wrap_purple_find_conversation_with_account, NULL); expect_value(lurch_api_status_chat_handler_cb_mock, err, EXIT_FAILURE); expect_value(lurch_api_status_chat_handler_cb_mock, status, LURCH_STATUS_CHAT_DISABLED); const char * mock_user_data = "MOCK_USER_DATA"; expect_value(lurch_api_status_chat_handler_cb_mock, user_data_p, mock_user_data); lurch_api_status_chat_handler(NULL, test_conversation_name, lurch_api_status_chat_handler_cb_mock, mock_user_data); } /** * Registers and connects all signals. */ static void test_lurch_api_init(void ** state) { (void) state; size_t signals = 11; for (int i = 0; i < signals; i++) { expect_function_call(__wrap_purple_signal_register); expect_function_call(__wrap_purple_signal_connect); } lurch_api_init(); } /** * Disconnects and unregisters all signals. */ static void test_lurch_api_unload(void ** state) { (void) state; size_t signals = 11; for (int i = 0; i < signals; i++) { expect_function_call(__wrap_purple_signal_disconnect); expect_function_call(__wrap_purple_signal_unregister); } lurch_api_unload(); } int main(void) { const struct CMUnitTest tests[] = { cmocka_unit_test(test_lurch_api_id_list_handler), cmocka_unit_test(test_lurch_api_id_list_handler_error), cmocka_unit_test(test_lurch_api_id_remove_handler), cmocka_unit_test(test_lurch_api_id_remove_handler_id_not_in_list), cmocka_unit_test(test_lurch_api_enable_im_handler), cmocka_unit_test(test_lurch_api_enable_im_handler_err), cmocka_unit_test(test_lurch_api_enable_chat_handler), cmocka_unit_test(test_lurch_api_enable_chat_handler_err), cmocka_unit_test(test_lurch_api_disable_im_handler), cmocka_unit_test(test_lurch_api_disable_im_handler_err), cmocka_unit_test(test_lurch_api_disable_chat_handler), cmocka_unit_test(test_lurch_api_disable_chat_handler_err), cmocka_unit_test(test_lurch_api_fp_get_handler), cmocka_unit_test(test_lurch_api_fp_get_handler_err), cmocka_unit_test(test_lurch_api_fp_list_handler), cmocka_unit_test(test_lurch_api_fp_list_handler_err), cmocka_unit_test(test_lurch_api_fp_other_handler), cmocka_unit_test(test_lurch_api_fp_other_handler_keyerr), cmocka_unit_test(test_lurch_api_fp_other_handler_empty), cmocka_unit_test(test_lurch_api_fp_other_handler_err), cmocka_unit_test(test_lurch_api_status_im_handler_disabled), cmocka_unit_test(test_lurch_api_status_im_handler_not_supported), cmocka_unit_test(test_lurch_api_status_im_handler_no_session), cmocka_unit_test(test_lurch_api_status_im_handler_ok), cmocka_unit_test(test_lurch_api_status_im_handler_err), cmocka_unit_test(test_lurch_api_status_chat_handler_disabled), cmocka_unit_test(test_lurch_api_status_chat_handler_anonymous), cmocka_unit_test(test_lurch_api_status_chat_handler_no_devicelist), cmocka_unit_test(test_lurch_api_status_chat_handler_ok), cmocka_unit_test(test_lurch_api_status_chat_handler_conv_not_found), cmocka_unit_test(test_lurch_api_init), cmocka_unit_test(test_lurch_api_unload) }; return cmocka_run_group_tests_name("lurch_api", tests, NULL, NULL); } purple-lurch-0.6.8+git20200527.388605/test/test_lurch_util.c000066400000000000000000000163641366351464100227030ustar00rootroot00000000000000#include #include #include #include #include #include "axc.h" #include "../src/lurch.h" #include "../src/lurch_util.h" void __wrap_purple_debug_error(const char * category, const char * format, ...) { function_called(); } void __wrap_purple_debug_info(const char * category, const char * format, ...) { function_called(); } void __wrap_purple_debug_misc(const char * category, const char * format, ...) { } int __wrap_axc_context_create(axc_context ** axc_ctx_pp) { int ret_val; ret_val = mock_type(int); return ret_val; } const char * __wrap_purple_user_dir(void) { char * user_dir; user_dir = mock_ptr_type(char *); return user_dir; } gboolean __wrap_purple_prefs_get_bool(const char * pref_name) { check_expected(pref_name); gboolean pref_val; pref_val = mock_type(gboolean); return pref_val; } int __wrap_purple_prefs_get_int(const char * pref_name) { check_expected(pref_name); int pref_val; pref_val = mock_type(int); return pref_val; } char * __wrap_purple_base16_encode_chunked(const guchar *data, gsize len) { char * fp; fp = mock_ptr_type(char *); return fp; } /** * Log only errors when log level is set to AXC_LOG_ERROR, using purple_debug_error(). */ static void test_lurch_util_axc_log_func_error(void ** state) { (void) state; axc_context * axc_ctx_p = (void *) 0; (void) axc_context_create(&axc_ctx_p); axc_context_set_log_level(axc_ctx_p, AXC_LOG_ERROR); expect_function_call(__wrap_purple_debug_error); lurch_util_axc_log_func(AXC_LOG_ERROR, "test", 4, axc_ctx_p); lurch_util_axc_log_func(AXC_LOG_WARNING, "test", 4, axc_ctx_p); lurch_util_axc_log_func(AXC_LOG_NOTICE, "test", 4, axc_ctx_p); lurch_util_axc_log_func(AXC_LOG_INFO, "test", 4, axc_ctx_p); lurch_util_axc_log_func(AXC_LOG_DEBUG, "test", 4, axc_ctx_p); lurch_util_axc_log_func(-1, "test", 4, axc_ctx_p); axc_context_destroy_all(axc_ctx_p); } /** * Log level info and above, but not below. */ static void test_lurch_util_axc_log_func_info(void ** state) { (void) state; axc_context * axc_ctx_p = (void *) 0; (void) axc_context_create(&axc_ctx_p); axc_context_set_log_level(axc_ctx_p, AXC_LOG_INFO); expect_function_call(__wrap_purple_debug_error); expect_function_calls(__wrap_purple_debug_info, 2); lurch_util_axc_log_func(AXC_LOG_ERROR, "test", 4, axc_ctx_p); lurch_util_axc_log_func(AXC_LOG_WARNING, "test", 4, axc_ctx_p); lurch_util_axc_log_func(AXC_LOG_NOTICE, "test", 4, axc_ctx_p); lurch_util_axc_log_func(AXC_LOG_INFO, "test", 4, axc_ctx_p); lurch_util_axc_log_func(AXC_LOG_DEBUG, "test", 4, axc_ctx_p); axc_context_destroy_all(axc_ctx_p); } static void test_lurch_util_axc_get_init_ctx_w_logging(void ** state) { (void) state; will_return(__wrap_purple_user_dir, "/home/testuser/.purple"); expect_string_count(__wrap_purple_prefs_get_bool, pref_name, LURCH_PREF_AXC_LOGGING, 2); will_return_count(__wrap_purple_prefs_get_bool, TRUE, 2); expect_string(__wrap_purple_prefs_get_int, pref_name, LURCH_PREF_AXC_LOGGING_LEVEL); will_return(__wrap_purple_prefs_get_int, AXC_LOG_NOTICE); char * test_jid = "test-user@example.com"; axc_context * test_axc_ctx_p = (void *) 0; lurch_util_axc_get_init_ctx(test_jid, &test_axc_ctx_p); assert_string_equal(axc_context_get_db_fn(test_axc_ctx_p), "/home/testuser/.purple/test-user@example.com_axc_db.sqlite"); assert_int_equal(axc_context_get_log_level(test_axc_ctx_p), AXC_LOG_NOTICE); } static void test_lurch_util_axc_get_init_ctx_wo_logging(void ** state) { (void) state; will_return(__wrap_purple_user_dir, "/home/testuser/.purple"); expect_string_count(__wrap_purple_prefs_get_bool, pref_name, LURCH_PREF_AXC_LOGGING, 2); will_return_count(__wrap_purple_prefs_get_bool, FALSE, 2); char * test_jid = "test-user@example.com"; axc_context * test_axc_ctx_p = (void *) 0; lurch_util_axc_get_init_ctx(test_jid, &test_axc_ctx_p); assert_string_equal(axc_context_get_db_fn(test_axc_ctx_p), "/home/testuser/.purple/test-user@example.com_axc_db.sqlite"); assert_int_equal(axc_context_get_log_level(test_axc_ctx_p), -1); } static void test_lurch_util_uname_strip(void ** state) { (void) state; assert_string_equal(lurch_util_uname_strip("node@domain/resource"), "node@domain"); } static void test_lurch_util_uname_strip_no_resource(void ** state) { (void) state; assert_string_equal(lurch_util_uname_strip("node@domain/"), "node@domain"); assert_string_equal(lurch_util_uname_strip("node@domain"), "node@domain"); } static void test_lurch_util_uname_strip_empty(void ** state) { (void) state; assert_null(lurch_util_uname_strip("")); assert_null(lurch_util_uname_strip(NULL)); } static void test_lurch_util_uname_get_db_fn(void ** state) { (void) state; will_return(__wrap_purple_user_dir, "/home/testuser/.purple"); assert_string_equal(lurch_util_uname_get_db_fn("test-uname@example.com", "TESTTYPE"), "/home/testuser/.purple/test-uname@example.com_TESTTYPE_db.sqlite"); } static void test_lurch_util_fp_get_printable(void ** state) { (void) state; const char * fp_as_returned_by_pidgin = "12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:ab:cd:ef:gh"; will_return(__wrap_purple_base16_encode_chunked, g_strdup(fp_as_returned_by_pidgin)); char * printable_fp = lurch_util_fp_get_printable((void *) &"fake non-null pointer"); assert_non_null(printable_fp); assert_string_equal(printable_fp, "34567812 34567812 34567812 34567812 34567812 34567812 34567812 abcdefgh"); } static void test_lurch_util_fp_get_printable_invalid(void ** state) { (void) state; assert_null(lurch_util_fp_get_printable(NULL)); will_return(__wrap_purple_base16_encode_chunked, NULL); assert_null(lurch_util_fp_get_printable((void *) &"fake non-null pointer")); const char * too_short = "12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:ab:cd:efgh"; will_return(__wrap_purple_base16_encode_chunked, g_strdup(too_short)); assert_null(lurch_util_fp_get_printable((void *) &"fake non-null pointer")); const char * too_long = "12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:ab:cd:ef:gh:"; will_return(__wrap_purple_base16_encode_chunked, g_strdup(too_long)); assert_null(lurch_util_fp_get_printable((void *) &"fake non-null pointer")); } int main(void) { const struct CMUnitTest tests[] = { cmocka_unit_test(test_lurch_util_axc_log_func_error), cmocka_unit_test(test_lurch_util_axc_log_func_info), cmocka_unit_test(test_lurch_util_axc_get_init_ctx_w_logging), cmocka_unit_test(test_lurch_util_axc_get_init_ctx_wo_logging), cmocka_unit_test(test_lurch_util_uname_strip), cmocka_unit_test(test_lurch_util_uname_strip_no_resource), cmocka_unit_test(test_lurch_util_uname_strip_empty), cmocka_unit_test(test_lurch_util_uname_get_db_fn), cmocka_unit_test(test_lurch_util_fp_get_printable), cmocka_unit_test(test_lurch_util_fp_get_printable_invalid) }; return cmocka_run_group_tests_name("lurch_util", tests, NULL, NULL); }