diff --git a/.gitignore b/.gitignore index 465fba0f6..9c9826840 100644 --- a/.gitignore +++ b/.gitignore @@ -106,7 +106,9 @@ deps/libconfig/libconfig-1.7.2/ #libmicrohttpd deps/libmicrohttpd/libmicrohttpd-0.9.55/ deps/libmicrohttpd/libmicrohttpd-0.9.68/ -https://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.68.tar.gz + +#libhttpserver +deps/libhttpserver/libhttpserver-master_20191121/ #clickhouse deps/clickhouse-cpp/clickhouse-cpp/ diff --git a/deps/Makefile b/deps/Makefile index 2c6ab8907..173b47fc7 100644 --- a/deps/Makefile +++ b/deps/Makefile @@ -11,9 +11,9 @@ endif PROXYSQLCLICKHOUSE := $(shell echo $(PROXYSQLCLICKHOUSE)) ifeq ($(PROXYSQLCLICKHOUSE),1) -default: libconfig libdaemon jemalloc mariadb_client re2 sqlite3 pcre clickhouse-cpp lz4 cityhash microhttpd curl ev libssl +default: libconfig libdaemon jemalloc mariadb_client re2 sqlite3 pcre clickhouse-cpp lz4 cityhash microhttpd curl ev libssl libhttpserver else -default: libconfig libdaemon jemalloc mariadb_client re2 sqlite3 pcre microhttpd curl ev libssl +default: libconfig libdaemon jemalloc mariadb_client re2 sqlite3 pcre microhttpd curl ev libssl libhttpserver endif .PHONY: default @@ -24,8 +24,17 @@ libssl/openssl/libssl.a: cd libssl && tar -zxf openssl-1.1.0h.tar.gz cd libssl/openssl && ./config no-ssl3 cd libssl/openssl && CC=${CC} CXX=${CXX} ${MAKE} + cd libssl/openssl && ln -s . lib # curl wants this path libssl: libssl/openssl/libssl.a +libhttpserver/libhttpserver/build/src/.libs/libhttpserver.a: libmicrohttpd/libmicrohttpd/src/microhttpd/.libs/libmicrohttpd.a + cd libhttpserver && rm -rf libhttpserver-master_20191121 || true + cd libhttpserver && tar -zxf libhttpserver-master_20191121.tar.gz + cd libhttpserver/libhttpserver && ./bootstrap && mkdir build + cd libhttpserver/libhttpserver/build && LDFLAGS=-L=$(shell pwd)/libmicrohttpd/libmicrohttpd/src/microhttpd/.libs/ CPPFLAGS=-I=$(shell pwd)/libmicrohttpd/libmicrohttpd/src/include ../configure --disable-doxygen-doc --disable-doxygen-dot --disable-doxygen-man --disable-doxygen-html + cd libhttpserver/libhttpserver/build && CC=${CC} CXX=${CXX} ${MAKE} +libhttpserver: libhttpserver/libhttpserver/build/src/.libs/libhttpserver.a + libev/libev/.libs/libev.a: cd libev && rm -rf libev-4.24 || true cd libev && tar -zxf libev-4.24.tar.gz @@ -33,17 +42,17 @@ libev/libev/.libs/libev.a: cd libev/libev && CC=${CC} CXX=${CXX} ${MAKE} ev: libev/libev/.libs/libev.a -curl/curl/lib/.libs/libcurl.a: #libssl/openssl/libssl.a +curl/curl/lib/.libs/libcurl.a: libssl/openssl/libssl.a cd curl && rm -rf curl-7.57.0 || true cd curl && tar -zxf curl-7.57.0.tar.gz #cd curl/curl && ./configure --disable-debug --disable-ftp --disable-ldap --disable-ldaps --disable-rtsp --disable-proxy --disable-dict --disable-telnet --disable-tftp --disable-pop3 --disable-imap --disable-smb --disable-smtp --disable-gopher --disable-manual --disable-ipv6 --disable-sspi --disable-crypto-auth --disable-ntlm-wb --disable-tls-srp --without-nghttp2 --without-libidn2 --without-libssh2 --without-brotli --with-ssl=$(shell pwd)/../../libssl/openssl/ && CC=${CC} CXX=${CXX} ${MAKE} - cd curl/curl && ./configure --disable-debug --disable-ftp --disable-ldap --disable-ldaps --disable-rtsp --disable-proxy --disable-dict --disable-telnet --disable-tftp --disable-pop3 --disable-imap --disable-smb --disable-smtp --disable-gopher --disable-manual --disable-ipv6 --disable-sspi --disable-crypto-auth --disable-ntlm-wb --disable-tls-srp --without-nghttp2 --without-libidn2 --without-libssh2 --without-brotli --without-librtmp --without-libpsl --without-ssl && CC=${CC} CXX=${CXX} ${MAKE} + cd curl/curl && ./configure --disable-debug --disable-ftp --disable-ldap --disable-ldaps --disable-rtsp --disable-proxy --disable-dict --disable-telnet --disable-tftp --disable-pop3 --disable-imap --disable-smb --disable-smtp --disable-gopher --disable-manual --disable-ipv6 --disable-sspi --disable-crypto-auth --disable-ntlm-wb --disable-tls-srp --without-nghttp2 --without-libidn2 --without-libssh2 --without-brotli --without-librtmp --without-libpsl --with-ssl=$(shell pwd)/libssl/openssl/ --enable-shared=no && CC=${CC} CXX=${CXX} ${MAKE} curl: curl/curl/lib/.libs/libcurl.a libmicrohttpd/libmicrohttpd/src/microhttpd/.libs/libmicrohttpd.a: - cd libmicrohttpd && rm -rf libmicrohttpd-0.9.55 || true - cd libmicrohttpd && tar -zxf libmicrohttpd-0.9.55.tar.gz - cd libmicrohttpd/libmicrohttpd && ./configure --disable-https && CC=${CC} CXX=${CXX} ${MAKE} + cd libmicrohttpd && rm -rf libmicrohttpd-0.9.68 || true + cd libmicrohttpd && tar -zxf libmicrohttpd-0.9.68.tar.gz + cd libmicrohttpd/libmicrohttpd && ./configure --enable-https && CC=${CC} CXX=${CXX} ${MAKE} microhttpd: libmicrohttpd/libmicrohttpd/src/microhttpd/.libs/libmicrohttpd.a cityhash/cityhash/src/.libs/libcityhash.a: @@ -156,6 +165,7 @@ cleanpart: .PHONY: cleanpart cleanall: + cd libhttpserver && rm -rf libhttpserver-master_20191121 || true cd libdaemon && rm -rf libdaemon-0.14 cd jemalloc && rm -rf jemalloc-4.3.1 || true cd jemalloc && rm -rf jemalloc-5.2.0 || true @@ -168,7 +178,7 @@ cleanall: cd sqlite3/sqlite3 && rm -rf * || true cd clickhouse-cpp/clickhouse-cpp && rm -rf * || true cd lz4 && rm -rf lz4-1.7.5 || true - cd libmicrohttpd && rm -rf libmicrohttpd-0.9.55 || true + cd libmicrohttpd && rm -rf libmicrohttpd-0.9.68 || true cd curl && rm -rf curl-7.57.0 || true cd libev && rm -rf libev-4.24 || true cd libssl && rm -rf openssl-1.1.0h || true diff --git a/deps/libhttpserver/COPYING.LESSER b/deps/libhttpserver/COPYING.LESSER new file mode 100644 index 000000000..5ab7695ab --- /dev/null +++ b/deps/libhttpserver/COPYING.LESSER @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +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 this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +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 +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "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 +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY 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 +LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey 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 library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/deps/libhttpserver/libhttpserver b/deps/libhttpserver/libhttpserver new file mode 120000 index 000000000..11d279558 --- /dev/null +++ b/deps/libhttpserver/libhttpserver @@ -0,0 +1 @@ +libhttpserver-master_20191121 \ No newline at end of file diff --git a/deps/libhttpserver/libhttpserver-master_20191121.tar.gz b/deps/libhttpserver/libhttpserver-master_20191121.tar.gz new file mode 100644 index 000000000..531ebe6ab Binary files /dev/null and b/deps/libhttpserver/libhttpserver-master_20191121.tar.gz differ diff --git a/deps/libmicrohttpd/libmicrohttpd b/deps/libmicrohttpd/libmicrohttpd index 9c350c309..f4be94a80 120000 --- a/deps/libmicrohttpd/libmicrohttpd +++ b/deps/libmicrohttpd/libmicrohttpd @@ -1 +1 @@ -libmicrohttpd-0.9.55 \ No newline at end of file +libmicrohttpd-0.9.68 \ No newline at end of file diff --git a/include/MySQL_Session.h b/include/MySQL_Session.h index 54333bcff..01209c094 100644 --- a/include/MySQL_Session.h +++ b/include/MySQL_Session.h @@ -242,7 +242,7 @@ class MySQL_Session MySQL_Backend * create_backend(int, MySQL_Data_Stream *_myds=NULL); MySQL_Backend * find_or_create_backend(int, MySQL_Data_Stream *_myds=NULL); - void SQLite3_to_MySQL(SQLite3_result *, char *, int , MySQL_Protocol *); + void SQLite3_to_MySQL(SQLite3_result *, char *, int , MySQL_Protocol *, bool in_transaction=false); void MySQL_Result_to_MySQL_wire(MYSQL *mysql, MySQL_ResultSet *MyRS, MySQL_Data_Stream *_myds=NULL); void MySQL_Stmt_Result_to_MySQL_wire(MYSQL_STMT *stmt, MySQL_Connection *myconn); unsigned int NumActiveTransactions(); diff --git a/include/ProxySQL_RESTAPI_Server.hpp b/include/ProxySQL_RESTAPI_Server.hpp new file mode 100644 index 000000000..8ce7aedd6 --- /dev/null +++ b/include/ProxySQL_RESTAPI_Server.hpp @@ -0,0 +1,22 @@ +#ifndef CLASS_PROXYSQL_RESTAPI_SERVER_H +#define CLASS_PROXYSQL_RESTAPI_SERVER_H +#include "proxysql.h" +#include "cpp.h" +#include + +#include "httpserver.hpp" + +class ProxySQL_RESTAPI_Server { + private: + //httpserver::webserver *ws; + httpserver::webserver * ws; + int port; + pthread_t thread_id; + httpserver::http_resource *hr; + public: + ProxySQL_RESTAPI_Server(int p); + ~ProxySQL_RESTAPI_Server(); + void init(); + void print_version(); +}; +#endif /* CLASS_PROXYSQL_RESTAPI_SERVER */ diff --git a/include/SQLite3_Server.h b/include/SQLite3_Server.h index 8742c244b..c4edb6062 100644 --- a/include/SQLite3_Server.h +++ b/include/SQLite3_Server.h @@ -83,7 +83,7 @@ class SQLite3_Server { bool init(); void wrlock(); void wrunlock(); - void send_MySQL_OK(MySQL_Protocol *myprot, char *msg, int rows=0); + void send_MySQL_OK(MySQL_Protocol *myprot, char *msg, int rows=0, uint16_t status=2); void send_MySQL_ERR(MySQL_Protocol *myprot, char *msg); }; #endif // CLASS_PROXYSQL_SQLITE3_SERVER_H diff --git a/include/proxysql_admin.h b/include/proxysql_admin.h index dee37d738..7c9ee59fa 100644 --- a/include/proxysql_admin.h +++ b/include/proxysql_admin.h @@ -6,6 +6,8 @@ #include "cpp.h" #include +#include "ProxySQL_RESTAPI_Server.hpp" + typedef struct { uint32_t hash; uint32_t key; } t_symstruct; @@ -104,6 +106,10 @@ class ProxySQL_Admin { int stats_system_cpu; int stats_system_memory; int mysql_show_processlist_extended; + bool restapi_enabled; + bool restapi_enabled_old; + int restapi_port; + int restapi_port_old; bool web_enabled; bool web_enabled_old; int web_port; @@ -304,6 +310,7 @@ class ProxySQL_Admin { void save_sqliteserver_variables_from_runtime() { flush_sqliteserver_variables___runtime_to_database(admindb, true, true, false); } ProxySQL_HTTP_Server *AdminHTTPServer; + ProxySQL_RESTAPI_Server *AdminRestApiServer; #ifdef PROXYSQLCLICKHOUSE // ClickHouse diff --git a/include/proxysql_glovars.hpp b/include/proxysql_glovars.hpp index a79760c3d..b2ec57e35 100644 --- a/include/proxysql_glovars.hpp +++ b/include/proxysql_glovars.hpp @@ -52,6 +52,7 @@ class ProxySQL_GlobalVariables { char *datadir; char *admindb; char *statsdb_disk; + char *sqlite3serverdb; char *errorlog; char *pid; int restart_on_missing_heartbeats; @@ -62,6 +63,7 @@ class ProxySQL_GlobalVariables { bool gdbg; bool nostart; bool monitor; + bool version_check; #ifdef SO_REUSEPORT bool reuseport; #endif /* SO_REUSEPORT */ diff --git a/include/proxysql_structs.h b/include/proxysql_structs.h index 7605d9f53..dad8d1d6e 100644 --- a/include/proxysql_structs.h +++ b/include/proxysql_structs.h @@ -522,6 +522,7 @@ struct _global_variables_t { bool has_debug; bool idle_threads; + bool version_check; volatile int shutdown; bool nostart; diff --git a/lib/Makefile b/lib/Makefile index 5f958fd4a..3a5cb7157 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -26,6 +26,9 @@ SQLITE3_DIR=$(DEPS_PATH)/sqlite3/sqlite3 CLICKHOUSE_CPP_DIR=$(DEPS_PATH)/clickhouse-cpp/clickhouse-cpp +LIBHTTPSERVER_DIR=$(DEPS_PATH)/libhttpserver/libhttpserver +LIBHTTPSERVER_IDIR=-I$(LIBHTTPSERVER_DIR)/src + MICROHTTPD_DIR=$(DEPS_PATH)/libmicrohttpd/libmicrohttpd MICROHTTPD_IDIR=-I$(MICROHTTPD_DIR) -I$(MICROHTTPD_DIR)/src/include @@ -42,7 +45,7 @@ EV_IDIR=$(EV_DIR) IDIR=../include -IDIRS=-I$(IDIR) -I$(JEMALLOC_IDIR) -I$(MARIADB_IDIR) $(LIBCONFIG_IDIR) -I$(RE2_IDIR) -I$(SQLITE3_DIR) -I$(PCRE_PATH) -I/usr/local/include -I$(CLICKHOUSE_CPP_DIR) $(MICROHTTPD_IDIR) $(CURL_IDIR) -I$(EV_DIR) -I$(SSL_IDIR) +IDIRS=-I$(IDIR) -I$(JEMALLOC_IDIR) -I$(MARIADB_IDIR) $(LIBCONFIG_IDIR) -I$(RE2_IDIR) -I$(SQLITE3_DIR) -I$(PCRE_PATH) -I/usr/local/include -I$(CLICKHOUSE_CPP_DIR) $(MICROHTTPD_IDIR) $(LIBHTTPSERVER_IDIR) $(CURL_IDIR) -I$(EV_DIR) -I$(SSL_IDIR) LDIRS=-L$(JEMALLOC_PATH)/lib -L$(RE2_PATH)/obj -L$(INJECTION_PATH) @@ -89,7 +92,7 @@ default: libproxysql.a _OBJ = c_tokenizer.o OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ)) -_OBJ_CXX = ProxySQL_GloVars.oo network.oo debug.oo configfile.oo Query_Cache.oo SpookyV2.oo MySQL_Authentication.oo gen_utils.oo sqlite3db.oo mysql_connection.oo MySQL_HostGroups_Manager.oo mysql_data_stream.oo MySQL_Thread.oo MySQL_Session.oo MySQL_Protocol.oo mysql_backend.oo Query_Processor.oo ProxySQL_Admin.oo MySQL_Monitor.oo MySQL_Logger.oo thread.oo MySQL_PreparedStatement.oo ProxySQL_Cluster.oo SQLite3_Server.oo ClickHouse_Authentication.oo ClickHouse_Server.oo ProxySQL_Statistics.oo Chart_bundle_js.oo ProxySQL_HTTP_Server.oo font-awesome.min.css.oo main-bundle.min.css.oo set_parser.oo +_OBJ_CXX = ProxySQL_GloVars.oo network.oo debug.oo configfile.oo Query_Cache.oo SpookyV2.oo MySQL_Authentication.oo gen_utils.oo sqlite3db.oo mysql_connection.oo MySQL_HostGroups_Manager.oo mysql_data_stream.oo MySQL_Thread.oo MySQL_Session.oo MySQL_Protocol.oo mysql_backend.oo Query_Processor.oo ProxySQL_Admin.oo MySQL_Monitor.oo MySQL_Logger.oo thread.oo MySQL_PreparedStatement.oo ProxySQL_Cluster.oo SQLite3_Server.oo ClickHouse_Authentication.oo ClickHouse_Server.oo ProxySQL_Statistics.oo Chart_bundle_js.oo ProxySQL_HTTP_Server.oo ProxySQL_RESTAPI_Server.oo font-awesome.min.css.oo main-bundle.min.css.oo set_parser.oo OBJ_CXX = $(patsubst %,$(ODIR)/%,$(_OBJ_CXX)) HEADERS = ../include/*.h ../include/*.hpp diff --git a/lib/MySQL_Protocol.cpp b/lib/MySQL_Protocol.cpp index d3d89e7b2..647d6adb7 100644 --- a/lib/MySQL_Protocol.cpp +++ b/lib/MySQL_Protocol.cpp @@ -1752,10 +1752,10 @@ __do_auth: ((*myds)->sess->session_type == PROXYSQL_SESSION_ADMIN) || ((*myds)->sess->session_type == PROXYSQL_SESSION_STATS) -#if defined(TEST_AURORA) || defined(TEST_GALERA) || defined(TEST_GROUPREP) +//#if defined(TEST_AURORA) || defined(TEST_GALERA) || defined(TEST_GROUPREP) || ((*myds)->sess->session_type == PROXYSQL_SESSION_SQLITE) -#endif // TEST_AURORA || TEST_GALERA +//#endif // TEST_AURORA || TEST_GALERA ) { if (strcmp((const char *)user,mysql_thread___monitor_username)==0) { proxy_scramble(reply, (*myds)->myconn->scramble_buff, mysql_thread___monitor_password); diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 006179f4b..9c7c453a1 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -4896,10 +4896,10 @@ void MySQL_Session::handler___status_CONNECTING_CLIENT___STATE_SERVER_HANDSHAKE( client_authenticated=true; switch (session_type) { case PROXYSQL_SESSION_SQLITE: -#if defined(TEST_AURORA) || defined(TEST_GALERA) || defined(TEST_GROUPREP) +//#if defined(TEST_AURORA) || defined(TEST_GALERA) || defined(TEST_GROUPREP) free_users=1; break; -#endif // TEST_AURORA || TEST_GALERA || TEST_GROUPREP +//#endif // TEST_AURORA || TEST_GALERA || TEST_GROUPREP case PROXYSQL_SESSION_MYSQL: proxy_debug(PROXY_DEBUG_MYSQL_CONNECTION,8,"Session=%p , DS=%p , session_type=PROXYSQL_SESSION_MYSQL\n", this, client_myds); if (ldap_ctx==NULL) { @@ -6566,7 +6566,7 @@ void MySQL_Session::MySQL_Result_to_MySQL_wire(MYSQL *mysql, MySQL_ResultSet *My } } -void MySQL_Session::SQLite3_to_MySQL(SQLite3_result *result, char *error, int affected_rows, MySQL_Protocol *myprot) { +void MySQL_Session::SQLite3_to_MySQL(SQLite3_result *result, char *error, int affected_rows, MySQL_Protocol *myprot, bool in_transaction) { assert(myprot); MySQL_Data_Stream *myds=myprot->get_myds(); myds->DSS=STATE_QUERY_SENT_DS; @@ -6578,10 +6578,17 @@ void MySQL_Session::SQLite3_to_MySQL(SQLite3_result *result, char *error, int af sid++; } myds->DSS=STATE_COLUMN_DEFINITION; - - unsigned int nTrx=NumActiveTransactions(); - uint16_t setStatus = (nTrx ? SERVER_STATUS_IN_TRANS : 0 ); - if (autocommit) setStatus |= SERVER_STATUS_AUTOCOMMIT; + unsigned int nTrx = 0; + uint16_t setStatus = 0; + if (in_transaction == false) { + nTrx=NumActiveTransactions(); + setStatus = (nTrx ? SERVER_STATUS_IN_TRANS : 0 ); + if (autocommit) setStatus |= SERVER_STATUS_AUTOCOMMIT; + } else { + // this is for SQLite3 Server + setStatus = SERVER_STATUS_AUTOCOMMIT; + setStatus |= SERVER_STATUS_IN_TRANS; + } myprot->generate_pkt_EOF(true,NULL,NULL,sid,0, setStatus ); sid++; char **p=(char **)malloc(sizeof(char*)*result->columns); unsigned long *l=(unsigned long *)malloc(sizeof(unsigned long *)*result->columns); @@ -6601,12 +6608,24 @@ void MySQL_Session::SQLite3_to_MySQL(SQLite3_result *result, char *error, int af } else { // no result set if (error) { // there was an error - myprot->generate_pkt_ERR(true,NULL,NULL,sid,1045,(char *)"28000",error); + if (strcmp(error,(char *)"database is locked")==0) { + myprot->generate_pkt_ERR(true,NULL,NULL,sid,1205,(char *)"HY000",error); + } else { + myprot->generate_pkt_ERR(true,NULL,NULL,sid,1045,(char *)"28000",error); + } } else { // no error, DML succeeded - unsigned int nTrx=NumActiveTransactions(); - uint16_t setStatus = (nTrx ? SERVER_STATUS_IN_TRANS : 0 ); - if (autocommit) setStatus |= SERVER_STATUS_AUTOCOMMIT; + unsigned int nTrx = 0; + uint16_t setStatus = 0; + if (in_transaction == false) { + nTrx=NumActiveTransactions(); + setStatus = (nTrx ? SERVER_STATUS_IN_TRANS : 0 ); + if (autocommit) setStatus |= SERVER_STATUS_AUTOCOMMIT; + } else { + // this is for SQLite3 Server + setStatus = SERVER_STATUS_AUTOCOMMIT; + setStatus |= SERVER_STATUS_IN_TRANS; + } myprot->generate_pkt_OK(true,NULL,NULL,sid,affected_rows,0,setStatus,0,NULL); } myds->DSS=STATE_SLEEP; diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index 94bea90b9..2ec872752 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -57,6 +57,50 @@ struct MHD_Daemon *Admin_HTTP_Server; extern ProxySQL_Statistics *GloProxyStats; +extern char *ssl_key_fp; +extern char *ssl_cert_fp; +extern char *ssl_ca_fp; + + +static long +get_file_size (const char *filename) { + FILE *fp; + fp = fopen (filename, "rb"); + if (fp) { + long size; + if ((0 != fseek (fp, 0, SEEK_END)) || (-1 == (size = ftell (fp)))) + size = 0; + fclose (fp); + return size; + } else + return 0; +} + +static char * load_file (const char *filename) { + FILE *fp; + char *buffer; + long size; + size = get_file_size (filename); + if (0 == size) + return NULL; + fp = fopen (filename, "rb"); + if (! fp) + return NULL; + buffer = (char *)malloc (size + 1); + if (! buffer) { + fclose (fp); + return NULL; + } + buffer[size] = '\0'; + if (size != (long)fread (buffer, 1, size, fp)) { + free (buffer); + buffer = NULL; + } + fclose (fp); + return buffer; +} + + /* int sqlite3_json_init( sqlite3 *db, @@ -462,6 +506,8 @@ static char * admin_variables_names[]= { (char *)"checksum_mysql_query_rules", (char *)"checksum_mysql_servers", (char *)"checksum_mysql_users", + (char *)"restapi_enabled", + (char *)"restapi_port", (char *)"web_enabled", (char *)"web_port", #ifdef DEBUG @@ -4452,6 +4498,10 @@ ProxySQL_Admin::ProxySQL_Admin() { GloProxyStats->variables.stats_system_memory = 60; #endif + variables.restapi_enabled = false; + variables.restapi_enabled_old = false; + variables.restapi_port = 6090; + variables.restapi_port_old = variables.restapi_port; variables.web_enabled = false; variables.web_enabled_old = false; variables.web_port = 6080; @@ -4536,6 +4586,12 @@ bool ProxySQL_Admin::init() { AdminHTTPServer->init(); AdminHTTPServer->print_version(); + AdminRestApiServer = NULL; +/* + AdminRestApiServer = new ProxySQL_RESTAPI_Server(); + AdminRestApiServer->print_version(); +*/ + child_func[0]=child_mysql; child_func[1]=child_telnet; child_func[2]=child_telnet_also; @@ -4819,6 +4875,10 @@ void ProxySQL_Admin::admin_shutdown() { } } delete AdminHTTPServer; + if (AdminRestApiServer) { + delete AdminRestApiServer; + AdminRestApiServer = NULL; + } AdminHTTPServer = NULL; pthread_join(admin_thr, NULL); delete admindb; @@ -4981,14 +5041,40 @@ void ProxySQL_Admin::flush_admin_variables___database_to_runtime(SQLite3DB *db, //commit(); NOT IMPLEMENTED wrunlock(); { + if (variables.restapi_enabled != variables.restapi_enabled_old) { + if (variables.restapi_enabled) { + AdminRestApiServer = new ProxySQL_RESTAPI_Server(variables.restapi_port); + } else { + delete AdminRestApiServer; + AdminRestApiServer = NULL; + } + variables.restapi_enabled_old = variables.restapi_enabled; + } else { + if (variables.restapi_port != variables.restapi_port_old) { + if (AdminRestApiServer) { + delete AdminRestApiServer; + AdminRestApiServer = NULL; + } + if (variables.restapi_enabled) { + AdminRestApiServer = new ProxySQL_RESTAPI_Server(variables.restapi_port); + } + variables.restapi_port_old = variables.restapi_port; + } + } if (variables.web_enabled != variables.web_enabled_old) { if (variables.web_enabled) { - Admin_HTTP_Server = MHD_start_daemon(MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, + char *key_pem; + char *cert_pem; + key_pem = load_file(ssl_key_fp); + cert_pem = load_file(ssl_cert_fp); + Admin_HTTP_Server = MHD_start_daemon(MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_SSL, variables.web_port, NULL, NULL, http_handler, NULL, MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120, MHD_OPTION_STRICT_FOR_CLIENT, (int) 1, MHD_OPTION_THREAD_POOL_SIZE, (unsigned int) 4, MHD_OPTION_NONCE_NC_SIZE, (unsigned int) 300, + MHD_OPTION_HTTPS_MEM_KEY, key_pem, + MHD_OPTION_HTTPS_MEM_CERT, cert_pem, MHD_OPTION_END); } else { MHD_stop_daemon(Admin_HTTP_Server); @@ -5000,12 +5086,18 @@ void ProxySQL_Admin::flush_admin_variables___database_to_runtime(SQLite3DB *db, if (variables.web_enabled) { MHD_stop_daemon(Admin_HTTP_Server); Admin_HTTP_Server = NULL; - Admin_HTTP_Server = MHD_start_daemon(MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, + char *key_pem; + char *cert_pem; + key_pem = load_file(ssl_key_fp); + cert_pem = load_file(ssl_cert_fp); + Admin_HTTP_Server = MHD_start_daemon(MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_SSL, variables.web_port, NULL, NULL, http_handler, NULL, MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120, MHD_OPTION_STRICT_FOR_CLIENT, (int) 1, MHD_OPTION_THREAD_POOL_SIZE, (unsigned int) 4, MHD_OPTION_NONCE_NC_SIZE, (unsigned int) 300, + MHD_OPTION_HTTPS_MEM_KEY, key_pem, + MHD_OPTION_HTTPS_MEM_CERT, cert_pem, MHD_OPTION_END); } variables.web_port_old = variables.web_port; @@ -5854,6 +5946,13 @@ char * ProxySQL_Admin::get_variable(char *name) { if (!strcasecmp(name,"checksum_mysql_users")) { return strdup((checksum_variables.checksum_mysql_users ? "true" : "false")); } + if (!strcasecmp(name,"restapi_enabled")) { + return strdup((variables.restapi_enabled ? "true" : "false")); + } + if (!strcasecmp(name,"restapi_port")) { + sprintf(intbuf,"%d",variables.restapi_port); + return strdup(intbuf); + } if (!strcasecmp(name,"web_enabled")) { return strdup((variables.web_enabled ? "true" : "false")); } @@ -6316,6 +6415,26 @@ bool ProxySQL_Admin::set_variable(char *name, char *value) { // this is the pub } return false; } + if (!strcasecmp(name,"restapi_enabled")) { + if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) { + variables.restapi_enabled=true; + return true; + } + if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) { + variables.restapi_enabled=false; + return true; + } + return false; + } + if (!strcasecmp(name,"restapi_port")) { + int intv=atoi(value); + if (intv > 0 && intv < 65535) { + variables.restapi_port=intv; + return true; + } else { + return false; + } + } if (!strcasecmp(name,"web_enabled")) { if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) { variables.web_enabled=true; diff --git a/lib/ProxySQL_GloVars.cpp b/lib/ProxySQL_GloVars.cpp index db06f64fa..ea7a02948 100644 --- a/lib/ProxySQL_GloVars.cpp +++ b/lib/ProxySQL_GloVars.cpp @@ -60,7 +60,7 @@ ProxySQL_GlobalVariables::ProxySQL_GlobalVariables() { statuses.stack_memory_admin_threads = 0; statuses.stack_memory_cluster_threads = 0; - + global.version_check = true; global.gdbg=false; global.nostart=false; global.foreground=false; @@ -114,6 +114,7 @@ ProxySQL_GlobalVariables::ProxySQL_GlobalVariables() { #ifdef IDLE_THREADS opt->add((const char *)"",0,0,0,(const char *)"Create auxiliary threads to handle idle connections",(const char *)"--idle-threads"); #endif /* IDLE_THREADS */ + opt->add((const char *)"",0,0,0,(const char *)"Do not check for the latest version of ProxySQL",(const char *)"--no-version-check"); opt->add((const char *)"",0,1,0,(const char *)"Administration Unix Socket",(const char *)"-S",(const char *)"--admin-socket"); opt->add((const char *)"",0,0,0,(const char *)"Enable SQLite3 Server",(const char *)"--sqlite3-server"); @@ -188,6 +189,10 @@ void ProxySQL_GlobalVariables::process_opts_pre() { } #endif /* IDLE_THREADS */ + if (opt->isSet("--no-version-check")) { + global.version_check=false; + glovars.version_check=false; + } if (opt->isSet("--sqlite3-server")) { global.sqlite3_server=true; } diff --git a/lib/ProxySQL_HTTP_Server.cpp b/lib/ProxySQL_HTTP_Server.cpp index fdc493489..da5d5ad5f 100644 --- a/lib/ProxySQL_HTTP_Server.cpp +++ b/lib/ProxySQL_HTTP_Server.cpp @@ -83,12 +83,15 @@ static char * check_latest_version() { curl_global_init(CURL_GLOBAL_ALL); curl_handle = curl_easy_init(); - curl_easy_setopt(curl_handle, CURLOPT_URL, "http://www.proxysql.com/latest"); + curl_easy_setopt(curl_handle, CURLOPT_URL, "https://www.proxysql.com/latest"); curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk); + curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0); - curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "proxysql-agent/1.4.4"); - curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 5); + string s = "proxysql-agent/"; + s += PROXYSQL_VERSION; + curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, s.c_str()); + curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 10); curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 10); res = curl_easy_perform(curl_handle); diff --git a/lib/ProxySQL_RESTAPI_Server.cpp b/lib/ProxySQL_RESTAPI_Server.cpp new file mode 100644 index 000000000..30b278074 --- /dev/null +++ b/lib/ProxySQL_RESTAPI_Server.cpp @@ -0,0 +1,67 @@ +#include "proxysql.h" +#include "cpp.h" +#include "httpserver.hpp" + +#include "ProxySQL_RESTAPI_Server.hpp" +using namespace httpserver; + + +#ifdef DEBUG +#define DEB "_DEBUG" +#else +#define DEB "" +#endif /* DEBUG */ +#define PROXYSQL_RESTAPI_SERVER_VERSION "2.0.1121" DEB + +class hello_world_resource : public http_resource { +public: + const std::shared_ptr render_GET(const http_request&) { + return std::shared_ptr(new string_response("GET: Hello, World!")); + } + + const std::shared_ptr render(const http_request&) { + return std::shared_ptr(new string_response("OTHER: Hello, World!")); + } +}; + +void * restapi_server_thread(void *arg) { + httpserver::webserver * ws = (httpserver::webserver *)arg; + ws->start(true); + return NULL; +} + +ProxySQL_RESTAPI_Server::ProxySQL_RESTAPI_Server(int p) { + + // for now, this is COMPLETELY DISABLED + // just adding a POC + return; + + //ws = NULL; + port = p; + ws = new webserver(create_webserver(p)); + //hello_world_resource hwr; + hr = new hello_world_resource(); + //ws->register_resource("/hello", &hwr); + ws->register_resource("/hello", hr); + if (pthread_create(&thread_id, NULL, restapi_server_thread, ws) !=0 ) { + perror("Thread creation"); + exit(EXIT_FAILURE); + } + //webserver ws2 = create_webserver(8080); + //webserws = create_webserver(8080); +} + +ProxySQL_RESTAPI_Server::~ProxySQL_RESTAPI_Server() { + if (ws) { + ws->stop(); + pthread_join(thread_id, NULL); + } +} + +void ProxySQL_RESTAPI_Server::init() { +} + +void ProxySQL_RESTAPI_Server::print_version() { + fprintf(stderr,"Standard ProxySQL REST API Server Handler rev. %s -- %s -- %s\n", PROXYSQL_RESTAPI_SERVER_VERSION, __FILE__, __TIMESTAMP__); +} + diff --git a/lib/SQLite3_Server.cpp b/lib/SQLite3_Server.cpp index 9183e01d9..ca34b866a 100644 --- a/lib/SQLite3_Server.cpp +++ b/lib/SQLite3_Server.cpp @@ -299,6 +299,7 @@ void SQLite3_Server_session_handler(MySQL_Session *sess, void *_pa, PtrSize_t *p // fix bug #1047 if ( +/* (!strncasecmp("BEGIN", query_no_space, strlen("BEGIN"))) || (!strncasecmp("START TRANSACTION", query_no_space, strlen("START TRANSACTION"))) @@ -307,6 +308,7 @@ void SQLite3_Server_session_handler(MySQL_Session *sess, void *_pa, PtrSize_t *p || (!strncasecmp("ROLLBACK", query_no_space, strlen("ROLLBACK"))) || +*/ (!strncasecmp("SET character_set_results", query_no_space, strlen("SET character_set_results"))) || (!strncasecmp("SET SQL_AUTO_IS_NULL", query_no_space, strlen("SET SQL_AUTO_IS_NULL"))) @@ -314,12 +316,46 @@ void SQLite3_Server_session_handler(MySQL_Session *sess, void *_pa, PtrSize_t *p (!strncasecmp("SET NAMES", query_no_space, strlen("SET NAMES"))) || (!strncasecmp("SET AUTOCOMMIT", query_no_space, strlen("SET AUTOCOMMIT"))) + || + (!strncasecmp("/*!40100 SET @@SQL_MODE='' */", query_no_space, strlen("/*!40100 SET @@SQL_MODE='' */"))) + || + (!strncasecmp("/*!40103 SET TIME_ZONE=", query_no_space, strlen("/*!40103 SET TIME_ZONE="))) + || + (!strncasecmp("/*!80000 SET SESSION", query_no_space, strlen("/*!80000 SET SESSION"))) + || + (!strncasecmp("SET SESSION", query_no_space, strlen("SET SESSION"))) + || + (!strncasecmp("SET wait_timeout", query_no_space, strlen("SET wait_timeout"))) ) { - GloSQLite3Server->send_MySQL_OK(&sess->client_myds->myprot, NULL); + SQLite3_Session *sqlite_sess = (SQLite3_Session *)sess->thread->gen_args; + sqlite3 *db = sqlite_sess->sessdb->get_db(); + uint16_t status=2; // autocommit + if (sqlite3_get_autocommit(db)==0) { + status = 3; // autocommit + transaction + } + GloSQLite3Server->send_MySQL_OK(&sess->client_myds->myprot, NULL, 0, status); run_query=false; goto __run_query; } + if (query_no_space_length==17) { + if (!strncasecmp((char *)"START TRANSACTION", query_no_space, query_no_space_length)) { + l_free(query_length,query); + query = l_strdup((char *)"BEGIN IMMEDIATE"); + query_length=strlen(query)+1; + goto __run_query; + } + } + + if (query_no_space_length==5) { + if (!strncasecmp((char *)"BEGIN", query_no_space, query_no_space_length)) { + l_free(query_length,query); + query = l_strdup((char *)"BEGIN IMMEDIATE"); + query_length=strlen(query)+1; + goto __run_query; + } + } + if (query_no_space_length==SELECT_VERSION_COMMENT_LEN) { if (!strncasecmp(SELECT_VERSION_COMMENT, query_no_space, query_no_space_length)) { l_free(query_length,query); @@ -586,7 +622,12 @@ __run_query: } } #endif // TEST_AURORA || TEST_GALERA || TEST_GROUPREP - sess->SQLite3_to_MySQL(resultset, error, affected_rows, &sess->client_myds->myprot); + sqlite3 *db = sqlite_sess->sessdb->get_db(); + bool in_trans = false; + if (sqlite3_get_autocommit(db)==0) { + in_trans = true; + } + sess->SQLite3_to_MySQL(resultset, error, affected_rows, &sess->client_myds->myprot, in_trans); delete resultset; } l_free(pkt->size-sizeof(mysql_hdr),query_no_space); // it is always freed here @@ -595,8 +636,11 @@ __run_query: SQLite3_Session::SQLite3_Session() { - sessdb = new SQLite3DB(); - sessdb->open((char *)"file:mem_sqlitedb?mode=memory&cache=shared", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX); + sessdb=new SQLite3DB(); + sessdb->open(GloVars.sqlite3serverdb, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX); + sessdb->execute((char *)"PRAGMA journal_mode=WAL"); + sessdb->execute((char *)"PRAGMA journal_size_limit=67108864"); + sessdb->execute((char *)"PRAGMA synchronous=0"); } SQLite3_Session::~SQLite3_Session() { @@ -877,8 +921,11 @@ SQLite3_Server::SQLite3_Server() { //Initialize locker pthread_rwlock_init(&rwlock,NULL); - sessdb = new SQLite3DB(); - sessdb->open((char *)"file:mem_sqlitedb?mode=memory&cache=shared", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX); + sessdb=new SQLite3DB(); + sessdb->open(GloVars.sqlite3serverdb, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX); + sessdb->execute((char *)"PRAGMA journal_mode=WAL"); + sessdb->execute((char *)"PRAGMA journal_size_limit=67108864"); + sessdb->execute((char *)"PRAGMA synchronous=0"); variables.read_only=false; @@ -1215,11 +1262,11 @@ bool SQLite3_Server::set_variable(char *name, char *value) { // this is the pub return false; } -void SQLite3_Server::send_MySQL_OK(MySQL_Protocol *myprot, char *msg, int rows) { +void SQLite3_Server::send_MySQL_OK(MySQL_Protocol *myprot, char *msg, int rows, uint16_t status) { assert(myprot); MySQL_Data_Stream *myds=myprot->get_myds(); myds->DSS=STATE_QUERY_SENT_DS; - myprot->generate_pkt_OK(true,NULL,NULL,1,rows,0,2,0,msg); + myprot->generate_pkt_OK(true,NULL,NULL,1,rows,0,status,0,msg); myds->DSS=STATE_SLEEP; } diff --git a/lib/configfile.cpp b/lib/configfile.cpp index 32158616b..7feccaf85 100644 --- a/lib/configfile.cpp +++ b/lib/configfile.cpp @@ -205,5 +205,3 @@ bool ProxySQL_ConfigFile::configVariable(const char *group, const char *key, cha } return true; } - - diff --git a/lib/sqlite3db.cpp b/lib/sqlite3db.cpp index b97b1005e..0534aacc6 100644 --- a/lib/sqlite3db.cpp +++ b/lib/sqlite3db.cpp @@ -198,6 +198,10 @@ bool SQLite3DB::execute_statement(const char *str, char **error, int *cols, int do { rc = sqlite3_prepare_v2(db, str, -1, &statement, 0); if (rc==SQLITE_LOCKED || rc==SQLITE_BUSY) { // the execution of the prepared statement failed because locked + if (sqlite3_get_autocommit(db)==0) { + *error=strdup(sqlite3_errmsg(db)); + goto __exit_execute_statement; + } usleep(USLEEP_SQLITE_LOCKED); } } while (rc==SQLITE_LOCKED || rc==SQLITE_BUSY); @@ -213,6 +217,10 @@ bool SQLite3DB::execute_statement(const char *str, char **error, int *cols, int do { rc=sqlite3_step(statement); if (rc==SQLITE_LOCKED || rc==SQLITE_BUSY) { // the execution of the prepared statement failed because locked + if (sqlite3_get_autocommit(db)==0) { + *error=strdup(sqlite3_errmsg(db)); + goto __exit_execute_statement; + } usleep(USLEEP_SQLITE_LOCKED); } } while (rc==SQLITE_LOCKED || rc==SQLITE_BUSY); @@ -229,6 +237,7 @@ bool SQLite3DB::execute_statement(const char *str, char **error, int *cols, int ret=true; } __exit_execute_statement: + sqlite3_reset(statement); sqlite3_finalize(statement); return ret; } diff --git a/notes/run_sysbench_on_sqlite3.md b/notes/run_sysbench_on_sqlite3.md new file mode 100644 index 000000000..eae80ddaf --- /dev/null +++ b/notes/run_sysbench_on_sqlite3.md @@ -0,0 +1,32 @@ + + +On Admin: + +```sql +insert into mysql_servers (hostgroup_id, hostname, port) values (100,'127.0.0.1',6030); +insert into mysql_users (username,password,default_hostgroup) values ('sqlite','sqlite',100); + +save mysql users to disk; +load mysql users to runtime; +save mysql servers to disk; +load mysql servers to runtime; + + + +INSERT INTO mysql_query_rules (active,username,match_digest,match_pattern,replace_pattern,apply) values (1,'sqlite','^CREATE TABLE sbtest','id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT','id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT',0); +INSERT INTO mysql_query_rules (active,username,match_digest,match_pattern,replace_pattern,apply) values (1,'sqlite','^CREATE TABLE sbtest',"pad CHAR\(60\) DEFAULT '' NOT NULL,","pad CHAR(60) DEFAULT '' NOT NULL",0); +INSERT INTO mysql_query_rules (active,username,match_digest,match_pattern,replace_pattern,apply) values (1,'sqlite','^CREATE TABLE sbtest','PRIMARY KEY \(id\)','',0); + +save mysql query rules to disk; +load mysql query rules to runtime; +``` + +Sysbbench: + +```shell +sysbench --db-driver=mysql --test=/usr/share/sysbench/tests/include/oltp_legacy/oltp.lua --oltp-tables-count=10 --oltp-table-size=10000 --mysql-host=127.0.0.1 --mysql-db=test --mysql-engine-trx=yes --mysql-port=6033 --mysql-user=sqlite --mysql-password=sqlite --num-threads=10 prepare +``` + +```shell +sysbench --report-interval=3 --db-driver=mysql /usr/share/sysbench/tests/include/oltp_legacy/oltp.lua --time=15 --oltp-tables-count=10 --oltp-table-size=10000 --mysql-host=127.0.0.1 --mysql-db=test --mysql-engine-trx=yes --oltp-skip-trx=off --mysql-port=6033 --mysql-user=sqlite --mysql-password=sqlite --threads=10 run +``` diff --git a/src/Makefile b/src/Makefile index 336aee714..5b7d17a11 100644 --- a/src/Makefile +++ b/src/Makefile @@ -36,6 +36,10 @@ LZ4_DIR=$(DEPS_PATH)/lz4/lz4 CLICKHOUSE_CPP_DIR=$(DEPS_PATH)/clickhouse-cpp/clickhouse-cpp +LIBHTTPSERVER_DIR=$(DEPS_PATH)/libhttpserver/libhttpserver +LIBHTTPSERVER_IDIR=$(LIBHTTPSERVER_DIR)/src +LIBHTTPSERVER_LDIR=$(LIBHTTPSERVER_DIR)/build/src/.libs/ + MICROHTTPD_DIR=$(DEPS_PATH)/libmicrohttpd/libmicrohttpd/src MICROHTTPD_IDIR=$(MICROHTTPD_DIR)/include MICROHTTPD_LDIR=$(MICROHTTPD_DIR)/microhttpd/.libs @@ -55,8 +59,8 @@ EV_LDIR=$(EV_DIR)/.libs IDIR=../include LDIR=../lib -IDIRS=-I$(IDIR) -I$(JEMALLOC_IDIR) -I$(MARIADB_IDIR) $(LIBCONFIG_IDIR) -I$(DAEMONPATH_IDIR) -I$(SQLITE3_DIR) -I$(CLICKHOUSE_CPP_DIR) -I$(MICROHTTPD_IDIR) -I$(CURL_IDIR) -I$(EV_IDIR) -I$(SSL_IDIR) -LDIRS=-L$(LDIR) -L$(JEMALLOC_LDIR) $(LIBCONFIG_LDIR) -L$(RE2_PATH)/obj -L$(MARIADB_LDIR) -L$(DAEMONPATH_LDIR) -L$(PCRE_LDIR) -L$(MICROHTTPD_LDIR) -L$(CURL_LDIR) -L$(EV_LDIR) -L$(SSL_LDIR) +IDIRS=-I$(IDIR) -I$(JEMALLOC_IDIR) -I$(MARIADB_IDIR) $(LIBCONFIG_IDIR) -I$(DAEMONPATH_IDIR) -I$(SQLITE3_DIR) -I$(CLICKHOUSE_CPP_DIR) -I$(MICROHTTPD_IDIR) -I$(LIBHTTPSERVER_IDIR) -I$(CURL_IDIR) -I$(EV_IDIR) -I$(SSL_IDIR) +LDIRS=-L$(LDIR) -L$(JEMALLOC_LDIR) $(LIBCONFIG_LDIR) -L$(RE2_PATH)/obj -L$(MARIADB_LDIR) -L$(DAEMONPATH_LDIR) -L$(PCRE_LDIR) -L$(MICROHTTPD_LDIR) -L$(LIBHTTPSERVER_LDIR) -L$(CURL_LDIR) -L$(EV_LDIR) -L$(SSL_LDIR) UNAME_S := $(shell uname -s) @@ -77,9 +81,9 @@ MYCXXFLAGS=-std=c++11 $(IDIRS) $(OPTZ) $(DEBUG) $(PSQLCH) -DGITVERSION=\"$(GIT_V LDFLAGS+= NOJEMALLOC := $(shell echo $(NOJEMALLOC)) ifeq ($(NOJEMALLOC),1) -MYLIBS=-Wl,--export-dynamic -Wl,-Bstatic -lconfig -lproxysql -ldaemon -lconfig++ -lre2 -lpcrecpp -lpcre -lmariadbclient -lmicrohttpd -lcurl -lev -Wl,-Bdynamic -lpthread -lm -lz -lrt $(EXTRALINK) +MYLIBS=-Wl,--export-dynamic -Wl,-Bstatic -lconfig -lproxysql -ldaemon -lconfig++ -lre2 -lpcrecpp -lpcre -lmariadbclient -lmicrohttpd -lhttpserver -lcurl -lssl -lcrypto -lev -Wl,-Bdynamic -lgnutls -lpthread -lm -lz -lrt $(EXTRALINK) else -MYLIBS=-Wl,--export-dynamic -Wl,-Bstatic -lconfig -lproxysql -ldaemon -ljemalloc -lconfig++ -lre2 -lpcrecpp -lpcre -lmariadbclient -lmicrohttpd -lcurl -lev -Wl,-Bdynamic -lpthread -lm -lz -lrt $(EXTRALINK) +MYLIBS=-Wl,--export-dynamic -Wl,-Bstatic -lconfig -lproxysql -ldaemon -ljemalloc -lconfig++ -lre2 -lpcrecpp -lpcre -lmariadbclient -lhttpserver -lmicrohttpd -lcurl -lssl -lcrypto -lev -Wl,-Bdynamic -lgnutls -lpthread -lm -lz -lrt $(EXTRALINK) endif ifeq ($(UNAME_S),Darwin) @@ -98,7 +102,7 @@ endif LIBPROXYSQLAR=$(LDIR)/libproxysql.a ifeq ($(UNAME_S),Darwin) - LIBPROXYSQLAR=$(LDIR)/libproxysql.a ../deps/libmicrohttpd/libmicrohttpd/src/microhttpd/.libs/libmicrohttpd.a ../deps/pcre/pcre/.libs/libpcre.a ../deps/pcre/pcre/.libs/libpcrecpp.a ../deps/libdaemon/libdaemon/libdaemon/.libs/libdaemon.a ../deps/libconfig/libconfig/lib/.libs/libconfig++.a ../deps/libconfig/libconfig/lib/.libs/libconfig.a ../deps/curl/curl/lib/.libs/libcurl.a ../deps/sqlite3/sqlite3/sqlite3.o + LIBPROXYSQLAR=$(LDIR)/libproxysql.a ../deps/libmicrohttpd/libmicrohttpd/src/microhttpd/.libs/libmicrohttpd.a ../deps/libhttpserver/libhttpserver/build/src/.libs/libhttpserver.a ../deps/pcre/pcre/.libs/libpcre.a ../deps/pcre/pcre/.libs/libpcrecpp.a ../deps/libdaemon/libdaemon/libdaemon/.libs/libdaemon.a ../deps/libconfig/libconfig/lib/.libs/libconfig++.a ../deps/libconfig/libconfig/lib/.libs/libconfig.a ../deps/curl/curl/lib/.libs/libcurl.a ../deps/sqlite3/sqlite3/sqlite3.o endif LIBPROXYSQLAR+= $(SSL_LDIR)/libssl.a $(SSL_LDIR)/libcrypto.a diff --git a/src/main.cpp b/src/main.cpp index 3db49efec..8ff00a746 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,6 +26,8 @@ #include #include "ev.h" +#include "curl/curl.h" + #include /* @@ -37,6 +39,10 @@ extern "C" MySQL_LDAP_Authentication * create_MySQL_LDAP_Authentication_func() { volatile create_MySQL_LDAP_Authentication_t * create_MySQL_LDAP_Authentication = NULL; void * __mysql_ldap_auth; +// absolute path of ssl files +char *ssl_key_fp = NULL; +char *ssl_cert_fp = NULL; +char *ssl_ca_fp = NULL; char *binary_sha1 = NULL; @@ -140,6 +146,77 @@ DH *get_dh2048() return(dh); } +struct MemoryStruct { + char *memory; + size_t size; +}; + + +static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) { + size_t realsize = size * nmemb; + struct MemoryStruct *mem = (struct MemoryStruct *)userp; + mem->memory = (char *)realloc(mem->memory, mem->size + realsize + 1); + assert(mem->memory); + memcpy(&(mem->memory[mem->size]), contents, realsize); + mem->size += realsize; + mem->memory[mem->size] = 0; + return realsize; +} + + +static char * main_check_latest_version() { + CURL *curl_handle; + CURLcode res; + struct MemoryStruct chunk; + chunk.memory = (char *)malloc(1); + chunk.size = 0; + curl_global_init(CURL_GLOBAL_ALL); + curl_handle = curl_easy_init(); + curl_easy_setopt(curl_handle, CURLOPT_URL, "https://www.proxysql.com/latest"); + curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); + curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk); + curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0); + + string s = "proxysql-agent/"; + s += PROXYSQL_VERSION; + if (binary_sha1) { + s += " (" ; + s+= binary_sha1; + s += ")" ; + } + curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, s.c_str()); + curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 10); + curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 10); + + res = curl_easy_perform(curl_handle); + + if (res != CURLE_OK) { + switch (res) { + case CURLE_COULDNT_RESOLVE_HOST: + case CURLE_COULDNT_CONNECT: + case CURLE_OPERATION_TIMEDOUT: + break; + default: + proxy_error("curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); + break; + } + free(chunk.memory); + chunk.memory = NULL; + } + curl_easy_cleanup(curl_handle); + curl_global_cleanup(); + return chunk.memory; +} + +void * main_check_latest_version_thread(void *arg) { + char * latest_version = main_check_latest_version(); + if (latest_version) { + proxy_info("Latest ProxySQL version available: %s\n", latest_version); + } + return NULL; +} + + @@ -362,11 +439,12 @@ int ssl_mkit(X509 **x509p, EVP_PKEY **pkeyp, int bits, int serial, int days) { const char * ssl_cert_rp = (const char *)"proxysql-cert.pem"; const char * ssl_ca_rp = (const char *)"proxysql-ca.pem"; +/* // absolute path of ssl files char *ssl_key_fp = NULL; char *ssl_cert_fp = NULL; char *ssl_ca_fp = NULL; - +*/ // how many files exists ? int nfiles = 0; bool ssl_key_exists = true; @@ -800,6 +878,9 @@ void ProxySQL_Main_process_global_variables(int argc, const char **argv) { GloVars.admindb=(char *)malloc(strlen(GloVars.datadir)+strlen((char *)"proxysql.db")+2); sprintf(GloVars.admindb,"%s/%s",GloVars.datadir, (char *)"proxysql.db"); + GloVars.sqlite3serverdb=(char *)malloc(strlen(GloVars.datadir)+strlen((char *)"sqlite3server.db")+2); + sprintf(GloVars.sqlite3serverdb,"%s/%s",GloVars.datadir, (char *)"sqlite3server.db"); + GloVars.statsdb_disk=(char *)malloc(strlen(GloVars.datadir)+strlen((char *)"proxysql_stats.db")+2); sprintf(GloVars.statsdb_disk,"%s/%s",GloVars.datadir, (char *)"proxysql_stats.db"); @@ -1611,6 +1692,16 @@ __start_label: #endif } + if (GloVars.global.version_check) { + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + pthread_t thr; + if (pthread_create(&thr, &attr, main_check_latest_version_thread, NULL) !=0 ) { + perror("Thread creation"); + exit(EXIT_FAILURE); + } + } { unsigned int missed_heartbeats = 0; unsigned long long previous_time = monotonic_time(); diff --git a/src/proxysql.cfg b/src/proxysql.cfg index 31a93535c..e3fe5cd4d 100644 --- a/src/proxysql.cfg +++ b/src/proxysql.cfg @@ -4,7 +4,6 @@ # http://www.hyperrealm.com/libconfig/libconfig_manual.html#Configuration-File-Grammar # Grammar is also copied at the end of this file - restart_on_missing_heartbeats=10 datadir="/var/lib/proxysql" //execute_on_exit_failure="/path/to/script"