From 44507542f6eff29204eb951212ebb4a44af87016 Mon Sep 17 00:00:00 2001 From: totoro Date: Sun, 5 Apr 2015 02:52:59 +0200 Subject: [PATCH] mistake in comment --- net_services_protocols/logger_service.anubis | 794 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1 file changed, 397 insertions(+), 397 deletions(-) diff --git a/net_services_protocols/logger_service.anubis b/net_services_protocols/logger_service.anubis index 9e9636c..f88b4ef 100644 --- a/net_services_protocols/logger_service.anubis +++ b/net_services_protocols/logger_service.anubis @@ -1,397 +1,397 @@ -/* - * - * User: David RENE - * Date: 29/07/2007 - * Time: 02:04 - * (c) Calexium - * - */ - -read tools/basis.anubis -read system/muscle.anubis -read system/data_io.anubis -read system/convert.anubis -read system/string.anubis -read system/logger.anubis -read system/message_queue.anubis -read system/message_transceiver.anubis - -read calexium_lib/CXM_message_constants.anubis -read calexium_lib/net_services/CXM_net_services.anubis -read calexium_lib/net_services/CXM_generic_protocol.anubis - -// Special non-existing file. This is a work arround for a impossibility to define global configuration in anubis. -// So this file allows you to specify on which UDP port the logger server is listening. -// You have to provide this file in your base source directory (or any other folder which is scanned by the compilater, -// and you define a function named 'logger_port' which simply return the port number as an Word32. -// Example: -// public define Word32 logger_port = 33610. - read logger_config.anubis - -// previous 'read' replaced by an empty declaration. Should be defined into main source file. -public define Word32 logger_port. - -public define Word32 logger_srv_version = 1. - - /** - * has_update scan the given message for finding corresponding available update - * package for the application. The request message come with AppId field which contain - * package or application signature and CurrentVersion field which is current version - * installed on the requester. - * - * --- REQUEST message format - * msg [_CXM_UPD_HAS_UPDATE] - * string "AppId" = hash or unique signature of the package - * string "CurrentVersion" = current version installed on the remote caller - * - * --- ANSWER message format - * - * ERROR case message format - * msg [_CXM_ACK] - * int32 "CMD" = _CXM_UPD_HAS_UPDATE - * int32 "STATUS" = _CXM_ERROR - * - * OK without update available - * msg [_CXM_ACK] - * int32 "CMD" = _CXM_UPD_HAS_UPDATE - * int32 "STATUS" = _CXM_OK - * msg "RESULT" [_CXM_ACK_RESULT_MSG] - * int32 "PackageStatus" = no_update // numerical value = 0 - * - */ - -define Bool - process_log - ( - Logger log, - Message msg - )= - if find_string(msg, "LogString") is - { - failure then logError(log, "process_log can't find LogString");false, - success(log_string) then - if find_int32(msg, "Level") is - { - failure then logError(log, "process_log can't find Level");false, - success(int_level) then - if find_int32(msg, "Thread") is - { - failure then logError(log, "process_log can't find Level");false, - success(thread_id) then - with level = get_LogLevel_from_value(to_Int(int_level)), - if level is logTrace then - if find_string(msg, "LogMask") is - { - failure then logError(log, "process_log can't find LogMask");false, - success(log_mask) then logTrace(log, logMask(log_mask), log_string, thread_id); true - } - else doLog(log, log_string, level, thread_id); true -// { -// logNone then true, -// logCriticalError then logCriticalError(log, log_string); true, -// logError then logError(log, log_string); true, -// logWarning then logWarning(log, log_string); true, -// logInfo then logInfo(log, log_string); true, -// logDebug then logDebug(log, log_string); true -// logTrace then -// if find_string(msg, "LogMask") is -// { -// failure then logError(log, "process_log can't find LogMask");false, -// success(log_mask) then logTrace(log, logMask(log_mask),log_string); true -// } -// } - } - } - }. - -define Bool - process_log - ( - List(Logger) logs, - Message msg - )= - if find_string(msg, "LogName") is - { - failure then println("process_log can't find LogName");false, - success(log_name) then - if get_logger(logs, log_name) is - { - failure then println("can't find log ["+log_name+"]");false, - success(log) then process_log(log, msg) - } - }. - - /** message_received is the principal - */ - /* - define One - message_received - ( - MessageQueue queue, - List(Logger) logs, - Message msg - )= - with msg_what = *msg.what, - if msg_what = _CXM_LOGGER_LOG then - send_result(queue, _CXM_LOGGER_LOG, process_log(logs, msg)) - else - println("wrong message_received is not _CXM_LOGGER_LOG ");unique - . - - define One - logger_handler - ( - MessageQueue queue, - List(Logger) logs - )= - if queue.get_next_received_Message(1) is - { - timeout then //println("logger_handler timeout ["+queue.get_name(unique)+"]"); - logger_handler(queue, logs), - closed then //println("logger_handler closed ["+queue.get_name(unique)+"]"); - unique, - msg(msg) then //println("logger_handler msg received ["+queue.get_name(unique)+"]"); - message_received(queue, logs, msg); - logger_handler(queue, logs) - }. - - public define NetService - logger_service - ( - List(Logger) logs - )= - net_service( - logger_srv_version, - _CXM_LOGGER_SERVICE_ID, //id of the service declared in CXM_message_constants - "Logger service", //human readable name of the service - ( - MessageQueue queue, - String peer - ) |-> logger_handler(queue, logs)). - - */ - /****************** LOCAL UDP SERVICE *************/ - - -public define String - data_preview - ( - ByteArray data, - Int max - ) = - with l = length(data), - firsts_bytes = extract(data, 0, max), - "Length=" + l + "; String='"+to_string(firsts_bytes)+"' Buffer=[" + to_ascii(firsts_bytes) + (if l > max then "...]" else "]"). - - -define (UDP_Socket, ByteArray, Truncation, Word32, Word32) -> One - make_udp_handler - ( - List(Logger) logs, - Logger debug_logger - ) = - ( - UDP_Socket socket, - ByteArray data, - Truncation truncation, - Word32 ip_address, - Word32 ip_port - ) |-> - with ip = ip_addr_to_string(ip_address), - logTrace(debug_logger, logMask("Logger"), "LoggerServer: data received (" + length(data) + " bytes) from IP " + ip + "... "); - if receive_message_from_io(make_data_io(data)) is - { - failure then logWarning(debug_logger, "LoggerServer: Bad data packet received from IP " + ip + ": " + data_preview(data, 20)), - success(msg) then - if *msg.what = _CXM_LOGGER_LOG then - forget(process_log(logs, msg)) - else - println("LoggerService: wrong message_received. [" + to_hexa(*msg.what) + "] is not _CXM_LOGGER_LOG ") - }. - -define One - my_notify - ( - One dummy - ) = - unique. - -public define Maybe(UDP_Server) - start_logger_server - ( - List(Logger) logs, - Logger debug_logger - ) = - if start_udp_server(0, - logger_port, - make_udp_handler(logs, debug_logger), - 8*1024, - my_notify) is - { - cannot_create_the_socket then logError(debug_logger, "Cannot create the listening socket."); failure, - cannot_bind_address_port then logError(debug_logger, "Cannot bind to port " + logger_port + ".");failure, - access_denied then logError(debug_logger, "Cannot listen on port " + logger_port + ".");failure, - ok(server) then logInfo(debug_logger, "LocalLog Server started on port " + logger_port + "."); success(server) - }. - - - /****************** CLIENT PART *******************/ - -define One - local_net_logger - ( - String logger_server, - Message log_message - )= - forget(send_message_by_udp(log_message, ip_address((127,0,0,1)), logger_port)). - - -define Message - create_log_msg - ( - String logger_name, - String log_string, - Int level - )= - with string = if length(log_string) > 1024 then (if sub_string(log_string, 0, 1024) is success(s) then s else "?") + "..." - else log_string, - with log_msg = message(_CXM_LOGGER_LOG), - forget(add_string(log_msg, "LogName", logger_name)); - forget(add_string(log_msg, "LogString", string)); - forget(add_int32(log_msg, "Level", truncate_to_Word32(level))); - forget(add_int32(log_msg, "Thread", virtual_machine_id)); - log_msg - . -*/ - -// HACK Begin of Hacked version - define String debug_log = "Debug". - define String config_log = "Config". - define String incoming_log = "Incoming". - define String outgoing_log = "Outgoing". - define String pop3_log = "POP3". - define String mailing_log = "Mailing". - define String errors_log = "Errors". - define String security_log = "Security". - define String spams_log = "Spams". - define String api_log = "MF_API". - define String internal_log = "INTERNAL". - - - define String - get_log_file - ( - String log_name - ) = - if log_name = debug_log then "debug.log" - else if log_name = "SendMail" then "debug.log" - else if log_name = config_log then "config.log" - else if log_name = incoming_log then "incoming.log" - else if log_name = outgoing_log then "outgoing.log" - else if log_name = pop3_log then "pop3.log" - else if log_name = mailing_log then "mailing.log" - else if log_name = errors_log then "errors.log" - else if log_name = "DB" then "errors.log" - else if log_name = "SQL" then "sql_profiling.log" - else if log_name = security_log then "security.log" - else if log_name = spams_log then "spams.log" - else if log_name = api_log then "api.log" - else if log_name = internal_log then "internal" - else "unknown.log". - - - define One - local_net_logger - ( - String logger_server, - One _ - )= - unique. - - define One - create_log_msg - ( - String logger_name, - String log_string, - Int level - )= - with log = createLogger(logger_name, 8, "/var/MailFountain/log/" + get_log_file(logger_name), logTrace, logTrace), - logLevel = get_LogLevel_from_value(level), - protect - doLog(log, log_string, logLevel, virtual_machine_id). - -// HACK End of Hacked version - - - -public define One - log( - LogLevel level, - String logger_name, - String log_string - )= - local_net_logger("127.0.0.1", create_log_msg(logger_name, log_string, get_log_level_value(level))). - -public define One - logNone( - String logger_name, - String log_string - )= - local_net_logger("127.0.0.1", create_log_msg(logger_name, log_string, 0)). - -public define One - logCriticalError( - String logger_name, - String log_string - )= - local_net_logger("127.0.0.1", create_log_msg(logger_name, log_string, 1)). - -public define One - logError( - String logger_name, - String log_string - )= - local_net_logger("127.0.0.1", create_log_msg(logger_name, log_string, 2)). - -public define One - logWarning( - String logger_name, - String log_string - )= - local_net_logger("127.0.0.1", create_log_msg(logger_name, log_string, 3)). - -public define One - logInfo( - String logger_name, - String log_string - )= - local_net_logger("127.0.0.1", create_log_msg(logger_name, log_string, 4)). - -public define One - logDebug( - String logger_name, - String log_string - )= - local_net_logger("127.0.0.1", create_log_msg(logger_name, log_string, 5)). - -public define One - logTrace( - String logger_name, - LogMask log_mask, - String log_string - )= - with log_msg = create_log_msg(logger_name, log_string, 6), - forget(add_string(log_msg, "LogMask", log_mask.mask)); - local_net_logger("127.0.0.1", log_msg). - -// HACK hacked version - public define One - logTrace( - String logger_name, - LogMask log_mask, - String log_string - )= - if log_mask is logMask(mask) then - if mask = "send_mail" | mask = "smtp" | mask = "sql_profiling" then - local_net_logger("127.0.0.1", create_log_msg(logger_name, log_string, 6)) - else unique. +/* + * + * User: David RENE + * Date: 29/07/2007 + * Time: 02:04 + * (c) Calexium + * + */ + +read tools/basis.anubis +read system/muscle.anubis +read system/data_io.anubis +read system/convert.anubis +read system/string.anubis +read system/logger.anubis +read system/message_queue.anubis +read system/message_transceiver.anubis + +read calexium_lib/CXM_message_constants.anubis +read calexium_lib/net_services/CXM_net_services.anubis +read calexium_lib/net_services/CXM_generic_protocol.anubis + +// Special non-existing file. This is a work arround for a impossibility to define global configuration in anubis. +// So this file allows you to specify on which UDP port the logger server is listening. +// You have to provide this file in your base source directory (or any other folder which is scanned by the compiler, +// and you define a function named 'logger_port' which simply return the port number as an Word32. +// Example: +// public define Word32 logger_port = 33610. + read logger_config.anubis + +// previous 'read' replaced by an empty declaration. Should be defined into main source file. +public define Word32 logger_port. + +public define Word32 logger_srv_version = 1. + + /** + * has_update scan the given message for finding corresponding available update + * package for the application. The request message come with AppId field which contain + * package or application signature and CurrentVersion field which is current version + * installed on the requester. + * + * --- REQUEST message format + * msg [_CXM_UPD_HAS_UPDATE] + * string "AppId" = hash or unique signature of the package + * string "CurrentVersion" = current version installed on the remote caller + * + * --- ANSWER message format + * + * ERROR case message format + * msg [_CXM_ACK] + * int32 "CMD" = _CXM_UPD_HAS_UPDATE + * int32 "STATUS" = _CXM_ERROR + * + * OK without update available + * msg [_CXM_ACK] + * int32 "CMD" = _CXM_UPD_HAS_UPDATE + * int32 "STATUS" = _CXM_OK + * msg "RESULT" [_CXM_ACK_RESULT_MSG] + * int32 "PackageStatus" = no_update // numerical value = 0 + * + */ + +define Bool + process_log + ( + Logger log, + Message msg + )= + if find_string(msg, "LogString") is + { + failure then logError(log, "process_log can't find LogString");false, + success(log_string) then + if find_int32(msg, "Level") is + { + failure then logError(log, "process_log can't find Level");false, + success(int_level) then + if find_int32(msg, "Thread") is + { + failure then logError(log, "process_log can't find Level");false, + success(thread_id) then + with level = get_LogLevel_from_value(to_Int(int_level)), + if level is logTrace then + if find_string(msg, "LogMask") is + { + failure then logError(log, "process_log can't find LogMask");false, + success(log_mask) then logTrace(log, logMask(log_mask), log_string, thread_id); true + } + else doLog(log, log_string, level, thread_id); true +// { +// logNone then true, +// logCriticalError then logCriticalError(log, log_string); true, +// logError then logError(log, log_string); true, +// logWarning then logWarning(log, log_string); true, +// logInfo then logInfo(log, log_string); true, +// logDebug then logDebug(log, log_string); true +// logTrace then +// if find_string(msg, "LogMask") is +// { +// failure then logError(log, "process_log can't find LogMask");false, +// success(log_mask) then logTrace(log, logMask(log_mask),log_string); true +// } +// } + } + } + }. + +define Bool + process_log + ( + List(Logger) logs, + Message msg + )= + if find_string(msg, "LogName") is + { + failure then println("process_log can't find LogName");false, + success(log_name) then + if get_logger(logs, log_name) is + { + failure then println("can't find log ["+log_name+"]");false, + success(log) then process_log(log, msg) + } + }. + + /** message_received is the principal + */ + /* + define One + message_received + ( + MessageQueue queue, + List(Logger) logs, + Message msg + )= + with msg_what = *msg.what, + if msg_what = _CXM_LOGGER_LOG then + send_result(queue, _CXM_LOGGER_LOG, process_log(logs, msg)) + else + println("wrong message_received is not _CXM_LOGGER_LOG ");unique + . + + define One + logger_handler + ( + MessageQueue queue, + List(Logger) logs + )= + if queue.get_next_received_Message(1) is + { + timeout then //println("logger_handler timeout ["+queue.get_name(unique)+"]"); + logger_handler(queue, logs), + closed then //println("logger_handler closed ["+queue.get_name(unique)+"]"); + unique, + msg(msg) then //println("logger_handler msg received ["+queue.get_name(unique)+"]"); + message_received(queue, logs, msg); + logger_handler(queue, logs) + }. + + public define NetService + logger_service + ( + List(Logger) logs + )= + net_service( + logger_srv_version, + _CXM_LOGGER_SERVICE_ID, //id of the service declared in CXM_message_constants + "Logger service", //human readable name of the service + ( + MessageQueue queue, + String peer + ) |-> logger_handler(queue, logs)). + + */ + /****************** LOCAL UDP SERVICE *************/ + + +public define String + data_preview + ( + ByteArray data, + Int max + ) = + with l = length(data), + firsts_bytes = extract(data, 0, max), + "Length=" + l + "; String='"+to_string(firsts_bytes)+"' Buffer=[" + to_ascii(firsts_bytes) + (if l > max then "...]" else "]"). + + +define (UDP_Socket, ByteArray, Truncation, Word32, Word32) -> One + make_udp_handler + ( + List(Logger) logs, + Logger debug_logger + ) = + ( + UDP_Socket socket, + ByteArray data, + Truncation truncation, + Word32 ip_address, + Word32 ip_port + ) |-> + with ip = ip_addr_to_string(ip_address), + logTrace(debug_logger, logMask("Logger"), "LoggerServer: data received (" + length(data) + " bytes) from IP " + ip + "... "); + if receive_message_from_io(make_data_io(data)) is + { + failure then logWarning(debug_logger, "LoggerServer: Bad data packet received from IP " + ip + ": " + data_preview(data, 20)), + success(msg) then + if *msg.what = _CXM_LOGGER_LOG then + forget(process_log(logs, msg)) + else + println("LoggerService: wrong message_received. [" + to_hexa(*msg.what) + "] is not _CXM_LOGGER_LOG ") + }. + +define One + my_notify + ( + One dummy + ) = + unique. + +public define Maybe(UDP_Server) + start_logger_server + ( + List(Logger) logs, + Logger debug_logger + ) = + if start_udp_server(0, + logger_port, + make_udp_handler(logs, debug_logger), + 8*1024, + my_notify) is + { + cannot_create_the_socket then logError(debug_logger, "Cannot create the listening socket."); failure, + cannot_bind_address_port then logError(debug_logger, "Cannot bind to port " + logger_port + ".");failure, + access_denied then logError(debug_logger, "Cannot listen on port " + logger_port + ".");failure, + ok(server) then logInfo(debug_logger, "LocalLog Server started on port " + logger_port + "."); success(server) + }. + + + /****************** CLIENT PART *******************/ + +define One + local_net_logger + ( + String logger_server, + Message log_message + )= + forget(send_message_by_udp(log_message, ip_address((127,0,0,1)), logger_port)). + + +define Message + create_log_msg + ( + String logger_name, + String log_string, + Int level + )= + with string = if length(log_string) > 1024 then (if sub_string(log_string, 0, 1024) is success(s) then s else "?") + "..." + else log_string, + with log_msg = message(_CXM_LOGGER_LOG), + forget(add_string(log_msg, "LogName", logger_name)); + forget(add_string(log_msg, "LogString", string)); + forget(add_int32(log_msg, "Level", truncate_to_Word32(level))); + forget(add_int32(log_msg, "Thread", virtual_machine_id)); + log_msg + . +*/ + +// HACK Begin of Hacked version + define String debug_log = "Debug". + define String config_log = "Config". + define String incoming_log = "Incoming". + define String outgoing_log = "Outgoing". + define String pop3_log = "POP3". + define String mailing_log = "Mailing". + define String errors_log = "Errors". + define String security_log = "Security". + define String spams_log = "Spams". + define String api_log = "MF_API". + define String internal_log = "INTERNAL". + + + define String + get_log_file + ( + String log_name + ) = + if log_name = debug_log then "debug.log" + else if log_name = "SendMail" then "debug.log" + else if log_name = config_log then "config.log" + else if log_name = incoming_log then "incoming.log" + else if log_name = outgoing_log then "outgoing.log" + else if log_name = pop3_log then "pop3.log" + else if log_name = mailing_log then "mailing.log" + else if log_name = errors_log then "errors.log" + else if log_name = "DB" then "errors.log" + else if log_name = "SQL" then "sql_profiling.log" + else if log_name = security_log then "security.log" + else if log_name = spams_log then "spams.log" + else if log_name = api_log then "api.log" + else if log_name = internal_log then "internal" + else "unknown.log". + + + define One + local_net_logger + ( + String logger_server, + One _ + )= + unique. + + define One + create_log_msg + ( + String logger_name, + String log_string, + Int level + )= + with log = createLogger(logger_name, 8, "/var/MailFountain/log/" + get_log_file(logger_name), logTrace, logTrace), + logLevel = get_LogLevel_from_value(level), + protect + doLog(log, log_string, logLevel, virtual_machine_id). + +// HACK End of Hacked version + + + +public define One + log( + LogLevel level, + String logger_name, + String log_string + )= + local_net_logger("127.0.0.1", create_log_msg(logger_name, log_string, get_log_level_value(level))). + +public define One + logNone( + String logger_name, + String log_string + )= + local_net_logger("127.0.0.1", create_log_msg(logger_name, log_string, 0)). + +public define One + logCriticalError( + String logger_name, + String log_string + )= + local_net_logger("127.0.0.1", create_log_msg(logger_name, log_string, 1)). + +public define One + logError( + String logger_name, + String log_string + )= + local_net_logger("127.0.0.1", create_log_msg(logger_name, log_string, 2)). + +public define One + logWarning( + String logger_name, + String log_string + )= + local_net_logger("127.0.0.1", create_log_msg(logger_name, log_string, 3)). + +public define One + logInfo( + String logger_name, + String log_string + )= + local_net_logger("127.0.0.1", create_log_msg(logger_name, log_string, 4)). + +public define One + logDebug( + String logger_name, + String log_string + )= + local_net_logger("127.0.0.1", create_log_msg(logger_name, log_string, 5)). + +public define One + logTrace( + String logger_name, + LogMask log_mask, + String log_string + )= + with log_msg = create_log_msg(logger_name, log_string, 6), + forget(add_string(log_msg, "LogMask", log_mask.mask)); + local_net_logger("127.0.0.1", log_msg). + +// HACK hacked version + public define One + logTrace( + String logger_name, + LogMask log_mask, + String log_string + )= + if log_mask is logMask(mask) then + if mask = "send_mail" | mask = "smtp" | mask = "sql_profiling" then + local_net_logger("127.0.0.1", create_log_msg(logger_name, log_string, 6)) + else unique. -- libgit2 0.21.4