davix  0.4.1
Public Member Functions
Davix::DavPosix Class Reference

POSIX-like API of Davix. More...

#include <davposix.hpp>

Inheritance diagram for Davix::DavPosix:
NonCopyable

Public Member Functions

 DavPosix (Context *handle)
 default constructor More...
 
int stat (const RequestParams *params, const std::string &str, struct stat *st, DavixError **err)
 POSIX-like stat() call. More...
 
int stat64 (const RequestParams *params, const std::string &url, StatInfo *st, DavixError **err)
 64bits version of /ref Davix::DavPosix::stat. More...
 
DAVIX_DIR * opendir (const RequestParams *params, const std::string &url, DavixError **err)
 open a directory for listing. More...
 
struct dirent * readdir (DAVIX_DIR *dir, DavixError **err)
 read an entry directory. More...
 
int closedir (DAVIX_DIR *d, DavixError **err)
 close a directory handle More...
 
DAVIX_DIR * opendirpp (const RequestParams *params, const std::string &url, DavixError **err)
 open a directory for listing with per entry meta-data informations. More...
 
struct dirent * readdirpp (DAVIX_DIR *dir, struct stat *st, DavixError **err)
 execute an readdirpp function More...
 
int closedirpp (DAVIX_DIR *d, DavixError **err)
 close a directory handle More...
 
int mkdir (const RequestParams *params, const std::string &url, mode_t right, DavixError **err)
 execute a mkdir function with Webdav. More...
 
int rename (const RequestParams *params, const std::string &source_url, const std::string &target_url, DavixError **err)
 rename a target file or collection. More...
 
int unlink (const RequestParams *params, const std::string &url, DavixError **err)
 execute a remove file operation. More...
 
int rmdir (const RequestParams *params, const std::string &url, DavixError **err)
 execute a remove directory operation. More...
 
DAVIX_FD * open (const RequestParams *params, const std::string &url, int flags, DavixError **err)
 open a file for read/write operation in a POSIX-like approach. More...
 
ssize_t read (DAVIX_FD *fd, void *buffer, size_t count, DavixError **err)
 read a file in a POSIX-like approach with HTTP(S). More...
 
ssize_t pread (DAVIX_FD *fd, void *buffer, size_t count, off_t offset, DavixError **err)
 do a partial read of a file in a POSIX-like approach with HTTP(S). More...
 
dav_ssize_t pread64 (DAVIX_FD *fd, void *buffer, dav_size_t count, dav_off_t offset, DavixError **err)
 64bits version of /ref Davix::DavPosix::pread
 
ssize_t pwrite (DAVIX_FD *fd, const void *buffer, size_t count, off_t offset, DavixError **err)
 do a partial write of a file in a POSIX-like approach with HTTP(S). More...
 
dav_ssize_t pwrite64 (DAVIX_FD *fd, const void *buffer, dav_size_t count, dav_off_t offset, DavixError **err)
 64bits version of /ref Davix::DavPosix::pwrite
 
dav_ssize_t preadVec (DAVIX_FD *fd, const DavIOVecInput *input_vec, DavIOVecOuput *output_vec, dav_size_t count_vec, DavixError **err)
 pread_vec a file in a POSIX-like approach with HTTP(S). More...
 
ssize_t write (DAVIX_FD *fd, const void *buf, size_t count, DavixError **err)
 write a file in a POSIX-like approach with HTTP(S). More...
 
off_t lseek (DAVIX_FD *fd, off_t offset, int flags, DavixError **err)
 move the cursor a davix file with HTTP(S). More...
 
dav_off_t lseek64 (DAVIX_FD *fd, dav_off_t, int flags, DavixError **err)
 64bits versions of /ref Davix::DavixPosix::lseek
 
int close (DAVIX_FD *fd, DavixError **err)
 close a existing file descriptor. More...
 
void fadvise (DAVIX_FD *fd, dav_off_t offset, dav_size_t len, advise_t advice)
 give advise about next file operation More...
 

