/** * @brief Get a subscription from the subscription list based on the IMPI * NB - does not return with a lock on the subscription but does increment ref count * @param impu string of impu to search for * @param s ims_subscription to be returned if found * @param leave_slot_locked if no subscription is found return with the slot locked (in case we want to add) * @return 0 on success */ int get_subscription(str* impi_s, ims_subscription** s, int leave_slot_locked) { int subscription_hash, sl; ims_subscription* ptr; subscription_hash = core_hash(impi_s, 0, 0); sl = subscription_hash & (subs_hash_size - 1); lock_subscription_slot(sl); ptr = ims_subscription_list->slot[sl].first; while (ptr) { if ((impi_s->len == ptr->private_identity.len) && (memcmp(impi_s->s, ptr->private_identity.s, impi_s->len) == 0)) { LM_DBG("found an existing subscription for IMPI [%.*s]\n", impi_s->len, impi_s->s); (*s) = ptr; lock_subscription(ptr); ref_subscription_unsafe(ptr); unlock_subscription(ptr); unlock_subscription_slot(sl); return 0; } ptr = ptr->next; } if (!leave_slot_locked) unlock_subscription_slot(sl); return 1; }
/*! * \brief Create and initialize new record structure * \param _dom domain name * \param _aor address of record * \param _r pointer to the new record * \return 0 on success, negative on failure */ int new_impurecord(str* _dom, str* public_identity, str* private_identity, int reg_state, int barring, ims_subscription** s, str* ccf1, str* ccf2, str* ecf1, str* ecf2, impurecord_t** _r) { *_r = (impurecord_t*) shm_malloc(sizeof (impurecord_t)); if (*_r == 0) { LM_ERR("no more shared memory\n"); return -1; } memset(*_r, 0, sizeof (impurecord_t)); //setup callback list (*_r)->cbs = (struct ulcb_head_list*) shm_malloc( sizeof (struct ulcb_head_list)); if ((*_r)->cbs == 0) { LM_CRIT("no more shared mem\n"); shm_free(*_r); goto error; } (*_r)->cbs->first = 0; (*_r)->cbs->reg_types = 0; (*_r)->public_identity.s = (char*) shm_malloc(public_identity->len); if ((*_r)->public_identity.s == 0) { LM_ERR("no more shared memory\n"); shm_free(*_r); goto error; } memcpy((*_r)->public_identity.s, public_identity->s, public_identity->len); (*_r)->public_identity.len = public_identity->len; (*_r)->private_identity.s = (char*) shm_malloc(private_identity->len); if ((*_r)->private_identity.s == 0) { LM_ERR("no more shared memory\n"); shm_free(*_r); goto error; } memcpy((*_r)->private_identity.s, private_identity->s, private_identity->len); (*_r)->private_identity.len = private_identity->len; (*_r)->domain = _dom; (*_r)->aorhash = core_hash(public_identity, 0, 0); (*_r)->reg_state = reg_state; if (barring >= 0) { //just in case we call this with no barring -1 will ignore (*_r)->barring = barring; } (*_r)->send_sar_on_delete = 1; /*defaults to 1 */ if (ccf1 && ccf1->len > 0) STR_SHM_DUP((*_r)->ccf1, *ccf1, "CCF1"); if (ccf2 && ccf2->len > 0) STR_SHM_DUP((*_r)->ccf2, *ccf2, "CCF2"); if (ecf1 && ecf1->len > 0) STR_SHM_DUP((*_r)->ecf1, *ecf1, "ECF1"); if (ecf2 && ecf2->len > 0) STR_SHM_DUP((*_r)->ecf2, *ecf2, "ECF2"); /*assign ims subscription profile*/ if (s && *s) { ref_subscription_unsafe(*s); (*_r)->s = *s; } return 0; out_of_memory: LM_ERR("no more shared memory\n"); *_r = 0; return -3; error: LM_ERR("Failed to create new impurecord...\n"); *_r = 0; return -2; }