macro definitions...
authorxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Wed, 11 Jun 2014 22:44:35 +0000 (22:44 +0000)
committerxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Wed, 11 Jun 2014 22:44:35 +0000 (22:44 +0000)
git-svn-id: https://dev.arachne.cz/repos/prometheus/trunk@242 251d49ef-1d17-4917-a970-b30cf55b089b

ipstruct.h
parsehosts.c
prometheus.c

index d8427deb8efa5815341858433eff38e47f1b7e60..797fb7bb72bca3bcd2f0f64157c1ffc08d9f1c11 100644 (file)
@@ -60,5 +60,12 @@ struct Keyword
  list(Keyword);\r
 };\r
 \r
+struct Macro\r
+{\r
+ char *rewrite_from;\r
+ char *rewrite_to;\r
+ list(Macro);\r
+};\r
+\r
 void TheIP(char *ipaddr, int is_network);\r
 /* function implemented in parsehosts.c */\r
index 9ee2c2b003995e59c746cbe7789dd563f553817a..18418eddb6b9c587d6ec23925a71c6f8ed011c48 100644 (file)
@@ -10,6 +10,7 @@
 extern struct IP *ips, *ip, *sharedip, *networks;\r
 extern struct Group *groups, *group;\r
 extern struct Keyword *keyword, *defaultkeyword, *keywords;\r
+extern struct Macro *macro, *macros;\r
 extern int class_count;\r
 extern int ip_count;\r
 extern int found_lmsid;\r
@@ -155,7 +156,7 @@ void parse_hosts(char *hosts)
 \r
  parse(hosts)\r
  {\r
-  str=_;\r
+  str = _;\r
 \r
   if(*str < '0' or *str > '9')\r
   {\r
@@ -163,6 +164,25 @@ void parse_hosts(char *hosts)
    continue;\r
   }\r
   \r
+  /* first, expand (rewrite) any predefined macros, if found*/\r
+  for_each(macro, macros)\r
+  {\r
+   substring = strstr(str, macro->rewrite_from);\r
+   if(substring);\r
+   {\r
+    int l1, l3;\r
+    *substring = 0;\r
+    substring += strlen(macro->rewrite_from);\r
+    l1 = strlen(str);\r
+    l3 = strlen(substring);\r
+    string(ptr, l1 + strlen(macro->rewrite_to) + l3);\r
+    strcpy(ptr, str);\r
+    strcat(ptr, macro->rewrite_to);\r
+    strcat(ptr, substring);\r
+    str = ptr;\r
+   }\r
+  }\r
+\r
   /* Does this IP share QoS class with some other ? */\r
   substring = strstr(str, "sharing-");\r
   if(substring)\r
index 087102e66aa75a0062260f3a2d5f7ef1d78fb8bb..e091d6e095df8ada02c802803c5d84cdf1a67a2d 100644 (file)
@@ -29,7 +29,7 @@
 #include "cll1-0.6.2.h"\r
 #include "ipstruct.h"\r
 \r
-const char *version = "0.8.3-j";\r
+const char *version = "0.8.5-a";\r
 \r
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */\r
 /* Versions: 0.8.3 is development release, 0.8.4 will be "stable"  */\r
@@ -58,6 +58,7 @@ const char               *ls = "/bin/ls"; /* this is not user configurable :-) *
 \r
 char          *config = "/etc/prometheus/prometheus.conf"; /* main configuration file */\r
 char           *hosts = "/etc/prometheus/hosts"; /* per-IP bandwidth definition file */\r
+char      *macrosfile = "/etc/prometheus/prometheus.macros"; /* rewrite rules for most common tariffs */\r
 char    *iptablesfile = "/var/spool/prometheus.iptables"; /* temporary file for iptables-restore*/\r
 char   *ip6tablesfile = "/var/spool/prometheus.ip6tables"; /* temporary file for ip6tables-restore*/\r
 char          *credit = "/var/lib/misc/prometheus.credit"; /* credit log file */\r
@@ -132,7 +133,8 @@ const int idxtable_bitmask2  = 3;        /* this is no longer configurable */
 \r
 struct IP *ips = NULL, *networks = NULL, *ip, *sharedip;\r
 struct Group *groups = NULL, *group;\r
-struct Keyword *keyword, *defaultkeyword=NULL, *keywords=NULL;\r
+struct Keyword *keyword, *defaultkeyword=NULL, *keywords = NULL;\r
+struct Macro *macro, *macros = NULL;\r
 \r
 #define FREE_CLASS      3\r
 #define OVERLIMIT_CLASS 4\r
@@ -237,7 +239,7 @@ void get_config(char *config_filename)
    keyword->leaf_discipline = "";\r
    keyword->allowed_avgmtu = 0;\r
 \r
-   push(keyword,keywords);\r
+   push(keyword, keywords);\r
    if(!defaultkeyword)\r
    {\r
     defaultkeyword = keyword;\r
@@ -450,12 +452,20 @@ void run_iptables_restore(void)
 \r
 char *parse_datafile_line(char *str)\r
 {\r
- char *ptr=strchr(str,' ');\r
+ char *ptr = strchr(str,' ');\r
+ if(!ptr)\r
+ {\r
+  ptr = strchr(str,'\t');\r
+ }\r
 \r
  if(ptr)\r
  {\r
-  *ptr=0;\r
+  *ptr = 0;\r
   ptr++;\r
+  while(*ptr == ' ' || *ptr == '\t')\r
+  {\r
+   ptr++;\r
+  }\r
   return ptr;\r
  } \r
  else \r
@@ -609,7 +619,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   /*-----------------------------------------------------------------*/\r
   parse(credit)\r
   {\r
-   ptr=parse_datafile_line(_);\r
+   ptr = parse_datafile_line(_);\r
    if(ptr)\r
    {\r
     if_exists(ip,ips,eq(ip->addr,_))\r
@@ -621,6 +631,26 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   done; /* ugly macro end */\r
  }\r
 \r
+ if(enable_credit && just_flush<9)\r
+ {\r
+  /*-----------------------------------------------------------------*/\r
+  printf("Parsing macro definition file %s ...\n", macrosfile);\r
+  /*-----------------------------------------------------------------*/\r
+  parse(macrosfile)\r
+  {\r
+   ptr = parse_datafile_line(_);\r
+   if(ptr)\r
+   {\r
+    create(macro, Macro);\r
+    macro->rewrite_from = _;\r
+    macro->rewrite_to = ptr;\r
+    push(macro, macros);\r
+    printf("%s -> %s\n", macro->rewrite_from, macro->rewrite_to);\r
+   }\r
+  }\r
+  done; /* ugly macro end */\r
+ }\r
+\r
  if(!just_preview)\r
  {\r
   /*-----------------------------------------------------------------*/\r
This page took 0.186803 seconds and 4 git commands to generate.