Detailed Description

POSIX-like API of Davix.

DavPosix offers a POSIX-like API for HTTP/WebDav file operations.

POSIX API can be used for convenience when porting application. to a POSIX like interface.

DavPosix and all associated method are Thread safe.

Constructor & Destructor Documentation

Davix::DavPosix::DavPosix ( Context handle)

default constructor

Parameters
handle
Context c;
DavPosix pos(&c);

Member Function Documentation

int Davix::DavPosix::close ( DAVIX_FD *  fd,
DavixError **  err 
)

close a existing file descriptor.

Note : all file descriptors MUST be closed before the destruction of the parent davix context

Parameters
fddavix file descriptor
errDavix Error report
Returns
0 if success, negative value if error
Context c;
DavixError* err = NULL;
DavPosix pos(&c);
DAVIX_FD* fd;
fd = pos.open(NULL, "http://example.org/myfile", O_RDONLY, &err);
pos.close(fd);
int Davix::DavPosix::closedir ( DAVIX_DIR *  d,
DavixError **  err 
)

close a directory handle

Parameters
ddirectory handle to close
errDavix error report system
Returns
0 if success else a negative value and err is set.
Context c;
DavixError* err = NULL;
DavPosix pos(&c);
DAVIX_DIR* fd;
struct dirent* entry;
fd = pos.opendir(NULL, "dav://example.org/collection_to_open", &err);
while(entry = pos.readdir(fd, &err)){
std::cout << entry->d_name << std::endl;
}
pos.closedir(fd, &err);
int Davix::DavPosix::closedirpp ( DAVIX_DIR *  d,
DavixError **  err 
)

close a directory handle

Parameters
ddirectory handle to close
errDavix error report system
Returns
0 if success else a negative value and err is set.
Context c;
DavixError* err = NULL;
DavPosix pos(&c);
DAVIX_DIR* fd;
struct dirent* entry;
struct stat info;
fd = posix.opendirpp(NULL, "dav://example.org/collection_to_open", &err);
while(entry = pos.readdirpp(fd, &info, &err)){
std::cout << entry->d_name << “is ” << info.st_size << “bytes in size.” << std::endl;
}
pos.closedirpp(fd, &err);
void Davix::DavPosix::fadvise ( DAVIX_FD *  fd,
dav_off_t  offset,
dav_size_t  len,
advise_t  advice 
)

give advise about next file operation

similar to posix_fadvise, allow I/O optimizations non-blocking asynchronous function

Parameters
fdDavix file descriptor
offsetoffset of the next chunk to read
lensize of the next chunk to read
advisetype of pattern for I/O : sequential, random
off_t Davix::DavPosix::lseek ( DAVIX_FD *  fd,
off_t  offset,
int  flags,
DavixError **  err 
)

move the cursor a davix file with HTTP(S).

Behavior similar to the POSIX lseek function.

Parameters
fddavix file descriptor
offsetoffset in byte inside the file
flagslseek flags, similar to the lseek function
errDavix Error report
Returns
the offset position or (off_t)-1 if error occurs
Context c;
DavixError* err = NULL;
DavPosix pos(&c);
DAVIX_FD* fd;
fd = pos.open(NULL, "http://example.com/myfile", O_RDONLY, &err);
// position cursor to 200 bytes offset
lseek(fd, 200, SEEK_SET, &err);
// position cursor to current location plus 100 offset
lseek(fd, 100, SEEK_CUR, &err);
// position cursor to end of the file plus offset 200
lseek(fd, 200, SEEK_END, &err);
pos.close(fd);
int Davix::DavPosix::mkdir ( const RequestParams params,
const std::string &  url,
mode_t  right,
DavixError **  err 
)

execute a mkdir function with Webdav.

Behavior similar to the POSIX mkdir function.

