catalinux / Conn (public) (License: LGPLv2) (since 2016-03-01) (hash sha1)
Net library for easy building ipv4/ipv6 network daemons/clients

/Conn.h (eeed3b0c1d148829337ae265d8fe5d7f8b01e99a) (6098 bytes) (mode 100644) (type blob)

#ifndef _Conn_h
#define _Conn_h 1

#include "Conn_config.h"

#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/socket.h>

struct Conn;
struct Conn_wpool;
struct Conn_split;
struct Conn_ws;

/* Parameters */
enum CONN_PARA {
        CONN_PARA_AUTO_RECONNECT = 0,
	CONN_PARA_RECONNECT_DELAY,
	CONN_PARA_IDLE_TIME,
	CONN_PARA_READ_TIMEOUT,
	CONN_PARA_CONN_TIMEOUT,
	CONN_PARA_TRIGGER,
	CONN_PARA_IBUF,
	CONN_PARA_OBUF
};

/* Callbacks */
enum CONN_CB {
	CONN_CB_ACCEPT = 0,
	CONN_CB_RECV,
	CONN_CB_SEND,
	CONN_CB_DATA,
	CONN_CB_CLOSE,
	CONN_CB_TRIGGER,
	CONN_CB_ERROR,
	CONN_CB_CONNECTED,
	CONN_CB_ACCEPT_ERROR,
	CONN_CB_WORKER_START
};

/* misc */
void		Log_simple(const unsigned short level, const char *msg);
void		Log(const unsigned short level, char *format, ...);
char		*Conn_dump(const void *buf_src0, const size_t len_src);
char		*Conn_dumphex(const void *buf_src0, const size_t len_src);
int		Conn_hex2bin(unsigned char *out, const size_t out_size,
			const char *hex);
void		Conn_debug(int fd, const unsigned short debug);


/* split */
void			Conn_split_free(struct Conn_split **s);
struct Conn_split	*Conn_split(const char *line0);
char			*Conn_split_get_size(const struct Conn_split *s,
					const char *left, unsigned int *size);
char			*Conn_split_get_e(const struct Conn_split *s,
					const char *l);
char			*Conn_split_get(const struct Conn_split *s,
					const char *l);
unsigned long		Conn_split_get_ul(const struct Conn_split *s,
					const char *l, unsigned int base);
unsigned long long	Conn_split_get_ull(const struct Conn_split *s,
					const char *l, unsigned int base);
double			Conn_split_get_d(const struct Conn_split *s,
					const char *l);

/* conn */
unsigned long long	Conn_lifetime(struct Conn *C);
char			*Conn_strerror(void);
void			Conn_set_error(const char *format, ...);
long long		Conn_time_diff(const struct timeval *t1,
				const struct timeval *t2);
char			*Conn_errno(const struct Conn *C);
char			*Conn_status(const unsigned int flags);

void			Conn_set_private(struct Conn *C, void *priv);
void			*Conn_get_private(struct Conn *C);
unsigned int		Conn_iqlen(const struct Conn *C);
unsigned int		Conn_oqlen(const struct Conn *C);
unsigned int		Conn_qlen(const struct Conn *C);
int			Conn_nodelay(const struct Conn *C);
void			Conn_rollback(struct Conn *C, const unsigned int bytes);
char			*Conn_ibuf(const struct Conn *C);
char			*Conn_obuf(const struct Conn *C);
unsigned long long	Conn_getid(const struct Conn *C); /* Obsolete */
unsigned long long	Conn_get_id(const struct Conn *C);
struct Conn		*Conn_get(const unsigned long long id);
void			Conn_last_time(const struct Conn *C, struct timeval *tv);
int			Conn_set_cb(struct Conn *C, const unsigned int cb_type,
				void (*f)(struct Conn *));
char			*Conn_ostrstr(struct Conn *C, const unsigned int off,
				const char *str, const unsigned int flags);
char			*Conn_strstr(struct Conn *C, const char *str);
char			*Conn_strcasestr(struct Conn *C, const char *str);
char			*Conn_get_line(struct Conn *C);
void			Conn_for_every_line(struct Conn *C,
				void (*cb)(struct Conn *C, char *line));
int			Conn_printf(struct Conn *C, const char *format, ...);
void			Conn_eat(struct Conn *C, const unsigned int bytes);
void			Conn_eatall(struct Conn *C);
void			Conn_send_done(struct Conn *C);
void			Conn_close(struct Conn *C);
void			Conn_stop(void);
int			Conn_get_fd(const struct Conn *C);
void			Conn_set(struct Conn *C, const unsigned int var,
				const int val);
char			*Conn_addr_local(struct Conn *C);
char			*Conn_addr_remote(struct Conn *C);
int			Conn_port_local(struct Conn *C);
int			Conn_port_remote(struct Conn *C);
int			Conn_addr_family(const char *addr);

/* wpool */
struct Conn_wpool	*Conn_wpool_create(const unsigned short workers);
int			Conn_wpool_destroy(struct Conn_wpool *wp);
void			Conn_set_wp(struct Conn *C, struct Conn_wpool *wp);
void			Conn_del_wp(struct Conn *C, struct Conn_wpool *wp);

