本文整理汇总了C++中CTXFREE函数的典型用法代码示例。如果您正苦于以下问题:C++ CTXFREE函数的具体用法?C++ CTXFREE怎么用?C++ CTXFREE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CTXFREE函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
}
开发者ID:crossbuild,项目名称:bind,代码行数:28,代码来源:lwres_gabn.c
示例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);
}
开发者ID:SylvestreG,项目名称:bitrig,代码行数:53,代码来源:lwconfig.c
示例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);
}
开发者ID:enukane,项目名称:netbsd-src,代码行数:8,代码来源:context.c
示例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);
}
开发者ID:274914765,项目名称:C,代码行数:58,代码来源:lwres_gnba.c
示例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));
}
开发者ID:274914765,项目名称:C,代码行数:20,代码来源:lwres_gnba.c
示例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;
}
开发者ID:SylvestreG,项目名称:bitrig,代码行数:42,代码来源:lwconfig.c
示例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();
}
开发者ID:mokerjoke,项目名称:HPCC-Platform,代码行数:21,代码来源:workunitservices.cpp
示例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));
}
开发者ID:274914765,项目名称:C,代码行数:13,代码来源:lwres_gnba.c
示例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);
}
开发者ID:SylvestreG,项目名称:bitrig,代码行数:40,代码来源:lwconfig.c
示例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));
}
开发者ID:Stichting-MINIX-Research-Foundation,项目名称:minix,代码行数:14,代码来源:lwres_noop.c
示例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);
}
开发者ID:Stichting-MINIX-Research-Foundation,项目名称:minix,代码行数:49,代码来源:lwres_noop.c
示例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);
}
开发者ID:Stichting-MINIX-Research-Foundation,项目名称:minix,代码行数:47,代码来源:lwres_noop.c
示例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));
}
开发者ID:enukane,项目名称:netbsd-src,代码行数:25,代码来源:context.c
示例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));
//.........这里部分代码省略.........
开发者ID:nakedible,项目名称:vpnease-l2tp,代码行数:101,代码来源:async.c
示例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);
}
开发者ID:crossbuild,项目名称:bind,代码行数:97,代码来源:lwres_gabn.c
示例16: lwres_gabnresponse_parse
//.........这里部分代码省略.........
flags = lwres_buffer_getuint32(b);
naliases = lwres_buffer_getuint16(b);
naddrs = lwres_buffer_getuint16(b);
gabn = CTXMALLOC(sizeof(lwres_gabnresponse_t));
if (gabn == NULL)
return (LWRES_R_NOMEMORY);
gabn->aliases = NULL;
gabn->aliaslen = NULL;
LWRES_LIST_INIT(gabn->addrs);
gabn->base = NULL;
gabn->flags = flags;
gabn->naliases = naliases;
gabn->naddrs = naddrs;
LWRES_LIST_INIT(addrlist);
if (naliases > 0) {
gabn->aliases = CTXMALLOC(sizeof(char *) * naliases);
if (gabn->aliases == NULL) {
ret = LWRES_R_NOMEMORY;
goto out;
}
gabn->aliaslen = CTXMALLOC(sizeof(lwres_uint16_t) * naliases);
if (gabn->aliaslen == NULL) {
ret = LWRES_R_NOMEMORY;
goto out;
}
}
for (x = 0; x < naddrs; x++) {
addr = CTXMALLOC(sizeof(lwres_addr_t));
if (addr == NULL) {
ret = LWRES_R_NOMEMORY;
goto out;
}
LWRES_LINK_INIT(addr, link);
LWRES_LIST_APPEND(addrlist, addr, link);
}
/*
* Now, pull off the real name.
*/
ret = lwres_string_parse(b, &gabn->realname, &gabn->realnamelen);
if (ret != LWRES_R_SUCCESS)
goto out;
/*
* Parse off the aliases.
*/
for (x = 0; x < gabn->naliases; x++) {
ret = lwres_string_parse(b, &gabn->aliases[x],
&gabn->aliaslen[x]);
if (ret != LWRES_R_SUCCESS)
goto out;
}
/*
* Pull off the addresses. We already strung the linked list
* up above.
*/
addr = LWRES_LIST_HEAD(addrlist);
for (x = 0; x < gabn->naddrs; x++) {
INSIST(addr != NULL);
ret = lwres_addr_parse(b, addr);
if (ret != LWRES_R_SUCCESS)
goto out;
addr = LWRES_LIST_NEXT(addr, link);
}
if (LWRES_BUFFER_REMAINING(b) != 0) {
ret = LWRES_R_TRAILINGDATA;
goto out;
}
gabn->addrs = addrlist;
*structp = gabn;
return (LWRES_R_SUCCESS);
out:
if (gabn != NULL) {
if (gabn->aliases != NULL)
CTXFREE(gabn->aliases, sizeof(char *) * naliases);
if (gabn->aliaslen != NULL)
CTXFREE(gabn->aliaslen,
sizeof(lwres_uint16_t) * naliases);
addr = LWRES_LIST_HEAD(addrlist);
while (addr != NULL) {
LWRES_LIST_UNLINK(addrlist, addr, link);
CTXFREE(addr, sizeof(lwres_addr_t));
addr = LWRES_LIST_HEAD(addrlist);
}
CTXFREE(gabn, sizeof(lwres_gabnresponse_t));
}
return (ret);
}
开发者ID:crossbuild,项目名称:bind,代码行数:101,代码来源:lwres_gabn.c
示例17: lwres_gnbaresponse_parse
lwres_result_t
lwres_gnbaresponse_parse (lwres_context_t * ctx, lwres_buffer_t * b,
lwres_lwpacket_t * pkt, lwres_gnbaresponse_t ** structp)
{
int ret;
unsigned int x;
lwres_uint32_t flags;
lwres_uint16_t naliases;
lwres_gnbaresponse_t *gnba;
REQUIRE (ctx != NULL);
REQUIRE (pkt != NULL);
REQUIRE (b != NULL);
REQUIRE (structp != NULL && *structp == NULL);
gnba = NULL;
if ((pkt->pktflags & LWRES_LWPACKETFLAG_RESPONSE) == 0)
return (LWRES_R_FAILURE);
/*
* Pull off flags & naliases
*/
if (!SPACE_REMAINING (b, 4 + 2))
return (LWRES_R_UNEXPECTEDEND);
flags = lwres_buffer_getuint32 (b);
naliases = lwres_buffer_getuint16 (b);
gnba = CTXMALLOC (sizeof (lwres_gnbaresponse_t));
if (gnba == NULL)
return (LWRES_R_NOMEMORY);
gnba->base = NULL;
gnba->aliases = NULL;
gnba->aliaslen = NULL;
gnba->flags = flags;
gnba->naliases = naliases;
if (naliases > 0)
{
gnba->aliases = CTXMALLOC (sizeof (char *) * naliases);
if (gnba->aliases == NULL)
{
ret = LWRES_R_NOMEMORY;
goto out;
}
gnba->aliaslen = CTXMALLOC (sizeof (lwres_uint16_t) * naliases);
if (gnba->aliaslen == NULL)
{
ret = LWRES_R_NOMEMORY;
goto out;
}
}
/*
* Now, pull off the real name.
*/
ret = lwres_string_parse (b, &gnba->realname, &gnba->realnamelen);
if (ret != LWRES_R_SUCCESS)
goto out;
/*
* Parse off the aliases.
*/
for (x = 0; x < gnba->naliases; x++)
{
ret = lwres_string_parse (b, &gnba->aliases[x], &gnba->aliaslen[x]);
if (ret != LWRES_R_SUCCESS)
goto out;
}
if (LWRES_BUFFER_REMAINING (b) != 0)
{
ret = LWRES_R_TRAILINGDATA;
goto out;
}
*structp = gnba;
return (LWRES_R_SUCCESS);
out:
if (gnba != NULL)
{
if (gnba->aliases != NULL)
CTXFREE (gnba->aliases, sizeof (char *) * naliases);
if (gnba->aliaslen != NULL)
CTXFREE (gnba->aliaslen, sizeof (lwres_uint16_t) * naliases);
CTXFREE (gnba, sizeof (lwres_gnbaresponse_t));
}
return (ret);
}
开发者ID:274914765,项目名称:C,代码行数:97,代码来源:lwres_gnba.c
示例18: lwres_gnbaresponse_render
/*% Converts a getnamebyaddr response structure lwres_gnbaresponse_t to the lightweight resolver's canonical format. */
lwres_result_t
lwres_gnbaresponse_render (lwres_context_t * ctx, lwres_gnbaresponse_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;
int x;
REQUIRE (ctx != NULL);
REQUIRE (req != NULL);
REQUIRE (pkt != NULL);
REQUIRE (b != NULL);
/*
* Calculate packet size.
*/
payload_length = 4; /* flags */
payload_length += 2; /* naliases */
payload_length += 2 + req->realnamelen + 1; /* real name encoding */
for (x = 0; x < req->naliases; x++) /* each alias */
payload_length += 2 + req->aliaslen[x] + 1;
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->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));
lwres_buffer_putuint32 (b, req->flags);
/* encode naliases */
lwres_buffer_putuint16 (b, req->naliases);
/* 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);
}
INSIST (LWRES_BUFFER_AVAILABLECOUNT (b) == 0);
return (LWRES_R_SUCCESS);
}
开发者ID:274914765,项目名称:C,代码行数:77,代码来源:lwres_gnba.c
示例19: lwres_getrdatabyname
/*% Get rdata by name. */
lwres_result_t
lwres_getrdatabyname(lwres_context_t *ctx, const char *name,
lwres_uint16_t rdclass, lwres_uint16_t rdtype,
lwres_uint32_t flags, lwres_grbnresponse_t **structp)
{
int ret;
int recvlen;
lwres_buffer_t b_in, b_out;
lwres_lwpacket_t pkt;
lwres_uint32_t serial;
char *buffer;
lwres_grbnrequest_t request;
lwres_grbnresponse_t *response;
char target_name[1024];
unsigned int target_length;
REQUIRE(ctx != NULL);
REQUIRE(name != NULL);
REQUIRE(structp != NULL && *structp == NULL);
b_in.base = NULL;
b_out.base = NULL;
response = NULL;
buffer = NULL;
serial = lwres_context_nextserial(ctx);
buffer = CTXMALLOC(LWRES_RECVLENGTH);
if (buffer == NULL) {
ret = LWRES_R_NOMEMORY;
goto out;
}
target_length = strlen(name);
if (target_length >= sizeof(target_name))
return (LWRES_R_FAILURE);
strcpy(target_name, name); /* strcpy is safe */
/*
* Set up our request and render it to a buffer.
*/
request.rdclass = rdclass;
request.rdtype = rdtype;
request.flags = flags;
request.name = target_name;
request.namelen = target_length;
pkt.pktflags = 0;
pkt.serial = serial;
pkt.result = 0;
pkt.recvlength = LWRES_RECVLENGTH;
again:
ret = lwres_grbnrequest_render(ctx, &request, &pkt, &b_out);
if (ret != LWRES_R_SUCCESS)
goto out;
ret = lwres_context_sendrecv(ctx, b_out.base, b_out.length, buffer,
LWRES_RECVLENGTH, &recvlen);
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;
/*
* Sanity check.
*/
if (pkt.serial != serial)
goto again;
if (pkt.opcode != LWRES_OPCODE_GETRDATABYNAME)
goto again;
/*
* Free what we've transmitted
*/
CTXFREE(b_out.base, b_out.length);
b_out.base = NULL;
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)
goto out;
response->base = buffer;
response->baselen = LWRES_RECVLENGTH;
buffer = NULL; /* don't free this below */
//.........这里部分代码省略.........
开发者ID:crossbuild,项目名称:bind,代码行数:101,代码来源:lwresutil.c
示例20: lwres_getnamebyaddr
/*% Used to perform reverse lookups. */
lwres_result_t
lwres_getnamebyaddr(lwres_context_t *ctx, lwres_uint32_t addrtype,
lwres_uint16_t addrlen, const unsigned char *addr,
lwres_gnbaresponse_t **structp)
{
lwres_gnbarequest_t request;
lwres_gnbaresponse_t *response;
int ret;
int recvlen;
lwres_buffer_t b_in, b_out;
lwres_lwpacket_t pkt;
lwres_uint32_t serial;
char *buffer;
REQUIRE(ctx != NULL);
REQUIRE(addrtype != 0);
REQUIRE(addrlen != 0);
REQUIRE(addr != NULL);
REQUIRE(structp != NULL && *structp == NULL);
b_in.base = NULL;
b_out.base = NULL;
response = NULL;
buffer = NULL;
serial = lwres_context_nextserial(ctx);
buffer = CTXMALLOC(LWRES_RECVLENGTH);
if (buffer == NULL) {
ret = LWRES_R_NOMEMORY;
goto out;
}
/*
* Set up our request and render it to a buffer.
*/
request.flags = 0;
request.addr.family = addrtype;
request.addr.length = addrlen;
memmove(request.addr.address, addr, addrlen);
pkt.pktflags = 0;
pkt.serial = serial;
pkt.result = 0;
pkt.recvlength = LWRES_RECVLENGTH;
again:
ret = lwres_gnbarequest_render(ctx, &request, &pkt, &b_out);
if (ret != LWRES_R_SUCCESS)
goto out;
ret = lwres_context_sendrecv(ctx, b_out.base, b_out.length, buffer,
LWRES_RECVLENGTH, &recvlen);
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;
/*
* Sanity check.
*/
if (pkt.serial != serial)
goto again;
if (pkt.opcode != LWRES_OPCODE_GETNAMEBYADDR)
goto again;
/*
* Free what we've transmitted
*/
CTXFREE(b_out.base, b_out.length);
b_out.base = NULL;
b_out.length = 0;
if (pkt.result != LWRES_R_SUCCESS) {
ret = pkt.result;
goto out;
}
/*
* Parse the response.
*/
ret = lwres_gnbaresponse_parse(ctx, &b_in, &pkt, &response);
if (ret != LWRES_R_SUCCESS)
goto out;
response->base = buffer;
response->baselen = LWRES_RECVLENGTH;
buffer = NULL; /* don't free this below */
*structp = response;
return (LWRES_R_SUCCESS);
out:
if (b_out.base != NULL)
//.........这里部分代码省略.........
开发者ID:crossbuild,项目名称:bind,代码行数:101,代码来源:lwresutil.c
注:本文中的CTXFREE函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论