Tag: libcurl

Twitter Me Xerces!

Following from the spirit of yesterdays post, little victories…

Yesterday I managed to download the front page of my website using libcurl. As good as that was as a learning experience, it wasn’t interesting or useful in the slightest. Today however, I decided to see if I could fetch my status updates from Twitter and display them in a program. So I had a look at the API documentation and it looks quite easy to use, with the exception of OAuth which I’m yet to get my head around. Thankfully, for now, basic authentication is still supported.

The Twitter API uses the REST (REpresentational State Transfer) paradigm which means there’s no concept of a state on the server; i.e. each transaction is considered separately. It also means that it uses HTTP, which is pretty simple to understand. Basically in a REST protocol the URI’s are objects in the system, and the HTTP verbs are how you interact with them. So a GET on a http://server/article?name=REST object would download an article named REST. Simple eh? Check this article if you’re interested.

Anyway, onto the meat ‘n’ taters. Data in a REST transaction is typically stored as XML or JSON. I considered downloading LibYAML and taking the JSON route but a) I already had Xerces, b) I understand XML more than JSON, and c) I couldn’t be bothered to learn yet another new thing.

(continue reading…)


Bashing Windows

I seem to blog the most about needing to blog more often. Unfortunately for me, interesting things don’t happen often. So instead of waiting for something cool to happen, I’m just going to blog about the little things and hope for the best.

I drafted a post about my adventures with trying to compile some open source software, but it turned out far too long and it didn’t actually concentrate on the point I was trying to make. So instead I’ll jump right to it.

Yesterday I decided, randomly, to have a look at libcurl. It’s a surprisingly powerful library for C that supports a huge amount of internet protocols with only a few function calls. The code examples on the website made it look easy enough to use, so I thought I’d download it and see what I can do with it. Unfortunately compiling it myself turned out to be annoyingly difficult, so I just downloaded the binaries. Naturally these were all in MinGW form and I needed them them to be MSVC compatible.

After some googling I found that MinGW comes with a tool called pexports which dumps all the symbols of a DLL. So using that I wrote a Bash script that does this for all the DLLs in a directory:

for i in $( ls | grep ".*\.dll" | sed "s/.dll//" ); do
    pexports "$i.dll" > "$i.def"
    echo "lib /machine:i386 /def:$i.def" >> makelib.bat
done

This creates a .def file for each DLL which lists all the symbols that must be exported, and adds a line to makelib.bat which will create the MSVC import library. The two pronged approach is unfortunately necessary here because the Microsoft LIB tool won’t run through the Cygwin prompt.

The first line might seem complicated, but it’s not too bad. ls lists all the files in the current directory, grep then singles out all the .dll files, and finally sed removes the trailing .dll. In the loop itself $i will therefore always be of the form “<mydll>” instead of “<mydll>.dll“.

I’m no expert with Bash scripting so there’s probably an easier way to do it.


Archives

Categories

Recent Comments

Copyright © 2008-2010 Kier Dugan. All rights reserved.
Jarrah theme by Templates Next | Powered by WordPress