{
struct glb_ctx *new_ctx = NULL;
int err = 0;
-
+
/*create context*/
new_ctx = (struct glb_ctx *) malloc(sizeof(*new_ctx));
if (!new_ctx) {
- err=1; //use errno instead
+ err=1; //use errno instead
//set_error(ctx->err_msg);
- goto end;
+ goto end;
}
/*openssl init. -check return value
/*delete content*/
if (ctx->io_ctx) {
- canl_io_destroy(ctx, ctx->io_ctx);
- ctx->io_ctx = NULL;
+ canl_io_destroy(ctx, ctx->io_ctx);
+ ctx->io_ctx = NULL;
}
if (ctx->err_msg) {
struct io_handler *new_io_h = NULL;
if (!cc) {
- goto end;
+ goto end;
}
/*create io handler*/
new_io_h = (struct io_handler *) malloc(sizeof(*new_io_h));
if (!new_io_h)
//set_error(ctx->err_msg);
- goto end;
+ goto end;
/*read cc and set io_handler accordingly ...*/
}
int canl_io_connect(canl_ctx cc, canl_io_handler io, char * host, int port,
- int flags, cred_handler ch, struct timeval *timeout)
+ int flags, cred_handler ch, struct timeval *timeout)
{
int err;
struct io_handler *io_cc = (struct io_handler*) io;
/*check cc and io*/
if (!cc) {
err = 1;
- goto end;
+ goto end;
}
if (!io) {
//set_error(ctx->err_msg);
- err = 1;
- goto end;
+ err = 1;
+ goto end;
}
/*dns*/
/*write succes or failure to cc, io*/
//if (err)
- /*cc or io set error*/
+ /*cc or io set error*/
//else
- /*cc or io set succes*/
+ /*cc or io set succes*/
end:
return err;
}
int canl_io_accept(canl_ctx cc, canl_io_handler io, int port,
- int flags, cred_handler ch, struct timeval *timeout,
- canl_io_handler *new_io)
+ int flags, cred_handler ch, struct timeval *timeout,
+ canl_io_handler *new_io)
{
int err;
struct io_handler *io_cc = (struct io_handler*) io;
/*check cc and io*/
if (!cc) {
err = 1;
- goto end;
+ goto end;
}
if (!io) {
//set_error(ctx->err_msg);
- err = 1;
- goto end;
+ err = 1;
+ goto end;
}
/*check cc and io*/
/*write succes or failure to cc, io*/
//if (err)
- /*cc or io set error*/
+ /*cc or io set error*/
//else
- /*cc or io set succes*/
+ /*cc or io set succes*/
end:
return err;
/*check cc and io*/
if (!cc) {
err = 1;
- goto end;
+ goto end;
}
if (!io) {
//set_error(ctx->err_msg);
- err = 1;
- goto end;
+ err = 1;
+ goto end;
}
-
+
/*ssl close*/
/*set cc and io accordingly*/
/*check cc and io*/
if (!cc) {
err = 1;
- goto end;
+ goto end;
}
if (!io) {
//set_error(ctx->err_msg);
- err = 1;
+ err = 1;
}
// delete io_handle content
-
+
// delete io itself
if (io) {
- free (io);
- io = NULL;
+ free (io);
+ io = NULL;
}
end:
return err;
int err = 0;
if (!cc) {
err = 1;
- goto end;
+ goto end;
}
if (!io) {
//set_error(ctx->err_msg);
- err = 1;
- goto end;
+ err = 1;
+ goto end;
}
//read something using openssl
int err;
if (!cc) {
err = 1;
- goto end;
+ goto end;
}
if (!io) {
//set_error(ctx->err_msg);
- err = 1;
- goto end;
+ err = 1;
+ goto end;
}
//write sometring using openssl
canl_io_handler canl_create_io_handler(canl_ctx cc);
int canl_io_connect(canl_ctx cc, canl_io_handler io, char * host,
- int port, int flags, cred_handler ch, struct timeval *timeout);
+ int port, int flags, cred_handler ch, struct timeval *timeout);
int canl_io_accept(canl_ctx cc, canl_io_handler io, int port, int flags, cred_handler ch,
- struct timeval *timeout, canl_io_handler * new_io);
+ struct timeval *timeout, canl_io_handler * new_io);
size_t canl_io_read(canl_ctx cc, canl_io_handler io, void *buffer, size_t size, struct timeval *timeout);
size_t canl_io_write(canl_ctx cc, canl_io_handler io, void *buffer, size_t size, struct timeval *timeout);
my_ctx = canl_create_ctx();
if (!my_ctx){
- // set_error("context cannot be created\n");
- goto end;
+ // set_error("context cannot be created\n");
+ goto end;
}
my_io_h = canl_create_io_handler(my_ctx);
if (!my_io_h) {
- //set_error("io handler cannot be created\n");
- goto end;
+ //set_error("io handler cannot be created\n");
+ goto end;
}
err = canl_io_connect(my_ctx, my_io_h, NULL, 1234, 0, NULL, NULL);
if (err) {
- //set_error("cannot make a connection");
- goto end;
+ //set_error("cannot make a connection");
+ goto end;
}
err = canl_io_write (my_ctx, my_io_h, NULL, 0, NULL);
if (err) {
- //set_error ("cannot write");
+ //set_error ("cannot write");
}
-
+
err = canl_io_read (my_ctx, my_io_h, NULL, 0, NULL);
if (err) {
- //set_error ("cannot read");
+ //set_error ("cannot read");
}
err = canl_io_close(my_ctx, my_io_h);
if (err){
- //set_error ("cannot close io");
+ //set_error ("cannot close io");
}
err = canl_io_destroy(my_ctx, my_io_h);
if (err){
- //set_error ("cannot destroy io");
+ //set_error ("cannot destroy io");
}
end:
canl_io_get_error(my_ctx, &err_msg);
if (err_msg != NULL)
printf("%s\n", err_msg);
-
+
canl_free_ctx(my_ctx);
return err;
my_ctx = canl_create_ctx();
if (!my_ctx){
- // set_error("context cannot be created\n");
- goto end;
+ // set_error("context cannot be created\n");
+ goto end;
}
my_io_h = canl_create_io_handler(my_ctx);
if (!my_io_h) {
- //set_error("io handler cannot be created\n");
- goto end;
+ //set_error("io handler cannot be created\n");
+ goto end;
}
err = canl_io_accept(my_ctx, my_io_h, 1234, 0, NULL, NULL, NULL);
err = canl_io_connect(my_ctx, my_io_h, NULL, 1234, 0, NULL, NULL);
if (err) {
- //set_error("cannot make a connection");
- canl_io_destroy(my_ctx, my_io_h);
- goto end;
+ //set_error("cannot make a connection");
+ canl_io_destroy(my_ctx, my_io_h);
+ goto end;
}
err = canl_io_write (my_ctx, my_io_h, NULL, 0, NULL);
if (err) {
- //set_error ("cannot write");
+ //set_error ("cannot write");
}
-
+
err = canl_io_read (my_ctx, my_io_h, NULL, 0, NULL);
if (err) {
- //set_error ("cannot read");
+ //set_error ("cannot read");
}
err = canl_io_close(my_ctx, my_io_h);
if (err){
- //set_error ("cannot close io");
+ //set_error ("cannot close io");
}
err = canl_io_destroy(my_ctx, my_io_h);
if (err){
- //set_error ("cannot destroy io");
+ //set_error ("cannot destroy io");
}
end:
canl_io_get_error(my_ctx, &err_msg);
if (err_msg != NULL)
printf("%s\n", err_msg);
-
+
canl_free_ctx(my_ctx);
return err;