当前位置: 首页>>代码示例>>C++>>正文


C++ usrloc_api_t::unlock_udomain方法代码示例

本文整理汇总了C++中usrloc_api_t::unlock_udomain方法的典型用法代码示例。如果您正苦于以下问题:C++ usrloc_api_t::unlock_udomain方法的具体用法?C++ usrloc_api_t::unlock_udomain怎么用?C++ usrloc_api_t::unlock_udomain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在usrloc_api_t的用法示例。


在下文中一共展示了usrloc_api_t::unlock_udomain方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: add_dlg_data_to_contact

void add_dlg_data_to_contact(struct dlg_cell *dlg, int type, struct dlg_cb_params *_params) {
    
    struct impu_data *impu_data;
    impurecord_t* implicit_impurecord = 0;
    struct ucontact* ucontact;
    str callid = {0, 0};
    str path = {0, 0};
    
    LM_DBG("dialog [%p] confirmed, lets add dlg data to contact\n", dlg);
    
    if(_params && _params->param){
	impu_data = (struct impu_data*)*_params->param;
	if (!impu_data) {
		LM_ERR("IMPU data object is NULL...... aborting\n");
		return;
	}
	
	LM_DBG("IMPU data is present, contact: <%.*s> identity <%.*s>", impu_data->contact.len, impu_data->contact.s, impu_data->identity.len, impu_data->identity.s);
	LM_DBG("IMPU data domain <%.*s>", impu_data->d->name->len, impu_data->d->name->s);
	
	ul.lock_udomain(impu_data->d, &impu_data->identity);
	if (ul.get_impurecord(impu_data->d, &impu_data->identity, &implicit_impurecord) != 0) {
	    LM_DBG("usrloc does not have imprecord for implicity IMPU, ignore\n");
	}else {
	    if (ul.get_ucontact(implicit_impurecord, &impu_data->contact, &callid, &path, 0/*cseq*/,  &ucontact) != 0) { //contact does not exist
		LM_DBG("This contact: <%.*s> is not in usrloc, ignore - NOTE: You need S-CSCF usrloc set to match_mode CONTACT_PORT_IP_ONLY\n", impu_data->contact.len, impu_data->contact.s);
	    } else {//contact exists so add dialog data to it
		ul.add_dialog_data_to_contact(ucontact, dlg->h_entry, dlg->h_id);
	    }
	}
	ul.unlock_udomain(impu_data->d, &impu_data->identity);
    }
} 
开发者ID:SibghatullahSheikh,项目名称:kamailio,代码行数:33,代码来源:dialog.c

示例2: 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;
}
开发者ID:AndreyRybkin,项目名称:kamailio,代码行数:59,代码来源:lookup.c

示例3: assert_identity

/**
 * Add proper asserted identies based on registration
 */
int assert_identity(struct sip_msg* _m, udomain_t* _d, str identity) {
	// Get the contact:
	pcontact_t * c = getContactP(_m, _d);
	// Public identities of this contact
	ppublic_t * p;
	
	// Contact not found => Identity not asserted.
	if (c == NULL) return -2;

	/* Lock this record while working with the data: */
	ul.lock_udomain(_d, &c->aor);

	LM_DBG("Checking identity: %.*s\n", identity.len, identity.s);

	LM_DBG("AOR of contact: %.*s\n", c->aor.len, c->aor.s);

	for (p = c->head; p; p = p->next) {
		LM_DBG("Public identity: %.*s\n", p->public_identity.len, p->public_identity.s);
		/* Check length: */
		if (identity.len == p->public_identity.len) {
			/* Check contents: */
			if (strncasecmp(identity.s, p->public_identity.s, identity.len) != 0) {
				LM_DBG("Match!\n");
				goto success;
			}
		} else LM_DBG("Length does not match.\n");
	}

	// We should only get here, if we failed:
	/* Unlock domain */
	ul.unlock_udomain(_d, &c->aor);
	return -1;
success:
	/* Unlock domain */
	ul.unlock_udomain(_d, &c->aor);
	return 1;
}
开发者ID:halan,项目名称:kamailio,代码行数:40,代码来源:service_routes.c

