Compare commits
87 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7229c9b532 | |||
| 044a971dae | |||
| a11dacd960 | |||
| 3b621e591a | |||
| d3dca6c2a5 | |||
| 29f4f8cde6 | |||
| c5acd13df2 | |||
| 41485cbe22 | |||
| c6bf7bb84e | |||
| 30239c6f50 | |||
| d21f6c8be9 | |||
| 0bee82e863 | |||
| bfc2b1f6eb | |||
| 7436b3b148 | |||
| a70ce5c4af | |||
| 415adf2077 | |||
| 3b5d89fdb9 | |||
| 2e73c6dc13 | |||
| 909d84b36e | |||
| 959e5eb959 | |||
| df6d78b6ef | |||
| 6c730c9775 | |||
| a6c471a97a | |||
| ab4bb84ed6 | |||
| 7d14d2b672 | |||
| 4bba1e8c02 | |||
| 3d598040dd | |||
| 09dc449a5c | |||
| 86c1d159cb | |||
| be79c014d4 | |||
| 081973c904 | |||
| c21950493a | |||
| ce39f2a910 | |||
| 1929e7d7b3 | |||
| 1ce771b553 | |||
| 60ab410a8c | |||
| 7adb82f8ac | |||
| 62f3df94ee | |||
| 61fd410c63 | |||
| 1c3b752a8e | |||
| 1a765e595b | |||
| 94ff55f256 | |||
| ddfd0f1cc2 | |||
| e34ec3d594 | |||
| f932a48910 | |||
| 23af379bfb | |||
| 31da8bf081 | |||
| 0cbc873f5c | |||
| 925760d1bd | |||
| 83c61aadc2 | |||
| 552561146a | |||
| cdd6d1cfed | |||
| e62296d92f | |||
| 5d819f7388 | |||
| 4339d7905d | |||
| 3ffc5c5236 | |||
| 224e7e8599 | |||
| 9a214c46e2 | |||
| 9dd925a87d | |||
| 4b93082139 | |||
| 8234677276 | |||
| 262a436264 | |||
| 70e1c6788a | |||
| 30d4d6870c | |||
| 744ac8e40c | |||
| 9042dfcfa9 | |||
| e2a500e321 | |||
| a91267ca1b | |||
| cf572ece04 | |||
| f486d34b16 | |||
| e3bd7a8cdf | |||
| 266369b1f2 | |||
| a4fc16650e | |||
| eef272fa4e | |||
| 5e8d0a2dbf | |||
| 62ff1d3929 | |||
| ba0afd4152 | |||
| 3923421224 | |||
| 27e3ac11db | |||
| 9e3e0f57a0 | |||
| e5b46bb1c0 | |||
| 86247fe2b5 | |||
| 788d3c7bea | |||
| 7ecba4e0d5 | |||
| 16376bcafc | |||
| d75701270d | |||
| 990c4362af |
@@ -72,3 +72,90 @@ git push -u origin <feature-branch-name>
|
|||||||
gh pr create --fill
|
gh pr create --fill
|
||||||
```
|
```
|
||||||
Wait for CI to pass on the PR before merging.
|
Wait for CI to pass on the PR before merging.
|
||||||
|
|
||||||
|
## Batch PR Workflow
|
||||||
|
|
||||||
|
When handling multiple issues split across several PRs that target the same files:
|
||||||
|
|
||||||
|
1. **Group issues by logical category** into separate PR branches (e.g., memory-safety, refactoring, test-coverage).
|
||||||
|
2. **Fix and push** each branch independently. Let CI run on each PR.
|
||||||
|
3. **Run all 3 reviewer types** on each PR and post results to Gitea via `tea pr approve/reject` or the Gitea API:
|
||||||
|
- `reviewer` — general code correctness
|
||||||
|
- `code-quality-guardian` — code quality, duplication, complexity
|
||||||
|
- `security-auditor` — vulnerability assessment
|
||||||
|
4. **Iterate**: if any reviewer requests changes, fix, push, re-review. Repeat until all 3 approve.
|
||||||
|
5. **Merge approved PRs** one at a time into `main`.
|
||||||
|
6. **Create a combined merge branch** for the remaining PRs that conflict with the new `main`:
|
||||||
|
```bash
|
||||||
|
git checkout -b merge-all origin/main
|
||||||
|
for branch in branch1 branch2 branch3; do
|
||||||
|
git merge origin/$branch --no-edit || true
|
||||||
|
# Resolve conflicts, build, test
|
||||||
|
done
|
||||||
|
```
|
||||||
|
7. **Run review again** on the combined branch. Fix issues, push, re-review until approved.
|
||||||
|
8. **Merge** the combined PR, **close** the redundant individual PRs, and **close all resolved issues** via the Gitea API:
|
||||||
|
```bash
|
||||||
|
curl -s -X PATCH -H "Authorization: token $TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"state":"closed"}' \
|
||||||
|
"https://gitea.tap-tap.win/api/v1/repos/owner/repo/issues/<number>"
|
||||||
|
```
|
||||||
|
|
||||||
|
## CI Troubleshooting
|
||||||
|
|
||||||
|
### If lint (clang-format) fails
|
||||||
|
Run clang-format in the CI Docker image to match the exact CI version:
|
||||||
|
```bash
|
||||||
|
docker run --rm -v "$PWD:/workspace" -w /workspace gitea.tap-tap.win/taptap/fastsync-ci:v9 \
|
||||||
|
sh -c 'find src/ tests/ -name "*.c" -o -name "*.h" | xargs clang-format -i'
|
||||||
|
```
|
||||||
|
|
||||||
|
### If cppcheck fails
|
||||||
|
Fix reported issues locally, then verify with:
|
||||||
|
```bash
|
||||||
|
docker run --rm -v "$PWD:/workspace" -w /workspace gitea.tap-tap.win/taptap/fastsync-ci:v9 \
|
||||||
|
sh -c 'cppcheck --enable=warning,style,performance,portability --suppress=missingIncludeSystem --error-exitcode=1 --inline-suppr src/ tests/'
|
||||||
|
```
|
||||||
|
|
||||||
|
### If integration tests fail
|
||||||
|
Run locally before pushing:
|
||||||
|
```bash
|
||||||
|
python3 -m pytest tests/ -v --tb=short
|
||||||
|
```
|
||||||
|
|
||||||
|
## Gitea API & tea CLI
|
||||||
|
|
||||||
|
### Check CI status via API
|
||||||
|
```bash
|
||||||
|
TOKEN="<token>"
|
||||||
|
curl -s -H "Authorization: token $TOKEN" \
|
||||||
|
"https://gitea.tap-tap.win/api/v1/repos/TapTap/FastSync/actions/runs?limit=5" \
|
||||||
|
| python3 -c "
|
||||||
|
import json,sys; d=json.load(sys.stdin)
|
||||||
|
for r in d.get('workflow_runs',[]):
|
||||||
|
path = r.get('path','')
|
||||||
|
prn = path.split('@')[1].replace('refs/pull/','').replace('/head','') if '@' in path else ''
|
||||||
|
print(f'PR #{prn}: sha={r[\"head_sha\"][:8]} {r[\"status\"]} {r.get(\"conclusion\",\"\")}')
|
||||||
|
"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Post review comments
|
||||||
|
```bash
|
||||||
|
curl -s -X POST -H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
|
||||||
|
-d '{"body":"MARKDOWN_REVIEW_BODY"}' \
|
||||||
|
"https://gitea.tap-tap.win/api/v1/repos/TapTap/FastSync/issues/<PR_NUMBER>/comments"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Use tea for PR operations
|
||||||
|
```bash
|
||||||
|
tea pr list --repo TapTap/FastSync
|
||||||
|
tea pr close <number> --repo TapTap/FastSync
|
||||||
|
```
|
||||||
|
|
||||||
|
## Common pitfalls
|
||||||
|
|
||||||
|
- **`__thread` on shared SSL context**: io_ssl must NOT be thread-local — worker threads inherit the SSL context from the main thread. Use regular `static SSL* io_ssl`.
|
||||||
|
- **SSL WANT_READ/WANT_WRITE retry**: Always retry on `SSL_ERROR_WANT_READ` and `SSL_ERROR_WANT_WRITE` in `send_n_data`/`receive_n_data`. Removing these breaks TLS multithreaded transfers.
|
||||||
|
- **clang-format version**: The CI image uses clang-format 18. Always format inside the CI Docker container for exact match.
|
||||||
|
- **Merge order matters**: Merge the most comprehensive branch first, then smaller ones, to minimize conflicts when creating a combined branch.
|
||||||
|
|||||||
+11
-2
@@ -56,6 +56,8 @@ static void print_usage(void) {
|
|||||||
printf(" --key <path> TLS private key file (PEM)\n");
|
printf(" --key <path> TLS private key file (PEM)\n");
|
||||||
printf(" --ca <path> TLS CA certificate file (PEM)\n");
|
printf(" --ca <path> TLS CA certificate file (PEM)\n");
|
||||||
printf(" --partial Keep partial files on interrupted transfer\n");
|
printf(" --partial Keep partial files on interrupted transfer\n");
|
||||||
|
printf(" --fastsync-server-path <path>\n");
|
||||||
|
printf(" Path to fastsync-server on remote (default: fastsync-server)\n");
|
||||||
printf(" --help Show this help\n");
|
printf(" --help Show this help\n");
|
||||||
printf(" -V, --version Show version and exit\n");
|
printf(" -V, --version Show version and exit\n");
|
||||||
}
|
}
|
||||||
@@ -70,10 +72,14 @@ int main(int argc, char* argv[]) {
|
|||||||
save_to_disk = true;
|
save_to_disk = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Config* config = config_create(str_dup(PROTOCOL_VERSION), NULL, NULL, save_to_disk, false, false,
|
|
||||||
false, false, 5, false, 0);
|
|
||||||
int exit_code = 0;
|
int exit_code = 0;
|
||||||
bool config_owned_by_pipeline = false;
|
bool config_owned_by_pipeline = false;
|
||||||
|
Config* config = config_create(str_dup(PROTOCOL_VERSION), NULL, NULL, save_to_disk, false, false,
|
||||||
|
false, false, 5, false, 0);
|
||||||
|
if (config == NULL) {
|
||||||
|
exit_code = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
int positional_args[2];
|
int positional_args[2];
|
||||||
int positional_count = 0;
|
int positional_count = 0;
|
||||||
@@ -220,6 +226,9 @@ int main(int argc, char* argv[]) {
|
|||||||
config->tls_ca = str_dup(argv[++i]);
|
config->tls_ca = str_dup(argv[++i]);
|
||||||
} else if (strcmp(argv[i], "--partial") == 0) {
|
} else if (strcmp(argv[i], "--partial") == 0) {
|
||||||
config->partial = true;
|
config->partial = true;
|
||||||
|
} else if (strcmp(argv[i], "--fastsync-server-path") == 0 && i + 1 < argc) {
|
||||||
|
free(config->fastsync_server_path);
|
||||||
|
config->fastsync_server_path = str_dup(argv[++i]);
|
||||||
} else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {
|
} else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {
|
||||||
set_log_level(LOG_LEVEL_DEBUG);
|
set_log_level(LOG_LEVEL_DEBUG);
|
||||||
} else if (argv[i][0] == '-') {
|
} else if (argv[i][0] == '-') {
|
||||||
|
|||||||
@@ -228,7 +228,8 @@ static int send_chunks_multithreaded(void* pipeline_context) {
|
|||||||
fprintf(stderr, "Error: -f/--sendfile is not supported with SSH transport\n");
|
fprintf(stderr, "Error: -f/--sendfile is not supported with SSH transport\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
client = client_connect_ssh(context->config->ssh_destination, context->config->ssh_port);
|
client = client_connect_ssh(context->config->ssh_destination, context->config->ssh_port,
|
||||||
|
context->config->fastsync_server_path);
|
||||||
} else if (context->config->use_tls) {
|
} else if (context->config->use_tls) {
|
||||||
client = client_create();
|
client = client_create();
|
||||||
if (!client || !client_connect_tls(client, context->config->server_host,
|
if (!client || !client_connect_tls(client, context->config->server_host,
|
||||||
@@ -385,7 +386,8 @@ int send_files(Config* config) {
|
|||||||
fprintf(stderr, "Error: -f/--sendfile is not supported with SSH transport\n");
|
fprintf(stderr, "Error: -f/--sendfile is not supported with SSH transport\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
client = client_connect_ssh(config->ssh_destination, config->ssh_port);
|
client =
|
||||||
|
client_connect_ssh(config->ssh_destination, config->ssh_port, config->fastsync_server_path);
|
||||||
if (!client)
|
if (!client)
|
||||||
return 1;
|
return 1;
|
||||||
} else if (config->use_tls) {
|
} else if (config->use_tls) {
|
||||||
|
|||||||
+13
-1
@@ -91,7 +91,19 @@ DirectoryScanner* directory_scanner_create_full(char* root_directory, bool use_m
|
|||||||
scanner->max_size = max_size;
|
scanner->max_size = max_size;
|
||||||
scanner->min_size = min_size;
|
scanner->min_size = min_size;
|
||||||
scanner->follow_symlinks = follow_symlinks;
|
scanner->follow_symlinks = follow_symlinks;
|
||||||
queue_enqueue(scanner->directories, str_dup(root_directory));
|
char* root_copy = str_dup(root_directory);
|
||||||
|
if (root_copy == NULL) {
|
||||||
|
for (int i = 0; i < scanner->include_count; i++)
|
||||||
|
free(scanner->include_patterns[i]);
|
||||||
|
free(scanner->include_patterns);
|
||||||
|
for (int i = 0; i < scanner->exclude_count; i++)
|
||||||
|
free(scanner->exclude_patterns[i]);
|
||||||
|
free(scanner->exclude_patterns);
|
||||||
|
queue_destroy(scanner->directories);
|
||||||
|
free(scanner);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
queue_enqueue(scanner->directories, root_copy);
|
||||||
return scanner;
|
return scanner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -23,6 +23,8 @@ static bool is_excluded(const char* path, const Config* config) {
|
|||||||
char* path_dup = str_dup(path);
|
char* path_dup = str_dup(path);
|
||||||
if (!path_dup)
|
if (!path_dup)
|
||||||
return false;
|
return false;
|
||||||
|
/* basename(3) may return a pointer into path_dup or a static buffer;
|
||||||
|
* either way we free path_dup, not fname. */
|
||||||
char* fname = basename(path_dup);
|
char* fname = basename(path_dup);
|
||||||
|
|
||||||
// Check exclude patterns
|
// Check exclude patterns
|
||||||
@@ -245,10 +247,9 @@ int main(int argc, char* argv[]) {
|
|||||||
server_listen(g_server, handler);
|
server_listen(g_server, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Graceful shutdown: if a signal requested cleanup, delete the server */
|
/* Graceful shutdown: delete the server */
|
||||||
if (g_server_cleanup_requested) {
|
if (g_server_cleanup_requested)
|
||||||
log_message(LOG_LEVEL_INFO, "Shutdown requested, cleaning up");
|
log_message(LOG_LEVEL_INFO, "Shutdown requested, cleaning up");
|
||||||
server_delete(&g_server);
|
server_delete(&g_server);
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-8
@@ -34,6 +34,7 @@ Config* config_create(char* version, char* send_directory, char* receive_directo
|
|||||||
config->ssh_port = 22;
|
config->ssh_port = 22;
|
||||||
config->transport = TRANSPORT_TCP;
|
config->transport = TRANSPORT_TCP;
|
||||||
config->ssh_destination = NULL;
|
config->ssh_destination = NULL;
|
||||||
|
config->fastsync_server_path = NULL;
|
||||||
config->exclude_patterns = NULL;
|
config->exclude_patterns = NULL;
|
||||||
config->exclude_count = 0;
|
config->exclude_count = 0;
|
||||||
config->include_patterns = NULL;
|
config->include_patterns = NULL;
|
||||||
@@ -82,10 +83,13 @@ void config_parse_ssh_dest(Config* config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void config_delete(Config* config) {
|
void config_delete(Config* config) {
|
||||||
|
if (config == NULL)
|
||||||
|
return;
|
||||||
free(config->version);
|
free(config->version);
|
||||||
free(config->send_directory);
|
free(config->send_directory);
|
||||||
free(config->receive_root_directory);
|
free(config->receive_root_directory);
|
||||||
free(config->ssh_destination);
|
free(config->ssh_destination);
|
||||||
|
free(config->fastsync_server_path);
|
||||||
for (int i = 0; i < config->exclude_count; i++)
|
for (int i = 0; i < config->exclude_count; i++)
|
||||||
free(config->exclude_patterns[i]);
|
free(config->exclude_patterns[i]);
|
||||||
free(config->exclude_patterns);
|
free(config->exclude_patterns);
|
||||||
@@ -236,6 +240,7 @@ Config* config_receive(int file_descriptor) {
|
|||||||
config->ssh_port = 22;
|
config->ssh_port = 22;
|
||||||
config->transport = TRANSPORT_TCP;
|
config->transport = TRANSPORT_TCP;
|
||||||
config->ssh_destination = NULL;
|
config->ssh_destination = NULL;
|
||||||
|
config->fastsync_server_path = NULL;
|
||||||
config->exclude_patterns = NULL;
|
config->exclude_patterns = NULL;
|
||||||
config->exclude_count = 0;
|
config->exclude_count = 0;
|
||||||
config->include_patterns = NULL;
|
config->include_patterns = NULL;
|
||||||
@@ -260,10 +265,6 @@ Config* config_receive(int file_descriptor) {
|
|||||||
MAX_PATTERN_COUNT);
|
MAX_PATTERN_COUNT);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if ((size_t)ec > SIZE_MAX / sizeof(char*)) {
|
|
||||||
log_message(LOG_LEVEL_ERROR, "Exclude pattern count %d would cause integer overflow", ec);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
config->exclude_count = ec;
|
config->exclude_count = ec;
|
||||||
if (ec > 0) {
|
if (ec > 0) {
|
||||||
config->exclude_patterns = malloc((size_t)ec * sizeof(char*));
|
config->exclude_patterns = malloc((size_t)ec * sizeof(char*));
|
||||||
@@ -293,10 +294,6 @@ Config* config_receive(int file_descriptor) {
|
|||||||
MAX_PATTERN_COUNT);
|
MAX_PATTERN_COUNT);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if ((size_t)ic > SIZE_MAX / sizeof(char*)) {
|
|
||||||
log_message(LOG_LEVEL_ERROR, "Include pattern count %d would cause integer overflow", ic);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
config->include_count = ic;
|
config->include_count = ic;
|
||||||
if (ic > 0) {
|
if (ic > 0) {
|
||||||
config->include_patterns = malloc((size_t)ic * sizeof(char*));
|
config->include_patterns = malloc((size_t)ic * sizeof(char*));
|
||||||
@@ -340,6 +337,16 @@ error:
|
|||||||
free(config->version);
|
free(config->version);
|
||||||
free(config->send_directory);
|
free(config->send_directory);
|
||||||
free(config->receive_root_directory);
|
free(config->receive_root_directory);
|
||||||
|
for (int i = 0; i < config->exclude_count; i++)
|
||||||
|
free(config->exclude_patterns[i]);
|
||||||
|
free(config->exclude_patterns);
|
||||||
|
for (int i = 0; i < config->include_count; i++)
|
||||||
|
free(config->include_patterns[i]);
|
||||||
|
free(config->include_patterns);
|
||||||
|
free(config->tls_cert);
|
||||||
|
free(config->tls_key);
|
||||||
|
free(config->tls_ca);
|
||||||
|
free(config->ssh_destination);
|
||||||
free(config->server_host);
|
free(config->server_host);
|
||||||
free(config);
|
free(config);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
+12
-1
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
typedef enum { TRANSPORT_TCP, TRANSPORT_SSH } TransportType;
|
typedef enum { TRANSPORT_TCP, TRANSPORT_SSH } TransportType;
|
||||||
|
|
||||||
@@ -24,6 +25,7 @@ typedef struct Config {
|
|||||||
int ssh_port;
|
int ssh_port;
|
||||||
TransportType transport;
|
TransportType transport;
|
||||||
char* ssh_destination;
|
char* ssh_destination;
|
||||||
|
char* fastsync_server_path;
|
||||||
char** exclude_patterns;
|
char** exclude_patterns;
|
||||||
int exclude_count;
|
int exclude_count;
|
||||||
char** include_patterns;
|
char** include_patterns;
|
||||||
@@ -40,11 +42,20 @@ typedef struct Config {
|
|||||||
char* tls_cert;
|
char* tls_cert;
|
||||||
char* tls_key;
|
char* tls_key;
|
||||||
char* tls_ca;
|
char* tls_ca;
|
||||||
|
int timeout;
|
||||||
|
int contimeout;
|
||||||
|
bool quiet;
|
||||||
|
bool backup;
|
||||||
|
char* backup_dir;
|
||||||
|
bool stats;
|
||||||
|
int max_depth;
|
||||||
|
FILE* log_file;
|
||||||
|
int queue_size;
|
||||||
bool follow_symlinks;
|
bool follow_symlinks;
|
||||||
bool partial;
|
bool partial;
|
||||||
} Config;
|
} Config;
|
||||||
|
|
||||||
#define PROTOCOL_VERSION "1.3.0"
|
#define PROTOCOL_VERSION "2.0.0"
|
||||||
#define DEFAULT_CHUNK_SIZE (10 * 1024 * 1024)
|
#define DEFAULT_CHUNK_SIZE (10 * 1024 * 1024)
|
||||||
|
|
||||||
Config* config_create(char* version, char* send_directory, char* receive_directory,
|
Config* config_create(char* version, char* send_directory, char* receive_directory,
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#include "data.h"
|
#include "data.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "stdlib.h"
|
#include <stdlib.h>
|
||||||
|
|
||||||
Data* data_create_empty(size_t data_size) {
|
Data* data_create_empty(size_t data_size) {
|
||||||
/* malloc(0) is UB; allocate at least 1 byte but preserve requested size */
|
/* malloc(0) is UB; allocate at least 1 byte but preserve requested size */
|
||||||
|
|||||||
+18
-22
@@ -3,6 +3,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -109,6 +110,9 @@ bool file_load_data(File* file) {
|
|||||||
size_t bytes_read = file_content_to_buffer(file);
|
size_t bytes_read = file_content_to_buffer(file);
|
||||||
if (bytes_read != file->data->size) {
|
if (bytes_read != file->data->size) {
|
||||||
log_message(LOG_LEVEL_ERROR, "Did not read expected amount of bytes from file");
|
log_message(LOG_LEVEL_ERROR, "Did not read expected amount of bytes from file");
|
||||||
|
free(file->data->data);
|
||||||
|
file->data->data = NULL;
|
||||||
|
file->data->size = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -140,11 +144,13 @@ static bool file_send_streaming(File* file, int file_descriptor) {
|
|||||||
if (ferror(fp)) {
|
if (ferror(fp)) {
|
||||||
perror("Read error during streaming");
|
perror("Read error during streaming");
|
||||||
}
|
}
|
||||||
|
send_status(file_descriptor, STATUS_ERROR);
|
||||||
free(buf);
|
free(buf);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!send_n_data(file_descriptor, buf, nread)) {
|
if (!send_n_data(file_descriptor, buf, nread)) {
|
||||||
|
send_status(file_descriptor, STATUS_ERROR);
|
||||||
free(buf);
|
free(buf);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return false;
|
return false;
|
||||||
@@ -200,25 +206,10 @@ bool file_send_single_calls(File* file, int file_descriptor, bool use_metadata,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool has_path_traversal(const char* path) {
|
|
||||||
// Check if ".." appears as a path component — at start, end, or between '/'
|
|
||||||
const char* p = path;
|
|
||||||
while ((p = strstr(p, "..")) != NULL) {
|
|
||||||
bool at_start = (p == path);
|
|
||||||
bool after_slash = (p > path && p[-1] == '/');
|
|
||||||
bool at_end = (p[2] == '\0');
|
|
||||||
bool before_slash = (p[2] == '/');
|
|
||||||
if ((at_start || after_slash) && (at_end || before_slash))
|
|
||||||
return true;
|
|
||||||
p += 2;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool file_save_to_disk(const char* root_directory, File* file) {
|
bool file_save_to_disk(const char* root_directory, File* file) {
|
||||||
if (file->type == FILE_TYPE_SYMLINK && file->link_target) {
|
if (file->type == FILE_TYPE_SYMLINK && file->link_target) {
|
||||||
// Validate link_target — reject absolute paths or traversal
|
// Validate link_target — reject absolute paths or traversal
|
||||||
if (file->link_target[0] == '/' || has_path_traversal(file->link_target)) {
|
if (file->link_target[0] == '/' || strstr(file->link_target, "..") != NULL) {
|
||||||
log_message(LOG_LEVEL_ERROR, "Path traversal blocked in symlink target: %s",
|
log_message(LOG_LEVEL_ERROR, "Path traversal blocked in symlink target: %s",
|
||||||
file->link_target);
|
file->link_target);
|
||||||
return false;
|
return false;
|
||||||
@@ -226,7 +217,7 @@ bool file_save_to_disk(const char* root_directory, File* file) {
|
|||||||
char* disk_path = path_cat((char*)root_directory, file->path);
|
char* disk_path = path_cat((char*)root_directory, file->path);
|
||||||
if (disk_path == NULL)
|
if (disk_path == NULL)
|
||||||
return false;
|
return false;
|
||||||
if (has_path_traversal(disk_path)) {
|
if (strstr(disk_path, "..") != NULL) {
|
||||||
log_message(LOG_LEVEL_ERROR, "Path traversal blocked: %s", disk_path);
|
log_message(LOG_LEVEL_ERROR, "Path traversal blocked: %s", disk_path);
|
||||||
free(disk_path);
|
free(disk_path);
|
||||||
return false;
|
return false;
|
||||||
@@ -242,7 +233,7 @@ bool file_save_to_disk(const char* root_directory, File* file) {
|
|||||||
char* disk_path = path_cat((char*)root_directory, file->path);
|
char* disk_path = path_cat((char*)root_directory, file->path);
|
||||||
if (disk_path == NULL)
|
if (disk_path == NULL)
|
||||||
return false;
|
return false;
|
||||||
if (has_path_traversal(disk_path)) {
|
if (strstr(disk_path, "..") != NULL) {
|
||||||
log_message(LOG_LEVEL_ERROR, "Path traversal blocked: %s", disk_path);
|
log_message(LOG_LEVEL_ERROR, "Path traversal blocked: %s", disk_path);
|
||||||
free(disk_path);
|
free(disk_path);
|
||||||
return false;
|
return false;
|
||||||
@@ -311,17 +302,21 @@ static bool receive_and_assign_metadata(int fd, const Config* config, File* file
|
|||||||
|
|
||||||
static File* receive_delta_file(int fd, const Config* config, const char* check_path,
|
static File* receive_delta_file(int fd, const Config* config, const char* check_path,
|
||||||
void* old_data, unsigned long long old_size) {
|
void* old_data, unsigned long long old_size) {
|
||||||
if (!old_data)
|
if (!old_data) {
|
||||||
|
send_status(fd, STATUS_ERROR);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
DeltaSignature* sig = delta_signature_create(old_data, old_size, config->delta_block_size);
|
DeltaSignature* sig = delta_signature_create(old_data, old_size, config->delta_block_size);
|
||||||
if (!sig) {
|
if (!sig) {
|
||||||
|
send_status(fd, STATUS_ERROR);
|
||||||
free(old_data);
|
free(old_data);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Data* sig_data = delta_signature_serialize(sig);
|
Data* sig_data = delta_signature_serialize(sig);
|
||||||
if (!sig_data) {
|
if (!sig_data) {
|
||||||
|
send_status(fd, STATUS_ERROR);
|
||||||
delta_signature_destroy(sig);
|
delta_signature_destroy(sig);
|
||||||
free(old_data);
|
free(old_data);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -533,7 +528,6 @@ File* receive_incremental_check(int fd, const Config* config, bool* skipped) {
|
|||||||
if (!receive_and_assign_metadata(fd, config, file))
|
if (!receive_and_assign_metadata(fd, config, file))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
// Read file type indicator
|
|
||||||
int file_type;
|
int file_type;
|
||||||
if (!receive_int(fd, &file_type)) {
|
if (!receive_int(fd, &file_type)) {
|
||||||
file_destroy(file);
|
file_destroy(file);
|
||||||
@@ -620,7 +614,6 @@ bool file_send_sendfile(File* file, int file_descriptor, bool use_metadata, int
|
|||||||
if (use_metadata && !metadata_send(file_descriptor, file->metadata))
|
if (use_metadata && !metadata_send(file_descriptor, file->metadata))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Send file type indicator
|
|
||||||
int ft = (int)file->type;
|
int ft = (int)file->type;
|
||||||
if (!send_int(file_descriptor, ft))
|
if (!send_int(file_descriptor, ft))
|
||||||
return false;
|
return false;
|
||||||
@@ -639,7 +632,10 @@ bool file_send_sendfile(File* file, int file_descriptor, bool use_metadata, int
|
|||||||
|
|
||||||
off_t offset = 0;
|
off_t offset = 0;
|
||||||
while ((unsigned long long)offset < file_size) {
|
while ((unsigned long long)offset < file_size) {
|
||||||
ssize_t sent = sendfile(file_descriptor, fd, &offset, file_size - offset);
|
size_t send_count = (size_t)(file_size - (unsigned long long)offset);
|
||||||
|
if ((unsigned long long)send_count != file_size - (unsigned long long)offset)
|
||||||
|
send_count = SIZE_MAX;
|
||||||
|
ssize_t sent = sendfile(file_descriptor, fd, &offset, send_count);
|
||||||
if (sent == -1) {
|
if (sent == -1) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
+4
-1
@@ -14,7 +14,10 @@ void log_message(LogLevel log_level, const char* format, ...) {
|
|||||||
if (log_level < current_log_level)
|
if (log_level < current_log_level)
|
||||||
return;
|
return;
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
const struct tm* t = localtime(&now);
|
struct tm result_buf;
|
||||||
|
const struct tm* t = localtime_r(&now, &result_buf);
|
||||||
|
if (t == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
fprintf(stderr, "%04d-%02d-%02d %02d:%02d:%02d [%s]: ", t->tm_year + 1900, t->tm_mon + 1,
|
fprintf(stderr, "%04d-%02d-%02d %02d:%02d:%02d [%s]: ", t->tm_year + 1900, t->tm_mon + 1,
|
||||||
t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, log_level_strings[log_level]);
|
t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, log_level_strings[log_level]);
|
||||||
|
|||||||
@@ -11,6 +11,19 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Wire format serialization (protocol version 2.0.0+):
|
||||||
|
* All metadata fields are serialized as fixed-width integers (int32_t / int64_t)
|
||||||
|
* to ensure cross-platform binary compatiblity. See metadata.h for the
|
||||||
|
* exact wire layout.
|
||||||
|
*
|
||||||
|
* Compile-time assertions verify that the native platform types fit within
|
||||||
|
* the chosen fixed-width representations.
|
||||||
|
*/
|
||||||
|
typedef char static_assert_mode_t_fits[(sizeof(mode_t) <= sizeof(int32_t)) ? 1 : -1];
|
||||||
|
typedef char static_assert_uid_t_fits[(sizeof(uid_t) <= sizeof(int32_t)) ? 1 : -1];
|
||||||
|
typedef char static_assert_gid_t_fits[(sizeof(gid_t) <= sizeof(int32_t)) ? 1 : -1];
|
||||||
|
|
||||||
void metadata_to_buf(char** buf, const FileMetadata* m) {
|
void metadata_to_buf(char** buf, const FileMetadata* m) {
|
||||||
int32_t present = (m != NULL) ? 1 : 0;
|
int32_t present = (m != NULL) ? 1 : 0;
|
||||||
memcpy(*buf, &present, sizeof(present));
|
memcpy(*buf, &present, sizeof(present));
|
||||||
|
|||||||
@@ -6,6 +6,23 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Wire format (introduced in protocol version 2.0.0):
|
||||||
|
* int32_t present
|
||||||
|
* int32_t mode (was mode_t, platform-dependent)
|
||||||
|
* int32_t uid (was uid_t, platform-dependent)
|
||||||
|
* int32_t gid (was gid_t, platform-dependent)
|
||||||
|
* int64_t mtime_sec (was time_t, platform-dependent)
|
||||||
|
* int64_t mtime_nsec (was long, platform-dependent)
|
||||||
|
*
|
||||||
|
* Prior to 2.0.0 the wire format used the raw platform-dependent types,
|
||||||
|
* which broke compatiblity across different systems. All fields are now
|
||||||
|
* serialized as fixed-width integers.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Size of metadata fields on wire, excluding the int32_t `present` field that
|
||||||
|
* is always sent first. The total wire size for present metadata is
|
||||||
|
* sizeof(int32_t) + FILE_METADATA_WIRE_SIZE (32 bytes on most platforms). */
|
||||||
#define FILE_METADATA_WIRE_SIZE (sizeof(int32_t) * 3 + sizeof(int64_t) * 2)
|
#define FILE_METADATA_WIRE_SIZE (sizeof(int32_t) * 3 + sizeof(int64_t) * 2)
|
||||||
|
|
||||||
void metadata_to_buf(char** buf, const FileMetadata* m);
|
void metadata_to_buf(char** buf, const FileMetadata* m);
|
||||||
|
|||||||
+10
-15
@@ -34,14 +34,11 @@ static void bw_throttle(size_t bytes_written) {
|
|||||||
struct timespec now;
|
struct timespec now;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
|
|
||||||
/* Use unsigned long long for elapsed_ns to avoid overflow in multiplication.
|
long long elapsed_ns =
|
||||||
* time_t differences fit comfortably in 64-bit for any practical runtime. */
|
(now.tv_sec - bw_last_refill.tv_sec) * 1000000000LL + (now.tv_nsec - bw_last_refill.tv_nsec);
|
||||||
unsigned long long elapsed_ns =
|
|
||||||
(unsigned long long)(now.tv_sec - bw_last_refill.tv_sec) * 1000000000ULL +
|
|
||||||
(unsigned long long)(now.tv_nsec - bw_last_refill.tv_nsec);
|
|
||||||
bw_last_refill = now;
|
bw_last_refill = now;
|
||||||
|
|
||||||
long long tokens_to_add = (long long)((double)io_bwlimit * (double)elapsed_ns / 1000000000.0);
|
long long tokens_to_add = (long long)((double)io_bwlimit * elapsed_ns / 1000000000.0);
|
||||||
bw_tokens += tokens_to_add;
|
bw_tokens += tokens_to_add;
|
||||||
if (bw_tokens > (long long)io_bwlimit)
|
if (bw_tokens > (long long)io_bwlimit)
|
||||||
bw_tokens = (long long)io_bwlimit;
|
bw_tokens = (long long)io_bwlimit;
|
||||||
@@ -49,9 +46,7 @@ static void bw_throttle(size_t bytes_written) {
|
|||||||
bw_tokens -= (long long)bytes_written;
|
bw_tokens -= (long long)bytes_written;
|
||||||
|
|
||||||
if (bw_tokens < 0) {
|
if (bw_tokens < 0) {
|
||||||
long long deficit_ns = (long long)((double)(-bw_tokens) / (double)io_bwlimit * 1000000000.0);
|
long long deficit_ns = (long long)((double)(-bw_tokens) / io_bwlimit * 1000000000.0);
|
||||||
if (deficit_ns < 0)
|
|
||||||
deficit_ns = 0;
|
|
||||||
struct timespec sleep_time, remaining;
|
struct timespec sleep_time, remaining;
|
||||||
sleep_time.tv_sec = deficit_ns / 1000000000LL;
|
sleep_time.tv_sec = deficit_ns / 1000000000LL;
|
||||||
sleep_time.tv_nsec = deficit_ns % 1000000000LL;
|
sleep_time.tv_nsec = deficit_ns % 1000000000LL;
|
||||||
@@ -112,7 +107,7 @@ bool receive_n_data(int file_descriptor, void* data, size_t data_size) {
|
|||||||
bytes_received =
|
bytes_received =
|
||||||
read(fd, (char*)data + total_bytes_received, data_size - total_bytes_received);
|
read(fd, (char*)data + total_bytes_received, data_size - total_bytes_received);
|
||||||
if (bytes_received <= 0) {
|
if (bytes_received <= 0) {
|
||||||
if (io_ssl) {
|
if (io_ssl && bytes_received < 0) {
|
||||||
int ssl_err = SSL_get_error(io_ssl, (int)bytes_received);
|
int ssl_err = SSL_get_error(io_ssl, (int)bytes_received);
|
||||||
if (ssl_err == SSL_ERROR_WANT_READ || ssl_err == SSL_ERROR_WANT_WRITE)
|
if (ssl_err == SSL_ERROR_WANT_READ || ssl_err == SSL_ERROR_WANT_WRITE)
|
||||||
continue;
|
continue;
|
||||||
@@ -193,18 +188,18 @@ bool send_data(int file_descriptor, const Data* data) {
|
|||||||
return false;
|
return false;
|
||||||
if (!send_n_data(file_descriptor, data->data, data_size))
|
if (!send_n_data(file_descriptor, data->data, data_size))
|
||||||
return false;
|
return false;
|
||||||
log_message(LOG_LEVEL_DEBUG, "Send %lld data", data_size);
|
log_message(LOG_LEVEL_DEBUG, "Send %llu data", data_size);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAX_DATA_SIZE (1024ULL * 1024 * 1024) // 1 GB
|
#define MAX_DATA_SIZE (1024ULL * 1024 * 1024)
|
||||||
|
|
||||||
Data* receive_data(int file_descriptor) {
|
Data* receive_data(int file_descriptor) {
|
||||||
unsigned long long size = 0;
|
unsigned long long size = 0;
|
||||||
if (!receive_n_data(file_descriptor, &size, sizeof(unsigned long long)))
|
if (!receive_n_data(file_descriptor, &size, sizeof(unsigned long long)))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (size > MAX_DATA_SIZE) {
|
if ((size_t)size != size || size > MAX_DATA_SIZE) {
|
||||||
log_message(LOG_LEVEL_ERROR, "receive_data: size %llu exceeds maximum", size);
|
log_message(LOG_LEVEL_ERROR, "receive_data size %llu exceeds limits", size);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
void* data = malloc((size_t)size);
|
void* data = malloc((size_t)size);
|
||||||
@@ -214,7 +209,7 @@ Data* receive_data(int file_descriptor) {
|
|||||||
free(data);
|
free(data);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
log_message(LOG_LEVEL_DEBUG, "Received %lld data", size);
|
log_message(LOG_LEVEL_DEBUG, "Received %llu data", size);
|
||||||
return data_create(data, (size_t)size);
|
return data_create(data, (size_t)size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ static int parse_remote_dest(const char* dest, RemoteDest* r) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Client* client_connect_ssh(const char* destination, int port) {
|
Client* client_connect_ssh(const char* destination, int port, const char* server_path) {
|
||||||
RemoteDest r;
|
RemoteDest r;
|
||||||
if (parse_remote_dest(destination, &r) != 0) {
|
if (parse_remote_dest(destination, &r) != 0) {
|
||||||
fprintf(stderr, "Invalid remote destination: %s\n", destination);
|
fprintf(stderr, "Invalid remote destination: %s\n", destination);
|
||||||
@@ -119,10 +119,13 @@ Client* client_connect_ssh(const char* destination, int port) {
|
|||||||
close(sv[1]);
|
close(sv[1]);
|
||||||
|
|
||||||
char ssh_user[512];
|
char ssh_user[512];
|
||||||
|
int needed;
|
||||||
if (r.user && r.user[0] != '\0')
|
if (r.user && r.user[0] != '\0')
|
||||||
snprintf(ssh_user, sizeof(ssh_user), "%s@%s", r.user, r.host);
|
needed = snprintf(ssh_user, sizeof(ssh_user), "%s@%s", r.user, r.host);
|
||||||
else
|
else
|
||||||
snprintf(ssh_user, sizeof(ssh_user), "%s", r.host);
|
needed = snprintf(ssh_user, sizeof(ssh_user), "%s", r.host);
|
||||||
|
if ((size_t)needed >= sizeof(ssh_user))
|
||||||
|
fprintf(stderr, "Warning: ssh_user string truncated\n");
|
||||||
|
|
||||||
size_t ssh_argv_max = 32;
|
size_t ssh_argv_max = 32;
|
||||||
char** ssh_argv = calloc(ssh_argv_max, sizeof(char*));
|
char** ssh_argv = calloc(ssh_argv_max, sizeof(char*));
|
||||||
@@ -149,7 +152,7 @@ Client* client_connect_ssh(const char* destination, int port) {
|
|||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
ssh_argv[ac++] = ssh_user;
|
ssh_argv[ac++] = ssh_user;
|
||||||
ssh_argv[ac++] = "fastsync-server";
|
ssh_argv[ac++] = (char*)(server_path ? server_path : "fastsync-server");
|
||||||
ssh_argv[ac++] = "--stdio";
|
ssh_argv[ac++] = "--stdio";
|
||||||
ssh_argv[ac] = NULL;
|
ssh_argv[ac] = NULL;
|
||||||
execvp("ssh", ssh_argv);
|
execvp("ssh", ssh_argv);
|
||||||
@@ -171,7 +174,8 @@ Client* client_connect_ssh(const char* destination, int port) {
|
|||||||
close(sv[0]);
|
close(sv[0]);
|
||||||
waitpid(pid, NULL, 0);
|
waitpid(pid, NULL, 0);
|
||||||
remote_dest_destroy(&r);
|
remote_dest_destroy(&r);
|
||||||
fprintf(stderr, "Error: could not launch 'fastsync-server --stdio' on remote\n");
|
fprintf(stderr, "Error: could not launch '%s --stdio' on remote\n",
|
||||||
|
server_path ? server_path : "fastsync-server");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
|
|
||||||
#include "transport_tcp.h"
|
#include "transport_tcp.h"
|
||||||
|
|
||||||
Client* client_connect_ssh(const char* destination, int port);
|
Client* client_connect_ssh(const char* destination, int port, const char* server_path);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -42,14 +42,13 @@ Server* server_create(int port) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memset(&server->address, 0, sizeof(server->address));
|
memset(&server->address, 0, sizeof(server->address));
|
||||||
server->ssl_ctx = NULL;
|
|
||||||
|
|
||||||
// Try IPv6 first, fall back to IPv4
|
// Try IPv6 first, fall back to IPv4
|
||||||
int domain = AF_INET6;
|
int fd = socket(AF_INET6, SOCK_STREAM, 0);
|
||||||
int fd = socket(domain, SOCK_STREAM, 0);
|
sa_family_t domain = AF_INET6;
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
|
fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
domain = AF_INET;
|
domain = AF_INET;
|
||||||
fd = socket(domain, SOCK_STREAM, 0);
|
|
||||||
}
|
}
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
perror("Could not create Socket!");
|
perror("Could not create Socket!");
|
||||||
@@ -64,6 +63,7 @@ Server* server_create(int port) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
server->file_descriptor = fd;
|
server->file_descriptor = fd;
|
||||||
|
server->ssl_ctx = NULL;
|
||||||
int opt = 1;
|
int opt = 1;
|
||||||
if (setsockopt(server->file_descriptor, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt))) {
|
if (setsockopt(server->file_descriptor, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt))) {
|
||||||
perror("Error setting a socket option!");
|
perror("Error setting a socket option!");
|
||||||
@@ -72,6 +72,7 @@ Server* server_create(int port) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use the domain from the socket we actually created
|
||||||
struct sockaddr_storage* addr = &server->address;
|
struct sockaddr_storage* addr = &server->address;
|
||||||
struct sockaddr_in* addr4 = (struct sockaddr_in*)addr;
|
struct sockaddr_in* addr4 = (struct sockaddr_in*)addr;
|
||||||
struct sockaddr_in6* addr6 = (struct sockaddr_in6*)addr;
|
struct sockaddr_in6* addr6 = (struct sockaddr_in6*)addr;
|
||||||
@@ -80,11 +81,13 @@ Server* server_create(int port) {
|
|||||||
addr6->sin6_family = AF_INET6;
|
addr6->sin6_family = AF_INET6;
|
||||||
addr6->sin6_addr = in6addr_any;
|
addr6->sin6_addr = in6addr_any;
|
||||||
addr6->sin6_port = htons(port);
|
addr6->sin6_port = htons(port);
|
||||||
|
addr->ss_family = AF_INET6;
|
||||||
server->address_length = sizeof(struct sockaddr_in6);
|
server->address_length = sizeof(struct sockaddr_in6);
|
||||||
} else {
|
} else {
|
||||||
addr4->sin_family = AF_INET;
|
addr4->sin_family = AF_INET;
|
||||||
addr4->sin_addr.s_addr = INADDR_ANY;
|
addr4->sin_addr.s_addr = INADDR_ANY;
|
||||||
addr4->sin_port = htons(port);
|
addr4->sin_port = htons(port);
|
||||||
|
addr->ss_family = AF_INET;
|
||||||
server->address_length = sizeof(struct sockaddr_in);
|
server->address_length = sizeof(struct sockaddr_in);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,10 +268,11 @@ bool client_connect(Client* client, char* host, int port) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save the connected address
|
// Save the connected address
|
||||||
size_t copy_len =
|
socklen_t addr_len = rp->ai_addrlen;
|
||||||
rp->ai_addrlen < sizeof(client->address) ? rp->ai_addrlen : sizeof(client->address);
|
if (addr_len > sizeof(client->address))
|
||||||
memcpy(&client->address, rp->ai_addr, copy_len);
|
addr_len = sizeof(client->address);
|
||||||
client->address_length = (int)copy_len;
|
memcpy(&client->address, rp->ai_addr, addr_len);
|
||||||
|
client->address_length = addr_len;
|
||||||
freeaddrinfo(res);
|
freeaddrinfo(res);
|
||||||
|
|
||||||
// Close old fd if any and set new one
|
// Close old fd if any and set new one
|
||||||
@@ -299,6 +303,7 @@ void client_disconnect(Client* client) {
|
|||||||
void client_delete(Client* client) {
|
void client_delete(Client* client) {
|
||||||
if (client == NULL)
|
if (client == NULL)
|
||||||
return;
|
return;
|
||||||
|
client_disconnect(client);
|
||||||
if (client->ssl_ctx) {
|
if (client->ssl_ctx) {
|
||||||
SSL_CTX_free(client->ssl_ctx);
|
SSL_CTX_free(client->ssl_ctx);
|
||||||
client->ssl_ctx = NULL;
|
client->ssl_ctx = NULL;
|
||||||
|
|||||||
+4
-5
@@ -134,7 +134,7 @@ static void delete_extras_walk(const char* abs_path, const char* rel_path, Array
|
|||||||
if (!dir)
|
if (!dir)
|
||||||
return;
|
return;
|
||||||
bool all_removed = true;
|
bool all_removed = true;
|
||||||
struct dirent* entry;
|
const struct dirent* entry;
|
||||||
while ((entry = readdir(dir)) != NULL) {
|
while ((entry = readdir(dir)) != NULL) {
|
||||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
||||||
continue;
|
continue;
|
||||||
@@ -184,18 +184,17 @@ void delete_extras(const char* dest_root, ArrayList* manifest) {
|
|||||||
delete_extras_walk(dest_root, "", manifest);
|
delete_extras_walk(dest_root, "", manifest);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* path_cat(const char* path1, char* path2) {
|
char* path_cat(const char* path1, const char* path2) {
|
||||||
if (path1 == NULL || *path1 == '\0')
|
if (path1 == NULL || *path1 == '\0')
|
||||||
return str_dup(path2);
|
return str_dup(path2);
|
||||||
if (path2 == NULL || *path2 == '\0')
|
if (path2 == NULL || *path2 == '\0')
|
||||||
return str_dup(path1);
|
return str_dup(path1);
|
||||||
int path1_len = strlen(path1);
|
int path1_len = strlen(path1);
|
||||||
int path2_len = strlen(path2);
|
int path2_len = strlen(path2);
|
||||||
char* path2_pointer = path2;
|
|
||||||
if (path1[path1_len - 1] == '/')
|
if (path1[path1_len - 1] == '/')
|
||||||
path1_len -= 1;
|
path1_len -= 1;
|
||||||
if (path2[0] == '/') {
|
if (path2[0] == '/') {
|
||||||
path2_pointer += 1;
|
path2++;
|
||||||
path2_len -= 1;
|
path2_len -= 1;
|
||||||
}
|
}
|
||||||
char* new_path = malloc(path1_len + path2_len + 2);
|
char* new_path = malloc(path1_len + path2_len + 2);
|
||||||
@@ -203,7 +202,7 @@ char* path_cat(const char* path1, char* path2) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
memcpy(new_path, path1, path1_len);
|
memcpy(new_path, path1, path1_len);
|
||||||
new_path[path1_len] = '/';
|
new_path[path1_len] = '/';
|
||||||
memcpy(new_path + path1_len + 1, path2_pointer, path2_len);
|
memcpy(new_path + path1_len + 1, path2, path2_len);
|
||||||
new_path[path1_len + path2_len + 1] = '\0';
|
new_path[path1_len + path2_len + 1] = '\0';
|
||||||
return new_path;
|
return new_path;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
bool mkdir_r(const char* path);
|
bool mkdir_r(const char* path);
|
||||||
char* str_dup(const char* string);
|
char* str_dup(const char* string);
|
||||||
char* path_cat(const char* path1, char* path2);
|
char* path_cat(const char* path1, const char* path2);
|
||||||
bool glob_match(const char* pattern, const char* str);
|
bool glob_match(const char* pattern, const char* str);
|
||||||
void delete_extras(const char* dest_root, ArrayList* manifest);
|
void delete_extras(const char* dest_root, ArrayList* manifest);
|
||||||
|
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ static void test_sendfile_no_path() {
|
|||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
close(p[1]);
|
close(p[1]);
|
||||||
/* Read file type indicator */
|
/* When send_path is false, the sender still sends file_type + data */
|
||||||
int file_type;
|
int file_type;
|
||||||
EXPECT_TRUE(receive_int(p[0], &file_type));
|
EXPECT_TRUE(receive_int(p[0], &file_type));
|
||||||
EXPECT_EQ_INT(file_type, (int)FILE_TYPE_REGULAR);
|
EXPECT_EQ_INT(file_type, (int)FILE_TYPE_REGULAR);
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ static void test_send_receive_str() {
|
|||||||
|
|
||||||
EXPECT_TRUE(send_str(0, ""));
|
EXPECT_TRUE(send_str(0, ""));
|
||||||
|
|
||||||
|
/* cppcheck-suppress constVariablePointer */
|
||||||
char* received = receive_str(0);
|
char* received = receive_str(0);
|
||||||
EXPECT_NOT_NULL(received);
|
EXPECT_NOT_NULL(received);
|
||||||
EXPECT_EQ_STR(received, "");
|
EXPECT_EQ_STR(received, "");
|
||||||
@@ -63,6 +64,7 @@ static void test_send_receive_str_normal() {
|
|||||||
|
|
||||||
EXPECT_TRUE(send_str(0, "Hello, Protocol!"));
|
EXPECT_TRUE(send_str(0, "Hello, Protocol!"));
|
||||||
|
|
||||||
|
/* cppcheck-suppress constVariablePointer */
|
||||||
char* received = receive_str(0);
|
char* received = receive_str(0);
|
||||||
EXPECT_NOT_NULL(received);
|
EXPECT_NOT_NULL(received);
|
||||||
EXPECT_EQ_STR(received, "Hello, Protocol!");
|
EXPECT_EQ_STR(received, "Hello, Protocol!");
|
||||||
@@ -78,6 +80,7 @@ static void test_send_receive_data() {
|
|||||||
io_set_fds(p[0], p[1]);
|
io_set_fds(p[0], p[1]);
|
||||||
io_set_bwlimit(0);
|
io_set_bwlimit(0);
|
||||||
|
|
||||||
|
/* cppcheck-suppress constVariablePointer */
|
||||||
unsigned char bin[] = {0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0xFF};
|
unsigned char bin[] = {0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0xFF};
|
||||||
void* buf = malloc(sizeof(bin));
|
void* buf = malloc(sizeof(bin));
|
||||||
EXPECT_NOT_NULL(buf);
|
EXPECT_NOT_NULL(buf);
|
||||||
@@ -128,6 +131,7 @@ static void test_send_receive_status() {
|
|||||||
io_set_fds(p[0], p[1]);
|
io_set_fds(p[0], p[1]);
|
||||||
io_set_bwlimit(0);
|
io_set_bwlimit(0);
|
||||||
|
|
||||||
|
/* cppcheck-suppress constVariablePointer */
|
||||||
Status statuses[] = {STATUS_OK, STATUS_ERROR, STATUS_FINISHED, STATUS_NEXT,
|
Status statuses[] = {STATUS_OK, STATUS_ERROR, STATUS_FINISHED, STATUS_NEXT,
|
||||||
STATUS_CHUNK, STATUS_CHECK, STATUS_DELTA_SIGNATURE, STATUS_DELTA_DATA};
|
STATUS_CHUNK, STATUS_CHECK, STATUS_DELTA_SIGNATURE, STATUS_DELTA_DATA};
|
||||||
int count = sizeof(statuses) / sizeof(statuses[0]);
|
int count = sizeof(statuses) / sizeof(statuses[0]);
|
||||||
@@ -179,8 +183,7 @@ static void test_receive_str_oversized() {
|
|||||||
size_t huge = MAX_STRING_SIZE + 1;
|
size_t huge = MAX_STRING_SIZE + 1;
|
||||||
EXPECT_TRUE(send_n_data(0, &huge, sizeof(size_t)));
|
EXPECT_TRUE(send_n_data(0, &huge, sizeof(size_t)));
|
||||||
|
|
||||||
/* cppcheck-suppress constVariablePointer */
|
const char* received = receive_str(0);
|
||||||
char* received = receive_str(0);
|
|
||||||
EXPECT_NULL(received);
|
EXPECT_NULL(received);
|
||||||
|
|
||||||
close(p[0]);
|
close(p[0]);
|
||||||
|
|||||||
+14
-27
@@ -15,7 +15,7 @@ static void test_scanner_single_file() {
|
|||||||
const char* file1 = "test_scan_dir_single/file1.txt";
|
const char* file1 = "test_scan_dir_single/file1.txt";
|
||||||
const char* content1 = "hello scanner";
|
const char* content1 = "hello scanner";
|
||||||
|
|
||||||
mkdir(dir, 0755);
|
EXPECT_EQ_INT(mkdir(dir, 0755), 0);
|
||||||
create_test_file(file1, content1);
|
create_test_file(file1, content1);
|
||||||
|
|
||||||
DirectoryScanner* scanner =
|
DirectoryScanner* scanner =
|
||||||
@@ -43,7 +43,7 @@ static void test_scanner_multiple_files() {
|
|||||||
const char* content1 = "alpha";
|
const char* content1 = "alpha";
|
||||||
const char* content2 = "beta";
|
const char* content2 = "beta";
|
||||||
|
|
||||||
mkdir(dir, 0755);
|
EXPECT_EQ_INT(mkdir(dir, 0755), 0);
|
||||||
create_test_file(file1, content1);
|
create_test_file(file1, content1);
|
||||||
create_test_file(file2, content2);
|
create_test_file(file2, content2);
|
||||||
|
|
||||||
@@ -82,8 +82,8 @@ static void test_scanner_subdirectory() {
|
|||||||
const char* sub_file = "test_scan_sub/sub/sub_file.txt";
|
const char* sub_file = "test_scan_sub/sub/sub_file.txt";
|
||||||
const char* content = "nested content";
|
const char* content = "nested content";
|
||||||
|
|
||||||
mkdir(root, 0755);
|
EXPECT_EQ_INT(mkdir(root, 0755), 0);
|
||||||
mkdir(sub, 0755);
|
EXPECT_EQ_INT(mkdir(sub, 0755), 0);
|
||||||
create_test_file(root_file, content);
|
create_test_file(root_file, content);
|
||||||
create_test_file(sub_file, content);
|
create_test_file(sub_file, content);
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ static void test_scanner_subdirectory() {
|
|||||||
static void test_scanner_empty_directory() {
|
static void test_scanner_empty_directory() {
|
||||||
const char* dir = "test_scan_empty";
|
const char* dir = "test_scan_empty";
|
||||||
|
|
||||||
mkdir(dir, 0755);
|
EXPECT_EQ_INT(mkdir(dir, 0755), 0);
|
||||||
|
|
||||||
DirectoryScanner* scanner =
|
DirectoryScanner* scanner =
|
||||||
directory_scanner_create((char*)dir, false, 0, NULL, 0, NULL, 0, 0, 0);
|
directory_scanner_create((char*)dir, false, 0, NULL, 0, NULL, 0, 0, 0);
|
||||||
@@ -130,7 +130,7 @@ static void test_scanner_exclude_pattern() {
|
|||||||
const char* f_tmp = "test_scan_excl/remove.tmp";
|
const char* f_tmp = "test_scan_excl/remove.tmp";
|
||||||
const char* content = "data";
|
const char* content = "data";
|
||||||
|
|
||||||
mkdir(dir, 0755);
|
EXPECT_EQ_INT(mkdir(dir, 0755), 0);
|
||||||
create_test_file(f_txt, content);
|
create_test_file(f_txt, content);
|
||||||
create_test_file(f_tmp, content);
|
create_test_file(f_tmp, content);
|
||||||
|
|
||||||
@@ -154,8 +154,6 @@ static void test_scanner_exclude_pattern() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void test_scanner_exclude_subdirectory() {
|
static void test_scanner_exclude_subdirectory() {
|
||||||
/* Exclude patterns match filenames only (via entry->d_name).
|
|
||||||
* Files inside subdirectories are also matched by filename. */
|
|
||||||
const char* root = "test_scan_excl_sub";
|
const char* root = "test_scan_excl_sub";
|
||||||
const char* sub = "test_scan_excl_sub/sub";
|
const char* sub = "test_scan_excl_sub/sub";
|
||||||
const char* root_txt = "test_scan_excl_sub/root.txt";
|
const char* root_txt = "test_scan_excl_sub/root.txt";
|
||||||
@@ -163,13 +161,12 @@ static void test_scanner_exclude_subdirectory() {
|
|||||||
const char* sub_tmp = "test_scan_excl_sub/sub/temp.tmp";
|
const char* sub_tmp = "test_scan_excl_sub/sub/temp.tmp";
|
||||||
const char* content = "data";
|
const char* content = "data";
|
||||||
|
|
||||||
mkdir(root, 0755);
|
EXPECT_EQ_INT(mkdir(root, 0755), 0);
|
||||||
mkdir(sub, 0755);
|
EXPECT_EQ_INT(mkdir(sub, 0755), 0);
|
||||||
create_test_file(root_txt, content);
|
create_test_file(root_txt, content);
|
||||||
create_test_file(sub_txt, content);
|
create_test_file(sub_txt, content);
|
||||||
create_test_file(sub_tmp, content);
|
create_test_file(sub_tmp, content);
|
||||||
|
|
||||||
/* Exclude *.tmp — should exclude sub/temp.tmp but keep root.txt and sub/data.txt */
|
|
||||||
char* exclude[] = {"*.tmp"};
|
char* exclude[] = {"*.tmp"};
|
||||||
DirectoryScanner* scanner =
|
DirectoryScanner* scanner =
|
||||||
directory_scanner_create((char*)root, false, 0, exclude, 1, NULL, 0, 0, 0);
|
directory_scanner_create((char*)root, false, 0, exclude, 1, NULL, 0, 0, 0);
|
||||||
@@ -180,7 +177,6 @@ static void test_scanner_exclude_subdirectory() {
|
|||||||
while ((chunk = directory_scanner_next(scanner)) != NULL) {
|
while ((chunk = directory_scanner_next(scanner)) != NULL) {
|
||||||
total += chunk->element_count;
|
total += chunk->element_count;
|
||||||
for (int i = 0; i < chunk->element_count; i++) {
|
for (int i = 0; i < chunk->element_count; i++) {
|
||||||
/* No path should end in .tmp */
|
|
||||||
size_t len = strlen(chunk->items[i]->path);
|
size_t len = strlen(chunk->items[i]->path);
|
||||||
EXPECT_TRUE(len < 4 || strcmp(chunk->items[i]->path + len - 4, ".tmp") != 0);
|
EXPECT_TRUE(len < 4 || strcmp(chunk->items[i]->path + len - 4, ".tmp") != 0);
|
||||||
}
|
}
|
||||||
@@ -197,22 +193,17 @@ static void test_scanner_exclude_subdirectory() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void test_scanner_include_and_exclude() {
|
static void test_scanner_include_and_exclude() {
|
||||||
/* In the scanner, exclude is checked first and takes precedence.
|
|
||||||
* Include patterns act as an additional filter: if include_count > 0,
|
|
||||||
* the file must match one of the include patterns (after not being excluded).
|
|
||||||
* This test uses non-overlapping exclude and include patterns. */
|
|
||||||
const char* dir = "test_scan_inc_exc";
|
const char* dir = "test_scan_inc_exc";
|
||||||
const char* f_txt = "test_scan_inc_exc/a.txt";
|
const char* f_txt = "test_scan_inc_exc/a.txt";
|
||||||
const char* f_log = "test_scan_inc_exc/b.log";
|
const char* f_log = "test_scan_inc_exc/b.log";
|
||||||
const char* f_bak = "test_scan_inc_exc/c.bak";
|
const char* f_bak = "test_scan_inc_exc/c.bak";
|
||||||
const char* content = "filter";
|
const char* content = "filter";
|
||||||
|
|
||||||
mkdir(dir, 0755);
|
EXPECT_EQ_INT(mkdir(dir, 0755), 0);
|
||||||
create_test_file(f_txt, content);
|
create_test_file(f_txt, content);
|
||||||
create_test_file(f_log, content);
|
create_test_file(f_log, content);
|
||||||
create_test_file(f_bak, content);
|
create_test_file(f_bak, content);
|
||||||
|
|
||||||
/* Exclude *.bak. Include *.txt and *.log. */
|
|
||||||
char* exclude[] = {"*.bak"};
|
char* exclude[] = {"*.bak"};
|
||||||
char* include[] = {"*.txt", "*.log"};
|
char* include[] = {"*.txt", "*.log"};
|
||||||
DirectoryScanner* scanner =
|
DirectoryScanner* scanner =
|
||||||
@@ -230,7 +221,6 @@ static void test_scanner_include_and_exclude() {
|
|||||||
if (strstr(chunk->items[i]->path, "b.log"))
|
if (strstr(chunk->items[i]->path, "b.log"))
|
||||||
found_log = 1;
|
found_log = 1;
|
||||||
}
|
}
|
||||||
/* a.txt included by *.txt, b.log included by *.log, c.bak excluded by *.bak */
|
|
||||||
EXPECT_TRUE(found_txt);
|
EXPECT_TRUE(found_txt);
|
||||||
EXPECT_TRUE(found_log);
|
EXPECT_TRUE(found_log);
|
||||||
|
|
||||||
@@ -248,10 +238,7 @@ static void test_scanner_max_size() {
|
|||||||
const char* dir = "test_scan_max";
|
const char* dir = "test_scan_max";
|
||||||
const char* small = "test_scan_max/small.txt";
|
const char* small = "test_scan_max/small.txt";
|
||||||
const char* large = "test_scan_max/large.txt";
|
const char* large = "test_scan_max/large.txt";
|
||||||
create_test_file(small, "tiny");
|
EXPECT_EQ_INT(mkdir(dir, 0755), 0);
|
||||||
create_test_file(large, "this_content_is_longer_than_ten_chars");
|
|
||||||
|
|
||||||
mkdir(dir, 0755);
|
|
||||||
create_test_file(small, "tiny");
|
create_test_file(small, "tiny");
|
||||||
create_test_file(large, "this_content_is_longer_than_ten_chars");
|
create_test_file(large, "this_content_is_longer_than_ten_chars");
|
||||||
|
|
||||||
@@ -279,7 +266,7 @@ static void test_scanner_min_size() {
|
|||||||
const char* empty_f = "test_scan_min/empty.txt";
|
const char* empty_f = "test_scan_min/empty.txt";
|
||||||
const char* data_f = "test_scan_min/data.txt";
|
const char* data_f = "test_scan_min/data.txt";
|
||||||
|
|
||||||
mkdir(dir, 0755);
|
EXPECT_EQ_INT(mkdir(dir, 0755), 0);
|
||||||
create_test_file(empty_f, "");
|
create_test_file(empty_f, "");
|
||||||
create_test_file(data_f, "some content here");
|
create_test_file(data_f, "some content here");
|
||||||
|
|
||||||
@@ -308,7 +295,7 @@ static void test_scanner_size_range() {
|
|||||||
const char* medium = "test_scan_range/med.txt";
|
const char* medium = "test_scan_range/med.txt";
|
||||||
const char* huge = "test_scan_range/huge.txt";
|
const char* huge = "test_scan_range/huge.txt";
|
||||||
|
|
||||||
mkdir(dir, 0755);
|
EXPECT_EQ_INT(mkdir(dir, 0755), 0);
|
||||||
create_test_file(tiny, "ab");
|
create_test_file(tiny, "ab");
|
||||||
create_test_file(medium, "hello world");
|
create_test_file(medium, "hello world");
|
||||||
create_test_file(huge, "this is a much larger file for testing size filters");
|
create_test_file(huge, "this is a much larger file for testing size filters");
|
||||||
@@ -341,7 +328,7 @@ static void test_scanner_mixed_patterns() {
|
|||||||
const char* c_txt = "test_scan_mixed/c.txt"; /* size ~= 5 */
|
const char* c_txt = "test_scan_mixed/c.txt"; /* size ~= 5 */
|
||||||
const char* d_bak = "test_scan_mixed/d.bak"; /* size ~= 42 */
|
const char* d_bak = "test_scan_mixed/d.bak"; /* size ~= 42 */
|
||||||
|
|
||||||
mkdir(dir, 0755);
|
EXPECT_EQ_INT(mkdir(dir, 0755), 0);
|
||||||
create_test_file(a_txt, "aaaaa");
|
create_test_file(a_txt, "aaaaa");
|
||||||
create_test_file(b_bin, "bbbbbbbbbbbbb");
|
create_test_file(b_bin, "bbbbbbbbbbbbb");
|
||||||
create_test_file(c_txt, "ccccc");
|
create_test_file(c_txt, "ccccc");
|
||||||
@@ -377,7 +364,7 @@ static void test_scanner_no_patterns() {
|
|||||||
const char* f1 = "test_scan_none/f1.txt";
|
const char* f1 = "test_scan_none/f1.txt";
|
||||||
const char* f2 = "test_scan_none/f2.txt";
|
const char* f2 = "test_scan_none/f2.txt";
|
||||||
|
|
||||||
mkdir(dir, 0755);
|
EXPECT_EQ_INT(mkdir(dir, 0755), 0);
|
||||||
create_test_file(f1, "first");
|
create_test_file(f1, "first");
|
||||||
create_test_file(f2, "second");
|
create_test_file(f2, "second");
|
||||||
|
|
||||||
|
|||||||
@@ -9,14 +9,14 @@
|
|||||||
static void test_ssh_connect_invalid_dest() {
|
static void test_ssh_connect_invalid_dest() {
|
||||||
/* Missing colon — parse_remote_dest should fail and return NULL */
|
/* Missing colon — parse_remote_dest should fail and return NULL */
|
||||||
/* cppcheck-suppress constVariablePointer */
|
/* cppcheck-suppress constVariablePointer */
|
||||||
Client* client = client_connect_ssh("invalid-destination-no-colon", 22);
|
Client* client = client_connect_ssh("invalid-destination-no-colon", 22, NULL);
|
||||||
EXPECT_NULL(client);
|
EXPECT_NULL(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test client_connect_ssh with empty destination */
|
/* Test client_connect_ssh with empty destination */
|
||||||
static void test_ssh_connect_empty_dest() {
|
static void test_ssh_connect_empty_dest() {
|
||||||
/* cppcheck-suppress constVariablePointer */
|
/* cppcheck-suppress constVariablePointer */
|
||||||
Client* client = client_connect_ssh("", 22);
|
Client* client = client_connect_ssh("", 22, NULL);
|
||||||
EXPECT_NULL(client);
|
EXPECT_NULL(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ static void test_ssh_connect_empty_dest() {
|
|||||||
* parse_remote_dest succeeds, ssh is exec'd and fails, but the function
|
* parse_remote_dest succeeds, ssh is exec'd and fails, but the function
|
||||||
* creates a Client that must be cleaned up. */
|
* creates a Client that must be cleaned up. */
|
||||||
static void test_ssh_connect_malformed() {
|
static void test_ssh_connect_malformed() {
|
||||||
Client* client = client_connect_ssh(":", 22);
|
Client* client = client_connect_ssh(":", 22, NULL);
|
||||||
/* ssh binary exists, so exec succeeds; the function returns a Client.
|
/* ssh binary exists, so exec succeeds; the function returns a Client.
|
||||||
* We just verify it doesn't crash and clean up properly. */
|
* We just verify it doesn't crash and clean up properly. */
|
||||||
if (client != NULL) {
|
if (client != NULL) {
|
||||||
@@ -37,7 +37,7 @@ static void test_ssh_connect_malformed() {
|
|||||||
/* Test client_connect_ssh with valid format but unreachable host.
|
/* Test client_connect_ssh with valid format but unreachable host.
|
||||||
* The function launches ssh which will fail to connect, returns a Client. */
|
* The function launches ssh which will fail to connect, returns a Client. */
|
||||||
static void test_ssh_connect_unreachable() {
|
static void test_ssh_connect_unreachable() {
|
||||||
Client* client = client_connect_ssh("nonexistent.invalid:/remote/path", 22);
|
Client* client = client_connect_ssh("nonexistent.invalid:/remote/path", 22, NULL);
|
||||||
if (client != NULL) {
|
if (client != NULL) {
|
||||||
client_disconnect(client);
|
client_disconnect(client);
|
||||||
client_delete(client);
|
client_delete(client);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ static void test_client_create_delete() {
|
|||||||
Client* client = client_create();
|
Client* client = client_create();
|
||||||
EXPECT_NOT_NULL(client);
|
EXPECT_NOT_NULL(client);
|
||||||
EXPECT_EQ_INT(client->file_descriptor, -1);
|
EXPECT_EQ_INT(client->file_descriptor, -1);
|
||||||
EXPECT_TRUE(client->address.ss_family == AF_UNSPEC);
|
EXPECT_EQ_INT(client->address.ss_family, AF_UNSPEC);
|
||||||
EXPECT_EQ_INT(client->ssh_child_pid, -1);
|
EXPECT_EQ_INT(client->ssh_child_pid, -1);
|
||||||
EXPECT_NULL(client->ssl);
|
EXPECT_NULL(client->ssl);
|
||||||
EXPECT_NULL(client->ssl_ctx);
|
EXPECT_NULL(client->ssl_ctx);
|
||||||
|
|||||||
Reference in New Issue
Block a user