parsing incoming extension data (both in the client and server).
The @funcintref{_foobar_send_params} function is responsible for
-sending extension data (both in the client and server).
+sending extension data (both in the client and server). It should
+append data to provided buffer and return a positive (or zero) number on
+success or a negative error code. Previous to 3.6.0 versions of GnuTLS required
+that function to return the number of bytes that were written. If zero
+is returned and no bytes are appended the extension will not be sent.
+If a zero byte extension is to be sent this function must return
+@code{GNUTLS_E_INT_RET_0}.
If you receive length fields that don't match, return
@code{GNUTLS_E_@-UNEXPECTED_@-PACKET_@-LENGTH}. If you receive invalid
int send_extension(gnutls_session_t session, const extension_entry_st *p,
gnutls_buffer_st *extdata, gnutls_ext_parse_type_t parse_type)
{
- int size_pos, size, ret;
+ int size_pos, appended, ret;
+ size_t size_prev;
if (p->send_func == NULL)
return 0;
if (ret < 0)
return gnutls_assert_val(ret);
- size = p->send_func(session, extdata);
+ size_prev = extdata->length;
+ ret = p->send_func(session, extdata);
+ if (ret < 0 && ret != GNUTLS_E_INT_RET_0) {
+ return gnutls_assert_val(ret);
+ }
+
/* returning GNUTLS_E_INT_RET_0 means to send an empty
* extension of this type.
*/
- if (size > 0 || size == GNUTLS_E_INT_RET_0) {
- if (size == GNUTLS_E_INT_RET_0)
- size = 0;
+ appended = extdata->length - size_prev;
+
+ if (appended > 0 || ret == GNUTLS_E_INT_RET_0) {
+ if (ret == GNUTLS_E_INT_RET_0)
+ appended = 0;
/* write the real size */
- _gnutls_write_uint16(size,
+ _gnutls_write_uint16(appended,
&extdata->data[size_pos]);
/* add this extension to the extension list
_gnutls_handshake_log
("EXT[%p]: Sending extension %s (%d bytes)\n",
- session, p->name, size);
- } else if (size < 0) {
- gnutls_assert();
- return size;
- } else if (size == 0)
+ session, p->name, appended);
+ } else if (appended == 0)
extdata->length -= 4; /* reset type and size */
return 0;
#define GNUTLS_E_UNIMPLEMENTED_FEATURE -1250
-
+/* Internal errors of the library; will never be returned
+ * to a calling application */
+#define GNUTLS_E_INT_RET_0 -1251
+#define GNUTLS_E_INT_CHECK_AGAIN -1252
#define GNUTLS_E_APPLICATION_ERROR_MAX -65000
#define GNUTLS_E_APPLICATION_ERROR_MIN -65500