Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

pdl_policy.c

Go to the documentation of this file.
00001 /*
00002  *   Copyright (c) 2003 EU DataGrid        http://www.eu-datagrid.org/
00003  *
00004  *   $Id: pdl_policy.c,v 1.13 2003/08/06 08:15:36 venekamp Exp $
00005  *
00006  *   Copyright (c) 2003 by
00007  *      G.M. Venekamp <venekamp@nikhef.nl>
00008  *      NIKHEF Amsterdam, the Netherlands
00009  *
00010  *   This software is distributed under a BSD-style open source
00011  *   licence. For a complete description of the licence take a look
00012  *   at: http://eu-datagrid.web.cern.ch/eu-datagrid/license.html
00013  *
00014  */
00015 
00016 
00030 #include <stdarg.h>
00031 #include <stdio.h>
00032 #include <stdlib.h>
00033 
00034 #include "lcmaps_log.h"
00035 #include "pdl_policy.h"
00036 
00037 static BOOL policies_reduced = FALSE;       
00038 
00039 static policy_t *top_policy=0, *last_policy=0;
00040 
00041 BOOL _add_policy(const record_t* name, const rule_t* rules);
00042 
00043 
00050 policy_t* current_policy(void)
00051 {
00052   return last_policy;
00053 }
00054 
00055 
00066 void allow_rules(BOOL allow)
00067 {
00068   allow_new_rules(allow);
00069 }
00070 
00071 
00084 void add_policy(record_t* policy, rule_t* rules)
00085 {
00086   /*
00087    *  Do not switch the order of the and operator, because the
00088    *  _add_policy needs to be done always.
00089    */
00090   if (!_add_policy(policy, rules)) {
00091     free_rules(rules);
00092     free(policy->string);
00093     free(policy);
00094 
00095     set_yylval(0);
00096   }
00097 
00098   free(policy);
00099 
00100   start_new_rules();
00101 };
00102 
00103 
00118 BOOL _add_policy(const record_t* name, const rule_t* rules)
00119 {
00120   policy_t *policy;
00121 
00122   if ((policy = find_policy(name->string))) {
00123     warning(PDL_ERROR, "policy '%s' already defined at line %d.", name->string, policy->lineno);
00124     allow_rules(FALSE);
00125     return FALSE;
00126   }
00127 
00128   if ((policy = (policy_t *)malloc(sizeof(policy_t)))) {
00129     policy->name   = name->string;
00130     policy->rule   = (rule_t*)rules;
00131     policy->lineno = name->lineno;
00132     policy->next   = 0;
00133     policy->prev   = last_policy;
00134 
00135     if (top_policy)
00136       last_policy->next = policy;
00137     else
00138       top_policy = policy;
00139 
00140     last_policy = policy;
00141   } else {
00142     warning(PDL_ERROR, "Out of memory; cannot add policy '%s'.\n", name);
00143     return FALSE;
00144   }
00145 
00146   return TRUE;
00147 }
00148 
00149 
00157 void remove_policy(record_t* policy)
00158 {
00159   free(policy->string);
00160   free(policy);
00161 }
00162 
00163 
00171 policy_t* find_policy(const char* name)
00172 {
00173   policy_t* policy=top_policy;
00174 
00175   while (policy && strcmp(name, policy->name)!=0) {
00176     policy = policy->next;
00177   }
00178 
00179   return policy;  
00180 }
00181 
00182 
00190 BOOL check_policies_for_recursion(void)
00191 {
00192   BOOL recursion = FALSE;
00193   policy_t* policy = get_policies();
00194 
00195   while (policy) {
00196     lcmaps_log_debug(1, "Checking policy '%s' for recursions.\n", policy->name);
00197 
00198     if (check_rule_for_recursion(policy->rule)) {
00199       recursion = TRUE;
00200       lcmaps_log_debug(1, "Recursions were found.\n");
00201     }
00202     else
00203       lcmaps_log_debug(1, "No recursions were found.\n");
00204 
00205     policy = policy->next;
00206   }
00207 
00208   return recursion;
00209 }
00210 
00211 
00217 void reduce_policies(void)
00218 {
00219   policy_t* policy = get_policies();
00220 
00221   while (policy) {
00222     rule_t* rule = policy->rule;
00223     set_top_rule(rule);
00224 
00225     while (rule) {
00226       reduce_rule(rule);
00227       rule = rule->next;
00228     }
00229 
00230     policy = policy->next;
00231   }
00232 
00233   policies_reduced = TRUE;
00234 }
00235 
00236 
00237 
00244 policy_t* get_policies(void)
00245 {
00246   return top_policy;
00247 }
00248 
00249 
00254 void show_policies(void)
00255 {
00256   policy_t* policy = top_policy;
00257 
00258   while (policy) {
00259     lcmaps_log_debug(1, "policy: %s\n", policy->name);
00260     show_rules(policy->rule);
00261 
00262     policy = policy->next;
00263   }
00264 }
00265 
00266 
00271 void free_policies(void)
00272 {
00273   policy_t* next_pol, *policy = top_policy;
00274 
00275   while (policy) {
00276     next_pol = policy->next;
00277     free((char *)policy->name);
00278     free_rules(policy->rule);
00279     free(policy);
00280     policy = next_pol;
00281   }
00282 
00283   top_policy = 0;
00284 }
00285 
00286 
00293 BOOL policies_have_been_reduced(void)
00294 {
00295   return policies_reduced;
00296 }

Generated at Thu Mar 4 17:39:03 2004 for edg-lcmaps by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001