Lines 210-213
static struct ftp_direntry *ftp_direntry
Link Here
|
210 |
dirent->size = rr->finfo.size; |
210 |
dirent->size = rr->finfo.size; |
211 |
dirent->csize = rr->finfo.csize; |
211 |
dirent->csize = rr->finfo.csize; |
|
|
212 |
dirent->ctime = rr->finfo.ctime; |
213 |
dirent->atime = rr->finfo.atime; |
214 |
dirent->mtime = rr->finfo.mtime; |
212 |
dirent->modestring = apr_pstrdup(r->pool, |
215 |
dirent->modestring = apr_pstrdup(r->pool, |
213 |
ftp_modestring_get( |
216 |
ftp_modestring_get( |
Lines 267-272
static struct ftp_direntry *ftp_direntry
Link Here
|
267 |
* be greater than d2. |
270 |
* be greater than d2. |
268 |
*/ |
271 |
*/ |
269 |
static int ftp_dsortf(struct ftp_direntry ** d1, |
272 |
static int ftp_dsortf(const struct ftp_direntry ** d1, |
270 |
struct ftp_direntry ** d2) |
273 |
const struct ftp_direntry ** d2) |
271 |
{ |
274 |
{ |
272 |
/* Simple sort based on filename */ |
275 |
/* Simple sort based on filename */ |
Lines 274-277
static int ftp_dsortf(struct ftp_direntr
Link Here
|
274 |
} |
277 |
} |
275 |
|
278 |
|
|
|
279 |
static int ftp_dsortf_desc(const struct ftp_direntry ** d1, |
280 |
const struct ftp_direntry ** d2) |
281 |
{ |
282 |
/* Simple sort based on filename, descending */ |
283 |
return strcmp((*d2)->name, (*d1)->name); |
284 |
} |
285 |
|
286 |
#define FTP_DSORT_TIME(field) \ |
287 |
static int ftp_dsort_##field(const struct ftp_direntry ** d1, \ |
288 |
const struct ftp_direntry ** d2) \ |
289 |
{ \ |
290 |
return (*d1)->field - (*d2)->field; \ |
291 |
} \ |
292 |
static int ftp_dsort_desc_##field(const struct ftp_direntry ** d1, \ |
293 |
const struct ftp_direntry ** d2) \ |
294 |
{ \ |
295 |
return (*d2)->field - (*d1)->field; \ |
296 |
} |
297 |
|
298 |
FTP_DSORT_TIME(mtime) |
299 |
FTP_DSORT_TIME(ctime) |
300 |
FTP_DSORT_TIME(atime) |
301 |
FTP_DSORT_TIME(size) |
302 |
|
276 |
/* ftp_direntry_get: Return an array of ftp_direntry structures based |
303 |
/* ftp_direntry_get: Return an array of ftp_direntry structures based |
277 |
* on the uri stored in the request rec. An extra |
304 |
* on the uri stored in the request rec. An extra |
Lines 283-287
static int ftp_dsortf(struct ftp_direntr
Link Here
|
283 |
* Returns: The sorted array of directory entries on success, NULL otherwise |
310 |
* Returns: The sorted array of directory entries on success, NULL otherwise |
284 |
*/ |
311 |
*/ |
285 |
struct ftp_direntry *ftp_direntry_get(request_rec *r, const char *pattern) |
312 |
struct ftp_direntry *ftp_direntry_get(request_rec *r, const char *pattern, |
|
|
313 |
enum ftp_sort sortby, int reverse) |
286 |
{ |
314 |
{ |
287 |
struct ftp_direntry *p, *head, *current, **a; |
315 |
struct ftp_direntry *p, *head, *current, **a; |
Lines 293-296
struct ftp_direntry *ftp_direntry_get(re
Link Here
|
293 |
const char *path, *search; |
321 |
const char *path, *search; |
294 |
|
322 |
|
|
|
323 |
int (*compar[])(const struct ftp_direntry **, |
324 |
const struct ftp_direntry **) = { |
325 |
/* The order here must match the enum ftp_sort! */ |
326 |
ftp_dsortf, ftp_dsortf_desc, |
327 |
ftp_dsort_mtime, ftp_dsort_desc_mtime, |
328 |
ftp_dsort_atime, ftp_dsort_desc_atime, |
329 |
ftp_dsort_ctime, ftp_dsort_desc_ctime, |
330 |
ftp_dsort_size, ftp_dsort_desc_size |
331 |
}; |
332 |
|
295 |
/* |
333 |
/* |
296 |
* The actual search pattern, used to determine if we should recurse into |
334 |
* The actual search pattern, used to determine if we should recurse into |
Lines 374-378
struct ftp_direntry *ftp_direntry_get(re
Link Here
|
374 |
const char *newpattern = apr_pstrcat(r->pool, fname, |
412 |
const char *newpattern = apr_pstrcat(r->pool, fname, |
375 |
"/*", NULL); |
413 |
"/*", NULL); |
376 |
p->child = ftp_direntry_get(r, newpattern); |
414 |
p->child = ftp_direntry_get(r, newpattern, sortby, reverse); |
377 |
} |
415 |
} |
378 |
else { |
416 |
else { |
Lines 396-401
struct ftp_direntry *ftp_direntry_get(re
Link Here
|
396 |
} |
434 |
} |
397 |
num = i; |
435 |
num = i; |
398 |
qsort((void *) a, num, sizeof(struct ftp_direntry *), |
436 |
if (sortby != SORT_NONE) { |
399 |
(int (*) (const void *, const void *)) ftp_dsortf); |
437 |
qsort((void *) a, num, sizeof(struct ftp_direntry *), |
|
|
438 |
(int (*)(const void *, |
439 |
const void *))compar[sortby * 2 + reverse]); |
440 |
} |
400 |
|
441 |
|
401 |
/* Re-construct the list from the sorted list */ |
442 |
/* Re-construct the list from the sorted list */ |