/* conn 2 */
int		Conn_init(const unsigned int max);
int		Conn_shutdown(void);
int		Conn_enqueue_wait(struct Conn *C, const void *buf,
			const unsigned int count);
int		Conn_enqueue(struct Conn *C, const void *buf,
			const unsigned int count);
void		Conn_kick(struct Conn *C);
struct Conn	*Conn_alloc(void);
int		Conn_set_socket_domain(struct Conn *C, const int domain);
int		Conn_set_socket_type(struct Conn *C, const int type);
int		Conn_set_socket_protocol(struct Conn *C, const int proto);
int		Conn_set_socket_bind_addr(struct Conn *C, const char *addr);
int		Conn_set_socket_addr(struct Conn *C, const char *addr);
int		Conn_set_socket_bind_port(struct Conn *C, const int port);
int		Conn_set_socket_port(struct Conn *C, const int port);
int		Conn_commit(struct Conn *C);
struct Conn	*Conn_socket_addr(const int domain, const int type,
			const char *addr, const int port);
struct Conn	*Conn_socket(const int domain, const int type,
			const int port);
struct Conn	*Conn_connect(const int domain, const int type,
			const char *addr, const int port);
int		Conn_band(struct Conn *C, const unsigned int width,
			const unsigned int factor);
int		Conn_poll(const int timeout);

/* web server */
char		*Conn_web_escape(const char *s);
int		Conn_web_create(struct Conn *C);
int		Conn_web_script(struct Conn *C, const char *url,
			void(*cb)(struct Conn *C));
int		Conn_web_path(struct Conn *C, const char *url,
			const char *path);
char		*Conn_web_header(const struct Conn *C);
int		Conn_web_header_lookup(char *out, const size_t out_size,
			const struct Conn *C, const char *h);


/* web server - websocket */
struct Conn_web_ws
{
	unsigned int		fin:1;
	unsigned int		opcode:4;
	unsigned int		mask:1;
	unsigned int		pad:26;
	unsigned char		maskkey[4];
	unsigned long long	len;
};

char		Conn_web_is_ws(const struct Conn *C);
void		Conn_web_ws_negociate(struct Conn *C);
void		Conn_web_ws_enqueue(struct Conn *C,
			const unsigned char opcode, const unsigned char final,
			const char *s, const unsigned int len);
void		Conn_web_ws_log(const struct Conn_web_ws *w);
int		Conn_web_ws_parse(struct Conn_web_ws *w, struct Conn *C);

#endif


Mode Type Size Ref File
100644 blob 129 38f2534580e0aace0e6a5b49d79ada2c2ca162be .exclude
100644 blob 162 30a78e3a392ae33217d139ce27c4e1ebd04aa6e0 .gitignore
100644 blob 169 c003c095218f64ad33aeb89987f61eb575557d96 .mailmap
100644 blob 1945 fecf0e7a7e8580485101a179685aedc7e00affbb Changelog.pre109
100644 blob 81468 04121fc5d4ad5c21b6e12114219185324515d768 Conn.c
100644 blob 6098 eeed3b0c1d148829337ae265d8fe5d7f8b01e99a Conn.h
100644 blob 905 884fa11125512f99984f40735af6c380330f871c Conn.spec.in
100644 blob 747 662c3f3fe8d0a3d23770631d7a0a260719d81e62 Conn_config.h.in
100644 blob 5546 7bc5f77db036d7714b28600ffd90ab4c5ee080e2 Conn_intern.h
100644 blob 12764 d7f5dfa1fc74f110cd31ed7433fbe4237d47cc84 Conn_web.c
100644 blob 93 4754320eef2b558b97b9c75bd01e545f102670b7 Conn_web.h
100644 blob 30 d987fa5df957830331139935d517009e2911b0cf INSTALL
100644 blob 25275 92b8903ff3fea7f49ef5c041b67a087bca21c5ec LICENSE
100644 blob 1261 fb7abee03563c44f3c579a4ada10e0826d5f3ebe Makefile.in
100644 blob 29 e214257f87a28e8fb0413b627cf7ee76ade2e94c Makefile.include.in
100644 blob 200 02d1f3eebc03e84013c23a35db5fe3b77f12f0cc README
100644 blob 19668 bf0f19113acc021dcdc92af4be32b2c737b362a7 TODO
100755 blob 30 92c4bc48245c00408cd7e1fd89bc1a03058f4ce4 configure
040000 tree - d4c9c4a69c5cfa2a84316967185f1661b6817779 docs
100755 blob 18252 e2438615edba7066a730ed6a796a5302263f1f37 duilder
100644 blob 1414 54b2baeaf7fbb58783b5588ab07ea8d547aef645 duilder.conf
040000 tree - b255bf8fe16832bbbb513181b1dc6ae9420deed1 examples
040000 tree - 5643f06c34660e576e6c5d0dee5ac74a2bf34f51 tests
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/catalinux/Conn

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/catalinux/Conn

Clone this repository using git:
git clone git://git.rocketgit.com/user/catalinux/Conn

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main