Esempio n. 1
0
void
router_id_get (struct prefix *p, vrf_id_t vrf_id)
{
  struct listnode *node;
  struct connected *c;
  struct zebra_vrf *zvrf = vrf_info_get (vrf_id);

  p->u.prefix4.s_addr = 0;
  p->family = AF_INET;
  p->prefixlen = 32;

  if (zvrf->rid_user_assigned.u.prefix4.s_addr)
    p->u.prefix4.s_addr = zvrf->rid_user_assigned.u.prefix4.s_addr;
  else if (!list_isempty (zvrf->rid_lo_sorted_list))
    {
      node = listtail (zvrf->rid_lo_sorted_list);
      c = listgetdata (node);
      p->u.prefix4.s_addr = c->address->u.prefix4.s_addr;
    }
  else if (!list_isempty (zvrf->rid_all_sorted_list))
    {
      node = listtail (zvrf->rid_all_sorted_list);
      c = listgetdata (node);
      p->u.prefix4.s_addr = c->address->u.prefix4.s_addr;
    }
}
Esempio n. 2
0
void
router_id_get (struct prefix *p)
{
  struct listnode *node;
  struct connected *c;

  p->u.prefix4.s_addr = 0;
  p->family = AF_INET;
  p->prefixlen = 32;

  if (rid_user_assigned.u.prefix4.s_addr)
    p->u.prefix4.s_addr = rid_user_assigned.u.prefix4.s_addr;
  else if (!list_isempty (&rid_lo_sorted_list))
    {
      node = listtail (&rid_lo_sorted_list);
      c = listgetdata (node);
      p->u.prefix4.s_addr = c->address->u.prefix4.s_addr;
    }
  else if (!list_isempty (&rid_all_sorted_list))
    {
      node = listtail (&rid_all_sorted_list);
      c = listgetdata (node);
      p->u.prefix4.s_addr = c->address->u.prefix4.s_addr;
    }
}
Esempio n. 3
0
void
ospf_if_stream_unset (struct ospf_interface *oi)
{
    struct ospf *ospf = oi->ospf;

    if (oi->obuf)
    {
        ospf_fifo_free (oi->obuf);
        oi->obuf = NULL;

        if (oi->on_write_q)
        {
            listnode_delete (ospf->oi_write_q, oi);
            if (list_isempty(ospf->oi_write_q))
            OSPF_TIMER_OFF (ospf->t_write);
            oi->on_write_q = 0;
        }
    }
    if (oi->obuf_hello)
    {
        ospf_fifo_free (oi->obuf_hello);
        oi->obuf_hello = NULL;

        if (oi->on_write_q_hello)
        {
            listnode_delete (ospf->oi_write_q_hello, oi);
            if (list_isempty(ospf->oi_write_q_hello))
            OSPF_TIMER_OFF (ospf->t_write_hello);
            oi->on_write_q_hello = 0;
        }
    }
}
Esempio n. 4
0
/**
 * Setup the audio-filter chain
 *
 * must be called before auplay/ausrc-alloc
 */
static int aufilt_setup(struct audio *a)
{
	struct aufilt_prm encprm, decprm;
	struct autx *tx = &a->tx;
	struct aurx *rx = &a->rx;
	struct le *le;

	/* wait until we have both Encoder and Decoder */
	if (!tx->ac || !rx->ac)
		return 0;

	if (!list_isempty(&tx->filtl) || !list_isempty(&rx->filtl))
		return 0;

	aufilt_param_set(&encprm, tx->ac, tx->ptime);
	aufilt_param_set(&decprm, rx->ac, rx->ptime);

	/* Audio filters */
	for (le = list_head(aufilt_list()); le; le = le->next) {
		struct aufilt *af = le->data;
		struct aufilt_enc_st *encst = NULL;
		struct aufilt_dec_st *decst = NULL;
		void *ctx = NULL;
		int err = 0;		

		if (af->encupdh) {
			err |= af->encupdh(&encst, &ctx, af, &encprm);
			if (err) {
				continue;
			}

			encst->af = af;
			list_append(&tx->filtl, &encst->le, encst);
		}

		if (af->decupdh) {
			err |= af->decupdh(&decst, &ctx, af, &decprm);
			if (err) {
				continue;
			}

			decst->af = af;
			list_append(&rx->filtl, &decst->le, decst);
		}

		if (err) {
			DEBUG_WARNING("audio-filter '%s' update failed (%m)\n", af->name, err);
			break;
		}
	}

	return 0;
}
Esempio n. 5
0
/**
 * Forming the Check Lists
 *
 *   To form the check list for a media stream,
 *   the agent forms candidate pairs, computes a candidate pair priority,
 *   orders the pairs by priority, prunes them, and sets their states.
 *   These steps are described in this section.
 *
 * @param icem ICE Media object
 *
 * @return 0 if success, otherwise errorcode
 */
