Monday, November 10, 2008

Is there anybody out there?

(Referring to The Wall, from pink Floyd...)

Anybody has ever read my (as for now) tiny blog? I am just wondering. No comments. And I could not figure out how to see any stats...

So if you did read, do read, please leave a comments. :)

And sorry for the need to log in, but I do not want bots to display millions of advertisements...

Sunday, April 13, 2008

CGI and HTTP user authentication

Another surprise (well documented, but unknown to me) is that when using HTTP authentication with CGI it is not the CGI script that does the authentication, but the server software itself. So unless you have set up your server with user names and passwords, your script will never get anything in the HTTP_REMOTE_USER variable. It will be called, but it won't receive the user ID as an indication of authentication failure.

See? Gee! Ayyyye...

For the last 24 hours I have been fighting with CGI. Installing the GNU cgicc library on both Mac OS X Leopard and Linux (openSuse). Well, it was an interesting endeavor. Let me bore you with the details.

First I have tried to build the library on the Mac side. I have used the latest version (at the time of writing), which is 3.2.5. I have downloaded the sources and run ./configure --prefix=${HOME}/local to try it out. Bang. Configure does not have a clue about the Mac: it tells me it has no idea what is the build platform. Oh why... After deleting some .in files and running autoreconf --install --force I was able to run configure to the end. Up to make I say! It goes on for a while, with weird compiler warnings about undefined (but used) inline functions (that I gracefully ignore; one shalt trust thy fellow programmers). Suddenly, at the point of linking, and I get a weird error about not being able to link @GNUCAP_LDFLAGS@...

Never give up, never surrender! Mac is not listed as officially supported platform, so I have turned to trusted Linux. After murmuring some friendly curses about the stability of VMWare Fusion, and restarting openSuse, I have gained access to my Midnight Commander and started the now-familiar routine of configuring the package... just to get the same weird error exactly the same time during make.

What shall one do in such a case? If in doubt, ask Google. So I did. The search for the error message brought up two unanswered questions on the cgicc mailing lists. Drat and double drat! So what the heck is GNUCAP anyways? Google to the rescue! It is a circuit designer software. Ahem... what???

After some thinking (yes, I do it sometimes) I have tried a simpler search on Google and this article turned up: Remove stray @GNUCAP_LDFLAGS@. Yippee! Or so I thought...

After removing the garbage from cgicc/Makefile.am I am able to go on with building a little longer, but then, another linker error. Actually a lot of them. Unresolved symbols. Fun, oh fun! How come?

Back to the drawing board: make clean; clear; make, then wait for the first warning and ctrl-C. OK. The same function is named in the "inline, used but not defined" warning as one of my unresolved externals. Nice. This is GNU code! From the GNU domain! Supposedly tested on platforms ranging from wristwatches to mainframes.

All right, I am supposedly a good C++ programmer, so how difficult it is for me to find an inline function that has no definition? Perhaps older compilers were more lenient in allowing the function to go undefined and use the "out of line" copy during linking? So the designers ignored the warnings, because they have got away with it?

So what was that function anyway... what file, what line number. Aha. It is an assignment operator of HTTPCookie. File is the header, line number is... whaddaheck??? The line number points to the following line:

class CGICC_API HTTPCookie : public MStreamable

Now that does not look like an assignment operator! Furthermore, the class definition does not declare an assignment operator at all! I must use my Vulcan/android logic:
  • There is no assignment operator declared
  • The warning message points to the class declarations first line
  • C++ implements the assignment operator for classes that do not declare one, if possible
  • The code assumes that there is an assignment operator, since the compiler says it is being used
  • So, according to the author's intent, the assignment operator must be generated, but it is not
The only reason in standard C++ for not generating such an operator is when a data member or a base class does not have one, thus preventing it from being assigned. I see "stream" in the name of the base class, I have insomnia, so my paranoia turns to the base class.

Compiling the base turns out the same warning, pointing to the class definitions' first line. No assignment operator is declared in the base class either. No more base classes. All data members can be assigned. Insomnia leads to paranoia: Apple has its own version of g++, perhaps it is broken? We have seen it happen with other distributions. And Apple favors Objective-C and "hates" C++, so this must be a conspiracy... It is time to have breakfast, time is passing 6:30am...

Finally, stumped, I read the web page (yes, I am a programmer, I read documentation only when all else fails) and it says: it was tested on Linux with 3.3 gcc. Aha, this Mac has 4.x. So does the Linux, which has the same problem. (I was going back and forth).

So, "select is not broken", Apple is not evil, but the code is broken. But how and why? What do I know already?
  • The assignment operator definition is not generated, but a declaration for the inline function is generated! That is weird and unexpected. What could make a compiler to do that?
  • The original code is written for gcc 3.3, and beginning with 3.4 the hard working people of the gcc community have rewritten the C++ compiler front-end (as far as I understood it) twice.
  • OK. So something tells g++ not to generate the inline function definition, only the declaration. That something is most probably g++ specific and has changed its meaning during the rewrite.
  • According to my understanding of the way compilers work, that something should be located in the lines of the source code that precedes the class declaration or passed to the compiler as a command line option.
As a first step, I have examined the command line options, since they were still sitting in the terminals scrollback buffer. None of the command line options had anything to do with code generation of inline functions. A careful look at the source code revealed the use of two gcc specific pragmas, #pragma interface in the headers and #pragma implementation in the .cpp files. After removing those lines from the files the warnings disappeared and so did the linker errors. Finally, I had a working cgicc library to experiment with.

