Exemple #1
0
void animate_spermicides(char *base) {

	if (spermicides->first == NULL) return;

	lst_iitem_t* curSp;
	
	int n = 0;
	for(curSp = spermicides->first; curSp != NULL; curSp = curSp->next)
		n++;
	
	for(curSp = spermicides->first; curSp != NULL; curSp = curSp->next){
		destroySprite(curSp->spr, base);
		
		if (!check_spermicide_colision(curSp->spr,curSp->spr->y - curSp->spr->yspeed)) {
			curSp->spr->y -= curSp->spr->yspeed;
			drawSprite(curSp->spr, base);
		}
		else {
			deleteSprite(curSp->spr);
			curSp = lst_remove(spermicides, curSp->spr);
			if (curSp == NULL) break;
		}
	}
	
}
int
ConnectorFree (c_tree * ct, ident_t ident)
{
  if (ident)
    lst_remove ( ct, ident);
  return 1;
}
Exemple #3
0
int readFromPipe(int inputPipe, char * buffer, int * terminalPid, TerminalList * termlist) {
  int len;
  int op;
  int statsPipe;
  double totalTime;
  TESTTRUE((read(inputPipe, &op, sizeof(int))==sizeof(int)), "Erro no formato do pipe (" _AT_ ")\n");
  printf("\nNew operation:\n");
  printf("op: %d\n", op);
  if (op==0) {
    TESTTRUE((read(inputPipe, &len, sizeof(int)) == sizeof(int)), "Erro no formato do pipe (" _AT_ ")\n");
    printf("len: %d\n", len);
    TESTTRUE((read(inputPipe, terminalPid, sizeof(int)) == sizeof(int)), "Erro no formato do pipe (" _AT_ ")\n");
    printf("pid: %d\n", *terminalPid);
    TESTTRUE((read(inputPipe, buffer, len) == len), "Erro no formato do pipe (" _AT_ ")\n");
    buffer[len]=0;
    return 0;
  } else if (op==1) { //informacao que foi criado um novo terminal
    TESTTRUE((read(inputPipe, terminalPid, sizeof(int)) == sizeof(int)), "Erro no formato do pipe (" _AT_ ")\n");
    lst_insert(termlist, *terminalPid);
    printf("pid: %d\n", *terminalPid);
    return 1;
  } else if (op==2) { //informacao que foi fechado um terminal
    TESTTRUE((read(inputPipe, terminalPid, sizeof(int)) == sizeof(int)), "Erro no formato do pipe (" _AT_ ")\n");
    lst_remove(termlist, *terminalPid);
    printf("pid: %d\n", *terminalPid);
    return 2;
  } else if (op==3) { //informacao que e para se fechar a par-shell
    exitCalled = 1;
    return 3;
  } else if (op==4)  {//recebeu um stats
    TESTTRUE((read(inputPipe, &len, sizeof(int)) == sizeof(int)), "Erro no formato do pipe (" _AT_ ")\n");
    printf("len: %d\n", len);
    TESTTRUE((read(inputPipe, terminalPid, sizeof(int)) == sizeof(int)), "Erro no formato do pipe (" _AT_ ")\n");
    printf("pid: %d\n", *terminalPid);
    TESTTRUE((read(inputPipe, buffer, len) == len), "Erro no formato do pipe (" _AT_ ")\n");
    buffer[len]=0;
    if ((statsPipe = open(buffer, O_WRONLY)) < 0) {
      fprintf(stderr, "Erro ao abrir o ficheiro de output " INPUT_FILE "\n");
      exit(EXIT_FAILURE);
    }
    totalTime = getTotalTime();
    if (write(statsPipe, (char*)&runningProcesses, sizeof(int)) != sizeof(int)) {
      fprintf(stderr, "Warning: erro a escrever para um pipe\n");
    }
    if (write(statsPipe, (char*)&totalTime, sizeof(double)) != sizeof(double)) {
      fprintf(stderr, "Warning: erro a escrever para um pipe \n");
    }
    if (close(statsPipe)) {
      fprintf(stderr, "Warning: erro ao fechar um pipe \n");
    }
    return 4;
  }
  fprintf(stderr,"Warning: Unknown operator!\n");
  return -1;
}
void		*lst_remove_iterator_node(t_lstiter *it)
{
	void	*data;
	size_t	pos;
	t_node	*node;

	node = it->current;
	pos = it->pos;
	lst_iterator_next(it);
	it->flag = 2;
	data = lst_remove(it->lst, pos);
	if (node == it->end)
		init_iter(it, it->lst, it->dir);
	else
		it->pos = pos;
	return (data);
}
/* description: free local resources
 */
