* ParseConnectionStatusSpec parses the connectionStatus command parameters * validates the parameters and returns the boolean flag of whether to show privileges. */
| 1212 | * validates the parameters and returns the boolean flag of whether to show privileges. |
| 1213 | */ |
| 1214 | static bool |
| 1215 | ParseConnectionStatusSpec(pgbson *connectionStatusSpec) |
| 1216 | { |
| 1217 | bson_iter_t connectionIter; |
| 1218 | PgbsonInitIterator(connectionStatusSpec, &connectionIter); |
| 1219 | |
| 1220 | bool showPrivileges = false; |
| 1221 | bool connectionStatusFound = false; |
| 1222 | bool dbFound = false; |
| 1223 | while (bson_iter_next(&connectionIter)) |
| 1224 | { |
| 1225 | const char *key = bson_iter_key(&connectionIter); |
| 1226 | |
| 1227 | if (strcmp(key, "connectionStatus") == 0) |
| 1228 | { |
| 1229 | if (bson_iter_type(&connectionIter) == BSON_TYPE_INT64) |
| 1230 | { |
| 1231 | if (bson_iter_as_int64(&connectionIter) != 1) |
| 1232 | { |
| 1233 | elog(DEBUG1, |
| 1234 | "The 'connectionStatus' field contains an integer not equal to 1, got %ld", |
| 1235 | bson_iter_as_int64(&connectionIter)); |
| 1236 | } |
| 1237 | } |
| 1238 | else |
| 1239 | { |
| 1240 | elog(DEBUG1, |
| 1241 | "The 'connectionStatus' field contains a non-integer value, got %s", |
| 1242 | BsonIterTypeName(&connectionIter)); |
| 1243 | } |
| 1244 | |
| 1245 | /* We accept all values and types */ |
| 1246 | connectionStatusFound = true; |
| 1247 | } |
| 1248 | else if (strcmp(key, "showPrivileges") == 0) |
| 1249 | { |
| 1250 | if (BSON_ITER_HOLDS_BOOL(&connectionIter)) |
| 1251 | { |
| 1252 | showPrivileges = bson_iter_as_bool(&connectionIter); |
| 1253 | } |
| 1254 | else |
| 1255 | { |
| 1256 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 1257 | errmsg("'showPrivileges' must be a boolean value"))); |
| 1258 | } |
| 1259 | } |
| 1260 | else if (strcmp(key, "$db") == 0 && EnableUsersAdminDBCheck) |
| 1261 | { |
| 1262 | EnsureTopLevelFieldType(key, &connectionIter, BSON_TYPE_UTF8); |
| 1263 | |
| 1264 | dbFound = true; |
| 1265 | } |
| 1266 | else if (IsCommonSpecIgnoredField(key)) |
| 1267 | { |
| 1268 | continue; |
| 1269 | } |
| 1270 | else |
| 1271 | { |
no test coverage detected