From e9918ba0a397dcd6135dad9d9e08b25b3a32db70 Mon Sep 17 00:00:00 2001 From: hev Date: Sat, 16 Sep 2023 19:41:41 -0600 Subject: [PATCH] HevSocks5UserMark: Init. --- src/hev-socks5-user-mark.c | 87 ++++++++++++++++++++++++++++++++++++++ src/hev-socks5-user-mark.h | 54 +++++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 src/hev-socks5-user-mark.c create mode 100644 src/hev-socks5-user-mark.h diff --git a/src/hev-socks5-user-mark.c b/src/hev-socks5-user-mark.c new file mode 100644 index 000000000..535a14e31 --- /dev/null +++ b/src/hev-socks5-user-mark.c @@ -0,0 +1,87 @@ +/* + ============================================================================ + Name : hev-socks5-user-mark.c + Author : Heiher + Copyright : Copyright (c) 2023 hev + Description : Socks5 User with mark + ============================================================================ + */ + +#include +#include + +#include "hev-logger.h" + +#include "hev-socks5-user-mark.h" + +HevSocks5UserMark * +hev_socks5_user_mark_new (const char *name, unsigned int name_len, + const char *pass, unsigned int pass_len, + unsigned int mark) +{ + HevSocks5UserMark *self; + int res; + + self = calloc (1, sizeof (HevSocks5UserMark)); + if (!self) + return NULL; + + res = hev_socks5_user_mark_construct (self, name, name_len, pass, pass_len, + mark); + if (res < 0) { + free (self); + return NULL; + } + + LOG_D ("%p socks5 user mark new", self); + + return self; +} + +int +hev_socks5_user_mark_construct (HevSocks5UserMark *self, const char *name, + unsigned int name_len, const char *pass, + unsigned int pass_len, unsigned int mark) +{ + int res; + + res = + hev_socks5_user_construct (&self->base, name, name_len, pass, pass_len); + if (res < 0) + return res; + + LOG_D ("%p socks5 user mark construct", self); + + HEV_OBJECT (self)->klass = HEV_SOCKS5_USER_MARK_TYPE; + + self->mark = mark; + + return 0; +} + +static void +hev_socks5_user_mark_destruct (HevObject *base) +{ + HevSocks5UserMark *self = HEV_SOCKS5_USER_MARK (base); + + LOG_D ("%p socks5 user mark destruct", self); + + HEV_SOCKS5_USER_TYPE->finalizer (base); +} + +HevObjectClass * +hev_socks5_user_mark_class (void) +{ + static HevSocks5UserMarkClass klass; + HevSocks5UserMarkClass *kptr = &klass; + HevObjectClass *okptr = HEV_OBJECT_CLASS (kptr); + + if (!okptr->name) { + memcpy (kptr, HEV_SOCKS5_USER_TYPE, sizeof (HevSocks5UserClass)); + + okptr->name = "HevSocks5UserMark"; + okptr->finalizer = hev_socks5_user_mark_destruct; + } + + return okptr; +} diff --git a/src/hev-socks5-user-mark.h b/src/hev-socks5-user-mark.h new file mode 100644 index 000000000..762993523 --- /dev/null +++ b/src/hev-socks5-user-mark.h @@ -0,0 +1,54 @@ +/* + ============================================================================ + Name : hev-socks5-user-mark.h + Author : Heiher + Copyright : Copyright (c) 2023 hev + Description : Socks5 User with mark + ============================================================================ + */ + +#ifndef __HEV_SOCKS5_USER_MARK_H__ +#define __HEV_SOCKS5_USER_MARK_H__ + +#include "hev-socks5-user.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define HEV_SOCKS5_USER_MARK(p) ((HevSocks5UserMark *)p) +#define HEV_SOCKS5_USER_MARK_CLASS(p) ((HevSocks5UserMarkClass *)p) +#define HEV_SOCKS5_USER_MARK_TYPE (hev_socks5_user_mark_class ()) + +typedef struct _HevSocks5UserMark HevSocks5UserMark; +typedef struct _HevSocks5UserMarkClass HevSocks5UserMarkClass; + +struct _HevSocks5UserMark +{ + HevSocks5User base; + + unsigned int mark; +}; + +struct _HevSocks5UserMarkClass +{ + HevSocks5UserClass base; +}; + +HevObjectClass *hev_socks5_user_mark_class (void); + +int hev_socks5_user_mark_construct (HevSocks5UserMark *self, const char *name, + unsigned int name_len, const char *pass, + unsigned int pass_len, unsigned int mark); + +HevSocks5UserMark *hev_socks5_user_mark_new (const char *name, + unsigned int name_len, + const char *pass, + unsigned int pass_len, + unsigned int mark); + +#ifdef __cplusplus +} +#endif + +#endif /* __HEV_SOCKS5_USER_MARK_H__ */