Warning
dependening of the server, implementation, mode_t parameter can be ignored
Parameters
paramsrequest options, can be NULL
urlurl of the directory to create
rightdefault mode of the directory ( ignored for now )
errDavix error report system
Returns
0 if success else a negative value and err is set.
Context c;
DavixError* err = NULL;
DavPosix pos(&c);
pos.mkdir(NULL, "dav://example.org/collection_to_create", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH, &err);
DAVIX_FD* Davix::DavPosix::open ( const RequestParams params,
const std::string &  url,
int  flags,
DavixError **  err 
)

open a file for read/write operation in a POSIX-like approach.

Behavior similar to the POSIX open function

This operation is supported on plain HTTP servers.

Parameters
paramsrequest options, can be NULL
urlurl of the HTTP file to open
flagsopen flags, similar to the POSIX function open
errDavix Error report
Returns
Davix file descriptor in case of success, or NULL if an error occures.
Context c;
DavixError* err = NULL;
DavPosix pos(&c);
DAVIX_FD* fd;
fd = pos.open(NULL, "http://example.org/myfile", O_RDONLY, &err);
DAVIX_DIR* Davix::DavPosix::opendir ( const RequestParams params,
const std::string &  url,
DavixError **  err 
)

open a directory for listing.

behavior similar to the POSIX opendir function.

Supported by Webdav.

Parameters
paramsrequest options, can be NULL
urlurl of the directory to list
errDavix error report system
Returns
DAVIX_DIR davix readdir handle, NULL if error
Context c;
DavixError* err = NULL;
DavPosix pos(&c);
DAVIX_DIR* fd;
struct dirent* entry;
fd = pos.opendir(NULL, "dav://example.org/collection_to_open", &err);
while(entry = pos.readdir(fd, &err)){
std::cout << entry->d_name << std::endl;
}
pos.closedir(fd, &err);
DAVIX_DIR* Davix::DavPosix::opendirpp ( const RequestParams params,
const std::string &  url,
DavixError **  err 
)

open a directory for listing with per entry meta-data informations.

Similar to Davix::DavPosix::opendir but provide stat() informations for each entry Supported by Webdav.

Parameters
paramsrequest options, can be NULL
urlurl of the directory to list
errDavix error report system
Returns
DAVIX_DIR davix readdir handle or NULL if error, in this case err is set.
Context c;
DavixError* err = NULL;
DavPosix pos(&c);
DAVIX_DIR* fd;
struct dirent* entry;
struct stat info;
fd = posix.opendirpp(NULL, "dav://example.org/collection_to_open", &err);
while(entry = pos.readdirpp(fd, &info, &err)){
std::cout << entry->d_name << “is ” << info.st_size << “bytes in size.” << std::endl;
}
pos.closedirpp(fd, &err);
ssize_t Davix::DavPosix::pread ( DAVIX_FD *  fd,
void *  buffer,
size_t  count,
off_t  offset,
DavixError **  err 
)

do a partial read of a file in a POSIX-like approach with HTTP(S).

Behavior similar to the POSIX pread function.

Parameters
fddavix file descriptor
bufferbuffer to fill
countmaximum number of bytes to read
offsetoffset to use
errDavix Error report
Returns
the size of data or a negative value if an error occured
Context c;
DavixError* err = NULL;
DavPosix pos(&c);
DAVIX_FD* fd;
fd = pos.open(NULL, "http://example.org/myfile", O_RDONLY, &err);
// read 50 bytes from myfile at offset 100
char buffer2[255];
pos.pread(fd, &buffer2, 50, 100, &err);
pos.close(fd);
dav_ssize_t Davix::DavPosix::preadVec ( DAVIX_FD *  fd,
const DavIOVecInput input_vec,
DavIOVecOuput output_vec,
dav_size_t  count_vec,
DavixError **  err 
)

pread_vec a file in a POSIX-like approach with HTTP(S).

Vector read operation.

Able to do several read operations in one single request.

