Exemple #1
0
static void run_nghttp2_frame_pack_settings(void) {
  nghttp2_frame frame, oframe;
  nghttp2_bufs bufs;
  nghttp2_buf *buf;
  nghttp2_settings_entry iv[2], *iv_copy;
  int rv;

  rv = frame_pack_bufs_init(&bufs);

  if (rv != 0) {
    return;
  }

  iv[0].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE;
  iv[0].value = 4096;
  iv[1].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS;
  iv[1].value = 100;

  iv_copy = nghttp2_frame_iv_copy(iv, 2, nghttp2_mem_fm());

  if (iv_copy == NULL) {
    goto iv_copy_fail;
  }

  nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE, iv_copy, 2);

  rv = nghttp2_frame_pack_settings(&bufs, &frame.settings);

  if (rv != 0) {
    goto fail;
  }

  buf = &bufs.head->buf;

  rv = nghttp2_frame_unpack_settings_payload2(
      &oframe.settings.iv, &oframe.settings.niv, buf->pos + NGHTTP2_FRAME_HDLEN,
      nghttp2_buf_len(buf) - NGHTTP2_FRAME_HDLEN, nghttp2_mem_fm());

  if (rv != 0) {
    goto fail;
  }
  nghttp2_frame_settings_free(&oframe.settings, nghttp2_mem_fm());

fail:
  nghttp2_frame_settings_free(&frame.settings, nghttp2_mem_fm());
iv_copy_fail:
  nghttp2_bufs_free(&bufs);
}
Exemple #2
0
void test_nghttp2_frame_pack_settings()
{
  nghttp2_settings frame, oframe;
  nghttp2_bufs bufs;
  int i;
  int rv;
  nghttp2_settings_entry iv[] =
    {
      {
        NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 256
      },
      {
        NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE, 16384
      },
      {
        NGHTTP2_SETTINGS_HEADER_TABLE_SIZE, 4096
      }
    };

  frame_pack_bufs_init(&bufs);

  nghttp2_frame_settings_init(&frame, NGHTTP2_FLAG_NONE,
                              nghttp2_frame_iv_copy(iv, 3), 3);
  rv = nghttp2_frame_pack_settings(&bufs, &frame);

  CU_ASSERT(0 == rv);
  CU_ASSERT(NGHTTP2_FRAME_HDLEN + 3 * NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH ==
            nghttp2_bufs_len(&bufs));

  CU_ASSERT(0 == unpack_framebuf((nghttp2_frame*)&oframe, &bufs));
  check_frame_header(3 * NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH,
                     NGHTTP2_SETTINGS, NGHTTP2_FLAG_NONE, 0, &oframe.hd);
  CU_ASSERT(3 == oframe.niv);
  for(i = 0; i < 3; ++i) {
    CU_ASSERT(iv[i].settings_id == oframe.iv[i].settings_id);
    CU_ASSERT(iv[i].value == oframe.iv[i].value);
  }

  nghttp2_bufs_free(&bufs);
  nghttp2_frame_settings_free(&frame);
  nghttp2_frame_settings_free(&oframe);
}
Exemple #3
0
static void run_nghttp2_session_recv(void) {
  nghttp2_session *session;
  nghttp2_session_callbacks callbacks;
  nghttp2_hd_deflater deflater;
  nghttp2_frame frame;
  nghttp2_bufs bufs;
  nghttp2_nv nv[] = {MAKE_NV(":authority", "example.org"),
                     MAKE_NV(":scheme", "https")};
  nghttp2_settings_entry iv[2];
  my_user_data ud;
  data_feed df;
  int rv;
  nghttp2_nv *nva;
  size_t nvlen;

  rv = frame_pack_bufs_init(&bufs);

  if (rv != 0) {
    return;
  }

  memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
  callbacks.recv_callback = data_feed_recv_callback;
  ud.df = &df;

  nghttp2_failmalloc_pause();
  nvlen = ARRLEN(nv);
  nghttp2_nv_array_copy(&nva, nv, nvlen, nghttp2_mem_fm());
  nghttp2_hd_deflate_init(&deflater, nghttp2_mem_fm());
  nghttp2_session_server_new3(&session, &callbacks, &ud, NULL,
                              nghttp2_mem_fm());
  nghttp2_failmalloc_unpause();

  /* HEADERS */
  nghttp2_failmalloc_pause();
  nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_STREAM, 1,
                             NGHTTP2_HCAT_REQUEST, NULL, nva, nvlen);
  nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater);
  nghttp2_frame_headers_free(&frame.headers, nghttp2_mem_fm());
  data_feed_init(&df, &bufs);
  nghttp2_bufs_reset(&bufs);

  nghttp2_failmalloc_unpause();

  rv = nghttp2_session_recv(session);
  if (rv != 0) {
    goto fail;
  }

  /* PING */
  nghttp2_failmalloc_pause();
  nghttp2_frame_ping_init(&frame.ping, NGHTTP2_FLAG_NONE, NULL);
  nghttp2_frame_pack_ping(&bufs, &frame.ping);
  nghttp2_frame_ping_free(&frame.ping);
  data_feed_init(&df, &bufs);
  nghttp2_bufs_reset(&bufs);

  nghttp2_failmalloc_unpause();

  rv = nghttp2_session_recv(session);
  if (rv != 0) {
    goto fail;
  }

  /* RST_STREAM */
  nghttp2_failmalloc_pause();
  nghttp2_frame_rst_stream_init(&frame.rst_stream, 1, NGHTTP2_PROTOCOL_ERROR);
  nghttp2_frame_pack_rst_stream(&bufs, &frame.rst_stream);
  nghttp2_frame_rst_stream_free(&frame.rst_stream);
  nghttp2_bufs_reset(&bufs);

  nghttp2_failmalloc_unpause();

  rv = nghttp2_session_recv(session);
  if (rv != 0) {
    goto fail;
  }

  /* SETTINGS */
  nghttp2_failmalloc_pause();
  iv[0].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE;
  iv[0].value = 4096;
  iv[1].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS;
  iv[1].value = 100;
  nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE,
                              nghttp2_frame_iv_copy(iv, 2, nghttp2_mem_fm()),
                              2);
  nghttp2_frame_pack_settings(&bufs, &frame.settings);
  nghttp2_frame_settings_free(&frame.settings, nghttp2_mem_fm());
  nghttp2_bufs_reset(&bufs);

  nghttp2_failmalloc_unpause();

  rv = nghttp2_session_recv(session);
  if (rv != 0) {
    goto fail;
  }

fail:
  nghttp2_bufs_free(&bufs);
  nghttp2_session_del(session);
  nghttp2_hd_deflate_free(&deflater);
}