I am sorry to say, I have no clue why those pragmas failed. I have decided to drop further investigation, since the gcc documentation page I have found stated that after gcc 2.7 (if I recall correctly) they have no (good) effect for production code. Perhaps, gcc was unable to match up the implementation and the header files, and so it did not emit the object code for the inline functions into the .cpp files? Not all the headers and .cpp files had these pragmas, which, again may be a problem. But after all the struggle (I have also installed application etc.) I have lost my motive to investigate it any further for the time being.

Saturday, April 12, 2008

Blocked for good

It seems that I cannot see/read my own blogs as it really looks for readers. The blogspot.com and all its subdomains seem to be blocked here. I have no idea why. This blocking seems weird. Some sites simply time out (such as blogspot), while others are definitely blocked by a fake TCP close message. According to some people living here for longer time, and having more internet technical knowledge than I do, the sites that time out seem to disappear in an Internet black hole. Now this may prove the existence of the Great Firewall, however there is a fly in the ointment: the black hole appears to be in South Korea! I have not checked that with blogspot, but a friend has checked it with Wikipedia.

Speaking of Wikipedia: the English version has been available for access for few days now. I have also heard that BBC has been accessible from normal internet connections all over China.

There are facts that seem to suggest there is an intelligence working behind these "blackouts". Try to read the English Wikipedia, and it may work. It works for me now. Try the main page, and even that works. However, if you try to click on the Chinese language link on the main page, you will get blocked. Try the zh.wikpedia.org, and you get blocked. Then try the English Wikipedia again and, TADA, it is blocked now! And it will remain blocked for quite some time. It seems that your IP address is registered as "someone looking for forbidden material" and so your options for choice are severely limited. Same thing happens in Google Picture search, which is quite annoying when you are looking for free images that you could use in a sideshow.

I fail to see the purpose of these blockings (if they are blockings after all). People of China travel all over the world, they meet "outsiders" frequently, as a result of the economic boom and the stronger relationships it brings. There are many companies operating here in Shanghai, Ericsson is one of them with many foreigners employed locally, also GM, Volkswagen etc. So people here are in contact with them, and the "foreign" ideas and behavior they may represent.

Many Chinese people do not speak or read good enough English to understand the sites that do not show up. There are sites that are blocked which can hardly be justified, since they contain no content political in nature.

These problems of accessing web content hinder the ability of the Chinese people to learn all that is there to learn (like technical information), so in my humble opinion it hurts more than helps. I have found that people in China are happy. Happy. And they love their country. So I fail to see any danger in letting them to see the world. In fact, I think that by not being able to see the what the world thinks or speak of China these people lack the opportunity (and therefore China lacks the opportunity) to react to those view and explain the Chinese viewpoint. Not as an the official statement, but - like it is so common now on the Internet - as the voice of the people. And that could and would be a powerful statement: when the Chinese people explain their way and their feelings and why they are happy and why they love their country so much.

China is another world. And so it will remain, independent of what its people can access on the internet. Just as Japan remained Japan, India remained India. But the rest of the world misses out greatly on the opportunity to listen to and to understand the people of China, its several millenia of culture and the healthy diversity its influence could inflict upon our view of humanity. And I do believe that this world that exists in China, and its people have a lot to offer.

Perhaps the most said result of the difficulties of accessing certain parts of the internet from China is that "outsiders" can chose to see it as a sign of weakness. It may be (mis?)interpreted as if the people of China would think or behave differently have they had access to those information. I beg to differ. I have found Chinese people not only to love their country, but they are also pragmatic and very patient. They know about the issues the fast growing China faces. They are aware of the negative views. And yet, they stand firm in their love and patience towards their community.


Well, of course these are only my naive thoughts, based on a limited exposure to this "other world". There may be motivations or cultural differences that I fail to see. China is its own world, and it has been that for millenia. Opening up to accept other cultures, viewpoints and sets of values is just as hard for these billions of people as it is proven to be hard for many other civilizations to recognize the values of other cultures.

It is interesting to watch Star Trek here, in Shanghai, and see how much of these misconceptions, preconceptions, misunderstandings and stirred emotions show up when two civilizations meet. And how it tests their abilities to understand that why the differences may be fundamental, they can and are to be learning from each other. And the toughest "test" of all: to realize that when two civilizations/cultures differ in their axioms, unproven fundamental beliefs (we believe it to be true) there is no way to prove which belief is the "true one". And to understand that as we had a choice to believe in our axioms, so do others.

Shanghaid

My life has taken me again to Shanghai, the second time, for an additional 6 months of labor. It is a labor of love, as I am here to care for our late products from Finland, as well as the people who have the job now to keep them alive and well... and profitable.

At the same time I am not alive and well. For some reason unknown to me (yet) I am experiencing a kind of cold and fatigue. Just like last year, when I was here. My plan is to visit a doctor Monday morning, allowing a chance to get a full checkup (including blood-work) and hopefully to pinpoint a reason for my unfortunate condition.

I am spending my spare time watching the Star Trek series; right now the "original". I have managed to buy here all the series on DVD, in very nice boxes. Unfortunately one of them has been "infected" by some sort of fungi . I don't know if I should bring it back to the shop for a replacement, or if I should take it to the doctor n Monday to check if it has anything to do with my symptoms. Well, I will figure it out.

It is interesting to see all these films in close succession. One can see how ideas and images from the first series show up later in Next Generation and Enterprise.

I hope once I get a bit better and start to perform again, I will be able to posts some pictures and videos of the city and the people here. And the unimaginably crazy traffic of cars, trucks, bicycles, pedestrians and so forth pushing to get their way, blissfully ignoring traffic rules and traffic lights. I will be telling about this later, since it is worth of their own post. :)