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

SOFIAPUBFUN issize_t url_dup ( char *  buf,
isize_t  bufsize,
url_t dst,
url_t const *  src 
)

Duplicate the url in the provided memory area.

Duplicate the url.

The function url_dup() copies the url structure src and the strings attached to it to url. The non-constant strings in src are copied to buf. If the size of duplicated strings exceed bufsize, the corresponding string fields in url are set to NULL.

The calling function can calculate the size of buffer required by calling url_dup() with zero as bufsize and NULL as dst.

Parameters:
buf Buffer for non-constant strings copied from src.
bufsize Size of buf.
dst Destination URL structure.  
src Source URL structure.
Returns:
Number of characters required for duplicating the strings in str, or -1 if an error occurred.

Definition at line 1092 of file url.c.

References url_d(), url_dup(), url_t::url_fragment, url_t::url_pad, url_t::url_root, url_scheme(), url_t::url_scheme, URL_STRING_P, url_t::url_type, and url_unknown.

Referenced by nth_site_create(), tport_name_by_url(), url_dup(), url_hdup(), and url_map_new().

{
  if (!src && !dst)
    return -1;
  else if (URL_STRING_P(src)) {
    size_t n = strlen((char *)src) + 1;
    if (n > bufsize || dst == NULL)
      return n;

    strcpy(buf, (char *)src);
    memset(dst, 0, sizeof(*dst));
    if (url_d(dst, buf) < 0)
      return -1;

    return n;
  }
  else {
    char *b = buf;
    char *end = b + bufsize;
    char const **dstp;
    char const * const *srcp;
    url_t dst0[1];

    if (dst == NULL)
      dst = dst0;

    memset(dst, 0, sizeof(*dst));

    if (!src)
      return 0;

    memset(dst->url_pad, 0, sizeof dst->url_pad);
    dst->url_type = src->url_type;
    dst->url_root = src->url_root;

    dstp = &dst->url_scheme;
    srcp = &src->url_scheme;

    if (dst->url_type > url_unknown)
      *dstp = url_scheme(dst->url_type);

    if (*dstp != NULL)
      dstp++, srcp++;   /* Skip scheme if it is constant */

    if (dst != dst0 && buf != NULL && bufsize != 0)
      for (; srcp <= &src->url_fragment; srcp++, dstp++)
      if (*srcp) {
        char *next = copy(b, end, *srcp);

        if (next > end)
          break;

        *dstp = b, b = next;
      }

    for (; srcp <= &src->url_fragment; srcp++)
      if (*srcp) {
      b += strlen(*srcp) + 1;
      }

    return b - buf;
  }
}


Generated by  Doxygen 1.6.0   Back to index