Changeset 4687:3205eb431074 for bcache.c

Show
Ignore:
Timestamp:
2006-07-04 10:59:54 (2 years ago)
Author:
Brendan Cully <brendan@…>
Branch:
HEAD
Message:

Rename mutt_bcache_path to bcache_path (it's static), simplify it a bit,
and just strip '/' in the URL portion up to path instead of replacing
them with '_', for prettier cache folder names.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • bcache.c

    r4684 r4687  
    3939}; 
    4040 
    41 static int mutt_bcache_path(ACCOUNT *account, const char *mailbox, 
    42                             char *dst, size_t dstlen) 
     41static int bcache_path(ACCOUNT *account, const char *mailbox, 
     42                       char *dst, size_t dstlen) 
    4343{ 
    4444  char host[STRING]; 
    45   char *s; 
     45  char *s, *p; 
    4646  ciss_url_t url; 
    4747  size_t len; 
     
    5858   */ 
    5959  url.path = NULL; 
    60   url_ciss_tostring (&url, host, sizeof (host), 0); 
    61  
    62   dprint (3, (debugfile, "bcache: host: '%s'\n", host)); 
    63  
    64   /* 
    65    * replace all '/' in proto://host part to '_' so the hierarchy 
    66    * doesn't get too deeply nested 
    67    * XXX imaps:__joe@example.com@imap.example.com doesn't look nice 
    68    * 
    69    * ('*(s+1)' since url_ciss_tostring() appends '/' after host part 
    70    * which we want to keep) 
    71    */ 
    72   for (s = host; s && *s && *(s+1) ; s++) 
    73     if (*s == '/') 
    74       *s = '_'; 
    75  
    76   /* 
    77    * not enough space is the only error I can think of 
    78    * (dstlen-1 for '/'-termination, see below) 
    79    */ 
    80   if (snprintf (dst, dstlen-1, "%s/%s%s", MessageCachedir, 
    81                 host, NONULL(mailbox)) <= 0) 
    82     return -1; 
    83  
    84   /* make sure to '/'-terminate the path as we assume that elsewhere */ 
    85   len = mutt_strlen (dst); 
    86   if (len <= dstlen+2 && dst[len-1] != '/') 
    87   { 
    88     dst[len++] = '/'; 
    89     dst[len] = '\0'; 
    90   } 
    91  
    92   dprint (3, (debugfile, "bcache: directory: '%s'\n", dst)); 
     60  if (url_ciss_tostring (&url, host, sizeof (host), 0) < 0) 
     61  { 
     62    dprint (1, (debugfile, "bcache_path: URL to string failed\n")); 
     63    return -1; 
     64  } 
     65 
     66  dprint (3, (debugfile, "bcache_path: URL: '%s'\n", host)); 
     67 
     68  /* transform URL scheme:// to scheme: */ 
     69  for (s = p = host; *s; s++) 
     70    /* keep trailing slash */ 
     71    if (*s != '/' || *(s + 1) == '\0') 
     72      *p++ = *s; 
     73  *p = '\0'; 
     74 
     75  len = snprintf (dst, dstlen-1, "%s/%s%s%s", MessageCachedir, 
     76                  host, NONULL(mailbox), 
     77                  (mailbox && *mailbox && 
     78                   mailbox[mutt_strlen(mailbox) - 1] == '/') ? "" : "/"); 
     79  if (len < 0 || len >= dstlen-1) 
     80    return -1; 
     81 
     82  dprint (3, (debugfile, "bcache_path: directory: '%s'\n", dst)); 
    9383 
    9484  return 0; 
     
    10393 
    10494  bcache = safe_calloc (1, sizeof (struct body_cache)); 
    105   if (mutt_bcache_path (account, mailbox, bcache->path, 
    106                         sizeof (bcache->path)) < 0) 
     95  if (bcache_path (account, mailbox, bcache->path, 
     96                   sizeof (bcache->path)) < 0) 
    10797    goto bail; 
    10898  bcache->pathlen = mutt_strlen (bcache->path);