1
0
mirror of https://github.com/fumiama/CMoe-Counter.git synced 2024-11-24 06:10:11 +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 simple-http-server -d port folder
``` ```
### 5. Enjoy it! ### 5. Enjoy it!
You can change token and datafile by passing env `TOKEN` & `DATFILE`.
## API ## API
The API of CMoe is simpler than [Moe-counter](https://github.com/journey-ad/Moe-counter) The API of CMoe is simpler than [Moe-counter](https://github.com/journey-ad/Moe-counter)
### 1. Register ### 1. Register
`token` is defined in `cmoe.h`
``` ```
http://yourdomain/cmoe?name=yourname&reg=token http://yourdomain/cmoe?name=yourname&reg=token
``` ```

7
cmoe.c
View File

@ -10,6 +10,9 @@
static uint32_t* items_len; static uint32_t* items_len;
static COUNTER counter; 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 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 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)) #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 // Usage: cmoe method query_string
int main(int argc, char **argv) { int main(int argc, char **argv) {
if(argc == 3) { 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="); char* name = strstr(QS, "name=");
items_len = align_struct(sizeof(COUNTER), 2, &counter.name, &counter.count); items_len = align_struct(sizeof(COUNTER), 2, &counter.name, &counter.count);
if(!items_len) http_error(HTTP500, "Align Struct Error."); if(!items_len) http_error(HTTP500, "Align Struct Error.");

3
cmoe.h
View File

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