Lines 377-512
char** cache_entry_changed_attributes(CacheEntry *new, CacheEntry *old)
|
Link Here
|
---|
|
377 |
|
377 |
|
378 |
return changes; |
378 |
return changes; |
379 |
} |
379 |
} |
380 |
|
|
|
381 |
int copy_cache_entry(CacheEntry *cache_entry, CacheEntry *backup_cache_entry) { |
382 |
CacheEntryAttribute **cur1, **cur2; |
383 |
int i=0; |
384 |
int rv=0; |
385 |
memset(backup_cache_entry, 0, sizeof(CacheEntry)); |
386 |
for (cur1 = cache_entry->attributes; cur1 != NULL && *cur1 != NULL; cur1++) { |
387 |
if ((backup_cache_entry->attributes = realloc(backup_cache_entry->attributes, (backup_cache_entry->attribute_count+2)*sizeof(CacheEntryAttribute*))) == NULL) { |
388 |
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of attributes array failed"); |
389 |
rv = 1; |
390 |
goto result; |
391 |
} |
392 |
if ((backup_cache_entry->attributes[backup_cache_entry->attribute_count] = malloc(sizeof(CacheEntryAttribute))) == NULL) { |
393 |
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: malloc for CacheEntryAttribute failed"); |
394 |
rv = 1; |
395 |
goto result; |
396 |
} |
397 |
cur2 = &backup_cache_entry->attributes[backup_cache_entry->attribute_count]; |
398 |
(*cur2)->name=strdup((*cur1)->name); |
399 |
(*cur2)->values=NULL; |
400 |
(*cur2)->length=NULL; |
401 |
(*cur2)->value_count=0; |
402 |
backup_cache_entry->attributes[backup_cache_entry->attribute_count+1]=NULL; |
403 |
|
404 |
for (i = 0; i < (*cur1)->value_count; i++) { |
405 |
if (((*cur2)->values = realloc((*cur2)->values, ((*cur2)->value_count+2)*sizeof(char*))) == NULL) { |
406 |
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of values array failed"); |
407 |
rv = 1; |
408 |
goto result; |
409 |
} |
410 |
if (((*cur2)->length = realloc((*cur2)->length, ((*cur2)->value_count+2)*sizeof(int))) == NULL) { |
411 |
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of length array failed"); |
412 |
rv = 1; |
413 |
goto result; |
414 |
} |
415 |
if ((*cur1)->length[i] == strlen((*cur1)->values[i]) + 1) { |
416 |
if (((*cur2)->values[(*cur2)->value_count]=strdup((*cur1)->values[i])) == NULL) { |
417 |
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: strdup of value failed"); |
418 |
rv = 1; |
419 |
goto result; |
420 |
} |
421 |
(*cur2)->length[(*cur2)->value_count]=strlen((*cur2)->values[(*cur2)->value_count])+1; |
422 |
} else { |
423 |
if (((*cur2)->values[(*cur2)->value_count]=malloc(((*cur1)->length[i])*sizeof(char))) == NULL) { |
424 |
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: malloc for value failed"); |
425 |
rv = 1; |
426 |
goto result; |
427 |
} |
428 |
memcpy((*cur2)->values[(*cur2)->value_count],(*cur1)->values[i],(*cur1)->length[i]); |
429 |
(*cur2)->length[(*cur2)->value_count]=(*cur1)->length[i]; |
430 |
} |
431 |
(*cur2)->values[(*cur2)->value_count+1]=NULL; |
432 |
(*cur2)->value_count++; |
433 |
} |
434 |
backup_cache_entry->attribute_count++; |
435 |
} |
436 |
char **module_ptr; |
437 |
for (module_ptr=cache_entry->modules; module_ptr != NULL && *module_ptr != NULL; module_ptr++) { |
438 |
backup_cache_entry->modules = realloc(backup_cache_entry->modules, (backup_cache_entry->module_count+2)*sizeof(char*)); |
439 |
backup_cache_entry->modules[backup_cache_entry->module_count] = strdup(*module_ptr); |
440 |
backup_cache_entry->modules[backup_cache_entry->module_count+1] = NULL; |
441 |
backup_cache_entry->module_count++; |
442 |
} |
443 |
result: |
444 |
return rv; |
445 |
} |
446 |
|
447 |
void compare_cache_entries(CacheEntry *lentry, CacheEntry *rentry) |
448 |
{ |
449 |
char **changes; |
450 |
char **cur; |
451 |
int i=0; |
452 |
|
453 |
changes = cache_entry_changed_attributes(lentry, rentry); |
454 |
|
455 |
for (cur = changes; cur != NULL && *cur != NULL; cur++) { |
456 |
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT: %s differs\n", *cur); |
457 |
|
458 |
for (i=0; lentry->attributes != NULL && lentry->attributes[i] != NULL; i++) { |
459 |
if (STREQ(lentry->attributes[i]->name, *cur)) |
460 |
break; |
461 |
} |
462 |
if (lentry->attributes == NULL || lentry->attributes[i] == NULL) { |
463 |
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT: lentry = []\n"); |
464 |
} else { |
465 |
int j; |
466 |
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT: lentry = ["); |
467 |
for (j=0; lentry->attributes[i]->values && |
468 |
lentry->attributes[i]->values[j] != NULL; |
469 |
j++) { |
470 |
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, j == 0 ? "%s" : ", %s", lentry->attributes[i]->values[j]); |
471 |
} |
472 |
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "]\n"); |
473 |
} |
474 |
|
475 |
for (i=0; rentry->attributes != NULL && rentry->attributes[i] != NULL; i++) { |
476 |
if (STREQ(rentry->attributes[i]->name, *cur)) |
477 |
break; |
478 |
} |
479 |
if (rentry->attributes == NULL || rentry->attributes[i] == NULL) { |
480 |
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT: rentry = []\n"); |
481 |
} else { |
482 |
int j; |
483 |
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT: rentry = ["); |
484 |
for (j=0; rentry->attributes[i]->values && |
485 |
rentry->attributes[i]->values[j] != NULL; |
486 |
j++) { |
487 |
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, j == 0 ? "%s" : ", %s", rentry->attributes[i]->values[j]); |
488 |
} |
489 |
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "]\n"); |
490 |
} |
491 |
} |
492 |
free(changes); |
493 |
|
494 |
char **cur1, **cur2; |
495 |
|
496 |
for (cur1=lentry->modules; cur1 != NULL && *cur1 != NULL; cur1++) { |
497 |
for (cur2=rentry->modules; cur2 != NULL && *cur2 != NULL; cur2++) |
498 |
if (STREQ(*cur1, *cur2)) |
499 |
break; |
500 |
if (cur2 != NULL && *cur2 != NULL) |
501 |
continue; |
502 |
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT: module %s on lentry missing on rentry\n", *cur1); |
503 |
} |
504 |
for (cur2=rentry->modules; cur2 != NULL && *cur2 != NULL; cur2++) { |
505 |
for (cur1=lentry->modules; cur1 != NULL && *cur1 != NULL; cur1++) |
506 |
if (STREQ(*cur1, *cur2)) |
507 |
break; |
508 |
if (cur1 != NULL && *cur1 != NULL) |
509 |
continue; |
510 |
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT: module %s on rentry missing on lentry\n", *cur2); |
511 |
} |
512 |
} |