Logo Search packages:      
Sourcecode: sofia-sip version File versions

TPORT_DLL int tport_name_dup ( su_home_t home,
tp_name_t dst,
tp_name_t const *  src 
)

Duplicate a transport name.

Duplicate name.

The tport_name_dup() function copies strings belonging to the transport name. It returns the copied strings via the dst transport name structure. The memory block required for copies is allocated from the memory home. Please note that only one memory block is allocated, so the memory can be reclainmed only by deinitializing the memory home itself.

Return values:
0 when successful
-1 upon an error

Definition at line 4478 of file tport.c.

References su_alloc(), tp_name_t::tpn_canon, tp_name_t::tpn_comp, tp_name_t::tpn_host, tp_name_t::tpn_port, tp_name_t::tpn_proto, and tport_name_dup().

Referenced by tport_convert_addr(), and tport_name_dup().

{
  size_t n_proto, n_host, n_port, n_canon, n_comp = 0;
  char *s;

  if (strcmp(src->tpn_proto, tpn_any)) 
    n_proto = strlen(src->tpn_proto) + 1;
  else
    n_proto = 0;

  n_host = strlen(src->tpn_host) + 1;

  n_port = strlen(src->tpn_port) + 1;

  if (src->tpn_comp != NULL)
    n_comp = strlen(src->tpn_comp) + 1;

  if (src->tpn_canon != src->tpn_host &&
      strcmp(src->tpn_canon, src->tpn_host))
    n_canon = strlen(src->tpn_canon) + 1;
  else
    n_canon = 0;

  s = su_alloc(home, n_proto + n_canon + n_host + n_port + n_comp);
  
  if (n_proto)
    dst->tpn_proto = memcpy(s, src->tpn_proto, n_proto), s += n_proto;
  else
    dst->tpn_proto = tpn_any;

  dst->tpn_host = memcpy(s, src->tpn_host, n_host), s += n_host;
  dst->tpn_port = memcpy(s, src->tpn_port, n_port), s += n_port;

  if (n_canon)
    dst->tpn_canon = memcpy(s, src->tpn_canon, n_canon), s += n_canon;
  else
    dst->tpn_canon = dst->tpn_host;

  if (n_comp)
    dst->tpn_comp = memcpy(s, src->tpn_comp, n_comp), s += n_comp;
  else
    dst->tpn_comp = NULL;
  
  return 0;
}


Generated by  Doxygen 1.6.0   Back to index