diff --git a/README.md b/README.md index f70c7b5..5e891ce 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/cmoe.c b/cmoe.c index c934a97..536efe9 100644 --- a/cmoe.c +++ b/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."); diff --git a/cmoe.h b/cmoe.h index f97b58e..0c9a554 100644 --- a/cmoe.h +++ b/cmoe.h @@ -3,9 +3,6 @@ #include -#define DATFILE "dat.sp" -#define TOKEN "fumiama" - #define COUNTER_NAME_LEN 64 struct COUNTER { char name[COUNTER_NAME_LEN];