Mercurial > hg > nnchat
view libnnchat.h @ 106:c587a99e2096
Drop internal use and storage of encoded usernames.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 22 Oct 2010 12:07:15 +0300 |
parents | eaa524e153f9 |
children | 741e45592522 |
line wrap: on
line source
/* * NNChat - Custom chat client for NewbieNudes.com chatrooms * Written by Matti 'ccr' Hämäläinen * (C) Copyright 2008-2010 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; 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, ...); nn_userhash_t *nn_userhash_new(void); nn_user_t * nn_userhash_foreach(const nn_userhash_t *, int (*func)(const nn_user_t *)); nn_user_t * nn_user_match(const nn_userhash_t *list, const char *str, const char *current); int nn_userhash_insert(nn_userhash_t *, const char *name); int nn_userhash_delete(nn_userhash_t *, const char *name); void nn_userhash_free(nn_userhash_t *); void nn_user_free(nn_user_t *); void nn_user_free_list(nn_user_t *); nn_user_t * nn_user_copy(const nn_user_t *src); nn_user_t * nn_user_find(const nn_userhash_t *list, const char *name); 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); char * nn_editbuf_get_string(nn_editbuf_t *buf, ssize_t start, ssize_t end); #endif