int icem_checklist_form(struct icem *icem)
{
	int err;

	if (!icem)
		return EINVAL;

	if (ICE_MODE_LITE == icem->ice->lmode) {
		DEBUG_WARNING("%s: Checklist: only valid for full-mode\n",
			      icem->name);
		return EINVAL;
	}

	if (!list_isempty(&icem->checkl))
		return EALREADY;

	/* 1. form candidate pairs */
	err = candpairs_form(icem);
	if (err)
		return err;

	/* 2. compute a candidate pair priority */
	/* 3. order the pairs by priority */
	icem_candpair_prio_order(&icem->checkl);

	/* 4. prune the pairs */
	candpair_prune(icem);

	/* 5. set the pair states -- first media stream only */
	if (icem->ice->ml.head->data == icem)
		candpair_set_states(icem);

	return err;
}
static void
thread_cleanup (void *val)
{
  if (val != NULL)
    {
      struct thread_node *thread = val;

      /* How did the signal thread get killed?  */
      assert (thread != &__timer_signal_thread_rclk);
#ifdef _POSIX_CPUTIME
      assert (thread != &__timer_signal_thread_pclk);
#endif
#ifdef _POSIX_THREAD_CPUTIME
      assert (thread != &__timer_signal_thread_tclk);
#endif

      pthread_mutex_lock (&__timer_mutex);

      thread->exists = 0;

      /* We are no longer processing a timer event.  */
      thread->current_timer = 0;

      if (list_isempty (&thread->timer_queue))
	  __timer_thread_dealloc (thread);
      else
	(void) __timer_thread_start (thread);

      pthread_mutex_unlock (&__timer_mutex);

      /* Unblock potentially blocked timer_delete().  */
      pthread_cond_broadcast (&thread->cond);
    }
}
Esempio n. 7
0
struct ua *uag_current(void)
{
	if (list_isempty(uag_list()))
		return NULL;

	return uag.ua_cur;
}
Esempio n. 8
0
/* The input function for a log buffer.  */
static int
ms_buffer_input (void *closure, char *data, size_t need, size_t size,
		 size_t *got)
{
    struct ms_buffer *mb = closure;
    int status;

    assert (mb->cur->input);
    status = (*mb->cur->input) (mb->cur->closure, data, need, size, got);
    if (status == -1)
    {
	Node *p;
	/* EOF.  Set up the next buffer in line but return success and no
	 * data since our caller may have selected on the target to find
	 * ready data before calling us.
	 *
	 * If there are no more buffers, return EOF.
	 */
	if (list_isempty (mb->bufs)) return -1;
	buf_shutdown (mb->cur);
	buf_free (mb->cur);
	p = mb->bufs->list->next;
	mb->cur = p->data;
	p->delproc = NULL;
	p->data = NULL;
	delnode (p);
	if (!buf_empty_p (mb->cur)) buf_append_buffer (mb->buf, mb->cur);
	ms_buffer_block (closure, mb->block);
	*got = 0;
	status = 0;
    }

    return status;
}
Esempio n. 9
0
/**
 * Start the audio playback and recording
 *
 * @param a Audio object
 *
 * @return 0 if success, otherwise errorcode
 */
