Exemplo n.º 1
0
static int send_one_packet(const char *packet_body, mbedtls_ssl_context *ssl) {
  int ret, len;
  unsigned char buf[10000];

  plog("sending packet: '%s'", packet_body);

  len = strlen(packet_body);

  do {
    ret = mbedtls_ssl_write(ssl, (unsigned char *)packet_body, len);
  } while (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE);

  if (ret < 0) {
    plog("ERROR: mbedtls_ssl_write returned %d", ret);
    return ret;
  }

  len = ret;
  plog("%d bytes written: '%s'", len, packet_body);

  if (strncmp("noreply", packet_body, 7) == 0) {
    /* Outgoing packet begins with "noreply", so don't attempt to read a
     * response from the server. Just return successfully. */
    return 0;
  }

  plog("Read from server...");

  len = sizeof(buf) - 1;
  memset(buf, 0, sizeof(buf));

  do {
    ret = mbedtls_ssl_read(ssl, buf, len);
  } while (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE);

  if (ret <= 0) {
    switch (ret) {
      case MBEDTLS_ERR_SSL_TIMEOUT:
        plog("ERROR: timeout");
        return ret;

      case MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY:
        plog("ERROR: connection was closed gracefully");
        return ret;

      default:
        plog("ERROR: mbedtls_ssl_read returned -0x%x", -ret);
        return ret;
    }
  }

  len = ret;
  plog("%d bytes read: '%s'", len, buf);

  if (is_reverse(packet_body, (char *)buf)) {
    return 0;                   /* Success */
  }
  return -1;
}
Exemplo n.º 2
0
Arquivo: 401.cpp Projeto: Accoral/uva
void judge ( char x, char y, bool &palindrome, bool &mirrored) { //1:palindrome 2:mirrored 3:neither
	palindrome = ( x == y );
	mirrored = is_reverse ( x, y );
}