Exemplo n.º 1
0
static int test_strdupcat(void)
{
  su_home_t home[1] = { SU_HOME_INIT(home) };

  BEGIN();

  TEST_S(su_strdup(home, "foo"), "foo");
  TEST_S(su_strcat(home, "foo", "bar"), "foobar");
  TEST_S(su_strndup(home, "foobar", 3), "foo");

  TEST_S(su_strcat_all(home, NULL), "");
  TEST_S(su_strcat_all(home, "a", "", "b", "", NULL), "ab");

  su_home_deinit(home);

  END();
}
Exemplo n.º 2
0
/** Convert a @Via header to @Contact URL string.
 *
 * The @Contact URI will contain the port number and transport parameters if
 * needed. If transport protocol name starts with "TLS", "SIPS:" URI schema
 * is used.
 *
 * The contact URI string returned will always have angle brackets ("<" and
 * ">") around it.
 *
 * @param home      memory home
 * @param v         @Via header field structure
 *                  (with <sent-by> parameter containing host and port)
 * @param user      username for @Contact URI (may be NULL)
 * @param transport transport name for @Contact URI (may be NULL)
 *
 * @retval string containing Contact URI with angle brackets
 * @retval NULL upon an error
 */
char *
sip_contact_string_from_via(su_home_t *home,
			    sip_via_t const *v,
			    char const *user,
			    char const *transport)
{
  const char *host, *port, *maddr, *comp;
  char const *scheme = "sip:";
  int one = 1;
  char _transport[16];

  if (!v) return NULL;

  host = v->v_host;
  if (v->v_received)
    host = v->v_received;
  port = sip_via_port(v, &one);
  maddr = v->v_maddr;
  comp = v->v_comp;

  if (host == NULL)
    return NULL;

  if (sip_transport_has_tls(v->v_protocol) ||
      sip_transport_has_tls(transport)) {
    scheme = "sips:";
    if (port && strcmp(port, SIPS_DEFAULT_SERV) == 0)
      port = NULL;
    if (port || host_is_ip_address(host))
      transport = NULL;
  }
  else if (port && strcmp(port, SIP_DEFAULT_SERV) == 0 &&
	   (host_is_ip_address(host) || host_has_domain_invalid(host))) {
    port = NULL;
  }

  if (su_casenmatch(transport, "SIP/2.0/", 8))
    transport += 8;

  /* Make transport parameter lowercase */
  if (transport && strlen(transport) < (sizeof _transport)) {
    char *s = strcpy(_transport, transport);
    short c;

    for (s = _transport; (c = *s) && c != ';'; s++)
      if (isupper(c))
	*s = tolower(c);

    transport = _transport;
  }

  return su_strcat_all(home,
		       "<",
		       scheme,
		       user ? user : "", user ? "@" : "",
		       host,
		       SIP_STRLOG(":", port),
		       SIP_STRLOG(";transport=", transport),
		       SIP_STRLOG(";maddr=", maddr),
		       SIP_STRLOG(";comp=", comp),
		       ">",
		       NULL);
}