Esempio n. 1
0
xmlNodePtr search_service_uri(xmlDocPtr doc, str* service_uri)
{
	xmlNodePtr rl_node, node;
	struct sip_uri sip_uri;
	str uri, uri_str;
	str *normalized_uri;

	rl_node= XMLDocGetNodeByName(doc, "rls-services", NULL);
	if(rl_node== NULL)
	{
		LM_ERR("while extracting rls-services node\n");
		return NULL;
	}
	for(node= rl_node->children; node; node= node->next)
	{
		if(xmlStrcasecmp(node->name,(unsigned char*)"service")== 0)
		{
			uri.s = XMLNodeGetAttrContentByName(node, "uri");
			if (uri.s == NULL)
			{
			        LM_DBG("failed to fetch 'uri' in service [invalid XML from XCAP]\n");
			        continue;
			}
			uri.len = strlen(uri.s);

			normalized_uri = normalizeSipUri(&uri);
			if (normalized_uri->s == NULL || normalized_uri->len == 0)
			{
				LM_ERR("failed to normalize service URI\n");
				xmlFree(uri.s);
				return NULL;
			}
			xmlFree(uri.s);

			if(parse_uri(normalized_uri->s, normalized_uri->len, &sip_uri)< 0)
			{
				LM_ERR("failed to parse uri\n");
				return NULL;
			}
			if(uandd_to_uri(sip_uri.user, sip_uri.host, &uri_str)< 0)
			{
				LM_ERR("failed to construct uri from user and domain\n");
				return NULL;
			}
			if(uri_str.len== service_uri->len && 
					strncmp(uri_str.s, service_uri->s, uri_str.len) == 0)
			{
				pkg_free(uri_str.s);
				return node;
			}
			LM_DBG("match not found, service-uri = [%.*s]\n", uri_str.len, uri_str.s);
			pkg_free(uri_str.s);
		}
	}
	return NULL;
}
Esempio n. 2
0
static inline int oma_match_external_list_condition(xmlNodePtr condition, subs_t *subs, str *w_uri)
{
        int found = 0;
        str anchor, uri;
        str *normalized_uri;
	struct sip_uri sip_uri;
        xcap_uri_t anchor_uri;
        xmlNodePtr entry_node = NULL;
        xmlNodePtr rl_node = NULL, rl_entry = NULL;
        xmlDocPtr rl_doc = NULL;

        if(!integrated_xcap_server)
        {
	        LM_ERR("<external-list> is not supported in non integrated mode\n");
	        return 0;
        }

        if(parse_uri(subs->pres_uri.s, subs->pres_uri.len, &sip_uri) < 0)
        {
                LM_ERR("failed to parse uri\n");
                return 0;
        }

	for(entry_node = condition->children; entry_node; entry_node = entry_node->next)
	{
		if(xmlStrcasecmp(entry_node->name, (unsigned char*)"entry") != 0)
		        continue;

		rl_node = NULL;
		rl_doc = NULL;
		anchor.s = NULL;
		uri.s = NULL;

                anchor.s = xmlNodeGetAttrContentByName(entry_node, "anc");
                if(anchor.s == NULL)
                {
                        LM_ERR("cannot get external-list entry anchor\n");
                        continue;
                }
                anchor.len = strlen(anchor.s);
		if(xcapParseUri(&anchor, &anchor_uri) != 0)
                {
		        LM_ERR("unable to parse URI for external-list entry anchor\n");
			xmlFree(anchor.s);
			continue;
                }
		xmlFree(anchor.s);
                /* TODO: validate XUI? */
		if(get_resource_list(&sip_uri.user, &sip_uri.host, &anchor_uri.filename, &anchor_uri.selector, &rl_node, &rl_doc) < 0)
                {
		        LM_ERR("error getting resource-list list pointed by external list anchor\n");
			continue;
                }
                for(rl_entry = rl_node->children; rl_entry; rl_entry = rl_entry->next)
                {
                        if(xmlStrcasecmp(rl_entry->name, (unsigned char*)"entry") != 0)
                                continue;
			uri.s = xmlNodeGetAttrContentByName(rl_entry, "uri");
			if(uri.s == NULL)
			{
				LM_ERR("when extracting entry uri attribute\n");
				continue;
			}
                        uri.len = strlen(uri.s);

                        normalized_uri = normalizeSipUri(&uri);
                        if (normalized_uri->s == NULL || normalized_uri->len == 0)
                        {
                                LM_ERR("normalizing URI\n");
                                xmlFree(uri.s);
                                continue;
                        }
                        xmlFree(uri.s);

                        if (normalized_uri->len == w_uri->len && strncmp(normalized_uri->s, w_uri->s, w_uri->len) == 0)
                        {
                                found = 1;
                                break;
                        }
                }
		xmlFreeDoc(rl_doc);
                if (found)
                        break;
	}

	return found;

}
Esempio n. 3
0
static inline int oma_match_identity_condition(xmlNodePtr condition, subs_t *subs, str *w_uri)
{
        int r = 0, many_match = 0;
        char *domain = NULL;
        str uri;
        str *normalized_uri;
        xmlNodePtr node = NULL, except_node = NULL;

        for(node = condition->children; node; node = node->next)
        {
                if(xmlStrcasecmp(node->name, (unsigned char*)"one") == 0)
                {
			uri.s = xmlNodeGetAttrContentByName(node, "id");
			if(uri.s == NULL)
			{
				LM_ERR("when extracting entry attribute\n");
				continue;
			}
                        uri.len = strlen(uri.s);

                        normalized_uri = normalizeSipUri(&uri);
                        if (normalized_uri->s == NULL || normalized_uri->len == 0)
                        {
                                LM_ERR("normalizing URI\n");
                                xmlFree(uri.s);
                                continue;
                        }
                        xmlFree(uri.s);

                        if (normalized_uri->len == w_uri->len && strncmp(normalized_uri->s, w_uri->s, w_uri->len) == 0)
                        {
                                r = 1;
                                break;
                        }
                }
                else if(xmlStrcasecmp(node->name, (unsigned char*)"many") == 0)
                {
                        domain = xmlNodeGetAttrContentByName(node, "domain");
                        if(domain == NULL)
                        {
                                LM_DBG("No domain attribute in identity many\n");
                        }
                        else
                        {
                                LM_DBG("<many domain= %s>\n", domain);
                                if(!(strlen(domain) == subs->from_domain.len &&
                                    strncmp(domain, subs->from_domain.s, subs->from_domain.len) == 0))
                                {
                                        xmlFree(domain);
                                        continue;
                                }
                                xmlFree(domain);
                        }

                        many_match = 1;
                        for(except_node = node->children; except_node; except_node= except_node->next)
                        {
                                if(xmlStrcasecmp(except_node->name, (unsigned char*)"except"))
                                        continue;

                                uri.s = xmlNodeGetAttrContentByName(except_node, "id");
                                if(uri.s != NULL)
                                {
                                    uri.len = strlen(uri.s);
                                    normalized_uri = normalizeSipUri(&uri);
                                    if (normalized_uri->s == NULL || normalized_uri->len == 0)
                                    {
                                            LM_ERR("normalizing URI\n");
                                            xmlFree(uri.s);
                                            continue;
                                    }
                                    xmlFree(uri.s);

                                    if (normalized_uri->len == w_uri->len && strncmp(normalized_uri->s, w_uri->s, w_uri->len) == 0)
                                    {
                                            many_match = 0;
                                            break;
                                    }
                                }
                                else
                                {
                                        domain = NULL;
                                        domain = xmlNodeGetAttrContentByName(except_node, "domain");
                                        if(domain != NULL)
                                        {
                                                LM_DBG("Found except domain= %s\n- strlen(domain)= %d\n", domain, (int)strlen(domain));
                                                if(strlen(domain)==subs->from_domain.len &&
                                                    (strncmp(domain,subs->from_domain.s , subs->from_domain.len)==0))
                                                {
                                                        LM_DBG("except domain match\n");
                                                        xmlFree(domain);
                                                        many_match = 0;
                                                        break;
                                                }
                                                xmlFree(domain);
                                        }

                                }
                        }

                        if(many_match)
                        {
                                r = 1;
                                break;
                        }
                }

        }

        return r;

}