lunedì 22 ottobre 2007

RESTful Web Services - Bugfixing CurlPlugin

Before moving to today’s example, in which we’re going to start interacting with the Amazon S3 server, I’ll take a diversion to explain why all this lateness. As I wrote in the previous post, this example is so late because of a bug in CurlPlugin that I introduced myself.

The original CurlPlugin didn’t expose at the Smalltalk level the functionalities for setting custom HTTP headers in the request, so I had to add these functionalities to the plugin. When I did that, I overlooked the fact that a Smalltalk string and a C string aren’t implemented in the same way: a Smalltalk string, being a Collection subclass, has an arrayed collection of character elements (either 8-bit or 32-bit wide) and an explicit size attribute, while a C string is a NULL-termined array of char.

This means that since you can’t be sure of the fact that, in the internal representation of a Smalltalk string, the value after the last character of the string will be a NULL, you have to explicitly add one. Since I forgot to do so (by sending a simple #asCString message, provided by CurlPlugin), I introduced a tricky bug in the plugin. To make things worse, this bug showed itself only when the string was longer than usual. So, when adding to the request short headers such as Date: or Content-Type: there were no problems, while the Authorization: header always had some spurious trailing characters.

In order to detect this bug, I had to install a packet sniffer, learn how to use it, and look at what libCurl was actually sending to the server. As it often happens, once the problem was identified, fixing it was a matter of minutes.

Now that the bug is fixed, you’ll have to download the new version of the CurlPlugin. Extract the archive, overwrite the CurlPlugin file in your image directory, file in the new file, and you’ll be ready for the next example.

5 commenti:

Anonimo ha detto...

I am trying your example on both os x and ubuntu 7.10. I place the curlplugin in my image directory, filein the code and tr5y an example. I always get a primitive failure when doing pNewCurlHandle. I suspect there is more to the install. It appears I have libcurl 7.16.4 installed.

Anonimo ha detto...

OK, the linux version works after I moved to curlPlugin to the same folder as the squeak executable. The mac version worked when I moved the plugin to the MoacOS folder where it’s executable resides.I am using the seaside one-click experience setup.

Anonimo ha detto...

I’m stuck trying to get curlplugin to work with os x using the ppc. I assume it needs recompiling but I don’t see anything to compile.

Anonimo ha detto...

I am having trouble with the CurlPlugin. I downloaded the new version and did as directed in your last paragraph but it fails.

I get the following message: ‘a primitive has failed (invalid curl handle or parameter?)’

If you can offer help I would really appreciate it.


Anonimo ha detto...

I suspect that the CurlPlugin in the new version download is for Linux. If this is true, how does one get the Windows version of the CurlPlugin.dll?