Saturday, July 14, 2007

A Strong Handshake...

After many gruelling hours I've managed to put together reliable methods for decoding the contents of both the Server Handshake packets and Client Credentials packets. Due to the fact that both packet types contain variable length-strings representing details such as the server's version and the client's username (added to the fact that I want to use the MySQL C API) I had to stay away from c++ strings and remain in the realm of null-terminated C-strings. Of course, this meant I had to introduce measures for preventing memory leaks since we're talking about variable length (dynamic!) strings.

That was quite a headache given the amount of complex pointer-passing I'm doing, with segfaults rearing their heads left right and center along the way. However now that I've got some solid methods for decoding, creating and destroying these data types, I'm confident that subsequent work on decoding command and response packets will got far more smoothly!


We'll be having a conference call tomorrow and I hope that I'll have the command decoding methods completed before then so that I'll have a nice lump of progress to demonstrate :)

1 comment:

Jan said...

Why are you using nul-terminate strings for storing ? The handshake packet mix length encoded and nul-terminated. As the len-encoded ones may contain \0 just use len-encoded strings for both. In C-world there is GString in glib, in php there is the normal string-type and in C++ I assume the string-class does the trick.

Check the mysqlnd driver or mysql-proxy for a protocol dissector which handles all protocol phases and commands.