CppCMS Blog http://blog.cppcms.com/ A blog on CppCMS - C++ Web Development Framework How not to do Unicode... http://blog.cppcms.com/post/105 http://blog.cppcms.com/post/105 <div style="direction:ltr"> <p>All started from a small problem, how to print Unicode text to the Windows Console with option redirect to a file.</p> <p>Let's say we have a program Hello that prints few words in several languages to the screen..</p> <pre><code>#include &lt;stdio.h&gt; int main() { printf("Мир Peace Ειρήνη\n"); return 0; } </code></pre> <p>The program above is trivial and works fine under Windows if current console codepage is set to UTF-8. Also this can be fixed from the program by calling <code>SetConsolseOutputCP(CP_UTF8)</code>.</p> <p>Now simple tweak... Instead of that standard C <code>printf</code> we would use standard C++ <code>std::cout</code>... It works fine for GCC. But under Visual C++ it prints squares...</p> <p>If I try redirection <code>test.exe &gt;test.txt</code> - I get perfectly fine UTF-8 text...</p> <p>I had started researching the issue and found the <a href="http://blogs.msdn.com/b/michkap/archive/2008/03/18/8306597.aspx">post</a> of one of the Windows Unicode Gurus <a href="http://blogs.msdn.com/b/michkap/">Michael Kaplan's</a>.</p> <p>I've tried to run <code>_setmode(_fileno(stdout), _O_U8TEXT)</code> as recommended by the Microsoft's Unicode guru and... By program crashed on attempt to write to the output stream.</p> <p>Keeping searching for an answer I've got to this <a href="http://connect.microsoft.com/VisualStudio/feedback/details/431244/std-ostream-fails-to-write-utf-8-encoded-string-to-console">bug report</a>...</p> <p>Short summary:</p> <ul> <li>User: Can't print UTF-8 to console with std::cout</li> <li>MS: Closing - this is by design, see Michael Kaplan's article about writing to console</li> <li>User: But if I do what suggested program crashes, and I still can't write Unicode to console</li> <li>MS: Reactivate the ticket if it does not works</li> <li>User: it does not!</li> <li>MS: Use wide output...</li> <li>User: I'd rather use fprintf in first place!?</li> </ul> <p>To the summary...</p> <p>If you use Visual C++ you can't use UTF-8 to print text to <code>std::cout</code>.</p> <p>If you still want to, please read this <a href="http://alfps.wordpress.com/2011/12/08/unicode-part-2-utf-8-stream-mode/">amazingly long article</a> about how to make <code>wcout</code> and <code>cout</code> working, but it does not really give a simple solution - finally falling to redefinition of the stream buffers...</p> <p>So please, if you design API or Operating System, <strong>do not use</strong> kind of "Wide" API... This is is the wrong way to do Unicode.</p> <p>Which reminds me... Spread around:</p> <p><a href="http://www.utf8everywhere.org/">http://www.utf8everywhere.org/</a></p> <p>Related Posts: <a href="http://blog.cppcms.com/post/62">http://blog.cppcms.com/post/62</a></p> </div> RPM Repositories for CppCMS http://blog.cppcms.com/post/104 http://blog.cppcms.com/post/104 <div style="direction:ltr"> <p>Additionally to <a href="http://apt.cppcms.com">DEB Repositories</a>, RPM repositories are ready as well.</p> <p>The packages are build using Open Build Service:</p> <ul> <li>Distributions: Fedora 15 and 16, CentOS 6, OpenSuse 11.4 and 12.1</li> <li>Architectures: x86, x86_64</li> <li>Packages: libcppcms, libcppcms-devel, cppcms-tools</li> <li>Sources: cppcms</li> </ul> <p><a href="http://download.opensuse.org/repositories/home:/artyom-beilis/">http://download.opensuse.org/repositories/home:/artyom-beilis/</a></p> </div> CppCMS 1.0.1 - Bug Fix Release http://blog.cppcms.com/post/103 http://blog.cppcms.com/post/103 <div style="direction:ltr"> <p>CppCMS 1.0.1 Released</p> <p>It is a bug fix release:</p> <ul> <li>Fixed crash when using process-shared memory cache, when CppCMS compiled in Release mode with gcc 4.5 and 4.6.</li> <li>Added support of CMake LIBDIR option to allow installation of libraries to lib64 instead of lib as required by Rad Had based distributions.</li> </ul> <p>Additionally to the deb releases, now source-rpm is available at sourceforge.</p> <p>In order to create RPMs for your system:</p> <p>Install dependent packages:</p> <pre><code>yum install cmake gcc-c++ gcc make zlib-devel pcre-devel libicu-devel libgcrypt-devel </code></pre> <p>Download source rpm and rebuild it as:</p> <pre><code>rpmbuild --rebuild cppcms-1.0.1-1.src.rpm </code></pre> <p>You will get 3 binary rpm packages: libcppcms, libcppcms-devel and cppcms-tools in the <code>~/rpmbuild/RPMS/</code> directory. Install them and use them.</p> <p><strong>Special Thanks:</strong> to Sagi Ben-Akiva for initial spec file that made this process much simpler for me.</p> </div> CppCMS 1.0.0 released and offered under dual license http://blog.cppcms.com/post/102 http://blog.cppcms.com/post/102 <div style="direction:ltr"> <p>CppCMS 1.0.0 was released today. Now it is offered under alternative commercial license. You can choose to use CppCMS under either open source LGPLv3 license or under a commercial license that allows your developing truly closed source applications.</p> <p>For more details about licensing and pricing please visit our web site:<br/> <a href="http://commercial.cppcms.com">http://commercial.cppcms.com</a></p> <p>The old-stable branch of CppCMS - 0.0.x is now deprecated and would not receive any updates. CppCMS users who still use CppCMS 0.0.8 are encouraged to upgrade to the CppCMS 1.</p> <p>The new version includes:</p> <ul> <li>Stable API and ABI</li> <li>Comet and Ajax support</li> <li>Powerful localization</li> <li>Native Windows support</li> <li>And much more</li> </ul> <p>You can find more details about the differences between CppCMS 1.0.0 and CppCMS 0.0.8 <a href="http://cppcms.com/wikipp/en/page/cppcms_1x_whats_new">here</a></p> </div> Apt Repositories http://blog.cppcms.com/post/101 http://blog.cppcms.com/post/101 <div style="direction:ltr"> <p>New Apt repositories for Debian and Ubuntu are available.</p> <p>Read: <a href="http://cppcms.com/wikipp/en/page/apt">http://cppcms.com/wikipp/en/page/apt</a></p> </div> CppCMS 0.999.1 - Release Candidate 2 http://blog.cppcms.com/post/100 http://blog.cppcms.com/post/100 <div style="direction:ltr"> <p>All CppCMS 1.0.0 milestone tasks had completed and thus the second release candidate was released. It contains mostly bug fixes including several security bug fixes. It is expected to be the last RC before the stable version would be delivered.</p> <p>All CppCMS users please download the RC2 and test it. If no critical problems would be found the stable version would be announced in a week or two.</p> <h2>Whats New?</h2> <p><em>Security Bug Fixes:</em></p> <ul> <li>Fixed a bug when calling <code>reset_session()</code> would not reset it when session content itself was not changed.</li> <li>Fixed a bug that could cause infinite waiting when POST data contained incomplete multi-part data potentially causing DOS.</li> </ul> <p><em>Breaking Changes:</em></p> <p>The protocol between <code>cppcms_scale</code> and <code>cppcms</code> clients had changed, you can't use old <code>cppcms_scale</code> with newer versions of <code>cppcms</code> and vise versa.</p> <p>The protocol now uses absolute 64 bit time-stamp rather then relative one.</p> <p><em>New Features:</em></p> <ul> <li>Many new unit tests implemented giving good test coverage for the CppCMS framework.</li> <li>Added support of nginx with SCGI protocol to <code>cppcms_run</code></li> <li>Many examples added: Asynchronous I/O, Serialization, Templates Inheritance. Some examples updated to use moder API.</li> </ul> <p><em>Bug Fixes:</em></p> <ul> <li>Fixed a bug that prevented "Keep-Alive" option to work with FastCGI protocol.</li> <li>Session cookie was not delete on clear session call with server side session storage.</li> <li>Fixed a bug that caused a session value to be unexposed what it was updated.</li> <li>Fixed incorrect call of <code>view_builder</code> instead of <code>unsafe_view_builder</code> when unsefe option was given</li> <li>Fixed status handling according to HTTP/CGI specifications in case of invalid POST input.</li> <li>Fixed a bug when in certain situations sockets were not shutdown properly.</li> <li>Added better error reporting when the content of invalid type was used during view rendering.</li> <li>Fixed <code>cppcms_run</code> to setup nginx's <code>PATH_INFO</code> correctly according to the options available in the latest version.</li> </ul> </div> Nginx? No thank you... Lighttpd http://blog.cppcms.com/post/99 http://blog.cppcms.com/post/99 <div style="direction:ltr"> <p>Nginx is 3rd (or 2nd depending on the statistics) <a href="http://news.netcraft.com/archives/2012/01/03/january-2012-web-server-survey.html">most popular</a> web server. It seems that it should be one of the best servers around however, every time I have to deal with it I understand that I really don't like it.</p> <p>When you look deep down into the Nginx web server you realize that it not as good as you think it is. Even though, it is a good reverse proxy and very well suited for serving static files, when it comes to dynamic content it begins to feel sloppy.</p> <p>It is not uncommon that you have a web site powered by nginx and in reality it works like a load balancer or reverse proxy in front of Apache or other services.</p> <p>And this is not an accident, this popular webs sever has too many flaws:</p> <ul> <li><p>First of all it is not capable to handle CGI scripts at all.</p></li> <li><p>It does not support automatic control of a lifetime of FastCGI and SCGI processes.</p> <p> Basically this means that you need to prepare a separate services to run your FastCGI application instead giving this simple job to a web server.</p></li> <li><p>FastCGI support was broken for a long time and only <a href="http://wiki.nginx.org/HttpFcgiModule#fastcgi_split_path_info">recently</a> we got an option to setup a CGI variable <code>PATH_INFO</code> correctly as required by CGI RFC.</p> <p> Before that you need to do some tricks with rewriting and you could not get url-decoded <code>PATH_INFO</code> as required by RFC.</p></li> <li><p>SCGI support is totally broken as:</p> <ul> <li>It requires from the SCGI server to send full HTTP headers instead of parsing <code>Status</code> header.</li> <li><code>PATH_INFO</code> and <code>SCRIPT_NAME</code> do not work in the same way they were not working with fastcgi.</li> </ul> </li> <li><p>Basic security feature like <code>Options -FollowSymLinks</code> that is implemented in all normal web servers starting from a "fat" Apache to a small and tiny thttpd is not implemented!</p> <p>Short explanation: consider Alice that creates a symbolic link such that it points to /var/users/passwords file. Alice does not have permissions to read this file but web sever may have such permissions. By creating an innocent symbolic link in the document root of her web server it escalates her abilities to read any file that the web server can read.</p> <p>Every modern web server has an option to track symbolic links and prevent serving files outside of the scope of the web server document root, but nginx does not have one.</p></li> <li><p>The documentation quality is overall lower then the quality of documents of Lighttpd or Apache web servers. Also the configuration is generally much more complicated and verbose even for simple tasks.</p></li> </ul> <p>I've worked with nginx in different configurations and what I get most of the times is a feeling that the development of this web server is not performed according to protocol specifications but rather according what feature is needed as this specific point.</p> <p>For example, it was mentioned in nginx source code that "Apache' specific <code>PATH_INFO</code> feature was not implemented. While <code>PATH_INFO</code> is a standardized environment variable defined by CGI 1.1 specifications and is not some "web server specific feature"</p> <p>I know such <em>note</em> may look petty, but this is the general feeling of the level of implementation of many features.</p> <hr /> <p>So despite the popularity of this web server I would not choose it for serving dynamic content. If I need a high quality lightweight web server I'd always choose <a href="http://www.lighttpd.net/">Lighttpd</a></p> <ul> <li>It has a similar asynchronous design as nginx has.</li> <li>It is very well suited for dynamic content and supports CGI, HTTP, FastCGI and SCGI protocols. The development version supports Tomcat's AJP13 protocol as well.</li> <li>It is very well documented and has a rich set of modules.</li> </ul> <p><em>Before you jump and say:</em></p> <blockquote><p>Buy lighttpd leaks!</p></blockquote> <p>I'll answer: "<em>not true</em>, it does not leak". It is one of the well know urban legends on the Internet.</p> <p>Quoting:</p> <blockquote><p>there are no memory leaks just stupid ways to use lighttpd.</p> <p>e.g. it is really stupid to stream large files via a fastcgi app, when x-lighttpd-send-file could do a much more efficient job.</p></blockquote> <p>For further reading:</p> <ul> <li><a href="http://redmine.lighttpd.net/issues/758">http://redmine.lighttpd.net/issues/758</a></li> <li><a href="http://redmine.lighttpd.net/boards/2/topics/4009">http://redmine.lighttpd.net/boards/2/topics/4009</a></li> </ul> <p>So if you consider using Nginx on your web site, I'd strongly recommend to take a look on Lighttpd first.</p> </div> CppBlog and Wiki++ are officially released http://blog.cppcms.com/post/98 http://blog.cppcms.com/post/98 <div style="direction:ltr"> <p>I had released the cppblog and wikipp latest versions based on CppCMS 1.x.x. Latest versions can be downloaded from the <a href="https://sourceforge.net/projects/cppcms/files/">sourceforge</a>. They are available under GPLv3 license.</p> <p>The documentation on building these two web applications can be found there:</p> <ul> <li><a href="http://cppcms.com/wikipp/en/page/install_wikipp">Wiki++</a></li> <li><a href="http://cppcms.com/wikipp/en/page/install_cppblog">CppBlog</a></li> </ul> <p>If you are want to use one of these applications in your language you are welcome to get the pot files from these project translate them and submit them to me. I'll happily add them to the trunk.</p> </div> The project moved to the new web server and domain name http://blog.cppcms.com/post/97 http://blog.cppcms.com/post/97 <div style="direction:ltr"> <p>Please update your RSS feeds and bookmarks:</p> <ul> <li>Project's main web site: <a href="http://cppcms.com">http://cppcms.com</a></li> <li>Project's blog: <a href="http://blog.cppcms.com">http://blog.cppcms.com</a></li> <li>Project author's blog (Hebrew): <a href="http://artyom.cppcms.com">http://artyom.cppcms.com</a></li> </ul> <p>If you find any broken links, please report it to me.</p> </div> CppCMS Project Receives Donations... http://blog.cppcms.com/post/96 http://blog.cppcms.com/post/96 <div style="direction:ltr"> <p><span style="float:right; padding-left:20px"><a href="http://sourceforge.net/donate/index.php?group_id=209965"><img src="http://images.sourceforge.net/images/project-support.jpg" width="88" height="32" border="0" alt="Support This Project" /></a></span> CppCMS project receives monetary donations using sourceforge donation system.</p> <p>If you are using this project consider donating some money. Follow the donations button on the CppCMS projects <a href="http://cppcms.sourceforge.net/wikipp/en/page/main">web site</a> or the button in this post.</p> <p>The money would help to create a better product and provide better service to the CppCMS users community.</p> </div>