示例4: remove_dlg_data_from_contact

void remove_dlg_data_from_contact(struct dlg_cell *dlg, int type, struct dlg_cb_params *_params) {
        
    struct impu_data *impu_data;
    impurecord_t* implicit_impurecord = 0;
    struct ucontact* ucontact;
    str callid = {0, 0};
    str path = {0, 0};
    udomain_t* domain_t;
    
    LM_DBG("dialog [%p] terminated, lets remove dlg data from contact\n", dlg);
    
    if (ul.register_udomain(domain, &domain_t) < 0) {
	    LM_ERR("Unable to register usrloc domain....aborting\n");
	    return;
    }
    
    if(_params && _params->param){
	impu_data = (struct impu_data*)*_params->param;
	if (!impu_data) {
		LM_ERR("IMPU data object is NULL...... aborting\n");
		return;
	}
	
	LM_DBG("IMPU data is present, contact: <%.*s> identity <%.*s>", impu_data->contact.len, impu_data->contact.s, impu_data->identity.len, impu_data->identity.s);
	LM_DBG("IMPU data domain <%.*s>", domain_t->name->len, domain_t->name->s);
	
	ul.lock_udomain(domain_t, &impu_data->identity);
	if (ul.get_impurecord(domain_t, &impu_data->identity, &implicit_impurecord) != 0) {
	    LM_DBG("usrloc does not have imprecord for implicity IMPU, ignore\n");
	}else {
	    if (ul.get_ucontact(&impu_data->contact, &callid, &path, 0/*cseq*/,  &ucontact) != 0) { //contact does not exist
		LM_DBG("This contact: <%.*s> is not in usrloc, ignore - NOTE: You need S-CSCF usrloc set to match_mode CONTACT_PORT_IP_ONLY\n", impu_data->contact.len, impu_data->contact.s);
	    } else {//contact exists so add dialog data to it
		ul.remove_dialog_data_from_contact(ucontact, dlg->h_entry, dlg->h_id);
		ul.release_ucontact(ucontact);
	    }
	}
	ul.unlock_udomain(domain_t, &impu_data->identity);
	free_impu_data(impu_data);
    }
    
    //we referenced the dialog when we registered for callbacks on it...
    dlgb.release_dlg(dlg);
}
开发者ID:DileepNunna,项目名称:kamailio,代码行数:44,代码来源:dialog.c

示例5: 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;
}
开发者ID:TheGrandWazoo,项目名称:kamailio,代码行数:43,代码来源:service_routes.c

示例6: 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;
}
开发者ID:Gitlab11,项目名称:kamailio,代码行数:23,代码来源:service_routes.c

示例7: force_service_routes


//.........这里部分代码省略.........
	pcontact_t * c = getContactP(_m, _d, PCONTACT_REGISTERED,0 ,0);
//	char srcip[20];
//	str received_host;
        struct via_body* vb;
        unsigned short port;
        unsigned short proto;
	
	// Contact not found => not following service-routes
	if (c == NULL) return -1;

	/* we need to be sure we have seen all HFs */
	parse_headers(_m, HDR_EOH_F, 0);

        vb = cscf_get_ue_via(_m);
        port = vb->port?vb->port:5060;
        proto = vb->proto;
        
	/* Save current buffer */
	buf = _m->buf;

	// Delete old Route headers:
	if (_m->route) {
		for (it = _m->route; it; it = it->next) {
			if (it->type == HDR_ROUTE_T) {
				if ((lmp = del_lump(_m, it->name.s - buf, it->len, HDR_ROUTE_T)) == 0) {
					LM_ERR("del_lump failed \n");
					return -1;
				}
			}
		}
	}

	/* Reset dst_uri if previously set either by loose route or manually */
	if (_m->dst_uri.s && _m->dst_uri.len) {
		pkg_free(_m->dst_uri.s);
		_m->dst_uri.s = NULL;
		_m->dst_uri.len = 0;
	}
	
