diff options
author | Uros Majstorovic <majstor@majstor.org> | 2024-05-03 00:09:19 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2024-05-03 00:09:19 +0200 |
commit | bcbcf079787bb37277769738a2edbaaee63f44c4 (patch) | |
tree | 91a7492c96006af40099f149caf305c315585d93 /ecp | |
parent | bda8ca03b59ac130b264f7ad39a10bb540e93a0a (diff) |
added user flags for connection
Diffstat (limited to 'ecp')
-rw-r--r-- | ecp/src/ecp/core.c | 72 | ||||
-rw-r--r-- | ecp/src/ecp/core.h | 11 |
2 files changed, 81 insertions, 2 deletions
diff --git a/ecp/src/ecp/core.c b/ecp/src/ecp/core.c index 69743fe..7166a44 100644 --- a/ecp/src/ecp/core.c +++ b/ecp/src/ecp/core.c @@ -935,15 +935,83 @@ void ecp_conn_init(ECPConnection *conn, ECPSocket *sock, unsigned char ctype) { } void ecp_conn_set_flags(ECPConnection *conn, unsigned char flags) { - flags &= ECP_CONN_FLAG_MASK; conn->flags_im |= flags; } void ecp_conn_clr_flags(ECPConnection *conn, unsigned char flags) { - flags &= ECP_CONN_FLAG_MASK; conn->flags_im &= ~flags; } +int ecp_conn_test_flags(ECPConnection *conn, unsigned char flags) { + return !!(conn->flags_im & flags); +} + +int _ecp_conn_set_uflags(ECPConnection *conn, unsigned char flags) { + if (flags & ~ECP_CONN_FLAG_UMASK) return ECP_ERR; + conn->flags |= flags; + return ECP_OK; +} + +int _ecp_conn_clr_uflags(ECPConnection *conn, unsigned char flags) { + if (flags & ~ECP_CONN_FLAG_UMASK) return ECP_ERR; + conn->flags &= ~flags; + return ECP_OK; +} + +int _ecp_conn_test_uflags(ECPConnection *conn, unsigned char flags) { + return !!(conn->flags & flags); +} + +int ecp_conn_set_uflags(ECPConnection *conn, unsigned char flags) { + int rv; + + pthread_mutex_lock(&conn->mutex); + rv = _ecp_conn_set_uflags(conn, flags); + pthread_mutex_unlock(&conn->mutex); + + return rv; +} + +int ecp_conn_clr_uflags(ECPConnection *conn, unsigned char flags) { + int rv; + + pthread_mutex_lock(&conn->mutex); + rv = _ecp_conn_clr_uflags(conn, flags); + pthread_mutex_unlock(&conn->mutex); + + return rv; +} + +int ecp_conn_test_uflags(ECPConnection *conn, unsigned char flags) { + int rv; + + pthread_mutex_lock(&conn->mutex); + rv = _ecp_conn_test_uflags(conn, flags); + pthread_mutex_unlock(&conn->mutex); + + return rv; +} + +int ecp_conn_is_reg(ECPConnection *conn) { + int rv; + + pthread_mutex_lock(&conn->mutex); + rv = _ecp_conn_is_reg(conn); + pthread_mutex_unlock(&conn->mutex); + + return rv; +} + +int ecp_conn_is_open(ECPConnection *conn) { + int rv; + + pthread_mutex_lock(&conn->mutex); + rv = _ecp_conn_is_open(conn); + pthread_mutex_unlock(&conn->mutex); + + return rv; +} + void ecp_conn_set_remote_key(ECPConnection *conn, ECPDHPub *key) { conn->remote.key_perma = *key; } diff --git a/ecp/src/ecp/core.h b/ecp/src/ecp/core.h index 212bee1..4d4c38a 100644 --- a/ecp/src/ecp/core.h +++ b/ecp/src/ecp/core.h @@ -161,6 +161,8 @@ #define ECP_CONN_FLAG_OPEN 0x02 #define ECP_CONN_FLAG_GCT 0x04 +#define ECP_CONN_FLAG_UMASK 0xF0 + #define ECP_SEND_FLAG_REPLY 0x01 #define ECP_SEND_FLAG_MORE 0x02 @@ -403,6 +405,15 @@ ECPConnection *ecp_conn_new_inb(ECPSocket *sock, unsigned char ctype); void ecp_conn_init(ECPConnection *conn, ECPSocket *sock, unsigned char ctype); void ecp_conn_set_flags(ECPConnection *conn, unsigned char flags); void ecp_conn_clr_flags(ECPConnection *conn, unsigned char flags); +int ecp_conn_test_flags(ECPConnection *conn, unsigned char flags); +int _ecp_conn_set_uflags(ECPConnection *conn, unsigned char flags); +int _ecp_conn_clr_uflags(ECPConnection *conn, unsigned char flags); +int _ecp_conn_test_uflags(ECPConnection *conn, unsigned char flags); +int ecp_conn_set_uflags(ECPConnection *conn, unsigned char flags); +int ecp_conn_clr_uflags(ECPConnection *conn, unsigned char flags); +int ecp_conn_test_uflags(ECPConnection *conn, unsigned char flags); +int ecp_conn_is_reg(ECPConnection *conn); +int ecp_conn_is_open(ECPConnection *conn); void ecp_conn_set_remote_key(ECPConnection *conn, ECPDHPub *key); void ecp_conn_set_remote_addr(ECPConnection *conn, ecp_tr_addr_t *addr); int ecp_conn_create(ECPConnection *conn, ECPConnection *parent); |