forked from cory/tildefriends
ios: Add a EULA to try to appease Apple's Guideline 1.2 - Safety - User-Generated Content.
This commit is contained in:
110
src/ssb.db.c
110
src/ssb.db.c
@@ -2186,56 +2186,40 @@ bool tf_ssb_db_identity_get_active(sqlite3* db, const char* user, const char* pa
|
||||
return found;
|
||||
}
|
||||
|
||||
typedef struct _resolve_index_t
|
||||
const char* tf_ssb_db_resolve_index(sqlite3* db, const char* host)
|
||||
{
|
||||
const char* host;
|
||||
const char* path;
|
||||
void (*callback)(const char* path, void* user_data);
|
||||
void* user_data;
|
||||
} resolve_index_t;
|
||||
const char* result = NULL;
|
||||
|
||||
static void _tf_ssb_db_resolve_index_work(tf_ssb_t* ssb, void* user_data)
|
||||
{
|
||||
resolve_index_t* request = user_data;
|
||||
|
||||
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
|
||||
sqlite3_stmt* statement;
|
||||
if (sqlite3_prepare_v2(db, "SELECT json_extract(value, '$.index_map') FROM properties WHERE id = 'core' AND key = 'settings'", -1, &statement, NULL) == SQLITE_OK)
|
||||
if (!result)
|
||||
{
|
||||
if (sqlite3_step(statement) == SQLITE_ROW)
|
||||
{
|
||||
const char* index_map = (const char*)sqlite3_column_text(statement, 0);
|
||||
const char* start = index_map;
|
||||
while (start)
|
||||
{
|
||||
const char* end = strchr(start, '\n');
|
||||
const char* equals = strchr(start, '=');
|
||||
if (equals && strncasecmp(request->host, start, equals - start) == 0)
|
||||
{
|
||||
size_t value_length = end && equals < end ? (size_t)(end - (equals + 1)) : strlen(equals + 1);
|
||||
char* path = tf_malloc(value_length + 1);
|
||||
memcpy(path, equals + 1, value_length);
|
||||
path[value_length] = '\0';
|
||||
request->path = path;
|
||||
break;
|
||||
}
|
||||
start = end ? end + 1 : NULL;
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(statement);
|
||||
}
|
||||
else
|
||||
{
|
||||
tf_printf("prepare failed: %s\n", sqlite3_errmsg(db));
|
||||
/* Maybe we need to force the EULA first. */
|
||||
}
|
||||
|
||||
if (!request->path)
|
||||
if (!result)
|
||||
{
|
||||
if (sqlite3_prepare_v2(db, "SELECT json_extract(value, '$.index') FROM properties WHERE id = 'core' AND key = 'settings'", -1, &statement, NULL) == SQLITE_OK)
|
||||
/* Use the index_map setting. */
|
||||
sqlite3_stmt* statement;
|
||||
if (sqlite3_prepare_v2(db, "SELECT json_extract(value, '$.index_map') FROM properties WHERE id = 'core' AND key = 'settings'", -1, &statement, NULL) == SQLITE_OK)
|
||||
{
|
||||
if (sqlite3_step(statement) == SQLITE_ROW)
|
||||
{
|
||||
request->path = tf_strdup((const char*)sqlite3_column_text(statement, 0));
|
||||
const char* index_map = (const char*)sqlite3_column_text(statement, 0);
|
||||
const char* start = index_map;
|
||||
while (start)
|
||||
{
|
||||
const char* end = strchr(start, '\n');
|
||||
const char* equals = strchr(start, '=');
|
||||
if (equals && strncasecmp(host, start, equals - start) == 0)
|
||||
{
|
||||
size_t value_length = end && equals < end ? (size_t)(end - (equals + 1)) : strlen(equals + 1);
|
||||
char* path = tf_malloc(value_length + 1);
|
||||
memcpy(path, equals + 1, value_length);
|
||||
path[value_length] = '\0';
|
||||
result = path;
|
||||
break;
|
||||
}
|
||||
start = end ? end + 1 : NULL;
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(statement);
|
||||
}
|
||||
@@ -2244,32 +2228,32 @@ static void _tf_ssb_db_resolve_index_work(tf_ssb_t* ssb, void* user_data)
|
||||
tf_printf("prepare failed: %s\n", sqlite3_errmsg(db));
|
||||
}
|
||||
}
|
||||
tf_ssb_release_db_reader(ssb, db);
|
||||
|
||||
if (!request->path)
|
||||
if (!result)
|
||||
{
|
||||
request->path = tf_strdup(tf_util_get_default_global_setting_string("index"));
|
||||
/* Use the index setting. */
|
||||
sqlite3_stmt* statement;
|
||||
if (sqlite3_prepare_v2(db, "SELECT json_extract(value, '$.index') FROM properties WHERE id = 'core' AND key = 'settings'", -1, &statement, NULL) == SQLITE_OK)
|
||||
{
|
||||
if (sqlite3_step(statement) == SQLITE_ROW)
|
||||
{
|
||||
result = tf_strdup((const char*)sqlite3_column_text(statement, 0));
|
||||
}
|
||||
sqlite3_finalize(statement);
|
||||
}
|
||||
else
|
||||
{
|
||||
tf_printf("prepare failed: %s\n", sqlite3_errmsg(db));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void _tf_ssb_db_resolve_index_after_work(tf_ssb_t* ssb, int status, void* user_data)
|
||||
{
|
||||
resolve_index_t* request = user_data;
|
||||
request->callback(request->path, request->user_data);
|
||||
tf_free((void*)request->host);
|
||||
tf_free((void*)request->path);
|
||||
tf_free(request);
|
||||
}
|
||||
if (!result)
|
||||
{
|
||||
/* Use the default index. */
|
||||
result = tf_strdup(tf_util_get_default_global_setting_string("index"));
|
||||
}
|
||||
|
||||
void tf_ssb_db_resolve_index_async(tf_ssb_t* ssb, const char* host, void (*callback)(const char* path, void* user_data), void* user_data)
|
||||
{
|
||||
resolve_index_t* request = tf_malloc(sizeof(resolve_index_t));
|
||||
*request = (resolve_index_t) {
|
||||
.host = tf_strdup(host),
|
||||
.callback = callback,
|
||||
.user_data = user_data,
|
||||
};
|
||||
tf_ssb_run_work(ssb, _tf_ssb_db_resolve_index_work, _tf_ssb_db_resolve_index_after_work, request);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void _tf_ssb_db_set_flags(tf_ssb_t* ssb, const char* message_id, int flags)
|
||||
@@ -2514,7 +2498,7 @@ bool tf_ssb_db_set_global_setting_from_string(sqlite3* db, const char* name, cha
|
||||
bound = sqlite3_bind_int(statement, 2, value && (strcmp(value, "true") == 0 || atoi(value))) == SQLITE_OK;
|
||||
break;
|
||||
case k_kind_int:
|
||||
bound = sqlite3_bind_int(statement, 2, atoi(value)) == SQLITE_OK;
|
||||
bound = sqlite3_bind_int64(statement, 2, atoll(value)) == SQLITE_OK;
|
||||
break;
|
||||
case k_kind_string:
|
||||
bound = sqlite3_bind_text(statement, 2, value, -1, NULL) == SQLITE_OK;
|
||||
|
||||
Reference in New Issue
Block a user