int audio_start(struct audio *a)
{
	int err;

	if (!a)
		return EINVAL;

	err = stream_start(a->strm);
	if (err)
		return err;

	/* Audio filter */
	if (!a->filtl.head && !list_isempty(aufilt_list())) {
		err = aufilt_setup(a);
		if (err)
			return err;
	}

	/* configurable order of play/src start */
	if (a->cfg.src_first) {
		err |= start_source(&a->tx, a);
		err |= start_player(&a->rx, a);
	}
	else {
		err |= start_player(&a->rx, a);
		err |= start_source(&a->tx, a);
	}

	return err;
}
Esempio n. 10
0
list_t* termFreeVars(TERM *t) {
	list_t *vars, *rvars;
	lnode_t *node;

	switch(t->type) {
	 case(TM_VAR):
		vars = list_create(LISTCOUNT_T_MAX);
		list_append(vars, lnode_create(t->name));
		break;

	 case(TM_ALIAS):
		vars = list_create(LISTCOUNT_T_MAX);
		break;

	 case(TM_ABSTR):
		vars = termFreeVars(t->rterm);
		while(node = list_find(vars, t->lterm->name, (int(*)(const void*, const void*))strcmp))
			lnode_destroy(list_delete(vars, node));
		break;

	 case(TM_APPL):
		vars = termFreeVars(t->lterm);
		rvars = termFreeVars(t->rterm);
		list_transfer(vars, rvars, list_first(rvars));
		list_destroy(rvars);
		break;
	}

	t->closed = list_isempty(vars);
	return vars;
}
Esempio n. 11
0
void show(void)
{
	size_t s;
	int i;
	Element e;
	printf("读取列表元素,列表%s,元素数量 = %zu\n", list_isempty(al) ? "为空" : "不空", (s = list_size(al)));
	printf("使用位置索引随机访问元素:\n");
	for (i = 0; i < s; i++) {
		e = list_get(al, i);
		printf("%2d) \"%s\"\n", i, POINTOF(e, char));		// String类型的元素不能用VALUEOF()宏
		free(e);						// 获取的元素值用完必须free
	}
	printf("Ok!\n");
	printf("使用正向迭代器迭代访问元素:\n");
	it_reset(fwd);
	i = 0;
	while ((e = it_next(fwd))) {
		printf("%2d) \"%s\"\n", i++, (char *)e);
		free(e);
	}
	printf("Ok!\n");
	printf("使用反向迭代器迭代访问元素:\n");
	it_reset(bwd);
	i = list_size(al);
	while ((e = it_next(bwd))) {
		printf("%2d) \"%s\"\n", --i, POINTOF(e, char));
		free(e);
	}
	printf("Ok!\n");
}
Esempio n. 12
0
/**
 * Forming Candidate Pairs
 */
