/*! \brief RPC htable.sets command to set one item to string value */ static void htable_rpc_sets(rpc_t* rpc, void* c) { str htname, keyname; int_str keyvalue; ht_t *ht; if (rpc->scan(c, "SS.S", &htname, &keyname, &keyvalue.s) < 3) { rpc->fault(c, 500, "Not enough parameters (htable name, key name and value)"); return; } /* Find the htable */ ht = ht_get_table(&htname); if (!ht) { rpc->fault(c, 500, "No such htable"); return; } if (ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_SET_CELL, &ht->name, &keyname, AVP_VAL_STR, &keyvalue, 1)!=0) { LM_ERR("dmq relication failed\n"); } if(ht_set_cell(ht, &keyname, AVP_VAL_STR, &keyvalue, 1)!=0) { LM_ERR("cannot set $ht(%.*s=>%.*s)\n", htname.len, htname.s, keyname.len, keyname.s); rpc->fault(c, 500, "Failed to set the item"); return; } return; }
static int ht_rm_value_re(struct sip_msg* msg, char* key, char* foo) { ht_pv_t *hpv; str sre; pv_spec_t *sp; sp = (pv_spec_t*)key; int_str isval; hpv = (ht_pv_t*)sp->pvp.pvn.u.dname; if(hpv->ht==NULL) { hpv->ht = ht_get_table(&hpv->htname); if(hpv->ht==NULL) return 1; } if(pv_printf_s(msg, hpv->pve, &sre)!=0) { LM_ERR("cannot get $ht expression\n"); return -1; } if (hpv->ht->dmqreplicate>0) { isval.s = sre; if (ht_dmq_replicate_action(HT_DMQ_RM_CELL_RE, &hpv->htname, NULL, AVP_VAL_STR, &isval, 1)!=0) { LM_ERR("dmq relication failed\n"); } } if(ht_rm_cell_re(&sre, hpv->ht, 1)<0) return -1; return 1; }
int pv_get_ht_add(struct sip_msg *msg, pv_param_t *param, pv_value_t *res, int val) { str htname; ht_cell_t *htc=NULL; ht_pv_t *hpv; hpv = (ht_pv_t*)param->pvn.u.dname; if(hpv->ht==NULL) { hpv->ht = ht_get_table(&hpv->htname); if(hpv->ht==NULL) return pv_get_null(msg, param, res); } if(pv_printf_s(msg, hpv->pve, &htname)!=0) { LM_ERR("cannot get $ht name\n"); return -1; } htc = ht_cell_value_add(hpv->ht, &htname, val, 1, _htc_local); if(htc==NULL) { return pv_get_null(msg, param, res); } if(_htc_local!=htc) { ht_cell_pkg_free(_htc_local); _htc_local=htc; } if(htc->flags&AVP_VAL_STR) return pv_get_null(msg, param, res); /* integer */ if (hpv->ht->dmqreplicate>0) { if (ht_dmq_replicate_action(HT_DMQ_SET_CELL, &hpv->htname, &htname, 0, &htc->value, 1)!=0) { LM_ERR("dmq relication failed\n"); } } return pv_get_sintval(msg, param, res, htc->value.n); }
static void htable_rpc_delete(rpc_t* rpc, void* c) { str htname, keyname; ht_t *ht; if (rpc->scan(c, "SS", &htname, &keyname) < 2) { rpc->fault(c, 500, "Not enough parameters (htable name & key name"); return; } ht = ht_get_table(&htname); if (!ht) { rpc->fault(c, 500, "No such htable"); return; } if (ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_DEL_CELL, &ht->name, &keyname, 0, NULL, 0)!=0) { LM_ERR("dmq relication failed\n"); } ht_del_cell(ht, &keyname); }
static struct mi_root* ht_mi_delete(struct mi_root* cmd_tree, void* param) { struct mi_node *node; str *htname, *key; ht_t *ht; node = cmd_tree->node.kids; if (!node) goto param_err; htname = &node->value; if (!htname->len) goto param_err; node = node->next; if (!node) goto param_err; key = &node->value; if (!key->len) goto param_err; ht = ht_get_table(htname); if (!ht) return init_mi_tree(404, MI_BAD_PARM_S, MI_BAD_PARM_LEN); if (ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_DEL_CELL, &ht->name, key, 0, NULL, 0)!=0) { LM_ERR("dmq relication failed\n"); } LM_DBG("deleting key [%.*s] from [%.*s]\n", key->len, key->s, htname->len, htname->s); ht_del_cell(ht, key); return init_mi_tree(200, MI_OK_S, MI_OK_LEN); param_err: return init_mi_tree(400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN); }
int pv_set_ht_cell_expire(struct sip_msg* msg, pv_param_t *param, int op, pv_value_t *val) { str htname; int_str isval; ht_pv_t *hpv; hpv = (ht_pv_t*)param->pvn.u.dname; if(hpv->ht==NULL) hpv->ht = ht_get_table(&hpv->htname); if(hpv->ht==NULL) return -1; if(pv_printf_s(msg, hpv->pve, &htname)!=0) { LM_ERR("cannot get $ht name\n"); return -1; } LM_DBG("set expire value for $ht(%.*s=>%.*s)\n", hpv->htname.len, hpv->htname.s, htname.len, htname.s); isval.n = 0; if(val!=NULL) { if(val->flags&PV_TYPE_INT) isval.n = val->ri; } if (hpv->ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_SET_CELL_EXPIRE, &hpv->htname, &htname, 0, &isval, 0)!=0) { LM_ERR("dmq relication failed\n"); } if(ht_set_cell_expire(hpv->ht, &htname, 0, &isval)!=0) { LM_ERR("cannot set $ht(%.*s)\n", htname.len, htname.s); return -1; } return 0; }
static int ht_rm_items(sip_msg_t* msg, str* hname, str* op, str *val, int mkey) { ht_t *ht; int_str isval; ht = ht_get_table(hname); if(ht==NULL) { LM_ERR("cannot get hash table [%.*s]\n", hname->len, hname->s); return -1; } switch(op->len) { case 2: if(strncmp(op->s, "re", 2)==0) { isval.s = *val; if (ht_dmq_replicate_action(HT_DMQ_RM_CELL_RE, &ht->name, NULL, AVP_VAL_STR, &isval, mkey)!=0) { LM_ERR("dmq relication failed (op %d)\n", mkey); } if(ht_rm_cell_re(val, ht, mkey)<0) { return -1; } return 1; } else if(strncmp(op->s, "sw", 2)==0) { if(ht_rm_cell_op(val, ht, mkey, HT_RM_OP_SW)<0) { return -1; } } LM_WARN("unsupported match operator: %.*s\n", op->len, op->s); break; default: LM_WARN("unsupported match operator: %.*s\n", op->len, op->s); } return -1; }
int pv_set_ht_cell(struct sip_msg* msg, pv_param_t *param, int op, pv_value_t *val) { str htname; int_str isval; ht_pv_t *hpv; hpv = (ht_pv_t*)param->pvn.u.dname; if(hpv->ht==NULL) hpv->ht = ht_get_table(&hpv->htname); if(hpv->ht==NULL) return -1; if(pv_printf_s(msg, hpv->pve, &htname)!=0) { LM_ERR("cannot get $sht name\n"); return -1; } LM_DBG("set value for $sht(%.*s=>%.*s)\n", hpv->htname.len, hpv->htname.s, htname.len, htname.s); if((val==NULL) || (val->flags&PV_VAL_NULL)) { /* delete it */ if (hpv->ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_DEL_CELL, &hpv->htname, &htname, 0, NULL, 0)!=0) { LM_ERR("dmq relication failed\n"); } ht_del_cell(hpv->ht, &htname); return 0; } if(val->flags&PV_TYPE_INT) { isval.n = val->ri; if (hpv->ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_SET_CELL, &hpv->htname, &htname, 0, &isval, 1)!=0) { LM_ERR("dmq relication failed\n"); } if(ht_set_cell(hpv->ht, &htname, 0, &isval, 1)!=0) { LM_ERR("cannot set $sht(%.*s)\n", htname.len, htname.s); return -1; } } else { isval.s = val->rs; if (hpv->ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_SET_CELL, &hpv->htname, &htname, AVP_VAL_STR, &isval, 1)!=0) { LM_ERR("dmq relication failed\n"); } if(ht_set_cell(hpv->ht, &htname, AVP_VAL_STR, &isval, 1)!=0) { LM_ERR("cannot set $sht(%.*s)\n", htname.len, htname.s); return -1; } } return 0; }