本文整理汇总了C++中usrloc_api_t::get_pcontact方法的典型用法代码示例。如果您正苦于以下问题:C++ usrloc_api_t::get_pcontact方法的具体用法?C++ usrloc_api_t::get_pcontact怎么用?C++ usrloc_api_t::get_pcontact使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类usrloc_api_t
的用法示例。
在下文中一共展示了usrloc_api_t::get_pcontact方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lookup_transport
/*! \brief
* Lookup contact in the database and rewrite Request-URI
* \return: 1 : contacts found and returned
* -1 : not found
* -2 : error
*/
int lookup_transport(struct sip_msg* _m, udomain_t* _d, str* _uri) {
str uri;
pcontact_t* pcontact;
char tmp[MAX_URI_SIZE];
char srcip[20];
str received_host;
str tmp_s;
int ret = 1;
if (_m->new_uri.s) uri = _m->new_uri;
else uri = _m->first_line.u.request.uri;
received_host.len = ip_addr2sbuf(&_m->rcv.src_ip, srcip, sizeof(srcip));
received_host.s = srcip;
//now lookup in usrloc
ul.lock_udomain(_d, &uri, &received_host, _m->rcv.src_port);
if (ul.get_pcontact(_d, &uri, &received_host, _m->rcv.src_port, &pcontact) != 0) { //need to insert new contact
LM_WARN("received request for contact that we don't know about\n");
ret = -1;
goto done;
}
if (pcontact->received_proto != _m->rcv.proto) {
reset_dst_uri(_m);
memset(tmp, 0, MAX_URI_SIZE);
switch (pcontact->received_proto) {
case PROTO_TCP:
snprintf(tmp, MAX_URI_SIZE, "%.*s;transport=tcp", pcontact->aor.len, pcontact->aor.s);
break;
case PROTO_UDP:
snprintf(tmp, MAX_URI_SIZE, "%.*s;transport=udp", pcontact->aor.len, pcontact->aor.s);
break;
default:
LM_WARN("unsupported transport [%d]\n", pcontact->received_proto);
ret = -2;
goto done;
}
tmp_s.s = tmp;
tmp_s.len = strlen(tmp);
if (set_dst_uri(_m, &tmp_s) < 0) {
LM_ERR("failed to set dst_uri for terminating UE\n");
ret = -2;
goto done;
}
LM_DBG("Changed dst URI transport for UE to [%.*s]\n", tmp_s.len, tmp_s.s);
}
done:
ul.unlock_udomain(_d, &uri, &received_host, _m->rcv.src_port);
return ret;
}
示例2: pcscf_unregister
int pcscf_unregister(udomain_t* _d, str * uri, str * received_host, int received_port) {
int result = -1;
struct pcontact * pcontact;
struct pcontact_info ci;
memset(&ci, 0, sizeof (struct pcontact_info));
pcontact_info_t search_ci;
memset(&ci, 0, sizeof(struct pcontact_info));
sip_uri_t contact_uri;
if (parse_uri(uri->s, uri->len, &contact_uri) != 0) {
LM_WARN("Failed to parse aor [%.*s]\n", uri->len, uri->s);
return -1;
}
search_ci.received_host.s = received_host->s;
search_ci.received_host.len = received_host->len;
search_ci.received_port = received_port;
search_ci.received_proto = contact_uri.proto? contact_uri.proto : PROTO_UDP;
search_ci.searchflag = SEARCH_RECEIVED;
search_ci.via_host.s = received_host->s;
search_ci.via_host.len = received_host->len;
search_ci.via_port = received_port;
search_ci.via_prot = search_ci.received_proto;
search_ci.aor.s = uri->s;
search_ci.aor.len = uri->len;
search_ci.reg_state = PCONTACT_ANY;
if (ul.get_pcontact(_d, &search_ci, &pcontact) == 0) {
/* Lock this record while working with the data: */
ul.lock_udomain(_d, &pcontact->via_host, pcontact->via_port, pcontact->via_proto);
LM_DBG("Updating contact [%.*s]: setting state to PCONTACT_DEREG_PENDING_PUBLISH\n", pcontact->aor.len, pcontact->aor.s);
ci.reg_state = PCONTACT_DEREG_PENDING_PUBLISH;
ci.num_service_routes = 0;
if (ul.update_pcontact(_d, &ci, pcontact) == 0) result = 1;
/* Unlock domain */
ul.unlock_udomain(_d, &pcontact->via_host, pcontact->via_port, pcontact->via_proto);
}
return result;
}
示例3: unregister
int unregister(udomain_t* _d, str * uri, str * received_host, int received_port) {
int result = -1;
struct pcontact * pcontact;
struct pcontact_info ci;
memset(&ci, 0, sizeof (struct pcontact_info));
if (ul.get_pcontact(_d, uri, received_host, received_port, &pcontact) == 0) {
/* Lock this record while working with the data: */
ul.lock_udomain(_d, &pcontact->aor, received_host, received_port);
LM_DBG("Updating contact [%.*s]: setting state to PCONTACT_DEREG_PENDING_PUBLISH\n", pcontact->aor.len, pcontact->aor.s);
ci.reg_state = PCONTACT_DEREG_PENDING_PUBLISH;
ci.num_service_routes = 0;
if (ul.update_pcontact(_d, &ci, pcontact) == 0) result = 1;
// if (ul.delete_pcontact(_d, &pc->aor, received_host, received_port, pcontact) == 0) result = 1;
/* Unlock domain */
ul.unlock_udomain(_d, &pcontact->aor, received_host, received_port);
}
return result;
}
示例4: async_aar_reg_callback
//.........这里部分代码省略.........
if (cdp_result >= 2000 && cdp_result < 3000) {
counter_inc(ims_qos_cnts_h.successful_registration_aars);
if (is_rereg) {
LM_DBG("this is a re-registration, therefore we don't need to do anything except know that the the subscription was successful\n");
result = CSCF_RETURN_TRUE;
create_return_code(result);
goto done;
}
//need to set Rx auth data to say this session has been successfully opened
//This is used elsewhere to prevent acting on termination events when the session has not been opened
//getting auth session
auth = cdpb.AAAGetAuthSession(aaa->sessionId->data);
if (!auth) {
LM_DBG("Could not get Auth Session for session id: [%.*s]\n", aaa->sessionId->data.len, aaa->sessionId->data.s);
goto error;
}
//getting session data
p_session_data = (rx_authsessiondata_t*) auth->u.auth.generic_data;
if (!p_session_data) {
LM_DBG("Could not get session data on Auth Session for session id: [%.*s]\n", aaa->sessionId->data.len, aaa->sessionId->data.s);
if (auth) cdpb.AAASessionsUnlock(auth->hash);
goto error;
}
p_session_data->session_has_been_opened = 1;
counter_inc(ims_qos_cnts_h.active_registration_rx_sessions);
if (auth) cdpb.AAASessionsUnlock(auth->hash);
LM_DBG("Success, received code: [%i] from PCRF for AAR request (contact: [%.*s]), (auth session id: %.*s)\n",
cdp_result, local_data->contact.len, local_data->contact.s,
local_data->auth_session_id.len, local_data->auth_session_id.s);
LM_DBG("Registering for Usrloc callbacks on DELETE\n");
ul.lock_udomain(domain_t, &local_data->via_host, local_data->via_port, local_data->via_proto);
contact_info.received_host = local_data->recv_host;
contact_info.received_port = local_data->recv_port;
contact_info.received_proto = local_data->recv_proto;
contact_info.searchflag = (1 << SEARCH_RECEIVED);
contact_info.aor = local_data->contact;
contact_info.via_host = local_data->via_host;
contact_info.via_port = local_data->via_port;
contact_info.via_prot = local_data->via_proto;
if (ul.get_pcontact(domain_t, &contact_info, &pcontact) != 0) {
LM_ERR("Shouldn't get here, can't find contact....\n");
ul.unlock_udomain(domain_t, &local_data->via_host, local_data->via_port, local_data->via_proto);
goto error;
}
//at this point we have the contact
/*set the contact state to say we have succesfully done ARR for register and that we dont need to do it again
* for the duration of the registration.
* */
if (ul.update_rx_regsession(domain_t, &local_data->auth_session_id, pcontact) != 0) {
LM_ERR("unable to update pcontact......\n");
ul.unlock_udomain(domain_t, &local_data->via_host, local_data->via_port, local_data->via_proto);
goto error;
}
memset(&ci, 0, sizeof (struct pcontact_info));
ci.reg_state = PCONTACT_REG_PENDING_AAR;
ci.num_service_routes = 0;
ci.num_public_ids = 0;
LM_DBG("impu: [%.*s] updating status to PCONTACT_REG_PENDING\n", pcontact->aor.len, pcontact->aor.s);
ul.update_pcontact(domain_t, &ci, pcontact);
//register for callbacks on contact
ul.register_ulcb(pcontact, PCSCF_CONTACT_DELETE | PCSCF_CONTACT_EXPIRE,
callback_pcscf_contact_cb, NULL);
ul.unlock_udomain(domain_t, &local_data->via_host, local_data->via_port, local_data->via_proto);
result = CSCF_RETURN_TRUE;
} else {
LM_DBG("Received negative reply from PCRF for AAR Request\n");
counter_inc(ims_qos_cnts_h.failed_registration_aars);
result = CSCF_RETURN_FALSE;
goto error;
}
//set success response code AVP
create_return_code(result);
goto done;
error:
//set failure response code
create_return_code(result);
done:
if (t) tmb.unref_cell(t);
//free memory
if (aaa)
cdpb.AAAFreeMessage(&aaa);
if (finalReply) {
tmb.t_continue(data->tindex, data->tlabel, data->act);
free_saved_transaction_global_data(data);
}
free_saved_transaction_data(local_data);
}
示例5: getContactP
pcontact_t * getContactP(struct sip_msg* _m, udomain_t* _d, enum pcontact_reg_states reg_state, char service_routes[][MAXROUTESIZE], int num_service_routes) {
ppublic_t * p;
contact_body_t *b = 0;
contact_t *ct;
pcontact_info_t search_ci;
str received_host = {0, 0};
char srcip[50];
struct via_body *vb;
unsigned short port, proto;
str host;
sip_uri_t contact_uri;
int mustRetryViaSearch = 0;
int mustRetryReceivedSearch = 0;
LM_DBG("number of service routes to look for is %d\n", num_service_routes);
b = cscf_parse_contacts(_m);
if (_m->first_line.type == SIP_REPLY && _m->contact && _m->contact->parsed && b->contacts) {
mustRetryViaSearch = 1;
mustRetryReceivedSearch = 1;
LM_DBG("This is a reply - to look for contact we favour the contact header above the via (b2bua)... if no contact we will use last via\n");
ct = b->contacts;
host = ct->uri;
if (parse_uri(ct->uri.s, ct->uri.len, &contact_uri) != 0) {
LM_WARN("Failed to parse contact [%.*s]\n", ct->uri.len, ct->uri.s);
return NULL;
}
host = contact_uri.host;
port = contact_uri.port_no ? contact_uri.port_no : 5060;
proto = contact_uri.proto;
if (proto == 0) {
LM_DBG("Contact protocol not specified - using received\n");
proto = _m->rcv.proto;
}
} else {
if (_m->first_line.type == SIP_REPLY)
LM_DBG("This is a reply but we are forced to use the via header\n");
else
LM_DBG("This is a request - using first via to find contact\n");
vb = cscf_get_ue_via(_m);
host = vb->host;
port = vb->port ? vb->port : 5060;
proto = vb->proto;
}
LM_DBG("searching for contact with host:port:proto contact [%d://%.*s:%d]\n", proto, host.len, host.s, port);
received_host.len = ip_addr2sbuf(&_m->rcv.src_ip, srcip, sizeof (srcip));
received_host.s = srcip;
// if (_m->id != current_msg_id) {
current_msg_id = _m->id;
c = NULL;
//search_ci.reg_state = PCONTACT_REGISTERED; //we can do this because this function is always called expecting a REGISTERED contact
memset(&search_ci, 0, sizeof(struct pcontact_info));
search_ci.reg_state = reg_state;
search_ci.received_host.s = received_host.s;
search_ci.received_host.len = received_host.len;
search_ci.received_port = _m->rcv.src_port;
search_ci.received_proto = _m->rcv.proto;
search_ci.searchflag = SEARCH_RECEIVED;
search_ci.num_service_routes = 0;
if (is_registered_fallback2ip == 1) {
search_ci.searchflag = SEARCH_NORMAL;
}
search_ci.via_host = host;
search_ci.via_port = port;
search_ci.via_prot = proto;
search_ci.aor.s = 0;
search_ci.aor.len = 0;
int size = num_service_routes==0?1:num_service_routes;
str s_service_routes[size];
int i;
for (i=0;i<num_service_routes;i++) {
s_service_routes[i].s = service_routes[i];
s_service_routes[i].len = strlen(service_routes[i]);
LM_DBG("Setting service routes str for pos %d to %.*s", i, s_service_routes[i].len, s_service_routes[i].s);
}
if (num_service_routes > 0) {
LM_DBG("asked to search for specific service routes...\n");
search_ci.service_routes = s_service_routes;
search_ci.num_service_routes = num_service_routes;
search_ci.extra_search_criteria = SEARCH_SERVICE_ROUTES;
}
// b = cscf_parse_contacts(_m);
tryagain:
if (b && b->contacts) {
for (ct = b->contacts; ct; ct = ct->next) {
search_ci.aor = ct->uri;
if (ul.get_pcontact(_d, &search_ci, &c) == 0) {
if (checkcontact(_m, c) != 0) {
c = NULL;
} else {
break;
}
}
}
//.........这里部分代码省略.........
示例6: getContactP
/**
* get PContact-Structure for message
* (search only once per Request)
*/
pcontact_t * getContactP(struct sip_msg* _m, udomain_t* _d) {
ppublic_t * p;
contact_body_t *b = 0;
str received_host = {0, 0};
contact_t *ct;
char srcip[50];
int security_server_port = -1;
if (_m->id != current_msg_id) {
current_msg_id = _m->id;
c = NULL;
b = cscf_parse_contacts(_m);
if (b && b->contacts) {
for (ct = b->contacts; ct; ct = ct->next) {
if (ul.get_pcontact(_d, &ct->uri, &c) == 0) {
if (c->security) {
switch (c->security->type) {
case SECURITY_IPSEC:
security_server_port = c->security->data.ipsec->port_uc;
break;
case SECURITY_TLS:
case SECURITY_NONE:
break;
}
} else if (c->security_temp) {
switch (c->security->type) {
case SECURITY_IPSEC:
security_server_port = c->security->data.ipsec->port_uc;
break;
case SECURITY_TLS:
case SECURITY_NONE:
break;
}
}
if ((c->reg_state == PCONTACT_REGISTERED) && ((c->received_port == _m->rcv.src_port) || (security_server_port == _m->rcv.src_port)) && (c->received_proto == _m->rcv.proto)) {
received_host.len = ip_addr2sbuf(&_m->rcv.src_ip, srcip, sizeof(srcip));
received_host.s = srcip;
LM_DBG("Received host len %d (search %d)\n", c->received_host.len, received_host.len);
// Then check the length:
if (c->received_host.len == received_host.len) {
LM_DBG("Received host %.*s (search %.*s)\n",
c->received_host.len, c->received_host.s,
received_host.len, received_host.s);
// Finally really compare the "received_host"
if (!memcmp(c->received_host.s, received_host.s, received_host.len))
break;
c = NULL;
}
} else {
c = NULL;
}
}
}
} else {
LM_WARN("No contact-header found\n");
}
if ((c == NULL) && (is_registered_fallback2ip > 0)) {
LM_WARN("Contact not found based on Contact-header, trying IP/Port/Proto\n");
received_host.len = ip_addr2sbuf(&_m->rcv.src_ip, srcip, sizeof(srcip));
received_host.s = srcip;
if (ul.get_pcontact_by_src(_d, &received_host, _m->rcv.src_port, _m->rcv.proto, &c) == 1)
LM_DBG("No entry in usrloc for %.*s:%i (Proto %i) found!\n", received_host.len, received_host.s, _m->rcv.src_port, _m->rcv.proto);
}
}
asserted_identity = NULL;
if (c) {
p = c->head;
while (p) {
if (p->is_default == 1)
asserted_identity = &p->public_identity;
p = p->next;
}
}
return c;
}
示例7: ipsec_forward
int ipsec_forward(struct sip_msg* m, udomain_t* d)
{
struct pcontact_info ci;
pcontact_t* pcontact = NULL;
int ret = IPSEC_CMD_FAIL; // FAIL by default
//
// Find the contact
//
if(fill_contact(&ci, m) != 0) {
LM_ERR("Error filling in contact data\n");
return ret;
}
ul.lock_udomain(d, &ci.via_host, ci.via_port, ci.via_prot);
if (ul.get_pcontact(d, &ci, &pcontact) != 0) {
LM_ERR("Contact doesn't exist\n");
goto cleanup;
}
if(pcontact->security_temp == NULL) {
LM_ERR("No security parameters found in contact\n");
goto cleanup;
}
//get security parameters
if(pcontact->security_temp->type != SECURITY_IPSEC ) {
LM_ERR("Unsupported security type: %d\n", pcontact->security_temp->type);
goto cleanup;
}
ipsec_t* s = pcontact->security_temp->data.ipsec;
// Update the destination
//
// from sec-agree
// v
// sip:host:port
// ^
// from URI
//int uri_len = 4 /* strlen("sip:") */ + ci.via_host.len + 5 /* max len of port number */ ;
if(m->dst_uri.s) {
pkg_free(m->dst_uri.s);
m->dst_uri.s = NULL;
m->dst_uri.len = 0;
}
char buf[1024];
int buf_len = snprintf(buf, sizeof(buf) - 1, "sip:%.*s:%d", ci.via_host.len, ci.via_host.s, s->port_us);
if((m->dst_uri.s = pkg_malloc(buf_len)) == NULL) {
LM_ERR("Error allocating memory for dst_uri\n");
goto cleanup;
}
memcpy(m->dst_uri.s, buf, buf_len);
m->dst_uri.len = buf_len;
// Set send socket
struct socket_info * client_sock = grep_sock_info(&ipsec_listen_addr, ipsec_client_port, PROTO_UDP);
if(!client_sock) {
LM_ERR("Error calling grep_sock_info() for ipsec client port in ipsec_forward\n");
return -1;
}
m->force_send_socket = client_sock;
// Set destination info
struct dest_info dst_info;
dst_info.send_sock = client_sock;
#ifdef USE_DNS_FAILOVER
if (!uri2dst(NULL, &dst_info, m, &m->dst_uri, PROTO_UDP)) {
#else
if (!uri2dst(&dst_info, m, &m->dst_uri, PROTO_UDP)) {
#endif
LM_ERR("Error converting dst_uri (%.*s) to struct dst_info\n", m->dst_uri.len, m->dst_uri.s);
goto cleanup;
}
// Update dst_info in message
if(m->first_line.type == SIP_REPLY) {
struct cell *t = tmb.t_gett();
if (!t) {
LM_ERR("Error getting transaction\n");
goto cleanup;
}
t->uas.response.dst = dst_info;
}
LM_DBG("Destination changed to %.*s\n", m->dst_uri.len, m->dst_uri.s);
ret = IPSEC_CMD_SUCCESS; // all good, return SUCCESS
if(add_supported_secagree_header(m) != 0) {
goto cleanup;
}
//.........这里部分代码省略.........
示例8: ipsec_create
int ipsec_create(struct sip_msg* m, udomain_t* d)
{
pcontact_t* pcontact = NULL;
struct pcontact_info ci;
int ret = IPSEC_CMD_FAIL; // FAIL by default
// Find the contact
if(fill_contact(&ci, m) != 0) {
LM_ERR("Error filling in contact data\n");
return ret;
}
ul.lock_udomain(d, &ci.via_host, ci.via_port, ci.via_prot);
if (ul.get_pcontact(d, &ci, &pcontact) != 0) {
LM_ERR("Contact doesn't exist\n");
goto cleanup;
}
// Get security parameters
if(pcontact->security_temp == NULL) {
LM_ERR("No security parameters found in contact\n");
goto cleanup;
}
if(pcontact->security_temp->type != SECURITY_IPSEC ) {
LM_ERR("Unsupported security type: %d\n", pcontact->security_temp->type);
goto cleanup;
}
ipsec_t* s = pcontact->security_temp->data.ipsec;
if(update_contact_ipsec_params(s, m) != 0) {
goto cleanup;
}
if(create_ipsec_tunnel(ci.received_host, s) != 0) {
goto cleanup;
}
// TODO: Save security_tmp to security!!!!!
if (ul.update_pcontact(d, &ci, pcontact) != 0) {
LM_ERR("Error updating contact\n");
goto cleanup;
}
// Destroy the tunnel, if the contact expires
if(ul.register_ulcb(pcontact, PCSCF_CONTACT_EXPIRE|PCSCF_CONTACT_DELETE, on_expire, NULL) != 1) {
LM_ERR("Error subscribing for contact\n");
goto cleanup;
}
if(add_supported_secagree_header(m) != 0) {
goto cleanup;
}
if(add_security_server_header(m, s) != 0) {
goto cleanup;
}
ret = IPSEC_CMD_SUCCESS; // all good, set ret to SUCCESS, and exit
cleanup:
// Do not free str* sec_header! It will be freed in data_lump.c -> free_lump()
ul.unlock_udomain(d, &ci.via_host, ci.via_port, ci.via_prot);
pkg_free(ci.received_host.s);
return ret;
}
示例9: process_contact
//.........这里部分代码省略.........
}
/*check for alias - NAT */
rest = uri.sip_params.s;
rest_len = uri.sip_params.len;
while (rest_len >= ALIAS_LEN) {
if (strncmp(rest, ALIAS, ALIAS_LEN) == 0) {
has_alias = 1;
break;
}
sep = memchr(rest, 59 /* ; */, rest_len);
if (sep == NULL) {
LM_DBG("no alias param\n");
break;
} else {
rest_len = rest_len - (sep - rest + 1);
rest = sep + 1;
}
}
if (has_alias) {
val = rest + ALIAS_LEN;
val_len = rest_len - ALIAS_LEN;
port = memchr(val, 126 /* ~ */, val_len);
if (port == NULL) {
LM_ERR("no '~' in alias param value\n");
return RESULT_ERROR;
}
port++;
// received_port = atoi(port);
trans = memchr(port, 126 /* ~ */, val_len - (port - val));
if (trans == NULL) {
LM_ERR("no second '~' in alias param value\n");
return RESULT_ERROR;
}
received_port_len = trans - port;
trans = trans + 1;
received_proto = *trans - 48 /* char 0 */;
memcpy(bufport, port, received_port_len);
bufport[received_port_len]=0;
ci.received_host.s = val;
ci.received_host.len = port - val - 1;
LM_DBG("Setting received host in search to [%.*s]\n", ci.received_host.len, ci.received_host.s);
ci.received_port = atoi(bufport);
LM_DBG("Setting received port in search to %d\n", ci.received_port);
ci.received_proto = received_proto;
LM_DBG("Setting received proto in search to %d\n", ci.received_proto);
ci.searchflag = SEARCH_RECEIVED;
} else {
LM_DBG("Contact in NOTIFY does not have an alias....\n");
}
if (ul.get_pcontact(_d, &ci, &pcontact) != 0) { //contact does not exist
if (contact_state == STATE_TERMINATED) {
LM_DBG("This contact: <%.*s> is in state terminated and is not in usrloc, ignore\n", contact_uri.len, contact_uri.s);
ret = RESULT_CONTACTS_FOUND;
goto done;
}
LM_WARN("This contact: <%.*s> is in state active and is not in usrloc - must be another contact on a different P so going to ignore\n", contact_uri.len, contact_uri.s);
// LM_DBG("This contact: <%.*s> is in state active and is not in usrloc so adding it to usrloc, expires: %d which is in %d seconds\n", contact_uri.len, contact_uri.s, expires, expires-local_time_now);
// if (ul.insert_pcontact(_d, &contact_uri, &ci, &pcontact) != 0) {
// LM_ERR("Failed inserting new pcontact\n");
// ret = RESULT_ERROR;
// goto done;
// } else {
// //register for callbacks on this contact so we can send PUBLISH to SCSCF should status change
// LM_DBG("registering for UL callback\n");
// ul.register_ulcb(pcontact, PCSCF_CONTACT_DELETE | PCSCF_CONTACT_EXPIRE, callback_pcscf_contact_cb, NULL);
// }
} else {//contact exists
if (contact_state == STATE_TERMINATED) {
//delete contact
LM_DBG("This contact <%.*s> is in state terminated and is in usrloc so removing it from usrloc\n", contact_uri.len, contact_uri.s);
if (ul.delete_pcontact(_d, pcontact) != 0) {
LM_DBG("failed to delete pcscf contact <%.*s> - not a problem this may have been removed by de registration", contact_uri.len, contact_uri.s);
}
/*TODO_LATEST - put this back */
} else {//state is active
//update this contact
LM_DBG("This contact: <%.*s> is in state active and is in usrloc so just updating - old expires: %li, new expires: %i which is in %i seconds\n", contact_uri.len, contact_uri.s,
pcontact->expires,
expires,
expires - local_time_now);
if (ul.update_pcontact(_d, &ci, pcontact) != 0) {
LM_ERR("failed to update pcscf contact\n");
ret = RESULT_ERROR;
goto done;
}
pcontact->expires = expires;
}
}
done:
ul.unlock_udomain(_d, &puri.host, puri.port_no, puri.proto);
return ret;
}
示例10: save_pending
/**
* Save contact based on REGISTER request. this will be a pending save, until we receive response
* from SCSCF. If no response after pending_timeout seconds, the contacts is removed. Can only be used from REQUEST ROUTE
*/
int save_pending(struct sip_msg* _m, udomain_t* _d) {
contact_body_t* cb = 0;
int cexpires = 0;
pcontact_t* pcontact;
contact_t* c;
struct pcontact_info ci;
struct via_body* vb;
unsigned short port, proto;
int_str val;
struct sip_uri parsed_received;
char srcip[50];
memset(&ci, 0, sizeof(struct pcontact_info));
vb = cscf_get_ue_via(_m);
port = vb->port?vb->port:5060;
proto = vb->proto;
cb = cscf_parse_contacts(_m);
if (!cb || (!cb->contacts)) {
LM_ERR("No contact headers\n");
goto error;
}
c = cb->contacts;
//TODO: need support for multiple contacts - currently assume one contact
//make sure this is not a de-registration
int expires_hdr = cscf_get_expires_hdr(_m, 0);
if (expires_hdr < 0) {
//no global header we have to check the contact expiry
if (c && c->expires && c->expires->body.len) {
str2int(&(c->expires->body), (unsigned int*) &cexpires);
}
if (!cexpires){ //assume de-registration
LM_DBG("not doing pending reg on de-registration\n");
return 1;
}
}
pcscf_act_time();
int local_time_now = time_now;
int expires = calc_contact_expires(c, expires_hdr, local_time_now);
if (expires <= 0) {
LM_DBG("not doing pending reg on de-registration\n");
return 1;
}
LM_DBG("Save Pending");
LM_DBG("contact requesting to expire in %d seconds\n", expires-local_time_now);
/*populate CI with bare minimum*/
ci.via_host = vb->host;
ci.via_port = port;
ci.via_prot = proto;
ci.aor = c->uri;
ci.num_public_ids=0;
ci.num_service_routes=0;
ci.expires=local_time_now + pending_reg_expires;
ci.reg_state=PCONTACT_ANY;
ci.searchflag=SEARCH_RECEIVED; //we want to make sure we are very specific with this search to make sure we get the correct contact to put into reg_pending.
// Received Info: First try AVP, otherwise simply take the source of the request:
memset(&val, 0, sizeof(int_str));
if (rcv_avp_name.n != 0
&& search_first_avp(rcv_avp_type, rcv_avp_name, &val, 0)
&& val.s.len > 0) {
if (val.s.len > RECEIVED_MAX_SIZE) {
LM_ERR("received too long\n");
goto error;
}
if (parse_uri(val.s.s, val.s.len, &parsed_received) < 0) {
LM_DBG("Error parsing Received URI <%.*s>\n", val.s.len, val.s.s);
goto error;
}
ci.received_host = parsed_received.host;
ci.received_port = parsed_received.port_no;
ci.received_proto = parsed_received.proto;
} else {
ci.received_host.len = ip_addr2sbuf(&_m->rcv.src_ip, srcip,
sizeof(srcip));
ci.received_host.s = srcip;
ci.received_port = _m->rcv.src_port;
ci.received_proto = _m->rcv.proto;
}
// Set to default, if not set:
if (ci.received_port == 0)
ci.received_port = 5060;
ul.lock_udomain(_d, &ci.via_host, ci.via_port, ci.via_prot);
if (ul.get_pcontact(_d, &ci, &pcontact) != 0) { //need to insert new contact
LM_DBG("Adding pending pcontact: <%.*s>\n", c->uri.len, c->uri.s);
ci.reg_state=PCONTACT_REG_PENDING;
if (ul.insert_pcontact(_d, &c->uri, &ci, &pcontact) != 0) {
LM_ERR("Failed inserting new pcontact\n");
} else {
LM_DBG("registering for UL callback\n");
//.........这里部分代码省略.........
示例11: getContactP
/**
* get PContact-Structure for message
* (search only once per Request)
*/
pcontact_t * getContactP(struct sip_msg* _m, udomain_t* _d) {
ppublic_t * p;
contact_body_t *b = 0;
contact_t *ct;
str received_host = {0, 0};
char srcip[50];
received_host.len = ip_addr2sbuf(&_m->rcv.src_ip, srcip, sizeof(srcip));
received_host.s = srcip;
if (_m->id != current_msg_id) {
current_msg_id = _m->id;
c = NULL;
if (is_registered_fallback2ip == 2) {
LM_DBG("Searching in usrloc for %.*s:%i (Proto %i)\n",
received_host.len, received_host.s,
_m->rcv.src_port, _m->rcv.proto);
if (ul.get_pcontact_by_src(_d, &received_host, _m->rcv.src_port, _m->rcv.proto, &c) == 1) {
LM_DBG("No entry in usrloc for %.*s:%i (Proto %i) found!\n", received_host.len, received_host.s, _m->rcv.src_port, _m->rcv.proto);
} else {
if (checkcontact(_m, c) != 0) {
c = NULL;
}
}
}
if (c == NULL) {
b = cscf_parse_contacts(_m);
if (b && b->contacts) {
for (ct = b->contacts; ct; ct = ct->next) {
if (ul.get_pcontact(_d, &ct->uri, &received_host, _m->rcv.src_port, &c) == 0) {
if (checkcontact(_m, c) != 0) {
c = NULL;
} else {
break;
}
}
}
} else {
LM_WARN("No contact-header found?!?\n");
}
}
if ((c == NULL) && (is_registered_fallback2ip == 1)) {
LM_INFO("Contact not found based on Contact-header, trying IP/Port/Proto\n");
received_host.len = ip_addr2sbuf(&_m->rcv.src_ip, srcip, sizeof(srcip));
received_host.s = srcip;
if (ul.get_pcontact_by_src(_d, &received_host, _m->rcv.src_port, _m->rcv.proto, &c) == 1) {
LM_DBG("No entry in usrloc for %.*s:%i (Proto %i) found!\n", received_host.len, received_host.s, _m->rcv.src_port, _m->rcv.proto);
} else {
if (checkcontact(_m, c) != 0) {
c = NULL;
}
}
}
}
asserted_identity = NULL;
registration_contact = NULL;
if (c) {
registration_contact = &c->contact_user;
p = c->head;
while (p) {
if (p->is_default == 1)
asserted_identity = &p->public_identity;
p = p->next;
}
}
return c;
}
示例12: sizeof
/**
* Updates the registrar with the new values
* @param req - the REGISTER request - to extract NAT info
* @param rpl - the REGISTER reply - to extract contact info
* @param is_star - whether this was a STAR contact header
* @param expires_hdr - value of the Expires header
* @param public_id - array of public identities attached to this contact
* @param public_id_cnt - size of the public_id array
* @param service_route - array of Service-Routes
* @param service_route_cnt - size of the service_route array
* @param requires_nat - if to create pinholes
* @returns the maximum expiration time, -1 on error
*/
static inline int update_contacts(struct sip_msg *req,struct sip_msg *rpl, udomain_t* _d, unsigned char is_star,int expires_hdr,
str *public_id,int public_id_cnt,str *service_route,int service_route_cnt, int requires_nat)
{
int local_time_now, expires=0;
struct hdr_field* h;
contact_t* c;
struct sip_uri puri;
struct pcontact_info ci;
pcontact_t* pcontact;
unsigned short port, proto;
char *alias_start, *p, *port_s, *proto_s;
char portbuf[5];
str alias_s;
pcscf_act_time();
local_time_now = time_now;
if (is_star) {
/* first of all, we shouldn't get here...
* then, we will update on NOTIFY */
return 0;
}
// Set the structure to "0", to make sure it's properly initialized
memset(&ci, 0, sizeof(struct pcontact_info));
for (h = rpl->contact; h; h = h->next) {
if (h->type == HDR_CONTACT_T && h->parsed) {
for (c = ((contact_body_t*) h->parsed)->contacts; c; c = c->next) {
expires = calc_contact_expires(c, expires_hdr, local_time_now);
if (parse_uri(c->uri.s, c->uri.len, &puri) < 0) {
LM_DBG("Error parsing Contact URI <%.*s>\n", c->uri.len, c->uri.s);
continue;
}
//build contact info
ci.aor = c->uri;
ci.expires = expires;
ci.public_ids = public_id;
ci.num_public_ids = public_id_cnt;
ci.service_routes = service_route;
ci.num_service_routes = service_route_cnt;
ci.reg_state = PCONTACT_REGISTERED|PCONTACT_REG_PENDING|PCONTACT_REG_PENDING_AAR; //we don't want to add contacts that did not come through us (pcscf)
ci.received_host.len = 0;
ci.received_host.s = 0;
ci.received_port = 0;
ci.received_proto = 0;
port = puri.port_no ? puri.port_no : 5060;
ci.via_host = puri.host;
ci.via_port = port;
ci.via_prot = puri.proto;
ci.searchflag = SEARCH_NORMAL; /* this must be reset for each contact iteration */
if (puri.params.len > 6 && (alias_start = _strnistr(puri.params.s, "alias=", puri.params.len)) != NULL) {
LM_DBG("contact has an alias [%.*s] - we can use that as the received\n", puri.params.len, puri.params.s);
alias_s.len = puri.params.len - (alias_start - puri.params.s) - 6;
alias_s.s = alias_start + 6;
LM_DBG("alias [%.*s]\n", alias_s.len, alias_s.s);
p = _strnistr(alias_s.s, "~", alias_s.len);
if (p!=NULL) {
ci.received_host.s = alias_s.s;
ci.received_host.len = p - alias_s.s;
LM_DBG("alias(host) [%.*s]\n", ci.received_host.len, ci.received_host.s);
port_s = p+1;
p = _strnistr(port_s, "~", alias_s.len - ci.received_host.len);
if (p!=NULL) {
LM_DBG("alias(port) [%.*s]\n", (int)(p - port_s) , port_s);
memset(portbuf, 0, 5);
memcpy(portbuf, port_s, (p-port_s));
port = atoi(portbuf);
LM_DBG("alias(port) [%d]\n", port);
proto_s = p + 1;
memset(portbuf, 0, 5);
memcpy(portbuf, proto_s, 1);
proto = atoi(portbuf);
LM_DBG("alias(proto) [%d]\n", proto);
ci.received_port = port;
ci.received_proto = proto;
ci.searchflag = SEARCH_RECEIVED;
}
}
}
ul.lock_udomain(_d, &puri.host, port, puri.proto);
if (ul.get_pcontact(_d, &ci, &pcontact) != 0) { //need to insert new contact
if ((expires-local_time_now)<=0) { //remove contact - de-register
LM_DBG("This is a de-registration for contact <%.*s> but contact is not in usrloc - ignore\n", c->uri.len, c->uri.s);
//.........这里部分代码省略.........
示例13: w_rx_aar_register
//.........这里部分代码省略.........
saved_t_data->act = cfg_action;
saved_t_data->domain = domain_t;
saved_t_data->lock = lock_alloc();
if (saved_t_data->lock == NULL) {
LM_ERR("unable to allocate init lock for saved_t_transaction reply counter\n");
return CSCF_RETURN_ERROR;
}
if (lock_init(saved_t_data->lock) == NULL) {
LM_ERR("unable to init lock for saved_t_transaction reply counter\n");
return CSCF_RETURN_ERROR;
}
LM_DBG("Suspending SIP TM transaction\n");
if (tmb.t_suspend(msg, &saved_t_data->tindex, &saved_t_data->tlabel) < 0) {
LM_ERR("failed to suspend the TM processing\n");
free_saved_transaction_global_data(saved_t_data);
return CSCF_RETURN_ERROR;
}
LM_DBG("Successfully suspended transaction\n");
//now get the contacts in the REGISTER and do AAR for each one.
cb = cscf_parse_contacts(msg);
if (!cb || (!cb->contacts && !cb->star)) {
LM_DBG("No contact headers in Register message\n");
goto error;
}
lock_get(saved_t_data->lock); //we lock here to make sure we send all requests before processing replies asynchronously
for (h = msg->contact; h; h = h->next) {
if (h->type == HDR_CONTACT_T && h->parsed) {
for (c = ((contact_body_t*) h->parsed)->contacts; c; c = c->next) {
ul.lock_udomain(domain_t, &c->uri);
if (ul.get_pcontact(domain_t, &c->uri, &pcontact) != 0) {
LM_DBG("This contact does not exist in PCSCF usrloc - error in cfg file\n");
ul.unlock_udomain(domain_t, &c->uri);
lock_release(saved_t_data->lock);
goto error;
} else if (pcontact->reg_state == PCONTACT_REG_PENDING
|| pcontact->reg_state == PCONTACT_REGISTERED) { //NEW reg request
LM_DBG("Contact [%.*s] exists and is in state PCONTACT_REG_PENDING or PCONTACT_REGISTERED\n"
, pcontact->aor.len, pcontact->aor.s);
//get IP address from contact
struct sip_uri puri;
if (parse_uri(c->uri.s, c->uri.len, &puri) < 0) {
LM_ERR("failed to parse Contact\n");
ul.unlock_udomain(domain_t, &c->uri);
lock_release(saved_t_data->lock);
goto error;
}
LM_DBG("Parsed URI of from host is [%.*s]\n", puri.host.len, puri.host.s);
uint16_t ip_version = AF_INET; //TODO IPv6!!!?
//check for existing Rx session
if (pcontact->rx_session_id.len > 0
&& pcontact->rx_session_id.s
&& (auth = cdpb.AAAGetAuthSession(pcontact->rx_session_id))) {
LM_DBG("Rx session already exists for this user\n");
if (memcmp(pcontact->rx_session_id.s, auth->id.s, auth->id.len) != 0) {
LM_ERR("Rx session mismatch when URI is [%.*s].......Aborting\n", puri.host.len, puri.host.s);
if (auth) cdpb.AAASessionsUnlock(auth->hash);
lock_release(saved_t_data->lock);
goto error;
}
示例14: cdp_cb_event_process
/*main event process function*/
void cdp_cb_event_process() {
cdp_cb_event_t *ev;
udomain_t* domain;
pcontact_t* pcontact;
str release_reason = {"QoS released", 12}; /* TODO: This could be a module parameter */
struct pcontact_info ci;
memset(&ci, 0, sizeof (struct pcontact_info));
for (;;) {
ev = pop_cdp_cb_event();
if (cdp_event_latency) { //track delays
unsigned int diff = time(NULL) - ev->registered;
if (diff > cdp_event_threshold) {
switch (cdp_event_latency_loglevel) {
case 0:
LM_ERR("Took to long to pickup CDP callback event [%d] > [%d]\n", diff, cdp_event_threshold);
break;
case 1:
LM_WARN("Took to long to pickup CDP callback event [%d] > [%d]\n", diff, cdp_event_threshold);
break;
case 2:
LM_INFO("Took to long to pickup CDP callback event [%d] > [%d]\n", diff, cdp_event_threshold);
break;
case 3:
LM_DBG("Took to long to pickup CDP callback event [%d] > [%d]\n", diff, cdp_event_threshold);
break;
default:
LM_DBG("Unknown log level....printing as debug\n");
LM_DBG("Took to long to pickup CDP callback event [%d] > [%d]\n", diff, cdp_event_threshold);
break;
}
}
}
LM_DBG("processing event [%d]\n", ev->event);
rx_authsessiondata_t *p_session_data = ev->session_data;
str *rx_session_id = &ev->rx_session_id;
switch (ev->event) {
case AUTH_EV_SESSION_TIMEOUT:
case AUTH_EV_SESSION_GRACE_TIMEOUT:
case AUTH_EV_RECV_ASR:
LM_DBG("Received notification of ASR from transport plane or CDP timeout for CDP session with Rx session ID: [%.*s] and associated contact [%.*s]"
" and domain [%.*s]\n",
rx_session_id->len, rx_session_id->s,
p_session_data->registration_aor.len, p_session_data->registration_aor.s,
p_session_data->domain.len, p_session_data->domain.s);
if (p_session_data->subscribed_to_signaling_path_status) {
LM_DBG("This is a subscription to signalling bearer session");
//nothing to do here - just wait for AUTH_EV_SERVICE_TERMINATED event
} else {
LM_DBG("This is a media bearer session session");
//this is a media bearer session that was terminated from the transport plane - we need to terminate the associated dialog
//so we set p_session_data->must_terminate_dialog to 1 and when we receive AUTH_EV_SERVICE_TERMINATED event we will terminate the dialog
p_session_data->must_terminate_dialog = 1;
}
break;
case AUTH_EV_SERVICE_TERMINATED:
LM_DBG("Received notification of CDP TERMINATE of CDP session with Rx session ID: [%.*s] and associated contact [%.*s]"
" and domain [%.*s]\n",
rx_session_id->len, rx_session_id->s,
p_session_data->registration_aor.len, p_session_data->registration_aor.s,
p_session_data->domain.len, p_session_data->domain.s);
if (p_session_data->subscribed_to_signaling_path_status) {
LM_DBG("This is a subscription to signalling bearer session");
//instead of removing the contact from usrloc_pcscf we just change the state of the contact to TERMINATE_PENDING_NOTIFY
//pcscf_registrar sees this, sends a SIP PUBLISH and on SIP NOTIFY the contact is deleted
if (ul.register_udomain(p_session_data->domain.s, &domain)
< 0) {
LM_DBG("Unable to register usrloc domain....aborting\n");
return;
}
ul.lock_udomain(domain, &p_session_data->registration_aor);
if (ul.get_pcontact(domain, &p_session_data->registration_aor,
&pcontact) != 0) {
LM_DBG("no contact found for terminated Rx reg session..... ignoring\n");
} else {
LM_DBG("Updating contact [%.*s] after Rx reg session terminated, setting state to PCONTACT_DEREG_PENDING_PUBLISH\n", pcontact->aor.len, pcontact->aor.s);
ci.reg_state = PCONTACT_DEREG_PENDING_PUBLISH;
ci.num_service_routes = 0;
ul.update_pcontact(domain, &ci, pcontact);
}
ul.unlock_udomain(domain, &p_session_data->registration_aor);
} else {
LM_DBG("This is a media bearer session session");
//we only terminate the dialog if this was triggered from the transport plane or timeout - i.e. if must_terminate_dialog is set
//if this was triggered from the signalling plane (i.e. someone hanging up) then we don'y need to terminate the dialog
if (p_session_data->must_terminate_dialog) {
LM_DBG("Terminating dialog with callid, ftag, ttag: [%.*s], [%.*s], [%.*s]\n",
p_session_data->callid.len, p_session_data->callid.s,
p_session_data->ftag.len, p_session_data->ftag.s,
p_session_data->ttag.len, p_session_data->ttag.s);
dlgb.terminate_dlg(&p_session_data->callid,
//.........这里部分代码省略.........
示例15: sizeof
/**
* Updates the registrar with the new values
* @param req - the REGISTER request - to extract NAT info
* @param rpl - the REGISTER reply - to extract contact info
* @param is_star - whether this was a STAR contact header
* @param expires_hdr - value of the Expires header
* @param public_id - array of public identities attached to this contact
* @param public_id_cnt - size of the public_id array
* @param service_route - array of Service-Routes
* @param service_route_cnt - size of the service_route array
* @param requires_nat - if to create pinholes
* @returns the maximum expiration time, -1 on error
*/
static inline int update_contacts(struct sip_msg *req,struct sip_msg *rpl, udomain_t* _d, unsigned char is_star,int expires_hdr,
str *public_id,int public_id_cnt,str *service_route,int service_route_cnt, int requires_nat)
{
int local_time_now, expires=0;
struct hdr_field* h;
contact_t* c;
struct sip_uri puri;
struct sip_uri parsed_received;
struct pcontact_info ci;
pcontact_t* pcontact;
char srcip[50];
int_str val;
pcscf_act_time();
local_time_now = time_now;
if (is_star) {
/* first of all, we shouldn't get here...
* then, we will update on NOTIFY */
return 0;
}
// Set the structure to "0", to make sure it's properly initialized
memset(&ci, 0, sizeof(struct pcontact_info));
for (h = rpl->contact; h; h = h->next) {
if (h->type == HDR_CONTACT_T && h->parsed)
for (c = ((contact_body_t*) h->parsed)->contacts; c; c = c->next) {
expires = calc_contact_expires(c, expires_hdr, local_time_now);
if (parse_uri(c->uri.s, c->uri.len, &puri) < 0) {
LM_DBG("Error parsing Contact URI <%.*s>\n", c->uri.len, c->uri.s);
continue;
}
//build contact info
ci.expires = expires;
ci.public_ids = public_id;
ci.num_public_ids = public_id_cnt;
ci.service_routes = service_route;
ci.num_service_routes = service_route_cnt;
ci.reg_state = PCONTACT_REGISTERED;
ci.received_host.len = 0;
ci.received_host.s = 0;
ci.received_port = 0;
ci.received_proto = 0;
// Received Info: First try AVP, otherwise simply take the source of the request:
memset(&val, 0, sizeof(int_str));
if (rcv_avp_name.n!=0 && search_first_avp(rcv_avp_type, rcv_avp_name, &val, 0) && val.s.len > 0) {
if (val.s.len>RECEIVED_MAX_SIZE) {
LM_ERR("received too long\n");
goto error;
}
if (parse_uri(val.s.s, val.s.len, &parsed_received) < 0) {
LM_DBG("Error parsing Received URI <%.*s>\n", val.s.len, val.s.s);
continue;
}
ci.received_host = parsed_received.host;
ci.received_port = parsed_received.port_no;
ci.received_proto = parsed_received.proto;
} else {
ci.received_host.len = ip_addr2sbuf(&req->rcv.src_ip, srcip, sizeof(srcip));
ci.received_host.s = srcip;
ci.received_port = req->rcv.src_port;
ci.received_proto = req->rcv.proto;
}
// Set to default, if not set:
if (ci.received_port == 0) ci.received_port = 5060;
ul.lock_udomain(_d, &c->uri);
if (ul.get_pcontact(_d, &c->uri, &pcontact) != 0) { //need to insert new contact
if ((expires-local_time_now)<=0) { //remove contact - de-register
LM_DBG("This is a de-registration for contact <%.*s> but contact is not in usrloc - ignore\n", c->uri.len, c->uri.s);
goto next_contact;
}
LM_DBG("Adding pcontact: <%.*s>, expires: %d which is in %d seconds\n", c->uri.len, c->uri.s, expires, expires-local_time_now);
if (ul.insert_pcontact(_d, &c->uri, &ci, &pcontact) != 0) {
LM_ERR("Failed inserting new pcontact\n");
} else {
//register for callbacks on this contact so we can send PUBLISH to SCSCF should status change
LM_DBG("registering for UL callback\n");
ul.register_ulcb(pcontact, PCSCF_CONTACT_DELETE | PCSCF_CONTACT_EXPIRE, callback_pcscf_contact_cb, NULL);
//we also need to subscribe to reg event of this contact at SCSCF
}
} else { //contact already exists - update
LM_DBG("contact already exists and is in state (%d) : [%s]\n",pcontact->reg_state, reg_state_to_string(pcontact->reg_state));
//.........这里部分代码省略.........