static struct msg_data* msg_data_create(const struct ast_msg *msg, const char *to, const char *from) { char *tag; struct msg_data *mdata = ao2_alloc(sizeof(*mdata), msg_data_destroy); if (!mdata) { return NULL; } /* typecast to suppress const warning */ mdata->msg = ast_msg_ref((struct ast_msg*)msg); /* starts with 'pjsip:' the 'pj' needs to be removed and maybe even the entire string. */ if (!(to = strchr(to, ':'))) { ao2_ref(mdata, -1); return NULL; } /* if there is another sip in the uri then we are good, otherwise it needs a sip: in front */ mdata->to = to == skip_sip(to) ? ast_strdup(to - 3) : ast_strdup(++to); mdata->from = ast_strdup(from); /* sometimes from can still contain the tag at this point, so remove it */ if ((tag = strchr(mdata->from, ';'))) { *tag = '\0'; } return mdata; }
/*! * \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; }