Commit c84cf0a2047f6c9221260854db777fff74b01d08
1 parent
c6903c95
Base for CXM errors handling on Net Services
Showing
3 changed files
with
189 additions
and
145 deletions
Show diff stats
| 1 | +/* | |
| 2 | + * Created by PyramIDE. | |
| 3 | + * User: ricard | |
| 4 | + * Date: 16/09/2007 | |
| 5 | + * Time: 21:10 | |
| 6 | + * | |
| 7 | + * To change this template use Tools | Options | Coding | Edit Standard Headers. | |
| 8 | + */ | |
| 9 | + | |
| 10 | +public type GeneralError: | |
| 11 | + ok, | |
| 12 | + unknown(Int32 val), | |
| 13 | + bad_type, | |
| 14 | + bad_value, | |
| 15 | + bad_parameters, | |
| 16 | + no_init, | |
| 17 | + unknown_command, | |
| 18 | + wrong_authentification, // Wrong login or password | |
| 19 | + access_denied. // login ok but no suffisiant right to access to this area. Can be use with wrong authentification too... | |
| 20 | + | |
| 21 | +public define Int32 | |
| 22 | + to_Int32 | |
| 23 | + ( | |
| 24 | + GeneralError e | |
| 25 | + ) = | |
| 26 | + if e is | |
| 27 | + { | |
| 28 | + ok then 0, | |
| 29 | + unknown(val) then val, | |
| 30 | + bad_type then 0x1, | |
| 31 | + bad_value then 0x2, | |
| 32 | + bad_parameters then 0x3, | |
| 33 | + no_init then 0x4, | |
| 34 | + unknown_command then 0x5, | |
| 35 | + wrong_authentification then 0x6, | |
| 36 | + access_denied then 0x7, | |
| 37 | + }. | ... | ... |
calexium_lib/net_services/CXM_generic_protocol.anubis
| 1 | -/* | |
| 2 | - * | |
| 3 | - * User: David RENE | |
| 4 | - * Date: 25/04/2007 | |
| 5 | - * Time: 16:20 | |
| 6 | - * (c) Calexium | |
| 7 | - * | |
| 8 | - */ | |
| 9 | - | |
| 10 | -read system/muscle.anubis | |
| 11 | -read system/data_io.anubis | |
| 12 | -read system/string.anubis | |
| 13 | -read tools/basis.anubis | |
| 14 | -read system/message_queue.anubis | |
| 15 | -read calexium_lib/CXM_message_constants.anubis | |
| 16 | - | |
| 17 | -public define Int32 _CXM_ERROR = 0. | |
| 18 | -public define Int32 _CXM_OK = 1. | |
| 19 | -public define Int32 _CXM_UNKNOW_CMD = 2. | |
| 20 | - | |
| 21 | -public type ProtocolResult: | |
| 22 | - failure, | |
| 23 | - timeout, | |
| 24 | - unknow_cmd, | |
| 25 | - error, | |
| 26 | - ok, | |
| 27 | - ok_msg(Message). | |
| 28 | - | |
| 29 | -public define One | |
| 30 | - send_ACK_error | |
| 31 | - ( | |
| 32 | - MessageQueue queue, | |
| 33 | - Int32 cmd_id | |
| 34 | - )= | |
| 35 | - with err_msg = message(_CXM_ACK), | |
| 36 | - forget(add_int32(err_msg, "CMD", cmd_id)); | |
| 37 | - forget(add_int32(err_msg, "STATUS", _CXM_ERROR)); | |
| 38 | - forget(queue.add_Message_to_send(err_msg)). | |
| 39 | - | |
| 40 | -public define One | |
| 41 | - send_ACK_ok | |
| 42 | - ( | |
| 43 | - MessageQueue queue, | |
| 44 | - Int32 cmd_id | |
| 45 | - )= | |
| 46 | - with ok_msg = message(_CXM_ACK), | |
| 47 | - forget(add_int32(ok_msg, "CMD", cmd_id)); | |
| 48 | - forget(add_int32(ok_msg, "STATUS", _CXM_OK)); | |
| 49 | - forget(queue.add_Message_to_send(ok_msg)) | |
| 50 | - . | |
| 51 | - | |
| 52 | -public define One | |
| 53 | - send_ACK_ok | |
| 54 | - ( | |
| 55 | - MessageQueue queue, | |
| 56 | - Int32 cmd_id, | |
| 57 | - Message result | |
| 58 | - )= | |
| 59 | - with ok_msg = message(_CXM_ACK), | |
| 60 | - forget(add_int32(ok_msg, "CMD", cmd_id)); | |
| 61 | - forget(add_int32(ok_msg, "STATUS", _CXM_OK)); | |
| 62 | - forget(add_message(ok_msg, "RESULT", result)); | |
| 63 | - forget(queue.add_Message_to_send(ok_msg)) | |
| 64 | - . | |
| 65 | - | |
| 66 | -public define One | |
| 67 | - send_result | |
| 68 | - ( | |
| 69 | - MessageQueue queue, | |
| 70 | - Int32 cmd_id, | |
| 71 | - Maybe(Message) mb_msg | |
| 72 | - )= | |
| 73 | - if mb_msg is | |
| 74 | - { | |
| 75 | - failure then send_ACK_error(queue, cmd_id), | |
| 76 | - success(msg) then send_ACK_ok(queue, cmd_id, msg) | |
| 77 | - }. | |
| 78 | - | |
| 79 | -public define One | |
| 80 | - send_result | |
| 81 | - ( | |
| 82 | - MessageQueue queue, | |
| 83 | - Int32 cmd_id, | |
| 84 | - Bool result | |
| 85 | - )= | |
| 86 | - if result then | |
| 87 | - send_ACK_ok(queue, cmd_id) | |
| 88 | - else | |
| 89 | - send_ACK_error(queue, cmd_id). | |
| 90 | - | |
| 91 | -public define ProtocolResult | |
| 92 | - wait_for_reply | |
| 93 | - ( | |
| 94 | - MessageQueue mQ, | |
| 95 | - Int32 wait_cmd, | |
| 96 | - Int32 t_out | |
| 97 | - ) = | |
| 98 | - if mQ.get_next_received_Message(t_out) is | |
| 99 | - { | |
| 100 | - timeout then timeout, | |
| 101 | - closed then failure, //println("wait_for_reply closed"); | |
| 102 | - | |
| 103 | - msg(_msg) then | |
| 104 | - if *_msg.what = _CXM_ACK then | |
| 105 | - if find_int32(_msg, "CMD") is | |
| 106 | - { | |
| 107 | - failure then failure, //println("wait_for_reply CMD"); | |
| 108 | - success(cmd) then | |
| 109 | -// println("wait_for_reply CMD="+to_hexa(cmd)); | |
| 110 | - if find_int32(_msg, "STATUS") is | |
| 111 | - { | |
| 112 | - failure then failure, //println("wait_for_reply STATUS"); | |
| 113 | - success(status) then | |
| 114 | - if cmd = wait_cmd & status = _CXM_OK then | |
| 115 | - if find_message(_msg, "RESULT") is | |
| 116 | - { | |
| 117 | - failure then ok, | |
| 118 | - success(ok_message) then ok_msg(ok_message) | |
| 119 | - } | |
| 120 | - else if cmd = wait_cmd & status = _CXM_ERROR then | |
| 121 | - error | |
| 122 | - else if cmd = wait_cmd & status = _CXM_UNKNOW_CMD then | |
| 123 | - unknow_cmd | |
| 124 | - else | |
| 125 | - failure //println("wait_for_reply "); | |
| 126 | - } | |
| 127 | - } | |
| 128 | - else | |
| 129 | - failure //println("wait_for_reply not ACK"); | |
| 130 | - }. | |
| 131 | - | |
| 1 | +/* | |
| 2 | + * | |
| 3 | + * User: David RENE | |
| 4 | + * Date: 25/04/2007 | |
| 5 | + * Time: 16:20 | |
| 6 | + * (c) Calexium | |
| 7 | + * | |
| 8 | + */ | |
| 9 | + | |
| 10 | +read system/muscle.anubis | |
| 11 | +read system/data_io.anubis | |
| 12 | +read system/string.anubis | |
| 13 | +read tools/basis.anubis | |
| 14 | +read system/message_queue.anubis | |
| 15 | +read calexium_lib/CXM_message_constants.anubis | |
| 16 | + | |
| 17 | +public define Int32 _CXM_OK = 0. | |
| 18 | +public define Int32 _CXM_ERROR = 1. | |
| 19 | +public define Int32 _CXM_UNKNOW_CMD = 2. | |
| 20 | + | |
| 21 | +public type ProtocolResult: | |
| 22 | + failure, | |
| 23 | + timeout, | |
| 24 | + unknow_cmd, | |
| 25 | + error, | |
| 26 | + ok, | |
| 27 | + ok_msg(Message). | |
| 28 | + | |
| 29 | +public define One | |
| 30 | + send_ACK_error | |
| 31 | + ( | |
| 32 | + MessageQueue queue, | |
| 33 | + Int32 cmd_id | |
| 34 | + )= | |
| 35 | + with err_msg = message(_CXM_ACK), | |
| 36 | + forget(add_int32(err_msg, "CMD", cmd_id)); | |
| 37 | + forget(add_int32(err_msg, "STATUS", _CXM_ERROR)); | |
| 38 | + forget(queue.add_Message_to_send(err_msg)). | |
| 39 | + | |
| 40 | +public define One | |
| 41 | + send_ACK_ok | |
| 42 | + ( | |
| 43 | + MessageQueue queue, | |
| 44 | + Int32 cmd_id | |
| 45 | + )= | |
| 46 | + with ok_msg = message(_CXM_ACK), | |
| 47 | + forget(add_int32(ok_msg, "CMD", cmd_id)); | |
| 48 | + forget(add_int32(ok_msg, "STATUS", _CXM_OK)); | |
| 49 | + forget(queue.add_Message_to_send(ok_msg)) | |
| 50 | + . | |
| 51 | + | |
| 52 | +public define One | |
| 53 | + send_ACK_ok | |
| 54 | + ( | |
| 55 | + MessageQueue queue, | |
| 56 | + Int32 cmd_id, | |
| 57 | + Message result | |
| 58 | + )= | |
| 59 | + with ok_msg = message(_CXM_ACK), | |
| 60 | + forget(add_int32(ok_msg, "CMD", cmd_id)); | |
| 61 | + forget(add_int32(ok_msg, "STATUS", _CXM_OK)); | |
| 62 | + forget(add_message(ok_msg, "RESULT", result)); | |
| 63 | + forget(queue.add_Message_to_send(ok_msg)) | |
| 64 | + . | |
| 65 | + | |
| 66 | +public define One | |
| 67 | + send_result | |
| 68 | + ( | |
| 69 | + MessageQueue queue, | |
| 70 | + Int32 cmd_id, | |
| 71 | + Maybe(Message) mb_msg | |
| 72 | + )= | |
| 73 | + if mb_msg is | |
| 74 | + { | |
| 75 | + failure then send_ACK_error(queue, cmd_id), | |
| 76 | + success(msg) then send_ACK_ok(queue, cmd_id, msg) | |
| 77 | + }. | |
| 78 | + | |
| 79 | +public define One | |
| 80 | + send_result | |
| 81 | + ( | |
| 82 | + MessageQueue queue, | |
| 83 | + Int32 cmd_id, | |
| 84 | + Bool result | |
| 85 | + )= | |
| 86 | + if result then | |
| 87 | + send_ACK_ok(queue, cmd_id) | |
| 88 | + else | |
| 89 | + send_ACK_error(queue, cmd_id). | |
| 90 | + | |
| 91 | +public define ProtocolResult | |
| 92 | + wait_for_reply | |
| 93 | + ( | |
| 94 | + MessageQueue mQ, | |
| 95 | + Int32 wait_cmd, | |
| 96 | + Int32 t_out | |
| 97 | + ) = | |
| 98 | + if mQ.get_next_received_Message(t_out) is | |
| 99 | + { | |
| 100 | + timeout then timeout, | |
| 101 | + closed then failure, //println("wait_for_reply closed"); | |
| 102 | + | |
| 103 | + msg(_msg) then | |
| 104 | + if *_msg.what = _CXM_ACK then | |
| 105 | + if find_int32(_msg, "CMD") is | |
| 106 | + { | |
| 107 | + failure then failure, //println("wait_for_reply CMD"); | |
| 108 | + success(cmd) then | |
| 109 | +// println("wait_for_reply CMD="+to_hexa(cmd)); | |
| 110 | + if find_int32(_msg, "STATUS") is | |
| 111 | + { | |
| 112 | + failure then failure, //println("wait_for_reply STATUS"); | |
| 113 | + success(status) then | |
| 114 | + if cmd = wait_cmd & status = _CXM_OK then | |
| 115 | + if find_message(_msg, "RESULT") is | |
| 116 | + { | |
| 117 | + failure then ok, | |
| 118 | + success(ok_message) then ok_msg(ok_message) | |
| 119 | + } | |
| 120 | + else if cmd = wait_cmd & status = _CXM_ERROR then | |
| 121 | + error | |
| 122 | + else if cmd = wait_cmd & status = _CXM_UNKNOW_CMD then | |
| 123 | + unknow_cmd | |
| 124 | + else | |
| 125 | + failure //println("wait_for_reply "); | |
| 126 | + } | |
| 127 | + } | |
| 128 | + else | |
| 129 | + failure //println("wait_for_reply not ACK"); | |
| 130 | + }. | |
| 131 | + | ... | ... |
calexium_lib/web/CXM_mime.anubis
| 1 | - | |
| 2 | - *Project* The Anubis Project | |
| 3 | - | |
| 4 | - *Title* MIME Types definition. | |
| 5 | - | |
| 6 | - *Copyright* Copyright (c) Alain Prouté 2005. | |
| 7 | - | |
| 8 | - | |
| 9 | - *Author* Alain Prouté | |
| 10 | - | |
| 1 | + | |
| 2 | + *Project* The Anubis Project | |
| 3 | + | |
| 4 | + *Title* MIME Types definition. | |
| 5 | + | |
| 6 | + *Copyright* Copyright (c) Alain Prouté 2005. | |
| 7 | + | |
| 11 | 8 | |
| 12 | - | |
| 9 | + *Authors* Alain Prouté | |
| 10 | + David René | |
| 13 | 11 | |
| 12 | + | |
| 13 | +read tools/base64.anubis | |
| 14 | +read tools/basis.anubis | |
| 15 | +read system/string.anubis | |
| 14 | 16 | |
| 15 | 17 | public type MIME: |
| 16 | 18 | mime(String name, |
| ... | ... | @@ -60,6 +62,11 @@ public define List(MIME) |
| 60 | 62 | mime("video/x-msvideo", ".avi"), |
| 61 | 63 | ]. |
| 62 | 64 | |
| 63 | - | |
| 64 | - | |
| 65 | - | |
| 66 | 65 | \ No newline at end of file |
| 66 | +public define String | |
| 67 | + to_MIME_text | |
| 68 | + ( | |
| 69 | + String charset, | |
| 70 | + String text | |
| 71 | + )= | |
| 72 | + with text = "=?"+charset+"?B?"+to_string(base64_encode(to_byte_array(text)))+"?=", | |
| 73 | + find_and_replace(text, implode([13,10]), implode([13,10,32])). | ... | ... |