Clipboard, TS Gateway

Clipboard:
Add server callback interface
Fix empty format list handling
Complete server message parsing
Fix extra null character (linux and OS X)
Fix missing last character (OS X)

TS Gateway:
Fix thread shutdown, input freeze
Fix async input mode

There is still a possible locking issue with TS Gateway, but I believe this code should be better than the old one. Some stuff was horribly broken before. I'll take a closer look at TS Gateway soon enough.