Esempio n. 1
0
int roadmap_ssl_open ( RoadMapSocket s, void *data, RoadMapNetSslConnectCallback callback )
{
   static BOOL initialized = FALSE;
   const SSL_METHOD *method;
   SSL_CTX *ctx;
   SSL *ssl;

   // Initialize the library
   if ( !initialized )
   {
      SSL_library_init();
   }
   /*
    * Initialize the ssl context
    */
   OpenSSL_add_all_algorithms();      /* Load cryptos, et.al. */
   SSL_load_error_strings();          /* Bring in and register error messages */
   method = SSLv23_client_method();    /* Create new client-method instance */
   ctx = SSL_CTX_new( method );       /* Create new context */
   if ( ctx == NULL )
   {
      roadmap_log( ROADMAP_ERROR, "Error obtaining ssl context: %s !!", last_err_string() );
      return 0;
   }

   ssl = SSL_new( ctx );                /* SSL connection state */
   SSL_set_fd( ssl, roadmap_net_get_fd( s ) );             /* Attach the socket */

   /*
    * Initialize the io context
    */

   RoadMapSslIO ssl_io_ctx = malloc( sizeof( struct roadmap_ssl_io_t ) );
   roadmap_check_allocated( ssl_io_ctx );

   ssl_io_ctx->ctx = ctx;
   ssl_io_ctx->ssl = ssl;
   ssl_io_ctx->s = s;
   ssl_io_ctx->data = data;
   ssl_io_ctx->on_connect = callback;

   if ( SSL_connect(ssl) == -1 )       /* perform the connection */
   {
      roadmap_log( ROADMAP_ERROR, "Error connecting ssl!!" );
      log_ssl();
      callback( s, data, ssl_io_ctx, err_net_failed );
      return 0;
   }

   callback( s, data, ssl_io_ctx, succeeded );

   return 1;
}
Esempio n. 2
0
static void set_io_handler(RoadMapIO *io, GIOCondition condition, RoadMapInput callback)
{
   int i;
   int fd = io->os.file; /* All the same on UNIX. */

   if (io->subsystem == ROADMAP_IO_NET)
	fd = roadmap_net_get_fd(io->os.socket);

   for (i = 0; i < ROADMAP_MAX_IO; ++i) {
      if (RoadMapMainIo[i].io.subsystem == ROADMAP_IO_INVALID) {
	 io->data = &RoadMapMainIo[i];
         RoadMapMainIo[i].io = *io;
         RoadMapMainIo[i].callback = callback;
	 RoadMapMainIo[i].start_time = condition == G_IO_OUT ? time(NULL) : 0;
         RoadMapMainIo[i].id = add_io_handler(fd, condition, &RoadMapMainIo[i]);
         break;
      }
   }
}