/* restore callbacks */ void acc_loaded_callback(struct dlg_cell *dlg, int type, struct dlg_cb_params *_params) { str flags_s, ctx_s, table_s; acc_ctx_t* ctx; if (!dlg) { LM_ERR("null dialog - cannot fetch message flags\n"); return; } if (dlg_api.fetch_dlg_value(dlg, &flags_str, &flags_s, 0) < 0) { LM_DBG("flags were not saved in dialog\n"); return; } /** * restore acc extra context(extra and leg values) */ if (restore_dlg_extra(dlg, &ctx)) { LM_ERR("failed to rebuild acc context!\n"); return; } /* copy flags value into the context */ memcpy(&ctx->flags, flags_s.s, flags_s.len); /* 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) { LM_DBG("table was not saved in dialog\n"); return; } if ((ctx->acc_table.s=shm_malloc(table_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; } /* replace the context value with a good pointer */ ctx_s.s = (char *)&ctx; ctx_s.len = sizeof(acc_ctx_t *); if (dlg_api.store_dlg_value(dlg, &acc_ctx_str, &ctx_s) < 0) { LM_ERR("failed to set new context value!\n"); return; } /* register database callbacks */ if (dlg_api.register_dlgcb(dlg, DLGCB_TERMINATED | DLGCB_EXPIRED, acc_dlg_callback, ctx, dlg_free_acc_ctx)){ LM_ERR("cannot register callback for database accounting\n"); return; } }
/* restore callbacks */ void acc_loaded_callback(struct dlg_cell *dlg, int type, struct dlg_cb_params *_params) { str flags_s, ctx_s, table_s, created_s; acc_ctx_t* ctx; time_t created; unsigned long long flags; 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) { 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) { LM_DBG("created time was not saved in dialog\n"); return; } /** * restore acc extra context(extra and leg values) */ if (restore_dlg_extra(dlg, &ctx)) { LM_ERR("failed to rebuild acc context!\n"); return; } /* copy flags value into the context */ ctx->flags = flags; /* copy created value into the context */ ctx->created = created; /* 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) { LM_DBG("table was not saved in dialog\n"); return; } if ((ctx->acc_table.s=shm_malloc(table_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; } /* replace the context value with a good pointer */ ctx_s.s = (char *)&ctx; ctx_s.len = sizeof(acc_ctx_t *); if (dlg_api.store_dlg_value(dlg, &acc_ctx_str, &ctx_s) < 0) { LM_ERR("failed to set new context value!\n"); return; } /* register database callbacks */ acc_ref_ex(ctx, 2); if (dlg_api.register_dlgcb(dlg, DLGCB_TERMINATED | DLGCB_EXPIRED, acc_dlg_ended, ctx, unref_acc_ctx)){ LM_ERR("cannot register callback for database accounting\n"); acc_unref_ex(ctx, 2); return; } /* register dlg callbacks for ctx management */ if (dlg_api.register_dlgcb(dlg, DLGCB_REQ_WITHIN, acc_merge_contexts, ctx, unref_acc_ctx) != 0) { acc_unref(ctx); /* only one, the other one was successful */ LM_ERR("cannot register callback ctx management\n"); return; } }