示例#1
0
static void
transform_destroy(TSCont contp)
{
  TransformData *data;

  data = TSContDataGet(contp);
  if (data != NULL) {
    if (data->input_buf) {
      TSIOBufferDestroy(data->input_buf);
    }

    if (data->output_buf) {
      TSIOBufferDestroy(data->output_buf);
    }

    if (data->pending_action) {
      TSActionCancel(data->pending_action);
    }

    if (data->server_vc) {
      TSVConnAbort(data->server_vc, 1);
    }

    TSfree(data);
  } else {
    TSError("[%s] Unable to get Continuation's Data. TSContDataGet returns NULL", PLUGIN_NAME);
  }

  TSContDestroy(contp);
}
示例#2
0
/*-------------------------------------------------------------------------
  cont_data_destroy
  Deallocate ContData structure associated to a transaction

  Input:
    data   structure to deallocate
  Output:
  Return Value:
    none
  -------------------------------------------------------------------------*/
static void
cont_data_destroy(ContData * data)
{
  TSDebug(DBG_TAG, "Destroying continuation data");
  if (data) {
    TSAssert(data->magic == MAGIC_ALIVE);
    if (data->output_reader) {
      TSIOBufferReaderFree(data->output_reader);
      data->output_reader = NULL;
    }
    if (data->output_buffer) {
      TSIOBufferDestroy(data->output_buffer);
      data->output_buffer = NULL;
    }
    if (data->psi_reader) {
      TSIOBufferReaderFree(data->psi_reader);
      data->psi_reader = NULL;
    }
    if (data->psi_buffer) {
      TSIOBufferDestroy(data->psi_buffer);
      data->psi_buffer = NULL;
    }
    data->magic = MAGIC_DEAD;
    TSfree(data);
  }
}
示例#3
0
文件: ironbee.c 项目: igalic/ironbee
static void ib_txn_ctx_destroy(ib_txn_ctx * data)
{
  if (data) {
    if (data->out.output_buffer) {
      TSIOBufferDestroy(data->out.output_buffer);
      data->out.output_buffer = NULL;
    }
    if (data->in.output_buffer) {
      TSIOBufferDestroy(data->in.output_buffer);
      data->in.output_buffer = NULL;
    }
    TSfree(data);
  }
}
示例#4
0
void
ts_http_fetcher_release(http_fetcher *fch)
{
    if (fch->http_vc) {
        TSVConnClose(fch->http_vc);
        fch->http_vc = NULL;
    }

    if (fch->http_parser)
        TSHttpParserDestroy(fch->http_parser);

    if (fch->hdr_loc) {
        TSMimeHdrDestroy(fch->hdr_bufp, fch->hdr_loc);
        TSHandleMLocRelease(fch->hdr_bufp, TS_NULL_MLOC, fch->hdr_loc);
    }

    if (fch->hdr_bufp)
        TSMBufferDestroy(fch->hdr_bufp);

    if (fch->hdr_reader)
        TSIOBufferReaderFree(fch->hdr_reader);
    if (fch->hdr_buffer)
        TSIOBufferDestroy(fch->hdr_buffer);

    if (fch->resp_reader)
        TSIOBufferReaderFree(fch->resp_reader);
    if (fch->resp_buffer)
        TSIOBufferDestroy(fch->resp_buffer);

    if (fch->body_reader)
        TSIOBufferReaderFree(fch->body_reader);
    if (fch->body_buffer)
        TSIOBufferDestroy(fch->body_buffer);

    if (fch->flow_reader)
        TSIOBufferReaderFree(fch->flow_reader);
    if (fch->flow_buffer)
        TSIOBufferDestroy(fch->flow_buffer);

    if (fch->req_reader)
        TSIOBufferReaderFree(fch->req_reader);
    if (fch->req_buffer)
        TSIOBufferDestroy(fch->req_buffer);

    TSContDestroy(fch->fetch_contp);

    TSfree(fch);
    fch = NULL;
}
示例#5
0
static int
transform_bypass(TSCont contp, TransformData *data)
{
  data->state = STATE_BYPASS;

  if (data->server_vc) {
    TSVConnAbort(data->server_vc, 1);
    data->server_vc  = NULL;
    data->server_vio = NULL;
  }

  if (data->output_buf) {
    TSIOBufferDestroy(data->output_buf);
    data->output_buf    = NULL;
    data->output_reader = NULL;
  }

  TSIOBufferReaderConsume(data->input_reader, sizeof(int));
  data->output_vc = TSTransformOutputVConnGet((TSVConn)contp);
  if (data->output_vc == NULL) {
    TSError("[%s] TSTransformOutputVConnGet returns NULL", PLUGIN_NAME);
  } else {
    data->output_vio = TSVConnWrite(data->output_vc, contp, data->input_reader, TSIOBufferReaderAvail(data->input_reader));
    if (data->output_vio == NULL) {
      TSError("[%s] TSVConnWrite returns NULL", PLUGIN_NAME);
    }
  }
  return 1;
}
static void stats_cleanup(TSCont contp, stats_state *my_state) {
	if (my_state->req_buffer) {
		TSIOBufferDestroy(my_state->req_buffer);
		my_state->req_buffer = NULL;
	}

	if (my_state->resp_buffer) {
		TSIOBufferDestroy(my_state->resp_buffer);
		my_state->resp_buffer = NULL;
	}

	TSVConnClose(my_state->net_vc);
	TSfree(my_state);
	my_state = NULL;
	TSContDestroy(contp);
}
static void
jcrusher_data_destroy(JCrusherData * data)
{
  TSDebug("jcrusher", "Start of jcrusher_data_destroy()");
  if (data) {
    if (data->downstream_buffer) {
      TSDebug("jcrusher", "jcrusher_data_destroy - destroying downstream buffer");
      TSIOBufferDestroy(data->downstream_buffer);
    }
    if (data->json_obj) {
      TSDebug("jcrusher", "jcrusher_data_destroy - destroying json object");
      json_object_put(data->json_obj);
      data->json_obj = NULL;
      TSDebug("jcrusher", "jcrusher_data_destroy - destroying json object -> done");
    }
    if (data->json_tok) {
      TSDebug("jcrusher", "jcrusher_data_destroy - destroying json tokener");
      json_tokener_free(data->json_tok);
      data->json_tok = NULL;
      TSDebug("jcrusher", "jcrusher_data_destroy - destroying json tokener -> done");
    }
    TSDebug("jcrusher", "jcrusher_data_destroy - Freeing data");
    TSfree(data);
    TSDebug("jcrusher", "jcrusher_data_destroy - Freeing data -> done");
  }
  TSDebug("jcrusher", "End of jcrusher_data_destroy()");
}
示例#8
0
static void
my_data_destroy(MyData *data)
{
  if (data) {
    if (data->output_buffer)
      TSIOBufferDestroy(data->output_buffer);
    TSfree(data);
  }
}
示例#9
0
static int
transform_connect(TSCont contp, TransformData *data)
{
  TSAction action;
  int content_length;
  struct sockaddr_in ip_addr;

  data->state = STATE_CONNECT;

  content_length = TSIOBufferReaderAvail(data->input_reader);
  if (content_length >= 0) {
    data->content_length = content_length;
    data->content_length = htonl(data->content_length);

    /* Prepend the content length to the buffer.
     * If we decide to not send the content to the transforming
     * server then we need to make sure and skip input_reader
     * over the content length.
     */

    {
      TSIOBuffer temp;
      TSIOBufferReader tempReader;

      temp       = TSIOBufferCreate();
      tempReader = TSIOBufferReaderAlloc(temp);

      TSIOBufferWrite(temp, (const char *)&content_length, sizeof(int));
      TSIOBufferCopy(temp, data->input_reader, content_length, 0);

      TSIOBufferReaderFree(data->input_reader);
      TSIOBufferDestroy(data->input_buf);
      data->input_buf    = temp;
      data->input_reader = tempReader;
    }
  } else {
    TSError("[%s] TSIOBufferReaderAvail returns TS_ERROR", PLUGIN_NAME);
    return 0;
  }

  /* TODO: This only supports IPv4, probably should be changed at some point, but
     it's an example ... */
  memset(&ip_addr, 0, sizeof(ip_addr));
  ip_addr.sin_family      = AF_INET;
  ip_addr.sin_addr.s_addr = server_ip; /* Should be in network byte order */
  ip_addr.sin_port        = server_port;
  TSDebug(PLUGIN_NAME, "net connect.");
  action = TSNetConnect(contp, (struct sockaddr const *)&ip_addr);

  if (!TSActionDone(action)) {
    data->pending_action = action;
  }

  return 0;
}
示例#10
0
static void
ts_chunked_destroy_transform_ctx(ts_chunked_transform_ctx *transform_ctx)
{
    if (!transform_ctx)
        return;

    if (transform_ctx->output_reader)
        TSIOBufferReaderFree(transform_ctx->output_reader);

    if (transform_ctx->output_buffer)
        TSIOBufferDestroy(transform_ctx->output_buffer);

    TSfree(transform_ctx);
}
示例#11
0
文件: ironbee.c 项目: igalic/ironbee
static void process_hdr(ib_txn_ctx *data, TSHttpTxn txnp,
                        ironbee_direction *ibd)
{
  ib_conndata_t icdata;
  int rv;
  TSMBuffer bufp;
  TSMLoc hdr_loc;
  TSIOBuffer iobufp;
  TSIOBufferReader readerp;
  TSIOBufferBlock blockp;
  int64_t len;

  TSDebug("ironbee", "process %s headers\n", ibd->word);

  icdata.ib = ironbee;
  icdata.mp = data->ssn->iconn->mp;
  icdata.conn = data->ssn->iconn;

  /* before the HTTP headers comes the request line / response code */
  rv = (*ibd->hdr_get)(txnp, &bufp, &hdr_loc);
  if (rv) {
    TSError ("couldn't retrieve %s header: %d\n", ibd->word, rv);
    return;
  }

  /* Get the data into an IOBuffer so we can access them! */
  //iobufp = TSIOBufferSizedCreate(...);
  iobufp = TSIOBufferCreate();
  TSHttpHdrPrint(bufp, hdr_loc, iobufp);

  readerp = TSIOBufferReaderAlloc(iobufp);
  blockp = TSIOBufferReaderStart(readerp);

  len = TSIOBufferBlockReadAvail(blockp, readerp);
  icdata.data = (void*)TSIOBufferBlockReadStart(blockp, readerp, &len);
  icdata.dlen = icdata.dalloc = len;

  (*ibd->ib_notify)(ironbee, &icdata);

  TSIOBufferDestroy(iobufp);
  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
}
示例#12
0
static int
transform_read(TSCont contp, TransformData *data)
{
  data->state = STATE_READ;

  TSIOBufferDestroy(data->input_buf);
  data->input_buf    = NULL;
  data->input_reader = NULL;

  data->server_vio = TSVConnRead(data->server_vc, contp, data->output_buf, data->content_length);
  data->output_vc  = TSTransformOutputVConnGet((TSVConn)contp);
  if (data->output_vc == NULL) {
    TSError("[%s] TSTransformOutputVConnGet returns NULL", PLUGIN_NAME);
  } else {
    data->output_vio = TSVConnWrite(data->output_vc, contp, data->output_reader, data->content_length);
    if (data->output_vio == NULL) {
      TSError("[%s] TSVConnWrite returns NULL", PLUGIN_NAME);
    }
  }

  return 0;
}
示例#13
0
static void
handle_dns(TSHttpTxn txnp, TSCont contp ATS_UNUSED)
{
  TSMBuffer bufp;
  TSMLoc hdr_loc;

  TSIOBuffer output_buffer;
  TSIOBufferReader reader;
  int total_avail;

  TSIOBufferBlock block;
  const char *block_start;
  int64_t block_avail;

  char *output_string;
  int64_t output_len;

  if (TSHttpTxnClientReqGet(txnp, &bufp, &hdr_loc) != TS_SUCCESS) {
    TSDebug(PLUGIN_NAME, "couldn't retrieve client request header");
    TSError("[%s] Couldn't retrieve client request header", PLUGIN_NAME);
    goto done;
  }

  output_buffer = TSIOBufferCreate();
  reader        = TSIOBufferReaderAlloc(output_buffer);

  /* This will print  just MIMEFields and not
     the http request line */
  TSDebug(PLUGIN_NAME, "Printing the hdrs ... ");
  TSMimeHdrPrint(bufp, hdr_loc, output_buffer);

  if (TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc) == TS_ERROR) {
    TSDebug(PLUGIN_NAME, "non-fatal: error releasing MLoc");
    TSError("[%s] non-fatal: Couldn't release MLoc", PLUGIN_NAME);
  }

  /* Find out how the big the complete header is by
     seeing the total bytes in the buffer.  We need to
     look at the buffer rather than the first block to
     see the size of the entire header */
  total_avail = TSIOBufferReaderAvail(reader);

  /* Allocate the string with an extra byte for the string
     terminator */
  output_string = (char *)TSmalloc(total_avail + 1);
  output_len    = 0;

  /* We need to loop over all the buffer blocks to make
     sure we get the complete header since the header can
     be in multiple blocks */
  block = TSIOBufferReaderStart(reader);
  while (block) {
    block_start = TSIOBufferBlockReadStart(block, reader, &block_avail);

    /* We'll get a block pointer back even if there is no data
       left to read so check for this condition and break out of
       the loop. A block with no data to read means we've exhausted
       buffer of data since if there was more data on a later
       block in the chain, this block would have been skipped over */
    if (block_avail == 0) {
      break;
    }

    memcpy(output_string + output_len, block_start, block_avail);
    output_len += block_avail;

    /* Consume the data so that we get to the next block */
    TSIOBufferReaderConsume(reader, block_avail);

    /* Get the next block now that we've consumed the
       data off the last block */
    block = TSIOBufferReaderStart(reader);
  }

  /* Terminate the string */
  output_string[output_len] = '\0';
  output_len++;

  /* Free up the TSIOBuffer that we used to print out the header */
  TSIOBufferReaderFree(reader);
  TSIOBufferDestroy(output_buffer);

  /* Although I'd never do this a production plugin, printf
     the header so that we can see it's all there */
  TSDebug(PLUGIN_NAME, "%s", output_string);

  TSfree(output_string);

done:
  TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
}