static void
_local_chann_close(tun_local_chann_t *c) {
   tun_local_t *tun = _tun_local();
   if (c->node) {
      _local_chann_closing(c);

      c->state = LOCAL_CHANN_STATE_NONE;

      lst_remove(tun->active_lst, c->node);
      lst_pushl(tun->free_lst, c);

      c->node = NULL;
      tun->channs[c->chann_id] = NULL;

      /* _verbose("chann %d:%d close, (a:%d,f:%d)\n", c->chann_id, c->magic, */
      /*         lst_count(tun->active_lst), lst_count(tun->free_lst)); */
   }
}
Exemple #6
0
/** Build the maze by removing walls according to Prim's algorithm.
 *
 *  @param maze a maze with all walls present.
 */
static void build_prim(maze_t* maze) {
    // MST edges and cells.  If (a, b) in mst_edges, then (b, a) not in
    // mst_edges.  (a, b) in mst_edges iff a, b both in mst_cells.
    list356_t* mst_edges = make_list() ;
    list356_t* mst_cells = make_list() ;

    // The frontier.  This is the collection of edges between cells in the MST
    // and cells not in the MST.  If (a, b) in frontier, then a in mst_cells
    // and b not in mst_cells.
    list356_t* frontier = make_list() ;

    // Choose two adjacent cells at random to put into the MST, then
    // populate the frontier accordinately.  For simplicitly, choose a
    // cell in the interior of the maze, then randomly choose a direction
    // for the other cell.
    cell_t* start = 
        get_cell(maze, random_limit(1, maze->nrows-1), 
                random_limit(1, maze->ncols-1));
    unsigned char direction = 1 << random_limit(0, 4) ;

    cell_t* next = get_neighbor(maze, start, direction) ;
    /*
    debug("Removing (%d, %d) - (%d, %d).\n",
            start->r, start->c, next->r, next->c) ;
    */
    remove_wall(maze, start, direction) ;

    edge_t init_edge = (edge_t){start, next} ;
    lst_add(mst_edges, &init_edge) ;
    lst_add(mst_cells, start) ;
    lst_add(mst_cells, next) ;

    for (int d=0; d<4; ++d) {
        if (directions[d] != direction && is_cell(maze, start, directions[d])) {
            cell_t* c = get_neighbor(maze, start, directions[d]) ;
            edge_t* e = malloc(sizeof(edge_t)) ;
            e->a = start ; e->b = c ;
            lst_add(frontier, e) ;
        }
    }

    for (int d=0; d<4; ++d) {
        if (directions[d] != opposite(direction) 
                && is_cell(maze, next, directions[d])) {
            cell_t* c = get_neighbor(maze, next, directions[d]) ;
            edge_t* e = malloc(sizeof(edge_t)) ;
            e->a = next ; e->b = c ;
            lst_add(frontier, e) ;
        }
    }

    // As long as we don't have all the cells in the MST, choose an
    // edge in the frontier at random.  Put the edge in the MST
    // and compute the new edges to add to the frontier.
    while (lst_size(mst_cells) < (maze->nrows)*(maze->ncols)) {
        int p = random_limit(0, lst_size(frontier)) ;
        edge_t* edge = lst_get(frontier, p) ;
        cell_t* old_cell = edge->a ;
        cell_t* new_cell = edge->b ;
        /*
        debug("Removing (%d, %d) - (%d, %d).\n",
                old_cell->r, old_cell->c, new_cell->r, new_cell->c) ;
        */
        remove_wall(maze, old_cell, get_direction(old_cell, new_cell)) ;

        lst_add(mst_edges, edge) ;
        lst_add(mst_cells, new_cell) ;

        for (int d=0; d<4; ++d) {
            unsigned char dir = directions[d] ;
            if (is_cell(maze, new_cell, dir)) {
                cell_t* adj_cell = get_neighbor(maze, new_cell, dir) ;
                edge_t* edge2 = malloc(sizeof(edge_t)) ;
                edge2->a = new_cell ; edge2->b = adj_cell ;
                if (lst_contains(mst_cells, adj_cell, cell_cmp)) {
                    lst_remove(frontier, edge2, edge_cmp) ;
                    if (adj_cell != old_cell) free(edge2) ;
                }
                else {
                    lst_add(frontier, edge2) ;
                }
            }
        }
    }


}
Exemple #7
0
/*
 *	reset_rl_fs_directives()
 *	Functions to remove releaser file policy
 *	for a particular file name.
 */
