Smartcard fixes

Rewritten and unified functions for smartcard redirection.
Parsing is now more robust and errors are not crashing the application but generate debug messages.