本文整理汇总了C++中CTXFREE函数的典型用法代码示例。如果您正苦于以下问题:C++ CTXFREE函数的具体用法?C++ CTXFREE怎么用?C++ CTXFREE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CTXFREE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lwres_gabnresponse_free
/*% Release the memory in resolver context ctx that was allocated to the lwres_gabnresponse_t. */
void
lwres_gabnresponse_free(lwres_context_t *ctx, lwres_gabnresponse_t **structp)
{
lwres_gabnresponse_t *gabn;
lwres_addr_t *addr;
REQUIRE(ctx != NULL);
REQUIRE(structp != NULL && *structp != NULL);
gabn = *structp;
*structp = NULL;
if (gabn->naliases > 0) {
CTXFREE(gabn->aliases, sizeof(char *) * gabn->naliases);
CTXFREE(gabn->aliaslen,
sizeof(lwres_uint16_t) * gabn->naliases);
}
addr = LWRES_LIST_HEAD(gabn->addrs);
while (addr != NULL) {
LWRES_LIST_UNLINK(gabn->addrs, addr, link);
CTXFREE(addr, sizeof(lwres_addr_t));
addr = LWRES_LIST_HEAD(gabn->addrs);
}
if (gabn->base != NULL)
CTXFREE(gabn->base, gabn->baselen);
CTXFREE(gabn, sizeof(lwres_gabnresponse_t));
}
示例2: lwres_conf_parsesearch
static lwres_result_t
lwres_conf_parsesearch(lwres_context_t *ctx, FILE *fp) {
int idx, delim;
char word[LWRES_CONFMAXLINELEN];
lwres_conf_t *confdata;
confdata = &ctx->confdata;
if (confdata->domainname != NULL) {
/*
* Search and domain are mutually exclusive.
*/
CTXFREE(confdata->domainname,
strlen(confdata->domainname) + 1);
confdata->domainname = NULL;
}
/*
* Remove any previous search definitions.
*/
for (idx = 0; idx < LWRES_CONFMAXSEARCH; idx++) {
if (confdata->search[idx] != NULL) {
CTXFREE(confdata->search[idx],
strlen(confdata->search[idx])+1);
confdata->search[idx] = NULL;
}
}
confdata->searchnxt = 0;
delim = getword(fp, word, sizeof(word));
if (strlen(word) == 0U)
return (LWRES_R_FAILURE); /* Nothing else on line. */
idx = 0;
while (strlen(word) > 0U) {
if (confdata->searchnxt == LWRES_CONFMAXSEARCH)
goto ignore; /* Too many domains. */
confdata->search[idx] = lwres_strdup(ctx, word);
if (confdata->search[idx] == NULL)
return (LWRES_R_FAILURE);
idx++;
confdata->searchnxt++;
ignore:
if (delim == EOF || delim == '\n')
break;
else
delim = getword(fp, word, sizeof(word));
}
return (LWRES_R_SUCCESS);
}
示例3: lwres_context_freemem
/*% Frees len bytes of space starting at location mem. */
void
lwres_context_freemem(lwres_context_t *ctx, void *mem, size_t len) {
REQUIRE(mem != NULL);
REQUIRE(len != 0U);
CTXFREE(mem, len);
}
示例4: lwres_gnbarequest_render
/*% Uses resolver context ctx to convert getnamebyaddr request structure req to canonical format. */
lwres_result_t
lwres_gnbarequest_render (lwres_context_t * ctx, lwres_gnbarequest_t * req, lwres_lwpacket_t * pkt, lwres_buffer_t * b)
{
unsigned char *buf;
size_t buflen;
int ret;
size_t payload_length;
REQUIRE (ctx != NULL);
REQUIRE (req != NULL);
REQUIRE (req->addr.family != 0);
REQUIRE (req->addr.length != 0);
REQUIRE (pkt != NULL);
REQUIRE (b != NULL);
payload_length = 4 + 4 + 2 + +req->addr.length;
buflen = LWRES_LWPACKET_LENGTH + payload_length;
buf = CTXMALLOC (buflen);
if (buf == NULL)
return (LWRES_R_NOMEMORY);
lwres_buffer_init (b, buf, buflen);
pkt->length = buflen;
pkt->version = LWRES_LWPACKETVERSION_0;
pkt->pktflags &= ~LWRES_LWPACKETFLAG_RESPONSE;
pkt->opcode = LWRES_OPCODE_GETNAMEBYADDR;
pkt->result = 0;
pkt->authtype = 0;
pkt->authlength = 0;
ret = lwres_lwpacket_renderheader (b, pkt);
if (ret != LWRES_R_SUCCESS)
{
lwres_buffer_invalidate (b);
CTXFREE (buf, buflen);
return (ret);
}
INSIST (SPACE_OK (b, payload_length));
/*
* Put the length and the data. We know this will fit because we
* just checked for it.
*/
lwres_buffer_putuint32 (b, req->flags);
lwres_buffer_putuint32 (b, req->addr.family);
lwres_buffer_putuint16 (b, req->addr.length);
lwres_buffer_putmem (b, (unsigned char *) req->addr.address, req->addr.length);
INSIST (LWRES_BUFFER_AVAILABLECOUNT (b) == 0);
return (LWRES_R_SUCCESS);
}
示例5: lwres_gnbaresponse_free
/*% Release the memory in resolver context ctx that was allocated to the lwres_gnbaresponse_t. */
void lwres_gnbaresponse_free (lwres_context_t * ctx, lwres_gnbaresponse_t ** structp)
{
lwres_gnbaresponse_t *gnba;
REQUIRE (ctx != NULL);
REQUIRE (structp != NULL && *structp != NULL);
gnba = *structp;
*structp = NULL;
if (gnba->naliases > 0)
{
CTXFREE (gnba->aliases, sizeof (char *) * gnba->naliases);
CTXFREE (gnba->aliaslen, sizeof (lwres_uint16_t) * gnba->naliases);
}
if (gnba->base != NULL)
CTXFREE (gnba->base, gnba->baselen);
CTXFREE (gnba, sizeof (lwres_gnbaresponse_t));
}
示例6: lwres_conf_clear
/*% Frees up all the internal memory used by the config data structure, returning it to the lwres_context_t. */
void
lwres_conf_clear(lwres_context_t *ctx) {
int i;
lwres_conf_t *confdata;
REQUIRE(ctx != NULL);
confdata = &ctx->confdata;
for (i = 0; i < confdata->nsnext; i++) {
lwres_resetaddr(&confdata->nameservers[i]);
confdata->nameserverports[i] = 0;
}
if (confdata->domainname != NULL) {
CTXFREE(confdata->domainname,
strlen(confdata->domainname) + 1);
confdata->domainname = NULL;
}
for (i = 0; i < confdata->searchnxt; i++) {
if (confdata->search[i] != NULL) {
CTXFREE(confdata->search[i],
strlen(confdata->search[i]) + 1);
confdata->search[i] = NULL;
}
}
for (i = 0; i < LWRES_CONFMAXSORTLIST; i++) {
lwres_resetaddr(&confdata->sortlist[i].addr);
lwres_resetaddr(&confdata->sortlist[i].mask);
}
confdata->nsnext = 0;
confdata->lwnext = 0;
confdata->domainname = NULL;
confdata->searchnxt = 0;
confdata->sortlistnxt = 0;
confdata->resdebug = 0;
confdata->ndots = 1;
confdata->no_tld_query = 0;
}
示例7: updateWorkunit
static IWorkUnit * updateWorkunit(ICodeContext * ctx)
{
// following bit of a kludge, as
// 1) eclagent keeps WU locked, and
// 2) rtti not available in generated .so's to convert to IAgentContext
IAgentContext * actx = dynamic_cast<IAgentContext *>(ctx);
if (actx == NULL) { // fall back to pure ICodeContext
// the following works for thor only
char * platform = ctx->getPlatform();
if (strcmp(platform,"thor")==0) {
CTXFREE(parentCtx, platform);
Owned<IWorkUnitFactory> factory = getWorkUnitFactory();
StringAttr wuid;
wuid.setown(ctx->getWuid());
return factory->updateWorkUnit(wuid);
}
CTXFREE(parentCtx, platform);
return NULL;
}
return actx->updateWorkUnit();
}
示例8: lwres_gnbarequest_free
/*% Release the memory in resolver context ctx that was allocated to the lwres_gnbarequest_t. */
void lwres_gnbarequest_free (lwres_context_t * ctx, lwres_gnbarequest_t ** structp)
{
lwres_gnbarequest_t *gnba;
REQUIRE (ctx != NULL);
REQUIRE (structp != NULL && *structp != NULL);
gnba = *structp;
*structp = NULL;
CTXFREE (gnba, sizeof (lwres_gnbarequest_t));
}
示例9: lwres_conf_parsedomain
static lwres_result_t
lwres_conf_parsedomain(lwres_context_t *ctx, FILE *fp) {
char word[LWRES_CONFMAXLINELEN];
int res, i;
lwres_conf_t *confdata;
confdata = &ctx->confdata;
res = getword(fp, word, sizeof(word));
if (strlen(word) == 0U)
return (LWRES_R_FAILURE); /* Nothing else on line. */
else if (res == ' ' || res == '\t')
res = eatwhite(fp);
if (res != EOF && res != '\n')
return (LWRES_R_FAILURE); /* Extra junk on line. */
if (confdata->domainname != NULL)
CTXFREE(confdata->domainname,
strlen(confdata->domainname) + 1); /* */
/*
* Search and domain are mutually exclusive.
*/
for (i = 0; i < LWRES_CONFMAXSEARCH; i++) {
if (confdata->search[i] != NULL) {
CTXFREE(confdata->search[i],
strlen(confdata->search[i])+1);
confdata->search[i] = NULL;
}
}
confdata->searchnxt = 0;
confdata->domainname = lwres_strdup(ctx, word);
if (confdata->domainname == NULL)
return (LWRES_R_FAILURE);
return (LWRES_R_SUCCESS);
}
示例10: lwres_nooprequest_free
/*% Release the memory in resolver context ctx. */
void
lwres_nooprequest_free(lwres_context_t *ctx, lwres_nooprequest_t **structp)
{
lwres_nooprequest_t *noop;
REQUIRE(ctx != NULL);
REQUIRE(structp != NULL && *structp != NULL);
noop = *structp;
*structp = NULL;
CTXFREE(noop, sizeof(lwres_nooprequest_t));
}
示例11: lwres_noopresponse_render
lwres_result_t
lwres_noopresponse_render(lwres_context_t *ctx, lwres_noopresponse_t *req,
lwres_lwpacket_t *pkt, lwres_buffer_t *b)
{
unsigned char *buf;
size_t buflen;
int ret;
size_t payload_length;
REQUIRE(ctx != NULL);
REQUIRE(req != NULL);
REQUIRE(pkt != NULL);
REQUIRE(b != NULL);
payload_length = sizeof(lwres_uint16_t) + req->datalength;
buflen = LWRES_LWPACKET_LENGTH + payload_length;
buf = CTXMALLOC(buflen);
if (buf == NULL)
return (LWRES_R_NOMEMORY);
lwres_buffer_init(b, buf, (unsigned int)buflen);
pkt->length = (lwres_uint32_t)buflen;
pkt->version = LWRES_LWPACKETVERSION_0;
pkt->pktflags |= LWRES_LWPACKETFLAG_RESPONSE;
pkt->opcode = LWRES_OPCODE_NOOP;
pkt->authtype = 0;
pkt->authlength = 0;
ret = lwres_lwpacket_renderheader(b, pkt);
if (ret != LWRES_R_SUCCESS) {
lwres_buffer_invalidate(b);
CTXFREE(buf, buflen);
return (ret);
}
INSIST(SPACE_OK(b, payload_length));
/*
* Put the length and the data. We know this will fit because we
* just checked for it.
*/
lwres_buffer_putuint16(b, req->datalength);
lwres_buffer_putmem(b, req->data, req->datalength);
INSIST(LWRES_BUFFER_AVAILABLECOUNT(b) == 0);
return (LWRES_R_SUCCESS);
}
示例12: lwres_noopresponse_parse
/*% Offers the same semantics as lwres_nooprequest_parse() except it yields a lwres_noopresponse_t structure. */
lwres_result_t
lwres_noopresponse_parse(lwres_context_t *ctx, lwres_buffer_t *b,
lwres_lwpacket_t *pkt, lwres_noopresponse_t **structp)
{
int ret;
lwres_noopresponse_t *req;
REQUIRE(ctx != NULL);
REQUIRE(b != NULL);
REQUIRE(pkt != NULL);
REQUIRE(structp != NULL && *structp == NULL);
if ((pkt->pktflags & LWRES_LWPACKETFLAG_RESPONSE) == 0)
return (LWRES_R_FAILURE);
req = CTXMALLOC(sizeof(lwres_noopresponse_t));
if (req == NULL)
return (LWRES_R_NOMEMORY);
if (!SPACE_REMAINING(b, sizeof(lwres_uint16_t))) {
ret = LWRES_R_UNEXPECTEDEND;
goto out;
}
req->datalength = lwres_buffer_getuint16(b);
if (!SPACE_REMAINING(b, req->datalength)) {
ret = LWRES_R_UNEXPECTEDEND;
goto out;
}
req->data = b->base + b->current;
lwres_buffer_forward(b, req->datalength);
if (LWRES_BUFFER_REMAINING(b) != 0) {
ret = LWRES_R_TRAILINGDATA;
goto out;
}
/* success! */
*structp = req;
return (LWRES_R_SUCCESS);
/* Error return */
out:
CTXFREE(req, sizeof(lwres_noopresponse_t));
return (ret);
}
示例13: lwres_context_destroy
/*%
Destroys a #lwres_context_t, closing its socket.
contextp is a pointer to a pointer to the context that is
to be destroyed. The pointer will be set to NULL
when the context has been destroyed.
*/
void
lwres_context_destroy(lwres_context_t **contextp) {
lwres_context_t *ctx;
REQUIRE(contextp != NULL && *contextp != NULL);
ctx = *contextp;
*contextp = NULL;
if (ctx->sock != -1) {
#ifdef WIN32
DestroySockets();
#endif
(void)close(ctx->sock);
ctx->sock = -1;
}
CTXFREE(ctx, sizeof(lwres_context_t));
}
示例14: lwres_getrrsetbyname_read
int
lwres_getrrsetbyname_read(struct lwres_async_state **plas,
lwres_context_t *ctx,
struct rrsetinfo **res)
{
lwres_result_t lwresult;
lwres_grbnresponse_t *response = NULL;
char *buffer;
struct rrsetinfo *rrset = NULL;
int recvlen;
int ret, result;
unsigned int i;
lwres_buffer_t b_in;
struct lwres_async_state *las;
struct lwres_async_state **las_prev;
lwres_lwpacket_t pkt;
buffer = NULL;
buffer = CTXMALLOC(LWRES_RECVLENGTH);
if (buffer == NULL) {
return ERRSET_NOMEMORY;
}
ret = LWRES_R_SUCCESS;
lwresult = lwres_context_recv(ctx, buffer, LWRES_RECVLENGTH, &recvlen);
if (lwresult == LWRES_R_RETRY) {
ret = LWRES_R_RETRY;
goto out;
}
if (ret != LWRES_R_SUCCESS)
goto out;
lwres_buffer_init(&b_in, buffer, recvlen);
b_in.used = recvlen;
/*
* Parse the packet header.
*/
ret = lwres_lwpacket_parseheader(&b_in, &pkt);
if (ret != LWRES_R_SUCCESS)
goto out;
/*
* find an appropriate waiting las entry. This is a linear search.
* we can do MUCH better, since we control the serial number!
* do that later.
*/
las_prev = &ctx->pending;
las = ctx->pending;
while(las && las->serial != pkt.serial) {
las_prev=&las->next;
las=las->next;
}
if(las == NULL) {
/* no matching serial number! */
return(LWRES_R_RETRY);
}
/* okay, remove it from the receive queue */
*las_prev = las->next;
las->next = NULL;
las->inqueue = 0;
*plas = las;
/*
* Free what we've transmitted, long ago.
*/
CTXFREE(las->b_out.base, las->b_out.length);
las->b_out.base = NULL;
las->b_out.length = 0;
if (pkt.result != LWRES_R_SUCCESS) {
ret = pkt.result;
goto out;
}
/*
* Parse the response.
*/
ret = lwres_grbnresponse_parse(ctx, &b_in, &pkt, &response);
if (ret != LWRES_R_SUCCESS) {
out:
if (buffer != NULL)
CTXFREE(buffer, LWRES_RECVLENGTH);
if (response != NULL)
lwres_grbnresponse_free(ctx, &response);
result = lwresult_to_result(ret);
goto fail;
}
response->base = buffer;
response->baselen = LWRES_RECVLENGTH;
buffer = NULL; /* don't free this below */
lwresult = LWRES_R_SUCCESS;
rrset = sane_malloc(sizeof(struct rrsetinfo));
//.........这里部分代码省略.........
示例15: lwres_gabnresponse_render
/*% converts a getaddrbyname response structure lwres_gabnresponse_t to the lightweight resolver's canonical format. */
lwres_result_t
lwres_gabnresponse_render(lwres_context_t *ctx, lwres_gabnresponse_t *req,
lwres_lwpacket_t *pkt, lwres_buffer_t *b)
{
unsigned char *buf;
size_t buflen;
int ret;
size_t payload_length;
lwres_uint16_t datalen;
lwres_addr_t *addr;
int x;
REQUIRE(ctx != NULL);
REQUIRE(req != NULL);
REQUIRE(pkt != NULL);
REQUIRE(b != NULL);
/* naliases, naddrs */
payload_length = 4 + 2 + 2;
/* real name encoding */
payload_length += 2 + req->realnamelen + 1;
/* each alias */
for (x = 0; x < req->naliases; x++)
payload_length += 2 + req->aliaslen[x] + 1;
/* each address */
x = 0;
addr = LWRES_LIST_HEAD(req->addrs);
while (addr != NULL) {
payload_length += 4 + 2;
payload_length += addr->length;
addr = LWRES_LIST_NEXT(addr, link);
x++;
}
INSIST(x == req->naddrs);
buflen = LWRES_LWPACKET_LENGTH + payload_length;
buf = CTXMALLOC(buflen);
if (buf == NULL)
return (LWRES_R_NOMEMORY);
lwres_buffer_init(b, buf, (unsigned int)buflen);
pkt->length = (lwres_uint32_t)buflen;
pkt->version = LWRES_LWPACKETVERSION_0;
pkt->pktflags |= LWRES_LWPACKETFLAG_RESPONSE;
pkt->opcode = LWRES_OPCODE_GETADDRSBYNAME;
pkt->authtype = 0;
pkt->authlength = 0;
ret = lwres_lwpacket_renderheader(b, pkt);
if (ret != LWRES_R_SUCCESS) {
lwres_buffer_invalidate(b);
CTXFREE(buf, buflen);
return (ret);
}
/*
* Check space needed here.
*/
INSIST(SPACE_OK(b, payload_length));
/* Flags. */
lwres_buffer_putuint32(b, req->flags);
/* encode naliases and naddrs */
lwres_buffer_putuint16(b, req->naliases);
lwres_buffer_putuint16(b, req->naddrs);
/* encode the real name */
datalen = req->realnamelen;
lwres_buffer_putuint16(b, datalen);
lwres_buffer_putmem(b, (unsigned char *)req->realname, datalen);
lwres_buffer_putuint8(b, 0);
/* encode the aliases */
for (x = 0; x < req->naliases; x++) {
datalen = req->aliaslen[x];
lwres_buffer_putuint16(b, datalen);
lwres_buffer_putmem(b, (unsigned char *)req->aliases[x],
datalen);
lwres_buffer_putuint8(b, 0);
}
/* encode the addresses */
addr = LWRES_LIST_HEAD(req->addrs);
while (addr != NULL) {
lwres_buffer_putuint32(b, addr->family);
lwres_buffer_putuint16(b, addr->length);
lwres_buffer_putmem(b, addr->address, addr->length);
addr = LWRES_LIST_NEXT(addr, link);
}
INSIST(LWRES_BUFFER_AVAILABLECOUNT(b) == 0);
INSIST(LWRES_BUFFER_USEDCOUNT(b) == pkt->length);
return (LWRES_R_SUCCESS);
}