view libnnchat.h @ 65:e763ef5cfd53

Move more functions to libnnchat.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 11 Nov 2008 23:57:49 +0200
parents 6a3a917303e4
children 3ab7751fdad1
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
#warning Compiling for Windows
#include <winsock.h>
#else
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#endif
#include <sys/types.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;
} ringbuf_t;

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


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, ...);


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);


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

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


#endif