Parameters
fddavix file descriptor
input_vecinput vectors, parameters
output_vecoutput vectors, results
count_vecnumber of vector struct
errDavix Error report
Returns
total number of bytes read, or -1 if error occures
Context c;
DavixError* err = NULL;
DavPosix pos(&c);
int number_of_vector = 2;
DavIOVecInput input_vector[number_of_vector];
DavIOVecOutput output_vector[number_of_vector];
DAVIX_FD* fd;
fd = pos.open(NULL, "http://example.org/myfile", O_RDONLY, &err);
// Setup vector operations parameters
char buf1[255] = {0};
char buf2[255] = {0};
input_vector[0].diov_offset = 100;
input_vector[0].diov_size = 200;
input_vector[0].diov_buffer = buf1;
input_vector[1].diov_offset = 600;
input_vector[1].diov_size = 150;
input_vector[1].diov_buffer = buf2;
// execute query
pos.pread_vec(fd, input_vector, output_vector, number_of_vector, &err);
std::cout << “Op 1 read ” << output_vector[0].diov_size << “bytes” << std::endl;
std::cout << “Op 2 read ” << output_vector[1].diov_size << “bytes” << std::endl;
// do things with content in output_vector[0].diov_buffer etc
pos.close(fd);
ssize_t Davix::DavPosix::pwrite ( DAVIX_FD *  fd,
const void *  buffer,
size_t  count,
off_t  offset,
DavixError **  err 
)

do a partial write of a file in a POSIX-like approach with HTTP(S).

Behavior similar to the POSIX pwrite function

Parameters
fddavix file descriptor
bufferbuffer to fill
countmaximum number of bytes to write
offsetoffset to use
errDavix Error report
Returns
the size of data written or a negative value if an error occured
ssize_t Davix::DavPosix::read ( DAVIX_FD *  fd,
void *  buffer,
size_t  count,
DavixError **  err 
)

read a file in a POSIX-like approach with HTTP(S).

Behavior similar to the POSIX read function

Parameters
fddavix file descriptor
bufferbuffer to fill
countmaximum number of bytes to read
errDavix Error report
Returns
the size of data or a negative value if an error occured
Context c;
DavixError* err = NULL;
DavPosix pos(&c);
DAVIX_FD* fd;
fd = pos.open(NULL, "http://example.org/myfile", O_RDONLY, &err);
// read 200 bytes from myfile
char buffer[255];
pos.read(fd, &buffer, 200, &err);
pos.close(fd);
struct dirent* Davix::DavPosix::readdir ( DAVIX_DIR *  dir,
DavixError **  err 
)

read an entry directory.

Behavior similar to the POSIX readdir function.

Parameters
dirdirectory handle
errDavix Error report
Returns
dirent struct if success, or NULL if error
Context c;
DavixError* err = NULL;
DavPosix pos(&c);
DAVIX_DIR* fd;
struct dirent* entry;
fd = pos.opendir(NULL, "dav://example.org/collection_to_open", &err);
while(entry = pos.readdir(fd, &err)){
std::cout << entry->d_name << std::endl;
}
pos.closedir(fd, &err);
struct dirent* Davix::DavPosix::readdirpp ( DAVIX_DIR *  dir,
struct stat * st  ,
DavixError **  err 
)

execute an readdirpp function

Similar to Davix::DavPosix::readdir but provide stat() informations for each entry.

Supported by Webdav.

Parameters
dirdirectory handle
ststruct to fill
errDavix Error report
Returns
dirent struct if success, or NULL if error
Context c;
DavixError* err = NULL;
DavPosix pos(&c);
DAVIX_DIR* fd;
struct dirent* entry;
struct stat info;
fd = posix.opendirpp(NULL, "dav://example.org/collection_to_open", &err);
while(entry = pos.readdirpp(fd, &info, &err)){
std::cout << entry->d_name << “is ” << info.st_size << “bytes in size.” << std::endl;
}
pos.closedirpp(fd, &err);
int Davix::DavPosix::rename ( const RequestParams params,
const std::string &  source_url,
const std::string &  target_url,
DavixError **  err 
)

