diff --git a/CHANGELOG.md b/CHANGELOG.md index ebeb82b..56bac3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,28 +1,17 @@ ## Next Release -BREAKING CHANGES: -FEATURES: -IMPROVEMENTS: +BREAKING CHANGES: +FEATURES: +IMPROVEMENTS: BUG FIXES: -## v3.37 -BUG FIXES: - * bug fix for dev_id=0 - * bug fix for users_data js api call - -## v3.36 - +## v3.35 + FEATURES: * add table users_data * add table revoked_tokens * add jwt support * add web_pipe_count command for track_* pipes - * add multi db - -## v3.35 - -BUG FIXES: - * bug `Table doesn't exist` for table `conference_members` ## v3.34 @@ -56,49 +45,20 @@ BUG FIXES: ## v3.30 BUG FIXES: - - * fix bug in cmake files + * errors when restart mysql server * fix bug #36 CometServerApi.js:824 Invalid pipe name subscription web_chat_pipe chatControl * fix bug #35 _cometServerApi.prototype.send_msg("pipe_log\n"+pipe_name+"\n"+marker+"\n"); * fix bug #34 tabSignal.connect is not a function - -## v3.29 - -BUG FIXES: - - * fix bug in star scripts - -IMPROVEMENTS: - - * add parametr connection_attempts to section db - * rebild docs in .md files and impruve links in docs - - -## v3.28 - -BUG FIXES: - - * fix bug in star and stop scripts - * fix bug in stats - ## v3.26 BUG FIXES: - - * bug fix to query `select * from pipes where name in ("web_test");` + * Command systemctl stop comet.service does not work on Ubuntu 16 ( #17 ) IMPROVEMENTS: - -* Added parameter `send_user_online_events` to `main` -* Added parameter `send_user_offline_events` to `main` -* Added parameter `save_users_last_online_time` to `main` - -* Added section `cluster` -* Added section `cometqlproxy` -* Added clustering mechanism #15 + * Added pidfile option in section `main`.`pidfile` * Added queryes like `set paramName paramValue` @@ -120,51 +80,35 @@ BUG FIXES: * Was rename parameter `benchmark` to `statistics` -## v3.23 - -IMPROVEMENTS: - - * added parametr `allow` to section `statistics` in .ini file - * added ini file documentation in to file ./docs/comet.ini.md - ## v3.22 -BUG FIXES: - - * last online time did not save - IMPROVEMENTS: * Added functions for aggregating statistics of using server * Added settings to .ini file for controll content-type header -* Added dosc in dokuwiki format -* Was translated comments in comet.ini -* Added the white list of hosts to .ini file - + ## v3.21 IMPROVEMENTS: * Added caching in memory for sending static files * Added cache-control headers for get requests - + ## v3.2 BUG FIXES: * Js Api version 3.28 (Fix bug in auth callbacks) * Fix bug in auth callbacks * complete api function getTrackPipeUsers + ## v3.1 - -FEATURES: + +FEATURES: * Added function to getting users in track_pipes from js api - * Added deleting api query for pipes history #5 + * Added deleting api query for pipes history #5 * Added CODE_OF_CONDUCT.md * Added CONTRIBUTING.md * Added CHANGELOG.md - * Added server version to ws answer - * Js Api version 3.26 - * Removed message `setState` from console log in Js Api - * Fixed bug when Js api in offline + * Added server version to ws answer \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a76b97..d8bf913 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -175,12 +175,35 @@ set_property(TARGET libjwta PROPERTY # Создает исполняемый файл с именем cpp_comet из исходников -add_executable(cpp_comet ${HASHLIB2PLUS_EXE} ${SOURCE_EXE} ${TINYXML2_EXE} ${ESL_EXE} ) +add_executable(cppcomet ${HASHLIB2PLUS_EXE} ${SOURCE_EXE} ${TINYXML2_EXE} ${ESL_EXE} ) # Подключение библиотеки pthreads -target_link_libraries (cpp_comet ${CMAKE_THREAD_LIBS_INIT} ${MYSQL_LIBRARIES} ${OPENSSL_LIBRARIES} crypt uuid libjwta) +target_link_libraries (cppcomet ${CMAKE_THREAD_LIBS_INIT} ${MYSQL_LIBRARIES} ${OPENSSL_LIBRARIES} crypt uuid libjwta) #cmake ./ && make +#INSTALL( DIRECTORY DESTINATION usr/myproject ) +#mkdir /etc/comet-server +#cp ./comet-service.sh /etc/comet-server/comet-service.sh +#cp ./comet.ini /etc/comet-server/comet.ini +#cp ./cpp_comet /etc/comet-server/cpp_comet +# https://mirkokiefer.com/cmake-by-example-f95eb47d45b1 + +set(INSTALL_CONF_DIR + /etc/comet-server) + +set(INSTALL_BIN_DIR + /usr/bin) + +set(INSTALL_SYSTEMD_DIR + /etc/systemd/system) + +install(FILES comet.service DESTINATION ${INSTALL_SYSTEMD_DIR}) +install(FILES comet.ini DESTINATION ${INSTALL_CONF_DIR}) +install(FILES comet-service.sh DESTINATION ${INSTALL_CONF_DIR}) +install(TARGETS cppcomet DESTINATION ${INSTALL_BIN_DIR}) + +# https://cmake.org/pipermail/cmake/2009-September/031887.html +# INSTALL(SCRIPT CopyIfNotExists.cmake) \ No newline at end of file diff --git a/comet-service.sh b/comet-service.sh index ab85d0c..c148f9b 100755 --- a/comet-service.sh +++ b/comet-service.sh @@ -3,7 +3,7 @@ echo "CppComet" PATH=/sbin:/usr/sbin:/bin:/usr/bin -RUNDIR=/etc/comet-server/ +RUNDIR=/usr/bin EXTRAOPTS= PIDFILE=/var/run/cppcomet.pid @@ -17,7 +17,7 @@ case "$1" in echo "CppComet already run" else echo "Starting CppComet" - ./cpp_comet > /var/log/cpp_comet.log 2>/var/log/cpp_comet.log & + /usr/bin/cppcomet --conf /etc/comet-server/comet.ini > /var/log/cpp_comet.log 2>/var/log/cpp_comet.log & fi ;; stop) @@ -41,7 +41,7 @@ case "$1" in echo "pid file does not exist" fi echo "Starting CppComet" - ./cpp_comet > /var/log/cpp_comet.log 2>/var/log/cpp_comet.log & + /usr/bin/cppcomet > /var/log/cpp_comet.log 2>/var/log/cpp_comet.log & ;; esac diff --git a/comet.ini b/comet.ini index 3ed99a0..1452a0d 100644 --- a/comet.ini +++ b/comet.ini @@ -1,11 +1,10 @@ [main] isTest = false; включение тестов - -dev_index_size = 100000 + node_name = n1 useQueryLoger = false -mono_password = false +mono_password = false # EE_VERSION base_dir = static diff --git a/db.sql b/db.sql index cf2e139..625079f 100644 --- a/db.sql +++ b/db.sql @@ -2,22 +2,16 @@ -- version 3.4.11.1deb2+deb7u8 -- http://www.phpmyadmin.net -- --- Хост: test.comet.su:3305 --- Время создания: Янв 24 2018 г., 14:56 --- Версия сервера: 5.5.57 +-- Хост: db-n1.comet.su:3306 +-- Время создания: Янв 09 2018 г., 02:24 +-- Версия сервера: 5.5.58 -- Версия PHP: 5.6.31-1~dotdeb+7.1 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; - -- --- База данных: `comet_db_saas` +-- База данных: `comet_db` -- -- -------------------------------------------------------- @@ -41,6 +35,21 @@ CREATE TABLE IF NOT EXISTS `conference` ( -- -------------------------------------------------------- +-- +-- Структура таблицы `dev_config` +-- + +CREATE TABLE IF NOT EXISTS `dev_config` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `key` char(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, + `url` char(255) CHARACTER SET ascii NOT NULL DEFAULT '*', + `active_time` int(11) NOT NULL DEFAULT '0' COMMENT 'Время последней активности', + PRIMARY KEY (`id`), + KEY `key` (`key`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=500001 ; + +-- -------------------------------------------------------- + -- -- Структура таблицы `log_event` -- @@ -49,7 +58,7 @@ CREATE TABLE IF NOT EXISTS `log_event` ( `id` int(11) NOT NULL AUTO_INCREMENT, `text` varchar(250) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1661 ; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1637 ; -- -------------------------------------------------------- @@ -102,19 +111,6 @@ CREATE TABLE IF NOT EXISTS `pipe_messages` ( -- -------------------------------------------------------- --- --- Структура таблицы `revoked_tokens` --- - -CREATE TABLE IF NOT EXISTS `revoked_tokens` ( - `dev_id` int(11) NOT NULL, - `token` varbinary(600) NOT NULL, - `time` int(11) NOT NULL, - PRIMARY KEY (`dev_id`,`token`) -) ENGINE=InnoDB DEFAULT CHARSET=ascii COLLATE=ascii_bin; - --- -------------------------------------------------------- - -- -- Структура таблицы `users_auth` -- @@ -137,7 +133,7 @@ CREATE TABLE IF NOT EXISTS `users_auth` ( CREATE TABLE IF NOT EXISTS `users_data` ( `dev_id` int(9) NOT NULL, `user_id` int(11) NOT NULL, - `data` varbinary(600) NOT NULL, + `data` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL, PRIMARY KEY (`dev_id`,`user_id`), KEY `dev_id` (`dev_id`), KEY `user_id` (`user_id`) @@ -178,6 +174,13 @@ CREATE TABLE IF NOT EXISTS `users_time` ( KEY `user_id` (`user_id`) ) ENGINE=MEMORY DEFAULT CHARSET=utf8; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +-- +-- Структура таблицы `revoked_tokens` +-- + +CREATE TABLE IF NOT EXISTS `revoked_tokens` ( + `dev_id` int(11) NOT NULL, + `token` varbinary(600) NOT NULL, + `time` int(11) NOT NULL, + PRIMARY KEY (`dev_id`,`token`) +) ENGINE=InnoDB DEFAULT CHARSET=ascii COLLATE=ascii_bin; diff --git a/src/Client_connection.cpp b/src/Client_connection.cpp index 288fadf..cd2ef03 100644 --- a/src/Client_connection.cpp +++ b/src/Client_connection.cpp @@ -57,6 +57,7 @@ Client_connection::~Client_connection(){ */ int Client_connection::un_subscription(thread_data* local_buf) { + auto t = TagTimer::mtime(); local_buf->setThreadStatus('U'); for(int i=0; i< MAX_SUBSCRIPTION_PIPE; i++) { @@ -98,6 +99,7 @@ int Client_connection::un_subscription(thread_data* local_buf) } bzero(subscriptions, MAX_SUBSCRIPTION_PIPE); + TagTimer::add("Client_connection::un_subscription", t); return 0; } @@ -115,12 +117,14 @@ int Client_connection::un_subscription(thread_data* local_buf) */ int Client_connection::ws_subscription(thread_data* local_buf, char* event_data,int client, int len) { + auto t = TagTimer::mtime(); local_buf->setThreadStatus('S'); int event_data_len = strlen(event_data); if(event_data_len > SUBSCRIPTION_DATA_LEN) { TagLoger::error(Log_ClientServer, 0, "\x1b[1;31mToo many letters[%d]\x1b[0m\n", event_data_len); message(local_buf, base64_encode( (const char*) "{\"error\":\"Too many letters\"}").data(), "_answer"); + TagTimer::add("Client_connection::subscription", t); return -1; } @@ -141,6 +145,7 @@ int Client_connection::ws_subscription(thread_data* local_buf, char* event_data, *p = 0; if(p - start_subscription_name < 2) { + TagTimer::add("Client_connection::subscription", t); return 0; } @@ -148,12 +153,14 @@ int Client_connection::ws_subscription(thread_data* local_buf, char* event_data, { TagLoger::warn(Log_ClientServer, 0, "\x1b[1;31mToo many letters [%d]\x1b[0m\n", i); message(local_buf, base64_encode( (const char*) "{\"error\":\"Too many letters\"}").data(), "_answer"); + TagTimer::add("Client_connection::subscription", t); return 0; } TagLoger::log(Log_ClientServer, 0, "start_key::[%zu][%s]\n",strlen(start_subscription_name), start_subscription_name); // В замен sadd_printf + local_buf->setThreadStatus('i'); devManager::instance()->getDevInfo(web_user_dev_id)->getPipe(std::string(start_subscription_name))->insert(fd); subscriptions[i] = start_subscription_name; @@ -190,9 +197,8 @@ int Client_connection::ws_subscription(thread_data* local_buf, char* event_data, } } } - - - if(memcmp(subscriptions[i], "trust_", strlen("trust_")) == 0) + + /*if(memcmp(subscriptions[i], "trust_", strlen("trust_")) == 0) { // Отправка последних 20 сообщений из канала trust_ local_buf->stm.pipe_messages_select->execute(web_user_dev_id, subscriptions[i], 20); @@ -208,7 +214,7 @@ int Client_connection::ws_subscription(thread_data* local_buf, char* event_data, message(local_buf, local_buf->stm.pipe_messages_select->result_message, NULL, MESSAGE_TEXT, serverData); } local_buf->stm.pipe_messages_select->free(); - } + }*/ p++; i++; @@ -219,10 +225,12 @@ int Client_connection::ws_subscription(thread_data* local_buf, char* event_data, { TagLoger::error(Log_ClientServer, 0, "\x1b[1;31mChannel name is too long [%s]\x1b[0m\n", start_subscription_name); message(local_buf, base64_encode( (const char*) "{\"error\":\"Channel name is too long\"}").data(), "_answer"); + TagTimer::add("Client_connection::subscription", t); return -1; } } + TagTimer::add("Client_connection::subscription", t); return 0; } @@ -934,6 +942,9 @@ int Client_connection::web_socket_request_message(int client, int len, thread_da // Установим 0 для удобства обозначения границы сообщения str_data[msg_data_len] = 0; + + local_buf->setThreadStatus('E'); + int res = 0; if( memcmp( str_data, "subscription", strlen("subscription")) == 0) { @@ -944,48 +955,56 @@ int Client_connection::web_socket_request_message(int client, int len, thread_da } else if(memcmp( str_data, "user_status", strlen("user_status")) == 0) { + local_buf->setThreadStatus('a'); TagLoger::log(Log_ClientServer, 0, "comand-user_status:\n" ); res = get_user_last_online_time(local_buf, (char*)(str_data + strlen("user_status") + 1), client, msg_data_len); if(res == -1) return -1; } else if(memcmp( str_data, "pipe_count", strlen("pipe_count")) == 0) { + local_buf->setThreadStatus('b'); TagLoger::log(Log_ClientServer, 0, "comand-pipe_count:\n" ); res = get_pipe_count(local_buf, (char*)(str_data + strlen("pipe_count") + 1), client, msg_data_len); if(res == -1) return -1; } else if(memcmp( str_data, "statistics", strlen("statistics")) == 0) { + local_buf->setThreadStatus('d'); TagLoger::log(Log_ClientServer, 0, "comand-statistics:\n" ); res = log_statistics(local_buf, (char*)(str_data + strlen("statistics") + 1), client, msg_data_len); if(res == -1) return -1; } else if(memcmp( str_data, "web_pipe2", strlen("web_pipe2")) == 0) { + local_buf->setThreadStatus('e'); TagLoger::log(Log_ClientServer, 0, "comand-web_pipe:web_pipe_msg_v2\n" ); res = web_pipe_msg_v2(local_buf, (char*)(str_data + strlen("web_pipe2") + 1), client, msg_data_len); if(res == -1) return -1; } else if(memcmp( str_data, "pipe_log", strlen("pipe_log")) == 0) { + local_buf->setThreadStatus('f'); TagLoger::log(Log_ClientServer, 0, "comand-pipe_log:\n" ); res = get_pipe_log(local_buf, (char*)(str_data + strlen("pipe_log") + 1), client, msg_data_len); if(res == -1) return -1; } else if(memcmp( str_data, "track_pipe_users", strlen("track_pipe_users")) == 0) { + local_buf->setThreadStatus('g'); TagLoger::log(Log_ClientServer, 0, "comand-web_pipe:track_pipe_users\n" ); res = track_pipe_users(local_buf, (char*)(str_data + strlen("track_pipe_users") + 1), client, msg_data_len); if(res == -1) return -1; } else if(memcmp( str_data, "user_data", strlen("user_data")) == 0) { + local_buf->setThreadStatus('k'); TagLoger::log(Log_ClientServer, 0, "user_data:\n" ); res = web_user_data(local_buf, (char*)(str_data + strlen("user_data") + 1), client, msg_data_len); if(res == -1) return -1; } else if(memcmp( str_data, "cgi_call", strlen("cgi_call")) == 0) { + local_buf->setThreadStatus('u'); TagLoger::log(Log_ClientServer, 0, "comand-cgi_call:\n" ); res = cgi_call(local_buf, (char*)(str_data + strlen("cgi_call") + 1), client, msg_data_len); if(res == -1) return -1; @@ -1035,12 +1054,15 @@ int Client_connection::log_statistics(thread_data* local_buf, const char* event_ */ int Client_connection::get_pipe_log(thread_data* local_buf, char* event_data,int client, int len) { + auto t = TagTimer::mtime(); char *pipe_name = event_data; char* pMarker = checking_channel_name( local_buf, pipe_name); if(pMarker == NULL) { TagLoger::warn(Log_ClientServer, 0, "\x1b[1;31msget_pipe_log Invalid channel name\x1b[0m\n" ); message(local_buf, base64_encode((const char*) "{\"data\":{\"number_messages\":-1,\"error\":\"Invalid channel name.\"},\"event_name\":\"answer\"}").data(), "_answer"); + + TagTimer::add("Client_connection::get_pipe_log", t); return -1; } @@ -1052,6 +1074,8 @@ int Client_connection::get_pipe_log(thread_data* local_buf, char* event_data,int { TagLoger::warn(Log_ClientServer, 0, "\x1b[1;31msget_pipe_log Invalid marker value\x1b[0m\n" ); message(local_buf, base64_encode((const char*) "{\"data\":{\"number_messages\":-1,\"error\":\"Invalid marker value.\"},\"event_name\":\"answer\"}").data(), "_answer"); + + TagTimer::add("Client_connection::get_pipe_log", t); return -1; } @@ -1059,6 +1083,8 @@ int Client_connection::get_pipe_log(thread_data* local_buf, char* event_data,int { TagLoger::warn(Log_ClientServer, 0, "\x1b[1;31mget_pipe_log argument error\x1b[0m\n"); message(local_buf, base64_encode((const char*) "{\"data\":{\"number_messages\":-1,\"error\":\"get_pipe_log argument error\"},\"event_name\":\"answer\"}").data(), "_answer"); + + TagTimer::add("Client_connection::get_pipe_log", t); return -1; } @@ -1067,6 +1093,7 @@ int Client_connection::get_pipe_log(thread_data* local_buf, char* event_data,int *end_pMarker = 0; send_pipe_log(local_buf, pipe_name, pMarker); + TagTimer::add("Client_connection::get_pipe_log", t); return 0; } @@ -1081,6 +1108,7 @@ int Client_connection::get_pipe_log(thread_data* local_buf, char* event_data,int */ int Client_connection::get_user_last_online_time(thread_data* local_buf, char* event_data,int client, int len) { + auto t = TagTimer::mtime(); char *pipe_name = event_data; int delta = 0; @@ -1091,6 +1119,7 @@ int Client_connection::get_user_last_online_time(thread_data* local_buf, char* e snprintf(answer_data, 300,"{\"data\":\"%ld\",\"event_name\":\"user_status_%ld\"}", time(0) - user_time, get_user_id ); // @todo Проверить работоспособность message(local_buf, base64_encode((const char*) answer_data).data(), "_answer_user_status"); + TagTimer::add("Client_connection::get_user_last_online_time", t); return 0; } @@ -1104,11 +1133,14 @@ int Client_connection::get_user_last_online_time(thread_data* local_buf, char* e */ int Client_connection::get_pipe_count(thread_data* local_buf, char* event_data,int client, int len) { + auto t = TagTimer::mtime(); char *pipe_name = event_data; char* pMarker = checking_channel_name( local_buf, pipe_name); if(pMarker == NULL) { message(local_buf, base64_encode((const char*) "{\"data\":{\"number_messages\":-1,\"error\":\"Invalid pipe name.\"},\"event_name\":\"answer\"}").data(), "_answer"); + + TagTimer::add("Client_connection::get_pipe_count", t); return -1; } @@ -1119,6 +1151,8 @@ int Client_connection::get_pipe_count(thread_data* local_buf, char* event_data,i if(end_pMarker == NULL) { message(local_buf, base64_encode((const char*) "{\"data\":{\"number_messages\":-1,\"error\":\"Invalid pipe name.\"},\"event_name\":\"answer\"}").data(), "_answer"); + + TagTimer::add("Client_connection::get_pipe_count", t); return -1; } @@ -1131,8 +1165,11 @@ int Client_connection::get_pipe_count(thread_data* local_buf, char* event_data,i { TagLoger::log(Log_ClientServer, 0, "\x1b[1;31mget_pipe_count argument error\x1b[0m\n"); message(local_buf, base64_encode((const char*) "{\"data\":{\"number_messages\":-1,\"error\":\"get_pipe_count argument error\"},\"event_name\":\"answer\"}").data(), "_answer"); + + TagTimer::add("Client_connection::get_pipe_count", t); return -1; } + TagTimer::add("Client_connection::get_pipe_count", t); return 0; } @@ -1214,6 +1251,7 @@ char* Client_connection::checking_event_name(thread_data* local_buf, const char* */ int Client_connection::web_pipe_msg_v2(thread_data* local_buf, char* event_data,int client, int len) { + auto t = TagTimer::mtime(); int set_user_id = web_user_id; char* name = event_data; if(memcmp(name, "@web_", 5) == 0) @@ -1227,12 +1265,14 @@ int Client_connection::web_pipe_msg_v2(thread_data* local_buf, char* event_data, TagLoger::warn(Log_ClientServer, 0, "\x1b[1;31mweb_pipe_msg_v2 Invalid channel name [name=%s]\x1b[0m\n", name); // @todo добавить ссылку на описание ошибки message(local_buf, base64_encode((const char*) "{\"data\":{\"number_messages\":-1,\"error\":\"[pipe_msg2] Invalid channel name. The channel should begin with web_\"},\"event_name\":\"answer\"}").data(), "_answer"); + TagTimer::add("Client_connection::web_pipe_msg_v2", t); return -1; } char* p = checking_channel_name( local_buf, name); if( p == 0) { + TagTimer::add("Client_connection::web_pipe_msg_v2", t); return -1; } *p = 0; @@ -1243,6 +1283,7 @@ int Client_connection::web_pipe_msg_v2(thread_data* local_buf, char* event_data, p = checking_event_name( local_buf, event_name); if( p == 0) { + TagTimer::add("Client_connection::web_pipe_msg_v2", t); return -1; } @@ -1256,6 +1297,7 @@ int Client_connection::web_pipe_msg_v2(thread_data* local_buf, char* event_data, { // @todo добавить ссылку на описание ошибки message(local_buf, base64_encode((const char*) "{\"data\":{\"number_messages\":-1,\"error\":\"Invalid value auth_type.\"},\"event_name\":\"answer\"}").data(), "_answer"); + TagTimer::add("Client_connection::web_pipe_msg_v2", t); return -1; } @@ -1363,8 +1405,11 @@ int Client_connection::web_pipe_msg_v2(thread_data* local_buf, char* event_data, if(message(local_buf, base64_encode( (const unsigned char*)local_buf->answer_buf.getAndUnlock(), answer_len ).data() , rdname) < 0) { + TagTimer::add("Client_connection::web_pipe_msg_v2", t); return -1; } + + TagTimer::add("Client_connection::web_pipe_msg_v2", t); return 0; } @@ -1401,22 +1446,26 @@ int Client_connection::cgi_call(thread_data* local_buf, char* event_data,int cli */ int Client_connection::web_user_data(thread_data* local_buf, char* event_data,int client, int len) { + auto t = TagTimer::mtime(); char* pMarker = event_data; char* end_pMarker = checking_channel_name( local_buf, pMarker); if(end_pMarker == NULL) { message(local_buf, base64_encode((const char*) "{\"data\":{\"user_id\":-1,\"user_data\":\"\",\"error\":\"Invalid marker name.\"},\"event_name\":\"answer\"}").data(), "_answer"); + TagTimer::add("Client_connection::web_user_data", t); return -1; } - *(end_pMarker-1) = 0; + *(end_pMarker) = 0; + end_pMarker++; int userId = 0; try{ userId = std::stoi(end_pMarker); }catch(...) { - message(local_buf, base64_encode((const char*) "{\"data\":{\"user_id\":-1,\"user_data\":\"\",\"error\":\"Invalid marker name.\"},\"event_name\":\"answer\"}").data(), "_answer"); + message(local_buf, base64_encode((const char*) "{\"data\":{\"user_id\":-1,\"user_data\":\"\",\"error\":\"Invalid marker name.\"},\"event_name\":\"answer\"}").data(), "_answer"); + TagTimer::add("Client_connection::web_user_data", t); return -1; } @@ -1443,8 +1492,9 @@ int Client_connection::web_user_data(thread_data* local_buf, char* event_data,in local_buf->stm.users_data_select->free(); + TagTimer::add("Client_connection::web_user_data", t); return 0; -} +} /** * Обрабатывает событие пришедшие от js для получения списка подписчиков на канале track_* @@ -1455,6 +1505,7 @@ int Client_connection::web_user_data(thread_data* local_buf, char* event_data,in */ int Client_connection::track_pipe_users(thread_data* local_buf, char* event_data,int client, int len) { + auto t = TagTimer::mtime(); char pipe_name[PIPE_NAME_LEN+1]; bzero(pipe_name, PIPE_NAME_LEN+1); @@ -1971,6 +2022,9 @@ int Client_connection::request(int client, int len, thread_data* local_buf) local_buf->setThreadStatus('Q'); TagLoger::log(Log_ClientServer, 0, " >HTTP REQUEST_WS\n"); r = web_socket_request_message(client,len, local_buf); + + + local_buf->setThreadStatus('C'); } if(isAuthUser) @@ -2025,6 +2079,8 @@ int Client_connection::message(thread_data* local_buf, const char* msg, const ch return message(local_buf, msg, name, message_type, "\"nodata\":true"); } + local_buf->setThreadStatus('m'); + auto t = TagTimer::mtime(); int server_data_len = strlen(server_data) + 1; TagLoger::log(Log_ClientServer, 0, "server_data_len->%d\n",server_data_len); @@ -2081,6 +2137,7 @@ int Client_connection::message(thread_data* local_buf, const char* msg, const ch devManager::instance()->getDevInfo(web_user_dev_id)->incrMessages(); // pthread_mutex_unlock(&message_mutex); + TagTimer::add("Client_connection::message", t); return ret; } @@ -2124,6 +2181,7 @@ int Client_connection::set_offline(thread_data* local_buf) return web_close(); } + auto t = TagTimer::mtime(); online_decr(local_buf); //pthread_mutex_lock(&request_mutex); isOnLine = false; @@ -2148,5 +2206,6 @@ int Client_connection::set_offline(thread_data* local_buf) TagLoger::error(Log_ClientServer, 0, "\x1b[31mset_online:web_close() = -1, fd=%d\x1b[0m\n", fd); } + TagTimer::add("Client_connection::set_offline", t); return close; } diff --git a/src/CometQL.cc b/src/CometQL.cc index 34a5fe5..edb92c3 100644 --- a/src/CometQL.cc +++ b/src/CometQL.cc @@ -1,8 +1,8 @@ -/* A Bison parser, made by GNU Bison 3.0.2. */ +/* A Bison parser, made by GNU Bison 3.0.4. */ /* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc. 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 @@ -44,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "3.0.2" +#define YYBISON_VERSION "3.0.4" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -305,7 +305,7 @@ extern int yydebug; /* Value type. */ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED -typedef union YYSTYPE YYSTYPE; + union YYSTYPE { #line 115 "src/CometQL.y" /* yacc.c:355 */ @@ -318,6 +318,8 @@ union YYSTYPE #line 320 "src/CometQL.cc" /* yacc.c:355 */ }; + +typedef union YYSTYPE YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_DECLARED 1 #endif @@ -331,7 +333,7 @@ int yyparse (void* qInfo); /* Copy the second part of user declarations. */ -#line 335 "src/CometQL.cc" /* yacc.c:358 */ +#line 337 "src/CometQL.cc" /* yacc.c:358 */ #ifdef short # undef short @@ -1510,7 +1512,7 @@ yyparse (void* qInfo) setTokValue(qData, qData->arg_set.value, (yyvsp[0].tokStruct)); //printf("\tСписок баз данных\n"); } -#line 1514 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1516 "src/CometQL.cc" /* yacc.c:1646 */ break; case 10: @@ -1521,7 +1523,7 @@ yyparse (void* qInfo) setTokValue(qData, qData->arg_set.varible, (yyvsp[-1].tokStruct)); setTokValue(qData, qData->arg_set.value, (yyvsp[0].tokStruct)); } -#line 1525 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1527 "src/CometQL.cc" /* yacc.c:1646 */ break; case 11: @@ -1533,7 +1535,7 @@ yyparse (void* qInfo) setTokValue(qData, qData->arg_set.varible, (yyvsp[-1].tokStruct)); setTokValue(qData, qData->arg_set.value, (yyvsp[0].tokStruct)); } -#line 1537 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1539 "src/CometQL.cc" /* yacc.c:1646 */ break; case 12: @@ -1544,7 +1546,7 @@ yyparse (void* qInfo) qData->arg_show.command = TOK_DATABASES; //printf("\tСписок баз данных\n"); } -#line 1548 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1550 "src/CometQL.cc" /* yacc.c:1646 */ break; case 13: @@ -1555,7 +1557,7 @@ yyparse (void* qInfo) qData->arg_show.command = TOK_PROCESSLIST; //printf("\tСписок потоков\n"); } -#line 1559 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1561 "src/CometQL.cc" /* yacc.c:1646 */ break; case 14: @@ -1566,7 +1568,7 @@ yyparse (void* qInfo) qData->arg_show.command = TOK_TABLES; //printf("\tСписок таблиц\n"); } -#line 1570 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1572 "src/CometQL.cc" /* yacc.c:1646 */ break; case 15: @@ -1578,7 +1580,7 @@ yyparse (void* qInfo) //printf("\tСписок таблиц\n"); } -#line 1582 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1584 "src/CometQL.cc" /* yacc.c:1646 */ break; case 16: @@ -1589,7 +1591,7 @@ yyparse (void* qInfo) qData->arg_show.command = TOK_STATUS; //printf("\tСтатус системы\n"); } -#line 1593 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1595 "src/CometQL.cc" /* yacc.c:1646 */ break; case 17: @@ -1601,7 +1603,7 @@ yyparse (void* qInfo) qData->arg_show.command = TOK_COLUMNS; //printf("\tСписок колонок\n"); } -#line 1605 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1607 "src/CometQL.cc" /* yacc.c:1646 */ break; case 18: @@ -1613,7 +1615,7 @@ yyparse (void* qInfo) qData->arg_show.command = TOK_COLUMNS; //printf("\tСписок колонок\n"); } -#line 1617 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1619 "src/CometQL.cc" /* yacc.c:1646 */ break; case 19: @@ -1626,7 +1628,7 @@ yyparse (void* qInfo) setTokValue(qData, qData->arg_show.like, (yyvsp[0].tokStruct)); //printf("\tПоказать переменные\n"); } -#line 1630 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1632 "src/CometQL.cc" /* yacc.c:1646 */ break; case 23: @@ -1635,7 +1637,7 @@ yyparse (void* qInfo) setQData; qData->arg_show.flag = FLAG_GLOBAL; } -#line 1639 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1641 "src/CometQL.cc" /* yacc.c:1646 */ break; case 24: @@ -1644,7 +1646,7 @@ yyparse (void* qInfo) setQData; qData->arg_show.flag = FLAG_SESSION; } -#line 1648 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1650 "src/CometQL.cc" /* yacc.c:1646 */ break; case 25: @@ -1653,7 +1655,7 @@ yyparse (void* qInfo) setQData; qData->arg_show.flag = FLAG_FILESYSTEM; } -#line 1657 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1659 "src/CometQL.cc" /* yacc.c:1646 */ break; case 26: @@ -1662,7 +1664,7 @@ yyparse (void* qInfo) setQData; qData->arg_show.flag = FLAG_RAM; } -#line 1666 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1668 "src/CometQL.cc" /* yacc.c:1646 */ break; case 27: @@ -1671,7 +1673,7 @@ yyparse (void* qInfo) setQData; qData->arg_show.flag = FLAG_AVG; } -#line 1675 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1677 "src/CometQL.cc" /* yacc.c:1646 */ break; case 28: @@ -1680,7 +1682,7 @@ yyparse (void* qInfo) setQData; qData->arg_show.flag = FLAG_UPTIME; } -#line 1684 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1686 "src/CometQL.cc" /* yacc.c:1646 */ break; case 30: @@ -1689,7 +1691,7 @@ yyparse (void* qInfo) setQData; qData->arg_show.flag = FLAG_FULL; } -#line 1693 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1695 "src/CometQL.cc" /* yacc.c:1646 */ break; case 31: @@ -1702,7 +1704,7 @@ yyparse (void* qInfo) //printf("\tВыборка %s\n", $2.text); } -#line 1706 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1708 "src/CometQL.cc" /* yacc.c:1646 */ break; case 32: @@ -1713,7 +1715,7 @@ yyparse (void* qInfo) qData->arg_select.command = TOK_DATABASE; //printf("\tВыборка DATABASE\n"); } -#line 1717 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1719 "src/CometQL.cc" /* yacc.c:1646 */ break; case 33: @@ -1723,7 +1725,7 @@ yyparse (void* qInfo) qData->command = TOK_SELECT; qData->arg_select.command = TOK_FROM; } -#line 1727 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1729 "src/CometQL.cc" /* yacc.c:1646 */ break; case 36: @@ -1738,7 +1740,7 @@ yyparse (void* qInfo) qData->where.whereExprValueCount = 0; qData->where.whereExprCount++; } -#line 1742 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1744 "src/CometQL.cc" /* yacc.c:1646 */ break; case 37: @@ -1757,7 +1759,7 @@ yyparse (void* qInfo) qData->where.whereExprCount++; qData->where.whereExprValueCount = 0; } -#line 1761 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1763 "src/CometQL.cc" /* yacc.c:1646 */ break; case 38: @@ -1776,7 +1778,7 @@ yyparse (void* qInfo) qData->where.whereExprCount++; qData->where.whereExprValueCount = 0; } -#line 1780 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1782 "src/CometQL.cc" /* yacc.c:1646 */ break; case 39: @@ -1785,7 +1787,7 @@ yyparse (void* qInfo) setQData; qData->where.whereExprCondition[qData->where.whereExprCount] = TOK_LIKE; } -#line 1789 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1791 "src/CometQL.cc" /* yacc.c:1646 */ break; case 40: @@ -1794,7 +1796,7 @@ yyparse (void* qInfo) setQData; qData->where.whereExprCondition[qData->where.whereExprCount] = MORE; } -#line 1798 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1800 "src/CometQL.cc" /* yacc.c:1646 */ break; case 41: @@ -1803,7 +1805,7 @@ yyparse (void* qInfo) setQData; qData->where.whereExprCondition[qData->where.whereExprCount] = LESS; } -#line 1807 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1809 "src/CometQL.cc" /* yacc.c:1646 */ break; case 42: @@ -1812,7 +1814,7 @@ yyparse (void* qInfo) setQData; qData->where.whereExprCondition[qData->where.whereExprCount] = EQUALLY; } -#line 1816 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1818 "src/CometQL.cc" /* yacc.c:1646 */ break; case 43: @@ -1821,7 +1823,7 @@ yyparse (void* qInfo) setQData; qData->where.whereExprCondition[qData->where.whereExprCount] = TOK_IN; } -#line 1825 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1827 "src/CometQL.cc" /* yacc.c:1646 */ break; case 46: @@ -1831,7 +1833,7 @@ yyparse (void* qInfo) setTokValue(qData, qData->where.whereExprColum[qData->where.whereExprCount], (yyvsp[0].tokStruct)); //printf("\texpr_Name %d[%.3s...]\n", qData->where.whereExprCount, $1.text); } -#line 1835 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1837 "src/CometQL.cc" /* yacc.c:1646 */ break; case 47: @@ -1850,7 +1852,7 @@ yyparse (void* qInfo) //printf("\texpr_Value %d[%.3s...]\n", qData->where.whereExprValueCount, $1.text); } } -#line 1854 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1856 "src/CometQL.cc" /* yacc.c:1646 */ break; case 49: @@ -1860,7 +1862,7 @@ yyparse (void* qInfo) setTokValue(qData, qData->orderBy.name, (yyvsp[-1].tokStruct)); qData->orderBy.type = TOK_ASC; } -#line 1864 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1866 "src/CometQL.cc" /* yacc.c:1646 */ break; case 50: @@ -1870,7 +1872,7 @@ yyparse (void* qInfo) setTokValue(qData, qData->orderBy.name, (yyvsp[-1].tokStruct)); qData->orderBy.type = TOK_ASC; } -#line 1874 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1876 "src/CometQL.cc" /* yacc.c:1646 */ break; case 51: @@ -1880,7 +1882,7 @@ yyparse (void* qInfo) setTokValue(qData, qData->orderBy.name, (yyvsp[-1].tokStruct)); qData->orderBy.type = TOK_DESC; } -#line 1884 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1886 "src/CometQL.cc" /* yacc.c:1646 */ break; case 53: @@ -1891,7 +1893,7 @@ yyparse (void* qInfo) //printf("\tВыборка limit %d\n", qData->limit.rows); } -#line 1895 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1897 "src/CometQL.cc" /* yacc.c:1646 */ break; case 54: @@ -1903,7 +1905,7 @@ yyparse (void* qInfo) //printf("\tВыборка limit_start %d, limit %d\n", qData->limit.start, qData->limit.rows); } -#line 1907 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1909 "src/CometQL.cc" /* yacc.c:1646 */ break; case 55: @@ -1912,7 +1914,7 @@ yyparse (void* qInfo) setQData; qData->arg_select.selectedColumnsCount=0; } -#line 1916 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1918 "src/CometQL.cc" /* yacc.c:1646 */ break; case 59: @@ -1931,7 +1933,7 @@ yyparse (void* qInfo) //printf("\tQUOTED_Name %d[%.3s...]\n", qData->arg_select.selectedColumnsCount, $1.text); } } -#line 1935 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1937 "src/CometQL.cc" /* yacc.c:1646 */ break; case 60: @@ -1941,7 +1943,7 @@ yyparse (void* qInfo) qData->command = TOK_INSERT; //printf("\tВставка\n"); } -#line 1945 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1947 "src/CometQL.cc" /* yacc.c:1646 */ break; case 61: @@ -1951,7 +1953,7 @@ yyparse (void* qInfo) qData->command = TOK_INSERT; //printf("\tВставка\n"); } -#line 1955 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1957 "src/CometQL.cc" /* yacc.c:1646 */ break; case 66: @@ -1970,7 +1972,7 @@ yyparse (void* qInfo) //printf("\tQUOTED_Name %d[%.3s...]\n", qData->arg_insert.namesCount, $1.text); } } -#line 1974 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1976 "src/CometQL.cc" /* yacc.c:1646 */ break; case 67: @@ -1989,7 +1991,7 @@ yyparse (void* qInfo) //printf("\tQUOTED_Value %d[%.3s...%d]\n", qData->arg_insert.valuesCount, $1.text, $1.len); } } -#line 1993 "src/CometQL.cc" /* yacc.c:1646 */ +#line 1995 "src/CometQL.cc" /* yacc.c:1646 */ break; case 68: @@ -1999,7 +2001,7 @@ yyparse (void* qInfo) qData->command = TOK_DELETE; //printf("\tУдаление\n"); } -#line 2003 "src/CometQL.cc" /* yacc.c:1646 */ +#line 2005 "src/CometQL.cc" /* yacc.c:1646 */ break; case 69: @@ -2009,11 +2011,11 @@ yyparse (void* qInfo) setTokValue(qData, qData->tableName, (yyvsp[0].tokStruct)); //printf("\tTable_Name [%.3s...%d]\n", $1.text, $1.len); } -#line 2013 "src/CometQL.cc" /* yacc.c:1646 */ +#line 2015 "src/CometQL.cc" /* yacc.c:1646 */ break; -#line 2017 "src/CometQL.cc" /* yacc.c:1646 */ +#line 2019 "src/CometQL.cc" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires diff --git a/src/CometQL.hh b/src/CometQL.hh index 9a1b0c3..5e300da 100644 --- a/src/CometQL.hh +++ b/src/CometQL.hh @@ -1,8 +1,8 @@ -/* A Bison parser, made by GNU Bison 3.0.2. */ +/* A Bison parser, made by GNU Bison 3.0.4. */ /* Bison interface for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc. 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 @@ -141,7 +141,7 @@ extern int yydebug; /* Value type. */ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED -typedef union YYSTYPE YYSTYPE; + union YYSTYPE { #line 115 "src/CometQL.y" /* yacc.c:1909 */ @@ -154,6 +154,8 @@ union YYSTYPE #line 156 "src/CometQL.hh" /* yacc.c:1909 */ }; + +typedef union YYSTYPE YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_DECLARED 1 #endif diff --git a/src/CometQL.tab.c b/src/CometQL.tab.c index 503cd3d..23dadbd 100644 --- a/src/CometQL.tab.c +++ b/src/CometQL.tab.c @@ -1,8 +1,8 @@ -/* A Bison parser, made by GNU Bison 3.0.2. */ +/* A Bison parser, made by GNU Bison 3.0.4. */ /* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc. 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 @@ -44,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "3.0.2" +#define YYBISON_VERSION "3.0.4" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -259,7 +259,7 @@ extern int yydebug; /* Value type. */ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED -typedef union YYSTYPE YYSTYPE; + union YYSTYPE { #line 115 "src/CometQL.y" /* yacc.c:355 */ @@ -272,6 +272,8 @@ union YYSTYPE #line 274 "CometQL.tab.c" /* yacc.c:355 */ }; + +typedef union YYSTYPE YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_DECLARED 1 #endif @@ -285,7 +287,7 @@ int yyparse (void* qInfo); /* Copy the second part of user declarations. */ -#line 289 "CometQL.tab.c" /* yacc.c:358 */ +#line 291 "CometQL.tab.c" /* yacc.c:358 */ #ifdef short # undef short @@ -1464,7 +1466,7 @@ yyparse (void* qInfo) setTokValue(qData, qData->arg_set.value, (yyvsp[0].tokStruct)); //printf("\tСписок баз данных\n"); } -#line 1468 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1470 "CometQL.tab.c" /* yacc.c:1646 */ break; case 10: @@ -1475,7 +1477,7 @@ yyparse (void* qInfo) setTokValue(qData, qData->arg_set.varible, (yyvsp[-1].tokStruct)); setTokValue(qData, qData->arg_set.value, (yyvsp[0].tokStruct)); } -#line 1479 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1481 "CometQL.tab.c" /* yacc.c:1646 */ break; case 11: @@ -1487,7 +1489,7 @@ yyparse (void* qInfo) setTokValue(qData, qData->arg_set.varible, (yyvsp[-1].tokStruct)); setTokValue(qData, qData->arg_set.value, (yyvsp[0].tokStruct)); } -#line 1491 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1493 "CometQL.tab.c" /* yacc.c:1646 */ break; case 12: @@ -1498,7 +1500,7 @@ yyparse (void* qInfo) qData->arg_show.command = TOK_DATABASES; //printf("\tСписок баз данных\n"); } -#line 1502 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1504 "CometQL.tab.c" /* yacc.c:1646 */ break; case 13: @@ -1509,7 +1511,7 @@ yyparse (void* qInfo) qData->arg_show.command = TOK_PROCESSLIST; //printf("\tСписок потоков\n"); } -#line 1513 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1515 "CometQL.tab.c" /* yacc.c:1646 */ break; case 14: @@ -1520,7 +1522,7 @@ yyparse (void* qInfo) qData->arg_show.command = TOK_TABLES; //printf("\tСписок таблиц\n"); } -#line 1524 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1526 "CometQL.tab.c" /* yacc.c:1646 */ break; case 15: @@ -1532,7 +1534,7 @@ yyparse (void* qInfo) //printf("\tСписок таблиц\n"); } -#line 1536 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1538 "CometQL.tab.c" /* yacc.c:1646 */ break; case 16: @@ -1543,7 +1545,7 @@ yyparse (void* qInfo) qData->arg_show.command = TOK_STATUS; //printf("\tСтатус системы\n"); } -#line 1547 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1549 "CometQL.tab.c" /* yacc.c:1646 */ break; case 17: @@ -1555,7 +1557,7 @@ yyparse (void* qInfo) qData->arg_show.command = TOK_COLUMNS; //printf("\tСписок колонок\n"); } -#line 1559 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1561 "CometQL.tab.c" /* yacc.c:1646 */ break; case 18: @@ -1567,7 +1569,7 @@ yyparse (void* qInfo) qData->arg_show.command = TOK_COLUMNS; //printf("\tСписок колонок\n"); } -#line 1571 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1573 "CometQL.tab.c" /* yacc.c:1646 */ break; case 19: @@ -1580,7 +1582,7 @@ yyparse (void* qInfo) setTokValue(qData, qData->arg_show.like, (yyvsp[0].tokStruct)); //printf("\tПоказать переменные\n"); } -#line 1584 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1586 "CometQL.tab.c" /* yacc.c:1646 */ break; case 23: @@ -1589,7 +1591,7 @@ yyparse (void* qInfo) setQData; qData->arg_show.flag = FLAG_GLOBAL; } -#line 1593 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1595 "CometQL.tab.c" /* yacc.c:1646 */ break; case 24: @@ -1598,7 +1600,7 @@ yyparse (void* qInfo) setQData; qData->arg_show.flag = FLAG_SESSION; } -#line 1602 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1604 "CometQL.tab.c" /* yacc.c:1646 */ break; case 25: @@ -1607,7 +1609,7 @@ yyparse (void* qInfo) setQData; qData->arg_show.flag = FLAG_FILESYSTEM; } -#line 1611 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1613 "CometQL.tab.c" /* yacc.c:1646 */ break; case 26: @@ -1616,7 +1618,7 @@ yyparse (void* qInfo) setQData; qData->arg_show.flag = FLAG_RAM; } -#line 1620 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1622 "CometQL.tab.c" /* yacc.c:1646 */ break; case 27: @@ -1625,7 +1627,7 @@ yyparse (void* qInfo) setQData; qData->arg_show.flag = FLAG_AVG; } -#line 1629 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1631 "CometQL.tab.c" /* yacc.c:1646 */ break; case 28: @@ -1634,7 +1636,7 @@ yyparse (void* qInfo) setQData; qData->arg_show.flag = FLAG_UPTIME; } -#line 1638 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1640 "CometQL.tab.c" /* yacc.c:1646 */ break; case 30: @@ -1643,7 +1645,7 @@ yyparse (void* qInfo) setQData; qData->arg_show.flag = FLAG_FULL; } -#line 1647 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1649 "CometQL.tab.c" /* yacc.c:1646 */ break; case 31: @@ -1656,7 +1658,7 @@ yyparse (void* qInfo) //printf("\tВыборка %s\n", $2.text); } -#line 1660 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1662 "CometQL.tab.c" /* yacc.c:1646 */ break; case 32: @@ -1667,7 +1669,7 @@ yyparse (void* qInfo) qData->arg_select.command = TOK_DATABASE; //printf("\tВыборка DATABASE\n"); } -#line 1671 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1673 "CometQL.tab.c" /* yacc.c:1646 */ break; case 33: @@ -1677,7 +1679,7 @@ yyparse (void* qInfo) qData->command = TOK_SELECT; qData->arg_select.command = TOK_FROM; } -#line 1681 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1683 "CometQL.tab.c" /* yacc.c:1646 */ break; case 36: @@ -1692,7 +1694,7 @@ yyparse (void* qInfo) qData->where.whereExprValueCount = 0; qData->where.whereExprCount++; } -#line 1696 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1698 "CometQL.tab.c" /* yacc.c:1646 */ break; case 37: @@ -1711,7 +1713,7 @@ yyparse (void* qInfo) qData->where.whereExprCount++; qData->where.whereExprValueCount = 0; } -#line 1715 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1717 "CometQL.tab.c" /* yacc.c:1646 */ break; case 38: @@ -1730,7 +1732,7 @@ yyparse (void* qInfo) qData->where.whereExprCount++; qData->where.whereExprValueCount = 0; } -#line 1734 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1736 "CometQL.tab.c" /* yacc.c:1646 */ break; case 39: @@ -1739,7 +1741,7 @@ yyparse (void* qInfo) setQData; qData->where.whereExprCondition[qData->where.whereExprCount] = TOK_LIKE; } -#line 1743 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1745 "CometQL.tab.c" /* yacc.c:1646 */ break; case 40: @@ -1748,7 +1750,7 @@ yyparse (void* qInfo) setQData; qData->where.whereExprCondition[qData->where.whereExprCount] = MORE; } -#line 1752 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1754 "CometQL.tab.c" /* yacc.c:1646 */ break; case 41: @@ -1757,7 +1759,7 @@ yyparse (void* qInfo) setQData; qData->where.whereExprCondition[qData->where.whereExprCount] = LESS; } -#line 1761 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1763 "CometQL.tab.c" /* yacc.c:1646 */ break; case 42: @@ -1766,7 +1768,7 @@ yyparse (void* qInfo) setQData; qData->where.whereExprCondition[qData->where.whereExprCount] = EQUALLY; } -#line 1770 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1772 "CometQL.tab.c" /* yacc.c:1646 */ break; case 43: @@ -1775,7 +1777,7 @@ yyparse (void* qInfo) setQData; qData->where.whereExprCondition[qData->where.whereExprCount] = TOK_IN; } -#line 1779 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1781 "CometQL.tab.c" /* yacc.c:1646 */ break; case 46: @@ -1785,7 +1787,7 @@ yyparse (void* qInfo) setTokValue(qData, qData->where.whereExprColum[qData->where.whereExprCount], (yyvsp[0].tokStruct)); //printf("\texpr_Name %d[%.3s...]\n", qData->where.whereExprCount, $1.text); } -#line 1789 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1791 "CometQL.tab.c" /* yacc.c:1646 */ break; case 47: @@ -1804,7 +1806,7 @@ yyparse (void* qInfo) //printf("\texpr_Value %d[%.3s...]\n", qData->where.whereExprValueCount, $1.text); } } -#line 1808 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1810 "CometQL.tab.c" /* yacc.c:1646 */ break; case 49: @@ -1814,7 +1816,7 @@ yyparse (void* qInfo) setTokValue(qData, qData->orderBy.name, (yyvsp[-1].tokStruct)); qData->orderBy.type = TOK_ASC; } -#line 1818 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1820 "CometQL.tab.c" /* yacc.c:1646 */ break; case 50: @@ -1824,7 +1826,7 @@ yyparse (void* qInfo) setTokValue(qData, qData->orderBy.name, (yyvsp[-1].tokStruct)); qData->orderBy.type = TOK_ASC; } -#line 1828 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1830 "CometQL.tab.c" /* yacc.c:1646 */ break; case 51: @@ -1834,7 +1836,7 @@ yyparse (void* qInfo) setTokValue(qData, qData->orderBy.name, (yyvsp[-1].tokStruct)); qData->orderBy.type = TOK_DESC; } -#line 1838 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1840 "CometQL.tab.c" /* yacc.c:1646 */ break; case 53: @@ -1845,7 +1847,7 @@ yyparse (void* qInfo) //printf("\tВыборка limit %d\n", qData->limit.rows); } -#line 1849 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1851 "CometQL.tab.c" /* yacc.c:1646 */ break; case 54: @@ -1857,7 +1859,7 @@ yyparse (void* qInfo) //printf("\tВыборка limit_start %d, limit %d\n", qData->limit.start, qData->limit.rows); } -#line 1861 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1863 "CometQL.tab.c" /* yacc.c:1646 */ break; case 55: @@ -1866,7 +1868,7 @@ yyparse (void* qInfo) setQData; qData->arg_select.selectedColumnsCount=0; } -#line 1870 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1872 "CometQL.tab.c" /* yacc.c:1646 */ break; case 59: @@ -1885,7 +1887,7 @@ yyparse (void* qInfo) //printf("\tQUOTED_Name %d[%.3s...]\n", qData->arg_select.selectedColumnsCount, $1.text); } } -#line 1889 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1891 "CometQL.tab.c" /* yacc.c:1646 */ break; case 60: @@ -1895,7 +1897,7 @@ yyparse (void* qInfo) qData->command = TOK_INSERT; //printf("\tВставка\n"); } -#line 1899 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1901 "CometQL.tab.c" /* yacc.c:1646 */ break; case 61: @@ -1905,7 +1907,7 @@ yyparse (void* qInfo) qData->command = TOK_INSERT; //printf("\tВставка\n"); } -#line 1909 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1911 "CometQL.tab.c" /* yacc.c:1646 */ break; case 66: @@ -1924,7 +1926,7 @@ yyparse (void* qInfo) //printf("\tQUOTED_Name %d[%.3s...]\n", qData->arg_insert.namesCount, $1.text); } } -#line 1928 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1930 "CometQL.tab.c" /* yacc.c:1646 */ break; case 67: @@ -1943,7 +1945,7 @@ yyparse (void* qInfo) //printf("\tQUOTED_Value %d[%.3s...%d]\n", qData->arg_insert.valuesCount, $1.text, $1.len); } } -#line 1947 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1949 "CometQL.tab.c" /* yacc.c:1646 */ break; case 68: @@ -1953,7 +1955,7 @@ yyparse (void* qInfo) qData->command = TOK_DELETE; //printf("\tУдаление\n"); } -#line 1957 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1959 "CometQL.tab.c" /* yacc.c:1646 */ break; case 69: @@ -1963,11 +1965,11 @@ yyparse (void* qInfo) setTokValue(qData, qData->tableName, (yyvsp[0].tokStruct)); //printf("\tTable_Name [%.3s...%d]\n", $1.text, $1.len); } -#line 1967 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1969 "CometQL.tab.c" /* yacc.c:1646 */ break; -#line 1971 "CometQL.tab.c" /* yacc.c:1646 */ +#line 1973 "CometQL.tab.c" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires diff --git a/src/CometQL.tab.h b/src/CometQL.tab.h index 4dc4439..4814bda 100644 --- a/src/CometQL.tab.h +++ b/src/CometQL.tab.h @@ -1,8 +1,8 @@ -/* A Bison parser, made by GNU Bison 3.0.2. */ +/* A Bison parser, made by GNU Bison 3.0.4. */ /* Bison interface for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc. 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 @@ -95,7 +95,7 @@ extern int yydebug; /* Value type. */ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED -typedef union YYSTYPE YYSTYPE; + union YYSTYPE { #line 115 "src/CometQL.y" /* yacc.c:1909 */ @@ -108,6 +108,8 @@ union YYSTYPE #line 110 "CometQL.tab.h" /* yacc.c:1909 */ }; + +typedef union YYSTYPE YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_DECLARED 1 #endif diff --git a/src/CometQLProxy_connection.h b/src/CometQLProxy_connection.h index 9b3adba..30f9372 100644 --- a/src/CometQLProxy_connection.h +++ b/src/CometQLProxy_connection.h @@ -43,6 +43,55 @@ using namespace std; #define PROXY_TO_RANDOM -2 +/** + * Класс одного соединения с сервером + * Содержит функции обработки запросов от бекенда + * + * Для кластеризации мы не ожидаем ответ от оповещаемых нод при вставке данных + * А просто говорим ок ещё до того как все ноды кластера были оповещены о запросе. + * + * Так как конкретная нода на вставке тоже может вернуть ответ до реального выполнения запроса + * то запросы будут отдаватся быстро а код потом ещё будет работать + * + * Для повышения скорости инсертов можно иметь более одного соединения между каждой из нод кластера + * Тогда два подряд запроса будут выполнятся параллельно + * + * Два варианта кластерезации: + * - Высокая доступность + * - Высокая производительность + * + * Высокая доступность: (Реализован) + * реализуется путём работы двух и более серверов с общей базой данных + * или кластером баз данных в режиме мастер-мастер. + * А отправка запросов осуществляется на любой из серверов, можно через haproxy + * Js подключается к обоим серверам и принимает сообщения от них двоих. + * + * Плюсы: если вырубить N - 1 серверов из кластера размером N серверов работа системы сохранится + * Минусы: избыточная нагрузка, система выдержит не более чем самый слабый из серверов + * + * + * + * Высокая производительность: + * Реализуется кластерезацией на уровне комет сервера + * Все запросы отправляются на все сервера кластера в не зависимости от того на какой из серверов запрос поступил. + * + * Бд у всех серверов должна быть общей или быть кластером в режиме мастер-мастер + * Или быть у каждого своей но с каким то дополнительным скриптом для синхронизации после падений + * + * Js подключается к одному из серверов группы. + * Режим 1: Пользователи распределяются случайно между доступными серверами в группе (Сейчас работвет так) + * Режим 2: Анонимные пользователи распределяются случайно. Авторизованные равномерно по серверам. + * + * + * Режим 1: (Сейчас работвет так) + * Плюсы: Нагрузка распределяется равномерно по кластеру, Падение одного сервера отключит часть пользователей максимум на несколько секунд + * Минусы: Масштабирование НЕ линейное так как cometQL запросы отправляются на все сервера группы + * + * Режим 2: + * Плюсы: Нагрузка распределяется равномерно по кластеру, масштабирование линейное так как cometQL запросы не отправляются на те сервера группы на которых точно нет адресата + * Минусы: Падение одного сервера отключит часть пользователей (решаемо на уровне js api) + * + */ class CometQLProxy_connection:public MySql_connection { friend class tcpServer; diff --git a/src/JwtConfig.cmake b/src/JwtConfig.cmake new file mode 100644 index 0000000..4726d3b --- /dev/null +++ b/src/JwtConfig.cmake @@ -0,0 +1,2 @@ + +include("${CMAKE_CURRENT_LIST_DIR}/JwtTargets.cmake") diff --git a/src/JwtConfigVersion.cmake b/src/JwtConfigVersion.cmake new file mode 100644 index 0000000..90730e8 --- /dev/null +++ b/src/JwtConfigVersion.cmake @@ -0,0 +1,46 @@ +# This is a basic version file for the Config-mode of find_package(). +# It is used by write_basic_package_version_file() as input file for configure_file() +# to create a version-file which can be installed along a config.cmake file. +# +# The created file sets PACKAGE_VERSION_EXACT if the current version string and +# the requested version string are exactly the same and it sets +# PACKAGE_VERSION_COMPATIBLE if the current version is >= requested version, +# but only if the requested major version is the same as the current one. +# The variable CVF_VERSION must be set before calling configure_file(). + + +set(PACKAGE_VERSION "1.1.0") + +if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else() + + if("1.1.0" MATCHES "^([0-9]+)\\.") + set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}") + else() + set(CVF_VERSION_MAJOR "1.1.0") + endif() + + if(PACKAGE_FIND_VERSION_MAJOR STREQUAL CVF_VERSION_MAJOR) + set(PACKAGE_VERSION_COMPATIBLE TRUE) + else() + set(PACKAGE_VERSION_COMPATIBLE FALSE) + endif() + + if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) + endif() +endif() + + +# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it: +if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "8" STREQUAL "") + return() +endif() + +# check that the installed version has the same 32/64bit-ness as the one which is currently searching: +if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "8") + math(EXPR installedBits "8 * 8") + set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)") + set(PACKAGE_VERSION_UNSUITABLE TRUE) +endif() diff --git a/src/MySqlProtocol.cpp b/src/MySqlProtocol.cpp index 2f004c7..48e4d26 100644 --- a/src/MySqlProtocol.cpp +++ b/src/MySqlProtocol.cpp @@ -174,7 +174,7 @@ int LengthEncodedInteger::setToBuff(long long value, char* buff) if(abs(value) < pow(2,64)) { - printf("warning LengthEncodedInteger is %lld (9)\n", value); + TagLoger::trace(Log_MySqlServer, 0,"warning LengthEncodedInteger is %lld (9)\n", value); *buff = 0xfe; memcpy(buff+1, &value, 8); // @todo уточнить можноли так чтоб 9 байт return 9; diff --git a/src/MySql_connection.cpp b/src/MySql_connection.cpp index f635466..1ef97e1 100644 --- a/src/MySql_connection.cpp +++ b/src/MySql_connection.cpp @@ -25,7 +25,6 @@ #include "Client_connection.h" #include "MySql_connection.h" #include "CometQLProxy_connection.h" -#include "Freeswitch_connection.h" #include "CometQL.h" @@ -37,7 +36,9 @@ #include #include -#include "sha1.h" +#include "sha1.h" +#include "Freeswitch_connection.h" +#include "CometQLProxy_connection.h" #include "tinyxml2/tinyxml2.h" @@ -129,6 +130,7 @@ MySql_connection::~MySql_connection() */ int MySql_connection::request(int client, int len, thread_data* local_buf) { + auto t = TagTimer::mtime(); /** * @fixme Тут нет проверок на то что покет мог прийти не полностью * @@ -172,11 +174,11 @@ int MySql_connection::request(int client, int len, thread_data* local_buf) unsigned int PacketLen = 0; char* p = local_buf->buf.getData(); - char* t = (char*)&PacketLen; - t[0] = p[0]; - t[1] = p[1]; - t[2] = p[2]; - t[3] = 0; + char* pl = (char*)&PacketLen; + pl[0] = p[0]; + pl[1] = p[1]; + pl[2] = p[2]; + pl[3] = 0; p+=3; TagLoger::log(Log_MySqlServer, 0, "PacketLen:%d\n", PacketLen); // @FixMe добавить проверку длины пакета и длины данных в обе стороны. @@ -245,12 +247,18 @@ int MySql_connection::request(int client, int len, thread_data* local_buf) p+=23; } - isAuthUser = false; - + isAuthUser = false; + char* name = p; p+= strlen(name)+1; TagLoger::log(Log_MySqlServer, 0, "UserName:%s\n", name); - + + long test_id = 0; + if(strcmp(name, "root") != 0 && strcmp(name, "0") != 0) + { + test_id = read_long(name, (char)0); + } + if(ClientFlags & MYSQL_CLIENT_SECURE_CONNECTION) { char authDataLen = *p; @@ -261,7 +269,7 @@ int MySql_connection::request(int client, int len, thread_data* local_buf) if(authDataLen == 0) { TagLoger::log(Log_MySqlServer, 0, "Authorization without password authDataLen=%d\n", authDataLen); - + // Здесь проверка для того можно ли пускать без пароля по имени пользователя if(memcmp(name, "haproxy_check", strlen("haproxy_check")) != 0) { @@ -269,7 +277,7 @@ int MySql_connection::request(int client, int len, thread_data* local_buf) Send_Err_Package(SQL_ERR_AUTHENTICATION,"Authentication failure, authDataLen!=20", PacketNomber+1, local_buf, this); return -1; } - + // Таки решили пустить без пароля Send_OK_Package(PacketNomber+1, local_buf, this); clientState = STATE_RECEIVED_HANDSHAKE; @@ -291,14 +299,15 @@ int MySql_connection::request(int client, int len, thread_data* local_buf) if(devInfo::testDevKey(random20bytes, DevKeyHashStart)) { - isAuthUser = true; + isAuthUser = true; + dev_id = test_id; TagLoger::debug(Log_MySqlServer, 0, "Authorization successful ok\n"); devManager::instance()->getDevInfo(dev_id)->incrBackendOnline(); devManager::instance()->getDevInfo(dev_id)->incrMessages(); } else { - isAuthUser = false; + isAuthUser = false; TagLoger::error(Log_MySqlServer, 0, "Authorization failed"); Send_Err_Package(SQL_ERR_AUTHENTICATION,"Authentication failure", PacketNomber+1, local_buf, this); return -1; @@ -306,7 +315,7 @@ int MySql_connection::request(int client, int len, thread_data* local_buf) } else { - isAuthUser = false; + isAuthUser = false; // string[NULL] auth-response p++; @@ -351,7 +360,7 @@ int MySql_connection::request(int client, int len, thread_data* local_buf) _countUerys++; TagLoger::warn(Log_MySqlServer, 0, "QUERY[%d, dev_id=%d, len=%d][BASE]:%s\n", _countUerys, dev_id, queryLen, startQuery); - if(isAuthUser) + if(isAuthUser) { // От имени root пользователя допустима работы репликации // Сдвиг в тексте запроса, если к запросу прикреплены мета данные от систем репликации @@ -391,8 +400,7 @@ int MySql_connection::request(int client, int len, thread_data* local_buf) memcmp("set ", startQuery, strlen("set ")) != 0 && memcmp("show ", startQuery, strlen("show ")) != 0 && memcmp("SET ", startQuery, strlen("SET ")) != 0 && - memcmp("SHOW ", startQuery, strlen("SHOW ")) != 0 && - memcmp("select @@version_comment limit 1", startQuery, strlen("select @@version_comment limit 1")) != 0 + memcmp("SHOW ", startQuery, strlen("SHOW ")) != 0 ) { // Пишем в лог запросов @@ -573,14 +581,18 @@ int MySql_connection::query_router(thread_data* local_buf, int PacketNomber) else if(local_buf->qInfo.tokCompare("pipes_settings", local_buf->qInfo.tableName)) { return sql_select_from_pipes_settings(local_buf,PacketNomber); - } + } else if(local_buf->qInfo.tokCompare("conference", local_buf->qInfo.tableName)) { return sql_select_from_conference(local_buf,PacketNomber); } else if(local_buf->qInfo.tokCompare("conference_members", local_buf->qInfo.tableName)) { - return sql_select_from_conference_members(local_buf,PacketNomber); + return sql_select_from_conference_members(local_buf,PacketNomber); + } + else if(local_buf->qInfo.tokCompare("profiler", local_buf->qInfo.tableName)) + { + return sql_select_from_profiler(local_buf,PacketNomber); } else { @@ -632,7 +644,7 @@ int MySql_connection::query_router(thread_data* local_buf, int PacketNomber) else if(local_buf->qInfo.tokCompare("pipes_settings", local_buf->qInfo.tableName)) { return sql_insert_into_pipes_settings(local_buf,PacketNomber); - } + } else if(local_buf->qInfo.tokCompare("conference", local_buf->qInfo.tableName)) { return sql_insert_into_conference(local_buf,PacketNomber); @@ -690,7 +702,7 @@ int MySql_connection::query_router(thread_data* local_buf, int PacketNomber) else if(local_buf->qInfo.tokCompare("pipes_settings", local_buf->qInfo.tableName)) { return sql_delete_from_pipes_settings(local_buf,PacketNomber); - } + } else if(local_buf->qInfo.tokCompare("conference", local_buf->qInfo.tableName)) { return sql_delete_from_conference(local_buf,PacketNomber); @@ -723,19 +735,23 @@ int MySql_connection::query_router(thread_data* local_buf, int PacketNomber) */ bool MySql_connection::test_api_version(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); TagLoger::log(Log_MySqlServer, 0, "api_version %d", api_version); if(api_version != -1) { + TagTimer::add("MySql_connection::test_api_version", t); return true; } // Указать нормальный код и текст ошибки. Send_Err_Package(SQL_ERR_NOT_EXIST, "Select database failure", PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::test_api_version", t); return false; } bool MySql_connection::sql_use_db(char* db_name) { + auto t = TagTimer::mtime(); if(strcmp(db_name, "CometQL_v1") == 0) { TagLoger::log(Log_MySqlServer, 0, "OK set api_version `%d`", 1); @@ -756,7 +772,7 @@ bool MySql_connection::sql_use_db(char* db_name) return false; } } - + TagLoger::log(Log_MySqlServer, 0, "Error: set api_version `%s`", db_name); int conf_api_version = appConf::instance()->get_int("main", "api_version"); @@ -775,6 +791,7 @@ bool MySql_connection::sql_use_db(char* db_name) int MySql_connection::sql_set_value(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); Send_OK_Package(0, 0, PacketNomber+1, local_buf, this); return 0; } @@ -789,6 +806,7 @@ int MySql_connection::sql_set_value(thread_data* local_buf, unsigned int PacketN */ int MySql_connection::sql_show_databases(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); // Отправляем пакет описания 1 колонки local_buf->answer_buf.lock(); char* answer = local_buf->answer_buf.getData(); @@ -810,6 +828,7 @@ int MySql_connection::sql_show_databases(thread_data* local_buf, unsigned int Pa int MySql_connection::sql_show_tables(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); // Отправляем пакет описания 1 колонки local_buf->answer_buf.lock(); char* answer = local_buf->answer_buf.getData(); @@ -857,6 +876,7 @@ int MySql_connection::sql_show_tables(thread_data* local_buf, unsigned int Packe */ int MySql_connection::sql_show_columns(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); // Field Type Null Key Default Extra local_buf->answer_buf.lock(); @@ -905,6 +925,7 @@ int MySql_connection::sql_show_columns(thread_data* local_buf, unsigned int Pack int MySql_connection::sql_show_table_status(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); // Отправляем пакет описания 1 колонки local_buf->answer_buf.lock(); char* answer = local_buf->answer_buf.getData(); @@ -969,7 +990,8 @@ int MySql_connection::sql_show_table_status(thread_data* local_buf, unsigned int int MySql_connection::sql_show_processlist(thread_data* local_buf, unsigned int PacketNomber) { - if(!isAuthUser) + auto t = TagTimer::mtime(); + if(!isAuthUser) { // Нет доступа не Root пользователям local_buf->qInfo.setError("Access denied", SQL_ERR_ACCESS_DENIED); @@ -1034,6 +1056,7 @@ int MySql_connection::sql_show_processlist(thread_data* local_buf, unsigned int int MySql_connection::sql_show_variables(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); // SHOW SESSION VARIABLES LIKE 'lower_case_table_names' // @todo simpleTask не доделан like и флаги SESSION и GLOBAL // @todo simpleTask показывать параметры ini файла @@ -1073,12 +1096,14 @@ int MySql_connection::sql_show_variables(thread_data* local_buf, unsigned int Pa } int MySql_connection::sql_show_status(thread_data* local_buf, unsigned int PacketNomber) -{ - if( !isAuthUser && ( - local_buf->qInfo.arg_show.flag == FLAG_GLOBAL || - local_buf->qInfo.arg_show.flag == FLAG_FILESYSTEM || - local_buf->qInfo.arg_show.flag == FLAG_RAM || - local_buf->qInfo.arg_show.flag == FLAG_AVG )) +{ + auto t = TagTimer::mtime(); + if(!isAuthUser) + if( + local_buf->qInfo.arg_show.flag == FLAG_GLOBAL || + local_buf->qInfo.arg_show.flag == FLAG_FILESYSTEM || + local_buf->qInfo.arg_show.flag == FLAG_RAM || + local_buf->qInfo.arg_show.flag == FLAG_AVG ) { // Нет доступа не Root пользователям к флагу GLOBAL local_buf->qInfo.setError("Access denied", SQL_ERR_ACCESS_DENIED); @@ -1344,7 +1369,8 @@ int MySql_connection::sql_show_status(thread_data* local_buf, unsigned int Packe snprintf(value[1].clear(), 255, "%.2f", (float)tcpServer ::instance()->bm.getPsDeleteClient()); delta = RowPackage(2, value, ++PacketNomber, answer); answer += delta; - + + value[0] = "network_events"; // Сетевые события только от авторизованных пользователей value[1] = devManager::instance()->getPsNetworkEvents(); delta = RowPackage(2, value, ++PacketNomber, answer); @@ -1414,6 +1440,7 @@ int MySql_connection::sql_show_status(thread_data* local_buf, unsigned int Packe int MySql_connection::sql_select_systemvarible(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); // Отправляем пакет описания 1 колонки local_buf->answer_buf.lock(); char* answer = local_buf->answer_buf.getData(); @@ -1436,6 +1463,7 @@ int MySql_connection::sql_select_systemvarible(thread_data* local_buf, unsigned int MySql_connection::sql_select_database_name(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); // Отправляем пакет описания 1 колонки local_buf->answer_buf.lock(); char* answer = local_buf->answer_buf.getData(); @@ -1469,6 +1497,7 @@ int MySql_connection::sql_select_database_name(thread_data* local_buf, unsigned // users_auth int MySql_connection::sql_select_from_users_auth(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); const static char* columDef[MAX_COLUMNS_COUNT] = { "id", "hash" @@ -1524,6 +1553,7 @@ int MySql_connection::sql_select_from_users_auth(thread_data* local_buf, unsigne int MySql_connection::sql_insert_into_users_auth(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); TagLoger::log(Log_MySqlServer, 0, " >MySql_connection::add_user_hash\n"); const static char* columDef[MAX_COLUMNS_COUNT] = { @@ -1588,6 +1618,7 @@ int MySql_connection::sql_insert_into_users_auth(thread_data* local_buf, unsigne int MySql_connection::sql_delete_from_users_auth(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); const static char* columDef[MAX_COLUMNS_COUNT] = { "id", "hash" @@ -1679,6 +1710,7 @@ int MySql_connection::sql_delete_from_users_auth(thread_data* local_buf, unsigne */ int MySql_connection::sql_select_from_users_data(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); const static char* columDef[MAX_COLUMNS_COUNT] = { "id", "data", // Можно записать только из cometQL @@ -1731,6 +1763,7 @@ int MySql_connection::sql_select_from_users_data(thread_data* local_buf, unsigne int MySql_connection::sql_insert_into_users_data(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); const static char* columDef[MAX_COLUMNS_COUNT] = { "id", "data" @@ -1783,6 +1816,7 @@ int MySql_connection::sql_insert_into_users_data(thread_data* local_buf, unsigne int MySql_connection::sql_delete_from_users_data(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); const static char* columDef[MAX_COLUMNS_COUNT] = { "id", "data" @@ -1837,6 +1871,7 @@ int MySql_connection::sql_delete_from_users_data(thread_data* local_buf, unsigne */ int MySql_connection::sql_select_from_revoked_tokens(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); const static char* columDef[MAX_COLUMNS_COUNT] = { "token", }; @@ -1885,6 +1920,7 @@ int MySql_connection::sql_select_from_revoked_tokens(thread_data* local_buf, uns int MySql_connection::sql_insert_into_revoked_tokens(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); const static char* columDef[MAX_COLUMNS_COUNT] = { "token" }; @@ -1927,6 +1963,7 @@ int MySql_connection::sql_insert_into_revoked_tokens(thread_data* local_buf, uns int MySql_connection::sql_delete_from_revoked_tokens(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); const static char* columDef[MAX_COLUMNS_COUNT] = { "token" }; @@ -1978,6 +2015,7 @@ int MySql_connection::sql_delete_from_revoked_tokens(thread_data* local_buf, uns // users_time int MySql_connection::sql_select_from_users_time(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); const static char* columDef[MAX_COLUMNS_COUNT] = { "id", "time" @@ -2026,12 +2064,14 @@ int MySql_connection::sql_select_from_users_time(thread_data* local_buf, unsigne int MySql_connection::sql_insert_into_users_time(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); Send_Err_Package(SQL_ERR_READ_ONLY, "Table `users_time` is read only", PacketNomber+1, local_buf, this); return 0; } int MySql_connection::sql_delete_from_users_time(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); Send_Err_Package(SQL_ERR_READ_ONLY, "Table `users_time` is read only", PacketNomber+1, local_buf, this); return 0; } @@ -2042,6 +2082,7 @@ int MySql_connection::sql_delete_from_users_time(thread_data* local_buf, unsigne // users_messages int MySql_connection::sql_select_from_users_messages(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); const static char* columDef[MAX_COLUMNS_COUNT] = { "id", "index", @@ -2098,6 +2139,7 @@ int MySql_connection::sql_select_from_users_messages(thread_data* local_buf, uns int MySql_connection::sql_insert_into_users_messages(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); TagLoger::log(Log_MySqlServer, 0, " >MySQL_connection::insert_from_users_messages\n"); const static char* columDef[MAX_COLUMNS_COUNT] = { @@ -2186,6 +2228,7 @@ int MySql_connection::sql_insert_into_users_messages(thread_data* local_buf, uns int MySql_connection::sql_delete_from_users_messages(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); const static char* columDef[MAX_COLUMNS_COUNT] = { "id", "index", @@ -2237,6 +2280,7 @@ int MySql_connection::sql_delete_from_users_messages(thread_data* local_buf, uns // pipes_messages int MySql_connection::sql_select_from_pipes_messages(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); const static char* columDef[MAX_COLUMNS_COUNT] = { "id", "time", @@ -2299,6 +2343,7 @@ int MySql_connection::sql_select_from_pipes_messages(thread_data* local_buf, uns int MySql_connection::sql_insert_into_pipes_messages(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); TagLoger::log(Log_MySqlServer, 0, " >MySql_connection::insert_into_pipes_messages\n"); const static char* columDef[MAX_COLUMNS_COUNT] = { @@ -2398,6 +2443,7 @@ int MySql_connection::sql_insert_into_pipes_messages(thread_data* local_buf, uns int MySql_connection::sql_delete_from_pipes_messages(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); const static char* columDef[MAX_COLUMNS_COUNT] = { "id", "time", @@ -2480,6 +2526,7 @@ int MySql_connection::sql_delete_from_pipes_messages(thread_data* local_buf, uns // users_in_pipes int MySql_connection::sql_select_from_users_in_pipes(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); const static char* columDef[MAX_COLUMNS_COUNT] = { "name", "user_id", @@ -2570,12 +2617,14 @@ int MySql_connection::sql_select_from_users_in_pipes(thread_data* local_buf, uns int MySql_connection::sql_insert_into_users_in_pipes(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); Send_Err_Package(SQL_ERR_READ_ONLY, "Table `users_in_pipes` is read only", PacketNomber+1, local_buf, this); return 0; } int MySql_connection::sql_delete_from_users_in_pipes(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); Send_Err_Package(SQL_ERR_READ_ONLY, "Table `users_in_pipes` is read only", PacketNomber+1, local_buf, this); return 0; } @@ -2584,6 +2633,7 @@ int MySql_connection::sql_delete_from_users_in_pipes(thread_data* local_buf, uns // pipes int MySql_connection::sql_select_from_pipes(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); const static char* columDef[MAX_COLUMNS_COUNT] = { "name", "users" @@ -2641,12 +2691,14 @@ int MySql_connection::sql_select_from_pipes(thread_data* local_buf, unsigned int int MySql_connection::sql_insert_into_pipes(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); Send_Err_Package(SQL_ERR_READ_ONLY, "Table `pipes` is read only", PacketNomber+1, local_buf, this); return 0; } int MySql_connection::sql_delete_from_pipes(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); Send_Err_Package(SQL_ERR_READ_ONLY, "Table `pipes` is read only", PacketNomber+1, local_buf, this); return 0; } @@ -2656,6 +2708,7 @@ int MySql_connection::sql_delete_from_pipes(thread_data* local_buf, unsigned int // pipes_settings int MySql_connection::sql_select_from_pipes_settings(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); const static char* columDef[MAX_COLUMNS_COUNT] = { "name", "length" @@ -2715,6 +2768,7 @@ int MySql_connection::sql_select_from_pipes_settings(thread_data* local_buf, uns int MySql_connection::sql_insert_into_pipes_settings(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); TagLoger::log(Log_MySqlServer, 0, " >MySql_connection::insert_into_pipes_messages\n"); const static char* columDef[MAX_COLUMNS_COUNT] = { @@ -2725,12 +2779,14 @@ int MySql_connection::sql_insert_into_pipes_settings(thread_data* local_buf, uns if(!local_buf->sql.prepare_columns_for_insert(columDef, local_buf->qInfo)) { Send_Err_Package(local_buf->qInfo.errorCode, local_buf->qInfo.errorText, PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_insert_into_pipes_settings", t); return 0; } if(local_buf->sql.columPositions[0] < 0) { Send_Err_Package(SQL_ERR_INVALID_DATA, "field `name` is required", PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_insert_into_pipes_settings", t); return 0; } @@ -2739,18 +2795,21 @@ int MySql_connection::sql_insert_into_pipes_settings(thread_data* local_buf, uns if(local_buf->qInfo.arg_insert.values[local_buf->sql.columPositions[0]].tokLen > PIPE_NAME_LEN) { Send_Err_Package(SQL_ERR_OVERFLOW, "Channel name is too long", PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_insert_into_pipes_settings", t); return 0; } if(local_buf->qInfo.arg_insert.values[local_buf->sql.columPositions[0]].tokLen < 3) { Send_Err_Package(SQL_ERR_EMPTY, "Channel name is too short", PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_insert_into_pipes_settings", t); return 0; } if(!AZ09test(pipe_name, local_buf->qInfo.arg_insert.values[local_buf->sql.columPositions[0]].tokLen)) { Send_Err_Package(SQL_ERR_INVALID_DATA, "The channel name can contain only the characters A-Za-z0-9_-", PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_insert_into_pipes_settings", t); return 0; } @@ -2764,16 +2823,18 @@ int MySql_connection::sql_insert_into_pipes_settings(thread_data* local_buf, uns if( pipe_settings.save(local_buf) < 0) { Send_Err_Package(SQL_ERR_INTERNAL_SERVER, "internal server error: sql_insert_into_pipes_settings", PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_insert_into_pipes_settings", t); return 0; } - Send_OK_Package(1, 0, PacketNomber+1, local_buf, this); + Send_OK_Package(1, 0, PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_insert_into_pipes_settings", t); return 0; } int MySql_connection::sql_delete_from_pipes_settings(thread_data* local_buf, unsigned int PacketNomber) { - + auto t = TagTimer::mtime(); const static char* columDef[MAX_COLUMNS_COUNT] = { "name", "length" @@ -2782,6 +2843,7 @@ int MySql_connection::sql_delete_from_pipes_settings(thread_data* local_buf, uns if(!local_buf->sql.prepare_where_expressions(columDef, local_buf->qInfo)) { Send_Err_Package(local_buf->qInfo.errorCode, local_buf->qInfo.errorText, PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_delete_from_pipes_settings", t); return 0; } @@ -2790,6 +2852,7 @@ int MySql_connection::sql_delete_from_pipes_settings(thread_data* local_buf, uns if(idExprPos == -1) { Send_Err_Package(SQL_ERR_WHERE_EXPRESSIONS, "Selection without transferring the requested values of the primary key is not supported", PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_delete_from_pipes_settings", t); return 0; } @@ -2820,11 +2883,13 @@ int MySql_connection::sql_delete_from_pipes_settings(thread_data* local_buf, uns * Для операций удаления affectedRows возвращатся не будет в целях оптимизации. */ Send_OK_Package(0, 0, PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_delete_from_pipes_settings", t); return 0; } int MySql_connection::sql_insert_into_conference(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); TagLoger::log(Log_MySqlServer, 0, " >MySql_connection::conference\n"); // @todo заменить на более читаемый код на базе перечислений или чего то подобного @@ -2834,7 +2899,8 @@ int MySql_connection::sql_insert_into_conference(thread_data* local_buf, unsigne "caller_id", // инициатор звонка "message", // сообщение "profile", // Режим video_*, audio_* [!Проверить что будет если у конференции одно имя но разные режимы] - "stream" // Не пусто и не 0 если активирован режим стриминга [это поле относится к пользователю а не конференции так как зависит от mode ] + "stream", // Не пусто и не 0 если активирован режим стриминга [это поле относится к пользователю а не конференции так как зависит от mode ] + "node", // нода для звонка }; // Поле tabUUID передается или отслеживается через текст сообщения `message` @@ -2842,18 +2908,21 @@ int MySql_connection::sql_insert_into_conference(thread_data* local_buf, unsigne if(!local_buf->sql.prepare_columns_for_insert(columDef, local_buf->qInfo)) { Send_Err_Package(local_buf->qInfo.errorCode, local_buf->qInfo.errorText, PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_insert_into_conference", t); return 0; } if(local_buf->sql.columPositions[0] < 0) { Send_Err_Package(SQL_ERR_INVALID_DATA, "field `name` is required", PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_insert_into_conference", t); return 0; } if(local_buf->sql.columPositions[1] < 0) { Send_Err_Package(SQL_ERR_INVALID_DATA, "field `user_id` is required", PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_insert_into_conference", t); return 0; } @@ -2866,6 +2935,7 @@ int MySql_connection::sql_insert_into_conference(thread_data* local_buf, unsigne if(local_buf->sql.columPositions[3] < 0) { Send_Err_Package(SQL_ERR_INVALID_DATA, "field `message` is required", PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_insert_into_conference", t); return 0; } @@ -2873,6 +2943,7 @@ int MySql_connection::sql_insert_into_conference(thread_data* local_buf, unsigne if(user_id < 0) { Send_Err_Package(SQL_ERR_INVALID_DATA, "The user_id field must be non-negative", PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_insert_into_conference", t); return 0; } @@ -2895,6 +2966,7 @@ int MySql_connection::sql_insert_into_conference(thread_data* local_buf, unsigne if(sipcluster.empty()) { Send_Err_Package(SQL_ERR_INTERNAL_SERVER, "field in ini file not set option `host` in section `sip`", PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_insert_into_conference", t); return 0; } @@ -2910,6 +2982,10 @@ int MySql_connection::sql_insert_into_conference(thread_data* local_buf, unsigne TagLoger::log(Log_MySqlServer, 0, " >sipNumber=%s", sipNumber.data()); + + /** + * @todo Если задан параметр с именем node то сервер берём не случайный а тот что передали нам в запросе + */ int serverPort = 7443; std::string serverName; @@ -2922,6 +2998,7 @@ int MySql_connection::sql_insert_into_conference(thread_data* local_buf, unsigne serverName = sipcluster[serverIndex]->getWSHost(); serverPort = sipcluster[serverIndex]->getWSPort(); + auto streamServer = sipcluster[serverIndex]->getStreamServer(); char callKey[37]; bzero(callKey, 37); @@ -2973,7 +3050,7 @@ int MySql_connection::sql_insert_into_conference(thread_data* local_buf, unsigne local_buf->answer_buf.getData(), strlen(local_buf->answer_buf.getData()), profile, - "", + streamServer.data(), nodeId.data()); /* $msg = json_encode( @@ -3024,11 +3101,13 @@ int MySql_connection::sql_insert_into_conference(thread_data* local_buf, unsigne local_buf->answer_buf.unlock(); Send_OK_Package(1, 0, PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_insert_into_conference", t); return 0; } int MySql_connection::sql_select_from_conference(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); // @todo заменить на более читаемый код на базе перечислений или чего то подобного const static char* columDef[MAX_COLUMNS_COUNT] = { "name", // имя конференции (только цифры) @@ -3037,11 +3116,13 @@ int MySql_connection::sql_select_from_conference(thread_data* local_buf, unsigne "message", // сообщение "profile", // Режим video_*, audio_* "stream", // Не пусто и не 0 если активирован режим стриминга [это поле относится к пользователю а не конференции так как зависит от mode ] + "node", // нода для звонка }; if(!local_buf->sql.prepare_columns_for_select(columDef, local_buf->qInfo)) { Send_Err_Package(local_buf->qInfo.errorCode, local_buf->qInfo.errorText, PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_select_from_conference", t); return 0; } @@ -3050,6 +3131,7 @@ int MySql_connection::sql_select_from_conference(thread_data* local_buf, unsigne if(idExprPos == -1) { Send_Err_Package(SQL_ERR_WHERE_EXPRESSIONS, "Selection without transferring the requested values of the primary key is not supported", PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_select_from_conference", t); return 0; } @@ -3095,17 +3177,20 @@ int MySql_connection::sql_select_from_conference(thread_data* local_buf, unsigne if(local_buf->sql.useColumn(3)) local_buf->sql.getValue(countRows, 3) = (const char*)local_buf->stm.conference_select->result_message; if(local_buf->sql.useColumn(4)) local_buf->sql.getValue(countRows, 4) = (const char*)local_buf->stm.conference_select->result_profile; if(local_buf->sql.useColumn(5)) local_buf->sql.getValue(countRows, 5) = (const char*)local_buf->stm.conference_select->result_stream; + if(local_buf->sql.useColumn(6)) local_buf->sql.getValue(countRows, 6) = (const char*)local_buf->stm.conference_select->result_node; countRows++; } } local_buf->sql.sendAllRowsAndHeaders(local_buf, PacketNomber, countRows, this); + TagTimer::add("MySql_connection::sql_select_from_conference", t); return 0; } int MySql_connection::sql_delete_from_conference(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); //Удаляет конференцию и всех участников. const static char* columDef[MAX_COLUMNS_COUNT] = { "name", // имя конференции (только цифры) @@ -3119,6 +3204,7 @@ int MySql_connection::sql_delete_from_conference(thread_data* local_buf, unsigne if(!local_buf->sql.prepare_where_expressions(columDef, local_buf->qInfo)) { Send_Err_Package(local_buf->qInfo.errorCode, local_buf->qInfo.errorText, PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_delete_from_conference", t); return 0; } @@ -3128,6 +3214,7 @@ int MySql_connection::sql_delete_from_conference(thread_data* local_buf, unsigne if(idExprPos == -1) { Send_Err_Package(SQL_ERR_WHERE_EXPRESSIONS, "Selection without transferring the requested values of the primary key is not supported", PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_delete_from_conference", t); return 0; } @@ -3171,18 +3258,22 @@ int MySql_connection::sql_delete_from_conference(thread_data* local_buf, unsigne * Для операций удаления affectedRows возвращатся не будет в целях оптимизации. */ Send_OK_Package(0, 0, PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_delete_from_conference", t); return 0; } int MySql_connection::sql_insert_into_conference_members(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); Send_Err_Package(SQL_ERR_READ_ONLY, "insert into `conference_members` is not ready yet", PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_insert_into_conference_members", t); return 0; } int MySql_connection::sql_select_from_conference_members(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); // @todo заменить на более читаемый код на базе перечислений или чего то подобного const static char* columDef[MAX_COLUMNS_COUNT] = { "name", // имя конференции (только цифры) @@ -3245,6 +3336,7 @@ int MySql_connection::sql_select_from_conference_members(thread_data* local_buf, if(!local_buf->sql.prepare_columns_for_select(columDef, local_buf->qInfo)) { Send_Err_Package(local_buf->qInfo.errorCode, local_buf->qInfo.errorText, PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_select_from_conference_members", t); return 0; } @@ -3539,24 +3631,95 @@ int MySql_connection::sql_select_from_conference_members(thread_data* local_buf, } } local_buf->sql.sendAllRowsAndHeaders(local_buf, PacketNomber, countRows, this); + TagTimer::add("MySql_connection::sql_select_from_conference_members", t); return 0; } int MySql_connection::sql_delete_from_conference_members(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); Send_Err_Package(SQL_ERR_READ_ONLY, "delete from `conference_members` is not ready yet", PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_delete_from_conference_members", t); return 0; } int MySql_connection::sql_insert_into_dialogs(thread_data* local_buf, unsigned int PacketNomber) { + auto t = TagTimer::mtime(); Send_Err_Package(SQL_ERR_READ_ONLY, "Table `dialogs` is not ready yet", PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_insert_into_dialogs", t); return 0; } + + +int MySql_connection::sql_select_from_profiler(thread_data* local_buf, unsigned int PacketNomber) +{ + auto t = TagTimer::mtime(); + + const static char* columDef[MAX_COLUMNS_COUNT] = { + "tag", + "time", + "calls", + //"time_ps", + //"calls_ps", + }; + + if(!local_buf->sql.prepare_columns_for_select(columDef, local_buf->qInfo)) + { + Send_Err_Package(local_buf->qInfo.errorCode, local_buf->qInfo.errorText, PacketNomber+1, local_buf, this); + TagTimer::add("MySql_connection::sql_select_from_profiler", t); + return 0; + } + + + int countRows = 0; + + auto dt = TagTimer::mtime() - TagTimer::lastReadTime; + //auto dt = (int)tcpServer ::instance()->bm.get_uptime(); + + TagTimer::lock(); + auto m = TagTimer::get(); + for(auto it = m.begin(); it != m.end(); ++it) + { + if(local_buf->sql.useColumn(0)) local_buf->sql.getValue(countRows, 0) = it->first.data(); + if(local_buf->sql.useColumn(1)) local_buf->sql.getValue(countRows, 1) = (float)(it->second.time/1000); + if(local_buf->sql.useColumn(2)) local_buf->sql.getValue(countRows, 2) = it->second.count; + //if(local_buf->sql.useColumn(2)) local_buf->sql.getValue(countRows, 2) = (float)(it->second.time/dt)/1000; + //if(local_buf->sql.useColumn(4)) local_buf->sql.getValue(countRows, 4) = (float)(it->second.count/(dt/1000)); + + //it->second.count = 0; + //it->second.time = 0; + countRows++; + } + + TagTimer::unlock(); + + TagTimer::lastReadTime = TagTimer::mtime(); + + local_buf->sql.sendAllRowsAndHeaders(local_buf, PacketNomber, countRows, this); + TagTimer::add("MySql_connection::sql_select_from_profiler", t); + return 0; +} + + + + + + + + + + + + + + + int MySql_connection::set_online(thread_data* local_buf) { + auto t = TagTimer::mtime(); if(isOnLine) { return 0; @@ -3639,8 +3802,8 @@ int MySql_connection::set_online(thread_data* local_buf) int dataLen = p - pakbuf; TagLoger::log(Log_MySqlServer, 0, "itit len:%d\n", dataLen); - int t = dataLen - 4; - memcpy(pakbuf, &t, 3); // Длина пакета + int dl = dataLen - 4; + memcpy(pakbuf, &dl, 3); // Длина пакета if(TagLoger::isLog(Log_MySqlServer, TAGLOG_DEBUG)) { @@ -3657,11 +3820,13 @@ int MySql_connection::set_online(thread_data* local_buf) clientState = STATE_SEND_HANDSHAKE; TagLoger::log(Log_MySqlServer, 0, "Connection will not be closed [4] [MySql_connection]\n"); + TagTimer::add("MySql_connection::set_online", t); return web_write(pakbuf, dataLen); } int MySql_connection::set_offline(thread_data* local_buf) { + auto t = TagTimer::mtime(); if(!isOnLine) { return web_close(); @@ -3674,10 +3839,11 @@ int MySql_connection::set_offline(thread_data* local_buf) api_version = 0; start_online_time = 0; cometqlcluster = 0; - + isAuthUser = false; isOnLine = false; + TagTimer::add("MySql_connection::set_offline", t); return web_close(); } diff --git a/src/MySql_connection.h b/src/MySql_connection.h index d570cf9..dc4bc3d 100644 --- a/src/MySql_connection.h +++ b/src/MySql_connection.h @@ -204,7 +204,10 @@ class MySql_connection:public connection * Не 0 если сообщение пришло из кластера */ int cometqlcluster = 0; - + + /** + * Указывает на то что у пользователя есть права супер пользователя + */ bool isAuthUser = false; int api_version = 0; @@ -294,6 +297,7 @@ class MySql_connection:public connection int sql_set_value(thread_data* local_buf, unsigned int PacketNomber); + int sql_select_from_profiler(thread_data* local_buf, unsigned int PacketNomber); int sql_select_database_name(thread_data* local_buf, unsigned int PacketNomber); int sql_select_systemvarible(thread_data* local_buf, unsigned int PacketNomber); int sql_select_from_users_auth(thread_data* local_buf, unsigned int PacketNomber); @@ -303,7 +307,7 @@ class MySql_connection:public connection int sql_select_from_pipes_messages(thread_data* local_buf, unsigned int PacketNomber); int sql_select_from_users_in_pipes(thread_data* local_buf, unsigned int PacketNomber); int sql_select_from_pipes(thread_data* local_buf, unsigned int PacketNomber); - int sql_select_from_pipes_settings(thread_data* local_buf, unsigned int PacketNomber); + int sql_select_from_pipes_settings(thread_data* local_buf, unsigned int PacketNomber); int sql_select_from_conference(thread_data* local_buf, unsigned int PacketNomber); int sql_select_from_conference_members(thread_data* local_buf, unsigned int PacketNomber); @@ -311,6 +315,7 @@ class MySql_connection:public connection int sql_insert_into_dialogs(thread_data* local_buf, unsigned int PacketNomber); int sql_insert_into_conference_members(thread_data* local_buf, unsigned int PacketNomber); + /** * Эквивалент таблицы содержащей ключи авторизации пользователей * @param local_buf @@ -331,7 +336,7 @@ class MySql_connection:public connection int sql_insert_into_pipes_messages(thread_data* local_buf, unsigned int PacketNomber); int sql_insert_into_users_in_pipes(thread_data* local_buf, unsigned int PacketNomber); int sql_insert_into_pipes(thread_data* local_buf, unsigned int PacketNomber); - int sql_insert_into_pipes_settings(thread_data* local_buf, unsigned int PacketNomber); + int sql_insert_into_pipes_settings(thread_data* local_buf, unsigned int PacketNomber); int sql_delete_from_users_auth(thread_data* local_buf, unsigned int PacketNomber); int sql_delete_from_users_data(thread_data* local_buf, unsigned int PacketNomber); @@ -340,7 +345,7 @@ class MySql_connection:public connection int sql_delete_from_pipes_messages(thread_data* local_buf, unsigned int PacketNomber); int sql_delete_from_users_in_pipes(thread_data* local_buf, unsigned int PacketNomber); int sql_delete_from_pipes(thread_data* local_buf, unsigned int PacketNomber); - int sql_delete_from_pipes_settings(thread_data* local_buf, unsigned int PacketNomber); + int sql_delete_from_pipes_settings(thread_data* local_buf, unsigned int PacketNomber); int sql_delete_from_conference(thread_data* local_buf, unsigned int PacketNomber); int sql_delete_from_conference_members(thread_data* local_buf, unsigned int PacketNomber); diff --git a/src/TagTimer.cpp b/src/TagTimer.cpp index 171d380..87c660e 100644 --- a/src/TagTimer.cpp +++ b/src/TagTimer.cpp @@ -2,32 +2,52 @@ // PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com #include "TagTimer.h" + +std::map TagTimer::timeMap; +bool TagTimer::on = true; +mTime TagTimer::lastReadTime = 0; - -mTime TagTimer::tagTimer[100]; -mTime TagTimer::tagTimerStart[100]; - - -void TagTimer::end(int tag) +pthread_mutex_t TagTimer_mutex; + +mTime TagTimer::mtime() { - tagTimer[tag] += mtime() - tagTimerStart[tag]; - tagTimerStart[tag] = 0; -} + struct timeval t; + gettimeofday(&t, NULL); + long long mt = (long long)t.tv_sec * 1000 + t.tv_usec / 1000; + return mt; +} -void TagTimer::start(int tag) +void TagTimer::init() { - tagTimerStart[tag] = mtime(); + pthread_mutex_init(&TagTimer_mutex,NULL); } - -void TagTimer::add(int tag, mTime t) + +void TagTimer::add(const char* key, mTime t) { - tagTimer[tag] += t; + if(!on) + { + return; + } + + pthread_mutex_lock(&TagTimer_mutex); + + // добавить блокировки для атомарности + statItem item = timeMap[std::string(key)]; + item.count++; + item.time += mtime() - t; + + timeMap[std::string(key)] = item; + pthread_mutex_unlock(&TagTimer_mutex); } - -mTime TagTimer::mtime() + +void TagTimer::lock() { - struct timeval t; - gettimeofday(&t, NULL); - long long mt = (long long)t.tv_sec * 1000 + t.tv_usec / 1000; - return mt; + pthread_mutex_lock(&TagTimer_mutex); + } + +void TagTimer::unlock() +{ + pthread_mutex_unlock(&TagTimer_mutex); + +} \ No newline at end of file diff --git a/src/TagTimer.h b/src/TagTimer.h index 99add4c..09fc364 100644 --- a/src/TagTimer.h +++ b/src/TagTimer.h @@ -5,28 +5,48 @@ #include #include +#include +#include + #ifndef TAG_TIMER_H #define TAG_TIMER_H #define mTime long long #define Time_start 1 +#define Time_db_query 2 -class TagTimer -{ - static mTime tagTimer[100]; - static mTime tagTimerStart[100]; - +class statItem{ public: + mTime time; + int count; + +}; + +class TagTimer +{ + static std::map timeMap; - static void end(int tag); + static bool on; +public: + static mTime lastReadTime; - static void start(int tag); - - static void add(int tag, mTime t); + static void setStatus(bool status) + { + on = status; + } + static void init(); + static void add(const char* key, mTime t); static mTime mtime(); + static void lock(); + static void unlock(); + static std::map get() + { + return timeMap; + } + }; #endif /* TAG_TIMER_H */ \ No newline at end of file diff --git a/src/appConf.cpp b/src/appConf.cpp index b84e6d6..a8cdd05 100644 --- a/src/appConf.cpp +++ b/src/appConf.cpp @@ -240,6 +240,19 @@ bool appConf::initFromFile(const char *fileName) return true; } +bool file_exists(const std::string& name) +{ + if (FILE *file = fopen(name.c_str(), "r")) + { + fclose(file); + return true; + } + else + { + return false; + } +} + bool appConf::init(int argc, char *argv[]) { int conf_path = -1; @@ -267,12 +280,19 @@ bool appConf::init(int argc, char *argv[]) } } } - - if(conf_path == -1) + + if(conf_path == -1 && file_exists("comet.ini")) { + printf("Config file: ./comet.ini\n"); return initFromFile("comet.ini"); } + else if(conf_path == -1 && file_exists("/etc/comet-server/comet.ini")) + { + printf("Config file: /etc/comet-server/comet.ini\n"); + return initFromFile("/etc/comet-server/comet.ini"); + } + printf("Config file: %s\n", argv[conf_path]); return initFromFile(argv[conf_path]); } diff --git a/src/connection.cpp b/src/connection.cpp index 2e28d48..d7f626e 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -43,7 +43,7 @@ connection::~connection() } -long connection::getUptime() +long connection::getUptime() const { if(start_online_time <= 0) { diff --git a/src/connection.h b/src/connection.h index 54de095..3bbd387 100644 --- a/src/connection.h +++ b/src/connection.h @@ -89,7 +89,7 @@ class connection: public CpClass /** * Возвращает Uptime соединения */ - long getUptime(); + long getUptime() const; inline void setfd(int Fd){ fd = Fd;} diff --git a/src/dbLink.cpp b/src/dbLink.cpp index b283621..ebb4bcc 100644 --- a/src/dbLink.cpp +++ b/src/dbLink.cpp @@ -346,6 +346,8 @@ bool dbLink::connect() return false; } + auto t = TagTimer::mtime(); + isConnected = true; mysqlLink = mysql_init(mysqlLink); @@ -368,6 +370,7 @@ bool dbLink::connect() { TagLoger::error(Log_dbLink, 0, "\x1b[1;31mMySQL connection not established\n%s\nip=%s:%d user=%s [errno=%d]\x1b[0m", mysql_error(mysqlLink), db_host.data(), db_port, db_user.data(), mysql_errno(mysqlLink)); + TagTimer::add("dbLink::connect", t); return false; } @@ -377,6 +380,7 @@ bool dbLink::connect() } TagLoger::log(Log_dbLink, 0, "\x1b[1;32mMySQL connection established\nip=%s:%d user=%s\x1b[0m", db_host.data(), db_port, db_user.data()); + TagTimer::add("dbLink::connect", t); return true; //return query("SET CHARACTER SET 'utf8' "); @@ -385,6 +389,8 @@ bool dbLink::connect() bool dbLink::query(const char *q) { + auto t = TagTimer::mtime(); + if(!isConnected) { connect(); @@ -393,6 +399,7 @@ bool dbLink::query(const char *q) TagLoger::log(Log_dbLink, 0, "\x1b[1;32mMySQL query[%d]=%s\x1b[0m", strlen(q), q); if(mysql_real_query(mysqlLink, q, strlen(q)) == 0) { + TagTimer::add("dbLink::query", t); return true; } @@ -407,6 +414,7 @@ bool dbLink::query(const char *q) if(mysql_real_query(mysqlLink, q, strlen(q)) == 0) { + TagTimer::add("dbLink::query", t); return true; } @@ -417,6 +425,7 @@ bool dbLink::query(const char *q) { if(mysql_real_query(mysqlLink, q, strlen(q)) == 0) { + TagTimer::add("dbLink::query", t); return true; } @@ -435,11 +444,13 @@ bool dbLink::query(const char *q) } } + TagTimer::add("dbLink::query", t); return false; } bool dbLink::query_format(const char *format, ...) { + auto t = TagTimer::mtime(); if(!isConnected) { connect(); @@ -456,6 +467,7 @@ bool dbLink::query_format(const char *format, ...) if(mysql_real_query(mysqlLink, buf, strlen(buf)) == 0) { va_end(ap); + TagTimer::add("dbLink::query_format", t); return true; } @@ -470,6 +482,7 @@ bool dbLink::query_format(const char *format, ...) if(mysql_real_query(mysqlLink, buf, strlen(buf)) == 0) { + TagTimer::add("dbLink::query_format", t); return true; } @@ -481,6 +494,7 @@ bool dbLink::query_format(const char *format, ...) if(mysql_real_query(mysqlLink, buf, strlen(buf)) == 0) { va_end(ap); + TagTimer::add("dbLink::query_format", t); return true; } @@ -500,6 +514,7 @@ bool dbLink::query_format(const char *format, ...) } va_end(ap); + TagTimer::add("dbLink::query_format", t); return false; } @@ -609,7 +624,10 @@ void stmMapper::init(dbLink *mysql) users_data_select = new stm_users_data_select(); } users_data_select->prepare(mysql); - + + + + if(pipes_settings_select == NULL) { pipes_settings_select = new stm_pipes_settings_select(); diff --git a/src/dbLink.h b/src/dbLink.h index 943ba01..15fc602 100644 --- a/src/dbLink.h +++ b/src/dbLink.h @@ -3,7 +3,8 @@ #include -#include "appConf.h" +#include "appConf.h" +#include "TagTimer.h" #ifndef DBLINK_H #define DBLINK_H @@ -201,7 +202,9 @@ class stm_log_query: public stmBase{ stm_log_query(){} int insert(int dev_id, const char* message, unsigned long message_length) - { + { + auto t = TagTimer::mtime(); + param_dev_id = dev_id; if(appConf::instance()->get_int("db", "buf_size") < message_length) { @@ -210,7 +213,13 @@ class stm_log_query: public stmBase{ memcpy(param_message, message, message_length); param_message_length = message_length; - return stmBase::insert(); + + + int res = stmBase::insert(); + + TagTimer::add("dbLink::stm_log_query", t); + TagTimer::add("dbLink::mysql_query", t); + return res; } int insert(int dev_id, const char* query) @@ -305,6 +314,8 @@ class stm_users_queue_insert: public stmBase{ int execute(const char* id, unsigned long time, unsigned long dev_id, unsigned long user_id, const char* event, const char* message, unsigned long message_length) { + auto t = TagTimer::mtime(); + param_time = time; param_dev_id = dev_id; param_user_id = user_id; @@ -335,7 +346,11 @@ class stm_users_queue_insert: public stmBase{ param_message_length = message_length; - return stmBase::insert(); + int res = stmBase::insert(); + + TagTimer::add("dbLink::stm_users_queue_insert", t); + TagTimer::add("dbLink::mysql_query", t); + return res; } }; @@ -384,6 +399,8 @@ class stm_conference_delete: public stmBase{ int execute(unsigned long dev_id, const char* name, unsigned long user_id) { + auto t = TagTimer::mtime(); + param_dev_id = dev_id; param_user_id = user_id; @@ -394,7 +411,12 @@ class stm_conference_delete: public stmBase{ } strncpy(param_name, name, param_name_length); - return stmBase::insert(); + + int res = stmBase::insert(); + + TagTimer::add("dbLink::stm_conference_delete", t); + TagTimer::add("dbLink::mysql_query", t); + return res; } }; @@ -526,6 +548,8 @@ class stm_conference_insert: public stmBase{ const char* stream, const char* node) { + auto t = TagTimer::mtime(); + param_time = time(NULL); param_dev_id = dev_id; @@ -572,7 +596,12 @@ class stm_conference_insert: public stmBase{ memcpy(param_message, message, message_length); param_message_length = message_length; - return stmBase::insert(); + + int res = stmBase::insert(); + + TagTimer::add("dbLink::stm_conference_insert", t); + TagTimer::add("dbLink::mysql_query", t); + return res; } }; @@ -699,6 +728,8 @@ class stm_conference_select: public stmBase{ bool execute(unsigned long dev_id, const char* name) { + auto t = TagTimer::mtime(); + param_dev_id = dev_id; param_name_length = strlen(name); @@ -708,7 +739,11 @@ class stm_conference_select: public stmBase{ } strncpy(param_name, name, param_name_length); - return stmBase::select(); + bool res = stmBase::select(); + + TagTimer::add("dbLink::stm_conference_select", t); + TagTimer::add("dbLink::mysql_query", t); + return res; } /** @@ -805,6 +840,8 @@ class stm_conference_select_nodes_for_room: public stmBase{ bool execute(unsigned long dev_id, const char* name) { + auto t = TagTimer::mtime(); + param_dev_id = dev_id; param_name_length = strlen(name); @@ -814,7 +851,11 @@ class stm_conference_select_nodes_for_room: public stmBase{ } strncpy(param_name, name, param_name_length); - return stmBase::select(); + bool res = stmBase::select(); + + TagTimer::add("dbLink::stm_conference_select_nodes_for_room", t); + TagTimer::add("dbLink::mysql_query", t); + return res; } /** @@ -955,12 +996,18 @@ class stm_users_queue_select: public stmBase{ bool execute(unsigned long dev_id, unsigned long user_id, unsigned long limit) { + auto t = TagTimer::mtime(); + // https://docs.oracle.com/cd/E17952_01/mysql-5.5-en/mysql-stmt-fetch.html param_dev_id = dev_id; param_user_id = user_id; param_limit = limit; - return stmBase::select(); + bool res = stmBase::select(); + + TagTimer::add("dbLink::stm_users_queue_select", t); + TagTimer::add("dbLink::mysql_query", t); + return res; } /** @@ -1035,11 +1082,18 @@ class stm_users_queue_delete: public stmBase{ int execute(unsigned long time, unsigned long dev_id, unsigned long user_id) { + auto t = TagTimer::mtime(); + param_time = time; param_dev_id = dev_id; param_user_id = user_id; - return stmBase::insert(); + + int res = stmBase::insert(); + + TagTimer::add("dbLink::stm_users_queue_delete", t); + TagTimer::add("dbLink::mysql_query", t); + return res; } }; @@ -1139,6 +1193,8 @@ class stm_pipe_messages_insert: public stmBase{ int execute(const char* id, unsigned long time, unsigned long dev_id, const char* pipe_name, const char* event, const char* message, unsigned long message_length, unsigned long user_id) { + auto t = TagTimer::mtime(); + param_time = time; param_dev_id = dev_id; param_user_id = user_id; @@ -1179,7 +1235,12 @@ class stm_pipe_messages_insert: public stmBase{ memcpy(param_message, message, message_length); param_message_length = message_length; - return stmBase::insert(); + + int res = stmBase::insert(); + + TagTimer::add("dbLink::stm_pipe_messages_insert", t); + TagTimer::add("dbLink::mysql_query", t); + return res; } }; @@ -1297,6 +1358,8 @@ class stm_pipe_messages_select: public stmBase{ bool execute(unsigned long dev_id, const char* pipe_name, unsigned long limit) { + auto t = TagTimer::mtime(); + // https://docs.oracle.com/cd/E17952_01/mysql-5.5-en/mysql-stmt-fetch.html param_dev_id = dev_id; param_limit = limit; @@ -1310,7 +1373,11 @@ class stm_pipe_messages_select: public stmBase{ bzero(param_pipe_name, PIPE_NAME_LEN); memcpy(param_pipe_name, pipe_name, param_pipe_name_length); - return stmBase::select(); + bool res = stmBase::select(); + + TagTimer::add("dbLink::stm_pipe_messages_select", t); + TagTimer::add("dbLink::mysql_query", t); + return res; } /** @@ -1390,6 +1457,8 @@ class stm_pipe_messages_delete: public stmBase{ int execute(unsigned long time, unsigned long dev_id, const char* pipe_name) { + auto t = TagTimer::mtime(); + param_time = time; param_dev_id = dev_id; @@ -1401,7 +1470,12 @@ class stm_pipe_messages_delete: public stmBase{ bzero(param_pipe_name, PIPE_NAME_LEN); memcpy(param_pipe_name, pipe_name, param_pipe_name_length); - return stmBase::insert(); + + int res = stmBase::insert(); + + TagTimer::add("dbLink::stm_pipe_messages_delete", t); + TagTimer::add("dbLink::mysql_query", t); + return res; } }; @@ -1445,11 +1519,18 @@ class stm_pipe_messages_delete_by_message_id: public stmBase{ int execute(const char* id, unsigned long dev_id) { + auto t = TagTimer::mtime(); + bzero(param_id, MYSQL_UUID_LEN); strncpy(param_id, id, MYSQL_UUID_LEN); param_dev_id = dev_id; - return stmBase::insert(); + + int res = stmBase::insert(); + + TagTimer::add("dbLink::stm_pipe_messages_delete_by_message_id", t); + TagTimer::add("dbLink::mysql_query", t); + return res; } }; @@ -1502,6 +1583,8 @@ class stm_users_auth_replace: public stmBase{ int execute(unsigned long dev_id, unsigned long user_id, const char* hash) { + auto t = TagTimer::mtime(); + param_dev_id = dev_id; param_user_id = user_id; @@ -1512,7 +1595,12 @@ class stm_users_auth_replace: public stmBase{ } bzero(param_hash, USER_HASH_LEN); memcpy(param_hash, hash, param_hash_length); - return stmBase::insert(); + + int res = stmBase::insert(); + + TagTimer::add("dbLink::stm_users_auth_replace", t); + TagTimer::add("dbLink::mysql_query", t); + return res; } }; @@ -1551,10 +1639,17 @@ class stm_users_auth_delete: public stmBase{ int execute(unsigned long dev_id, unsigned long user_id) { + auto t = TagTimer::mtime(); + param_dev_id = dev_id; param_user_id = user_id; - return stmBase::insert(); + + int res = stmBase::insert(); + + TagTimer::add("dbLink::stm_users_auth_delete", t); + TagTimer::add("dbLink::mysql_query", t); + return res; } }; @@ -1614,11 +1709,17 @@ class stm_users_auth_select: public stmBase{ bool execute(unsigned long dev_id, unsigned long user_id) { + auto t = TagTimer::mtime(); + // https://docs.oracle.com/cd/E17952_01/mysql-5.5-en/mysql-stmt-fetch.html param_dev_id = dev_id; param_user_id = user_id; - return stmBase::select(); + bool res = stmBase::select(); + + TagTimer::add("dbLink::stm_users_auth_select", t); + TagTimer::add("dbLink::mysql_query", t); + return res; } /** @@ -1713,6 +1814,8 @@ class stm_users_data_replace: public stmBase{ int execute(unsigned long dev_id, unsigned long user_id, const char* data, int data_length) { + auto t = TagTimer::mtime(); + param_dev_id = dev_id; param_user_id = user_id; @@ -1729,7 +1832,12 @@ class stm_users_data_replace: public stmBase{ printf("param_data_length=%ld", param_data_length); printf("param_dev_id=%ld", param_dev_id); - return stmBase::insert(); + + int res = stmBase::insert(); + + TagTimer::add("dbLink::stm_users_data_replace", t); + TagTimer::add("dbLink::mysql_query", t); + return res; } }; @@ -1768,10 +1876,17 @@ class stm_users_data_delete: public stmBase{ int execute(unsigned long dev_id, unsigned long user_id) { + auto t = TagTimer::mtime(); + param_dev_id = dev_id; param_user_id = user_id; - return stmBase::insert(); + + int res = stmBase::insert(); + + TagTimer::add("dbLink::stm_users_data_delete", t); + TagTimer::add("dbLink::mysql_query", t); + return res; } }; @@ -1839,12 +1954,18 @@ class stm_users_data_select: public stmBase{ bool execute(unsigned long dev_id, unsigned long user_id) { + auto t = TagTimer::mtime(); + // https://docs.oracle.com/cd/E17952_01/mysql-5.5-en/mysql-stmt-fetch.html param_dev_id = dev_id; param_user_id = user_id; - return stmBase::select(); + bool res = stmBase::select(); + + TagTimer::add("dbLink::stm_users_data_select", t); + TagTimer::add("dbLink::mysql_query", t); + return res; } /** @@ -1938,6 +2059,8 @@ class stm_revoked_tokens_replace: public stmBase{ int execute(unsigned long dev_id, const char* token) { + auto t = TagTimer::mtime(); + param_dev_id = dev_id; param_time = 9999999999; @@ -1954,7 +2077,12 @@ class stm_revoked_tokens_replace: public stmBase{ printf("param_token_length=%ld", param_token_length); printf("param_dev_id=%ld", param_dev_id); - return stmBase::insert(); + + int res = stmBase::insert(); + + TagTimer::add("dbLink::stm_revoked_tokens_replace", t); + TagTimer::add("dbLink::mysql_query", t); + return res; } }; @@ -2000,6 +2128,8 @@ class stm_revoked_tokens_delete: public stmBase{ int execute(unsigned long dev_id, const char* token) { + auto t = TagTimer::mtime(); + param_dev_id = dev_id; param_token_length = strlen(token); @@ -2010,7 +2140,12 @@ class stm_revoked_tokens_delete: public stmBase{ bzero(param_token, MAX_JWT_LEN); memcpy(param_token, token, param_token_length); - return stmBase::insert(); + + int res = stmBase::insert(); + + TagTimer::add("dbLink::stm_revoked_tokens_delete", t); + TagTimer::add("dbLink::mysql_query", t); + return res; } }; @@ -2077,6 +2212,8 @@ class stm_revoked_tokens_select: public stmBase{ bool execute(unsigned long dev_id, const char* token) { + auto t = TagTimer::mtime(); + // https://docs.oracle.com/cd/E17952_01/mysql-5.5-en/mysql-stmt-fetch.html param_dev_id = dev_id; @@ -2088,7 +2225,12 @@ class stm_revoked_tokens_select: public stmBase{ bzero(param_token, MAX_JWT_LEN); memcpy(param_token, token, param_token_length); - return stmBase::select(); + + bool res = stmBase::select(); + + TagTimer::add("dbLink::stm_revoked_tokens_select", t); + TagTimer::add("dbLink::mysql_query", t); + return res; } /** @@ -2141,7 +2283,23 @@ class stm_revoked_tokens_select: public stmBase{ return stmBase::free(); } }; - + + + + + + + + + + + + + + + + + class stm_pipes_settings_select: public stmBase{ friend stmMapper; @@ -2198,6 +2356,7 @@ class stm_pipes_settings_select: public stmBase{ bool execute(unsigned long dev_id, const char* pipe_name) { + auto t = TagTimer::mtime(); // https://docs.oracle.com/cd/E17952_01/mysql-5.5-en/mysql-stmt-fetch.html param_dev_id = dev_id; @@ -2209,7 +2368,11 @@ class stm_pipes_settings_select: public stmBase{ bzero(param_pipe_name, PIPE_NAME_LEN); memcpy(param_pipe_name, pipe_name, param_pipe_name_length); - return stmBase::select(); + bool res = stmBase::select(); + + TagTimer::add("dbLink::stm_pipes_settings_select", t); + TagTimer::add("dbLink::mysql_query", t); + return res; } /** @@ -2304,10 +2467,15 @@ class stm_users_time_select: public stmBase{ bool execute(unsigned long dev_id, unsigned long user_id) { + auto t = TagTimer::mtime(); // https://docs.oracle.com/cd/E17952_01/mysql-5.5-en/mysql-stmt-fetch.html param_dev_id = dev_id; param_user_id = user_id; - return stmBase::select(); + bool res = stmBase::select(); + + TagTimer::add("dbLink::stm_users_time_select", t); + TagTimer::add("dbLink::mysql_query", t); + return res; } /** @@ -2368,7 +2536,8 @@ class stmMapper{ stm_users_data_replace *users_data_replace = NULL; stm_users_data_delete *users_data_delete = NULL; stm_users_data_select *users_data_select = NULL; - + + stm_users_time_select *users_time_select = NULL; stm_pipes_settings_select *pipes_settings_select = NULL; diff --git a/src/devManager.cpp b/src/devManager.cpp index 9d0c6a7..4775d77 100644 --- a/src/devManager.cpp +++ b/src/devManager.cpp @@ -1,11 +1,12 @@ // This is an independent project of an individual developer. Dear PVS-Studio, please check it. // PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - + #include "sha1.h" #include "base64.h" #include "devManager.h" + const char* devInfo::getDevUrl(int i) const { if(i < 0 || i > urls_count) @@ -66,17 +67,25 @@ devInfo::devInfo(int dev_id) index = new user_index(dev_id); pthread_mutex_init(&pipe_index_mutex,NULL); } - + + + + + + devInfo::~devInfo() { - delete index; + delete index; } bool devInfo::testDevKey(const char* devKey) const -{ - return memcmp(appConf::instance()->get_chars("main", "password"), devKey, DEV_KEY_LEN) == 0; +{ + return memcmp(appConf::instance()->get_chars("main", "password"), devKey, DEV_KEY_LEN) == 0; + + } + /** * Проверяет DevKey в соответсвии с механизмом авторизации Mysql * @param dev_id @@ -85,12 +94,13 @@ bool devInfo::testDevKey(const char* devKey) const * @return */ bool devInfo::testDevKey(const char* random20bytes, const char* DevKeyHashStart) -{ +{ + const char* devKeyPassword = appConf::instance()->get_chars("main", "password"); - + unsigned char sha1_password[20]; bzero(sha1_password, 20); - sha1::calc(devKeyPassword, strlen(devKeyPassword) ,sha1_password); + sha1::calc(devKeyPassword, strlen(devKeyPassword), sha1_password); unsigned char sha1_password2[20]; bzero(sha1_password2, 20); @@ -140,14 +150,14 @@ devManager* devManager::instance() devManager::~devManager() { - if(dev_index_size > 0) - { - for(int i =0; i< dev_index_size; i++) + if(dev_index_size > 0) { - delete index[i]; + for(int i =0; i< dev_index_size; i++) + { + delete index[i]; + } + delete[] index; } - delete[] index; - } } /** @@ -167,10 +177,9 @@ void devManager::setDevIndexSize(int size) /** * Инициализация первого devInfo * Он будет возвращатся во всех случаях кода getDevInfo(int dev_id) будет получать не валидный dev_id - */ - index[0] = new devInfo(0); + */ + index[0] = new devInfo(0); } - else if(dev_index_size > size) { dev_index_size = size; @@ -187,7 +196,7 @@ devInfo* devManager::getDevInfo(int dev_id) if( index[dev_id] == NULL) { - index[dev_id] = new devInfo(dev_id); + index[dev_id] = new devInfo(dev_id); } return index[dev_id]; diff --git a/src/devManager.h b/src/devManager.h index 696c993..c91ffe1 100644 --- a/src/devManager.h +++ b/src/devManager.h @@ -273,7 +273,8 @@ class devInfo friend class devManager; int id; - bool active = false; + bool active = false; + char* url = NULL; char** urls = NULL; @@ -300,11 +301,13 @@ class devInfo pthread_mutex_unlock(&pipe_index_mutex); } - protected: + protected: + devInfo(int dev_id); - + + public: - + void setDevUrl(const char* devUrl); int countDevUrl() const; @@ -319,7 +322,7 @@ class devInfo * @param random20bytes * @param dev_key * @return - */ + */ static bool testDevKey(const char* random20bytes, const char* DevKeyHashStart); CP getPipe(const std::string &pipe_name) @@ -378,7 +381,7 @@ class devInfo user_index* index; ~devInfo(); - + int getDevId() const { return id;} bool testDevKey(const char* devKey) const; diff --git a/src/internalApi.cpp b/src/internalApi.cpp index 81366fc..ba050a8 100644 --- a/src/internalApi.cpp +++ b/src/internalApi.cpp @@ -19,6 +19,8 @@ int internalApi::send_to_user(thread_data* local_buf, int dev_id, int user_id, c int internalApi::send_to_user(thread_data* local_buf, int dev_id, int user_id, const char* pipe_event, const char* msg_data, const char* server_data) { + auto t = TagTimer::mtime(); + local_buf->setThreadStatus('t'); int *conection_id = devManager::instance()->getDevInfo(dev_id)->index->get_conection_id(local_buf, user_id); int isSend = -1; if(conection_id != NULL) @@ -55,11 +57,14 @@ int internalApi::send_to_user(thread_data* local_buf, int dev_id, int user_id, c local_buf->stm.users_queue_insert->execute(uid, (long int)time(NULL), dev_id, user_id, pipe_event, msg_data, strlen(msg_data)); } + TagTimer::add("internalApi::send_to_user", t); return isSend; } int internalApi::local_send_to_user(thread_data* local_buf, int dev_id, int user_id, const char* pipe_event, const char* msg_data) { + auto t = TagTimer::mtime(); + local_buf->setThreadStatus('l'); //char server_data[EVENT_NAME_LEN+64]; //snprintf(server_data, EVENT_NAME_LEN+64, "\"event_name\":\"%s\",\"SendToUser\":true", pipe_event); std::string server_data; @@ -96,6 +101,7 @@ int internalApi::local_send_to_user(thread_data* local_buf, int dev_id, int user TagLoger::log(Log_MySqlServer, 0, "Connection ID not found for dev_id=%d, user_id=%d\n", dev_id, user_id); } + TagTimer::add("internalApi::local_send_to_user", t); return isSend; } @@ -109,6 +115,8 @@ int internalApi::local_send_to_user(thread_data* local_buf, int dev_id, int user */ int internalApi::cluster_send_to_user(thread_data* local_buf, int dev_id, int user_id, const char* pipe_event, const char* msg_data) { + auto t = TagTimer::mtime(); + local_buf->setThreadStatus('s'); char uuid[37]; bzero(uuid, 37); uuid37(uuid); @@ -145,6 +153,8 @@ int internalApi::cluster_send_to_user(thread_data* local_buf, int dev_id, int us { local_buf->stm.users_queue_insert->execute(uuid, (long int)time(NULL), dev_id, user_id, pipe_event, msg_data, strlen(msg_data)); } + + TagTimer::add("internalApi::cluster_send_to_user", t); return 0; } @@ -157,20 +167,31 @@ int internalApi::cluster_send_to_user(thread_data* local_buf, int dev_id, int us * @return */ int internalApi::send_event_to_pipe(thread_data* local_buf, const char* pipe_name, const char* msg_data, int dev_id, const char* server_data) -{ - - CP pipe = devManager::instance()->getDevInfo(dev_id)->findPipe(std::string(pipe_name)); - +{ + auto t = TagTimer::mtime(); + + local_buf->setThreadStatus('P'); + + auto dinfo = devManager::instance()->getDevInfo(dev_id); + + local_buf->setThreadStatus('8'); + + CP pipe = dinfo->findPipe(std::string(pipe_name)); + + local_buf->setThreadStatus('7'); + if(pipe.isNULL()) { // internal server error TagLoger::log(Log_Any, 0, "pipe[%s] == NULL\n",pipe_name); + TagTimer::add("internalApi::send_event_to_pipe", t); return 0; } else if(pipe->empty() ) { // internal server error TagLoger::log(Log_Any, 0, "pipe[%s] == empty\n",pipe_name); + TagTimer::add("internalApi::send_event_to_pipe", t); return 0; } @@ -198,5 +219,6 @@ int internalApi::send_event_to_pipe(thread_data* local_buf, const char* pipe_nam it = it->Next(); } + TagTimer::add("internalApi::send_event_to_pipe", t); return num_msg; } diff --git a/src/lex.yy.c b/src/lex.yy.c index afc6185..f7dd8b1 100644 --- a/src/lex.yy.c +++ b/src/lex.yy.c @@ -7,8 +7,8 @@ #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 5 -#define YY_FLEX_SUBMINOR_VERSION 39 +#define YY_FLEX_MINOR_VERSION 6 +#define YY_FLEX_SUBMINOR_VERSION 0 #if YY_FLEX_SUBMINOR_VERSION > 0 #define FLEX_BETA #endif @@ -210,7 +210,7 @@ struct yy_buffer_state /* Number of characters read into yy_ch_buf, not including EOB * characters. */ - yy_size_t yy_n_chars; + int yy_n_chars; /* Whether we "own" the buffer - i.e., we know we created it, * and can realloc() it to grow it, and should free() it to @@ -280,7 +280,7 @@ static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ /* yy_hold_char holds the character lost when yytext is formed. */ static char yy_hold_char; -static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */ +static int yy_n_chars; /* number of characters read into yy_ch_buf */ yy_size_t yyleng; /* Points to current character in buffer. */ @@ -352,11 +352,17 @@ extern int yylineno; int yylineno = 1; extern char *yytext; +#ifdef yytext_ptr +#undef yytext_ptr +#endif #define yytext_ptr yytext static yy_state_type yy_get_previous_state (void ); static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); static int yy_get_next_buffer (void ); +#if defined(__GNUC__) && __GNUC__ >= 3 +__attribute__((__noreturn__)) +#endif static void yy_fatal_error (yyconst char msg[] ); /* Done after the current pattern has been matched and before the @@ -405,7 +411,7 @@ static yyconst flex_int16_t yy_accept[204] = 0, 41, 0 } ; -static yyconst flex_int32_t yy_ec[256] = +static yyconst YY_CHAR yy_ec[256] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -437,7 +443,7 @@ static yyconst flex_int32_t yy_ec[256] = 1, 1, 1, 1, 1 } ; -static yyconst flex_int32_t yy_meta[61] = +static yyconst YY_CHAR yy_meta[61] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, @@ -447,7 +453,7 @@ static yyconst flex_int32_t yy_meta[61] = 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 } ; -static yyconst flex_int16_t yy_base[220] = +static yyconst flex_uint16_t yy_base[220] = { 0, 0, 0, 443, 712, 60, 98, 712, 712, 712, 712, 433, 712, 712, 712, 428, 86, 429, 66, 73, 110, @@ -503,7 +509,7 @@ static yyconst flex_int16_t yy_def[220] = 203, 203, 203, 203, 203, 203, 203, 203, 203 } ; -static yyconst flex_int16_t yy_nxt[773] = +static yyconst flex_uint16_t yy_nxt[773] = { 0, 4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 17, 20, 21, @@ -708,7 +714,7 @@ char *yytext; * Слово sync будет требоватся в тех случаях если надо получить в ответе точное количество затронутых строк * async режим по умолчанию в ответ возвращает нижнею границу количества затронутых строк. Так как на других серверах это значение ещё не расчитано из за асинхронной работы команд. */ -#line 712 "lex.yy.c" +#line 718 "lex.yy.c" #define INITIAL 0 @@ -741,11 +747,11 @@ void yyset_extra (YY_EXTRA_TYPE user_defined ); FILE *yyget_in (void ); -void yyset_in (FILE * in_str ); +void yyset_in (FILE * _in_str ); FILE *yyget_out (void ); -void yyset_out (FILE * out_str ); +void yyset_out (FILE * _out_str ); yy_size_t yyget_leng (void ); @@ -753,7 +759,7 @@ char *yyget_text (void ); int yyget_lineno (void ); -void yyset_lineno (int line_number ); +void yyset_lineno (int _line_number ); /* Macros after this point can all be overridden by user definitions in * section 1. @@ -767,8 +773,12 @@ extern int yywrap (void ); #endif #endif +#ifndef YY_NO_UNPUT + static void yyunput (int c,char *buf_ptr ); +#endif + #ifndef yytext_ptr static void yy_flex_strncpy (char *,yyconst char *,int ); #endif @@ -881,7 +891,7 @@ extern int yylex (void); /* Code executed at the end of each rule. */ #ifndef YY_BREAK -#define YY_BREAK break; +#define YY_BREAK /*LINTED*/break; #endif #define YY_RULE_SETUP \ @@ -891,9 +901,9 @@ extern int yylex (void); */ YY_DECL { - register yy_state_type yy_current_state; - register char *yy_cp, *yy_bp; - register int yy_act; + yy_state_type yy_current_state; + char *yy_cp, *yy_bp; + int yy_act; if ( !(yy_init) ) { @@ -924,9 +934,9 @@ YY_DECL { #line 15 "src/CometQL.l" -#line 928 "lex.yy.c" +#line 938 "lex.yy.c" - while ( 1 ) /* loops until end-of-file is reached */ + while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ { yy_cp = (yy_c_buf_p); @@ -942,7 +952,7 @@ YY_DECL yy_match: do { - register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; + YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; if ( yy_accept[yy_current_state] ) { (yy_last_accepting_state) = yy_current_state; @@ -1248,7 +1258,7 @@ YY_RULE_SETUP #line 68 "src/CometQL.l" ECHO; YY_BREAK -#line 1252 "lex.yy.c" +#line 1262 "lex.yy.c" case YY_STATE_EOF(INITIAL): yyterminate(); @@ -1391,9 +1401,9 @@ case YY_STATE_EOF(INITIAL): */ static int yy_get_next_buffer (void) { - register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - register char *source = (yytext_ptr); - register int number_to_move, i; + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + char *source = (yytext_ptr); + yy_size_t number_to_move, i; int ret_val; if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) @@ -1422,7 +1432,7 @@ static int yy_get_next_buffer (void) /* Try to read more data. */ /* First move last chars to start of buffer. */ - number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; + number_to_move = (yy_size_t) ((yy_c_buf_p) - (yytext_ptr)) - 1; for ( i = 0; i < number_to_move; ++i ) *(dest++) = *(source++); @@ -1504,9 +1514,9 @@ static int yy_get_next_buffer (void) else ret_val = EOB_ACT_CONTINUE_SCAN; - if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + if ((int) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { /* Extend the array by 50%, plus the number we really need. */ - yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); @@ -1525,14 +1535,14 @@ static int yy_get_next_buffer (void) static yy_state_type yy_get_previous_state (void) { - register yy_state_type yy_current_state; - register char *yy_cp; + yy_state_type yy_current_state; + char *yy_cp; yy_current_state = (yy_start); for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) { - register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); if ( yy_accept[yy_current_state] ) { (yy_last_accepting_state) = yy_current_state; @@ -1557,10 +1567,10 @@ static int yy_get_next_buffer (void) */ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) { - register int yy_is_jam; - register char *yy_cp = (yy_c_buf_p); + int yy_is_jam; + char *yy_cp = (yy_c_buf_p); - register YY_CHAR yy_c = 1; + YY_CHAR yy_c = 1; if ( yy_accept[yy_current_state] ) { (yy_last_accepting_state) = yy_current_state; @@ -1578,9 +1588,11 @@ static int yy_get_next_buffer (void) return yy_is_jam ? 0 : yy_current_state; } - static void yyunput (int c, register char * yy_bp ) +#ifndef YY_NO_UNPUT + + static void yyunput (int c, char * yy_bp ) { - register char *yy_cp; + char *yy_cp; yy_cp = (yy_c_buf_p); @@ -1590,10 +1602,10 @@ static int yy_get_next_buffer (void) if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) { /* need to shift things up to make room */ /* +2 for EOB chars. */ - register yy_size_t number_to_move = (yy_n_chars) + 2; - register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ + yy_size_t number_to_move = (yy_n_chars) + 2; + char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; - register char *source = + char *source = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) @@ -1615,6 +1627,8 @@ static int yy_get_next_buffer (void) (yy_c_buf_p) = yy_cp; } +#endif + #ifndef YY_NO_INPUT #ifdef __cplusplus static int yyinput (void) @@ -1764,7 +1778,7 @@ static void yy_load_buffer_state (void) if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - b->yy_buf_size = size; + b->yy_buf_size = (yy_size_t)size; /* yy_ch_buf has to be 2 characters longer than the size given because * we need to put in 2 end-of-buffer characters. @@ -1919,7 +1933,7 @@ static void yyensure_buffer_stack (void) * scanner will even need a stack. We use 2 instead of 1 to avoid an * immediate realloc on the next call. */ - num_to_alloc = 1; + num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc (num_to_alloc * sizeof(struct yy_buffer_state*) ); @@ -1936,7 +1950,7 @@ static void yyensure_buffer_stack (void) if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ /* Increase the buffer to prepare for a possible push. */ - int grow_size = 8 /* arbitrary grow size */; + yy_size_t grow_size = 8 /* arbitrary grow size */; num_to_alloc = (yy_buffer_stack_max) + grow_size; (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc @@ -2044,7 +2058,7 @@ YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len static void yy_fatal_error (yyconst char* msg ) { - (void) fprintf( stderr, "%s\n", msg ); + (void) fprintf( stderr, "%s\n", msg ); exit( YY_EXIT_FAILURE ); } @@ -2110,29 +2124,29 @@ char *yyget_text (void) } /** Set the current line number. - * @param line_number + * @param _line_number line number * */ -void yyset_lineno (int line_number ) +void yyset_lineno (int _line_number ) { - yylineno = line_number; + yylineno = _line_number; } /** Set the input stream. This does not discard the current * input buffer. - * @param in_str A readable stream. + * @param _in_str A readable stream. * * @see yy_switch_to_buffer */ -void yyset_in (FILE * in_str ) +void yyset_in (FILE * _in_str ) { - yyin = in_str ; + yyin = _in_str ; } -void yyset_out (FILE * out_str ) +void yyset_out (FILE * _out_str ) { - yyout = out_str ; + yyout = _out_str ; } int yyget_debug (void) @@ -2140,9 +2154,9 @@ int yyget_debug (void) return yy_flex_debug; } -void yyset_debug (int bdebug ) +void yyset_debug (int _bdebug ) { - yy_flex_debug = bdebug ; + yy_flex_debug = _bdebug ; } static int yy_init_globals (void) @@ -2202,7 +2216,8 @@ int yylex_destroy (void) #ifndef yytext_ptr static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) { - register int i; + + int i; for ( i = 0; i < n; ++i ) s1[i] = s2[i]; } @@ -2211,7 +2226,7 @@ static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) #ifdef YY_NEED_STRLEN static int yy_flex_strlen (yyconst char * s ) { - register int n; + int n; for ( n = 0; s[n]; ++n ) ; @@ -2221,11 +2236,12 @@ static int yy_flex_strlen (yyconst char * s ) void *yyalloc (yy_size_t size ) { - return (void *) malloc( size ); + return (void *) malloc( size ); } void *yyrealloc (void * ptr, yy_size_t size ) { + /* The cast to (char *) in the following accommodates both * implementations that use char* generic pointers, and those * that use void* generic pointers. It works with the latter @@ -2238,11 +2254,11 @@ void *yyrealloc (void * ptr, yy_size_t size ) void yyfree (void * ptr ) { - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ } #define YYTABLES_NAME "yytables" -#line 67 "src/CometQL.l" +#line 68 "src/CometQL.l" diff --git a/src/main.cpp b/src/main.cpp index 220d4ae..d4765a5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -338,6 +338,8 @@ void command_line_fork() #include +#include "jwt/jwt_all.h" +using json = nlohmann::json; /** * valgrind --tool=memcheck --track-origins=yes --leak-check=yes ./cpp_comet * valgrind --tool=memcheck --track-origins=yes --leak-check=full --show-reachable=yes ./cpp_comet @@ -350,9 +352,35 @@ void command_line_fork() * @return */ int main(int argc, char *argv[]) -{ - TagTimer::start(Time_start); - +{ + // + //secret=OTRpassfs4V9b5ptNtOTKIH93lED05es41, + //token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxNjM0NTY3ODkwIiwidXNlcl9pZCI6NX0.B4P8ONwZZPtb4Zb9zNmV9fdF0WjqxfQy19l4LjK_qtU +/* + ExpValidator exp; + HS256Validator signer("OTRpassfs4V9b5ptNtOTKIH93lED05es41"); + + // Now let's use these validators to parse and verify the token we created + // in the previous example + std::string str_token = + "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNSIsImV4cCI6MTY4MzIyODgwMH0.xYfZWh6HmBs88Bb07QxdaM4r59IgqNjPJjr_BJx0U2k"; + try { + // Decode and validate the token + ::json header, payload; + + std::tie(header, payload) = JWT::Decode(str_token, &signer, &exp); + std::cout << "Header: " << header << std::endl; + std::cout << "Payload: " << payload << std::endl; + } catch (InvalidTokenError &tfe) { + // An invalid token + std::cout << "Validation failed: " << tfe.what() << std::endl; + } + return 0;*/ + + // @todo добавить автоматическое создание бд и таблиц если их нет в базе от которой получили логин и пароль. + // @todo добавить параметр для того чтоб можно было включать/отключать перехват и игнорирование сигнала отрыва от терминала. + + // Назначает обработчик на сигнал смерти signal(SIGSEGV, posix_death_signal); @@ -410,6 +438,8 @@ int main(int argc, char *argv[]) TagLoger::log(Log_Any, 0, "Server starting pid:%d, getrusage:%d\n", (int)getpid()); TagLoger::initTagLevels(); + + TagTimer::setStatus(appConf::instance()->get_chars("statistics", "profiler")); dbLink mydb; mydb.init(appConf::instance()->get_chars("db", "host"), @@ -466,7 +496,7 @@ int main(int argc, char *argv[]) fprintf(fp, "%d", (int)getpid()); fclose(fp); } - + while(true) { pid_t pid = fork(); @@ -523,7 +553,6 @@ int main(int argc, char *argv[]) command_line_fork(); - TagTimer::end(Time_start); pthread_exit(NULL); return 0; diff --git a/src/main.h b/src/main.h index 225bcd7..7c4fea4 100644 --- a/src/main.h +++ b/src/main.h @@ -1,4 +1,8 @@ - + + +//#define CE_VERSION + + #define MAIN_BUF_SIZE 10384 #define MAIN_PASSWORD "password" @@ -117,8 +121,8 @@ \ " -#define MYSQL_SERVERNAME "CppComet enterprise 3.35" -#define MYSQL_SYSTEMVARIBLE "CppComet enterprise 3.35 (comet-server.com, support@comet-server.com)" +#define MYSQL_SERVERNAME "CppComet enterprise 3.36" +#define MYSQL_SYSTEMVARIBLE "CppComet enterprise 3.36 (comet-server.com, support@comet-server.com)" #define maxValue( a, b ) ( (a) > (b) ? (a) : (b) ) diff --git a/src/mime_types.h b/src/mime_types.h new file mode 100644 index 0000000..18edf86 --- /dev/null +++ b/src/mime_types.h @@ -0,0 +1,272 @@ +mime_types.insert(std::pair("ai", "application/postscript")); +mime_types.insert(std::pair("aif", "audio/aiff")); +mime_types.insert(std::pair("aif", "audio/x-aiff")); +mime_types.insert(std::pair("aiff", "audio/aiff")); +mime_types.insert(std::pair("aiff", "audio/x-aiff")); +mime_types.insert(std::pair("ani", "application/x-navi-animation")); +mime_types.insert(std::pair("aos", "application/x-nokia-9000-communicator-add-on-software")); +mime_types.insert(std::pair("aps", "application/mime")); +mime_types.insert(std::pair("arc", "application/octet-stream")); +mime_types.insert(std::pair("arj", "application/arj")); +mime_types.insert(std::pair("arj", "application/octet-stream")); +mime_types.insert(std::pair("art", "image/x-jg")); +mime_types.insert(std::pair("asf", "video/x-ms-asf")); +mime_types.insert(std::pair("asm", "text/x-asm")); +mime_types.insert(std::pair("asp", "text/asp")); +mime_types.insert(std::pair("asx", "application/x-mplayer2")); +mime_types.insert(std::pair("asx", "video/x-ms-asf")); +mime_types.insert(std::pair("asx", "video/x-ms-asf-plugin")); +mime_types.insert(std::pair("au", "audio/basic")); +mime_types.insert(std::pair("au", "audio/x-au")); +mime_types.insert(std::pair("avi", "application/x-troff-msvideo")); +mime_types.insert(std::pair("avi", "video/avi")); +mime_types.insert(std::pair("avi", "video/msvideo")); +mime_types.insert(std::pair("avi", "video/x-msvideo")); +mime_types.insert(std::pair("bin", "application/mac-binary")); +mime_types.insert(std::pair("bin", "application/macbinary")); +mime_types.insert(std::pair("bin", "application/octet-stream")); +mime_types.insert(std::pair("bin", "application/x-binary")); +mime_types.insert(std::pair("bin", "application/x-macbinary")); +mime_types.insert(std::pair("bm", "image/bmp")); +mime_types.insert(std::pair("bmp", "image/bmp")); +mime_types.insert(std::pair("bmp", "image/x-windows-bmp")); +mime_types.insert(std::pair("boo", "application/book")); +mime_types.insert(std::pair("book", "application/book")); +mime_types.insert(std::pair("c", "text/x-c")); +mime_types.insert(std::pair("c++", "text/plain")); +mime_types.insert(std::pair("ccad", "application/clariscad")); +mime_types.insert(std::pair("class", "application/java")); +mime_types.insert(std::pair("class", "application/java-byte-code")); +mime_types.insert(std::pair("class", "application/x-java-class")); +mime_types.insert(std::pair("com", "application/octet-stream")); +mime_types.insert(std::pair("com", "text/plain")); +mime_types.insert(std::pair("conf", "text/plain")); +mime_types.insert(std::pair("cpp", "text/x-c")); +mime_types.insert(std::pair("cpt", "application/mac-compactpro")); +mime_types.insert(std::pair("cpt", "application/x-compactpro")); +mime_types.insert(std::pair("cpt", "application/x-cpt")); +mime_types.insert(std::pair("css", "application/x-pointplus")); +mime_types.insert(std::pair("css", "text/css")); +mime_types.insert(std::pair("dcr", "application/x-director")); +mime_types.insert(std::pair("def", "text/plain")); +mime_types.insert(std::pair("dif", "video/x-dv")); +mime_types.insert(std::pair("dir", "application/x-director")); +mime_types.insert(std::pair("dl", "video/dl")); +mime_types.insert(std::pair("dl", "video/x-dl")); +mime_types.insert(std::pair("doc", "application/msword")); +mime_types.insert(std::pair("dot", "application/msword")); +mime_types.insert(std::pair("drw", "application/drafting")); +mime_types.insert(std::pair("dvi", "application/x-dvi")); +mime_types.insert(std::pair("dwg", "application/acad")); +mime_types.insert(std::pair("dwg", "image/vnd.dwg")); +mime_types.insert(std::pair("dwg", "image/x-dwg")); +mime_types.insert(std::pair("dxf", "application/dxf")); +mime_types.insert(std::pair("dxf", "image/vnd.dwg")); +mime_types.insert(std::pair("dxf", "image/x-dwg")); +mime_types.insert(std::pair("dxr", "application/x-director")); +mime_types.insert(std::pair("exe", "application/octet-stream")); +mime_types.insert(std::pair("gif", "image/gif")); +mime_types.insert(std::pair("gz", "application/x-compressed")); +mime_types.insert(std::pair("gz", "application/x-gzip")); +mime_types.insert(std::pair("gzip", "application/x-gzip")); +mime_types.insert(std::pair("gzip", "multipart/x-gzip")); +mime_types.insert(std::pair("h", "text/plain")); +mime_types.insert(std::pair("h", "text/x-h")); +mime_types.insert(std::pair("hlp", "application/hlp")); +mime_types.insert(std::pair("hlp", "application/x-helpfile")); +mime_types.insert(std::pair("hlp", "application/x-winhelp")); +mime_types.insert(std::pair("htc", "text/x-component")); +mime_types.insert(std::pair("htm", "text/html")); +mime_types.insert(std::pair("html", "text/html")); +mime_types.insert(std::pair("htmls", "text/html")); +mime_types.insert(std::pair("htt", "text/webviewhtml")); +mime_types.insert(std::pair("ice", "x-conference/x-cooltalk")); +mime_types.insert(std::pair("ico", "image/x-icon")); +mime_types.insert(std::pair("inf", "application/inf")); +mime_types.insert(std::pair("jam", "audio/x-jam")); +mime_types.insert(std::pair("jav", "text/plain")); +mime_types.insert(std::pair("jav", "text/x-java-source")); +mime_types.insert(std::pair("java", "text/plain")); +mime_types.insert(std::pair("java", "text/x-java-source")); +mime_types.insert(std::pair("jcm", "application/x-java-commerce")); +mime_types.insert(std::pair("jfif", "image/jpeg")); +mime_types.insert(std::pair("jfif", "image/pjpeg")); +mime_types.insert(std::pair("jfif-tbnl", "image/jpeg")); +mime_types.insert(std::pair("jpe", "image/jpeg")); +mime_types.insert(std::pair("jpe", "image/pjpeg")); +mime_types.insert(std::pair("jpeg", "image/jpeg")); +mime_types.insert(std::pair("jpeg", "image/pjpeg")); +mime_types.insert(std::pair("jpg", "image/jpeg")); +mime_types.insert(std::pair("jpg", "image/pjpeg")); +mime_types.insert(std::pair("jps", "image/x-jps")); +mime_types.insert(std::pair("js", "application/x-javascript")); +mime_types.insert(std::pair("js", "application/javascript")); +mime_types.insert(std::pair("js", "application/ecmascript")); +mime_types.insert(std::pair("js", "text/javascript")); +mime_types.insert(std::pair("js", "text/ecmascript")); +mime_types.insert(std::pair("latex", "application/x-latex")); +mime_types.insert(std::pair("lha", "application/lha")); +mime_types.insert(std::pair("lha", "application/octet-stream")); +mime_types.insert(std::pair("lha", "application/x-lha")); +mime_types.insert(std::pair("lhx", "application/octet-stream")); +mime_types.insert(std::pair("list", "text/plain")); +mime_types.insert(std::pair("lsp", "application/x-lisp")); +mime_types.insert(std::pair("lsp", "text/x-script.lisp")); +mime_types.insert(std::pair("lst", "text/plain")); +mime_types.insert(std::pair("lzh", "application/octet-stream")); +mime_types.insert(std::pair("lzh", "application/x-lzh")); +mime_types.insert(std::pair("lzx", "application/lzx")); +mime_types.insert(std::pair("lzx", "application/octet-stream")); +mime_types.insert(std::pair("lzx", "application/x-lzx")); +mime_types.insert(std::pair("m3u", "audio/x-mpequrl")); +mime_types.insert(std::pair("man", "application/x-troff-man")); +mime_types.insert(std::pair("mid", "application/x-midi")); +mime_types.insert(std::pair("mid", "audio/midi")); +mime_types.insert(std::pair("mid", "audio/x-mid")); +mime_types.insert(std::pair("mid", "audio/x-midi")); +mime_types.insert(std::pair("mid", "music/crescendo")); +mime_types.insert(std::pair("mid", "x-music/x-midi")); +mime_types.insert(std::pair("midi", "application/x-midi")); +mime_types.insert(std::pair("midi", "audio/midi")); +mime_types.insert(std::pair("midi", "audio/x-mid")); +mime_types.insert(std::pair("midi", "audio/x-midi")); +mime_types.insert(std::pair("midi", "music/crescendo")); +mime_types.insert(std::pair("midi", "x-music/x-midi")); +mime_types.insert(std::pair("mod", "audio/mod")); +mime_types.insert(std::pair("mod", "audio/x-mod")); +mime_types.insert(std::pair("mov", "video/quicktime")); +mime_types.insert(std::pair("movie", "video/x-sgi-movie")); +mime_types.insert(std::pair("mp2", "audio/mpeg")); +mime_types.insert(std::pair("mp2", "audio/x-mpeg")); +mime_types.insert(std::pair("mp2", "video/mpeg")); +mime_types.insert(std::pair("mp2", "video/x-mpeg")); +mime_types.insert(std::pair("mp2", "video/x-mpeq2a")); +mime_types.insert(std::pair("mp3", "audio/mpeg3")); +mime_types.insert(std::pair("mp3", "audio/x-mpeg-3")); +mime_types.insert(std::pair("mp3", "video/mpeg")); +mime_types.insert(std::pair("mp3", "video/x-mpeg")); +mime_types.insert(std::pair("mp4", "video/mp4")); +mime_types.insert(std::pair("mpa", "audio/mpeg")); +mime_types.insert(std::pair("mpa", "video/mpeg")); +mime_types.insert(std::pair("mpeg", "video/mpeg")); +mime_types.insert(std::pair("mpg", "audio/mpeg")); +mime_types.insert(std::pair("mpg", "video/mpeg")); +mime_types.insert(std::pair("mpga", "audio/mpeg")); +mime_types.insert(std::pair("pas", "text/pascal")); +mime_types.insert(std::pair("pcl", "application/vnd.hp-pcl")); +mime_types.insert(std::pair("pcl", "application/x-pcl")); +mime_types.insert(std::pair("pct", "image/x-pict")); +mime_types.insert(std::pair("pcx", "image/x-pcx")); +mime_types.insert(std::pair("pdf", "application/pdf")); +mime_types.insert(std::pair("pic", "image/pict")); +mime_types.insert(std::pair("pict", "image/pict")); +mime_types.insert(std::pair("pl", "text/plain")); +mime_types.insert(std::pair("pl", "text/x-script.perl")); +mime_types.insert(std::pair("pm", "image/x-xpixmap")); +mime_types.insert(std::pair("pm", "text/x-script.perl-module")); +mime_types.insert(std::pair("pm4", "application/x-pagemaker")); +mime_types.insert(std::pair("pm5", "application/x-pagemaker")); +mime_types.insert(std::pair("png", "image/png")); +mime_types.insert(std::pair("pot", "application/mspowerpoint")); +mime_types.insert(std::pair("pot", "application/vnd.ms-powerpoint")); +mime_types.insert(std::pair("ppa", "application/vnd.ms-powerpoint")); +mime_types.insert(std::pair("pps", "application/mspowerpoint")); +mime_types.insert(std::pair("pps", "application/vnd.ms-powerpoint")); +mime_types.insert(std::pair("ppt", "application/mspowerpoint")); +mime_types.insert(std::pair("ppt", "application/powerpoint")); +mime_types.insert(std::pair("ppt", "application/vnd.ms-powerpoint")); +mime_types.insert(std::pair("ppt", "application/x-mspowerpoint")); +mime_types.insert(std::pair("ppz", "application/mspowerpoint")); +mime_types.insert(std::pair("ps", "application/postscript")); +mime_types.insert(std::pair("psd", "application/octet-stream")); +mime_types.insert(std::pair("pwz", "application/vnd.ms-powerpoint")); +mime_types.insert(std::pair("py", "text/x-script.phyton")); +mime_types.insert(std::pair("pyc", "applicaiton/x-bytecode.python")); +mime_types.insert(std::pair("qt", "video/quicktime")); +mime_types.insert(std::pair("qtif", "image/x-quicktime")); +mime_types.insert(std::pair("ra", "audio/x-pn-realaudio")); +mime_types.insert(std::pair("ra", "audio/x-pn-realaudio-plugin")); +mime_types.insert(std::pair("ra", "audio/x-realaudio")); +mime_types.insert(std::pair("ram", "audio/x-pn-realaudio")); +mime_types.insert(std::pair("rm", "application/vnd.rn-realmedia")); +mime_types.insert(std::pair("rm", "audio/x-pn-realaudio")); +mime_types.insert(std::pair("rpm", "audio/x-pn-realaudio-plugin")); +mime_types.insert(std::pair("rtf", "application/rtf")); +mime_types.insert(std::pair("rtf", "application/x-rtf")); +mime_types.insert(std::pair("rtf", "text/richtext")); +mime_types.insert(std::pair("rtx", "application/rtf")); +mime_types.insert(std::pair("rtx", "text/richtext")); +mime_types.insert(std::pair("rv", "video/vnd.rn-realvideo")); +mime_types.insert(std::pair("sgml", "text/sgml")); +mime_types.insert(std::pair("sgml", "text/x-sgml")); +mime_types.insert(std::pair("sh", "application/x-bsh")); +mime_types.insert(std::pair("sh", "application/x-sh")); +mime_types.insert(std::pair("sh", "application/x-shar")); +mime_types.insert(std::pair("sh", "text/x-script.sh")); +mime_types.insert(std::pair("shtml", "text/html")); +mime_types.insert(std::pair("shtml", "text/x-server-parsed-html")); +mime_types.insert(std::pair("ssi", "text/x-server-parsed-html")); +mime_types.insert(std::pair("tar", "application/x-tar")); +mime_types.insert(std::pair("tcl", "application/x-tcl")); +mime_types.insert(std::pair("tcl", "text/x-script.tcl")); +mime_types.insert(std::pair("text", "application/plain")); +mime_types.insert(std::pair("text", "text/plain")); +mime_types.insert(std::pair("tgz", "application/gnutar")); +mime_types.insert(std::pair("tgz", "application/x-compressed")); +mime_types.insert(std::pair("tif", "image/tiff")); +mime_types.insert(std::pair("tif", "image/x-tiff")); +mime_types.insert(std::pair("tiff", "image/tiff")); +mime_types.insert(std::pair("tiff", "image/x-tiff")); +mime_types.insert(std::pair("txt", "text/plain")); +mime_types.insert(std::pair("uri", "text/uri-list")); +mime_types.insert(std::pair("vcd", "application/x-cdlink")); +mime_types.insert(std::pair("vmd", "application/vocaltec-media-desc")); +mime_types.insert(std::pair("vrml", "application/x-vrml")); +mime_types.insert(std::pair("vrml", "model/vrml")); +mime_types.insert(std::pair("vrml", "x-world/x-vrml")); +mime_types.insert(std::pair("vsd", "application/x-visio")); +mime_types.insert(std::pair("vst", "application/x-visio")); +mime_types.insert(std::pair("vsw", "application/x-visio")); +mime_types.insert(std::pair("wav", "audio/wav")); +mime_types.insert(std::pair("wav", "audio/x-wav")); +mime_types.insert(std::pair("wmf", "windows/metafile")); +mime_types.insert(std::pair("xla", "application/excel")); +mime_types.insert(std::pair("xla", "application/x-excel")); +mime_types.insert(std::pair("xla", "application/x-msexcel")); +mime_types.insert(std::pair("xlb", "application/excel")); +mime_types.insert(std::pair("xlb", "application/vnd.ms-excel")); +mime_types.insert(std::pair("xlb", "application/x-excel")); +mime_types.insert(std::pair("xlc", "application/excel")); +mime_types.insert(std::pair("xlc", "application/vnd.ms-excel")); +mime_types.insert(std::pair("xlc", "application/x-excel")); +mime_types.insert(std::pair("xld", "application/excel")); +mime_types.insert(std::pair("xld", "application/x-excel")); +mime_types.insert(std::pair("xlk", "application/excel")); +mime_types.insert(std::pair("xlk", "application/x-excel")); +mime_types.insert(std::pair("xll", "application/excel")); +mime_types.insert(std::pair("xll", "application/vnd.ms-excel")); +mime_types.insert(std::pair("xll", "application/x-excel")); +mime_types.insert(std::pair("xlm", "application/excel")); +mime_types.insert(std::pair("xlm", "application/vnd.ms-excel")); +mime_types.insert(std::pair("xlm", "application/x-excel")); +mime_types.insert(std::pair("xls", "application/excel")); +mime_types.insert(std::pair("xls", "application/vnd.ms-excel")); +mime_types.insert(std::pair("xls", "application/x-excel")); +mime_types.insert(std::pair("xls", "application/x-msexcel")); +mime_types.insert(std::pair("xlt", "application/excel")); +mime_types.insert(std::pair("xlt", "application/x-excel")); +mime_types.insert(std::pair("xlv", "application/excel")); +mime_types.insert(std::pair("xlv", "application/x-excel")); +mime_types.insert(std::pair("xlw", "application/excel")); +mime_types.insert(std::pair("xlw", "application/vnd.ms-excel")); +mime_types.insert(std::pair("xlw", "application/x-excel")); +mime_types.insert(std::pair("xlw", "application/x-msexcel")); +mime_types.insert(std::pair("xm", "audio/xm")); +mime_types.insert(std::pair("xml", "application/xml")); +mime_types.insert(std::pair("xml", "text/xml")); +mime_types.insert(std::pair("z", "application/x-compress")); +mime_types.insert(std::pair("z", "application/x-compressed")); +mime_types.insert(std::pair("zip", "application/x-compressed")); +mime_types.insert(std::pair("zip", "application/x-zip-compressed")); +mime_types.insert(std::pair("zip", "application/zip")); +mime_types.insert(std::pair("zip", "multipart/x-zip")); \ No newline at end of file diff --git a/src/tcpServer.cpp b/src/tcpServer.cpp index f05c0b1..30f58a7 100644 --- a/src/tcpServer.cpp +++ b/src/tcpServer.cpp @@ -19,15 +19,15 @@ #include #include // @todo Перейти с std::map на std::unordered_map - + using namespace std; - + #ifndef TCPSERVER_CPP #define TCPSERVER_CPP - + template< class connectionType > tcpServer * tcpServer::inst = NULL; - + template< class connectionType > void * tcpServer::add_th_loop(void* arg) { @@ -36,7 +36,7 @@ void * tcpServer::add_th_loop(void* arg) tinfo->parent_server_obj->loop(tinfo); TagLoger::debug(Log_tcpServer, 0, "\x1b[32mS%d:Terminated thread for processing messages\x1b[0m\n",tinfo->parent_server_obj->id); - + return 0; } @@ -49,7 +49,7 @@ tcpServer::tcpServer() template< class connectionType > tcpServer::tcpServer(int Epoll_size, int Epoll_timeout):epoll_size(Epoll_size),epoll_timeout(Epoll_timeout) -{ +{ bzero(&gev, sizeof(gev)); init(); } @@ -95,9 +95,9 @@ tcpServer::~tcpServer() if(th != NULL) { delete[] th; - } - - + } + + for(int i=0; i::init() } catch (std::bad_alloc& ba) { - TagLoger::error(Log_UserIndex, 0, "\x1b[31mbad_alloc caught\x1b[0m\n" ); + TagLoger::error(Log_UserIndex, 0, "\x1b[31mbad_alloc caught\x1b[0m\n" ); } request_mutex = new pthread_mutex_t[map_index_size+1]; @@ -144,7 +144,7 @@ bool tcpServer::start(const char* Host,const int Port, const cha { name = server_name; if(benchmark) bm.start(this->id,thread_num, server_name); - + #ifdef EPOL_CTL_DISABLE TagLoger::debug(Log_tcpServer, 0, "\x1b[1;33mUsing EPOL_CTL_DISABLE\x1b[0m\n"); #else @@ -198,7 +198,7 @@ bool tcpServer::start(const char* Host,const int Port, const cha // struct epoll_event ev; // watch just incoming(EPOLLIN) // and Edge Trigged(EPOLLET) events - + gev.events = EPOLLHUP | EPOLLIN | EPOLLERR | EPOLLRDHUP; // !|EPOLLET !|EPOLLRDHUP -- |EPOLLOUT | EPOLLRDNORM |EPOLLRDBAND|EPOLLWRNORM | EPOLLWRNORM | EPOLLWRBAND |EPOLLMSG |EPOLLERR|EPOLLHUP|EPOLLRDHUP|EPOLLONESHOT @@ -237,19 +237,19 @@ bool tcpServer::start(const char* Host,const int Port, const cha perror("eval"); exit(-1); } - + int yes = 1; // Устанавливает возможность запуска при ещё не освободившемя сокете, уменьшая время старта после падения. Устраняет проблему "Address Already in Use" if(setsockopt(listener, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) { printf("\x1b[1;31mCannot set SO_REUSEADDR option on listen socket (%s)\x1b[0m\n", strerror(errno)); } - + if(setsockopt(listener, IPPROTO_TCP, TCP_NODELAY, (char *) &yes, sizeof(yes)) < 0) { printf("\x1b[1;31mCannot set TCP_NODELAY option on listen socket (%s)\x1b[0m\n", strerror(errno)); } - + // bind listener to address(addr) /** * Связывает сокет с конкретным адресом @@ -277,10 +277,10 @@ bool tcpServer::start(const char* Host,const int Port, const cha * backlog — целое число, означающее число установленных соединений, которые могут быть обработаны в любой момент времени */ if(listen(listener, backlog) != 0 ) - { + { printf("\x1b[1;31mService:%s host:%s port:%d\x1b[0m\n",server_name, Host, Port); perror("eval"); - exit(-1); + exit(-1); } TagLoger::log(Log_tcpServer, 0, "Start to listen: %s\n", host); @@ -317,12 +317,12 @@ bool tcpServer::start(const char* Host,const int Port, const cha } TagLoger::log(Log_tcpServer, 0, "Main listener(%d) added to epoll\n", epfd); - + if(appConf::instance()->get_int(name, "uptimeTestInterval") > 0) { intervalLoop::instance()->add((intervalLoopObject*)this); } - + // Создаём потоки обработки соединений и сообщений th = new tcpServer_loop_data[thread_num]; for(int i=0; i::start(const char* Host,const int Port, const cha th[i].ev = gev; th[i].listener = listener; th[i].parent_server_obj=this; - + TagLoger::log(Log_tcpServer, 0, "Создаётся новый поток обработки сообщений %d\n",i); pthread_create(&th[i].th_id, NULL, add_th_loop , (void *)&th[i]); } @@ -382,25 +382,27 @@ void tcpServer::step(int uptime, thread_data* local_buf) } int maxUptime = appConf::instance()->get_int(name, "maxUptime"); - + int onlineSum = 0; // Пробегает по всем конектам и проверяет не порали отключить по истичению uptime for(int i =0; i< map_index_size; i++) { if(maxUptime > 0) { + std::list> forClose; + pthread_mutex_lock(&request_mutex[i]); - auto it = map_index[i].begin(); + auto it = map_index[i].begin(); while( it != map_index[i].end()) - { + { CP clientObj = it->second; if(!clientObj.isNULL()) { if(clientObj->getUptime() > maxUptime) { it = map_index[i].erase(it); - TagLoger::log(Log_tcpServer, 0, "S%d:tcpServer::closeClientConnection maxUptime=%d, uptime=%d\n",this->id, maxUptime, clientObj->getUptime()); - closeClientConnection(clientObj, local_buf); + TagLoger::log(Log_tcpServer, 0, "S%d:tcpServer::closeClientConnection maxUptime=%d, uptime=%d\n",this->id, maxUptime, clientObj->getUptime()); + forClose.push_back(clientObj); } else { @@ -410,13 +412,20 @@ void tcpServer::step(int uptime, thread_data* local_buf) else { it++; - } + } } pthread_mutex_unlock(&request_mutex[i]); - } + + auto itl = forClose.begin(); + while( itl != forClose.end()) + { + closeClientConnection(it->second, local_buf); + it++; + } + } onlineSum+= map_index[i].size(); - } - + } + // Правим значение колва онлайн так как сщётчик мог накопить погрешность. if(benchmark) bm.setConections(onlineSum); } @@ -446,7 +455,7 @@ void tcpServer::loop(const tcpServer_loop_data* thread_data* hm_thread_data = new thread_data(appConf::instance()); hm_thread_data->bm = &bm; hm_thread_data->thread_id = d->thread_id; - + struct epoll_event loop_ev = d->ev; struct sockaddr_in their_addr; // define ip & ports for server(addr) and incoming client ip & ports(their_addr) socklen_t socklen = sizeof(struct sockaddr_in); // size of address @@ -455,7 +464,7 @@ void tcpServer::loop(const tcpServer_loop_data* int epfd = d->epfd; int next_epfd_index = 0; - + while(1) { @@ -480,7 +489,7 @@ void tcpServer::loop(const tcpServer_loop_data* TagLoger::log(Log_tcpServer, 0, "Epoll events count: %d, thread_id=%d\n", epoll_events_count, d->thread_id); bm.add_th_count(d->thread_id,epoll_events_count); - + for(int i = 0; i < epoll_events_count ; i++) { if(TagLoger::isLog(Log_tcpServer, TAGLOG_LOG) ) @@ -511,9 +520,9 @@ void tcpServer::loop(const tcpServer_loop_data* if(events[i].events & EPOLLERR) TagLoger::log(Log_tcpServer, 0, " \x1b[1;31mEPOLLERR\x1b[0m "); if(events[i].events & EPOLLHUP) - TagLoger::log(Log_tcpServer, 0, " \x1b[1;31mEPOLLHUP\x1b[0m "); + TagLoger::log(Log_tcpServer, 0, " \x1b[1;31mEPOLLHUP\x1b[0m "); } - + if(events[i].events & EPOLLERR ) { TagLoger::log(Log_tcpServer, 0, " \x1b[32mdeleteClient EPOLLERR\x1b[0m\n"); @@ -554,7 +563,7 @@ void tcpServer::loop(const tcpServer_loop_data* if(client_id < 0 ) { perror("Could not connect in accept in server loop"); - TagLoger::error(Log_tcpServer, 0, "\x1b[31mS%d:Could not connect %d (errno=%d)\x1b[0m",this->id, client_id, errno); + TagLoger::error(Log_tcpServer, 0, "\x1b[31mS%d:Could not connect %d (errno=%d)\x1b[0m",this->id, client_id, errno); continue; } @@ -565,11 +574,11 @@ void tcpServer::loop(const tcpServer_loop_data* close(client_id); continue; }*/ - + try{ - CP clientObj; + CP clientObj; clientObj->event.events = EPOLLIN | EPOLLERR | EPOLLHUP | EPOLLRDHUP; // events[i].events; - clientObj->event.data.fd = client_id; + clientObj->event.data.fd = client_id; clientObj->event.data.ptr = (void*)clientObj.get(); // Решает в какой из потоков обработки сообщений добавить соединение, раскидывает каждому потоку поровну входящих соединений @@ -580,27 +589,31 @@ void tcpServer::loop(const tcpServer_loop_data* else { next_epfd_index = 1; - } + } int c_epfd = th[next_epfd_index].epfd; - //addClient(client_id, client_id, hm_thread_data, c_epfd); + //addClient(client_id, client_id, hm_thread_data, c_epfd); TagLoger::debug(Log_tcpServer, 0, "S%d:A new client is created %d=%d...",this->id,client_id,clientObj->event.data.fd); - clientObj->setIp(inet_ntoa(their_addr.sin_addr)); + clientObj->setIp(inet_ntoa(their_addr.sin_addr)); clientObj->setEpfd(c_epfd); clientObj->setfd(client_id); - + // Выполняется в контексте потока приёма входящих сообщений - clientObj->set_online(hm_thread_data); + clientObj->set_online(hm_thread_data); + + bm.set_th_status(d->thread_id,'2'); // Вставка объекта соединения в std::map чтоб объект можно было найти по его client_id - pthread_mutex_lock(&request_mutex[client_id%map_index_size]); - getMapToUserId(client_id).insert(std::pair>(client_id, clientObj)); - pthread_mutex_unlock(&request_mutex[client_id%map_index_size]); + map_index_lock(client_id); + getMapToUserId(client_id).insert(std::pair>(client_id, clientObj)); + map_index_unlock(client_id); + + bm.set_th_status(d->thread_id,'3'); if(benchmark) bm.increment_addClient(); - TagLoger::log(Log_tcpServer, 0, "th(%d) epoll_ctl(c_epfd:%d, next_epfd_index:%d)\n",d->thread_id, c_epfd, next_epfd_index); + TagLoger::log(Log_tcpServer, 0, "th(%d) epoll_ctl(c_epfd:%d, next_epfd_index:%d)\n",d->thread_id, c_epfd, next_epfd_index); if(epoll_ctl(c_epfd, EPOLL_CTL_ADD, client_id, &clientObj->event) != 0) { perror("Add new client to epoll - faile"); @@ -613,7 +626,7 @@ void tcpServer::loop(const tcpServer_loop_data* close(client_id); TagLoger::warn(Log_tcpServer, 0, "S%d:Fail in establish new connection"); continue; - } + } } else { @@ -632,6 +645,18 @@ void tcpServer::loop(const tcpServer_loop_data* delete[] events; } +template< class connectionType > +int tcpServer::map_index_lock(int client_id) +{ + return pthread_mutex_lock(&request_mutex[client_id%map_index_size]); +} + +template< class connectionType > +int tcpServer::map_index_unlock(int client_id) +{ + return pthread_mutex_unlock(&request_mutex[client_id%map_index_size]); +} + /** * Удаляет соединение из epoll */ @@ -646,19 +671,21 @@ int tcpServer::epoll_detached(int fd, int epfd) return epoll_ctl ( epfd, EPOLL_CTL_DEL, fd, &gev ); #endif } - + /** * Удаляет соединение из std::map> * Таким образом если ссылок кроме как в std::map не останется то объект будет реально удалён из памяти * @param client_id * @param local_buf - * + * */ template< class connectionType > void tcpServer::deleteClientFromMap(CP clientObj) -{ - TagLoger::log(Log_tcpServer, 0, "S%d:tcpServer::delete-Client Epfd=%d, fd=%d\n",this->id, clientObj->getEpfd(), clientObj->getfd()); - pthread_mutex_lock(&request_mutex[clientObj->getfd()%map_index_size]); +{ + TagLoger::log(Log_tcpServer, 0, "S%d:tcpServer::delete-Client Epfd=%d, fd=%d\n",this->id, clientObj->getEpfd(), clientObj->getfd()); + + int client_id = clientObj->getfd(); + map_index_lock(client_id); auto it = getMapToUserId(clientObj->getfd()).find(clientObj->getfd()); if( it != getMapToUserId(clientObj->getfd()).end() ) @@ -670,25 +697,24 @@ void tcpServer::deleteClientFromMap(CP clientObj TagLoger::error(Log_tcpServer, 0, "\x1b[31mS%d:Could not find user %d in map_index\x1b[0m\n",this->id, clientObj->getfd()); } - pthread_mutex_unlock(&request_mutex[clientObj->getfd()%map_index_size]); + map_index_unlock(client_id); } /** * Закрывает сетевое соединение клиента. * @param client_id - * @param local_buf + * @param local_buf */ template< class connectionType > void tcpServer::closeClientConnection(CP clientObj, thread_data* local_buf) -{ - TagLoger::log(Log_tcpServer, 0, "S%d:tcpServer::closeClientConnection Epfd=%d, fd=%d\n",this->id, clientObj->getEpfd(), clientObj->getfd()); +{ + TagLoger::log(Log_tcpServer, 0, "S%d:tcpServer::closeClientConnection Epfd=%d, fd=%d\n",this->id, clientObj->getEpfd(), clientObj->getfd()); /** * Если не ошибаюсь, то после этой строчки событий от клиента в epoll не будет. * И поэтому будет можно безопасно удалить память на которую указывает events[i].data.ptr в событиях epoll */ epoll_detached(clientObj->getfd(), clientObj->getEpfd()); - - + if(clientObj->set_offline(local_buf) < 0 ) { TagLoger::error(Log_tcpServer, 0, "\x1b[31mS%d:Failed to disconnect client %d\x1b[0m\n",this->id, clientObj->getfd()); @@ -697,11 +723,11 @@ void tcpServer::closeClientConnection(CP clientO { TagLoger::debug(Log_tcpServer, 0, "S%d:Succeeded set_online false\n",this->id); } - + /** * @fixme Если начнёт утекать память то надо проверить этот момент. */ - //delete clientObj; + //delete clientObj; if(benchmark) bm.increment_deleteClient(); TagLoger::debug(Log_tcpServer, 0, "S%d:Succeeded disconnect client\n",this->id); } @@ -712,14 +738,19 @@ void tcpServer::closeClientConnection(CP clientO * Таким образом если ссылок кроме как в std::map не останется то объект будет реально удалён из памяти * @param client_id * @param local_buf - * + * */ template< class connectionType > void tcpServer::deleteClient(CP clientObj, thread_data* local_buf) -{ +{ TagLoger::debug(Log_tcpServer, 0, "S%d:call closeClientConnection from deleteClient\n",this->id); + bm.set_th_status(local_buf->thread_id, 'D'); deleteClientFromMap(clientObj); + + bm.set_th_status(local_buf->thread_id, 'C'); closeClientConnection(clientObj, local_buf); + + bm.set_th_status(local_buf->thread_id, '9'); } /** @@ -732,18 +763,23 @@ void tcpServer::deleteClient(CP clientObj, threa template< class connectionType > void tcpServer::deleteClient(int client_id, thread_data* local_buf) { - pthread_mutex_lock(&request_mutex[client_id%map_index_size]); + local_buf->setThreadStatus('4'); + + map_index_lock(client_id); auto it = getMapToUserId(client_id).find(client_id); if( it != getMapToUserId(client_id).end() ) { CP clientObj = it->second; - pthread_mutex_unlock(&request_mutex[client_id%map_index_size]); - + map_index_unlock(client_id); + + local_buf->setThreadStatus('5'); TagLoger::debug(Log_tcpServer, 0, "S%d:call deleteClient client_id=%\n",this->id, client_id); deleteClient(clientObj, local_buf); return; } - pthread_mutex_unlock(&request_mutex[client_id%map_index_size]); + + map_index_unlock(client_id); + local_buf->setThreadStatus('6'); } /** @@ -757,19 +793,19 @@ template< class connectionType > int tcpServer::handle_message(CP clientObj, int thread_id, thread_data* local_buf) { int len = 0; - + if(benchmark) bm.increment_handle_message(); local_buf->unlockAll(); int client = clientObj->getfd(); - + bm.set_th_status(thread_id, 'R'); - - + + TagLoger::log(Log_tcpServer, 0, "S%d:{thread_id:%d}Try to read from fd(%d)\n",this->id, thread_id, client); len = clientObj->web_read(local_buf); - + TagLoger::log(Log_tcpServer, 0, "S%d:{%d}clients[%d].web_read() = %d\n\n",this->id, thread_id, client, len); if(len < 0 ) @@ -779,7 +815,7 @@ template< class connectionType > deleteClient(clientObj, local_buf); } else if(len > 0) - { + { bm.set_th_status(thread_id, 'M'); // Обработка сообщения от клиента if(clientObj->request(client, len, local_buf) == -1 ) @@ -790,13 +826,13 @@ template< class connectionType > } } else - { + { bm.set_th_status(thread_id, 'D'); // zero size of len mean the client closed connection TagLoger::warn(Log_tcpServer, 0, "\x1b[32m{%d} zero size of len mean the client closed connection from %d\x1b[0m\n",thread_id, client); deleteClient(clientObj, local_buf); } - + bm.set_th_status(thread_id, 'E'); return len; } @@ -810,31 +846,31 @@ template< class connectionType > template< class connectionType > CP tcpServer::get(int client_id) { - pthread_mutex_lock(&request_mutex[client_id%map_index_size]); + map_index_lock(client_id); auto it = getMapToUserId(client_id).find(client_id); if( it != getMapToUserId(client_id).end() ) { - pthread_mutex_unlock(&request_mutex[client_id%map_index_size]); + map_index_unlock(client_id); return it->second; } - pthread_mutex_unlock(&request_mutex[client_id%map_index_size]); + map_index_unlock(client_id); return NULL; } - -#include "Client_connection.h" + +#include "Client_connection.h" #include "MySql_connection.h" #include "Freeswitch_connection.h" #include "CometQLProxy_connection.h" -template class tcpServer; +template class tcpServer; template class tcpServer; template class tcpServer; template class tcpServer; -#endif /* TCPSERVER_CPP */ +#endif /* TCPSERVER_CPP */ diff --git a/src/tcpServer.h b/src/tcpServer.h index 3b8bb0f..0432fdd 100644 --- a/src/tcpServer.h +++ b/src/tcpServer.h @@ -142,6 +142,9 @@ class tcpServer: public intervalLoopObject int map_index_size = 101; pthread_mutex_t* request_mutex; + int map_index_lock(int client_id); + int map_index_unlock(int client_id); + /** * @todo Заменить std::map на std::unordered_map так как он быстрее http://forum.vingrad.ru/topic-341520.html */ diff --git a/src/thread_data.cpp b/src/thread_data.cpp index dc4bdde..5364b51 100644 --- a/src/thread_data.cpp +++ b/src/thread_data.cpp @@ -70,6 +70,10 @@ bool fs_esl::init(std::string connectionString){ return false; } } + else if(StreamServer.compare("StreamServer") == 0) + { + StreamServer = paramValue; + } } if(WShost.empty()) diff --git a/src/thread_data.h b/src/thread_data.h index 8c0d245..d1068a7 100644 --- a/src/thread_data.h +++ b/src/thread_data.h @@ -214,6 +214,8 @@ class fs_esl{ std::string WShost; int WSport = 7443; + + std::string StreamServer; public: fs_esl(std::string Name){ @@ -224,6 +226,10 @@ class fs_esl{ return WShost; } + std::string getStreamServer(){ + return StreamServer; + } + int getWSPort(){ return WSport; } diff --git a/src/user_index.cpp b/src/user_index.cpp index 9980aea..743f056 100644 --- a/src/user_index.cpp +++ b/src/user_index.cpp @@ -13,6 +13,7 @@ time_t user_index::start_time=time(0); #include "jwt/jwt_all.h" +#include "mystring.h" using json = nlohmann::json; useritem::useritem() @@ -311,8 +312,12 @@ bool useritem::getHash(thread_data* local_buf, char* out_hash) bool useritem::testToken(thread_data* local_buf, std::string token, int dev_id, int user_id) { ExpValidator exp; - HS256Validator signer(appConf::instance()->get_chars("main", "password")); - + + std::string secret(appConf::instance()->get_chars("main", "password")); + + secret.append(std::to_string(dev_id)); + HS256Validator signer(secret); + // https://jwt.io/ // Now let's use these validators to parse and verify the token we created // in the previous example @@ -327,6 +332,7 @@ bool useritem::testToken(thread_data* local_buf, std::string token, int dev_id, if(payload["user_id"] != user_id) { + TagLoger::debug(Log_UserItem, 0, "Validation failed user_id error:jwt-user_id=%d, user_id=%d\n", (int)payload["user_id"], user_id); return false; } @@ -334,16 +340,23 @@ bool useritem::testToken(thread_data* local_buf, std::string token, int dev_id, if(local_buf->stm.revoked_tokens_select->fetch()) { // Токен не найден среди отозванных + TagLoger::debug(Log_UserItem, 0, "Validation ok:[secret=%s, token=%s]\n", secret.data(), token.data()); local_buf->stm.revoked_tokens_select->free(); return true; } + TagLoger::debug(Log_UserItem, 0, "Validation failed revoked_tokens:[secret=%s, token=%s]\n", secret.data(), token.data()); local_buf->stm.revoked_tokens_select->free(); return false; } catch (InvalidTokenError &tfe) { // An invalid token - TagLoger::debug(Log_UserItem, 0, "Validation failed: %s\n", tfe.what()); + TagLoger::debug(Log_UserItem, 0, "Validation failed: %s [secret=%s, token=%s]\n", tfe.what(), secret.data(), token.data()); + } + catch(...) + { + // handling for exceptions with any type + TagLoger::debug(Log_UserItem, 0, "Validation failed: secret=%s, token=%s\n", secret.data(), token.data()); } return false; @@ -377,7 +390,7 @@ bool useritem::testHash(thread_data* local_buf, std::string Hash) * @param local_buf * @param Hash * @param user_id - * @param dev_id + * @param dev_id * @return */ bool useritem::testHash(thread_data* local_buf, std::string Hash, unsigned int user_id, int dev_id) @@ -388,7 +401,18 @@ bool useritem::testHash(thread_data* local_buf, std::string Hash, unsigned int u // Если токен верен но хеша авторизации нет то установим значение токена в качестве хеша авторизации if(!getHash(local_buf, user_id, dev_id, NULL)) { - local_buf->stm.users_auth_replace->execute(dev_id, user_id, Hash.data()); + char uuidHash[38]; + bzero(uuidHash, 38); + uuid37(uuidHash); + for(int i = 0; i<38; i++) + { + if(uuidHash[i] == '-') + { + uuidHash[i] = '0'; + } + } + + local_buf->stm.users_auth_replace->execute(dev_id, user_id, uuidHash); } return true; } @@ -406,6 +430,7 @@ bool useritem::testHash(thread_data* local_buf, std::string Hash, unsigned int u return true; } + local_buf->stm.users_auth_select->free(); return false; } diff --git a/src/user_index.h b/src/user_index.h index 79b2054..a78931b 100644 --- a/src/user_index.h +++ b/src/user_index.h @@ -523,6 +523,7 @@ class user_index return false; } + local_buf->setThreadStatus('u'); pthread_mutex_lock(&request_mutex[user_id%map_index_size]); std::map::const_iterator it = getMapToUserId(user_id).find(user_id); if( it != getMapToUserId(user_id).end() ) diff --git a/src/y.tab.c b/src/y.tab.c index bc016e6..d5b3a76 100644 --- a/src/y.tab.c +++ b/src/y.tab.c @@ -1,8 +1,8 @@ -/* A Bison parser, made by GNU Bison 3.0.2. */ +/* A Bison parser, made by GNU Bison 3.0.4. */ /* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc. 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 @@ -44,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "3.0.2" +#define YYBISON_VERSION "3.0.4" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -305,7 +305,7 @@ extern int yydebug; /* Value type. */ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED -typedef union YYSTYPE YYSTYPE; + union YYSTYPE { #line 115 "src/CometQL.y" /* yacc.c:355 */ @@ -318,6 +318,8 @@ union YYSTYPE #line 320 "y.tab.c" /* yacc.c:355 */ }; + +typedef union YYSTYPE YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_DECLARED 1 #endif @@ -331,7 +333,7 @@ int yyparse (void* qInfo); /* Copy the second part of user declarations. */ -#line 335 "y.tab.c" /* yacc.c:358 */ +#line 337 "y.tab.c" /* yacc.c:358 */ #ifdef short # undef short @@ -1510,7 +1512,7 @@ yyparse (void* qInfo) setTokValue(qData, qData->arg_set.value, (yyvsp[0].tokStruct)); //printf("\tСписок баз данных\n"); } -#line 1514 "y.tab.c" /* yacc.c:1646 */ +#line 1516 "y.tab.c" /* yacc.c:1646 */ break; case 10: @@ -1521,7 +1523,7 @@ yyparse (void* qInfo) setTokValue(qData, qData->arg_set.varible, (yyvsp[-1].tokStruct)); setTokValue(qData, qData->arg_set.value, (yyvsp[0].tokStruct)); } -#line 1525 "y.tab.c" /* yacc.c:1646 */ +#line 1527 "y.tab.c" /* yacc.c:1646 */ break; case 11: @@ -1533,7 +1535,7 @@ yyparse (void* qInfo) setTokValue(qData, qData->arg_set.varible, (yyvsp[-1].tokStruct)); setTokValue(qData, qData->arg_set.value, (yyvsp[0].tokStruct)); } -#line 1537 "y.tab.c" /* yacc.c:1646 */ +#line 1539 "y.tab.c" /* yacc.c:1646 */ break; case 12: @@ -1544,7 +1546,7 @@ yyparse (void* qInfo) qData->arg_show.command = TOK_DATABASES; //printf("\tСписок баз данных\n"); } -#line 1548 "y.tab.c" /* yacc.c:1646 */ +#line 1550 "y.tab.c" /* yacc.c:1646 */ break; case 13: @@ -1555,7 +1557,7 @@ yyparse (void* qInfo) qData->arg_show.command = TOK_PROCESSLIST; //printf("\tСписок потоков\n"); } -#line 1559 "y.tab.c" /* yacc.c:1646 */ +#line 1561 "y.tab.c" /* yacc.c:1646 */ break; case 14: @@ -1566,7 +1568,7 @@ yyparse (void* qInfo) qData->arg_show.command = TOK_TABLES; //printf("\tСписок таблиц\n"); } -#line 1570 "y.tab.c" /* yacc.c:1646 */ +#line 1572 "y.tab.c" /* yacc.c:1646 */ break; case 15: @@ -1578,7 +1580,7 @@ yyparse (void* qInfo) //printf("\tСписок таблиц\n"); } -#line 1582 "y.tab.c" /* yacc.c:1646 */ +#line 1584 "y.tab.c" /* yacc.c:1646 */ break; case 16: @@ -1589,7 +1591,7 @@ yyparse (void* qInfo) qData->arg_show.command = TOK_STATUS; //printf("\tСтатус системы\n"); } -#line 1593 "y.tab.c" /* yacc.c:1646 */ +#line 1595 "y.tab.c" /* yacc.c:1646 */ break; case 17: @@ -1601,7 +1603,7 @@ yyparse (void* qInfo) qData->arg_show.command = TOK_COLUMNS; //printf("\tСписок колонок\n"); } -#line 1605 "y.tab.c" /* yacc.c:1646 */ +#line 1607 "y.tab.c" /* yacc.c:1646 */ break; case 18: @@ -1613,7 +1615,7 @@ yyparse (void* qInfo) qData->arg_show.command = TOK_COLUMNS; //printf("\tСписок колонок\n"); } -#line 1617 "y.tab.c" /* yacc.c:1646 */ +#line 1619 "y.tab.c" /* yacc.c:1646 */ break; case 19: @@ -1626,7 +1628,7 @@ yyparse (void* qInfo) setTokValue(qData, qData->arg_show.like, (yyvsp[0].tokStruct)); //printf("\tПоказать переменные\n"); } -#line 1630 "y.tab.c" /* yacc.c:1646 */ +#line 1632 "y.tab.c" /* yacc.c:1646 */ break; case 23: @@ -1635,7 +1637,7 @@ yyparse (void* qInfo) setQData; qData->arg_show.flag = FLAG_GLOBAL; } -#line 1639 "y.tab.c" /* yacc.c:1646 */ +#line 1641 "y.tab.c" /* yacc.c:1646 */ break; case 24: @@ -1644,7 +1646,7 @@ yyparse (void* qInfo) setQData; qData->arg_show.flag = FLAG_SESSION; } -#line 1648 "y.tab.c" /* yacc.c:1646 */ +#line 1650 "y.tab.c" /* yacc.c:1646 */ break; case 25: @@ -1653,7 +1655,7 @@ yyparse (void* qInfo) setQData; qData->arg_show.flag = FLAG_FILESYSTEM; } -#line 1657 "y.tab.c" /* yacc.c:1646 */ +#line 1659 "y.tab.c" /* yacc.c:1646 */ break; case 26: @@ -1662,7 +1664,7 @@ yyparse (void* qInfo) setQData; qData->arg_show.flag = FLAG_RAM; } -#line 1666 "y.tab.c" /* yacc.c:1646 */ +#line 1668 "y.tab.c" /* yacc.c:1646 */ break; case 27: @@ -1671,7 +1673,7 @@ yyparse (void* qInfo) setQData; qData->arg_show.flag = FLAG_AVG; } -#line 1675 "y.tab.c" /* yacc.c:1646 */ +#line 1677 "y.tab.c" /* yacc.c:1646 */ break; case 28: @@ -1680,7 +1682,7 @@ yyparse (void* qInfo) setQData; qData->arg_show.flag = FLAG_UPTIME; } -#line 1684 "y.tab.c" /* yacc.c:1646 */ +#line 1686 "y.tab.c" /* yacc.c:1646 */ break; case 30: @@ -1689,7 +1691,7 @@ yyparse (void* qInfo) setQData; qData->arg_show.flag = FLAG_FULL; } -#line 1693 "y.tab.c" /* yacc.c:1646 */ +#line 1695 "y.tab.c" /* yacc.c:1646 */ break; case 31: @@ -1702,7 +1704,7 @@ yyparse (void* qInfo) //printf("\tВыборка %s\n", $2.text); } -#line 1706 "y.tab.c" /* yacc.c:1646 */ +#line 1708 "y.tab.c" /* yacc.c:1646 */ break; case 32: @@ -1713,7 +1715,7 @@ yyparse (void* qInfo) qData->arg_select.command = TOK_DATABASE; //printf("\tВыборка DATABASE\n"); } -#line 1717 "y.tab.c" /* yacc.c:1646 */ +#line 1719 "y.tab.c" /* yacc.c:1646 */ break; case 33: @@ -1723,7 +1725,7 @@ yyparse (void* qInfo) qData->command = TOK_SELECT; qData->arg_select.command = TOK_FROM; } -#line 1727 "y.tab.c" /* yacc.c:1646 */ +#line 1729 "y.tab.c" /* yacc.c:1646 */ break; case 36: @@ -1738,7 +1740,7 @@ yyparse (void* qInfo) qData->where.whereExprValueCount = 0; qData->where.whereExprCount++; } -#line 1742 "y.tab.c" /* yacc.c:1646 */ +#line 1744 "y.tab.c" /* yacc.c:1646 */ break; case 37: @@ -1757,7 +1759,7 @@ yyparse (void* qInfo) qData->where.whereExprCount++; qData->where.whereExprValueCount = 0; } -#line 1761 "y.tab.c" /* yacc.c:1646 */ +#line 1763 "y.tab.c" /* yacc.c:1646 */ break; case 38: @@ -1776,7 +1778,7 @@ yyparse (void* qInfo) qData->where.whereExprCount++; qData->where.whereExprValueCount = 0; } -#line 1780 "y.tab.c" /* yacc.c:1646 */ +#line 1782 "y.tab.c" /* yacc.c:1646 */ break; case 39: @@ -1785,7 +1787,7 @@ yyparse (void* qInfo) setQData; qData->where.whereExprCondition[qData->where.whereExprCount] = TOK_LIKE; } -#line 1789 "y.tab.c" /* yacc.c:1646 */ +#line 1791 "y.tab.c" /* yacc.c:1646 */ break; case 40: @@ -1794,7 +1796,7 @@ yyparse (void* qInfo) setQData; qData->where.whereExprCondition[qData->where.whereExprCount] = MORE; } -#line 1798 "y.tab.c" /* yacc.c:1646 */ +#line 1800 "y.tab.c" /* yacc.c:1646 */ break; case 41: @@ -1803,7 +1805,7 @@ yyparse (void* qInfo) setQData; qData->where.whereExprCondition[qData->where.whereExprCount] = LESS; } -#line 1807 "y.tab.c" /* yacc.c:1646 */ +#line 1809 "y.tab.c" /* yacc.c:1646 */ break; case 42: @@ -1812,7 +1814,7 @@ yyparse (void* qInfo) setQData; qData->where.whereExprCondition[qData->where.whereExprCount] = EQUALLY; } -#line 1816 "y.tab.c" /* yacc.c:1646 */ +#line 1818 "y.tab.c" /* yacc.c:1646 */ break; case 43: @@ -1821,7 +1823,7 @@ yyparse (void* qInfo) setQData; qData->where.whereExprCondition[qData->where.whereExprCount] = TOK_IN; } -#line 1825 "y.tab.c" /* yacc.c:1646 */ +#line 1827 "y.tab.c" /* yacc.c:1646 */ break; case 46: @@ -1831,7 +1833,7 @@ yyparse (void* qInfo) setTokValue(qData, qData->where.whereExprColum[qData->where.whereExprCount], (yyvsp[0].tokStruct)); //printf("\texpr_Name %d[%.3s...]\n", qData->where.whereExprCount, $1.text); } -#line 1835 "y.tab.c" /* yacc.c:1646 */ +#line 1837 "y.tab.c" /* yacc.c:1646 */ break; case 47: @@ -1850,7 +1852,7 @@ yyparse (void* qInfo) //printf("\texpr_Value %d[%.3s...]\n", qData->where.whereExprValueCount, $1.text); } } -#line 1854 "y.tab.c" /* yacc.c:1646 */ +#line 1856 "y.tab.c" /* yacc.c:1646 */ break; case 49: @@ -1860,7 +1862,7 @@ yyparse (void* qInfo) setTokValue(qData, qData->orderBy.name, (yyvsp[-1].tokStruct)); qData->orderBy.type = TOK_ASC; } -#line 1864 "y.tab.c" /* yacc.c:1646 */ +#line 1866 "y.tab.c" /* yacc.c:1646 */ break; case 50: @@ -1870,7 +1872,7 @@ yyparse (void* qInfo) setTokValue(qData, qData->orderBy.name, (yyvsp[-1].tokStruct)); qData->orderBy.type = TOK_ASC; } -#line 1874 "y.tab.c" /* yacc.c:1646 */ +#line 1876 "y.tab.c" /* yacc.c:1646 */ break; case 51: @@ -1880,7 +1882,7 @@ yyparse (void* qInfo) setTokValue(qData, qData->orderBy.name, (yyvsp[-1].tokStruct)); qData->orderBy.type = TOK_DESC; } -#line 1884 "y.tab.c" /* yacc.c:1646 */ +#line 1886 "y.tab.c" /* yacc.c:1646 */ break; case 53: @@ -1891,7 +1893,7 @@ yyparse (void* qInfo) //printf("\tВыборка limit %d\n", qData->limit.rows); } -#line 1895 "y.tab.c" /* yacc.c:1646 */ +#line 1897 "y.tab.c" /* yacc.c:1646 */ break; case 54: @@ -1903,7 +1905,7 @@ yyparse (void* qInfo) //printf("\tВыборка limit_start %d, limit %d\n", qData->limit.start, qData->limit.rows); } -#line 1907 "y.tab.c" /* yacc.c:1646 */ +#line 1909 "y.tab.c" /* yacc.c:1646 */ break; case 55: @@ -1912,7 +1914,7 @@ yyparse (void* qInfo) setQData; qData->arg_select.selectedColumnsCount=0; } -#line 1916 "y.tab.c" /* yacc.c:1646 */ +#line 1918 "y.tab.c" /* yacc.c:1646 */ break; case 59: @@ -1931,7 +1933,7 @@ yyparse (void* qInfo) //printf("\tQUOTED_Name %d[%.3s...]\n", qData->arg_select.selectedColumnsCount, $1.text); } } -#line 1935 "y.tab.c" /* yacc.c:1646 */ +#line 1937 "y.tab.c" /* yacc.c:1646 */ break; case 60: @@ -1941,7 +1943,7 @@ yyparse (void* qInfo) qData->command = TOK_INSERT; //printf("\tВставка\n"); } -#line 1945 "y.tab.c" /* yacc.c:1646 */ +#line 1947 "y.tab.c" /* yacc.c:1646 */ break; case 61: @@ -1951,7 +1953,7 @@ yyparse (void* qInfo) qData->command = TOK_INSERT; //printf("\tВставка\n"); } -#line 1955 "y.tab.c" /* yacc.c:1646 */ +#line 1957 "y.tab.c" /* yacc.c:1646 */ break; case 66: @@ -1970,7 +1972,7 @@ yyparse (void* qInfo) //printf("\tQUOTED_Name %d[%.3s...]\n", qData->arg_insert.namesCount, $1.text); } } -#line 1974 "y.tab.c" /* yacc.c:1646 */ +#line 1976 "y.tab.c" /* yacc.c:1646 */ break; case 67: @@ -1989,7 +1991,7 @@ yyparse (void* qInfo) //printf("\tQUOTED_Value %d[%.3s...%d]\n", qData->arg_insert.valuesCount, $1.text, $1.len); } } -#line 1993 "y.tab.c" /* yacc.c:1646 */ +#line 1995 "y.tab.c" /* yacc.c:1646 */ break; case 68: @@ -1999,7 +2001,7 @@ yyparse (void* qInfo) qData->command = TOK_DELETE; //printf("\tУдаление\n"); } -#line 2003 "y.tab.c" /* yacc.c:1646 */ +#line 2005 "y.tab.c" /* yacc.c:1646 */ break; case 69: @@ -2009,11 +2011,11 @@ yyparse (void* qInfo) setTokValue(qData, qData->tableName, (yyvsp[0].tokStruct)); //printf("\tTable_Name [%.3s...%d]\n", $1.text, $1.len); } -#line 2013 "y.tab.c" /* yacc.c:1646 */ +#line 2015 "y.tab.c" /* yacc.c:1646 */ break; -#line 2017 "y.tab.c" /* yacc.c:1646 */ +#line 2019 "y.tab.c" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires diff --git a/src/y.tab.h b/src/y.tab.h index 459db86..d91300d 100644 --- a/src/y.tab.h +++ b/src/y.tab.h @@ -1,8 +1,8 @@ -/* A Bison parser, made by GNU Bison 3.0.2. */ +/* A Bison parser, made by GNU Bison 3.0.4. */ /* Bison interface for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc. 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 @@ -141,7 +141,7 @@ extern int yydebug; /* Value type. */ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED -typedef union YYSTYPE YYSTYPE; + union YYSTYPE { #line 115 "src/CometQL.y" /* yacc.c:1909 */ @@ -154,6 +154,8 @@ union YYSTYPE #line 156 "y.tab.h" /* yacc.c:1909 */ }; + +typedef union YYSTYPE YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_DECLARED 1 #endif diff --git a/tests/api-tests/CometServerApi.js b/tests/api-tests/CometServerApi.js index fe8f1b6..38668ee 100644 --- a/tests/api-tests/CometServerApi.js +++ b/tests/api-tests/CometServerApi.js @@ -297,7 +297,7 @@ var _cometServerApi = function(opt) /** * @private */ -_cometServerApi.prototype.version = "3.32"; +_cometServerApi.prototype.version = "3.33"; /** * @private @@ -1944,6 +1944,11 @@ _cometServerApi.prototype.getUserData = function(user_id, callBack) return; } + if(callBack === undefined) + { + return; + } + var marker = _cometServerApi.prototype.getCustomString(); _cometServerApi.prototype.subscription_callBack("_answer", callBack, marker); diff --git a/tests/api-tests/conf.php b/tests/api-tests/conf.php index 655b425..7773b39 100644 --- a/tests/api-tests/conf.php +++ b/tests/api-tests/conf.php @@ -1,22 +1,22 @@ "test.comet.su", + "host" => "otr-n1.comet-server.ru", "user" => "root", - "password" => "0000000000000000000000000000000000000000000000000000000000000000", + "password" => "OTRpassfs4V9b5ptNtOTKIH93lED05es4", "api_version" => "CometQL_v1", "webTestsUrl" => "https://comet-server.com/doc/CE-api-tests/", - "port" => 3301, - "js_nodes" => ["test.comet.su:8087", "test.comet.su:8087"] + "port" => 3306, + "js_nodes" => ["otr-n1.comet-server.ru", "otr-n2.comet-server.ru"] ]; +*/ -/* $serverConf = [ - "host" => "app.comet-server.ru", + "host" => "test.comet.su", "user" => "15", "password" => "lPXBFPqNg3f661JcegBY0N0dPXqUBdHXqj2cHf04PZgLHxT6z55e20ozojvMRvB8", "api_version" => "CometQL_v1", "webTestsUrl" => "https://comet-server.com/doc/CE-api-tests/", - "port" => 3306, - "js_nodes" => ["app.comet-server.ru"] // ["test.comet.su:8087", "test.comet.su:8087"] -];*/ \ No newline at end of file + "port" => 3307, + "js_nodes" => ["test.comet.su:8087", "test.comet.su:8087"] // ["app.comet-server.ru"] // +]; diff --git a/tests/api-tests/tests/common.php b/tests/api-tests/tests/common.php index 9f824a1..5874759 100644 --- a/tests/api-tests/tests/common.php +++ b/tests/api-tests/tests/common.php @@ -46,9 +46,9 @@ function test() $bigArr = []; - for($j = 0; $j < 10; $j++) + for($j = 0; $j < 2; $j++) { - for($i = 0; $i < 1000; $i++) + for($i = 0; $i < 100; $i++) { $bigArr[] = $j*$i; }