1
0
mirror of https://github.com/fumiama/CMoe-Counter.git synced 2024-11-23 22:00:56 +01:00
This commit is contained in:
源文雨 2022-05-20 15:13:49 +08:00
parent f30d2af652
commit 6924c0dbd1
3 changed files with 8 additions and 4 deletions

View File

@ -40,11 +40,11 @@ make
simple-http-server -d port folder
```
### 5. Enjoy it!
You can change token and datafile by passing env `TOKEN` & `DATFILE`.
## API
The API of CMoe is simpler than [Moe-counter](https://github.com/journey-ad/Moe-counter)
### 1. Register
`token` is defined in `cmoe.h`
```
http://yourdomain/cmoe?name=yourname&reg=token
```

7
cmoe.c
View File

@ -10,6 +10,9 @@
static uint32_t* items_len;
static COUNTER counter;
static char* DATFILE = "dat.sp";
static char* TOKEN = "fumiama";
#define ADD_HEADER_PARAM(buf, offset, h, p) sprintf(buf + offset, (h), (p))
#define HEADER(content_type) HTTP200 SERVER_STRING CACHE_CTRL CONTENT_TYPE(content_type)
#define headers(content_len, content_type) (_headers(content_len, HEADER(content_type), sizeof(HEADER(content_type))-1))
@ -183,6 +186,10 @@ static int name_exist(char* name) {
// Usage: cmoe method query_string
int main(int argc, char **argv) {
if(argc == 3) {
char* str = getenv("DATFILE");
if(str != NULL) DATFILE = str;
str = getenv("TOKEN");
if(str != NULL) TOKEN = str;
char* name = strstr(QS, "name=");
items_len = align_struct(sizeof(COUNTER), 2, &counter.name, &counter.count);
if(!items_len) http_error(HTTP500, "Align Struct Error.");

3
cmoe.h
View File

@ -3,9 +3,6 @@
#include <stdint.h>
#define DATFILE "dat.sp"
#define TOKEN "fumiama"
#define COUNTER_NAME_LEN 64
struct COUNTER {
char name[COUNTER_NAME_LEN];