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

Function cgrates_set_engine

modules/cgrates/cgrates.c:295–354  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

293}
294
295static int cgrates_set_engine(modparam_t type, void * val)
296{
297 char *p;
298 unsigned int port;
299 str host;
300 str port_s;
301 struct cgr_engine *e;
302 struct ip_addr *ip;
303 char *s = (char *)val;
304
305 if (!s)
306 return 0;
307
308 host.s = s;
309 p = strchr(s, ':');
310 if (p) {
311 host.len = p - s;
312 port_s.s = p + 1;
313 port_s.len = strlen(s) - host.len - 1;
314 str_trim_spaces_lr(port_s);
315 if (str2int(&port_s, &port) < 0) {
316 LM_ERR("Invalid engine port [%.*s]\n", port_s.len, port_s.s);
317 return -1;
318 }
319 if (port > 65536) {
320 LM_ERR("Invalid port number %u\n", port);
321 return -1;
322 }
323 } else {
324 host.len = strlen(s);
325 port = CGR_DEFAULT_PORT;
326 }
327 str_trim_spaces_lr(host);
328
329 LM_DBG("Adding cgrates engine %.*s:%u\n", host.len, host.s, port);
330
331 e = pkg_malloc(sizeof(*e) + host.len + 1);
332 if (!e) {
333 LM_ERR("out of pkg mem!\n");
334 return -1;
335 }
336 memset(e, 0, sizeof(*e));
337 e->host.s = (char *)(e + 1);
338 e->host.len = host.len;
339 memcpy(e->host.s, host.s, host.len);
340 e->host.s[e->host.len] = '\0';
341
342 e->port = port;
343
344 if ((ip = str2ip(&host)) || (ip = str2ip6(&host)))
345 init_su(&e->su, ip, port);
346 else
347 e->is_fqdn = 1;
348
349 INIT_LIST_HEAD(&e->conns);
350
351 list_add_tail(&e->list, &cgrates_engines);
352

Callers

nothing calls this directly

Calls 6

str2intFunction · 0.85
str2ipFunction · 0.85
str2ip6Function · 0.85
init_suFunction · 0.85
INIT_LIST_HEADFunction · 0.85
list_add_tailFunction · 0.85

Tested by

no test coverage detected