From: jiyong.min Date: Tue, 19 Feb 2019 00:23:29 +0000 (+0900) Subject: Rearrange safe functions to remove duplicated code X-Git-Tag: submit/tizen/20190220.071038^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=af90c9108be3707dc07fbe4f75a27aac0a071b79;p=platform%2Fcore%2Fapi%2Fmedia-controller.git Rearrange safe functions to remove duplicated code - The shared library will be seperated. So new files are renamed mc_xxx. Change-Id: Ia091efcd0f9403948777bc63f808b7f2803eb76a --- diff --git a/include/media_controller_private.h b/include/media_controller_private.h old mode 100755 new mode 100644 index 107e932..1eeb218 --- a/include/media_controller_private.h +++ b/include/media_controller_private.h @@ -389,8 +389,6 @@ int mc_util_set_command_available(mc_priv_type_e priv_type, const char *name, co int mc_util_get_command_available(mc_priv_type_e priv_type, const char *name, const char *command_type, const char *command); char *mc_util_generate_uuid(void); int mc_util_bundle_to_string(bundle *bundle_data, char **str_data); -int mc_safe_strtoi(const char *buffer, int *value); -int mc_safe_strtoull(const char *buffer, unsigned long long *value); /* for d-bus IPC */ int mc_ipc_get_dbus_connection(GDBusConnection **conn, int *dref_count); diff --git a/src/media_controller_client.c b/src/media_controller_client.c index 48368e5..05fad18 100755 --- a/src/media_controller_client.c +++ b/src/media_controller_client.c @@ -17,6 +17,7 @@ #include "media_controller_client.h" #include "media_controller_private.h" #include "media_controller_db.h" +#include "mc_util.h" #include static void __client_server_cb(const char *interface_name, const char *signal_name, const char *message, const char *request_id, void *user_data); diff --git a/src/media_controller_server.c b/src/media_controller_server.c index b55c9b2..a1a0e2a 100755 --- a/src/media_controller_server.c +++ b/src/media_controller_server.c @@ -16,6 +16,7 @@ #include "media_controller_private.h" #include "media_controller_db.h" +#include "mc_util.h" #include #define MAX_PLAYLIST_LEN 100 diff --git a/src/media_controller_util.c b/src/media_controller_util.c old mode 100755 new mode 100644 index 0ba4519..8d15578 --- a/src/media_controller_util.c +++ b/src/media_controller_util.c @@ -220,39 +220,3 @@ int mc_util_bundle_to_string(bundle *bundle_data, char **str_data) return ret; } - -int mc_safe_strtoi(const char *buffer, int *value) -{ - char *end = NULL; - errno = 0; - mc_retvm_if(buffer == NULL || value == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid parameter"); - - const long sl = strtol(buffer, &end, 10); - - mc_retvm_if(end == buffer, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "not a decimal number"); - mc_retvm_if('\0' != *end, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "extra characters at end of input: %s", end); - mc_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "out of range of type long"); - mc_retvm_if(sl > INT_MAX, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "greater than INT_MAX"); - mc_retvm_if(sl < INT_MIN, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "smaller than INT_MIN"); - - *value = (int)sl; - - return MEDIA_CONTROLLER_ERROR_NONE; -} - -int mc_safe_strtoull(const char *buffer, unsigned long long *value) -{ - char *end = NULL; - errno = 0; - mc_retvm_if(buffer == NULL || value == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid parameter"); - - const unsigned long long ull = strtoull(buffer, &end, 10); - - mc_retvm_if(end == buffer, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "not a decimal number"); - mc_retvm_if('\0' != *end, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "extra characters at end of input: %s", end); - mc_retvm_if((ULLONG_MAX == ull) && (ERANGE == errno), MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "out of range of type long"); - - *value = (unsigned long long)ull; - - return MEDIA_CONTROLLER_ERROR_NONE; -} diff --git a/svc/include/mc_util.h b/svc/include/mc_util.h new file mode 100644 index 0000000..0003568 --- /dev/null +++ b/svc/include/mc_util.h @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef __TIZEN_MULTIMEDIA_MEDIA_CONTROLLER_UTIL_H__ +#define __TIZEN_MULTIMEDIA_MEDIA_CONTROLLER_UTIL_H__ + +int mc_safe_strtoi(const char *buffer, int *value); +int mc_safe_strtoull(const char *buffer, unsigned long long *value); + +#endif /*__TIZEN_MULTIMEDIA_MEDIA_CONTROLLER_UTIL_H__*/ diff --git a/svc/include/media_controller_cynara.h b/svc/include/media_controller_cynara.h index 743ae82..1a2c6d9 100644 --- a/svc/include/media_controller_cynara.h +++ b/svc/include/media_controller_cynara.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __TIZEN_MEDIA_CONTROLLER_CYNARA_H__ -#define __TIZEN_MEDIA_CONTROLLER_CYNARA_H__ +#ifndef __TIZEN_MULTIMEDIA_MEDIA_CONTROLLER_CYNARA_H__ +#define __TIZEN_MULTIMEDIA_MEDIA_CONTROLLER_CYNARA_H__ #include @@ -37,4 +37,4 @@ int mc_cynara_enable_credentials_passing(int sockfd); void mc_cynara_finish(void); -#endif/* _MEDIA_CONTROLLER_CYNARA_H_ */ +#endif/* __TIZEN_MULTIMEDIA_MEDIA_CONTROLLER_CYNARA_H__ */ diff --git a/svc/include/media_controller_db_util.h b/svc/include/media_controller_db_util.h index c47b66e..2989036 100644 --- a/svc/include/media_controller_db_util.h +++ b/svc/include/media_controller_db_util.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __TIZEN_MEDIA_CONTROLLER_DB_UTIL_H__ -#define __TIZEN_MEDIA_CONTROLLER_DB_UTIL_H__ +#ifndef __TIZEN_MULTIMEDIA_MEDIA_CONTROLLER_DB_UTIL_H__ +#define __TIZEN_MULTIMEDIA_MEDIA_CONTROLLER_DB_UTIL_H__ #include @@ -33,4 +33,4 @@ int mc_db_parse_and_update_db(uid_t uid, const char *data, int data_size); int mc_db_util_remove_dead_application(uid_t uid, const char *app_id, mc_priv_type_e priv_type); -#endif /*__TIZEN_MEDIA_CONTROLLER_DB_UTIL_H__*/ +#endif /*__TIZEN_MULTIMEDIA_MEDIA_CONTROLLER_DB_UTIL_H__*/ diff --git a/svc/include/media_controller_socket.h b/svc/include/media_controller_socket.h index d93f825..3dfd97f 100755 --- a/svc/include/media_controller_socket.h +++ b/svc/include/media_controller_socket.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __TIZEN_MEDIA_CONTROLLER_SOCKET_H__ -#define __TIZEN_MEDIA_CONTROLLER_SOCKET_H__ +#ifndef __TIZEN_MULTIMEDIA_MEDIA_CONTROLLER_SOCKET_H__ +#define __TIZEN_MULTIMEDIA_MEDIA_CONTROLLER_SOCKET_H__ #include #include @@ -73,4 +73,4 @@ int mc_ipc_accept_client_tcp(int serv_sock, int* client_sock); } #endif /* __cplusplus */ -#endif /* __TIZEN_MEDIA_CONTROLLER_SERVER_H__ */ +#endif /* __TIZEN_MULTIMEDIA_MEDIA_CONTROLLER_SOCKET_H__ */ diff --git a/svc/include/media_controller_svc.h b/svc/include/media_controller_svc.h index d6bb053..ce28f60 100755 --- a/svc/include/media_controller_svc.h +++ b/svc/include/media_controller_svc.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef _MEDIA_CONTROLLER_SVC_H_ -#define _MEDIA_CONTROLLER_SVC_H_ +#ifndef __TIZEN_MULTIMEDIA_MEDIA_CONTROLLER_SVC_H__ +#define __TIZEN_MULTIMEDIA_MEDIA_CONTROLLER_SVC_H__ #include @@ -41,4 +41,4 @@ int mc_svc_get_connection_cnt(void); } #endif /* __cplusplus */ -#endif/* _MEDIA_CONTROLLER_SVC_H_ */ +#endif/* __TIZEN_MULTIMEDIA_MEDIA_CONTROLLER_SVC_H__ */ diff --git a/svc/mc_util.c b/svc/mc_util.c new file mode 100644 index 0000000..969f294 --- /dev/null +++ b/svc/mc_util.c @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include +#include + +#include "media_controller_private.h" +#include "mc_util.h" + +int mc_safe_strtoi(const char *buffer, int *value) +{ + char *end = NULL; + errno = 0; + mc_retvm_if(buffer == NULL || value == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid parameter"); + + const long sl = strtol(buffer, &end, 10); + + mc_retvm_if(end == buffer, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "not a decimal number"); + mc_retvm_if('\0' != *end, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "extra characters at end of input: %s", end); + mc_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "out of range of type long"); + mc_retvm_if(sl > INT_MAX, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "greater than INT_MAX"); + mc_retvm_if(sl < INT_MIN, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "smaller than INT_MIN"); + + *value = (int)sl; + + return MEDIA_CONTROLLER_ERROR_NONE; +} + +int mc_safe_strtoull(const char *buffer, unsigned long long *value) +{ + char *end = NULL; + errno = 0; + mc_retvm_if(buffer == NULL || value == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid parameter"); + + const unsigned long long ull = strtoull(buffer, &end, 10); + + mc_retvm_if(end == buffer, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "not a decimal number"); + mc_retvm_if('\0' != *end, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "extra characters at end of input: %s", end); + mc_retvm_if((ULLONG_MAX == ull) && (ERANGE == errno), MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "out of range of type unsigned long long"); + + *value = ull; + + return MEDIA_CONTROLLER_ERROR_NONE; +} diff --git a/svc/media_controller_db_util.c b/svc/media_controller_db_util.c index d305fa2..f7bc6e0 100644 --- a/svc/media_controller_db_util.c +++ b/svc/media_controller_db_util.c @@ -22,6 +22,7 @@ #include "media_controller_private.h" #include "media_controller_db_util.h" +#include "mc_util.h" #define MC_DB_TRIGGER_PLAYLIST "cleanup_playlist" @@ -303,42 +304,6 @@ static int __mc_update_dead_server(void *handle, const char *server_name) return ret; } -int mc_safe_strtoi(const char *buffer, int *value) -{ - char *end = NULL; - errno = 0; - mc_retvm_if(buffer == NULL || value == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid parameter"); - - const long sl = strtol(buffer, &end, 10); - - mc_retvm_if(end == buffer, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "not a decimal number"); - mc_retvm_if('\0' != *end, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "extra characters at end of input: %s", end); - mc_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "out of range of type long"); - mc_retvm_if(sl > INT_MAX, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "greater than INT_MAX"); - mc_retvm_if(sl < INT_MIN, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "smaller than INT_MIN"); - - *value = (int)sl; - - return MEDIA_CONTROLLER_ERROR_NONE; -} - -int mc_safe_strtoull(const char *buffer, unsigned long long *value) -{ - char *end = NULL; - errno = 0; - mc_retvm_if(buffer == NULL || value == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid parameter"); - - const unsigned long long ull = strtoull(buffer, &end, 10); - - mc_retvm_if(end == buffer, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "not a decimal number"); - mc_retvm_if('\0' != *end, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "extra characters at end of input: %s", end); - mc_retvm_if((ULLONG_MAX == ull) && (ERANGE == errno), MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "out of range of type long"); - - *value = (unsigned long long)ull; - - return MEDIA_CONTROLLER_ERROR_NONE; -} - char *mc_db_get_db_path(uid_t uid) { char *db_path = NULL; diff --git a/svc/media_controller_socket.c b/svc/media_controller_socket.c old mode 100755 new mode 100644