From b7b409e089800d6e93eb3e12cdc60490ef06c9a8 Mon Sep 17 00:00:00 2001 From: Ghislain MARY <ghislain.mary@belledonne-communications.com> Date: Tue, 20 Dec 2016 15:27:57 +0100 Subject: [PATCH] Put error info code in its own files. --- coreapi/CMakeLists.txt | 1 + coreapi/Makefile.am | 1 + coreapi/error_info.c | 135 ++++++++++++++++++++++++ coreapi/im_encryption_engine.c | 2 +- coreapi/linphonecore.c | 95 ----------------- coreapi/misc.c | 46 -------- include/CMakeLists.txt | 1 + include/linphone/Makefile.am | 1 + include/linphone/core.h | 68 +----------- include/linphone/error_info.h | 123 +++++++++++++++++++++ include/linphone/im_encryption_engine.h | 8 +- 11 files changed, 269 insertions(+), 212 deletions(-) create mode 100644 coreapi/error_info.c create mode 100644 include/linphone/error_info.h diff --git a/coreapi/CMakeLists.txt b/coreapi/CMakeLists.txt index c69773f8c6..3fefc23ff6 100644 --- a/coreapi/CMakeLists.txt +++ b/coreapi/CMakeLists.txt @@ -76,6 +76,7 @@ set(LINPHONE_SOURCE_FILES_C ec-calibrator.c echo-tester.c enum.c + error_info.c event.c friend.c friendlist.c diff --git a/coreapi/Makefile.am b/coreapi/Makefile.am index 3a7b6e8357..5c03c9f7ed 100644 --- a/coreapi/Makefile.am +++ b/coreapi/Makefile.am @@ -43,6 +43,7 @@ liblinphone_la_SOURCES=\ ec-calibrator.c \ echo-tester.c \ enum.c enum.h \ + error_info.c \ event.c \ friend.c \ friendlist.c \ diff --git a/coreapi/error_info.c b/coreapi/error_info.c new file mode 100644 index 0000000000..5ebab0a8f7 --- /dev/null +++ b/coreapi/error_info.c @@ -0,0 +1,135 @@ +/* +error_info.c +Copyright (C) 2016 Belledonne Communications SARL + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "linphone/core.h" +#include "private.h" + + +const char *linphone_reason_to_string(LinphoneReason err){ + switch(err) { + case LinphoneReasonNone: + return "No error"; + case LinphoneReasonNoResponse: + return "No response"; + case LinphoneReasonForbidden: + return "Bad credentials"; + case LinphoneReasonDeclined: + return "Call declined"; + case LinphoneReasonNotFound: + return "User not found"; + case LinphoneReasonNotAnswered: + return "Not answered"; + case LinphoneReasonBusy: + return "Busy"; + case LinphoneReasonMedia: + return "Incompatible media capabilities"; + case LinphoneReasonIOError: + return "IO error"; + case LinphoneReasonDoNotDisturb: + return "Do not disturb"; + case LinphoneReasonUnauthorized: + return "Unauthorized"; + case LinphoneReasonNotAcceptable: + return "Not acceptable here"; + case LinphoneReasonNoMatch: + return "No match"; + case LinphoneReasonMovedPermanently: + return "Moved permanently"; + case LinphoneReasonGone: + return "Gone"; + case LinphoneReasonTemporarilyUnavailable: + return "Temporarily unavailable"; + case LinphoneReasonAddressIncomplete: + return "Address incomplete"; + case LinphoneReasonNotImplemented: + return "Not implemented"; + case LinphoneReasonBadGateway: + return "Bad gateway"; + case LinphoneReasonServerTimeout: + return "Server timeout"; + case LinphoneReasonUnknown: + return "Unknown error"; + } + return "unknown error"; +} + +LinphoneReason linphone_error_code_to_reason(int err) { + switch (err) { + case 200: + return LinphoneReasonNone; + case 301: + return LinphoneReasonMovedPermanently; + case 400: + return LinphoneReasonUnknown; + case 401: + return LinphoneReasonUnauthorized; + case 403: + return LinphoneReasonForbidden; + case 404: + return LinphoneReasonNotFound; + case 410: + return LinphoneReasonGone; + case 415: + return LinphoneReasonUnsupportedContent; + case 480: + return LinphoneReasonTemporarilyUnavailable; + case 481: + return LinphoneReasonNoMatch; + case 484: + return LinphoneReasonAddressIncomplete; + case 486: + return LinphoneReasonBusy; + case 488: + return LinphoneReasonNotAcceptable; + case 501: + return LinphoneReasonNotImplemented; + case 502: + return LinphoneReasonBadGateway; + case 503: + return LinphoneReasonIOError; + case 504: + return LinphoneReasonServerTimeout; + case 600: + return LinphoneReasonDoNotDisturb; + case 603: + return LinphoneReasonDeclined; + } + return LinphoneReasonUnknown; +} + + +LinphoneReason linphone_error_info_get_reason(const LinphoneErrorInfo *ei) { + const SalErrorInfo *sei = (const SalErrorInfo *)ei; + return linphone_reason_from_sal(sei->reason); +} + +const char *linphone_error_info_get_phrase(const LinphoneErrorInfo *ei) { + const SalErrorInfo *sei = (const SalErrorInfo *)ei; + return sei->status_string; +} + +const char *linphone_error_info_get_details(const LinphoneErrorInfo *ei) { + const SalErrorInfo *sei = (const SalErrorInfo *)ei; + return sei->warnings; +} + +int linphone_error_info_get_protocol_code(const LinphoneErrorInfo *ei) { + const SalErrorInfo *sei = (const SalErrorInfo *)ei; + return sei->protocol_code; +} diff --git a/coreapi/im_encryption_engine.c b/coreapi/im_encryption_engine.c index 16e7b8c09e..c09406e6ef 100644 --- a/coreapi/im_encryption_engine.c +++ b/coreapi/im_encryption_engine.c @@ -1,5 +1,5 @@ /* -ImEncryptionEgine.c +im_encryption_engine.c Copyright (C) 2016 Belledonne Communications SARL This program is free software; you can redistribute it and/or diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index c7f7c554f1..a91ccbb53d 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -6252,101 +6252,6 @@ LinphoneCallParams *linphone_core_create_call_params(LinphoneCore *lc, LinphoneC return NULL; } -const char *linphone_reason_to_string(LinphoneReason err){ - switch(err){ - case LinphoneReasonNone: - return "No error"; - case LinphoneReasonNoResponse: - return "No response"; - case LinphoneReasonForbidden: - return "Bad credentials"; - case LinphoneReasonDeclined: - return "Call declined"; - case LinphoneReasonNotFound: - return "User not found"; - case LinphoneReasonNotAnswered: - return "Not answered"; - case LinphoneReasonBusy: - return "Busy"; - case LinphoneReasonMedia: - return "Incompatible media capabilities"; - case LinphoneReasonIOError: - return "IO error"; - case LinphoneReasonDoNotDisturb: - return "Do not disturb"; - case LinphoneReasonUnauthorized: - return "Unauthorized"; - case LinphoneReasonNotAcceptable: - return "Not acceptable here"; - case LinphoneReasonNoMatch: - return "No match"; - case LinphoneReasonMovedPermanently: - return "Moved permanently"; - case LinphoneReasonGone: - return "Gone"; - case LinphoneReasonTemporarilyUnavailable: - return "Temporarily unavailable"; - case LinphoneReasonAddressIncomplete: - return "Address incomplete"; - case LinphoneReasonNotImplemented: - return "Not implemented"; - case LinphoneReasonBadGateway: - return "Bad gateway"; - case LinphoneReasonServerTimeout: - return "Server timeout"; - case LinphoneReasonUnknown: - return "Unknown error"; - } - return "unknown error"; -} - -LinphoneReason linphone_error_code_to_reason(int err) { - if (err == 200) { - return LinphoneReasonNone; - } else if (err == 503) { - return LinphoneReasonIOError; - } else if (err == 400) { - return LinphoneReasonUnknown; - } else if (err == 486) { - return LinphoneReasonBusy; - } else if (err == 603) { - return LinphoneReasonDeclined; - } else if (err == 600) { - return LinphoneReasonDoNotDisturb; - } else if (err == 403) { - return LinphoneReasonForbidden; - } else if (err == 415) { - return LinphoneReasonUnsupportedContent; - } else if (err == 404) { - return LinphoneReasonNotFound; - } else if (err == 480) { - return LinphoneReasonTemporarilyUnavailable; - } else if (err == 401) { - return LinphoneReasonUnauthorized; - } else if (err == 488) { - return LinphoneReasonNotAcceptable; - } else if (err == 481) { - return LinphoneReasonNoMatch; - } else if (err == 301) { - return LinphoneReasonMovedPermanently; - } else if (err == 410) { - return LinphoneReasonGone; - } else if (err == 484) { - return LinphoneReasonAddressIncomplete; - } else if (err == 501) { - return LinphoneReasonNotImplemented; - } else if (err == 504) { - return LinphoneReasonServerTimeout; - } else if (err == 502) { - return LinphoneReasonBadGateway; - } - return LinphoneReasonUnknown; -} - -const char *linphone_error_to_string(LinphoneReason err){ - return linphone_reason_to_string(err); -} - void linphone_core_enable_keep_alive(LinphoneCore* lc,bool_t enable) { #ifdef BUILD_UPNP if (linphone_core_get_firewall_policy(lc)==LinphonePolicyUseUpnp) { diff --git a/coreapi/misc.c b/coreapi/misc.c index 125d632f1f..6eaacc70dd 100644 --- a/coreapi/misc.c +++ b/coreapi/misc.c @@ -1237,52 +1237,6 @@ LinphoneReason linphone_reason_from_sal(SalReason r){ return ret; } -/** - * Get reason code from the error info. - * @param ei the error info. - * @return a #LinphoneReason - * @ingroup misc -**/ -LinphoneReason linphone_error_info_get_reason(const LinphoneErrorInfo *ei){ - const SalErrorInfo *sei=(const SalErrorInfo*)ei; - return linphone_reason_from_sal(sei->reason); -} - -/** - * Get textual phrase from the error info. - * This is the text that is provided by the peer in the protocol (SIP). - * @param ei the error info. - * @return the error phrase - * @ingroup misc -**/ -const char *linphone_error_info_get_phrase(const LinphoneErrorInfo *ei){ - const SalErrorInfo *sei=(const SalErrorInfo*)ei; - return sei->status_string; -} - -/** - * Provides additional information regarding the failure. - * With SIP protocol, the "Reason" and "Warning" headers are returned. - * @param ei the error info. - * @return more details about the failure. - * @ingroup misc -**/ -const char *linphone_error_info_get_details(const LinphoneErrorInfo *ei){ - const SalErrorInfo *sei=(const SalErrorInfo*)ei; - return sei->warnings; -} - -/** - * Get the status code from the low level protocol (ex a SIP status code). - * @param ei the error info. - * @return the status code. - * @ingroup misc -**/ -int linphone_error_info_get_protocol_code(const LinphoneErrorInfo *ei){ - const SalErrorInfo *sei=(const SalErrorInfo*)ei; - return sei->protocol_code; -} - /** * Set the name of the mediastreamer2 filter to be used for rendering video. * This is for advanced users of the library, mainly to workaround hardware/driver bugs. diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 569216e786..cd7b3c1290 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -32,6 +32,7 @@ set(HEADER_FILES content.h core.h core_utils.h + error_info.h event.h friend.h friendlist.h diff --git a/include/linphone/Makefile.am b/include/linphone/Makefile.am index 8e3d419171..f8d31657d0 100644 --- a/include/linphone/Makefile.am +++ b/include/linphone/Makefile.am @@ -12,6 +12,7 @@ linphone_include_HEADERS=\ content.h \ core.h \ core_utils.h \ + error_info.h \ event.h \ friend.h \ friendlist.h \ diff --git a/include/linphone/core.h b/include/linphone/core.h index 3199f78263..e6991957a2 100644 --- a/include/linphone/core.h +++ b/include/linphone/core.h @@ -158,67 +158,7 @@ struct _LinphoneCall; **/ typedef struct _LinphoneCall LinphoneCall; -/** - * Enum describing various failure reasons or contextual information for some events. - * @see linphone_call_get_reason() - * @see linphone_proxy_config_get_error() - * @see linphone_error_info_get_reason() - * @ingroup misc -**/ -enum _LinphoneReason{ - LinphoneReasonNone, - LinphoneReasonNoResponse, /**<No response received from remote*/ - LinphoneReasonForbidden, /**<Authentication failed due to bad credentials or resource forbidden*/ - LinphoneReasonDeclined, /**<The call has been declined*/ - LinphoneReasonNotFound, /**<Destination of the call was not found.*/ - LinphoneReasonNotAnswered, /**<The call was not answered in time (request timeout)*/ - LinphoneReasonBusy, /**<Phone line was busy */ - LinphoneReasonUnsupportedContent, /**<Unsupported content */ - LinphoneReasonIOError, /**<Transport error: connection failures, disconnections etc...*/ - LinphoneReasonDoNotDisturb, /**<Do not disturb reason*/ - LinphoneReasonUnauthorized, /**<Operation is unauthorized because missing credential*/ - LinphoneReasonNotAcceptable, /**<Operation is rejected due to incompatible or unsupported media parameters*/ - LinphoneReasonNoMatch, /**<Operation could not be executed by server or remote client because it didn't have any context for it*/ - LinphoneReasonMovedPermanently, /**<Resource moved permanently*/ - LinphoneReasonGone, /**<Resource no longer exists*/ - LinphoneReasonTemporarilyUnavailable, /**<Temporarily unavailable*/ - LinphoneReasonAddressIncomplete, /**<Address incomplete*/ - LinphoneReasonNotImplemented, /**<Not implemented*/ - LinphoneReasonBadGateway, /**<Bad gateway*/ - LinphoneReasonServerTimeout, /**<Server timeout*/ - LinphoneReasonUnknown /**Unknown reason*/ -}; - -#define LinphoneReasonBadCredentials LinphoneReasonForbidden - -/*for compatibility*/ -#define LinphoneReasonMedia LinphoneReasonUnsupportedContent - -/** - * Enum describing failure reasons. - * @ingroup misc -**/ -typedef enum _LinphoneReason LinphoneReason; - -/** - * Converts a LinphoneReason enum to a string. - * @ingroup misc -**/ -LINPHONE_PUBLIC const char *linphone_reason_to_string(LinphoneReason err); - -/** - * Converts a error code to a LinphoneReason. - * @ingroup misc -**/ -LINPHONE_PUBLIC LinphoneReason linphone_error_code_to_reason(int err); - -/** - * Object representing full details about a signaling error or status. - * All LinphoneErrorInfo object returned by the liblinphone API are readonly and transcients. For safety they must be used immediately - * after obtaining them. Any other function call to the liblinphone may change their content or invalidate the pointer. - * @ingroup misc -**/ -typedef struct _LinphoneErrorInfo LinphoneErrorInfo; +#include "linphone/error_info.h" /** * Enum describing the authentication methods @@ -235,11 +175,6 @@ enum _LinphoneAuthMethod { **/ typedef enum _LinphoneAuthMethod LinphoneAuthMethod; -LINPHONE_PUBLIC LinphoneReason linphone_error_info_get_reason(const LinphoneErrorInfo *ei); -LINPHONE_PUBLIC const char *linphone_error_info_get_phrase(const LinphoneErrorInfo *ei); -LINPHONE_PUBLIC const char *linphone_error_info_get_details(const LinphoneErrorInfo *ei); -LINPHONE_PUBLIC int linphone_error_info_get_protocol_code(const LinphoneErrorInfo *ei); - /* linphone dictionary */ LINPHONE_PUBLIC LinphoneDictionary* linphone_dictionary_new(void); LINPHONE_PUBLIC LinphoneDictionary * linphone_dictionary_clone(const LinphoneDictionary* src); @@ -3381,6 +3316,7 @@ LINPHONE_PUBLIC const bctbx_list_t *linphone_core_get_auth_info_list(const Linph * @param username the SIP username to be authenticated (mandatory) * @param sip_domain the SIP domain name (optional) * @return a #LinphoneAuthInfo + * @ingroup authentication **/ LINPHONE_PUBLIC const LinphoneAuthInfo *linphone_core_find_auth_info(LinphoneCore *lc, const char *realm, const char *username, const char *sip_domain); diff --git a/include/linphone/error_info.h b/include/linphone/error_info.h new file mode 100644 index 0000000000..b25e31630a --- /dev/null +++ b/include/linphone/error_info.h @@ -0,0 +1,123 @@ +/* +error_info.h +Copyright (C) 2016 Belledonne Communications SARL + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef LINPHONE_ERROR_INFO_H +#define LINPHONE_ERROR_INFO_H + +/** + * @addtogroup misc + * @{ + */ + +/** + * Enum describing various failure reasons or contextual information for some events. + * @see linphone_call_get_reason() + * @see linphone_proxy_config_get_error() + * @see linphone_error_info_get_reason() +**/ +enum _LinphoneReason{ + LinphoneReasonNone, + LinphoneReasonNoResponse, /**< No response received from remote */ + LinphoneReasonForbidden, /**< Authentication failed due to bad credentials or resource forbidden */ + LinphoneReasonDeclined, /**< The call has been declined */ + LinphoneReasonNotFound, /**< Destination of the call was not found */ + LinphoneReasonNotAnswered, /**< The call was not answered in time (request timeout) */ + LinphoneReasonBusy, /**< Phone line was busy */ + LinphoneReasonUnsupportedContent, /**< Unsupported content */ + LinphoneReasonIOError, /**< Transport error: connection failures, disconnections etc... */ + LinphoneReasonDoNotDisturb, /**< Do not disturb reason */ + LinphoneReasonUnauthorized, /**< Operation is unauthorized because missing credential */ + LinphoneReasonNotAcceptable, /**< Operation is rejected due to incompatible or unsupported media parameters */ + LinphoneReasonNoMatch, /**< Operation could not be executed by server or remote client because it didn't have any context for it */ + LinphoneReasonMovedPermanently, /**< Resource moved permanently */ + LinphoneReasonGone, /**< Resource no longer exists */ + LinphoneReasonTemporarilyUnavailable, /**< Temporarily unavailable */ + LinphoneReasonAddressIncomplete, /**< Address incomplete */ + LinphoneReasonNotImplemented, /**< Not implemented */ + LinphoneReasonBadGateway, /**< Bad gateway */ + LinphoneReasonServerTimeout, /**< Server timeout */ + LinphoneReasonUnknown /**< Unknown reason */ +}; + +#define LinphoneReasonBadCredentials LinphoneReasonForbidden + +/*for compatibility*/ +#define LinphoneReasonMedia LinphoneReasonUnsupportedContent + +/** + * Enum describing failure reasons. +**/ +typedef enum _LinphoneReason LinphoneReason; + +/** + * Converts a LinphoneReason enum to a string. + * @param[in] err A #LinphoneReason + * @return The string representation of the specified LinphoneReason +**/ +LINPHONE_PUBLIC const char *linphone_reason_to_string(LinphoneReason err); + +/** + * Converts a error code to a LinphoneReason. + * @param[in] err An error code + * @return The LinphoneReason corresponding to the specified error code +**/ +LINPHONE_PUBLIC LinphoneReason linphone_error_code_to_reason(int err); + +/** + * Object representing full details about a signaling error or status. + * All LinphoneErrorInfo object returned by the liblinphone API are readonly and transcients. For safety they must be used immediately + * after obtaining them. Any other function call to the liblinphone may change their content or invalidate the pointer. +**/ +typedef struct _LinphoneErrorInfo LinphoneErrorInfo; + +/** + * Get reason code from the error info. + * @param[in] ei ErrorInfo object + * @return A #LinphoneReason +**/ +LINPHONE_PUBLIC LinphoneReason linphone_error_info_get_reason(const LinphoneErrorInfo *ei); + +/** + * Get textual phrase from the error info. + * This is the text that is provided by the peer in the protocol (SIP). + * @param[in] ei ErrorInfo object + * @return The error phrase +**/ +LINPHONE_PUBLIC const char * linphone_error_info_get_phrase(const LinphoneErrorInfo *ei); + +/** + * Provides additional information regarding the failure. + * With SIP protocol, the "Reason" and "Warning" headers are returned. + * @param[in] ei ErrorInfo object + * @return More details about the failure +**/ +LINPHONE_PUBLIC const char * linphone_error_info_get_details(const LinphoneErrorInfo *ei); + +/** + * Get the status code from the low level protocol (ex a SIP status code). + * @param[in] ei ErrorInfo object + * @return The status code +**/ +LINPHONE_PUBLIC int linphone_error_info_get_protocol_code(const LinphoneErrorInfo *ei); + +/** + * @} + */ + +#endif /* LINPHONE_ERROR_INFO_H */ diff --git a/include/linphone/im_encryption_engine.h b/include/linphone/im_encryption_engine.h index 63796ebf06..5b6d1038f6 100644 --- a/include/linphone/im_encryption_engine.h +++ b/include/linphone/im_encryption_engine.h @@ -1,5 +1,5 @@ /* -ImEncryptionEgine.h +im_encryption_engine.h Copyright (C) 2016 Belledonne Communications SARL This program is free software; you can redistribute it and/or @@ -17,8 +17,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef IM_ENCRYPTION_ENGINE_H -#define IM_ENCRYPTION_ENGINE_H +#ifndef LINPHONE_IM_ENCRYPTION_ENGINE_H +#define LINPHONE_IM_ENCRYPTION_ENGINE_H #include <mediastreamer2/mscommon.h> @@ -254,4 +254,4 @@ LINPHONE_PUBLIC void linphone_im_encryption_engine_cbs_set_generate_file_transfe * @} */ -#endif /* IM_ENCRYPTION_ENGINE_H */ +#endif /* LINPHONE_IM_ENCRYPTION_ENGINE_H */ -- GitLab