+ return 0;
+}
+
+int cs_get_peer_certificate_x509(COMSTACK cs, char **buf, int *len)
+{
+
+#if HAVE_GNUTLS_H
+#if USE_GNUTLS_X509_CRT_PRINT
+ struct tcpip_state *sp = (struct tcpip_state *) cs->cprivate;
+ if (cs->type == ssl_type && sp->session)
+ {
+ const gnutls_datum_t *cert_list;
+ unsigned cert_list_size;
+ if (gnutls_certificate_type_get(sp->session) != GNUTLS_CRT_X509)
+ return 0;
+ cert_list = gnutls_certificate_get_peers(sp->session, &cert_list_size);
+ if (cert_list_size > 0)
+ {
+ gnutls_x509_crt_t cert;
+ int ret;
+ gnutls_datum_t cinfo;
+
+ gnutls_x509_crt_init(&cert);
+ gnutls_x509_crt_import(cert, &cert_list[0], GNUTLS_X509_FMT_DER);
+
+ ret = gnutls_x509_crt_print(cert, GNUTLS_CRT_PRINT_FULL, &cinfo);
+ if (ret == 0)
+ {
+ *buf = xstrdup((char *) cinfo.data);
+ *len = strlen(*buf);
+ gnutls_free(cinfo.data);
+ gnutls_x509_crt_deinit(cert);
+ return 1;
+ }
+ gnutls_x509_crt_deinit(cert);
+ }
+ }
+#endif
+#endif
+ return 0;
+}
+
+static int tcpip_put_connect(COMSTACK h, char *buf, int size)
+{
+ struct tcpip_state *state = (struct tcpip_state *)h->cprivate;
+
+ int r = tcpip_put(h, state->connect_request_buf,
+ state->connect_request_len);
+ if (r == 0)
+ {
+ /* it's sent */
+ h->f_put = tcpip_put; /* switch to normal tcpip put */
+ r = tcpip_put(h, buf, size);
+ }
+ return r;
+}
+
+static int tcpip_get_connect(COMSTACK h, char **buf, int *bufsize)
+{
+ struct tcpip_state *state = (struct tcpip_state *)h->cprivate;
+ int r;
+
+ r = tcpip_get(h, &state->connect_response_buf,
+ &state->connect_response_len);
+ if (r < 1)
+ return r;
+ /* got the connect response completely */
+ state->complete = cs_complete_auto; /* switch to normal tcpip get */
+ h->f_get = tcpip_get;
+ return tcpip_get(h, buf, bufsize);
+}
+
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+