Support reference uri & fix gobs of C code

I swear, it feels like 3-4 different people wrote this code all with different degrees of understanding about C memory management, libxmlsec1, and the ruby C API.