Skip to content

Commit

Permalink
HevSocks5UserMark: Init.
Browse files Browse the repository at this point in the history
  • Loading branch information
heiher committed Sep 16, 2023
1 parent ffd49c8 commit e9918ba
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 0 deletions.
87 changes: 87 additions & 0 deletions src/hev-socks5-user-mark.c
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;
}
54 changes: 54 additions & 0 deletions src/hev-socks5-user-mark.h
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__ */

0 comments on commit e9918ba

Please sign in to comment.