int
reset_rl_fs_directive(
ctx_t *ctx,				/* ARGSUSED */
rl_fs_directive_t *rl_fs_directives)	/* Not freed in this function */
{
	releaser_cfg_t *releaser;
	rl_fs_directive_t *rl_fsname;
	node_t *node_c;
	int match_flag = 0;

	Trace(TR_MISC, "reset releaser's file system directives");
	if (ISNULL(rl_fs_directives)) {
		Trace(TR_ERR, "%s", samerrmsg);
		return (-1);
	}

	/*
	 *	read releaser.cmd file to get all
	 *	releaser.cmd information.
	 */
	if (read_releaser_cfg(&releaser) != 0) {
		Trace(TR_MISC, "Read of %s failed with error: %s",
		    releaser_file, samerrmsg);
		return (-1);
	}
	/*
	 *	Following block traverses rl_fs_dir_list
	 *	list, to find if given file system already
	 *	exist. It it exist, remove its list from
	 *	rl_fs_dir_list.
	 */
	node_c = (releaser->rl_fs_dir_list)->head;
	while (node_c != NULL) {
		rl_fsname = (rl_fs_directive_t *)node_c ->data;
		if (strcmp(rl_fsname->fs,
		    rl_fs_directives->fs) == 0) {
			if (lst_remove(releaser->rl_fs_dir_list, node_c) != 0) {
				goto error;
			}
			free(rl_fsname);
			match_flag = 1;
			break;
		}
		node_c = node_c->next;
	}
	if (match_flag == 0) {
		samerrno = SE_NO_RL_FS_FOUND;
		snprintf(samerrmsg, MAX_MSG_LEN,
		    GetCustMsg(SE_NO_RL_FS_FOUND),
		    rl_fs_directives->fs);
		goto error;
	}
	/*
	 *	write releaser.cmd with TRUE option
	 *	and it will force to write a new releaser.cmd.
	 */
	if (write_releaser_cfg(releaser, B_TRUE) != 0) {
		goto error;
	}
	Trace(TR_FILES, "rl_fsname %s is removed from releaser.cmd\n",
	    rl_fs_directives->fs);
	free_releaser_cfg(releaser);
	Trace(TR_MISC, "reset releaser's file system directives success");
	return (0);
error:
	free_releaser_cfg(releaser);
	Trace(TR_ERR, "%s", samerrmsg);
	return (-1);
}
Exemple #8
0
/*
 *  filepath may be either a directory or a fully-qualified path.
 *  if it's fully-qualified, only directory entries that sort alphabetically
 *  after the specified file will be returned.
 *
 *  morefiles will be set if there are more entries left in the directory
 *  after maxentries have been returned.  This is intended to let the caller
 *  know they can continue reading.
 *
 *  Note that the directory may change while we're reading it.  If it does,
 *  files that have been added or removed since we started reading it may
 *  not be accurately reflected.
 */
