MCPcopy Create free account
hub / github.com/ClusterLabs/pacemaker / expand_plus_plus

Function expand_plus_plus

lib/common/xml.c:257–316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

255
256
257void
258expand_plus_plus(xmlNode* target, const char *name, const char *value)
259{
260 int offset = 1;
261 int name_len = 0;
262 int int_value = 0;
263 int value_len = 0;
264
265 const char *old_value = NULL;
266
267 if(value == NULL || name == NULL) {
268 return;
269 }
270
271 old_value = crm_element_value(target, name);
272
273 if(old_value == NULL) {
274 /* if no previous value, set unexpanded */
275 goto set_unexpanded;
276
277 } else if(strstr(value, name) != value) {
278 goto set_unexpanded;
279 }
280
281 name_len = strlen(name);
282 value_len = strlen(value);
283 if(value_len < (name_len + 2)
284 || value[name_len] != '+'
285 || (value[name_len+1] != '+' && value[name_len+1] != '=')) {
286 goto set_unexpanded;
287 }
288
289 /* if we are expanding ourselves,
290 * then no previous value was set and leave int_value as 0
291 */
292 if(old_value != value) {
293 int_value = char2score(old_value);
294 }
295
296 if(value[name_len+1] != '+') {
297 const char *offset_s = value+(name_len+2);
298 offset = char2score(offset_s);
299 }
300 int_value += offset;
301
302 if(int_value > INFINITY) {
303 int_value = INFINITY;
304 }
305
306 crm_xml_add_int(target, name, int_value);
307 return;
308
309 set_unexpanded:
310 if(old_value == value) {
311 /* the old value is already set, nothing to do */
312 return;
313 }
314 crm_xml_add(target, name, value);

Callers 2

copy_in_propertiesFunction · 0.85
fix_plus_plus_recursiveFunction · 0.85

Calls 4

crm_element_valueFunction · 0.85
char2scoreFunction · 0.85
crm_xml_add_intFunction · 0.85
crm_xml_addFunction · 0.85

Tested by

no test coverage detected