Skip to content

Commit

Permalink
dialog: support integer type for dialog values
Browse files Browse the repository at this point in the history
  • Loading branch information
rvlad-patrascu committed Mar 10, 2023
1 parent bfb6221 commit 543a40c
Show file tree
Hide file tree
Showing 20 changed files with 903 additions and 481 deletions.
59 changes: 33 additions & 26 deletions modules/acc/acc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1470,16 +1470,16 @@ static void complete_dlg_values(str *stored_values,str *val_arr,short nr_vals)
/* stores core values and leg values into dlg */
int store_core_leg_values(struct dlg_cell *dlg, struct sip_msg *req)
{
str bytes;
int_str bytes;

if ( build_core_dlg_values(dlg, req) < 0) {
LM_ERR("cannot build core value string\n");
return -1;
}

bytes.s = cdr_buf.s;
bytes.len = cdr_data_len;
if ( dlg_api.store_dlg_value(dlg, &core_str, &bytes) < 0) {
bytes.s.s = cdr_buf.s;
bytes.s.len = cdr_data_len;
if ( dlg_api.store_dlg_value(dlg, &core_str, &bytes, DLG_VAL_TYPE_STR) < 0) {
LM_ERR("cannot store core values into dialog\n");
return -1;
}
Expand All @@ -1492,16 +1492,16 @@ int store_core_leg_values(struct dlg_cell *dlg, struct sip_msg *req)
int store_extra_values(extra_value_t* values, str *values_str,
struct dlg_cell *dlg)
{
str bytes;
int_str bytes;

if ( build_extra_dlg_values(values) < 0) {
LM_ERR("cannot build core value string\n");
return -1;
}

bytes.s = cdr_buf.s;
bytes.len = cdr_data_len;
if ( dlg_api.store_dlg_value(dlg, values_str, &bytes) < 0) {
bytes.s.s = cdr_buf.s;
bytes.s.len = cdr_data_len;
if ( dlg_api.store_dlg_value(dlg, values_str, &bytes, DLG_VAL_TYPE_STR) < 0) {
LM_ERR("cannot store core values into dialog\n");
return -1;
}
Expand All @@ -1511,7 +1511,7 @@ int store_extra_values(extra_value_t* values, str *values_str,

int store_leg_values(acc_ctx_t* ctx, str* values_str, struct dlg_cell *dlg)
{
str bytes;
int_str bytes;

if (ctx == NULL || values_str == NULL) {
LM_ERR("bad usage!\n");
Expand All @@ -1523,9 +1523,9 @@ int store_leg_values(acc_ctx_t* ctx, str* values_str, struct dlg_cell *dlg)
return -1;
}

bytes.s = cdr_buf.s;
bytes.len = cdr_data_len;
if (dlg_api.store_dlg_value(dlg, values_str, &bytes) < 0) {
bytes.s.s = cdr_buf.s;
bytes.s.len = cdr_data_len;
if (dlg_api.store_dlg_value(dlg, values_str, &bytes, DLG_VAL_TYPE_STR) < 0) {
LM_ERR("cannot store dialog string\n");
return -1;
}
Expand Down Expand Up @@ -1636,18 +1636,23 @@ struct dlg_cell *create_acc_dlg(struct sip_msg* req)
/* gets core values from dlg and stores them into val_arr array */
static int prebuild_core_arr(struct dlg_cell *dlg, str *buffer, struct timeval *start)
{
int_str isval;
int val_type;

if (!start || !buffer) {
LM_ERR("invalid parameters\n");
return -1;
}
buffer->len = 0;
buffer->s = 0;

isval.s = *buffer;
/* fetching core string values */
if (dlg_api.fetch_dlg_value(dlg, &core_str, buffer, 1) < 0) {
if (dlg_api.fetch_dlg_value(dlg, &core_str, &val_type, &isval, 1) < 0) {
LM_ERR("cannot fetch core string value\n");
return -1;
}
*buffer = isval.s;

complete_dlg_values(buffer, val_arr, ACC_CORE_LEN+1);
memcpy(start, val_arr[ACC_CORE_LEN].s, val_arr[ACC_CORE_LEN].len);
Expand Down Expand Up @@ -1690,23 +1695,24 @@ static int restore_extra(struct dlg_cell* dlg,
str *type_str, acc_ctx_t* ctx)
{
int extra_len;
str buffer;
int_str buffer;
int val_type;

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

if (dlg_api.fetch_dlg_value(dlg, type_str, &buffer, 0) < 0) {
if (dlg_api.fetch_dlg_value(dlg, type_str, &val_type, &buffer, 0) < 0) {
LM_ERR("cannot fetch <%.*s> value from dialog!\n",
type_str->len, type_str->s);
return -1;
}

/* jump over the total length */
extra_len = GET_LEN(buffer.s);
buffer.s += 2;
buffer.len -= 2;
extra_len = GET_LEN(buffer.s.s);
buffer.s.s += 2;
buffer.s.len -= 2;

if (extra_len != extra_tgs_len) {
LM_WARN("extra tags were added/removed since last run!"
Expand All @@ -1720,7 +1726,7 @@ static int restore_extra(struct dlg_cell* dlg,
return -1;
}

if (restore_extra_from_str(ctx->extra_values, &buffer, extra_len) < 0) {
if (restore_extra_from_str(ctx->extra_values, &buffer.s, extra_len) < 0) {
LM_ERR("failed to restore extra values!\n");
free_extra_array(ctx->extra_values, extra_len);
return -1;
Expand All @@ -1733,21 +1739,22 @@ static int restore_legs(struct dlg_cell* dlg,
str *type_str, acc_ctx_t* ctx)
{
short extra_len, i;
str buffer;
int_str buffer;
int val_type;

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

if (dlg_api.fetch_dlg_value(dlg, type_str, &buffer, 0) < 0) {
if (dlg_api.fetch_dlg_value(dlg, type_str, &val_type, &buffer, 0) < 0) {
LM_ERR("cannot fetch <%.*s> value from dialog!\n",
type_str->len, type_str->s);
return -1;
}

ctx->legs_no = GET_LEN(buffer.s+2);
extra_len = GET_LEN(buffer.s);
ctx->legs_no = GET_LEN(buffer.s.s+2);
extra_len = GET_LEN(buffer.s.s);

if (extra_len != leg_tgs_len) {
LM_WARN("tags were added/removed since last run! won't restore values!\n");
Expand All @@ -1768,11 +1775,11 @@ static int restore_legs(struct dlg_cell* dlg,
}
}

buffer.s += 4;
buffer.len -=4;
buffer.s.s += 4;
buffer.s.len -=4;

for (i=0; i<ctx->legs_no; i++) {
if (restore_extra_from_str(ctx->leg_values[i], &buffer, extra_len) < 0) {
if (restore_extra_from_str(ctx->leg_values[i], &buffer.s, extra_len) < 0) {
LM_ERR("failed to restore leg values!\n");
goto error;
}
Expand Down
53 changes: 28 additions & 25 deletions modules/acc/acc_logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,10 @@ static void acc_merge_contexts(struct dlg_cell *dlg, int type,
void acc_update_ctx_callback(struct dlg_cell *dlg, int type,
struct dlg_cb_params *_params)
{
str flags_s;
int_str flags_s;
acc_ctx_t* ctx = (acc_ctx_t *)(*_params->param);
unsigned long long flags;
int val_type;

if (!dlg) {
LM_ERR("null dialog - cannot fetch message flags\n");
Expand All @@ -611,9 +612,9 @@ void acc_update_ctx_callback(struct dlg_cell *dlg, int type,
return;
}

flags_s.s = (char *)&flags;
flags_s.len = sizeof(flags);
if (dlg_api.fetch_dlg_value(dlg, &flags_str, &flags_s, 1) < 0) {
flags_s.s.s = (char *)&flags;
flags_s.s.len = sizeof(flags);
if (dlg_api.fetch_dlg_value(dlg, &flags_str, &val_type, &flags_s, 1) < 0) {
LM_DBG("flags were not saved in dialog\n");
return;
}
Expand All @@ -627,26 +628,27 @@ void acc_update_ctx_callback(struct dlg_cell *dlg, int type,

void acc_loaded_callback(struct dlg_cell *dlg, int type,
struct dlg_cb_params *_params) {
str flags_s, table_s, created_s;
int_str flags_s, table_s, created_s;
acc_ctx_t* ctx;
time_t created;
unsigned long long flags;
int val_type;

if (!dlg) {
LM_ERR("null dialog - cannot fetch message flags\n");
return;
}

flags_s.s = (char *)&flags;
flags_s.len = sizeof(flags);
if (dlg_api.fetch_dlg_value(dlg, &flags_str, &flags_s, 1) < 0) {
flags_s.s.s = (char *)&flags;
flags_s.s.len = sizeof(flags);
if (dlg_api.fetch_dlg_value(dlg, &flags_str, &val_type, &flags_s, 1) < 0) {
LM_DBG("flags were not saved in dialog\n");
return;
}

created_s.s = (char *)&created;
created_s.len = sizeof(created);
if (dlg_api.fetch_dlg_value(dlg, &created_str, &created_s, 1) < 0) {
created_s.s.s = (char *)&created;
created_s.s.len = sizeof(created);
if (dlg_api.fetch_dlg_value(dlg, &created_str, &val_type, &created_s, 1) < 0) {
LM_DBG("created time was not saved in dialog\n");
return;
}
Expand All @@ -667,18 +669,18 @@ void acc_loaded_callback(struct dlg_cell *dlg, int type,

/* restore accounting table if db accounting is used */
if (is_db_acc_on(ctx->flags)) {
if (dlg_api.fetch_dlg_value(dlg, &table_str, &table_s, 0) < 0) {
if (dlg_api.fetch_dlg_value(dlg, &table_str, &val_type, &table_s, 0) < 0) {
LM_DBG("table was not saved in dialog\n");
return;
}

if ((ctx->acc_table.s=shm_malloc(table_s.len)) == NULL) {
if ((ctx->acc_table.s=shm_malloc(table_s.s.len)) == NULL) {
LM_ERR("no more shm!\n");
return;
}

memcpy(ctx->acc_table.s, table_s.s, table_s.len);
ctx->acc_table.len = table_s.len;
memcpy(ctx->acc_table.s, table_s.s.s, table_s.s.len);
ctx->acc_table.len = table_s.s.len;
}


Expand Down Expand Up @@ -903,10 +905,10 @@ static void acc_dlg_ended(struct dlg_cell *dlg, int type,
static void acc_dlg_onwrite(struct dlg_cell *dlg, int type,
struct dlg_cb_params *_params)
{
str flags_s;
int_str flags_s;
acc_ctx_t* ctx;

str created_s;
int_str isval;
int_str created_s;

if (!_params) {
LM_ERR("not enough info!\n");
Expand All @@ -927,25 +929,26 @@ static void acc_dlg_onwrite(struct dlg_cell *dlg, int type,
return;
}

flags_s.s = (char*)(&ctx->flags);
flags_s.len = sizeof(unsigned long long);
flags_s.s.s = (char*)(&ctx->flags);
flags_s.s.len = sizeof(unsigned long long);

/* store flags into dlg */
if ( dlg_api.store_dlg_value(dlg, &flags_str, &flags_s) < 0) {
if ( dlg_api.store_dlg_value(dlg, &flags_str, &flags_s, DLG_VAL_TYPE_STR) < 0) {
LM_ERR("cannot store flag value into dialog\n");
return;
}

created_s.s = (char*)(&ctx->created);
created_s.len = sizeof(time_t);
created_s.s.s = (char*)(&ctx->created);
created_s.s.len = sizeof(time_t);

if ( dlg_api.store_dlg_value(dlg,&created_str,&created_s) < 0) {
if ( dlg_api.store_dlg_value(dlg,&created_str,&created_s,DLG_VAL_TYPE_STR) < 0) {
LM_ERR("cannot store created value!\n");
return;
}

if (is_db_acc_on(ctx->flags) && ctx->acc_table.s && ctx->acc_table.len) {
if ( dlg_api.store_dlg_value(dlg, &table_str, &ctx->acc_table) < 0) {
isval.s = ctx->acc_table;
if ( dlg_api.store_dlg_value(dlg, &table_str, &isval, DLG_VAL_TYPE_STR) < 0) {
LM_ERR("cannot store table name into dialog\n");
return;
}
Expand Down

0 comments on commit 543a40c

Please sign in to comment.