|
The client had built the target hardware. It was our task to implement the software. Our target platform was SigmaDesign's em8561 (ARM) architecture, 4MB of onboard flash and uClinux. So code space was a premium.
The XML implementation was a simple once I had found the TinyXML library (http://www.grinninglizard.com/tinyxml). However, the HTTP client library ended up being a little more problematic than anticipated. I had researched libwww and libcurl. libcurl would compile but provided some fun segmentation faults that I was not interested in debugging. libcurl’s event handling mechanism seemed too pervasive to provide a simple blocking HTTP GET call. After linking with either library, the program file ended 200KB+ fatter. These options were not going to work.
After some thought, the solution was simpler than expected. After a few moments designing the components to build the custom functionality, the resulting code was fairly brief and clean. All that was needed was a sockets class, string class, string splitter class, URL class and the final HttpGet function.
I found a simple Sockets class (PracticalSockets @ http://cs.ecs.baylor.edu/~donahoo/practical/CSocke ts/practical). It is an elegant implementation, BUT it also uses STL. There nothing wrong with STL, but I need to reduce code where ever possible - So I have included a version that I have modified to use a custom lightweight String class. The Splitter class is used for parsing URLs strings and HTTP header data. The URL class is the container for the URL tokens. The HttpGet(char *url, char *file) function is a high level function to download the specified “char *url” to the “char *file”.
Full source @ HttpGet.zip,
Enjoy
|