mirror of
https://github.com/fumiama/CMoe-Counter.git
synced 2024-11-27 23:20:49 +01:00
add env
This commit is contained in:
parent
f30d2af652
commit
6924c0dbd1
@ -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®=token
|
||||
```
|
||||
|
7
cmoe.c
7
cmoe.c
@ -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.");
|
||||
|
Loading…
Reference in New Issue
Block a user