Changeset 1163

Show
Ignore:
Timestamp:
2005-03-21 01:58:49 (4 years ago)
Author:
conrad
Message:

cleaning up -- move file extension handling into ma_extsub()

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • mod_annodex-ap20/trunk/mod_annodex.c

    r1161 r1163  
    694694} 
    695695 
     696static char * 
     697ma_extsub (request_rec * r, char * filename, 
     698           char * oldext, int oldext_len, 
     699           char * newext, int newext_len) 
     700{ 
     701  char * extpos; 
     702  char * srcfile; 
     703  int filename_len; 
     704  int diff; /* how many bytes longer the new extension is */ 
     705  char * ret; 
     706 
     707  extpos = rindex (r->filename, '.'); 
     708  if (extpos == NULL) return NULL; 
     709 
     710  if (strncmp (++extpos, oldext, oldext_len)) return NULL; 
     711 
     712  /* s/.oldext/.newext/ */ 
     713  diff = newext_len - oldext_len; 
     714  filename_len = strlen (filename); 
     715  srcfile = apr_palloc (r->pool, filename_len + diff + 1 /* '\0' */); 
     716  apr_cpystrn (srcfile, filename, filename_len-oldext_len+1); 
     717  apr_cpystrn (srcfile+filename_len-oldext_len, newext, newext_len+1); 
     718 
     719  ret = r->path_info ? 
     720    apr_pstrcat (r->pool, srcfile, r->path_info, NULL) : srcfile; 
     721 
     722  return ret; 
     723} 
     724 
    696725/* The annodex content handler */ 
    697726static int annodex_handler(request_rec *r) 
     
    725754    int filename_len; 
    726755 
    727     extpos = rindex (r->filename, '.'); 
    728     if (extpos && !strncmp (extpos, ".anx", 4)) { 
    729       /* s/.anx$/.cmml/ */ 
    730       filename_len = strlen (r->filename); 
    731       srcfile = apr_palloc (r->pool, filename_len+2); 
    732       apr_cpystrn (srcfile, r->filename, filename_len-2); 
    733       apr_cpystrn (srcfile+filename_len-3, "cmml", 5); 
    734  
    735       srcpath = r->path_info ? 
    736         apr_pstrcat(r->pool, srcfile, r->path_info, NULL) : srcfile; 
     756    if ((srcpath = ma_extsub (r, r->filename, "anx", 3, "cmml", 4))) { 
    737757 
    738758      if (apr_file_open (&f, srcpath, APR_READ, APR_OS_DEFAULT, r->pool) != 
     
    748768      filename = srcpath; 
    749769 
    750     } else if (extpos && !strncmp (extpos, ".cmml", 5)) { 
    751       /* s/.cmml$/.anx/ */ 
    752       filename_len = strlen (r->filename); 
    753       srcfile = apr_palloc (r->pool, filename_len+1); 
    754       apr_cpystrn (srcfile, r->filename, filename_len-3); 
    755       apr_cpystrn (srcfile+filename_len-4, "anx", 4); 
    756  
    757       srcpath = r->path_info ? 
    758         apr_pstrcat(r->pool, srcfile, r->path_info, NULL) : srcfile; 
     770    } else if ((srcpath = ma_extsub (r, r->filename, "cmml", 4, "anx", 3))) { 
    759771 
    760772      if (apr_file_open (&f, srcpath, APR_READ, APR_OS_DEFAULT, r->pool) !=