Commit a54314b2 authored by Niels Möller's avatar Niels Möller
Browse files

* Use uint32_t and friends instead of UINT32.

Rev: src/sftp/buffer.c:1.15
Rev: src/sftp/buffer.h:1.10
Rev: src/sftp/client.c:1.5
Rev: src/sftp/client.h:1.3
Rev: src/sftp/io_input.c:1.2
Rev: src/sftp/io_output.c:1.2
Rev: src/sftp/sftp-server.c:1.20
Rev: src/sftp/sftp-test-client.c:1.13
Rev: src/sftp/sftp_c.c:1.7
Rev: src/sftp/sftp_c.h:1.4
Rev: src/sftp/str_utils.c:1.6
parent 8442a2c5
......@@ -46,15 +46,15 @@
(sftp_get_data((i), sizeof((buf)), (buf)))
int
sftp_get_uint8(struct sftp_input *i, UINT8 *value)
sftp_get_uint8(struct sftp_input *i, uint8_t *value)
{
return sftp_get_data(i, 1, value);
}
int
sftp_get_uint32(struct sftp_input *i, UINT32 *value)
sftp_get_uint32(struct sftp_input *i, uint32_t *value)
{
UINT8 buf[4];
uint8_t buf[4];
if (!GET_DATA(i, buf))
return 0;
......@@ -62,10 +62,10 @@ sftp_get_uint32(struct sftp_input *i, UINT32 *value)
return 1;
}
UINT8 *
sftp_get_string(struct sftp_input *i, UINT32 *length)
uint8_t *
sftp_get_string(struct sftp_input *i, uint32_t *length)
{
UINT8 *data;
uint8_t *data;
if (!(sftp_get_uint32(i, length) && sftp_check_input(i, *length)))
return NULL;
......@@ -85,15 +85,15 @@ sftp_get_string(struct sftp_input *i, UINT32 *length)
}
void
sftp_free_string(UINT8 *s)
sftp_free_string(uint8_t *s)
{
free(s);
}
UINT8 *
sftp_get_string_auto(struct sftp_input *i, UINT32 *length)
uint8_t *
sftp_get_string_auto(struct sftp_input *i, uint32_t *length)
{
UINT8 *data;
uint8_t *data;
data = sftp_get_string(i, length);
......@@ -114,23 +114,23 @@ sftp_get_string_auto(struct sftp_input *i, UINT32 *length)
(sftp_put_data((o), sizeof((buf)), (buf)))
void
sftp_put_uint32(struct sftp_output *o, UINT32 value)
sftp_put_uint32(struct sftp_output *o, uint32_t value)
{
UINT8 buf[4];
uint8_t buf[4];
WRITE_UINT32(buf, value);
PUT_DATA(o, buf);
}
void
sftp_put_string(struct sftp_output *o, UINT32 length, const UINT8 *data)
sftp_put_string(struct sftp_output *o, uint32_t length, const uint8_t *data)
{
sftp_put_uint32(o, length);
sftp_put_data(o, length, data);
}
UINT32
uint32_t
sftp_put_printf(struct sftp_output *o, const char *format, ...)
{
/* Initial buffer space */
......@@ -159,8 +159,8 @@ sftp_put_printf(struct sftp_output *o, const char *format, ...)
/* If SIZE > 0 it is the desired field length, and
* smaller output is padded with blanks. */
UINT32
sftp_put_strftime(struct sftp_output *o, UINT32 size, const char *format,
uint32_t
sftp_put_strftime(struct sftp_output *o, uint32_t size, const char *format,
const struct tm *tm)
{
/* Initial buffer space */
......@@ -202,7 +202,7 @@ sftp_put_strftime(struct sftp_output *o, UINT32 size, const char *format,
int
sftp_get_uint64(struct sftp_input *i, off_t *value)
{
UINT8 buf[8];
uint8_t buf[8];
if (!GET_DATA(i, buf))
return 0;
......@@ -225,9 +225,9 @@ do { \
void
sftp_put_uint64(struct sftp_output *o, off_t value)
{
UINT8 buf[8];
uint8_t buf[8];
WRITE_UINT64(buf, value);
WRITE_uint64_t(buf, value);
PUT_DATA(o, buf);
}
......@@ -237,8 +237,8 @@ sftp_put_uint64(struct sftp_output *o, off_t value)
int
sftp_get_uint64(struct sftp_input *i, off_t *value)
{
UINT32 high;
UINT32 low;
uint32_t high;
uint32_t low;
if (sftp_get_uint32(i, &high)
&& !high
......@@ -279,8 +279,8 @@ sftp_clear_attrib(struct sftp_attrib *a)
int
sftp_skip_extension(struct sftp_input *i)
{
UINT32 length;
UINT8 *data;
uint32_t length;
uint8_t *data;
unsigned j;
/* Skip name and value*/
......@@ -334,8 +334,8 @@ sftp_get_attrib(struct sftp_input *i, struct sftp_attrib *a)
if (a->flags & SSH_FILEXFER_ATTR_EXTENDED)
{
UINT32 count;
UINT32 n;
uint32_t count;
uint32_t n;
if (!sftp_get_uint32(i, &count))
return 0;
......
......@@ -35,36 +35,6 @@
/* For off_t */
#include <sys/types.h>
#if SIZEOF_SHORT >= 4
# define UINT32 unsigned short
#elif SIZEOF_INT >= 4
# define UINT32 unsigned int
#elif SIZEOF_LONG >= 4
# define UINT32 unsigned long
#else
# error No suitable type found to use for UINT32
#endif /* UINT32 */
#if SIZEOF_SHORT >= 2
# define UINT16 unsigned short
#elif SIZEOF_INT >= 2
# define UINT16 unsigned int
#else
# error No suitable type found to use for UINT16
#endif /* UINT16 */
#define UINT8 unsigned char
#if __GNUC__ && HAVE_GCC_ATTRIBUTE
# define NORETURN __attribute__ ((__noreturn__))
# define PRINTF_STYLE(f, a) __attribute__ ((__format__ (__printf__, f, a)))
# define UNUSED __attribute__ ((__unused__))
#else
# define NORETURN
# define PRINTF_STYLE(f, a)
# define UNUSED
#endif
/* Abstract input and output functions */
#include <time.h>
......@@ -79,32 +49,32 @@ int
sftp_read_packet(struct sftp_input *i);
int
sftp_check_input(const struct sftp_input *i, UINT32 length);
sftp_check_input(const struct sftp_input *i, uint32_t length);
int
sftp_get_data(struct sftp_input *i, UINT32 length, UINT8 *data);
sftp_get_data(struct sftp_input *i, uint32_t length, uint8_t *data);
int
sftp_get_uint8(struct sftp_input *i, UINT8 *value);
sftp_get_uint8(struct sftp_input *i, uint8_t *value);
int
sftp_get_uint32(struct sftp_input *i, UINT32 *value);
sftp_get_uint32(struct sftp_input *i, uint32_t *value);
int
sftp_get_uint64(struct sftp_input *i, off_t *value);
/* Allocates storage. Caller must deallocate using
* sftp_free_string. */
UINT8 *
sftp_get_string(struct sftp_input *i, UINT32 *length);
uint8_t *
sftp_get_string(struct sftp_input *i, uint32_t *length);
void
sftp_free_string(UINT8 *s);
sftp_free_string(uint8_t *s);
/* Like sftp_get_string, but the data is deallocated automatically by
* sftp_read_packet and sftp_input_clear_strings. */
UINT8 *
sftp_get_string_auto(struct sftp_input *i, UINT32 *length);
uint8_t *
sftp_get_string_auto(struct sftp_input *i, uint32_t *length);
void
sftp_input_clear_strings(struct sftp_input *i);
......@@ -118,28 +88,28 @@ sftp_get_eod(struct sftp_input *i);
/* Output */
void
sftp_set_msg(struct sftp_output *o, UINT8 msg);
sftp_set_msg(struct sftp_output *o, uint8_t msg);
void
sftp_set_id(struct sftp_output *o, UINT32 id);
sftp_set_id(struct sftp_output *o, uint32_t id);
int
sftp_write_packet(struct sftp_output *o);
void
sftp_put_data(struct sftp_output *o, UINT32 length, const UINT8 *data);
sftp_put_data(struct sftp_output *o, uint32_t length, const uint8_t *data);
void
sftp_put_uint8(struct sftp_output *o, UINT8 value);
sftp_put_uint8(struct sftp_output *o, uint8_t value);
void
sftp_put_uint32(struct sftp_output *o, UINT32 value);
sftp_put_uint32(struct sftp_output *o, uint32_t value);
void
sftp_put_uint64(struct sftp_output *o, off_t value);
void
sftp_put_string(struct sftp_output *o, UINT32 length, const UINT8 *data);
sftp_put_string(struct sftp_output *o, uint32_t length, const uint8_t *data);
/* Low-level functions, used by sftp_put_printf and sftp_put_strftime */
uint8_t *
......@@ -149,28 +119,28 @@ void
sftp_put_end(struct sftp_output *o, uint32_t length);
/* Returns index. */
UINT32
uint32_t
sftp_put_reserve_length(struct sftp_output *o);
void
sftp_put_final_length(struct sftp_output *o,
UINT32 index);
uint32_t index);
void
sftp_put_length(struct sftp_output *o,
UINT32 index,
UINT32 length);
uint32_t index,
uint32_t length);
void
sftp_put_reset(struct sftp_output *o,
UINT32 index);
uint32_t index);
UINT32
uint32_t
sftp_put_printf(struct sftp_output *o, const char *format, ...)
PRINTF_STYLE(2,3);
UINT32
sftp_put_strftime(struct sftp_output *o, UINT32 size,
uint32_t
sftp_put_strftime(struct sftp_output *o, uint32_t size,
const char *format,
const struct tm *tm);
......@@ -181,15 +151,15 @@ sftp_packet_size(struct sftp_output* out);
struct sftp_attrib
{
UINT32 flags;
uint32_t flags;
off_t size;
UINT32 uid;
UINT32 gid;
UINT32 permissions;
uint32_t uid;
uint32_t gid;
uint32_t permissions;
/* NOTE: The representations of times is about to change. */
UINT32 atime;
UINT32 mtime;
uint32_t atime;
uint32_t mtime;
};
void
......@@ -209,10 +179,10 @@ sftp_skip_extension(struct sftp_input *i);
/* Macros */
/* Reads a 32-bit integer, in network byte order */
#define READ_UINT32(p) \
( (((UINT32) (p)[0]) << 24) \
| (((UINT32) (p)[1]) << 16) \
| (((UINT32) (p)[2]) << 8) \
| ((UINT32) (p)[3]))
( (((uint32_t) (p)[0]) << 24) \
| (((uint32_t) (p)[1]) << 16) \
| (((uint32_t) (p)[2]) << 8) \
| ((uint32_t) (p)[3]))
#define WRITE_UINT32(p, i) \
do { \
......@@ -222,5 +192,4 @@ do { \
(p)[3] = (i) & 0xff; \
} while(0)
#endif /* SFTP_BUFFER_H_INCLUDED */
......@@ -34,15 +34,15 @@
#include <string.h>
/* We never have several pending calls at once. */
static UINT32
static uint32_t
sftp_client_new_id(void)
{ return 17; }
static struct client_handle *
client_get_handle(struct sftp_input *i)
{
UINT32 length;
UINT8 *data;
uint32_t length;
uint8_t *data;
struct client_handle *handle;
data = sftp_get_string(i, &length);
......@@ -56,11 +56,11 @@ client_get_handle(struct sftp_input *i)
return handle;
}
static UINT8
client_get_msg(struct client_ctx *ctx, UINT32 expected)
static uint8_t
client_get_msg(struct client_ctx *ctx, uint32_t expected)
{
UINT8 msg;
UINT32 id;
uint8_t msg;
uint32_t id;
if (sftp_get_uint8(ctx->i, &msg)
&& sftp_get_uint32(ctx->i, &id)
......@@ -71,10 +71,10 @@ client_get_msg(struct client_ctx *ctx, UINT32 expected)
fatal("Protocol error, client_get_msg");
}
static UINT32
client_get_status(struct client_ctx *ctx, UINT32 id)
static uint32_t
client_get_status(struct client_ctx *ctx, uint32_t id)
{
UINT32 status;
uint32_t status;
if ( (client_get_msg(ctx, id) == SSH_FXP_STATUS)
&& sftp_get_uint32(ctx->i, &status))
......@@ -94,11 +94,11 @@ client_put_handle(struct client_ctx *ctx, struct client_handle *handle)
struct client_handle *
sftp_open(struct client_ctx *ctx,
const char *name,
UINT32 flags,
uint32_t flags,
const struct sftp_attrib *a)
{
UINT8 msg;
UINT32 id = sftp_client_new_id();
uint8_t msg;
uint32_t id = sftp_client_new_id();
/* Send a OPEN message */
sftp_set_msg(ctx->o, SSH_FXP_OPEN);
......@@ -133,7 +133,7 @@ int
sftp_close(struct client_ctx *ctx,
struct client_handle *handle)
{
UINT32 id = sftp_client_new_id();
uint32_t id = sftp_client_new_id();
sftp_set_msg(ctx->o, SSH_FXP_CLOSE); /* Send a close message */
sftp_set_id(ctx->o, id);
......
......@@ -34,21 +34,21 @@ struct client_ctx
struct sftp_output *o;
/* Status from latest message. */
UINT32 status;
uint32_t status;
};
/* Handles are strings, choosen by the server. */
struct client_handle
{
UINT32 length;
UINT8 *data;
uint32_t length;
uint8_t *data;
};
/* Creates a file handle */
struct client_handle *
sftp_open(struct client_ctx *ctx,
const char *name,
UINT32 flags,
uint32_t flags,
const struct sftp_attrib *a);
/* Destroys a file or directory handle */
......
......@@ -32,26 +32,26 @@
struct sftp_input
{
int fd;
UINT32 left;
uint32_t left;
/* Strings that we own */
UINT8 *strings[SFTP_MAX_STRINGS];
uint8_t *strings[SFTP_MAX_STRINGS];
unsigned used_strings;
};
int
sftp_check_input(const struct sftp_input *i, UINT32 length)
sftp_check_input(const struct sftp_input *i, uint32_t length)
{
return (i->left >= length);
}
int
sftp_get_data(struct sftp_input *i, UINT32 length, UINT8 *data)
sftp_get_data(struct sftp_input *i, uint32_t length, uint8_t *data)
{
if (sftp_check_input(i, length))
{
UINT8* buf = data;
uint8_t* buf = data;
int j;
while (length)
......@@ -115,12 +115,12 @@ sftp_get_eod(struct sftp_input *i)
int
sftp_read_packet(struct sftp_input *i)
{
UINT8 buf[4];
uint8_t buf[4];
int bytesread = 0;
if (i->left) /* Unread data? */
{
UINT8 d;
uint8_t d;
while (i->left && /* Data remaining? */
0<sftp_get_data(i, 1, &d) /* Read OK? */
......
......@@ -34,15 +34,15 @@ struct sftp_output
/* The message type is the first byte of a message, after the
* length. */
UINT8 msg;
uint8_t msg;
/* The next word is either the id, or the version. */
UINT32 first;
uint32_t first;
/* The rest of the packet is variable length. */
UINT8 *data;
UINT32 size;
UINT32 i;
uint8_t *data;
uint32_t size;
uint32_t i;
};
......@@ -67,24 +67,24 @@ sftp_make_output(int fd)
}
void
sftp_set_msg(struct sftp_output *o, UINT8 msg)
sftp_set_msg(struct sftp_output *o, uint8_t msg)
{
o->msg = msg;
}
void
sftp_set_id(struct sftp_output *o, UINT32 id)
sftp_set_id(struct sftp_output *o, uint32_t id)
{
o->first = id;
}
static void
sftp_check_output(struct sftp_output *o, UINT32 length)
sftp_check_output(struct sftp_output *o, uint32_t length)
{
UINT32 needed = o->i + length;
uint32_t needed = o->i + length;
if (!o->data || (needed > o->size))
{
UINT32 size = 2 * needed + 40;
uint32_t size = 2 * needed + 40;
o->data = xrealloc(o->data, size);
o->size = size;
......@@ -92,7 +92,7 @@ sftp_check_output(struct sftp_output *o, UINT32 length)
}
void
sftp_put_data(struct sftp_output *o, UINT32 length, const UINT8 *data)
sftp_put_data(struct sftp_output *o, uint32_t length, const uint8_t *data)
{
sftp_check_output(o, length);
......@@ -101,7 +101,7 @@ sftp_put_data(struct sftp_output *o, UINT32 length, const UINT8 *data)
}
void
sftp_put_uint8(struct sftp_output *o, UINT8 value)
sftp_put_uint8(struct sftp_output *o, uint8_t value)
{
sftp_check_output(o, 1);
......@@ -125,7 +125,7 @@ sftp_put_end(struct sftp_output *o, uint32_t length)
uint32_t
sftp_put_reserve_length(struct sftp_output *o)
{
UINT32 index;
uint32_t index;
sftp_check_output(o, 4);
index = o->i;
......@@ -136,8 +136,8 @@ sftp_put_reserve_length(struct sftp_output *o)
void
sftp_put_length(struct sftp_output *o,
UINT32 index,
UINT32 length)
uint32_t index,
uint32_t length)
{
assert( (index + 4) < o->i);
WRITE_UINT32(o->data + index, length);
......@@ -145,14 +145,14 @@ sftp_put_length(struct sftp_output *o,
void
sftp_put_final_length(struct sftp_output *o,
UINT32 index)
uint32_t index)
{
sftp_put_length(o, index, o->i - index - 4);
}
void
sftp_put_reset(struct sftp_output *o,
UINT32 index)
uint32_t index)
{
assert(index < o->i);
o->i = index;
......@@ -163,8 +163,8 @@ sftp_write_packet(struct sftp_output *o)
{
int j;
int written = 0;
UINT32 length = o->i + 5;
UINT8 buf[9];
uint32_t length = o->i + 5;
uint8_t buf[9];
WRITE_UINT32(buf, length);
buf[4] = o->msg;
......
......@@ -220,7 +220,7 @@ static void
sftp_put_longname_mode(struct sftp_output *o, struct stat *st)
{
/* A 10 character modestring and a space */
UINT8 modes[MODE_STRING_LENGTH];
uint8_t modes[MODE_STRING_LENGTH];
filemodestring(st, modes);
......@@ -229,12 +229,12 @@ sftp_put_longname_mode(struct sftp_output *o, struct stat *st)
static void
sftp_put_longname(struct sftp_ctx *ctx,
struct stat *st, const UINT8 *fname)
struct stat *st, const uint8_t *fname)
{
/* NOTE: The current spec doesn't mandate utf8. */
/* Where to store the length. */
UINT32 length_index = sftp_put_reserve_length(ctx->o);
uint32_t length_index = sftp_put_reserve_length(ctx->o);
const char *user_name;
const char *group_name;
time_t now, when;
......@@ -298,11 +298,11 @@ sftp_put_filename(struct sftp_ctx *ctx,
/* FIXME: We need to distinguish invalid messages from invalid file
names. */
static const UINT8 *
static const uint8_t *
sftp_get_name(struct sftp_input *i)
{
UINT8 *name;
UINT32 length;
uint8_t *name;
uint32_t length;
name = sftp_get_string_auto(i, &length);
if (!length)
......@@ -317,7 +317,7 @@ sftp_get_name(struct sftp_input *i)
}
static int
sftp_handle_used(struct sftp_ctx *ctx, UINT32 handle)
sftp_handle_used(struct sftp_ctx *ctx, uint32_t handle)
{
return (handle < SFTP_MAX_HANDLES)