-DEFUN ("gnutls-handshake", Fgnutls_handshake,
- Sgnutls_handshake, 1, 1, 0,
- doc: /* Perform GNU TLS handshake for PROCESS.
-The identity of the peer is checked automatically. This function will
-fail if any problem is encountered, and will return a negative error
-code. In case of a client, if it has been asked to resume a session,
-but the server didn't, then a full handshake will be performed.
-
-If the error `gnutls-e-not-ready-for-handshake' is returned, you
-didn't call `gnutls-boot' first.
-
-This function may also return the non-fatal errors `gnutls-e-again',
-or `gnutls-e-interrupted'. In that case you may resume the handshake
-(by calling this function again). */)
- (Lisp_Object proc)
-{
- gnutls_session_t state;
- int ret;
-
- CHECK_PROCESS (proc);
- state = XPROCESS (proc)->gnutls_state;
-
- if (GNUTLS_INITSTAGE (proc) < GNUTLS_STAGE_HANDSHAKE_CANDO)
- return Qgnutls_e_not_ready_for_handshake;
-
-
- if (GNUTLS_INITSTAGE (proc) < GNUTLS_STAGE_TRANSPORT_POINTERS_SET)
- {
- /* for a network process in Emacs infd and outfd are the same
- but this shows our intent more clearly. */
- message ("gnutls: handshake: setting the transport pointers to %d/%d",
- XPROCESS (proc)->infd, XPROCESS (proc)->outfd);
-
- /* FIXME: This can't be right: infd and outfd are integers (file handles)
- whereas the function expects args of type gnutls_transport_ptr_t. */
- gnutls_transport_set_ptr2 (state, XPROCESS (proc)->infd,
- XPROCESS (proc)->outfd);
-
- GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_TRANSPORT_POINTERS_SET;
- }
-
- ret = gnutls_handshake (state);
- GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_HANDSHAKE_TRIED;
-
- if (GNUTLS_E_SUCCESS == ret)
- {
- /* here we're finally done. */
- GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_READY;
- }
-
- return gnutls_make_error (ret);
-}
-