Kannel: Open Source WAP and SMS gateway  svn-r5335
cfg.c File Reference
#include "gwlib/gwlib.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <errno.h>
#include "cfg.def"

Go to the source code of this file.

Data Structures

struct  CfgGroup
 
struct  CfgLoc
 
struct  Cfg
 

Macros

#define OCTSTR(name)
 
#define SINGLE_GROUP(name, fields)
 
#define MULTI_GROUP(name, fields)
 
#define OCTSTR(name)
 
#define SINGLE_GROUP(name, fields)
 
#define MULTI_GROUP(name, fields)
 
#define OCTSTR(name)   printf("%s = <please consult user doc>\n", #name);
 
#define SINGLE_GROUP(name, fields)
 
#define MULTI_GROUP(name, fields)
 

Functions

static CfgGroupcreate_group (void)
 
static void destroy_group (void *arg)
 
static CfgLoccfgloc_create (Octstr *filename)
 
static void cfgloc_destroy (CfgLoc *cfgloc)
 
static void destroy_group_list (void *arg)
 
static void set_group_name (CfgGroup *grp, Octstr *name)
 
static int octstr_sort_cb (const void *a, const void *b)
 
static int octstr_cmp_cb (void *a, void *b)
 
static int core_is_allowed_in_group (Octstr *group, Octstr *variable)
 
static int core_is_single_group (Octstr *query)
 
static int is_allowed_in_group (Octstr *group, Octstr *variable)
 
static int is_single_group (Octstr *query)
 
void cfg_add_hooks (void *allowed, void *single)
 
static int add_group (Cfg *cfg, CfgGroup *grp)
 
Cfgcfg_create (Octstr *filename)
 
void cfg_destroy (Cfg *cfg)
 
static void parse_value (Octstr *value)
 
static Listexpand_file (Octstr *file, int forward)
 
int cfg_read (Cfg *cfg)
 
CfgGroupcfg_get_single_group (Cfg *cfg, Octstr *name)
 
Listcfg_get_multi_group (Cfg *cfg, Octstr *name)
 
Octstrcfg_get_group_name (CfgGroup *grp)
 
Octstrcfg_get_group_checksum (CfgGroup *grp,...)
 
Octstrcfg_get_configfile (CfgGroup *grp)
 
Octstrcfg_get_real (CfgGroup *grp, Octstr *varname, const char *file, long line, const char *func)
 
int cfg_get_integer (long *n, CfgGroup *grp, Octstr *varname)
 
int cfg_get_bool (int *n, CfgGroup *grp, Octstr *varname)
 
Listcfg_get_list (CfgGroup *grp, Octstr *varname)
 
void cfg_set (CfgGroup *grp, Octstr *varname, Octstr *value)
 
void grp_dump (CfgGroup *grp)
 
void cfg_dump (Cfg *cfg)
 
void cfg_dump_all (void)
 
void cfg_init (void)
 
void cfg_shutdown (void)
 

Variables

static Listallowed_hooks
 
static Listsingle_hooks
 

Macro Definition Documentation

◆ MULTI_GROUP [1/3]

