1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-06-23 06:25:24 +00:00

Update: Refactor error codes to a key-indexed array

Instead of storing the ID in the icecast_error_tag, use it as
array index for the error codes lookup list. That way its not
needed anymore to iterate the whole list to lookup errors by id.
This commit is contained in:
Marvin Scholz 2020-09-04 01:27:29 +02:00
parent 987bdec373
commit d22ce7b95d
2 changed files with 209 additions and 133 deletions

View File

@ -16,140 +16,215 @@
#include "logging.h" #include "logging.h"
#define CATMODULE "errors" #define CATMODULE "errors"
// cut -d' ' -f2 x | while read x; do printf " {.id = %-60s .http_status = xxx,\n .message = \"\"},\n" "$x",; done static const icecast_error_t __errors[ICECAST_ERROR_END_SENTINEL] =
static const icecast_error_t __errors[] = { {
{.id = ICECAST_ERROR_ADMIN_DEST_NOT_RUNNING, .http_status = 400, [ICECAST_ERROR_ADMIN_DEST_NOT_RUNNING] = {
.uuid = "52735a81-16fe-4d7e-9984-5aed8a941055", .http_status = 400,
.message = "Destination not running"}, .uuid = "52735a81-16fe-4d7e-9984-5aed8a941055",
{.id = ICECAST_ERROR_ADMIN_METADAT_BADCALL, .http_status = 400, .message = "Destination not running"
.uuid = "85d33e67-5c4e-4511-b4fa-3ca69ccd03de", },
.message = "illegal metadata call"}, [ICECAST_ERROR_ADMIN_METADAT_BADCALL] = {
{.id = ICECAST_ERROR_ADMIN_METADAT_NO_SUCH_ACTION, .http_status = 501, .http_status = 400,
.uuid = "14f4d814-98d9-468c-8a0b-ba5e74c9d771", .uuid = "85d33e67-5c4e-4511-b4fa-3ca69ccd03de",
.message = "No such action"}, .message = "illegal metadata call"
{.id = ICECAST_ERROR_ADMIN_MISSING_PARAMETER, .http_status = 400, },
.uuid = "cb11dc71-6149-454c-8d4e-47a3af26b03a", [ICECAST_ERROR_ADMIN_METADAT_NO_SUCH_ACTION] = {
.message = "Missing parameter"}, .http_status = 501,
{.id = ICECAST_ERROR_ADMIN_missing_parameter, .http_status = 400, .uuid = "14f4d814-98d9-468c-8a0b-ba5e74c9d771",
.uuid = "8be9ef0a-2b32-450c-aec9-a414ca0c074c", .message = "No such action"
.message = "missing parameter"}, },
{.id = ICECAST_ERROR_ADMIN_MOUNT_NOT_ACCEPT_URL_UPDATES, .http_status = 501, [ICECAST_ERROR_ADMIN_MISSING_PARAMETER] = {
.uuid = "3bed51bb-a10f-4af3-9965-4e67181de7d6", .http_status = 400,
.message = "mountpoint will not accept URL updates"}, .uuid = "cb11dc71-6149-454c-8d4e-47a3af26b03a",
{.id = ICECAST_ERROR_ADMIN_NO_SUCH_DESTINATION, .http_status = 404, .message = "Missing parameter"
.uuid = "c5f1ee06-46a0-4697-9f01-6e9fc333d555", },
.message = "No such destination"}, [ICECAST_ERROR_ADMIN_missing_parameter] = {
{.id = ICECAST_ERROR_ADMIN_ROLEMGN_ADD_NOSYS, .http_status = 501, .http_status = 400,
.uuid = "7e1a8426-2ae1-4a6b-bfd9-59d8f8153021", .uuid = "8be9ef0a-2b32-450c-aec9-a414ca0c074c",
.message = "Adding users to role not supported by role"}, .message = "missing parameter"
{.id = ICECAST_ERROR_ADMIN_ROLEMGN_DELETE_NOSYS, .http_status = 501, },
.uuid = "367fbad1-389e-4292-bba8-c97984e616cc", [ICECAST_ERROR_ADMIN_MOUNT_NOT_ACCEPT_URL_UPDATES] = {
.message = "Deleting users from role not supported by role"}, .http_status = 501,
{.id = ICECAST_ERROR_ADMIN_ROLEMGN_ROLE_NOT_FOUND, .http_status = 404, .uuid = "3bed51bb-a10f-4af3-9965-4e67181de7d6",
.uuid = "59fe9c81-8c34-49ff-800f-7ec42ea498be", .message = "mountpoint will not accept URL updates"
.message = "Role not found"}, },
{.id = ICECAST_ERROR_ADMIN_SOURCE_DOES_NOT_EXIST, .http_status = 404, [ICECAST_ERROR_ADMIN_NO_SUCH_DESTINATION] = {
.uuid = "2f51a026-02e4-4fe4-bf9d-cc16557b3b65", .http_status = 404,
.message = "Source does not exist"}, .uuid = "c5f1ee06-46a0-4697-9f01-6e9fc333d555",
{.id = ICECAST_ERROR_ADMIN_SOURCE_IS_NOT_AVAILABLE, .http_status = 400, .message = "No such destination"
.uuid = "00b9d977-f41d-455f-820f-6d457dffb246", },
.message = "Source is not available"}, [ICECAST_ERROR_ADMIN_ROLEMGN_ADD_NOSYS] = {
{.id = ICECAST_ERROR_ADMIN_SUPPLIED_MOUNTPOINTS_ARE_IDENTICAL, .http_status = 400, .http_status = 501,
.uuid = "4be9a010-7a3f-44e4-b74d-3c6d9c4f7236", .uuid = "7e1a8426-2ae1-4a6b-bfd9-59d8f8153021",
.message = "supplied mountpoints are identical"}, .message = "Adding users to role not supported by role"
{.id = ICECAST_ERROR_ADMIN_UNRECOGNISED_COMMAND, .http_status = 400, },
.uuid = "811bddac-5be5-4580-9cde-7b849e66dfe5", [ICECAST_ERROR_ADMIN_ROLEMGN_DELETE_NOSYS] = {
.message = "unrecognised command"}, .http_status = 501,
{.id = ICECAST_ERROR_AUTH_BUSY, .http_status = 503, .uuid = "367fbad1-389e-4292-bba8-c97984e616cc",
.uuid = "26708754-8f98-4191-81d1-7fb7246200d6", .message = "Deleting users from role not supported by role"
.message = "busy, please try again later"}, },
{.id = ICECAST_ERROR_CON_CONTENT_TYPE_NOSYS, .http_status = 415, [ICECAST_ERROR_ADMIN_ROLEMGN_ROLE_NOT_FOUND] = {
.uuid = "f684ad3c-513b-4d87-9a66-424788bc6adb", .http_status = 404,
.message = "Content-type not supported"}, .uuid = "59fe9c81-8c34-49ff-800f-7ec42ea498be",
{.id = ICECAST_ERROR_CON_INTERNAL_FORMAT_ALLOC_ERROR, .http_status = 500, .message = "Role not found"
.uuid = "47a4b11b-5d2a-46e2-8948-942e7b0af3e6", },
.message = "internal format allocation problem"}, [ICECAST_ERROR_ADMIN_SOURCE_DOES_NOT_EXIST] = {
{.id = ICECAST_ERROR_CON_MISSING_PASS_PARAMETER, .http_status = 400 /* XXX */, .http_status = 404,
.uuid = "b59c3a05-e2b1-4a14-8798-bbe1ae46603b", .uuid = "2f51a026-02e4-4fe4-bf9d-cc16557b3b65",
.message = "missing pass parameter"}, .message = "Source does not exist"
{.id = ICECAST_ERROR_CON_MOUNT_IN_USE, .http_status = 409, },
.uuid = "c5724467-5f85-48c7-b45a-915c3150c292", [ICECAST_ERROR_ADMIN_SOURCE_IS_NOT_AVAILABLE] = {
.message = "Mountpoint in use"}, .http_status = 400,
{.id = ICECAST_ERROR_CON_MOUNTPOINT_NOT_STARTING_WITH_SLASH, .http_status = 400, .uuid = "00b9d977-f41d-455f-820f-6d457dffb246",
.uuid = "1ae45ead-40fc-4de2-b56f-e54d3247f2ee", .message = "Source is not available"
.message = "source mountpoint not starting with /"}, },
{.id = ICECAST_ERROR_CON_NO_CONTENT_TYPE_GIVEN, .http_status = 400, [ICECAST_ERROR_ADMIN_SUPPLIED_MOUNTPOINTS_ARE_IDENTICAL] = {
.uuid = "2cd86778-ac30-49e7-a108-26d627a7923b", .http_status = 400,
.message = "No Content-type given"}, .uuid = "4be9a010-7a3f-44e4-b74d-3c6d9c4f7236",
{.id = ICECAST_ERROR_CON_PER_CRED_CLIENT_LIMIT, .http_status = 429, .message = "supplied mountpoints are identical"
.uuid = "9c72c1ec-f638-4d33-a077-6acbbff25317", },
.message = "Reached limit of concurrent connections on those credentials"}, [ICECAST_ERROR_ADMIN_UNRECOGNISED_COMMAND] = {
{.id = ICECAST_ERROR_CON_rejecting_client_for_whatever_reason, .http_status = 403 /* XXX */, .http_status = 400,
.uuid = "534ee9af-8be5-4645-a839-501d22d541bd", .uuid = "811bddac-5be5-4580-9cde-7b849e66dfe5",
.message = "Rejecting client for whatever reason"}, .message = "unrecognised command"
{.id = ICECAST_ERROR_CON_SOURCE_CLIENT_LIMIT, .http_status = 503, },
.uuid = "c770182d-c854-422a-a8e5-7142689234a3", [ICECAST_ERROR_AUTH_BUSY] = {
.message = "too many sources connected"}, .http_status = 503,
{.id = ICECAST_ERROR_CON_UNIMPLEMENTED, .http_status = 501, .uuid = "26708754-8f98-4191-81d1-7fb7246200d6",
.uuid = "58ce6cb4-72b4-49da-8ad2-feaf775bc61e", .message = "busy, please try again later"
.message = "Unimplemented"}, },
{.id = ICECAST_ERROR_CON_UNKNOWN_REQUEST, .http_status = 405, [ICECAST_ERROR_CON_CONTENT_TYPE_NOSYS] = {
.uuid = "78f590cc-8812-40d5-a4ef-17344ab75b35", .http_status = 415,
.message = "unknown request"}, .uuid = "f684ad3c-513b-4d87-9a66-424788bc6adb",
{.id = ICECAST_ERROR_CON_UPGRADE_ERROR, .http_status = 400 /* XXX */, .message = "Content-type not supported"
.uuid = "ec16f654-f262-415f-ab91-95703ae33704", },
.message = "Can not upgrade protocol"}, [ICECAST_ERROR_CON_INTERNAL_FORMAT_ALLOC_ERROR] = {
{.id = ICECAST_ERROR_FSERV_FILE_NOT_FOUND, .http_status = 404, .http_status = 500,
.uuid = "18c32b43-0d8e-469d-b434-10133cdd06ad", .uuid = "47a4b11b-5d2a-46e2-8948-942e7b0af3e6",
.message = "The file you requested could not be found"}, .message = "internal format allocation problem"
{.id = ICECAST_ERROR_FSERV_FILE_NOT_READABLE, .http_status = 404 /* XXX */, },
.uuid = "c883d55d-fb41-4f4c-8800-563f5542f51d", [ICECAST_ERROR_CON_MISSING_PASS_PARAMETER] = {
.message = "File not readable"}, .http_status = 400 /* XXX */,
{.id = ICECAST_ERROR_FSERV_REQUEST_RANGE_NOT_SATISFIABLE, .http_status = 416, .uuid = "b59c3a05-e2b1-4a14-8798-bbe1ae46603b",
.uuid = "5874cc51-770b-42b5-82d2-737b2b406b30", .message = "missing pass parameter"
.message = "Request Range Not Satisfiable"}, },
{.id = ICECAST_ERROR_GEN_BUFFER_REALLOC, .http_status = 500, [ICECAST_ERROR_CON_MOUNT_IN_USE] = {
.uuid = "cda8203e-f237-4090-8d43-544efdd6295c", .http_status = 409,
.message = "Buffer reallocation failed."}, .uuid = "c5724467-5f85-48c7-b45a-915c3150c292",
{.id = ICECAST_ERROR_GEN_CLIENT_LIMIT, .http_status = 503, .message = "Mountpoint in use"
.uuid = "87fd3e61-6702-4473-b506-f616d27a142f", },
.message = "Icecast connection limit reached"}, [ICECAST_ERROR_CON_MOUNTPOINT_NOT_STARTING_WITH_SLASH] = {
{.id = ICECAST_ERROR_GEN_CLIENT_NEEDS_TO_AUTHENTICATE, .http_status = 401, .http_status = 400,
.uuid = "25387198-0643-4577-9139-7c4f24f59d4a", .uuid = "1ae45ead-40fc-4de2-b56f-e54d3247f2ee",
.message = "You need to authenticate"}, .message = "source mountpoint not starting with /"
{.id = ICECAST_ERROR_GEN_HEADER_GEN_FAILED, .http_status = 500, },
.uuid = "a8b3c3fe-cb87-45fe-9a9d-ee4c2075d43a", [ICECAST_ERROR_CON_NO_CONTENT_TYPE_GIVEN] = {
.message = "Header generation failed."}, .http_status = 400,
{.id = ICECAST_ERROR_GEN_MEMORY_EXHAUSTED, .http_status = 503, .uuid = "2cd86778-ac30-49e7-a108-26d627a7923b",
.uuid = "18411e73-713e-4910-b7e4-52a2e324b4e0", .message = "No Content-type given"
.message = "memory exhausted"}, },
{.id = ICECAST_ERROR_SOURCE_MOUNT_UNAVAILABLE, .http_status = 404 /* XXX */, [ICECAST_ERROR_CON_PER_CRED_CLIENT_LIMIT] = {
.uuid = "88d06875-fcf2-4417-84af-05866c97745c", .http_status = 429,
.message = "Mount unavailable"}, .uuid = "9c72c1ec-f638-4d33-a077-6acbbff25317",
{.id = ICECAST_ERROR_SOURCE_STREAM_PREPARATION_ERROR, .http_status = 500 /* XXX */, .message = "Reached limit of concurrent connections on those credentials"
.uuid = "9e50d94d-f03d-4515-8216-577bf8e9f70d", },
.message = "Stream preparation error"}, [ICECAST_ERROR_CON_rejecting_client_for_whatever_reason] = {
{.id = ICECAST_ERROR_XSLT_PARSE, .http_status = 404 /* XXX */, .http_status = 403 /* XXX */,
.uuid = "f86b5b28-c1f8-49f6-a4cd-a18e2a6a44fd", .uuid = "534ee9af-8be5-4645-a839-501d22d541bd",
.message = "Could not parse XSLT file"}, .message = "Rejecting client for whatever reason"
{.id = ICECAST_ERROR_XSLT_problem, .http_status = 500, },
.uuid = "d3c6e4b3-7d6e-4191-a81b-970273067ae3", [ICECAST_ERROR_CON_SOURCE_CLIENT_LIMIT] = {
.message = "XSLT problem"}, .http_status = 503,
{.id = ICECAST_ERROR_RECURSIVE_ERROR, .http_status = 500, .uuid = "c770182d-c854-422a-a8e5-7142689234a3",
.uuid = "13489d5c-eae6-4bf3-889e-ec1fa9a9b9ac", .message = "too many sources connected"
.message = "Recursive error"} },
[ICECAST_ERROR_CON_UNIMPLEMENTED] = {
.http_status = 501,
.uuid = "58ce6cb4-72b4-49da-8ad2-feaf775bc61e",
.message = "Unimplemented"
},
[ICECAST_ERROR_CON_UNKNOWN_REQUEST] = {
.http_status = 405,
.uuid = "78f590cc-8812-40d5-a4ef-17344ab75b35",
.message = "unknown request"
},
[ICECAST_ERROR_CON_UPGRADE_ERROR] = {
.http_status = 400 /* XXX */,
.uuid = "ec16f654-f262-415f-ab91-95703ae33704",
.message = "Can not upgrade protocol"
},
[ICECAST_ERROR_FSERV_FILE_NOT_FOUND] = {
.http_status = 404,
.uuid = "18c32b43-0d8e-469d-b434-10133cdd06ad",
.message = "The file you requested could not be found"
},
[ICECAST_ERROR_FSERV_FILE_NOT_READABLE] = {
.http_status = 404 /* XXX */,
.uuid = "c883d55d-fb41-4f4c-8800-563f5542f51d",
.message = "File not readable"
},
[ICECAST_ERROR_FSERV_REQUEST_RANGE_NOT_SATISFIABLE] = {
.http_status = 416,
.uuid = "5874cc51-770b-42b5-82d2-737b2b406b30",
.message = "Request Range Not Satisfiable"
},
[ICECAST_ERROR_GEN_BUFFER_REALLOC] = {
.http_status = 500,
.uuid = "cda8203e-f237-4090-8d43-544efdd6295c",
.message = "Buffer reallocation failed."
},
[ICECAST_ERROR_GEN_CLIENT_LIMIT] = {
.http_status = 503,
.uuid = "87fd3e61-6702-4473-b506-f616d27a142f",
.message = "Icecast connection limit reached"
},
[ICECAST_ERROR_GEN_CLIENT_NEEDS_TO_AUTHENTICATE] = {
.http_status = 401,
.uuid = "25387198-0643-4577-9139-7c4f24f59d4a",
.message = "You need to authenticate"
},
[ICECAST_ERROR_GEN_HEADER_GEN_FAILED] = {
.http_status = 500,
.uuid = "a8b3c3fe-cb87-45fe-9a9d-ee4c2075d43a",
.message = "Header generation failed."
},
[ICECAST_ERROR_GEN_MEMORY_EXHAUSTED] = {
.http_status = 503,
.uuid = "18411e73-713e-4910-b7e4-52a2e324b4e0",
.message = "memory exhausted"
},
[ICECAST_ERROR_SOURCE_MOUNT_UNAVAILABLE] = {
.http_status = 404 /* XXX */,
.uuid = "88d06875-fcf2-4417-84af-05866c97745c",
.message = "Mount unavailable"
},
[ICECAST_ERROR_SOURCE_STREAM_PREPARATION_ERROR] = {
.http_status = 500 /* XXX */,
.uuid = "9e50d94d-f03d-4515-8216-577bf8e9f70d",
.message = "Stream preparation error"
},
[ICECAST_ERROR_XSLT_PARSE] = {
.http_status = 404 /* XXX */,
.uuid = "f86b5b28-c1f8-49f6-a4cd-a18e2a6a44fd",
.message = "Could not parse XSLT file"
},
[ICECAST_ERROR_XSLT_problem] = {
.http_status = 500,
.uuid = "d3c6e4b3-7d6e-4191-a81b-970273067ae3",
.message = "XSLT problem"
},
[ICECAST_ERROR_RECURSIVE_ERROR] = {
.http_status = 500,
.uuid = "13489d5c-eae6-4bf3-889e-ec1fa9a9b9ac",
.message = "Recursive error"
},
}; };
const icecast_error_t * error_get_by_id(icecast_error_id_t id) { const icecast_error_t * error_get_by_id(icecast_error_id_t id) {
size_t i; if (id >= ICECAST_ERROR_END_SENTINEL || id < 0)
return NULL;
for (i = 0; i < (sizeof(__errors)/sizeof(*__errors)); i++) { return &(__errors[id]);
if (__errors[i].id == id) {
return &(__errors[i]);
}
}
return NULL;
} }
const icecast_error_t * error_get_by_uuid(const char *uuid) const icecast_error_t * error_get_by_uuid(const char *uuid)

