…lines 1–24 unchanged (24 lines)
25
26#include "farmpolicy.h"
27#include "farms.h"
28#include "farmaddress.h"
29#include "objects.h"
30#include "network.h"
31#include "zcu_log.h"
32
33
34static struct farmpolicy * farmpolicy_create(struct farm *f, struct policy *p)
35{
36 struct farmpolicy *fp = (struct farmpolicy *)malloc(sizeof(struct farmpolicy));
37 if (!fp) {
38 zcu_log_print(LOG_ERR, "Farm Policy memory allocation error");
39 return NULL;
40 }
41
42 fp->farm = f;
43 fp->policy = p;
44 fp->action = DEFAULT_ACTION;
…lines 45–74 unchanged (30 lines)
75
76void farmpolicy_s_print(struct farm *f)
77{
78 struct farmpolicy *fp;
79
80 list_for_each_entry(fp, &f->policies, list) {
81 zcu_log_print(LOG_DEBUG," [policy] ");
82 zcu_log_print(LOG_DEBUG," [%s] %s", CONFIG_KEY_NAME, fp->policy->name);
83 zcu_log_print(LOG_DEBUG," *[%s] %d", CONFIG_KEY_ACTION, fp->action);
84 }
85}
86
87struct farmpolicy * farmpolicy_lookup_by_name(struct farm *f, const char *name)
88{
89 struct farmpolicy *fp;
…lines 90–95 unchanged (6 lines)
96 return NULL;
97}
98
99int farmpolicy_set_action(struct farmpolicy *fp, int action)
100{
101 struct farm *f = fp->farm;
102
103 zcu_log_print(LOG_DEBUG, "%s():%d: farm %s action %d", __FUNCTION__, __LINE__, fp->farm->name, action);
104
105 if (action == ACTION_DELETE) {
106 farmpolicy_delete(fp);
107 farmaddress_s_set_action(f, ACTION_RELOAD);
108 return 1;
109 }
…lines 110–122 unchanged (13 lines)
123 return 0;
124}
125
126int farmpolicy_s_set_action(struct farm *f, int action)
127{
128 struct farmpolicy *fp, *next;
129
130 zcu_log_print(LOG_DEBUG, "%s():%d: farm %s action %d", __FUNCTION__, __LINE__, f->name, action);
131
132 list_for_each_entry_safe(fp, next, &f->policies, list)
133 farmpolicy_set_action(fp, action);
134
135 f->policies_action = action;
136
…lines 137–147 unchanged (11 lines)
148}
149
150int farmpolicy_s_lookup_policy_action(struct farm *f, char *name, int action)
151{
152 struct farmpolicy *fp;
153 int ret = 0;
154
155 zcu_log_print(LOG_DEBUG, "%s():%d: looking for policy %s in farm %s", __FUNCTION__, __LINE__, name, f->name);
156
157 fp = farmpolicy_lookup_by_name(f, name);
158 if (fp)
159 ret = farmpolicy_set_action(fp, action);
160
161 if (ret) {
…lines 162–197 unchanged (36 lines)
198int farmpolicy_pre_actionable(struct config_pair *c)
199{
200 struct farm *f = obj_get_current_farm();
201
202 if (!f)
203 return -1;
204
205 zcu_log_print(LOG_DEBUG, "%s():%d: pre actionable farm policy for farm %s", __FUNCTION__, __LINE__, f->name);
206
207 farm_set_action(f, ACTION_RELOAD);
208 farmaddress_s_set_action(f, ACTION_RELOAD);
209 farm_rulerize(f);
210
211 return 0;
212}
213
214int farmpolicy_pos_actionable(struct config_pair *c)
215{
216 struct farmpolicy *fp = obj_get_current_farmpolicy();
217 struct farm *f = obj_get_current_farm();
218
219 if (!fp || !f)
220 return -1;
221
222 zcu_log_print(LOG_DEBUG, "%s():%d: pos actionable farm policy %s for farm %s with param %d", __FUNCTION__, __LINE__, fp->policy->name, f->name, c->key);
223
224 farm_set_action(f, ACTION_RELOAD);
225 farmaddress_s_set_action(f, ACTION_RELOAD);
226
227 return 0;
228}
229