int sip_rewrite_to(osip_message_t* osip_msg, char* host, char* username) { osip_to_t* from = osip_message_get_to(osip_msg); if (NULL != from) { osip_uri_t* uri = osip_to_get_url(from); if (NULL != uri) { sip_rewrite_osip_uri(uri, host, username); return RC_OK; } } return RC_ERR; }
/* code (entry point) */ static int plugin_regex_process(sip_ticket_t *ticket) { int sts=STS_SUCCESS; osip_uri_t *req_url; osip_uri_t *to_url; osip_generic_param_t *r=NULL; /* plugin loaded and not configured, return with success */ if (plugin_cfg.regex_pattern.used==0) return STS_SUCCESS; if (plugin_cfg.regex_replace.used==0) return STS_SUCCESS; DEBUGC(DBCLASS_PLUGIN,"plugin entered"); req_url=osip_message_get_uri(ticket->sipmsg); to_url=osip_to_get_url(ticket->sipmsg); /* only outgoing direction is handled */ sip_find_direction(ticket, NULL); if (ticket->direction != DIR_OUTGOING) return STS_SUCCESS; /* only INVITE and ACK are handled */ if (!MSG_IS_INVITE(ticket->sipmsg) && !MSG_IS_ACK(ticket->sipmsg)) return STS_SUCCESS; /* expire old cache entries */ expire_redirected_cache(&redirected_cache); /* REQ URI with username must exist, prefix string must exist */ if (!req_url || !req_url->username) return STS_SUCCESS; /* ignore */ /* Loop avoidance: * If this INVITE has already been redirected by a prior 302 * moved response a "REDIRECTED_TAG" parameter should be present in the * URI. * Hopefully all UAs (Clients) do honor RFC3261 and copy the * *full* URI form the contact header into the new request header * upon a 3xx response. */ if (req_url) { osip_uri_param_get_byname(&(req_url->url_params), REDIRECTED_TAG, &r); if (r && r->gvalue && strcmp(r->gvalue,REDIRECTED_VAL)== 0) { DEBUGC(DBCLASS_PLUGIN,"Packet has already been processed (ReqURI)"); return STS_SUCCESS; } } if (to_url) { osip_uri_param_get_byname(&(to_url->url_params), REDIRECTED_TAG, &r); if (r && r->gvalue && strcmp(r->gvalue,REDIRECTED_VAL)== 0) { DEBUGC(DBCLASS_PLUGIN,"Packet has already been processed (ToURI)"); return STS_SUCCESS; } } /* * The SIP message is to be processed */ /* outgoing INVITE request */ if (MSG_IS_INVITE(ticket->sipmsg)) { DEBUGC(DBCLASS_PLUGIN,"processing INVITE"); sts=plugin_regex_redirect(ticket); } /* outgoing ACK request: is result of a local 3xx answer (moved...) * * Only consume that particular ACK that belongs to a sent 302 answer, * nothing else. Otherwise the ACK from the redirected call will get * consumed as well and causes the call to be aborted (timeout). * We keep a cache with Call-Ids of such "302 moved" dialogs. * Only consume such ACKs that are part of such a dialog. */ else if (MSG_IS_ACK(ticket->sipmsg)) { if (is_in_redirected_cache(&redirected_cache, ticket) == STS_TRUE) { DEBUGC(DBCLASS_PLUGIN,"processing ACK (consume it)"); sts=STS_SIP_SENT; /* eat up the ACK that was directed to myself */ } } return sts; }