int
osip_dialog_update_route_set_as_uas (osip_dialog_t * dialog, osip_message_t * invite)
{
  osip_contact_t *contact;
  int i;

  if (dialog == NULL)
    return OSIP_BADPARAMETER;
  if (invite == NULL)
    return OSIP_BADPARAMETER;

  if (osip_list_eol (&invite->contacts, 0)) {
    OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_WARNING, NULL, "missing a contact in invite!\n"));
  }
  else {
    if (dialog->remote_contact_uri != NULL) {
      osip_contact_free (dialog->remote_contact_uri);
    }
    dialog->remote_contact_uri = NULL;
    contact = osip_list_get (&invite->contacts, 0);
    i = osip_contact_clone (contact, &(dialog->remote_contact_uri));
    if (i != 0)
      return i;
  }
  return OSIP_SUCCESS;
}
Пример #2
0
static int
_eXosip_call_reuse_contact (osip_message_t * invite, osip_message_t * msg)
{
  osip_contact_t *co_invite = NULL;
  osip_contact_t *co_msg = NULL;
  int i;
  i = osip_message_get_contact (invite, 0, &co_invite);
  if (i < 0 || co_invite == NULL || co_invite->url == NULL)
    {
      return i;
    }

  i = osip_message_get_contact (msg, 0, &co_msg);
  if (i >= 0 && co_msg != NULL)
    {
      osip_list_remove (&msg->contacts, 0);
      osip_contact_free (co_msg);
    }

  co_msg = NULL;
  i = osip_contact_clone (co_invite, &co_msg);
  if (i >= 0 && co_msg != NULL)
    {
      osip_list_add (&msg->contacts, co_msg, 0);
      return OSIP_SUCCESS;
    }
  return i;
}
Пример #3
0
int
osip_dialog_update_route_set_as_uac (osip_dialog_t * dialog,
                                     osip_message_t * response)
{
  /* only the remote target URI is updated here... */
  osip_contact_t *contact;
  int i;

  if (dialog == NULL)
    return -1;
  if (response == NULL)
    return -1;

  if (osip_list_eol (&response->contacts, 0))
    {                           /* no contact header in response? */
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_WARNING, NULL,
                   "missing a contact in response!\n"));
  } else
    {
      /* I personally think it's a bad idea to keep the old
         value in case the new one is broken... */
      if (dialog->remote_contact_uri != NULL)
        {
          osip_contact_free (dialog->remote_contact_uri);
        }
      dialog->remote_contact_uri = NULL;
      contact = osip_list_get (&response->contacts, 0);
      i = osip_contact_clone (contact, &(dialog->remote_contact_uri));
      if (i != 0)
        return -1;
    }

  if (dialog->state == DIALOG_EARLY && osip_list_size (&dialog->route_set) == 0)
    {                           /* update the route set */
      int pos = 0;

      while (!osip_list_eol (&response->record_routes, pos))
        {
          osip_record_route_t *rr;
          osip_record_route_t *rr2;

          rr =
            (osip_record_route_t *) osip_list_get (&response->record_routes, pos);
          i = osip_record_route_clone (rr, &rr2);
          if (i != 0)
            return -1;
          osip_list_add (&dialog->route_set, rr2, 0);
          pos++;
        }
    }

  if (MSG_IS_STATUS_2XX (response))
    dialog->state = DIALOG_CONFIRMED;
  return 0;
}
void
osip_dialog_free (osip_dialog_t * dialog)
{
  if (dialog == NULL)
    return;
  osip_contact_free (dialog->remote_contact_uri);
  osip_from_free (dialog->local_uri);
  osip_to_free (dialog->remote_uri);
  osip_list_special_free (&dialog->route_set, (void (*)(void *)) &osip_record_route_free);
  osip_free (dialog->line_param);
  osip_free (dialog->remote_tag);
  osip_free (dialog->local_tag);
  osip_free (dialog->call_id);
  osip_free (dialog);
}
Пример #5
0
/* returns -1 on error. */
int osip_message_set_contact(osip_message_t * sip, const char *hvalue)
{
	int i;
	osip_contact_t *contact;

	if (hvalue == NULL || hvalue[0] == '\0')
		return OSIP_SUCCESS;

	i = osip_contact_init(&contact);
	if (i != 0)
		return i;
	i = osip_contact_parse(contact, hvalue);
	if (i != 0) {
		osip_contact_free(contact);
		return i;
	}
	sip->message_property = 2;
	osip_list_add(&sip->contacts, contact, -1);
	return OSIP_SUCCESS;		/* ok */
}
Пример #6
0
/*
 * SIP_REWRITE_CONTACT
 *
 * rewrite the Contact header
 *
 * RETURNS
 *	STS_SUCCESS on success
 *	STS_FAILURE on error
 */
