Commit 90f8df96afcf7139d44f1568a58f7a3d6d8db0da

Authored by Cédric RICARD
1 parent a5322e9e

Removed _CXM_DOMAIN_STORE_NAME for security reason (was an old and no more used message).

Added generic client code
calexium_lib/CXM_message_constants.anubis
@@ -54,7 +54,7 @@ public define Int32 _CXM_LOGGER_LOG = 0x33771802. @@ -54,7 +54,7 @@ public define Int32 _CXM_LOGGER_LOG = 0x33771802.
54 // MF <-> DomainManager 54 // MF <-> DomainManager
55 public define Int32 _CXM_DOMAIN_SERVICE_MSG_BASIS = 0x33771C00. // 55 public define Int32 _CXM_DOMAIN_SERVICE_MSG_BASIS = 0x33771C00. //
56 public define Int32 _CXM_DOMAIN_SERVICE_ID = 0x33771C01. 56 public define Int32 _CXM_DOMAIN_SERVICE_ID = 0x33771C01.
57 -public define Int32 _CXM_DOMAIN_STORE_NAME = 0x33771C02. 57 +//public define Int32 _CXM_DOMAIN_STORE_NAME = 0x33771C02. // No more used (security hole
58 public define Int32 _CXM_DOMAIN_GET_NAME = 0x33771C03. 58 public define Int32 _CXM_DOMAIN_GET_NAME = 0x33771C03.
59 public define Int32 _CXM_DOMAIN_GET_MY_IP = 0x33771C04. 59 public define Int32 _CXM_DOMAIN_GET_MY_IP = 0x33771C04.
60 public define Int32 _CXM_DOMAIN_PUBLISH_MY_IP = 0x33771C05. 60 public define Int32 _CXM_DOMAIN_PUBLISH_MY_IP = 0x33771C05.
@@ -69,4 +69,4 @@ public define Int32 _CXM_GANDI_CREATE_CONTACT = 0x33771D02. // &#39;CLASS&#39; (S @@ -69,4 +69,4 @@ public define Int32 _CXM_GANDI_CREATE_CONTACT = 0x33771D02. // &#39;CLASS&#39; (S
69 // --> CXM_ACK with 'CONTACT_HANDLE' (String): Created handle for this contact 69 // --> CXM_ACK with 'CONTACT_HANDLE' (String): Created handle for this contact
70 public define Int32 _CXM_GANDI_CREATE_DOMAIN = 0x33771D03. // 'DOMAIN' (String): Domain full name 70 public define Int32 _CXM_GANDI_CREATE_DOMAIN = 0x33771D03. // 'DOMAIN' (String): Domain full name
71 // 'OWNER' (String): Owner handle 71 // 'OWNER' (String): Owner handle
72 - // --> CXM_ACK 72 + // --> CXM_ACK with 'DOMAIN_HANDLE' (String): Created handle for this domain
calexium_lib/net_services/CXM_generic_client.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: ricard
  4 + * Date: 02/02/2008
  5 + * Time: 11:47
  6 + *
  7 + * To change this template use Tools | Options | Coding | Edit Standard Headers.
  8 + */
  9 +
  10 +
  11 +read tools/basis.anubis
  12 +read system/muscle.anubis
  13 +read system/data_io.anubis
  14 +read system/convert.anubis
  15 +read system/string.anubis
  16 +read system/message_queue.anubis
  17 +read system/message_transceiver.anubis
  18 +
  19 +read calexium_lib/CXM_message_constants.anubis
  20 +read calexium_lib/net_services/CXM_net_services.anubis
  21 +read calexium_lib/net_services/CXM_generic_protocol.anubis
  22 +
  23 +// --Generic types---------------------------------------------------------------------
  24 +public type NetServiceAnswer:
  25 + netservice_error (Int32 cmd,
  26 + Int32 result_code,
  27 + String result_string),
  28 + netservice_ok (Int32 cmd,
  29 + Maybe(Message) result_msg).
  30 +
  31 +// --Generic functions---------------------------------------------------------------------
  32 +
  33 +
  34 +public define Maybe(NetServiceAnswer)
  35 + generic_send_message
  36 + (
  37 + MessageQueue queue,
  38 + Message msg_to_send,
  39 + Int32 timeout,
  40 + (String) -> One logger
  41 + )=
  42 + queue.add_Message_to_send(msg_to_send);
  43 + if queue.get_next_received_Message(timeout) is
  44 + {
  45 + timeout then logger("["+queue.get_name(unique)+"]: receive timeout");failure,
  46 + closed then logger("["+queue.get_name(unique)+"]: socket closed");failure,
  47 + msg(msg) then
  48 + if find_int32(msg, "CMD") is
  49 + {
  50 + failure then logger("["+queue.get_name(unique)+"]: CMD field not found"); failure,
  51 + success(cmd) then
  52 + if find_int32(msg, "STATUS") is
  53 + {
  54 + failure then logger("["+queue.get_name(unique)+"]: STATUS field not found"); failure,
  55 + success(v) then
  56 + if v = _CXM_OK then
  57 + success(netservice_ok(cmd, find_message(msg, "RESULT")))
  58 + else
  59 + with error_string = if find_string(msg, "STATUS_STR") is success(s) then s else "",
  60 + success(netservice_error(cmd, v, error_string))
  61 + }
  62 + }
  63 + }.
  64 +
  65 +define Maybe($T)
  66 + generic_handler
  67 + (
  68 + MessageQueue queue,
  69 + Message msg_to_send,
  70 + (Message) -> Maybe($T) handler,
  71 + (String) -> One logger
  72 + )=
  73 + queue.add_Message_to_send(msg_to_send);
  74 + if queue.get_next_received_Message(10) is
  75 + {
  76 + timeout then logger("["+queue.get_name(unique)+"]: receive timeout");failure,
  77 + closed then logger("["+queue.get_name(unique)+"]: socket closed");failure,
  78 + msg(msg) then
  79 + if find_int32(msg, "STATUS") is
  80 + {
  81 + failure then logger("["+queue.get_name(unique)+"]: status not found");failure,
  82 + success(v) then
  83 + if v = _CXM_OK then
  84 + //println("generic_handler("+queue.get_name(unique)+"): message status ok");
  85 + if find_message(msg, "RESULT") is
  86 + {
  87 + failure then logger("["+queue.get_name(unique)+"]: can't find RESULT");failure,
  88 + success(result) then handler(result)
  89 + }
  90 + else
  91 + logger("["+queue.get_name(unique)+"]: message status ERROR");failure
  92 + }
  93 + }.
  94 +
  95 +public define (MessageQueue) -> Maybe($T)
  96 + make_generic_handler
  97 + (
  98 + Message msg_to_send,
  99 + (Message) -> Maybe($T) handler,
  100 + (String) -> One logger
  101 + ) =
  102 + (MessageQueue queue) |->
  103 + generic_handler(queue, msg_to_send, handler, logger).
  104 +
  105 +define Maybe($T)
  106 + generic_request_for_service
  107 + (
  108 + MessageQueue queue,
  109 + Int32 service_id,
  110 + Int32 service_version,
  111 + (MessageQueue) -> Maybe($T) handler,
  112 + (String) -> One logger
  113 + )=
  114 + with test_msg = message(_CXM_REQUEST_FOR_SERVICE),
  115 + forget(add_int32(test_msg, "service", service_id));
  116 + forget(add_int32(test_msg, "version", service_version));
  117 + queue.add_Message_to_send(test_msg);
  118 + if queue.get_next_received_Message(10) is
  119 + {
  120 + timeout then logger("["+queue.get_name(unique)+"]: requesting service receive timeout");failure,
  121 + closed then logger("["+queue.get_name(unique)+"]: requesting service socket closed");failure,
  122 + msg(msg) then
  123 + if find_int32(msg, "STATUS") is
  124 + {
  125 + failure then logger("["+queue.get_name(unique)+"]: requesting service status not found");failure,
  126 + success(v) then
  127 + if v = _CXM_OK then
  128 + handler(queue)
  129 + else
  130 + logger("["+queue.get_name(unique)+"]: requested service started won't start");failure
  131 + }
  132 + }.
  133 +
  134 +public define Maybe($T)
  135 + generic_connect_to_net_service
  136 + (
  137 + String queue_name,
  138 + Int32 server,
  139 + Int32 port,
  140 + Int32 service_id,
  141 + Int32 service_version,
  142 + (MessageQueue) -> Maybe($T) handler,
  143 + (String) -> One logger
  144 + )
  145 + =
  146 + if connect( server, port) is
  147 + {
  148 + error(_) then logger(queue_name + ": Can't connect to domain manager ["+ip_addr_to_string(server)+":"+port+"]");failure,
  149 + ok(conn) then
  150 + with queue = create_MessageQueue(queue_name),
  151 + message_transceiver(conn, queue);
  152 + with result = generic_request_for_service(queue, service_id, service_version, handler, logger),
  153 + queue.quit(unique);
  154 + //logInfo(debug_log,"domain_manager client quit");
  155 + result
  156 + }.