view libnnchat.h @ 100:ed4067c10a8a

Remove useless buffer usage from error reporting function.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 17 Nov 2009 23:09:10 +0200
parents 218efd2f0641
children b096ae97fc7d
line wrap: on
line source

/*
 * NNChat - Custom chat client for NewbieNudes.com chatrooms
 * Written by Matti 'ccr' Hämäläinen
 * (C) Copyright 2008 Tecnic Software productions (TNSP)
 */
#ifndef LIBNNCHAT_H
#define LIBNNCHAT_H

#include <stdio.h>
#include <unistd.h>
#ifdef __WIN32
#include <windows.h>
#include <winsock.h>
#else
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#endif
#include <sys/types.h>
#include <time.h>
#include <errno.h>
#include "th_string.h"

#define SET_BUFSIZE     (4096)
#define SET_ALLOC_SIZE  (128)

typedef struct {
    char **data;
    size_t n, size;
} nn_ringbuf_t;

typedef struct {
    ssize_t pos, len, size;
    char *data;
} nn_editbuf_t;

typedef struct _nn_user_t {
    char *name, *encname;
    time_t lastspoke, joined;
    struct _nn_user_t *next;
} nn_user_t;

#define NN_NUM_BUCKETS (256)

typedef struct {
    nn_user_t *buckets[NN_NUM_BUCKETS];
} nn_userhash_t;


#ifdef __WIN32
const char *hstrerror(int err);
#endif
int         nn_get_socket_errno(void);
const char *nn_get_socket_errstr(int err);
BOOL        nn_network_init(void);
void        nn_network_close(void);

int         nn_open_connection(struct in_addr *addr, const int port);
void        nn_close_connection(const int sock);
BOOL        nn_send_to_socket(const int sock, char *buf, const size_t bufLen);
BOOL        nn_send_msg(const int sock, const char *user, const char *fmt, ...);

int         addUserToHash(nn_userhash_t **, char *encname);
void        freeUserHash(nn_userhash_t *);
void        freeUserList(nn_user_t *);
nn_user_t * copyUser(nn_user_t *src);
nn_user_t * findUserEnc(nn_userhash_t *list, char *encname);
nn_user_t * matchUsersEnc(nn_userhash_t *list, char *encname, int index);

char *      nn_encode_str1(const char *str);
char *      nn_decode_str1(const char *str);
char *      nn_encode_str2(const char *str);
char *      nn_decode_str2(const char *str);
char *      nn_strip_tags(const char *str);
char *      nn_dbldecode_str(const char *str);
char *      nn_dblencode_str(const char *str);


nn_ringbuf_t * nn_ringbuf_new(const size_t size);
void        nn_ringbuf_free(nn_ringbuf_t *buf);
void        nn_ringbuf_add(nn_ringbuf_t *buf, const char *str);

int         nn_editbuf_write(nn_editbuf_t *buf, ssize_t pos, int ch);
int         nn_editbuf_insert(nn_editbuf_t *buf, ssize_t pos, int ch);
int         nn_editbuf_delete(nn_editbuf_t *buf, ssize_t pos);
void        nn_editbuf_clear(nn_editbuf_t *buf);
nn_editbuf_t * nn_editbuf_new(ssize_t n);
void        nn_editbuf_free(nn_editbuf_t *buf);
nn_editbuf_t * nn_editbuf_copy(nn_editbuf_t *src);
void        nn_editbuf_setpos(nn_editbuf_t *buf, ssize_t pos);


#endif