Ejemplo n.º 1
0
/**
 * Pack the data frame into a buffer for transmitting.
 * @param out Target buffer
 * @param bufsize Size of the target buffer
 * @param outlen Length of the data written by this function
 * @param frame Frame to pack
 * @see spdy_data_frame
 * @return Errorcode
 */
int spdy_data_frame_pack_header(char *out, size_t bufsize,
                                size_t *outlen, spdy_data_frame *frame)
{
  if(bufsize < 8)
    return SPDY_ERROR_TOO_SMALL_BUFFER;

  BE_STORE_32(out, (frame->stream_id & 0x8FFFFFFF));
  out += 4;
  BE_STORE_32(out, frame->length);
  /* The flags are set after the length is written, because
   * otherwise the flags would get overwritten by the length. */
  out[0] = frame->flags;
  *outlen = 8;
  return SPDY_ERROR_NONE;
}
Ejemplo n.º 2
0
/*
 * Pack SYN_STREAM into an output buffer for transmitting.
 */
int spdy_syn_stream_pack(unsigned char *out, size_t bufsize,
                         size_t *outsize, spdy_syn_stream *str)
{
  char buf[2];
  size_t consumed;
  char *deflated;
  size_t deflated_length;
  int rc;

  if(bufsize < 10)
    return SPDY_ERROR_TOO_SMALL_BUFFER;
  BE_STORE_32(out, str->stream_id);
  out += 4;
  BE_STORE_32(out, str->associated_to);
  out += 4;
  BE_STORE_16(out, (str->priority << 14)); /* 14 bits unused */
  out += 2;

  /* create the NV block to include */
  BE_STORE_16(buf, 0); /* 16 bit NV pair counter */

  rc = spdy_zlib_deflate(buf, 2, &consumed, &deflated, &deflated_length);
  if(rc)
    return rc;

  if(bufsize < (10 + deflated_length)) {
    free(deflated);
    return SPDY_ERROR_TOO_SMALL_BUFFER;
  }

  memcpy(out, deflated, deflated_length);
  free(deflated);

  *outsize = 10 + deflated_length;
  return SPDY_ERROR_NONE;
}