#define MULTI_GROUP (   name,
  fields 
)
Value:
if (octstr_compare(octstr_imm(#name), group) == 0) { \
if (octstr_compare(groupstr, variable) == 0) \
return 1; \
fields \
return 0; \
}
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
char * name
Definition: smsc_cimd2.c:212
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:871

◆ MULTI_GROUP [2/3]

#define MULTI_GROUP (   name,
  fields 
)
Value:
if (octstr_compare(octstr_imm(#name), query) == 0) \
return 0;
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
char * name
Definition: smsc_cimd2.c:212
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:871

◆ MULTI_GROUP [3/3]

#define MULTI_GROUP (   name,
  fields 
)
Value:
printf("#\n# Multi Group\n#\n"); \
printf("group = %s\n", #name); \
fields; \
printf("\n\n");
char * name
Definition: smsc_cimd2.c:212

◆ OCTSTR [1/3]

#define OCTSTR (   name)
Value:
if (octstr_compare(octstr_imm(#name), variable) == 0) \
return 1;
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
char * name
Definition: smsc_cimd2.c:212
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:871

◆ OCTSTR [2/3]

#define OCTSTR (   name)

◆ OCTSTR [3/3]

#define OCTSTR (   name)    printf("%s = <please consult user doc>\n", #name);

◆ SINGLE_GROUP [1/3]

#define SINGLE_GROUP (   name,
  fields 
)
Value:
if (octstr_compare(octstr_imm(#name), group) == 0) { \
if (octstr_compare(groupstr, variable) == 0) \
return 1; \
fields \
return 0; \
}
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
char * name
Definition: smsc_cimd2.c:212
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:871

◆ SINGLE_GROUP [2/3]

#define SINGLE_GROUP (   name,
  fields 
)
Value:
if (octstr_compare(octstr_imm(#name), query) == 0) \
return 1;
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
char * name
Definition: smsc_cimd2.c:212
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:871

◆ SINGLE_GROUP [3/3]

#define SINGLE_GROUP (   name,
  fields 
)
Value:
printf("#\n# Single Group\n#\n"); \
printf("group = %s\n", #name); \
fields; \
printf("\n\n");
char * name
Definition: smsc_cimd2.c:212

Function Documentation

◆ add_group()

static int add_group ( Cfg cfg,
CfgGroup grp 
)
static

Definition at line 260 of file cfg.c.

References cfg, cfg_get, dict_get(), dict_keys(), dict_put(), error(), gwlist_append(), gwlist_create, gwlist_destroy(), gwlist_extract_first(), is_allowed_in_group(), is_single_group(), Cfg::multi_groups, name, octstr_destroy(), octstr_destroy_item(), octstr_get_cstr, octstr_imm(), set_group_name(), Cfg::single_groups, and CfgGroup::vars.

Referenced by cfg_read().

261 {
262  Octstr *groupname;
263  Octstr *name;
264  List *names;
265  List *list;
266 
267  groupname = cfg_get(grp, octstr_imm("group"));
268  if (groupname == NULL) {
269  error(0, "Group does not contain variable 'group'.");
270  return -1;
271  }
272  set_group_name(grp, groupname);
273 
274  names = dict_keys(grp->vars);
275 
276  while ((name = gwlist_extract_first(names)) != NULL) {
277  int a = is_allowed_in_group(groupname, name);
278  switch (a) {
279  case 0:
280  error(0, "Group '%s' may not contain field '%s'.",
281  octstr_get_cstr(groupname), octstr_get_cstr(name));
283  octstr_destroy(groupname);
285  return -1;
286  break;
287  case -1:
288  error(0, "Group '%s' is no valid group identifier.",
289  octstr_get_cstr(groupname));
291  octstr_destroy(groupname);
293  return -1;
294  break;
295  default:
297  break;
298  }
299  }
300  gwlist_destroy(names, NULL);
301 
302  if (is_single_group(groupname)) {
303  dict_put(cfg->single_groups, groupname, grp);
304  } else {
305  list = dict_get(cfg->multi_groups, groupname);
306  if (list == NULL) {
307  list = gwlist_create();
308  dict_put(cfg->multi_groups, groupname, list);
309  }
310  gwlist_append(list, grp);
311  }
312 
313  octstr_destroy(groupname);
314  return 0;
315 }
void error(int err, const char *fmt,...)
Definition: log.c:648
void dict_put(Dict *dict, Octstr *key, void *value)
Definition: dict.c:240
void gwlist_append(List *list, void *item)
Definition: list.c:179
#define cfg_get(grp, varname)
Definition: cfg.h:86
static Cfg * cfg
Definition: opensmppbox.c:95
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Dict * multi_groups
Definition: cfg.c:167
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
void * gwlist_extract_first(List *list)
Definition: list.c:305
void * dict_get(Dict *dict, Octstr *key)
Definition: dict.c:286
char * name
Definition: smsc_cimd2.c:212
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
void octstr_destroy_item(void *os)
Definition: octstr.c:336
Definition: octstr.c:118
static int is_single_group(Octstr *query)
Definition: cfg.c:239
List * dict_keys(Dict *dict)
Definition: dict.c:347
#define gwlist_create()
Definition: list.h:136
static void set_group_name(CfgGroup *grp, Octstr *name)
Definition: cfg.c:142
Definition: list.c:102
Dict * vars
Definition: cfg.c:75
Dict * single_groups
Definition: cfg.c:166
static int is_allowed_in_group(Octstr *group, Octstr *variable)
Definition: cfg.c:224
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ cfg_add_hooks()

void cfg_add_hooks ( void *  allowed,
void *  single 
)

Definition at line 253 of file cfg.c.

References allowed_hooks, gwlist_append(), and single_hooks.

Referenced by main().

254 {
255  gwlist_append(allowed_hooks, allowed);
256  gwlist_append(single_hooks, single);
257 }
void gwlist_append(List *list, void *item)
Definition: list.c:179
static List * allowed_hooks
Definition: cfg.c:177
static List * single_hooks
Definition: cfg.c:178

◆ cfg_create()

Cfg* cfg_create ( Octstr filename)

Definition at line 318 of file cfg.c.

References cfg, destroy_group(), destroy_group_list(), dict_create(), Cfg::filename, filename, Cfg::multi_groups, octstr_duplicate, and Cfg::single_groups.

Referenced by at2_read_modems(), bb_graceful_restart(), bb_reload_smsc_groups(), config_reload(), main(), and read_test_ppg_config().

319 {
320  Cfg *cfg;
321 
322  cfg = gw_malloc(sizeof(*cfg));
326 
327  return cfg;
328 }
Dict * dict_create(long size_hint, void(*destroy_value)(void *))
Definition: dict.c:192
static void destroy_group_list(void *arg)
Definition: cfg.c:136
static Cfg * cfg
Definition: opensmppbox.c:95
Dict * multi_groups
Definition: cfg.c:167
Definition: cfg.c:164
#define octstr_duplicate(ostr)
Definition: octstr.h:187
static void destroy_group(void *arg)
Definition: cfg.c:93
char filename[FILENAME_MAX+1]
Definition: log.c:171
Octstr * filename
Definition: cfg.c:165
Dict * single_groups
Definition: cfg.c:166

◆ cfg_destroy()

void cfg_destroy ( Cfg cfg)

Definition at line 331 of file cfg.c.

References cfg, dict_destroy(), Cfg::filename, Cfg::multi_groups, octstr_destroy(), and Cfg::single_groups.

Referenced by at2_read_modems(), bb_reload_smsc_groups(), config_reload(), init_wapbox(), main(), read_ppg_config(), and read_test_ppg_config().

332 {
333  if (cfg != NULL) {
337  gw_free(cfg);
338  }
339 }
static Cfg * cfg
Definition: opensmppbox.c:95
Dict * multi_groups
Definition: cfg.c:167
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
void dict_destroy(Dict *dict)
Definition: dict.c:215
Octstr * filename
Definition: cfg.c:165
Dict * single_groups
Definition: cfg.c:166

◆ cfg_dump()

void cfg_dump ( Cfg cfg)

Definition at line 835 of file cfg.c.

References cfg, cfg_get_multi_group(), cfg_get_single_group(), debug(), dict_keys(), Cfg::filename, grp_dump(), gwlist_destroy(), gwlist_extract_first(), Cfg::multi_groups, name, octstr_destroy(), octstr_get_cstr, and Cfg::single_groups.

Referenced by init_wapbox(), main(), and read_test_ppg_config().

836 {
837  CfgGroup *grp;
838  List *list;
839  List *names;
840  Octstr *name;
841 
842  debug("gwlib.cfg", 0, "Dumping Cfg %p", (void *) cfg);
843  debug("gwlib.cfg", 0, " filename = <%s>",
845 
846  names = dict_keys(cfg->single_groups);
847  while ((name = gwlist_extract_first(names)) != NULL) {
848  grp = cfg_get_single_group(cfg, name);
849  if (grp != NULL)
850  grp_dump(grp);
852  }
853  gwlist_destroy(names, NULL);
854 
855  names = dict_keys(cfg->multi_groups);
856  while ((name = gwlist_extract_first(names)) != NULL) {
857  list = cfg_get_multi_group(cfg, name);
858  while ((grp = gwlist_extract_first(list)) != NULL)
859  grp_dump(grp);
860  gwlist_destroy(list, NULL);
862  }
863  gwlist_destroy(names, NULL);
864 
865  debug("gwlib.cfg", 0, "Dump ends.");
866 }
static Cfg * cfg
Definition: opensmppbox.c:95
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Dict * multi_groups
Definition: cfg.c:167
void * gwlist_extract_first(List *list)
Definition: list.c:305
void grp_dump(CfgGroup *grp)
Definition: cfg.c:811
List * cfg_get_multi_group(Cfg *cfg, Octstr *name)
Definition: cfg.c:645
char * name
Definition: smsc_cimd2.c:212
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
Definition: octstr.c:118
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
Definition: cfg.c:73
List * dict_keys(Dict *dict)
Definition: dict.c:347
Octstr * filename
Definition: cfg.c:165
CfgGroup * cfg_get_single_group(Cfg *cfg, Octstr *name)
Definition: cfg.c:639
Definition: list.c:102
Dict * single_groups
Definition: cfg.c:166
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ cfg_dump_all()

void cfg_dump_all ( void  )

Definition at line 869 of file cfg.c.

Referenced by get_and_set_debugs().

870 {
871  #define OCTSTR(name) \
872  printf("%s = <please consult user doc>\n", #name);
873  #define SINGLE_GROUP(name, fields) \
874  printf("#\n# Single Group\n#\n"); \
875  printf("group = %s\n", #name); \
876  fields; \
877  printf("\n\n");
878  #define MULTI_GROUP(name, fields) \
879  printf("#\n# Multi Group\n#\n"); \
880  printf("group = %s\n", #name); \
881  fields; \
882  printf("\n\n");
883  #include "cfg.def"
884 }

◆ cfg_get_bool()

int cfg_get_bool ( int *  n,
CfgGroup grp,
Octstr varname 
)

Definition at line 759 of file cfg.c.

References cfg_get, octstr_case_compare(), octstr_destroy(), octstr_imm(), and warning().

Referenced by at2_read_modems(), config_reload(), create_onetrans(), httpadmin_start(), init_bearerbox(), init_reroute(), init_smppbox(), init_smsbox(), init_sqlbox(), init_wapbox(), read_ppg_config(), read_test_ppg_config(), smsbox_start(), smsc2_start(), smsc_at2_create(), smsc_cimd2_create(), smsc_http_create(), smsc_oisd_create(), smsc_smpp_create(), smsc_soap_create(), smscconn_create(), and wapbox_start().

760 {
761  Octstr *os;
762 
763  os = cfg_get(grp, varname);
764  if (os == NULL) {
765  *n = 0;
766  return -1;
767  }
768  if (octstr_case_compare(os, octstr_imm("true")) == 0
769  || octstr_case_compare(os, octstr_imm("yes")) == 0
770  || octstr_case_compare(os, octstr_imm("on")) == 0
771  || octstr_case_compare(os, octstr_imm("1")) == 0)
772  {
773  *n = 1;
774  } else if (octstr_case_compare(os, octstr_imm("false")) == 0
775  || octstr_case_compare(os, octstr_imm("no")) == 0
776  || octstr_case_compare(os, octstr_imm("off")) == 0
777  || octstr_case_compare(os, octstr_imm("0")) == 0)
778  {
779  *n = 0;
780  }
781  else {
782  *n = 1;
783  warning(0, "bool variable set to strange value, assuming 'true'");
784  }
785  octstr_destroy(os);
786  return 0;
787 }
#define cfg_get(grp, varname)
Definition: cfg.h:86
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
int octstr_case_compare(const Octstr *os1, const Octstr *os2)
Definition: octstr.c:903
void warning(int err, const char *fmt,...)
Definition: log.c:660
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
Definition: octstr.c:118

◆ cfg_get_configfile()

Octstr* cfg_get_configfile ( CfgGroup grp)

Definition at line 716 of file cfg.c.

References CfgGroup::configfile, and octstr_duplicate.

Referenced by smsc_at2_create().

717 {
718  return octstr_duplicate(grp->configfile);
719 }
#define octstr_duplicate(ostr)
Definition: octstr.h:187
Octstr * configfile
Definition: cfg.c:76

◆ cfg_get_group_checksum()

Octstr* cfg_get_group_checksum ( CfgGroup grp,
  ... 
)

Definition at line 666 of file cfg.c.

References dict_get(), dict_keys(), gwlist_append(), gwlist_create, gwlist_delete_equal(), gwlist_destroy(), gwlist_extract_first(), gwlist_search(), gwlist_sort(), md5(), CfgGroup::name, octstr_append(), octstr_cmp_cb(), octstr_destroy(), octstr_duplicate, octstr_get_cstr, octstr_sort_cb(), panic, and CfgGroup::vars.

Referenced by cmp_conn_grp_checksum(), cmp_rout_grp_checksum(), smscconn_create(), and smscconn_reconfig().

667 {
668  va_list args;
669  Octstr *ret, *os, *key, *val;
670  List *exclude, *keys;
671 
672  exclude = gwlist_create();
673 
674  /*
675  * Variadic Octstr* arguments may contain the
676  * config key names that DO NOT go into the
677  * checksum computation. This allows differential
678  * compares and detection of single changes.
679  */
680  va_start(args, grp);
681  while ((os = va_arg(args, Octstr*)) != NULL) {
682  gwlist_append(exclude, os);
683  }
684  va_end(args);
685 
686  /* all configured config names of this group */
687  keys = dict_keys(grp->vars);
688 
689  /* remove all excluded configs names */
690  while ((os = gwlist_extract_first(exclude)) != NULL) {
691  if ((key = gwlist_search(keys, os, octstr_cmp_cb)) != NULL) {
692  if (gwlist_delete_equal(keys, key) != 1)
693  panic(0, "%s: multiple config variables with same name `%s'?!", __func__,
694  octstr_get_cstr(key));
695  octstr_destroy(key);
696  }
697  }
698  gwlist_destroy(exclude, NULL);
699 
700  os = octstr_duplicate(grp->name);
702  while ((key = gwlist_extract_first(keys)) != NULL) {
703  octstr_append(os, key);
704  if ((val = dict_get(grp->vars, key)) != NULL)
705  octstr_append(os, val);
706  octstr_destroy(key);
707  }
708  gwlist_destroy(keys, NULL);
709 
710  ret = md5(os);
711  octstr_destroy(os);
712 
713  return ret;
714 }
Octstr * md5(Octstr *data)
Definition: md5.c:387
void * gwlist_search(List *list, void *pattern, int(*cmp)(void *, void *))
Definition: list.c:486
void gwlist_append(List *list, void *item)
Definition: list.c:179
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1504
void gwlist_sort(List *list, int(*cmp)(const void *, const void *))
Definition: list.c:576
Octstr * name
Definition: cfg.c:74
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static int octstr_cmp_cb(void *a, void *b)
Definition: cfg.c:158
void * gwlist_extract_first(List *list)
Definition: list.c:305
void * dict_get(Dict *dict, Octstr *key)
Definition: dict.c:286
static int octstr_sort_cb(const void *a, const void *b)
Definition: cfg.c:149
#define octstr_duplicate(ostr)
Definition: octstr.h:187
long gwlist_delete_equal(List *list, void *item)
Definition: list.c:266
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
Definition: octstr.c:118
#define panic
Definition: log.h:87
List * dict_keys(Dict *dict)
Definition: dict.c:347
#define gwlist_create()
Definition: list.h:136
Definition: list.c:102
Dict * vars
Definition: cfg.c:75
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ cfg_get_group_name()

Octstr* cfg_get_group_name ( CfgGroup grp)

Definition at line 661 of file cfg.c.

References CfgGroup::name, and octstr_duplicate.

Referenced by create_onetrans().

662 {
663  return octstr_duplicate(grp->name);
664 }
Octstr * name
Definition: cfg.c:74
#define octstr_duplicate(ostr)
Definition: octstr.h:187

◆ cfg_get_integer()

int cfg_get_integer ( long *  n,
CfgGroup grp,
Octstr varname 
)

Definition at line 742 of file cfg.c.

References cfg_get, octstr_destroy(), and octstr_parse_long().

Referenced by at2_read_modems(), check_config(), config_reload(), create_onetrans(), dlr_db_fields_create(), generic_get_field_map(), httpadmin_start(), init_bearerbox(), init_configuration(), init_smppbox(), init_smsbox(), init_sqlbox(), init_wapbox(), radius_acct_init(), read_ppg_config(), read_test_ppg_config(), smpp_pdu_init(), smsbox_start(), smsc2_start(), smsc_at2_create(), smsc_cgw_create(), smsc_cimd2_create(), smsc_emi2_create(), smsc_fake_create(), smsc_http_create(), smsc_oisd_create(), smsc_open(), smsc_smpp_create(), smsc_soap_create(), smscconn_create(), smscconn_instances(), and wapbox_start().

743 {
744  Octstr *os;
745  int ret;
746 
747  os = cfg_get(grp, varname);
748  if (os == NULL)
749  return -1;
750  if (octstr_parse_long(n, os, 0, 0) == -1)
751  ret = -1;
752  else
753  ret = 0;
754  octstr_destroy(os);
755  return ret;
756 }
#define cfg_get(grp, varname)
Definition: cfg.h:86
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
Definition: octstr.c:118
long octstr_parse_long(long *nump, Octstr *ostr, long pos, int base)
Definition: octstr.c:749

◆ cfg_get_list()

List* cfg_get_list ( CfgGroup grp,
Octstr varname 
)

Definition at line 790 of file cfg.c.

References cfg_get, octstr_destroy(), and octstr_split_words().

Referenced by config_reload(), init_bearerbox(), and init_smsbox().

791 {
792  Octstr *os;
793  List *list;
794 
795  os = cfg_get(grp, varname);
796  if (os == NULL)
797  return NULL;
798 
799  list = octstr_split_words(os);
800  octstr_destroy(os);
801  return list;
802 }
#define cfg_get(grp, varname)
Definition: cfg.h:86
List * octstr_split_words(const Octstr *ostr)
Definition: octstr.c:1602
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
Definition: octstr.c:118
Definition: list.c:102

◆ cfg_get_multi_group()

List* cfg_get_multi_group ( Cfg cfg,
Octstr name 
)

Definition at line 645 of file cfg.c.

References cfg, dict_get(), gwlist_append(), gwlist_create, gwlist_get(), gwlist_len(), Cfg::multi_groups, and name.

Referenced by at2_read_modems(), bb_reload_smsc_groups(), cfg_dump(), config_reload(), init_bearerbox(), init_smsbox_routes(), init_smsc_routes(), read_ppg_config(), smpp_pdu_init(), smsbox_req_sendota(), smsc2_graceful_restart(), smsc2_start(), and urltrans_add_cfg().

646 {
647  List *list, *copy;
648  long i;
649 
650  list = dict_get(cfg->multi_groups, name);
651  if (list == NULL)
652  return NULL;
653 
654  copy = gwlist_create();
655  for (i = 0; i < gwlist_len(list); ++i)
656  gwlist_append(copy, gwlist_get(list, i));
657  return copy;
658 }
void gwlist_append(List *list, void *item)
Definition: list.c:179
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
static Cfg * cfg
Definition: opensmppbox.c:95
Dict * multi_groups
Definition: cfg.c:167
void * dict_get(Dict *dict, Octstr *key)
Definition: dict.c:286
char * name
Definition: smsc_cimd2.c:212
#define gwlist_create()
Definition: list.h:136
Definition: list.c:102

◆ cfg_get_real()

Octstr* cfg_get_real ( CfgGroup grp,
Octstr varname,
const char *  file,
long  line,
const char *  func 
)

Definition at line 722 of file cfg.c.

References dict_get(), file, is_allowed_in_group(), CfgGroup::name, octstr_duplicate, octstr_get_cstr, panic, and CfgGroup::vars.

724 {
725  Octstr *os;
726 
727  if(grp == NULL)
728  panic(0, "Trying to fetch variable `%s' in non-existing group",
729  octstr_get_cstr(varname));
730 
731  if (grp->name != NULL && !is_allowed_in_group(grp->name, varname))
732  panic(0, "Trying to fetch variable `%s' in group `%s', not allowed.",
733  octstr_get_cstr(varname), octstr_get_cstr(grp->name));
734 
735  os = dict_get(grp->vars, varname);
736  if (os == NULL)
737  return NULL;
738  return gw_claim_area_for(octstr_duplicate(os), file, line, func);
739 }
Octstr * name
Definition: cfg.c:74
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
FILE * file
Definition: log.c:169
void * dict_get(Dict *dict, Octstr *key)
Definition: dict.c:286
#define octstr_duplicate(ostr)
Definition: octstr.h:187
Definition: octstr.c:118
#define panic
Definition: log.h:87
Dict * vars
Definition: cfg.c:75
static int is_allowed_in_group(Octstr *group, Octstr *variable)
Definition: cfg.c:224

◆ cfg_get_single_group()

CfgGroup* cfg_get_single_group ( Cfg cfg,
Octstr name 
)

Definition at line 639 of file cfg.c.

References cfg, dict_get(), name, and Cfg::single_groups.

Referenced by cfg_dump(), check_config(), config_reload(), dlr_init(), dlr_init_spool(), httpadmin_start(), init_bearerbox(), init_smppbox(), init_smsbox(), init_sqlbox(), init_wapbox(), read_ppg_config(), read_test_ppg_config(), smsbox_start(), smsc2_start(), udp_start(), and wapbox_start().

640 {
641  return dict_get(cfg->single_groups, name);
642 }
static Cfg * cfg
Definition: opensmppbox.c:95
void * dict_get(Dict *dict, Octstr *key)
Definition: dict.c:286
char * name
Definition: smsc_cimd2.c:212
Dict * single_groups
Definition: cfg.c:166

◆ cfg_init()

void cfg_init ( void  )

Definition at line 887 of file cfg.c.

References allowed_hooks, core_is_allowed_in_group(), core_is_single_group(), gwlist_append(), gwlist_create, and single_hooks.

Referenced by gwlib_init().

888 {
889  /* make sure we put our own core hooks into the lists */
892 
895 }
void gwlist_append(List *list, void *item)
Definition: list.c:179
static List * allowed_hooks
Definition: cfg.c:177
static int core_is_single_group(Octstr *query)
Definition: cfg.c:210
static int core_is_allowed_in_group(Octstr *group, Octstr *variable)
Definition: cfg.c:180
static List * single_hooks
Definition: cfg.c:178
#define gwlist_create()
Definition: list.h:136

◆ cfg_read()

int cfg_read ( Cfg cfg)

Definition at line 452 of file cfg.c.

References add_group(), cfg, cfg_set(), cfgloc_create(), cfgloc_destroy(), CfgGroup::configfile, create_group(), debug(), destroy_group(), error(), expand_file(), file, CfgLoc::filename, Cfg::filename, filename, gwlist_create, gwlist_destroy(), gwlist_extract_first(), gwlist_insert(), gwlist_search(), CfgLoc::line, CfgLoc::line_no, lines, name, octstr_append_cstr(), octstr_copy, octstr_destroy(), octstr_destroy_item(), octstr_duplicate, octstr_get_char(), octstr_get_cstr, octstr_imm(), octstr_item_match(), octstr_len(), octstr_search(), octstr_search_char(), octstr_strip_blanks(), panic, and parse_value().

Referenced by at2_read_modems(), bb_graceful_restart(), bb_reload_smsc_groups(), config_reload(), main(), and read_test_ppg_config().

453 {
454  CfgLoc *loc;
455  CfgLoc *loc_inc;
456  List *lines;
457  List *expand;
458  List *stack;
459  Octstr *name;
460  Octstr *value;
461  Octstr *filename;
462  CfgGroup *grp;
463  long equals;
464  CfgLoc *err_loc = NULL;
465 
466  loc = loc_inc = NULL;
467 
468  /*
469  * expand initial main config file and add it to the recursion
470  * stack to protect against cycling
471  */
472  if ((lines = expand_file(cfg->filename, 1)) == NULL) {
473  panic(0, "Failed to load main configuration file `%s'. Aborting!",
475  }
476  stack = gwlist_create();
478 
479  grp = NULL;
480  err_loc = NULL;
481  while (err_loc == NULL && (loc = gwlist_extract_first(lines)) != NULL) {
482  octstr_strip_blanks(loc->line);
483  if (octstr_len(loc->line) == 0) {
484  if (grp != NULL && add_group(cfg, grp) == -1) {
485  err_loc = loc; loc = NULL;
486  destroy_group(grp);
487  }
488  grp = NULL;
489  } else if (octstr_get_char(loc->line, 0) != '#') {
490  equals = octstr_search_char(loc->line, '=', 0);
491  if (equals == -1) {
492  error(0, "An equals sign ('=') is missing on line %ld of file %s.",
493  loc->line_no, octstr_get_cstr(loc->filename));
494  err_loc = loc; loc = NULL;
495  } else
496 
497  /*
498  * check for special config directives, like include or conditional
499  * directives here
500  */
501  if (octstr_search(loc->line, octstr_imm("include"), 0) != -1) {
502  List *files = NULL;
503  Octstr *file;
504  struct stat filestat;
505 
506  filename = octstr_copy(loc->line, equals + 1, octstr_len(loc->line));
508  files = gwlist_create();
509 
510  /* check if included file is a directory */
511  if (lstat(octstr_get_cstr(filename), &filestat) != 0) {
512  error(errno, "lstat failed: couldn't stat `%s'",
514  panic(0, "Failed to include `%s' "
515  "(on line %ld of file %s). Aborting!",
517  octstr_get_cstr(loc->filename));
518  }
519 
520  /*
521  * is a directory, create a list with files of
522  * this directory and load all as part of the
523  * whole configuration.
524  */
525  if (S_ISDIR(filestat.st_mode)) {
526  DIR *dh;
527  struct dirent *diritem;
528 
529  debug("gwlib.cfg", 0, "Loading include dir `%s' "
530  "(on line %ld of file %s).",
532  octstr_get_cstr(loc->filename));
533 
534  dh = opendir(octstr_get_cstr(filename));
535  while ((diritem = readdir(dh))) {
536  Octstr *fileitem;
537 
538  fileitem = octstr_duplicate(filename);
539  octstr_append_cstr(fileitem, "/");
540  octstr_append_cstr(fileitem, diritem->d_name);
541 
542  lstat(octstr_get_cstr(fileitem), &filestat);
543  if (!S_ISDIR(filestat.st_mode)) {
544  gwlist_insert(files, 0, fileitem);
545  } else {
546  octstr_destroy(fileitem);
547  }
548  }
549  closedir(dh);
550  }
551  /* is a file, create a list with it */
552  else {
554  }
555 
556  /* include files */
557  while ((file = gwlist_extract_first(files)) != NULL) {
558 
559  /* check if we are cycling and ignore this file */
560  if (gwlist_search(stack, file, octstr_item_match) != NULL) {
561  debug("gwlib.cfg", 0, "Recursive/multiple include for config file `%s' detected "
562  "(on line %ld of file %s), ignore this file.",
564  octstr_get_cstr(loc->filename));
566  continue;
567  }
568 
569  gwlist_insert(stack, 0, octstr_duplicate(file));
570  debug("gwlib.cfg", 0, "Loading include file `%s' (on line %ld of file %s).",
572  octstr_get_cstr(loc->filename));
573 
574  /*
575  * expand the given include file and add it to the current
576  * processed main while loop
577  */
578  if ((expand = expand_file(file, 0)) != NULL) {
579  while ((loc_inc = gwlist_extract_first(expand)) != NULL)
580  gwlist_insert(lines, 0, loc_inc);
581  } else {
582  panic(0, "Failed to load whole configuration. Aborting!");
583  }
584 
585  gwlist_destroy(expand, NULL);
586  cfgloc_destroy(loc_inc);
588  }
591  }
592  /*
593  * this is a "normal" line, so process it accordingly
594  */
595  else {
596  name = octstr_copy(loc->line, 0, equals);
598  value = octstr_copy(loc->line, equals + 1, octstr_len(loc->line));
599  parse_value(value);
600 
601  if (grp == NULL)
602  grp = create_group();
603 
604  if (grp->configfile != NULL) {
605  octstr_destroy(grp->configfile);
606  grp->configfile = NULL;
607  }
609 
610  cfg_set(grp, name, value);
612  octstr_destroy(value);
613  }
614  }
615 
616  cfgloc_destroy(loc);
617  }
618 
619  if (grp != NULL && add_group(cfg, grp) == -1) {
620  err_loc = cfgloc_create(cfg->filename);
621  err_loc->line_no = 1;
622  destroy_group(grp);
623  }
624 
625  gwlist_destroy(lines, NULL);
627 
628  if (err_loc != NULL) {
629  error(0, "Error found on line %ld of file `%s'.",
630  err_loc->line_no, octstr_get_cstr(err_loc->filename));
631  cfgloc_destroy(err_loc);
632  return -1;
633  }
634 
635  return 0;
636 }
void error(int err, const char *fmt,...)
Definition: log.c:648
void * gwlist_search(List *list, void *pattern, int(*cmp)(void *, void *))
Definition: list.c:486
static List * expand_file(Octstr *file, int forward)
Definition: cfg.c:389
Octstr * filename
Definition: cfg.c:108
static int add_group(Cfg *cfg, CfgGroup *grp)
Definition: cfg.c:260
static void cfgloc_destroy(CfgLoc *cfgloc)
Definition: cfg.c:126
static CfgLoc * cfgloc_create(Octstr *filename)
Definition: cfg.c:114
long octstr_search(const Octstr *haystack, const Octstr *needle, long pos)
Definition: octstr.c:1070
void octstr_append_cstr(Octstr *ostr, const char *cstr)
Definition: octstr.c:1511
static Cfg * cfg
Definition: opensmppbox.c:95
void octstr_strip_blanks(Octstr *text)
Definition: octstr.c:1346
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
#define octstr_copy(ostr, from, len)
Definition: octstr.h:178
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1012
static List * lines
Definition: mtbatch.c:88
Definition: cfg.c:107
FILE * file
Definition: log.c:169
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
void * gwlist_extract_first(List *list)
Definition: list.c:305
#define octstr_duplicate(ostr)
Definition: octstr.h:187
static void destroy_group(void *arg)
Definition: cfg.c:93
int octstr_item_match(void *item, void *pattern)
Definition: octstr.c:1661
char * name
Definition: smsc_cimd2.c:212
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
char filename[FILENAME_MAX+1]
Definition: log.c:171
void octstr_destroy_item(void *os)
Definition: octstr.c:336
void gwlist_insert(List *list, long pos, void *item)
Definition: list.c:214
void cfg_set(CfgGroup *grp, Octstr *varname, Octstr *value)
Definition: cfg.c:805
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: octstr.c:118
long line_no
Definition: cfg.c:109
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
#define panic
Definition: log.h:87
static CfgGroup * create_group(void)
Definition: cfg.c:81
Definition: cfg.c:73
#define gwlist_create()
Definition: list.h:136
Octstr * filename
Definition: cfg.c:165
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:406
Definition: list.c:102
Octstr * configfile
Definition: cfg.c:76
Octstr * line
Definition: cfg.c:110
static void parse_value(Octstr *value)
Definition: cfg.c:342
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ cfg_set()

void cfg_set ( CfgGroup grp,
Octstr varname,
Octstr value 
)

Definition at line 805 of file cfg.c.

References dict_put(), octstr_duplicate, and CfgGroup::vars.

Referenced by cfg_read().

806 {
807  dict_put(grp->vars, varname, octstr_duplicate(value));
808 }
void dict_put(Dict *dict, Octstr *key, void *value)
Definition: dict.c:240
#define octstr_duplicate(ostr)
Definition: octstr.h:187
Dict * vars
Definition: cfg.c:75

◆ cfg_shutdown()

void cfg_shutdown ( void  )

Definition at line 898 of file cfg.c.

References allowed_hooks, gwlist_destroy(), and single_hooks.

Referenced by gwlib_shutdown().

899 {
902  allowed_hooks = single_hooks = NULL;
903 }
static List * allowed_hooks
Definition: cfg.c:177
static List * single_hooks
Definition: cfg.c:178
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ cfgloc_create()

static CfgLoc* cfgloc_create ( Octstr filename)
static

Definition at line 114 of file cfg.c.

References CfgLoc::filename, filename, CfgLoc::line, CfgLoc::line_no, and octstr_duplicate.

Referenced by cfg_read(), and expand_file().

115 {
116  CfgLoc *cfgloc;
117 
118  cfgloc = gw_malloc(sizeof(*cfgloc));
119  cfgloc->filename = octstr_duplicate(filename);
120  cfgloc->line_no = 0;
121  cfgloc->line = NULL;
122  return cfgloc;
123 }
Octstr * filename
Definition: cfg.c:108
Definition: cfg.c:107
#define octstr_duplicate(ostr)
Definition: octstr.h:187
char filename[FILENAME_MAX+1]
Definition: log.c:171
long line_no
Definition: cfg.c:109
Octstr * line
Definition: cfg.c:110

◆ cfgloc_destroy()

static void cfgloc_destroy ( CfgLoc cfgloc)
static

Definition at line 126 of file cfg.c.

References CfgLoc::filename, CfgLoc::line, and octstr_destroy().

Referenced by cfg_read().

127 {
128  if (cfgloc != NULL) {
129  octstr_destroy(cfgloc->filename);
130  octstr_destroy(cfgloc->line);
131  gw_free(cfgloc);
132  }
133 }
Octstr * filename
Definition: cfg.c:108
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
Octstr * line
Definition: cfg.c:110

◆ core_is_allowed_in_group()

static int core_is_allowed_in_group ( Octstr group,
Octstr variable 
)
static

Definition at line 180 of file cfg.c.

References octstr_imm().

Referenced by cfg_init().

181 {
182  Octstr *groupstr;
183 
184  groupstr = octstr_imm("group");
185 
186  #define OCTSTR(name) \
187  if (octstr_compare(octstr_imm(#name), variable) == 0) \
188  return 1;
189  #define SINGLE_GROUP(name, fields) \
190  if (octstr_compare(octstr_imm(#name), group) == 0) { \
191  if (octstr_compare(groupstr, variable) == 0) \
192  return 1; \
193  fields \
194  return 0; \
195  }
196  #define MULTI_GROUP(name, fields) \
197  if (octstr_compare(octstr_imm(#name), group) == 0) { \
198  if (octstr_compare(groupstr, variable) == 0) \
199  return 1; \
200  fields \
201  return 0; \
202  }
203  #include "cfg.def"
204 
205  /* unknown group identifier */
206  return -1;
207 }
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
Definition: octstr.c:118

◆ core_is_single_group()

static int core_is_single_group ( Octstr query)
static

Definition at line 210 of file cfg.c.

Referenced by cfg_init().

211 {
212  #define OCTSTR(name)
213  #define SINGLE_GROUP(name, fields) \
214  if (octstr_compare(octstr_imm(#name), query) == 0) \
215  return 1;
216  #define MULTI_GROUP(name, fields) \
217  if (octstr_compare(octstr_imm(#name), query) == 0) \
218  return 0;
219  #include "cfg.def"
220  return 0;
221 }

◆ create_group()

static CfgGroup* create_group ( void  )
static

Definition at line 81 of file cfg.c.

References CfgGroup::configfile, dict_create(), CfgGroup::line, CfgGroup::name, octstr_destroy_item(), and CfgGroup::vars.

Referenced by cfg_read().

82 {
83  CfgGroup *grp;
84 
85  grp = gw_malloc(sizeof(*grp));
86  grp->name = NULL;
88  grp->configfile = NULL;
89  grp->line = 0;
90  return grp;
91 }
Dict * dict_create(long size_hint, void(*destroy_value)(void *))
Definition: dict.c:192
Octstr * name
Definition: cfg.c:74
void octstr_destroy_item(void *os)
Definition: octstr.c:336
long line
Definition: cfg.c:77
Definition: cfg.c:73
Dict * vars
Definition: cfg.c:75
Octstr * configfile
Definition: cfg.c:76

◆ destroy_group()

static void destroy_group ( void *  arg)
static

Definition at line 93 of file cfg.c.

References CfgGroup::configfile, dict_destroy(), CfgGroup::name, octstr_destroy(), and CfgGroup::vars.

Referenced by cfg_create(), cfg_read(), and destroy_group_list().

94 {
95  CfgGroup *grp;
96 
97  if (arg != NULL) {
98  grp = arg;
99  octstr_destroy(grp->name);
100  octstr_destroy(grp->configfile);
101  dict_destroy(grp->vars);
102  gw_free(grp);
103  }
104 }
Octstr * name
Definition: cfg.c:74
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
void dict_destroy(Dict *dict)
Definition: dict.c:215
Definition: cfg.c:73
Dict * vars
Definition: cfg.c:75
Octstr * configfile
Definition: cfg.c:76

◆ destroy_group_list()

static void destroy_group_list ( void *  arg)
static

Definition at line 136 of file cfg.c.

References destroy_group(), and gwlist_destroy().

Referenced by cfg_create().

137 {
139 }
static void destroy_group(void *arg)
Definition: cfg.c:93
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ expand_file()

static List* expand_file ( Octstr file,
int  forward 
)
static

Definition at line 389 of file cfg.c.

References cfgloc_create(), file, gwlist_append(), gwlist_create, gwlist_destroy(), gwlist_extract_first(), gwlist_insert(), CfgLoc::line, CfgLoc::line_no, lines, octstr_append(), octstr_create, octstr_delete(), octstr_destroy(), octstr_destroy_item(), octstr_get_char(), octstr_get_cstr, octstr_imm(), octstr_len(), octstr_read_file(), and octstr_split().

Referenced by cfg_read().

390 {
391  Octstr *os;
392  Octstr *line;
393  List *lines;
394  List *expand;
395  long lineno;
396  CfgLoc *loc = NULL;
397 
399  if (os == NULL)
400  return NULL;
401 
402  lines = octstr_split(os, octstr_imm("\n"));
403  lineno = 0;
404  expand = gwlist_create();
405 
406  while ((line = gwlist_extract_first(lines)) != NULL) {
407  if (loc == NULL) {
408  ++lineno;
409  loc = cfgloc_create(file);
410  loc->line_no = lineno;
411  loc->line = octstr_create("");
412  if (forward)
413  gwlist_append(expand, loc);
414  else
415  gwlist_insert(expand, 0, loc);
416  }
417  /* check for escape and then add to existing loc */
418  if (octstr_get_char(line, octstr_len(line) - 1) == '\\') {
419  octstr_delete(line, octstr_len(line) - 1, 1);
420  octstr_append(loc->line, line);
421  /* check for second escape */
422  if (octstr_get_char(line, octstr_len(line) - 1) == '\\')
423  loc = NULL;
424  } else {
425  octstr_append(loc->line, line);
426  loc = NULL;
427  }
428  octstr_destroy(line);
429  }
430 
431  /*
432  * add newline at each end of included files to avoid
433  * concatenating different groups by mistake
434  */
435  if (lineno > 0) {
436  loc = cfgloc_create(file);
437  loc->line_no = lineno;
438  loc->line = octstr_create("\n");
439  if (forward)
440  gwlist_append(expand, loc);
441  else
442  gwlist_insert(expand, 0, loc);
443  }
444 
446  octstr_destroy(os);
447 
448  return expand;
449 }
void gwlist_append(List *list, void *item)
Definition: list.c:179
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1504
static CfgLoc * cfgloc_create(Octstr *filename)
Definition: cfg.c:114
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static List * lines
Definition: mtbatch.c:88
Definition: cfg.c:107
FILE * file
Definition: log.c:169
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
void * gwlist_extract_first(List *list)
Definition: list.c:305
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1527
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
#define octstr_create(cstr)
Definition: octstr.h:125
void octstr_destroy_item(void *os)
Definition: octstr.c:336
void gwlist_insert(List *list, long pos, void *item)
Definition: list.c:214
Octstr * octstr_read_file(const char *filename)
Definition: octstr.c:1548
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: octstr.c:118
long line_no
Definition: cfg.c:109
#define gwlist_create()
Definition: list.h:136
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:406
List * octstr_split(const Octstr *os, const Octstr *sep)
Definition: octstr.c:1640
Definition: list.c:102
Octstr * line
Definition: cfg.c:110
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ grp_dump()

void grp_dump ( CfgGroup grp)

Definition at line 811 of file cfg.c.

References cfg_get, debug(), dict_keys(), gwlist_destroy(), gwlist_extract_first(), CfgGroup::name, name, octstr_destroy(), octstr_get_cstr, and CfgGroup::vars.

Referenced by cfg_dump(), create_onetrans(), init_reroute(), init_smsbox_routes(), and init_smsc_routes().

812 {
813  List *names;
814  Octstr *name;
815  Octstr *value;
816 
817  if (grp->name == NULL)
818  debug("gwlib.cfg", 0, " dumping group (name not set):");
819  else
820  debug("gwlib.cfg", 0, " dumping group (%s):",
821  octstr_get_cstr(grp->name));
822  names = dict_keys(grp->vars);
823  while ((name = gwlist_extract_first(names)) != NULL) {
824  value = cfg_get(grp, name);
825  debug("gwlib.cfg", 0, " <%s> = <%s>",
827  octstr_get_cstr(value));
828  octstr_destroy(value);
830  }
831  gwlist_destroy(names, NULL);
832 }
Octstr * name
Definition: cfg.c:74
#define cfg_get(grp, varname)
Definition: cfg.h:86
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void * gwlist_extract_first(List *list)
Definition: list.c:305
char * name
Definition: smsc_cimd2.c:212
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
Definition: octstr.c:118
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
List * dict_keys(Dict *dict)
Definition: dict.c:347
Definition: list.c:102
Dict * vars
Definition: cfg.c:75
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ is_allowed_in_group()

static int is_allowed_in_group ( Octstr group,
Octstr variable 
)
static

Definition at line 224 of file cfg.c.

References allowed_hooks, gwlist_get(), and gwlist_len().

Referenced by add_group(), and cfg_get_real().

225 {
226  long i;
227  int x, r = -1;
228 
229  for (i = 0; i < gwlist_len(allowed_hooks); ++i) {
230  x = ((int(*)(Octstr *, Octstr *))
231  gwlist_get(allowed_hooks, i))(group, variable);
232  r = (x == -1 ? (r == -1 ? x : r) : (r == -1 ? x : r + x));
233  }
234 
235  return r;
236 }
static List * allowed_hooks
Definition: cfg.c:177
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
Definition: octstr.c:118

◆ is_single_group()

static int is_single_group ( Octstr query)
static

Definition at line 239 of file cfg.c.

References gwlist_get(), gwlist_len(), and single_hooks.

Referenced by add_group().

240 {
241  long i;
242  int r = 0;
243 
244  for (i = 0; i < gwlist_len(single_hooks); ++i) {
245  r += ((int(*)(Octstr *))
246  gwlist_get(single_hooks, i))(query);
247  }
248 
249  return (r > 0);
250 }
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
static List * single_hooks
Definition: cfg.c:178
Definition: octstr.c:118

◆ octstr_cmp_cb()

static int octstr_cmp_cb ( void *  a,
void *  b 
)
static

Definition at line 158 of file cfg.c.

References octstr_compare().

Referenced by cfg_get_group_checksum().

159 {
160  return (octstr_compare((Octstr*)a, (Octstr*)b) == 0);
161 }
Definition: octstr.c:118
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:871

◆ octstr_sort_cb()

static int octstr_sort_cb ( const void *  a,
const void *  b 
)
static

Definition at line 149 of file cfg.c.

References octstr_compare().

Referenced by cfg_get_group_checksum().

150 {
151  const Octstr *fa = a;
152  const Octstr *fb = b;
153 
154  return octstr_compare(fa, fb);
155 }
Definition: octstr.c:118
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:871

◆ parse_value()

static void parse_value ( Octstr value)
static

Definition at line 342 of file cfg.c.

References octstr_append_char(), octstr_delete(), octstr_destroy(), octstr_duplicate, octstr_get_char(), octstr_len(), octstr_strip_blanks(), and octstr_truncate().

Referenced by cfg_read().

343 {
344  Octstr *temp;
345  long len;
346  int c;
347 
348  octstr_strip_blanks(value);
349 
350  len = octstr_len(value);
351  if (octstr_get_char(value, 0) != '"' ||
352  octstr_get_char(value, len - 1) != '"')
353  return;
354 
355  octstr_delete(value, len - 1, 1);
356  octstr_delete(value, 0, 1);
357 
358  temp = octstr_duplicate(value);
359  octstr_truncate(value, 0);
360 
361  while (octstr_len(temp) > 0) {
362  c = octstr_get_char(temp, 0);
363  octstr_delete(temp, 0, 1);
364 
365  if (c != '\\' || octstr_len(temp) == 0)
366  octstr_append_char(value, c);
367  else {
368  c = octstr_get_char(temp, 0);
369  octstr_delete(temp, 0, 1);
370 
371  switch (c) {
372  case '\\':
373  case '"':
374  octstr_append_char(value, c);
375  break;
376 
377  default:
378  octstr_append_char(value, '\\');
379  octstr_append_char(value, c);
380  break;
381  }
382  }
383  }
384 
385  octstr_destroy(temp);
386 }
void octstr_append_char(Octstr *ostr, int ch)
Definition: octstr.c:1517
void octstr_strip_blanks(Octstr *text)
Definition: octstr.c:1346
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1527
#define octstr_duplicate(ostr)
Definition: octstr.h:187
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: octstr.c:118
void octstr_truncate(Octstr *ostr, int new_len)
Definition: octstr.c:1327
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:406

◆ set_group_name()

static void set_group_name ( CfgGroup grp,
Octstr name 
)
static

Definition at line 142 of file cfg.c.

References CfgGroup::name, name, octstr_destroy(), and octstr_duplicate.

Referenced by add_group().

143 {
144  octstr_destroy(grp->name);
145  grp->name = octstr_duplicate(name);
146 }
Octstr * name
Definition: cfg.c:74
#define octstr_duplicate(ostr)
Definition: octstr.h:187
char * name
Definition: smsc_cimd2.c:212
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324

Variable Documentation

◆ allowed_hooks

List* allowed_hooks
static

Definition at line 177 of file cfg.c.

Referenced by cfg_add_hooks(), cfg_init(), cfg_shutdown(), and is_allowed_in_group().

◆ single_hooks

List* single_hooks
static

Definition at line 178 of file cfg.c.

Referenced by cfg_add_hooks(), cfg_init(), cfg_shutdown(), and is_single_group().

See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.