Example #1
0
size_t xacml_obligation_attributeassignments_length(const xacml_obligation_t * obligation) {
    if (obligation == NULL) {
        log_warn("xacml_obligation_attributeassignments_length: NULL obligation.");
        return 0;
    }
    return llist_length(obligation->assignments);
}
Example #2
0
size_t xacml_response_results_length(const xacml_response_t * response) {
    if (response == NULL) {
        log_warn("xacml_response_results_length: NULL response.");
        return 0;
    }
    return llist_length(response->results);
}
Example #3
0
void test_llist_length(void) {
  Node node;
  Llist list = NULL;
  node_alloc(&node);
  node.score = 0;
  for (int i = 0; i < 50; ++i) {
    llist_add(node, &list);
    node.score++;
  }
  node_free(&node);

  CU_ASSERT_EQUAL(llist_length(list), 50);

  llist_free(&list);
}
Example #4
0
int main() //@ : main
  //@ requires emp;
  //@ ensures emp;
{
  struct llist *l1 = create_llist();
  struct llist *l2 = create_llist();
  llist_add(l1, 10);
  llist_add(l1, 20);
  llist_add(l1, 30);
  llist_add(l2, 40);
  llist_add(l2, 50);
  llist_add(l2, 60);
  int x = llist_removeFirst(l2); assert(x == 40);
  llist_append(l1, l2);
  int n = llist_length(l1); assert(n == 5);
  int e0 = llist_lookup(l1, 0); assert(e0 == 10);
  int e1 = llist_lookup(l1, 1); assert(e1 == 20);
  int e2 = llist_lookup(l1, 2); assert(e2 == 30);
  int e3 = llist_lookup(l1, 3); assert(e3 == 50);
  int e4 = llist_lookup(l1, 4); assert(e4 == 60);
  llist_dispose(l1);
  return 0;
}
Example #5
0
int llist_delete_elements(linkedlist_t * list, delete_element_func deletef) {
    size_t list_l;
    void ** unique_elts;
    void * elt, * unique_elt;
    int unique_elts_l, i, j, duplicated;
    if (list == NULL) {
        log_error("llist_delete_elements: NULL pointer list.");
        return LLIST_ERROR;
    }
    /* WARN: the list can contains many times the same element (same memory address) */
    list_l= llist_length(list);
    unique_elts= calloc(list_l,sizeof(void *));
    unique_elts_l= 0, i= 0, j= 0;
    for (i=0; i<list_l; i++) {
        elt= llist_get(list,i);
        /* add elt to elts list if not already included */
        duplicated= 0;
        for(j= 0; j<unique_elts_l; j++) {
            if (elt == unique_elts[j]) {
                duplicated= 1;
            }
        }
        if (!duplicated) {
            /* add at end */
            unique_elts[unique_elts_l++]= elt;
        }
    }
    /* apply delete func on unique element */
    for(i= 0; i<unique_elts_l; i++) {
        unique_elt= unique_elts[i];
        if (deletef) {
            deletef(unique_elt);
        }
    }
    free(unique_elts);
    return LLIST_OK;
}
Example #6
0
/**
 * read_from_client
 *
 * Handles the activities that take place on the sockets monitored by
 * select. The activity includes new connections or data transfer from
 * existing connections.
 *
 * @param s Server struct, contains information about the server.
 */
void read_from_socket(server *s) {
	//int ret, maxi;
	client *c = NULL;
	node *n = NULL;

	//maxi = 0;

	/* Check if a client is trying to connect */
	pthread_mutex_trylock(&s->dataLock);
	if (FD_ISSET(s->listen_sd, &s->allset)) {

		/* get the client data ready */
		c = client_new();

		/* blocking call waiting for connections */
		c->fd = accept(s->listen_sd, (struct sockaddr *) &c->sa, &c->sa_len);
		/* make the client Socket non-blocking */
		if (fcntl(c->fd, F_SETFL, O_NONBLOCK | fcntl(c->fd, F_GETFL, 0)) == -1)
			SystemFatal("fcntl(): Client Non-Block Failed\n");

		fprintf(stdout, "Received connection from (%s, %d)\n",
			inet_ntoa(c->sa.sin_addr),
			ntohs(c->sa.sin_port));
		s->n_clients++;
		s->n_max_connected++;
		/*s->n_max_connected = (s->n_clients > s->n_max_connected) ?
				s->n_clients : s->n_max_connected;*/
		s->client_list = llist_append(s->client_list, (void *)c);
		fprintf(stdout, "Added client to list, new size: %d\n",
			llist_length(s->client_list));
		/* add the client to the list */
		/*for (i = 0; i < FD_SETSIZE; i++) {
			if (s->clientConn[i] == NULL) {
			s->clientConn[i] = c;
			//break;
			}
			if (s->clients[i] < 0) {
			s->clients[i] = c->fd;
			break;
			}
			if (i == FD_SETSIZE) {
			SystemFatal("To Many Clients\n");
			}
			}*/
		/* add the socket connections to the fd_set */
		/*FD_SET(c->fd, &s->allset);
		s->maxfd = (c->fd > s->maxfd) ?
		c->fd : s->maxfd;
		maxi = (i > maxi) ? i : maxi;*/
		c = NULL;
	}
	pthread_mutex_unlock(&s->dataLock);

	for (n = s->client_list->link; n != NULL; n = n->next) {

		/* check if the client cause an event */
		pthread_mutex_trylock(&s->dataLock);
		c = (client *)n->data;
		if (FD_ISSET(c->fd, &s->allset)) {
			process_client_req(c, s);
			//process_client_data(c, s);
		}
		pthread_mutex_unlock(&s->dataLock);

		//pthread_mutex_trylock(&s->dataLock);  TRY THIS LATER
		if (c->quit) {
			pthread_mutex_trylock(&s->dataLock);
			s->n_clients--;
			s->client_list = llist_remove(s->client_list, (void *)c, client_compare);
			fprintf(stderr, "[%5d]Removed client from list, new size: %d\n",
				c->fd, llist_length(s->client_list));
			close(c->fd);
			free(c);
			c = NULL;
			pthread_mutex_unlock(&s->dataLock);
		}
		//pthread_mutex_unlock(&s->dataLock);  TRY THIS LATER
	}

	/* go through the available connections */
	/*for(n = 0; n <= maxi; n++) {
		pthread_mutex_trylock(&s->dataLock);
		if(FD_ISSET(s->clients[n], &s->allset)){
		process_client_data();
		}
		pthread_mutex_unlock(&s->dataLock);
		}*/
	//free(c);
}