From c84cf0a2047f6c9221260854db777fff74b01d08 Mon Sep 17 00:00:00 2001 From: Cedric RICARD Date: Sun, 23 Sep 2007 13:49:31 +0000 Subject: [PATCH] Base for CXM errors handling on Net Services --- calexium_lib/CXM_errors.anubis | 37 +++++++++++++++++++++++++++++++++++++ calexium_lib/net_services/CXM_generic_protocol.anubis | 262 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------------------- calexium_lib/web/CXM_mime.anubis | 35 +++++++++++++++++++++-------------- 3 files changed, 189 insertions(+), 145 deletions(-) create mode 100644 calexium_lib/CXM_errors.anubis diff --git a/calexium_lib/CXM_errors.anubis b/calexium_lib/CXM_errors.anubis new file mode 100644 index 0000000..88d50a6 --- /dev/null +++ b/calexium_lib/CXM_errors.anubis @@ -0,0 +1,37 @@ +/* + * Created by PyramIDE. + * User: ricard + * Date: 16/09/2007 + * Time: 21:10 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ + +public type GeneralError: + ok, + unknown(Int32 val), + bad_type, + bad_value, + bad_parameters, + no_init, + unknown_command, + wrong_authentification, // Wrong login or password + access_denied. // login ok but no suffisiant right to access to this area. Can be use with wrong authentification too... + +public define Int32 + to_Int32 + ( + GeneralError e + ) = + if e is + { + ok then 0, + unknown(val) then val, + bad_type then 0x1, + bad_value then 0x2, + bad_parameters then 0x3, + no_init then 0x4, + unknown_command then 0x5, + wrong_authentification then 0x6, + access_denied then 0x7, + }. diff --git a/calexium_lib/net_services/CXM_generic_protocol.anubis b/calexium_lib/net_services/CXM_generic_protocol.anubis index c4a5ac2..bd60a64 100644 --- a/calexium_lib/net_services/CXM_generic_protocol.anubis +++ b/calexium_lib/net_services/CXM_generic_protocol.anubis @@ -1,131 +1,131 @@ -/* - * - * User: David RENE - * Date: 25/04/2007 - * Time: 16:20 - * (c) Calexium - * - */ - -read system/muscle.anubis -read system/data_io.anubis -read system/string.anubis -read tools/basis.anubis -read system/message_queue.anubis -read calexium_lib/CXM_message_constants.anubis - -public define Int32 _CXM_ERROR = 0. -public define Int32 _CXM_OK = 1. -public define Int32 _CXM_UNKNOW_CMD = 2. - -public type ProtocolResult: - failure, - timeout, - unknow_cmd, - error, - ok, - ok_msg(Message). - -public define One - send_ACK_error - ( - MessageQueue queue, - Int32 cmd_id - )= - with err_msg = message(_CXM_ACK), - forget(add_int32(err_msg, "CMD", cmd_id)); - forget(add_int32(err_msg, "STATUS", _CXM_ERROR)); - forget(queue.add_Message_to_send(err_msg)). - -public define One - send_ACK_ok - ( - MessageQueue queue, - Int32 cmd_id - )= - with ok_msg = message(_CXM_ACK), - forget(add_int32(ok_msg, "CMD", cmd_id)); - forget(add_int32(ok_msg, "STATUS", _CXM_OK)); - forget(queue.add_Message_to_send(ok_msg)) - . - -public define One - send_ACK_ok - ( - MessageQueue queue, - Int32 cmd_id, - Message result - )= - with ok_msg = message(_CXM_ACK), - forget(add_int32(ok_msg, "CMD", cmd_id)); - forget(add_int32(ok_msg, "STATUS", _CXM_OK)); - forget(add_message(ok_msg, "RESULT", result)); - forget(queue.add_Message_to_send(ok_msg)) - . - -public define One - send_result - ( - MessageQueue queue, - Int32 cmd_id, - Maybe(Message) mb_msg - )= - if mb_msg is - { - failure then send_ACK_error(queue, cmd_id), - success(msg) then send_ACK_ok(queue, cmd_id, msg) - }. - -public define One - send_result - ( - MessageQueue queue, - Int32 cmd_id, - Bool result - )= - if result then - send_ACK_ok(queue, cmd_id) - else - send_ACK_error(queue, cmd_id). - -public define ProtocolResult - wait_for_reply - ( - MessageQueue mQ, - Int32 wait_cmd, - Int32 t_out - ) = - if mQ.get_next_received_Message(t_out) is - { - timeout then timeout, - closed then failure, //println("wait_for_reply closed"); - - msg(_msg) then - if *_msg.what = _CXM_ACK then - if find_int32(_msg, "CMD") is - { - failure then failure, //println("wait_for_reply CMD"); - success(cmd) then -// println("wait_for_reply CMD="+to_hexa(cmd)); - if find_int32(_msg, "STATUS") is - { - failure then failure, //println("wait_for_reply STATUS"); - success(status) then - if cmd = wait_cmd & status = _CXM_OK then - if find_message(_msg, "RESULT") is - { - failure then ok, - success(ok_message) then ok_msg(ok_message) - } - else if cmd = wait_cmd & status = _CXM_ERROR then - error - else if cmd = wait_cmd & status = _CXM_UNKNOW_CMD then - unknow_cmd - else - failure //println("wait_for_reply "); - } - } - else - failure //println("wait_for_reply not ACK"); - }. - +/* + * + * User: David RENE + * Date: 25/04/2007 + * Time: 16:20 + * (c) Calexium + * + */ + +read system/muscle.anubis +read system/data_io.anubis +read system/string.anubis +read tools/basis.anubis +read system/message_queue.anubis +read calexium_lib/CXM_message_constants.anubis + +public define Int32 _CXM_OK = 0. +public define Int32 _CXM_ERROR = 1. +public define Int32 _CXM_UNKNOW_CMD = 2. + +public type ProtocolResult: + failure, + timeout, + unknow_cmd, + error, + ok, + ok_msg(Message). + +public define One + send_ACK_error + ( + MessageQueue queue, + Int32 cmd_id + )= + with err_msg = message(_CXM_ACK), + forget(add_int32(err_msg, "CMD", cmd_id)); + forget(add_int32(err_msg, "STATUS", _CXM_ERROR)); + forget(queue.add_Message_to_send(err_msg)). + +public define One + send_ACK_ok + ( + MessageQueue queue, + Int32 cmd_id + )= + with ok_msg = message(_CXM_ACK), + forget(add_int32(ok_msg, "CMD", cmd_id)); + forget(add_int32(ok_msg, "STATUS", _CXM_OK)); + forget(queue.add_Message_to_send(ok_msg)) + . + +public define One + send_ACK_ok + ( + MessageQueue queue, + Int32 cmd_id, + Message result + )= + with ok_msg = message(_CXM_ACK), + forget(add_int32(ok_msg, "CMD", cmd_id)); + forget(add_int32(ok_msg, "STATUS", _CXM_OK)); + forget(add_message(ok_msg, "RESULT", result)); + forget(queue.add_Message_to_send(ok_msg)) + . + +public define One + send_result + ( + MessageQueue queue, + Int32 cmd_id, + Maybe(Message) mb_msg + )= + if mb_msg is + { + failure then send_ACK_error(queue, cmd_id), + success(msg) then send_ACK_ok(queue, cmd_id, msg) + }. + +public define One + send_result + ( + MessageQueue queue, + Int32 cmd_id, + Bool result + )= + if result then + send_ACK_ok(queue, cmd_id) + else + send_ACK_error(queue, cmd_id). + +public define ProtocolResult + wait_for_reply + ( + MessageQueue mQ, + Int32 wait_cmd, + Int32 t_out + ) = + if mQ.get_next_received_Message(t_out) is + { + timeout then timeout, + closed then failure, //println("wait_for_reply closed"); + + msg(_msg) then + if *_msg.what = _CXM_ACK then + if find_int32(_msg, "CMD") is + { + failure then failure, //println("wait_for_reply CMD"); + success(cmd) then +// println("wait_for_reply CMD="+to_hexa(cmd)); + if find_int32(_msg, "STATUS") is + { + failure then failure, //println("wait_for_reply STATUS"); + success(status) then + if cmd = wait_cmd & status = _CXM_OK then + if find_message(_msg, "RESULT") is + { + failure then ok, + success(ok_message) then ok_msg(ok_message) + } + else if cmd = wait_cmd & status = _CXM_ERROR then + error + else if cmd = wait_cmd & status = _CXM_UNKNOW_CMD then + unknow_cmd + else + failure //println("wait_for_reply "); + } + } + else + failure //println("wait_for_reply not ACK"); + }. + diff --git a/calexium_lib/web/CXM_mime.anubis b/calexium_lib/web/CXM_mime.anubis index deffb74..e2774e4 100644 --- a/calexium_lib/web/CXM_mime.anubis +++ b/calexium_lib/web/CXM_mime.anubis @@ -1,16 +1,18 @@ - - *Project* The Anubis Project - - *Title* MIME Types definition. - - *Copyright* Copyright (c) Alain Prouté 2005. - - - *Author* Alain Prouté - + + *Project* The Anubis Project + + *Title* MIME Types definition. + + *Copyright* Copyright (c) Alain Prouté 2005. + - + *Authors* Alain Prouté + David René + +read tools/base64.anubis +read tools/basis.anubis +read system/string.anubis public type MIME: mime(String name, @@ -60,6 +62,11 @@ public define List(MIME) mime("video/x-msvideo", ".avi"), ]. - - - \ No newline at end of file +public define String + to_MIME_text + ( + String charset, + String text + )= + with text = "=?"+charset+"?B?"+to_string(base64_encode(to_byte_array(text)))+"?=", + find_and_replace(text, implode([13,10]), implode([13,10,32])). -- libgit2 0.21.4