-int caseenumerate(const struct vol *vol, struct path *path, struct dir *dir)
-{
- DIR *dp;
- struct dirent *de;
- int ret;
- static u_int32_t did = 0;
- static char cname[MAXPATHLEN];
- static char lname[MAXPATHLEN];
- ucs2_t u2_path[MAXPATHLEN];
- ucs2_t u2_dename[MAXPATHLEN];
- char *tmp, *savepath;
-
- if (!(vol->v_flags & AFPVOL_CASEINSEN))
- return -1;
-
- if (veto_file(ENUMVETO, path->u_name))
- return -1;
-
- savepath = path->u_name;
-
- /* very simple cache */
- if ( dir->d_did == did && strcmp(lname, path->u_name) == 0) {
- path->u_name = cname;
- path->d_dir = NULL;
- if (of_stat( path ) == 0 ) {
- return 0;
- }
- /* something changed, we cannot stat ... */
- did = 0;
- }
-
- if (NULL == ( dp = opendir( "." )) ) {
- LOG(log_debug, logtype_afpd, "caseenumerate: opendir failed: %s", dir->d_u_name);
- return -1;
- }
-
-
- /* LOG(log_debug, logtype_afpd, "caseenumerate: for %s", path->u_name); */
- if ((size_t) -1 == convert_string(vol->v_volcharset, CH_UCS2, path->u_name, -1, u2_path, sizeof(u2_path)) )
- LOG(log_debug, logtype_afpd, "caseenumerate: conversion failed for %s", path->u_name);
-
- /*LOG(log_debug, logtype_afpd, "caseenumerate: dir: %s, path: %s", dir->d_u_name, path->u_name); */
- ret = -1;
- for ( de = readdir( dp ); de != NULL; de = readdir( dp )) {
- if (NULL == check_dirent(vol, de->d_name))
- continue;
-
- if ((size_t) -1 == convert_string(vol->v_volcharset, CH_UCS2, de->d_name, -1, u2_dename, sizeof(u2_dename)) )
- continue;
-
- if (strcasecmp_w( u2_path, u2_dename) == 0) {
- tmp = path->u_name;
- strlcpy(cname, de->d_name, sizeof(cname));
- path->u_name = cname;
- path->d_dir = NULL;
- if (of_stat( path ) == 0 ) {
- LOG(log_debug, logtype_afpd, "caseenumerate: using dir: %s, path: %s", de->d_name, path->u_name);
- strlcpy(lname, tmp, sizeof(lname));
- did = dir->d_did;
- ret = 0;
- break;
- }
- else
- path->u_name = tmp;
- }
-
- }
- closedir(dp);
-
- if (ret) {
- /* invalidate cache */
- cname[0] = 0;
- did = 0;
- path->u_name = savepath;
- }
- /* LOG(log_debug, logtype_afpd, "caseenumerate: path on ret: %s", path->u_name); */
- return ret;
-}
-
-