授权管理使用共享内存支持主从模式

This commit is contained in:
luwenpeng
2023-06-20 21:49:58 +08:00
parent 61233aac97
commit 4c8c7f8759
17 changed files with 430 additions and 138 deletions

View File

@@ -0,0 +1,69 @@
#ifndef _HASP_LOG_H
#define _HASP_LOG_H
#ifdef __cpluscplus
extern "C"
{
#endif
#include <time.h>
#include <stdio.h>
#if ENABLD_LOG_FIEL
#define LOG_FILE(time, format, ...) \
{ \
FILE *fp = fopen("licenses.log", "a+"); \
if (fp == NULL) \
{ \
break; \
} \
fprintf(fp, "%s " format "\n", time, ##__VA_ARGS__); \
fflush(fp); \
fclose(fp); \
}
#else
#define LOG_FILE(time, format, ...)
#endif
#define LOG_STOUT(time, format, ...) \
{ \
fprintf(stderr, "%s " format "\n", time, ##__VA_ARGS__); \
}
#define LOG_INFO(format, ...) \
do \
{ \
char buffer[64] = {0}; \
local_time_string(buffer, sizeof(buffer)); \
LOG_STOUT(buffer, format, ##__VA_ARGS__); \
LOG_FILE(buffer, format, ##__VA_ARGS__); \
} while (0)
static void local_time_string(char *buff, int size)
{
static unsigned char weekday_str[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
static unsigned char month_str[12][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
time_t now;
struct tm local_time;
time(&now);
if (NULL == (localtime_r(&now, &local_time)))
{
return;
}
snprintf(buff, size,
"%s %s %d %02d:%02d:%02d %d",
weekday_str[local_time.tm_wday],
month_str[local_time.tm_mon],
local_time.tm_mday,
local_time.tm_hour,
local_time.tm_min,
local_time.tm_sec,
local_time.tm_year + 1900);
}
#ifdef __cpluscplus
}
#endif
#endif

View File

@@ -0,0 +1,23 @@
#ifndef _HASP_SHM_H
#define _HASP_SHM_H
#ifdef __cpluscplus
extern "C"
{
#endif
struct hasp_shm;
struct hasp_shm *hasp_shm_new(const char *name);
void hasp_shm_free(struct hasp_shm *shm);
void hasp_shm_lock(struct hasp_shm *shm);
void hasp_shm_unlock(struct hasp_shm *shm);
void hasp_shm_write(struct hasp_shm *shm, char *data, int len);
void hasp_shm_read(struct hasp_shm *shm, char *buff, int size);
#ifdef __cpluscplus
}
#endif
#endif

View File

@@ -8,7 +8,8 @@ extern "C"
#include <stdint.h>
void hasp_verify(uint64_t feature_id, uint64_t interval_s);
void hasp_monitor(uint64_t feature_id, uint64_t interval);
void hasp_verify(uint64_t feature_id);
#ifdef __cpluscplus
}