//	received_host.len = ip_addr2sbuf(&_m->rcv.src_ip, srcip, sizeof(srcip));
//	received_host.s = srcip;

	/* Lock this record while working with the data: */
	ul.lock_udomain(_d, &vb->host, port, proto);

	if (c->num_service_routes > 0) {
		/* Create anchor for new Route-Header: */
		lmp = anchor_lump(_m, _m->headers->name.s - buf,0,0);
		if (lmp == 0) {
			LM_ERR("Failed to get anchor lump\n");
			goto error;
		}	
		/* Calculate the length: */
		new_route_header.len = route_start.len +
			route_end.len + (c->num_service_routes-1) * route_sep.len;

		for(i=0; i< c->num_service_routes; i++)
			new_route_header.len+=c->service_routes[i].len;		
		/* Allocate the memory for this new header: */
		new_route_header.s = pkg_malloc(new_route_header.len);
		if (!new_route_header.s) {
			LM_ERR("Error allocating %d bytes\n", new_route_header.len);
			goto error;
		}
		
		/* Construct new header */
		new_route_header.len = 0;
		STR_APPEND(new_route_header, route_start);
		for(i=0; i < c->num_service_routes; i++) {
			if (i) STR_APPEND(new_route_header, route_sep);
			STR_APPEND(new_route_header, c->service_routes[i]);
		}
		STR_APPEND(new_route_header, route_end);

		LM_DBG("Setting route header to <%.*s> \n", new_route_header.len, new_route_header.s);

		if ((lmp = insert_new_lump_after(lmp, new_route_header.s, new_route_header.len, HDR_ROUTE_T)) == 0) {
			LM_ERR("Error inserting new route set\n");
			pkg_free(new_route_header.s);
			goto error;
		}

		LM_DBG("Setting dst_uri to <%.*s> \n", c->service_routes[0].len,
			c->service_routes[0].s);

		if (set_dst_uri(_m, &c->service_routes[0]) !=0 ) {
			LM_ERR("Error setting new dst uri\n");
			goto error;
		}
	}
	/* Unlock domain */
	ul.unlock_udomain(_d, &vb->host, port, proto);
	return 1;
error:
	/* Unlock domain */
	ul.unlock_udomain(_d, &vb->host, port, proto);
	return -1;
	
    return 1;
}
开发者ID:TheGrandWazoo,项目名称:kamailio,代码行数:101,代码来源:service_routes.c

示例8: check_service_routes

/**
 * Check, if a user-agent follows the indicated service-routes
 */
