-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
============================================================================ | ||
Name : hev-socks5-user-mark.c | ||
Author : Heiher <[email protected]> | ||
Copyright : Copyright (c) 2023 hev | ||
Description : Socks5 User with mark | ||
============================================================================ | ||
*/ | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
============================================================================ | ||
Name : hev-socks5-user-mark.h | ||
Author : Heiher <[email protected]> | ||
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__ */ |