public CMPPDeliver unwrapUserReport(SGIPPacket packet) {
   try {
     SGIPUserReport sgip_user_report = new SGIPUserReport(packet);
     sgip_user_report.unwrap();
     if (!sgip_user_report.isValid()) return null;
     CMPPDeliver deliver = new CMPPDeliver(packet.sequence_id);
     deliver.gateway_name = sgip_user_report.gateway_name;
     deliver.session_id = sgip_user_report.session_id;
     deliver.guid = sgip_user_report.guid;
     long msg_id = (long) sgip_user_report.node_id & 0xfffffffffL;
     msg_id <<= 32;
     msg_id |= (long) sgip_user_report.time_stamp & 0xffffffffL;
     deliver.msg_id = msg_id;
     deliver.registered_delivery = 1;
     deliver.service_id = "USERRPT";
     deliver.destination_id = sgip_user_report.sp_number;
     deliver.src_terminal_id = sgip_user_report.user_number;
     deliver.status_report.done_time = Utility.get_time_stamp(sgip_user_report.time_stamp);
     if (sgip_user_report.user_condition == 0) deliver.status_report.status = "ABOLISH";
     else if (sgip_user_report.user_condition == 1) deliver.status_report.status = "ARREAR";
     else if (sgip_user_report.user_condition == 2) deliver.status_report.status = "NORMAL";
     else deliver.status_report.status = "UNKNOWN";
     return deliver;
   } catch (Exception e) {
     Log.log(e);
   }
   Log.log(
       "SGIPExchanger("
           + m_nID
           + ","
           + m_gateway.m_strName
           + ").unwrapUserReport : unexpected exit !",
       0x2000000000000004L);
   return null;
 }
 public void dump(long lMethod) {
   Log.log(
       "\ttag = 0x" + Utility.toHexString(tag) + " (" + OptionalParameterTag.toString(tag) + ")",
       0x100000000000000L | lMethod);
   Log.log("\tlength = " + length, 0x100000000000000L | lMethod);
   Log.log("\tvalue(binary) = 0x" + Utility.toHexString(value), 0x100000000000000L | lMethod);
 }
 public SGIPPacket wrapDeliverResponse(CMPPDeliverResponse response) {
   try {
     SGIPResponse sgip_response = null;
     if (response.result == 1) sgip_response = new SGIPReportResponse(response.sequence_id);
     else if (response.result == 2)
       sgip_response = new SGIPUserReportResponse(response.sequence_id);
     else sgip_response = new SGIPDeliverResponse(response.sequence_id);
     sgip_response.gateway_name = response.gateway_name;
     sgip_response.session_id = response.session_id;
     sgip_response.guid = response.guid;
     sgip_response.node_id = (int) (response.msg_id >> 32 & -1L);
     sgip_response.time_stamp = (int) (response.msg_id & -1L);
     sgip_response.result = 0;
     sgip_response.wrap();
     return sgip_response;
   } catch (Exception e) {
     Log.log(e);
   }
   Log.log(
       "SGIPExchanger("
           + m_nID
           + ","
           + m_gateway.m_strName
           + ").wrapDeliverResponse : unexpected exit !",
       0x2000000000000004L);
   return null;
 }
 public CMPPSubmitResponse unwrapSubmitResponse(SGIPPacket packet) {
   try {
     SGIPSubmitResponse sgip_response = new SGIPSubmitResponse(packet);
     sgip_response.unwrap();
     if (!sgip_response.isValid()) {
       return null;
     } else {
       CMPPSubmitResponse response = new CMPPSubmitResponse(packet.sequence_id);
       response.gateway_name = sgip_response.gateway_name;
       response.session_id = sgip_response.session_id;
       response.guid = sgip_response.guid;
       response.result = sgip_response.result;
       long msg_id = (long) sgip_response.time_stamp & -1L;
       msg_id <<= 32;
       msg_id |= (long) sgip_response.sequence_id & -1L;
       response.msg_id = msg_id;
       return response;
     }
   } catch (Exception e) {
     Log.log(e);
   }
   Log.log(
       "SGIPExchanger("
           + m_nID
           + ","
           + m_gateway.m_strName
           + ").unwrapSubmitResponse : unexpected exit !",
       0x2000000000000004L);
   return null;
 }
 public void close() {
   try {
     if (m_socket != null) m_socket.close();
   } catch (Exception e) {
     Log.log(e);
     Log.log("CMPPXMLExchanger.close : unexpected exit !", 0x2000000800000000L);
   }
 }
 public boolean isValid() {
   if (length <= 0 || length >= 512) {
     Log.log("OptionalParameter.wrap : invalid length !", 0x100600000000000L);
     return false;
   }
   if (value == null || value.length != length) {
     Log.log("OptionalParameter.wrap : invalid valid !", 0x100600000000000L);
     return false;
   } else {
     return true;
   }
 }
 public void reencode_message_content(SGIPDeliver deliver) {
   String content = Utility.ucs2_to_gb2312(deliver.message_content);
   if (content == null) return;
   try {
     deliver.message_content = content.getBytes("GB2312");
     deliver.message_coding = 15;
     deliver.message_length = deliver.message_content.length;
   } catch (Exception e) {
     Log.log(e.getMessage(), 0x2000000000000004L);
     Log.log(e);
     Log.log("SGIPExchanger.reencode_message_content : unexpected exit !", 0x2000000000000004L);
   }
 }
