Ejemplo n.º 1
0
static void tcase_free (TCase *tc)
{
  list_apply (tc->tflst, free);
  list_apply (tc->unch_sflst, free);
  list_apply (tc->ch_sflst, free);
  list_apply (tc->unch_tflst, free);
  list_apply (tc->ch_tflst, free);
  list_free(tc->tflst);
  list_free(tc->unch_sflst);
  list_free(tc->ch_sflst);
  list_free(tc->unch_tflst);
  list_free(tc->ch_tflst);
  
  free(tc);
}
Ejemplo n.º 2
0
Archivo: tmr.c Proyecto: soramimi/qSIP
/**
 * Start a timer
 *
 * @param tmr   Timer to start
 * @param delay Timer delay in [ms]
 * @param th    Timeout handler
 * @param arg   Handler argument
 */
void tmr_start(struct tmr *tmr, uint64_t delay, tmr_h *th, void *arg)
{
	struct list *tmrl = tmrl_get();
	struct le *le;

	if (!tmr)
		return;

	if (tmr->th) {
		list_unlink(&tmr->le);
	}

	tmr->th  = th;
	tmr->arg = arg;

	if (!th)
		return;

	tmr->jfs = delay + tmr_jiffies();

	if (delay == 0) {
		le = list_apply(tmrl, true, inspos_handler_0, &tmr->jfs);
		if (le) {
			list_insert_before(tmrl, le, &tmr->le, tmr);
		}
		else {
			list_append(tmrl, &tmr->le, tmr);
		}
	}
	else {
		le = list_apply(tmrl, false, inspos_handler, &tmr->jfs);
		if (le) {
			list_insert_after(tmrl, le, &tmr->le, tmr);
		}
		else {
			list_prepend(tmrl, &tmr->le, tmr);
		}
	}

#ifdef HAVE_ACTSCHED
	/* TODO: this is a hack. when a new timer is started we must reset
	   the main sleeping timer in actsched.cpp */
	{
		extern void actsched_restart_timer(void);
		actsched_restart_timer();
	}
#endif
}
Ejemplo n.º 3
0
/*打印字符串链表信息*/
void print_strlist(const T strlist) 
{
    assert(strlist);
    
    /* 打印模式集基本信息 */
    printf("file: %s\n"
    	   "str num: %d\n"
    	   "min len: %d\n"
    	   "max len: %d\n"
    	   "total len: %ld\n"
    	   "avg len: %.2f\n"
    	   "len sd: %.2f\n",
    	   strlist->file,
    	   strlist->str_num,
    	   strlist->min_strlen,
    	   strlist->max_strlen,
    	   strlist->total_strlen,
    	   strlist->avg_strlen,
    	   strlist->strlen_sd);
    
    /* 打印串长分布 */
    if (1) {
    	printf("length    number:\n");
    	for (Str_Len_T len = 1; len <= strlist->max_strlen; len++) {
    	    Str_Num_T num = strlist->strlen_num[len];
    	    if (num) printf(" %3d  %5d %7.2f%%\n",
    		       len, num, ((double) num / strlist->str_num) * 100);
    	}
    }
    
    /* 打印每个模式串 */
    if (0)
      list_apply(strlist->list, print_str, NULL);
}
Ejemplo n.º 4
0
void sip_request_close(struct sip *sip)
{
	if (!sip)
		return;

	list_apply(&sip->reql, true, close_handler, NULL);
}
Ejemplo n.º 5
0
static double cal_sd(T strlist) /*计算标准差*/
{
    /* two_value[0]为sd */
    double sd_mean[2] = {0, strlist->avg_strlen}; 
    list_apply(strlist->list, get_sd, sd_mean);

    return sqrt(sd_mean[0] / strlist->str_num);
}
Ejemplo n.º 6
0
int sip_transp_debug(struct re_printf *pf, const struct sip *sip)
{
	int err;

	err = re_hprintf(pf, "transports:\n");
	list_apply(&sip->transpl, true, debug_handler, pf);

	return err;
}
Ejemplo n.º 7
0
static void upd(struct tcuplinks *ups, struct list*upl)
{
    hash_alloc(&ups->uris_c, 16);
    list_apply(upl, true, apply_add, ups);
    if(ups->data_c) {
        hash_apply(ups->data_c, apply_rm, ups);
    }

}
Ejemplo n.º 8
0
static void tcpconn_close(struct tcpconn *tc, int err)
{
	if (!tc)
		return;

	/* avoid trying this connection again (e.g. same address) */
	tc->conn = mem_deref(tc->conn);
	(void)list_apply(&tc->ql, true, tcpconn_fail_handler, &err);
	mem_deref(tc);
}
Ejemplo n.º 9
0
/*销毁字符串链表*/
void strlist_free(T *strlist_p) 
{
    /* 释放模式集文件名 */
    FREE((*strlist_p)->file);
    /* 释放链表节点连着的模式串 */
    list_apply((*strlist_p)->list, free_str, NULL);
    /* 释放模式集链表 */
    list_free(&(*strlist_p)->list);
    /* 释放模式集 */
    FREE(*strlist_p);
}
Ejemplo n.º 10
0
static void query_destructor(void *data)
{
	struct dns_query *q = data;
	uint32_t i;

	query_abort(q);
	mbuf_reset(&q->mb);
	mem_deref(q->name);

	for (i=0; i<ARRAY_SIZE(q->rrlv); i++)
		(void)list_apply(&q->rrlv[i], true, rr_unlink_handler, NULL);
}
Ejemplo n.º 11
0
void report_ctlist(int err, struct list*ctlist, void*arg)
{
    int cnt;
    msgpack_packer *pk = arg;
    msgpack_pack_array(pk, err ? 2 : 3);
    push_cstr("contacts.res");
    msgpack_pack_int(pk, err);
    if(err) return;

    cnt = list_count(ctlist);
    msgpack_pack_array(pk, cnt);

    list_apply(ctlist, true, write_contact_el, arg);

}
Ejemplo n.º 12
0
void report_hist(int err, char *idx, struct list*hlist, void*arg)
{
    int cnt;
    msgpack_packer *pk = arg;
    msgpack_pack_array(pk, err ? 2 : 4);
    push_cstr("hist.res");
    msgpack_pack_int(pk, err);
    if(err) return;

    push_cstr_len(idx);
    cnt = list_count(hlist);
    msgpack_pack_array(pk, cnt);

    list_apply(hlist, true, write_history_el, arg);
}
Ejemplo n.º 13
0
/**
 * list_apply_each()
 *  Applies function (*fn) to each node's *data object in *list
 *  @list -- linked list
 *  @fn -- Pointer to function taking/returning void* to apply
 *  @return -- NULL on failure, or ptr to list again
 */
