Start making the code initialization logic
This commit is contained in:
parent
325116e15f
commit
018003ebd4
9 changed files with 65 additions and 4 deletions
|
@ -1 +1,7 @@
|
||||||
SUBDIRS = src
|
SUBDIRS = src
|
||||||
|
AM_CFLAGS = -std=c17
|
||||||
|
|
||||||
|
.PHONY: run
|
||||||
|
|
||||||
|
run:
|
||||||
|
./src/fckgw
|
||||||
|
|
|
@ -2,6 +2,5 @@ AC_INIT([fckgw],[1.0])
|
||||||
AC_CONFIG_SRCDIR([src/main.c])
|
AC_CONFIG_SRCDIR([src/main.c])
|
||||||
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
|
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
|
||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
CFLAGS="$CFLAGS -std=c17"
|
|
||||||
AC_CONFIG_FILES([Makefile src/Makefile])
|
AC_CONFIG_FILES([Makefile src/Makefile])
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
bin_PROGRAMS = fckgw
|
bin_PROGRAMS = fckgw
|
||||||
fckgw_SOURCES = main.c api_key.c
|
fckgw_SOURCES = main.c code.c
|
||||||
|
|
24
src/code.c
Normal file
24
src/code.c
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/random.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "code.h"
|
||||||
|
#include "errors.h"
|
||||||
|
|
||||||
|
int code_init(struct code *key) {
|
||||||
|
struct timespec ts;
|
||||||
|
|
||||||
|
if (clock_gettime(CLOCK_REALTIME, &ts) == -1) {
|
||||||
|
perror("Unable to read clock 'CLOCK_REALTIME'");
|
||||||
|
return ERR_CLOCK_READ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
key->unix_ts_sec = ts.tv_sec;
|
||||||
|
key->unix_ts_msec = ts.tv_nsec / 1000000;
|
||||||
|
key->purpose = ACCESS;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
23
src/code.h
Normal file
23
src/code.h
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#ifdef __SIZEOF_INT128__
|
||||||
|
typedef unsigned __int128 uint128_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum code_purpose {
|
||||||
|
ACCESS,
|
||||||
|
DISCOUNT,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct code {
|
||||||
|
time_t unix_ts_sec;
|
||||||
|
long unix_ts_msec;
|
||||||
|
enum code_purpose purpose;
|
||||||
|
uint16_t rand_a;
|
||||||
|
uint64_t rand_b;
|
||||||
|
};
|
||||||
|
|
||||||
|
int code_init(struct code *key);
|
||||||
|
|
||||||
|
uint128_t code_convert_to_num(struct code *key);
|
1
src/errors.h
Normal file
1
src/errors.h
Normal file
|
@ -0,0 +1 @@
|
||||||
|
#define ERR_CLOCK_READ 1
|
12
src/main.c
12
src/main.c
|
@ -1,6 +1,14 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <./api_key.h>
|
|
||||||
|
#include "code.h"
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
return 0;
|
struct code key;
|
||||||
|
|
||||||
|
int key_init_err = code_init(&key);
|
||||||
|
if (key_init_err != 0) {
|
||||||
|
return key_init_err;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("unix_ts_sec: %ld, unix_ts_nsec: %ld, purpose: %d\n", key.unix_ts_sec, key.unix_ts_msec, key.purpose);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue