int ht_api_del_cell(str *hname, str *name) { ht_t* ht; ht = ht_get_table(hname); if(ht==NULL) return -1; return ht_del_cell(ht, name); }
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 $ht name\n"); return -1; } LM_DBG("set value for $ht(%.*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 $ht(%.*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 $ht(%.*s)\n", htname.len, htname.s); return -1; } } return 0; }
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 ht_dmq_replay_action(ht_dmq_action_t action, str* htname, str* cname, int type, int_str* val, int mode) { ht_t* ht; ht = ht_get_table(htname); if(ht==NULL) { LM_ERR("unable to get table\n"); return -1; } LM_DBG("replaying action %d on %.*s=>%.*s...\n", action, htname->len, htname->s, cname->len, cname->s); if (action==HT_DMQ_SET_CELL) { return ht_set_cell(ht, cname, type, val, mode); } else if (action==HT_DMQ_SET_CELL_EXPIRE) { return ht_set_cell_expire(ht, cname, 0, val); } else if (action==HT_DMQ_DEL_CELL) { return ht_del_cell(ht, cname); } else if (action==HT_DMQ_RM_CELL_RE) { return ht_rm_cell_re(&val->s, ht, mode); } else { LM_ERR("unrecognized action"); return -1; } }