View File

@ -10,7 +10,7 @@
#define __ERRORS_H__ #define __ERRORS_H__
typedef enum { typedef enum {
ICECAST_ERROR_ADMIN_DEST_NOT_RUNNING, ICECAST_ERROR_ADMIN_DEST_NOT_RUNNING = 0,
ICECAST_ERROR_ADMIN_METADAT_BADCALL, ICECAST_ERROR_ADMIN_METADAT_BADCALL,
ICECAST_ERROR_ADMIN_METADAT_NO_SUCH_ACTION, ICECAST_ERROR_ADMIN_METADAT_NO_SUCH_ACTION,
ICECAST_ERROR_ADMIN_MISSING_PARAMETER, ICECAST_ERROR_ADMIN_MISSING_PARAMETER,
@ -49,11 +49,12 @@ typedef enum {
ICECAST_ERROR_SOURCE_STREAM_PREPARATION_ERROR, ICECAST_ERROR_SOURCE_STREAM_PREPARATION_ERROR,
ICECAST_ERROR_XSLT_PARSE, ICECAST_ERROR_XSLT_PARSE,
ICECAST_ERROR_XSLT_problem, ICECAST_ERROR_XSLT_problem,
ICECAST_ERROR_RECURSIVE_ERROR ICECAST_ERROR_RECURSIVE_ERROR,
ICECAST_ERROR_END_SENTINEL /* This element must always be the last! */
} icecast_error_id_t; } icecast_error_id_t;
struct icecast_error_tag { struct icecast_error_tag {
const icecast_error_id_t id;
const int http_status; const int http_status;
const char *uuid; const char *uuid;
const char *message; const char *message;