Simplified mapping list construction.
authorZdeněk Šustr <sustr4@cesnet.cz>
Mon, 3 Sep 2012 10:09:59 +0000 (10:09 +0000)
committerZdeněk Šustr <sustr4@cesnet.cz>
Mon, 3 Sep 2012 10:09:59 +0000 (10:09 +0000)
org.glite.lb.server/src/bkserverd.c
org.glite.lb.server/src/lb_authz.c

index 3bd9925..7655638 100644 (file)
@@ -1122,9 +1122,10 @@ int bk_handle_connection(int conn, struct timeval *timeout, void *data)
        else ctx->html_header_file = NULL;
 
        ctx->id_mapping.num = id_mapping.num;
+       ctx->id_mapping.rules = (_edg_wll_mapping_rule*)malloc(ctx->id_mapping.num * sizeof(_edg_wll_mapping_rule));
        for ( i = 0; i < ctx->id_mapping.num; i++ ) {
-               ctx->id_mapping.rules[i]->a = strdup(id_mapping.rules[i]->a);
-               ctx->id_mapping.rules[i]->b = strdup(id_mapping.rules[i]->b);
+               ctx->id_mapping.rules[i].a = strdup(id_mapping.rules[i].a);
+               ctx->id_mapping.rules[i].b = strdup(id_mapping.rules[i].b);
        }
 
        gettimeofday(&conn_start, 0);
index ce9e53b..42e8c17 100644 (file)
@@ -1237,11 +1237,11 @@ equal_mapped(const char *a, const char *b, struct _edg_wll_id_mapping *mapping)
        return 0;
 
     for (i = 0; i < mapping->num; i++) {
-       if (edg_wll_gss_equal_subj(a, mapping->rules[i]->a) &&
-           edg_wll_gss_equal_subj(b, mapping->rules[i]->b))
+       if (edg_wll_gss_equal_subj(a, mapping->rules[i].a) &&
+           edg_wll_gss_equal_subj(b, mapping->rules[i].b))
            return 1;
-       if (edg_wll_gss_equal_subj(a, mapping->rules[i]->b) &&
-           edg_wll_gss_equal_subj(b, mapping->rules[i]->a))
+       if (edg_wll_gss_equal_subj(a, mapping->rules[i].b) &&
+           edg_wll_gss_equal_subj(b, mapping->rules[i].a))
            return 1;
     }
     return 0;
@@ -1300,7 +1300,6 @@ parse_gridmap(edg_wll_Context ctx,
     char line[4096];
     char *p, *a, *b;
     int ret;
-    struct _edg_wll_mapping_rule *rule = NULL, **tmp;
 
     fd = fopen(file, "r");
     if (fd == NULL)
@@ -1330,26 +1329,18 @@ parse_gridmap(edg_wll_Context ctx,
            p++;
        b = p;
 
-       rule = malloc(sizeof(*rule));
-       if (rule == NULL) {
-           ret = edg_wll_SetError(ctx, ENOMEM, "Not enough memory");
-           goto end;
-       }
-       rule->a = strdup(a);
-       rule->b = strdup(b);
-       if (rule->a == NULL || rule->b == NULL) {
+
+       mapping->rules = realloc(mapping->rules, (mapping->num+1) * sizeof(_edg_wll_mapping_rule));
+       if (mapping->rules == NULL) {
            ret = edg_wll_SetError(ctx, ENOMEM, "Not enough memory");
            goto end;
        }
-
-       tmp = realloc(mapping->rules, (mapping->num+1) * sizeof(*tmp));
-       if (tmp == NULL) {
+       if (!(mapping->rules[mapping->num].a = strdup(a)) ||
+           !(mapping->rules[mapping->num].b = strdup(b))) {
            ret = edg_wll_SetError(ctx, ENOMEM, "Not enough memory");
            goto end;
        }
-       mapping->rules = tmp;
-       mapping->rules[mapping->num++] = rule;
-       rule = NULL;
+       mapping->num++;
     }
 
     ret = 0;