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

Function readconfig

src/conf.c:1513–1569  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1511
1512
1513int readconfig(FILE * fp){
1514 unsigned char ** argv = NULL;
1515 unsigned char * buf = NULL;
1516 int bufsize = STRINGBUF*2;
1517 int inbuf = 0;
1518 int argc;
1519 struct commands * cm;
1520 int res = 0;
1521
1522 if( !(buf = myalloc(bufsize)) || ! (argv = myalloc((NPARAMS + 1) * sizeof(unsigned char *))) ) {
1523 fprintf(stderr, "No memory for configuration");
1524 return(10);
1525 }
1526 for (linenum = 1; fgets((char *)buf, STRINGBUF, fp); linenum++){
1527 if(!*buf || isspace(*buf) || (*buf) == '#')continue;
1528
1529 inbuf = (int)(strlen((char *)buf) + 1);
1530 argc = parsestr (buf, argv, NPARAMS-1, &buf, &inbuf, &bufsize);
1531 if(argc < 1) {
1532 fprintf(stderr, "Parse error line %d\n", linenum);
1533 return(21);
1534 }
1535 argv[argc] = NULL;
1536 if(!strcmp((char *)argv[0], "end") && argc == 1) {
1537 break;
1538 }
1539 else if(!strcmp((char *)argv[0], "writable") && argc == 1) {
1540 if(!writable){
1541 writable = freopen(curconf, "r+", fp);
1542 if(!writable){
1543 fprintf(stderr, "Unable to reopen config for writing: %s\n", curconf);
1544 return 1;
1545 }
1546 }
1547 continue;
1548 }
1549
1550 res = 1;
1551 for(cm = commandhandlers; cm; cm = cm->next){
1552 if(!strcmp((char *)argv[0], (char *)cm->command) && argc >= cm->minargs && (!cm->maxargs || argc <= cm->maxargs)){
1553 res = (*cm->handler)(argc, argv);
1554 if(res > 0){
1555 fprintf(stderr, "Command: '%s' failed with code %d, line %d\n", argv[0], res, linenum);
1556 return(linenum);
1557 }
1558 if(!res) break;
1559 }
1560 }
1561 if(res != 1)continue;
1562 fprintf(stderr, "Unknown command: '%s' line %d\n", argv[0], linenum);
1563 return(linenum);
1564 }
1565 myfree(buf);
1566 myfree(argv);
1567 return 0;
1568
1569}
1570

Callers 3

WinMainFunction · 0.85
h_includeFunction · 0.85
reloadFunction · 0.85

Calls 3

myallocFunction · 0.85
parsestrFunction · 0.85
myfreeFunction · 0.85

Tested by

no test coverage detected