int
list_directory(
	ctx_t		*c,			/* ARGSUSED */
	int		maxentries,
	char		*listDir,		/* directory to list */
	char		*startFile,		/* if continuing, start here */
	char		*restrictions,
	uint32_t	*morefiles,		/* OUT */
	sqm_lst_t		**direntries)		/* OUT */
{
	int		rval = 0;
	int		st = 0;
	DIR		*curdir; /* Variable for directory system calls */
	dirent64_t	*entry;	/* Pointer to a directory entry */
	dirent64_t	*entryp;
	struct stat64	sout;
	restrict_t	filter = {0};
	char		*data;	/* Pointer to data item to add to list */
	node_t		*node;
	sqm_lst_t		*lstp = NULL;
	char		buf[MAXPATHLEN + 1];
	char		*fname;

	if (ISNULL(listDir, direntries, morefiles)) {
		return (-1);
	}

	*morefiles = 0;

	/* Set up wildcard restrictions */
	rval = set_restrict(restrictions, &filter);
	if (rval) {
		return (rval);
	}

	curdir = opendir(listDir); /* Set up to ask for directory entries */
	if (curdir == NULL) {
		return (samrerr(SE_NOSUCHPATH, listDir));
	}

	*direntries = lst_create(); /* Return results in this list */
	if (*direntries == NULL) {
		closedir(curdir);
		return (-1);	/* If allocation failed, samerr is set */
	}
	lstp = *direntries;

	entry = mallocer(sizeof (struct dirent64) + MAXPATHLEN + 1);
	if (entry == NULL) {
		closedir(curdir);
		lst_free(*direntries);
		*direntries = NULL;
		return (-1);
	}

	/* Walk through directory entries */
	while ((rval = readdir64_r(curdir, entry, &entryp)) == 0) {
		if (entryp == NULL) {
			break;
		}

		fname = (char *)&(entry->d_name[0]);

		if ((strcmp(fname, ".") == 0) ||
		    (strcmp(fname, "..") == 0)) {
			continue;
		}

		/*
		 * If we were given a non-directory, start after
		 * that file alphabetically.
		 */
		if (startFile != NULL) {
			if ((strcmp(fname, startFile)) <= 0) {
				continue;
			}
		}

		/* Create full pathname and get stat info */
		snprintf(buf, sizeof (buf), "%s/%s", listDir, fname);
		if (lstat64(buf, &sout) != 0) {
			continue; /* Ignore file which can't be stat'ed */
		}

		/*
		 * think about ways to avoid a double-stat in when we're
		 * fetching file details
		 */
		if (check_restrict_stat(fname, &sout, &filter)) {
			continue; /* Not this entry */
		}

		/* copy to allocated struct */
		data = copystr(fname);
		if (data == NULL) {
			rval = -1;
			break;	/* samerr already set */
		}

		/*
		 * caller wants all entries for the directory
		 * should there be a top-end limit, to avoid the case where
		 * the directory has millions of entries?
		 */
		if (maxentries <= 0) {
			rval = lst_append(lstp, data);
			if (rval != 0) {
				free(data);
				break;
			}
			continue;
		}

		/*
		 * Directory may have more entries than requested, so pre-sort
		 * the list so we return the first <n> sorted alphabetically.
		 */
		for (node = lstp->head; node != NULL; node = node->next) {

			st = strcmp(data, (char *)(node->data));
			if (st > 0) {
				continue;
			}

			if (st < 0) {
				rval = lst_ins_before(lstp, node, data);
				data = NULL;
			}

			if ((rval != 0) || (st == 0)) {
				free(data);
				data = NULL;
			}
			break;
		}

		/* entry sorts higher than existing entries */
		if (data != NULL) {
			if (lstp->length < maxentries) {
				rval = lst_append(lstp, data);
				if (rval != 0) {
					free(data);
					break;
				}
			} else {
				/* no room for this entry */
				free(data);
				(*morefiles)++;
			}
		}

		/* Keep list to designated limits */
		if (lstp->length > maxentries) {
			/* pop off the last entry */
			lst_remove(lstp, lstp->tail);
			(*morefiles)++;
		}
	}

	closedir(curdir);
	free(entry);

	if (rval) {
		lst_free_deep(*direntries);
		*direntries = NULL;
	} else if (maxentries <= 0) {
		lst_qsort(*direntries, node_cmp);
	}

	return (rval);
}
Exemple #9
0
int callback_home(struct lws *wsi, enum lws_callback_reasons reason, void *user,
    void *in, size_t len)  {

    struct per_session_data__details *pss =
    (struct per_session_data__details *)user; 




    switch (reason) {
        case LWS_CALLBACK_PROTOCOL_INIT:{
            break;
        }
        case LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION:
        {            
            check_session(wsi,pss);
            increment_client_count();
            if(lst_find(&clinets_lst,pss->uid)<0){
                lst_append(&clinets_lst, pss->user,pss->uid,pss->gid,pss->session_id+24);
            }               
            break; 
        }         
        case LWS_CALLBACK_WS_PEER_INITIATED_CLOSE:
        {
            new_user=pss->user;
            decrement_client_count();
            lst_remove(&clinets_lst,pss->uid);
        }   
        case LWS_CALLBACK_ESTABLISHED:
        {

            dump_user_info(pss);
            new_user=pss->user;


        }
        case LWS_CALLBACK_SERVER_WRITEABLE:
        {         
            if(strncmp(pss->checked,hash,32)!=0){
                memcpy(pss->checked,hash,32);
                
                char *out = lst_json(&clinets_lst);

                int count = strlen(out);

                unsigned char buffer[LWS_PRE + count];
                unsigned char *p = &buffer[LWS_PRE];

                int n = sprintf((char *)p, "%s", out);

                lws_write(wsi, p,  n, LWS_WRITE_TEXT);  
                free(out);  
                    
                break;              

            }


            
            break;
        }
        case LWS_CALLBACK_RECEIVE:
        {
        //received_msg = (char *) in;
        //chalter=1;
        //lws_callback_on_writable_all_protocol(lws_get_context(wsi),lws_get_protocol(wsi));

            break;
        }  
        default:
        break;      

    }
    return 0;
}