static int candpairs_form(struct icem *icem)
{
	struct le *le;
	int err = 0;

	if (list_isempty(&icem->lcandl))
		return ENOENT;

	for (le = icem->lcandl.head; le; le = le->next) {

		struct cand *lcand = le->data;
		struct le *rle;

		for (rle = icem->rcandl.head; rle; rle = rle->next) {

			struct cand *rcand = rle->data;

			if (lcand->compid != rcand->compid)
				continue;

			if (sa_af(&lcand->addr) != sa_af(&rcand->addr))
				continue;

			err |= icem_candpair_alloc(NULL, icem, lcand, rcand);
		}
	}

	return err;
}
Esempio n. 13
0
static int
ls_print_dir (Node *p, void *closure)
{
    static bool printed = false;

    if (recurse && !(ls_prune_dirs && list_isempty (p->data)))
    {
        /* Keep track of whether we've printed.  If we have, then put a blank
         * line before directory headers, to separate the header from the
         * listing of the previous directory.
         */
        if (printed)
            cvs_output ("\n", 1);
        else
            printed = true;

        if (!strcmp (p->key, ""))
            cvs_output (".", 1);
        else
	    cvs_output (p->key, 0);
        cvs_output (":\n", 2);
    }
    walklist (p->data, ls_print, NULL);
    return 0;
}
Esempio n. 14
0
int agent_process_remote_attr(struct agent *ag,
			      const char *name, const char *value)
{
	int err = 0;

	if (!ag || !name)
		return EINVAL;

	if (0 == str_casecmp(name, "ice-ufrag")) {
		ag->rufrag = true;
		err = trice_set_remote_ufrag(ag->icem, value);
	}
	else if (0 == str_casecmp(name, "ice-pwd")) {
		ag->rpwd = true;
		err = trice_set_remote_pwd(ag->icem, value);
	}
	else if (0 == str_casecmp(name, "candidate")) {
		unsigned i;

		err = agent_rcand_decode_add(ag->icem, value);

		for (i=0; i<ag->candc; i++)
			candidate_add_permissions(&ag->candv[i]);
	}
	else if (0 == str_casecmp(name, "end-of-candidates")) {
		re_printf("got end-of-candidates from remote\n");
		ag->remote_eoc = true;
	}
	else {
		re_printf("attribute ignored: %s\n", name);
	}

	if (err) {
		re_printf("remote attr error (%m)\n", err);
		return err;
	}

	if (ag->rufrag && ag->rpwd && ag->cli->param.run_checklist
	    && !list_isempty(trice_rcandl(ag->icem))
	    && !trice_checklist_isrunning(ag->icem)) {

		re_printf("starting ICE checklist with pacing interval"
			  " %u milliseconds..\n",
			  ag->cli->param.pacing_interval);

		err = trice_checklist_start(ag->icem, NULL,
					    ag->cli->param.pacing_interval,
					    true,
					    ice_estab_handler,
					    ice_failed_handler, ag);
		if (err) {
			re_fprintf(stderr, "could not start checklist (%m)\n",
				   err);
		}
	}

	return 0;
}
Esempio n. 15
0
void list_display(list *me){
	if (list_isempty(me) == TRUE) {
		return;
	}
	while (me->next) {
		me = me->next;
		printf("%d ", me->data);
	}
	printf("\n");
}
Esempio n. 16
0
/*
 * Cleanup the array with empty lists from start to end index.
 */
static
void
cleanup_array_with_lists(struct list** vals, unsigned int start, unsigned int end)
{
    int i;
    for (i = start; i < end; ++i) {
        assert(list_isempty(vals[i]));
        list_destroy(vals[i]);
    }
}
Esempio n. 17
0
/**
 * \brief Merge pairs of nodes and reverse the order.
 *
 * Given a list of \p src nodes, merge adjacent pairs and reverse the ordering
 * of the result. The resulting merged nodes are stored in \p dst. This is the
 * first merge pass when deleting the minimum node from the heap.
 *
 * \param [in] ph Pairing heap containing the nodes to merge.
 * \param [out] dst List into which the nodes are merged.
 * \param [in] src List from which to merge nodes.
 *
 * \post \c list_isempty(src)
 *
 * \note This operation has a time complexity of O(n) with respect to the length
 * of \p src.
 */
static void _merge_pairs_reverse(const struct pheap *ph, struct list *dst,
        struct list *src)
{
    struct pheap_elem *left, *right;

    /* Move left to right, merging pairs */
    while (!list_isempty(src))
    {
        left = containerof(list_popfront(src),
                struct pheap_elem, child_le);
        if (!list_isempty(src))
        {
            right = containerof(list_popfront(src),
                    struct pheap_elem, child_le);
            left = _merge(ph, left, right);
        }

        /* Push the merged element onto the front of the destination, so that
         * the result is in reverse order.
         */
        list_pushfront(dst, &left->child_le);
    }
Esempio n. 18
0
struct bstree *parser_analisar_tokens(list **lista)
{
	struct lnode *no = list_front(*lista);