Exemple #8
0
  public boolean loadReceiverSession(String strHostAddress) {
    try {
      SessionConfig sc = m_scReceiver == null ? getReceiver() : m_scReceiver;
      sc.m_address = InetAddress.getByName(strHostAddress);
      for (int i = 0; i < sc.m_nCount; i++) if (!loadSession(sc, false)) return false;

      return true;
    } catch (Exception e) {
      Log.log(e);
    }
    Log.log(
        "MISCGateway(" + m_strName + ").loadReceiverSessions : unexpected exit !",
        0x2000080000000000L);
    return false;
  }
 public void wrap(SMPPPacket packet) throws BufferException {
   Log.log("OptionalParameter.wrap : wrap elements !", 0x100800000000000L);
   dump(0x800000000000L);
   packet.addShort((short) (tag & 0xffff));
   packet.addShort((short) (length & 0xffff));
   packet.addBytes(value);
 }
 public void unwrap(SMPPPacket packet) throws BufferException {
   Log.log("OptionalParameter.unwrap : unwrap elements !", 0x100800000000000L);
   tag = packet.getShort();
   length = packet.getShort();
   value = packet.getBytes(length);
   dump(0x800000000000L);
 }
Exemple #11
0
 public CMPPQueryResponse getConfig() {
   try {
     CMPPQueryResponse response = new CMPPQueryResponse(0);
     response.gateway_name = m_strName;
     response.session_id = 0;
     response.guid = 0L;
     response.query_time = GatewayType.toString(m_gc.m_nType);
     response.query_type = 4;
     getServiceProvider(response, m_sp);
     if (m_scTransceiver != null) m_scTransceiver.getConfig(response);
     if (m_scReceiver != null) m_scReceiver.getConfig(response);
     return response;
   } catch (Exception e) {
     Log.log(e);
   }
   Log.log("MISCGateway.getConfig : unexpected exit !", 0x2000080000000000L);
   return null;
 }
 public CMPPDeliver unwrapReport(SGIPPacket packet) {
   try {
     SGIPReport sgip_report = new SGIPReport(packet);
     sgip_report.unwrap();
     SGIPReportResponse response = new SGIPReportResponse(sgip_report.sequence_id);
     response.gateway_name = sgip_report.gateway_name;
     response.sequence_id = sgip_report.sequence_id;
     response.node_id = sgip_report.node_id;
     response.time_stamp = sgip_report.time_stamp;
     response.result = 0;
     response.session_id = sgip_report.session_id;
     response.wrap();
     for (; !m_gateway.send(response); Engine.nap()) ;
     if (!sgip_report.isValid()) return null;
     CMPPDeliver deliver = new CMPPDeliver(packet.sequence_id);
     deliver.gateway_name = sgip_report.gateway_name;
     deliver.session_id = sgip_report.session_id;
     deliver.guid = sgip_report.guid;
     long msg_id = (long) sgip_report.node_id & 0xfffffffffL;
     msg_id <<= 32;
     msg_id |= (long) sgip_report.time_stamp & 0xffffffffL;
     deliver.msg_id = msg_id;
     deliver.registered_delivery = 1;
     deliver.service_id = "REPORT";
     msg_id = (long) sgip_report.packet_time_stamp & 0xfffffffffL;
     msg_id <<= 32;
     msg_id |= (long) sgip_report.packet_sequence_id & 0xffffffffL;
     deliver.status_report.msg_id = msg_id;
     deliver.status_report.submit_time = Utility.get_time_stamp(sgip_report.time_stamp);
     if (sgip_report.state == 0) deliver.status_report.status = "DELIVRD";
     else if (sgip_report.state == 1) deliver.status_report.status = "WAITING";
     else if (sgip_report.state == 2) deliver.status_report.status = "FAILED";
     else deliver.status_report.status = "UNKNOWN";
     deliver.destination_id = sgip_report.user_number;
     deliver.status_report.smsc_sequence = sgip_report.error_code;
     return deliver;
   } catch (Exception e) {
     Log.log(e);
   }
   Log.log(
       "SGIPExchanger(" + m_nID + "," + m_gateway.m_strName + ").unwrapReport : unexpected exit !",
       0x2000000000000004L);
   return null;
 }
 public void unwrap(CMPPPacket packet) throws BufferException {
   Log.log("CMPPStatusReport.unwrap : unwrap elements !", 0x4800000000000L);
   msg_id = packet.getLong();
   status = packet.getString(7);
   submit_time = packet.getString(10);
   done_time = packet.getString(10);
   dest_terminal_id = packet.getString(21);
   smsc_sequence = packet.getInteger();
   dump(0x800000000000L);
 }
 public CMPPDeliver unwrapDeliver(SGIPPacket packet) {
   try {
     SGIPDeliver sgip_deliver = new SGIPDeliver(packet);
     sgip_deliver.unwrap();
     SGIPDeliverResponse response = new SGIPDeliverResponse(sgip_deliver.sequence_id);
     response.gateway_name = sgip_deliver.gateway_name;
     response.sequence_id = sgip_deliver.sequence_id;
     response.node_id = sgip_deliver.node_id;
     response.time_stamp = sgip_deliver.time_stamp;
     response.result = (byte) sgip_deliver.checkValid();
     response.session_id = sgip_deliver.session_id;
     response.wrap();
     for (; !m_gateway.send(response); Engine.nap()) ;
     if (sgip_deliver.message_coding == 8) reencode_message_content(sgip_deliver);
     CMPPDeliver deliver = new CMPPDeliver(packet.sequence_id);
     deliver.gateway_name = sgip_deliver.gateway_name;
     deliver.session_id = sgip_deliver.session_id;
     deliver.guid = sgip_deliver.guid;
     long msg_id = (long) sgip_deliver.node_id & 0xfffffffffL;
     msg_id <<= 32;
     msg_id |= (long) sgip_deliver.time_stamp & 0xffffffffL;
     deliver.msg_id = msg_id;
     deliver.registered_delivery = 0;
     deliver.destination_id = sgip_deliver.sp_number;
     deliver.src_terminal_id = sgip_deliver.user_number;
     deliver.tp_pid = sgip_deliver.tp_pid;
     deliver.tp_udhi = sgip_deliver.tp_udhi;
     deliver.msg_fmt = sgip_deliver.message_coding;
     deliver.msg_length = sgip_deliver.message_length;
     deliver.msg_content = sgip_deliver.message_content;
     return deliver;
   } catch (Exception e) {
     Log.log(e);
   }
   Log.log(
       "SGIPExchanger("
           + m_nID
           + ","
           + m_gateway.m_strName
           + ").unwrapDeliver : unexpected exit !",
       0x2000000000000004L);
   return null;
 }
 public void wrap(CMPPPacket packet) throws BufferException {
   Log.log("CMPPStatusReport.wrap : wrap elements !", 0x4800000000000L);
   dump(0x800000000000L);
   packet.addLong(msg_id);
   packet.addString(status, 7);
   packet.addString(submit_time, 10);
   packet.addString(done_time, 10);
   packet.addString(dest_terminal_id, 21);
   packet.addInteger(smsc_sequence);
 }
 public void dump(long lMethod) {
   Log.log("消息类型=CMPP_Report,状态报告报文为: ", 0x4000000000000L | lMethod);
   Log.log("\tmsg_id = 0x" + Utility.toHexString(msg_id), 0x4000000000000L | lMethod);
   Log.log("\tstatus = \"" + status + "\"", 0x4000000000000L | lMethod);
   Log.log("\tsubmit_time = \"" + submit_time + "\"", 0x4000000000000L | lMethod);
   Log.log("\tdone_time = \"" + done_time + "\"", 0x4000000000000L | lMethod);
   Log.log("\tdest_terminal_id = \"" + dest_terminal_id + "\"", 0x4000000000000L | lMethod);
   Log.log("\tsmsc_sequence = " + smsc_sequence, 0x4000000000000L | lMethod);
 }
 public boolean isValid() {
   if (status != null && status.length() > 7) {
     Log.log("CMPPStatusReport.isValid : invalid status !", 0x4600000000000L);
     return false;
   }
   if (submit_time != null && submit_time.length() > 10) {
     Log.log("CMPPStatusReport.isValid : invalid submit_time !", 0x4600000000000L);
     return false;
   }
   if (done_time != null && done_time.length() > 10) {
     Log.log("CMPPStatusReport.isValid : invalid done_time !", 0x4600000000000L);
     return false;
   }
   if (dest_terminal_id != null && dest_terminal_id.length() > 21) {
     Log.log("CMPPStatusReport.isValid : invalid dest_terminal_id !", 0x4600000000000L);
     return false;
   } else {
     return true;
   }
 }
 public void run() {
   try {
     Log.log("CMPPXMLExchanger.run : xml exchanger startup !", 0x800000000L);
     m_nStatus = 1;
     while (isRunning()) {
       checkTimeout();
       checkAllPorters();
       if (m_socket != null) accept();
       else sleep();
     }
   } catch (Exception e) {
     Log.log(e.getMessage(), 0x2000000800000000L);
     Log.log(e);
     Log.log("CMPPXMLExchanger.run : unexpected exit !", 0x2000000800000000L);
   }
   shutdownAllPorters();
   close();
   empty();
   m_nStatus = 3;
   Log.log("CMPPXMLExchanger.run : thread stopped !", 0x800000000L);
 }
 public void accept() {
   if (m_socket == null) return;
   try {
     Socket socket = m_socket.accept();
     Log.log(
         "CMPPXMLExchanger.accept : client(" + socket.toString() + ") connected !",
         0x2000000800000000L);
     int nID = getUniquePorterID();
     CMPPXMLPorter porter = new CMPPXMLPorter(nID, socket, this);
     porter.startup();
     Engine.wait(porter);
     m_porters.addElement(porter);
   } catch (Exception e) {
   }
 }
  public void run() {
    try {
      Log.log(
          "SGIPExchanger(" + m_nID + "," + m_gateway.m_strName + ").run : thread startup !", 4L);
      m_nStatus = 1;
      for (; isRunning(); Engine.nap()) {
        if (m_gateway.isStopped()) {
          Log.log(
              "SGIPExchanger(" + m_nID + "," + m_gateway.m_strName + ").run : gateway is stopped !",
              0x2000000000000004L);
          break;
        }
        if (sgip_output == null) handleOutput();
        toGateway();
        if (m_database.isStopped()) {
          Log.log(
              "SGIPExchanger("
                  + m_nID
                  + ","
                  + m_gateway.m_strName
                  + ").run : database is stopped !",
              0x2000000000000004L);
          break;
        }
        if (cmpp_input == null) handleInput();
        toDatabase();
      }

    } catch (Exception e) {
      Log.log(e);
      Log.log(
          "SGIPExchanger(" + m_nID + "," + m_gateway.m_strName + ").run : unexpected exit !",
          0x2000000000000004L);
    }
    m_nStatus = 3;
    Log.log("SGIPExchanger(" + m_nID + "," + m_gateway.m_strName + ").run : thread stopped !", 4L);
  }
  public SGIPPacket wrapSubmit(CMPPSubmit submit) {
    try {
      if (submit.fee_terminal_id != null && !submit.fee_terminal_id.startsWith("86"))
        submit.fee_terminal_id = "86" + submit.fee_terminal_id;
      int length = submit.dest_terminal_id != null ? submit.dest_terminal_id.length : 0;
      for (int i = 0; i < length; i++)
        if (!submit.dest_terminal_id[i].startsWith("86"))
          submit.dest_terminal_id[i] = "86" + submit.dest_terminal_id[i];

      SGIPSubmit sgip_submit = new SGIPSubmit(submit.sequence_id);
      sgip_submit.gateway_name = submit.gateway_name;
      sgip_submit.session_id = submit.session_id;
      sgip_submit.guid = submit.guid;
      if (m_gateway.m_sp != null && m_gateway.m_sp.enterprise_code != null)
        if (m_gateway.m_sp.enterprise_code.length() <= 5)
          sgip_submit.node_id = 0x493e0 + Integer.parseInt(m_gateway.m_sp.enterprise_code);
        else
          sgip_submit.node_id =
              (int) (0xb2d05e00L + (long) Integer.parseInt(m_gateway.m_sp.enterprise_code));
      sgip_submit.time_stamp = Utility.get_time_stamp(Utility.toTimeString(new LeadToneDate()));
      if (m_gateway.m_sp != null) {
        sgip_submit.sp_number = m_gateway.m_sp.service_code;
        if (submit.src_terminal_id != null && submit.src_terminal_id.length() > 0)
          sgip_submit.sp_number = submit.src_terminal_id;
      }
      if (submit.fee_user_type == 0) sgip_submit.charge_number = null;
      else if (submit.fee_user_type == 1) sgip_submit.charge_number = submit.src_terminal_id;
      else if (submit.fee_user_type == 2) sgip_submit.charge_number = "000000000000000000000";
      else if (submit.fee_user_type == 3) sgip_submit.charge_number = submit.fee_terminal_id;
      sgip_submit.user_count = submit.dest_usr_tl;
      sgip_submit.user_number = submit.dest_terminal_id;
      if (m_gateway.m_sp != null && m_gateway.m_sp.enterprise_code != null)
        if (m_gateway.m_sp.enterprise_code.length() <= 5) {
          sgip_submit.corporation_id = m_gateway.m_sp.enterprise_code;
        } else {
          int nLength = m_gateway.m_sp.enterprise_code.length();
          sgip_submit.corporation_id = m_gateway.m_sp.enterprise_code.substring(nLength - 5);
        }
      sgip_submit.service_type = submit.service_id;
      if (submit.fee_type != null)
        if (submit.fee_type.equals("00")) sgip_submit.fee_type = 0;
        else if (submit.fee_type.equals("01")) sgip_submit.fee_type = 1;
        else if (submit.fee_type.equals("02")) sgip_submit.fee_type = 2;
        else if (submit.fee_type.equals("03")) sgip_submit.fee_type = 3;
        else if (submit.fee_type.equals("04")) sgip_submit.fee_type = 3;
        else if (submit.fee_type.equals("05")) sgip_submit.fee_type = 4;
      sgip_submit.fee_value = submit.fee_code;
      sgip_submit.given_value = submit.given_value;
      sgip_submit.agent_flag = submit.agent_flag;
      sgip_submit.mo_relate_to_mt_flag = submit.mo_relate_to_mt_flag;
      sgip_submit.priority = submit.msg_level;
      sgip_submit.expire_time = submit.valid_time;
      sgip_submit.schedule_time = submit.at_time;
      if (submit.registered_delivery == 0) sgip_submit.report_flag = 2;
      else if (submit.registered_delivery == 1) sgip_submit.report_flag = 1;
      else if (submit.registered_delivery == 2) {
        sgip_submit.report_flag = 3;
        sgip_submit.mo_relate_to_mt_flag = 3;
      }
      sgip_submit.tp_pid = submit.tp_pid;
      sgip_submit.tp_udhi = submit.tp_udhi;
      sgip_submit.message_coding = submit.msg_fmt;
      sgip_submit.message_type = 0;
      sgip_submit.message_length = submit.msg_length;
      sgip_submit.message_content = submit.msg_content;
      sgip_submit.wrap();
      return sgip_submit;
    } catch (Exception e) {
      Log.log(e);
    }
    Log.log(
        "SGIPExchanger(" + m_nID + "," + m_gateway.m_strName + ").wrapSubmit : unexpected exit !",
        0x2000000000000004L);
    return null;
  }