linked_list *list_apply_each(linked_list *list, void *(*fn)(void *))
{
    list_node *p;

    if(list==NULL)
    {
        fprintf(stderr, "Library error: list_apply_each passed a NULL list\n");
        return NULL;
    }

    p = list->head;
    while((p = list_apply(p, fn)) != NULL)
		; /* Do nothing */

    return list;
}
Ejemplo n.º 14
0
int sipsess_reply_ack(struct sipsess *sess, const struct sip_msg *msg,
		      bool *awaiting_answer)
{
	struct sipsess_reply *reply;

	reply = list_ledata(list_apply(&sess->replyl, false, cmp_handler,
				       (void *)msg));
	if (!reply)
		return ENOENT;

	*awaiting_answer = reply->awaiting_answer;

	mem_deref(reply);

	return 0;
}
Ejemplo n.º 15
0
void report_signup(int err, struct list*elist, void *arg)
{
    msgpack_packer *pk = arg;
    if(err == 1) {
        msgpack_pack_array(pk, 3);
    } else {
        msgpack_pack_array(pk, 2);
    }

    push_cstr("api.signup");
    msgpack_pack_int(pk, err);

    if(err==1) {
        msgpack_pack_array(pk, list_count(elist));
        list_apply(elist, true, write_field_err, arg);
    }
}
Ejemplo n.º 16
0
/**
 * Debug all allocated memory objects
 */
