view libnnchat.h @ 90:1e0bf7b4fd41

Move socket error handling functions to libnnchat.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 06 May 2009 23:55:21 +0300
parents c2d916b340bf
children acfc4b4bc180
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 {
    char *name, *encname;
    time_t lastspoke, joined;
} nn_user_t;


#ifdef __WIN32
const char *hstrerror(int err);
#endif
int         getSocketErrno(void);
const char *getSocketErrStr(int err);

int         openConnection(struct in_addr *addr, const int port);
void        closeConnection(const int sock);
BOOL        sendToSocket(const int sock, char *buf, const size_t bufLen);
BOOL        sendUserMsg(const int sock, const char *user, const char *fmt, ...);

int         addUser(nn_user_t **list, char *encname);
int         freeUser(nn_user_t *);
int         freeUserList(nn_user_t *);

char *      encodeStr1(const char *str);
char *      decodeStr1(const char *str);
char *      encodeStr2(const char *str);
char *      decodeStr2(const char *str);
char *      stripXMLTags(const char *str);
char *      doubleDecodeStr(const char *str);
char *      doubleEncodeStr(const char *str);


nn_ringbuf_t * newRingBuf(const size_t size);
void        freeRingBuf(nn_ringbuf_t *buf);
void        addRingBuf(nn_ringbuf_t *buf, const char *str);

int         writeBuf(nn_editbuf_t *buf, ssize_t pos, int ch);
int         insertBuf(nn_editbuf_t *buf, ssize_t pos, int ch);
int         deleteBuf(nn_editbuf_t *buf, ssize_t pos);
void        clearBuf(nn_editbuf_t *buf);
nn_editbuf_t * newBuf(ssize_t n);
void        freeBuf(nn_editbuf_t *buf);
nn_editbuf_t * copyBuf(nn_editbuf_t *src);
void        setBufPos(nn_editbuf_t *buf, ssize_t pos);


#endif