Test API to control the storage client

Overview

Generic client functions for storage service. More…

// typedefs

typedef struct tapi_storage_client tapi_storage_client;
typedef te_errno (*tapi_storage_client_method_open)(tapi_storage_client *client);
typedef te_errno (*tapi_storage_client_method_close)(tapi_storage_client *client);

typedef te_errno (*tapi_storage_client_method_pwd)(
    tapi_storage_client *client,
    tapi_local_file *directory
    );

typedef te_errno (*tapi_storage_client_method_ls)(
    tapi_storage_client *client,
    const char *path,
    tapi_local_file_list *files
    );

typedef te_errno (*tapi_storage_client_method_cd)(
    tapi_storage_client *client,
    const char *remote_directory
    );

typedef te_errno (*tapi_storage_client_method_put)(
    tapi_storage_client *client,
    const char *local_file,
    const char *remote_file
    );

typedef te_errno (*tapi_storage_client_method_get)(
    tapi_storage_client *client,
    const char *remote_file,
    const char *local_file
    );

typedef te_errno (*tapi_storage_client_method_rm)(
    tapi_storage_client *client,
    const char *filename,
    bool recursive
    );

typedef te_errno (*tapi_storage_client_method_mkdir)(
    tapi_storage_client *client,
    const char *directory_name
    );

typedef te_errno (*tapi_storage_client_method_rmdir)(
    tapi_storage_client *client,
    const char *directory_name
    );

typedef struct tapi_storage_client_methods tapi_storage_client_methods;

// structs

struct tapi_storage_client;
struct tapi_storage_client_methods;

// global functions

static te_errno tapi_storage_client_connect(tapi_storage_client* client);
static te_errno tapi_storage_client_disconnect(tapi_storage_client* client);
static te_errno tapi_storage_client_pwd(tapi_storage_client* client, tapi_local_file* directory);
static te_errno tapi_storage_client_ls(tapi_storage_client* client, const char* path, tapi_local_file_list* files);
static te_errno tapi_storage_client_cd(tapi_storage_client* client, const char* remote_directory);
static te_errno tapi_storage_client_put(tapi_storage_client* client, const char* local_file, const char* remote_file);
static te_errno tapi_storage_client_get(tapi_storage_client* client, const char* remote_file, const char* local_file);
static te_errno tapi_storage_client_rm(tapi_storage_client* client, const char* filename, bool recursive);
static te_errno tapi_storage_client_mkdir(tapi_storage_client* client, const char* directory_name);
static te_errno tapi_storage_client_rmdir(tapi_storage_client* client, const char* directory_name);
te_errno tapi_storage_client_init(tapi_storage_service_type type, rcf_rpc_server* rpcs, const tapi_storage_client_methods* methods, tapi_storage_auth_params* auth, void* context, tapi_storage_client* client);
void tapi_storage_client_fini(tapi_storage_client* client);
te_errno tapi_storage_client_mput(tapi_storage_client* client, const tapi_local_file* local_file, const char* remote_file, bool recursive, bool force);
te_errno tapi_storage_client_mget(tapi_storage_client* client, const char* remote_file, const char* local_file, bool recursive);

// macros

#define TAPI_STORAGE_CLIENT_INIT

Detailed Documentation

Generic client functions for storage service.

Copyright (C) 2004-2022 OKTET Labs Ltd. All rights reserved.

Typedefs

typedef te_errno (*tapi_storage_client_method_open)(tapi_storage_client *client)

Open a connection.

Parameters:

client

Client handle.

Returns:

Status code.

typedef te_errno (*tapi_storage_client_method_close)(tapi_storage_client *client)

Close the connection.

Parameters:

client

Client handle.

Returns:

Status code.

typedef te_errno (*tapi_storage_client_method_pwd)(
    tapi_storage_client *client,
    tapi_local_file *directory
    )

Get current work directory name.

Parameters:

client

Client handle.

directory

File context where the directory name will be saved.

Returns:

Status code.

typedef te_errno (*tapi_storage_client_method_ls)(
    tapi_storage_client *client,
    const char *path,
    tapi_local_file_list *files
    )

Get files list.

Parameters:

service

Service handle.

path

Path to the files.

files

Files list.

Returns:

Status code.

typedef te_errno (*tapi_storage_client_method_cd)(
    tapi_storage_client *client,
    const char *remote_directory
    )

Change remote work directory.

Parameters:

client

Client handle.

remote_directory

Remote directory.

Returns:

Status code.

typedef te_errno (*tapi_storage_client_method_put)(
    tapi_storage_client *client,
    const char *local_file,
    const char *remote_file
    )

Put a local file to remote storage.

Parameters:

client

Client handle.

local_file

Local file name.

remote_file

Remote file name or NULL to use the same.

Returns:

Status code.

typedef te_errno (*tapi_storage_client_method_get)(
    tapi_storage_client *client,
    const char *remote_file,
    const char *local_file
    )

Get a file from remote storage.

Parameters:

client

Client handle.

remote_file

Remote file name.

local_file

Local file name or NULL to use the same.

Returns:

Status code.

typedef te_errno (*tapi_storage_client_method_rm)(
    tapi_storage_client *client,
    const char *filename,
    bool recursive
    )

Remove a file(s) from the current working directory on the remote storage.

