Merge pull request #1 from veox/forward-port

Forward port

Pull in changes in ckolivas/cgminer (up to commit 8fa5ddf, made on Wed Nov 13 11:57:29 2013 +0100).

This is still useful for all functionality not related to SHA256d/Scrypt mining. Obviously, ckolivas/cgminer developers are few bits more familiar with the code base.
Update authors.

Still pulling from ckolivas/cgminer, so note that.
core: Display difficulty in cgminer style, not true network difficulty (for consistency within the interface).

This regression was introduced by commit 3f6b9d679621bfd88ce1e435dc265fa0a4d78c79.
We can't connect to a GBT pool at all with fix protocol enabled.
api.c: Release io_data->ptr when releasing io_data in io_free()
api.c: Release apisock on error in api()
api.c trylock() add missing locklock
Provide a function for setting the work ntime.
Don't run device restart code if the device is not enabled.
Do not hold the mining thread lock in restart_threads when calling the driver flush work commands.
Set priority of various threads if possible.

Conflicts:
	cgminer.c
Prevent a deadlock with use of restart_threads by spawning a thread to send the driver flush work messages.

Conflicts:
	cgminer.c
Update api example compilation instructions.
line 2913 added urlencode

There was a cross site scripting vulnerability due to insufficient input sanitation on the $pg parameter.  This patch fixes that issue.
Decrement json references in api.c to not leak memory.

The json_val in api.c is a borrowed reference, not a new one so don't decref it.
Provide a function to discard queued work based on age. (NOTE: may be unused)
Silence irrelevant warning.
Drop json stratum auth failed message log level to verbose.
Initialise devices before attempting to connect to pools to allow their thread prepare function to be called before having to connect to pools.

Conflicts:
	cgminer.c
Fix json parsing in api.c