Exemplo n.º 1
0
/*
 * create/add new row to the leg matrix
 * initialize all values in current row with null
 *
 * */
int expand_legs(acc_ctx_t* ctx)
{
	if (ctx == NULL) {
		LM_ERR("bad usage!\n");
		return -1;
	}

	if (ctx->leg_values == NULL) {
		ctx->leg_values =
			shm_malloc(LEG_MATRIX_ALLOC_FACTOR * sizeof(leg_value_p));
		ctx->allocated_legs = LEG_MATRIX_ALLOC_FACTOR;
	} else if (ctx->legs_no + 1 == ctx->allocated_legs) {
		ctx->leg_values =
			shm_realloc(ctx->leg_values,
					(ctx->allocated_legs + LEG_MATRIX_ALLOC_FACTOR) *
						sizeof(leg_value_p));
		ctx->allocated_legs += LEG_MATRIX_ALLOC_FACTOR;
	}

	if (ctx->leg_values == NULL) {
		LM_ERR("no more shm!\n");
		return -1;
	}

	return build_acc_extra_array(leg_tags,
					leg_tgs_len, &ctx->leg_values[ctx->legs_no++]);
}
Exemplo n.º 2
0
int init_acc_ctx(acc_ctx_t** ctx_p)
{
	acc_ctx_t* ctx;

	if (ctx_p == NULL) {
		LM_ERR("bad usage!\n");
		return -1;
	}

	ctx=shm_malloc(sizeof(acc_ctx_t));
	if (ctx == NULL) {
		LM_ERR("no more shm!\n");
		return -1;
	}

	memset(ctx, 0, sizeof(acc_ctx_t));
	lock_init(&ctx->lock);

	/* init extra s array */
	if (extra_tags != NULL &&
			build_acc_extra_array(extra_tags, extra_tgs_len,
									&ctx->extra_values) < 0) {
		LM_ERR("failed to build extra values array!\n");
		return -1;
	}


	if (leg_tags != NULL && expand_legs(ctx) < 0) {
		LM_ERR("failed to build extra values array!\n");
		return -1;
	}
	acc_ref_unsafe(ctx, 1);
	ACC_PUT_CTX(ctx);

	*ctx_p = ctx;
	return 0;

}