use size_t where appropriate instead of unsigned int

This commit is contained in:
Sean Middleditch 2009-03-19 02:08:46 -04:00
parent 8daf77446e
commit 340a51b1e0
5 changed files with 29 additions and 31 deletions

8
README
View File

@ -87,7 +87,7 @@ IIa. Initialization
IIb. Receiving Data
void libtelnet_push(libtelnet_t *telnet,
const unsigned char *buffer, unsigned int size, void *user_data);
const char *buffer, unsigned int size, void *user_data);
When your application receives data over the socket from the
remote end, it must pass the received bytes into this function.
@ -125,12 +125,12 @@ IIc. Sending Data
negotiate.
void libtelnet_send_data(libtelnet_t *telnet,
const unsigned char *buffer, unsigned int size);
const char *buffer, unsigned int size);
Sends raw data, which would be either the process output from
a server or the user input from a client.
void libtelnet_send_subnegotiation(libtelnet_t *telnet,
unsigned char telopt, const unsigned char *buffer,
unsigned char telopt, const char *buffer,
unsigned int size);
Sends a TELNET sub-negotiation command. The telopt parameter
is the sub-negotiation option.
@ -187,7 +187,7 @@ IId. Event Handling
pointer passed to libtelnet_init().
struct libtelnet_event_t {
const unsigned char *buffer;
const char *buffer;
unsigned int size;
libtelnet_event_type_t type;
unsigned char command;

View File

@ -35,21 +35,21 @@
#define RFC1143_WANTYES_OP (RFC1143_WANTYES|RFC1143_OP)
/* buffer sizes */
static const unsigned int _buffer_sizes[] = {
static const size_t _buffer_sizes[] = {
0,
512,
2048,
8192,
16384,
};
static const unsigned int _buffer_sizes_count = sizeof(_buffer_sizes) /
static const size_t _buffer_sizes_count = sizeof(_buffer_sizes) /
sizeof(_buffer_sizes[0]);
/* event dispatch helper; return value is value of the accept field of the
* event struct after dispatch; used for the funky REQUEST event */
static int _event(libtelnet_t *telnet, libtelnet_event_type_t type,
unsigned char command, unsigned char telopt,
const char *buffer, unsigned int size) {
const char *buffer, size_t size) {
libtelnet_event_t ev;
ev.buffer = buffer;
ev.size = size;
@ -129,7 +129,7 @@ libtelnet_error_t _init_zlib(libtelnet_t *telnet, int deflate, int err_fatal) {
/* push bytes out, compressing them first if need be */
static void _send(libtelnet_t *telnet, const char *buffer,
unsigned int size) {
size_t size) {
#ifdef HAVE_ZLIB
/* if we have a deflate (compression) zlib box, use it */
if (telnet->z != 0 && telnet->flags & LIBTELNET_PFLAG_DEFLATE) {
@ -417,7 +417,7 @@ void libtelnet_free(libtelnet_t *telnet) {
static libtelnet_error_t _buffer_byte(libtelnet_t *telnet,
unsigned char byte) {
char *new_buffer;
unsigned int i;
size_t i;
/* check if we're out of room */
if (telnet->buffer_pos == telnet->buffer_size) {
@ -455,9 +455,9 @@ static libtelnet_error_t _buffer_byte(libtelnet_t *telnet,
}
static void _process(libtelnet_t *telnet, const char *buffer,
unsigned int size) {
size_t size) {
unsigned char byte;
unsigned int i, start;
size_t i, start;
for (i = start = 0; i != size; ++i) {
byte = buffer[i];
switch (telnet->state) {
@ -615,7 +615,7 @@ static void _process(libtelnet_t *telnet, const char *buffer,
/* push a bytes into the state tracker */
void libtelnet_push(libtelnet_t *telnet, const char *buffer,
unsigned int size) {
size_t size) {
#ifdef HAVE_ZLIB
/* if we have an inflate (decompression) zlib stream, use it */
if (telnet->z != 0 && !(telnet->flags & LIBTELNET_PFLAG_DEFLATE)) {
@ -797,8 +797,8 @@ void libtelnet_send_negotiate(libtelnet_t *telnet, unsigned char cmd,
/* send non-command data (escapes IAC bytes) */
void libtelnet_send_data(libtelnet_t *telnet, const char *buffer,
unsigned int size) {
unsigned int i, l;
size_t size) {
size_t i, l;
for (l = i = 0; i != size; ++i) {
/* dump prior portion of text, send escaped bytes */
@ -820,7 +820,7 @@ void libtelnet_send_data(libtelnet_t *telnet, const char *buffer,
/* send sub-request */
void libtelnet_send_subnegotiation(libtelnet_t *telnet, unsigned char telopt,
const char *buffer, unsigned int size) {
const char *buffer, size_t size) {
libtelnet_send_telopt(telnet, LIBTELNET_SB, telopt);
libtelnet_send_data(telnet, buffer, size);
libtelnet_send_command(telnet, LIBTELNET_SE);

View File

@ -136,7 +136,7 @@ typedef enum libtelnet_event_type_t libtelnet_event_type_t;
struct libtelnet_event_t {
/* data buffer: for DATA, SEND, SUBNEGOTIATION, and ERROR events */
const char *buffer;
unsigned int size;
size_t size;
/* type of event */
enum libtelnet_event_type_t type;
/* IAC command */
@ -172,9 +172,9 @@ struct libtelnet_t {
/* sub-request buffer */
char *buffer;
/* current size of the buffer */
unsigned int buffer_size;
size_t buffer_size;
/* current buffer write position (also length of buffer data) */
unsigned int buffer_pos;
size_t buffer_pos;
/* current state */
enum libtelnet_state_t state;
/* option flags */
@ -194,7 +194,7 @@ extern void libtelnet_free(libtelnet_t *telnet);
/* push a byte buffer into the state tracker */
extern void libtelnet_push(libtelnet_t *telnet, const char *buffer,
unsigned int size);
size_t size);
/* send an iac command */
extern void libtelnet_send_command(libtelnet_t *telnet, unsigned char cmd);
@ -212,7 +212,7 @@ extern void libtelnet_send_negotiate(libtelnet_t *telnet, unsigned char cmd,
/* send non-command data (escapes IAC bytes) */
extern void libtelnet_send_data(libtelnet_t *telnet,
const char *buffer, unsigned int size);
const char *buffer, size_t size);
/* send sub-request, equivalent to:
* libtelnet_send_telopt(telnet, LIBTELNET_SB, telopt)
@ -222,7 +222,7 @@ extern void libtelnet_send_data(libtelnet_t *telnet,
* thare are most easily implemented with a series of send_data calls.
*/
extern void libtelnet_send_subnegotiation(libtelnet_t *telnet,
unsigned char telopt, const char *buffer, unsigned int size);
unsigned char telopt, const char *buffer, size_t size);
/* begin sending compressed data (server only) */
extern void libtelnet_begin_compress2(libtelnet_t *telnet);

View File

@ -57,7 +57,7 @@ static void _input(char *buffer, int size) {
}
}
static void _send(int sock, const char *buffer, unsigned int size) {
static void _send(int sock, const char *buffer, size_t size) {
int rs;
/* send data */
@ -132,7 +132,7 @@ static void _event_handler(libtelnet_t *telnet, libtelnet_event_t *ev,
break;
/* error */
case LIBTELNET_EV_ERROR:
fprintf(stderr, "ERROR: %.*s\n", ev->size, ev->buffer);
fprintf(stderr, "ERROR: %s\n", ev->buffer);
exit(1);
default:
/* ignore */

View File

@ -129,8 +129,8 @@ static const char *get_opt(unsigned char opt) {
}
}
static void print_buffer(const char *buffer, unsigned int size) {
unsigned int i;
static void print_buffer(const char *buffer, size_t size) {
size_t i;
for (i = 0; i != size; ++i) {
if (buffer[i] == ' ' || (isprint(buffer[i]) && !isspace(buffer[i])))
printf("%c", (char)buffer[i]);
@ -142,7 +142,7 @@ static void print_buffer(const char *buffer, unsigned int size) {
}
}
static void _send(int sock, const char *buffer, unsigned int size) {
static void _send(int sock, const char *buffer, size_t size) {
int rs;
/* send data */
@ -227,7 +227,7 @@ static void _event_handler(libtelnet_t *telnet, libtelnet_event_t *ev,
printf("%s SUB %d (%s)", conn->name, (int)ev->telopt,
get_opt(ev->telopt));
if (ev->size > 0) {
printf(" [%u]: ", ev->size);
printf(" [%zi]: ", ev->size);
print_buffer(ev->buffer, ev->size);
}
printf(COLOR_NORMAL "\n");
@ -242,13 +242,11 @@ static void _event_handler(libtelnet_t *telnet, libtelnet_event_t *ev,
break;
/* warning */
case LIBTELNET_EV_WARNING:
printf("%s WARNING: %.*s" COLOR_NORMAL "\n", conn->name, ev->size,
ev->buffer);
printf("%s WARNING: %s" COLOR_NORMAL "\n", conn->name, ev->buffer);
break;
/* error */
case LIBTELNET_EV_ERROR:
printf("%s ERROR: %.*s" COLOR_NORMAL "\n", conn->name, ev->size,
ev->buffer);
printf("%s ERROR: %s" COLOR_NORMAL "\n", conn->name, ev->buffer);
exit(1);
}
}