diff --git a/bin/ej-jobs.c b/bin/ej-jobs.c index 37492deeee..b47def4617 100644 --- a/bin/ej-jobs.c +++ b/bin/ej-jobs.c @@ -2026,12 +2026,4 @@ job_server_force_link[] = ej_bson_parse_string_new, }; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - -void * -job_server_force_link[] = -{ - ej_bson_parse_string, -}; - #endif diff --git a/include/ejudge/bson_utils.h b/include/ejudge/bson_utils.h index a1c83b963b..2e57dc9916 100644 --- a/include/ejudge/bson_utils.h +++ b/include/ejudge/bson_utils.h @@ -26,7 +26,7 @@ struct _bson; struct _bson_cursor; -// for libmogoc +// for libmongoc struct _bson_t; // FIXME: no opaque structure tag for bson_iter_t diff --git a/include/ejudge/common_mongo_plugin.h b/include/ejudge/common_mongo_plugin.h index bee8715100..9c546d9c15 100644 --- a/include/ejudge/common_mongo_plugin.h +++ b/include/ejudge/common_mongo_plugin.h @@ -30,12 +30,6 @@ struct _bson_t; typedef struct _mongoc_client_t ej_mongo_conn_t; typedef struct _bson_t ej_bson_t; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 -struct _mongo_sync_connection; -struct _bson; - -typedef struct _mongo_sync_connection ej_mongo_conn_t; -typedef struct _bson ej_bson_t; #else struct mongo_connection_missing; struct bson_definition_missing; diff --git a/lib/bson_utils.c b/lib/bson_utils.c index 69b572657d..bdbcf6bc8a 100644 --- a/lib/bson_utils.c +++ b/lib/bson_utils.c @@ -16,453 +16,6 @@ #include "ejudge/config.h" -#if HAVE_LIBMONGO_CLIENT - 0 == 1 - -#include "ejudge/bson_utils.h" -#include "ejudge/ej_uuid.h" -#include "ejudge/errlog.h" -#include "ejudge/xml_utils.h" - -#include "ejudge/xalloc.h" - -#include - -void -ej_bson_unparse( - FILE *out, - const struct _bson *b, - int is_array) -{ - if (!b) { - fprintf(out, "NULL"); - return; - } - if (is_array) { - fprintf(out, "[ "); - } else { - fprintf(out, "{ "); - } - bson_cursor *cursor = bson_cursor_new(b); - int first = 1; - while (bson_cursor_next(cursor)) { - if (!first) fprintf(out, ", "); - if (!is_array) { - fprintf(out, "%s : ", bson_cursor_key(cursor)); - } - bson_type t = bson_cursor_type(cursor); - switch (t) { - case BSON_TYPE_DOUBLE: - break; - case BSON_TYPE_STRING: - { - const char *value = NULL; - if (bson_cursor_get_string(cursor, &value)) { - fprintf(out, "\"%s\"", value); - } - } - break; - case BSON_TYPE_DOCUMENT: - { - bson *doc = NULL; - if (bson_cursor_get_document(cursor, &doc)) { - ej_bson_unparse(out, doc, 0); - bson_free(doc); - } - } - break; - case BSON_TYPE_ARRAY: - { - bson *doc = NULL; - if (bson_cursor_get_array(cursor, &doc)) { - ej_bson_unparse(out, doc, 1); - bson_free(doc); - } - } - break; - case BSON_TYPE_BINARY: - { - bson_binary_subtype bt = 0; - const unsigned char *bd = NULL; - int bz = 0; - if (bson_cursor_get_binary(cursor, &bt, &bd, &bz) - && bt == BSON_BINARY_SUBTYPE_UUID && bz == sizeof(ej_uuid_t)) { - ej_uuid_t value; - memcpy(&value, bd, sizeof(value)); - fprintf(out, "\"%s\"", ej_uuid_unparse(&value, NULL)); - } - } - break; - case BSON_TYPE_OID: - break; - case BSON_TYPE_BOOLEAN: - { - gboolean bb = 0; - if (bson_cursor_get_boolean(cursor, &bb)) { - fprintf(out, "%s", bb?"true":"false"); - } - } - break; - case BSON_TYPE_UTC_DATETIME: - { - gint64 ts = 0; - if (bson_cursor_get_utc_datetime(cursor, &ts)) { - time_t tt = (time_t) (ts / 1000); - int ms = (int) (ts % 1000); - struct tm *ptm = gmtime(&tt); - fprintf(out, "\"%d-%02d-%02d %02d:%02d:%02d.%04d\"", - ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, - ptm->tm_hour, ptm->tm_min, ptm->tm_sec, ms); - } - } - break; - case BSON_TYPE_NULL: - break; - case BSON_TYPE_INT32: - { - int value = 0; - if (bson_cursor_get_int32(cursor, &value)) { - fprintf(out, "%d", value); - } - } - break; - case BSON_TYPE_INT64: - { - gint64 value = 0; - if (bson_cursor_get_int64(cursor, &value)) { - fprintf(out, "%lld", (long long) value); - } - } - break; - default: - break; - } - first = 0; - } - bson_cursor_free(cursor); cursor = NULL; - if (is_array) { - fprintf(out, " ]"); - } else { - fprintf(out, " }"); - } -} - -int -ej_bson_parse_int( - struct _bson_cursor *bc, - const unsigned char *field_name, - int *p_value, - int check_low, - int low_value, - int check_high, - int high_value) -{ - if (bson_cursor_type(bc) != BSON_TYPE_INT32) { - err("parse_bson_int: int32 field type expected for '%s'", field_name); - return -1; - } - int value = 0; - if (!bson_cursor_get_int32(bc, &value)) { - err("parse_bson_int: failed to fetch int32 value of '%s'", field_name); - return -1; - } - if ((check_low > 0 && value < low_value) || (check_high > 0 && value >= high_value)) { - err("parse_bson_int: invalid value of '%s': %d", field_name, value); - return -1; - } - *p_value = value; - return 1; -} - -int -ej_bson_parse_int64( - struct _bson_cursor *bc, - const unsigned char *field_name, - long long *p_value) -{ - if (bson_cursor_type(bc) != BSON_TYPE_INT64) { - err("parse_bson_int: int64 field type expected for '%s'", field_name); - return -1; - } - gint64 value = 0; - if (!bson_cursor_get_int64(bc, &value)) { - err("parse_bson_int: failed to fetch int64 value of '%s'", field_name); - return -1; - } - *p_value = value; - return 1; -} - -int -ej_bson_parse_boolean( - struct _bson_cursor *bc, - const unsigned char *field_name, - int *p_value) -{ - if (bson_cursor_type(bc) != BSON_TYPE_BOOLEAN) { - err("parse_bson_boolean: boolean field type expected for '%s'", field_name); - return -1; - } - gboolean value = 0; - if (!bson_cursor_get_boolean(bc, &value)) { - err("parse_bson_boolean: failed to fetch boolean value of '%s'", field_name); - return -1; - } - *p_value = !!value; - return 1; -} - -int -ej_bson_parse_boolean_uc( - struct _bson_cursor *bc, - const unsigned char *field_name, - unsigned char *p_value) -{ - if (bson_cursor_type(bc) != BSON_TYPE_BOOLEAN) { - err("parse_bson_boolean: boolean field type expected for '%s'", field_name); - return -1; - } - gboolean value = 0; - if (!bson_cursor_get_boolean(bc, &value)) { - err("parse_bson_boolean: failed to fetch boolean value of '%s'", field_name); - return -1; - } - *p_value = !!value; - return 1; -} - -int -ej_bson_parse_utc_datetime( - struct _bson_cursor *bc, - const unsigned char *field_name, - time_t *p_value) -{ - if (bson_cursor_type(bc) != BSON_TYPE_UTC_DATETIME) { - err("parse_bson_utc_datetime: utc_datetime field type expected for '%s'", field_name); - return -1; - } - gint64 value = 0; - if (!bson_cursor_get_utc_datetime(bc, &value)) { - err("parse_bson_utc_datetime: failed to fetch utc_datetime value of '%s'", field_name); - return -1; - } - if (p_value) { - *p_value = (time_t) (value / 1000); - } - return 1; -} - -int -ej_bson_parse_utc_datetime_64( - struct _bson_cursor *bc, - const unsigned char *field_name, - ej_time64_t *p_value) -{ - if (bson_cursor_type(bc) != BSON_TYPE_UTC_DATETIME) { - err("parse_bson_utc_datetime: utc_datetime field type expected for '%s'", field_name); - return -1; - } - gint64 value = 0; - if (!bson_cursor_get_utc_datetime(bc, &value)) { - err("parse_bson_utc_datetime: failed to fetch utc_datetime value of '%s'", field_name); - return -1; - } - if (p_value) { - *p_value = value / 1000LL; - } - return 1; -} - -int -ej_bson_parse_uuid( - struct _bson_cursor *bc, - const unsigned char *field_name, - ej_uuid_t *p_value) -{ - if (bson_cursor_type(bc) != BSON_TYPE_BINARY) { - err("parse_bson_uuid: uuid field type expected for '%s'", field_name); - return -1; - } - - bson_binary_subtype bt = 0; - const unsigned char *bd = NULL; - int bz = 0; - if (!bson_cursor_get_binary(bc, &bt, &bd, &bz)) { - err("parse_bson_uuid: failed to fetch binary data for '%s'", field_name); - return -1; - } - if (bt != BSON_BINARY_SUBTYPE_UUID || bz != sizeof(ej_uuid_t)) { - err("parse_bson_uuid: invalid binary data for in '%s'", field_name); - return -1; - } - if (p_value) { - memcpy(p_value, bd, sizeof(ej_uuid_t)); - } - return 1; -} - -int -ej_bson_parse_oid( - struct _bson_cursor *bc, - const unsigned char *field_name, - unsigned char *p_value) -{ - if (bson_cursor_type(bc) != BSON_TYPE_OID) { - err("parse_bson_oid: oid field type expected for '%s'", field_name); - return -1; - } - - const unsigned char *p = NULL; - if (!bson_cursor_get_oid(bc, &p) || !p) { - err("parse_bson_oid: failed to fetch oid for '%s'", field_name); - return -1; - } - memcpy(p_value, p, 12); - return 1; -} - -int -ej_bson_parse_ip( - struct _bson_cursor *bc, - const unsigned char *field_name, - ej_ip_t *p_value) -{ - if (bson_cursor_type(bc) != BSON_TYPE_STRING) { - err("parse_bson_ip: string field type expected for '%s'", field_name); - return -1; - } - const char *data = NULL; - if (!bson_cursor_get_string(bc, &data)) { - err("parse_bson_ip: failed to fetch string for '%s'", field_name); - return -1; - } - if (!data) { - err("parse_bson_ip: invalid string for in '%s'", field_name); - return -1; - } - if (xml_parse_ipv6(NULL, 0, 0, 0, data, p_value) < 0) return -1; - return 1; -} - -int -ej_bson_parse_string( - struct _bson_cursor *bc, - const unsigned char *field_name, - unsigned char **p_value) -{ - if (bson_cursor_type(bc) != BSON_TYPE_STRING) { - err("parse_bson_string: string field type expected for '%s'", field_name); - return -1; - } - const char *data = NULL; - if (!bson_cursor_get_string(bc, &data)) { - err("parse_bson_string: failed to fetch string for '%s'", field_name); - return -1; - } - if (!data) { - err("parse_bson_string: invalid string for in '%s'", field_name); - return -1; - } - if (p_value) { - *p_value = xstrdup(data); - } - return 1; -} - -int -ej_bson_parse_array( - bson_cursor *bc, - const unsigned char *field_name, - bson **p_value) -{ - if (bson_cursor_type(bc) != BSON_TYPE_ARRAY) { - err("parse_bson_array: array field type expected for '%s'", field_name); - return -1; - } - bson *data = NULL; - if (!bson_cursor_get_array(bc, &data) || !data) { - err("parse_bson_array: failed to fetch array for '%s'", field_name); - return -1; - } - if (p_value) { - *p_value = data; - } else { - bson_free(data); - } - return 1; -} - -int -ej_bson_parse_document( - bson_cursor *bc, - const unsigned char *field_name, - bson **p_value) -{ - if (bson_cursor_type(bc) != BSON_TYPE_DOCUMENT) { - err("parse_bson_document: document field type expected for '%s', got %s", field_name, bson_cursor_type_as_string(bc)); - return -1; - } - bson *data = NULL; - if (!bson_cursor_get_document(bc, &data) || !data) { - err("parse_bson_document: failed to fetch document for '%s'", field_name); - return -1; - } - if (p_value) { - *p_value = data; - } else { - bson_free(data); - } - return 1; -} - -void -ej_bson_append_uuid( - struct _bson *b, - const unsigned char *key, - const ej_uuid_t *p_uuid) -{ - bson_append_binary(b, key, BSON_BINARY_SUBTYPE_UUID, (const unsigned char *) p_uuid, sizeof(*p_uuid)); -} - -void -ej_bson_append_ip( - struct _bson *b, - const unsigned char *key, - const ej_ip_t *p_ip) -{ - bson_append_string(b, key, xml_unparse_ipv6(p_ip), -1); -} - -bson * -ej_bson_unparse_array_int(const int *values, int count) -{ - bson *arr = bson_new(); - for (int i = 0; i < count; ++i) { - unsigned char buf[32]; - sprintf(buf, "%d", i); - bson_append_int32(arr, buf, values[i]); - } - bson_finish(arr); - return arr; -} - -bson * -ej_bson_unparse_array_uuid( - ej_uuid_t *values, - int count) -{ - bson *arr = bson_new(); - for (int i = 0; i < count; ++i) { - unsigned char buf[32]; - sprintf(buf, "%d", i); - ej_bson_append_uuid(arr, buf, &values[i]); - } - bson_finish(arr); - return arr; - -} - -#endif - int ej_bson_force_link_dummy = 0; /* diff --git a/plugins/avatar-mongo/avatar_mongo.c b/plugins/avatar-mongo/avatar_mongo.c index 24c7dd0950..9f671569e6 100644 --- a/plugins/avatar-mongo/avatar_mongo.c +++ b/plugins/avatar-mongo/avatar_mongo.c @@ -26,8 +26,6 @@ #include #elif HAVE_LIBMONGOC - 0 > 0 #include -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 -#include #endif #include @@ -122,96 +120,6 @@ avatar_info_bson_parse(ej_bson_t *b, struct avatar_info *av) fail: free(mt_str); return retval; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - bson_cursor *bc = NULL; - unsigned char *mt_str = NULL; - - bc = bson_cursor_new(b); - while (bson_cursor_next(bc)) { - const unsigned char *key = bson_cursor_key(bc); - if (!strcmp(key, "_id")) { - // what to do with mongo's _id? - } else if (!strcmp(key, "user_id")) { - if (ej_bson_parse_int(bc, "user_id", &av->user_id, 1, 1, 0, 0) < 0) - goto fail; - } else if (!strcmp(key, "contest_id")) { - if (ej_bson_parse_int(bc, "contest_id", &av->contest_id, 1, 0, 0, 0) < 0) - goto fail; - } else if (!strcmp(key, "is_cropped")) { - if (ej_bson_parse_boolean(bc, "is_cropped", &av->is_cropped) < 0) - goto fail; - } else if (!strcmp(key, "is_temporary")) { - if (ej_bson_parse_boolean(bc, "is_temporary", &av->is_temporary) < 0) - goto fail; - } else if (!strcmp(key, "is_public")) { - if (ej_bson_parse_boolean(bc, "is_public", &av->is_public) < 0) - goto fail; - } else if (!strcmp(key, "mime_type")) { - if (ej_bson_parse_string(bc, "mime_type", &mt_str) < 0) - goto fail; - int mt = mime_type_parse(mt_str); - if (mt < 0) { - err("avatar_info_bson_parse: invalid mime type '%s'", mt_str); - goto fail; - } - if (mt < MIME_TYPE_IMAGE_FIRST || mt > MIME_TYPE_IMAGE_LAST) { - err("avatar_info_bson_parse: mime type '%s' is not image mime type", mime_type_get_type(mt)); - goto fail; - } - av->mime_type = mt; - } else if (!strcmp(key, "width")) { - if (ej_bson_parse_int(bc, "width", &av->width, 1, 0, 0, 0) < 0) - goto fail; - } else if (!strcmp(key, "height")) { - if (ej_bson_parse_int(bc, "height", &av->height, 1, 0, 0, 0) < 0) - goto fail; - } else if (!strcmp(key, "random_key")) { - if (ej_bson_parse_string(bc, "random_key", &av->random_key) < 0) - goto fail; - } else if (!strcmp(key, "create_time")) { - if (ej_bson_parse_utc_datetime(bc, "create_time", &av->create_time) < 0) - goto fail; - } else if (!strcmp(key, "size")) { - long long llsz = 0; - if (ej_bson_parse_int64(bc, "size", &llsz) < 0) - goto fail; - if (llsz < 0) { - err("avatar_info_bson_parse: size < 0"); - goto fail; - } - if ((size_t) llsz != llsz) { - err("avatar_info_bson_parse: size overflow"); - goto fail; - } - av->img_size = llsz; - } else if (!strcmp(key, "image")) { - //bson_append_binary(res, "image", BSON_BINARY_SUBTYPE_USER_DEFINED, img_data, img_size); - if (bson_cursor_type(bc) != BSON_TYPE_BINARY) { - err("avatar_info_bson_parse: binary field type expected for '%s'", "image"); - goto fail; - } - bson_binary_subtype subtype = 0; - const guint8 *bson_data = NULL; - gint32 bson_size = 0; - if (!bson_cursor_get_binary(bc, &subtype, &bson_data, &bson_size)) { - err("avatar_info_bson_parse: failed to fetch binary data for '%s'", "image"); - goto fail; - } - if (subtype != BSON_BINARY_SUBTYPE_USER_DEFINED) { - err("avatar_info_bson_parse: user-defined binary subtype expected for '%s'", "image"); - goto fail; - } - av->img_data = xmalloc(bson_size); - memcpy(av->img_data, bson_data, bson_size); - } - } - bson_cursor_free(bc); - return 1; - -fail:; - if (bc) bson_cursor_free(bc); - xfree(mt_str); - return -1; #else return -1; #endif @@ -370,40 +278,6 @@ insert_func( state->avatar_table_index_created = 1; } - return 0; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - struct avatar_mongo_state *state = (struct avatar_mongo_state *) data; - - bson *res = bson_new(); - bson_append_int32(res, "user_id", user_id); - bson_append_int32(res, "contest_id", contest_id); - bson_append_boolean(res, "is_cropped", is_cropped); - bson_append_boolean(res, "is_temporary", is_temporary); - bson_append_boolean(res, "is_public", is_public); - const unsigned char *mime_type_str = mime_type_get_type(mime_type); - bson_append_string(res, "mime_type", mime_type_str, strlen(mime_type_str)); - bson_append_int32(res, "width", width); - bson_append_int32(res, "height", height); - bson_append_string(res, "random_key", random_key, strlen(random_key)); - bson_append_utc_datetime(res, "create_time", create_time * 1000LL); - bson_append_int64(res, "size", (long long) img_size); - bson_append_binary(res, "image", BSON_BINARY_SUBTYPE_USER_DEFINED, img_data, img_size); - bson_finish(res); - - // FIXME: handle errors - state->common->i->insert_and_free(state->common, state->avatar_table, &res); - /* - if (state->plugin_state->common->i->insert_and_free(state->plugin_state->common, "xuser", &b) < 0) { - return -1; - } - */ - - res = bson_new(); - bson_append_int32(res, "random_key", 1); - bson_finish(res); - state->common->i->index_create(state->common, state->avatar_table, res); - bson_free(res); - return 0; #else return 0; @@ -453,47 +327,6 @@ cleanup:; xfree(results); } return retval; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - struct avatar_mongo_state *state = (struct avatar_mongo_state *) data; - bson *query = NULL; - bson **results = NULL; - int count = 0; - int retval = -1; - struct avatar_info avatar; - - query = bson_new(); - bson_append_string(query, "random_key", random_key, strlen(random_key)); - bson_finish(query); - - // FIXME: also specify selector in case of omit_image != 0 - - count = state->common->i->query(state->common, state->avatar_table, 0, 100, query, NULL, &results); - if (count < 0) goto cleanup; - if (count > 1) { - err("fetch_by_key_func: multiple entries returned"); - goto cleanup; - } - if (!count) { - retval = 0; - goto cleanup; - } - memset(&avatar, 0, sizeof(avatar)); - if (avatar_info_bson_parse(results[0], &avatar) < 0) goto cleanup; - if (result->u >= result->a) { - avatar_vector_expand(result); - } - memcpy(&result->v[result->u++], &avatar, sizeof(avatar)); - retval = 1; - -cleanup:; - if (query) bson_free(query); - if (results) { - for (int i = 0; i < count; ++i) { - bson_free(results[i]); - } - xfree(results); - } - return retval; #else return -1; #endif @@ -520,23 +353,6 @@ delete_by_key_func( cleanup:; if (query) bson_destroy(query); return retval; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - int retval = -1; - struct avatar_mongo_state *state = (struct avatar_mongo_state *) data; - bson *query = NULL; - int r; - - query = bson_new(); - bson_append_string(query, "random_key", random_key, strlen(random_key)); - bson_finish(query); - - r = state->common->i->remove(state->common, state->avatar_table, query); - if (r < 0) goto cleanup; - retval = 0; - -cleanup:; - if (query) bson_free(query); - return retval; #else return -1; #endif diff --git a/plugins/common-mongo/common_mongo.c b/plugins/common-mongo/common_mongo.c index 5629670f5e..089c79676e 100644 --- a/plugins/common-mongo/common_mongo.c +++ b/plugins/common-mongo/common_mongo.c @@ -26,8 +26,6 @@ #include #elif HAVE_LIBMONGOC - 0 > 0 #include -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 -#include #endif #include @@ -284,20 +282,6 @@ prepare_func( return -1; } } -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - state->conn = mongo_sync_connect(state->host, state->port, 0); - if (!state->conn) { - err("cannot connect to mongodb: %s", os_ErrorMsg()); - return -1; - } - mongo_sync_conn_set_safe_mode(state->conn, 1); - mongo_sync_conn_set_auto_reconnect(state->conn, 1); - if (state->user && state->password) { - if (!mongo_sync_cmd_authenticate(state->conn, state->database, state->user, state->password)) { - err("authentification failed: %s", os_ErrorMsg()); - return -1; - } - } #endif return 0; @@ -359,50 +343,6 @@ query_func( if (coll) mongoc_collection_destroy(coll); free(full_table_name); return retval; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - mongo_packet *pkt = NULL; - mongo_sync_cursor *cursor = NULL; - unsigned char ns[1024]; - bson **res = NULL; - int a = 0, u = 0; - bson *result = NULL; - - if (state->show_queries > 0) { - fprintf(stderr, "query: "); ej_bson_unparse(stderr, query, 0); fprintf(stderr, "\n"); - } - - snprintf(ns, sizeof(ns), "%s.%s%s", state->database, state->table_prefix, table); - if (!(pkt = mongo_sync_cmd_query(state->conn, ns, 0, skip, count, query, sel))) { - if (errno == ENOENT) { - // empty result set - *p_res = NULL; - return 0; - } - err("common_mongo::query: failed: %s", os_ErrorMsg()); - return -1; - } - - if (!(cursor = mongo_sync_cursor_new(state->conn, ns, pkt))) { - err("common_mongo::query: cannot create cursor: %s", os_ErrorMsg()); - mongo_wire_packet_free(pkt); - return -1; - } - pkt = NULL; - while (mongo_sync_cursor_next(cursor)) { - result = mongo_sync_cursor_get_data(cursor); - if (state->show_queries > 0) { - fprintf(stderr, "result: "); ej_bson_unparse(stderr, result, 0); fprintf(stderr, "\n"); - } - if (u == a) { - if (!(a *= 2)) a = 8; - XREALLOC(res, a); - } - res[u++] = result; - result = NULL; - } - mongo_sync_cursor_free(cursor); - *p_res = res; - return u; #else return 0; #endif @@ -444,18 +384,6 @@ insert_func( mongoc_collection_destroy(coll); free(full_table_name); return 0; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - unsigned char ns[1024]; - - if (state->show_queries > 0) { - fprintf(stderr, "insert: "); ej_bson_unparse(stderr, b, 0); fprintf(stderr, "\n"); - } - snprintf(ns, sizeof(ns), "%s.%s%s", state->database, state->table_prefix, table); - if (!mongo_sync_cmd_insert(state->conn, ns, b, NULL)) { - err("common_mongo::insert: failed: %s", os_ErrorMsg()); - return -1; - } - return 0; #else return 0; #endif @@ -502,15 +430,6 @@ insert_and_free_func( bson_destroy(bb); *b = NULL; return 0; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - bson *p = NULL; - if (b) p = *b; - int res = insert_func(state, table, p); - if (p) { - bson_free(p); - *b = NULL; - } - return res; #else return 0; #endif @@ -554,19 +473,6 @@ update_func( mongoc_collection_destroy(coll); free(full_table_name); return 0; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - unsigned char ns[1024]; - - if (state->show_queries > 0) { - fprintf(stderr, "update selector: "); ej_bson_unparse(stderr, selector, 0); fprintf(stderr, "\n"); - fprintf(stderr, "update update: "); ej_bson_unparse(stderr, update, 0); fprintf(stderr, "\n"); - } - snprintf(ns, sizeof(ns), "%s.%s%s", state->database, state->table_prefix, table); - if (!mongo_sync_cmd_update(state->conn, ns, 0, selector, update)) { - err("common_mongo::update: failed: %s", os_ErrorMsg()); - return -1; - } - return 0; #else return 0; #endif @@ -621,21 +527,6 @@ update_and_free_func( if (*pupdate) *pupdate = NULL; free(full_table_name); return retval; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - bson *selector = NULL; - bson *update = NULL; - if (pselector) selector = *pselector; - if (pupdate) update = *pupdate; - int res = update_func(state, table, selector, update); - if (selector) { - bson_free(selector); - *pselector = NULL; - } - if (update) { - bson_free(update); - *pupdate = NULL; - } - return res; #else return 0; #endif @@ -668,20 +559,8 @@ index_create_func( bson_destroy(index_bson); bson_free(index_name); free(full_table_name); - - return 0; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - unsigned char ns[1024]; - - snprintf(ns, sizeof(ns), "%s.%s%s", state->database, state->table_prefix, table); - if (!mongo_sync_cmd_index_create(state->conn, ns, b, 0)) { - err("common_mongo::index_create: failed: %s", os_ErrorMsg()); - return -1; - } - return 0; -#else - return 0; #endif + return 0; } static int @@ -720,18 +599,6 @@ remove_func( mongoc_collection_destroy(coll); free(full_table_name); return 0; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - unsigned char ns[1024]; - - if (state->show_queries > 0) { - fprintf(stderr, "delete selector: "); ej_bson_unparse(stderr, selector, 0); fprintf(stderr, "\n"); - } - snprintf(ns, sizeof(ns), "%s.%s%s", state->database, state->table_prefix, table); - if (!mongo_sync_cmd_delete(state->conn, ns, 0, selector)) { - err("common_mongo::delete: failed: %s", os_ErrorMsg()); - return -1; - } - return 0; #else return 0; #endif @@ -775,19 +642,6 @@ upsert_func( mongoc_collection_destroy(coll); free(full_table_name); return 0; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - unsigned char ns[1024]; - - if (state->show_queries > 0) { - fprintf(stderr, "update selector: "); ej_bson_unparse(stderr, selector, 0); fprintf(stderr, "\n"); - fprintf(stderr, "update update: "); ej_bson_unparse(stderr, update, 0); fprintf(stderr, "\n"); - } - snprintf(ns, sizeof(ns), "%s.%s%s", state->database, state->table_prefix, table); - if (!mongo_sync_cmd_update(state->conn, ns, MONGO_WIRE_FLAG_UPDATE_UPSERT, selector, update)) { - err("common_mongo::update: failed: %s", os_ErrorMsg()); - return -1; - } - return 0; #else return 0; #endif @@ -842,21 +696,6 @@ upsert_and_free_func( if (*pupdate) *pupdate = NULL; free(full_table_name); return retval; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - bson *selector = NULL; - bson *update = NULL; - if (pselector) selector = *pselector; - if (pupdate) update = *pupdate; - int res = upsert_func(state, table, selector, update); - if (selector) { - bson_free(selector); - *pselector = NULL; - } - if (update) { - bson_free(update); - *pupdate = NULL; - } - return res; #else return 0; #endif diff --git a/plugins/status-mongo/status_mongo.c b/plugins/status-mongo/status_mongo.c index a6c2b836cf..fa26ec2248 100644 --- a/plugins/status-mongo/status_mongo.c +++ b/plugins/status-mongo/status_mongo.c @@ -27,8 +27,6 @@ #include #elif HAVE_LIBMONGOC - 0 > 0 #include -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 -#include #endif #include @@ -244,57 +242,6 @@ cleanup:; xfree(results); } return retval; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - struct status_mongo_state *sms = (struct status_mongo_state *) sds; - struct status_mongo_plugin_state *ps = (struct status_mongo_plugin_state *) sms->b.plugin->data; - bson *query = NULL; - int count = 0; - bson **results = NULL; - bson *bs = NULL; - int retval = -1; - bson_cursor *bc = NULL; - - query = bson_new(); - bson_append_int32(query, "contest_id", cnts->id); - bson_finish(query); - - count = ps->common->i->query(ps->common, "status", 0, 1, query, NULL, &results); - if (count < 0) goto done; - if (count > 1) { - err("load_func: multiple entries returned: %d", count); - goto done; - } - if (count == 1) { - bc = bson_find(results[0], "s"); - if (bc) { - if (bson_cursor_type(bc) != BSON_TYPE_DOCUMENT) { - goto done; - } - if (!bson_cursor_get_document(bc, &bs)) { - goto done; - } - if (serve_status_bson_parse(bs, stat) < 0) { - goto done; - } - retval = 1; - } else { - retval = 0; - } - } else { - retval = 0; - } - -done: - if (bc) bson_cursor_free(bc); - if (query) bson_free(query); - if (bs) bson_free(bs); - if (results) { - for (int i = 0; i < count; ++i) { - bson_free(results[i]); - } - xfree(results); - } - return retval; #else return -1; #endif @@ -340,35 +287,6 @@ save_func( if (bstat) bson_destroy(bstat); if (filter) bson_destroy(filter); return retval; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - struct status_mongo_state *sms = (struct status_mongo_state *) sds; - struct status_mongo_plugin_state *ps = (struct status_mongo_plugin_state *) sms->b.plugin->data; - int retval = -1; - bson *filter = bson_new(); - bson_append_int32(filter, "contest_id", cnts->id); - bson_finish(filter); - bson *bs = serve_status_bson_unparse(stat); - bson *update = bson_new(); - bson_append_int32(update, "contest_id", cnts->id); - bson_append_document(update, "s", bs); - bson_finish(update); - bson *index = NULL; - - retval = ps->common->i->upsert_and_free(ps->common, "status", &filter, &update); - - if (!ps->contest_id_index_created) { - index = bson_new(); - bson_append_int32(index, "contest_id", 1); - bson_finish(index); - ps->common->i->index_create(ps->common, "status", index); - ps->contest_id_index_created = 1; - } - - if (index) bson_free(index); - if (update) bson_free(update); - if (filter) bson_free(filter); - if (bs) bson_free(bs); - return retval; #else return -1; #endif @@ -390,12 +308,6 @@ remove_func( bson_append_int32(filter, "contest_id", -1, cnts->id); ps->common->i->remove(ps->common, "status", filter); if (filter) bson_destroy(filter); -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - bson *filter = bson_new(); - bson_append_int32(filter, "contest_id", cnts->id); - bson_finish(filter); - ps->common->i->remove(ps->common, "status", filter); - if (filter) bson_free(filter); #endif } @@ -437,37 +349,6 @@ cleanup:; xfree(results); } return retval; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - bson *query = NULL; - int count = 0; - bson **results = NULL; - int retval = -1; - - query = bson_new(); - bson_append_int32(query, "contest_id", cnts->id); - bson_finish(query); - - count = ps->common->i->query(ps->common, "status", 0, 1, query, NULL, &results); - if (count < 0) goto done; - if (count > 1) { - err("load_func: multiple entries returned: %d", count); - goto done; - } - if (count == 1) { - retval = 1; - } else { - retval = 0; - } - -done: - if (query) bson_free(query); - if (results) { - for (int i = 0; i < count; ++i) { - bson_free(results[i]); - } - xfree(results); - } - return retval; #else return -1; #endif @@ -552,83 +433,6 @@ serve_status_bson_unparse( #undef UNPARSE_DATE_FIELD #undef UNPARSE_INT32NZ_FIELD #undef UNPARSE_BOOLEAN_FIELD -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 -#define UNPARSE_DATE_FIELD(f) do { if (status->f > 0) { bson_append_utc_datetime(res, #f, status->f * 1000LL); } } while (0) -#define UNPARSE_INT32NZ_FIELD(f) do { if (status->f != 0) { bson_append_int32(res, #f, status->f); } } while (0) -#define UNPARSE_BOOLEAN_FIELD(f) do { if (status->f > 0) { bson_append_boolean(res, #f, status->f); } } while (0) - - bson *res = bson_new(); - - UNPARSE_DATE_FIELD(cur_time); - UNPARSE_DATE_FIELD(start_time); - UNPARSE_DATE_FIELD(sched_time); - UNPARSE_DATE_FIELD(stop_time); - UNPARSE_DATE_FIELD(freeze_time); - UNPARSE_DATE_FIELD(finish_time); - UNPARSE_DATE_FIELD(stat_reported_before); - UNPARSE_DATE_FIELD(stat_report_time); - UNPARSE_DATE_FIELD(max_online_time); - UNPARSE_DATE_FIELD(last_daily_reminder); - - UNPARSE_INT32NZ_FIELD(duration); - UNPARSE_INT32NZ_FIELD(total_runs); - UNPARSE_INT32NZ_FIELD(total_clars); - UNPARSE_INT32NZ_FIELD(download_interval); - UNPARSE_INT32NZ_FIELD(max_online_count); - - UNPARSE_BOOLEAN_FIELD(clars_disabled); - UNPARSE_BOOLEAN_FIELD(team_clars_disabled); - UNPARSE_BOOLEAN_FIELD(standings_frozen); - UNPARSE_BOOLEAN_FIELD(clients_suspended); - UNPARSE_BOOLEAN_FIELD(testing_suspended); - UNPARSE_BOOLEAN_FIELD(is_virtual); - UNPARSE_BOOLEAN_FIELD(continuation_enabled); - UNPARSE_BOOLEAN_FIELD(printing_enabled); - UNPARSE_BOOLEAN_FIELD(printing_suspended); - UNPARSE_BOOLEAN_FIELD(always_show_problems); - UNPARSE_BOOLEAN_FIELD(accepting_mode); - UNPARSE_BOOLEAN_FIELD(upsolving_mode); - UNPARSE_BOOLEAN_FIELD(upsolving_freeze_standings); - UNPARSE_BOOLEAN_FIELD(upsolving_view_source); - UNPARSE_BOOLEAN_FIELD(upsolving_view_protocol); - UNPARSE_BOOLEAN_FIELD(upsolving_full_protocol); - UNPARSE_BOOLEAN_FIELD(upsolving_disable_clars); - UNPARSE_BOOLEAN_FIELD(testing_finished); - UNPARSE_BOOLEAN_FIELD(online_view_judge_score); - UNPARSE_BOOLEAN_FIELD(online_final_visibility); - UNPARSE_BOOLEAN_FIELD(online_valuer_judge_comments); - UNPARSE_BOOLEAN_FIELD(disable_virtual_start); - - bson_append_int32(res, "score_system", status->score_system); - - if (status->online_view_source) { - bson_append_int32(res, "online_view_source", status->online_view_source); - } - if (status->online_view_report) { - bson_append_int32(res, "online_view_report", status->online_view_report); - } - - { - int nz_idx = (int)(sizeof(status->prob_prio) / sizeof(status->prob_prio[0])) - 1; - for (; nz_idx >= 0 && !status->prob_prio[nz_idx]; --nz_idx) {} - if (nz_idx >= 0) { - bson *arr = bson_new(); - for (int i = 0; i <= nz_idx; ++i) { - unsigned char buf[32]; - sprintf(buf, "%d", i); - bson_append_int32(arr, buf, status->prob_prio[i]); - } - bson_finish(arr); - bson_append_document(res, "prob_prio", arr); - bson_free(arr); - } - } - - bson_finish(res); - return res; -#undef UNPARSE_DATE_FIELD -#undef UNPARSE_INT32NZ_FIELD -#undef UNPARSE_BOOLEAN_FIELD #else return -1; #endif @@ -768,136 +572,6 @@ serve_status_bson_parse( fail:; if (arr) bson_destroy(arr); return -1; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - bson_cursor *bc = NULL; - bson_cursor *bca = NULL; - bson *arr = NULL; - - bc = bson_cursor_new(b); - while (bson_cursor_next(bc)) { - const unsigned char *key = bson_cursor_key(bc); - if (!strcmp(key, "cur_time")) { - if (ej_bson_parse_utc_datetime_64(bc, "cur_time", &status->cur_time) < 0) goto fail; - } else if (!strcmp(key, "start_time")) { - if (ej_bson_parse_utc_datetime_64(bc, "start_time", &status->start_time) < 0) goto fail; - } else if (!strcmp(key, "sched_time")) { - if (ej_bson_parse_utc_datetime_64(bc, "sched_time", &status->sched_time) < 0) goto fail; - } else if (!strcmp(key, "stop_time")) { - if (ej_bson_parse_utc_datetime_64(bc, "stop_time", &status->stop_time) < 0) goto fail; - } else if (!strcmp(key, "freeze_time")) { - if (ej_bson_parse_utc_datetime_64(bc, "freeze_time", &status->freeze_time) < 0) goto fail; - } else if (!strcmp(key, "finish_time")) { - if (ej_bson_parse_utc_datetime_64(bc, "finish_time", &status->finish_time) < 0) goto fail; - } else if (!strcmp(key, "stat_reported_before")) { - if (ej_bson_parse_utc_datetime_64(bc, "stat_reported_before", &status->stat_reported_before) < 0) goto fail; - } else if (!strcmp(key, "stat_report_time")) { - if (ej_bson_parse_utc_datetime_64(bc, "stat_report_time", &status->stat_report_time) < 0) goto fail; - } else if (!strcmp(key, "max_online_time")) { - if (ej_bson_parse_utc_datetime_64(bc, "max_online_time", &status->max_online_time) < 0) goto fail; - } else if (!strcmp(key, "last_daily_reminder")) { - if (ej_bson_parse_utc_datetime_64(bc, "last_daily_reminder", &status->last_daily_reminder) < 0) goto fail; - } else if (!strcmp(key, "duration")) { - if (ej_bson_parse_int(bc, "duration", &status->duration, 1, 0, 0, 0) < 0) goto fail; - } else if (!strcmp(key, "total_runs")) { - if (ej_bson_parse_int(bc, "total_runs", &status->total_runs, 1, 0, 0, 0) < 0) goto fail; - } else if (!strcmp(key, "total_clars")) { - if (ej_bson_parse_int(bc, "total_clars", &status->total_clars, 1, 0, 0, 0) < 0) goto fail; - } else if (!strcmp(key, "download_interval")) { - if (ej_bson_parse_int(bc, "download_interval", &status->download_interval, 1, 0, 0, 0) < 0) goto fail; - } else if (!strcmp(key, "max_online_count")) { - if (ej_bson_parse_int(bc, "max_online_count", &status->max_online_count, 1, 0, 0, 0) < 0) goto fail; - } else if (!strcmp(key, "clars_disabled")) { - if (ej_bson_parse_boolean_uc(bc, "clars_disabled", &status->clars_disabled) < 0) goto fail; - } else if (!strcmp(key, "team_clars_disabled")) { - if (ej_bson_parse_boolean_uc(bc, "team_clars_disabled", &status->team_clars_disabled) < 0) goto fail; - } else if (!strcmp(key, "standings_frozen")) { - if (ej_bson_parse_boolean_uc(bc, "standings_frozen", &status->standings_frozen) < 0) goto fail; - } else if (!strcmp(key, "clients_suspended")) { - if (ej_bson_parse_boolean_uc(bc, "clients_suspended", &status->clients_suspended) < 0) goto fail; - } else if (!strcmp(key, "testing_suspended")) { - if (ej_bson_parse_boolean_uc(bc, "testing_suspended", &status->testing_suspended) < 0) goto fail; - } else if (!strcmp(key, "is_virtual")) { - if (ej_bson_parse_boolean_uc(bc, "is_virtual", &status->is_virtual) < 0) goto fail; - } else if (!strcmp(key, "continuation_enabled")) { - if (ej_bson_parse_boolean_uc(bc, "continuation_enabled", &status->continuation_enabled) < 0) goto fail; - } else if (!strcmp(key, "printing_enabled")) { - if (ej_bson_parse_boolean_uc(bc, "printing_enabled", &status->printing_enabled) < 0) goto fail; - } else if (!strcmp(key, "printing_suspended")) { - if (ej_bson_parse_boolean_uc(bc, "printing_suspended", &status->printing_suspended) < 0) goto fail; - } else if (!strcmp(key, "always_show_problems")) { - if (ej_bson_parse_boolean_uc(bc, "always_show_problems", &status->always_show_problems) < 0) goto fail; - } else if (!strcmp(key, "accepting_mode")) { - if (ej_bson_parse_boolean_uc(bc, "accepting_mode", &status->accepting_mode) < 0) goto fail; - } else if (!strcmp(key, "upsolving_mode")) { - if (ej_bson_parse_boolean_uc(bc, "upsolving_mode", &status->upsolving_mode) < 0) goto fail; - } else if (!strcmp(key, "upsolving_freeze_standings")) { - if (ej_bson_parse_boolean_uc(bc, "upsolving_freeze_standings", &status->upsolving_freeze_standings) < 0) goto fail; - } else if (!strcmp(key, "upsolving_view_source")) { - if (ej_bson_parse_boolean_uc(bc, "upsolving_view_source", &status->upsolving_view_source) < 0) goto fail; - } else if (!strcmp(key, "upsolving_view_protocol")) { - if (ej_bson_parse_boolean_uc(bc, "upsolving_view_protocol", &status->upsolving_view_protocol) < 0) goto fail; - } else if (!strcmp(key, "upsolving_full_protocol")) { - if (ej_bson_parse_boolean_uc(bc, "upsolving_full_protocol", &status->upsolving_full_protocol) < 0) goto fail; - } else if (!strcmp(key, "upsolving_disable_clars")) { - if (ej_bson_parse_boolean_uc(bc, "upsolving_disable_clars", &status->upsolving_disable_clars) < 0) goto fail; - } else if (!strcmp(key, "testing_finished")) { - if (ej_bson_parse_boolean_uc(bc, "testing_finished", &status->testing_finished) < 0) goto fail; - } else if (!strcmp(key, "online_view_judge_score")) { - if (ej_bson_parse_boolean_uc(bc, "online_view_judge_score", &status->online_view_judge_score) < 0) goto fail; - } else if (!strcmp(key, "online_final_visibility")) { - if (ej_bson_parse_boolean_uc(bc, "online_final_visibility", &status->online_final_visibility) < 0) goto fail; - } else if (!strcmp(key, "online_valuer_judge_comments")) { - if (ej_bson_parse_boolean_uc(bc, "online_valuer_judge_comments", &status->online_valuer_judge_comments) < 0) goto fail; - } else if (!strcmp(key, "disable_virtual_start")) { - if (ej_bson_parse_boolean_uc(bc, "disable_virtual_start", &status->disable_virtual_start) < 0) goto fail; - } else if (!strcmp(key, "score_system")) { - int ss; - if (ej_bson_parse_int(bc, "score_system", &ss, 1, 0, 1, 100) < 0) goto fail; - status->score_system = ss; - } else if (!strcmp(key, "online_view_source")) { - int v; - if (ej_bson_parse_int(bc, "online_view_source", &v, 0, 0, 0, 0) < 0) goto fail; - if (v < 0) v = -1; - if (v > 0) v = 1; - status->online_view_source = v; - } else if (!strcmp(key, "online_view_report")) { - int v; - if (ej_bson_parse_int(bc, "online_view_report", &v, 0, 0, 0, 0) < 0) goto fail; - if (v < 0) v = -1; - if (v > 0) v = 1; - status->online_view_report = v; - } else if (!strcmp(key, "prob_prio")) { - if (ej_bson_parse_array(bc, "prob_prio", &arr) < 0) goto fail; - bca = bson_cursor_new(arr); - while (bson_cursor_next(bca)) { - const unsigned char *key = bson_cursor_key(bca); - char *eptr = NULL; - long val = 0; - errno = 0; - if (!key || (val = strtol(key, &eptr, 10)) < 0 || errno || *eptr || (const unsigned char *) eptr == key || (int) val != val) { - err("serve_status_bson_parse: invalid index in 'prob_prio': %s", key); - goto fail; - } - int prio = 0; - if (ej_bson_parse_int(bca, "prob_prio/prio", &prio, 1, -128, 1, 127) < 0) goto fail; - if (val >= 0 && val < EJ_SERVE_STATUS_TOTAL_PROBS_NEW) { - status->prob_prio[val] = prio; - } - } - bson_cursor_free(bca); bca = NULL; - bson_free(arr); arr = NULL; - } else { - // do nothing: ignore unknown - } - } - bson_cursor_free(bc); - return 0; - -fail: - if (bc) bson_cursor_free(bc); - if (bca) bson_cursor_free(bca); - if (arr) bson_free(arr); - return -1; #else return -1; #endif diff --git a/plugins/telegram/mongo_conn.c b/plugins/telegram/mongo_conn.c index a9b9819631..c58a704b1f 100644 --- a/plugins/telegram/mongo_conn.c +++ b/plugins/telegram/mongo_conn.c @@ -24,8 +24,6 @@ #include #elif HAVE_LIBMONGOC - 0 > 0 #include -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 -#include #endif #include @@ -157,20 +155,6 @@ mongo_conn_free(struct mongo_conn *conn) xfree(conn); } return NULL; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - if (conn) { - xfree(conn->database); - xfree(conn->host); - xfree(conn->table_prefix); - xfree(conn->user); - xfree(conn->password); - if (conn->conn) { - mongo_sync_disconnect(conn->conn); - } - memset(conn, 0xff, sizeof(*conn)); - xfree(conn); - } - return NULL; #else return NULL; #endif @@ -227,39 +211,6 @@ mongo_conn_open(struct mongo_conn *state) mongoc_client_set_appname(state->client, "ejudge-plugin-telegram"); - return 1; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - if (state->conn) return 1; - - time_t current_time = time(NULL); - if (state->last_check_time > 0 && state->last_check_time + MONGO_RETRY_TIMEOUT > current_time) { - return 0; - } - - if (!state->database) { - if (!state->database) state->database = xstrdup("ejudge"); - state->show_queries = 1; - } - if (!state->host) state->host = xstrdup("localhost"); - if (!state->table_prefix) state->table_prefix = xstrdup(""); - if (state->port <= 0) state->port = 27017; - state->last_check_time = current_time; - - state->conn = mongo_sync_connect(state->host, state->port, 0); - if (!state->conn) { - err("cannot connect to mongodb: %s", os_ErrorMsg()); - return 0; - } - mongo_sync_conn_set_safe_mode(state->conn, 1); - mongo_sync_conn_set_auto_reconnect(state->conn, 1); - if (state->user && state->password) { - if (!mongo_sync_cmd_authenticate(state->conn, state->database, state->user, state->password)) { - err("mongodb authentification failed: %s", os_ErrorMsg()); - mongo_sync_disconnect(state->conn); - state->conn = NULL; - return 0; - } - } return 1; #else return 0; diff --git a/plugins/telegram/mongo_conn.h b/plugins/telegram/mongo_conn.h index c658e2e8f6..e5fa124b42 100644 --- a/plugins/telegram/mongo_conn.h +++ b/plugins/telegram/mongo_conn.h @@ -25,8 +25,6 @@ #include #elif HAVE_LIBMONGOC - 0 > 0 #include -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 -struct _mongo_sync_connection; #endif // mongo connectivity @@ -35,8 +33,6 @@ struct mongo_conn struct generic_conn b; #if HAVE_LIBMONGOC - 0 > 0 mongoc_client_t *client; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - struct _mongo_sync_connection *conn; #endif time_t last_check_time; int token_index_created; diff --git a/plugins/telegram/telegram_chat.c b/plugins/telegram/telegram_chat.c index dfabdccf23..3babd3b49e 100644 --- a/plugins/telegram/telegram_chat.c +++ b/plugins/telegram/telegram_chat.c @@ -28,8 +28,6 @@ #include #elif HAVE_LIBMONGOC - 0 > 0 #include -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 -#include #endif #include @@ -38,9 +36,6 @@ #if HAVE_LIBMONGOC - 0 > 0 struct _bson_t; typedef struct _bson_t ej_bson_t; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 -struct _bson; -typedef struct _bson ej_bson_t; #endif #define TELEGRAM_CHATS_TABLE_NAME "telegram_chats" @@ -106,34 +101,6 @@ telegram_chat_parse_bson(const ej_bson_t *bson) telegram_chat_free(tc); return NULL; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - bson_cursor *bc = NULL; - struct telegram_chat *tc = NULL; - - XCALLOC(tc, 1); - bc = bson_cursor_new(bson); - while (bson_cursor_next(bc)) { - const unsigned char *key = bson_cursor_key(bc); - if (!strcmp(key, "_id")) { - if (ej_bson_parse_int64(bc, "_id", &tc->_id) < 0) goto cleanup; - } else if (!strcmp(key, "type")) { - if (ej_bson_parse_string(bc, "type", &tc->type) < 0) goto cleanup; - } else if (!strcmp(key, "title")) { - if (ej_bson_parse_string(bc, "title", &tc->title) < 0) goto cleanup; - } else if (!strcmp(key, "username")) { - if (ej_bson_parse_string(bc, "username", &tc->username) < 0) goto cleanup; - } else if (!strcmp(key, "first_name")) { - if (ej_bson_parse_string(bc, "first_name", &tc->first_name) < 0) goto cleanup; - } else if (!strcmp(key, "last_name")) { - if (ej_bson_parse_string(bc, "last_name", &tc->last_name) < 0) goto cleanup; - } - } - bson_cursor_free(bc); - return tc; - -cleanup: - telegram_chat_free(tc); - return NULL; #else return NULL; #endif @@ -166,30 +133,6 @@ telegram_chat_unparse_bson(const struct telegram_chat *tc) bson_append_utf8(bson, "last_name", -1, tc->last_name, strlen(tc->last_name)); } - return bson; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - if (!tc) return NULL; - - bson *bson = bson_new(); - if (tc->_id) { - bson_append_int64(bson, "_id", tc->_id); - } - if (tc->type && *tc->type) { - bson_append_string(bson, "type", tc->type, strlen(tc->type)); - } - if (tc->title && *tc->title) { - bson_append_string(bson, "title", tc->title, strlen(tc->title)); - } - if (tc->username && *tc->username) { - bson_append_string(bson, "username", tc->username, strlen(tc->username)); - } - if (tc->first_name && *tc->first_name) { - bson_append_string(bson, "first_name", tc->first_name, strlen(tc->first_name)); - } - if (tc->last_name && *tc->last_name) { - bson_append_string(bson, "last_name", tc->last_name, strlen(tc->last_name)); - } - bson_finish(bson); return bson; #else return NULL; @@ -227,48 +170,6 @@ telegram_chat_fetch(struct mongo_conn *conn, long long _id) if (query) bson_destroy(query); return retval; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - if (!mongo_conn_open(conn)) return NULL; - - bson *query = NULL; - mongo_packet *pkt = NULL; - mongo_sync_cursor *cursor = NULL; - bson *result = NULL; - struct telegram_chat *retval = NULL; - - query = bson_new(); - bson_append_int64(query, "_id", _id); - bson_finish(query); - - pkt = mongo_sync_cmd_query(conn->conn, mongo_conn_ns(conn, TELEGRAM_CHATS_TABLE_NAME), 0, 0, 1, query, NULL); - if (!pkt && errno == ENOENT) { - goto cleanup; - } - if (!pkt) { - err("mongo query failed: %s", os_ErrorMsg()); - goto cleanup; - } - bson_free(query); query = NULL; - - cursor = mongo_sync_cursor_new(conn->conn, conn->ns, pkt); - if (!cursor) { - err("mongo query failed: cannot create cursor: %s", os_ErrorMsg()); - goto cleanup; - } - pkt = NULL; - if (mongo_sync_cursor_next(cursor)) { - result = mongo_sync_cursor_get_data(cursor); - if (result) { - retval = telegram_chat_parse_bson(result); - } - } - -cleanup: - if (result) bson_free(result); - if (cursor) mongo_sync_cursor_free(cursor); - if (pkt) mongo_wire_packet_free(pkt); - if (query) bson_free(query); - return retval; #else return NULL; #endif @@ -306,26 +207,6 @@ telegram_chat_save(struct mongo_conn *conn, const struct telegram_chat *tc) if (query) bson_destroy(query); if (bson) bson_destroy(bson); return retval; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - if (!mongo_conn_open(conn)) return -1; - int retval = -1; - - bson *b = telegram_chat_unparse_bson(tc); - bson *q = bson_new(); - bson_append_int64(q, "_id", tc->_id); - bson_finish(q); - - if (!mongo_sync_cmd_update(conn->conn, mongo_conn_ns(conn, TELEGRAM_CHATS_TABLE_NAME), MONGO_WIRE_FLAG_UPDATE_UPSERT, q, b)) { - err("save_token: failed: %s", os_ErrorMsg()); - goto cleanup; - } - - retval = 0; - -cleanup: - bson_free(q); - bson_free(b); - return retval; #else return 0; #endif diff --git a/plugins/telegram/telegram_chat_state.c b/plugins/telegram/telegram_chat_state.c index 2baeebb015..62438b2a26 100644 --- a/plugins/telegram/telegram_chat_state.c +++ b/plugins/telegram/telegram_chat_state.c @@ -28,8 +28,6 @@ #include #elif HAVE_LIBMONGOC - 0 > 0 #include -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 -#include #endif #include @@ -38,9 +36,6 @@ #if HAVE_LIBMONGOC - 0 > 0 struct _bson_t; typedef struct _bson_t ej_bson_t; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 -struct _bson; -typedef struct _bson ej_bson_t; #endif #define TELEGRAM_CHAT_STATES_TABLE_NAME "telegram_chat_states" @@ -107,34 +102,6 @@ telegram_chat_state_parse_bson(const ej_bson_t *bson) return tcs; -cleanup: - telegram_chat_state_free(tcs); - return NULL; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - bson_cursor *bc = NULL; - struct telegram_chat_state *tcs = NULL; - - XCALLOC(tcs, 1); - bc = bson_cursor_new(bson); - while (bson_cursor_next(bc)) { - const unsigned char *key = bson_cursor_key(bc); - if (!strcmp(key, "_id")) { - if (ej_bson_parse_int64(bc, "_id", &tcs->_id) < 0) goto cleanup; - } else if (!strcmp(key, "command")) { - if (ej_bson_parse_string(bc, "command", &tcs->command) < 0) goto cleanup; - } else if (!strcmp(key, "token")) { - if (ej_bson_parse_string(bc, "token", &tcs->token) < 0) goto cleanup; - } else if (!strcmp(key, "state")) { - if (ej_bson_parse_int(bc, "state", &tcs->state, 0, 0, 0, 0) < 0) goto cleanup; - } else if (!strcmp(key, "review_flag")) { - if (ej_bson_parse_int(bc, "review_flag", &tcs->review_flag, 0, 0, 0, 0) < 0) goto cleanup; - } else if (!strcmp(key, "reply_flag")) { - if (ej_bson_parse_int(bc, "reply_flag", &tcs->reply_flag, 0, 0, 0, 0) < 0) goto cleanup; - } - } - bson_cursor_free(bc); - return tcs; - cleanup: telegram_chat_state_free(tcs); return NULL; @@ -170,30 +137,6 @@ telegram_chat_state_unparse_bson(const struct telegram_chat_state *tcs) bson_append_int32(bson, "reply_flag", -1, tcs->reply_flag); } - return bson; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - if (!tcs) return NULL; - - bson *bson = bson_new(); - if (tcs->_id) { - bson_append_int64(bson, "_id", tcs->_id); - } - if (tcs->command && *tcs->command) { - bson_append_string(bson, "command", tcs->command, strlen(tcs->command)); - } - if (tcs->token && *tcs->token) { - bson_append_string(bson, "token", tcs->token, strlen(tcs->token)); - } - if (tcs->state > 0) { - bson_append_int32(bson, "state", tcs->state); - } - if (tcs->review_flag > 0) { - bson_append_int32(bson, "review_flag", tcs->review_flag); - } - if (tcs->reply_flag > 0) { - bson_append_int32(bson, "reply_flag", tcs->reply_flag); - } - bson_finish(bson); return bson; #else return NULL; @@ -231,48 +174,6 @@ telegram_chat_state_fetch(struct mongo_conn *conn, long long _id) if (query) bson_destroy(query); if (coll) mongoc_collection_destroy(coll); - return retval; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - if (!mongo_conn_open(conn)) return NULL; - - bson *query = NULL; - mongo_packet *pkt = NULL; - mongo_sync_cursor *cursor = NULL; - bson *result = NULL; - struct telegram_chat_state *retval = NULL; - - query = bson_new(); - bson_append_int64(query, "_id", _id); - bson_finish(query); - - pkt = mongo_sync_cmd_query(conn->conn, mongo_conn_ns(conn, TELEGRAM_CHAT_STATES_TABLE_NAME), 0, 0, 1, query, NULL); - if (!pkt && errno == ENOENT) { - goto cleanup; - } - if (!pkt) { - err("mongo query failed: %s", os_ErrorMsg()); - goto cleanup; - } - bson_free(query); query = NULL; - - cursor = mongo_sync_cursor_new(conn->conn, conn->ns, pkt); - if (!cursor) { - err("mongo query failed: cannot create cursor: %s", os_ErrorMsg()); - goto cleanup; - } - pkt = NULL; - if (mongo_sync_cursor_next(cursor)) { - result = mongo_sync_cursor_get_data(cursor); - if (result) { - retval = telegram_chat_state_parse_bson(result); - } - } - -cleanup: - if (result) bson_free(result); - if (cursor) mongo_sync_cursor_free(cursor); - if (pkt) mongo_wire_packet_free(pkt); - if (query) bson_free(query); return retval; #else return NULL; @@ -311,26 +212,6 @@ telegram_chat_state_save(struct mongo_conn *conn, const struct telegram_chat_sta if (query) bson_destroy(query); if (bson) bson_destroy(bson); return retval; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - if (!mongo_conn_open(conn)) return -1; - int retval = -1; - - bson *b = telegram_chat_state_unparse_bson(tcs); - bson *q = bson_new(); - bson_append_int64(q, "_id", tcs->_id); - bson_finish(q); - - if (!mongo_sync_cmd_update(conn->conn, mongo_conn_ns(conn, TELEGRAM_CHAT_STATES_TABLE_NAME), MONGO_WIRE_FLAG_UPDATE_UPSERT, q, b)) { - err("save_token: failed: %s", os_ErrorMsg()); - goto cleanup; - } - - retval = 0; - -cleanup: - bson_free(q); - bson_free(b); - return retval; #else return 0; #endif diff --git a/plugins/telegram/telegram_pbs.c b/plugins/telegram/telegram_pbs.c index a693ebc681..c31087b55b 100644 --- a/plugins/telegram/telegram_pbs.c +++ b/plugins/telegram/telegram_pbs.c @@ -26,17 +26,12 @@ #if HAVE_LIBMONGOC - 0 > 0 struct _bson_t; typedef struct _bson_t ej_bson_t; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 -struct _bson; -typedef struct _bson ej_bson_t; #endif #if HAVE_LIBMONGOC - 0 > 1 #include #elif HAVE_LIBMONGOC - 0 > 0 #include -#elif HAVE_LIBMONGO_CLIENT -#include #endif #include @@ -88,26 +83,6 @@ telegram_pbs_parse_bson(const ej_bson_t *bson) return pbs; -cleanup: - telegram_pbs_free(pbs); - return NULL; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - bson_cursor *bc = NULL; - struct telegram_pbs *pbs = NULL; - - XCALLOC(pbs, 1); - bc = bson_cursor_new(bson); - while (bson_cursor_next(bc)) { - const unsigned char *key = bson_cursor_key(bc); - if (!strcmp(key, "_id")) { - if (ej_bson_parse_string(bc, "_id", &pbs->_id) < 0) goto cleanup; - } else if (!strcmp(key, "update_id")) { - if (ej_bson_parse_int64(bc, "update_id", &pbs->update_id) < 0) goto cleanup; - } - } - bson_cursor_free(bc); - return pbs; - cleanup: telegram_pbs_free(pbs); return NULL; @@ -130,18 +105,6 @@ telegram_pbs_unparse_bson(const struct telegram_pbs *pbs) bson_append_int64(bson, "update_id", -1, pbs->update_id); } return bson; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - if (!pbs) return NULL; - - bson *bson = bson_new(); - if (pbs->_id && *pbs->_id) { - bson_append_string(bson, "_id", pbs->_id, strlen(pbs->_id)); - } - if (pbs->update_id != 0) { - bson_append_int64(bson, "update_id", pbs->update_id); - } - bson_finish(bson); - return bson; #else return NULL; #endif @@ -179,25 +142,6 @@ telegram_pbs_save(struct mongo_conn *conn, const struct telegram_pbs *pbs) if (query) bson_destroy(query); if (bson) bson_destroy(bson); return retval; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - if (!mongo_conn_open(conn)) return -1; - int retval = -1; - - bson *s = bson_new(); - bson_append_string(s, "_id", pbs->_id, strlen(pbs->_id)); - bson_finish(s); - - bson *b = telegram_pbs_unparse_bson(pbs); - if (!mongo_sync_cmd_update(conn->conn, mongo_conn_ns(conn, TELEGRAM_BOTS_TABLE_NAME), MONGO_WIRE_FLAG_UPDATE_UPSERT, s, b)) { - err("save_persistent_bot_state: failed: %s", os_ErrorMsg()); - goto done; - } - retval = 0; - -done: - bson_free(s); - bson_free(b); - return retval; #else return 0; #endif @@ -239,51 +183,6 @@ telegram_pbs_fetch(struct mongo_conn *conn, const unsigned char *bot_id) if (coll) mongoc_collection_destroy(coll); if (query) bson_destroy(query); return retval; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - if (!mongo_conn_open(conn)) return NULL; - - mongo_packet *pkt = NULL; - bson *query = NULL; - mongo_sync_cursor *cursor = NULL; - bson *result = NULL; - struct telegram_pbs *pbs = NULL; - - query = bson_new(); - bson_append_string(query, "_id", bot_id, strlen(bot_id)); - bson_finish(query); - pkt = mongo_sync_cmd_query(conn->conn, mongo_conn_ns(conn, TELEGRAM_BOTS_TABLE_NAME), 0, 0, 1, query, NULL); - if (!pkt && errno == ENOENT) { - bson_free(query); query = NULL; - pbs = telegram_pbs_create(bot_id); - telegram_pbs_save(conn, pbs); - goto cleanup; - } - if (!pkt) { - err("mongo query failed: %s", os_ErrorMsg()); - goto cleanup; - } - bson_free(query); query = NULL; - cursor = mongo_sync_cursor_new(conn->conn, conn->ns, pkt); - if (!cursor) { - err("mongo query failed: cannot create cursor: %s", os_ErrorMsg()); - goto cleanup; - } - pkt = NULL; - if (mongo_sync_cursor_next(cursor)) { - result = mongo_sync_cursor_get_data(cursor); - pbs = telegram_pbs_parse_bson(result); - } else { - mongo_sync_cursor_free(cursor); cursor = NULL; - pbs = telegram_pbs_create(bot_id); - telegram_pbs_save(conn, pbs); - } - -cleanup: - if (result) bson_free(result); - if (cursor) mongo_sync_cursor_free(cursor); - if (pkt) mongo_wire_packet_free(pkt); - if (query) bson_free(query); - return pbs; #else return NULL; #endif diff --git a/plugins/telegram/telegram_subscription.c b/plugins/telegram/telegram_subscription.c index 1f56f13248..ee33e7ff5f 100644 --- a/plugins/telegram/telegram_subscription.c +++ b/plugins/telegram/telegram_subscription.c @@ -26,8 +26,6 @@ #include #elif HAVE_LIBMONGOC - 0 > 0 #include -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 -#include #endif #include @@ -37,9 +35,6 @@ #if HAVE_LIBMONGOC - 0 > 0 struct _bson_t; typedef struct _bson_t ej_bson_t; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 -struct _bson; -typedef struct _bson ej_bson_t; #endif #define TELEGRAM_SUBSCRIPTIONS_TABLE_NAME "telegram_subscriptions" @@ -108,36 +103,6 @@ telegram_subscription_parse_bson(const ej_bson_t *bson) } return sub; -cleanup: - telegram_subscription_free(sub); - return NULL; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - struct telegram_subscription *sub = NULL; - bson_cursor *bc = NULL; - - XCALLOC(sub, 1); - bc = bson_cursor_new(bson); - while (bson_cursor_next(bc)) { - const unsigned char *key = bson_cursor_key(bc); - if (!strcmp(key, "_id")) { - if (ej_bson_parse_string(bc, "_id", &sub->_id) < 0) goto cleanup; - } else if (!strcmp(key, "bot_id")) { - if (ej_bson_parse_string(bc, "bot_id", &sub->bot_id) < 0) goto cleanup; - } else if (!strcmp(key, "user_id")) { - if (ej_bson_parse_int(bc, "user_id", &sub->user_id, 1, 1, 0, 0) < 0) goto cleanup; - } else if (!strcmp(key, "contest_id")) { - if (ej_bson_parse_int(bc, "contest_id", &sub->contest_id, 1, 0, 0, 0) < 0) goto cleanup; - } else if (!strcmp(key, "review_flag")) { - if (ej_bson_parse_int(bc, "review_flag", &sub->review_flag, 1, 0, 0, 0) < 0) goto cleanup; - } else if (!strcmp(key, "reply_flag")) { - if (ej_bson_parse_int(bc, "reply_flag", &sub->reply_flag, 1, 0, 0, 0) < 0) goto cleanup; - } else if (!strcmp(key, "chat_id")) { - if (ej_bson_parse_int64(bc, "chat_id", &sub->chat_id) < 0) goto cleanup; - } - } - bson_cursor_free(bc); - return sub; - cleanup: telegram_subscription_free(sub); return NULL; @@ -175,33 +140,6 @@ telegram_subscription_unparse_bson(const struct telegram_subscription *sub) bson_append_int64(bson, "chat_id", -1, sub->chat_id); } return bson; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - if (!sub) return NULL; - - bson *b = bson_new(); - if (sub->_id && *sub->_id) { - bson_append_string(b, "_id", sub->_id, strlen(sub->_id)); - } - if (sub->bot_id && *sub->bot_id) { - bson_append_string(b, "bot_id", sub->bot_id, strlen(sub->bot_id)); - } - if (sub->user_id > 0) { - bson_append_int32(b, "user_id", sub->user_id); - } - if (sub->contest_id > 0) { - bson_append_int32(b, "contest_id", sub->contest_id); - } - if (sub->review_flag > 0) { - bson_append_int32(b, "review_flag", sub->review_flag); - } - if (sub->reply_flag > 0) { - bson_append_int32(b, "reply_flag", sub->reply_flag); - } - if (sub->chat_id) { - bson_append_int64(b, "chat_id", sub->chat_id); - } - bson_finish(b); - return b; #else return NULL; #endif @@ -242,52 +180,6 @@ telegram_subscription_fetch(struct mongo_conn *conn, const unsigned char *bot_id if (coll) mongoc_collection_destroy(coll); if (query) bson_destroy(query); return retval; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - if (!mongo_conn_open(conn)) return NULL; - - unsigned char buf[1024]; - if (!bot_id || !*bot_id || contest_id <= 0 || user_id <= 0) return NULL; - snprintf(buf, sizeof(buf), "%s-%d-%d", bot_id, contest_id, user_id); - - bson *query = NULL; - mongo_packet *pkt = NULL; - mongo_sync_cursor *cursor = NULL; - bson *result = NULL; - struct telegram_subscription *retval = NULL; - - query = bson_new(); - bson_append_string(query, "_id", buf, strlen(buf)); - bson_finish(query); - - pkt = mongo_sync_cmd_query(conn->conn, mongo_conn_ns(conn, TELEGRAM_SUBSCRIPTIONS_TABLE_NAME), 0, 0, 1, query, NULL); - if (!pkt && errno == ENOENT) { - goto cleanup; - } - if (!pkt) { - err("mongo query failed: %s", os_ErrorMsg()); - goto cleanup; - } - bson_free(query); query = NULL; - - cursor = mongo_sync_cursor_new(conn->conn, conn->ns, pkt); - if (!cursor) { - err("mongo query failed: cannot create cursor: %s", os_ErrorMsg()); - goto cleanup; - } - pkt = NULL; - if (mongo_sync_cursor_next(cursor)) { - result = mongo_sync_cursor_get_data(cursor); - if (result) { - retval = telegram_subscription_parse_bson(result); - } - } - -cleanup: - if (result) bson_free(result); - if (cursor) mongo_sync_cursor_free(cursor); - if (pkt) mongo_wire_packet_free(pkt); - if (query) bson_free(query); - return retval; #else return NULL; #endif @@ -326,26 +218,6 @@ telegram_subscription_save(struct mongo_conn *conn, const struct telegram_subscr if (query) bson_destroy(query); if (bson) bson_destroy(bson); return retval; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - if (!mongo_conn_open(conn)) return -1; - int retval = -1; - - bson *b = telegram_subscription_unparse_bson(sub); - bson *q = bson_new(); - bson_append_string(q, "_id", sub->_id, strlen(sub->_id)); - bson_finish(q); - - if (!mongo_sync_cmd_update(conn->conn, mongo_conn_ns(conn, TELEGRAM_SUBSCRIPTIONS_TABLE_NAME), MONGO_WIRE_FLAG_UPDATE_UPSERT, q, b)) { - err("save_token: failed: %s", os_ErrorMsg()); - goto cleanup; - } - - retval = 0; - -cleanup: - bson_free(q); - bson_free(b); - return retval; #else return 0; #endif diff --git a/plugins/telegram/telegram_token.c b/plugins/telegram/telegram_token.c index 8181441374..254dc83487 100644 --- a/plugins/telegram/telegram_token.c +++ b/plugins/telegram/telegram_token.c @@ -25,17 +25,12 @@ #if HAVE_LIBMONGOC - 0 > 0 struct _bson_t; typedef struct _bson_t ej_bson_t; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 -struct _bson; -typedef struct _bson ej_bson_t; #endif #if HAVE_LIBMONGOC - 0 > 1 #include #elif HAVE_LIBMONGOC - 0 > 0 #include -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 -#include #endif #include @@ -96,42 +91,6 @@ telegram_token_parse_bson(const ej_bson_t *bson) } } return token; -cleanup: - telegram_token_free(token); - return NULL; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - struct telegram_token *token = NULL; - bson_cursor *bc = NULL; - - XCALLOC(token, 1); - bc = bson_cursor_new(bson); - while (bson_cursor_next(bc)) { - const unsigned char *key = bson_cursor_key(bc); - if (!strcmp(key, "_id")) { - if (ej_bson_parse_oid(bc, "_id", token->_id) < 0) goto cleanup; - } else if (!strcmp(key, "bot_id")) { - if (ej_bson_parse_string(bc, "bot_id", &token->bot_id) < 0) goto cleanup; - } else if (!strcmp(key, "user_id")) { - if (ej_bson_parse_int(bc, "user_id", &token->user_id, 1, 1, 0, 0) < 0) goto cleanup; - } else if (!strcmp(key, "user_login")) { - if (ej_bson_parse_string(bc, "user_login", &token->user_login) < 0) goto cleanup; - } else if (!strcmp(key, "user_name")) { - if (ej_bson_parse_string(bc, "user_name", &token->user_name) < 0) goto cleanup; - } else if (!strcmp(key, "token")) { - if (ej_bson_parse_string(bc, "token", &token->token) < 0) goto cleanup; - } else if (!strcmp(key, "contest_id")) { - if (ej_bson_parse_int(bc, "contest_id", &token->contest_id, 1, 0, 0, 0) < 0) goto cleanup; - } else if (!strcmp(key, "contest_name")) { - if (ej_bson_parse_string(bc, "contest_name", &token->contest_name) < 0) goto cleanup; - } else if (!strcmp(key, "locale_id")) { - if (ej_bson_parse_int(bc, "locale_id", &token->locale_id, 1, 0, 0, 0) < 0) goto cleanup; - } else if (!strcmp(key, "expiry_time")) { - if (ej_bson_parse_utc_datetime(bc, "expiry_time", &token->expiry_time) < 0) goto cleanup; - } - } - bson_cursor_free(bc); - return token; - cleanup: telegram_token_free(token); return NULL; @@ -194,49 +153,6 @@ telegram_token_unparse_bson(const struct telegram_token *token) bson_append_date_time(bson, "expiry_time", -1, 1000LL * token->expiry_time); } return bson; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - if (!token) return NULL; - - bson *b = bson_new(); - int empty_id = 1; - for (int i = 0; i < 12; ++i) { - if (token->_id[i]) { - empty_id = 0; - break; - } - } - if (!empty_id) { - bson_append_oid(b, "_id", token->_id); - } - if (token->bot_id && *token->bot_id) { - bson_append_string(b, "bot_id", token->bot_id, strlen(token->bot_id)); - } - if (token->user_id > 0) { - bson_append_int32(b, "user_id", token->user_id); - } - if (token->user_login && *token->user_login) { - bson_append_string(b, "user_login", token->user_login, strlen(token->user_login)); - } - if (token->user_name && *token->user_name) { - bson_append_string(b, "user_name", token->user_name, strlen(token->user_name)); - } - if (token->token && *token->token) { - bson_append_string(b, "token", token->token, strlen(token->token)); - } - if (token->contest_id > 0) { - bson_append_int32(b, "contest_id", token->contest_id); - } - if (token->contest_name && *token->contest_name) { - bson_append_string(b, "contest_name", token->contest_name, strlen(token->contest_name)); - } - if (token->locale_id > 0) { - bson_append_int32(b, "locale_id", token->locale_id); - } - if (token->expiry_time > 0) { - bson_append_utc_datetime(b, "expiry_time", 1000LL * token->expiry_time); - } - bson_finish(b); - return b; #else return NULL; #endif @@ -276,21 +192,6 @@ telegram_token_remove_expired(struct mongo_conn *conn, time_t current_time) if (qq) bson_destroy(qq); if (coll) mongoc_collection_destroy(coll); return; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - if (current_time <= 0) current_time = time(NULL); - - if (!mongo_conn_open(conn)) return; - - bson *qq = bson_new(); - bson_append_utc_datetime(qq, "$lt", 1000LL * current_time); - bson_finish(qq); - bson *q = bson_new(); - bson_append_document(q, "expiry_time", qq); qq = NULL; - bson_finish(q); - - mongo_sync_cmd_delete(conn->conn, mongo_conn_ns(conn, TELEGRAM_TOKENS_TABLE_NAME), 0, q); - - bson_free(q); #endif } @@ -320,16 +221,6 @@ telegram_token_remove(struct mongo_conn *conn, const unsigned char *token) cleanup: if (query) bson_destroy(query); if (coll) mongoc_collection_destroy(coll); -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - if (!mongo_conn_open(conn)) return; - - bson *q = bson_new(); - bson_append_string(q, "token", token, strlen(token)); - bson_finish(q); - - mongo_sync_cmd_delete(conn->conn, mongo_conn_ns(conn, TELEGRAM_TOKENS_TABLE_NAME), 0, q); - - bson_free(q); #endif } @@ -368,58 +259,6 @@ telegram_token_fetch(struct mongo_conn *conn, const unsigned char *token_str, st if (query) bson_destroy(query); if (coll) mongoc_collection_destroy(coll); return retval; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - int retval = -1; - - if (!mongo_conn_open(conn)) return -1; - - bson *query = NULL; - mongo_packet *pkt = NULL; - mongo_sync_cursor *cursor = NULL; - bson *result = NULL; - - query = bson_new(); - bson_append_string(query, "token", token_str, strlen(token_str)); - bson_finish(query); - - pkt = mongo_sync_cmd_query(conn->conn, mongo_conn_ns(conn, TELEGRAM_TOKENS_TABLE_NAME), 0, 0, 1, query, NULL); - if (!pkt && errno == ENOENT) { - retval = 0; - goto cleanup; - } - if (!pkt) { - err("mongo query failed: %s", os_ErrorMsg()); - goto cleanup; - } - bson_free(query); query = NULL; - - cursor = mongo_sync_cursor_new(conn->conn, conn->ns, pkt); - if (!cursor) { - err("mongo query failed: cannot create cursor: %s", os_ErrorMsg()); - goto cleanup; - } - pkt = NULL; - if (mongo_sync_cursor_next(cursor)) { - result = mongo_sync_cursor_get_data(cursor); - if (result) { - struct telegram_token *t = telegram_token_parse_bson(result); - if (t) { - *p_token = t; - retval = 1; - } - } else { - retval = 0; - } - } else { - retval = 0; - } - -cleanup: - if (result) bson_free(result); - if (cursor) mongo_sync_cursor_free(cursor); - if (pkt) mongo_wire_packet_free(pkt); - if (query) bson_free(query); - return retval; #else return 0; #endif @@ -476,28 +315,6 @@ telegram_token_save(struct mongo_conn *conn, const struct telegram_token *token) if (coll) mongoc_collection_destroy(coll); if (db) mongoc_database_destroy(db); return retval; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - if (!mongo_conn_open(conn)) return -1; - int retval = -1; - - bson *b = telegram_token_unparse_bson(token); - bson *ind = NULL; - - if (!mongo_sync_cmd_insert(conn->conn, mongo_conn_ns(conn, TELEGRAM_TOKENS_TABLE_NAME), b, NULL)) { - err("save_token: failed: %s", os_ErrorMsg()); - goto cleanup; - } - - ind = bson_new(); - bson_append_int32(ind, "token", 1); - bson_finish(ind); - mongo_sync_cmd_index_create(conn->conn, conn->ns, ind, 0); - - retval = 0; -cleanup: - if (ind) bson_free(ind); - bson_free(b); - return retval; #else return 0; #endif diff --git a/plugins/telegram/telegram_user.c b/plugins/telegram/telegram_user.c index 7dde5328e6..5f3aaac3f8 100644 --- a/plugins/telegram/telegram_user.c +++ b/plugins/telegram/telegram_user.c @@ -28,8 +28,6 @@ #include #elif HAVE_LIBMONGOC - 0 > 0 #include -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 -#include #endif #include @@ -38,9 +36,6 @@ #if HAVE_LIBMONGOC - 0 > 0 struct _bson_t; typedef struct _bson_t ej_bson_t; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 -struct _bson; -typedef struct _bson ej_bson_t; #endif #define TELEGRAM_USERS_TABLE_NAME "telegram_users" @@ -96,30 +91,6 @@ telegram_user_parse_bson(const ej_bson_t *bson) return tu; -cleanup: - telegram_user_free(tu); - return NULL; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - bson_cursor *bc = NULL; - struct telegram_user *tu = NULL; - - XCALLOC(tu, 1); - bc = bson_cursor_new(bson); - while (bson_cursor_next(bc)) { - const unsigned char *key = bson_cursor_key(bc); - if (!strcmp(key, "_id")) { - if (ej_bson_parse_int64(bc, "_id", &tu->_id) < 0) goto cleanup; - } else if (!strcmp(key, "username")) { - if (ej_bson_parse_string(bc, "username", &tu->username) < 0) goto cleanup; - } else if (!strcmp(key, "first_name")) { - if (ej_bson_parse_string(bc, "first_name", &tu->first_name) < 0) goto cleanup; - } else if (!strcmp(key, "last_name")) { - if (ej_bson_parse_string(bc, "last_name", &tu->last_name) < 0) goto cleanup; - } - } - bson_cursor_free(bc); - return tu; - cleanup: telegram_user_free(tu); return NULL; @@ -149,24 +120,6 @@ telegram_user_unparse_bson(const struct telegram_user *tu) bson_append_utf8(bson, "last_name", -1, tu->last_name, strlen(tu->last_name)); } - return bson; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - if (!tu) return NULL; - - bson *bson = bson_new(); - if (tu->_id) { - bson_append_int64(bson, "_id", tu->_id); - } - if (tu->username && *tu->username) { - bson_append_string(bson, "username", tu->username, strlen(tu->username)); - } - if (tu->first_name && *tu->first_name) { - bson_append_string(bson, "first_name", tu->first_name, strlen(tu->first_name)); - } - if (tu->last_name && *tu->last_name) { - bson_append_string(bson, "last_name", tu->last_name, strlen(tu->last_name)); - } - bson_finish(bson); return bson; #else return NULL; @@ -205,48 +158,6 @@ telegram_user_fetch(struct mongo_conn *conn, long long _id) if (query) bson_destroy(query); if (coll) mongoc_collection_destroy(coll); return retval; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - if (!mongo_conn_open(conn)) return NULL; - - bson *query = NULL; - mongo_packet *pkt = NULL; - mongo_sync_cursor *cursor = NULL; - bson *result = NULL; - struct telegram_user *retval = NULL; - - query = bson_new(); - bson_append_int64(query, "_id", _id); - bson_finish(query); - - pkt = mongo_sync_cmd_query(conn->conn, mongo_conn_ns(conn, TELEGRAM_USERS_TABLE_NAME), 0, 0, 1, query, NULL); - if (!pkt && errno == ENOENT) { - goto cleanup; - } - if (!pkt) { - err("mongo query failed: %s", os_ErrorMsg()); - goto cleanup; - } - bson_free(query); query = NULL; - - cursor = mongo_sync_cursor_new(conn->conn, conn->ns, pkt); - if (!cursor) { - err("mongo query failed: cannot create cursor: %s", os_ErrorMsg()); - goto cleanup; - } - pkt = NULL; - if (mongo_sync_cursor_next(cursor)) { - result = mongo_sync_cursor_get_data(cursor); - if (result) { - retval = telegram_user_parse_bson(result); - } - } - -cleanup: - if (result) bson_free(result); - if (cursor) mongo_sync_cursor_free(cursor); - if (pkt) mongo_wire_packet_free(pkt); - if (query) bson_free(query); - return retval; #else return NULL; #endif @@ -285,26 +196,6 @@ telegram_user_save(struct mongo_conn *conn, const struct telegram_user *tu) if (bson) bson_destroy(bson); if (coll) mongoc_collection_destroy(coll); return retval; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - if (!mongo_conn_open(conn)) return -1; - int retval = -1; - - bson *b = telegram_user_unparse_bson(tu); - bson *q = bson_new(); - bson_append_int64(q, "_id", tu->_id); - bson_finish(q); - - if (!mongo_sync_cmd_update(conn->conn, mongo_conn_ns(conn, TELEGRAM_USERS_TABLE_NAME), MONGO_WIRE_FLAG_UPDATE_UPSERT, q, b)) { - err("save_token: failed: %s", os_ErrorMsg()); - goto cleanup; - } - - retval = 0; - -cleanup: - bson_free(b); - bson_free(q); - return retval; #else return 0; #endif diff --git a/plugins/xuser-mongo/team_extra_bson.c b/plugins/xuser-mongo/team_extra_bson.c index b1d728ad68..c70ebf5ace 100644 --- a/plugins/xuser-mongo/team_extra_bson.c +++ b/plugins/xuser-mongo/team_extra_bson.c @@ -28,10 +28,6 @@ typedef struct _bson_t ej_bson_t; #include struct _bson_t; typedef struct _bson_t ej_bson_t; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 -#include -struct _bson; -typedef struct _bson ej_bson_t; #endif #define BPE (CHAR_BIT * sizeof(((struct team_extra*)0)->clar_map[0])) @@ -71,40 +67,6 @@ fail:; xfree(res); } return NULL; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - struct team_warning *res = NULL; - bson_cursor *bc = NULL; - - if (!b) return NULL; - - XCALLOC(res, 1); - bc = bson_cursor_new(b); - while (bson_cursor_next(bc)) { - const unsigned char *key = bson_cursor_key(bc); - if (!strcmp(key, "date")) { - if (ej_bson_parse_utc_datetime(bc, "date", &res->date) < 0) goto fail; - } else if (!strcmp(key, "issuer_id")) { - if (ej_bson_parse_int(bc, "issuer_id", &res->issuer_id, 1, 1, 0, 0) < 0) goto fail; - } else if (!strcmp(key, "issuer_ip")) { - if (ej_bson_parse_ip(bc, "issuer_ip", &res->issuer_ip) < 0) goto fail; - } else if (!strcmp(key, "text")) { - if (ej_bson_parse_string(bc, "text", &res->text) < 0) goto fail; - } else if (!strcmp(key, "comment")) { - if (ej_bson_parse_string(bc, "comment", &res->comment) < 0) goto fail; - } - } - bson_cursor_free(bc); - - return res; - -fail: - if (res) { - xfree(res->text); - xfree(res->comment); - xfree(res); - } - if (bc) bson_cursor_free(bc); - return NULL; #else return NULL; #endif @@ -186,82 +148,6 @@ fail:; if (arr) bson_destroy(arr); team_extra_free(res); return NULL; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - bson_cursor *bc = NULL; - bson_cursor *bc2 = NULL; - struct team_extra *res = NULL; - bson *arr = NULL; - bson *doc = NULL; - struct team_warning *tw = NULL; - - if (!b) return NULL; - - XCALLOC(res, 1); - bc = bson_cursor_new(b); - while (bson_cursor_next(bc)) { - const unsigned char *key = bson_cursor_key(bc); - if (!strcmp(key, "_id")) { - if (ej_bson_parse_uuid(bc, "_id", &res->uuid) < 0) goto fail; - } else if (!strcmp(key, "contest_id")) { - if (ej_bson_parse_int(bc, "contest_id", &res->contest_id, 1, 1, 0, 0) < 0) goto fail; - } else if (!strcmp(key, "user_id")) { - if (ej_bson_parse_int(bc, "user_id", &res->user_id, 1, 1, 0, 0) < 0) goto fail; - } else if (!strcmp(key, "viewed_clars")) { - if (ej_bson_parse_array(bc, "viewed_clars", &arr) < 0) goto fail; - bc2 = bson_cursor_new(arr); - while (bson_cursor_next(bc2)) { - int clar_id = 0; - if (ej_bson_parse_int(bc2, "viewed_clars/clar_id", &clar_id, 1, 0, 0, 0) < 0) goto fail; - if (clar_id >= res->clar_map_size) team_extra_extend_clar_map(res, clar_id); - res->clar_map[clar_id / BPE] |= (1UL << clar_id % BPE); - } - bson_cursor_free(bc2); bc2 = NULL; - bson_free(arr); arr = NULL; - } else if (!strcmp(key, "clar_uuids")) { - if (ej_bson_parse_array(bc, "clar_uuids", &arr) < 0) goto fail; - bc2 = bson_cursor_new(arr); - while (bson_cursor_next(bc2)) { - ej_uuid_t uuid; - if (ej_bson_parse_uuid(bc2, "clar_uuids/uuid", &uuid) < 0) goto fail; - team_extra_add_clar_uuid(res, &uuid); - } - bson_cursor_free(bc2); bc2 = NULL; - bson_free(arr); arr = NULL; - } else if (!strcmp(key, "disq_comment")) { - if (ej_bson_parse_string(bc, "disq_comment", &res->disq_comment) < 0) goto fail; - } else if (!strcmp(key, "problem_dir_prefix")) { - if (ej_bson_parse_string(bc, "problem_dir_prefix", &res->problem_dir_prefix) < 0) goto fail; - } else if (!strcmp(key, "warnings")) { - if (ej_bson_parse_array(bc, "warnings", &arr) < 0) goto fail; - bc2 = bson_cursor_new(arr); - while (bson_cursor_next(bc2)) { - if (ej_bson_parse_document(bc2, "warnings/warning", &doc) < 0) goto fail; - if (!(tw = team_warning_bson_parse(doc))) goto fail; - if (res->warn_u == res->warn_a) { - if (!(res->warn_a *= 2)) res->warn_a = 16; - XREALLOC(res->warns, res->warn_a); - } - res->warns[res->warn_u++] = tw; tw = NULL; - bson_free(doc); doc = NULL; - } - bson_cursor_free(bc2); bc2 = NULL; - bson_free(arr); arr = NULL; - } else if (!strcmp(key, "status")) { - if (ej_bson_parse_int(bc, "status", &res->status, 1, 0, 0, 0) < 0) goto fail; - } else if (!strcmp(key, "run_fields")) { - if (ej_bson_parse_int64(bc, "run_fields", &res->run_fields, 1, 0, 0, 0) < 0) goto fail; - } - } - bson_cursor_free(bc); - return res; - -fail: - team_extra_free(res); - if (doc) bson_free(doc); - if (arr) bson_free(arr); - if (bc2) bson_cursor_free(bc2); - if (bc) bson_cursor_free(bc); - return NULL; #else return NULL; #endif @@ -283,20 +169,6 @@ team_warning_bson_unparse(const struct team_warning *tw) bson_append_utf8(res, "comment", -1, tw->comment, strlen(tw->comment)); } return res; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - bson *res = bson_new(); - long long utc_dt = (long long) tw->date * 1000; - bson_append_utc_datetime(res, "date", utc_dt); - bson_append_int32(res, "issuer_id", tw->issuer_id); - ej_bson_append_ip(res, "issuer_ip", &tw->issuer_ip); - if (tw->text) { - bson_append_string(res, "text", tw->text, strlen(tw->text)); - } - if (tw->comment) { - bson_append_string(res, "comment", tw->comment, strlen(tw->comment)); - } - bson_finish(res); - return res; #else return NULL; #endif @@ -317,19 +189,6 @@ team_warnings_bson_unparse(struct team_warning **tws, int count) } } return res; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - bson *res = bson_new(); - if (tws && count > 0) { - for (int i = 0; i < count; ++i) { - unsigned char buf[32]; - bson *w; - sprintf(buf, "%d", i); - bson_append_document(res, buf, (w = team_warning_bson_unparse(tws[i]))); - bson_free(w); - } - } - bson_finish(res); - return res; #else return NULL; #endif @@ -374,44 +233,6 @@ team_extra_bson_unparse(const struct team_extra *extra) bson_destroy(arr); arr = NULL; } return res; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - bson *res = bson_new(); - ej_bson_append_uuid(res, "_id", &extra->uuid); - bson_append_int32(res, "user_id", extra->user_id); - bson_append_int32(res, "contest_id", extra->contest_id); - if (extra->disq_comment) { - bson_append_string(res, "disq_comment", extra->disq_comment, strlen(extra->disq_comment)); - } - if (extra->problem_dir_prefix) { - bson_append_string(res, "problem_dir_prefix", extra->problem_dir_prefix, strlen(extra->problem_dir_prefix)); - } - bson_append_int32(res, "status", extra->status); - bson_append_int64(res, "run_fields", extra->run_fields); - if (extra->clar_map_size > 0) { - bson *arr = bson_new(); - for (int i = 0, j = 0; i < extra->clar_map_size; ++i) { - if (extra->clar_map[i / BPE] & (1UL << i % BPE)) { - unsigned char buf[32]; - sprintf(buf, "%d", j++); - bson_append_int32(arr, buf, i); - } - } - bson_finish(arr); - bson_append_document(res, "viewed_clars", arr); - bson_free(arr); arr = NULL; - } - if (extra->clar_uuids_size > 0) { - bson *arr = NULL; - bson_append_array(res, "clar_uuids", (arr = ej_bson_unparse_array_uuid(extra->clar_uuids, extra->clar_uuids_size))); - bson_free(arr); arr = NULL; - } - if (extra->warn_u > 0) { - bson *arr = team_warnings_bson_unparse(extra->warns, extra->warn_u); - bson_append_array(res, "warnings", arr); - bson_free(arr); arr = NULL; - } - bson_finish(res); - return res; #else return NULL; #endif diff --git a/plugins/xuser-mongo/xuser_mongo.c b/plugins/xuser-mongo/xuser_mongo.c index 9eb555f2ce..c985660542 100644 --- a/plugins/xuser-mongo/xuser_mongo.c +++ b/plugins/xuser-mongo/xuser_mongo.c @@ -34,8 +34,6 @@ #include #elif HAVE_LIBMONGOC - 0 > 0 #include -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 -#include #endif #include @@ -377,48 +375,6 @@ done:; } if (query) bson_destroy(query); return extra; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - struct team_extra *extra = NULL; - bson *query = NULL; - int pos = 0, count = 0; - bson **results = NULL; - - if (user_id <= 0) return NULL; - - if ((extra = find_entry(state, user_id, &pos))) - return extra; - - query = bson_new(); - bson_append_int32(query, "contest_id", state->contest_id); - bson_append_int32(query, "user_id", user_id); - bson_finish(query); - count = state->plugin_state->common->i->query(state->plugin_state->common, "xuser", 0, 1, query, NULL, &results); - if (count < 0) goto done; - if (count > 1) { - err("do_get_entry: multiple entries returned: %d", count); - goto done; - } - if (count == 1) { - if (!(extra = team_extra_bson_parse(results[0]))) { - goto done; - } - } - if (!extra) { - XCALLOC(extra, 1); - extra->user_id = user_id; - extra->contest_id = state->contest_id; - } - insert_entry(state, user_id, extra, pos); - -done: - if (query) bson_free(query); - if (results) { - for (int i = 0; i < count; ++i) { - bson_free(results[i]); - } - xfree(results); - } - return extra; #else return NULL; #endif @@ -464,16 +420,6 @@ do_insert( return -1; } return 0; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - if (extra->contest_id <= 0) extra->contest_id = state->contest_id; - if (!ej_uuid_is_nonempty(extra->uuid)) { - ej_uuid_generate(&extra->uuid); - } - bson *b = team_extra_bson_unparse(extra); - if (state->plugin_state->common->i->insert_and_free(state->plugin_state->common, "xuser", &b) < 0) { - return -1; - } - return 0; #else return -1; #endif @@ -496,20 +442,6 @@ do_update( int retval = state->plugin_state->common->i->update_and_free(state->plugin_state->common, "xuser", &filter, &update); return retval; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - bson *filter = bson_new(); - ej_bson_append_uuid(filter, "_id", &extra->uuid); - bson_finish(filter); - bson *update = bson_new(); - if (!op) op = "$set"; - bson_append_document(update, op, update_doc); - bson_finish(update); - - int retval = state->plugin_state->common->i->update(state->plugin_state->common, "xuser", filter, update); - bson_free(update); update = NULL; - bson_free(filter); filter = NULL; - bson_free(update_doc); update_doc = NULL; - return retval; #else return -1; #endif @@ -539,24 +471,6 @@ set_clar_status_func( return do_insert(state, extra); } return -1; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - struct xuser_mongo_cnts_state *state = (struct xuser_mongo_cnts_state *) data; - struct team_extra *extra = do_get_entry(state, user_id); - if (!extra) return -1; - if (!p_clar_uuid) return -1; - int r = team_extra_add_clar_uuid(extra, p_clar_uuid); - if (r <= 0) return r; - if (ej_uuid_is_nonempty(extra->uuid)) { - bson *arr = ej_bson_unparse_array_uuid(extra->clar_uuids, extra->clar_uuids_size); - bson *doc = bson_new(); - bson_append_array(doc, "clar_uuids", arr); - bson_free(arr); arr = NULL; - bson_finish(doc); - return do_update(state, extra, NULL, doc); - } else { - return do_insert(state, extra); - } - return -1; #else return -1; #endif @@ -606,35 +520,6 @@ append_warning_func( } else { return do_insert(state, extra); } -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - struct xuser_mongo_cnts_state *state = (struct xuser_mongo_cnts_state *) data; - struct team_extra *extra = do_get_entry(state, user_id); - if (!extra) return -1; - - if (extra->warn_u == extra->warn_a) { - extra->warn_a *= 2; - if (!extra->warn_a) extra->warn_a = 8; - XREALLOC(extra->warns, extra->warn_a); - } - struct team_warning *cur_warn = NULL; - XCALLOC(cur_warn, 1); - extra->warns[extra->warn_u++] = cur_warn; - - cur_warn->date = issue_date; - cur_warn->issuer_id = issuer_id; - cur_warn->issuer_ip = *issuer_ip; - cur_warn->text = xstrdup(txt); - cur_warn->comment = xstrdup(cmt); - if (ej_uuid_is_nonempty(extra->uuid)) { - bson *w = team_warning_bson_unparse(cur_warn); - bson *doc = bson_new(); - bson_append_document(doc, "warnings", w); - bson_free(w); w = NULL; - bson_finish(doc); - return do_update(state, extra, "$push", doc); - } else { - return do_insert(state, extra); - } #else return -1; #endif @@ -659,20 +544,6 @@ set_status_func( } else { return do_insert(state, extra); } -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - struct xuser_mongo_cnts_state *state = (struct xuser_mongo_cnts_state *) data; - struct team_extra *extra = do_get_entry(state, user_id); - if (!extra) return -1; - if (extra->status == status) return 0; - extra->status = status; - if (ej_uuid_is_nonempty(extra->uuid)) { - bson *doc = bson_new(); - bson_append_int32(doc, "status", status); - bson_finish(doc); - return do_update(state, extra, NULL, doc); - } else { - return do_insert(state, extra); - } #else return -1; #endif @@ -709,33 +580,6 @@ set_disq_comment_func( } else { return do_insert(state, extra); } -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - struct xuser_mongo_cnts_state *state = (struct xuser_mongo_cnts_state *) data; - struct team_extra *extra = do_get_entry(state, user_id); - if (!extra) return -1; - if (!extra->disq_comment && !disq_comment) { - return 0; - } - if (extra->disq_comment && !disq_comment) { - ASSERT(ej_uuid_is_nonempty(extra->uuid)); - xfree(extra->disq_comment); extra->disq_comment = NULL; - bson *doc = bson_new(); - bson_append_string(doc, "disq_comment", "", 0); - bson_finish(doc); - return do_update(state, extra, "$unset", doc); - } - if (extra->disq_comment && !strcmp(extra->disq_comment, disq_comment)) - return 0; - xfree(extra->disq_comment); - extra->disq_comment = xstrdup(disq_comment); - if (ej_uuid_is_nonempty(extra->uuid)) { - bson *doc = bson_new(); - bson_append_string(doc, "disq_comment", extra->disq_comment, strlen(extra->disq_comment)); - bson_finish(doc); - return do_update(state, extra, NULL, doc); - } else { - return do_insert(state, extra); - } #else return -1; #endif @@ -767,21 +611,6 @@ set_run_fields_func( if (ej_uuid_is_nonempty(extra->uuid)) { bson_t *doc = bson_new(); bson_append_int64(doc, "run_fields", -1, run_fields); - return do_update(state, extra, NULL, doc); - } else { - return do_insert(state, extra); - } -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - struct xuser_mongo_cnts_state *state = (struct xuser_mongo_cnts_state *) data; - struct team_extra *extra = do_get_entry(state, user_id); - if (!extra) return -1; - if (extra->run_fields == run_fields) return 0; - extra->run_fields = run_fields; - if (ej_uuid_is_nonempty(extra->uuid)) { - bson *doc = bson_new(); - bson_append_int64(doc, "run_fields", run_fields); - bson_finish(doc); - return do_update(state, extra, NULL, doc); } else { return do_insert(state, extra); @@ -947,34 +776,6 @@ get_entries_func( bson_destroy(query); query = NULL; xfree(query_results); query_results = NULL; } -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - { - int query_count = 0; - struct team_extra *extra = NULL; - bson **query_results = NULL; - bson *arr = ej_bson_unparse_array_int(loc_users, loc_count); - bson *indoc = bson_new(); - bson_append_array(indoc, "$in", arr); - bson_finish(indoc); - bson_free(arr); arr = NULL; - bson *query = bson_new(); - bson_append_int32(query, "contest_id", state->contest_id); - bson_append_document(query, "user_id", indoc); - bson_finish(query); - bson_free(indoc); indoc = NULL; - - query_count = state->plugin_state->common->i->query(state->plugin_state->common, "xuser", 0, loc_count, query, NULL, &query_results); - if (query_count > 0) { - for (i1 = 0; i1 < query_count; ++i1) { - if ((extra = team_extra_bson_parse(query_results[i1]))) { - insert_entry(state, extra->user_id, extra, -1); - } - bson_free(query_results[i1]); query_results[i1] = NULL; - } - } - bson_free(query); query = NULL; - xfree(query_results); query_results = NULL; - } #else return NULL; #endif @@ -1060,33 +861,6 @@ set_problem_dir_prefix_func( } else { return do_insert(state, extra); } -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - struct xuser_mongo_cnts_state *state = (struct xuser_mongo_cnts_state *) data; - struct team_extra *extra = do_get_entry(state, user_id); - if (!extra) return -1; - if (!extra->problem_dir_prefix && !problem_dir_prefix) { - return 0; - } - if (extra->problem_dir_prefix && !problem_dir_prefix) { - ASSERT(ej_uuid_is_nonempty(extra->uuid)); - xfree(extra->problem_dir_prefix); extra->problem_dir_prefix = NULL; - bson *doc = bson_new(); - bson_append_string(doc, "problem_dir_prefix", "", 0); - bson_finish(doc); - return do_update(state, extra, "$unset", doc); - } - if (extra->problem_dir_prefix && !strcmp(extra->problem_dir_prefix, problem_dir_prefix)) - return 0; - xfree(extra->problem_dir_prefix); - extra->problem_dir_prefix = xstrdup(problem_dir_prefix); - if (ej_uuid_is_nonempty(extra->uuid)) { - bson *doc = bson_new(); - bson_append_string(doc, "problem_dir_prefix", extra->problem_dir_prefix, strlen(extra->problem_dir_prefix)); - bson_finish(doc); - return do_update(state, extra, NULL, doc); - } else { - return do_insert(state, extra); - } #else return -1; #endif @@ -1145,51 +919,6 @@ get_user_ids_func( *p_count = size; *p_user_ids = user_ids; return 0; -#elif HAVE_LIBMONGO_CLIENT - 0 == 1 - bson *query = NULL; - bson *sel = NULL; - int count = 0; - bson **results = NULL; - bson_cursor *bc = NULL; - - query = bson_new(); - bson_append_int32(query, "contest_id", state->contest_id); - bson_finish(query); - sel = bson_new(); - bson_append_int32(sel, "user_id", 1); - bson_finish(sel); - count = state->plugin_state->common->i->query(state->plugin_state->common, "xuser", 0, 1, query, NULL, &results); - if (count > 0) { - for (int i = 0; i < count; ++i) { - int user_id = 0; - bc = bson_cursor_new(results[i]); - if (bson_cursor_find(bc, "user_id") - && bson_cursor_type(bc) == BSON_TYPE_INT32 - && bson_cursor_get_int32(bc, &user_id)) { - if (size == reserved) { - if (!(reserved *= 2)) reserved = 16; - XREALLOC(user_ids, reserved); - } - user_ids[size++] = user_id; - } - bson_cursor_free(bc); bc = NULL; - } - } - if (size > 1) { - qsort(user_ids, size, sizeof(user_ids[0]), isort_func); - } - if (bc) bson_cursor_free(bc); - if (query) bson_free(query); - if (sel) bson_free(sel); - if (results) { - for (int i = 0; i < count; ++i) { - bson_free(results[i]); - } - xfree(results); - } - *p_count = size; - *p_user_ids = user_ids; - return 0; #else return 0; #endif