Ejemplo n.º 1
0
void ast_sip_location_retrieve_contact_and_aor_from_list(const char *aor_list, struct ast_sip_aor **aor,
	struct ast_sip_contact **contact)
{
	char *aor_name;
	char *rest;

	/* If the location is still empty we have nowhere to go */
	if (ast_strlen_zero(aor_list) || !(rest = ast_strdupa(aor_list))) {
		ast_log(LOG_WARNING, "Unable to determine contacts from empty aor list\n");
		return;
	}

	*aor = NULL;
	*contact = NULL;

	while ((aor_name = ast_strip(strsep(&rest, ",")))) {
		*aor = ast_sip_location_retrieve_aor(aor_name);

		if (!(*aor)) {
			continue;
		}
		*contact = ast_sip_location_retrieve_first_aor_contact(*aor);
		/* If a valid contact is available use its URI for dialing */
		if (*contact) {
			break;
		}

		ao2_ref(*aor, -1);
		*aor = NULL;
	}
}
Ejemplo n.º 2
0
/*!
 * \internal
 * \brief Retrieves an endpoint if specified in the given 'to'
 *
 * Expects the given 'to' to be in one of the following formats:
 *      sip[s]:endpoint[/aor]
 *      sip[s]:endpoint[/uri]
 *      sip[s]:uri <-- will use default outbound endpoint
 *
 * If an optional aor is given it will try to find an associated uri
 * to return.  If an optional uri is given then that will be returned,
 * otherwise uri will be NULL.
 *
 * \param to 'From' or 'To' field with possible endpoint
 * \param uri Optional uri to return
 */
static struct ast_sip_endpoint* get_outbound_endpoint(
	const char *to, char **uri)
{
	char *name, *aor_uri;
	struct ast_sip_endpoint* endpoint;
	RAII_VAR(struct ast_sip_aor *, aor, NULL, ao2_cleanup);
	RAII_VAR(struct ast_sip_contact *, contact, NULL, ao2_cleanup);

	name = ast_strdupa(skip_sip(to));

	/* attempt to extract the endpoint name */
	if ((aor_uri = strchr(name, '/'))) {
		/* format was 'endpoint/' */
		*aor_uri++ = '\0';
	} else if ((aor_uri = strchr(name, '@'))) {
		/* format was 'endpoint@' - don't use the rest */
		*aor_uri = '\0';
	}

	/* at this point, if name is not empty then it
	   might be an endpoint, so try to retrieve it */
	if (ast_strlen_zero(name) || !(endpoint = ast_sorcery_retrieve_by_id(
		      ast_sip_get_sorcery(), "endpoint", name))) {
		/* an endpoint was not found, so assume sending directly
		   to a uri and use the default outbound endpoint */
		*uri = ast_strdup(to);
		return ast_sip_default_outbound_endpoint();
	}

	*uri = aor_uri;
	if (*uri) {
		char *end = strchr(*uri, '>');
		if (end) {
			*end++ = '\0';
		}

		/* if what's in 'uri' is a retrievable aor use the uri on it
		   instead, otherwise assume what's there is already a uri*/
		if ((aor = ast_sip_location_retrieve_aor(*uri)) &&
			(contact = ast_sip_location_retrieve_first_aor_contact(aor))) {
			*uri = (char*)contact->uri;
		}
		/* need to copy because underlying uri goes away */
		*uri = ast_strdup(*uri);
	}

	return endpoint;
}