int level_deep_diff(poldiff_t * diff, const void *x, const void *y) { const qpol_level_t *l1 = x; const qpol_level_t *l2 = y; apol_vector_t *v1 = NULL, *v2 = NULL; apol_vector_t *added = NULL, *removed = NULL, *unmodified = NULL; const char *name; poldiff_level_t *l = NULL; int retval = -1, error = 0, compval; if (qpol_level_get_name(diff->orig_qpol, l1, &name) < 0 || (v1 = level_get_cats(diff, diff->orig_pol, l1)) == NULL || (v2 = level_get_cats(diff, diff->mod_pol, l2)) == NULL) { error = errno; goto cleanup; } apol_vector_sort(v1, apol_str_strcmp, NULL); apol_vector_sort(v2, apol_str_strcmp, NULL); compval = level_deep_diff_cats(diff, v1, v2, &added, &removed, &unmodified); if (compval < 0) { error = errno; goto cleanup; } else if (compval > 0) { if ((l = make_diff(diff, POLDIFF_FORM_MODIFIED, name)) == NULL) { error = errno; goto cleanup; } apol_vector_destroy(&l->added_cats); apol_vector_destroy(&l->removed_cats); apol_vector_destroy(&l->unmodified_cats); if ((l->added_cats = apol_vector_create_from_vector(added, apol_str_strdup, NULL, free)) == NULL || (l->removed_cats = apol_vector_create_from_vector(removed, apol_str_strdup, NULL, free)) == NULL || (l->unmodified_cats = apol_vector_create_from_vector(unmodified, apol_str_strdup, NULL, free)) == NULL) { error = errno; ERR(diff, "%s", strerror(error)); goto cleanup; } apol_vector_sort(l->removed_cats, level_cat_comp, diff->orig_qpol); apol_vector_sort(l->added_cats, level_cat_comp, diff->mod_qpol); apol_vector_sort(l->unmodified_cats, level_cat_comp, diff->orig_qpol); if (apol_vector_append(diff->level_diffs->diffs, l) < 0) { error = errno; ERR(diff, "%s", strerror(error)); goto cleanup; } diff->level_diffs->num_modified++; } retval = 0; cleanup: apol_vector_destroy(&v1); apol_vector_destroy(&v2); apol_vector_destroy(&added); apol_vector_destroy(&removed); apol_vector_destroy(&unmodified); if (retval != 0) { level_free(l); } errno = error; return retval; }
int level_new_diff(poldiff_t * diff, poldiff_form_e form, const void *item) { const qpol_level_t *l = item; const char *name = NULL; poldiff_level_t *pl = NULL; apol_policy_t *p; qpol_policy_t *q; apol_vector_t *v = NULL; int error = 0, retval = -1; if (form == POLDIFF_FORM_ADDED) { p = diff->mod_pol; q = diff->mod_qpol; } else { p = diff->orig_pol; q = diff->orig_qpol; } if (qpol_level_get_name(q, l, &name) < 0 || (pl = make_diff(diff, form, name)) == NULL) { error = errno; goto cleanup; } if ((v = level_get_cats(diff, p, l)) == NULL) { error = errno; ERR(diff, "%s", strerror(error)); goto cleanup; } if (form == POLDIFF_FORM_ADDED) { apol_vector_destroy(&pl->added_cats); if ((pl->added_cats = apol_vector_create_from_vector(v, apol_str_strdup, NULL, free)) == NULL) { error = errno; ERR(diff, "%s", strerror(error)); goto cleanup; } } else if (form == POLDIFF_FORM_REMOVED) { apol_vector_destroy(&pl->removed_cats); if ((pl->removed_cats = apol_vector_create_from_vector(v, apol_str_strdup, NULL, free)) == NULL) { error = errno; ERR(diff, "%s", strerror(error)); goto cleanup; } } if (apol_vector_append(diff->level_diffs->diffs, pl) < 0) { error = errno; ERR(diff, "%s", strerror(error)); goto cleanup; } if (form == POLDIFF_FORM_ADDED) { diff->level_diffs->num_added++; } else { diff->level_diffs->num_removed++; } retval = 0; cleanup: apol_vector_destroy(&v); if (retval < 0) { level_free(pl); errno = error; } return retval; }
TEST(linear_function_mixer, mix) { linear_function_mixer m( linear_function_mixer::model_ptr(new storage::storage_mock_1)); diffv d1 = make_diff(1, 2, 3, 5); diffv d = make_diff(2, 3, 4, 3); m.mix(d1, d); EXPECT_EQ(8, d.count); ASSERT_EQ(1u, d.v.diff.size()); EXPECT_EQ("f1", d.v.diff[0].first); ASSERT_EQ(1u, d.v.diff[0].second.size()); EXPECT_EQ("l1", d.v.diff[0].second[0].first); // (1 * 5 + 2 * 3) / (5 + 3) EXPECT_EQ(11./8., d.v.diff[0].second[0].second.v1); // min(2, 3) EXPECT_EQ(2., d.v.diff[0].second[0].second.v2); // (3 * 5 + 4 * 3) / (5 + 3) EXPECT_EQ(27./8., d.v.diff[0].second[0].second.v3); }
TEST(linear_function_mixer, mix) { linear_function_mixer m; diffv d1 = make_diff(1, 2, 3, 5); diffv d2 = make_diff(2, 3, 4, 3); diffv d; m.mix_impl(d1, d2, d); EXPECT_EQ(8, d.count); ASSERT_EQ(1u, d.v.size()); EXPECT_EQ("f1", d.v[0].first); ASSERT_EQ(1u, d.v[0].second.size()); EXPECT_EQ("l1", d.v[0].second[0].first); // (1 * 5 + 2 * 3) / (5 + 3) EXPECT_EQ(11./8., d.v[0].second[0].second.v1); // min(2, 3) EXPECT_EQ(2., d.v[0].second[0].second.v2); // (3 * 5 + 4 * 3) / (5 + 3) EXPECT_EQ(27./8., d.v[0].second[0].second.v3); }
int genere_diff(int sock,int nb){ long lus; int i; char buff[57]; buff[56]='\0'; for(i=0;i<nb;i++){ char type[5]; char id[9]; char ip1[16]; char port1[5]; char ip2[16]; char port2[5]; lus=recv(sock, buff, 57, 0);//4+1+8+1+15+1+4+1+15+1+4+2 // printf("LUS : %lu -%s-\n",lus,buff); if(lus!=57){ print("Erreur de format -5-, fin de la connexion au gestionnaire."); return 0; } snprintf(type,5,"%s",buff); if(strcmp("ITEM",type)){ print("Erreur de format -6-, fin de la connexion au gestionnaire."); return 0; } snprintf(id,9,"%s",(buff+5)); snprintf(ip1,16,"%s",(buff+14)); snprintf(port1, 5, "%s",(buff+30)); snprintf(ip2,16,"%s",(buff+35)); snprintf(port2, 5, "%s",(buff+51)); if(strlen(id)!=8 || !verif_ip(ip1) || !verif_ip(ip2) || !verif_port(port1) || !verif_port(port2)){ print("Erreur de format -7-, fin de la connexion au gestionnaire."); return 0; } printf("GENERE LIST : \n"); printf("id : -%s-\n p1 : -%s-\n ip1 : -%s-\n p2 : -%s-\n ip2 : -%s-\n",id,port1,ip1,port2,ip2); add_diff(&liste_tmp, make_diff(id, port1, ip1, port2, ip2)); } return 1; }
static lisp_cell_t *subr_diff(lisp_t * l, lisp_cell_t * args) { /**@bug makes results in reverse order*/ /**@todo This should operate on two strings as well as lists of strings*/ size_t i; lisp_cell_t *a, *b, *tmp, *ret = NULL; char **aa, **bb; diff *d = NULL; a = car(args); b = CADR(args); if (!(aa = calloc(get_length(a) + 2, sizeof(*aa)))) /**@bug +2??*/ LISP_HALT(l, "\"%s\"", "out of memory"); if (!(bb = calloc(get_length(b) + 2, sizeof(*bb)))) /**@bug +2??*/ LISP_HALT(l, "\"%s\"", "out of memory"); for (tmp = a, i = 0; !is_nil(tmp); tmp = cdr(tmp), i++) if (!is_asciiz(car(tmp))) goto cleanup; else aa[i] = get_str(car(tmp)); for (tmp = b, i = 0; !is_nil(tmp); tmp = cdr(tmp), i++) if (!is_asciiz(car(tmp))) goto cleanup; else bb[i] = get_str(car(tmp)); if (!(d = lcs(aa, get_length(a), bb, get_length(b)))) LISP_HALT(l, "\"%s\"", "out of memory"); ret = make_diff(l, d, aa, bb); cleanup: free(aa); free(bb); if (d) free(d->c); free(d); if (ret) return ret; LISP_RECOVER(l, "\"expected two lists of strings\" '%S", args); return gsym_error(); }
explicit countdown(Difference n) : m_n(make_diff(n)) {}
int level_deep_diff_apol_mls_levels(poldiff_t * diff, const apol_mls_level_t * level1, const apol_mls_level_t * level2, poldiff_level_t ** orig_pl, poldiff_level_t ** mod_pl) { poldiff_level_t *u1 = NULL, *u2 = NULL; apol_vector_t *added = NULL, *removed = NULL, *unmodified = NULL; const char *sens1 = apol_mls_level_get_sens(level1); const apol_vector_t *cats1 = apol_mls_level_get_cats(level1); const char *sens2 = apol_mls_level_get_sens(level2); const apol_vector_t *cats2 = apol_mls_level_get_cats(level2); int retval = -1, compval; *orig_pl = *mod_pl = NULL; if (strcmp(sens1, sens2) != 0) { /* sensitivities do not match, so don't check categories */ if ((u1 = make_diff(diff, POLDIFF_FORM_REMOVED, sens1)) == NULL || (u2 = make_diff(diff, POLDIFF_FORM_ADDED, sens2)) == NULL) { ERR(diff, "%s", strerror(errno)); level_free(u1); level_free(u2); return -1; } apol_vector_destroy(&u1->removed_cats); apol_vector_destroy(&u2->added_cats); if ((u1->removed_cats = apol_vector_create_from_vector(cats1, apol_str_strdup, NULL, free)) == NULL || (u2->added_cats = apol_vector_create_from_vector(cats2, apol_str_strdup, NULL, free)) == NULL) { ERR(diff, "%s", strerror(errno)); level_free(u1); level_free(u2); return -1; } apol_vector_sort(u1->removed_cats, level_cat_comp, diff->orig_qpol); apol_vector_sort(u2->added_cats, level_cat_comp, diff->mod_qpol); *orig_pl = u1; *mod_pl = u2; return 0; } compval = level_deep_diff_cats(diff, cats1, cats2, &added, &removed, &unmodified); if (compval < 0) { goto cleanup; } else if (compval > 0) { if ((u1 = calloc(1, sizeof(*u1))) == NULL || (u1->name = strdup(sens1)) == NULL || (u1->added_cats = apol_vector_create_from_vector(added, apol_str_strdup, NULL, free)) == NULL || (u1->removed_cats = apol_vector_create_from_vector(removed, apol_str_strdup, NULL, free)) == NULL || (u1->unmodified_cats = apol_vector_create_from_vector(unmodified, apol_str_strdup, NULL, free)) == NULL) { ERR(diff, "%s", strerror(errno)); level_free(u1); goto cleanup; } apol_vector_sort(u1->added_cats, level_cat_comp, diff->mod_qpol); apol_vector_sort(u1->removed_cats, level_cat_comp, diff->orig_qpol); apol_vector_sort(u1->unmodified_cats, level_cat_comp, diff->orig_qpol); u1->form = POLDIFF_FORM_MODIFIED; *orig_pl = u1; } retval = 0; cleanup: apol_vector_destroy(&added); apol_vector_destroy(&removed); apol_vector_destroy(&unmodified); return retval; }