void mem_debug(void)
{
#if MEM_DEBUG
	uint32_t n;

	mem_lock();
	n = list_count(&meml);
	mem_unlock();

	if (!n)
		return;

	DEBUG_WARNING("Memory leaks (%u):\n", n);

	mem_lock();
	(void)list_apply(&meml, true, debug_handler, NULL);
	mem_unlock();
#endif
}
Ejemplo n.º 17
0
static bool auth_handler(const struct sip_hdr *hdr, const struct sip_msg *msg,
			 void *arg)
{
	struct httpauth_digest_chall ch;
	struct sip_auth *auth = arg;
	struct realm *realm = NULL;
	int err;
	(void)msg;

	if (httpauth_digest_challenge_decode(&ch, &hdr->val)) {
		err = EBADMSG;
		goto out;
	}

	if (pl_isset(&ch.algorithm) && pl_strcasecmp(&ch.algorithm, "md5")) {
		err = ENOSYS;
		goto out;
	}

	realm = list_ledata(list_apply(&auth->realml, true, cmp_handler,
				       &ch.realm));
	if (!realm) {
		realm = mem_zalloc(sizeof(*realm), realm_destructor);
		if (!realm) {
			err = ENOMEM;
			goto out;
		}

		list_append(&auth->realml, &realm->le, realm);

		err = pl_strdup(&realm->realm, &ch.realm);
		if (err)
			goto out;

		err = auth->authh(&realm->user, &realm->pass,
				  realm->realm, auth->arg);
		if (err)
			goto out;
	}
	else {
		if (!pl_isset(&ch.stale) || pl_strcasecmp(&ch.stale, "true")) {
			err = EAUTH;
			goto out;
		}

		realm->nonce  = mem_deref(realm->nonce);
		realm->qop    = mem_deref(realm->qop);
		realm->opaque = mem_deref(realm->opaque);
	}

	realm->hdr = hdr->id;
	realm->nc  = 1;

	err = pl_strdup(&realm->nonce, &ch.nonce);

	if (pl_isset(&ch.qop))
		err |= pl_strdup(&realm->qop, &ch.qop);

	if (pl_isset(&ch.opaque))
		err |= pl_strdup(&realm->opaque, &ch.opaque);

 out:
	if (err) {
		mem_deref(realm);
		auth->err = err;
		return true;
	}

	return false;
}
Ejemplo n.º 18
0
int location_update(struct list *locl, const struct sip_msg *msg,
                    const struct sip_addr *contact, uint32_t expires)
{
    struct location *loc, *loc_new = NULL;
    struct loctmp *tmp;
    struct pl pl;
    int err;

    if (!locl || !msg || !contact)
        return EINVAL;

    loc = list_ledata(list_apply(locl, true, cmp_handler,
                                 (void *)&contact->uri));
    if (!loc) {
        if (expires == 0)
            return 0;

        loc = loc_new = mem_zalloc(sizeof(*loc), destructor_location);
        if (!loc)
            return ENOMEM;

        list_append(locl, &loc->le, loc);
    }
    else {
        if (!pl_strcmp(&msg->callid, loc->callid) &&
                msg->cseq.num <= loc->cseq)
            return EPROTO;

        if (expires == 0) {
            loc->rm = true;
            return 0;
        }
    }

    tmp = mem_zalloc(sizeof(*tmp), destructor_loctmp);
    if (!tmp) {
        err = ENOMEM;
        goto out;
    }

    err = pl_strdup(&tmp->uri, &contact->auri);
    if (err)
        goto out;

    pl_set_str(&pl, tmp->uri);

    if (uri_decode(&tmp->duri, &pl)) {
        err = EBADMSG;
        goto out;
    }

    err = pl_strdup(&tmp->callid, &msg->callid);
    if (err)
        goto out;


    if (!msg_param_decode(&contact->params, "q", &pl))
        tmp->q = pl_float(&pl);
    else
        tmp->q = 1;

    tmp->cseq    = msg->cseq.num;
    tmp->expires = expires;
    tmp->src     = msg->src;

out:
    if (err) {
        mem_deref(loc_new);
        mem_deref(tmp);
    }
    else {
        mem_deref(loc->tmp);
        loc->tmp = tmp;
    }

    return err;
}
Ejemplo n.º 19
0
Archivo: list.c Proyecto: entwanne/BNF
void list_clear(list_t* list)
{
  list_apply(*list, (list_apply_t) free);
  *list = 0;
}