lwresutil.c revision 88ed7381f16a72409061875ddeda598f477e5ef6
/*
* Copyright (C) 2000 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#include <config.h>
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <lwres/lwbuffer.h>
#include "assert_p.h"
#include "context_p.h"
/*
* Requires:
*
* The "current" pointer in "b" point to an encoded string.
*
* Ensures:
*
* The address of the first byte of the string is returned via "c",
* and the length is returned via "len". If NULL, they are not
* set.
*
* On return, the current pointer of "b" will point to the character
* following the string length, the stirng, and the trailing NUL.
*
*/
int
{
char *string;
if (!SPACE_REMAINING(b, sizeof(isc_uint16_t)))
return (-1);
datalen++;
if (!SPACE_REMAINING(b, datalen))
return (-1);
if (c != NULL)
*c = string;
return (0);
}
int
{
return (-1);
return (-1);
return (0);
}
int
{
int ret;
int free_b;
char *buffer;
free_b = 0;
ret = -1;
goto out;
}
/*
* Set up our request and render it to a buffer.
*/
if (ret != 0)
goto out;
free_b = 1;
if (ret < 0)
goto out;
free_b = 0;
/*
* Parse the packet header.
*/
if (ret != 0)
goto out;
/*
* Sanity check.
*/
ret = -1;
goto out;
}
ret = -1;
goto out;
}
/*
* Parse the response.
*/
if (ret != 0)
goto out;
return (0);
out:
if (free_b != 0)
return (ret);
}
int
{
int ret;
int free_b;
char *buffer;
free_b = 0;
ret = -1;
goto out;
}
/*
* Set up our request and render it to a buffer.
*/
if (ret != 0)
goto out;
free_b = 1;
if (ret < 0)
goto out;
free_b = 0;
/*
* Parse the packet header.
*/
if (ret != 0)
goto out;
/*
* Sanity check.
*/
ret = -1;
goto out;
}
ret = -1;
goto out;
}
/*
* Parse the response.
*/
if (ret != 0)
goto out;
return (0);
out:
if (free_b != 0)
return (ret);
}