ucommon
7.0.0
About: GNU uCommon C++ is a portable and optimized class framework for writing C++ applications that need to use threads and support concurrent synchronization, and that use sockets, XML parsing, object serialization, thread-optimized string and data structure classes, etc.. Fossies Dox: ucommon-7.0.0.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation) 
|
Go to the documentation of this file. 40 static const char *
argv0 =
"car";
47 static void report(
const char *path,
int code)
49 const char *err =
_TEXT(
"i/o error");
54 err =
_TEXT(
"permission denied");
57 err =
_TEXT(
"read-only file system");
61 err =
_TEXT(
"no such file or directory");
64 err =
_TEXT(
"not a directory");
67 err =
_TEXT(
"directory not empty");
70 err =
_TEXT(
"no space left on device");
74 err =
_TEXT(
"bad file path");
78 err =
_TEXT(
"file or directory busy");
81 err =
_TEXT(
"operation interupted");
84 err =
_TEXT(
"is a directory");
88 err =
_TEXT(
"too many sym links");
101 static bool encode(
const char *path, FILE *fp,
size_t offset = 0)
105 size_t count = fread(
frame + offset, 1,
sizeof(
frame) - offset, fp);
117 if(count <
sizeof(
frame))
118 frame[
sizeof(
frame) - 1] = (
char)(count - offset);
122 if(encoded !=
sizeof(
frame)) {
135 if(count ==
sizeof(
frame))
147 fputs(
"car: type your message\n", stderr);
152 if(!
encode(
"-", stdin, offset))
158 fprintf(
output,
"-----END CAR STREAM-----\n");
181 FILE *fp = fopen(path,
"r");
208 static void final(void)
253 path =
str((
char *)(
cbuf + 6));
254 cp = strrchr((
char *)(
cbuf + 6),
'/');
264 string_t prompt =
str(
"overwrite ") + path +
" <y/n>? ";
283 output = fopen(*path,
"w");
288 printf(
"decoding %s...\n", *path);
314 argv0, path,
_TEXT(
"not a cryptographic archive"));
339 if(NULL == fgets(
buffer,
sizeof(
buffer), fp) || feof(fp)) {
348 if(
eq(
"-----BEGIN CAR STREAM-----\n",
buffer))
366 if(
eq(
"-----END CAR STREAM-----\n",
buffer)) {
392 while(
is(
dir) &&
dir.
read(filename,
sizeof(filename))) {
393 if(*filename ==
'.' && (filename[1] ==
'.' || !filename[1]))
399 filepath =
str(path) +
str(
"/") +
str(filename);
403 name ^=
str(filename);
407 scan(filepath, name);
409 report(*filepath, EISDIR);
416 int main(
int argc,
char **argv)
419 shell args(argc, argv);
422 char passphrase[256];
429 printf(
"%s\n",
_TEXT(
"Usage: car [options] path..."));
430 printf(
"%s\n\n",
_TEXT(
"Crytographic archiver"));
431 printf(
"%s\n",
_TEXT(
"Options:"));
433 printf(
"\n%s\n",
_TEXT(
"Report bugs to dyfet@gnu.org"));
451 if(!
eq(passphrase, confirm))
453 argv0,
_TEXT(
"passphrase does not match confirmation"));
457 memset(passphrase, 0,
sizeof(passphrase));
458 memset(confirm, 0,
sizeof(confirm));
475 FILE *fp = fopen(args[0],
"r");
478 argv0, args[0],
_TEXT(
"cannot open or access"));
480 const char *ext = strrchr(args[0],
'.');
498 ext = strrchr(*
out,
'.');
503 fprintf(
output,
"-----BEGIN CAR STREAM-----\n");
513 while(count < args()) {
517 const char *cp = args[count++];
518 const char *ep = strrchr(cp,
'/');
520 ep = strrchr(cp,
'\\');
530 fprintf(
output,
"-----END CAR STREAM-----\n");
static size_t b64encode(char *string, const uint8_t *binary, size_t size, size_t width=0)
static size_t b64decode(uint8_t *binary, const char *string, size_t size, bool ws=false)
void set(uint8_t *address, size_t size=0)
static const char * argv0
static char * getpass(const char *prompt, char *buffer, size_t size)
static shell::stringopt out('o', "--output", _TEXT("output file"), "filename", "-")
static void bind(const char *name)
bool eq_case(char const *s1, char const *s2)
static shell::stringopt tag('t', "--tag", _TEXT("tag annotation"), "text", "")
static shell::flagopt recursive('R', "--recursive", _TEXT("recursive directory scan"))
static shell::flagopt altrecursive('r', NULL, NULL)
static bool has(const char *name)
static shell::flagopt helpflag('h',"--help", _TEXT("display this list"))
size_t put(const uint8_t *data, size_t size)
static int inkey(const char *prompt=NULL)
static void binarydecode(FILE *fp, const char *path)
static shell::stringopt hash('h', "--digest", _TEXT("digest method (sha)"), "method", "sha")
void lsb_setlong(uint8_t *b, uint32_t v)
static shell::stringopt algo('c', "--cipher", _TEXT("cipher method (aes256)"), "method", "aes256")
static bool has(const char *name)
static int create(const char *path, unsigned mode)
static shell::flagopt althelp('?', NULL, NULL)
static bool encode(const char *path, FILE *fp, size_t offset=0)
static void static void errexit(int exitcode, const char *format=NULL,...) __PRINTF(2
int main(int argc, char **argv)
int info(fileinfo_t *buffer)
uint32_t lsb_getlong(uint8_t *b)
static void scan(string_t path, string_t prefix)
bool eq(const struct sockaddr *s1, const struct sockaddr *s2)
static void process(void)
void set(const char *text)
static shell::flagopt yes('y', "--overwrite", _TEXT("overwrite existing files"))
static shell::flagopt quiet('q', "--quiet", _TEXT("quiet operation"))
String str(Socket &so, size_t size)
static bool is_dir(const char *path)
static uint8_t buffer[65536]
static void streamdecode(FILE *fp, const char *path)
ssize_t read(char *buffer, size_t count)
static void encodefile(const char *path, const char *name)
static void encodestream(void)
const char * argv0() const
static void report(const char *path, int code)
static shell::flagopt decode('d', "--decode", _TEXT("decode archive"))
static shell::flagopt hidden('s', "--hidden", _TEXT("include hidden files"))
static shell::flagopt noheader('n', "--no-header", _TEXT("without wrapper"))
static size_t printf(const char *format,...) __PRINTF(1
static bool is_file(const char *path)
const char * _TEXT(const char *s)