Ejemplo n.º 1
0
int32_t interweb_ws_parse_frame_data(kr_web_client *client) {
  kr_websocket_client *ws;
  int32_t ret;
  int32_t pos;
  int32_t max;
  uint8_t output[4096];

  ws = &client->ws;
  ws->input_len = client->in->len;
  ws->input = client->in->rd_buf;

  if (ws->input_len < ws->len) {
    printk("Incomplete WS frame: %u / %"PRIu64"", ws->input_len,
     ws->len);
    return 0;
  }

  ws->output = output;
  ws->output_len = sizeof(output);

  pos = 0;

  if ((ws->len == 0) || (ws->pos == ws->len) || (ws->input_len == 0) ||
      (ws->output_len == 0)) {
    return 0;
  }

  max = MIN(MIN((ws->len - ws->pos), ws->input_len), ws->output_len);

  //printk ("max is %d", max);

  for (pos = 0; pos < max; pos++) {
    ws->output[pos] = ws->input[ws->pos] ^ ws->mask[ws->pos % 4];
    ws->pos++;
  }

  output[pos] = '\0';
  //printk("unmasked %d bytes %s", pos, (char *)output);

  ret = handle_json(client, (char *)output, pos);
  if (ret != 0) return -1;

  kr_io2_pulled (client->in, pos);

  if (ws->pos == ws->len) {
    ws->len = 0;
    ws->pos = 0;
  }

  return pos;
}
Ejemplo n.º 2
0
/**
 *  Ungets JSON formatted message to WebSocket.
 *  @param  msg JSON formatted message to be pushed back to receive
 *          message queue.
 */
void
ungetMessageWebsocket( std::string &msg )
{
    handle_json( msg );
}