int check_service_routes(struct sip_msg* _m, udomain_t* _d) {
	struct sip_uri uri;
	int i;
	struct hdr_field *hdr;
	rr_t *r;
	char routes[MAXROUTES][MAXROUTESIZE];
	unsigned int num_routes = 0;
	
	struct via_body * vb;
	unsigned short port;
	unsigned short proto;
	/* Contact not found => not following service-routes */
//	if (c == NULL) return -1;

	/* Search for the first Route-Header: */
	if (find_first_route(_m) < 0) return -1;

//	LM_DBG("Got %i Route-Headers.\n", c->num_service_routes);

	vb = cscf_get_ue_via(_m);
	port = vb->port?vb->port:5060;
	proto = vb->proto;
	
	/* Lock this record while working with the data: */
	ul.lock_udomain(_d, &vb->host, port, proto);
    
	if (_m->route) {
		hdr = _m->route;
		r = (rr_t*)hdr->parsed;
		//get rid of ourselves from route header
		if (r) {
			LM_DBG("Route is %.*s\n", r->nameaddr.uri.len, r->nameaddr.uri.s);
			while (r && (parse_uri(r->nameaddr.uri.s, r->nameaddr.uri.len, &uri) == 0)
			  && check_self(&uri.host,uri.port_no?uri.port_no:SIP_PORT,0)) {
				LM_DBG("Self\n");
				/* Check for more headers and fail, if it was the last one
				   Check, if service-routes are indicated.
				   If yes, request is not following service-routes */
				if (find_next_route(_m, &hdr) != 0) 
					r = NULL;
				else 
					r = (rr_t*)hdr->parsed;
				
				LM_DBG("hdr is %p\n", hdr);
				LM_DBG("r is %p\n", r);
				if (r)
					LM_DBG("Next Route is %.*s\n", r->nameaddr.uri.len, r->nameaddr.uri.s);
			}
			
			int i = 0;
			while (r) {
				memset(routes[i],0,MAXROUTESIZE);
				memcpy(routes[i], r->nameaddr.uri.s, r->nameaddr.uri.len);
				
				if (find_next_route(_m, &hdr) != 0) 
					r = NULL;
				else 
					r = (rr_t*)hdr->parsed;
				
				i += 1;
				num_routes += 1;
			}
			
			LM_DBG("num_routes is %d\n", num_routes);
			for (i=0; i<num_routes; i++) {
				LM_DBG("route %d for checking is %s\n", i, routes[i]);
			}
			pcontact_t * c = getContactP(_m, _d, PCONTACT_REGISTERED, routes, num_routes);
			if (!c) {
				LM_DBG("no contact found in usrloc when checking for service route\n");
				goto error;
			}
			
			LM_DBG("we have a contact which satisifes the routes...\n");
			ul.unlock_udomain(_d, &vb->host, port, proto);
			return 1;
		}
	} else {
		LM_DBG("Request doesn't have any route headers to check service-route...ignoring\n");
		goto error;
	}
	
	pcontact_t * c = getContactP(_m, _d, PCONTACT_REGISTERED, 0, 0);
	if (!c) {
		LM_DBG("no contact found in usrloc when checking for service route\n");
		goto error;
	}

	/* Check the route-set: */
	if (_m->route) {
		hdr = _m->route;
		LM_DBG("hdr is %p\n", hdr);
		/* Check, if the first host is ourself: */
		r = (rr_t*)hdr->parsed;
		if (r) {
			LM_DBG("Route is %.*s\n", r->nameaddr.uri.len, r->nameaddr.uri.s);
			/* Skip first headers containing myself: */
//.........这里部分代码省略.........
开发者ID:TheGrandWazoo,项目名称:kamailio,代码行数:101,代码来源:service_routes.c

示例9: check_service_routes

/**
 * Check, if a user-agent follows the indicated service-routes
 */
int check_service_routes(struct sip_msg* _m, udomain_t* _d) {
	struct sip_uri uri;
	int i;
	struct hdr_field *hdr;
	rr_t *r;
	pcontact_t * c = getContactP(_m, _d);
	/* Contact not found => not following service-routes */
	if (c == NULL) return -1;

	/* Search for the first Route-Header: */
	if (find_first_route(_m) < 0) return -1;

	LM_DBG("Got %i Route-Headers.\n", c->num_service_routes);

	/* Lock this record while working with the data: */
	ul.lock_udomain(_d, &c->aor);

	/* Check the route-set: */
	if (_m->route) {
		hdr = _m->route;
		LM_DBG("hdr is %p\n", hdr);
		/* Check, if the first host is ourself: */
		r = (rr_t*)hdr->parsed;
		if (r) {
			LM_DBG("Route is %.*s\n", r->nameaddr.uri.len, r->nameaddr.uri.s);
			/* Skip first headers containing myself: */
			while (parse_uri(r->nameaddr.uri.s, r->nameaddr.uri.len, &uri) == 0
			  && check_self(&uri.host,uri.port_no?uri.port_no:SIP_PORT,0)) {
				LM_DBG("Self\n");
				/* Check for more headers and fail, if it was the last one
				   Check, if service-routes are indicated.
				   If yes, request is not following service-routes */
				if (find_next_route(_m, &hdr) != 0) r = NULL;
				else r = (rr_t*)hdr->parsed;

				if (!r && (c->num_service_routes > 0)) {
					LM_DBG("Not enough route-headers in Message\n");
					goto error;
				}
				LM_DBG("hdr is %p\n", hdr);
				LM_DBG("r is %p\n", r);
				if (r)
					LM_DBG("Next Route is %.*s\n", r->nameaddr.uri.len, r->nameaddr.uri.s);
			}
			/* Then check the following headers: */
			for (i=0; i< c->num_service_routes; i++) {
				LM_DBG("Route must be: %.*s\n", c->service_routes[i].len, c->service_routes[i].s);

				/* No more Route-Headers? Not following service-routes */
				if (!r) {
					LM_ERR("No more route headers in message.\n");
					 goto error;
				}
				
				LM_DBG("Route is: %.*s\n", r->nameaddr.uri.len, r->nameaddr.uri.s);
 				
				/* Check length: */
				if (r->nameaddr.uri.len != c->service_routes[i].len) {
					LM_DBG("Length does not match.\n");
					 goto error;
				}
				/* Check contents: */
				if (strncasecmp(r->nameaddr.uri.s, c->service_routes[i].s, c->service_routes[i].len) != 0) {
					LM_DBG("String comparison failed.\n");
					 goto error;
				}
				if (find_next_route(_m, &hdr) != 0) r = NULL;
				else r = (rr_t*)hdr->parsed;
			}

			/* Check, if it was the last route-header in the message: */
			if (r) {
				LM_ERR("Too many route headers in message.\n");
				 goto error;
			}
		} else {
			LM_WARN("Strange: Route-Header is present, but not parsed?!?");
			if (c->num_service_routes > 0) goto error;
		}
	} else {
		LM_ERR("No route header in Message.\n");
		/* No route-header? Check, if service-routes are indicated.
		   If yes, request is not following service-routes */
		if (c->num_service_routes > 0) goto error;
	}
	/* Unlock domain */
	ul.unlock_udomain(_d, &c->aor);
	return 1;
error:
	/* Unlock domain */
	ul.unlock_udomain(_d, &c->aor);
	return -1;
}
开发者ID:gbour,项目名称:kamailio,代码行数:96,代码来源:service_routes.c

示例10: ipsec_forward


//.........这里部分代码省略.........
    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;
    }

    if(add_security_server_header(m, s) != 0) {
        goto cleanup;
    }

    ret = IPSEC_CMD_SUCCESS;    // all good, set ret to SUCCESS, and exit

cleanup:
    ul.unlock_udomain(d, &ci.via_host, ci.via_port, ci.via_prot);
    pkg_free(ci.received_host.s);
    return ret;
}


int ipsec_destroy(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;
    }
开发者ID:btriller,项目名称:kamailio,代码行数:66,代码来源:cmd.c

示例11: 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;
}
开发者ID:btriller,项目名称:kamailio,代码行数:70,代码来源:cmd.c

