int insert_pcontact(struct udomain* _d, str* _contact, struct pcontact_info* _ci, struct pcontact** _c) { if (mem_insert_pcontact(_d, _contact, _ci, _c)){ LM_ERR("inserting pcontact failed\n"); goto error; } if (exists_ulcb_type(PCSCF_CONTACT_INSERT)) { run_ul_create_callbacks(*_c); } if (db_mode == WRITE_THROUGH && db_insert_pcontact(*_c) != 0) { LM_ERR("error inserting contact into db"); goto error; } return 0; error: return -1; }
int db_update_pcontact_security(struct pcontact* _c, security_type _t, security_t* _s) { db_val_t match_values[1]; db_key_t match_keys[1] = { &aor_col }; db_op_t op[1]; db_key_t update_keys[13] = { &security_type_col, &protocol_col, &mode_col, &ck_col, &ik_col, &ealg_col, &ialg_col, &port_uc_col, &port_us_col, &spi_pc_col, &spi_ps_col, &spi_uc_col, &spi_us_col }; db_val_t values[13]; LM_DBG("updating security for pcontact: %.*s\n", _c->aor.len, _c->aor.s); VAL_TYPE(match_values) = DB1_STR; VAL_NULL(match_values) = 0; VAL_STR(match_values) = _c->aor; op[0]=OP_EQ; if (use_location_pcscf_table(_c->domain) < 0) { LM_ERR("Error trying to use table %.*s\n", _c->domain->len, _c->domain->s); return -1; } VAL_TYPE(values) = DB1_INT; VAL_TIME(values) = _s?_s->type:0; VAL_NULL(values) = 0; switch (_t) { case SECURITY_IPSEC: { ipsec_t* ipsec = _s?_s->data.ipsec:0; int i = 1; str s_empty = {0,0}; VAL_TYPE(values + i) = DB1_STR; VAL_NULL(values + i) = ipsec?0:1; VAL_STR(values + i) = ipsec?ipsec->prot:s_empty; VAL_TYPE(values + ++i) = DB1_STR; VAL_NULL(values + i) = ipsec?0:1; VAL_STR(values + i) = ipsec?ipsec->mod:s_empty; VAL_TYPE(values + ++i) = DB1_STR; VAL_NULL(values + i) = ipsec?0:1; VAL_STR(values + i) = ipsec?ipsec->ck:s_empty; VAL_TYPE(values + ++i) = DB1_STR; VAL_NULL(values + i) = ipsec?0:1; VAL_STR(values + i) = ipsec?ipsec->ik:s_empty; VAL_TYPE(values + ++i) = DB1_STR; VAL_NULL(values + i) = ipsec?0:1; VAL_STR(values + i) = ipsec?ipsec->ealg:s_empty; VAL_TYPE(values + ++i) = DB1_STR; VAL_NULL(values + i) = ipsec?0:1; VAL_STR(values + i) = ipsec?ipsec->alg:s_empty; VAL_TYPE(values + ++i) = DB1_INT; VAL_NULL(values + i) = ipsec?0:1; VAL_INT(values + i) = ipsec?ipsec->port_uc:0; VAL_TYPE(values + ++i) = DB1_INT; VAL_NULL(values + i) = ipsec?0:1; VAL_INT(values + i) = ipsec?ipsec->port_us:0; VAL_TYPE(values + ++i) = DB1_BIGINT; VAL_NULL(values + i) = ipsec?0:1; VAL_BIGINT(values + i) = ipsec?ipsec->spi_pc:0; VAL_TYPE(values + ++i) = DB1_BIGINT; VAL_NULL(values + i) = ipsec?0:1; VAL_BIGINT(values + i) = ipsec?ipsec->spi_ps:0; VAL_TYPE(values + ++i) = DB1_BIGINT; VAL_NULL(values + i) = ipsec?0:1; VAL_BIGINT(values + i) = ipsec?ipsec->spi_uc:0; VAL_TYPE(values + ++i) = DB1_BIGINT; VAL_NULL(values + i) = ipsec?0:1; VAL_BIGINT(values + i) = ipsec?ipsec->spi_us:0; if ((ul_dbf.update(ul_dbh, match_keys, op, match_values, update_keys, values, 1, 13)) != 0) { LM_ERR("could not update database info\n"); return -1; } if (ul_dbf.affected_rows && ul_dbf.affected_rows(ul_dbh) == 0) { LM_DBG("no existing rows for an update... doing insert\n"); if (db_insert_pcontact(_c) != 0) { LM_ERR("Failed to insert a pcontact on update\n"); } } break; } default: LM_WARN("not yet implemented or unknown security type\n"); return -1; } return 0; }
int db_update_pcontact(pcontact_t* _c) { str impus, service_routes; db_val_t match_values[1]; db_key_t match_keys[1] = { &aor_col }; db_op_t op[1]; db_key_t update_keys[8] = { &expires_col, ®_state_col, &service_routes_col, &received_col, &received_port_col, &received_proto_col, &rx_session_id_col, &public_ids_col }; db_val_t values[8]; LM_DBG("updating pcontact: %.*s\n", _c->aor.len, _c->aor.s); VAL_TYPE(match_values) = DB1_STR; VAL_NULL(match_values) = 0; VAL_STR(match_values) = _c->aor; op[0]=OP_EQ; if (use_location_pcscf_table(_c->domain) < 0) { LM_ERR("Error trying to use table %.*s\n", _c->domain->len, _c->domain->s); return -1; } VAL_TYPE(values) = DB1_DATETIME; VAL_TIME(values) = _c->expires; VAL_NULL(values) = 0; VAL_TYPE(values + 1)= DB1_INT; VAL_NULL(values + 1)= 0; VAL_INT(values + 1) = _c->reg_state; str empty_str = str_init(""); if (_c->service_routes) { service_routes.len = service_routes_as_string(_c, &service_route_buffer); service_routes.s = service_route_buffer.buf; } SET_STR_VALUE(values + 2, (_c->service_routes)?service_routes:empty_str); VAL_TYPE(values + 2) = DB1_STR; VAL_NULL(values + 2) = 0; SET_STR_VALUE(values + 3, _c->received_host); VAL_TYPE(values + 3) = DB1_STR; VAL_NULL(values + 3) = 0; VAL_TYPE(values + 4)= DB1_INT; VAL_NULL(values + 4)= 0; VAL_INT(values + 4) = _c->received_port; VAL_TYPE(values + 5)= DB1_INT; VAL_NULL(values + 5)= 0; VAL_INT(values + 5) = _c->received_proto; VAL_TYPE(values + 6) = DB1_STR; SET_PROPER_NULL_FLAG(_c->rx_session_id, values, 6); LM_DBG("Trying to set rx session id: %.*s\n", _c->rx_session_id.len, _c->rx_session_id.s); SET_STR_VALUE(values + 6, _c->rx_session_id); /* add the public identities */ impus.len = impus_as_string(_c, &impu_buffer); impus.s = impu_buffer.buf; VAL_TYPE(values + 7) = DB1_STR; SET_PROPER_NULL_FLAG(impus, values, 7); SET_STR_VALUE(values + 7, impus); if((ul_dbf.update(ul_dbh, match_keys, op, match_values, update_keys,values, 1, 8)) !=0){ LM_ERR("could not update database info\n"); return -1; } if (ul_dbf.affected_rows && ul_dbf.affected_rows(ul_dbh) == 0) { LM_DBG("no existing rows for an update... doing insert\n"); if (db_insert_pcontact(_c) != 0) { LM_ERR("Failed to insert a pcontact on update\n"); } } return 0; }