int sip_rewrite_contact (sip_ticket_t *ticket, int direction,
			 struct in_addr *local_ip) {
   osip_message_t *sip_msg=ticket->sipmsg;
   osip_contact_t *contact;
   int i;

#if UNREG_WITHOUT_REG_HG522
   char tmpUserName[128] = {0};
   char tmpPort[6] = {0};
#endif
   if (sip_msg == NULL) return STS_FAILURE;

   osip_message_get_contact(sip_msg, 0, &contact);
   if (contact == NULL)
   {
       printsip("sip: rewrite_contact contact is NULL \r\n");
       return STS_FAILURE;
   }

   for (i=0;i<URLMAP_SIZE;i++){
      if (urlmap[i].active == 0) continue;
      if ((direction == DIR_OUTGOING) &&
          (compare_url(contact->url, urlmap[i].true_url)==STS_SUCCESS)) break;
      if ((direction == DIR_INCOMING) &&
          (compare_url(contact->url, urlmap[i].masq_url)==STS_SUCCESS)) break;
#if UNREG_WITHOUT_REG_HG522
      if ((direction == DIR_OUTGOING) && (NULL != contact->url) && (NULL != urlmap[i].true_url)
          && (NULL != contact->url->host) && (NULL != urlmap[i].true_url->host)
          && (strcmp(contact->url->host, urlmap[i].true_url->host) == 0))
      {
          strcpy(tmpUserName, contact->url->username);
          if (NULL != contact->url->port)
          {
              strncpy(tmpPort, contact->url->port, 6);
          }
          break;
      }
#endif
   }

   /* found a mapping entry */
   if (i<URLMAP_SIZE) {
      char *tmp;
      if (NULL != contact->url)
      {
          printsip("************* sip: rewrote Contact header %s@%s:%s -> %s@%s:%s \r\n",
                 (contact->url->username)? contact->url->username : "******",
                 (contact->url->host)? contact->url->host : "*NULL*",
                 (contact->url->port)? contact->url->port : "NULL port",
                 urlmap[i].masq_url->username, urlmap[i].masq_url->host,
                 (urlmap[i].masq_url->port)? urlmap[i].masq_url->port : "NULL port");
      }

      /* remove old entry */
      osip_list_remove(sip_msg->contacts,0);
      osip_contact_to_str(contact, &tmp);
      osip_contact_free(contact);

      /* clone the url from urlmap */
      osip_contact_init(&contact);
      osip_contact_parse(contact,tmp);
      osip_free(tmp);
      osip_uri_free(contact->url);
      if (direction == DIR_OUTGOING) {
         /* outgoing, use masqueraded url */
         osip_uri_clone(urlmap[i].masq_url, &contact->url);
	     if (local_ip != NULL) {
            char *ip = malloc(20);
            strncpy(ip, inet_ntoa(*local_ip), 20);
            free(contact->url->host);
            contact->url->host = ip;
         }

#if UNREG_WITHOUT_REG_HG522
         if ('\0' != tmpUserName[0])
         {
             char *username = malloc(strlen(tmpUserName)+1);
             strncpy(username, tmpUserName, strlen(tmpUserName)+1);
             free(contact->url->username);
             contact->url->username = username;
         }
         if ((NULL == urlmap[i].masq_url->port) && ('\0' != tmpPort[0]))
         {
             char *port = malloc(strlen(tmpPort)+1);
             strncpy(port, tmpPort, strlen(tmpPort)+1);
             contact->url->port = port;
         }
#endif
      } else {
         /* incoming, use true url */
         osip_uri_clone(urlmap[i].true_url, &contact->url);
         printsip("incoming: osip_uri_clone from %s \r\n",
         urlmap[i].true_url->host);
      }

      osip_list_add(sip_msg->contacts,contact,-1);
   } else {
      return STS_FAILURE;
   } 

   return STS_SUCCESS;
}
Пример #7
0
/* private plugin code */
static int plugin_regex_redirect(sip_ticket_t *ticket) {
   osip_uri_t *to_url=ticket->sipmsg->to->url;
   char *url_string=NULL;
   osip_uri_t *new_to_url;
   int  i, sts;
   osip_contact_t *contact = NULL;
   /* character workspaces for regex */
   #define WORKSPACE_SIZE 128
   static char in[WORKSPACE_SIZE+1], rp[WORKSPACE_SIZE+1];

   /* do apply to full To URI... */
   sts = osip_uri_to_str(to_url, &url_string);
   if (sts != 0) {
      ERROR("osip_uri_to_str() failed");
      return STS_FAILURE;
   }
   DEBUGC(DBCLASS_BABBLE, "To URI string: [%s]", url_string);

   /* perform search and replace of the regexes, first match hits */
   for (i = 0; i < plugin_cfg.regex_pattern.used; i++) {
      regmatch_t *pmatch = NULL;
      pmatch = rmatch(url_string, WORKSPACE_SIZE, &re[i]);
      if (pmatch == NULL) continue; /* no match, next */

      /* have a match, do the replacement */
      INFO("Matched rexec rule: %s",plugin_cfg.regex_desc.string[i] );
      strncpy (in, url_string, WORKSPACE_SIZE);
      in[WORKSPACE_SIZE]='\0';
      strncpy (rp, plugin_cfg.regex_replace.string[i], WORKSPACE_SIZE);
      rp[WORKSPACE_SIZE]='\0';

      sts = rreplace(in, WORKSPACE_SIZE, &re[i], pmatch, rp);
      if (sts != STS_SUCCESS) {
         ERROR("regex replace failed: pattern:[%s] replace:[%s]",
               plugin_cfg.regex_pattern.string[i],
               plugin_cfg.regex_replace.string[i]);
         osip_free(url_string);
         return STS_FAILURE;
      }
      /* only do first match */
      break;
   }
   if (i >= plugin_cfg.regex_pattern.used) {
      /* no match */
      osip_free(url_string);
      return STS_SUCCESS;
   }
   /* in: contains the new string */

   sts = osip_uri_init(&new_to_url);
   if (sts != 0) {
      ERROR("Unable to initialize URI");
      osip_free(url_string);
      return STS_FAILURE;
   }

   sts = osip_uri_parse(new_to_url, in);
   if (sts != 0) {
      ERROR("Unable to parse To URI: %s", in);
      osip_uri_free(new_to_url);
      osip_free(url_string);
      return STS_FAILURE;
   }

   /* use a "302 Moved temporarily" response back to the client */
   /* new target is within the Contact Header */

   /* remove all Contact headers in message */
   for (i=0; (contact != NULL) || (i == 0); i++) {
      osip_message_get_contact(ticket->sipmsg, 0, &contact);
      if (contact) {
         osip_list_remove(&(ticket->sipmsg->contacts),0);
         osip_contact_free(contact);
      }
   } /* for i */

   /* insert one new Contact header containing the new target address */
   osip_contact_init(&contact);
   osip_list_add(&(ticket->sipmsg->contacts),contact,0);
   
   /* link the new_to_url into the Contact list */
   contact->url = new_to_url;
   new_to_url = NULL;

   /*
    * Add the 'REDIRECTED_TAG=REDIRECTED_VAL' parameter to URI. Required to figure out
    * if this INVITE has already been processed (redirected) and
    * does not need further attention by this plugin.
    * THIS IS REQUIRED TO AVOID A LOOP
    */
   osip_uri_param_add(&(contact->url->url_params), osip_strdup(REDIRECTED_TAG), 
                      osip_strdup(REDIRECTED_VAL));

   INFO("redirecting %s -> %s", url_string, in);

   /* sent redirect message back to local client */
   add_to_redirected_cache(&redirected_cache, ticket);
   sip_gen_response(ticket, 302 /*Moved temporarily*/);

   /* release resources and return */
   osip_free(url_string);
   return STS_SIP_SENT;
}
Пример #8
0
/*
 * SIP_REWRITE_CONTACT
 *
 * rewrite the Contact header
 *
 * RETURNS
 *	STS_SUCCESS on success
 *	STS_FAILURE on error
 */
