start changing from 'int' returns to 'lwres_result_t'
This commit is contained in:
@@ -38,9 +38,9 @@
|
||||
|
||||
static void *lwres_malloc(void *, size_t);
|
||||
static void lwres_free(void *, void *, size_t);
|
||||
static int context_connect(lwres_context_t *);
|
||||
static lwres_result_t context_connect(lwres_context_t *);
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_context_create(lwres_context_t **contextp, void *arg,
|
||||
lwres_malloc_t malloc_function,
|
||||
lwres_free_t free_function)
|
||||
@@ -157,7 +157,7 @@ lwres_free(void *arg, void *mem, size_t len)
|
||||
free(mem);
|
||||
}
|
||||
|
||||
static int
|
||||
static lwres_result_t
|
||||
context_connect(lwres_context_t *ctx)
|
||||
{
|
||||
int s;
|
||||
@@ -184,7 +184,7 @@ context_connect(lwres_context_t *ctx)
|
||||
return (LWRES_R_SUCCESS);
|
||||
}
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_context_sendrecv(lwres_context_t *ctx,
|
||||
void *sendbase, int sendlen,
|
||||
void *recvbase, int recvlen,
|
||||
@@ -203,7 +203,7 @@ lwres_context_sendrecv(lwres_context_t *ctx,
|
||||
|
||||
ret = sendto(ctx->sock, sendbase, sendlen, 0, NULL, 0);
|
||||
if (ret < 0)
|
||||
return (ret);
|
||||
return (LWRES_R_IOERROR);
|
||||
if (ret != sendlen)
|
||||
return (LWRES_R_IOERROR);
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <lwres/lang.h>
|
||||
#include <lwres/int.h>
|
||||
#include <lwres/result.h>
|
||||
|
||||
/*
|
||||
* Used to set various options such as timeout, authentication, etc
|
||||
@@ -33,7 +34,7 @@ LWRES_LANG_BEGINDECLS
|
||||
typedef void *(*lwres_malloc_t)(void *arg, size_t length);
|
||||
typedef void (*lwres_free_t)(void *arg, void *mem, size_t length);
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_context_create(lwres_context_t **contextp, void *arg,
|
||||
lwres_malloc_t malloc_function,
|
||||
lwres_free_t free_function);
|
||||
@@ -77,7 +78,7 @@ lwres_context_freemem(lwres_context_t *ctx, void *mem, size_t len);
|
||||
void *
|
||||
lwres_context_allocmem(lwres_context_t *ctx, size_t len);
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_context_sendrecv(lwres_context_t *ctx,
|
||||
void *sendbase, int sendlen,
|
||||
void *recvbase, int recvlen,
|
||||
|
||||
@@ -21,9 +21,9 @@
|
||||
#include <stddef.h>
|
||||
|
||||
#include <lwres/lang.h>
|
||||
#include <lwres/int.h>
|
||||
|
||||
#include <lwres/lwbuffer.h>
|
||||
#include <lwres/int.h>
|
||||
#include <lwres/result.h>
|
||||
|
||||
typedef struct lwres_lwpacket lwres_lwpacket_t;
|
||||
|
||||
@@ -115,10 +115,10 @@ struct lwres_lwpacket {
|
||||
|
||||
LWRES_LANG_BEGINDECLS
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_lwpacket_renderheader(lwres_buffer_t *b, lwres_lwpacket_t *pkt);
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_lwpacket_parseheader(lwres_buffer_t *b, lwres_lwpacket_t *pkt);
|
||||
|
||||
LWRES_LANG_ENDDECLS
|
||||
|
||||
@@ -21,11 +21,11 @@
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <lwres/lang.h>
|
||||
#include <lwres/int.h>
|
||||
|
||||
#include <lwres/context.h>
|
||||
#include <lwres/int.h>
|
||||
#include <lwres/lang.h>
|
||||
#include <lwres/lwpacket.h>
|
||||
#include <lwres/result.h>
|
||||
|
||||
/*
|
||||
* Design notes:
|
||||
@@ -206,19 +206,19 @@ typedef struct {
|
||||
|
||||
LWRES_LANG_BEGINDECLS
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_gabnrequest_render(lwres_context_t *ctx, lwres_gabnrequest_t *req,
|
||||
lwres_lwpacket_t *pkt, lwres_buffer_t *b);
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_gabnresponse_render(lwres_context_t *ctx, lwres_gabnresponse_t *req,
|
||||
lwres_lwpacket_t *pkt, lwres_buffer_t *b);
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_gabnrequest_parse(lwres_context_t *ctx, lwres_buffer_t *b,
|
||||
lwres_lwpacket_t *pkt, lwres_gabnrequest_t **structp);
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_gabnresponse_parse(lwres_context_t *ctx, lwres_buffer_t *b,
|
||||
lwres_lwpacket_t *pkt,
|
||||
lwres_gabnresponse_t **structp);
|
||||
@@ -262,19 +262,19 @@ lwres_gabnresponse_free(lwres_context_t *ctx, lwres_gabnresponse_t **structp);
|
||||
*/
|
||||
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_gnbarequest_render(lwres_context_t *ctx, lwres_gnbarequest_t *req,
|
||||
lwres_lwpacket_t *pkt, lwres_buffer_t *b);
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_gnbaresponse_render(lwres_context_t *ctx, lwres_gnbaresponse_t *req,
|
||||
lwres_lwpacket_t *pkt, lwres_buffer_t *b);
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_gnbarequest_parse(lwres_context_t *ctx, lwres_buffer_t *b,
|
||||
lwres_lwpacket_t *pkt, lwres_gnbarequest_t **structp);
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_gnbaresponse_parse(lwres_context_t *ctx, lwres_buffer_t *b,
|
||||
lwres_lwpacket_t *pkt,
|
||||
lwres_gnbaresponse_t **structp);
|
||||
@@ -317,7 +317,7 @@ lwres_gnbaresponse_free(lwres_context_t *ctx, lwres_gnbaresponse_t **structp);
|
||||
* system via the context's free function.
|
||||
*/
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_nooprequest_render(lwres_context_t *ctx, lwres_nooprequest_t *req,
|
||||
lwres_lwpacket_t *pkt, lwres_buffer_t *b);
|
||||
/*
|
||||
@@ -342,11 +342,11 @@ lwres_nooprequest_render(lwres_context_t *ctx, lwres_nooprequest_t *req,
|
||||
* packet. It can be transmitted in any way, including lwres_sendblock().
|
||||
*/
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_noopresponse_render(lwres_context_t *ctx, lwres_noopresponse_t *req,
|
||||
lwres_lwpacket_t *pkt, lwres_buffer_t *b);
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_nooprequest_parse(lwres_context_t *ctx, lwres_buffer_t *b,
|
||||
lwres_lwpacket_t *pkt, lwres_nooprequest_t **structp);
|
||||
/*
|
||||
@@ -357,7 +357,7 @@ lwres_nooprequest_parse(lwres_context_t *ctx, lwres_buffer_t *b,
|
||||
* The function verifies bits of the header, but does not modify it.
|
||||
*/
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_noopresponse_parse(lwres_context_t *ctx, lwres_buffer_t *b,
|
||||
lwres_lwpacket_t *pkt,
|
||||
lwres_noopresponse_t **structp);
|
||||
@@ -385,9 +385,8 @@ lwres_noopresponse_free(lwres_context_t *ctx, lwres_noopresponse_t **structp);
|
||||
* system via the context's free function.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
int lwres_conf_parse(const char *filename, lwres_conf_t *confdata);
|
||||
int
|
||||
lwres_conf_parse(const char *filename, lwres_conf_t *confdata);
|
||||
/*
|
||||
* parses a resolv.conf-format file and puts the results into *confdata;
|
||||
*
|
||||
@@ -400,7 +399,8 @@ int lwres_conf_parse(const char *filename, lwres_conf_t *confdata);
|
||||
* -1 on failure (errno will be != 0 on failure like file not found.
|
||||
*/
|
||||
|
||||
void lwres_conf_free(lwres_conf_t *confdata);
|
||||
void
|
||||
lwres_conf_free(lwres_conf_t *confdata);
|
||||
/*
|
||||
* Returns the data in confdata to the system.
|
||||
*
|
||||
@@ -409,19 +409,22 @@ void lwres_conf_free(lwres_conf_t *confdata);
|
||||
* that confdata had been previously passed to lwres_conf_parse()
|
||||
*/
|
||||
|
||||
int lwres_conf_print(FILE *fp, lwres_conf_t *confdata);
|
||||
int
|
||||
lwres_conf_print(FILE *fp, lwres_conf_t *confdata);
|
||||
/*
|
||||
* Prints a resolv.conf-format of confdata output to fp.
|
||||
*/
|
||||
|
||||
void lwres_conf_init(lwres_context_t *ctx, lwres_conf_t *confdata);
|
||||
void
|
||||
lwres_conf_init(lwres_context_t *ctx, lwres_conf_t *confdata);
|
||||
/*
|
||||
* sets all internal fields to a default state. Used to initialize a new
|
||||
* lwres_conf_t structure (not reset a used on).
|
||||
*/
|
||||
|
||||
|
||||
void lwres_conf_clear(lwres_conf_t *confdata);
|
||||
void
|
||||
lwres_conf_clear(lwres_conf_t *confdata);
|
||||
/*
|
||||
* frees all internally allocated memory in confdata. Uses the memory
|
||||
* routines supplies by ctx (so that should probably be the same value as
|
||||
@@ -432,17 +435,17 @@ void lwres_conf_clear(lwres_conf_t *confdata);
|
||||
* Helper functions
|
||||
*/
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_string_parse(lwres_buffer_t *b, char **c, lwres_uint16_t *len);
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_addr_parse(lwres_buffer_t *b, lwres_addr_t *addr);
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_getaddrsbyname(lwres_context_t *ctx, const char *name,
|
||||
lwres_uint32_t addrtypes, lwres_gabnresponse_t **structp);
|
||||
|
||||
int
|
||||
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);
|
||||
|
||||
@@ -18,12 +18,7 @@
|
||||
#ifndef LWRES_RESULT_H
|
||||
#define LWRES_RESULT_H 1
|
||||
|
||||
/*
|
||||
* XXXMLG
|
||||
* should be unsigned when functions are fixed to return a status, not both
|
||||
* a status and an FD or whatever.
|
||||
*/
|
||||
typedef int lwres_result_t;
|
||||
typedef unsigned int lwres_result_t;
|
||||
|
||||
#define LWRES_R_SUCCESS 0
|
||||
#define LWRES_R_NOMEMORY -1
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
#define LWPACKET_LENGTH (sizeof(lwres_uint16_t) * 4 + sizeof(lwres_uint32_t) * 5)
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_lwpacket_renderheader(lwres_buffer_t *b, lwres_lwpacket_t *pkt)
|
||||
{
|
||||
REQUIRE(b != NULL);
|
||||
@@ -51,7 +51,7 @@ lwres_lwpacket_renderheader(lwres_buffer_t *b, lwres_lwpacket_t *pkt)
|
||||
return (LWRES_R_SUCCESS);
|
||||
}
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_lwpacket_parseheader(lwres_buffer_t *b, lwres_lwpacket_t *pkt)
|
||||
{
|
||||
lwres_uint32_t space;
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
* following the string length, the string, and the trailing NULL.
|
||||
*
|
||||
*/
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_string_parse(lwres_buffer_t *b, char **c, lwres_uint16_t *len)
|
||||
{
|
||||
lwres_uint16_t datalen;
|
||||
@@ -60,7 +60,7 @@ lwres_string_parse(lwres_buffer_t *b, char **c, lwres_uint16_t *len)
|
||||
/*
|
||||
* Pull off the length (2 bytes)
|
||||
*/
|
||||
if (!SPACE_REMAINING(b, sizeof(lwres_uint16_t)))
|
||||
if (!SPACE_REMAINING(b, 2))
|
||||
return (LWRES_R_UNEXPECTEDEND);
|
||||
datalen = lwres_buffer_getuint16(b);
|
||||
|
||||
@@ -89,15 +89,17 @@ lwres_string_parse(lwres_buffer_t *b, char **c, lwres_uint16_t *len)
|
||||
return (LWRES_R_SUCCESS);
|
||||
}
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_addr_parse(lwres_buffer_t *b, lwres_addr_t *addr)
|
||||
{
|
||||
REQUIRE(addr != NULL);
|
||||
|
||||
if (!SPACE_REMAINING(b, sizeof(lwres_uint32_t) + sizeof(lwres_uint16_t)))
|
||||
if (!SPACE_REMAINING(b, 6))
|
||||
return (LWRES_R_UNEXPECTEDEND);
|
||||
|
||||
addr->family = lwres_buffer_getuint32(b);
|
||||
addr->length = lwres_buffer_getuint16(b);
|
||||
|
||||
if (!SPACE_REMAINING(b, addr->length))
|
||||
return (LWRES_R_UNEXPECTEDEND);
|
||||
addr->address = b->base + b->current;
|
||||
@@ -106,7 +108,7 @@ lwres_addr_parse(lwres_buffer_t *b, lwres_addr_t *addr)
|
||||
return (LWRES_R_SUCCESS);
|
||||
}
|
||||
|
||||
int
|
||||
lwres_result_t
|
||||
lwres_getaddrsbyname(lwres_context_t *ctx, const char *name,
|
||||
lwres_uint32_t addrtypes, lwres_gabnresponse_t **structp)
|
||||
{
|
||||
@@ -164,7 +166,7 @@ lwres_getaddrsbyname(lwres_context_t *ctx, const char *name,
|
||||
* Parse the packet header.
|
||||
*/
|
||||
ret = lwres_lwpacket_parseheader(&b_in, &pkt);
|
||||
if (ret != 0)
|
||||
if (ret != LWRES_R_SUCCESS)
|
||||
goto out;
|
||||
|
||||
/*
|
||||
@@ -191,7 +193,7 @@ lwres_getaddrsbyname(lwres_context_t *ctx, const char *name,
|
||||
* Parse the response.
|
||||
*/
|
||||
ret = lwres_gabnresponse_parse(ctx, &b_in, &pkt, &response);
|
||||
if (ret != 0)
|
||||
if (ret != LWRES_R_SUCCESS)
|
||||
goto out;
|
||||
response->base = buffer;
|
||||
response->baselen = LWRES_RECVLENGTH;
|
||||
@@ -212,7 +214,7 @@ lwres_getaddrsbyname(lwres_context_t *ctx, const char *name,
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
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)
|
||||
@@ -257,7 +259,7 @@ lwres_getnamebyaddr(lwres_context_t *ctx, lwres_uint32_t addrtype,
|
||||
|
||||
again:
|
||||
ret = lwres_gnbarequest_render(ctx, &request, &pkt, &b_out);
|
||||
if (ret != 0)
|
||||
if (ret != LWRES_R_SUCCESS)
|
||||
goto out;
|
||||
|
||||
ret = lwres_context_sendrecv(ctx, b_out.base, b_out.length, buffer,
|
||||
@@ -272,7 +274,7 @@ lwres_getnamebyaddr(lwres_context_t *ctx, lwres_uint32_t addrtype,
|
||||
* Parse the packet header.
|
||||
*/
|
||||
ret = lwres_lwpacket_parseheader(&b_in, &pkt);
|
||||
if (ret != 0)
|
||||
if (ret != LWRES_R_SUCCESS)
|
||||
goto out;
|
||||
|
||||
/*
|
||||
@@ -299,7 +301,7 @@ lwres_getnamebyaddr(lwres_context_t *ctx, lwres_uint32_t addrtype,
|
||||
* Parse the response.
|
||||
*/
|
||||
ret = lwres_gnbaresponse_parse(ctx, &b_in, &pkt, &response);
|
||||
if (ret != 0)
|
||||
if (ret != LWRES_R_SUCCESS)
|
||||
goto out;
|
||||
response->base = buffer;
|
||||
response->baselen = LWRES_RECVLENGTH;
|
||||
|
||||
Reference in New Issue
Block a user