MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / loadServerConfigFromString

Function loadServerConfigFromString

src/config.cpp:477–827  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

475}
476
477void loadServerConfigFromString(char *config) {
478 const char *err = NULL;
479 int linenum = 0, totlines, i;
480 int slaveof_linenum = 0;
481 sds *lines;
482 int save_loaded = 0;
483
484 lines = sdssplitlen(config,strlen(config),"\n",1,&totlines);
485
486 for (i = 0; i < totlines; i++) {
487 sds *argv;
488 int argc;
489
490 linenum = i+1;
491 lines[i] = sdstrim(lines[i]," \t\r\n");
492
493 /* Skip comments and blank lines */
494 if (lines[i][0] == '#' || lines[i][0] == '\0') continue;
495
496 /* Split into arguments */
497 argv = sdssplitargs(lines[i],&argc);
498 if (argv == NULL) {
499 err = "Unbalanced quotes in configuration line";
500 goto loaderr;
501 }
502
503 /* Skip this line if the resulting command vector is empty. */
504 if (argc == 0) {
505 sdsfreesplitres(argv,argc);
506 continue;
507 }
508 sdstolower(argv[0]);
509
510 /* Iterate the configs that are standard */
511 int match = 0;
512 for (standardConfig *config = configs; config->name != NULL; config++) {
513 if ((!strcasecmp(argv[0],config->name) ||
514 (config->alias && !strcasecmp(argv[0],config->alias))))
515 {
516 if (argc != 2) {
517 err = "wrong number of arguments";
518 goto loaderr;
519 }
520 if (!config->interface.set(config->data, argv[1], 0, &err)) {
521 goto loaderr;
522 }
523
524 match = 1;
525 break;
526 }
527 }
528
529 if (match) {
530 sdsfreesplitres(argv,argc);
531 continue;
532 }
533
534 /* Execute config directives */

Callers 1

loadServerConfigFunction · 0.85

Calls 15

sdssplitlenFunction · 0.85
sdstrimFunction · 0.85
sdssplitargsFunction · 0.85
sdsfreesplitresFunction · 0.85
sdstolowerFunction · 0.85
zfreeFunction · 0.85
zstrdupFunction · 0.85
resetServerSaveParamsFunction · 0.85
appendServerSaveParamsFunction · 0.85
serverLogFunction · 0.85
sdscatprintfFunction · 0.85
sdsemptyFunction · 0.85

Tested by

no test coverage detected