Skip to content

Commit 1cf482f

Browse files
committed
fix(apple-network): fix port handling and error messages
1 parent 880c862 commit 1cf482f

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

Makefile

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ endif
136136
T_LDFLAGS += -fprofile-arcs -ftest-coverage
137137
endif
138138

139+
# Native network support only for Apple platforms
140+
ifdef NATIVE_NETWORK
141+
RELEASE_OBJ += $(patsubst %.m, $(BUILD_RELEASE)/%_m.o, $(notdir $(wildcard $(SRC_DIR)/*.m)))
142+
LDFLAGS += -framework Foundation
143+
CFLAGS += -DCLOUDSYNC_OMIT_CURL
144+
145+
$(BUILD_RELEASE)/%_m.o: %.m
146+
$(CC) $(CFLAGS) -O3 -fPIC -c $< -o $@
147+
endif
148+
139149
# Windows .def file generation
140150
$(DEF_FILE):
141151
ifeq ($(PLATFORM),windows)
@@ -314,15 +324,15 @@ clean:
314324
help:
315325
@echo "SQLite Sync Extension Makefile"
316326
@echo "Usage:"
317-
@echo " make [PLATFORM=platform] [ARCH=arch] [ANDROID_NDK=\$$ANDROID_HOME/ndk/26.1.10909125] [target]"
327+
@echo " make [PLATFORM=platform] [ARCH=arch] [ANDROID_NDK=\$$ANDROID_HOME/ndk/26.1.10909125] [NATIVE_NETWORK=ON] [target]"
318328
@echo ""
319329
@echo "Platforms:"
320330
@echo " linux (default on Linux)"
321-
@echo " macos (default on macOS)"
331+
@echo " macos (default on macOS - can be compiled with native network support)"
322332
@echo " windows (default on Windows)"
323333
@echo " android (needs ARCH to be set to x86_64 or arm64-v8a and ANDROID_NDK to be set)"
324-
@echo " ios (only on macOS)"
325-
@echo " isim (only on macOS)"
334+
@echo " ios (only on macOS - can be compiled with native network support)"
335+
@echo " isim (only on macOS - can be compiled with native network support)"
326336
@echo " wasm (needs wabt[brew install wabt/sudo apt install wabt])"
327337
@echo ""
328338
@echo "Targets:"

src/network.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ bool network_compute_endpoints (sqlite3_context *context, network_data *data, co
5858
}
5959

6060
char *site_id = network_data_get_siteid(data);
61-
char *port_or_default = (port) ? (char *)port.UTF8String : CLOUDSYNC_DEFAULT_ENDPOINT_PORT;
61+
char *port_or_default = (port && strcmp(port.UTF8String, "8860") != 0) ? (char *)port.UTF8String : CLOUDSYNC_DEFAULT_ENDPOINT_PORT;
6262

6363
NSString *check_endpoint = [NSString stringWithFormat:@"%s://%s:%s/%s%s/%s", scheme.UTF8String, host.UTF8String, port_or_default, CLOUDSYNC_ENDPOINT_PREFIX, database.UTF8String, site_id];
6464
NSString *upload_endpoint = [NSString stringWithFormat: @"%s://%s:%s/%s%s/%s/%s", scheme.UTF8String, host.UTF8String, port_or_default, CLOUDSYNC_ENDPOINT_PREFIX, database.UTF8String, site_id, CLOUDSYNC_ENDPOINT_UPLOAD];
@@ -188,7 +188,18 @@ NETWORK_RESULT network_receive_buffer(network_data *data, const char *endpoint,
188188

189189
// return error
190190
NETWORK_RESULT result = {};
191-
NSString *msg = (responseError) ? [responseError localizedDescription] : [NSString stringWithCString:"Unknown network URL" encoding:NSUTF8StringEncoding];
191+
NSString *msg;
192+
if (responseError) {
193+
msg = [responseError localizedDescription];
194+
} else if (responseData && [responseData length] > 0) {
195+
// Use the actual response body as the error message
196+
msg = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
197+
if (!msg) {
198+
msg = [NSString stringWithCString:"Invalid error response encoding" encoding:NSUTF8StringEncoding];
199+
}
200+
} else {
201+
msg = [NSString stringWithFormat:@"HTTP %ld error", (long)statusCode];
202+
}
192203
result.code = CLOUDSYNC_NETWORK_ERROR;
193204
result.buffer = (char *)msg.UTF8String;
194205
result.xdata = (void *)CFBridgingRetain(msg);

0 commit comments

Comments
 (0)