MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / parse_opensips_cfg

Function parse_opensips_cfg

cfg_pp.c:64–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62 char *line, int len);
63
64int parse_opensips_cfg(const char *cfg_file, const char *preproc_cmdline,
65 str *ret_buffer)
66{
67 FILE *cfg_stream;
68 str cfg_buf, pp_buf;
69
70 /* fill missing arguments with the default values*/
71 if (!cfg_file)
72 cfg_file = CFG_FILE;
73
74 if (strlen(cfg_file) == 1 && cfg_file[0] == '-') {
75 cfg_stream = stdin;
76 } else {
77 /* load config file or die */
78 cfg_stream = fopen(cfg_file, "r");
79 if (!cfg_stream) {
80 LM_ERR("loading config file %s: %s\n", cfg_file,
81 strerror(errno));
82 return -1;
83 }
84 }
85
86 cfg_context_reset_all();
87
88 if (flatten_opensips_cfg(cfg_stream,
89 cfg_stream == stdin ? "stdin" : cfg_file, &cfg_buf) < 0) {
90 LM_ERR("failed to resolve file imports for %s\n", cfg_file);
91 return -1;
92 }
93
94 cfg_stream = fmemopen(cfg_buf.s, cfg_buf.len, "r");
95 if (!cfg_stream) {
96 LM_ERR("failed to open file for flattened cfg buffer\n");
97 goto out_free;
98 }
99
100 if (preproc_cmdline) {
101 if (exec_preprocessor(cfg_stream, preproc_cmdline, &pp_buf) < 0) {
102 LM_ERR("failed to exec preprocessor cmd: '%s'\n", preproc_cmdline);
103 goto out_free;
104 }
105 free(cfg_buf.s);
106 cfg_buf = pp_buf;
107
108 cfg_stream = fmemopen(cfg_buf.s, cfg_buf.len, "r");
109 if (!cfg_stream) {
110 LM_ERR("failed to open file for processed cfg buffer\n");
111 goto out_free;
112 }
113 }
114
115#ifdef DEBUG_PARSER
116 /* used for parser debugging */
117 yydebug = 1;
118#endif
119
120 /* parse the config file, prior to this only default values
121 e.g. for debugging settings will be used */

Callers 2

reload_routing_scriptFunction · 0.85
mainFunction · 0.85

Calls 3

cfg_context_reset_allFunction · 0.85
flatten_opensips_cfgFunction · 0.85
exec_preprocessorFunction · 0.85

Tested by

no test coverage detected