Add call ERR_clear_error() before SSL_* calls

SSL_get_error function requires calling ERR_clear_error queue
before executing function which error code is to be determined.
Otherwise spurious error codes may be returned even for successful
operations.

http://www.openssl.org/docs/ssl/SSL_get_error.html

NOTE: This is a manual merge of https://github.com/losipiuk/stud/commit/f6dfcf83e6b544c28014ed7e63daa6d0c66a341b
Append CFLAGS/LDFLAGS to any flags already set, so custom builds with non-standard include paths can work.

NOTE: This is a manual merge of https://github.com/argv0/stud/commit/27de53bfc72065ec545c7ca698ca016fb89e4d50
support client certificate verification

NOTE: Manual patch of https://github.com/bumptech/stud/pull/103
Fix Client Mode memory Leak

NOTE: Manual patch of https://github.com/bumptech/stud/pull/107
Fix shctx memory leak

NOTE: Manual patch of https://github.com/bumptech/stud/pull/108