rename a target file or collection.

Behavior similar to the POSIX rename function.

Parameters
paramsrequest options, can be NULL
source_urlold url of the resource
target_urlnew url of the resource
errDavix error report system
Returns
0 if success else a negative value and err is set.
Context c;
DavixError* err = NULL;
DavPosix pos(&c);
pos.rename(NULL, "http://example.org/myfolder/old_file_name”, “http://example.org/myfolder/new_file_name", &err);
int Davix::DavPosix::rmdir ( const RequestParams params,
const std::string &  url,
DavixError **  err 
)

execute a remove directory operation.

Behavior similar to the POSIX rmdir function

Parameters
paramsrequest options, can be NULL
urldirectory to delete
errDavix error report system
Returns
0 if success else a negative value and err is set.
Context c;
DavixError* err = NULL;
DavPosix pos(&c);
pos.rmdir(NULL, "dav://example.org/collection_to_remove", &err);
int Davix::DavPosix::stat ( const RequestParams params,
const std::string &  str,
struct stat * st  ,
DavixError **  err 
)

POSIX-like stat() call.

Behavior similar to the POSIX stat function, see man 3 stat.

Supported by Webdav, Http and S3.

Depending of the protocol, some struct stat field can be ignored.

Parameters
paramsrequest options, can be NULL
strstring url
ststat struct to fill
errDavix error report system
Returns
0 if success, negative value if error
Contect c;
DavixError* err = NULL;
DavFile file(c, Uri(“http://example.org/dir/file_to_stat”));
StatInfo info;
file.stat(NULL, info, &err);
std::cout << "my file is " << info.size << " bytes large " << std::endl;
std::cout << " mode : 0" << std::oct << info.mode << std::endl;
std::cout << " atime : " << info.atime << std::endl;
std::cout << " mtime : " << info.mtime << std::endl;
std::cout << " ctime : " << info.ctime << std::endl;
int Davix::DavPosix::stat64 ( const RequestParams params,
const std::string &  url,
StatInfo st,
DavixError **  err 
)

64bits version of /ref Davix::DavPosix::stat.

Contect c;
DavixError* err = NULL;
DavFile file(c, Uri(“http://example.org/dir/file_to_stat”));
StatInfo info;
file.stat(NULL, info, &err);
std::cout << "my file is " << info.size << " bytes large " << std::endl;
std::cout << " mode : 0" << std::oct << info.mode << std::endl;
std::cout << " atime : " << info.atime << std::endl;
std::cout << " mtime : " << info.mtime << std::endl;
std::cout << " ctime : " << info.ctime << std::endl;
int Davix::DavPosix::unlink ( const RequestParams params,
const std::string &  url,
DavixError **  err 
)

execute a remove file operation.

Behavior similar to the POSIX unlink function.

Parameters
paramsrequest options, can be NULL
urlfile to delete
errDavix error report system
Returns
0 if success else a negative value and err is set.
Context c;
DavixError* err = NULL;
DavPosix pos(&c);
pos.unlink(NULL, "http://example.org/file_to_delete", &err);
ssize_t Davix::DavPosix::write ( DAVIX_FD *  fd,
const void *  buf,
size_t  count,
DavixError **  err 
)

write a file in a POSIX-like approach with HTTP(S).

Behavior similar to the POSIX write function.

Parameters
fddavix file descriptor
bufbuffer with the write content
countnumber of bytes to write
errDavix Error report
Returns
the size of the written data or a negative value if an error occured
Context c;
DavixError* err = NULL;
DavPosix pos(&c);
DAVIX_FD* fd;
// create a new file and write 200 bytes from buffer to it
fd = pos.open(NULL, "http://example.org/myfolder/mynewfile", O_WRONLY | O_CREAT, &err);
pos.write(fd, &buffer, 200);
pos.close(fd);

The documentation for this class was generated from the following file: