0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2000, 2001, 2004, 2005, 2007, 2013, 2015, 2016 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
70e5a7403f0e0a3bd292b8287c5fed5772c15270Automatic Updater/* $Id: lwres_grbn.c,v 1.10 2007/06/19 23:47:22 tbox Exp $ */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*% Thread-save equivalent to \link lwres_gabn.c lwres_gabn* \endlink routines. */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellingtonlwres_grbnrequest_render(lwres_context_t *ctx, lwres_grbnrequest_t *req,
bcb68be0a8f3c3eca58d6a6a869267e5c1841de2Francis Dupont datalen = (lwres_uint16_t) strlen(req->name);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington payload_length = 4 + 2 + 2 + 2 + req->namelen + 1;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington buflen = LWRES_LWPACKET_LENGTH + payload_length;
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews lwres_buffer_init(b, buf, (unsigned int)buflen);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington pkt->pktflags &= ~LWRES_LWPACKETFLAG_RESPONSE;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington * Put the length and the data. We know this will fit because we
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington * just checked for it.
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington lwres_buffer_putmem(b, (unsigned char *)req->name, datalen);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington lwres_buffer_putuint8(b, 0); /* trailing NUL */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington INSIST(LWRES_BUFFER_AVAILABLECOUNT(b) == 0);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*% Thread-save equivalent to \link lwres_gabn.c lwres_gabn* \endlink routines. */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellingtonlwres_grbnresponse_render(lwres_context_t *ctx, lwres_grbnresponse_t *req,
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington /* flags, class, type, ttl, nrdatas, nsigs */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington /* real name encoding */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington payload_length += 2 + req->realnamelen + 1;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington /* each rr */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington buflen = LWRES_LWPACKET_LENGTH + payload_length;
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews lwres_buffer_init(b, buf, (unsigned int)buflen);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington pkt->pktflags |= LWRES_LWPACKETFLAG_RESPONSE;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington * Check space needed here.
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington /* encode class, type, ttl, and nrdatas */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington /* encode the real name */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington lwres_buffer_putmem(b, (unsigned char *)req->realname, datalen);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington /* encode the rdatas */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington lwres_buffer_putmem(b, req->rdatas[x], datalen);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington /* encode the signatures */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington lwres_buffer_putmem(b, req->sigs[x], datalen);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington INSIST(LWRES_BUFFER_AVAILABLECOUNT(b) == 0);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington INSIST(LWRES_BUFFER_USEDCOUNT(b) == pkt->length);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*% Thread-save equivalent to \link lwres_gabn.c lwres_gabn* \endlink routines. */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellingtonlwres_grbnrequest_parse(lwres_context_t *ctx, lwres_buffer_t *b,
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington lwres_lwpacket_t *pkt, lwres_grbnrequest_t **structp)
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington REQUIRE(structp != NULL && *structp == NULL);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington if ((pkt->pktflags & LWRES_LWPACKETFLAG_RESPONSE) != 0)
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington * Pull off the flags, class, and type.
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington * Pull off the name itself
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington ret = lwres_string_parse(b, &name, &namelen);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington grbn = CTXMALLOC(sizeof(lwres_grbnrequest_t));
83baacd8ff7bf1aa282981bd4785a71b1a4cb0dfMark Andrews/*% Thread-safe equivalent to \link lwres_gabn.c lwres_gabn* \endlink routines. */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellingtonlwres_grbnresponse_parse(lwres_context_t *ctx, lwres_buffer_t *b,
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington lwres_lwpacket_t *pkt, lwres_grbnresponse_t **structp)
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington unsigned int x;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington REQUIRE(structp != NULL && *structp == NULL);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington if ((pkt->pktflags & LWRES_LWPACKETFLAG_RESPONSE) == 0)
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington * Pull off the flags, class, type, ttl, nrdatas, and nsigs
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington if (!SPACE_REMAINING(b, 4 + 2 + 2 + 4 + 2 + 2))
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington * Pull off the name itself
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington grbn = CTXMALLOC(sizeof(lwres_grbnresponse_t));
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington grbn->rdatas = CTXMALLOC(sizeof(char *) * nrdatas);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington grbn->rdatalen = CTXMALLOC(sizeof(lwres_uint16_t) * nrdatas);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington grbn->sigs = CTXMALLOC(sizeof(char *) * nsigs);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington grbn->siglen = CTXMALLOC(sizeof(lwres_uint16_t) * nsigs);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington * Now, pull off the real name.
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington ret = lwres_string_parse(b, &grbn->realname, &grbn->realnamelen);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington * Parse off the rdatas.
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington ret = lwres_data_parse(b, &grbn->rdatas[x],
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington * Parse off the signatures.
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington ret = lwres_data_parse(b, &grbn->sigs[x], &grbn->siglen[x]);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington CTXFREE(grbn->rdatas, sizeof(char *) * nrdatas);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington CTXFREE(grbn->sigs, sizeof(char *) * nsigs);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington CTXFREE(grbn->siglen, sizeof(lwres_uint16_t) * nsigs);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington CTXFREE(grbn, sizeof(lwres_grbnresponse_t));
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*% Thread-save equivalent to \link lwres_gabn.c lwres_gabn* \endlink routines. */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellingtonlwres_grbnrequest_free(lwres_context_t *ctx, lwres_grbnrequest_t **structp)
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington REQUIRE(structp != NULL && *structp != NULL);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington CTXFREE(grbn, sizeof(lwres_grbnrequest_t));
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*% Thread-save equivalent to \link lwres_gabn.c lwres_gabn* \endlink routines. */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellingtonlwres_grbnresponse_free(lwres_context_t *ctx, lwres_grbnresponse_t **structp)
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington REQUIRE(structp != NULL && *structp != NULL);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington CTXFREE(grbn->rdatas, sizeof(char *) * grbn->nrdatas);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington CTXFREE(grbn->sigs, sizeof(char *) * grbn->nsigs);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington CTXFREE(grbn->siglen, sizeof(lwres_uint16_t) * grbn->nsigs);