diff --git a/modules/presence/notify.c b/modules/presence/notify.c index aeee31b94b4..06f17dff84b 100644 --- a/modules/presence/notify.c +++ b/modules/presence/notify.c @@ -94,6 +94,7 @@ str str_id_col = str_init("id"); str str_sender_col = str_init("sender"); str str_updated_col = str_init("updated"); str str_updated_winfo_col = str_init("updated_winfo"); +str str_priority_col = str_init("priority"); int subset=0; diff --git a/modules/presence/notify.h b/modules/presence/notify.h index d83a81cf67d..4f8276cc8a6 100644 --- a/modules/presence/notify.h +++ b/modules/presence/notify.h @@ -96,6 +96,7 @@ extern str str_id_col; extern str str_sender_col; extern str str_updated_col; extern str str_updated_winfo_col; +extern str str_priority_col; void PRINT_DLG(FILE* out, dlg_t* _d); diff --git a/modules/presence/presence.c b/modules/presence/presence.c index 828ff462d86..30b3d3af300 100644 --- a/modules/presence/presence.c +++ b/modules/presence/presence.c @@ -149,6 +149,8 @@ int publ_cache_enabled = 1; int pres_waitn_time = 5; int pres_notifier_poll_rate = 10; int pres_notifier_processes = 1; +str pres_xavp_cfg = {0}; +int pres_retrieve_order = 0; int db_table_lock_type = 1; db_locking_t db_table_lock = DB_LOCKING_WRITE; @@ -208,6 +210,8 @@ static param_export_t params[]={ { "db_table_lock_type", INT_PARAM, &db_table_lock_type}, { "local_log_level", PARAM_INT, &pres_local_log_level}, { "subs_remove_match", PARAM_INT, &pres_subs_remove_match}, + { "xavp_cfg", PARAM_STR, &pres_xavp_cfg}, + { "retrieve_order", PARAM_INT, &pres_retrieve_order}, {0,0,0} }; diff --git a/modules/presence/presence.h b/modules/presence/presence.h index 5dc529a8386..93c28792d42 100644 --- a/modules/presence/presence.h +++ b/modules/presence/presence.h @@ -88,6 +88,8 @@ extern int pres_fetch_rows; extern int pres_waitn_time; extern int pres_notifier_poll_rate; extern int pres_notifier_processes; +extern str pres_xavp_cfg; +extern int pres_retrieve_order; extern int phtable_size; extern phtable_t* pres_htable; diff --git a/modules/presence/presentity.c b/modules/presence/presentity.c index 024a3ca822c..cdefabbd1f3 100644 --- a/modules/presence/presentity.c +++ b/modules/presence/presentity.c @@ -35,8 +35,8 @@ #include "../../hashes.h" #include "../../dprint.h" #include "../../mem/shm_mem.h" +#include "../../xavp.h" #include "../../str.h" -#include "../alias_db/alias_db.h" #include "../../data_lump_rpl.h" #include "presentity.h" #include "presence.h" @@ -46,6 +46,9 @@ #include "utils_func.h" +/* base priority value (20150101T000000) */ +#define PRES_PRIORITY_TBASE 1420070400 + xmlNodePtr xmlNodeGetNodeByName(xmlNodePtr node, const char *name, const char *ns); static str pu_200_rpl = str_init("OK"); @@ -164,7 +167,31 @@ int publ_send200ok(struct sip_msg *msg, int lexpire, str etag) pkg_free(hdr_append2.s); return -1; -} +} + +/** + * get priority value for presence document + */ +unsigned int pres_get_priority(void) +{ + sr_xavp_t *vavp = NULL; + str vname = str_init("priority"); + + if(pres_xavp_cfg.s==NULL || pres_xavp_cfg.len<=0) { + return 0; + } + + vavp = xavp_get_child_with_ival(&pres_xavp_cfg, &vname); + if(vavp!=NULL) { + return (unsigned int)vavp->val.v.i; + } + + return (unsigned int)(time(NULL) - PRES_PRIORITY_TBASE); +} + +/** + * create new presentity record + */ presentity_t* new_presentity( str* domain,str* user,int expires, pres_ev_t* event, str* etag, str* sender) { @@ -221,6 +248,7 @@ presentity_t* new_presentity( str* domain,str* user,int expires, presentity->event= event; presentity->expires = expires; presentity->received_time= (int)time(NULL); + presentity->priority = pres_get_priority(); return presentity; error: @@ -268,9 +296,9 @@ int check_if_dialog(str body, int *is_dialog) int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, int new_t, int* sent_reply, char* sphere) { - db_key_t query_cols[12], update_keys[8], result_cols[5]; - db_op_t query_ops[12]; - db_val_t query_vals[12], update_vals[8]; + db_key_t query_cols[13], update_keys[9], result_cols[6]; + db_op_t query_ops[13]; + db_val_t query_vals[13], update_vals[9]; db1_res_t *result= NULL; int n_query_cols = 0; int n_update_cols = 0; @@ -375,6 +403,12 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, query_vals[n_query_cols].nul = 0; query_vals[n_query_cols].val.int_val = presentity->received_time; n_query_cols++; + + query_cols[n_query_cols] = &str_priority_col; + query_vals[n_query_cols].type = DB1_INT; + query_vals[n_query_cols].nul = 0; + query_vals[n_query_cols].val.int_val = presentity->priority; + n_query_cols++; if (presentity->expires != -1) { @@ -677,6 +711,12 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, update_vals[n_update_cols].val.int_val= presentity->received_time; n_update_cols++; + update_keys[n_update_cols] = &str_priority_col; + update_vals[n_update_cols].type = DB1_INT; + update_vals[n_update_cols].nul = 0; + update_vals[n_update_cols].val.int_val= presentity->priority; + n_update_cols++; + if(body && body->s) { update_keys[n_update_cols] = &str_body_col; @@ -1088,7 +1128,11 @@ char* get_sphere(str* pres_uri) return NULL; } - query_str = str_received_time_col; + if(pres_retrieve_order==1) { + query_str = str_priority_col; + } else { + query_str = str_received_time_col; + } if (pa_dbf.query (pa_db, query_cols, 0, query_vals, result_cols, n_query_cols, n_result_cols, &query_str , &result) < 0) { diff --git a/modules/presence/presentity.h b/modules/presence/presentity.h index ca719e3649d..a9258305b14 100644 --- a/modules/presence/presentity.h +++ b/modules/presence/presentity.h @@ -46,6 +46,7 @@ typedef struct presentity str* sender; time_t expires; time_t received_time; + unsigned int priority; } presentity_t; /* create new presentity */