23 #include <sys/types.h>
24 #include <sys/socket.h>
25 #include <netinet/in.h>
108 printf(
"%p->FA::Open(%s,%d)\n",
this,fn?fn:
"NULL",mode);
146 return(
"Operation is in progress");
156 return(
"Class is not Open()ed");
160 return(
_(
"File cannot be accessed"));
162 return(
_(
"Not connected"));
166 return(
_(
"Fatal error"));
168 return(
_(
"Store failed - you have to reput"));
172 return(
_(
"Login failed"));
176 return(
_(
"Operation not supported"));
232 if(tmp.
ne(
".") && tmp.
ne(
".."))
284 if(!f || (f[0]!=
'/' && f[0]!=
'~'))
358 save_pass.
set(o->pass);
361 o->pass.
set(save_pass);
372 static void expand_tilde(
xstring &path,
const char *home,
int i=0)
374 if(!(path[i]==
'~' && (path[i+1]==0 || path[i+1]==
'/')))
376 char prefix_len=(
last_char(home)==
'/' ? 2 : 1);
377 if(home[0]==
'/' && i>0 && path[i-1]==
'/')
392 expand_tilde(
file,home);
394 expand_tilde(
file1,home);
404 if(!home || !(s[0]==
'~' && (s[1]==
'/' || s[1]==0)))
409 expand_tilde(buf,home);
414 bool last_element_is_doubledot(
const char *path,
const char *end)
416 return((end==path+2 && !strncmp(path,
"..",2))
417 || (end>path+2 && !strncmp(end-3,
"/..",3)));
428 if(i>0 && path[i]==
':')
429 return i+1+(path[i+1]==
'/');
437 if(path[0]==
'/' && path[1]==
'~' && device_prefix_len==1)
440 while(path[prefix_size]!=
'/' && path[prefix_size]!=
'\0')
443 else if(path[0]==
'/')
446 if(path[1]==
'/' && (!path[2] || path[2]!=
'/'))
449 else if(path[0]==
'~')
452 while(path[prefix_size]!=
'/' && path[prefix_size]!=
'\0')
466 while((in[0]==
'.' && (in[1]==
'/' || in[1]==0))
467 || (in>path && in[-1]==
'/' && (in[0]==
'/'
468 || (in[0]==
'.' && in[1]==
'.' && (in[2]==
'/' || in[2]==0)))))
470 if(in[0]==
'.' && in[1]==
'.')
490 if(in[2]==
'/' || in[2]==
'\0')
496 if(in[2]==
'.' && (in[3]==
'/' || in[3]==
'\0'))
498 if(last_element_is_doubledot(path+prefix_size,out)
500 || (out==path+prefix_size && out[-1]!=
'/'))
502 if(out>path && out[-1]!=
'/')
509 while(out>path+prefix_size && *--out!=
'/')
517 if(out>path && out[-1]==
'/')
591 for(
int i=0; fn[i]; i++)
594 if(iscntrl((
unsigned char)fn[i]))
623 for(i=0; i<pool_size; i++)
632 for(i=0; i<pool_size; i++)
650 for(i=0; i<pool_size; i++)
670 if(n<0 || n>=pool_size)
679 for( ; *n<pool_size; (*n)++)
681 if(pool[*n] && !strcmp(pool[*n]->
GetProto(),proto))
689 for(
int n=0;
n<pool_size;
n++)
773 for( ; scan; scan=scan->next)
786 if(!strcmp(proto,
"slot"))
789 return session?session->Clone():0;
796 const char *n_proto=session->ProtocolSubstitution(host);
797 if(n_proto && strcmp(n_proto,proto))
804 session->SetVisualProto(proto);
809 session->Connect(host,port);
823 if(strcmp(proto,
"slot"))
859 #define PROTO_PREFIX "proto-"
883 error_text.append(
_(
" [cached]"));
923 void FileAccess::Path::init()
944 if(!new_path && new_path_enc)
946 if(!new_path || !*new_path)
949 if(!strcmp(bn,
".") || !strcmp(bn,
".."))
961 new_url_path.
set(
"/~");
965 if(new_path[0]==
'/' || new_path[0]==
'~' || new_device_prefix_len!=0)
967 bool have_slash=((new_path_enc?new_path_enc:new_path)[0]==
'/');
968 new_url_path.
set(have_slash?
"":
"/");
971 new_url_path.
append(new_path_enc);
976 Optimize(new_url_path,!strncmp(new_url_path,
"/~",2));
977 url.truncate(path_index);
978 url.append(new_url_path);
981 if(new_path[0]!=
'/' && new_path[0]!=
'~' && new_device_prefix_len==0
1000 if(!strcmp(path,
"/") || !strcmp(path,
"//"))
1011 LogError(0,
"URL mismatch %s [%s] vs %s, dropping URL\n",
url.get(),u.
path.
get(),path.get());
1018 const Path &p1=*
this;
1031 if(path && path[0]==
'~' && (path[1]==
'/' || path[1]==
'\0'))
1040 if(
url[pi]==
'/' &&
url[pi+1]==
'~')
1044 expand_tilde(path,home.
path);
1051 #ifndef MODULE_PROTO_FTP
1053 # define _ftp Ftp::ClassInit()
1057 #ifndef MODULE_PROTO_FILE
1059 # define _file LocalAccess::ClassInit()
1063 #ifndef MODULE_PROTO_HTTP
1065 # define _http Http::ClassInit()
1069 #ifndef MODULE_PROTO_FISH
1071 # define _fish Fish::ClassInit()
1075 #ifndef MODULE_PROTO_SFTP
1077 # define _sftp SFtp::ClassInit()
1081 bool FileAccess::class_inited;