MCPcopy Create free account
hub / github.com/3proxy/3proxy / h_counter

Function h_counter

src/conf.c:394–432  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

392}
393
394static int h_counter(int argc, unsigned char **argv){
395 struct counter_header ch1;
396 if(conf.counterd >=0)close(conf.counterd);
397 if(!conf.trafcountfunc) conf.trafcountfunc = trafcountfunc;
398 conf.counterd = open((char *)argv[1], O_BINARY|O_RDWR|O_CREAT, 0660);
399 if(conf.counterd<0){
400 fprintf(stderr, "Unable to open counter file %s, line %d\n", argv[1], linenum);
401 return 1;
402 }
403 if(read(conf.counterd, &ch1, sizeof(ch1))==sizeof(ch1)){
404 if(memcmp(&ch1, &cheader, 4)){
405 fprintf(stderr, "Not a counter file %s, line %d\n", argv[1], linenum);
406 return 2;
407 }
408#ifdef _TIME64_T_DEFINED
409#ifdef _MAX__TIME64_T
410#define MAX_COUNTER_TIME (_MAX__TIME64_T)
411#elif defined (MAX__TIME64_T)
412#define MAX_COUNTER_TIME (MAX__TIME64_T)
413#else
414#define MAX_COUNTER_TIME (0x793406fff)
415#endif
416#else
417#define MAX_COUNTER_TIME ((sizeof(time_t)>4)?(time_t)0x793406fff:(time_t)0x7fffffff)
418#endif
419
420 if(ch1.updated < 0 || ch1.updated >= MAX_COUNTER_TIME){
421 fprintf(stderr, "Invalid or corrupted counter file %s. Use countersutil utility to convert from older version\n", argv[1]);
422 return 3;
423 }
424 cheader.updated = ch1.updated;
425 }
426 if(argc >=4) {
427 conf.countertype = getrotate(*argv[2]);
428 if(conf.counterfile) myfree(conf.counterfile);
429 conf.counterfile = mystrdup((char *)argv[3]);
430 }
431 return 0;
432}
433
434static int h_rotate(int argc, unsigned char **argv){
435 conf.rotate = atoi((char *)argv[1]);

Callers

nothing calls this directly

Calls 3

getrotateFunction · 0.85
myfreeFunction · 0.85
mystrdupFunction · 0.85

Tested by

no test coverage detected