Ejemplo n.º 1
0
static ssize_t pn_input_read_sasl(pn_transport_t* transport, unsigned int layer, const char* bytes, size_t available)
{
  pni_sasl_t *sasl = transport->sasl;

  bool eos = pn_transport_capacity(transport)==PN_EOS;
  if (eos) {
    pn_do_error(transport, "amqp:connection:framing-error", "connection aborted");
    pn_set_error_layer(transport);
    return PN_EOS;
  }

  pni_sasl_start_server_if_needed(transport);

  if (!pni_sasl_is_final_input_state(sasl)) {
    return pn_dispatcher_input(transport, bytes, available, false, &transport->halt);
  }

  if (pni_sasl_impl_can_encrypt(transport)) {
    sasl->max_encrypt_size = pni_sasl_impl_max_encrypt_size(transport);
    if (transport->trace & PN_TRACE_DRV)
      pn_transport_logf(transport, "SASL Encryption enabled: buffer=%d", sasl->max_encrypt_size);
    transport->io_layers[layer] = &sasl_encrypt_layer;
  } else if (sasl->client) {
    transport->io_layers[layer] = &pni_passthru_layer;
  } else {
    return pni_passthru_layer.process_input(transport, layer, bytes, available);
  }
  return transport->io_layers[layer]->process_input(transport, layer, bytes, available);
}
Ejemplo n.º 2
0
ssize_t pn_sasl_input(pn_sasl_t *sasl, char *bytes, size_t available)
{
  ssize_t n = pn_dispatcher_input(sasl->disp, bytes, available);
  if (n < 0) return n;

  pn_sasl_process(sasl);

  if (sasl->rcvd_done) {
    if (pn_sasl_state(sasl) == PN_SASL_PASS) {
      if (n) {
        return n;
      } else {
        return PN_EOS;
      }
    } else {
      // XXX: should probably do something better here
      return PN_ERR;
    }
  } else {
    return n;
  }
}