Skip to content

Commit 04c1066

Browse files
committed
Minor refactor
1 parent 723841d commit 04c1066

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

src/cloudsync.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3156,6 +3156,15 @@ APIEXPORT int sqlite3_cloudsync_init (sqlite3 *db, char **pzErrMsg, const sqlite
31563156
rc = dbutils_register_function(db, "cloudsync_network_decode", cloudsync_network_decode, -1, pzErrMsg, ctx, NULL);
31573157
if (rc != SQLITE_OK) return rc;
31583158

3159+
rc = dbutils_register_function(db, "cloudsync_begin_alter", cloudsync_begin_alter, 1, pzErrMsg, ctx, NULL);
3160+
if (rc != SQLITE_OK) return rc;
3161+
3162+
rc = dbutils_register_function(db, "cloudsync_commit_alter", cloudsync_commit_alter, 1, pzErrMsg, ctx, NULL);
3163+
if (rc != SQLITE_OK) return rc;
3164+
3165+
rc = dbutils_register_function(db, "cloudsync_uuid", cloudsync_uuid, 0, pzErrMsg, ctx, NULL);
3166+
if (rc != SQLITE_OK) return rc;
3167+
31593168
// PRIVATE functions
31603169
rc = dbutils_register_function(db, "cloudsync_is_sync", cloudsync_is_sync, 1, pzErrMsg, ctx, NULL);
31613170
if (rc != SQLITE_OK) return rc;
@@ -3181,15 +3190,6 @@ APIEXPORT int sqlite3_cloudsync_init (sqlite3 *db, char **pzErrMsg, const sqlite
31813190
rc = dbutils_register_function(db, "cloudsync_seq", cloudsync_seq, 0, pzErrMsg, ctx, NULL);
31823191
if (rc != SQLITE_OK) return rc;
31833192

3184-
rc = dbutils_register_function(db, "cloudsync_begin_alter", cloudsync_begin_alter, 1, pzErrMsg, ctx, NULL);
3185-
if (rc != SQLITE_OK) return rc;
3186-
3187-
rc = dbutils_register_function(db, "cloudsync_commit_alter", cloudsync_commit_alter, 1, pzErrMsg, ctx, NULL);
3188-
if (rc != SQLITE_OK) return rc;
3189-
3190-
rc = dbutils_register_function(db, "cloudsync_uuid", cloudsync_uuid, 0, pzErrMsg, ctx, NULL);
3191-
if (rc != SQLITE_OK) return rc;
3192-
31933193
// NETWORK LAYER
31943194
#ifndef CLOUDSYNC_OMIT_NETWORK
31953195
rc = cloudsync_network_register(db, pzErrMsg, ctx);

src/network.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ typedef struct {
5454
size_t blen; // blen if code is SQLITE_OK, rc in case of error
5555
} NETWORK_RESULT;
5656

57+
typedef struct {
58+
const char *data;
59+
size_t size;
60+
size_t read_pos;
61+
} network_read_data;
62+
5763
// MARK: -
5864

5965
static bool network_buffer_check (network_buffer *data, size_t needed) {
@@ -155,12 +161,6 @@ static NETWORK_RESULT network_receive_buffer (network_data *data, const char *en
155161
return result;
156162
}
157163

158-
typedef struct {
159-
const char *data;
160-
size_t size;
161-
size_t read_pos;
162-
} network_read_data;
163-
164164
static size_t network_read_callback(char *buffer, size_t size, size_t nitems, void *userdata) {
165165
network_read_data *rd = (network_read_data *)userdata;
166166
size_t max_read = size * nitems;
@@ -292,7 +292,7 @@ char *network_authentication_token(const char *key, const char *value) {
292292
return buffer;
293293
}
294294

295-
int extract_query_param(const char *query, const char *key, char *output, size_t output_size) {
295+
int network_extract_query_param(const char *query, const char *key, char *output, size_t output_size) {
296296
if (!query || !key || !output || output_size == 0) {
297297
return -1; // Invalid input
298298
}
@@ -380,10 +380,10 @@ bool network_compute_endpoints (sqlite3_context *context, network_data *data, co
380380
if (rc != CURLE_OK && rc != CURLUE_NO_QUERY) goto finalize;
381381
if (query != NULL) {
382382
char value[MAX_QUERY_VALUE_LEN];
383-
if (!authentication && extract_query_param(query, "apikey", value, sizeof(value)) == 0) {
383+
if (!authentication && network_extract_query_param(query, "apikey", value, sizeof(value)) == 0) {
384384
authentication = network_authentication_token("apikey", value);
385385
}
386-
if (!authentication && extract_query_param(query, "token", value, sizeof(value)) == 0) {
386+
if (!authentication && network_extract_query_param(query, "token", value, sizeof(value)) == 0) {
387387
authentication = network_authentication_token("token", value);
388388
}
389389
}
@@ -428,6 +428,12 @@ bool network_compute_endpoints (sqlite3_context *context, network_data *data, co
428428
return result;
429429
}
430430

431+
void network_result_to_sqlite_error (sqlite3_context *context, NETWORK_RESULT res, const char *default_error_message) {
432+
sqlite3_result_error(context, ((res.code == CLOUDSYNC_NETWORK_ERROR) && (res.buffer)) ? res.buffer : default_error_message, -1);
433+
sqlite3_result_error_code(context, ((res.code == CLOUDSYNC_NETWORK_ERROR) && (res.blen)) ? (int)res.blen : SQLITE_ERROR);
434+
if (res.buffer) cloudsync_memory_free(res.buffer);
435+
}
436+
431437
// MARK: -
432438

433439
void cloudsync_network_init (sqlite3_context *context, int argc, sqlite3_value **argv) {
@@ -532,12 +538,6 @@ void cloudsync_network_set_apikey (sqlite3_context *context, int argc, sqlite3_v
532538

533539
// MARK: -
534540

535-
void network_result_to_sqlite_error (sqlite3_context *context, NETWORK_RESULT res, const char *default_error_message) {
536-
sqlite3_result_error(context, ((res.code == CLOUDSYNC_NETWORK_ERROR) && (res.buffer)) ? res.buffer : default_error_message, -1);
537-
sqlite3_result_error_code(context, ((res.code == CLOUDSYNC_NETWORK_ERROR) && (res.blen)) ? (int)res.blen : SQLITE_ERROR);
538-
if (res.buffer) cloudsync_memory_free(res.buffer);
539-
}
540-
541541
void cloudsync_network_send_changes (sqlite3_context *context, int argc, sqlite3_value **argv) {
542542
DEBUG_FUNCTION("cloudsync_network_send_changes");
543543

0 commit comments

Comments
 (0)