END_TEST

START_TEST (test_spdy_control_frame_parse)
{
	spdy_zlib_context zlib_ctx;
	spdy_control_frame frame;
	spdy_data data;
	int ret;

	spdy_zlib_inflate_init(&zlib_ctx);

	spdy_control_frame_init(&frame);
	ret = spdy_control_frame_parse(
			&frame,
			spdy_data_use(&data, test_control_syn_stream_frame, 296),
			&zlib_ctx);
	fail_unless(ret == SPDY_ERROR_NONE, "spdy_control_frame_parse failed.");
	fail_unless(data.cursor - data.data == 296, "data_used is incorrect.");
	fail_unless(frame.version == 2, "Version failed.");
	fail_unless(frame.type == SPDY_CTRL_SYN_STREAM, "Type failed.");
	fail_unless(frame.flags == 1, "Flag failed.");
	fail_unless(frame.length == 288, "Length failed.");
        spdy_control_frame_destroy(&frame);
        spdy_zlib_inflate_end(&zlib_ctx);
}
示例#2
0
END_TEST

START_TEST (test_spdy_syn_reply_parse)
{
	int ret;
	spdy_zlib_context zlib_ctx;
	spdy_syn_reply syn_reply;
	spdy_data data;
	ret = spdy_zlib_inflate_init(&zlib_ctx);
	fail_unless(ret == 0, "spdy_zlib_inflate_init failed.");
	ret = spdy_syn_reply_parse(
			&syn_reply,
			spdy_data_use(&data, test_control_syn_reply_frame+8, 55),
			55,
			&zlib_ctx);
	fail_unless(ret == 0, "spdy_syn_reply_parse failed.");
        spdy_syn_reply_destroy(&syn_reply);
        spdy_zlib_inflate_end(&zlib_ctx);
}
END_TEST

START_TEST (test_spdy_syn_stream_parse)
{
    int ret;
    spdy_zlib_context zlib_ctx;
    spdy_syn_stream syn_stream;
    spdy_data data;
    ret = spdy_zlib_inflate_init(&zlib_ctx);
    fail_unless(ret == 0, "spdy_zlib_inflate_init failed.");
    ret = spdy_syn_stream_parse(
              &syn_stream,
              spdy_data_use(&data, test_control_syn_stream_frame+8, 288),
              288,
              &zlib_ctx);
    fail_unless(ret == 0, "spdy_syn_stream_parse failed.");
    spdy_syn_stream_destroy(&syn_stream);
    spdy_zlib_inflate_end(&zlib_ctx);
}
示例#4
0
/*
 * Create a handle for a single duplex physical connection, SIDE is either
 * client or server - what side the handle is made to handle. PROTVER is the
 * specific SPDY protocol version.
 *
 * TODO: provide a means to replace the memory functions
 */
struct spindly_phys *spindly_phys_init(spindly_side_t side,
                                       spindly_spdyver_t protver,
                                       struct spindly_phys_config *config)
{
  struct spindly_phys *phys;
  int rc;
  struct spindly_outdata *od;

  /* this is the first malloc, it should use the malloc function provided in
     the config struct if set, but probably cannot use the MALLOC macro */
  phys = malloc(sizeof(struct spindly_phys));
  if(!phys)
    goto fail;
  phys->config = config;
  phys->side = side;
  phys->protver = protver;
  phys->num_streams = 0;
  phys->streamid = side == SPINDLY_SIDE_CLIENT?1:2;
  phys->outgoing = NULL;
  phys->outgoing_tosend = 0;

  /* create zlib contexts for incoming and outgoing data */
  rc = spdy_zlib_inflate_init(&phys->zlib_in);
  if(rc)
    goto fail;

  rc = spdy_zlib_inflate_init(&phys->zlib_out);
  if(rc)
    goto fail;

  _spindly_list_init(&phys->streams);
  _spindly_list_init(&phys->outq);
  _spindly_list_init(&phys->inq);
  _spindly_list_init(&phys->pendq);

  /* now add all outdata nodes to the pending queue */
  for(rc=0; rc < PHYS_NUM_OUTDATA; rc++) {
    od = CALLOC(phys, sizeof(struct spindly_outdata));
    if(!od)
      goto fail;

    _spindly_list_add(&phys->pendq, &od->node);
  }

  /* init receiver variables  */
  spdy_frame_init(&phys->frame);
  spdy_data_use(&phys->data, NULL, 0);

  /* for stream-ID to stream struct lookups */
  _spindly_hash_init(&phys->streamhash, phys);

  return phys;

fail:
  spdy_zlib_inflate_end(&phys->zlib_in);
  spdy_zlib_inflate_end(&phys->zlib_out);

  /* TODO: clean up the pendq list */

  if(phys)
    free(phys);

  return NULL;
}