	tokens = lista;
	if (list_isempty(*lista)) {
		err("Lista de tokens vazia: nada para analisar.");
		exit(1);
	}
	parser_montar_arvore(no);
	debug("\033[1mÁrvore dos lexemas montada.\033[0m");
	return tree;
}
Esempio n. 19
0
/**
 * Allocate an audio filter-chain
 */
int aufilt_chain_alloc(struct aufilt_chain **fcp,
		       const struct aufilt_prm *encprm,
		       const struct aufilt_prm *decprm)
{
	struct aufilt_chain *fc;
	struct le *le;
	int err = 0;

	if (!fcp || !encprm || !decprm)
		return EINVAL;

	fc = mem_zalloc(sizeof(*fc), aufilt_chain_destructor);
	if (!fc)
		return ENOMEM;

	list_init(&fc->filtl);

	/* Loop through all filter modules */
	for (le = aufiltl.head; le; le = le->next) {
		struct aufilt *af = le->data;
		struct aufilt_elem *f = mem_zalloc(sizeof(*f),
						   aufilt_elem_destructor);
		if (!f)	{
			err = ENOMEM;
			goto out;
		}
		list_append(&fc->filtl, &f->le, f);

		err = af->alloch(&f->st, af, encprm, decprm);
		if (err) {
			mem_deref(f);
			goto out;
		}
	}

	if (!list_isempty(&fc->filtl)) {
		(void)re_printf("audio-filter chain: enc=%u-%uHz/%dch"
				" dec=%u-%uHz/%dch (%u filters)\n",
				encprm->srate, encprm->srate_out, encprm->ch,
				decprm->srate, decprm->srate_out, decprm->ch,
				list_count(&fc->filtl));
	}

 out:
	if (err)
		mem_deref(fc);
	else
		*fcp = fc;

	return err;
}
Esempio n. 20
0
static int shutdown_idle_cb(void *user_data)
{
	// int restart = (int )user_data;
	lnode_t *n;
	if (shutdown_handlers == NULL) {
		goto NULL_SHUTDOWN_HANDLERS;
	}

	if (list_isempty(shutdown_handlers)) {
		goto EMPTY_LIST;
	}

	n = list_first(shutdown_handlers);

	debug("shutdown_idle_cb started");

	while (n) {
		ShutdownHandler *handler = n->list_data;

		if (handler && handler->fn)
			handler->fn(handler->user_data);

		u_free(handler);
		n = list_next(shutdown_handlers, n);
	}

	// list_destroy_nodes (shutdown_handlers);
      EMPTY_LIST:
	// list_destroy (shutdown_handlers);
      NULL_SHUTDOWN_HANDLERS:

	if (user_data == NULL) {
		/* We should be quitting the main loop (which will cause us to
		   exit) in a handler.  If not, we'll throw in an exit just to be
		   sure. */
		exit(0);
	} else {
		const char **argv = wsmand_options_get_argv();

		errno = 0;
		if ((execv(argv[0], (char **) argv)) < 0) {
			debug("Can not restart wsmand: %s",
			      strerror(errno));
			exit(EXIT_FAILURE);
		}
	}

	/* We should never reach here... */
	assert(1 == 1);
	return 0;
}
Esempio n. 21
0
void list_destory(list *me){
	list *ptr = me, *next_ptr;
	if (list_isempty(ptr) == TRUE) {
		return;
	}

	while (ptr->next) {
		next_ptr = ptr->next;
		free(ptr->next);
		ptr = next_ptr;

	}
	free(me);
}
Esempio n. 22
0
void type(void)
{
	size_t s;
	int i;
	Element e;
	printf("读取列表元素,列表%s,元素数量 = %zu\n", list_isempty(al) ? "为空" : "不空", (s = list_size(al)));
	printf("使用位置索引随机访问元素:\n");
	for (i = 0; i < s; i++) {
		e = list_get(al, i);
		printf("%2d) \"%s\"\n", i, POINTOF(e, char));		// String类型的元素不能用VALUEOF()宏
		free(e);						// 获取的元素值用完必须free
	}
	printf("Ok!\n");
}
Esempio n. 23
0
void
zebra_remove_rnh_client (struct rnh *rnh, struct zserv *client)
{
  if (IS_ZEBRA_DEBUG_NHT)
    {
      char buf[INET6_ADDRSTRLEN];
      zlog_debug("client %s unregisters rnh %s",
		 zebra_route_string(client->proto),
		 rnh_str(rnh, buf, INET6_ADDRSTRLEN));
    }
  listnode_delete(rnh->client_list, client);
  if (list_isempty(rnh->client_list))
    zebra_delete_rnh(rnh);
}
Esempio n. 24
0
void
list_destroy(struct list* lst)
{
    if (lst != NULL) {
        assert(list_isempty(lst));
        struct listnode* p = lst->head;
        struct listnode* q;
        while (p != NULL) {
            q = p->next;
            free(p);
            p = q;
        }
    }
    free(lst);
}
Esempio n. 25
0
/**
 * Forming Candidate Pairs
 */
static int candpairs_form(struct icem *icem)
{
	struct le *le;
	int err = 0;

	if (list_isempty(&icem->lcandl))
		return ENOENT;

	if (list_isempty(&icem->rcandl)) {
		DEBUG_WARNING("%s: no remote candidates\n", icem->name);
		return ENOENT;
	}

	for (le = icem->lcandl.head; le; le = le->next) {

		struct cand *lcand = le->data;
		struct le *rle;

		for (rle = icem->rcandl.head; rle; rle = rle->next) {

			struct cand *rcand = rle->data;

			if (lcand->compid != rcand->compid)
				continue;

			if (sa_af(&lcand->addr) != sa_af(&rcand->addr))
				continue;

			err = icem_candpair_alloc(NULL, icem, lcand, rcand);
			if (err)
				return err;
		}
	}

	return err;
}
Esempio n. 26
0
int main(int argc, char *argv[])
{
    struct list uut;
    struct list_elem e;

    list_init(&uut);
    list_pushback(&uut, &e);

    assert(!list_isempty(&uut));
    assert(list_head(&uut) == &e);
    assert(list_tail(&uut) == &e);
    assert(list_popback(&uut) == &e);

    return 0;
}
Esempio n. 27
0
void list_append(struct List *list, struct Entry *data) {
    struct Node *node = malloc(sizeof(struct Node));

    node->data = data;
    node->next = NULL;

    if (list_isempty(list)) {
        node->previous = NULL;
        list->start = node;
        list->end = node;
    }
    else {
        node->previous = list->end;
        list->end->next = node;
        list->end = node;
    }
}
Esempio n. 28
0
void enqueue(queue_t *q, void* data)
{
    lnode_t *n = lnode_create(data);
    
    pthread_mutex_lock(&q->lock);
    
    if (list_isfull(q->list)) {
        pthread_cond_wait(&q->notfull, &q->lock);
    }
    
    if (list_isempty(q->list)) {
        list_append(q->list, n);
        pthread_cond_broadcast(&q->notempty);
    }
    
    pthread_mutex_unlock(&q->lock);
}
Esempio n. 29
0
/* Delete all sync belonging to the given process */
void delete_sync(struct syncstruct *snc)
{
	struct sync *s;

	while(1)
	{
		if(list_isempty(&snc->syncs))
			return;

		list_dequeue(&snc->syncs, s, syncs, struct sync *);
		if(!s)
			return;
		shash_remove(s);

		kmem_cache_free(sync_cache, s);
	}
}
Esempio n. 30
0
/**
 * Stop all User-Agents
 *
 * @param forced True to force, otherwise false
 */
void ua_stop_all(bool forced)
{
	module_app_unload();

	if (!list_isempty(&uag.ual)) {
		const uint32_t n = list_count(&uag.ual);
		info("Stopping %u useragent%s.. %s\n",
		     n, n==1 ? "" : "s", forced ? "(Forced)" : "");
	}

	if (forced)
		sipsess_close_all(uag.sock);
	else
		list_flush(&uag.ual);

	sip_close(uag.sip, forced);
}