* _remove - Delete an entire AOR entry or one or more of its Contacts * * @domain: logical domain name (usually name of location table) * @aor_gp: address-of-record as a SIP URI (plain string or pvar) * @contact_gp: contact URI to be deleted * @next_hop_gp: IP/domain in front of contacts to be deleted * @sip_instance_gp: delete contacts with given "+sip_instance"
| 916 | * @return: 1 on success, negative on failure |
| 917 | */ |
| 918 | int _remove(struct sip_msg *msg, void *udomain, str *aor_uri, str *match_ct, |
| 919 | str *match_next_hop, str *match_sin, int* bflag) |
| 920 | { |
| 921 | struct hostent delete_nh_he, *he; |
| 922 | urecord_t *record; |
| 923 | ucontact_t *contact, *it; |
| 924 | str aor_user; |
| 925 | int ret = 1; |
| 926 | unsigned short delete_port = 0; |
| 927 | |
| 928 | if (extract_aor(aor_uri, &aor_user, 0, 0, reg_use_domain) < 0) { |
| 929 | LM_ERR("failed to extract Address Of Record\n"); |
| 930 | return E_BAD_URI; |
| 931 | } |
| 932 | |
| 933 | memset( &delete_nh_he, 0, sizeof(struct hostent)); |
| 934 | |
| 935 | ul.lock_udomain((udomain_t *)udomain, &aor_user); |
| 936 | |
| 937 | if (ul.get_urecord((udomain_t *)udomain, &aor_user, &record) != 0) { |
| 938 | LM_DBG("no record '%.*s' found!\n", aor_user.len, aor_user.s); |
| 939 | goto out_unlock; |
| 940 | } |
| 941 | |
| 942 | /* without any additional filtering, delete the whole urecord entry */ |
| 943 | if (!match_ct && !match_next_hop && !match_sin && (!bflag ||!*bflag)) { |
| 944 | if (ul.delete_urecord((udomain_t *)udomain, &aor_user, record, 0) != 0) { |
| 945 | LM_ERR("failed to delete urecord for aor '%.*s'\n", |
| 946 | aor_user.len, aor_user.s); |
| 947 | ret = E_UNSPEC; |
| 948 | goto out_unlock; |
| 949 | } |
| 950 | |
| 951 | goto out_unlock; |
| 952 | } |
| 953 | |
| 954 | if (match_ct) |
| 955 | LM_DBG("Delete by contact: [%.*s]\n", match_ct->len, match_ct->s); |
| 956 | |
| 957 | if (match_sin) |
| 958 | LM_DBG("Delete by sip_instance: [%.*s]\n", |
| 959 | match_sin->len, match_sin->s); |
| 960 | |
| 961 | if (match_next_hop) { |
| 962 | he = sip_resolvehost(match_next_hop, &delete_port, NULL, 0, NULL); |
| 963 | if (!he) { |
| 964 | LM_ERR("cannot resolve given host: '%.*s'\n", |
| 965 | match_next_hop->len, match_next_hop->s); |
| 966 | ret = E_UNSPEC; |
| 967 | goto out_unlock; |
| 968 | } |
| 969 | |
| 970 | struct sockaddr_in daddr; |
| 971 | memcpy(&daddr.sin_addr, he->h_addr_list[0], sizeof(daddr.sin_addr)); |
| 972 | LM_DBG("Delete by host: '%s'\n", |
| 973 | inet_ntoa(daddr.sin_addr)); |
| 974 | |
| 975 | if (hostent_cpy(&delete_nh_he, he) != 0) { |
nothing calls this directly
no test coverage detected