split out main functions of mquery and mhttp

this way a shared library build can work