I've reworked this patch to: * Not use nested functions * Fix indentation * Use -1/0 instead of 0/1 for return values * Make the diff a little nicer by moving things around make check passes with the exception of test_upload and test_download. I've confirmed that these also fail without this patch (RHBZ#515764).