Skip to content

Commit

Permalink
Added wrapper and missing memory deallocation.
Browse files Browse the repository at this point in the history
  • Loading branch information
interkosmos committed Oct 6, 2024
1 parent 25994b4 commit 1481d5f
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/xmpp.f90
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ module xmpp
public :: xmpp_send_raw_string
public :: xmpp_send_raw_string_
public :: xmpp_sha1
public :: xmpp_sha1_
public :: xmpp_sha1_digest
public :: xmpp_sha1_final
public :: xmpp_sha1_free
Expand Down Expand Up @@ -1056,14 +1057,14 @@ subroutine xmpp_send_raw_string_(conn, str) bind(c, name='xmpp_send_raw_string_'
end subroutine xmpp_send_raw_string_

! char *xmpp_sha1(xmpp_ctx_t *ctx, const unsigned char *data, size_t len)
function xmpp_sha1(ctx, data, len) bind(c, name='xmpp_sha1')
function xmpp_sha1_(ctx, data, data_len) bind(c, name='xmpp_sha1')
import :: c_char, c_ptr, c_size_t
implicit none
type(c_ptr), intent(in), value :: ctx
character(kind=c_char), intent(in) :: data
integer(kind=c_size_t), intent(in), value :: len
type(c_ptr) :: xmpp_sha1
end function xmpp_sha1
integer(kind=c_size_t), intent(in), value :: data_len
type(c_ptr) :: xmpp_sha1_
end function xmpp_sha1_

! void xmpp_sha1_digest(const unsigned char *data, size_t len, unsigned char *digest)
subroutine xmpp_sha1_digest(data, len, digest) bind(c, name='xmpp_sha1_digest')
Expand Down Expand Up @@ -1687,6 +1688,7 @@ function xmpp_conn_send_queue_drop_element(conn, which)

ptr = xmpp_conn_send_queue_drop_element_(conn, which)
call c_f_str_ptr(ptr, xmpp_conn_send_queue_drop_element)
call xmpp_free(xmpp_conn_get_context(conn), ptr)
end function xmpp_conn_send_queue_drop_element

subroutine xmpp_conn_set_cafile(conn, path)
Expand Down Expand Up @@ -1974,6 +1976,26 @@ subroutine xmpp_send_raw_string(conn, str)
call xmpp_send_raw_string_(conn, str // c_null_char)
end subroutine xmpp_send_raw_string

function xmpp_sha1(ctx, data, data_len)
type(c_ptr), intent(in) :: ctx
character(len=*), intent(in) :: data
integer(kind=c_size_t), intent(in), optional :: data_len
character(len=:), allocatable :: xmpp_sha1

integer(kind=c_size_t) :: n
type(c_ptr) :: ptr

if (present(data_len)) then
n = data_len
else
n = len(data, kind=c_size_t)
end if

ptr = xmpp_sha1_(ctx, data, n)
call c_f_str_ptr(ptr, xmpp_sha1)
call xmpp_free(ctx, ptr)
end function xmpp_sha1

subroutine xmpp_sha1_free(sha1)
type(c_ptr), intent(inout) :: sha1

Expand Down

0 comments on commit 1481d5f

Please sign in to comment.