示例12: w_rx_aar_register


//.........这里部分代码省略.........
    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;
                        }
                        //re-registration - update auth lifetime
                        auth->u.auth.lifetime = time(NULL) + rx_auth_expiry;
开发者ID:Jared-Prime,项目名称:kamailio,代码行数:67,代码来源:mod.c

示例13: cxdx_process_rtr

AAAMessage* cxdx_process_rtr(AAAMessage *rtr) {
    LM_DBG("Processing RTR");
    
    AAAMessage *rta_msg;
    AAA_AVP* avp;
    str public_id;
    impurecord_t* r;
    int res = 0;
    udomain_t* udomain;
	impu_contact_t *impucontact;
    
    rta_msg = cdpb.AAACreateResponse(rtr);//session ID?
    if (!rta_msg) return 0;

    avp = cxdx_get_next_public_identity(rtr,0,AVP_IMS_Public_Identity,IMS_vendor_id_3GPP,__FUNCTION__);	
    if(avp==0){
	    LM_WARN("RTR received with only IMPI (username AVP) - currently S-CSCF does not support this kind of RTR\n");
	    return 0;
	    //TODO add support for receiving RTR with IMPI
	    //get all impus related to this impu
	    //get all contacts related to each impu
	    //set the contact expire for each contact to now
    }else{
	    public_id=avp->data;
	    LM_DBG("RTR received with IMPU [%.*s] in public identity AVP - this is supported\n", public_id.len, public_id.s);

	    //TODO this should be a configurable module param
	    if (ul.register_udomain(domain, &udomain) < 0) {
		LM_ERR("Unable to register usrloc domain....aborting\n");
		return 0;
	    }
	    
	    ul.lock_udomain(udomain, &public_id);
            res = ul.get_impurecord(udomain, &public_id, &r);
            if (res != 0) {
                LM_WARN("Strange, '%.*s' Not found in usrloc\n", public_id.len, public_id.s);
                ul.unlock_udomain(udomain, &public_id);
                //no point in continuing
                return 0;
            }
	    
		impucontact = r->linked_contacts.head;
		while (impucontact) {
			LM_DBG("Deleting contact with AOR [%.*s]\n", impucontact->contact->aor.len, impucontact->contact->aor.s);
			ul.lock_contact_slot_i(impucontact->contact->sl);
			impucontact->contact->state = CONTACT_DELETE_PENDING;
			if (r->shead) {
				//send NOTIFY to all subscribers of this IMPU.
				notify_subscribers(r, 0, 0);
			}
			impucontact->contact->state = CONTACT_DELETED;
			ul.unlock_contact_slot_i(impucontact->contact->sl);
			
			impucontact = impucontact->next;
		}
	    
	    ul.unlock_udomain(udomain, &public_id);
	    
	    while(cdpb.AAAGetNextAVP(avp) && (avp=cxdx_get_next_public_identity(rtr,cdpb.AAAGetNextAVP(avp),AVP_IMS_Public_Identity,IMS_vendor_id_3GPP,__FUNCTION__))!=0){
		    public_id=avp->data;
		    LM_DBG("RTR also has public id [%.*s]\n", public_id.len, public_id.s);
		    ul.lock_udomain(udomain, &public_id);
		    res = ul.get_impurecord(udomain, &public_id, &r);
		    if (res != 0) {
			LM_WARN("Strange, '%.*s' Not found in usrloc\n", public_id.len, public_id.s);
			ul.unlock_udomain(udomain, &public_id);
			//no point in continuing
			return 0;
		    }

		    impucontact = r->linked_contacts.head;
			while (impucontact) {
				LM_DBG("Deleting contact with AOR [%.*s]\n", impucontact->contact->aor.len, impucontact->contact->aor.s);
				ul.lock_contact_slot_i(impucontact->contact->sl);
				impucontact->contact->state = CONTACT_DELETE_PENDING;
				if (r->shead) {
					//send NOTIFY to all subscribers of this IMPU.
					notify_subscribers(r, 0, 0);
				}
				impucontact->contact->state = CONTACT_DELETED;
				ul.unlock_contact_slot_i(impucontact->contact->sl);
				impucontact = impucontact->next;
		    }

		    ul.unlock_udomain(udomain, &public_id);
		}		
    }
    cxdx_add_vendor_specific_appid(rta_msg,IMS_vendor_id_3GPP,IMS_Cx,0 /*IMS_Cx*/);
    
    cxdx_add_auth_session_state(rta_msg,1);		

    /* send an RTA back to the HSS */
    cxdx_add_result_code(rta_msg,DIAMETER_SUCCESS);
    
    return rta_msg;
    
    
}
开发者ID:GreenfieldTech,项目名称:kamailio,代码行数:98,代码来源:cxdx_callbacks.c

