Skip to content

Commit 6ad10b7

Browse files
authored
Create Network.md
1 parent 57e25fe commit 6ad10b7

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

docs/Network.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
Starting from **CloudSync version 0.8.3**, the built-in network layer (based on **libcurl**) can be easily replaced with a custom implementation.
2+
3+
#### How It Works
4+
5+
The CloudSync core library provides an abstraction for network operations used to send and receive data during synchronization. By default, it uses libcurl internally. However, you can disable the built-in libcurl support and provide your own network implementation.
6+
7+
This is useful when:
8+
9+
* You want to reduce dependencies on libcurl.
10+
* You need to integrate CloudSync with platform-native networking (such as NSURLSession on Apple platforms).
11+
* You want to use a different networking stack (e.g. for embedded environments, or custom transports).
12+
13+
#### Steps to Provide a Custom Network Layer
14+
15+
1. **Disable libcurl**
16+
17+
Define the following preprocessor macro in your build system or project:
18+
19+
```c
20+
#define CLOUDSYNC_OMIT_CURL
21+
```
22+
23+
This will exclude the default libcurl-based implementation from your build.
24+
25+
2. **Include the network interface**
26+
27+
Include the CloudSync internal header that defines the required network API:
28+
29+
```c
30+
#include "network_private.h"
31+
```
32+
33+
3. **Implement the required functions**
34+
35+
You must provide implementations for the following C functions:
36+
37+
```c
38+
bool network_compute_endpoints (sqlite3_context *context, network_data *data, const char *conn_string);
39+
40+
// Parses `conn_string` and fills the `network_data` structure with connection information (e.g. base URL, endpoints, credentials).
41+
// Returns `true` on success, `false` on error (you can use `sqlite3_result_error` to report errors to SQLite).
42+
43+
```
44+
45+
```c
46+
bool network_send_buffer (network_data *data, const char *endpoint, const char *authentication, const void *blob, int blob_size);
47+
48+
// Sends the provided `blob` (binary data) to the specified `endpoint`, using the given `authentication` token or header.
49+
// Returns `true` on success, `false` on failure.
50+
```
51+
52+
```c
53+
NETWORK_RESULT network_receive_buffer (network_data *data, const char *endpoint, const char *authentication, bool zero_terminated, bool is_post_request, char *json_payload, const char *custom_header);
54+
55+
// Performs a network request (GET or POST depending on `is_post_request`) to the specified `endpoint`, using the given `authentication` token or header.
56+
// If `json_payload` is provided, it will be sent as the POST body (for `is_post_request == true`).
57+
// If `zero_terminated == true`, ensure that the returned buffer is null-terminated.
58+
// Returns a `NETWORK_RESULT` enum value indicating success, error, or timeout.
59+
```
60+
61+
#### Platform-Specific Notes
62+
63+
* On **macOS**, **iOS**, and **iPadOS**, a native Objective-C implementation is already provided: `network.m`.
64+
You can use this as a reference or directly include it in your build if you want to use Apple's networking APIs (NSURLSession).
65+
66+
#### Example Use Case
67+
68+
To integrate CloudSync with your own networking stack (e.g. based on `libhttp`, `Boost::Beast`, or a proprietary stack), implement the required functions above and link your network code instead of libcurl.

0 commit comments

Comments
 (0)