int sip_rewrite_contact (sip_ticket_t *ticket, int direction) {
   osip_message_t *sip_msg=ticket->sipmsg;
   osip_contact_t *contact;
   int i, j;
   int replaced=0;

   if (sip_msg == NULL) return STS_FAILURE;

   /* at least one contact header present? */
   osip_message_get_contact(sip_msg, 0, &contact);
   if (contact == NULL) return STS_FAILURE;

   /* loop for all existing contact headers in message */
   for (j=0; contact != NULL; j++) {
      osip_message_get_contact(sip_msg, j, &contact);
      if (contact == NULL) break;
      if (contact->url == NULL) continue;

      /* search for an entry */
      for (i=0;i<URLMAP_SIZE;i++){
         if (urlmap[i].active == 0) continue;
         if ((direction == DIR_OUTGOING) &&
             (compare_url(contact->url, urlmap[i].true_url)==STS_SUCCESS)) break;
         if ((direction == DIR_INCOMING) &&
             (compare_url(contact->url, urlmap[i].masq_url)==STS_SUCCESS)) break;
      }

      /* found a mapping entry */
      if (i<URLMAP_SIZE) {
         char *tmp;

         if (direction == DIR_OUTGOING) {
            DEBUGC(DBCLASS_PROXY, "rewriting Contact header %s@%s -> %s@%s",
                   (contact->url->username)? contact->url->username : "******",
                   (contact->url->host)? contact->url->host : "*NULL*",
                   urlmap[i].masq_url->username, urlmap[i].masq_url->host);
         } else {
            DEBUGC(DBCLASS_PROXY, "rewriting Contact header %s@%s -> %s@%s",
                   (contact->url->username)? contact->url->username : "******",
                   (contact->url->host)? contact->url->host : "*NULL*",
                   urlmap[i].true_url->username, urlmap[i].true_url->host);
         }

         /* remove old entry */
         osip_list_remove(sip_msg->contacts,j);
         osip_contact_to_str(contact, &tmp);
         osip_contact_free(contact);

         /* clone the url from urlmap*/
         osip_contact_init(&contact);
         osip_contact_parse(contact,tmp);
         osip_free(tmp);
         osip_uri_free(contact->url);
         if (direction == DIR_OUTGOING) {
            /* outgoing, use masqueraded url */
            osip_uri_clone(urlmap[i].masq_url, &contact->url);
         } else {
            /* incoming, use true url */
            osip_uri_clone(urlmap[i].true_url, &contact->url);
         }

         osip_list_add(sip_msg->contacts,contact,j);
         replaced=1;
      }

   }

   if (replaced == 0) {
      DEBUGC(DBCLASS_PROXY, "no Contact header rewritten");
      return STS_FAILURE;
   }

   return STS_SUCCESS;
}
Пример #9
0
void
osip_message_free (osip_message_t * sip)
{
    int pos = 0;

    if (sip == NULL)
        return;

    osip_free (sip->sip_method);
    osip_free (sip->sip_version);
    if (sip->req_uri != NULL)
    {
        osip_uri_free (sip->req_uri);
    }
    osip_free (sip->reason_phrase);

    {
        osip_accept_t *accept;

        while (!osip_list_eol (&sip->accepts, pos))
        {
            accept = (osip_accept_t *) osip_list_get (&sip->accepts, pos);
            osip_list_remove (&sip->accepts, pos);
            osip_accept_free (accept);
        }
    }
    {
        osip_accept_encoding_t *accept_encoding;

        while (!osip_list_eol (&sip->accept_encodings, pos))
        {
            accept_encoding =
                (osip_accept_encoding_t *) osip_list_get (&sip->accept_encodings, pos);
            osip_list_remove (&sip->accept_encodings, pos);
            osip_accept_encoding_free (accept_encoding);
        }
    }
    {
        osip_accept_language_t *accept_language;

        while (!osip_list_eol (&sip->accept_languages, pos))
        {
            accept_language =
                (osip_accept_language_t *) osip_list_get (&sip->accept_languages, pos);
            osip_list_remove (&sip->accept_languages, pos);
            osip_accept_language_free (accept_language);
        }
    }
    {
        osip_alert_info_t *alert_info;

        while (!osip_list_eol (&sip->alert_infos, pos))
        {
            alert_info = (osip_alert_info_t *) osip_list_get (&sip->alert_infos, pos);
            osip_list_remove (&sip->alert_infos, pos);
            osip_alert_info_free (alert_info);
        }
    }
    {
        osip_allow_t *al;

        while (!osip_list_eol (&sip->allows, pos))
        {
            al = (osip_allow_t *) osip_list_get (&sip->allows, pos);
            osip_list_remove (&sip->allows, pos);
            osip_allow_free (al);
        }
    }
    {
        osip_authentication_info_t *al;

        while (!osip_list_eol (&sip->authentication_infos, pos))
        {
            al =
                (osip_authentication_info_t *) osip_list_get (&sip->
                        authentication_infos, pos);
            osip_list_remove (&sip->authentication_infos, pos);
            osip_authentication_info_free (al);
        }
    }
    {
        osip_authorization_t *al;

        while (!osip_list_eol (&sip->authorizations, pos))
        {
            al = (osip_authorization_t *) osip_list_get (&sip->authorizations, pos);
            osip_list_remove (&sip->authorizations, pos);
            osip_authorization_free (al);
        }
    }
    if (sip->call_id != NULL)
    {
        osip_call_id_free (sip->call_id);
    }
    {
        osip_call_info_t *call_info;

        while (!osip_list_eol (&sip->call_infos, pos))
        {
            call_info = (osip_call_info_t *) osip_list_get (&sip->call_infos, pos);
            osip_list_remove (&sip->call_infos, pos);
            osip_call_info_free (call_info);
        }
    }
    {
        osip_contact_t *contact;

        while (!osip_list_eol (&sip->contacts, pos))
        {
            contact = (osip_contact_t *) osip_list_get (&sip->contacts, pos);
            osip_list_remove (&sip->contacts, pos);
            osip_contact_free (contact);
        }
    }
    {
        osip_content_encoding_t *ce;

        while (!osip_list_eol (&sip->content_encodings, pos))
        {
            ce =
                (osip_content_encoding_t *) osip_list_get (&sip->content_encodings, pos);
            osip_list_remove (&sip->content_encodings, pos);
            osip_content_encoding_free (ce);
        }
    }
    if (sip->content_length != NULL)
    {
        osip_content_length_free (sip->content_length);
    }
    if (sip->content_type != NULL)
    {
        osip_content_type_free (sip->content_type);
    }
    if (sip->cseq != NULL)
    {
        osip_cseq_free (sip->cseq);
    }
    {
        osip_error_info_t *error_info;

        while (!osip_list_eol (&sip->error_infos, pos))
        {
            error_info = (osip_error_info_t *) osip_list_get (&sip->error_infos, pos);
            osip_list_remove (&sip->error_infos, pos);
            osip_error_info_free (error_info);
        }
    }
    if (sip->from != NULL)
    {
        osip_from_free (sip->from);
    }
    if (sip->mime_version != NULL)
    {
        osip_mime_version_free (sip->mime_version);
    }
    {
        osip_proxy_authenticate_t *al;

        while (!osip_list_eol (&sip->proxy_authenticates, pos))
        {
            al =
                (osip_proxy_authenticate_t *) osip_list_get (&sip->
                        proxy_authenticates, pos);
            osip_list_remove (&sip->proxy_authenticates, pos);
            osip_proxy_authenticate_free (al);
        }
    }
    {
        osip_proxy_authentication_info_t *al;

        while (!osip_list_eol (&sip->proxy_authentication_infos, pos))
        {
            al =
                (osip_proxy_authentication_info_t *) osip_list_get (&sip->
                        proxy_authentication_infos,
                        pos);
            osip_list_remove (&sip->proxy_authentication_infos, pos);
            osip_proxy_authentication_info_free (al);
        }
    }
    {
        osip_proxy_authorization_t *proxy_authorization;

        while (!osip_list_eol (&sip->proxy_authorizations, pos))
        {
            proxy_authorization =
                (osip_proxy_authorization_t *) osip_list_get (&sip->
                        proxy_authorizations, pos);
            osip_list_remove (&sip->proxy_authorizations, pos);
            osip_proxy_authorization_free (proxy_authorization);
        }
    }
    {
        osip_record_route_t *record_route;

        while (!osip_list_eol (&sip->record_routes, pos))
        {
            record_route =
                (osip_record_route_t *) osip_list_get (&sip->record_routes, pos);
            osip_list_remove (&sip->record_routes, pos);
            osip_record_route_free (record_route);
        }
    }
    {
        osip_route_t *route;

        while (!osip_list_eol (&sip->routes, pos))
        {
            route = (osip_route_t *) osip_list_get (&sip->routes, pos);
            osip_list_remove (&sip->routes, pos);
            osip_route_free (route);
        }
    }
    if (sip->to != NULL)
    {
        osip_to_free (sip->to);
    }
    {
        osip_via_t *via;

        while (!osip_list_eol (&sip->vias, pos))
        {
            via = (osip_via_t *) osip_list_get (&sip->vias, pos);
            osip_list_remove (&sip->vias, pos);
            osip_via_free (via);
        }
    }
    {
        osip_www_authenticate_t *al;

        while (!osip_list_eol (&sip->www_authenticates, pos))
        {
            al =
                (osip_www_authenticate_t *) osip_list_get (&sip->www_authenticates, pos);
            osip_list_remove (&sip->www_authenticates, pos);
            osip_www_authenticate_free (al);
        }
    }

    {
        osip_header_t *header;

        while (!osip_list_eol (&sip->headers, pos))
        {
            header = (osip_header_t *) osip_list_get (&sip->headers, pos);
            osip_list_remove (&sip->headers, pos);
            osip_header_free (header);
        }
    }

    {
        osip_body_t *body;

        while (!osip_list_eol (&sip->bodies, pos))
        {
            body = (osip_body_t *) osip_list_get (&sip->bodies, pos);
            osip_list_remove (&sip->bodies, pos);
            osip_body_free (body);
        }
    }
    osip_free (sip->message);
    osip_free (sip);
}