Module: sip-router Branch: jason.penton/kamailio_ims_extensions Commit: 7010ac9a5cd364db4684215fde4496d5a77d400a URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=7010ac9a...
Author: Jason Penton jason.penton@gmail.com Committer: Jason Penton jason.penton@gmail.com Date: Thu Oct 27 15:57:17 2011 +0200
Dialog2: expose API using only callid, from tag and to tag - Removed the use of struct dlg_cell * for dialog api calls This makes using the API alot safer!
---
modules_k/dialog2/dialog.c | 9 +++++-- modules_k/dialog2/dlg_cb.c | 20 +++++++++++++++++++ modules_k/dialog2/dlg_cb.h | 14 +++++++++++- modules_k/dialog2/dlg_hash.c | 25 ++++++++++++++++++++++++ modules_k/dialog2/dlg_hash.h | 2 + modules_k/dialog2/dlg_load.h | 7 ++++- modules_k/dialog2/dlg_req_within.c | 5 ++++ modules_k/dialog2/dlg_var.c | 37 ++++++++++++++++++++++++++++++++++- modules_k/dialog2/dlg_var.h | 3 ++ 9 files changed, 113 insertions(+), 9 deletions(-)
diff --git a/modules_k/dialog2/dialog.c b/modules_k/dialog2/dialog.c index 58a0210..1d64c59 100644 --- a/modules_k/dialog2/dialog.c +++ b/modules_k/dialog2/dialog.c @@ -298,11 +298,14 @@ static int fixup_dlg_terminate(void** param, int param_no) }
int load_dlg(struct dlg_binds *dlgb) { + dlgb->register_dlgcb = register_dlgcb; - dlgb->set_dlg_var = set_dlg_variable; - dlgb->get_dlg_var = get_dlg_variable; + dlgb->register_dlgcb_nodlg = register_dlgcb_nodlg; + dlgb->set_dlg_var = api_set_dlg_variable; + dlgb->get_dlg_var = api_get_dlg_variable; dlgb->terminate_dlg = w_api_terminate_dlg; - dlgb->get_current_dialog = get_current_dialog; + dlgb->get_dlg_expires = api_get_dlg_expires; + return 1; }
diff --git a/modules_k/dialog2/dlg_cb.c b/modules_k/dialog2/dlg_cb.c index 3cfbeae..829c5ed 100644 --- a/modules_k/dialog2/dlg_cb.c +++ b/modules_k/dialog2/dlg_cb.c @@ -100,6 +100,26 @@ void destroy_dlg_callbacks(unsigned int types) } }
+int register_dlgcb_nodlg(str *callid, str *ftag, str *ttag, + int types, dialog_cb f, + void *param, param_free_cb ff ) +{ + struct dlg_cell *dlg; + + unsigned int dir = DLG_DIR_NONE; + dlg = get_dlg(callid, ftag, ttag, &dir); //increments ref count! + + if (!dlg) { + LM_ERR("Can't find dialog to register callback\n"); + return -1; + } + + int ret = register_dlgcb(dlg, types, f, param, ff); + unref_dlg(dlg, 1); + + return ret; +} +
int register_dlgcb(struct dlg_cell *dlg, int types, dialog_cb f, void *param, param_free_cb ff ) diff --git a/modules_k/dialog2/dlg_cb.h b/modules_k/dialog2/dlg_cb.h index 8eed01d..16be1a9 100644 --- a/modules_k/dialog2/dlg_cb.h +++ b/modules_k/dialog2/dlg_cb.h @@ -53,12 +53,21 @@ typedef void (param_free_cb) (void *param); typedef int (*register_dlgcb_f)(struct dlg_cell* dlg, int cb_types, dialog_cb f, void *param, param_free_cb ff);
+typedef int (*register_dlgcb_nodlg_f)(str *callid, str *ftag, str *ttag, int cb_types, + dialog_cb f, void *param, param_free_cb ff); + /* method to set a variable within a dialog */ -typedef int (*set_dlg_variable_f)( struct dlg_cell* dlg, +//typedef int (*set_dlg_variable_f)( struct dlg_cell* dlg, +// str* key, +// str* val); +typedef int (*set_dlg_variable_f)( str* callid, str* ftag, str* ttag, str* key, str* val); /* method to get a variable from a dialog */ -typedef str* (*get_dlg_variable_f)( struct dlg_cell* dlg, +//typedef str* (*get_dlg_variable_f)( struct dlg_cell* dlg, +// str* key); + +typedef str* (*get_dlg_variable_f)( str *callid, str *ftag, str *ttag, str* key);
typedef struct dlg_cell* (*get_current_dlg_f)( struct sip_msg* msg); @@ -99,6 +108,7 @@ void destroy_dlg_callbacks(unsigned int type);
void destroy_dlg_callbacks_list(struct dlg_callback *cb);
+int register_dlgcb_nodlg(str *callid, str *ftag, str *ttag, int types, dialog_cb f, void *param, param_free_cb ff ); int register_dlgcb( struct dlg_cell* dlg, int types, dialog_cb f, void *param, param_free_cb ff);
void run_create_callbacks(struct dlg_cell *dlg, struct sip_msg *msg); diff --git a/modules_k/dialog2/dlg_hash.c b/modules_k/dialog2/dlg_hash.c index b7f85ad..57b7c3d 100644 --- a/modules_k/dialog2/dlg_hash.c +++ b/modules_k/dialog2/dlg_hash.c @@ -1712,6 +1712,31 @@ error: return NULL; }
+time_t api_get_dlg_expires(str *callid, str *ftag, str *ttag) +{ + struct dlg_cell *dlg; + time_t expires = 0; + time_t start; + + if (!callid || !ftag || !ttag) { LM_ERR("Missing callid, from tag or to tag\n"); return 0; } + + unsigned int direction = DLG_DIR_NONE; + dlg = get_dlg(callid, ftag, ttag, &direction); + if (!dlg) return 0; + + if (dlg->state != DLG_STATE_CONFIRMED || !dlg->start_ts) { + /* Dialog not started yet so lets assume start time is now.*/ + start = time(0); + } else { + start = dlg->start_ts; + } + + expires = start + dlg->lifetime; + unref_dlg(dlg, 1); + + return expires; +} +
diff --git a/modules_k/dialog2/dlg_hash.h b/modules_k/dialog2/dlg_hash.h index 71b786d..17602d3 100644 --- a/modules_k/dialog2/dlg_hash.h +++ b/modules_k/dialog2/dlg_hash.h @@ -597,4 +597,6 @@ int update_dlg_out_did(struct dlg_cell_out *dlg_out, str *new_did);
int update_dlg_did(struct dlg_cell *dlg, str *new_did);
+time_t api_get_dlg_expires(str *callid, str *ftag, str *ttag); + #endif diff --git a/modules_k/dialog2/dlg_load.h b/modules_k/dialog2/dlg_load.h index dd7e9b9..9c6ec4d 100644 --- a/modules_k/dialog2/dlg_load.h +++ b/modules_k/dialog2/dlg_load.h @@ -35,13 +35,16 @@ /* terminate_dlg function prototype */ typedef int (*terminate_dlg_f)(str *callid, str *ftag, str *ttag, str *hdrs, str *reason);
+/* get_dlg_lifetime function prototype */ +typedef time_t (*get_dlg_expires_f)(str *callid, str *ftag, str *ttag); + struct dlg_binds { register_dlgcb_f register_dlgcb; + register_dlgcb_nodlg_f register_dlgcb_nodlg; terminate_dlg_f terminate_dlg; set_dlg_variable_f set_dlg_var; get_dlg_variable_f get_dlg_var; - get_current_dlg_f get_current_dialog; - + get_dlg_expires_f get_dlg_expires; };
diff --git a/modules_k/dialog2/dlg_req_within.c b/modules_k/dialog2/dlg_req_within.c index b2341d7..d4ee886 100644 --- a/modules_k/dialog2/dlg_req_within.c +++ b/modules_k/dialog2/dlg_req_within.c @@ -317,12 +317,17 @@ int dlg_terminate(struct dlg_cell *dlg, struct sip_msg *msg, str *reason, int si struct cell* t; str default_reason = {"call failed", 4}; int cfg_cmd = 0; + str default_extra_headers = {0,0};
if (!dlg) { LM_ERR("calling end_dialog with NULL pointer dlg\n"); return -1; }
+ if (!extra_hdrs) + extra_hdrs = & default_extra_headers; + + if (msg) { //assume called from cfg command -> dlg_terminate, as opposed to internal API or mi interface cfg_cmd = 1; diff --git a/modules_k/dialog2/dlg_var.c b/modules_k/dialog2/dlg_var.c index 8bef6f2..0ce0e7d 100644 --- a/modules_k/dialog2/dlg_var.c +++ b/modules_k/dialog2/dlg_var.c @@ -37,8 +37,7 @@ int msg_id;
int dlg_cfg_cb(struct sip_msg *foo, unsigned int flags, void *bar) { - memset(&_dlg_ctx, 0, sizeof(dlg_ctx_t)); - + memset(&_dlg_ctx, 0, sizeof(dlg_ctx_t)); return 1; }
@@ -219,6 +218,22 @@ void print_lists(struct dlg_cell *dlg) { } }
+str * api_get_dlg_variable(str *callid, str *ftag, str *ttag, str *key) { + struct dlg_cell *dlg; + + unsigned int dir = DLG_DIR_NONE; + dlg = get_dlg(callid, ftag, ttag, &dir); //increments ref count! + + if (!dlg) { + LM_ERR("Asked to tear down non existent dialog\n"); + return NULL; + } + + unref_dlg(dlg, 1); + + return get_dlg_variable(dlg, key); +} + str * get_dlg_variable(struct dlg_cell *dlg, str *key) { str* var = NULL; @@ -237,6 +252,24 @@ str * get_dlg_variable(struct dlg_cell *dlg, str *key) return var; }
+int api_set_dlg_variable(str *callid, str *ftag, str *ttag, str *key, str *val) { + struct dlg_cell *dlg; + + unsigned int dir = DLG_DIR_NONE; + dlg = get_dlg(callid, ftag, ttag, &dir); //increments ref count! + + if (!dlg) { + LM_ERR("Asked to tear down non existent dialog\n"); + return -1; + } + + unref_dlg(dlg, 1); + + return set_dlg_variable(dlg, key, val); + + +} + int set_dlg_variable(struct dlg_cell *dlg, str *key, str *val) { if( !dlg || !key || key->len > strlen(key->s) || (val && val->len > strlen(val->s))) diff --git a/modules_k/dialog2/dlg_var.h b/modules_k/dialog2/dlg_var.h index cd53807..dadde4d 100644 --- a/modules_k/dialog2/dlg_var.h +++ b/modules_k/dialog2/dlg_var.h @@ -49,7 +49,10 @@ struct dlg_var { struct dlg_var *next; };
+str * api_get_dlg_variable(str *callid, str *ftag, str *ttag, str *key); str * get_dlg_variable(struct dlg_cell *dlg, str *key); + +int api_set_dlg_variable(str *callid, str *ftag, str *ttag, str *key, str *val); int set_dlg_variable(struct dlg_cell *dlg, str *key, str *val);
int pv_parse_dialog_var_name(pv_spec_p sp, str *in);