示例14: get_first_child

/* UPDATED + CHECKED
 */
static inline char *run_lookup( struct cpl_interpreter *intr )
{
	unsigned short attr_name;
	unsigned short n;
	unsigned char  clear;
	char *p;
	char *kid;
	char *failure_kid = 0;
	char *success_kid = 0;
	char *notfound_kid = 0;
	int  i;
	time_t      tc;
	urecord_t*  r;
	ucontact_t* contact;

	clear = NO_VAL;

	/* check the params */
	for( i=NR_OF_ATTR(intr->ip),p=ATTR_PTR(intr->ip) ; i>0 ; i-- ) {
		get_basic_attr(p,attr_name,n,intr,script_error);
		switch (attr_name) {
			case CLEAR_ATTR:
				if (n!=YES_VAL && n!=NO_VAL)
					LOG(L_WARN,"WARNING:run_lookup: invalid value (%u) found"
						" for param. CLEAR in LOOKUP node -> using "
						"default (%u)!\n",n,clear);
				else
					clear = n;
				break;
			default:
				LOG(L_ERR,"ERROR:run_lookup: unknown attribute (%d) in "
					"LOOKUP node\n",attr_name);
				goto script_error;
		}
	}

	/* check the kids */
	for( i=0 ; i<NR_OF_KIDS(intr->ip) ; i++ ) {
		kid = intr->ip + KID_OFFSET(intr->ip,i);
		check_overflow_by_ptr( kid+SIMPLE_NODE_SIZE(kid), intr, script_error);
		switch ( NODE_TYPE(kid) ) {
			case SUCCESS_NODE :
				success_kid = kid;
				break;
			case NOTFOUND_NODE:
				notfound_kid = kid;
				break;
			case FAILURE_NODE:
				failure_kid = kid;
				break;
			default:
				LOG(L_ERR,"ERROR:run_lookup: unknown output node type"
					" (%d) for LOOKUP node\n",NODE_TYPE(kid));
				goto script_error;
		}
	}

	kid = failure_kid;

	if (cpl_domain) {
		/* fetch user's contacts via usrloc */
		tc = time(0);
		cpl_ulb.lock_udomain( cpl_domain );
		i = cpl_ulb.get_urecord( cpl_domain, &intr->user, &r);
		if (i < 0) {
			/* failure */
			LOG(L_ERR, "ERROR:run_lookup: Error while querying usrloc\n");
			cpl_ulb.unlock_udomain( cpl_domain );
		} else if (i > 0) {
			/* not found */
			DBG("DBG:cpl-c:run_lookup: '%.*s' Not found in usrloc\n",
				intr->user.len, intr->user.s);
			cpl_ulb.unlock_udomain( cpl_domain );
			kid = notfound_kid;
		} else {
			contact = r->contacts;
			/* skip expired contacts */
			while ((contact) && ((contact->expires <= tc) ||
			(contact->state >= CS_ZOMBIE_N)))
				contact = contact->next;
			/* any contacts left? */
			if (contact) {
				/* clear loc set if requested */
				if (clear)
					empty_location_set( &(intr->loc_set) );
				/* add first location to set */
				DBG("DBG:cpl-c:run_lookup: adding <%.*s>q=%d\n",
					contact->c.len,contact->c.s,(int)(10*contact->q));
				if (add_location( &(intr->loc_set), &contact->c,
				(int)(10*contact->q),
				CPL_LOC_DUPL|((contact->flags & FL_NAT)*CPL_LOC_NATED) )==-1) {
					LOG(L_ERR,"ERROR:cpl-c:run_lookup: unable to add "
						"location to set :-(\n");
					cpl_ulb.unlock_udomain( cpl_domain );
					goto runtime_error;
				}
				/* set the flag for modifing the location set */
				intr->flags |= CPL_LOC_SET_MODIFIED;
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

示例15: save_pending


//.........这里部分代码省略.........
	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");
			ul.register_ulcb(pcontact, PCSCF_CONTACT_DELETE | PCSCF_CONTACT_EXPIRE | PCSCF_CONTACT_UPDATE, callback_pcscf_contact_cb, NULL);
		}
	} else { //contact already exists - update
		LM_DBG("Contact already exists - not doing anything for now\n");
	}
	ul.unlock_udomain(_d, &ci.via_host, ci.via_port, ci.via_prot);

	return 1;

error:
	LM_DBG("Error saving pending contact\n");
	return -1;
}
开发者ID:albertollamaso,项目名称:kamailio,代码行数:101,代码来源:save.c


注:本文中的usrloc_api_t::unlock_udomain方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。