| 388 | } |
| 389 | |
| 390 | void loadServerConfigFromString(char *config) { |
| 391 | const char *err = NULL; |
| 392 | int linenum = 0, totlines, i; |
| 393 | int slaveof_linenum = 0; |
| 394 | sds *lines; |
| 395 | int save_loaded = 0; |
| 396 | |
| 397 | lines = sdssplitlen(config,strlen(config),"\n",1,&totlines); |
| 398 | |
| 399 | for (i = 0; i < totlines; i++) { |
| 400 | sds *argv; |
| 401 | int argc; |
| 402 | |
| 403 | linenum = i+1; |
| 404 | lines[i] = sdstrim(lines[i]," \t\r\n"); |
| 405 | |
| 406 | /* Skip comments and blank lines */ |
| 407 | if (lines[i][0] == '#' || lines[i][0] == '\0') continue; |
| 408 | |
| 409 | /* Split into arguments */ |
| 410 | argv = sdssplitargs(lines[i],&argc); |
| 411 | if (argv == NULL) { |
| 412 | err = "Unbalanced quotes in configuration line"; |
| 413 | goto loaderr; |
| 414 | } |
| 415 | |
| 416 | /* Skip this line if the resulting command vector is empty. */ |
| 417 | if (argc == 0) { |
| 418 | sdsfreesplitres(argv,argc); |
| 419 | continue; |
| 420 | } |
| 421 | sdstolower(argv[0]); |
| 422 | |
| 423 | /* Iterate the configs that are standard */ |
| 424 | int match = 0; |
| 425 | for (standardConfig *config = configs; config->name != NULL; config++) { |
| 426 | if ((!strcasecmp(argv[0],config->name) || |
| 427 | (config->alias && !strcasecmp(argv[0],config->alias)))) |
| 428 | { |
| 429 | if (argc != 2) { |
| 430 | err = "wrong number of arguments"; |
| 431 | goto loaderr; |
| 432 | } |
| 433 | if (!config->interface.set(config->data, argv[1], 0, &err)) { |
| 434 | goto loaderr; |
| 435 | } |
| 436 | |
| 437 | match = 1; |
| 438 | break; |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | if (match) { |
| 443 | sdsfreesplitres(argv,argc); |
| 444 | continue; |
| 445 | } |
| 446 | |
| 447 | /* Execute config directives */ |
no test coverage detected