Parameters:

client

Client handle.

filename

Remote file name to remove.

recursive

Perform recursive removing if true and specified file is directory.

Returns:

Status code.

typedef te_errno (*tapi_storage_client_method_mkdir)(
    tapi_storage_client *client,
    const char *directory_name
    )

Make a new directory in the current working directory on the remote storage. It behaves like a ‘mkdir -p’ i.e. it creates a parent directories as needed.

Parameters:

client

Client handle.

directory_name

Directory name to create on remote storage.

Returns:

Status code.

typedef te_errno (*tapi_storage_client_method_rmdir)(
    tapi_storage_client *client,
    const char *directory_name
    )

Remove the directory from the remote storage.

Parameters:

client

Client handle.

directory_name

Directory name to remove it from the remote storage.

Returns:

Status code.

typedef struct tapi_storage_client_methods tapi_storage_client_methods

Methods to operate the client.

Global Functions

static te_errno tapi_storage_client_connect(tapi_storage_client* client)

Open a connection.

Parameters:

client

Client handle.

Returns:

Status code.

static te_errno tapi_storage_client_disconnect(tapi_storage_client* client)

Close the connection.

Parameters:

client

Client handle.

Returns:

Status code.

static te_errno tapi_storage_client_pwd(tapi_storage_client* client, tapi_local_file* directory)

Get current work directory name.

Parameters:

client

Client handle.

directory

File context where the directory name will be saved.

Returns:

Status code.

static te_errno tapi_storage_client_ls(tapi_storage_client* client, const char* path, tapi_local_file_list* files)

Get files list.

Parameters:

service

Service handle.

path

Path to the files.

files

Files list.

Returns:

Status code.

static te_errno tapi_storage_client_cd(tapi_storage_client* client, const char* remote_directory)

Change remote work directory.

Parameters:

client

Client handle.

remote_directory

Remote directory.

Returns:

Status code.

static te_errno tapi_storage_client_put(tapi_storage_client* client, const char* local_file, const char* remote_file)

Put a local file to remote storage.

Parameters:

client

Client handle.

local_file

Local file name.

remote_file

Remote file name or NULL to use the same.

Returns:

Status code.

static te_errno tapi_storage_client_get(tapi_storage_client* client, const char* remote_file, const char* local_file)

Get a file from remote storage.

Parameters:

client

Client handle.

remote_file

Remote file name.

local_file

Local file name or NULL to use the same.

Returns:

Status code.

static te_errno tapi_storage_client_rm(tapi_storage_client* client, const char* filename, bool recursive)

Remove a file(s) from the current working directory on the remote storage.

Parameters:

client

Client handle.

filename

Remote file name to remove.

recursive

Perform recursive removing if true and specified file is directory.

Returns:

Status code.

static te_errno tapi_storage_client_mkdir(tapi_storage_client* client, const char* directory_name)

Make a new directory in the current working directory on the remote storage.

Parameters:

client

Client handle.

directory_name

Directory name to create on remote storage.

Returns:

Status code.

static te_errno tapi_storage_client_rmdir(tapi_storage_client* client, const char* directory_name)

Remove the directory from the remote storage.

Parameters:

client

Client handle.

directory_name

Directory name to remove it from the remote storage.

Returns:

Status code.

te_errno tapi_storage_client_init(tapi_storage_service_type type, rcf_rpc_server* rpcs, const tapi_storage_client_methods* methods, tapi_storage_auth_params* auth, void* context, tapi_storage_client* client)

Initialize client handle. Client should be released with tapi_storage_client_fini when it is no longer needed.

Parameters:

type

Back-end client type.

rpcs

RPC server handle.

methods

Back-end client scpecific methods.

auth

Back-end client specific authorization parameters. May be NULL.

context

Back-end client specific context. Don’t free the context before finishing work with client.

client

Client handle.

Returns:

Status code.

See also:

tapi_storage_client_fini

void tapi_storage_client_fini(tapi_storage_client* client)

Release client that was initialized with tapi_storage_client_init.

Parameters:

client

Client handle.

Returns:

Status code.

See also:

tapi_storage_client_init

te_errno tapi_storage_client_mput(tapi_storage_client* client, const tapi_local_file* local_file, const char* remote_file, bool recursive, bool force)

Copy local files to the storage server location. Can be used for recursive copying of directories.

Parameters:

client

Client handle.

local_file

Local file name.

remote_file

Remote file name or NULL to use the same.

recursive

It has effect only if local_file is directory. If false then only files from mentioned directory will be copied. If true then additionally the all files from subdirectories will be copied.

force

Force to replace existent content by the same. If false the existent content will not be rewriten by the same (lazy behaviour).

Returns:

Status code.

te_errno tapi_storage_client_mget(tapi_storage_client* client, const char* remote_file, const char* local_file, bool recursive)

Copy files from the storage server to local location. Can be used for recursive copying of directories.

Parameters:

client

Client handle.

remote_file

Remote file name.

local_file

Local file name or NULL to use the same.

recursive

It has effect only if remote_file is directory. If false then only files from mentioned directory will be copied. If true then additionally the all files from subdirectories will be copied.

Returns:

Status code.

Macros

#define TAPI_STORAGE_CLIENT_INIT

On-stack tapi_storage_client structure initializer.