Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

conn.h 2.1 KB
Newer Older
1 2
/* $Id$ */

3 4 5 6
#ifndef _CONN_H_
#define _CONN_H_

#include "sockwrap.h"
7
#include "threadwrap.h"
8

9 10
#include "bbslist.h"

11
extern char *conn_types[];
12
extern int conn_ports[];
13 14 15 16 17 18

enum {
	 CONN_TYPE_UNKNOWN
	,CONN_TYPE_RLOGIN
	,CONN_TYPE_TELNET
	,CONN_TYPE_RAW
deuce's avatar
deuce committed
19
	,CONN_TYPE_SSH
deuce's avatar
deuce committed
20
	,CONN_TYPE_MODEM
21 22 23
	,CONN_TYPE_TERMINATOR
};

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
struct conn_api {
	int (*connect)(struct bbslist *bbs);
	int (*close)(void);
	void (*binary_mode_on)(void);
	void (*binary_mode_off)(void);
	int log_level;
	int type;
	int input_thread_running;
	int output_thread_running;
	int terminate;
	unsigned char *rd_buf;
	size_t rd_buf_size;
	unsigned char *wr_buf;
	size_t wr_buf_size;
};

struct conn_buffer {
	unsigned char	*buf;
	size_t			bufsize;
	size_t			buftop;
	size_t			bufbot;
	pthread_mutex_t	mutex;
	sem_t			in_sem;
	sem_t			out_sem;
};

/*
 * Functions for stuff using connections
 */
53
int conn_recv(char *buffer, size_t buflen, unsigned int timeout);
54
int conn_peek(char *buffer, size_t buflen);
55
int conn_send(char *buffer, size_t buflen, unsigned int timeout);
56
int conn_connect(struct bbslist *bbs);
57
int conn_close(void);
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
BOOL conn_connected(void);
BOOL conn_data_waiting(void);
void conn_binary_mode_on(void);
void conn_binary_mode_off(void);

/*
 * For connection providers
 */

#define BUFFER_SIZE	16384

extern struct conn_buffer conn_inbuf;
extern struct conn_buffer conn_outbuf;
extern struct conn_api conn_api;

struct conn_buffer *create_conn_buf(struct conn_buffer *buf, size_t size);
void destroy_conn_buf(struct conn_buffer *buf);
size_t conn_buf_bytes(struct conn_buffer *buf);
size_t conn_buf_peek(struct conn_buffer *buf, unsigned char *outbuf, size_t outlen);
size_t conn_buf_get(struct conn_buffer *buf, unsigned char *outbuf, size_t outlen);
size_t conn_buf_put(struct conn_buffer *buf, const unsigned char *outbuf, size_t outlen);
size_t conn_buf_wait_cond(struct conn_buffer *buf, size_t bcount, unsigned long timeout, int free);
#define conn_buf_wait_bytes(buf, count, timeout)	conn_buf_wait_cond(buf, count, timeout, 0)
#define conn_buf_wait_free(buf, count, timeout)	conn_buf_wait_cond(buf, count, timeout, 1)
int conn_socket_connect(struct bbslist *bbs);
83 84

#endif