|
|
@@ -72,7 +72,7 @@ static void MongoFree(MONGO * info) {
|
|
|
if(info) {
|
|
|
if(info->uri) mongoc_uri_destroy(info->uri);
|
|
|
if(info->client) mongoc_client_destroy(info->client);
|
|
|
- turn_free(info, sizeof(MONGO));
|
|
|
+ turn_free(info, sizeof(MONGO));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -860,7 +860,8 @@ static int mongo_set_realm_option_one(u08bits *realm, unsigned long value, const
|
|
|
BSON_APPEND_UTF8(&query, "realm", (const char *)realm);
|
|
|
bson_init(&doc);
|
|
|
|
|
|
- char * _k = (char *)turn_malloc(9 + strlen(opt));
|
|
|
+ size_t klen = 9 + strlen(opt);
|
|
|
+ char * _k = (char *)turn_malloc(klen);
|
|
|
strcpy(_k, "options.");
|
|
|
strcat(_k, opt);
|
|
|
|
|
|
@@ -873,7 +874,7 @@ static int mongo_set_realm_option_one(u08bits *realm, unsigned long value, const
|
|
|
BSON_APPEND_INT32(&child, _k, 1);
|
|
|
bson_append_document_end(&doc, &child);
|
|
|
}
|
|
|
- free(_k);
|
|
|
+ turn_free(_k,klen);
|
|
|
|
|
|
int ret = -1;
|
|
|
|
|
|
@@ -1010,113 +1011,129 @@ static int mongo_get_ip_list(const char *kind, ip_range_list_t * list) {
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-static void mongo_reread_realms(secrets_list_t * realms_list) {
|
|
|
- UNUSED_ARG(realms_list);
|
|
|
-
|
|
|
- mongoc_collection_t * collection = mongo_get_collection("realm");
|
|
|
-
|
|
|
- if(!collection)
|
|
|
- return;
|
|
|
|
|
|
- bson_t query;
|
|
|
- bson_init(&query);
|
|
|
+static void mongo_reread_realms(secrets_list_t * realms_list) {
|
|
|
|
|
|
- bson_t fields;
|
|
|
- bson_init(&fields);
|
|
|
- BSON_APPEND_INT32(&fields, "realm", 1);
|
|
|
- BSON_APPEND_INT32(&fields, "origin", 1);
|
|
|
- BSON_APPEND_INT32(&fields, "options", 1);
|
|
|
-
|
|
|
- mongoc_cursor_t * cursor;
|
|
|
- cursor = mongoc_collection_find(collection, MONGOC_QUERY_NONE, 0, 0, 0, &query, &fields, NULL);
|
|
|
+ UNUSED_ARG(realms_list);
|
|
|
|
|
|
- if (!cursor) {
|
|
|
- TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Error querying MongoDB collection 'realm'\n");
|
|
|
- } else {
|
|
|
- ur_string_map *o_to_realm_new = ur_string_map_create(free);
|
|
|
+ mongoc_collection_t * collection = mongo_get_collection("realm");
|
|
|
|
|
|
- const bson_t * item;
|
|
|
- uint32_t length;
|
|
|
- bson_iter_t iter;
|
|
|
-
|
|
|
- while (mongoc_cursor_next(cursor, &item)) {
|
|
|
- if (bson_iter_init(&iter, item) && bson_iter_find(&iter, "realm") && BSON_ITER_HOLDS_UTF8(&iter)) {
|
|
|
- char * _realm = strdup(bson_iter_utf8(&iter, &length));
|
|
|
+ if (!collection)
|
|
|
+ return;
|
|
|
|
|
|
- get_realm(_realm);
|
|
|
+ bson_t query;
|
|
|
+ bson_init(&query);
|
|
|
|
|
|
- if (bson_iter_init(&iter, item) && bson_iter_find(&iter, "origin") && BSON_ITER_HOLDS_ARRAY(&iter)) {
|
|
|
- const uint8_t *docbuf = NULL;
|
|
|
- uint32_t doclen = 0;
|
|
|
- bson_t origin_array;
|
|
|
- bson_iter_t origin_iter;
|
|
|
+ bson_t fields;
|
|
|
+ bson_init(&fields);
|
|
|
+ BSON_APPEND_INT32(&fields, "realm", 1);
|
|
|
+ BSON_APPEND_INT32(&fields, "origin", 1);
|
|
|
+ BSON_APPEND_INT32(&fields, "options", 1);
|
|
|
|
|
|
- bson_iter_array(&iter, &doclen, &docbuf);
|
|
|
- bson_init_static(&origin_array, docbuf, doclen);
|
|
|
+ mongoc_cursor_t * cursor;
|
|
|
+ cursor = mongoc_collection_find(collection, MONGOC_QUERY_NONE, 0, 0, 0,
|
|
|
+ &query, &fields, NULL);
|
|
|
|
|
|
- if (bson_iter_init(&origin_iter, &origin_array)) {
|
|
|
- while(bson_iter_next(&origin_iter)) {
|
|
|
- if (BSON_ITER_HOLDS_UTF8(&origin_iter)) {
|
|
|
- char * _origin = strdup(bson_iter_utf8(&origin_iter, &length));
|
|
|
- char *rval = strdup(_realm);
|
|
|
- ur_string_map_value_type value = (ur_string_map_value_type)(rval);
|
|
|
- ur_string_map_put(o_to_realm_new, (const ur_string_map_key_type) _origin, value);
|
|
|
- free(_origin);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- realm_params_t* rp = get_realm(_realm);
|
|
|
- lock_realms();
|
|
|
- rp->options.perf_options.max_bps = turn_params.max_bps;
|
|
|
- rp->options.perf_options.total_quota = turn_params.total_quota;
|
|
|
- rp->options.perf_options.user_quota = turn_params.user_quota;
|
|
|
- unlock_realms();
|
|
|
+ if (!cursor) {
|
|
|
+ TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR,
|
|
|
+ "Error querying MongoDB collection 'realm'\n");
|
|
|
+ } else {
|
|
|
+ ur_string_map *o_to_realm_new = ur_string_map_create(turn_free_simple);
|
|
|
|
|
|
- if (bson_iter_init(&iter, item) && bson_iter_find(&iter, "options") && BSON_ITER_HOLDS_DOCUMENT(&iter)) {
|
|
|
- const uint8_t *docbuf = NULL;
|
|
|
- uint32_t doclen = 0;
|
|
|
- bson_t options;
|
|
|
- bson_iter_t options_iter;
|
|
|
+ const bson_t * item;
|
|
|
+ uint32_t length;
|
|
|
+ bson_iter_t iter;
|
|
|
|
|
|
- bson_iter_document(&iter, &doclen, &docbuf);
|
|
|
- bson_init_static(&options, docbuf, doclen);
|
|
|
+ while (mongoc_cursor_next(cursor, &item)) {
|
|
|
+
|
|
|
+ if (bson_iter_init(&iter, item) && bson_iter_find(&iter, "realm")
|
|
|
+ && BSON_ITER_HOLDS_UTF8(&iter)) {
|
|
|
+
|
|
|
+ char * _realm = turn_strdup(bson_iter_utf8(&iter, &length));
|
|
|
+
|
|
|
+ get_realm(_realm);
|
|
|
+
|
|
|
+ if (bson_iter_init(&iter, item) && bson_iter_find(&iter,
|
|
|
+ "origin") && BSON_ITER_HOLDS_ARRAY(&iter)) {
|
|
|
+ const uint8_t *docbuf = NULL;
|
|
|
+ uint32_t doclen = 0;
|
|
|
+ bson_t origin_array;
|
|
|
+ bson_iter_t origin_iter;
|
|
|
+
|
|
|
+ bson_iter_array(&iter, &doclen, &docbuf);
|
|
|
+ bson_init_static(&origin_array, docbuf, doclen);
|
|
|
+
|
|
|
+ if (bson_iter_init(&origin_iter, &origin_array)) {
|
|
|
+ while (bson_iter_next(&origin_iter)) {
|
|
|
+ if (BSON_ITER_HOLDS_UTF8(&origin_iter)) {
|
|
|
+ char* _origin = turn_strdup(bson_iter_utf8(&origin_iter, &length));
|
|
|
+ char *rval = turn_strdup(_realm);
|
|
|
+ ur_string_map_value_type value =
|
|
|
+ (ur_string_map_value_type) (rval);
|
|
|
+ ur_string_map_put(o_to_realm_new,
|
|
|
+ (const ur_string_map_key_type) _origin,
|
|
|
+ value);
|
|
|
+ turn_free(_origin,strlen(_origin)+1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (bson_iter_init(&options_iter, &options)) {
|
|
|
- while(bson_iter_next(&options_iter)) {
|
|
|
- const char * _k = bson_iter_key(&options_iter);
|
|
|
- int32_t _v = 0;
|
|
|
- if (BSON_ITER_HOLDS_DOUBLE(&options_iter)) {
|
|
|
- _v = (int32_t)bson_iter_double(&options_iter);
|
|
|
- } else if (BSON_ITER_HOLDS_INT32(&options_iter)) {
|
|
|
- _v = bson_iter_int32(&options_iter);
|
|
|
- } else if (BSON_ITER_HOLDS_INT64(&options_iter)) {
|
|
|
- _v = (int32_t)bson_iter_int64(&options_iter);
|
|
|
- }
|
|
|
- if (_v) {
|
|
|
- if(!strcmp(_k,"max-bps"))
|
|
|
- rp->options.perf_options.max_bps = (band_limit_t)_v;
|
|
|
- else if(!strcmp(_k,"total-quota"))
|
|
|
- rp->options.perf_options.total_quota = (vint)_v;
|
|
|
- else if(!strcmp(_k,"user-quota"))
|
|
|
- rp->options.perf_options.user_quota = (vint)_v;
|
|
|
+ realm_params_t* rp = get_realm(_realm);
|
|
|
+ lock_realms();
|
|
|
+ rp->options.perf_options.max_bps = turn_params.max_bps;
|
|
|
+ rp->options.perf_options.total_quota = turn_params.total_quota;
|
|
|
+ rp->options.perf_options.user_quota = turn_params.user_quota;
|
|
|
+ unlock_realms();
|
|
|
+
|
|
|
+ if (bson_iter_init(&iter, item) && bson_iter_find(&iter,
|
|
|
+ "options") && BSON_ITER_HOLDS_DOCUMENT(&iter)) {
|
|
|
+ const uint8_t *docbuf = NULL;
|
|
|
+ uint32_t doclen = 0;
|
|
|
+ bson_t options;
|
|
|
+ bson_iter_t options_iter;
|
|
|
+
|
|
|
+ bson_iter_document(&iter, &doclen, &docbuf);
|
|
|
+ bson_init_static(&options, docbuf, doclen);
|
|
|
+
|
|
|
+ if (bson_iter_init(&options_iter, &options)) {
|
|
|
+ while (bson_iter_next(&options_iter)) {
|
|
|
+ const char * _k = bson_iter_key(&options_iter);
|
|
|
+ int32_t _v = 0;
|
|
|
+ if (BSON_ITER_HOLDS_DOUBLE(&options_iter)) {
|
|
|
+ _v = (int32_t) bson_iter_double(&options_iter);
|
|
|
+ } else if (BSON_ITER_HOLDS_INT32(&options_iter)) {
|
|
|
+ _v = bson_iter_int32(&options_iter);
|
|
|
+ } else if (BSON_ITER_HOLDS_INT64(&options_iter)) {
|
|
|
+ _v = (int32_t) bson_iter_int64(&options_iter);
|
|
|
+ }
|
|
|
+ if (_v) {
|
|
|
+ if (!strcmp(_k, "max-bps"))
|
|
|
+ rp->options.perf_options.max_bps
|
|
|
+ = (band_limit_t) _v;
|
|
|
+ else if (!strcmp(_k, "total-quota"))
|
|
|
+ rp->options.perf_options.total_quota
|
|
|
+ = (vint) _v;
|
|
|
+ else if (!strcmp(_k, "user-quota"))
|
|
|
+ rp->options.perf_options.user_quota
|
|
|
+ = (vint) _v;
|
|
|
else {
|
|
|
- TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Unknown realm option: %s\n", _k);
|
|
|
+ TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR,
|
|
|
+ "Unknown realm option: %s\n", _k);
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- free(_realm);
|
|
|
- }
|
|
|
- }
|
|
|
- update_o_to_realm(o_to_realm_new);
|
|
|
- mongoc_cursor_destroy(cursor);
|
|
|
- }
|
|
|
- mongoc_collection_destroy(collection);
|
|
|
- bson_destroy(&query);
|
|
|
- bson_destroy(&fields);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ turn_free(_realm,strlen(_realm)+1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ update_o_to_realm(o_to_realm_new);
|
|
|
+ mongoc_cursor_destroy(cursor);
|
|
|
+ }
|
|
|
+ mongoc_collection_destroy(collection);
|
|
|
+ bson_destroy(&query);
|
|
|
+ bson_destroy(&fields);
|
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|